Class PatchProcessor
- Namespace
- HarmonyLib
- Assembly
- 0Harmony.dll
A PatchProcessor handles patches on a method/constructor
public class PatchProcessor
- Inheritance
-
objectPatchProcessor
Constructors
PatchProcessor(Harmony, MethodBase)
Creates a new PatchProcessor
public PatchProcessor(Harmony instance, MethodBase original)
Parameters
instanceHarmonyThe Harmony instance
originalMethodBaseThe original method/constructor
Methods
AddFinalizer(HarmonyMethod)
Replaces the pending finalizer; installed patches are unchanged
public PatchProcessor AddFinalizer(HarmonyMethod finalizer)
Parameters
finalizerHarmonyMethodThe finalizer as a HarmonyMethod
Returns
- PatchProcessor
A PatchProcessor for chaining calls
AddFinalizer(MethodInfo)
Replaces the pending finalizer; installed patches are unchanged
public PatchProcessor AddFinalizer(MethodInfo fixMethod)
Parameters
fixMethodMethodInfoThe finalizer method
Returns
- PatchProcessor
A PatchProcessor for chaining calls
AddInnerFinalizer(HarmonyMethod)
Appends a pending inner finalizer
public PatchProcessor AddInnerFinalizer(HarmonyMethod innerFinalizer)
Parameters
innerFinalizerHarmonyMethodThe callback with an explicit target or HarmonyInfix declaration
Returns
- PatchProcessor
This processor for chaining calls
AddInnerFinalizer(MethodInfo)
Appends a pending inner finalizer
public PatchProcessor AddInnerFinalizer(MethodInfo fixMethod)
Parameters
fixMethodMethodInfoThe callback with a HarmonyInfix target
Returns
- PatchProcessor
This processor for chaining calls
AddInnerPostfix(HarmonyMethod)
Appends a pending inner postfix
public PatchProcessor AddInnerPostfix(HarmonyMethod innerPostfix)
Parameters
innerPostfixHarmonyMethodThe callback with an explicit target or HarmonyInfix declaration
Returns
- PatchProcessor
A PatchProcessor for chaining calls
AddInnerPostfix(MethodInfo)
Appends a pending inner postfix
public PatchProcessor AddInnerPostfix(MethodInfo fixMethod)
Parameters
fixMethodMethodInfoThe callback with a HarmonyInfix target
Returns
- PatchProcessor
A PatchProcessor for chaining calls
AddInnerPrefix(HarmonyMethod)
Appends a pending inner prefix
public PatchProcessor AddInnerPrefix(HarmonyMethod innerPrefix)
Parameters
innerPrefixHarmonyMethodThe callback with an explicit target or HarmonyInfix declaration
Returns
- PatchProcessor
A PatchProcessor for chaining calls
AddInnerPrefix(MethodInfo)
Appends a pending inner prefix
public PatchProcessor AddInnerPrefix(MethodInfo fixMethod)
Parameters
fixMethodMethodInfoThe callback with a HarmonyInfix target
Returns
- PatchProcessor
A PatchProcessor for chaining calls
AddPostfix(HarmonyMethod)
Replaces the pending postfix; installed patches are unchanged
public PatchProcessor AddPostfix(HarmonyMethod postfix)
Parameters
postfixHarmonyMethodThe postfix as a HarmonyMethod
Returns
- PatchProcessor
A PatchProcessor for chaining calls
AddPostfix(MethodInfo)
Replaces the pending postfix; installed patches are unchanged
public PatchProcessor AddPostfix(MethodInfo fixMethod)
Parameters
fixMethodMethodInfoThe postfix method
Returns
- PatchProcessor
A PatchProcessor for chaining calls
AddPrefix(HarmonyMethod)
Replaces the pending prefix; installed patches are unchanged
public PatchProcessor AddPrefix(HarmonyMethod prefix)
Parameters
prefixHarmonyMethodThe prefix as a HarmonyMethod
Returns
- PatchProcessor
A PatchProcessor for chaining calls
AddPrefix(MethodInfo)
Replaces the pending prefix; installed patches are unchanged
public PatchProcessor AddPrefix(MethodInfo fixMethod)
Parameters
fixMethodMethodInfoThe prefix method
Returns
- PatchProcessor
A PatchProcessor for chaining calls
AddTranspiler(HarmonyMethod)
Replaces the pending transpiler; installed patches are unchanged
public PatchProcessor AddTranspiler(HarmonyMethod transpiler)
Parameters
transpilerHarmonyMethodThe transpiler as a HarmonyMethod
Returns
- PatchProcessor
A PatchProcessor for chaining calls
AddTranspiler(MethodInfo)
Replaces the pending transpiler; installed patches are unchanged
public PatchProcessor AddTranspiler(MethodInfo fixMethod)
Parameters
fixMethodMethodInfoThe transpiler method
Returns
- PatchProcessor
A PatchProcessor for chaining calls
CreateILGenerator()
Creates a new empty generator to use when reading method bodies
public static ILGenerator CreateILGenerator()
Returns
- ILGenerator
A new System.Reflection.Emit.ILGenerator
CreateILGenerator(MethodBase)
Creates a new generator matching the method/constructor to use when reading method bodies
public static ILGenerator CreateILGenerator(MethodBase original)
Parameters
originalMethodBaseThe original method/constructor to copy method information from
Returns
- ILGenerator
A new System.Reflection.Emit.ILGenerator
GetAllPatchedMethods()
Gets all patched original methods in the appdomain
public static IEnumerable<MethodBase> GetAllPatchedMethods()
Returns
- IEnumerable<MethodBase>
An enumeration of patched method/constructor
GetCurrentInstructions(MethodBase, int, ILGenerator)
Returns the methods current list of code instructions after all existing transpilers have been applied
public static List<CodeInstruction> GetCurrentInstructions(MethodBase original, int maxTranspilers = 2147483647, ILGenerator generator = null)
Parameters
originalMethodBaseThe original method/constructor
maxTranspilersintApply only the first count of transpilers
generatorILGeneratorOptionally an existing generator that will be used to create all local variables and labels contained in the result (if not specified, an internal generator is used)
Returns
- List<CodeInstruction>
A list of CodeInstruction
GetCurrentInstructions(MethodBase, out ILGenerator, int)
Returns the methods current list of code instructions after all existing transpilers have been applied
public static List<CodeInstruction> GetCurrentInstructions(MethodBase original, out ILGenerator generator, int maxTranspilers = 2147483647)
Parameters
originalMethodBaseThe original method/constructor
generatorILGeneratorA new generator that now contains all local variables and labels contained in the result
maxTranspilersintApply only the first count of transpilers
Returns
- List<CodeInstruction>
A list of CodeInstruction
GetOriginalInstructions(MethodBase, ILGenerator)
Returns the methods unmodified list of code instructions
public static List<CodeInstruction> GetOriginalInstructions(MethodBase original, ILGenerator generator = null)
Parameters
originalMethodBaseThe original method/constructor
generatorILGeneratorOptionally an existing generator that will be used to create all local variables and labels contained in the result (if not specified, an internal generator is used)
Returns
- List<CodeInstruction>
A list containing all the original CodeInstruction
GetOriginalInstructions(MethodBase, out ILGenerator)
Returns the methods unmodified list of code instructions
public static List<CodeInstruction> GetOriginalInstructions(MethodBase original, out ILGenerator generator)
Parameters
originalMethodBaseThe original method/constructor
generatorILGeneratorA new generator that now contains all local variables and labels contained in the result
Returns
- List<CodeInstruction>
A list containing all the original CodeInstruction
GetPatchInfo(MethodBase)
Gets patch information on an original
public static Patches GetPatchInfo(MethodBase method)
Parameters
methodMethodBaseThe original method/constructor
Returns
GetSortedPatchMethods(MethodBase, Patch[])
Sort patch methods by their priority rules
public static List<MethodInfo> GetSortedPatchMethods(MethodBase original, Patch[] patches)
Parameters
originalMethodBaseThe original method
patchesPatch[]Patches to sort
Returns
- List<MethodInfo>
The sorted patch methods
Patch()
Installs the pending configuration alongside existing patches and rebuilds the method
public MethodInfo Patch()
Returns
- MethodInfo
The generated replacement method
Remarks
Retains the configuration. Repeated calls add registrations; they do not replace earlier installations.
ReadMethodBody(MethodBase)
A low level way to read the body of a method. Used for quick searching in methods
public static IEnumerable<KeyValuePair<OpCode, object>> ReadMethodBody(MethodBase method)
Parameters
methodMethodBaseThe original method
Returns
- IEnumerable<KeyValuePair<OpCode, object>>
All instructions as opcode/operand pairs
ReadMethodBody(MethodBase, ILGenerator)
A low level way to read the body of a method. Used for quick searching in methods
public static IEnumerable<KeyValuePair<OpCode, object>> ReadMethodBody(MethodBase method, ILGenerator generator)
Parameters
methodMethodBaseThe original method
generatorILGeneratorAn existing generator that will be used to create all local variables and labels contained in the result
Returns
- IEnumerable<KeyValuePair<OpCode, object>>
All instructions as opcode/operand pairs
Unpatch(HarmonyPatchType, string)
Unpatches patches of a given type and/or Harmony ID
public PatchProcessor Unpatch(HarmonyPatchType type, string harmonyID)
Parameters
typeHarmonyPatchTypeThe HarmonyPatchType patch type
harmonyIDstringHarmony ID or
*for any
Returns
- PatchProcessor
A PatchProcessor for chaining calls
Unpatch(MethodInfo)
Unpatches a specific patch
public PatchProcessor Unpatch(MethodInfo patch)
Parameters
patchMethodInfoThe method of the patch
Returns
- PatchProcessor
A PatchProcessor for chaining calls
VersionInfo(out Version)
Gets Harmony version for all active Harmony instances
public static Dictionary<string, Version> VersionInfo(out Version currentVersion)
Parameters
currentVersionVersion[out] The current Harmony version
Returns
- Dictionary<string, Version>
A dictionary containing assembly version keyed by Harmony ID