Use reflection for adding Unity log callback to avoid unstripping errors

This commit is contained in:
Sinai 2021-03-24 17:13:43 +11:00
parent 594abc47f8
commit 77878ddd94

View File

@ -2,6 +2,8 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Reflection;
using BF = System.Reflection.BindingFlags;
using System.Text; using System.Text;
using UnhollowerBaseLib; using UnhollowerBaseLib;
using UnhollowerRuntimeLib; using UnhollowerRuntimeLib;
@ -21,14 +23,22 @@ namespace UnityExplorer.Core.Runtime.Il2Cpp
public override void SetupEvents() public override void SetupEvents()
{ {
Application.add_logMessageReceived( try
new Action<string, string, LogType>(ExplorerCore.Instance.OnUnityLog)); {
//Application.add_logMessageReceived(new Action<string, string, LogType>(ExplorerCore.Instance.OnUnityLog));
//SceneManager.add_sceneLoaded( var logType = ReflectionUtility.GetTypeByName("UnityEngine.Application+LogCallback");
// new Action<Scene, LoadSceneMode>(ExplorerCore.Instance.OnSceneLoaded1)); var castMethod = logType.GetMethod("op_Implicit", new[] { typeof(Action<string, string, LogType>) });
var addMethod = typeof(Application).GetMethod("add_logMessageReceived", BF.Static | BF.Public, null, new[] { logType }, null);
//SceneManager.add_activeSceneChanged( addMethod.Invoke(null, new[]
// new Action<Scene, Scene>(ExplorerCore.Instance.OnSceneLoaded2)); {
castMethod.Invoke(null, new[] { new Action<string, string, LogType>(ExplorerCore.Instance.OnUnityLog) })
});
}
catch
{
ExplorerCore.LogWarning("Exception setting up Unity log listener, make sure Unity libraries have been unstripped!");
}
} }
internal delegate IntPtr d_LayerToName(int layer); internal delegate IntPtr d_LayerToName(int layer);