diff --git a/BepInEx/Logging/UnityLogListener.cs b/BepInEx/Logging/UnityLogListener.cs index 08cfa24..30a47d9 100644 --- a/BepInEx/Logging/UnityLogListener.cs +++ b/BepInEx/Logging/UnityLogListener.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Reflection; using System.Runtime.CompilerServices; using System.Text; @@ -30,6 +30,22 @@ namespace BepInEx.Logging break; } + // Fix for Unity 6. Both methods previously targeted no longer use internal calls + if (WriteStringToUnityLog == null) + { + try + { + var type = Type.GetType("UnityEngine.UnityLogWriter, UnityEngine.CoreModule"); + var methodInfo = type.GetMethod("WriteStringToUnityLogImpl", + BindingFlags.Static | BindingFlags.NonPublic, + null, + new Type[] { typeof(string) }, + null); + methodInfo.Invoke(null, new object[] { "" }); + WriteStringToUnityLog = (Action)Delegate.CreateDelegate(typeof(Action), methodInfo); + } catch { } + } + if (WriteStringToUnityLog == null) Logger.LogError("Unable to start Unity log writer"); }