mirror of
https://gitea.tendokyu.moe/TeamTofuShop/taitools.git
synced 2026-09-30 18:57:59 +03:00
103 lines
1.9 KiB
C
103 lines
1.9 KiB
C
#include <windows.h>
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
|
|
#include "hook/process.h"
|
|
|
|
#include "hooklib/serial.h"
|
|
|
|
#include "idmac/idmac.h"
|
|
|
|
#include "gchook/fastio.h"
|
|
#include "gchook/reader.h"
|
|
#include "gchook/config.h"
|
|
#include "gchook/gc-dll.h"
|
|
|
|
#include "platform/platform.h"
|
|
|
|
#include "util/dprintf.h"
|
|
|
|
static HMODULE gc_hook_mod;
|
|
static process_entry_t gc_startup;
|
|
static struct gc_hook_config gc_hook_cfg;
|
|
|
|
/* This hook is based on mu3hook, with leaked gchook i/o codes. */
|
|
|
|
static DWORD CALLBACK gc_pre_startup(void)
|
|
{
|
|
HRESULT hr;
|
|
|
|
dprintf("--- Begin gc_pre_startup ---\n");
|
|
|
|
/* Load config */
|
|
|
|
gc_hook_config_load(&gc_hook_cfg, L".\\taitools.ini");
|
|
|
|
/* Hook Win32 APIs */
|
|
serial_hook_init();
|
|
|
|
/* Initialize emulation hooks */
|
|
|
|
hr = platform_hook_init(
|
|
&gc_hook_cfg.platform,
|
|
2110,
|
|
gc_hook_mod);
|
|
|
|
if (FAILED(hr)) {
|
|
goto fail;
|
|
}
|
|
|
|
hr = gc_dll_init(&gc_hook_cfg.dll, gc_hook_mod);
|
|
|
|
if (FAILED(hr)) {
|
|
goto fail;
|
|
}
|
|
|
|
struct idmac_hardware idhw = {
|
|
.dipsw = 0b0000,
|
|
.jvs = gc_reader_init,
|
|
.fastio_main = gc_fastio_init,
|
|
.fastio_sub = NULL,
|
|
};
|
|
|
|
hr = idmac_hook_init(&gc_hook_cfg.idmac, &idhw);
|
|
|
|
if (FAILED(hr)) {
|
|
goto fail;
|
|
}
|
|
|
|
/* Initialize debug helpers */
|
|
|
|
dprintf("--- End gc_pre_startup ---\n");
|
|
|
|
/* Jump to EXE start address */
|
|
|
|
return gc_startup();
|
|
|
|
fail:
|
|
ExitProcess(EXIT_FAILURE);
|
|
}
|
|
|
|
BOOL WINAPI DllMain(HMODULE mod, DWORD cause, void *ctx)
|
|
{
|
|
HRESULT hr;
|
|
|
|
if (sizeof(uint64_t) == 4) {
|
|
printf("Connected\n");
|
|
}
|
|
|
|
if (cause != DLL_PROCESS_ATTACH) {
|
|
return TRUE;
|
|
}
|
|
|
|
gc_hook_mod = mod;
|
|
|
|
hr = process_hijack_startup(gc_pre_startup, &gc_startup);
|
|
|
|
if (!SUCCEEDED(hr)) {
|
|
dprintf("Failed to hijack process startup: %x\n", (int) hr);
|
|
}
|
|
|
|
return SUCCEEDED(hr);
|
|
}
|