Patching methods during runtime


This guide is still WIP.

Runtime patching is the process of modifying methods without permanently patching them. Runtime patching happens while the game is running and on .NET can be done very extensively.

BepInEx ships with HarmonyX and MonoMod.RuntimeDetour to perform runtime patching. You can use either or both libraries -- both of them have different API but it does not matter which one you use.


BepInEx uses HarmonyX to perform runtime patching. HarmonyX is a fork of Harmony with changes to specifically allow interop with MonoMod.RuntimeDetour.

HarmonyX is attribute-based, which means you define patches by applying attributes to a method.

Refer to the following guides on how to use HarmonyX:


MonoMod.RuntimeDetour is a helper library that allows to apply runtime patches as C# objects.

Alternatively, RuntimeDetour supports defining patches as events.

Some useful guides