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:
@@ -98,6 +98,10 @@ void InjectionPanel::refresh_targets()
|
||||
|
||||
InjectionPanel::~InjectionPanel()
|
||||
{
|
||||
// Graceful tool exit: unhook everything so a still-running game returns to normal (the DLL
|
||||
// stays injected, dormant). Short timeout -- the flags persist in the section the DLL keeps
|
||||
// alive, so the unhook completes even if the process exits before it confirms.
|
||||
disconnect_graceful(/*timeout_ms=*/300);
|
||||
if (vk_layer_enabled_)
|
||||
{
|
||||
unregister_vk_layer(); // don't leave the implicit layer registered after the tool closes
|
||||
@@ -105,6 +109,25 @@ InjectionPanel::~InjectionPanel()
|
||||
close_target_handle();
|
||||
}
|
||||
|
||||
void InjectionPanel::disconnect_graceful(int timeout_ms)
|
||||
{
|
||||
// Tell the DLL to remove every hook so the game runs as if it was never touched, then wait
|
||||
// (bounded) for it to confirm before we drop the channel. The flags persist in the section the
|
||||
// DLL keeps alive, so it unhooks even if we time out or exit first -- the wait just lets us
|
||||
// observe a clean game. The DLL is left injected (dormant) for a later reconnect; we never eject.
|
||||
if (server_.running())
|
||||
{
|
||||
server_.request_unhook_all();
|
||||
for (int waited = 0; waited < timeout_ms && !server_.all_hooks_removed(); waited += 10)
|
||||
{
|
||||
Sleep(10);
|
||||
}
|
||||
}
|
||||
server_.stop();
|
||||
injected_ = false;
|
||||
close_target_handle();
|
||||
}
|
||||
|
||||
void InjectionPanel::close_target_handle()
|
||||
{
|
||||
if (target_process_ != nullptr)
|
||||
@@ -557,10 +580,10 @@ void InjectionPanel::draw(bool debug_details)
|
||||
}
|
||||
if (ImGui::Button("Disconnect"))
|
||||
{
|
||||
server_.stop();
|
||||
injected_ = false;
|
||||
close_target_handle();
|
||||
status_ = "Stopped.";
|
||||
// Leave the game vanilla: unhook everything before dropping the channel. The DLL stays
|
||||
// injected (dormant), so it can be reconnected later without re-injecting.
|
||||
disconnect_graceful(/*timeout_ms=*/700);
|
||||
status_ = "Disconnected (game unhooked; DLL left injected).";
|
||||
status_color_ = kGrey;
|
||||
}
|
||||
// A relaunched game has a new pid; re-attach by image name without hunting for
|
||||
|
||||
Reference in New Issue
Block a user