MonoDetourManager Class
Definition
Section titled “Definition”A manager for MonoDetourHooks.
public class MonoDetourManager : IDisposableInheritance object
Implements IDisposable
Constructors
Section titled “Constructors”MonoDetourManager(string)
Section titled “MonoDetourManager(string)”A manager for MonoDetourHooks.
public MonoDetourManager(string id)Parameters
Section titled “Parameters”id string
The identifier for this manager. This will be used as the identifier in MonoDetourConfig by default.
This ID should be unique per mod, such as the assembly name, but a single mod can use the same ID for all its MonoDetourManagers.
Properties
Section titled “Properties”Identifier for a MonoDetourManager. This will be used as the identifier in MonoDetourConfig by default.
This ID should be unique per mod such as the assembly name, but a single mod can use the same ID for all its MonoDetourManagers.
public string Id { get; }LogFilter
Section titled “LogFilter”Filter for which channels this log source logs to.
public MonoDetourLogger.LogChannel LogFilter { get; set; }The hooks applied by this MonoDetourManager.
public List<IMonoDetourHook> Hooks { get; }Methods
Section titled “Methods”InvokeHookInitializers(Assembly, bool)
Section titled “InvokeHookInitializers(Assembly, bool)”Invokes hook initializers for the specified assembly.
public static void InvokeHookInitializers(Assembly assembly, bool reportUnloadableTypes = true)Parameters
Section titled “Parameters”assembly Assembly
The assembly whose hook initializers to invoke.
reportUnloadableTypes bool
Whether or not MonoDetour will log on unloadable types.
If you are aware that sometimes types can’t be loaded, e.g. when soft-depending on another assembly, and you don’t need MonoDetour to tell you that this is the reason your hook initializer isn’t running, you can set this value to false.
Remarks
Section titled “Remarks”If a hook initializer throws, this method throws.
InvokeHookInitializers(Assembly)
Section titled “InvokeHookInitializers(Assembly)”Invokes hook initializers for the specified assembly.
public static void InvokeHookInitializers(Assembly assembly)Parameters
Section titled “Parameters”assembly Assembly
The assembly whose hook initializers to invoke.
Remarks
Section titled “Remarks”If a hook initializer throws, this method throws.
InvokeHookInitializers(Type, bool)
Section titled “InvokeHookInitializers(Type, bool)”Invokes hook initializers for the specified type.
public static void InvokeHookInitializers(Type type, bool reportUnloadableTypes = true)Parameters
Section titled “Parameters”type Type
The type whose hook initializers to invoke.
reportUnloadableTypes bool
Whether or not MonoDetour will log on unloadable types.
If you are aware that sometimes types can’t be loaded, e.g. when soft-depending on another assembly, and you don’t need MonoDetour to tell you that this is the reason your hook initializer isn’t running, you can set this value to false.
Remarks
Section titled “Remarks”If a hook initializer throws, this method throws.
InvokeHookInitializers(Type)
Section titled “InvokeHookInitializers(Type)”Invokes hook initializers for the specified type.
public static void InvokeHookInitializers(Type type)Parameters
Section titled “Parameters”type Type
The type whose hook initializers to invoke.
Remarks
Section titled “Remarks”If a hook initializer throws, this method throws.
ApplyHooks()
Section titled “ApplyHooks()”Applies all hooks belonging to this manager.
public void ApplyHooks()Remarks
Section titled “Remarks”By default, a MonoDetourManager won’t have any hooks. You need to initialize the hooks first, either calling them manually or using InvokeHookInitializers(Assembly) or any of its overloads.
UndoHooks()
Section titled “UndoHooks()”Undoes all applied hooks belonging to this manager.
public void UndoHooks()DisposeHooks()
Section titled “DisposeHooks()”Undoes and disposes all hooks belonging to this manager.
public void DisposeHooks()ILHook(Delegate, Manipulator, MonoDetourConfig?, bool)
Section titled “ILHook(Delegate, Manipulator, MonoDetourConfig?, bool)”Creates a ILHookDetour hook using the information defined.
public MonoDetourHook ILHook(Delegate target, ILManipulationInfo.Manipulator manipulator, MonoDetourConfig? config = null, bool applyByDefault = true)Parameters
Section titled “Parameters”target Delegate
The method to be hooked.
manipulator ILManipulationInfo.Manipulator
The manipulator method.
config MonoDetourConfig
The priority configuration for this hook.
applyByDefault bool
Whether or not the hook should be applied after it has been constructed.
Returns
Section titled “Returns”MonoDetourHook
The hook.
Remarks
Section titled “Remarks”This method is not intended to be used directly, but is instead used by MonoDetour’s HookGen.
ILHook(MethodBase, Manipulator, MonoDetourConfig?, bool)
Section titled “ILHook(MethodBase, Manipulator, MonoDetourConfig?, bool)”Creates a ILHookDetour hook using the information defined.
public MonoDetourHook ILHook(MethodBase target, ILManipulationInfo.Manipulator manipulator, MonoDetourConfig? config = null, bool applyByDefault = true)Parameters
Section titled “Parameters”target MethodBase
The method to be hooked.
manipulator ILManipulationInfo.Manipulator
The manipulator method.
config MonoDetourConfig
The priority configuration for this hook.
applyByDefault bool
Whether or not the hook should be applied after it has been constructed.
Returns
Section titled “Returns”MonoDetourHook
The hook.
Remarks
Section titled “Remarks”This method is not intended to be used directly, but is instead used by MonoDetour’s HookGen.
Hook<TApplier>(Delegate, Delegate, MonoDetourConfig?, bool)
Section titled “Hook<TApplier>(Delegate, Delegate, MonoDetourConfig?, bool)”Creates a MonoDetour Hook using the information defined.
public MonoDetourHook Hook<TApplier>(Delegate target, Delegate manipulator, MonoDetourConfig? config = null, bool applyByDefault = true) where TApplier : class, IMonoDetourHookApplierParameters
Section titled “Parameters”target Delegate
The method to be hooked.
manipulator Delegate
The hook or manipulator method.
config MonoDetourConfig
Metadata configuration for the MonoDetour Hook.
applyByDefault bool
Whether or not the hook should be applied after it has been constructed.
Returns
Section titled “Returns”MonoDetourHook
The hook.
Remarks
Section titled “Remarks”This method is not intended to be used directly, but is instead used by MonoDetour’s HookGen.
Hook<TApplier>(MethodBase, Delegate, MonoDetourConfig?, bool)
Section titled “Hook<TApplier>(MethodBase, Delegate, MonoDetourConfig?, bool)”Creates a MonoDetour Hook using the information defined.
public MonoDetourHook Hook<TApplier>(MethodBase target, Delegate manipulator, MonoDetourConfig? config = null, bool applyByDefault = true) where TApplier : class, IMonoDetourHookApplierParameters
Section titled “Parameters”target MethodBase
The method to be hooked.
manipulator Delegate
The hook or manipulator method.
config MonoDetourConfig
Metadata configuration for the MonoDetour Hook.
applyByDefault bool
Whether or not the hook should be applied after it has been constructed.
Returns
Section titled “Returns”MonoDetourHook
The hook.
Remarks
Section titled “Remarks”This method is not intended to be used directly, but is instead used by MonoDetour’s HookGen.
Hook<TApplier>(MethodBase, MethodBase, MonoDetourConfig?, bool)
Section titled “Hook<TApplier>(MethodBase, MethodBase, MonoDetourConfig?, bool)”Creates a MonoDetour Hook using the information defined.
public MonoDetourHook Hook<TApplier>(MethodBase target, MethodBase manipulator, MonoDetourConfig? config = null, bool applyByDefault = true) where TApplier : class, IMonoDetourHookApplierParameters
Section titled “Parameters”target MethodBase
The method to be hooked.
manipulator MethodBase
The hook or manipulator method.
config MonoDetourConfig
Metadata configuration for the MonoDetour Hook.
applyByDefault bool
Whether or not the hook should be applied after it has been constructed.
Returns
Section titled “Returns”MonoDetourHook
The hook.
Remarks
Section titled “Remarks”This method is not intended to be used directly, but is instead used by MonoDetour’s HookGen.
Dispose()
Section titled “Dispose()”Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()Events
Section titled “Events”OnHookThrew
Section titled “OnHookThrew”An event which is called when a hook owned by this MonoDetourManager throws, just before all hooks from the MonoDetourManager are disposed as a consequence.
Use this event for cleaning up related resources to help prevent as much damage as possible.
The hook which threw is passed as the only argument.
public event Action<IReadOnlyMonoDetourHook>? OnHookThrew