From 8123ec241242dc12ae20b6e88e6441855fd0a76a Mon Sep 17 00:00:00 2001 From: Sinai <49360850+sinai-dev@users.noreply.github.com> Date: Sat, 20 Nov 2021 18:57:53 +1100 Subject: [PATCH] Revert "Use PatchProcessor ctor directly instead of Harmony.CreatePatchProcessor" This reverts commit 9c1d4596554773c4cce9fbccba837c927800e16c. --- 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, 6 insertions(+), 10 deletions(-) diff --git a/src/Core/Input/CursorUnlocker.cs b/src/Core/Input/CursorUnlocker.cs index 52185d1..4f7d891 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.CreatePatch(methodInfo); + var processor = ExplorerCore.Harmony.CreateProcessor(methodInfo); processor.AddPrefix(prefix); processor.Patch(); } @@ -207,7 +207,7 @@ namespace UnityExplorer.Core.Input { try { - var processor = ExplorerCore.CreatePatch(type.GetProperty(property, ReflectionUtility.FLAGS).GetSetMethod()); + var processor = ExplorerCore.Harmony.CreateProcessor(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 ffc1fa9..658008e 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.CreatePatch(method); + var processor = ExplorerCore.Harmony.CreateProcessor(method); processor.AddFinalizer(typeof(ReflectionPatches).GetMethod(nameof(Assembly_GetTypes))); processor.Patch(); } diff --git a/src/ExplorerCore.cs b/src/ExplorerCore.cs index 095bdb7..40b051c 100644 --- a/src/ExplorerCore.cs +++ b/src/ExplorerCore.cs @@ -14,8 +14,6 @@ using UnityExplorer.UI; using UnityExplorer.Inspectors; using UnityExplorer.ObjectExplorer; using UnityExplorer.UI.Panels; -using HarmonyLib; -using System.Reflection; namespace UnityExplorer { @@ -29,9 +27,7 @@ namespace UnityExplorer public static IExplorerLoader Loader { get; private set; } public static RuntimeContext Context { get; internal set; } - private static HarmonyLib.Harmony Harmony { get; } = new HarmonyLib.Harmony(GUID); - - public static PatchProcessor CreatePatch(MethodBase targetMethod) => new PatchProcessor(Harmony, targetMethod); + public static HarmonyLib.Harmony Harmony { get; } = new HarmonyLib.Harmony(GUID); /// /// Initialize UnityExplorer with the provided Loader implementation. diff --git a/src/Hooks/HookInstance.cs b/src/Hooks/HookInstance.cs index 7d381f8..970929f 100644 --- a/src/Hooks/HookInstance.cs +++ b/src/Hooks/HookInstance.cs @@ -61,7 +61,7 @@ namespace UnityExplorer.Hooks try { - patchProcessor = ExplorerCore.CreatePatch(TargetMethod); + patchProcessor = ExplorerCore.Harmony.CreateProcessor(TargetMethod); // Dynamically compile the patch method diff --git a/src/UI/UIManager.cs b/src/UI/UIManager.cs index 73c95d5..e0d04e7 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.CreatePatch(unloadAllBundles); + var processor = ExplorerCore.Harmony.CreateProcessor(unloadAllBundles); var prefix = new HarmonyMethod(typeof(UIManager).GetMethod(nameof(Prefix_UnloadAllAssetBundles), AccessTools.all)); processor.AddPrefix(prefix); processor.Patch();