The code functionality for runtime detouring. Use `DetourFactory.Current` to get a DetourFactory capable of installing unique method detours. WARNING: THIS IS A LOW-LEVEL LIBRARY THAT IS DIFFICULT TO USE ON ITS OWN. If possible, use MonoMod.RuntimeDetour instead.
$ dotnet add package MonoModReorg.CoreRuntimeDetour instead.You have been warned.
MonoMod.Core.DetourFactory.CurrentMonoMod.Core.ICoreDetourUse DetourFactory.Current.CreateDetour to create a single detour from one method to another. The detour will be
automatically undone when the returnedc object is disposed or garbage collected. Only one such detour may be made per
method. If multiple are made, they will not be cleaned up properly. MonoMod.Core does not track which methods have
already been detoured, and will not throw.
It is therefore highly recommended to use a higher-level detouring API (like that provided by
MonoMod.RuntimeDetour or Harmony) to perform detours. Those higher level APIs also provide solutions to many of
the limitations to Core's detour abstraction, such as the ability to call the original, unmodified method, or
modify the IL of the method. (See their documentation for how this is actually done.)
The default IDetourFactory utilizes MonoMod.Core.Platforms.PlatformTriple.Current to implement detours. Notably,
that factory handles re-creating the underlying ISimpleNativeDetour objects when methods are recompiled by the
runtime.
PlatformTriple does provide a few other utilities which may be useful for a higher-level library, however:
PlatformTriple.Prepare JIT compiles a method, sully supporting generic instantiationsPlatformTriple.GetIdentifiable translates the provided MethodBase into an instance which can be used as, for
instance, the key to a ConditionalWeakTableThe other methods of PlatformTriple are means of implementing the detour factory, and likely should not be touched.