Skip to content

Commit d2a1d05

Browse files
committed
Fixes to the new infix processor parameter
1 parent e23cf68 commit d2a1d05

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

Harmony/Patch.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,11 @@ public Patch(MethodInfo patch, int index, string owner, int priority, string[] b
126126

127127
public HarmonyProcessor GetProcessor(MethodBase original)
128128
{
129-
if (patch.ReturnType != typeof(HarmonyProcessor)) return null;
130-
if (patch.IsStatic == false) return null;
129+
if (patch.ReturnType != typeof(HarmonyProcessor)) throw new Exception("Processor factory " + original + " must have a return type 'HarmonyProcessor'");
130+
if (patch.IsStatic == false) throw new Exception("Processor factory " + original + " must be static");
131131
var parameters = patch.GetParameters();
132-
if (parameters.Count() != 1) return null;
133-
if (parameters[0].ParameterType != typeof(MethodBase)) return null;
132+
if (parameters.Count() != 1) throw new Exception("Processor factory " + original + " must have exactly one parameter");
133+
if (parameters[0].ParameterType != typeof(MethodBase)) throw new Exception("Processor factory " + original + " must have a parameter of type 'MethodBase'");
134134

135135
return patch.Invoke(null, new object[] { original }) as HarmonyProcessor;
136136
}

Harmony/PatchProcessor.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,20 @@ public PatchProcessor(HarmonyInstance instance, Type type, HarmonyMethod attribu
2222
{
2323
this.instance = instance;
2424
container = type;
25-
containerAttributes = attributes;
25+
containerAttributes = attributes ?? new HarmonyMethod(null);
2626
prefix = containerAttributes.Clone();
2727
postfix = containerAttributes.Clone();
28-
infix = null;
28+
infix = containerAttributes.Clone();
2929
ProcessType();
3030
}
3131

3232
public PatchProcessor(HarmonyInstance instance, MethodBase original, HarmonyMethod prefix, HarmonyMethod postfix, HarmonyMethod infix)
3333
{
3434
this.instance = instance;
3535
this.original = original;
36-
this.prefix = prefix;
37-
this.postfix = postfix;
38-
this.infix = infix;
36+
this.prefix = prefix ?? new HarmonyMethod(null);
37+
this.postfix = postfix ?? new HarmonyMethod(null);
38+
this.infix = infix ?? new HarmonyMethod(null);
3939
}
4040

4141
public static Patches IsPatched(MethodBase method)
@@ -91,6 +91,12 @@ void ProcessType()
9191
var postfixAttributes = postfix.method.GetHarmonyMethods();
9292
containerAttributes.Merge(HarmonyMethod.Merge(postfixAttributes)).CopyTo(postfix);
9393
}
94+
95+
if (infix.method != null)
96+
{
97+
var infixAttributes = infix.method.GetHarmonyMethods();
98+
containerAttributes.Merge(HarmonyMethod.Merge(infixAttributes)).CopyTo(infix);
99+
}
94100
}
95101
}
96102

Harmony/Tools/PatchTools.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ public static MethodInfo GetPatchMethod<T>(Type patchType, string name, Type[] p
2323
return method;
2424
}
2525

26-
public static void GetPatches(Type patchType, MethodBase original, out MethodInfo prefix, out MethodInfo postfix, out MethodInfo processors)
26+
public static void GetPatches(Type patchType, MethodBase original, out MethodInfo prefix, out MethodInfo postfix, out MethodInfo infix)
2727
{
2828
var type = original.DeclaringType;
2929
var methodName = original.Name;
3030

3131
prefix = GetPatchMethod<HarmonyPrefix>(patchType, "Prefix");
3232
postfix = GetPatchMethod<HarmonyPostfix>(patchType, "Postfix");
33-
processors = GetPatchMethod<HarmonyProcessors>(patchType, "Processors");
33+
infix = GetPatchMethod<HarmonyProcessors>(patchType, "Processors");
3434
}
3535
}
3636
}

0 commit comments

Comments
 (0)