|
HydraHook
Direct3D and Core Audio hooking library for Windows
|
#include <Windows.h>#include <Utils/Hook.h>#include "Game.h"#include "Shutdown.h"#include "Utils/Global.h"#include "Exceptions.hpp"#include "CrashHandler.h"#include <Game/Hook/Direct3D9.h>#include <Game/Hook/Direct3D9Ex.h>#include <Game/Hook/DXGI.h>#include <dxgi1_2.h>#include <dxgi1_4.h>#include <d3d12.h>#include <wrl/client.h>#include <Game/Hook/Direct3D10.h>#include <Game/Hook/Direct3D11.h>#include <Game/Hook/Direct3D12.h>#include <Game/Hook/AudioRenderClientHook.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 "Utils/SrwLock.h"#include <memory>#include <atomic>#include <cstdint>#include <cstring>#include <unordered_map>#include <vector>#include <spdlog/spdlog.h>Go to the source code of this file.
Classes | |
| struct | HookAnnouncements |
| Once-per-hook announcements; re-armed at the start of every worker run. More... | |
Macros | |
| #define | WIN32_LEAN_AND_MEAN |
Enumerations | |
| enum class | DxgiModuleStatus : std::uint32_t { Unknown = 0 , Unsupported = 1 , Supported = 2 } |
| enum class | DxgiRuntime { None , D3D10 , D3D11 , D3D12 } |
Functions | |
| static void | ResetDxgiModuleCache () noexcept |
| static void | RecordD3D12SwapChainQueue (IDXGISwapChain *chain, ID3D12CommandQueue *queue) |
| static void | D3D12_ReleaseQueueMaps () |
| static void | BindChannelLoggers () |
| static void | ClearChannelLoggers () |
| template<typename TDevice> | |
| bool | DispatchSwapChainDevice (IDXGISwapChain *chain, BOOL enabled) |
| True when this swap chain was created for TDevice and that API is enabled. | |
| DxgiRuntime | DetectDxgiRuntime (IDXGISwapChain *chain) |
| std::uint32_t | IpcShutdownOrigin (ShutdownOrigin origin) |
| void | PerformShutdownCleanup (PHYDRAHOOK_ENGINE engine, ShutdownOrigin origin) |
| Performs pre-exit cleanup based on shutdown origin. | |
| DWORD | HydraHookMainThread (LPVOID Params) |
| Main hook worker thread; probes and hooks render and audio APIs. | |
| ID3D12CommandQueue * | GetUniformD3D12PresentQueue (UINT bufferCount, IUnknown *const *presentQueues) |
| ID3D12CommandQueue * | GetD3D12CommandQueueForSwapChain (IDXGISwapChain *pSwapChain, bool requireVerifiedQueue) |
| Returns the D3D12 command queue associated with a swap chain. | |
Variables | |
| static SRWLOCK | g_d3d12QueueMapLock = SRWLOCK_INIT |
| static std::unordered_map< IDXGISwapChain *, ID3D12CommandQueue * > | g_d3d12SwapChainToQueue |
| static std::unordered_map< ID3D12Device *, ID3D12CommandQueue * > | g_d3d12DeviceToQueue |
| Runtime capture: device -> queue (for mid-process injection when CreateSwapChain already ran). | |
| static std::atomic< ID3D12CommandQueue * > | g_lastObservedDirectQueue {nullptr} |
| static std::atomic< std::uint32_t > | g_dxgiModuleStatus {static_cast<std::uint32_t>(DxgiModuleStatus::Unknown)} |
| static std::atomic< const BYTE * > | g_dxgiModuleImage {nullptr} |
| static Hook< CallConvention::stdcall_t, VOID, UINT > | g_exitProcessHook |
| static Hook< CallConvention::stdcall_t, void, int > | g_postQuitMessageHook |
| static Hook< CallConvention::stdcall_t, BOOL, HMODULE > | g_freeLibraryHook |
| static std::atomic< HMODULE > | g_freeLibraryTarget {nullptr} |
| static std::atomic< HMODULE > | g_freeLibraryHost {nullptr} |
| static PHYDRAHOOK_ENGINE | engine = nullptr |
| static struct HookAnnouncements | g_announce |
| static std::shared_ptr< spdlog::logger > | g_logGame |
| static std::shared_ptr< spdlog::logger > | g_logD3D9 |
| static std::shared_ptr< spdlog::logger > | g_logD3D10 |
| static std::shared_ptr< spdlog::logger > | g_logD3D11 |
| static std::shared_ptr< spdlog::logger > | g_logD3D12 |
| static std::shared_ptr< spdlog::logger > | g_logArc |
|
strong |
|
strong |
|
static |
Definition at line 195 of file Game.cpp.
References BindChannelLoggers(), g_logArc, g_logD3D10, g_logD3D11, g_logD3D12, g_logD3D9, and g_logGame.
Referenced by BindChannelLoggers(), and HydraHookMainThread().
|
static |
Definition at line 208 of file Game.cpp.
References ClearChannelLoggers(), g_logArc, g_logD3D10, g_logD3D11, g_logD3D12, g_logD3D9, and g_logGame.
Referenced by ClearChannelLoggers().
|
static |
Definition at line 126 of file Game.cpp.
References D3D12_ReleaseQueueMaps(), g_d3d12DeviceToQueue, g_d3d12QueueMapLock, g_d3d12SwapChainToQueue, g_lastObservedDirectQueue, and ResetDxgiModuleCache().
Referenced by D3D12_ReleaseQueueMaps().
| DxgiRuntime DetectDxgiRuntime | ( | IDXGISwapChain * | chain | ) |
Definition at line 241 of file Game.cpp.
References D3D10, D3D11, D3D12, DetectDxgiRuntime(), DispatchSwapChainDevice(), engine, HydraHookDirect3DVersion10, HydraHookDirect3DVersion11, HydraHookDirect3DVersion12, HydraHookDirect3DVersionUnknown, and None.
Referenced by DetectDxgiRuntime().
| bool DispatchSwapChainDevice | ( | IDXGISwapChain * | chain, |
| BOOL | enabled ) |
True when this swap chain was created for TDevice and that API is enabled.
Definition at line 220 of file Game.cpp.
References DispatchSwapChainDevice().
Referenced by DetectDxgiRuntime(), and DispatchSwapChainDevice().
| ID3D12CommandQueue * GetD3D12CommandQueueForSwapChain | ( | IDXGISwapChain * | pSwapChain, |
| bool | requireVerifiedQueue = false ) |
Returns the D3D12 command queue associated with a swap chain.
Checks the recorded association, then the current back buffer's queue on a supported DXGI build, then the device map filled by the ExecuteCommandLists hook.
| pSwapChain | The swap chain to query. May be null. |
| requireVerifiedQueue | Only accept an exact association for the current back buffer. |
pSwapChain is null. Definition at line 2188 of file Game.cpp.
References g_d3d12DeviceToQueue, g_d3d12QueueMapLock, g_d3d12SwapChainToQueue, and GetD3D12CommandQueueForSwapChain().
Referenced by GetD3D12CommandQueueForSwapChain(), HydraHookEngineGetD3D12CommandQueue(), and HydraHookEngineGetVerifiedD3D12CommandQueue().
| ID3D12CommandQueue * GetUniformD3D12PresentQueue | ( | UINT | bufferCount, |
| IUnknown *const * | presentQueues ) |
Definition at line 2077 of file Game.cpp.
References GetUniformD3D12PresentQueue().
Referenced by GetUniformD3D12PresentQueue().
| DWORD HydraHookMainThread | ( | LPVOID | Params | ) |
Main hook worker thread; probes and hooks render and audio APIs.
Installs the configured hooks, waits for cancellation, then uninstalls them. The worker does not own the unload. When the host calls FreeLibrary, that hook runs cleanup and its caller exits with FreeLibraryAndExitThread, while the worker exits with ExitThread. On any other shutdown the worker exits with FreeLibraryAndExitThread after cleanup.
| Params | PHYDRAHOOK_ENGINE cast to LPVOID. |
Definition at line 451 of file Game.cpp.
References Hook< cc, retn, args >::apply(), BindChannelLoggers(), ResettableOnce::call(), Hook< cc, retn, args >::call_orig(), Direct3D9Hooking::EndScene, HookAnnouncements::endScene9, engine, ExitProcessHook, g_announce, g_exitProcessHook, g_freeLibraryHook, g_freeLibraryHost, g_freeLibraryTarget, g_logD3D9, g_logGame, g_postQuitMessageHook, HYDRAHOOK_ERROR_NONE, HydraHookCrashHandlerInstallThreadSEH(), HydraHookDirect3DVersion9, HydraHookEngineDestroyBeforeUnload(), HydraHookLoggingEnableAsync(), HydraHookMainThread(), HookActivityTracker::Guard::invoke, INVOKE_D3D9_CALLBACK, INVOKE_HYDRAHOOK_GAME_HOOKED, PerformShutdownCleanup(), PostQuitMessageHook, Direct3D9Hooking::Present, HookAnnouncements::present9, Direct3D9Hooking::PresentEx, HydraHook::Core::Util::process_name(), Direct3D9Hooking::Reset, HookAnnouncements::reset9, HookAnnouncements::reset9Ex, HookAnnouncements::reset_all(), ResetDxgiModuleCache(), Direct3D9Hooking::ResetEx, stdcall_t, and StoreRenderPipelinePtr().
Referenced by HydraHookEngineCreate(), HydraHookEngineRehook(), and HydraHookMainThread().
| std::uint32_t IpcShutdownOrigin | ( | ShutdownOrigin | origin | ) |
Definition at line 296 of file Game.cpp.
References DllMainProcessDetach, ExitProcessHook, FreeLibraryHook, HydraHookIpcShutdownOriginDllMainDetach, HydraHookIpcShutdownOriginExitProcess, HydraHookIpcShutdownOriginFreeLibrary, HydraHookIpcShutdownOriginManualUnhook, HydraHookIpcShutdownOriginNone, HydraHookIpcShutdownOriginPostQuitMessage, IpcShutdownOrigin(), ManualUnhook, and PostQuitMessageHook.
Referenced by IpcShutdownOrigin(), and PerformShutdownCleanup().
| void PerformShutdownCleanup | ( | PHYDRAHOOK_ENGINE | engine, |
| ShutdownOrigin | origin ) |
Performs pre-exit cleanup based on shutdown origin.
For ExitProcessHook and PostQuitMessageHook: removes the other hook, invokes EvtHydraHookGamePreExit, signals the engine thread, and waits for it to finish. For FreeLibraryHook: removes ExitProcess and PostQuitMessage hooks, invokes EvtHydraHookGamePreExit, signals and waits. For DllMainProcessDetach: skips user callbacks and uses remove_nothrow (loader lock); optionally signals and does a brief wait. For ManualUnhook (HydraHookEngineUnhook): skips EvtHydraHookGamePreExit, signals the worker, which removes every hook itself and exits without unloading the DLL, and waits for it.
| engine | Engine instance to clean up. |
| origin | Shutdown origin for decision making. |
Definition at line 315 of file Game.cpp.
References DllMainProcessDetach, engine, ExitProcessHook, FreeLibraryHook, g_exitProcessHook, g_freeLibraryHook, g_postQuitMessageHook, HydraHookCloneRegisteredLogger(), HydraHookIpcPublish(), HydraHookIpcStateShuttingDown, IpcShutdownOrigin(), ManualUnhook, PerformShutdownCleanup(), and PostQuitMessageHook.
Referenced by DestroyEngine(), HydraHookEngineUnhook(), HydraHookMainThread(), and PerformShutdownCleanup().
|
static |
Definition at line 106 of file Game.cpp.
References g_d3d12QueueMapLock, g_d3d12SwapChainToQueue, and RecordD3D12SwapChainQueue().
Referenced by RecordD3D12SwapChainQueue().
|
staticnoexcept |
Definition at line 100 of file Game.cpp.
References g_dxgiModuleImage, g_dxgiModuleStatus, ResetDxgiModuleCache(), and Unknown.
Referenced by D3D12_ReleaseQueueMaps(), HydraHookMainThread(), and ResetDxgiModuleCache().
|
static |
Definition at line 165 of file Game.cpp.
Referenced by DetectDxgiRuntime(), HydraHookMainThread(), and PerformShutdownCleanup().
|
static |
Referenced by HydraHookMainThread().
|
static |
Runtime capture: device -> queue (for mid-process injection when CreateSwapChain already ran).
Definition at line 88 of file Game.cpp.
Referenced by D3D12_ReleaseQueueMaps(), and GetD3D12CommandQueueForSwapChain().
|
static |
Definition at line 85 of file Game.cpp.
Referenced by D3D12_ReleaseQueueMaps(), GetD3D12CommandQueueForSwapChain(), and RecordD3D12SwapChainQueue().
|
static |
Definition at line 86 of file Game.cpp.
Referenced by D3D12_ReleaseQueueMaps(), GetD3D12CommandQueueForSwapChain(), and RecordD3D12SwapChainQueue().
|
static |
Definition at line 98 of file Game.cpp.
Referenced by ResetDxgiModuleCache().
|
static |
Definition at line 97 of file Game.cpp.
Referenced by ResetDxgiModuleCache().
|
static |
Definition at line 155 of file Game.cpp.
Referenced by HydraHookMainThread(), and PerformShutdownCleanup().
|
static |
Definition at line 157 of file Game.cpp.
Referenced by HydraHookMainThread(), and PerformShutdownCleanup().
|
static |
Definition at line 159 of file Game.cpp.
Referenced by HydraHookMainThread().
|
static |
Definition at line 158 of file Game.cpp.
Referenced by HydraHookMainThread().
|
static |
Definition at line 89 of file Game.cpp.
Referenced by D3D12_ReleaseQueueMaps().
|
static |
Definition at line 193 of file Game.cpp.
Referenced by BindChannelLoggers(), and ClearChannelLoggers().
|
static |
Definition at line 190 of file Game.cpp.
Referenced by BindChannelLoggers(), and ClearChannelLoggers().
|
static |
Definition at line 191 of file Game.cpp.
Referenced by BindChannelLoggers(), and ClearChannelLoggers().
|
static |
Definition at line 192 of file Game.cpp.
Referenced by BindChannelLoggers(), and ClearChannelLoggers().
|
static |
Definition at line 189 of file Game.cpp.
Referenced by BindChannelLoggers(), ClearChannelLoggers(), and HydraHookMainThread().
|
static |
Definition at line 188 of file Game.cpp.
Referenced by BindChannelLoggers(), ClearChannelLoggers(), and HydraHookMainThread().
|
static |
Definition at line 156 of file Game.cpp.
Referenced by HydraHookMainThread(), and PerformShutdownCleanup().