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}'!");
}
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();
}

View File

@ -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();
}

View File

@ -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);
/// <summary>
/// Initialize UnityExplorer with the provided Loader implementation.

View File

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

View File

@ -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();