Use PatchProcessor ctor directly instead of Harmony.CreatePatchProcessor

This commit is contained in:
Sinai 2021-11-20 17:47:01 +11:00
parent 6aa9b3aa15
commit 9c1d459655
5 changed files with 10 additions and 6 deletions

View File

@ -193,7 +193,7 @@ namespace UnityExplorer.Core.Input
throw new MissingMethodException($"Could not find method for patching - '{type.FullName}.{method}'!"); 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.AddPrefix(prefix);
processor.Patch(); processor.Patch();
} }
@ -207,7 +207,7 @@ namespace UnityExplorer.Core.Input
{ {
try 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.AddPrefix(prefix);
processor.Patch(); processor.Patch();
} }

View File

@ -14,7 +14,7 @@ namespace UnityExplorer
try try
{ {
var method = typeof(Assembly).GetMethod(nameof(Assembly.GetTypes), new Type[0]); 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.AddFinalizer(typeof(ReflectionPatches).GetMethod(nameof(Assembly_GetTypes)));
processor.Patch(); processor.Patch();
} }

View File

@ -14,6 +14,8 @@ using UnityExplorer.UI;
using UnityExplorer.Inspectors; using UnityExplorer.Inspectors;
using UnityExplorer.ObjectExplorer; using UnityExplorer.ObjectExplorer;
using UnityExplorer.UI.Panels; using UnityExplorer.UI.Panels;
using HarmonyLib;
using System.Reflection;
namespace UnityExplorer namespace UnityExplorer
{ {
@ -27,7 +29,9 @@ namespace UnityExplorer
public static IExplorerLoader Loader { get; private set; } public static IExplorerLoader Loader { get; private set; }
public static RuntimeContext Context { get; internal 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);
/// <summary> /// <summary>
/// Initialize UnityExplorer with the provided Loader implementation. /// Initialize UnityExplorer with the provided Loader implementation.

View File

@ -61,7 +61,7 @@ namespace UnityExplorer.Hooks
try try
{ {
patchProcessor = ExplorerCore.Harmony.CreateProcessor(TargetMethod); patchProcessor = ExplorerCore.CreatePatch(TargetMethod);
// Dynamically compile the patch method // Dynamically compile the patch method

View File

@ -511,7 +511,7 @@ namespace UnityExplorer.UI
if (UnhollowerBaseLib.UnhollowerUtils.GetIl2CppMethodInfoPointerFieldForGeneratedMethod(unloadAllBundles) == null) if (UnhollowerBaseLib.UnhollowerUtils.GetIl2CppMethodInfoPointerFieldForGeneratedMethod(unloadAllBundles) == null)
return; return;
#endif #endif
var processor = ExplorerCore.Harmony.CreateProcessor(unloadAllBundles); var processor = ExplorerCore.CreatePatch(unloadAllBundles);
var prefix = new HarmonyMethod(typeof(UIManager).GetMethod(nameof(Prefix_UnloadAllAssetBundles), AccessTools.all)); var prefix = new HarmonyMethod(typeof(UIManager).GetMethod(nameof(Prefix_UnloadAllAssetBundles), AccessTools.all));
processor.AddPrefix(prefix); processor.AddPrefix(prefix);
processor.Patch(); processor.Patch();