Browse Source

Don't use Mono unmanaged call to determine Unity log icall

Bepis 6 years ago
parent
commit
5a103e9c99
1 changed files with 10 additions and 5 deletions
  1. 10 5
      BepInEx/Logging/UnityLogListener.cs

+ 10 - 5
BepInEx/Logging/UnityLogListener.cs

@@ -1,7 +1,6 @@
 using System;
 using System.Reflection;
 using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
 
 namespace BepInEx.Logging
 {
@@ -12,19 +11,25 @@ namespace BepInEx.Logging
 	{
 		internal static readonly Action<string> WriteStringToUnityLog;
 
-		[DllImport("mono.dll", EntryPoint = "mono_lookup_internal_call")]
-		private static extern IntPtr MonoLookupInternalCall(IntPtr gconstpointer);
-
 		static UnityLogListener()
 		{
 			foreach (MethodInfo methodInfo in typeof(UnityEngine.UnityLogWriter).GetMethods(BindingFlags.Static | BindingFlags.Public))
 			{
-				if (MonoLookupInternalCall(methodInfo.MethodHandle.Value) == IntPtr.Zero)
+				try
+				{
+					methodInfo.Invoke(null, new object[] { "" });
+				}
+				catch
+				{
 					continue;
+				}
 
 				WriteStringToUnityLog = (Action<string>)Delegate.CreateDelegate(typeof(Action<string>), methodInfo);
 				break;
 			}
+			
+			if (WriteStringToUnityLog == null)
+				Logger.LogError("Unable to start Unity log writer");
 		}
 
 		public void LogEvent(object sender, LogEventArgs eventArgs)