MonoModReorg.RuntimeDetour 23.1.2-prerelease.1

.NET 5.0 .NET Standard 2.0 .NET Framework 3.5
This is a prerelease version of MonoModReorg.RuntimeDetour.
There is a newer version of this package available.
See the version list below for details.
dotnet add package MonoModReorg.RuntimeDetour --version 23.1.2-prerelease.1
NuGet\Install-Package MonoModReorg.RuntimeDetour -Version 23.1.2-prerelease.1
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="MonoModReorg.RuntimeDetour" Version="23.1.2-prerelease.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MonoModReorg.RuntimeDetour --version 23.1.2-prerelease.1
#r "nuget: MonoModReorg.RuntimeDetour, 23.1.2-prerelease.1"
#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.
// Install MonoModReorg.RuntimeDetour as a Cake Addin
#addin nuget:?package=MonoModReorg.RuntimeDetour&version=23.1.2-prerelease.1&prerelease

// Install MonoModReorg.RuntimeDetour as a Cake Tool
#tool nuget:?package=MonoModReorg.RuntimeDetour&version=23.1.2-prerelease.1&prerelease

Notable APIs

  • MonoMod.RuntimeDetour.Hook - An easy-to-use method hook
  • MonoMod.RuntimeDetour.ILHook - Modifies the IL of a method
  • MonoMod.RuntiemDetour.DetourContext - Persistent, shared detour configuration

Basic Usage

// Create a Hook.
using (var d = new Hook(methodInfoFrom, methodInfoTo))
{
    // When the detour goes out-of-scope (and thus has Dispose() called), the detour is undone.
    // If the object is collected by the garbage collector, the detour is also undone.
}

Visit the GitHub and look for RuntimeDetour for more documentation.

Detour Types

There are 2 managed detour types that are available:

  1. Hook - This is effectively Detour but better. It sits as part of the same detour chain as Detour objects. The target of the hook may be a delegate, and so may be an instance method associated with some object. Hook targets may also take as their first parameter a delegate with a signature matching the detour source. This delegate, when called, will invoke the next detour in the chain, or the original if this is the last detour in the chain. Note: this delegate should usually only be called while the hook method is on the stack. See The Detour Chain for more information.
  2. ILHook - This is a different kind of detour. If you're familiar with Harmony, this is effectively a transpiler. When you construct an ILHook, you provide a delegate which gets provided an ILContext which can be used to modify the IL of the method. If multiple ILHooks are present for the same method, the order the manipulators are invoked is the same as the order detours in a detour chain would be.

Each detour (Hook or ILHook) may have an associated DetourConfig. Each detour config must have an ID--this will typically be the name of the mod which applies the hook. They also have a list of IDs which detours associated with this config will run before, and a similar list that they will run after. If some config A wants to run before B, and B wants to run before A, the resulting order is unspecified. The MonoMod debug log will make a note of this.

Detour configs may also have a priority. Detours with any priority will execute before any without, unless one of the before or after fields caused it to be placed differently. The before and after fields take precedence over the priority field.

Any detours with no DetourConfig get run in an arbitrary order after all those with a DetourConfig.

The Detour Chain

All detours whose source method is the same are part of one detour chain. When the source method is called, the first detour in the chain gets called. That detour then has complete control over how that function behaves. It may, at any point, invoke the delegate (gotten from the delegate parameter to a hook method) to invoke the next detour in the chain. It may pass any parameters, and do anything with the return value.

While within the original method invocation (i.e. in the detour chain, with every prior detour on the stack), invoking the continuation delegate is safe, and will always invoke the next detour in the chain. Modifying the detour chain for a method is thread safe, and modifications will wait until all existing invocations of the detour chain exit, and all new invocations of the chain will wait until the chain modification is complete before execution. Notably, though, this means that invoking continuation delegates while the detour chain is not on the stack is not thread-safe, nor is it guaranteed to actually invoke the delegate chain as it exists at the moment of invocation. Always invoke the original method, and never delay invocation of the original delegate.

Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows
.NET Core netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.0 netstandard2.1
.NET Framework net35 net40 net403 net45 net451 net452 net46 net461 net462 net463 net47 net471 net472 net48 net481
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on MonoModReorg.RuntimeDetour:

Repository Stars
goatcorp/Dalamud
FFXIV plugin framework and API
Version Downloads Last updated
23.3.22.1 59 3/23/2023
23.3.2.1 374 3/2/2023
23.1.2-prerelease.1 757 1/3/2023
22.11.21-prerelease.2 933 11/22/2022
22.11.21-prerelease.1 57 11/21/2022
22.11.17-prerelease.1 75 11/17/2022
22.11.9-prerelease.1 479 11/9/2022
22.11.8-prerelease.1 63 11/8/2022
22.11.8-prerelease 56 11/8/2022
22.11.4-prerelease 56 11/5/2022
22.10.25-prerelease 68 10/25/2022
22.10.21-prerelease 74 10/21/2022
22.10.11-prerelease 67 10/11/2022
22.10.6-prerelease 44 10/6/2022
22.9.29-prerelease 93 9/29/2022
22.9.23-prerelease 143 9/23/2022
22.9.14-prerelease 101 9/14/2022
22.9.7-prerelease 69 9/7/2022
22.8.29-prerelease 71 8/29/2022