Show / Hide Table of Contents

Class PatchProcessor

A PatchProcessor handles patches on a method/constructor

Inheritance
object
PatchProcessor
Namespace: HarmonyLib
Assembly: 0Harmony.dll
Syntax
public class PatchProcessor

Constructors

PatchProcessor(Harmony, MethodBase)

Creates a new PatchProcessor

Declaration
public PatchProcessor(Harmony instance, MethodBase original)
Parameters
Type Name Description
Harmony instance

The Harmony instance

MethodBase original

The original method/constructor

Methods

AddFinalizer(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
MethodInfo fixMethod

The finalizer method

Returns
Type Description
PatchProcessor

A PatchProcessor for chaining calls

AddInnerPostfix(HarmonyMethod)

Adds an inner postfix

Declaration
public PatchProcessor AddInnerPostfix(HarmonyMethod innerPostfix)
Parameters
Type Name Description
HarmonyMethod innerPostfix

The inner postfix as a HarmonyMethod

Returns
Type Description
PatchProcessor

A PatchProcessor for chaining calls

AddInnerPostfix(MethodInfo)

Adds an inner postfix

Declaration
public PatchProcessor AddInnerPostfix(MethodInfo fixMethod)
Parameters
Type Name Description
MethodInfo fixMethod

The inner postfix method

Returns
Type Description
PatchProcessor

A PatchProcessor for chaining calls

AddInnerPrefix(HarmonyMethod)

Adds an inner prefix

Declaration
public PatchProcessor AddInnerPrefix(HarmonyMethod innerPrefix)
Parameters
Type Name Description
HarmonyMethod innerPrefix

The inner prefix as a HarmonyMethod

Returns
Type Description
PatchProcessor

A PatchProcessor for chaining calls

AddInnerPrefix(MethodInfo)

Adds an inner prefix

Declaration
public PatchProcessor AddInnerPrefix(MethodInfo fixMethod)
Parameters
Type Name Description
MethodInfo fixMethod

The inner prefix 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
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
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
MethodInfo fixMethod

The transpiler method

Returns
Type Description
PatchProcessor

A PatchProcessor for chaining calls

CreateILGenerator()

Creates a new empty generator to use when reading method bodies

Declaration
public static ILGenerator CreateILGenerator()
Returns
Type Description
ILGenerator

A new System.Reflection.Emit.ILGenerator

CreateILGenerator(MethodBase)

Creates a new generator matching the method/constructor to use when reading method bodies

Declaration
public static ILGenerator CreateILGenerator(MethodBase original)
Parameters
Type Name Description
MethodBase original

The original method/constructor to copy method information from

Returns
Type Description
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
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

Declaration
public static List<CodeInstruction> GetCurrentInstructions(MethodBase original, int maxTranspilers = 2147483647, ILGenerator generator = null)
Parameters
Type Name Description
MethodBase original

The original method/constructor

int maxTranspilers

Apply only the first count of transpilers

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
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

Declaration
public static List<CodeInstruction> GetCurrentInstructions(MethodBase original, out ILGenerator generator, int maxTranspilers = 2147483647)
Parameters
Type Name Description
MethodBase original

The original method/constructor

ILGenerator generator

A new generator that now contains all local variables and labels contained in the result

int maxTranspilers

Apply only the first count of transpilers

Returns
Type Description
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
MethodBase original

The original method/constructor

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
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
MethodBase original

The original method/constructor

ILGenerator generator

A new generator that now contains all local variables and labels contained in the result

Returns
Type Description
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
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
MethodBase original

The original method

Patch[] patches

Patches to sort

Returns
Type Description
List<MethodInfo>

The sorted patch methods

Patch()

Applies all registered patches

Declaration
public MethodInfo Patch()
Returns
Type Description
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
MethodBase method

The original method

Returns
Type Description
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

Declaration
public static IEnumerable<KeyValuePair<OpCode, object>> ReadMethodBody(MethodBase method, ILGenerator generator)
Parameters
Type Name Description
MethodBase method

The original method

ILGenerator generator

An existing generator that will be used to create all local variables and labels contained in the result

Returns
Type Description
IEnumerable<KeyValuePair<OpCode, 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

string harmonyID

Harmony ID or * for any

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
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
Version currentVersion

[out] The current Harmony version

Returns
Type Description
Dictionary<string, Version>

A dictionary containing assembly version keyed by Harmony ID

In this article
Back to top Generated by DocFX