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:
@@ -20,6 +20,7 @@
|
||||
#include <windows.h>
|
||||
|
||||
#include "coop/audio_ring.hpp"
|
||||
#include "coop/log_ring.hpp"
|
||||
#include "coop/protocol.hpp"
|
||||
#include "coop/shared_memory.hpp"
|
||||
|
||||
@@ -124,6 +125,16 @@ int wmain(int argc, wchar_t** argv)
|
||||
}
|
||||
block->magic = coop::kProtocolMagic;
|
||||
|
||||
// Log ring (host's role): the hook opens this and streams its log lines back.
|
||||
coop::SharedMemory log_shm;
|
||||
coop::LogRing* log_ring = nullptr;
|
||||
std::uint64_t log_cursor = 0;
|
||||
if (log_shm.create(coop::log_ring_name(pid), coop::log_ring_total_size(coop::kLogCapacity)))
|
||||
{
|
||||
log_ring = log_shm.as<coop::LogRing>();
|
||||
coop::log_ring_init(*log_ring, coop::kLogCapacity);
|
||||
}
|
||||
|
||||
// Enable the hook's file trace (%TEMP%\coop_hook.log) for this debug session.
|
||||
{
|
||||
wchar_t dir[MAX_PATH] = {};
|
||||
@@ -259,6 +270,14 @@ int wmain(int argc, wchar_t** argv)
|
||||
e.installed ? "ON " : "off", static_cast<unsigned long long>(e.calls));
|
||||
}
|
||||
|
||||
// Drain the IPC log ring to verify the hook streams its logs to the host.
|
||||
if (log_ring != nullptr)
|
||||
{
|
||||
std::printf("\nHook log (streamed over IPC):\n");
|
||||
coop::log_ring_drain(*log_ring, log_cursor,
|
||||
[](const coop::LogRecord& rec) { std::printf(" %s\n", rec.text); });
|
||||
}
|
||||
|
||||
std::printf("\nDone. Leaving the hook loaded in the game.\n");
|
||||
block->magic = 0; // invalidate so a late hook read won't trust stale data
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user