Namespace HarmonyLib
Harmony patches existing .NET methods at runtime. Create a Harmony instance with your own owner ID, then use patch attributes or a PatchProcessor to install patches.
Prefixes, postfixes and finalizers apply to a whole method. HarmonyInfix applies those same roles to selected operations inside a method; InnerMethod and InnerTarget describe targets for manual registration. Transpilers edit instructions directly, with CodeMatcher for matching and editing instruction sequences and InlineSignature for inspecting indirect calls.
The types below form the API reference. For working examples and the rules shared by these APIs, start with the patching guide or the Infix guide.
Classes
- AccessTools
A helper class for reflection related functions
- AccessToolsExtensions
Adds extensions to Type for a lot of AccessTools methods
- Code
By adding the following using statement to your source code:
using static HarmonyLib.Code;you can for example start usingLdarg_1in you code instead ofnew CodeMatch(OpCodes.Ldarg_1)and then you can use array notation to add an operand and/or a name:Call[myMethodInfo]instead ofnew CodeMatch(OpCodes.Call, myMethodInfo)
- CodeInstruction
An abstract wrapper around OpCode and their operands. Used by transpilers
- CodeInstructionExtensions
Extensions for CodeInstruction
- CodeInstructionsExtensions
Extensions for a sequence of CodeInstruction
- CodeMatch
A CodeInstruction match
- CodeMatcher
A CodeInstruction matcher
- CollectionExtensions
General extensions for collections
- DelegateTypeFactory
A factory to create delegate types
- ExceptionBlock
An exception block
- FastAccess
A helper class for fast access to getters and setters
- FileLog
A file log for debugging
- GeneralExtensions
General extensions for common cases
- Harmony
The Harmony instance is the main entry to Harmony. After creating one with an unique identifier, it is used to patch and query the current application domain
- HarmonyAfter
A Harmony annotation
- HarmonyArgument
A Harmony annotation
- HarmonyAttribute
The base class for all Harmony annotations (not meant to be used directly)
- HarmonyBefore
A Harmony annotation
- HarmonyCleanup
Specifies the Cleanup function in a patch class
- HarmonyDebug
A Harmony annotation
- HarmonyDelegate
Annotation to define the original method for delegate injection
- HarmonyException
Under Mono, HarmonyException wraps IL compile errors with detailed information about the failure
- HarmonyFinalizer
Specifies the Finalizer function in a patch class
- HarmonyInfix
Selects operations inside the outer patched method for an inner prefix, postfix, or finalizer
- HarmonyInline
Allows inlining an inner patch body; unsupported bodies keep a normal call
- HarmonyMethod
A wrapper around a method to use it as a patch (for example a Prefix)
- HarmonyMethodExtensions
Annotation extensions
- HarmonyOuter
Binds an Infix parameter to the containing outer method
- HarmonyPatch
Annotation to define your Harmony patch methods
- HarmonyPatchAll
A Harmony annotation to define that all methods in a class are to be patched
- HarmonyPatchCategory
Annotation to define a category for use with PatchCategory
- HarmonyPostfix
Specifies the Postfix function in a patch class
- HarmonyPrefix
Specifies the Prefix function in a patch class
- HarmonyPrepare
Specifies the Prepare function in a patch class
- HarmonyPriority
A Harmony annotation
- HarmonyReversePatch
Annotation to define your standin methods for reverse patching
- HarmonyTargetMethod
Specifies the TargetMethod function in a patch class
- HarmonyTargetMethods
Specifies the TargetMethods function in a patch class
- HarmonyTranspiler
Specifies the Transpiler function in a patch class
- InlineSignature
A mutable signature used as the operand of a
calliinstruction. Parameter and return entries are System.Type, nested InlineSignature, or InlineSignature.ModifierType objects.
- InlineSignature.ModifierType
A mutable type with an optional
modoptor requiredmodreqmodifier.
- InnerMethod
Selects call occurrences of an exact method or explicit generic family inside an outer method
- InnerTarget
Selects occurrences of a member operation or literal load inside an outer method
- MethodBaseExtensions
General extensions for collections
- MethodInvoker
A helper class to invoke method with delegates
- Patch
A serializable patch
- PatchClassProcessor
A PatchClassProcessor used to turn HarmonyAttribute on a class/type into patches
- PatchInfo
Serializable patch information
- PatchProcessor
A PatchProcessor handles patches on a method/constructor
- Patches
A group of patches
- Priority
A patch priority
- ReversePatcher
A reverse patcher
- SymbolExtensions
A helper class to retrieve reflection info for non-private methods and fields
- Transpilers
A collection of commonly used transpilers
- Traverse
A reflection helper to read and write private elements
- Traverse<T>
A reflection helper to read and write private elements
Enums
- ArgumentMode
Specifies how Harmony resolves an argument name
- ArgumentType
Specifies the type of argument
- ExceptionBlockType
Exception block types
- HarmonyPatchType
Specifies the type of patch
- HarmonyReversePatchType
Specifies the type of reverse patch
- InfixOuterBody
Selects the containing method body searched by an Infix
- InnerTargetKind
The operation selected by an Infix declaration
- MethodDispatchType
Specifies the type of method call dispatching mechanics
- MethodType
Specifies the type of method
Delegates
- AccessTools.FieldRef<F>
A readable/assignable reference delegate to a static field
- AccessTools.FieldRef<T, F>
A readable/assignable reference delegate to an instance field of a class or static field (NOT an instance field of a struct)
- AccessTools.StructFieldRef<T, F>
A readable/assignable reference delegate to an instance field of a struct
- CodeMatcher.ErrorHandler
Delegate for error handling
- FastInvokeHandler
A delegate to invoke a method
- InstantiationHandler<T>
A constructor delegate type
- RefResult<T>
Delegate type for "ref return" injections