public PatchProcessor Patch(MethodBase original, HarmonyMethod prefix, HarmonyMethod postfix, HarmonyMethod transpiler = null) { var processor = new PatchProcessor(this, original, prefix, postfix, transpiler); processor.Patch(); return(processor); }
/// <summary>Creates patches by manually specifying the methods</summary> /// <param name="original">The original method</param> /// <param name="prefix">An optional prefix method wrapped in a HarmonyMethod object</param> /// <param name="postfix">An optional postfix method wrapped in a HarmonyMethod object</param> /// <param name="transpiler">An optional transpiler method wrapped in a HarmonyMethod object</param> /// <returns>The dynamic method that was created to patch the original method</returns> /// public DynamicMethod Patch(MethodBase original, HarmonyMethod prefix = null, HarmonyMethod postfix = null, HarmonyMethod transpiler = null) { var processor = new PatchProcessor(this, new List <MethodBase> { original }, prefix, postfix, transpiler); return(processor.Patch().FirstOrDefault()); }
public void PatchVoid(MethodBase original, HarmonyMethod prefix, HarmonyMethod postfix, HarmonyMethod transpiler) { var processor = new PatchProcessor(this, new List <MethodBase> { original }, prefix, postfix, transpiler); processor.Patch(); }
static void ApplyPatch(string owner, MethodBase target, HarmonyMethod prefix = null, HarmonyMethod postfix = null, HarmonyMethod transpiler = null) { var instance = HarmonyInstance.Create(owner); var processor = new Harmony.PatchProcessor(instance, new List <MethodBase> { target }, prefix: prefix, postfix: postfix, transpiler: transpiler); processor.Patch(); }
/// <summary>Searches an assembly for Harmony annotations and uses them to create patches</summary> /// <param name="assembly">The assembly</param> /// public void PatchAll(Assembly assembly) { assembly.GetTypes().Do(type => { var parentMethodInfos = type.GetHarmonyMethods(); if (parentMethodInfos != null && parentMethodInfos.Count() > 0) { var info = HarmonyMethod.Merge(parentMethodInfos); var processor = new PatchProcessor(this, type, info); processor.Patch(); } }); }
public DynamicMethod Patch(MethodBase original, HarmonyMethod prefix = null, HarmonyMethod postfix = null, HarmonyMethod transpiler = null) { if ((original.DeclaringType.Assembly.GetCustomAttributes(typeof(HarmonyShield), false).Count() > 0) || (original.DeclaringType.GetCustomAttributes(typeof(HarmonyShield), false).Count() > 0) || (original.GetCustomAttributes(typeof(HarmonyShield), false).Count() > 0)) { return(null); } var processor = new PatchProcessor(this, new List <MethodBase> { original }, prefix, postfix, transpiler); return(processor.Patch().FirstOrDefault()); }
public void TestMultiple() { var targetMethods = new List <MethodBase>() { AccessTools.Method(typeof(PatchProcessorClass1), nameof(PatchProcessorClass1.TestA)), AccessTools.Method(typeof(PatchProcessorClass1), nameof(PatchProcessorClass1.TestB)) }; var postfix = new HarmonyMethod(typeof(PatchProcessorPatchClass1), nameof(PatchProcessorPatchClass1.Postfix)); var harmony = HarmonyInstance.Create("test"); var processor = new Harmony.PatchProcessor(harmony, targetMethods, postfix: postfix); processor.Patch(); Assert.AreEqual("Patched", PatchProcessorClass1.TestA(), "Test A"); Assert.AreEqual("Patched", PatchProcessorClass1.TestB(), "Test B"); }
public void PatchAll(Assembly assembly) { if (assembly.GetCustomAttributes(typeof(HarmonyShield), false).Count() > 0) { return; } assembly.GetTypes().Do(type => { var parentMethodInfos = type.GetHarmonyMethods(); if (parentMethodInfos != null && parentMethodInfos.Count() > 0) { var info = HarmonyMethod.Merge(parentMethodInfos); var processor = new PatchProcessor(this, type, info); processor.Patch(); } }); }
public PatchInfoData Patch(MethodBase original, HarmonyMethod prefix, HarmonyMethod postfix, HarmonyMethod transpiler, PatchFlags flags) { var processor = new PatchProcessor(this, original, prefix, postfix, transpiler); return(processor.Patch(flags)); }
public void Patch(MethodBase original, HarmonyMethod prefix, HarmonyMethod postfix, HarmonyMethod infix = null) { var processor = new PatchProcessor(this, original, prefix, postfix, infix); processor.Patch(); }