[fix] 修复MonoHook在2020.3.x系列编辑器compile的时候,有可能发生hook没有及时注入从而导致打iOS包失败

[fix]  较高版本的Unity GetFunctionPointer不再依赖GUISkin.current,反而高版本unity的GUISkin.current这个值不会立即有值,导致在编辑器compile等时候,hook没有及时注入从而导致打iOS包失败

---------

Co-authored-by: liaoqiang <liaoqiang@nibirutech.com>
main
Jonson 2023-03-28 13:25:32 +08:00 committed by GitHub
parent 75cb53cb19
commit 1d5f2a953c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 6 deletions

View File

@ -1,4 +1,4 @@
/* /*
Desc: Hook Mono UnityEditor.dll Desc: Hook Mono UnityEditor.dll
Author: Misaka Mikoto Author: Misaka Mikoto
Github: https://github.com/Misaka-Mikoto-Tech/MonoHook Github: https://github.com/Misaka-Mikoto-Tech/MonoHook
@ -85,7 +85,7 @@ namespace MonoHook
private CodePatcher _codePatcher; private CodePatcher _codePatcher;
#if UNITY_EDITOR #if UNITY_EDITOR && !UNITY_2020_3_OR_NEWER
/// <summary> /// <summary>
/// call `MethodInfo.MethodHandle.GetFunctionPointer()` /// call `MethodInfo.MethodHandle.GetFunctionPointer()`
/// will visit static class `UnityEditor.IMGUI.Controls.TreeViewGUI.Styles` and invoke its static constructor, /// will visit static class `UnityEditor.IMGUI.Controls.TreeViewGUI.Styles` and invoke its static constructor,
@ -97,7 +97,7 @@ namespace MonoHook
static MethodHook() static MethodHook()
{ {
#if UNITY_EDITOR #if UNITY_EDITOR && !UNITY_2020_3_OR_NEWER
s_fi_GUISkin_current = typeof(GUISkin).GetField("current", BindingFlags.Static | BindingFlags.NonPublic); s_fi_GUISkin_current = typeof(GUISkin).GetField("current", BindingFlags.Static | BindingFlags.NonPublic);
#endif #endif
} }
@ -126,7 +126,7 @@ namespace MonoHook
if (isHooked) if (isHooked)
return; return;
#if UNITY_EDITOR #if UNITY_EDITOR && !UNITY_2020_3_OR_NEWER
if (s_fi_GUISkin_current.GetValue(null) != null) if (s_fi_GUISkin_current.GetValue(null) != null)
DoInstall(); DoInstall();
else else
@ -191,7 +191,7 @@ namespace MonoHook
if (targetMethod.IsAbstract) if (targetMethod.IsAbstract)
throw new Exception($"WRANING: you can not hook abstract method [{methodName}]"); throw new Exception($"WRANING: you can not hook abstract method [{methodName}]");
#if UNITY_EDITOR #if UNITY_EDITOR && !UNITY_2020_3_OR_NEWER
int minMethodBodySize = 10; int minMethodBodySize = 10;
{ {
@ -358,7 +358,7 @@ namespace MonoHook
} }
} }
#if UNITY_EDITOR #if UNITY_EDITOR && !UNITY_2020_3_OR_NEWER
private void OnEditorUpdate() private void OnEditorUpdate()
{ {
if (s_fi_GUISkin_current.GetValue(null) != null) if (s_fi_GUISkin_current.GetValue(null) != null)