Skip to content

Commit

Permalink
Fixes to the new infix processor parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
pardeike committed Feb 14, 2017
1 parent e23cf68 commit d2a1d05
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
8 changes: 4 additions & 4 deletions Harmony/Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
16 changes: 11 additions & 5 deletions Harmony/PatchProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@ 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();
}

public PatchProcessor(HarmonyInstance instance, MethodBase original, HarmonyMethod prefix, HarmonyMethod postfix, HarmonyMethod infix)
{
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)
Expand Down Expand Up @@ -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);
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions Harmony/Tools/PatchTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ public static MethodInfo GetPatchMethod<T>(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<HarmonyPrefix>(patchType, "Prefix");
postfix = GetPatchMethod<HarmonyPostfix>(patchType, "Postfix");
processors = GetPatchMethod<HarmonyProcessors>(patchType, "Processors");
infix = GetPatchMethod<HarmonyProcessors>(patchType, "Processors");
}
}
}

0 comments on commit d2a1d05

Please sign in to comment.