From 3b54f3017195cd84e80eaf666495ff8bf3f699e4 Mon Sep 17 00:00:00 2001 From: Tau Date: Fri, 30 Aug 2019 19:06:32 -0400 Subject: [PATCH] mu3hook: Add initial Ongeki hook --- meson.build | 1 + mu3hook/config.c | 18 ++++++++++++ mu3hook/config.h | 16 ++++++++++ mu3hook/dllmain.c | 72 +++++++++++++++++++++++++++++++++++++++++++++ mu3hook/meson.build | 28 ++++++++++++++++++ mu3hook/mu3hook.def | 1 + 6 files changed, 136 insertions(+) create mode 100644 mu3hook/config.c create mode 100644 mu3hook/config.h create mode 100644 mu3hook/dllmain.c create mode 100644 mu3hook/meson.build create mode 100644 mu3hook/mu3hook.def diff --git a/meson.build b/meson.build index 3ee6f9f..7dce095 100644 --- a/meson.build +++ b/meson.build @@ -48,4 +48,5 @@ subdir('chunihook') subdir('divahook') subdir('idzhook') subdir('minihook') +subdir('mu3hook') subdir('zinput') diff --git a/mu3hook/config.c b/mu3hook/config.c new file mode 100644 index 0000000..14b552a --- /dev/null +++ b/mu3hook/config.c @@ -0,0 +1,18 @@ +#include + +#include "board/config.h" + +#include "mu3hook/config.h" + +#include "platform/config.h" + +void mu3_hook_config_load( + struct mu3_hook_config *cfg, + const wchar_t *filename) +{ + assert(cfg != NULL); + assert(filename != NULL); + + alls_config_load(&cfg->alls, filename); + aime_config_load(&cfg->aime, filename); +} diff --git a/mu3hook/config.h b/mu3hook/config.h new file mode 100644 index 0000000..c2f0de9 --- /dev/null +++ b/mu3hook/config.h @@ -0,0 +1,16 @@ +#pragma once + +#include + +#include "board/config.h" + +#include "platform/config.h" + +struct mu3_hook_config { + struct alls_config alls; + struct aime_config aime; +}; + +void mu3_hook_config_load( + struct mu3_hook_config *cfg, + const wchar_t *filename); diff --git a/mu3hook/dllmain.c b/mu3hook/dllmain.c new file mode 100644 index 0000000..b5204cf --- /dev/null +++ b/mu3hook/dllmain.c @@ -0,0 +1,72 @@ +#include + +#include "board/io4.h" +#include "board/sg-reader.h" +#include "board/vfd.h" + +#include "hook/process.h" + +#include "hooklib/clock.h" +#include "hooklib/serial.h" +#include "hooklib/spike.h" + +#include "mu3hook/config.h" +#include "mu3hook/io4.h" + +#include "platform/platform.h" + +#include "util/dprintf.h" + +static HMODULE mu3_hook_mod; +static process_entry_t mu3_startup; +static struct mu3_hook_config mu3_hook_cfg; + +static DWORD CALLBACK mu3_pre_startup(void) +{ + dprintf("--- Begin mu3_pre_startup ---\n"); + + /* Load config */ + + mu3_hook_config_load(&mu3_hook_cfg, L".\\segatools.ini"); + + /* Hook Win32 APIs */ + + clock_write_hook_init(); + serial_hook_init(); + + /* Initialize emulation hooks */ + + platform_hook_init_alls(&mu3_hook_cfg.alls, "SDDT", "AAV2", mu3_hook_mod); + sg_reader_hook_init(&mu3_hook_cfg.aime, 1); + vfd_hook_init(2); + mu3_io4_hook_init(); + + /* Initialize debug helpers */ + + spike_hook_init("mu3spike.txt"); + + dprintf("--- End mu3_pre_startup ---\n"); + + /* Jump to EXE start address */ + + return mu3_startup(); +} + +BOOL WINAPI DllMain(HMODULE mod, DWORD cause, void *ctx) +{ + HRESULT hr; + + if (cause != DLL_PROCESS_ATTACH) { + return TRUE; + } + + mu3_hook_mod = mod; + + hr = process_hijack_startup(mu3_pre_startup, &mu3_startup); + + if (!SUCCEEDED(hr)) { + dprintf("Failed to hijack process startup: %x\n", (int) hr); + } + + return SUCCEEDED(hr); +} diff --git a/mu3hook/meson.build b/mu3hook/meson.build new file mode 100644 index 0000000..66293dc --- /dev/null +++ b/mu3hook/meson.build @@ -0,0 +1,28 @@ +shared_library( + 'mu3hook', + name_prefix : '', + include_directories : inc, + implicit_include_directories : false, + vs_module_defs : 'mu3hook.def', + c_pch : '../precompiled.h', + dependencies : [ + capnhook.get_variable('hook_dep'), + capnhook.get_variable('hooklib_dep'), + xinput_lib, + ], + link_with : [ + aimeio_dll, + board_lib, + hooklib_lib, + mu3io_dll, + platform_lib, + util_lib, + ], + sources : [ + 'config.c', + 'config.h', + 'dllmain.c', + 'io4.c', + 'io4.h', + ], +) diff --git a/mu3hook/mu3hook.def b/mu3hook/mu3hook.def new file mode 100644 index 0000000..cd7d5bb --- /dev/null +++ b/mu3hook/mu3hook.def @@ -0,0 +1 @@ +LIBRARY mu3hook