Graceful disconnect: tell the DLL to unhook everything

On an explicit Disconnect and on graceful tool exit, the host now asks the
injected DLL to remove every subsystem so the game runs exactly as if it was
never hooked (each hook restores its original bytes). The DLL stays injected but
dormant, ready for a later reconnect -- we never eject it.

Before, both paths just dropped the IPC channel (IpcServer::stop) without telling
the DLL, leaving the hooks active with frozen forwarded state until the game
exited.

- IpcServer::request_unhook_all() sets every subsystem_disabled flag (the DLL
  reconciles to fully unhooked on its next tick); all_hooks_removed() reads the
  hook registry back so the host can confirm the game is vanilla.
- InjectionPanel::disconnect_graceful() requests the unhook, waits (bounded) for
  the registry to clear, then stops. Wired into the Disconnect button (700ms) and
  the destructor (300ms). The flags persist in the section the DLL keeps alive, so
  the unhook completes even if the host exits before confirming.

Tests (failing first):
- ipc_server_test: request_unhook_all() disables all subsystems; all_hooks_removed()
  tracks the registry. Deterministic, no game.
- mock_game_test test_graceful_disconnect: inject -> hooks installed -> request
  unhook-all -> every hook removed (game vanilla) while the DLL stays alive
  (heartbeat advancing). Full suite still passes.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-23 13:46:51 +02:00
parent 39558171e9
commit 6d96531ac7
8 changed files with 278 additions and 8 deletions

View File

@@ -112,10 +112,6 @@ Completed work lives in **Lessons learned** + the test suite, not here.
### Current tasks
- **Graceful disconnect unhooks everything.** On an explicit *Disconnect* and on a graceful tool
exit, ask the injected DLL to disable *all* subsystems so the game runs exactly as if it was never
hooked (every hook's original bytes restored). The DLL stays injected but dormant — ready for a
later reconnect. Today neither path tells the DLL anything, so the hooks are left active/frozen.
- **Reconnect to an already-injected DLL.** Support disconnect → reconnect reusing the DLL that's
already in the game, *including across a tool restart or crash*: the host detects the live DLL
(via its advancing IPC heartbeat on the per-pid section), re-attaches to the same shared section,