2024-06-23 19:04:08 +00:00
|
|
|
/*
|
|
|
|
"O.N.G.E.K.I." (mu3) hook
|
|
|
|
|
|
|
|
Devices
|
|
|
|
|
|
|
|
USB: 837-15257-01 "Type 4" I/O Board
|
|
|
|
USB: 3 * 601-13216 USB "QR Code" Camera (SDDT1-SDDT3)
|
|
|
|
COM1: 837-15396 "Gen 3" Aime Reader
|
|
|
|
COM2: 200-6275 VFD GP1232A02A FUTABA Board
|
|
|
|
COM3: 837-15093-06 LED Controller Board
|
|
|
|
*/
|
|
|
|
|
2019-08-30 23:06:32 +00:00
|
|
|
#include <windows.h>
|
|
|
|
|
2021-05-23 18:17:14 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2019-08-30 23:06:32 +00:00
|
|
|
#include "board/sg-reader.h"
|
|
|
|
#include "board/vfd.h"
|
|
|
|
|
2021-11-03 17:14:24 +00:00
|
|
|
#include "gfxhook/d3d9.h"
|
|
|
|
#include "gfxhook/d3d11.h"
|
|
|
|
#include "gfxhook/dxgi.h"
|
|
|
|
#include "gfxhook/gfx.h"
|
|
|
|
|
2019-08-30 23:06:32 +00:00
|
|
|
#include "hook/process.h"
|
|
|
|
|
2021-06-16 10:08:08 +00:00
|
|
|
#include "hooklib/dvd.h"
|
2019-08-30 23:06:32 +00:00
|
|
|
#include "hooklib/serial.h"
|
|
|
|
#include "hooklib/spike.h"
|
|
|
|
|
|
|
|
#include "mu3hook/config.h"
|
|
|
|
#include "mu3hook/io4.h"
|
2021-06-06 18:23:55 +00:00
|
|
|
#include "mu3hook/mu3-dll.h"
|
2019-08-30 23:06:32 +00:00
|
|
|
|
|
|
|
#include "platform/platform.h"
|
|
|
|
|
2024-04-15 19:30:28 +00:00
|
|
|
#include "unityhook/config.h"
|
|
|
|
#include "unityhook/hook.h"
|
|
|
|
|
2019-08-30 23:06:32 +00:00
|
|
|
#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)
|
|
|
|
{
|
2019-11-05 23:03:24 +00:00
|
|
|
HRESULT hr;
|
|
|
|
|
2019-08-30 23:06:32 +00:00
|
|
|
dprintf("--- Begin mu3_pre_startup ---\n");
|
|
|
|
|
|
|
|
/* Load config */
|
|
|
|
|
|
|
|
mu3_hook_config_load(&mu3_hook_cfg, L".\\segatools.ini");
|
|
|
|
|
|
|
|
/* Hook Win32 APIs */
|
|
|
|
|
2021-06-16 10:08:08 +00:00
|
|
|
dvd_hook_init(&mu3_hook_cfg.dvd, mu3_hook_mod);
|
2021-12-22 04:32:33 +00:00
|
|
|
gfx_hook_init(&mu3_hook_cfg.gfx);
|
2021-10-25 09:16:14 +00:00
|
|
|
gfx_d3d9_hook_init(&mu3_hook_cfg.gfx, mu3_hook_mod);
|
|
|
|
gfx_d3d11_hook_init(&mu3_hook_cfg.gfx, mu3_hook_mod);
|
|
|
|
gfx_dxgi_hook_init(&mu3_hook_cfg.gfx, mu3_hook_mod);
|
2019-08-30 23:06:32 +00:00
|
|
|
serial_hook_init();
|
|
|
|
|
|
|
|
/* Initialize emulation hooks */
|
|
|
|
|
2019-11-05 23:03:24 +00:00
|
|
|
hr = platform_hook_init(
|
|
|
|
&mu3_hook_cfg.platform,
|
|
|
|
"SDDT",
|
2020-03-23 07:31:58 +00:00
|
|
|
"ACA1",
|
2019-11-05 23:03:24 +00:00
|
|
|
mu3_hook_mod);
|
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
2021-05-23 18:17:14 +00:00
|
|
|
goto fail;
|
2019-11-05 23:03:24 +00:00
|
|
|
}
|
|
|
|
|
2024-05-12 17:36:08 +00:00
|
|
|
hr = mu3_dll_init(&mu3_hook_cfg.dll, mu3_hook_mod);
|
2023-12-03 20:34:38 +00:00
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
2024-05-12 17:36:08 +00:00
|
|
|
goto fail;
|
2023-12-03 20:34:38 +00:00
|
|
|
}
|
|
|
|
|
2024-05-12 17:36:08 +00:00
|
|
|
hr = led15093_hook_init(&mu3_hook_cfg.led15093,
|
|
|
|
mu3_dll.led_init, mu3_dll.led_set_leds, 3, 1, 1, 2);
|
2019-11-05 23:03:24 +00:00
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
2024-05-12 17:36:08 +00:00
|
|
|
return hr;
|
2019-11-05 23:03:24 +00:00
|
|
|
}
|
|
|
|
|
2024-05-12 17:36:08 +00:00
|
|
|
hr = sg_reader_hook_init(&mu3_hook_cfg.aime, 1, 1, mu3_hook_mod);
|
2019-11-05 23:03:24 +00:00
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
2021-05-23 18:17:14 +00:00
|
|
|
goto fail;
|
2019-11-05 23:03:24 +00:00
|
|
|
}
|
|
|
|
|
2024-05-12 17:36:08 +00:00
|
|
|
hr = vfd_hook_init(&mu3_hook_cfg.vfd, 2);
|
2021-06-06 18:23:55 +00:00
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2020-10-07 17:26:12 +00:00
|
|
|
hr = mu3_io4_hook_init(&mu3_hook_cfg.io4);
|
2019-11-05 23:03:24 +00:00
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
2021-05-23 18:17:14 +00:00
|
|
|
goto fail;
|
2019-11-05 23:03:24 +00:00
|
|
|
}
|
2019-08-30 23:06:32 +00:00
|
|
|
|
2020-03-23 07:31:58 +00:00
|
|
|
/* Initialize Unity native plugin DLL hooks
|
|
|
|
|
|
|
|
There seems to be an issue with other DLL hooks if `LoadLibraryW` is
|
|
|
|
hooked earlier in the `mu3hook` initialization. */
|
|
|
|
|
2024-04-15 19:30:28 +00:00
|
|
|
unity_hook_init(&mu3_hook_cfg.unity, mu3_hook_mod);
|
2020-03-23 07:31:58 +00:00
|
|
|
|
2019-08-30 23:06:32 +00:00
|
|
|
/* Initialize debug helpers */
|
|
|
|
|
2019-10-19 20:15:14 +00:00
|
|
|
spike_hook_init(L".\\segatools.ini");
|
2019-08-30 23:06:32 +00:00
|
|
|
|
|
|
|
dprintf("--- End mu3_pre_startup ---\n");
|
|
|
|
|
|
|
|
/* Jump to EXE start address */
|
|
|
|
|
|
|
|
return mu3_startup();
|
2021-05-23 18:17:14 +00:00
|
|
|
|
|
|
|
fail:
|
|
|
|
ExitProcess(EXIT_FAILURE);
|
2019-08-30 23:06:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|