HydraHook
Direct3D and Core Audio hooking library for Windows
Loading...
Searching...
No Matches
HydraHookCore.h File Reference

Core engine API for HydraHook - Direct3D and Core Audio hooking library. More...

Go to the source code of this file.

Classes

struct  PHYDRAHOOK_EVT_PRE_EXTENSION
 Extension data passed to pre-hook event callbacks (D3D11/12, Core Audio). More...
struct  PHYDRAHOOK_EVT_POST_EXTENSION
 Extension data passed to post-hook event callbacks (D3D11/12, Core Audio). More...
struct  PHYDRAHOOK_ENGINE_CONFIG
 Engine configuration passed to HydraHookEngineCreate. Initialize with HYDRAHOOK_ENGINE_CONFIG_INIT. New fields are appended so a caller can pass a larger config to an engine that knows only this layout. More...

Macros

#define HYDRAHOOK_API
#define HYDRAHOOK_DEFINE_DLLMAIN(config_init)
 Defines a compatible DllMain that bootstraps the HydraHook engine.

Typedefs

typedef enum _HYDRAHOOK_D3D_VERSION * PHYDRAHOOK_D3D_VERSION
typedef struct _HYDRAHOOK_ENGINE * PHYDRAHOOK_ENGINE
 Opaque handle to the HydraHook engine instance.
typedef struct _HYDRAHOOK_D3D9_EVENT_CALLBACKS * PHYDRAHOOK_D3D9_EVENT_CALLBACKS
typedef struct _HYDRAHOOK_D3D10_EVENT_CALLBACKS * PHYDRAHOOK_D3D10_EVENT_CALLBACKS
typedef struct _HYDRAHOOK_D3D11_EVENT_CALLBACKS * PHYDRAHOOK_D3D11_EVENT_CALLBACKS
typedef struct _HYDRAHOOK_D3D12_EVENT_CALLBACKS * PHYDRAHOOK_D3D12_EVENT_CALLBACKS
typedef struct _HYDRAHOOK_ARC_EVENT_CALLBACKS * PHYDRAHOOK_ARC_EVENT_CALLBACKS
typedef BOOL EVT_HYDRAHOOK_CRASH_HANDLER(PHYDRAHOOK_ENGINE EngineHandle, DWORD ExceptionCode, struct _EXCEPTION_POINTERS *ExceptionInfo)
 Crash handler callback invoked before a minidump is written.
typedef EVT_HYDRAHOOK_CRASH_HANDLER * PFN_HYDRAHOOK_CRASH_HANDLER
typedef VOID EVT_HYDRAHOOK_GAME_HOOKED(PHYDRAHOOK_ENGINE EngineHandle, const HYDRAHOOK_D3D_VERSION GameVersion)
 Callback invoked when a render API has been hooked successfully.
typedef EVT_HYDRAHOOK_GAME_HOOKED * PFN_HYDRAHOOK_GAME_HOOKED
typedef VOID EVT_HYDRAHOOK_GAME_UNHOOKED(PHYDRAHOOK_ENGINE EngineHandle)
 Callback invoked before or after unhooking the render API.
typedef EVT_HYDRAHOOK_GAME_UNHOOKED * PFN_HYDRAHOOK_GAME_UNHOOKED
typedef VOID EVT_HYDRAHOOK_GAME_EXIT(PHYDRAHOOK_ENGINE EngineHandle)
 Callback invoked when host process shutdown is detected.
typedef EVT_HYDRAHOOK_GAME_EXIT * PFN_HYDRAHOOK_GAME_EXIT

Enumerations

enum  HYDRAHOOK_ERROR {
  HYDRAHOOK_ERROR_NONE = 0x20000000 , HYDRAHOOK_ERROR_INVALID_ENGINE_HANDLE = 0xE0000001 , HYDRAHOOK_ERROR_CREATE_THREAD_FAILED = 0xE0000002 , HYDRAHOOK_ERROR_ENGINE_ALLOCATION_FAILED = 0xE0000003 ,
  HYDRAHOOK_ERROR_ENGINE_ALREADY_ALLOCATED = 0xE0000004 , HYDRAHOOK_ERROR_INVALID_HMODULE_HANDLE = 0xE0000005 , HYDRAHOOK_ERROR_GET_MODULE_HANDLE_FAILED = 0xE0000006 , HYDRAHOOK_ERROR_REFERENCE_INCREMENT_FAILED = HYDRAHOOK_ERROR_GET_MODULE_HANDLE_FAILED ,
  HYDRAHOOK_ERROR_CONTEXT_ALLOCATION_FAILED = 0xE0000007 , HYDRAHOOK_ERROR_CREATE_EVENT_FAILED = 0xE0000008 , HYDRAHOOK_ERROR_CREATE_LOGGER_FAILED = 0xE0000009 , HYDRAHOOK_ERROR_NO_LOADER_LOCK = 0xE000000A ,
  HYDRAHOOK_ERROR_UNHOOK_INCOMPLETE = 0xE000000B , HYDRAHOOK_ERROR_INVALID_ENGINE_CONFIG = 0xE000000C
}
 Error codes returned by HydraHook engine functions. More...
enum  HYDRAHOOK_D3D_VERSION {
  HydraHookDirect3DVersionUnknown = 0 , HydraHookDirect3DVersion9 = 1 << 0 , HydraHookDirect3DVersion10 = 1 << 1 , HydraHookDirect3DVersion11 = 1 << 2 ,
  HydraHookDirect3DVersion12 = 1 << 3
}
 Bitmask of detected Direct3D API versions. More...
enum  HYDRAHOOK_DUMP_TYPE { HydraHookDumpTypeMinimal = 0 , HydraHookDumpTypeNormal = 1 , HydraHookDumpTypeFull = 2 }
 Minidump verbosity levels for the crash handler. More...

Functions

VOID HYDRAHOOK_EVT_PRE_EXTENSION_INIT (PHYDRAHOOK_EVT_PRE_EXTENSION Extension, PHYDRAHOOK_ENGINE Engine, PVOID Context)
 Initializes a pre-extension structure for event callbacks.
VOID HYDRAHOOK_EVT_POST_EXTENSION_INIT (PHYDRAHOOK_EVT_POST_EXTENSION Extension, PHYDRAHOOK_ENGINE Engine, PVOID Context)
 Initializes a post-extension structure for event callbacks.
VOID HYDRAHOOK_ENGINE_CONFIG_INIT (PHYDRAHOOK_ENGINE_CONFIG EngineConfig)
HYDRAHOOK_ERROR HydraHookEngineCreate (_In_ HMODULE HostInstance, _In_ PHYDRAHOOK_ENGINE_CONFIG EngineConfig, _Out_opt_ PHYDRAHOOK_ENGINE *Engine)
 Creates and initializes the HydraHook engine.
HYDRAHOOK_ERROR HydraHookEngineDestroy (_In_ HMODULE HostInstance)
 Destroys the engine and frees all resources.
HYDRAHOOK_ERROR HydraHookEngineUnhook (_In_ PHYDRAHOOK_ENGINE Engine)
 Removes all render and audio hooks while keeping the DLL and engine loaded.
HYDRAHOOK_ERROR HydraHookEngineRehook (_In_ PHYDRAHOOK_ENGINE Engine)
 Reinstalls hooks on an engine previously stopped with HydraHookEngineUnhook.
HYDRAHOOK_ERROR HydraHookEngineAllocCustomContext (_In_ PHYDRAHOOK_ENGINE Engine, _Out_ PVOID *Context, _In_ size_t ContextSize)
 Allocates custom context memory accessible from all event callbacks.
HYDRAHOOK_ERROR HydraHookEngineFreeCustomContext (_In_ PHYDRAHOOK_ENGINE Engine)
 Frees custom context memory for the engine.
PVOID HydraHookEngineGetCustomContext (_In_ PHYDRAHOOK_ENGINE Engine)
 Returns pointer to custom context memory, or NULL if none allocated.
BOOL HydraHookEngineAreCallbacksDrained (_In_ PHYDRAHOOK_ENGINE Engine)
 Reports whether all in-flight render callbacks were confirmed finished by the last unhook.
VOID HydraHookEngineSetD3D9EventCallbacks (_In_ PHYDRAHOOK_ENGINE Engine, _In_ PHYDRAHOOK_D3D9_EVENT_CALLBACKS Callbacks)
 Registers Direct3D 9/9Ex render pipeline callbacks.
VOID HydraHookEngineSetD3D10EventCallbacks (_In_ PHYDRAHOOK_ENGINE Engine, _In_ PHYDRAHOOK_D3D10_EVENT_CALLBACKS Callbacks)
 Registers Direct3D 10 render pipeline callbacks.
VOID HydraHookEngineSetD3D11EventCallbacks (_In_ PHYDRAHOOK_ENGINE Engine, _In_ PHYDRAHOOK_D3D11_EVENT_CALLBACKS Callbacks)
 Registers Direct3D 11 render pipeline callbacks.
VOID HydraHookEngineSetARCEventCallbacks (_In_ PHYDRAHOOK_ENGINE Engine, _In_ PHYDRAHOOK_ARC_EVENT_CALLBACKS Callbacks)
 Registers Core Audio (IAudioRenderClient) event callbacks.
VOID HydraHookEngineLogDebug (_In_ LPCSTR Format, _In_opt_ ...)
 Logs a debug message (printf-style format).
VOID HydraHookEngineLogInfo (_In_ LPCSTR Format, _In_opt_ ...)
 Logs an informational message (printf-style format).
VOID HydraHookEngineLogWarning (_In_ LPCSTR Format, _In_opt_ ...)
 Logs a warning message (printf-style format).
VOID HydraHookEngineLogError (_In_ LPCSTR Format, _In_opt_ ...)
 Logs an error message (printf-style format).

Detailed Description

Core engine API for HydraHook - Direct3D and Core Audio hooking library.

This header defines the main engine interface, configuration structures, error codes, and lifecycle functions. Intended to be called from DllMain() at DLL_PROCESS_ATTACH and DLL_PROCESS_DETACH.

Windows Integration
Uses Microsoft SAL annotations (In, Out, etc.) for static analysis. Compatible with Visual Studio IntelliSense and Doxygen documentation.

Definition in file HydraHookCore.h.

Macro Definition Documentation

◆ HYDRAHOOK_API

#define HYDRAHOOK_API

Definition at line 52 of file HydraHookCore.h.

Referenced by HydraHookD3D12ReadbackCreate(), HydraHookD3D12ReadbackCreate(), HydraHookD3D12ReadbackCreateRegion(), HydraHookD3D12ReadbackCreateRegion(), HydraHookD3D12ReadbackDestroy(), HydraHookD3D12ReadbackDestroy(), HydraHookD3D12ReadbackReleaseFrame(), HydraHookD3D12ReadbackReleaseFrame(), HydraHookD3D12ReadbackTryReadLatest(), HydraHookD3D12ReadbackTryReadLatest(), HydraHookD3D12ReadbackTrySubmit(), HydraHookD3D12ReadbackTrySubmit(), HydraHookEngineAllocCustomContext(), HydraHookEngineAllocCustomContext(), HydraHookEngineAreCallbacksDrained(), HydraHookEngineAreCallbacksDrained(), HydraHookEngineCreate(), HydraHookEngineCreate(), HydraHookEngineDeferD3D12Resize(), HydraHookEngineDeferD3D12Resize(), HydraHookEngineDestroy(), HydraHookEngineDestroy(), HydraHookEngineFreeCustomContext(), HydraHookEngineFreeCustomContext(), HydraHookEngineGetCustomContext(), HydraHookEngineGetCustomContext(), HydraHookEngineGetD3D12CommandQueue(), HydraHookEngineGetD3D12CommandQueue(), HydraHookEngineGetHandleFromD3D10SwapChain(), HydraHookEngineGetHandleFromD3D10SwapChain(), HydraHookEngineGetHandleFromD3D9Device(), HydraHookEngineGetHandleFromD3D9Device(), HydraHookEngineGetHandleFromD3D9ExDevice(), HydraHookEngineGetHandleFromD3D9ExDevice(), HydraHookEngineGetVerifiedD3D12CommandQueue(), HydraHookEngineGetVerifiedD3D12CommandQueue(), HydraHookEngineLogDebug(), HydraHookEngineLogDebug(), HydraHookEngineLogError(), HydraHookEngineLogError(), HydraHookEngineLogInfo(), HydraHookEngineLogInfo(), HydraHookEngineLogWarning(), HydraHookEngineLogWarning(), HydraHookEngineRehook(), HydraHookEngineRehook(), HydraHookEngineSetARCEventCallbacks(), HydraHookEngineSetARCEventCallbacks(), HydraHookEngineSetD3D10EventCallbacks(), HydraHookEngineSetD3D10EventCallbacks(), HydraHookEngineSetD3D11EventCallbacks(), HydraHookEngineSetD3D11EventCallbacks(), HydraHookEngineSetD3D12EventCallbacks(), HydraHookEngineSetD3D12EventCallbacks(), HydraHookEngineSetD3D9EventCallbacks(), HydraHookEngineSetD3D9EventCallbacks(), HydraHookEngineUnhook(), and HydraHookEngineUnhook().

◆ HYDRAHOOK_DEFINE_DLLMAIN

#define HYDRAHOOK_DEFINE_DLLMAIN ( config_init)
Value:
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID) \
{ \
switch (dwReason) \
{ \
case DLL_PROCESS_ATTACH: \
DisableThreadLibraryCalls((HMODULE)(hInstance)); \
{ \
HYDRAHOOK_ENGINE_CONFIG_INIT(&cfg); \
config_init \
(void)HydraHookEngineCreate((HMODULE)(hInstance), &cfg, NULL); \
} \
break; \
case DLL_PROCESS_DETACH: \
(void)HydraHookEngineDestroy((HMODULE)(hInstance)); \
break; \
default: \
break; \
} \
return TRUE; \
}
HYDRAHOOK_ERROR HydraHookEngineDestroy(_In_ HMODULE HostInstance)
Destroys the engine and frees all resources.
HYDRAHOOK_ERROR HydraHookEngineCreate(_In_ HMODULE HostInstance, _In_ PHYDRAHOOK_ENGINE_CONFIG EngineConfig, _Out_opt_ PHYDRAHOOK_ENGINE *Engine)
Creates and initializes the HydraHook engine.
Engine configuration passed to HydraHookEngineCreate. Initialize with HYDRAHOOK_ENGINE_CONFIG_INIT....

Defines a compatible DllMain that bootstraps the HydraHook engine.

Use this macro in exactly one translation unit of your hosting DLL. Requires Windows.h (or equivalent) to be included before use.

Parameters
config_initBlock of statements that configure the engine config. The config variable is named cfg (HYDRAHOOK_ENGINE_CONFIG). Example:
cfg.Direct3D.HookDirect3D11 = TRUE;
cfg.EvtHydraHookGameHooked = EvtHydraHookGameHooked;
cfg.CrashHandler.IsEnabled = TRUE;
)
#define HYDRAHOOK_DEFINE_DLLMAIN(config_init)
Defines a compatible DllMain that bootstraps the HydraHook engine.

Definition at line 293 of file HydraHookCore.h.

Typedef Documentation

◆ EVT_HYDRAHOOK_CRASH_HANDLER

typedef BOOL EVT_HYDRAHOOK_CRASH_HANDLER(PHYDRAHOOK_ENGINE EngineHandle, DWORD ExceptionCode, struct _EXCEPTION_POINTERS *ExceptionInfo)

Crash handler callback invoked before a minidump is written.

Returns
TRUE to proceed with dump file creation, FALSE to skip it.

Definition at line 173 of file HydraHookCore.h.

◆ EVT_HYDRAHOOK_GAME_EXIT

typedef VOID EVT_HYDRAHOOK_GAME_EXIT(PHYDRAHOOK_ENGINE EngineHandle)

Callback invoked when host process shutdown is detected.

Definition at line 206 of file HydraHookCore.h.

◆ EVT_HYDRAHOOK_GAME_HOOKED

typedef VOID EVT_HYDRAHOOK_GAME_HOOKED(PHYDRAHOOK_ENGINE EngineHandle, const HYDRAHOOK_D3D_VERSION GameVersion)

Callback invoked when a render API has been hooked successfully.

Definition at line 185 of file HydraHookCore.h.

◆ EVT_HYDRAHOOK_GAME_UNHOOKED

typedef VOID EVT_HYDRAHOOK_GAME_UNHOOKED(PHYDRAHOOK_ENGINE EngineHandle)

Callback invoked before or after unhooking the render API.

Definition at line 196 of file HydraHookCore.h.

◆ PFN_HYDRAHOOK_CRASH_HANDLER

◆ PFN_HYDRAHOOK_GAME_EXIT

◆ PFN_HYDRAHOOK_GAME_HOOKED

◆ PFN_HYDRAHOOK_GAME_UNHOOKED

◆ PHYDRAHOOK_ARC_EVENT_CALLBACKS

Core Audio callbacks.

Definition at line 99 of file HydraHookCore.h.

◆ PHYDRAHOOK_D3D10_EVENT_CALLBACKS

D3D10 callbacks.

Definition at line 96 of file HydraHookCore.h.

◆ PHYDRAHOOK_D3D11_EVENT_CALLBACKS

D3D11 callbacks.

Definition at line 97 of file HydraHookCore.h.

◆ PHYDRAHOOK_D3D12_EVENT_CALLBACKS

D3D12 callbacks.

Definition at line 98 of file HydraHookCore.h.

◆ PHYDRAHOOK_D3D9_EVENT_CALLBACKS

D3D9 callbacks.

Definition at line 95 of file HydraHookCore.h.

◆ PHYDRAHOOK_D3D_VERSION

typedef enum _HYDRAHOOK_D3D_VERSION * PHYDRAHOOK_D3D_VERSION

◆ PHYDRAHOOK_ENGINE

typedef struct _HYDRAHOOK_ENGINE* PHYDRAHOOK_ENGINE

Opaque handle to the HydraHook engine instance.

Definition at line 93 of file HydraHookCore.h.

Enumeration Type Documentation

◆ HYDRAHOOK_D3D_VERSION

Bitmask of detected Direct3D API versions.

Enumerator
HydraHookDirect3DVersionUnknown 

No Direct3D detected.

HydraHookDirect3DVersion9 

Direct3D 9 or 9Ex.

HydraHookDirect3DVersion10 

Direct3D 10.

HydraHookDirect3DVersion11 

Direct3D 11.

HydraHookDirect3DVersion12 

Direct3D 12.

Definition at line 84 of file HydraHookCore.h.

◆ HYDRAHOOK_DUMP_TYPE

Minidump verbosity levels for the crash handler.

Enumerator
HydraHookDumpTypeMinimal 

Threads + stacks only (small).

HydraHookDumpTypeNormal 
  • data segments, handles, unloaded modules.
HydraHookDumpTypeFull 

Full process memory (large).

Definition at line 160 of file HydraHookCore.h.

◆ HYDRAHOOK_ERROR

Error codes returned by HydraHook engine functions.

Enumerator
HYDRAHOOK_ERROR_NONE 

Success.

HYDRAHOOK_ERROR_INVALID_ENGINE_HANDLE 

Engine handle is NULL or invalid.

HYDRAHOOK_ERROR_CREATE_THREAD_FAILED 

CreateThread failed for hook worker.

HYDRAHOOK_ERROR_ENGINE_ALLOCATION_FAILED 

Failed to allocate engine structure.

HYDRAHOOK_ERROR_ENGINE_ALREADY_ALLOCATED 

Engine already created for this HMODULE.

HYDRAHOOK_ERROR_INVALID_HMODULE_HANDLE 

HMODULE not associated with an engine.

HYDRAHOOK_ERROR_GET_MODULE_HANDLE_FAILED 

GetModuleHandleEx failed.

HYDRAHOOK_ERROR_REFERENCE_INCREMENT_FAILED 
Deprecated
Use HYDRAHOOK_ERROR_GET_MODULE_HANDLE_FAILED.
HYDRAHOOK_ERROR_CONTEXT_ALLOCATION_FAILED 

Custom context allocation failed.

HYDRAHOOK_ERROR_CREATE_EVENT_FAILED 

CreateEvent failed for cancellation.

HYDRAHOOK_ERROR_CREATE_LOGGER_FAILED 

Failed to create fallback logger.

HYDRAHOOK_ERROR_NO_LOADER_LOCK 

Initialization attempted outside of loader lock.

HYDRAHOOK_ERROR_UNHOOK_INCOMPLETE 

Worker did not finish unhooking, or hook callbacks are still running; engine state is kept, retry later.

HYDRAHOOK_ERROR_INVALID_ENGINE_CONFIG 

The engine config size is smaller than required.

Definition at line 62 of file HydraHookCore.h.

Function Documentation

◆ HYDRAHOOK_ENGINE_CONFIG_INIT()

VOID HYDRAHOOK_ENGINE_CONFIG_INIT ( PHYDRAHOOK_ENGINE_CONFIG EngineConfig)
inline

Initialize an HYDRAHOOK_ENGINE_CONFIG structure with library defaults (logging enabled; fallback log path "%TEMP%\\HydraHook.log").

Parameters
[in,out]EngineConfigPointer to the HYDRAHOOK_ENGINE_CONFIG to initialize. Must point to a writable structure.

Definition at line 263 of file HydraHookCore.h.

References HYDRAHOOK_ENGINE_CONFIG_INIT(), and HydraHookDumpTypeNormal.

Referenced by HYDRAHOOK_ENGINE_CONFIG_INIT(), and HydraHookEngineCreate().

◆ HYDRAHOOK_EVT_POST_EXTENSION_INIT()

VOID HYDRAHOOK_EVT_POST_EXTENSION_INIT ( PHYDRAHOOK_EVT_POST_EXTENSION Extension,
PHYDRAHOOK_ENGINE Engine,
PVOID Context )
inline

Initializes a post-extension structure for event callbacks.

Parameters
[in,out]ExtensionThe extension structure to initialize.
[in]EngineThe engine handle.
[in]ContextOptional custom context pointer.

Definition at line 145 of file HydraHookCore.h.

References HYDRAHOOK_EVT_POST_EXTENSION_INIT().

Referenced by HYDRAHOOK_EVT_POST_EXTENSION_INIT().

◆ HYDRAHOOK_EVT_PRE_EXTENSION_INIT()

VOID HYDRAHOOK_EVT_PRE_EXTENSION_INIT ( PHYDRAHOOK_EVT_PRE_EXTENSION Extension,
PHYDRAHOOK_ENGINE Engine,
PVOID Context )
inline

Initializes a pre-extension structure for event callbacks.

Parameters
[in,out]ExtensionThe extension structure to initialize.
[in]EngineThe engine handle.
[in]ContextOptional custom context pointer.

Definition at line 117 of file HydraHookCore.h.

References HYDRAHOOK_EVT_PRE_EXTENSION_INIT().

Referenced by HYDRAHOOK_EVT_PRE_EXTENSION_INIT().

◆ HydraHookEngineAllocCustomContext()

HYDRAHOOK_ERROR HydraHookEngineAllocCustomContext ( _In_ PHYDRAHOOK_ENGINE Engine,
_Out_ PVOID * Context,
_In_ size_t ContextSize )

Allocates custom context memory accessible from all event callbacks.

Replaces any previously allocated context. Use HydraHookEngineGetCustomContext from callbacks to retrieve the pointer.

Parameters
[in]EngineValid engine handle.
[out]ContextReceives pointer to allocated memory.
[in]ContextSizeSize in bytes.
Return values
HYDRAHOOK_ERROR_NONESuccess.
HYDRAHOOK_ERROR_INVALID_ENGINE_HANDLEEngine is NULL.
HYDRAHOOK_ERROR_CONTEXT_ALLOCATION_FAILEDmalloc failed.

References HYDRAHOOK_API, and HydraHookEngineAllocCustomContext().

Referenced by HydraHookEngineAllocCustomContext(), and HydraHookEngineAllocCustomContext().

◆ HydraHookEngineAreCallbacksDrained()

BOOL HydraHookEngineAreCallbacksDrained ( _In_ PHYDRAHOOK_ENGINE Engine)

Reports whether all in-flight render callbacks were confirmed finished by the last unhook.

Query it from EvtHydraHookGamePostUnhook before destroying a custom context. When it returns FALSE, a callback may still hold a pointer obtained from the context; keep the context allocated. The engine releases it in HydraHookEngineDestroy after the callbacks have returned.

Parameters
[in]EngineValid engine handle.
Returns
TRUE when the callback drain completed, FALSE when it timed out or Engine is NULL.

References HYDRAHOOK_API, and HydraHookEngineAreCallbacksDrained().

Referenced by HydraHookEngineAreCallbacksDrained(), and HydraHookEngineAreCallbacksDrained().

◆ HydraHookEngineCreate()

HYDRAHOOK_ERROR HydraHookEngineCreate ( _In_ HMODULE HostInstance,
_In_ PHYDRAHOOK_ENGINE_CONFIG EngineConfig,
_Out_opt_ PHYDRAHOOK_ENGINE * Engine )

Creates and initializes the HydraHook engine.

Spawns a worker thread that detects and hooks the host process's render pipeline (Direct3D 9/10/11/12) and optionally Core Audio. Also hooks ExitProcess, PostQuitMessage, and FreeLibrary for graceful shutdown. Set Shutdown.DisableThreadQuitMonitoring to let a host thread quit independently. On FreeLibrary of the host module the hook destroys the engine before entering the loader, then calls FreeLibraryAndExitThread(hLibModule, TRUE) so remote-thread ejectors observe a TRUE BOOL result. Busy teardown returns FALSE with ERROR_BUSY and can be retried. Call from DllMain() at DLL_PROCESS_ATTACH.

Parameters
[in]HostInstanceHMODULE of the injecting DLL (typically from DllMain).
[in]EngineConfigConfiguration and callbacks initialized with HYDRAHOOK_ENGINE_CONFIG_INIT.
[out]EngineOptional; receives the engine handle on success.
Return values
HYDRAHOOK_ERROR_NONESuccess.
HYDRAHOOK_ERROR_ENGINE_ALREADY_ALLOCATEDEngine already exists for this HMODULE.
HYDRAHOOK_ERROR_GET_MODULE_HANDLE_FAILEDGetModuleHandleEx failed (deprecated alias: HYDRAHOOK_ERROR_REFERENCE_INCREMENT_FAILED).
HYDRAHOOK_ERROR_ENGINE_ALLOCATION_FAILEDmalloc failed.
HYDRAHOOK_ERROR_CREATE_EVENT_FAILEDCreateEvent failed.
HYDRAHOOK_ERROR_CREATE_THREAD_FAILEDCreateThread failed.
HYDRAHOOK_ERROR_CREATE_LOGGER_FAILEDFallback logger creation failed.
HYDRAHOOK_ERROR_INVALID_ENGINE_CONFIGConfiguration's Size is smaller than required.

References HYDRAHOOK_API, and HydraHookEngineCreate().

Referenced by HydraHookEngineCreate(), and HydraHookEngineCreate().

◆ HydraHookEngineDestroy()

HYDRAHOOK_ERROR HydraHookEngineDestroy ( _In_ HMODULE HostInstance)

Destroys the engine and frees all resources.

Unhooks the render pipeline and invokes shutdown callbacks. Call from DllMain() at DLL_PROCESS_DETACH. This function does not wait, including on the lifecycle lock. It frees the engine, its cancellation event, and its thread handle only after the worker has exited and a current callback drain succeeds. Otherwise the engine stays allocated, the module that contains the worker is pinned for the rest of the process, and static Hook destructors do not detach.

Parameters
[in]HostInstanceHMODULE passed to HydraHookEngineCreate.
Return values
HYDRAHOOK_ERROR_NONESuccess.
HYDRAHOOK_ERROR_INVALID_HMODULE_HANDLENo engine for this HMODULE.
HYDRAHOOK_ERROR_UNHOOK_INCOMPLETEThe lifecycle lock is busy, or the worker or a hook callback is still running. The engine and its thread handle stay allocated. A DLL_PROCESS_DETACH caller cannot retry after the loader would have unmapped the module; the pin keeps that code mapped.

References HYDRAHOOK_API, and HydraHookEngineDestroy().

Referenced by HydraHookEngineDestroy(), and HydraHookEngineDestroy().

◆ HydraHookEngineFreeCustomContext()

HYDRAHOOK_ERROR HydraHookEngineFreeCustomContext ( _In_ PHYDRAHOOK_ENGINE Engine)

Frees custom context memory for the engine.

Parameters
[in]EngineValid engine handle.
Return values
HYDRAHOOK_ERROR_NONESuccess.
HYDRAHOOK_ERROR_INVALID_ENGINE_HANDLEEngine is NULL.

References HYDRAHOOK_API, and HydraHookEngineFreeCustomContext().

Referenced by HydraHookEngineAllocCustomContext(), HydraHookEngineFreeCustomContext(), and HydraHookEngineFreeCustomContext().

◆ HydraHookEngineGetCustomContext()

PVOID HydraHookEngineGetCustomContext ( _In_ PHYDRAHOOK_ENGINE Engine)

Returns pointer to custom context memory, or NULL if none allocated.

Parameters
[in]EngineValid engine handle.
Returns
Pointer to context, or NULL.

References HYDRAHOOK_API, and HydraHookEngineGetCustomContext().

Referenced by HydraHookEngineGetCustomContext(), and HydraHookEngineGetCustomContext().

◆ HydraHookEngineLogDebug()

VOID HydraHookEngineLogDebug ( _In_ LPCSTR Format,
_In_opt_ ...  )

Logs a debug message (printf-style format).

Parameters
[in]Formatprintf format string.
[in]...Format arguments.

References HYDRAHOOK_API, and HydraHookEngineLogDebug().

Referenced by HydraHookEngineLogDebug(), and HydraHookEngineLogDebug().

◆ HydraHookEngineLogError()

VOID HydraHookEngineLogError ( _In_ LPCSTR Format,
_In_opt_ ...  )

Logs an error message (printf-style format).

Parameters
[in]Formatprintf format string.
[in]...Format arguments.

References HYDRAHOOK_API, and HydraHookEngineLogError().

Referenced by HydraHookEngineLogError(), and HydraHookEngineLogError().

◆ HydraHookEngineLogInfo()

VOID HydraHookEngineLogInfo ( _In_ LPCSTR Format,
_In_opt_ ...  )

Logs an informational message (printf-style format).

Parameters
[in]Formatprintf format string.
[in]...Format arguments.

References HYDRAHOOK_API, and HydraHookEngineLogInfo().

Referenced by HydraHookEngineLogInfo(), and HydraHookEngineLogInfo().

◆ HydraHookEngineLogWarning()

VOID HydraHookEngineLogWarning ( _In_ LPCSTR Format,
_In_opt_ ...  )

Logs a warning message (printf-style format).

Parameters
[in]Formatprintf format string.
[in]...Format arguments.

References HYDRAHOOK_API, and HydraHookEngineLogWarning().

Referenced by HydraHookEngineLogWarning(), and HydraHookEngineLogWarning().

◆ HydraHookEngineRehook()

HYDRAHOOK_ERROR HydraHookEngineRehook ( _In_ PHYDRAHOOK_ENGINE Engine)

Reinstalls hooks on an engine previously stopped with HydraHookEngineUnhook.

Clears the shutdown state, re-arms the once-per-hook announcements (so EvtHydraHookGameHooked fires again), restores the registered callback tables, and starts a new worker thread. Calling it on an engine whose worker is running succeeds.

Do not call while holding the loader lock (for example from DllMain), from a hook callback, or from the engine worker thread.

Parameters
[in]EngineValid engine handle.
Return values
HYDRAHOOK_ERROR_NONESuccess or already hooked.
HYDRAHOOK_ERROR_INVALID_ENGINE_HANDLEEngine is NULL.
HYDRAHOOK_ERROR_CREATE_THREAD_FAILEDCreateThread failed.
HYDRAHOOK_ERROR_UNHOOK_INCOMPLETECallbacks from the previous run are still active.

References HYDRAHOOK_API, and HydraHookEngineRehook().

Referenced by HydraHookEngineRehook(), and HydraHookEngineRehook().

◆ HydraHookEngineSetARCEventCallbacks()

VOID HydraHookEngineSetARCEventCallbacks ( _In_ PHYDRAHOOK_ENGINE Engine,
_In_ PHYDRAHOOK_ARC_EVENT_CALLBACKS Callbacks )

Registers Core Audio (IAudioRenderClient) event callbacks.

Parameters
[in]EngineValid engine handle.
[in]CallbacksCallback collection; NULL pointers are ignored.

References HYDRAHOOK_API, and HydraHookEngineSetARCEventCallbacks().

Referenced by HydraHookEngineSetARCEventCallbacks(), and HydraHookEngineSetARCEventCallbacks().

◆ HydraHookEngineSetD3D10EventCallbacks()

VOID HydraHookEngineSetD3D10EventCallbacks ( _In_ PHYDRAHOOK_ENGINE Engine,
_In_ PHYDRAHOOK_D3D10_EVENT_CALLBACKS Callbacks )

Registers Direct3D 10 render pipeline callbacks.

Parameters
[in]EngineValid engine handle.
[in]CallbacksCallback collection; NULL pointers are ignored.

References HYDRAHOOK_API, and HydraHookEngineSetD3D10EventCallbacks().

Referenced by HydraHookEngineSetD3D10EventCallbacks(), and HydraHookEngineSetD3D10EventCallbacks().

◆ HydraHookEngineSetD3D11EventCallbacks()

VOID HydraHookEngineSetD3D11EventCallbacks ( _In_ PHYDRAHOOK_ENGINE Engine,
_In_ PHYDRAHOOK_D3D11_EVENT_CALLBACKS Callbacks )

Registers Direct3D 11 render pipeline callbacks.

Parameters
[in]EngineValid engine handle.
[in]CallbacksCallback collection; NULL pointers are ignored.

References HYDRAHOOK_API, and HydraHookEngineSetD3D11EventCallbacks().

Referenced by HydraHookEngineSetD3D11EventCallbacks(), and HydraHookEngineSetD3D11EventCallbacks().

◆ HydraHookEngineSetD3D9EventCallbacks()

VOID HydraHookEngineSetD3D9EventCallbacks ( _In_ PHYDRAHOOK_ENGINE Engine,
_In_ PHYDRAHOOK_D3D9_EVENT_CALLBACKS Callbacks )

Registers Direct3D 9/9Ex render pipeline callbacks.

Parameters
[in]EngineValid engine handle.
[in]CallbacksCallback collection; NULL pointers are ignored.

References HYDRAHOOK_API, and HydraHookEngineSetD3D9EventCallbacks().

Referenced by HydraHookEngineSetD3D9EventCallbacks(), and HydraHookEngineSetD3D9EventCallbacks().

◆ HydraHookEngineUnhook()

HYDRAHOOK_ERROR HydraHookEngineUnhook ( _In_ PHYDRAHOOK_ENGINE Engine)

Removes all render and audio hooks while keeping the DLL and engine loaded.

Invokes EvtHydraHookGamePreUnhook and EvtHydraHookGamePostUnhook, stops the worker thread, and clears the live callback tables. Callbacks registered through the HydraHookEngineSet*EventCallbacks functions are retained and restored by HydraHookEngineRehook. Calling it on an already unhooked engine succeeds.

Do not call while holding the loader lock (for example from DllMain), from a hook callback, or from the engine worker thread.

Parameters
[in]EngineValid engine handle.
Return values
HYDRAHOOK_ERROR_NONESuccess or already unhooked.
HYDRAHOOK_ERROR_INVALID_ENGINE_HANDLEEngine is NULL.
HYDRAHOOK_ERROR_UNHOOK_INCOMPLETEThe worker did not exit within 8 seconds, or a hook callback is still running. The worker is never terminated and the engine state is kept; call again later. Do not free resources used by callbacks yet.

References HYDRAHOOK_API, and HydraHookEngineUnhook().

Referenced by HydraHookEngineUnhook(), and HydraHookEngineUnhook().