Browse documentation

Class PatchProcessor

Namespace
HarmonyLib
Assembly
0Harmony.dll

A PatchProcessor handles patches on a method/constructor

public class PatchProcessor
Inheritance
object
PatchProcessor

Constructors

PatchProcessor(Harmony, MethodBase)

Creates a new PatchProcessor

public PatchProcessor(Harmony instance, MethodBase original)

Parameters

instance Harmony

The Harmony instance

original MethodBase

The original method/constructor

Methods

AddFinalizer(HarmonyMethod)

Replaces the pending finalizer; installed patches are unchanged

public PatchProcessor AddFinalizer(HarmonyMethod finalizer)

Parameters

finalizer HarmonyMethod

The 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

fixMethod MethodInfo

The finalizer method

Returns

PatchProcessor

A PatchProcessor for chaining calls

AddInnerFinalizer(HarmonyMethod)

Appends a pending inner finalizer

public PatchProcessor AddInnerFinalizer(HarmonyMethod innerFinalizer)

Parameters

innerFinalizer HarmonyMethod

The 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

fixMethod MethodInfo

The 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

innerPostfix HarmonyMethod

The 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

fixMethod MethodInfo

The 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

innerPrefix HarmonyMethod

The 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

fixMethod MethodInfo

The 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

postfix HarmonyMethod

The 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

fixMethod MethodInfo

The 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

prefix HarmonyMethod

The 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

fixMethod MethodInfo

The 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

transpiler HarmonyMethod

The 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

fixMethod MethodInfo

The 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

original MethodBase

The 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

original MethodBase

The original method/constructor

maxTranspilers int

Apply only the first count of transpilers

generator ILGenerator

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

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

original MethodBase

The original method/constructor

generator ILGenerator

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

maxTranspilers int

Apply 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

original MethodBase

The original method/constructor

generator ILGenerator

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

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

original MethodBase

The original method/constructor

generator ILGenerator

A 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

method MethodBase

The original method/constructor

Returns

Patches

The patch information as Patches

GetSortedPatchMethods(MethodBase, Patch[])

Sort patch methods by their priority rules

public static List<MethodInfo> GetSortedPatchMethods(MethodBase original, Patch[] patches)

Parameters

original MethodBase

The original method

patches Patch[]

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

method MethodBase

The 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

method MethodBase

The original method

generator ILGenerator

An 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

type HarmonyPatchType

The HarmonyPatchType patch type

harmonyID string

Harmony ID or * for any

Returns

PatchProcessor

A PatchProcessor for chaining calls

Unpatch(MethodInfo)

Unpatches a specific patch

public PatchProcessor Unpatch(MethodInfo patch)

Parameters

patch MethodInfo

The 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

currentVersion Version

[out] The current Harmony version

Returns

Dictionary<string, Version>

A dictionary containing assembly version keyed by Harmony ID

Harmony 3 preview

For the stable release, read the 2.x documentation.