refactor: Move all hook and IO libraries to use btools log and thread api

Remove usages of AVS threads and logging functions from the bemanitools backend. Use the bemanitools 6 API instead
which propagates interfaces to call thread and log APIs.

Prior design decisions for using these were:
- have a single log stream through the AVS logging system for “neatness”, log output redirection options in launcher, and theoretically logging to an xrpc endpoint
- IIDX 19 to IIDX 24 crash the AVS logging engine in libavs due to IO hook code running in a non AVS thread (threads in ezusb library) causing a stackoverflow when trying to acquire a mutex (see dev journal 2018-02-10-logging-breakdown-avs.md for details)

With a flexible log sink architecture in the core of bemanitools, and a separate writer function that is hooked up as a log writer to AVS, log streams are still unified on a sink level. This takes care of having all log messaged sinked to the same targets no matter how many logging engines are using them.

This avoids going through the AVS logging engine with the IO related hooking code in iidx, which just uses the bemanitools logging engine instead.

Furthermore, this removes any needs to having to switch thread and logging implementations once AVS is booted which significantly simplifies the runtime orchestration during bootstrapping.

The log-server, which was specifically implemented for iidx to solve the threading issue, can also be removed now. Unfortunately, this also caused performance issues such as stuttering due to it’s rather simplistic implementation.
This commit is contained in:
icex2
2024-08-15 11:34:31 +02:00
parent 57e68f928a
commit e61dfb3977
48 changed files with 693 additions and 1055 deletions
+33 -28
View File
@@ -5,14 +5,10 @@
#include <stdio.h>
#include <stdlib.h>
#include "avs-ext/log.h"
#include "avs-ext/thread.h"
#include "cconfig/cconfig-hook.h"
#include "hooklib/acp.h"
#include "hooklib/adapter.h"
#include "hooklib/app.h"
#include "hooklib/config-adapter.h"
#include "hooklib/memfile.h"
#include "hooklib/rs232.h"
@@ -40,7 +36,9 @@
#include "d3d9exhook/config-gfx.h"
#include "d3d9exhook/d3d9ex.h"
#include "imports/avs.h"
#include "sdk/module/core/log.h"
#include "sdk/module/core/thread.h"
#include "sdk/module/hook.h"
#include "util/str.h"
@@ -99,12 +97,18 @@ static void _sdvxhook2_io_eam_init(module_io_t **module)
bt_io_eam_api_set(&api);
}
static bool my_dll_entry_init(char *sidcode, struct property_node *param)
static bool
_sdvxhook2_main_init(HMODULE game_module, const bt_core_config_t *config_)
{
struct cconfig *config;
log_info("--- Begin sdvxhook dll_entry_init ---");
// TODO sidcode back-propagation required like jubeat, figure out
char *sidcode = NULL;
log_assert(sidcode);
config = cconfig_init();
sdvxhook2_config_io_init(config);
@@ -130,6 +134,10 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param)
log_info(SDVXHOOK2_INFO_HEADER);
log_info("Initializing sdvxhook2...");
acp_hook_init();
adapter_hook_init();
d3d9ex_hook_init();
d3d9ex_configure(&config_gfx);
/* Start up sdvxio.DLL */
@@ -196,15 +204,11 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param)
log_info("--- End sdvxhook dll_entry_init ---");
return app_hook_invoke_init(sidcode, param);
return true;
}
static bool my_dll_entry_main(void)
static void _sdvxhook2_main_fini()
{
bool result;
result = app_hook_invoke_main();
if (!config_cam.disable_emu) {
camhook_fini();
}
@@ -230,8 +234,24 @@ static bool my_dll_entry_main(void)
if (!config_io.disable_file_hooks) {
memfile_hook_fini();
}
}
return result;
void bt_module_core_log_api_set(const bt_core_log_api_t *api)
{
bt_core_log_api_set(api);
}
void bt_module_core_thread_api_set(const bt_core_thread_api_t *api)
{
bt_core_thread_api_set(api);
}
void bt_module_hook_api_get(bt_hook_api_t *api)
{
api->version = 1;
api->v1.main_init = _sdvxhook2_main_init;
api->v1.main_fini = _sdvxhook2_main_fini;
}
/**
@@ -239,20 +259,5 @@ static bool my_dll_entry_main(void)
*/
BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx)
{
if (reason != DLL_PROCESS_ATTACH) {
goto end;
}
// Use AVS APIs
avs_ext_log_core_api_set();
avs_ext_thread_core_api_set();
app_hook_init(my_dll_entry_init, my_dll_entry_main);
acp_hook_init();
adapter_hook_init();
d3d9ex_hook_init();
end:
return TRUE;
}
+5
View File
@@ -2,3 +2,8 @@ LIBRARY sdvxhook2
EXPORTS
DllMain@12 @1 NONAME
; Bemanitools 6 API
bt_module_core_log_api_set
bt_module_core_thread_api_set
bt_module_hook_api_get