Class Hook<T>
Manages a hook which can be used to intercept a call to native function. This class is basically a thin wrapper around the LocalHook type to provide helper functions.
Inheritance
Inherited Members
Namespace: Dalamud.Hooking
Assembly: Dalamud.dll
Syntax
public class Hook<T> : IDisposable, IDalamudHook where T : Delegate
Type Parameters
| Name | Description |
|---|---|
| T | Delegate type to represents a function prototype. This must be the same prototype as original function do. |
Constructors
| Improve this Doc View SourceHook(IntPtr, T)
Initializes a new instance of the Hook<T> class. Hook is not activated until Enable() method is called.
Declaration
[Obsolete("Use Hook<T>.FromAddress instead.")]
public Hook(IntPtr address, T detour)
Parameters
| Type | Name | Description |
|---|---|---|
| System.IntPtr | address | A memory address to install a hook. |
| T | detour | Callback function. Delegate must have a same original function prototype. |
Hook(IntPtr, T, Boolean)
Initializes a new instance of the Hook<T> class. Hook is not activated until Enable() method is called. Please do not use MinHook unless you have thoroughly troubleshot why Reloaded does not work.
Declaration
[Obsolete("Use Hook<T>.FromAddress instead.")]
public Hook(IntPtr address, T detour, bool useMinHook)
Parameters
| Type | Name | Description |
|---|---|---|
| System.IntPtr | address | A memory address to install a hook. |
| T | detour | Callback function. Delegate must have a same original function prototype. |
| System.Boolean | useMinHook | Use the MinHook hooking library instead of Reloaded. |
Properties
| Improve this Doc View SourceAddress
Gets a memory address of the target function.
Declaration
public IntPtr Address { get; }
Property Value
| Type | Description |
|---|---|
| System.IntPtr |
Exceptions
| Type | Condition |
|---|---|
| System.ObjectDisposedException | Hook is already disposed. |
BackendName
Gets the name of the hooking backend used for the hook.
Declaration
public virtual string BackendName { get; }
Property Value
| Type | Description |
|---|---|
| System.String |
IsDisposed
Gets a value indicating whether or not the hook has been disposed.
Declaration
public bool IsDisposed { get; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
IsEnabled
Gets a value indicating whether or not the hook is enabled.
Declaration
public virtual bool IsEnabled { get; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
Original
Gets a delegate function that can be used to call the actual function as if function is not hooked yet.
Declaration
public virtual T Original { get; }
Property Value
| Type | Description |
|---|---|
| T |
Exceptions
| Type | Condition |
|---|---|
| System.ObjectDisposedException | Hook is already disposed. |
OriginalDisposeSafe
Gets a delegate function that can be used to call the actual function as if function is not hooked yet. This can be called even after Dispose.
Declaration
public T OriginalDisposeSafe { get; }
Property Value
| Type | Description |
|---|---|
| T |
Methods
| Improve this Doc View SourceCheckDisposed()
Check if this object has been disposed already.
Declaration
protected void CheckDisposed()
Disable()
Stops intercepting a call to the function.
Declaration
public virtual void Disable()
Dispose()
Remove a hook from the current process.
Declaration
public virtual void Dispose()
Enable()
Starts intercepting a call to the function.
Declaration
public virtual void Enable()
FromAddress(IntPtr, T, Boolean)
Creates a hook. Hooking address is inferred by calling to GetProcAddress() function. The hook is not activated until Enable() method is called. Please do not use MinHook unless you have thoroughly troubleshot why Reloaded does not work.
Declaration
public static Hook<T> FromAddress(IntPtr procAddress, T detour, bool useMinHook = false)
Parameters
| Type | Name | Description |
|---|---|---|
| System.IntPtr | procAddress | A memory address to install a hook. |
| T | detour | Callback function. Delegate must have a same original function prototype. |
| System.Boolean | useMinHook | Use the MinHook hooking library instead of Reloaded. |
Returns
| Type | Description |
|---|---|
| Hook<T> | The hook with the supplied parameters. |
FromFunctionPointerVariable(IntPtr, T)
Creates a hook by rewriting import table address.
Declaration
public static Hook<T> FromFunctionPointerVariable(IntPtr address, T detour)
Parameters
| Type | Name | Description |
|---|---|---|
| System.IntPtr | address | A memory address to install a hook. |
| T | detour | Callback function. Delegate must have a same original function prototype. |
Returns
| Type | Description |
|---|---|
| Hook<T> | The hook with the supplied parameters. |
FromImport(ProcessModule, String, String, UInt32, T)
Creates a hook by rewriting import table address.
Declaration
public static Hook<T> FromImport(ProcessModule module, string moduleName, string functionName, uint hintOrOrdinal, T detour)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Diagnostics.ProcessModule | module | Module to check for. Current process' main module if null. |
| System.String | moduleName | Name of the DLL, including the extension. |
| System.String | functionName | Decorated name of the function. |
| System.UInt32 | hintOrOrdinal | Hint or ordinal. 0 to unspecify. |
| T | detour | Callback function. Delegate must have a same original function prototype. |
Returns
| Type | Description |
|---|---|
| Hook<T> | The hook with the supplied parameters. |
FromSymbol(String, String, T)
Creates a hook. Hooking address is inferred by calling to GetProcAddress() function. The hook is not activated until Enable() method is called.
Declaration
public static Hook<T> FromSymbol(string moduleName, string exportName, T detour)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | moduleName | A name of the module currently loaded in the memory. (e.g. ws2_32.dll). |
| System.String | exportName | A name of the exported function name (e.g. send). |
| T | detour | Callback function. Delegate must have a same original function prototype. |
Returns
| Type | Description |
|---|---|
| Hook<T> | The hook with the supplied parameters. |
FromSymbol(String, String, T, Boolean)
Creates a hook. Hooking address is inferred by calling to GetProcAddress() function. The hook is not activated until Enable() method is called. Please do not use MinHook unless you have thoroughly troubleshot why Reloaded does not work.
Declaration
public static Hook<T> FromSymbol(string moduleName, string exportName, T detour, bool useMinHook)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | moduleName | A name of the module currently loaded in the memory. (e.g. ws2_32.dll). |
| System.String | exportName | A name of the exported function name (e.g. send). |
| T | detour | Callback function. Delegate must have a same original function prototype. |
| System.Boolean | useMinHook | Use the MinHook hooking library instead of Reloaded. |
Returns
| Type | Description |
|---|---|
| Hook<T> | The hook with the supplied parameters. |