Phase 1a: input forwarding via DLL injection + XInput hook

The host can now inject coop_hook.dll into a running game and forward
controller state to it over shared memory, so the game reads the host's
(eventually the guest's) input and nothing else.

- hook/: coop_hook.dll. DllMain spawns a worker that opens the shared-memory
  channel (named by the game's pid) and installs SafetyHook inline hooks on
  XInputGetState/GetStateEx/GetCapabilities/SetState. Detours synthesize state
  from shared memory; unmanaged slots report disconnected, hiding physical pads.
- host/: process picker (Toolhelp32), CreateRemoteThread(LoadLibraryW) injector
  with an IsWow64Process2 bitness guard, IPC server publishing pads each frame,
  and an ImGui Injection panel wiring it together.
- tests/: hook_selftest exercises the IPC seqlock + hook detours in-process
  (no game/controller needed); passes.

Build: SafetyHook wired in (COOP_BUILD_HOOK=ON), Zydis via FetchContent.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-18 23:21:20 +02:00
parent cf058aecfa
commit e370c8dcc5
19 changed files with 1038 additions and 11 deletions

18
hook/src/xinput_hook.hpp Normal file
View File

@@ -0,0 +1,18 @@
// Installs XInput hooks inside the target game so it reads the controller state
// the host forwards over shared memory -- and nothing else.
#pragma once
#include "ipc_client.hpp"
namespace coop::hook
{
// Locates the loaded XInput module(s) and hooks the state/capability entry
// points. `ipc` must outlive the hooks. Returns true if at least one module was
// hooked. Safe to call repeatedly while waiting for xinput to load.
bool install_xinput_hooks(const IpcClient& ipc);
// Removes all installed hooks (best effort; used on DLL detach).
void remove_xinput_hooks();
} // namespace coop::hook