Injection: session-only auto re-attach on relaunch
Add an "Auto re-attach this game on relaunch" checkbox (default off, never persisted, shown while attached or terminated). While on and the target has terminated, the host polls the process list for the same image name and re-injects the moment it reappears -- built on the existing re-attach-by-image-name path, so there's no target to pick. The kill+relaunch recovery for a wrong audio format: re-attaching early catches IAudioClient::Initialize and reads the exact format. Validated live (harness): inject coop_tone -> kill -> relaunch -> auto re-injected into the new pid, and early enough that the format came back as Exact. Trim README. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -115,6 +115,37 @@ void InjectionPanel::close_target_handle()
|
||||
void InjectionPanel::tick()
|
||||
{
|
||||
update_liveness();
|
||||
auto_reattach_tick();
|
||||
}
|
||||
|
||||
void InjectionPanel::auto_reattach_tick()
|
||||
{
|
||||
if (!auto_reattach_ || target_state_ != TargetState::Terminated || selected_name_.empty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
// Poll the process list a couple of times a second (cheap, and we want to catch the
|
||||
// relaunch early to read the exact audio format before the game creates its client).
|
||||
const double now = ImGui::GetTime();
|
||||
if (now - last_auto_poll_ < 0.5)
|
||||
{
|
||||
return;
|
||||
}
|
||||
last_auto_poll_ = now;
|
||||
refresh_processes();
|
||||
for (const ProcessEntry& e : processes_)
|
||||
{
|
||||
if (iequals_name(e.exe_name, selected_name_))
|
||||
{
|
||||
// The same game relaunched -> tear down the stale channel and re-attach to it.
|
||||
server_.stop();
|
||||
close_target_handle();
|
||||
injected_ = false;
|
||||
selected_pid_ = e.pid;
|
||||
inject_selected(); // logs success/failure in status_; retried next poll on failure
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void InjectionPanel::update_liveness()
|
||||
@@ -538,6 +569,18 @@ void InjectionPanel::draw(bool debug_details)
|
||||
ImGui::SameLine();
|
||||
ImGui::TextDisabled("(relaunched %s)", narrow(selected_name_).c_str());
|
||||
}
|
||||
// Session-only auto re-attach: tick it (while attached or terminated), then kill +
|
||||
// relaunch the game and it re-injects itself early -- the kill+relaunch fix for a
|
||||
// wrong audio format, without picking a target again.
|
||||
if (!selected_name_.empty())
|
||||
{
|
||||
ImGui::Checkbox("Auto re-attach this game on relaunch", &auto_reattach_);
|
||||
if (auto_reattach_ && target_state_ == TargetState::Terminated)
|
||||
{
|
||||
ImGui::SameLine();
|
||||
ImGui::TextColored(kGrey, "(watching for %s...)", narrow(selected_name_).c_str());
|
||||
}
|
||||
}
|
||||
ImGui::Separator();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user