Show / Hide Table of Contents

# 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

System.Object
Hook<T>

##### Implements

System.IDisposable
IDalamudHook

##### Inherited Members

System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()

###### 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 Source

#### Hook(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.

| Improve this Doc View Source

#### 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 Source

#### Address

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.

| Improve this Doc View Source

#### BackendName

Gets the name of the hooking backend used for the hook.

##### Declaration

    public virtual string BackendName { get; }

##### Property Value

Type | Description
--- | ---
System.String |

| Improve this Doc View Source

#### IsDisposed

Gets a value indicating whether or not the hook has been disposed.

##### Declaration

    public bool IsDisposed { get; }

##### Property Value

Type | Description
--- | ---
System.Boolean |

| Improve this Doc View Source

#### IsEnabled

Gets a value indicating whether or not the hook is enabled.

##### Declaration

    public virtual bool IsEnabled { get; }

##### Property Value

Type | Description
--- | ---
System.Boolean |

| Improve this Doc View Source

#### 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.

| Improve this Doc View Source

#### 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 Source

#### CheckDisposed()

Check if this object has been disposed already.

##### Declaration

    protected void CheckDisposed()

| Improve this Doc View Source

#### Disable()

Stops intercepting a call to the function.

##### Declaration

    public virtual void Disable()

| Improve this Doc View Source

#### Dispose()

Remove a hook from the current process.

##### Declaration

    public virtual void Dispose()

| Improve this Doc View Source

#### Enable()

Starts intercepting a call to the function.

##### Declaration

    public virtual void Enable()

| Improve this Doc View Source

#### 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.

| Improve this Doc View Source

#### 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.

| Improve this Doc View Source

#### 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.

| Improve this Doc View Source

#### 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.

| Improve this Doc View Source

#### 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.

### Implements

System.IDisposable
IDalamudHook