Skip to content

MonoDetourManager Class

A manager for MonoDetourHooks.

C#
public class MonoDetourManager : IDisposable

Inheritance object

Implements IDisposable

A manager for MonoDetourHooks.

C#
public MonoDetourManager(string id)

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.

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.

C#
public string Id { get; }

Filter for which channels this log source logs to.

C#
public MonoDetourLogger.LogChannel LogFilter { get; set; }

The hooks applied by this MonoDetourManager.

C#
public List<IMonoDetourHook> Hooks { get; }

Invokes hook initializers for the specified assembly.

C#
public static void InvokeHookInitializers(Assembly assembly, bool reportUnloadableTypes = true)

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.

If a hook initializer throws, this method throws.

Invokes hook initializers for the specified assembly.

C#
public static void InvokeHookInitializers(Assembly assembly)

assembly Assembly
The assembly whose hook initializers to invoke.

If a hook initializer throws, this method throws.

Invokes hook initializers for the specified type.

C#
public static void InvokeHookInitializers(Type type, bool reportUnloadableTypes = true)

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.

If a hook initializer throws, this method throws.

Invokes hook initializers for the specified type.

C#
public static void InvokeHookInitializers(Type type)

type Type
The type whose hook initializers to invoke.

If a hook initializer throws, this method throws.

Applies all hooks belonging to this manager.

C#
public void ApplyHooks()

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.

Undoes all applied hooks belonging to this manager.

C#
public void UndoHooks()

Undoes and disposes all hooks belonging to this manager.

C#
public void DisposeHooks()

ILHook(Delegate, Manipulator, MonoDetourConfig?, bool)

Section titled “ILHook(Delegate, Manipulator, MonoDetourConfig?, bool)”

Creates a ILHookDetour hook using the information defined.

C#
public MonoDetourHook ILHook(Delegate target, ILManipulationInfo.Manipulator manipulator, MonoDetourConfig? config = null, bool applyByDefault = true)

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.

MonoDetourHook
The hook.

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.

C#
public MonoDetourHook ILHook(MethodBase target, ILManipulationInfo.Manipulator manipulator, MonoDetourConfig? config = null, bool applyByDefault = true)

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.

MonoDetourHook
The hook.

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.

C#
public MonoDetourHook Hook<TApplier>(Delegate target, Delegate manipulator, MonoDetourConfig? config = null, bool applyByDefault = true) where TApplier : class, IMonoDetourHookApplier

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.

MonoDetourHook
The hook.

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.

C#
public MonoDetourHook Hook<TApplier>(MethodBase target, Delegate manipulator, MonoDetourConfig? config = null, bool applyByDefault = true) where TApplier : class, IMonoDetourHookApplier

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.

MonoDetourHook
The hook.

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.

C#
public MonoDetourHook Hook<TApplier>(MethodBase target, MethodBase manipulator, MonoDetourConfig? config = null, bool applyByDefault = true) where TApplier : class, IMonoDetourHookApplier

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.

MonoDetourHook
The hook.

This method is not intended to be used directly, but is instead used by MonoDetour’s HookGen.

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

C#
public void Dispose()

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.

C#
public event Action<IReadOnlyMonoDetourHook>? OnHookThrew

Action<IReadOnlyMonoDetourHook>