MonoDetour 0.6.0

dotnet add package MonoDetour --version 0.6.0
                    
NuGet\Install-Package MonoDetour -Version 0.6.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MonoDetour" Version="0.6.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MonoDetour" Version="0.6.0" />
                    
Directory.Packages.props
<PackageReference Include="MonoDetour" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add MonoDetour --version 0.6.0
                    
#r "nuget: MonoDetour, 0.6.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=MonoDetour&version=0.6.0
                    
Install MonoDetour as a Cake Addin
#tool nuget:?package=MonoDetour&version=0.6.0
                    
Install MonoDetour as a Cake Tool

MonoDetour

MonoDetour MonoDetour.HookGen Community Support
MonoDetour MonoDetour.HookGen Discord

A MonoMod.RuntimeDetour wrapper optimized for convenience, based around HookGen with C# source generators.

This library is not fully released, and things will change.

  • Bugs and missing functionality is expected
  • Documentation may not reflect reality

Major things missing for you may be:

  • Currently there is no HarmonyX interoperability
    • Hooks that change control flow (HarmonyX prefix return false) will ignore MonoDetour/HarmonyX

Add to Your Project

Change the version number to optimally the newest:

<ItemGroup>
  <PackageReference Include="MonoDetour.HookGen" Version="0.4.2" PrivateAssets="all" />
  <PackageReference Include="MonoDetour" Version="0.4.0" />
</ItemGroup>

MonoDetour.HookGen will automatically bring in the oldest MonoDetour reference it supports, so it's a good idea to specify the version for both.

Additionally MonoDetour automatically brings in the oldest MonoMod.RuntimeDetour version it supports, so also specify its version to the one you want (or don't if it's included by e.g. BepInEx references). MonoDetour should support MonoMod.RuntimeDetour versions 21.12.13.1 and 25.*, with possibly anything in between.

Note that MonoDetour.HookGen will strip unused generated hooks when building with Release configuration by default when MonoDetourHookGenStripUnusedHooks is undefined (evaluates to empty string).

You can configure this setting yourself however you wish, such as replicating the default behavior:

<PropertyGroup Condition="'$(Configuration)' == 'Release'">
  <MonoDetourHookGenStripUnusedHooks>true</MonoDetourHookGenStripUnusedHooks>
</PropertyGroup>

Having this setting enabled will be more expensive generation wise and intellisense may not keep up when writing hooks, e.g. Prefix, Postfix and ILHook methods may not immediately appear when typing On.Namespace.Type.Method. even if they have just been generated.

If the default HookGen namespace On causes collisions or you just don't like it, you can set it with the following property:

<PropertyGroup>
  <MonoDetourHookGenNamespace>On</MonoDetourHookGenNamespace>
</PropertyGroup>

Documentation

Usage

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:

[MonoDetourTargets(typeof(SomeType))]
class SomeTypeHooks
{
    [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_SomeType_SomeMethod);
    }

    static void Prefix_SomeType_SomeMethod(SomeType self)
    {
        Console.WriteLine("Hello from Prefix hook 1!");
    }
}

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.

Core Concepts

MonoDetourManager

https://monodetour.github.io/getting-started/monodetourmanager/

Why?

https://monodetour.github.io/getting-started/why-monodetour/

How Does the HookGen Work?

https://monodetour.github.io/getting-started/hookgen/

Credits

The HookGen source generator is heavily based on MonoMod.HookGen.V2. Without it, this project probably wouldn't exist.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on MonoDetour:

Package Downloads
MonoDetour.HookGen

Hook generation for MonoDetour via C# source generators: On.Namespace.Type.Method.Prefix(MyPrefix);

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.6.0 47 6/6/2025
0.5.4 68 6/6/2025
0.5.3 102 6/4/2025
0.5.2 96 6/4/2025
0.5.1 96 6/4/2025
0.5.0 114 6/4/2025
0.4.7 99 6/4/2025
0.4.6 103 6/3/2025
0.4.5 102 6/1/2025
0.4.4 63 6/1/2025
0.4.3 65 6/1/2025
0.4.2 78 5/30/2025
0.4.0 199 5/28/2025
0.3.1-dev 110 5/28/2025
0.3.0-dev 170 5/27/2025
0.2.0-dev 111 5/26/2025
0.1.1-dev 156 5/25/2025
0.1.0-dev.10 120 5/25/2025
0.1.0-dev.5 75 5/24/2025
0.1.0-dev 52 5/24/2025