|
HydraHook
Direct3D and Core Audio hooking library for Windows
|
HydraHook engine implementation - create, destroy, context, callbacks. More...
#include <Windows.h>#include <stdarg.h>#include "HydraHook/Engine/HydraHookCore.h"#include "HydraHook/Engine/HydraHookDirect3D9.h"#include "HydraHook/Engine/HydraHookDirect3D10.h"#include "HydraHook/Engine/HydraHookDirect3D11.h"#include "HydraHook/Engine/HydraHookDirect3D12.h"#include "HydraHook/Engine/HydraHookCoreAudio.h"#include "Engine.h"#include "CrashHandler.h"#include "Game/Game.h"#include "Game/Shutdown.h"#include "Utils/Global.h"#include "Utils/Hook.h"#include "Utils/SrwLock.h"#include <spdlog/spdlog.h>#include <spdlog/async.h>#include <spdlog/async_logger.h>#include <spdlog/sinks/basic_file_sink.h>#include <spdlog/sinks/null_sink.h>#include <spdlog/sinks/stdout_color_sinks.h>#include <algorithm>#include <cstddef>#include <memory>#include <new>#include <string>#include <string_view>#include <utility>#include <vector>Go to the source code of this file.
Macros | |
| #define | WIN32_LEAN_AND_MEAN |
Functions | |
| bool | HydraHookPinWorkerModule () |
| Pins the module that contains this engine for the rest of the process. | |
| HYDRAHOOK_ERROR | HydraHookEngineCreate (HMODULE HostInstance, PHYDRAHOOK_ENGINE_CONFIG EngineConfig, PHYDRAHOOK_ENGINE *Engine) |
| static HYDRAHOOK_ERROR | DestroyEngine (HMODULE HostInstance, bool(*detachFreeLibraryHook)() noexcept) |
| HYDRAHOOK_ERROR | HydraHookEngineDestroy (HMODULE HostInstance) |
| HYDRAHOOK_ERROR | HydraHookEngineDestroyBeforeUnload (HMODULE host, bool(*detachFreeLibraryHook)() noexcept) |
| Tears down the registered engine before explicit unload. Busy failures keep the hook installed. | |
| HYDRAHOOK_D3D_VERSION | HydraHookEngineGameVersionForTest (PHYDRAHOOK_ENGINE engine) |
| void | HydraHookEngineSetLifecycleLockForTest (PHYDRAHOOK_ENGINE engine, BOOL acquire) |
| HYDRAHOOK_ERROR | HydraHookEngineUnhook (PHYDRAHOOK_ENGINE Engine) |
| HYDRAHOOK_ERROR | HydraHookEngineRehook (PHYDRAHOOK_ENGINE Engine) |
| HYDRAHOOK_ERROR | HydraHookEngineAllocCustomContext (PHYDRAHOOK_ENGINE Engine, PVOID *Context, size_t ContextSize) |
| HYDRAHOOK_ERROR | HydraHookEngineFreeCustomContext (PHYDRAHOOK_ENGINE Engine) |
| PVOID | HydraHookEngineGetCustomContext (PHYDRAHOOK_ENGINE Engine) |
| BOOL | HydraHookEngineAreCallbacksDrained (PHYDRAHOOK_ENGINE Engine) |
| VOID | HydraHookEngineSetD3D9EventCallbacks (PHYDRAHOOK_ENGINE Engine, PHYDRAHOOK_D3D9_EVENT_CALLBACKS Callbacks) |
| PHYDRAHOOK_ENGINE | HydraHookEngineGetHandleFromD3D9Device (LPDIRECT3DDEVICE9 Device) |
| PHYDRAHOOK_ENGINE | HydraHookEngineGetHandleFromD3D9ExDevice (LPDIRECT3DDEVICE9EX Device) |
| VOID | HydraHookEngineSetD3D10EventCallbacks (PHYDRAHOOK_ENGINE Engine, PHYDRAHOOK_D3D10_EVENT_CALLBACKS Callbacks) |
| PHYDRAHOOK_ENGINE | HydraHookEngineGetHandleFromD3D10SwapChain (IDXGISwapChain *SwapChain) |
| VOID | HydraHookEngineSetD3D11EventCallbacks (PHYDRAHOOK_ENGINE Engine, PHYDRAHOOK_D3D11_EVENT_CALLBACKS Callbacks) |
| VOID | HydraHookEngineSetD3D12EventCallbacks (PHYDRAHOOK_ENGINE Engine, PHYDRAHOOK_D3D12_EVENT_CALLBACKS Callbacks) |
| ID3D12CommandQueue * | HydraHookEngineGetD3D12CommandQueue (IDXGISwapChain *pSwapChain) |
| ID3D12CommandQueue * | HydraHookEngineGetVerifiedD3D12CommandQueue (IDXGISwapChain *pSwapChain) |
| BOOL | HydraHookEngineDeferD3D12Resize (PHYDRAHOOK_EVT_PRE_EXTENSION Extension) |
| VOID | HydraHookEngineSetARCEventCallbacks (PHYDRAHOOK_ENGINE Engine, PHYDRAHOOK_ARC_EVENT_CALLBACKS Callbacks) |
| 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. | |
| static std::shared_ptr< spdlog::logger > | GetHostLogger () |
| Returns a cached host-scoped logger clone for the process-wide "HYDRAHOOK" logger. | |
| static void | HydraHookEngineLogImpl (spdlog::level::level_enum level, LPCSTR Format, va_list args) |
| Format a printf-style message and emit it to the host logger at the specified level. | |
| _Use_decl_annotations_ VOID | HydraHookEngineLogDebug (LPCSTR Format,...) |
| _Use_decl_annotations_ VOID | HydraHookEngineLogInfo (LPCSTR Format,...) |
| _Use_decl_annotations_ VOID | HydraHookEngineLogWarning (LPCSTR Format,...) |
| _Use_decl_annotations_ VOID | HydraHookEngineLogError (LPCSTR Format,...) |
Variables | |
| static SRWLOCK | g_EngineHostInstancesLock = SRWLOCK_INIT |
| static std::vector< std::pair< HMODULE, PHYDRAHOOK_ENGINE > > | g_EngineHostInstances |
| static SRWLOCK | g_engineDestroyLock = SRWLOCK_INIT |
HydraHook engine implementation - create, destroy, context, callbacks.
Implements the public C API declared in HydraHookCore.h. Uses spdlog for logging and maintains HMODULE-to-engine handle mapping.
Definition in file Engine.cpp.
| #define WIN32_LEAN_AND_MEAN |
Definition at line 36 of file Engine.cpp.
|
static |
Definition at line 414 of file Engine.cpp.
References DestroyEngine(), DllMainProcessDetach, HookActivityTracker::drain(), FreeLibraryHook, g_engineDestroyLock, g_EngineHostInstances, g_EngineHostInstancesLock, g_hookDestructorDetachSuppressed, HYDRAHOOK_ERROR_INVALID_HMODULE_HANDLE, HYDRAHOOK_ERROR_NONE, HYDRAHOOK_ERROR_UNHOOK_INCOMPLETE, HydraHookCloneRegisteredLogger(), HydraHookCrashHandlerReferencesEngine(), HydraHookCrashHandlerUninstall(), HydraHookIpcAbandonRehookWait(), HydraHookIpcClose(), PerformShutdownCleanup(), and HookActivityTracker::shutdown().
Referenced by DestroyEngine(), HydraHookEngineDestroy(), and HydraHookEngineDestroyBeforeUnload().
|
static |
Returns a cached host-scoped logger clone for the process-wide "HYDRAHOOK" logger.
The returned logger is created once on first call and reused for subsequent calls. If the process-wide "HYDRAHOOK" logger is not available, this function returns nullptr.
Definition at line 1076 of file Engine.cpp.
References GetHostLogger().
Referenced by GetHostLogger(), and HydraHookEngineLogImpl().
| 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().
| HYDRAHOOK_ERROR HydraHookEngineAllocCustomContext | ( | PHYDRAHOOK_ENGINE | Engine, |
| PVOID * | Context, | ||
| size_t | ContextSize ) |
Definition at line 733 of file Engine.cpp.
References HYDRAHOOK_API, HYDRAHOOK_ERROR_CONTEXT_ALLOCATION_FAILED, HYDRAHOOK_ERROR_INVALID_ENGINE_HANDLE, HYDRAHOOK_ERROR_NONE, HydraHookEngineAllocCustomContext(), and HydraHookEngineFreeCustomContext().
| BOOL HydraHookEngineAreCallbacksDrained | ( | PHYDRAHOOK_ENGINE | Engine | ) |
Definition at line 786 of file Engine.cpp.
References HYDRAHOOK_API, and HydraHookEngineAreCallbacksDrained().
| HYDRAHOOK_ERROR HydraHookEngineCreate | ( | HMODULE | HostInstance, |
| PHYDRAHOOK_ENGINE_CONFIG | EngineConfig, | ||
| PHYDRAHOOK_ENGINE * | Engine ) |
Definition at line 161 of file Engine.cpp.
References HydraHook::Core::Util::expand_environment_variables(), g_EngineHostInstances, g_EngineHostInstancesLock, HydraHook::Core::Util::get_module_directory(), HydraHook::Core::Util::get_process_directory(), HYDRAHOOK_ENGINE::HostInstance, HYDRAHOOK_API, HYDRAHOOK_ENGINE_CONFIG_INIT(), HYDRAHOOK_ERROR_CREATE_EVENT_FAILED, HYDRAHOOK_ERROR_CREATE_LOGGER_FAILED, HYDRAHOOK_ERROR_CREATE_THREAD_FAILED, HYDRAHOOK_ERROR_ENGINE_ALLOCATION_FAILED, HYDRAHOOK_ERROR_ENGINE_ALREADY_ALLOCATED, HYDRAHOOK_ERROR_GET_MODULE_HANDLE_FAILED, HYDRAHOOK_ERROR_INVALID_ENGINE_CONFIG, HYDRAHOOK_ERROR_INVALID_ENGINE_HANDLE, HYDRAHOOK_ERROR_NONE, HydraHookCrashHandlerInstall(), HydraHookCrashHandlerReferencesEngine(), HydraHookCrashHandlerUninstall(), HydraHookEngineCreate(), HydraHookIpcClose(), HydraHookIpcCreate(), HydraHookMainThread(), and HookActivityTracker::reset().
| BOOL HydraHookEngineDeferD3D12Resize | ( | PHYDRAHOOK_EVT_PRE_EXTENSION | Extension | ) |
Definition at line 936 of file Engine.cpp.
References D3D12ResizeCallbackScope::Current, D3D12ResizePreExtension::Deferred, HYDRAHOOK_API, and HydraHookEngineDeferD3D12Resize().
| HYDRAHOOK_ERROR HydraHookEngineDestroy | ( | HMODULE | HostInstance | ) |
Definition at line 568 of file Engine.cpp.
References DestroyEngine(), HYDRAHOOK_API, and HydraHookEngineDestroy().
| 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().
| HYDRAHOOK_ERROR HydraHookEngineFreeCustomContext | ( | PHYDRAHOOK_ENGINE | Engine | ) |
Definition at line 761 of file Engine.cpp.
References HYDRAHOOK_API, HYDRAHOOK_ERROR_INVALID_ENGINE_HANDLE, HYDRAHOOK_ERROR_NONE, and HydraHookEngineFreeCustomContext().
| HYDRAHOOK_D3D_VERSION HydraHookEngineGameVersionForTest | ( | PHYDRAHOOK_ENGINE | engine | ) |
Definition at line 578 of file Engine.cpp.
References HydraHookDirect3DVersionUnknown, and HydraHookEngineGameVersionForTest().
Referenced by HydraHookEngineGameVersionForTest().
| PVOID HydraHookEngineGetCustomContext | ( | PHYDRAHOOK_ENGINE | Engine | ) |
Definition at line 776 of file Engine.cpp.
References HYDRAHOOK_API, and HydraHookEngineGetCustomContext().
| ID3D12CommandQueue * HydraHookEngineGetD3D12CommandQueue | ( | IDXGISwapChain * | pSwapChain | ) |
Definition at line 926 of file Engine.cpp.
References GetD3D12CommandQueueForSwapChain(), HYDRAHOOK_API, and HydraHookEngineGetD3D12CommandQueue().
| PHYDRAHOOK_ENGINE HydraHookEngineGetHandleFromD3D10SwapChain | ( | IDXGISwapChain * | SwapChain | ) |
Definition at line 874 of file Engine.cpp.
References g_EngineHostInstances, g_EngineHostInstancesLock, HYDRAHOOK_API, HydraHookEngineGetHandleFromD3D10SwapChain(), and LoadRenderPipelinePtr().
| PHYDRAHOOK_ENGINE HydraHookEngineGetHandleFromD3D9Device | ( | LPDIRECT3DDEVICE9 | Device | ) |
Definition at line 808 of file Engine.cpp.
References g_EngineHostInstances, g_EngineHostInstancesLock, HYDRAHOOK_API, HydraHookEngineGetHandleFromD3D9Device(), and LoadRenderPipelinePtr().
| PHYDRAHOOK_ENGINE HydraHookEngineGetHandleFromD3D9ExDevice | ( | LPDIRECT3DDEVICE9EX | Device | ) |
Definition at line 834 of file Engine.cpp.
References g_EngineHostInstances, g_EngineHostInstancesLock, HYDRAHOOK_API, HydraHookEngineGetHandleFromD3D9ExDevice(), and LoadRenderPipelinePtr().
| ID3D12CommandQueue * HydraHookEngineGetVerifiedD3D12CommandQueue | ( | IDXGISwapChain * | pSwapChain | ) |
Definition at line 931 of file Engine.cpp.
References GetD3D12CommandQueueForSwapChain(), HYDRAHOOK_API, and HydraHookEngineGetVerifiedD3D12CommandQueue().
| _Use_decl_annotations_ VOID HydraHookEngineLogDebug | ( | LPCSTR | Format, |
| ... ) |
Definition at line 1138 of file Engine.cpp.
References HYDRAHOOK_API, HydraHookEngineLogDebug(), and HydraHookEngineLogImpl().
| _Use_decl_annotations_ VOID HydraHookEngineLogError | ( | LPCSTR | Format, |
| ... ) |
Definition at line 1165 of file Engine.cpp.
References HYDRAHOOK_API, HydraHookEngineLogError(), and HydraHookEngineLogImpl().
|
static |
Format a printf-style message and emit it to the host logger at the specified level.
Formats the provided Format string with args into a stack buffer when it fits, then logs through the host-scoped logger. Disabled logging returns before taking a lock or formatting.
| level | Log severity level to use when emitting the message. |
| Format | printf-style format string describing the message. |
| args | Variadic argument list corresponding to Format. |
Definition at line 1104 of file Engine.cpp.
References GetHostLogger(), and HydraHookEngineLogImpl().
Referenced by HydraHookEngineLogDebug(), HydraHookEngineLogError(), HydraHookEngineLogImpl(), HydraHookEngineLogInfo(), and HydraHookEngineLogWarning().
| _Use_decl_annotations_ VOID HydraHookEngineLogInfo | ( | LPCSTR | Format, |
| ... ) |
Definition at line 1147 of file Engine.cpp.
References HYDRAHOOK_API, HydraHookEngineLogImpl(), and HydraHookEngineLogInfo().
| _Use_decl_annotations_ VOID HydraHookEngineLogWarning | ( | LPCSTR | Format, |
| ... ) |
Definition at line 1156 of file Engine.cpp.
References HYDRAHOOK_API, HydraHookEngineLogImpl(), and HydraHookEngineLogWarning().
| HYDRAHOOK_ERROR HydraHookEngineRehook | ( | PHYDRAHOOK_ENGINE | Engine | ) |
Definition at line 653 of file Engine.cpp.
References ClearRenderPipeline(), HookActivityTracker::drain(), HYDRAHOOK_API, HYDRAHOOK_ERROR_CREATE_THREAD_FAILED, HYDRAHOOK_ERROR_INVALID_ENGINE_HANDLE, HYDRAHOOK_ERROR_NONE, HYDRAHOOK_ERROR_UNHOOK_INCOMPLETE, HydraHookDirect3DVersionUnknown, HydraHookEngineRehook(), HydraHookIpcArmRehookWait(), HydraHookIpcDisarmRehookWait(), HydraHookIpcFlagRehookSupported, HydraHookIpcPhaseInCallback, HydraHookIpcPhaseInCallbackExternal, HydraHookIpcPublish(), HydraHookIpcShutdownOriginNone, HydraHookIpcStateInitializing, HydraHookIpcStateStopped, HydraHookMainThread(), and HookActivityTracker::reset().
| VOID HydraHookEngineSetARCEventCallbacks | ( | PHYDRAHOOK_ENGINE | Engine, |
| PHYDRAHOOK_ARC_EVENT_CALLBACKS | Callbacks ) |
Definition at line 949 of file Engine.cpp.
References HYDRAHOOK_API, and HydraHookEngineSetARCEventCallbacks().
| VOID HydraHookEngineSetD3D10EventCallbacks | ( | PHYDRAHOOK_ENGINE | Engine, |
| PHYDRAHOOK_D3D10_EVENT_CALLBACKS | Callbacks ) |
Definition at line 864 of file Engine.cpp.
References HYDRAHOOK_API, and HydraHookEngineSetD3D10EventCallbacks().
| VOID HydraHookEngineSetD3D11EventCallbacks | ( | PHYDRAHOOK_ENGINE | Engine, |
| PHYDRAHOOK_D3D11_EVENT_CALLBACKS | Callbacks ) |
Definition at line 902 of file Engine.cpp.
References HYDRAHOOK_API, and HydraHookEngineSetD3D11EventCallbacks().
| VOID HydraHookEngineSetD3D12EventCallbacks | ( | PHYDRAHOOK_ENGINE | Engine, |
| PHYDRAHOOK_D3D12_EVENT_CALLBACKS | Callbacks ) |
Definition at line 916 of file Engine.cpp.
References HYDRAHOOK_API, and HydraHookEngineSetD3D12EventCallbacks().
| VOID HydraHookEngineSetD3D9EventCallbacks | ( | PHYDRAHOOK_ENGINE | Engine, |
| PHYDRAHOOK_D3D9_EVENT_CALLBACKS | Callbacks ) |
Definition at line 798 of file Engine.cpp.
References HYDRAHOOK_API, and HydraHookEngineSetD3D9EventCallbacks().
| void HydraHookEngineSetLifecycleLockForTest | ( | PHYDRAHOOK_ENGINE | engine, |
| BOOL | acquire ) |
Definition at line 583 of file Engine.cpp.
References HydraHookEngineSetLifecycleLockForTest().
Referenced by HydraHookEngineSetLifecycleLockForTest().
| HYDRAHOOK_ERROR HydraHookEngineUnhook | ( | PHYDRAHOOK_ENGINE | Engine | ) |
Definition at line 593 of file Engine.cpp.
References ClearRenderPipeline(), HookActivityTracker::drain(), HYDRAHOOK_API, HYDRAHOOK_ERROR_INVALID_ENGINE_HANDLE, HYDRAHOOK_ERROR_NONE, HYDRAHOOK_ERROR_UNHOOK_INCOMPLETE, HydraHookDirect3DVersionUnknown, HydraHookEngineUnhook(), ManualUnhook, and PerformShutdownCleanup().
| 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().
| 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().
| 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().
|
static |
Definition at line 88 of file Engine.cpp.
Referenced by DestroyEngine().
|
static |
Definition at line 87 of file Engine.cpp.
Referenced by DestroyEngine(), HydraHookEngineCreate(), HydraHookEngineGetHandleFromD3D10SwapChain(), HydraHookEngineGetHandleFromD3D9Device(), and HydraHookEngineGetHandleFromD3D9ExDevice().
|
static |
Definition at line 86 of file Engine.cpp.
Referenced by DestroyEngine(), HydraHookEngineCreate(), HydraHookEngineGetHandleFromD3D10SwapChain(), HydraHookEngineGetHandleFromD3D9Device(), and HydraHookEngineGetHandleFromD3D9ExDevice().