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

Session-local shared-memory engine status and rehook control. More...

#include <Windows.h>
#include "HydraHook/Engine/HydraHookCore.h"
#include <atomic>
#include <cstddef>
#include <cstdint>
#include <cstdio>

Go to the source code of this file.

Classes

struct  HydraHookIpcStatus

Typedefs

using HydraHookIpcRehookHold = void (*)(PHYDRAHOOK_ENGINE engine)

Functions

void HydraHookIpcFormatNames (DWORD pid, std::uintptr_t host, wchar_t *stateName, std::size_t stateCch, wchar_t *rehookName, std::size_t rehookCch)
void HydraHookIpcCreate (PHYDRAHOOK_ENGINE engine)
void HydraHookIpcPublish (PHYDRAHOOK_ENGINE engine, std::uint32_t state, std::uint32_t origin, std::uint32_t gameVersion, std::uint32_t flags)
void HydraHookIpcPublishRunning (PHYDRAHOOK_ENGINE engine)
 Moves Initializing to Running. Does not write the graphics API a Hooked publish owns.
void HydraHookIpcArmRehookWait (PHYDRAHOOK_ENGINE engine)
void HydraHookIpcDisarmRehookWait (PHYDRAHOOK_ENGINE engine)
bool HydraHookIpcAbandonRehookWait (PHYDRAHOOK_ENGINE engine)
 Cancels a pending rehook wait so the engine can be freed.
void HydraHookIpcClose (PHYDRAHOOK_ENGINE engine)
 Closes IPC objects. The caller guarantees no rehook callback is running.

Variables

constexpr std::uint32_t HydraHookIpcMagic = 0x534B4848u
constexpr std::uint32_t HydraHookIpcVersion = 1u
constexpr std::uint32_t HydraHookIpcStateNone = 0u
constexpr std::uint32_t HydraHookIpcStateInitializing = 1u
constexpr std::uint32_t HydraHookIpcStateRunning = 2u
constexpr std::uint32_t HydraHookIpcStateHooked = 3u
constexpr std::uint32_t HydraHookIpcStateShuttingDown = 4u
constexpr std::uint32_t HydraHookIpcStateStopped = 5u
constexpr std::uint32_t HydraHookIpcShutdownOriginNone = 0u
constexpr std::uint32_t HydraHookIpcShutdownOriginExitProcess = 1u
constexpr std::uint32_t HydraHookIpcShutdownOriginPostQuitMessage = 2u
constexpr std::uint32_t HydraHookIpcShutdownOriginFreeLibrary = 3u
constexpr std::uint32_t HydraHookIpcShutdownOriginDllMainDetach = 4u
constexpr std::uint32_t HydraHookIpcShutdownOriginManualUnhook = 5u
constexpr std::uint32_t HydraHookIpcFlagRehookSupported = 1u << 0
constexpr std::uint32_t HydraHookIpcFlagDrainIncomplete = 1u << 1
constexpr std::int32_t HydraHookIpcPhaseIdle = 0
constexpr std::int32_t HydraHookIpcPhaseArmed = 1
constexpr std::int32_t HydraHookIpcPhaseInCallback = 2
constexpr std::int32_t HydraHookIpcPhaseInCallbackExternal = 3
std::atomic< HydraHookIpcRehookHold > HydraHookIpcRehookHoldForTest

Detailed Description

Session-local shared-memory engine status and rehook control.

Each engine publishes a 64-byte status block named Local\HydraHook.State.<pid>.<hostInstanceHex16> and a companion auto-reset event Local\HydraHook.Rehook.<pid>.<hostInstanceHex16>. Readers (HydraHook Manager) open the section read-only. The rehook event is waited on with the process thread pool only while the engine is stopped for a recoverable reason, so a pinned DLL can be restarted without LoadLibrary.

Layout (little-endian, natural alignment, 64 bytes): 0 uint32 Magic 0x534B4848 ('HHKS') 4 uint32 Version 1 8 uint32 Size 64 12 uint32 State HydraHookIpcState 16 uint32 ShutdownOrigin HydraHookIpcShutdownOrigin 20 uint32 GameVersion HYDRAHOOK_D3D_VERSION 24 uint32 Generation starts at 1, increments on each rehook 28 uint32 Flags HydraHookIpcFlags 32 uint64 LastTransitionTick64 40 uint32 Reserved[6]

State is published last with an interlocked store. Readers that sample State twice around the other fields observe one transition.

Definition in file EngineIpc.h.

Typedef Documentation

◆ HydraHookIpcRehookHold

using HydraHookIpcRehookHold = void (*)(PHYDRAHOOK_ENGINE engine)

Definition at line 96 of file EngineIpc.h.

Function Documentation

◆ HydraHookIpcAbandonRehookWait()

bool HydraHookIpcAbandonRehookWait ( PHYDRAHOOK_ENGINE engine)

Cancels a pending rehook wait so the engine can be freed.

Returns
false when a rehook callback is queued or running. The caller must keep the engine.

Definition at line 390 of file EngineIpc.cpp.

References HydraHookIpcAbandonRehookWait(), HydraHookIpcPhaseArmed, and HydraHookIpcPhaseIdle.

Referenced by DestroyEngine(), and HydraHookIpcAbandonRehookWait().

◆ HydraHookIpcArmRehookWait()

◆ HydraHookIpcClose()

void HydraHookIpcClose ( PHYDRAHOOK_ENGINE engine)

Closes IPC objects. The caller guarantees no rehook callback is running.

Definition at line 419 of file EngineIpc.cpp.

References HydraHookIpcClose().

Referenced by DestroyEngine(), HydraHookEngineCreate(), and HydraHookIpcClose().

◆ HydraHookIpcCreate()

◆ HydraHookIpcDisarmRehookWait()

void HydraHookIpcDisarmRehookWait ( PHYDRAHOOK_ENGINE engine)

◆ HydraHookIpcFormatNames()

void HydraHookIpcFormatNames ( DWORD pid,
std::uintptr_t host,
wchar_t * stateName,
std::size_t stateCch,
wchar_t * rehookName,
std::size_t rehookCch )
inline

Definition at line 87 of file EngineIpc.h.

References HydraHookIpcFormatNames().

Referenced by HydraHookIpcCreate(), and HydraHookIpcFormatNames().

◆ HydraHookIpcPublish()

void HydraHookIpcPublish ( PHYDRAHOOK_ENGINE engine,
std::uint32_t state,
std::uint32_t origin,
std::uint32_t gameVersion,
std::uint32_t flags )

◆ HydraHookIpcPublishRunning()

void HydraHookIpcPublishRunning ( PHYDRAHOOK_ENGINE engine)

Moves Initializing to Running. Does not write the graphics API a Hooked publish owns.

Definition at line 264 of file EngineIpc.cpp.

References HydraHookIpcPublishRunning(), HydraHookIpcStateInitializing, and HydraHookIpcStateRunning.

Referenced by HydraHookIpcPublishRunning().

Variable Documentation

◆ HydraHookIpcFlagDrainIncomplete

std::uint32_t HydraHookIpcFlagDrainIncomplete = 1u << 1
constexpr

Definition at line 60 of file EngineIpc.h.

◆ HydraHookIpcFlagRehookSupported

std::uint32_t HydraHookIpcFlagRehookSupported = 1u << 0
constexpr

Definition at line 59 of file EngineIpc.h.

Referenced by HydraHookEngineRehook().

◆ HydraHookIpcMagic

std::uint32_t HydraHookIpcMagic = 0x534B4848u
constexpr

Definition at line 42 of file EngineIpc.h.

Referenced by HydraHookIpcCreate().

◆ HydraHookIpcPhaseArmed

std::int32_t HydraHookIpcPhaseArmed = 1
constexpr

◆ HydraHookIpcPhaseIdle

std::int32_t HydraHookIpcPhaseIdle = 0
constexpr

◆ HydraHookIpcPhaseInCallback

std::int32_t HydraHookIpcPhaseInCallback = 2
constexpr

Definition at line 64 of file EngineIpc.h.

Referenced by HydraHookEngineRehook(), and HydraHookIpcArmRehookWait().

◆ HydraHookIpcPhaseInCallbackExternal

std::int32_t HydraHookIpcPhaseInCallbackExternal = 3
constexpr

Definition at line 65 of file EngineIpc.h.

Referenced by HydraHookEngineRehook(), and HydraHookIpcArmRehookWait().

◆ HydraHookIpcRehookHoldForTest

std::atomic<HydraHookIpcRehookHold> HydraHookIpcRehookHoldForTest
extern

Test seam. Invoked after a successful rehook callback starts the worker and before it releases the phase.

Definition at line 27 of file EngineIpc.cpp.

◆ HydraHookIpcShutdownOriginDllMainDetach

std::uint32_t HydraHookIpcShutdownOriginDllMainDetach = 4u
constexpr

Definition at line 56 of file EngineIpc.h.

Referenced by IpcShutdownOrigin().

◆ HydraHookIpcShutdownOriginExitProcess

std::uint32_t HydraHookIpcShutdownOriginExitProcess = 1u
constexpr

Definition at line 53 of file EngineIpc.h.

Referenced by IpcShutdownOrigin().

◆ HydraHookIpcShutdownOriginFreeLibrary

std::uint32_t HydraHookIpcShutdownOriginFreeLibrary = 3u
constexpr

Definition at line 55 of file EngineIpc.h.

Referenced by IpcShutdownOrigin().

◆ HydraHookIpcShutdownOriginManualUnhook

std::uint32_t HydraHookIpcShutdownOriginManualUnhook = 5u
constexpr

Definition at line 57 of file EngineIpc.h.

Referenced by IpcShutdownOrigin().

◆ HydraHookIpcShutdownOriginNone

std::uint32_t HydraHookIpcShutdownOriginNone = 0u
constexpr

Definition at line 52 of file EngineIpc.h.

Referenced by HydraHookEngineRehook(), HydraHookIpcCreate(), and IpcShutdownOrigin().

◆ HydraHookIpcShutdownOriginPostQuitMessage

std::uint32_t HydraHookIpcShutdownOriginPostQuitMessage = 2u
constexpr

Definition at line 54 of file EngineIpc.h.

Referenced by IpcShutdownOrigin().

◆ HydraHookIpcStateHooked

std::uint32_t HydraHookIpcStateHooked = 3u
constexpr

Definition at line 48 of file EngineIpc.h.

◆ HydraHookIpcStateInitializing

std::uint32_t HydraHookIpcStateInitializing = 1u
constexpr

◆ HydraHookIpcStateNone

std::uint32_t HydraHookIpcStateNone = 0u
constexpr

Definition at line 45 of file EngineIpc.h.

◆ HydraHookIpcStateRunning

std::uint32_t HydraHookIpcStateRunning = 2u
constexpr

Definition at line 47 of file EngineIpc.h.

Referenced by HydraHookIpcPublishRunning().

◆ HydraHookIpcStateShuttingDown

std::uint32_t HydraHookIpcStateShuttingDown = 4u
constexpr

Definition at line 49 of file EngineIpc.h.

Referenced by PerformShutdownCleanup().

◆ HydraHookIpcStateStopped

std::uint32_t HydraHookIpcStateStopped = 5u
constexpr

Definition at line 50 of file EngineIpc.h.

Referenced by HydraHookEngineRehook().

◆ HydraHookIpcVersion

std::uint32_t HydraHookIpcVersion = 1u
constexpr

Definition at line 43 of file EngineIpc.h.

Referenced by HydraHookIpcCreate().