Skip to content

Auto Patcher [No Dependency]

TheInsanityGod edited this page Sep 23, 2026 · 2 revisions

InsanityLib will automatically generate methods for doing the patching/unpatching (these are called by AutoSetup and AutoDispose).

Conditional Patches

For finer control over the patches you can make use of the [HarmonyPatchCategory] attribute (from Harmony itself) to better split the patches and allow them to be conditionally applied.

The convention for category names is as following: type:condition

Currently the following type will trigger an automatic conditional registration:

  • mod if the condition is the modid of a mod that is present it will automatically run those patches

Manual

Sometimes you might want to apply patches based on a more complex condition, in this case you can implement the ManualPatches method:

partial void ManualPatches(Harmony harmony, ICoreAPI api)
{
    if(AccessTools.Method("DynamicClassesModSystem.DynamicClassesModSystem:LoadOrCreateTraitsConfig") is not null)
    {
        TryPatchCategory(harmony, "feature:extendedtraits_dynamictraits", Mod.Logger);
    }

    if(AccessTools.TypeByName("XLib.XLeveling.XLeveling") is not null)
    {
        TryPatchCategory(harmony, "feature:extendedtraits_xlib", Mod.Logger);
    }
}

Legacy

when : is not specified in the category it is assumed that type is mod, this is to avoid breaking existing mods. This might be removed at a later point so it is not recommended to use this approach anymore.

For finer control you can use the [HarmonyPatchCategory] to group patches: if the category name matches a ModID then it will be automatically applied, if not then you can manually decide when to patch this category by implementing the partial ManualPatches method.

Clone this wiki locally