forked from Dniel97/segatools
140 lines
2.9 KiB
C
140 lines
2.9 KiB
C
/*
|
|
"ALLS.NET PRAS MULTI 3" (apm3) hook
|
|
|
|
Devices
|
|
|
|
USB: 837-15257-01 "Type 4" I/O Board
|
|
USB: 838-20006 "WinTouch" Controller Board
|
|
COM1: 200-6275 VFD GP1232A02A FUTABA Board
|
|
COM2: 837-15093-06 LED Controller Board
|
|
COM3: 837-15396 "Gen 3" Aime Reader
|
|
*/
|
|
|
|
#include <windows.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "board/io4.h"
|
|
#include "board/sg-reader.h"
|
|
#include "board/vfd.h"
|
|
|
|
#include "hook/process.h"
|
|
|
|
#include "hooklib/dvd.h"
|
|
#include "hooklib/touch.h"
|
|
#include "hooklib/serial.h"
|
|
#include "hooklib/spike.h"
|
|
|
|
#include "apm3hook/config.h"
|
|
#include "apm3hook/io4.h"
|
|
#include "apm3hook/apm3-dll.h"
|
|
|
|
#include "platform/platform.h"
|
|
|
|
#include "unityhook/hook.h"
|
|
|
|
#include "util/dprintf.h"
|
|
|
|
static HMODULE apm3_hook_mod;
|
|
static process_entry_t apm3_startup;
|
|
static struct apm3_hook_config apm3_hook_cfg;
|
|
|
|
static DWORD CALLBACK apm3_pre_startup(void)
|
|
{
|
|
HRESULT hr;
|
|
|
|
dprintf("--- Begin apm3_pre_startup ---\n");
|
|
|
|
/* Load config */
|
|
|
|
apm3_hook_config_load(&apm3_hook_cfg, L".\\segatools.ini");
|
|
|
|
/* Hook Win32 APIs */
|
|
|
|
dvd_hook_init(&apm3_hook_cfg.dvd, apm3_hook_mod);
|
|
touch_screen_hook_init(&apm3_hook_cfg.touch, apm3_hook_mod);
|
|
serial_hook_init();
|
|
|
|
/* Initialize emulation hooks */
|
|
|
|
hr = platform_hook_init(
|
|
&apm3_hook_cfg.platform,
|
|
"SDEM",
|
|
"ACA1",
|
|
apm3_hook_mod);
|
|
|
|
if (FAILED(hr)) {
|
|
goto fail;
|
|
}
|
|
|
|
hr = apm3_dll_init(&apm3_hook_cfg.dll, apm3_hook_mod);
|
|
|
|
if (FAILED(hr)) {
|
|
goto fail;
|
|
}
|
|
|
|
hr = led15093_hook_init(&apm3_hook_cfg.led15093,
|
|
apm3_dll.led_init, apm3_dll.led_set_leds, 2, 1, 1, 2);
|
|
|
|
if (FAILED(hr)) {
|
|
return hr;
|
|
}
|
|
|
|
hr = sg_reader_hook_init(&apm3_hook_cfg.aime, 3, 1, apm3_hook_mod);
|
|
|
|
if (FAILED(hr)) {
|
|
goto fail;
|
|
}
|
|
|
|
hr = vfd_hook_init(&apm3_hook_cfg.vfd, 1);
|
|
|
|
if (FAILED(hr)) {
|
|
goto fail;
|
|
}
|
|
|
|
hr = apm3_io4_hook_init(&apm3_hook_cfg.io4);
|
|
|
|
if (FAILED(hr)) {
|
|
goto fail;
|
|
}
|
|
|
|
/* Initialize Unity native plugin DLL hooks
|
|
|
|
There seems to be an issue with other DLL hooks if `LoadLibraryW` is
|
|
hooked earlier in the `apm3hook` initialization. */
|
|
|
|
unity_hook_init(&apm3_hook_cfg.unity, apm3_hook_mod);
|
|
|
|
/* Initialize debug helpers */
|
|
|
|
spike_hook_init(L".\\segatools.ini");
|
|
|
|
dprintf("--- End apm3_pre_startup ---\n");
|
|
|
|
/* Jump to EXE start address */
|
|
|
|
return apm3_startup();
|
|
|
|
fail:
|
|
ExitProcess(EXIT_FAILURE);
|
|
}
|
|
|
|
BOOL WINAPI DllMain(HMODULE mod, DWORD cause, void *ctx)
|
|
{
|
|
HRESULT hr;
|
|
|
|
if (cause != DLL_PROCESS_ATTACH) {
|
|
return TRUE;
|
|
}
|
|
|
|
apm3_hook_mod = mod;
|
|
|
|
hr = process_hijack_startup(apm3_pre_startup, &apm3_startup);
|
|
|
|
if (!SUCCEEDED(hr)) {
|
|
dprintf("Failed to hijack process startup: %x\n", (int) hr);
|
|
}
|
|
|
|
return SUCCEEDED(hr);
|
|
}
|