v5: Fix log writer errors for Unity 6 (#1264)

This commit is contained in:
Soggy_Pancake authored and GitHub committed 2026-02-08 00:54:32 +01:00
1 parent 3e8aebdb9b
commit 37f0a9aa5a
1 file changed
+17 -1
+17 -1
View File
@@ -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<string>)Delegate.CreateDelegate(typeof(Action<string>), methodInfo);
} catch { }
}
if (WriteStringToUnityLog == null)
Logger.LogError("Unable to start Unity log writer");
}