Log window: stream the hook's logs over IPC into an in-app Log panel

Add a shared log ring (common/coop/log_ring.hpp): a lossy multi-producer /
single-consumer ring named coop_log_<pid>. The hook logs from several threads,
so producers claim a slot with fetch_add and publish each record with a
release store of its sequence; the consumer reads in order and tolerates
losing the oldest lines if it falls a whole ring behind.

The DLL's logf() now formats once and pushes every line to the ring (the file
trace stays as an opt-in mirror); the worker attaches the ring right after IPC
connect so bring-up is captured. The host (IpcServer) creates the ring at
injection time and exposes drain_logs(); a new LogPanel pulls new lines each
frame into a bounded rolling buffer and renders them with auto-scroll, a
filter, and clear. Added to the View menu (and UiState.show_log).

Verified against Phantom Brave via coop_audio_probe, which now also creates the
ring and drains it: the full hook bring-up trace streamed over IPC. All four
tests pass.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-19 20:25:04 +02:00
parent 0935dccfc4
commit 9557b9ca69
15 changed files with 371 additions and 21 deletions

View File

@@ -1,14 +1,21 @@
// Lightweight file logger for diagnosing the injected hook from inside a game.
//
// We can't see stdout from an injected DLL, so route diagnostics to a file in
// %TEMP%\coop_hook.log. Thread-safe, opened lazily, append-only. Intended for
// development / bring-up; cheap enough to leave compiled in.
// Lightweight logger for the injected hook. We can't see stdout from an injected
// DLL, so each line is (a) streamed to the host over the shared log ring for the
// in-app Log window, and (b) optionally written to %TEMP%\coop_hook.log (opt-in;
// see debug_log.cpp). Thread-safe; cheap enough to leave compiled in.
#pragma once
namespace coop
{
struct LogRing;
}
namespace coop::hook
{
// Append a printf-style line to %TEMP%\coop_hook.log (prefixed with pid + time).
// Append a printf-style line to the log ring (if attached) and the file (if on).
void logf(const char* fmt, ...);
// Attach/detach the host's shared log ring so lines stream to the Log window.
void set_log_ring(coop::LogRing* ring);
} // namespace coop::hook