36#define WIN32_LEAN_AND_MEAN
64#include <spdlog/spdlog.h>
65#include <spdlog/async.h>
66#include <spdlog/async_logger.h>
67#include <spdlog/sinks/basic_file_sink.h>
68#include <spdlog/sinks/null_sink.h>
69#include <spdlog/sinks/stdout_color_sinks.h>
92 SRWLOCK g_hostLoggerLock = SRWLOCK_INIT;
93 std::shared_ptr<spdlog::logger> g_hostLogger;
94 std::shared_ptr<spdlog::logger> g_installedDefaultLogger;
95 std::shared_ptr<spdlog::logger> g_syncLogger;
96 std::shared_ptr<spdlog::details::thread_pool> g_logThreadPool;
97 std::atomic<bool> g_hostLoggingEnabled{
false};
98 std::atomic<int> g_hostLogLevel{
static_cast<int>(spdlog::level::off)};
99 std::atomic<bool> g_asyncLoggingActive{
false};
101 void ResetHostLogger()
104 g_hostLogger.reset();
107 void RememberInstalledDefaultLogger(
const std::shared_ptr<spdlog::logger>& logger)
110 g_installedDefaultLogger = logger;
113 std::shared_ptr<spdlog::logger> TakeInstalledDefaultLogger()
116 auto installed = g_installedDefaultLogger;
117 g_installedDefaultLogger.reset();
125 if (kv.first == host)
131 void EraseHostEngineUnlocked(HMODULE host)
135 [host](
const auto& kv) { return kv.first == host; }),
139 HYDRAHOOK_ERROR RetainEngine(
const std::shared_ptr<spdlog::logger>& logger,
const char* reason)
143 if (logger && !std::dynamic_pointer_cast<spdlog::async_logger>(logger))
144 logger->warn(
"{}", reason);
153 HMODULE module =
nullptr;
154 return GetModuleHandleExW(
155 GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_PIN,
172 const SIZE_T configSize = EngineConfig->Size;
173 if (configSize < minimumConfigSize)
178 if (FindHostEngineUnlocked(HostInstance))
183 if (!GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
184 reinterpret_cast<LPCTSTR
>(HostInstance),
198 engine->DllModule = hMod;
200 auto& config = engine->EngineConfig;
202 const SIZE_T copySize = configSize <
sizeof(config) ? configSize :
sizeof(config);
203 CopyMemory(&config, EngineConfig, copySize);
204 config.Size = copySize;
210 auto logger = spdlog::get(
"HYDRAHOOK");
213 if (!config.Logging.IsEnabled)
217 logger = std::make_shared<spdlog::logger>(
219 std::make_shared<spdlog::sinks::null_sink_mt>());
220 spdlog::register_logger(logger);
222 catch (
const std::exception&)
232 const char* configuredPath = config.Logging.FilePath;
233 const std::string tempPath = configuredPath
237 auto tryCreateLogger = [](
const std::string& path) ->
bool
243 (void)spdlog::basic_logger_mt(
"HYDRAHOOK", path);
246 catch (
const std::exception&)
252 if (!processDir.empty() && tryCreateLogger(processDir +
"HydraHook.log"))
256 else if (!dllDir.empty() && tryCreateLogger(dllDir +
"HydraHook.log"))
260 else if (!tempPath.empty())
262 tryCreateLogger(tempPath);
265 logger = spdlog::get(
"HYDRAHOOK");
270 logger = spdlog::stdout_color_mt(
"HYDRAHOOK");
272 catch (
const std::exception&)
281 if (!config.Logging.IsEnabled)
283 logger->set_level(spdlog::level::off);
284 g_hostLoggingEnabled.store(
false, std::memory_order_release);
285 g_hostLogLevel.store(
static_cast<int>(spdlog::level::off), std::memory_order_release);
290 spdlog::set_level(spdlog::level::debug);
291 logger->set_level(spdlog::level::debug);
292 logger->flush_on(spdlog::level::debug);
293 g_hostLogLevel.store(
static_cast<int>(spdlog::level::debug), std::memory_order_release);
295 logger->set_level(spdlog::level::info);
296 logger->flush_on(spdlog::level::info);
297 g_hostLogLevel.store(
static_cast<int>(spdlog::level::info), std::memory_order_release);
299 g_hostLoggingEnabled.store(
true, std::memory_order_release);
300 spdlog::set_default_logger(logger);
301 RememberInstalledDefaultLogger(logger);
306 g_syncLogger = spdlog::get(
"HYDRAHOOK");
309 logger = logger->clone(
"api");
314 if (config.CrashHandler.IsEnabled)
322 engine->EngineCancellationEvent = CreateEvent(
329 if (engine->EngineCancellationEvent ==
nullptr)
331 logger->error(
"Failed to create the Engine Cancellation Event: {}", GetLastError());
332 if (engine->CrashHandlerInstalled)
335 engine->CrashHandlerInstalled = FALSE;
344 logger->info(
"HydraHook engine initialized, attempting to launch main thread");
351 engine->EngineThread = CreateThread(
360 if (!engine->EngineThread)
362 logger->error(
"Could not create main thread, library unusable");
363 if (engine->CrashHandlerInstalled)
366 engine->CrashHandlerInstalled = FALSE;
368 CloseHandle(engine->EngineCancellationEvent);
378 if (FindHostEngineUnlocked(HostInstance))
383 if (ResumeThread(engine->EngineThread) ==
static_cast<DWORD
>(-1))
385 EraseHostEngineUnlocked(HostInstance);
393 TerminateThread(engine->EngineThread, 0);
394 if (engine->CrashHandlerInstalled)
396 CloseHandle(engine->EngineCancellationEvent);
397 CloseHandle(engine->EngineThread);
404 logger->info(
"Main thread created successfully");
416 const bool explicitUnload = detachFreeLibraryHook !=
nullptr;
417 const auto incomplete = [explicitUnload](
const std::shared_ptr<spdlog::logger>& logger,
const char* reason)
427 return incomplete(logger,
"Engine kept alive; another destroy is running");
433 return incomplete(logger,
"Engine kept alive; host map lock is busy");
434 engine = FindHostEngineUnlocked(HostInstance);
444 return incomplete(logger,
"Engine kept alive; lifecycle lock is busy");
447 engine->RehookDisabled.store(
true, std::memory_order_release);
448 engine->FreeLibraryHookActive.store(
true, std::memory_order_release);
463 return incomplete(logger,
"Engine kept alive; lifecycle lock is busy");
465 const bool onWorker = engine->EngineThread !=
nullptr
466 && GetThreadId(engine->EngineThread) == GetCurrentThreadId();
467 bool workerExited = engine->EngineThread ==
nullptr;
468 if (!workerExited && !onWorker)
469 workerExited = WaitForSingleObject(engine->EngineThread, 0) == WAIT_OBJECT_0;
471 return incomplete(logger,
"Engine kept alive; worker is still running");
479 return incomplete(logger,
"Engine kept alive; hook callbacks are still running");
486 return incomplete(logger,
"Engine kept alive; lifecycle lock is busy");
489 return incomplete(logger,
"Engine kept alive; rehook callback is running");
491 if (engine->EngineThread !=
nullptr
492 && WaitForSingleObject(engine->EngineThread, 0) != WAIT_OBJECT_0)
493 return incomplete(logger,
"Engine kept alive; worker is still running");
496 bool lastEngine =
false;
500 return incomplete(logger,
"Engine kept alive; host map lock is busy");
502 if (explicitUnload && !detachFreeLibraryHook())
504 EraseHostEngineUnlocked(HostInstance);
510 logger->info(
"Freeing remaining resources");
512 if (PVOID ctx = engine->CustomContext.exchange(
nullptr, std::memory_order_acq_rel))
517 if (engine->CrashHandlerInstalled)
520 engine->CrashHandlerInstalled = FALSE;
525 if (engine->EngineCancellationEvent)
527 CloseHandle(engine->EngineCancellationEvent);
529 if (engine->EngineThread)
531 CloseHandle(engine->EngineThread);
536 logger->info(
"Engine shutdown complete");
553 const auto installedDefault = TakeInstalledDefaultLogger();
554 if (installedDefault && spdlog::default_logger() == installedDefault)
556 spdlog::set_default_logger(std::make_shared<spdlog::logger>(
558 std::make_shared<spdlog::sinks::null_sink_mt>()));
560 spdlog::drop(
"HYDRAHOOK");
561 g_hostLoggingEnabled.store(
false, std::memory_order_release);
562 g_hostLogLevel.store(
static_cast<int>(spdlog::level::off), std::memory_order_release);
588 AcquireSRWLockExclusive(&engine->LifecycleLock);
590 ReleaseSRWLockExclusive(&engine->LifecycleLock);
602 if (!Engine->EngineThread)
608 if (GetThreadId(Engine->EngineThread) == GetCurrentThreadId())
614 Engine->SkipDllUnloadOnExit.store(
true, std::memory_order_release);
621 if (WaitForSingleObject(Engine->EngineThread, 8000) != WAIT_OBJECT_0)
628 if (Engine->DrainIncomplete.load(std::memory_order_acquire))
635 ZeroMemory(&Engine->EventsD3D9,
sizeof(Engine->EventsD3D9));
636 ZeroMemory(&Engine->EventsD3D10,
sizeof(Engine->EventsD3D10));
637 ZeroMemory(&Engine->EventsD3D11,
sizeof(Engine->EventsD3D11));
638 ZeroMemory(&Engine->EventsD3D12,
sizeof(Engine->EventsD3D12));
639 ZeroMemory(&Engine->EventsARC,
sizeof(Engine->EventsARC));
640 Engine->DrainIncomplete.store(
false, std::memory_order_release);
643 CloseHandle(Engine->EngineThread);
644 Engine->EngineThread =
nullptr;
647 ZeroMemory(&Engine->CoreAudio,
sizeof(Engine->CoreAudio));
663 if (Engine->RehookDisabled.load(std::memory_order_acquire))
666 if (Engine->EngineThread)
668 if (WaitForSingleObject(Engine->EngineThread, 0) == WAIT_TIMEOUT)
673 if (Engine->DrainIncomplete.load(std::memory_order_acquire)
679 CloseHandle(Engine->EngineThread);
680 Engine->EngineThread =
nullptr;
683 Engine->DrainIncomplete.store(
false, std::memory_order_release);
686 Engine->ShutdownCleanupDone.store(
false);
687 Engine->FreeLibraryHookActive.store(
false);
688 Engine->SkipDllUnloadOnExit.store(
false);
689 ResetEvent(Engine->EngineCancellationEvent);
691 Engine->EventsD3D9 = Engine->SavedEventsD3D9;
692 Engine->EventsD3D10 = Engine->SavedEventsD3D10;
693 Engine->EventsD3D11 = Engine->SavedEventsD3D11;
694 Engine->EventsD3D12 = Engine->SavedEventsD3D12;
695 Engine->EventsARC = Engine->SavedEventsARC;
698 ZeroMemory(&Engine->CoreAudio,
sizeof(Engine->CoreAudio));
701 Engine->IpcGeneration.fetch_add(1, std::memory_order_acq_rel);
704 Engine->EngineThread = CreateThread(
713 if (!Engine->EngineThread)
715 Engine->ShutdownCleanupDone.store(
true);
716 const std::uint32_t flags = Engine->RehookDisabled.load(std::memory_order_acquire) || !Engine->RehookWait
722 const std::int32_t phase = Engine->RehookWaitPhase.load(std::memory_order_acquire);
736 if (!Engine || !Context)
741 if (Engine->CustomContext.load(std::memory_order_acquire))
746 void* block = malloc(ContextSize);
754 ZeroMemory(block, ContextSize);
755 Engine->CustomContext.store(block, std::memory_order_release);
768 if (PVOID ctx = Engine->CustomContext.exchange(
nullptr, std::memory_order_acq_rel))
783 return Engine->CustomContext.load(std::memory_order_acquire);
793 return Engine->DrainIncomplete.load(std::memory_order_acquire) ? FALSE : TRUE;
796#ifndef HYDRAHOOK_NO_D3D9
801 if (Engine && Callbacks)
803 Engine->EventsD3D9 = *Callbacks;
804 Engine->SavedEventsD3D9 = *Callbacks;
810 if (Device ==
nullptr)
818 const auto& engine = kv.second;
836 if (Device ==
nullptr)
844 const auto& engine = kv.second;
862#ifndef HYDRAHOOK_NO_D3D10
867 if (Engine && Callbacks)
869 Engine->EventsD3D10 = *Callbacks;
870 Engine->SavedEventsD3D10 = *Callbacks;
876 if (SwapChain ==
nullptr)
882 const auto& engine = kv.second;
900#ifndef HYDRAHOOK_NO_D3D11
905 if (Engine && Callbacks)
907 Engine->EventsD3D11 = *Callbacks;
908 Engine->SavedEventsD3D11 = *Callbacks;
914#ifndef HYDRAHOOK_NO_D3D12
919 if (Engine && Callbacks)
921 Engine->EventsD3D12 = *Callbacks;
922 Engine->SavedEventsD3D12 = *Callbacks;
939 if (!resize || resize != Extension)
947#ifndef HYDRAHOOK_NO_COREAUDIO
952 if (Engine && Callbacks)
954 Engine->EventsARC = *Callbacks;
955 Engine->SavedEventsARC = *Callbacks;
963 if (!g_hostLoggingEnabled.load(std::memory_order_acquire))
967 if (g_asyncLoggingActive.load(std::memory_order_acquire))
970 auto sync = spdlog::get(
"HYDRAHOOK");
971 if (!sync || std::dynamic_pointer_cast<spdlog::async_logger>(sync))
976 auto pool = std::make_shared<spdlog::details::thread_pool>(4096, 1);
977 auto asyncLogger = std::make_shared<spdlog::async_logger>(
979 sync->sinks().begin(),
982 spdlog::async_overflow_policy::overrun_oldest);
983 asyncLogger->set_level(sync->level());
985 asyncLogger->flush_on(spdlog::level::debug);
987 asyncLogger->flush_on(spdlog::level::info);
989 const bool wasDefault = spdlog::default_logger() == sync;
990 spdlog::drop(
"HYDRAHOOK");
991 spdlog::register_logger(asyncLogger);
994 spdlog::set_default_logger(asyncLogger);
995 g_installedDefaultLogger = asyncLogger;
999 g_logThreadPool = std::move(pool);
1000 g_hostLogger.reset();
1001 g_asyncLoggingActive.store(
true, std::memory_order_release);
1003 catch (
const std::exception&)
1007 if (!spdlog::get(
"HYDRAHOOK"))
1008 spdlog::register_logger(sync);
1010 catch (
const std::exception&)
1018 std::shared_ptr<spdlog::logger> asyncLogger;
1019 std::shared_ptr<spdlog::logger> sync;
1020 std::shared_ptr<spdlog::details::thread_pool> pool;
1023 if (!g_asyncLoggingActive.load(std::memory_order_acquire))
1025 asyncLogger = spdlog::get(
"HYDRAHOOK");
1026 sync = g_syncLogger;
1027 g_syncLogger.reset();
1028 pool = std::move(g_logThreadPool);
1029 g_hostLogger.reset();
1030 g_asyncLoggingActive.store(
false, std::memory_order_release);
1034 asyncLogger->flush();
1039 const bool wasDefault = asyncLogger && spdlog::default_logger() == asyncLogger;
1040 spdlog::drop(
"HYDRAHOOK");
1043 spdlog::register_logger(sync);
1046 spdlog::set_default_logger(sync);
1047 g_installedDefaultLogger = sync;
1050 catch (
const std::exception&)
1053 g_hostLogger.reset();
1062 auto base = spdlog::get(
"HYDRAHOOK");
1065 return channel ? base->clone(channel) : base;
1081 return g_hostLogger;
1086 return g_hostLogger;
1087 auto base = spdlog::get(
"HYDRAHOOK");
1090 g_hostLogger = base->clone(
"host");
1091 return g_hostLogger;
1106 if (!g_hostLoggingEnabled.load(std::memory_order_relaxed))
1108 if (
static_cast<int>(level) < g_hostLogLevel.load(std::memory_order_relaxed))
1114 if (!logger || !logger->should_log(level))
1119 va_copy(copy, args);
1120 const int needed = vsnprintf(stack,
sizeof(stack), Format, copy);
1125 if (
static_cast<size_t>(needed) <
sizeof(stack))
1127 logger->log(level, std::string_view(stack,
static_cast<size_t>(needed)));
1131 std::string message(
static_cast<size_t>(needed) + 1,
'\0');
1132 vsnprintf(message.data(), message.size(), Format, args);
1133 message.resize(
static_cast<size_t>(needed));
1134 logger->log(level, message);
1137_Use_decl_annotations_
1141 va_start(args, Format);
1146_Use_decl_annotations_
1150 va_start(args, Format);
1155_Use_decl_annotations_
1159 va_start(args, Format);
1164_Use_decl_annotations_
1168 va_start(args, Format);
bool HydraHookCrashHandlerInstall(PHYDRAHOOK_ENGINE engine)
Installs global crash handlers (ref-counted) for the given engine.
bool HydraHookCrashHandlerReferencesEngine(PHYDRAHOOK_ENGINE engine)
True when a published or deferred snapshot still names this engine. Destroy must not free the engine ...
void HydraHookCrashHandlerUninstall(PHYDRAHOOK_ENGINE engine)
Decrements the crash handler reference count.
Internal crash handler installation and teardown.
HYDRAHOOK_ERROR HydraHookEngineDestroyBeforeUnload(HMODULE host, bool(*detachFreeLibraryHook)() noexcept)
Tears down the registered engine before explicit unload. Busy failures keep the hook installed.
static SRWLOCK g_engineDestroyLock
void HydraHookLoggingEnableAsync()
Swaps the process logger to a HydraHook-owned async pool. Call from the worker, not DllMain.
static std::shared_ptr< spdlog::logger > GetHostLogger()
Returns a cached host-scoped logger clone for the process-wide "HYDRAHOOK" logger.
static SRWLOCK g_EngineHostInstancesLock
void HydraHookEngineSetLifecycleLockForTest(PHYDRAHOOK_ENGINE engine, BOOL acquire)
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.
static std::vector< std::pair< HMODULE, PHYDRAHOOK_ENGINE > > g_EngineHostInstances
static HYDRAHOOK_ERROR DestroyEngine(HMODULE HostInstance, bool(*detachFreeLibraryHook)() noexcept)
bool HydraHookPinWorkerModule()
Pins the module that contains this engine for the rest of the process.
std::shared_ptr< spdlog::logger > HydraHookCloneRegisteredLogger(const char *channel)
Clones the registered HYDRAHOOK logger; replacement cannot drop it during this call....
void HydraHookLoggingDisableAsync()
Flushes, restores the sync logger, and joins the async pool. Call from the worker,...
HYDRAHOOK_D3D_VERSION HydraHookEngineGameVersionForTest(PHYDRAHOOK_ENGINE engine)
Internal engine structure and callback invocation macros.
T * LoadRenderPipelinePtr(const std::atomic< T * > &slot)
void ClearRenderPipeline(Pipeline &pipeline)
Resets every RenderPipeline pointer atomically, so concurrent lookups never see a torn value.
void HydraHookIpcDisarmRehookWait(PHYDRAHOOK_ENGINE engine)
void HydraHookIpcArmRehookWait(PHYDRAHOOK_ENGINE engine)
void HydraHookIpcClose(PHYDRAHOOK_ENGINE engine)
Closes IPC objects. The caller guarantees no rehook callback is running.
void HydraHookIpcPublish(PHYDRAHOOK_ENGINE engine, std::uint32_t state, std::uint32_t origin, std::uint32_t gameVersion, std::uint32_t flags)
bool HydraHookIpcAbandonRehookWait(PHYDRAHOOK_ENGINE engine)
Cancels a pending rehook wait so the engine can be freed.
void HydraHookIpcCreate(PHYDRAHOOK_ENGINE engine)
constexpr std::int32_t HydraHookIpcPhaseInCallbackExternal
constexpr std::uint32_t HydraHookIpcFlagRehookSupported
constexpr std::uint32_t HydraHookIpcStateStopped
constexpr std::uint32_t HydraHookIpcStateInitializing
constexpr std::uint32_t HydraHookIpcShutdownOriginNone
constexpr std::int32_t HydraHookIpcPhaseInCallback
void PerformShutdownCleanup(PHYDRAHOOK_ENGINE engine, ShutdownOrigin origin)
Performs pre-exit cleanup based on shutdown origin.
ID3D12CommandQueue * GetD3D12CommandQueueForSwapChain(IDXGISwapChain *pSwapChain, bool requireVerifiedQueue)
Returns the D3D12 command queue associated with a swap chain.
DWORD HydraHookMainThread(LPVOID Params)
Main hook worker thread; probes and hooks render and audio APIs.
Main hook worker thread entry point.
Utility functions for environment expansion and process info.
C++ wrapper for Microsoft Detours function hooking.
bool g_hookDestructorDetachSuppressed
When set, ~Hook() does not detach.
Core engine API for HydraHook - Direct3D and Core Audio hooking library.
HYDRAHOOK_ERROR HydraHookEngineRehook(_In_ PHYDRAHOOK_ENGINE Engine)
Reinstalls hooks on an engine previously stopped with HydraHookEngineUnhook.
struct _HYDRAHOOK_D3D11_EVENT_CALLBACKS * PHYDRAHOOK_D3D11_EVENT_CALLBACKS
VOID HydraHookEngineSetD3D11EventCallbacks(_In_ PHYDRAHOOK_ENGINE Engine, _In_ PHYDRAHOOK_D3D11_EVENT_CALLBACKS Callbacks)
Registers Direct3D 11 render pipeline callbacks.
struct _HYDRAHOOK_D3D12_EVENT_CALLBACKS * PHYDRAHOOK_D3D12_EVENT_CALLBACKS
HYDRAHOOK_D3D_VERSION
Bitmask of detected Direct3D API versions.
@ HydraHookDirect3DVersionUnknown
BOOL HydraHookEngineAreCallbacksDrained(_In_ PHYDRAHOOK_ENGINE Engine)
Reports whether all in-flight render callbacks were confirmed finished by the last unhook.
VOID HydraHookEngineLogError(_In_ LPCSTR Format, _In_opt_ ...)
Logs an error message (printf-style format).
VOID HydraHookEngineLogWarning(_In_ LPCSTR Format, _In_opt_ ...)
Logs a warning message (printf-style format).
HYDRAHOOK_ERROR
Error codes returned by HydraHook engine functions.
@ HYDRAHOOK_ERROR_CONTEXT_ALLOCATION_FAILED
@ HYDRAHOOK_ERROR_INVALID_ENGINE_HANDLE
@ HYDRAHOOK_ERROR_ENGINE_ALREADY_ALLOCATED
@ HYDRAHOOK_ERROR_ENGINE_ALLOCATION_FAILED
@ HYDRAHOOK_ERROR_INVALID_ENGINE_CONFIG
@ HYDRAHOOK_ERROR_CREATE_THREAD_FAILED
@ HYDRAHOOK_ERROR_CREATE_EVENT_FAILED
@ HYDRAHOOK_ERROR_UNHOOK_INCOMPLETE
@ HYDRAHOOK_ERROR_INVALID_HMODULE_HANDLE
@ HYDRAHOOK_ERROR_CREATE_LOGGER_FAILED
@ HYDRAHOOK_ERROR_GET_MODULE_HANDLE_FAILED
HYDRAHOOK_ERROR HydraHookEngineDestroy(_In_ HMODULE HostInstance)
Destroys the engine and frees all resources.
HYDRAHOOK_ERROR HydraHookEngineAllocCustomContext(_In_ PHYDRAHOOK_ENGINE Engine, _Out_ PVOID *Context, _In_ size_t ContextSize)
Allocates custom context memory accessible from all event callbacks.
struct _HYDRAHOOK_D3D10_EVENT_CALLBACKS * PHYDRAHOOK_D3D10_EVENT_CALLBACKS
PVOID HydraHookEngineGetCustomContext(_In_ PHYDRAHOOK_ENGINE Engine)
Returns pointer to custom context memory, or NULL if none allocated.
VOID HydraHookEngineSetD3D9EventCallbacks(_In_ PHYDRAHOOK_ENGINE Engine, _In_ PHYDRAHOOK_D3D9_EVENT_CALLBACKS Callbacks)
Registers Direct3D 9/9Ex render pipeline callbacks.
VOID HYDRAHOOK_ENGINE_CONFIG_INIT(PHYDRAHOOK_ENGINE_CONFIG EngineConfig)
struct _HYDRAHOOK_D3D9_EVENT_CALLBACKS * PHYDRAHOOK_D3D9_EVENT_CALLBACKS
VOID HydraHookEngineLogDebug(_In_ LPCSTR Format, _In_opt_ ...)
Logs a debug message (printf-style format).
HYDRAHOOK_ERROR HydraHookEngineFreeCustomContext(_In_ PHYDRAHOOK_ENGINE Engine)
Frees custom context memory for the engine.
VOID HydraHookEngineLogInfo(_In_ LPCSTR Format, _In_opt_ ...)
Logs an informational message (printf-style format).
struct _HYDRAHOOK_ENGINE * PHYDRAHOOK_ENGINE
Opaque handle to the HydraHook engine instance.
struct _HYDRAHOOK_ARC_EVENT_CALLBACKS * PHYDRAHOOK_ARC_EVENT_CALLBACKS
HYDRAHOOK_ERROR HydraHookEngineUnhook(_In_ PHYDRAHOOK_ENGINE Engine)
Removes all render and audio hooks while keeping the DLL and engine loaded.
VOID HydraHookEngineSetARCEventCallbacks(_In_ PHYDRAHOOK_ENGINE Engine, _In_ PHYDRAHOOK_ARC_EVENT_CALLBACKS Callbacks)
Registers Core Audio (IAudioRenderClient) event callbacks.
VOID HydraHookEngineSetD3D10EventCallbacks(_In_ PHYDRAHOOK_ENGINE Engine, _In_ PHYDRAHOOK_D3D10_EVENT_CALLBACKS Callbacks)
Registers Direct3D 10 render pipeline callbacks.
HYDRAHOOK_ERROR HydraHookEngineCreate(_In_ HMODULE HostInstance, _In_ PHYDRAHOOK_ENGINE_CONFIG EngineConfig, _Out_opt_ PHYDRAHOOK_ENGINE *Engine)
Creates and initializes the HydraHook engine.
Core Audio (IAudioRenderClient) hook callbacks.
Direct3D 10 hook callbacks and helpers.
PHYDRAHOOK_ENGINE HydraHookEngineGetHandleFromD3D10SwapChain(_In_ IDXGISwapChain *SwapChain)
Resolves the engine handle from the swap chain passed to a Direct3D 10 callback.
Direct3D 11 hook callbacks and helpers.
Direct3D 12 hook callbacks.
VOID HydraHookEngineSetD3D12EventCallbacks(_In_ PHYDRAHOOK_ENGINE Engine, _In_ PHYDRAHOOK_D3D12_EVENT_CALLBACKS Callbacks)
Registers Direct3D 12 render pipeline callbacks.
ID3D12CommandQueue * HydraHookEngineGetD3D12CommandQueue(_In_ IDXGISwapChain *pSwapChain)
Returns the D3D12 command queue for a swap chain (for overlay rendering). Exact associations are reco...
BOOL HydraHookEngineDeferD3D12Resize(_In_ PHYDRAHOOK_EVT_PRE_EXTENSION Extension)
Defers the active D3D12 ResizeBuffers or ResizeBuffers1 call.
ID3D12CommandQueue * HydraHookEngineGetVerifiedD3D12CommandQueue(_In_ IDXGISwapChain *pSwapChain)
Returns the verified direct queue for the current D3D12 back buffer.
Direct3D 9/9Ex hook callbacks and helpers.
PHYDRAHOOK_ENGINE HydraHookEngineGetHandleFromD3D9Device(_In_ LPDIRECT3DDEVICE9 Device)
Resolves engine handle from IDirect3DDevice9 pointer.
PHYDRAHOOK_ENGINE HydraHookEngineGetHandleFromD3D9ExDevice(_In_ LPDIRECT3DDEVICE9EX Device)
Resolves engine handle from IDirect3DDevice9Ex pointer.
Internal shutdown origin and cleanup for HydraHook engine.
RAII guards for Win32 SRWLOCK.
Exclusive (writer) lock. Call unlock() to release before COM Release or similar.
Shared (reader) lock. Call unlock() to release before COM Release or similar.
Non-blocking exclusive lock. True when the lock was acquired.
std::string get_module_directory(HMODULE hMod)
Returns the directory containing the given module.
std::string get_process_directory()
Returns the directory containing the main process executable.
std::string expand_environment_variables(const std::string &str)
Expands environment variables (e.g. TEMP%) in a string.
static D3D12ResizePreExtension * Current
Engine configuration passed to HydraHookEngineCreate. Initialize with HYDRAHOOK_ENGINE_CONFIG_INIT....
Internal engine instance structure (opaque in public API).
static void shutdown() noexcept
Sets the shutdown flag so new Guard instances skip callbacks.
static void reset() noexcept
Clears the shutdown flag so a rehook invokes callbacks again.
static bool drain(DWORD timeout_ms=5000) noexcept
Spin-waits until every in-flight lambda has returned.