segatools/tokyohook/dllmain.c
2024-08-20 13:32:35 +02:00

113 lines
2.1 KiB
C

/*
"Mario & Sonic at the Tokyo 2020 Olympics Arcade" (tokyo) hook
Devices
USB: 837-15257 "Type 4" I/O Board
COM1: 837-15093-04 LED Controller Board
*/
#include <windows.h>
#include <stdlib.h>
#include "board/io4.h"
#include "hook/process.h"
#include "hooklib/dvd.h"
#include "hooklib/serial.h"
#include "hooklib/spike.h"
#include "tokyohook/config.h"
#include "tokyohook/io4.h"
#include "tokyohook/tokyo-dll.h"
#include "platform/platform.h"
#include "util/dprintf.h"
static HMODULE tokyo_hook_mod;
static process_entry_t tokyo_startup;
static struct tokyo_hook_config tokyo_hook_cfg;
static DWORD CALLBACK tokyo_pre_startup(void)
{
HRESULT hr;
dprintf("--- Begin tokyo_pre_startup ---\n");
/* Load config */
tokyo_hook_config_load(&tokyo_hook_cfg, L".\\segatools.ini");
/* Hook Win32 APIs */
dvd_hook_init(&tokyo_hook_cfg.dvd, tokyo_hook_mod);
zinput_hook_init(&tokyo_hook_cfg.zinput);
serial_hook_init();
/* Initialize emulation hooks */
hr = platform_hook_init(
&tokyo_hook_cfg.platform,
"SDFV",
"ACA1",
tokyo_hook_mod);
if (FAILED(hr)) {
goto fail;
}
hr = tokyo_dll_init(&tokyo_hook_cfg.dll, tokyo_hook_mod);
if (FAILED(hr)) {
goto fail;
}
hr = led15093_hook_init(&tokyo_hook_cfg.led15093,
tokyo_dll.led_init, tokyo_dll.led_set_leds, 1, 1, 1, 2);
if (FAILED(hr)) {
return hr;
}
hr = tokyo_io4_hook_init(&tokyo_hook_cfg.io4);
if (FAILED(hr)) {
goto fail;
}
/* Initialize debug helpers */
spike_hook_init(L".\\segatools.ini");
dprintf("--- End tokyo_pre_startup ---\n");
/* Jump to EXE start address */
return tokyo_startup();
fail:
ExitProcess(EXIT_FAILURE);
}
BOOL WINAPI DllMain(HMODULE mod, DWORD cause, void *ctx)
{
HRESULT hr;
if (cause != DLL_PROCESS_ATTACH) {
return TRUE;
}
tokyo_hook_mod = mod;
hr = process_hijack_startup(tokyo_pre_startup, &tokyo_startup);
if (!SUCCEEDED(hr)) {
dprintf("Failed to hijack process startup: %x\n", (int) hr);
}
return SUCCEEDED(hr);
}