mirror of
https://github.com/sinai-dev/UnityExplorer.git
synced 2025-01-07 10:03:38 +08:00
Use reflection for adding Unity log callback to avoid unstripping errors
This commit is contained in:
parent
594abc47f8
commit
77878ddd94
@ -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);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user