Skip to content

Introduction

MonoDetour is mainly designed to be used with HookGen. That is, MonoDetour generates helpers hooks to make hooking easy.

You can use the generated hooks like so:

// Generate helper hooks for the target type.
[MonoDetourTargets(typeof(SomeType))]
class SomeTypeHooks
{
// MonoDetourManager.InvokeHookInitializers will
// call methods marked with this attribute in types
// which have the MonoDetourTargetsAttribute.
[MonoDetourHookInit]
internal static void InitHooks()
{
// Note: this is using the default generated MonoDetourManager
// MonoDetour.HookGen.DefaultMonoDetourManager.Instance by default.
// Use it for managing your hooks.
On.SomeNamespace.SomeType.SomeMethod.Prefix(Prefix_SomeMethod);
}
private static void Prefix_SomeMethod(SomeType self, ref int number)
{
Console.WriteLine("Hello from Prefix hook!");
}
}

MonoDetour entirely relies on ILHooks for hooking similar to HarmonyX. But instead of having monolithic ILHook methods like in HarmonyX, MonoDetour maps every hook to a unique ILHook.