2023-07-13 22:52:50 +00:00
|
|
|
#include <windows.h>
|
|
|
|
#include <shlwapi.h>
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "board/sg-reader.h"
|
|
|
|
#include "board/io4.h"
|
|
|
|
#include "board/vfd.h"
|
|
|
|
|
|
|
|
#include "hook/process.h"
|
|
|
|
|
|
|
|
#include "hooklib/dvd.h"
|
|
|
|
#include "hooklib/serial.h"
|
|
|
|
#include "hooklib/spike.h"
|
|
|
|
|
|
|
|
#include "swdchook/config.h"
|
|
|
|
#include "swdchook/swdc-dll.h"
|
|
|
|
#include "swdchook/io4.h"
|
|
|
|
|
|
|
|
#include "platform/platform.h"
|
|
|
|
|
|
|
|
#include "util/dprintf.h"
|
|
|
|
|
|
|
|
static HMODULE swdc_hook_mod;
|
|
|
|
static process_entry_t swdc_startup;
|
|
|
|
static struct swdc_hook_config swdc_hook_cfg;
|
|
|
|
|
|
|
|
static DWORD CALLBACK swdc_pre_startup(void)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
dprintf("--- Begin swdc_pre_startup ---\n");
|
|
|
|
|
|
|
|
/* Config load */
|
|
|
|
|
|
|
|
swdc_hook_config_load(&swdc_hook_cfg, L".\\segatools.ini");
|
|
|
|
|
|
|
|
/* Hook Win32 APIs */
|
|
|
|
|
|
|
|
serial_hook_init();
|
|
|
|
dvd_hook_init(&swdc_hook_cfg.dvd, swdc_hook_mod);
|
|
|
|
|
|
|
|
/* Initialize emulation hooks */
|
|
|
|
|
|
|
|
hr = platform_hook_init(
|
|
|
|
&swdc_hook_cfg.platform,
|
|
|
|
"SDDS",
|
|
|
|
"ACA4",
|
|
|
|
swdc_hook_mod);
|
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2024-01-16 16:56:24 +00:00
|
|
|
hr = swdc_dll_init(&swdc_hook_cfg.dll, swdc_hook_mod);
|
2023-07-13 22:52:50 +00:00
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2024-01-16 16:56:24 +00:00
|
|
|
hr = sg_reader_hook_init(&swdc_hook_cfg.aime, 3, 3, swdc_hook_mod);
|
2023-07-13 22:52:50 +00:00
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
2024-01-16 16:56:24 +00:00
|
|
|
goto fail;
|
2023-07-13 22:52:50 +00:00
|
|
|
}
|
|
|
|
|
2024-01-16 16:56:24 +00:00
|
|
|
hr = vfd_hook_init(4);
|
2023-07-13 22:52:50 +00:00
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
2024-01-16 16:56:24 +00:00
|
|
|
return hr;
|
2023-07-13 22:52:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
hr = swdc_io4_hook_init(&swdc_hook_cfg.io4);
|
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2024-01-16 16:56:24 +00:00
|
|
|
/* Hook external DLL APIs */
|
|
|
|
|
|
|
|
zinput_hook_init(&swdc_hook_cfg.zinput);
|
|
|
|
|
2023-07-13 22:52:50 +00:00
|
|
|
/* Initialize debug helpers */
|
|
|
|
|
|
|
|
spike_hook_init(L".\\segatools.ini");
|
|
|
|
|
|
|
|
dprintf("--- End swdc_pre_startup ---\n");
|
|
|
|
|
|
|
|
/* Jump to EXE start address */
|
|
|
|
|
|
|
|
return swdc_startup();
|
|
|
|
|
|
|
|
fail:
|
|
|
|
ExitProcess(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WINAPI DllMain(HMODULE mod, DWORD cause, void *ctx)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if (cause != DLL_PROCESS_ATTACH) {
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
swdc_hook_mod = mod;
|
|
|
|
|
|
|
|
hr = process_hijack_startup(swdc_pre_startup, &swdc_startup);
|
|
|
|
|
|
|
|
if (!SUCCEEDED(hr)) {
|
|
|
|
dprintf("Failed to hijack process startup: %x\n", (int) hr);
|
|
|
|
}
|
|
|
|
|
|
|
|
return SUCCEEDED(hr);
|
|
|
|
}
|