60 template <
typename Fn>
63 if (done_.load(std::memory_order_acquire))
66 std::lock_guard<std::mutex> lock(mutex_);
67 if (done_.load(std::memory_order_acquire))
71 done_.store(
true, std::memory_order_release);
77 std::lock_guard<std::mutex> lock(mutex_);
78 done_.store(
false, std::memory_order_release);
83 std::atomic<bool> done_{
false};
89typedef struct _HYDRAHOOK_ENGINE
133 IAudioRenderClient *
pARC =
nullptr;
142template <
typename T,
typename U>
145 if (slot.load(std::memory_order_relaxed) == value)
147 slot.store(value, std::memory_order_release);
151template <
typename Pipeline>
154 pipeline.pSwapChain.store(
nullptr, std::memory_order_release);
155 pipeline.pD3D9Device.store(
nullptr, std::memory_order_release);
156 pipeline.pD3D9ExDevice.store(
nullptr, std::memory_order_release);
162 return slot.load(std::memory_order_acquire);
175 alignas(64)
static inline std::atomic<int32_t>
s_active{0};
191 s_active.fetch_add(1, std::memory_order_seq_cst);
197 s_active.fetch_sub(1, std::memory_order_release);
226 static bool drain(DWORD timeout_ms = 5000) noexcept
228 const ULONGLONG deadline = GetTickCount64() + timeout_ms;
229 while (
s_active.load(std::memory_order_seq_cst) > 0)
231 if (GetTickCount64() >= deadline)
257#define INVOKE_HYDRAHOOK_GAME_HOOKED(_engine_, _version_) \
259 (_engine_)->GameVersion = (_version_); \
260 HydraHookIpcPublish((_engine_), HydraHookIpcStateHooked, HydraHookIpcShutdownOriginNone, \
261 static_cast<std::uint32_t>(_version_), 0); \
262 if ((_engine_)->EngineConfig.EvtHydraHookGameHooked) \
263 (_engine_)->EngineConfig.EvtHydraHookGameHooked((_engine_), (_version_)); \
267#define INVOKE_D3D9_CALLBACK(_engine_, _callback_, ...) \
269 const auto _pfn_ = (_engine_)->EventsD3D9._callback_; \
270 if (_pfn_) _pfn_(##__VA_ARGS__); \
274#define INVOKE_D3D10_CALLBACK(_engine_, _callback_, ...) \
276 const auto _pfn_ = (_engine_)->EventsD3D10._callback_; \
277 if (_pfn_) _pfn_(##__VA_ARGS__); \
281#define INVOKE_D3D11_CALLBACK(_engine_, _callback_, ...) \
283 const auto _pfn_ = (_engine_)->EventsD3D11._callback_; \
284 if (_pfn_) _pfn_(##__VA_ARGS__); \
288#define INVOKE_D3D12_CALLBACK(_engine_, _callback_, ...) \
290 const auto _pfn_ = (_engine_)->EventsD3D12._callback_; \
291 if (_pfn_) _pfn_(##__VA_ARGS__); \
295#define INVOKE_ARC_CALLBACK(_engine_, _callback_, ...) \
297 const auto _pfn_ = (_engine_)->EventsARC._callback_; \
298 if (_pfn_) _pfn_(##__VA_ARGS__); \
HYDRAHOOK_ERROR HydraHookEngineDestroyBeforeUnload(HMODULE host, bool(*detachFreeLibraryHook)() noexcept)
Tears down the registered engine before explicit unload. Busy failures keep the hook installed.
void HydraHookLoggingEnableAsync()
Swaps the process logger to a HydraHook-owned async pool. Call from the worker, not DllMain.
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,...
void StoreRenderPipelinePtr(std::atomic< T * > &slot, U *value)
Publishes a RenderPipeline pointer. Render threads write it while other threads look engines up by it...
T * LoadRenderPipelinePtr(const std::atomic< T * > &slot)
void ClearRenderPipeline(Pipeline &pipeline)
Resets every RenderPipeline pointer atomically, so concurrent lookups never see a torn value.
Session-local shared-memory engine status and rehook control.
constexpr std::uint32_t HydraHookIpcShutdownOriginNone
constexpr std::int32_t HydraHookIpcPhaseIdle
@ HydraHookDirect3DVersionUnknown
HYDRAHOOK_ERROR
Error codes returned by HydraHook engine functions.
Once-per-hook announcement guard that can be re-armed.
void call(Fn &&fn)
Runs fn once until reset() is called; concurrent callers wait for the first.
void reset()
Re-arms the guard.
Core Audio (IAudioRenderClient) event callback collection.
Direct3D 10 event callback collection.
Direct3D 11 event callback collection.
Direct3D 12 event callback collection.
Direct3D 9/9Ex event callback collection.
IAudioRenderClient * pARC
std::atomic< LPDIRECT3DDEVICE9 > pD3D9Device
std::atomic< IDXGISwapChain * > pSwapChain
std::atomic< LPDIRECT3DDEVICE9EX > pD3D9ExDevice
Engine configuration passed to HydraHookEngineCreate. Initialize with HYDRAHOOK_ENGINE_CONFIG_INIT....
Internal engine instance structure (opaque in public API).
HYDRAHOOK_D3D10_EVENT_CALLBACKS EventsD3D10
std::atomic< bool > DrainIncomplete
HYDRAHOOK_D3D12_EVENT_CALLBACKS SavedEventsD3D12
std::atomic< uint32_t > LastShutdownOrigin
HYDRAHOOK_ARC_EVENT_CALLBACKS SavedEventsARC
HYDRAHOOK_D3D10_EVENT_CALLBACKS SavedEventsD3D10
HYDRAHOOK_D3D9_EVENT_CALLBACKS EventsD3D9
std::atomic< uint32_t > IpcGeneration
HANDLE EngineCancellationEvent
std::atomic< uint32_t > RehookOwnerThread
std::atomic< int32_t > RehookWaitPhase
HYDRAHOOK_D3D11_EVENT_CALLBACKS SavedEventsD3D11
HYDRAHOOK_D3D12_EVENT_CALLBACKS EventsD3D12
HYDRAHOOK_ARC_EVENT_CALLBACKS EventsARC
std::atomic< bool > ShutdownCleanupDone
std::atomic< bool > FreeLibraryHookActive
std::atomic< HYDRAHOOK_D3D_VERSION > GameVersion
HYDRAHOOK_D3D9_EVENT_CALLBACKS SavedEventsD3D9
BOOL CrashHandlerInstalled
HYDRAHOOK_ENGINE_CONFIG EngineConfig
HYDRAHOOK_D3D11_EVENT_CALLBACKS EventsD3D11
std::atomic< bool > SkipDllUnloadOnExit
std::atomic< PVOID > CustomContext
std::atomic< bool > RehookDisabled
Guard(const Guard &)=delete
Guard & operator=(const Guard &)=delete
Lock-free tracker for in-flight hook lambda invocations.
static void shutdown() noexcept
Sets the shutdown flag so new Guard instances skip callbacks.
static std::atomic< bool > s_shutting_down
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.
static std::atomic< int32_t > s_active