2019-08-31 01:06:32 +02:00
|
|
|
#include <windows.h>
|
|
|
|
|
|
|
|
#include "board/io4.h"
|
|
|
|
#include "board/sg-reader.h"
|
|
|
|
#include "board/vfd.h"
|
|
|
|
|
|
|
|
#include "hook/process.h"
|
|
|
|
|
|
|
|
#include "hooklib/serial.h"
|
|
|
|
#include "hooklib/spike.h"
|
|
|
|
|
|
|
|
#include "mu3hook/config.h"
|
|
|
|
#include "mu3hook/io4.h"
|
2020-03-13 06:30:18 +01:00
|
|
|
#include "mu3hook/unity.h"
|
2019-08-31 01:06:32 +02:00
|
|
|
|
|
|
|
#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)
|
|
|
|
{
|
2019-11-06 00:03:24 +01:00
|
|
|
HRESULT hr;
|
|
|
|
|
2019-08-31 01:06:32 +02:00
|
|
|
dprintf("--- Begin mu3_pre_startup ---\n");
|
|
|
|
|
|
|
|
/* Load config */
|
|
|
|
|
|
|
|
mu3_hook_config_load(&mu3_hook_cfg, L".\\segatools.ini");
|
|
|
|
|
|
|
|
/* Hook Win32 APIs */
|
|
|
|
|
2020-03-23 07:53:48 +01:00
|
|
|
gfx_hook_init(&mu3_hook_cfg.gfx);
|
2019-08-31 01:06:32 +02:00
|
|
|
serial_hook_init();
|
|
|
|
|
|
|
|
/* Initialize emulation hooks */
|
|
|
|
|
2019-11-06 00:03:24 +01:00
|
|
|
hr = platform_hook_init(
|
|
|
|
&mu3_hook_cfg.platform,
|
|
|
|
"SDDT",
|
2020-03-23 08:31:58 +01:00
|
|
|
"ACA1",
|
2019-11-06 00:03:24 +01:00
|
|
|
mu3_hook_mod);
|
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = sg_reader_hook_init(&mu3_hook_cfg.aime, 1);
|
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = vfd_hook_init(2);
|
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = mu3_io4_hook_init();
|
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
return hr;
|
|
|
|
}
|
2019-08-31 01:06:32 +02:00
|
|
|
|
2020-03-23 08:31:58 +01: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. */
|
|
|
|
|
|
|
|
unity_hook_init();
|
|
|
|
|
2019-08-31 01:06:32 +02:00
|
|
|
/* Initialize debug helpers */
|
|
|
|
|
2019-10-19 22:15:14 +02:00
|
|
|
spike_hook_init(L".\\segatools.ini");
|
2019-08-31 01:06:32 +02:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|