From 27e9f8dea8c3cbd554d3f14e0cfb6cb3fec1211e Mon Sep 17 00:00:00 2001 From: icex2 Date: Thu, 15 Aug 2024 11:34:31 +0200 Subject: [PATCH] feat(inject): Use async log sink for logging MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Solves similar issues with the old games not using the AVS logging system (because there is none). Threads calling the log functions are still logging using OutputDebugStr, but the dispatching in the debugger module in inject hands those messages off to the async log sink which avoids blocking the calling thread (for long). We want to keep this feature around as there are several games actually having non-removed OutputDebugStr calls which can provide some useful debugging information. Furthermore, neutral hooks only using DllMain and not the bemanitools API can still channel log messages this way to bemanitools’s logging system (though less efficiently than calling it directly). Further changes to existing hooks will be applied to migrate their logger usage to using the logger directly through the bemanitools API. --- src/main/inject/main.c | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/src/main/inject/main.c b/src/main/inject/main.c index 9f73fb7..d2b8249 100644 --- a/src/main/inject/main.c +++ b/src/main/inject/main.c @@ -53,25 +53,12 @@ static void _inject_log_header() void _inject_log_init( const char *log_file_path, enum core_log_bt_log_level level) { - core_log_sink_t sinks[2]; - core_log_sink_t sink_composed; - core_log_sink_t sink_mutex; - if (log_file_path) { - core_log_sink_std_out_open(true, &sinks[0]); - core_log_sink_file_open(log_file_path, false, true, 10, &sinks[1]); - core_log_sink_list_open(sinks, 2, &sink_composed); + core_log_bt_ext_init_async_with_stderr_and_file(log_file_path, false, true, 10); } else { - core_log_sink_std_out_open(true, &sink_composed); + core_log_bt_ext_init_async_with_stderr(); } - // Different threads logging the same destination, e.g. debugger thread, - // main thread - // TODO this needs to be de-coupled with async logging to fix latency - // issues for any game related threads logging - core_log_sink_mutex_open(&sink_composed, &sink_mutex); - - core_log_bt_init(&sink_mutex); core_log_bt_core_api_set(); core_log_bt_level_set(level); @@ -217,6 +204,8 @@ int main(int argc, char **argv) goto init_options_fail; } + core_thread_crt_core_api_set(); + // TODO expose log level _inject_log_init( strlen(options.log_file) > 0 ? options.log_file : NULL, @@ -225,8 +214,6 @@ int main(int argc, char **argv) _inject_log_header(); os_version_log(); - core_thread_crt_core_api_set(); - signal_exception_handler_init(); // Cleanup remote process on CTRL+C signal_register_shutdown_handler(signal_shutdown_handler);