Hook registry: list installed hooks + call counts in Injection panel

Add a process-wide hook registry (hook/src/hook_registry) that every hook
module registers its hooks with and bumps a counter from each detour. The
XInput, focus-spoof, and audio render-hooks now register their individual
hooks (XInputGetState/Ex/Caps/SetState; GetForegroundWindow/GetActiveWindow/
GetFocus/WndProc guard; IMMDevice::Activate, IAudioClient::Initialize/
GetService, IAudioRenderClient::GetBuffer/ReleaseBuffer) and count calls.

The worker publishes the table to the host each tick over a new HookStatus
field (protocol v4 -> v5: HookEntry[] + count). The Injection panel shows it
as a collapsible table grouped by subsystem with an installed flag and call
count per hook; coop_audio_probe prints the same table headless.

Verified against Phantom Brave: 13 hooks listed with live counts (focus APIs
polled heavily, GetBuffer/ReleaseBuffer ticking with the audio render loop).
All four tests pass.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-19 20:09:39 +02:00
parent 565934e8cf
commit 1f905940ef
16 changed files with 371 additions and 14 deletions

View File

@@ -11,7 +11,7 @@ namespace coop
// Bump whenever the layout of SharedBlock or CoopPadState changes. The hook
// refuses to attach to a host with a mismatched version.
inline constexpr std::uint32_t kProtocolVersion = 4;
inline constexpr std::uint32_t kProtocolVersion = 5;
// 'COOP' little-endian, used to sanity-check the mapping before trusting it.
inline constexpr std::uint32_t kProtocolMagic = 0x504F4F43u;
@@ -60,6 +60,28 @@ struct AudioStreamInfo
std::uint64_t frames_rendered;
};
// Orthogonal hook subsystems the host can install/remove independently.
enum HookSubsystem : std::uint32_t
{
HookSubsys_Input = 0, // XInput hooks (forward the guest pad)
HookSubsys_Focus = 1, // focus spoof (keep the game running unfocused)
HookSubsys_Audio = 2, // WASAPI render-hook (audio mirror without echo)
HookSubsys_Count = 3,
};
// Maximum individual hooks reported in the registry (a few per subsystem).
inline constexpr std::uint32_t kMaxHookEntries = 24;
// One installed hook, for the Injection panel's hook list. POD diagnostics, like
// AudioStreamInfo: the hook is the sole writer; benign cross-process races are ok.
struct HookEntry
{
char name[40]; // e.g. "XInputGetState"
std::uint32_t subsystem; // HookSubsystem
std::uint32_t installed; // 1 if currently hooked
std::uint64_t calls; // cumulative times the detour ran
};
// Indices into HookStatus::focus_query_calls.
enum FocusApi : std::uint32_t
{
@@ -97,6 +119,11 @@ struct HookStatus
// multi-stream game is visible before/without turning the mirror on.
std::uint32_t audio_streams_seen; // distinct render clients ever created
AudioStreamInfo audio_streams[kMaxAudioStreams]; // per-slot detail, [0] is primary
// Hook registry: every individual hook the DLL has installed, with a running
// call count. Lets the Injection panel list exactly what's hooked and how busy.
std::uint32_t hook_entry_count;
HookEntry hook_entries[kMaxHookEntries];
};
// Top-level shared block. The host is the sole writer of pad state; the hook is