Browse documentation

Runtime patching
for .NET

Run your code before, after, or inside existing methods. Combine patches from multiple authors without changing files on disk.

Change a return value
[HarmonyPatch(typeof(Player), "GetSpeed")]
static class SpeedPatch
{
    static void Postfix(ref float __result)
    {
        __result *= 1.5f;
    }
}
See how postfixes work

You're reading the Harmony 3 preview. For the current stable version, use the 2.x documentation.

Guides and reference

Your first patch

Install Harmony, pick a method, and apply a patch. Start with a complete working example.

Follow the example

Infix patching

Target an operation inside a method using familiar patch types. New in v3.

Explore Infix

API reference

Find types, signatures, parameters, and overloads generated directly from Harmony.

Browse the API

How a patch fits together

On each call · the ordinary execution path
  1. PrefixRead arguments, change them, or skip the original.
  2. OriginalRun the method body, including any instruction edits.
  3. PostfixRead or change the result after completion or a skip.
Finalizer · success or exceptionWhen installed, handles the outcome of the sequence above.

A prefix can skip the original; postfixes still run. An exception interrupts the sequence and skips remaining postfixes. A finalizer can observe, change, or suppress that exception.

Built for patches that coexist

Harmony combines patches on the same method and lets their authors coordinate execution order. It supports .NET and Mono environments, including many Unity games. Runtime capabilities still matter: see the limits of runtime patching.

Choose a patch type · Understand patch ordering

Get Harmony into your project

Use Lib.Harmony for one DLL with its dependencies merged in. Use Lib.Harmony.Thin when you want to manage those dependencies yourself.

This site describes v3 preview development on the v3 branch. Check the version your application loads before using new APIs. The installation guide covers the steps.

Made for the modding community

Andreas Pardeike created Harmony for RimWorld and its modding community. Today it is used in many games and applications.

Discuss patches on Discord, report a problem on GitHub, or contribute an improvement to the guides.

Contact Andreas at [email protected]. Support Harmony on Patreon.