Class PatchProcessor
A PatchProcessor handles patches on a method/constructor
Inheritance
Namespace: HarmonyLib
Assembly: 0Harmony.dll
Syntax
public class PatchProcessor
Constructors
| Improve this Doc View SourcePatchProcessor(Harmony, MethodBase)
Creates a new PatchProcessor.
Declaration
public PatchProcessor(Harmony instance, MethodBase original)
Parameters
Type | Name | Description |
---|---|---|
Harmony | instance | The Harmony instance |
System.Reflection.MethodBase | original | The original method/constructor |
Methods
| Improve this Doc View SourceAddFinalizer(HarmonyMethod)
Adds a finalizer
Declaration
public PatchProcessor AddFinalizer(HarmonyMethod finalizer)
Parameters
Type | Name | Description |
---|---|---|
HarmonyMethod | finalizer | The finalizer as a HarmonyMethod |
Returns
Type | Description |
---|---|
PatchProcessor | A PatchProcessor for chaining calls |
AddFinalizer(MethodInfo)
Adds a finalizer
Declaration
public PatchProcessor AddFinalizer(MethodInfo fixMethod)
Parameters
Type | Name | Description |
---|---|---|
System.Reflection.MethodInfo | fixMethod | The finalizer method |
Returns
Type | Description |
---|---|
PatchProcessor | A PatchProcessor for chaining calls |
AddPostfix(HarmonyMethod)
Adds a postfix
Declaration
public PatchProcessor AddPostfix(HarmonyMethod postfix)
Parameters
Type | Name | Description |
---|---|---|
HarmonyMethod | postfix | The postfix as a HarmonyMethod |
Returns
Type | Description |
---|---|
PatchProcessor | A PatchProcessor for chaining calls |
AddPostfix(MethodInfo)
Adds a postfix
Declaration
public PatchProcessor AddPostfix(MethodInfo fixMethod)
Parameters
Type | Name | Description |
---|---|---|
System.Reflection.MethodInfo | fixMethod | The postfix method |
Returns
Type | Description |
---|---|
PatchProcessor | A PatchProcessor for chaining calls |
AddPrefix(HarmonyMethod)
Adds a prefix
Declaration
public PatchProcessor AddPrefix(HarmonyMethod prefix)
Parameters
Type | Name | Description |
---|---|---|
HarmonyMethod | prefix | The prefix as a HarmonyMethod |
Returns
Type | Description |
---|---|
PatchProcessor | A PatchProcessor for chaining calls |
AddPrefix(MethodInfo)
Adds a prefix
Declaration
public PatchProcessor AddPrefix(MethodInfo fixMethod)
Parameters
Type | Name | Description |
---|---|---|
System.Reflection.MethodInfo | fixMethod | The prefix method |
Returns
Type | Description |
---|---|
PatchProcessor | A PatchProcessor for chaining calls |
AddTranspiler(HarmonyMethod)
Adds a transpiler
Declaration
public PatchProcessor AddTranspiler(HarmonyMethod transpiler)
Parameters
Type | Name | Description |
---|---|---|
HarmonyMethod | transpiler | The transpiler as a HarmonyMethod |
Returns
Type | Description |
---|---|
PatchProcessor | A PatchProcessor for chaining calls |
AddTranspiler(MethodInfo)
Adds a transpiler
Declaration
public PatchProcessor AddTranspiler(MethodInfo fixMethod)
Parameters
Type | Name | Description |
---|---|---|
System.Reflection.MethodInfo | fixMethod | The transpiler method |
Returns
Type | Description |
---|---|
PatchProcessor | A PatchProcessor for chaining calls |
CreateILGenerator()
Creates a new empty System.Reflection.Emit.ILGenerator to use when reading method bodies
Declaration
public static ILGenerator CreateILGenerator()
Returns
Type | Description |
---|---|
System.Reflection.Emit.ILGenerator | A new System.Reflection.Emit.ILGenerator |
CreateILGenerator(MethodBase)
Creates a new System.Reflection.Emit.ILGenerator matching the method/constructor to use when reading method bodies
Declaration
public static ILGenerator CreateILGenerator(MethodBase original)
Parameters
Type | Name | Description |
---|---|---|
System.Reflection.MethodBase | original | The original method/constructor to copy method information from |
Returns
Type | Description |
---|---|
System.Reflection.Emit.ILGenerator | A new System.Reflection.Emit.ILGenerator |
GetAllPatchedMethods()
Gets all patched original methods in the appdomain
Declaration
public static IEnumerable<MethodBase> GetAllPatchedMethods()
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<System.Reflection.MethodBase> | An enumeration of patched method/constructor |
GetCurrentInstructions(MethodBase, Int32, ILGenerator)
Returns the methods current list of code instructions after all existing transpilers have been applied
Declaration
public static List<CodeInstruction> GetCurrentInstructions(MethodBase original, int maxTranspilers = 2147483647, ILGenerator generator = null)
Parameters
Type | Name | Description |
---|---|---|
System.Reflection.MethodBase | original | The original method/constructor |
System.Int32 | maxTranspilers | Apply only the first count of transpilers |
System.Reflection.Emit.ILGenerator | generator | Optionally 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
Type | Description |
---|---|
System.Collections.Generic.List<CodeInstruction> | A list of CodeInstruction |
GetCurrentInstructions(MethodBase, out ILGenerator, Int32)
Returns the methods current list of code instructions after all existing transpilers have been applied
Declaration
public static List<CodeInstruction> GetCurrentInstructions(MethodBase original, out ILGenerator generator, int maxTranspilers = 2147483647)
Parameters
Type | Name | Description |
---|---|---|
System.Reflection.MethodBase | original | The original method/constructor |
System.Reflection.Emit.ILGenerator | generator | A new generator that now contains all local variables and labels contained in the result |
System.Int32 | maxTranspilers | Apply only the first count of transpilers |
Returns
Type | Description |
---|---|
System.Collections.Generic.List<CodeInstruction> | A list of CodeInstruction |
GetOriginalInstructions(MethodBase, ILGenerator)
Returns the methods unmodified list of code instructions
Declaration
public static List<CodeInstruction> GetOriginalInstructions(MethodBase original, ILGenerator generator = null)
Parameters
Type | Name | Description |
---|---|---|
System.Reflection.MethodBase | original | The original method/constructor |
System.Reflection.Emit.ILGenerator | generator | Optionally 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
Type | Description |
---|---|
System.Collections.Generic.List<CodeInstruction> | A list containing all the original CodeInstruction |
GetOriginalInstructions(MethodBase, out ILGenerator)
Returns the methods unmodified list of code instructions
Declaration
public static List<CodeInstruction> GetOriginalInstructions(MethodBase original, out ILGenerator generator)
Parameters
Type | Name | Description |
---|---|---|
System.Reflection.MethodBase | original | The original method/constructor |
System.Reflection.Emit.ILGenerator | generator | A new generator that now contains all local variables and labels contained in the result |
Returns
Type | Description |
---|---|
System.Collections.Generic.List<CodeInstruction> | A list containing all the original CodeInstruction |
GetPatchInfo(MethodBase)
Gets patch information on an original
Declaration
public static Patches GetPatchInfo(MethodBase method)
Parameters
Type | Name | Description |
---|---|---|
System.Reflection.MethodBase | method | The original method/constructor |
Returns
Type | Description |
---|---|
Patches | The patch information as Patches |
GetSortedPatchMethods(MethodBase, Patch[])
Sort patch methods by their priority rules
Declaration
public static List<MethodInfo> GetSortedPatchMethods(MethodBase original, Patch[] patches)
Parameters
Type | Name | Description |
---|---|---|
System.Reflection.MethodBase | original | The original method |
Patch[] | patches | Patches to sort |
Returns
Type | Description |
---|---|
System.Collections.Generic.List<System.Reflection.MethodInfo> | The sorted patch methods |
Patch()
Applies all registered patches
Declaration
public MethodInfo Patch()
Returns
Type | Description |
---|---|
System.Reflection.MethodInfo | The generated replacement method |
ReadMethodBody(MethodBase)
A low level way to read the body of a method. Used for quick searching in methods
Declaration
public static IEnumerable<KeyValuePair<OpCode, object>> ReadMethodBody(MethodBase method)
Parameters
Type | Name | Description |
---|---|---|
System.Reflection.MethodBase | method | The original method |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<System.Reflection.Emit.OpCode, System.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
Declaration
public static IEnumerable<KeyValuePair<OpCode, object>> ReadMethodBody(MethodBase method, ILGenerator generator)
Parameters
Type | Name | Description |
---|---|---|
System.Reflection.MethodBase | method | The original method |
System.Reflection.Emit.ILGenerator | generator | An existing generator that will be used to create all local variables and labels contained in the result |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<System.Reflection.Emit.OpCode, System.Object>> | All instructions as opcode/operand pairs |
Unpatch(HarmonyPatchType, String)
Unpatches patches of a given type and/or Harmony ID
Declaration
public PatchProcessor Unpatch(HarmonyPatchType type, string harmonyID)
Parameters
Type | Name | Description |
---|---|---|
HarmonyPatchType | type | The HarmonyPatchType patch type |
System.String | harmonyID | Harmony ID or |
Returns
Type | Description |
---|---|
PatchProcessor | A PatchProcessor for chaining calls |
Unpatch(MethodInfo)
Unpatches a specific patch
Declaration
public PatchProcessor Unpatch(MethodInfo patch)
Parameters
Type | Name | Description |
---|---|---|
System.Reflection.MethodInfo | patch | The method of the patch |
Returns
Type | Description |
---|---|
PatchProcessor | A PatchProcessor for chaining calls |
VersionInfo(out Version)
Gets Harmony version for all active Harmony instances
Declaration
public static Dictionary<string, Version> VersionInfo(out Version currentVersion)
Parameters
Type | Name | Description |
---|---|---|
System.Version | currentVersion | [out] The current Harmony version |
Returns
Type | Description |
---|---|
System.Collections.Generic.Dictionary<System.String, System.Version> | A dictionary containing assembly version keyed by Harmony ID |