Skip to content

Patch annotations

Geoffrey Horsington edited this page Jan 22, 2020 · 2 revisions

The main way to apply patches is by annotating your patch classes or patch methods with special Harmony attributes. In addition, Harmony supports some special magic methods to handle various aspects of patching.

HarmonyX supports two types of patches: class patches and method patches.
Class patches are defined by annotating a class with HarmonyPatch attribute, while method patches are defined by annotating each method with HarmonyPatch.

Please refer to the next subsections for more information on patch annotations. Here's a table that outlines main differences between the two patch types:

Feature Class patches Method patches
Declared by... Adding HarmonyPatch attribute to a class Adding HarmonyPatch attribute to a method
Supported patch types Prefixes, postfixes, transpilers, finalizers, reverse patchers Prefixes, postfixes, transpilers, finalizers
Additional lifetime methods HarmonyPrepare, HarmonyTargetMethod(s), HarmonyCleanup None
Applied with Harmony.PatchAll(Assembly assembly) Harmony.PatchAll(Type type)