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

Internal engine structure and callback invocation macros. More...

#include <atomic>
#include <memory>
#include <mutex>
#include "EngineIpc.h"

Go to the source code of this file.

Classes

class  ResettableOnce
 Once-per-hook announcement guard that can be re-armed. More...
struct  HYDRAHOOK_ENGINE
 Internal engine instance structure (opaque in public API). More...
struct  HYDRAHOOK_ENGINE::RenderPipelineState
struct  HookActivityTracker
 Lock-free tracker for in-flight hook lambda invocations. More...
struct  HookActivityTracker::Guard
 RAII guard placed at the top of every hook lambda. More...

Namespaces

namespace  spdlog

Macros

#define INVOKE_HYDRAHOOK_GAME_HOOKED(_engine_, _version_)
 Invokes EvtHydraHookGameHooked if non-NULL.
#define INVOKE_D3D9_CALLBACK(_engine_, _callback_, ...)
 Invokes D3D9 callback if registered.
#define INVOKE_D3D10_CALLBACK(_engine_, _callback_, ...)
 Invokes D3D10 callback if registered.
#define INVOKE_D3D11_CALLBACK(_engine_, _callback_, ...)
 Invokes D3D11 callback if registered.
#define INVOKE_D3D12_CALLBACK(_engine_, _callback_, ...)
 Invokes D3D12 callback if registered.
#define INVOKE_ARC_CALLBACK(_engine_, _callback_, ...)
 Invokes Core Audio callback if registered.

Functions

template<typename T, typename U>
void StoreRenderPipelinePtr (std::atomic< T * > &slot, U *value)
 Publishes a RenderPipeline pointer. Render threads write it while other threads look engines up by it (HydraHookEngineGetHandleFrom*), so every access goes through these.
template<typename Pipeline>
void ClearRenderPipeline (Pipeline &pipeline)
 Resets every RenderPipeline pointer atomically, so concurrent lookups never see a torn value.
template<typename T>
T * LoadRenderPipelinePtr (const std::atomic< T * > &slot)
bool HydraHookPinWorkerModule ()
 Pins the module that contains this engine for the rest of the process.
void HydraHookLoggingEnableAsync ()
 Swaps the process logger to a HydraHook-owned async pool. Call from the worker, not DllMain.
void HydraHookLoggingDisableAsync ()
 Flushes, restores the sync logger, and joins the async pool. Call from the worker, not DllMain.
std::shared_ptr< spdlog::logger > HydraHookCloneRegisteredLogger (const char *channel)
 Clones the registered HYDRAHOOK logger; replacement cannot drop it during this call. Do not call from DllMain: this takes a blocking host-logger lock and may post through async_logger.
HYDRAHOOK_ERROR HydraHookEngineDestroyBeforeUnload (HMODULE host, bool(*detachFreeLibraryHook)() noexcept)
 Tears down the registered engine before explicit unload. Busy failures keep the hook installed.

Detailed Description

Internal engine structure and callback invocation macros.

Defines the opaque HYDRAHOOK_ENGINE layout and macros for invoking version-specific callbacks. Internal use only; not part of public API.

Definition in file Engine.h.

Macro Definition Documentation

◆ INVOKE_ARC_CALLBACK

#define INVOKE_ARC_CALLBACK ( _engine_,
_callback_,
... )
Value:
do { \
const auto _pfn_ = (_engine_)->EventsARC._callback_; \
if (_pfn_) _pfn_(##__VA_ARGS__); \
} while(0)

Invokes Core Audio callback if registered.

Definition at line 295 of file Engine.h.

◆ INVOKE_D3D10_CALLBACK

#define INVOKE_D3D10_CALLBACK ( _engine_,
_callback_,
... )
Value:
do { \
const auto _pfn_ = (_engine_)->EventsD3D10._callback_; \
if (_pfn_) _pfn_(##__VA_ARGS__); \
} while(0)

Invokes D3D10 callback if registered.

Definition at line 274 of file Engine.h.

◆ INVOKE_D3D11_CALLBACK

#define INVOKE_D3D11_CALLBACK ( _engine_,
_callback_,
... )
Value:
do { \
const auto _pfn_ = (_engine_)->EventsD3D11._callback_; \
if (_pfn_) _pfn_(##__VA_ARGS__); \
} while(0)

Invokes D3D11 callback if registered.

Definition at line 281 of file Engine.h.

◆ INVOKE_D3D12_CALLBACK

#define INVOKE_D3D12_CALLBACK ( _engine_,
_callback_,
... )
Value:
do { \
const auto _pfn_ = (_engine_)->EventsD3D12._callback_; \
if (_pfn_) _pfn_(##__VA_ARGS__); \
} while(0)

Invokes D3D12 callback if registered.

Definition at line 288 of file Engine.h.

◆ INVOKE_D3D9_CALLBACK

#define INVOKE_D3D9_CALLBACK ( _engine_,
_callback_,
... )
Value:
do { \
const auto _pfn_ = (_engine_)->EventsD3D9._callback_; \
if (_pfn_) _pfn_(##__VA_ARGS__); \
} while(0)

Invokes D3D9 callback if registered.

Definition at line 267 of file Engine.h.

Referenced by HydraHookMainThread().

◆ INVOKE_HYDRAHOOK_GAME_HOOKED

#define INVOKE_HYDRAHOOK_GAME_HOOKED ( _engine_,
_version_ )
Value:
do { \
(_engine_)->GameVersion = (_version_); \
HydraHookIpcPublish((_engine_), HydraHookIpcStateHooked, HydraHookIpcShutdownOriginNone, \
static_cast<std::uint32_t>(_version_), 0); \
if ((_engine_)->EngineConfig.EvtHydraHookGameHooked) \
(_engine_)->EngineConfig.EvtHydraHookGameHooked((_engine_), (_version_)); \
} while (0)
constexpr std::uint32_t HydraHookIpcStateHooked
Definition EngineIpc.h:48
constexpr std::uint32_t HydraHookIpcShutdownOriginNone
Definition EngineIpc.h:52

Invokes EvtHydraHookGameHooked if non-NULL.

Definition at line 257 of file Engine.h.

Referenced by HydraHookMainThread().

Function Documentation

◆ ClearRenderPipeline()

template<typename Pipeline>
void ClearRenderPipeline ( Pipeline & pipeline)
inline

Resets every RenderPipeline pointer atomically, so concurrent lookups never see a torn value.

Definition at line 152 of file Engine.h.

References ClearRenderPipeline().

Referenced by ClearRenderPipeline(), HydraHookEngineRehook(), and HydraHookEngineUnhook().

◆ HydraHookCloneRegisteredLogger()

std::shared_ptr< spdlog::logger > HydraHookCloneRegisteredLogger ( const char * channel)

Clones the registered HYDRAHOOK logger; replacement cannot drop it during this call. Do not call from DllMain: this takes a blocking host-logger lock and may post through async_logger.

Definition at line 1059 of file Engine.cpp.

References HydraHookCloneRegisteredLogger().

Referenced by DestroyEngine(), HydraHookCloneRegisteredLogger(), and PerformShutdownCleanup().

◆ HydraHookEngineDestroyBeforeUnload()

HYDRAHOOK_ERROR HydraHookEngineDestroyBeforeUnload ( HMODULE host,
bool(* detachFreeLibraryHook )() noexcept )

Tears down the registered engine before explicit unload. Busy failures keep the hook installed.

Definition at line 573 of file Engine.cpp.

References DestroyEngine(), and HydraHookEngineDestroyBeforeUnload().

Referenced by HydraHookEngineDestroyBeforeUnload(), and HydraHookMainThread().

◆ HydraHookLoggingDisableAsync()

void HydraHookLoggingDisableAsync ( )

Flushes, restores the sync logger, and joins the async pool. Call from the worker, not DllMain.

Definition at line 1016 of file Engine.cpp.

References HydraHookLoggingDisableAsync().

Referenced by HydraHookLoggingDisableAsync().

◆ HydraHookLoggingEnableAsync()

void HydraHookLoggingEnableAsync ( )

Swaps the process logger to a HydraHook-owned async pool. Call from the worker, not DllMain.

Definition at line 961 of file Engine.cpp.

References HydraHookLoggingEnableAsync().

Referenced by HydraHookLoggingEnableAsync(), and HydraHookMainThread().

◆ HydraHookPinWorkerModule()

bool HydraHookPinWorkerModule ( )

Pins the module that contains this engine for the rest of the process.

Definition at line 150 of file Engine.cpp.

References HydraHookPinWorkerModule().

Referenced by HydraHookPinWorkerModule().

◆ LoadRenderPipelinePtr()

template<typename T>
T * LoadRenderPipelinePtr ( const std::atomic< T * > & slot)
inline

◆ StoreRenderPipelinePtr()

template<typename T, typename U>
void StoreRenderPipelinePtr ( std::atomic< T * > & slot,
U * value )
inline

Publishes a RenderPipeline pointer. Render threads write it while other threads look engines up by it (HydraHookEngineGetHandleFrom*), so every access goes through these.

Definition at line 143 of file Engine.h.

References StoreRenderPipelinePtr().

Referenced by HydraHookMainThread(), and StoreRenderPipelinePtr().