From d2a1d0581e5e5616580588d8ed7bb47fd1d1e6eb Mon Sep 17 00:00:00 2001 From: Andreas Pardeike Date: Tue, 14 Feb 2017 07:49:54 +0100 Subject: [PATCH] Fixes to the new infix processor parameter --- Harmony/Patch.cs | 8 ++++---- Harmony/PatchProcessor.cs | 16 +++++++++++----- Harmony/Tools/PatchTools.cs | 4 ++-- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/Harmony/Patch.cs b/Harmony/Patch.cs index bf8245f7..362160ba 100644 --- a/Harmony/Patch.cs +++ b/Harmony/Patch.cs @@ -126,11 +126,11 @@ public Patch(MethodInfo patch, int index, string owner, int priority, string[] b public HarmonyProcessor GetProcessor(MethodBase original) { - if (patch.ReturnType != typeof(HarmonyProcessor)) return null; - if (patch.IsStatic == false) return null; + if (patch.ReturnType != typeof(HarmonyProcessor)) throw new Exception("Processor factory " + original + " must have a return type 'HarmonyProcessor'"); + if (patch.IsStatic == false) throw new Exception("Processor factory " + original + " must be static"); var parameters = patch.GetParameters(); - if (parameters.Count() != 1) return null; - if (parameters[0].ParameterType != typeof(MethodBase)) return null; + if (parameters.Count() != 1) throw new Exception("Processor factory " + original + " must have exactly one parameter"); + if (parameters[0].ParameterType != typeof(MethodBase)) throw new Exception("Processor factory " + original + " must have a parameter of type 'MethodBase'"); return patch.Invoke(null, new object[] { original }) as HarmonyProcessor; } diff --git a/Harmony/PatchProcessor.cs b/Harmony/PatchProcessor.cs index 9a741a72..31e1502e 100644 --- a/Harmony/PatchProcessor.cs +++ b/Harmony/PatchProcessor.cs @@ -22,10 +22,10 @@ public PatchProcessor(HarmonyInstance instance, Type type, HarmonyMethod attribu { this.instance = instance; container = type; - containerAttributes = attributes; + containerAttributes = attributes ?? new HarmonyMethod(null); prefix = containerAttributes.Clone(); postfix = containerAttributes.Clone(); - infix = null; + infix = containerAttributes.Clone(); ProcessType(); } @@ -33,9 +33,9 @@ public PatchProcessor(HarmonyInstance instance, MethodBase original, HarmonyMeth { this.instance = instance; this.original = original; - this.prefix = prefix; - this.postfix = postfix; - this.infix = infix; + this.prefix = prefix ?? new HarmonyMethod(null); + this.postfix = postfix ?? new HarmonyMethod(null); + this.infix = infix ?? new HarmonyMethod(null); } public static Patches IsPatched(MethodBase method) @@ -91,6 +91,12 @@ void ProcessType() var postfixAttributes = postfix.method.GetHarmonyMethods(); containerAttributes.Merge(HarmonyMethod.Merge(postfixAttributes)).CopyTo(postfix); } + + if (infix.method != null) + { + var infixAttributes = infix.method.GetHarmonyMethods(); + containerAttributes.Merge(HarmonyMethod.Merge(infixAttributes)).CopyTo(infix); + } } } diff --git a/Harmony/Tools/PatchTools.cs b/Harmony/Tools/PatchTools.cs index 6c9433ca..f9369497 100644 --- a/Harmony/Tools/PatchTools.cs +++ b/Harmony/Tools/PatchTools.cs @@ -23,14 +23,14 @@ public static MethodInfo GetPatchMethod(Type patchType, string name, Type[] p return method; } - public static void GetPatches(Type patchType, MethodBase original, out MethodInfo prefix, out MethodInfo postfix, out MethodInfo processors) + public static void GetPatches(Type patchType, MethodBase original, out MethodInfo prefix, out MethodInfo postfix, out MethodInfo infix) { var type = original.DeclaringType; var methodName = original.Name; prefix = GetPatchMethod(patchType, "Prefix"); postfix = GetPatchMethod(patchType, "Postfix"); - processors = GetPatchMethod(patchType, "Processors"); + infix = GetPatchMethod(patchType, "Processors"); } } } \ No newline at end of file