refactor: Entire code base, thread and log usage
Boils down to: - Include headers - Reduce boiler plate with helpers - Swap out explicit usages with core API layer and ensure the right API is configured beforehand
This commit is contained in:
@@ -7,6 +7,8 @@ deplibs_ddrhook1 := \
|
||||
avs \
|
||||
|
||||
libs_ddrhook1 := \
|
||||
avs-util \
|
||||
core \
|
||||
acioemu \
|
||||
cconfig \
|
||||
ddrhook-util \
|
||||
|
||||
@@ -5,6 +5,9 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "core/log-bt.h"
|
||||
#include "core/log.h"
|
||||
|
||||
#include "hook/iohook.h"
|
||||
#include "hook/table.h"
|
||||
|
||||
@@ -13,7 +16,6 @@
|
||||
#include "ddrhook1/avs-boot.h"
|
||||
#include "ddrhook1/filesystem.h"
|
||||
|
||||
#include "util/log.h"
|
||||
#include "util/str.h"
|
||||
|
||||
static void (*real_avs_boot)(
|
||||
@@ -50,6 +52,11 @@ static const struct hook_symbol ddrhook1_avs_ea3_hook_syms[] = {
|
||||
.link = (void **) &real_ea3_boot},
|
||||
};
|
||||
|
||||
static AVS_LOG_WRITER(_avs_boot_log_writer, chars, nchars, ctx)
|
||||
{
|
||||
core_log_bt_direct_sink_write(chars, nchars);
|
||||
}
|
||||
|
||||
static void avs_boot_replace_property_str(
|
||||
struct property_node *node, const char *name, const char *val)
|
||||
{
|
||||
@@ -115,7 +122,7 @@ static void my_avs_boot(
|
||||
sz_std_heap,
|
||||
avs_heap,
|
||||
sz_avs_heap,
|
||||
log_writer_debug,
|
||||
_avs_boot_log_writer,
|
||||
NULL);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
#include "cconfig/cconfig-util.h"
|
||||
|
||||
#include "ddrhook1/config-ddrhook1.h"
|
||||
#include "core/log.h"
|
||||
|
||||
#include "util/log.h"
|
||||
#include "ddrhook1/config-ddrhook1.h"
|
||||
|
||||
#define DDRHOOK1_CONFIG_DDRHOOK1_USE_COM4_EMU_KEY "ddrhook1.use_com4_emu"
|
||||
#define DDRHOOK1_CONFIG_DDRHOOK1_STANDARD_DEF_KEY "ddrhook1.standard_def"
|
||||
|
||||
@@ -2,9 +2,10 @@
|
||||
|
||||
#include "cconfig/cconfig-util.h"
|
||||
|
||||
#include "core/log.h"
|
||||
|
||||
#include "ddrhook1/config-eamuse.h"
|
||||
|
||||
#include "util/log.h"
|
||||
#include "util/net.h"
|
||||
|
||||
#define DDRHOOK1_CONFIG_EAMUSE_SERVER_KEY "eamuse.server"
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
#include "cconfig/cconfig-util.h"
|
||||
|
||||
#include "ddrhook1/config-gfx.h"
|
||||
#include "core/log.h"
|
||||
|
||||
#include "util/log.h"
|
||||
#include "ddrhook1/config-gfx.h"
|
||||
|
||||
#define DDRHOOK1_CONFIG_GFX_WINDOWED_KEY "gfx.windowed"
|
||||
|
||||
|
||||
@@ -2,11 +2,12 @@
|
||||
|
||||
#include "cconfig/cconfig-util.h"
|
||||
|
||||
#include "core/log.h"
|
||||
|
||||
#include "ddrhook1/config-security.h"
|
||||
|
||||
#include "security/mcode.h"
|
||||
|
||||
#include "util/log.h"
|
||||
#include "util/net.h"
|
||||
|
||||
#define DDRHOOK1_CONFIG_SECURITY_MCODE_KEY "security.mcode"
|
||||
|
||||
@@ -2,11 +2,20 @@
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "avs-util/core-interop.h"
|
||||
|
||||
#include "bemanitools/ddrio.h"
|
||||
#include "bemanitools/eamio.h"
|
||||
|
||||
#include "cconfig/cconfig-hook.h"
|
||||
|
||||
#include "core/log-bt-ext.h"
|
||||
#include "core/log-bt.h"
|
||||
#include "core/log-sink-debug.h"
|
||||
#include "core/log.h"
|
||||
#include "core/thread-crt.h"
|
||||
#include "core/thread.h"
|
||||
|
||||
#include "ddrhook-util/_com4.h"
|
||||
#include "ddrhook-util/extio.h"
|
||||
#include "ddrhook-util/p3io.h"
|
||||
@@ -37,8 +46,6 @@
|
||||
|
||||
#include "util/cmdline.h"
|
||||
#include "util/defs.h"
|
||||
#include "util/log.h"
|
||||
#include "util/thread.h"
|
||||
|
||||
#define DDRHOOK1_INFO_HEADER \
|
||||
"ddrhook1 for DDR X" \
|
||||
@@ -68,6 +75,15 @@ static const struct hook_symbol init_hook_syms[] = {
|
||||
},
|
||||
};
|
||||
|
||||
static void _ddrhook1_log_init()
|
||||
{
|
||||
core_log_bt_ext_impl_set();
|
||||
core_log_bt_ext_init_with_debug();
|
||||
|
||||
// TODO change log level support
|
||||
core_log_bt_level_set(CORE_LOG_BT_LOG_LEVEL_MISC);
|
||||
}
|
||||
|
||||
static DWORD STDCALL
|
||||
my_GetModuleFileNameA(HMODULE hModule, LPSTR lpFilename, DWORD nSize)
|
||||
{
|
||||
@@ -155,7 +171,12 @@ my_GetModuleFileNameA(HMODULE hModule, LPSTR lpFilename, DWORD nSize)
|
||||
|
||||
log_info("Initializing DDR IO backend");
|
||||
|
||||
ok = ddr_io_init(thread_create, thread_join, thread_destroy);
|
||||
core_log_impl_assign(ddr_io_set_loggers);
|
||||
|
||||
ok = ddr_io_init(
|
||||
core_thread_create_impl_get(),
|
||||
core_thread_join_impl_get(),
|
||||
core_thread_destroy_impl_get());
|
||||
|
||||
if (!ok) {
|
||||
log_fatal("Couldn't initialize DDR IO backend");
|
||||
@@ -165,10 +186,12 @@ my_GetModuleFileNameA(HMODULE hModule, LPSTR lpFilename, DWORD nSize)
|
||||
if (config_ddrhook1.use_com4_emu) {
|
||||
log_info("Initializing card reader backend");
|
||||
|
||||
eam_io_set_loggers(
|
||||
log_body_misc, log_body_info, log_body_warning, log_body_fatal);
|
||||
core_log_impl_assign(eam_io_set_loggers);
|
||||
|
||||
ok = eam_io_init(thread_create, thread_join, thread_destroy);
|
||||
ok = eam_io_init(
|
||||
core_thread_create_impl_get(),
|
||||
core_thread_join_impl_get(),
|
||||
core_thread_destroy_impl_get());
|
||||
|
||||
if (!ok) {
|
||||
log_fatal("Couldn't initialize card reader backend");
|
||||
@@ -185,7 +208,12 @@ skip:
|
||||
BOOL WINAPI DllMain(HMODULE self, DWORD reason, void *ctx)
|
||||
{
|
||||
if (reason == DLL_PROCESS_ATTACH) {
|
||||
log_to_writer(log_writer_debug, NULL);
|
||||
// Use AVS APIs
|
||||
avs_util_core_interop_thread_avs_impl_set();
|
||||
|
||||
// TODO init debug logging but with avs available? why not use avs
|
||||
// logging?
|
||||
_ddrhook1_log_init();
|
||||
|
||||
hook_table_apply(
|
||||
NULL, "kernel32.dll", init_hook_syms, lengthof(init_hook_syms));
|
||||
|
||||
@@ -6,10 +6,11 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "core/log.h"
|
||||
|
||||
#include "hook/table.h"
|
||||
|
||||
#include "util/defs.h"
|
||||
#include "util/log.h"
|
||||
#include "util/mem.h"
|
||||
#include "util/str.h"
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#include "core/log.h"
|
||||
|
||||
#include "ddrhook1/master.h"
|
||||
|
||||
#include "ddrhook-util/dinput.h"
|
||||
@@ -9,7 +11,6 @@
|
||||
#include "p3ioemu/devmgr.h"
|
||||
|
||||
#include "util/defs.h"
|
||||
#include "util/log.h"
|
||||
|
||||
static HMODULE(STDCALL *real_LoadLibraryA)(const char *name);
|
||||
static BOOL(STDCALL *real_IsDebuggerPresent)();
|
||||
|
||||
Reference in New Issue
Block a user