From 9c1d4596554773c4cce9fbccba837c927800e16c Mon Sep 17 00:00:00 2001 From: Sinai <49360850+sinai-dev@users.noreply.github.com> Date: Sat, 20 Nov 2021 17:47:01 +1100 Subject: [PATCH] Use PatchProcessor ctor directly instead of Harmony.CreatePatchProcessor --- src/Core/Input/CursorUnlocker.cs | 4 ++-- src/Core/Reflection/Patches.cs | 2 +- src/ExplorerCore.cs | 6 +++++- src/Hooks/HookInstance.cs | 2 +- src/UI/UIManager.cs | 2 +- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/Core/Input/CursorUnlocker.cs b/src/Core/Input/CursorUnlocker.cs index 4f7d891..52185d1 100644 --- a/src/Core/Input/CursorUnlocker.cs +++ b/src/Core/Input/CursorUnlocker.cs @@ -193,7 +193,7 @@ namespace UnityExplorer.Core.Input throw new MissingMethodException($"Could not find method for patching - '{type.FullName}.{method}'!"); } - var processor = ExplorerCore.Harmony.CreateProcessor(methodInfo); + var processor = ExplorerCore.CreatePatch(methodInfo); processor.AddPrefix(prefix); processor.Patch(); } @@ -207,7 +207,7 @@ namespace UnityExplorer.Core.Input { try { - var processor = ExplorerCore.Harmony.CreateProcessor(type.GetProperty(property, ReflectionUtility.FLAGS).GetSetMethod()); + var processor = ExplorerCore.CreatePatch(type.GetProperty(property, ReflectionUtility.FLAGS).GetSetMethod()); processor.AddPrefix(prefix); processor.Patch(); } diff --git a/src/Core/Reflection/Patches.cs b/src/Core/Reflection/Patches.cs index 658008e..ffc1fa9 100644 --- a/src/Core/Reflection/Patches.cs +++ b/src/Core/Reflection/Patches.cs @@ -14,7 +14,7 @@ namespace UnityExplorer try { var method = typeof(Assembly).GetMethod(nameof(Assembly.GetTypes), new Type[0]); - var processor = ExplorerCore.Harmony.CreateProcessor(method); + var processor = ExplorerCore.CreatePatch(method); processor.AddFinalizer(typeof(ReflectionPatches).GetMethod(nameof(Assembly_GetTypes))); processor.Patch(); } diff --git a/src/ExplorerCore.cs b/src/ExplorerCore.cs index 40b051c..095bdb7 100644 --- a/src/ExplorerCore.cs +++ b/src/ExplorerCore.cs @@ -14,6 +14,8 @@ using UnityExplorer.UI; using UnityExplorer.Inspectors; using UnityExplorer.ObjectExplorer; using UnityExplorer.UI.Panels; +using HarmonyLib; +using System.Reflection; namespace UnityExplorer { @@ -27,7 +29,9 @@ namespace UnityExplorer public static IExplorerLoader Loader { get; private set; } public static RuntimeContext Context { get; internal set; } - public static HarmonyLib.Harmony Harmony { get; } = new HarmonyLib.Harmony(GUID); + private static HarmonyLib.Harmony Harmony { get; } = new HarmonyLib.Harmony(GUID); + + public static PatchProcessor CreatePatch(MethodBase targetMethod) => new PatchProcessor(Harmony, targetMethod); /// /// Initialize UnityExplorer with the provided Loader implementation. diff --git a/src/Hooks/HookInstance.cs b/src/Hooks/HookInstance.cs index 970929f..7d381f8 100644 --- a/src/Hooks/HookInstance.cs +++ b/src/Hooks/HookInstance.cs @@ -61,7 +61,7 @@ namespace UnityExplorer.Hooks try { - patchProcessor = ExplorerCore.Harmony.CreateProcessor(TargetMethod); + patchProcessor = ExplorerCore.CreatePatch(TargetMethod); // Dynamically compile the patch method diff --git a/src/UI/UIManager.cs b/src/UI/UIManager.cs index e0d04e7..73c95d5 100644 --- a/src/UI/UIManager.cs +++ b/src/UI/UIManager.cs @@ -511,7 +511,7 @@ namespace UnityExplorer.UI if (UnhollowerBaseLib.UnhollowerUtils.GetIl2CppMethodInfoPointerFieldForGeneratedMethod(unloadAllBundles) == null) return; #endif - var processor = ExplorerCore.Harmony.CreateProcessor(unloadAllBundles); + var processor = ExplorerCore.CreatePatch(unloadAllBundles); var prefix = new HarmonyMethod(typeof(UIManager).GetMethod(nameof(Prefix_UnloadAllAssetBundles), AccessTools.all)); processor.AddPrefix(prefix); processor.Patch();