diff --git a/Makefile b/Makefile index 28562a1..0381552 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,8 @@ V ?= @ BUILD_DIR := build BUILD_DIR_32 := $(BUILD_DIR)/build32 BUILD_DIR_64 := $(BUILD_DIR)/build64 +BUILD_DIR_GAMES_32 := $(BUILD_DIR_32)/games +BUILD_DIR_GAMES_64 := $(BUILD_DIR_64)/games BUILD_DIR_ZIP := $(BUILD_DIR)/zip DOC_DIR := doc diff --git a/Package.mk b/Package.mk index 5647e9b..ae87f73 100644 --- a/Package.mk +++ b/Package.mk @@ -3,7 +3,7 @@ $(BUILD_DIR_ZIP)/chuni.zip: $(V)mkdir -p $(BUILD_DIR_ZIP)/chuni $(V)mkdir -p $(BUILD_DIR_ZIP)/chuni/DEVICE $(V)cp $(BUILD_DIR_32)/subprojects/capnhook/inject/inject.exe \ - $(BUILD_DIR_32)/chunihook/chunihook.dll \ + $(BUILD_DIR_GAMES_32)/chunihook/chunihook.dll \ $(DIST_DIR)/chuni/segatools.ini \ $(DIST_DIR)/chuni/launch.bat \ $(BUILD_DIR_ZIP)/chuni @@ -18,7 +18,7 @@ $(BUILD_DIR_ZIP)/cxb.zip: $(V)mkdir -p $(BUILD_DIR_ZIP)/cxb $(V)mkdir -p $(BUILD_DIR_ZIP)/cxb/DEVICE $(V)cp $(BUILD_DIR_32)/subprojects/capnhook/inject/inject.exe \ - $(BUILD_DIR_32)/cxbhook/cxbhook.dll \ + $(BUILD_DIR_GAMES_32)/cxbhook/cxbhook.dll \ $(DIST_DIR)/cxb/segatools.ini \ $(DIST_DIR)/cxb/launch.bat \ $(BUILD_DIR_ZIP)/cxb @@ -33,7 +33,7 @@ $(BUILD_DIR_ZIP)/diva.zip: $(V)mkdir -p $(BUILD_DIR_ZIP)/diva $(V)mkdir -p $(BUILD_DIR_ZIP)/diva/DEVICE $(V)cp $(BUILD_DIR_64)/subprojects/capnhook/inject/inject.exe \ - $(BUILD_DIR_64)/divahook/divahook.dll \ + $(BUILD_DIR_GAMES_64)/divahook/divahook.dll \ $(DIST_DIR)/diva/segatools.ini \ $(DIST_DIR)/diva/launch.bat \ $(BUILD_DIR_ZIP)/diva @@ -48,7 +48,7 @@ $(BUILD_DIR_ZIP)/carol.zip: $(V)mkdir -p $(BUILD_DIR_ZIP)/carol $(V)mkdir -p $(BUILD_DIR_ZIP)/carol/DEVICE $(V)cp $(BUILD_DIR_32)/subprojects/capnhook/inject/inject.exe \ - $(BUILD_DIR_32)/carolhook/carolhook.dll \ + $(BUILD_DIR_GAMES_32)/carolhook/carolhook.dll \ $(DIST_DIR)/carol/segatools.ini \ $(DIST_DIR)/carol/launch.bat \ $(BUILD_DIR_ZIP)/carol @@ -63,7 +63,7 @@ $(BUILD_DIR_ZIP)/idz.zip: $(V)mkdir -p $(BUILD_DIR_ZIP)/idz $(V)mkdir -p $(BUILD_DIR_ZIP)/idz/DEVICE $(V)cp $(BUILD_DIR_64)/subprojects/capnhook/inject/inject.exe \ - $(BUILD_DIR_64)/idzhook/idzhook.dll \ + $(BUILD_DIR_GAMES_64)/idzhook/idzhook.dll \ $(DIST_DIR)/idz/segatools.ini \ $(DIST_DIR)/idz/launch.bat \ $(BUILD_DIR_ZIP)/idz @@ -78,7 +78,7 @@ $(BUILD_DIR_ZIP)/fgo.zip: $(V)mkdir -p $(BUILD_DIR_ZIP)/fgo $(V)mkdir -p $(BUILD_DIR_ZIP)/fgo/DEVICE $(V)cp $(BUILD_DIR_64)/subprojects/capnhook/inject/inject.exe \ - $(BUILD_DIR_64)/fgohook/fgohook.dll \ + $(BUILD_DIR_GAMES_64)/fgohook/fgohook.dll \ $(DIST_DIR)/fgo/segatools.ini \ $(DIST_DIR)/fgo/launch.bat \ $(BUILD_DIR_ZIP)/fgo @@ -93,7 +93,7 @@ $(BUILD_DIR_ZIP)/idac.zip: $(V)mkdir -p $(BUILD_DIR_ZIP)/idac $(V)mkdir -p $(BUILD_DIR_ZIP)/idac/DEVICE $(V)cp $(BUILD_DIR_64)/subprojects/capnhook/inject/inject.exe \ - $(BUILD_DIR_64)/idachook/idachook.dll \ + $(BUILD_DIR_GAMES_64)/idachook/idachook.dll \ $(DIST_DIR)/idac/segatools.ini \ $(DIST_DIR)/idac/config_hook.json \ $(DIST_DIR)/idac/launch.bat \ @@ -109,7 +109,7 @@ $(BUILD_DIR_ZIP)/swdc.zip: $(V)mkdir -p $(BUILD_DIR_ZIP)/swdc $(V)mkdir -p $(BUILD_DIR_ZIP)/swdc/DEVICE $(V)cp $(BUILD_DIR_64)/subprojects/capnhook/inject/inject.exe \ - $(BUILD_DIR_64)/swdchook/swdchook.dll \ + $(BUILD_DIR_GAMES_64)/swdchook/swdchook.dll \ $(DIST_DIR)/swdc/segatools.ini \ $(DIST_DIR)/swdc/config_hook.json \ $(DIST_DIR)/swdc/launch.bat \ @@ -125,7 +125,7 @@ $(BUILD_DIR_ZIP)/mercury.zip: $(V)mkdir -p $(BUILD_DIR_ZIP)/mercury $(V)mkdir -p $(BUILD_DIR_ZIP)/mercury/DEVICE $(V)cp $(BUILD_DIR_64)/subprojects/capnhook/inject/inject.exe \ - $(BUILD_DIR_64)/mercuryhook/mercuryhook.dll \ + $(BUILD_DIR_GAMES_64)/mercuryhook/mercuryhook.dll \ $(DIST_DIR)/mercury/segatools.ini \ $(DIST_DIR)/mercury/launch.bat \ $(BUILD_DIR_ZIP)/mercury @@ -143,9 +143,9 @@ $(BUILD_DIR_ZIP)/chusan.zip: $(DIST_DIR)/chusan/config_hook.json \ $(DIST_DIR)/chusan/launch.bat \ $(BUILD_DIR_ZIP)/chusan - $(V)cp $(BUILD_DIR_32)/chusanhook/chusanhook.dll \ + $(V)cp $(BUILD_DIR_GAMES_32)/chusanhook/chusanhook.dll \ $(BUILD_DIR_ZIP)/chusan/chusanhook_x86.dll - $(V)cp $(BUILD_DIR_64)/chusanhook/chusanhook.dll \ + $(V)cp $(BUILD_DIR_GAMES_64)/chusanhook/chusanhook.dll \ $(BUILD_DIR_ZIP)/chusan/chusanhook_x64.dll $(V)cp $(BUILD_DIR_32)/subprojects/capnhook/inject/inject.exe \ $(BUILD_DIR_ZIP)/chusan/inject_x86.exe @@ -162,7 +162,7 @@ $(BUILD_DIR_ZIP)/mu3.zip: $(V)mkdir -p $(BUILD_DIR_ZIP)/mu3 $(V)mkdir -p $(BUILD_DIR_ZIP)/mu3/DEVICE $(V)cp $(BUILD_DIR_64)/subprojects/capnhook/inject/inject.exe \ - $(BUILD_DIR_64)/mu3hook/mu3hook.dll \ + $(BUILD_DIR_GAMES_64)/mu3hook/mu3hook.dll \ $(DIST_DIR)/mu3/segatools.ini \ $(DIST_DIR)/mu3/launch.bat \ $(BUILD_DIR_ZIP)/mu3 @@ -177,7 +177,7 @@ $(BUILD_DIR_ZIP)/mai2.zip: $(V)mkdir -p $(BUILD_DIR_ZIP)/mai2 $(V)mkdir -p $(BUILD_DIR_ZIP)/mai2/DEVICE $(V)cp $(BUILD_DIR_64)/subprojects/capnhook/inject/inject.exe \ - $(BUILD_DIR_64)/mai2hook/mai2hook.dll \ + $(BUILD_DIR_GAMES_64)/mai2hook/mai2hook.dll \ $(DIST_DIR)/mai2/segatools.ini \ $(DIST_DIR)/mai2/launch.bat \ $(BUILD_DIR_ZIP)/mai2 @@ -192,7 +192,7 @@ $(BUILD_DIR_ZIP)/cm.zip: $(V)mkdir -p $(BUILD_DIR_ZIP)/cm $(V)mkdir -p $(BUILD_DIR_ZIP)/cm/DEVICE $(V)cp $(BUILD_DIR_64)/subprojects/capnhook/inject/inject.exe \ - $(BUILD_DIR_64)/cmhook/cmhook.dll \ + $(BUILD_DIR_GAMES_64)/cmhook/cmhook.dll \ $(DIST_DIR)/cm/config_hook.json \ $(DIST_DIR)/cm/segatools.ini \ $(DIST_DIR)/cm/launch.bat \ @@ -208,7 +208,7 @@ $(BUILD_DIR_ZIP)/tokyo.zip: $(V)mkdir -p $(BUILD_DIR_ZIP)/tokyo $(V)mkdir -p $(BUILD_DIR_ZIP)/tokyo/DEVICE $(V)cp $(BUILD_DIR_64)/subprojects/capnhook/inject/inject.exe \ - $(BUILD_DIR_64)/tokyohook/tokyohook.dll \ + $(BUILD_DIR_GAMES_64)/tokyohook/tokyohook.dll \ $(DIST_DIR)/tokyo/config_hook.json \ $(DIST_DIR)/tokyo/segatools.ini \ $(DIST_DIR)/tokyo/launch.bat \ @@ -226,9 +226,9 @@ $(BUILD_DIR_ZIP)/kemono.zip: $(V)cp $(DIST_DIR)/kemono/segatools.ini \ $(DIST_DIR)/kemono/launch.bat \ $(BUILD_DIR_ZIP)/kemono - $(V)cp $(BUILD_DIR_32)/kemonohook/kemonohook.dll \ + $(V)cp $(BUILD_DIR_GAMES_32)/kemonohook/kemonohook.dll \ $(BUILD_DIR_ZIP)/kemono/kemonohook_x86.dll - $(V)cp $(BUILD_DIR_64)/kemonohook/kemonohook.dll \ + $(V)cp $(BUILD_DIR_GAMES_64)/kemonohook/kemonohook.dll \ $(BUILD_DIR_ZIP)/kemono/kemonohook_x64.dll $(V)cp $(BUILD_DIR_32)/subprojects/capnhook/inject/inject.exe \ $(BUILD_DIR_ZIP)/kemono/inject_x86.exe diff --git a/aimeio/aimeio.c b/common/aimeio/aimeio.c similarity index 100% rename from aimeio/aimeio.c rename to common/aimeio/aimeio.c diff --git a/aimeio/aimeio.h b/common/aimeio/aimeio.h similarity index 100% rename from aimeio/aimeio.h rename to common/aimeio/aimeio.h diff --git a/aimeio/meson.build b/common/aimeio/meson.build similarity index 100% rename from aimeio/meson.build rename to common/aimeio/meson.build diff --git a/amex/amex.c b/common/amex/amex.c similarity index 100% rename from amex/amex.c rename to common/amex/amex.c diff --git a/amex/amex.h b/common/amex/amex.h similarity index 100% rename from amex/amex.h rename to common/amex/amex.h diff --git a/amex/config.c b/common/amex/config.c similarity index 100% rename from amex/config.c rename to common/amex/config.c diff --git a/amex/config.h b/common/amex/config.h similarity index 100% rename from amex/config.h rename to common/amex/config.h diff --git a/amex/ds.c b/common/amex/ds.c similarity index 100% rename from amex/ds.c rename to common/amex/ds.c diff --git a/amex/ds.h b/common/amex/ds.h similarity index 100% rename from amex/ds.h rename to common/amex/ds.h diff --git a/amex/eeprom.c b/common/amex/eeprom.c similarity index 100% rename from amex/eeprom.c rename to common/amex/eeprom.c diff --git a/amex/eeprom.h b/common/amex/eeprom.h similarity index 100% rename from amex/eeprom.h rename to common/amex/eeprom.h diff --git a/amex/gpio.c b/common/amex/gpio.c similarity index 100% rename from amex/gpio.c rename to common/amex/gpio.c diff --git a/amex/gpio.h b/common/amex/gpio.h similarity index 100% rename from amex/gpio.h rename to common/amex/gpio.h diff --git a/amex/guid.c b/common/amex/guid.c similarity index 100% rename from amex/guid.c rename to common/amex/guid.c diff --git a/amex/jvs.c b/common/amex/jvs.c similarity index 100% rename from amex/jvs.c rename to common/amex/jvs.c diff --git a/amex/jvs.h b/common/amex/jvs.h similarity index 100% rename from amex/jvs.h rename to common/amex/jvs.h diff --git a/amex/meson.build b/common/amex/meson.build similarity index 100% rename from amex/meson.build rename to common/amex/meson.build diff --git a/amex/nvram.c b/common/amex/nvram.c similarity index 100% rename from amex/nvram.c rename to common/amex/nvram.c diff --git a/amex/nvram.h b/common/amex/nvram.h similarity index 100% rename from amex/nvram.h rename to common/amex/nvram.h diff --git a/amex/sram.c b/common/amex/sram.c similarity index 100% rename from amex/sram.c rename to common/amex/sram.c diff --git a/amex/sram.h b/common/amex/sram.h similarity index 100% rename from amex/sram.h rename to common/amex/sram.h diff --git a/board/aime-dll.c b/common/board/aime-dll.c similarity index 100% rename from board/aime-dll.c rename to common/board/aime-dll.c diff --git a/board/aime-dll.h b/common/board/aime-dll.h similarity index 100% rename from board/aime-dll.h rename to common/board/aime-dll.h diff --git a/board/config.c b/common/board/config.c similarity index 90% rename from board/config.c rename to common/board/config.c index 19d47bc..96c4146 100644 --- a/board/config.c +++ b/common/board/config.c @@ -75,6 +75,15 @@ void aime_config_load(struct aime_config *cfg, const wchar_t *filename) cfg->port_no = GetPrivateProfileIntW(L"aime", L"portNo", 0, filename); cfg->high_baudrate = GetPrivateProfileIntW(L"aime", L"highBaud", 1, filename); cfg->gen = GetPrivateProfileIntW(L"aime", L"gen", 0, filename); + cfg->proxy_flag = GetPrivateProfileIntW(L"aime", L"proxyFlag", 2, filename); + + GetPrivateProfileStringW( + L"aime", + L"authdataPath", + L"DEVICE\\authdata.bin", + cfg->authdata_path, + _countof(cfg->authdata_path), + filename); } void io4_config_load(struct io4_config *cfg, const wchar_t *filename) diff --git a/board/config.h b/common/board/config.h similarity index 100% rename from board/config.h rename to common/board/config.h diff --git a/board/ffb.c b/common/board/ffb.c similarity index 100% rename from board/ffb.c rename to common/board/ffb.c diff --git a/board/ffb.h b/common/board/ffb.h similarity index 100% rename from board/ffb.h rename to common/board/ffb.h diff --git a/board/guid.c b/common/board/guid.c similarity index 100% rename from board/guid.c rename to common/board/guid.c diff --git a/board/guid.h b/common/board/guid.h similarity index 100% rename from board/guid.h rename to common/board/guid.h diff --git a/board/io3.c b/common/board/io3.c similarity index 100% rename from board/io3.c rename to common/board/io3.c diff --git a/board/io3.h b/common/board/io3.h similarity index 100% rename from board/io3.h rename to common/board/io3.h diff --git a/board/io4.c b/common/board/io4.c similarity index 100% rename from board/io4.c rename to common/board/io4.c diff --git a/board/io4.h b/common/board/io4.h similarity index 100% rename from board/io4.h rename to common/board/io4.h diff --git a/board/led15070-cmd.h b/common/board/led15070-cmd.h similarity index 100% rename from board/led15070-cmd.h rename to common/board/led15070-cmd.h diff --git a/board/led15070-frame.c b/common/board/led15070-frame.c similarity index 100% rename from board/led15070-frame.c rename to common/board/led15070-frame.c diff --git a/board/led15070-frame.h b/common/board/led15070-frame.h similarity index 100% rename from board/led15070-frame.h rename to common/board/led15070-frame.h diff --git a/board/led15070.c b/common/board/led15070.c similarity index 100% rename from board/led15070.c rename to common/board/led15070.c diff --git a/board/led15070.h b/common/board/led15070.h similarity index 100% rename from board/led15070.h rename to common/board/led15070.h diff --git a/board/led15093-cmd.h b/common/board/led15093-cmd.h similarity index 100% rename from board/led15093-cmd.h rename to common/board/led15093-cmd.h diff --git a/board/led15093-frame.c b/common/board/led15093-frame.c similarity index 100% rename from board/led15093-frame.c rename to common/board/led15093-frame.c diff --git a/board/led15093-frame.h b/common/board/led15093-frame.h similarity index 100% rename from board/led15093-frame.h rename to common/board/led15093-frame.h diff --git a/board/led15093.c b/common/board/led15093.c similarity index 100% rename from board/led15093.c rename to common/board/led15093.c diff --git a/board/led15093.h b/common/board/led15093.h similarity index 100% rename from board/led15093.h rename to common/board/led15093.h diff --git a/board/meson.build b/common/board/meson.build similarity index 100% rename from board/meson.build rename to common/board/meson.build diff --git a/board/sg-cmd.c b/common/board/sg-cmd.c similarity index 100% rename from board/sg-cmd.c rename to common/board/sg-cmd.c diff --git a/board/sg-cmd.h b/common/board/sg-cmd.h similarity index 100% rename from board/sg-cmd.h rename to common/board/sg-cmd.h diff --git a/board/sg-frame.c b/common/board/sg-frame.c similarity index 100% rename from board/sg-frame.c rename to common/board/sg-frame.c diff --git a/board/sg-frame.h b/common/board/sg-frame.h similarity index 100% rename from board/sg-frame.h rename to common/board/sg-frame.h diff --git a/board/sg-led-cmd.h b/common/board/sg-led-cmd.h similarity index 100% rename from board/sg-led-cmd.h rename to common/board/sg-led-cmd.h diff --git a/board/sg-led.c b/common/board/sg-led.c similarity index 100% rename from board/sg-led.c rename to common/board/sg-led.c diff --git a/board/sg-led.h b/common/board/sg-led.h similarity index 100% rename from board/sg-led.h rename to common/board/sg-led.h diff --git a/board/sg-nfc-cmd.h b/common/board/sg-nfc-cmd.h similarity index 73% rename from board/sg-nfc-cmd.h rename to common/board/sg-nfc-cmd.h index 08923fd..e54e0a7 100644 --- a/board/sg-nfc-cmd.h +++ b/common/board/sg-nfc-cmd.h @@ -5,21 +5,21 @@ #pragma pack(push, 1) enum { - SG_NFC_CMD_GET_FW_VERSION = 0x30, - SG_NFC_CMD_GET_HW_VERSION = 0x32, - SG_NFC_CMD_RADIO_ON = 0x40, - SG_NFC_CMD_RADIO_OFF = 0x41, - SG_NFC_CMD_POLL = 0x42, - SG_NFC_CMD_MIFARE_SELECT_TAG = 0x43, - SG_NFC_CMD_MIFARE_SET_KEY_AIME = 0x50, - SG_NFC_CMD_MIFARE_AUTHENTICATE_A = 0x51, - SG_NFC_CMD_MIFARE_READ_BLOCK = 0x52, - SG_NFC_CMD_MIFARE_SET_KEY_BANA = 0x54, - SG_NFC_CMD_MIFARE_AUTHENTICATE_B = 0x55, - SG_NFC_CMD_TO_UPDATE_MODE = 0x60, - SG_NFC_CMD_SEND_HEX_DATA = 0x61, - SG_NFC_CMD_RESET = 0x62, - SG_NFC_CMD_FELICA_ENCAP = 0x71, + SG_NFC_CMD_GET_FW_VERSION = 0x30, + SG_NFC_CMD_GET_HW_VERSION = 0x32, + SG_NFC_CMD_RADIO_ON = 0x40, + SG_NFC_CMD_RADIO_OFF = 0x41, + SG_NFC_CMD_POLL = 0x42, + SG_NFC_CMD_MIFARE_SELECT_TAG = 0x43, + SG_NFC_CMD_MIFARE_SET_KEY_AIME = 0x50, + SG_NFC_CMD_MIFARE_AUTHENTICATE_AIME = 0x51, + SG_NFC_CMD_MIFARE_READ_BLOCK = 0x52, + SG_NFC_CMD_MIFARE_SET_KEY_BANA = 0x54, + SG_NFC_CMD_MIFARE_AUTHENTICATE_BANA = 0x55, + SG_NFC_CMD_TO_UPDATE_MODE = 0x60, + SG_NFC_CMD_SEND_HEX_DATA = 0x61, + SG_NFC_CMD_RESET = 0x62, + SG_NFC_CMD_FELICA_ENCAP = 0x71, }; struct sg_nfc_res_get_fw_version { diff --git a/board/sg-nfc.c b/common/board/sg-nfc.c similarity index 84% rename from board/sg-nfc.c rename to common/board/sg-nfc.c index eac0984..b103336 100644 --- a/board/sg-nfc.c +++ b/common/board/sg-nfc.c @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -16,6 +17,7 @@ #include "util/dprintf.h" #include "util/dump.h" +#include "util/slurp.h" static HRESULT sg_nfc_dispatch( void *ctx, @@ -87,6 +89,8 @@ void sg_nfc_init( uint8_t addr, const struct sg_nfc_ops *ops, unsigned int gen, + unsigned int proxy_flag, + const wchar_t* authdata_path, void *ops_ctx) { assert(nfc != NULL); @@ -96,6 +100,8 @@ void sg_nfc_init( nfc->ops_ctx = ops_ctx; nfc->addr = addr; nfc->gen = gen; + nfc->proxy_flag = proxy_flag; + nfc->authdata_path = authdata_path; } #ifdef NDEBUG @@ -189,8 +195,8 @@ static HRESULT sg_nfc_dispatch( &req->felica_encap, &res->felica_encap); - case SG_NFC_CMD_MIFARE_AUTHENTICATE_A: - case SG_NFC_CMD_MIFARE_AUTHENTICATE_B: + case SG_NFC_CMD_MIFARE_AUTHENTICATE_AIME: + case SG_NFC_CMD_MIFARE_AUTHENTICATE_BANA: case SG_NFC_CMD_SEND_HEX_DATA: return sg_nfc_cmd_send_hex_data(nfc, &req->simple, &res->simple); @@ -315,6 +321,7 @@ static HRESULT sg_nfc_poll_aime( mifare->type = 0x10; mifare->id_len = sizeof(mifare->uid); + // mifare->uid = _byteswap_ulong(0x8FBECBFF); mifare->uid = _byteswap_ulong(0x01020304); /* Initialize MIFARE IC emulator */ @@ -382,18 +389,62 @@ static HRESULT sg_nfc_cmd_mifare_read_block( sg_nfc_dprintf(nfc, "Read uid %08x block %i\n", uid, req->payload.block_no); - if (req->payload.block_no > 3) { + if (req->payload.block_no > 14) { sg_nfc_dprintf(nfc, "MIFARE block number out of range\n"); return E_FAIL; + } else if (req->payload.block_no >= 5){ // emoney auth encrypted + + sg_res_init(&res->res, &req->req, sizeof(res->block)); + + char* auth; + long size = wslurp(nfc->authdata_path, &auth, false); + if (size < 0){ + sg_nfc_dprintf(nfc, "Failed to read %ls: %lx!\n", nfc->authdata_path, GetLastError()); + return E_FAIL; + } + + int offset = 0; + if (req->payload.block_no == 6){ + offset = 16; + } else if (req->payload.block_no == 8){ + offset = 32; + } else if (req->payload.block_no == 9){ + offset = 48; + } else if (req->payload.block_no == 10){ + offset = 64; + } else if (req->payload.block_no == 12){ + offset = 82; + } else if (req->payload.block_no == 13){ + offset = 98; + } else if (req->payload.block_no == 14){ + offset = 114; + } + + for (int i = 0; i < 16 && offset + i < size; i++){ + res->block[i] = auth[offset + i]; + } + + free(auth); + + } else if (req->payload.block_no == 4){ // emoney auth plain + + sg_res_init(&res->res, &req->req, sizeof(res->block)); + + res->block[0] = 0x54; // header + res->block[1] = 0x43; + res->block[2] = nfc->proxy_flag; // 2 or 3 depending on game (useProxy in env.json) + res->block[3] = 0x01; // unknown flag + + } else { // read all other blocks normally + + sg_res_init(&res->res, &req->req, sizeof(res->block)); + + memcpy( res->block, + nfc->mifare.sectors[0].blocks[req->payload.block_no].bytes, + sizeof(res->block)); } - sg_res_init(&res->res, &req->req, sizeof(res->block)); - - memcpy( res->block, - nfc->mifare.sectors[0].blocks[req->payload.block_no].bytes, - sizeof(res->block)); - return S_OK; } diff --git a/board/sg-nfc.h b/common/board/sg-nfc.h similarity index 86% rename from board/sg-nfc.h rename to common/board/sg-nfc.h index 3c8eb49..092b3e3 100644 --- a/board/sg-nfc.h +++ b/common/board/sg-nfc.h @@ -23,8 +23,10 @@ struct sg_nfc { void *ops_ctx; uint8_t addr; unsigned int gen; + unsigned int proxy_flag; struct felica felica; struct mifare mifare; + const wchar_t* authdata_path; }; void sg_nfc_init( @@ -32,6 +34,8 @@ void sg_nfc_init( uint8_t addr, const struct sg_nfc_ops *ops, unsigned int gen, + unsigned int proxy_flag, + const wchar_t* authdata_path, void *ops_ctx); void sg_nfc_transact( diff --git a/board/sg-reader.c b/common/board/sg-reader.c similarity index 97% rename from board/sg-reader.c rename to common/board/sg-reader.c index bcc9701..2dc3c3d 100644 --- a/board/sg-reader.c +++ b/common/board/sg-reader.c @@ -81,7 +81,7 @@ HRESULT sg_reader_hook_init( return E_INVALIDARG; } - sg_nfc_init(&sg_reader_nfc, 0x00, &sg_reader_nfc_ops, gen, NULL); + sg_nfc_init(&sg_reader_nfc, 0x00, &sg_reader_nfc_ops, gen, cfg->proxy_flag, cfg->authdata_path, NULL); sg_led_init(&sg_reader_led, 0x08, &sg_reader_led_ops, gen, NULL); InitializeCriticalSection(&sg_reader_lock); diff --git a/board/sg-reader.h b/common/board/sg-reader.h similarity index 85% rename from board/sg-reader.h rename to common/board/sg-reader.h index 1824e28..64de7e9 100644 --- a/board/sg-reader.h +++ b/common/board/sg-reader.h @@ -12,6 +12,8 @@ struct aime_config { unsigned int port_no; bool high_baudrate; unsigned int gen; + unsigned int proxy_flag; + wchar_t authdata_path[MAX_PATH]; }; HRESULT sg_reader_hook_init( diff --git a/board/slider-cmd.h b/common/board/slider-cmd.h similarity index 100% rename from board/slider-cmd.h rename to common/board/slider-cmd.h diff --git a/board/slider-frame.c b/common/board/slider-frame.c similarity index 100% rename from board/slider-frame.c rename to common/board/slider-frame.c diff --git a/board/slider-frame.h b/common/board/slider-frame.h similarity index 100% rename from board/slider-frame.h rename to common/board/slider-frame.h diff --git a/board/vfd-cmd.h b/common/board/vfd-cmd.h similarity index 100% rename from board/vfd-cmd.h rename to common/board/vfd-cmd.h diff --git a/board/vfd-frame.c b/common/board/vfd-frame.c similarity index 100% rename from board/vfd-frame.c rename to common/board/vfd-frame.c diff --git a/board/vfd-frame.h b/common/board/vfd-frame.h similarity index 100% rename from board/vfd-frame.h rename to common/board/vfd-frame.h diff --git a/board/vfd.c b/common/board/vfd.c similarity index 100% rename from board/vfd.c rename to common/board/vfd.c diff --git a/board/vfd.h b/common/board/vfd.h similarity index 100% rename from board/vfd.h rename to common/board/vfd.h diff --git a/gfxhook/config.c b/common/gfxhook/config.c similarity index 87% rename from gfxhook/config.c rename to common/gfxhook/config.c index 98db059..5c49625 100644 --- a/gfxhook/config.c +++ b/common/gfxhook/config.c @@ -14,4 +14,5 @@ void gfx_config_load(struct gfx_config *cfg, const wchar_t *filename) cfg->windowed = GetPrivateProfileIntW(L"gfx", L"windowed", 0, filename); cfg->framed = GetPrivateProfileIntW(L"gfx", L"framed", 1, filename); cfg->monitor = GetPrivateProfileIntW(L"gfx", L"monitor", 0, filename); + cfg->dpiAware = GetPrivateProfileIntW(L"gfx", L"dpiAware", 1, filename); } diff --git a/gfxhook/config.h b/common/gfxhook/config.h similarity index 100% rename from gfxhook/config.h rename to common/gfxhook/config.h diff --git a/gfxhook/d3d11.c b/common/gfxhook/d3d11.c similarity index 100% rename from gfxhook/d3d11.c rename to common/gfxhook/d3d11.c diff --git a/gfxhook/d3d11.h b/common/gfxhook/d3d11.h similarity index 100% rename from gfxhook/d3d11.h rename to common/gfxhook/d3d11.h diff --git a/gfxhook/d3d9.c b/common/gfxhook/d3d9.c similarity index 100% rename from gfxhook/d3d9.c rename to common/gfxhook/d3d9.c diff --git a/gfxhook/d3d9.h b/common/gfxhook/d3d9.h similarity index 100% rename from gfxhook/d3d9.h rename to common/gfxhook/d3d9.h diff --git a/gfxhook/dxgi.c b/common/gfxhook/dxgi.c similarity index 100% rename from gfxhook/dxgi.c rename to common/gfxhook/dxgi.c diff --git a/gfxhook/dxgi.h b/common/gfxhook/dxgi.h similarity index 100% rename from gfxhook/dxgi.h rename to common/gfxhook/dxgi.h diff --git a/gfxhook/gfx.c b/common/gfxhook/gfx.c similarity index 93% rename from gfxhook/gfx.c rename to common/gfxhook/gfx.c index 0acc1ae..5d7b8cd 100644 --- a/gfxhook/gfx.c +++ b/common/gfxhook/gfx.c @@ -67,6 +67,14 @@ void gfx_hook_init(const struct gfx_config *cfg) return; } + if (cfg->dpiAware) { + if (SetProcessDPIAware()) { + dprintf("Gfx: Game process set to DPI aware.\n"); + } else { + dprintf("Gfx: Failed to set process DPI aware\n"); + } + } + memcpy(&gfx_config, cfg, sizeof(*cfg)); hook_table_apply(NULL, "user32.dll", gfx_hooks, _countof(gfx_hooks)); } diff --git a/gfxhook/gfx.h b/common/gfxhook/gfx.h similarity index 90% rename from gfxhook/gfx.h rename to common/gfxhook/gfx.h index 9a7e27c..6f3c1b2 100644 --- a/gfxhook/gfx.h +++ b/common/gfxhook/gfx.h @@ -7,6 +7,7 @@ struct gfx_config { bool windowed; bool framed; int monitor; + bool dpiAware; }; void gfx_hook_init(const struct gfx_config *cfg); diff --git a/gfxhook/gl.c b/common/gfxhook/gl.c similarity index 100% rename from gfxhook/gl.c rename to common/gfxhook/gl.c diff --git a/gfxhook/gl.h b/common/gfxhook/gl.h similarity index 100% rename from gfxhook/gl.h rename to common/gfxhook/gl.h diff --git a/gfxhook/meson.build b/common/gfxhook/meson.build similarity index 100% rename from gfxhook/meson.build rename to common/gfxhook/meson.build diff --git a/gfxhook/util.c b/common/gfxhook/util.c similarity index 100% rename from gfxhook/util.c rename to common/gfxhook/util.c diff --git a/gfxhook/util.h b/common/gfxhook/util.h similarity index 100% rename from gfxhook/util.h rename to common/gfxhook/util.h diff --git a/hooklib/config.c b/common/hooklib/config.c similarity index 100% rename from hooklib/config.c rename to common/hooklib/config.c diff --git a/hooklib/config.h b/common/hooklib/config.h similarity index 100% rename from hooklib/config.h rename to common/hooklib/config.h diff --git a/hooklib/createprocess.c b/common/hooklib/createprocess.c similarity index 100% rename from hooklib/createprocess.c rename to common/hooklib/createprocess.c diff --git a/hooklib/createprocess.h b/common/hooklib/createprocess.h similarity index 100% rename from hooklib/createprocess.h rename to common/hooklib/createprocess.h diff --git a/hooklib/cursor.c b/common/hooklib/cursor.c similarity index 86% rename from hooklib/cursor.c rename to common/hooklib/cursor.c index 87e3ca8..7caba97 100644 --- a/hooklib/cursor.c +++ b/common/hooklib/cursor.c @@ -14,6 +14,7 @@ static HCURSOR (*next_SetCursor)(HCURSOR hCursor); static BOOL my_SetCursorPos(int x, int y); static BOOL my_SetPhysicalCursorPos(int x, int y); static int my_ShowCursor(BOOL bShow); +static int cursor_track = -1; // If no mouse is connected, this starts as -1 static const struct hook_symbol cursor_syms[] = { { @@ -45,7 +46,7 @@ void cursor_hook_init() static BOOL my_SetCursorPos(int x, int y) { - dprintf("my_SetCursorPos Hit! x %d y %d\n", x, y); + // dprintf("my_SetCursorPos Hit! x %d y %d\n", x, y); return true; } @@ -58,7 +59,12 @@ static BOOL my_SetPhysicalCursorPos(int x, int y) static int my_ShowCursor(BOOL bShow) { dprintf("my_ShowCursor Hit!\n"); - return 0; + if (bShow) { + cursor_track++; + } else { + cursor_track--; + } + return cursor_track; } static HCURSOR my_SetCursor(HCURSOR hCursor) diff --git a/hooklib/cursor.h b/common/hooklib/cursor.h similarity index 100% rename from hooklib/cursor.h rename to common/hooklib/cursor.h diff --git a/hooklib/dll.c b/common/hooklib/dll.c similarity index 100% rename from hooklib/dll.c rename to common/hooklib/dll.c diff --git a/hooklib/dll.h b/common/hooklib/dll.h similarity index 100% rename from hooklib/dll.h rename to common/hooklib/dll.h diff --git a/hooklib/dns.c b/common/hooklib/dns.c similarity index 99% rename from hooklib/dns.c rename to common/hooklib/dns.c index 45b463e..9e06e5b 100644 --- a/hooklib/dns.c +++ b/common/hooklib/dns.c @@ -217,20 +217,24 @@ static void dns_hook_init(void) dns_hook_initted = true; InitializeCriticalSection(&dns_hook_lock); + dns_hook_apply_hooks(NULL); +} + +void dns_hook_apply_hooks(HMODULE mod){ hook_table_apply( - NULL, + mod, "dnsapi.dll", dns_hook_syms_dnsapi, _countof(dns_hook_syms_dnsapi)); hook_table_apply( - NULL, + mod, "ws2_32.dll", dns_hook_syms_ws2, _countof(dns_hook_syms_ws2)); hook_table_apply( - NULL, + mod, "winhttp.dll", dns_hook_syms_winhttp, _countof(dns_hook_syms_winhttp)); diff --git a/hooklib/dns.h b/common/hooklib/dns.h similarity index 88% rename from hooklib/dns.h rename to common/hooklib/dns.h index 9279a37..b03f7dc 100644 --- a/hooklib/dns.h +++ b/common/hooklib/dns.h @@ -8,3 +8,4 @@ void port_hook_init(unsigned short _startup_port, unsigned short _billing_port, // if to_src is NULL, all lookups for from_src will fail HRESULT dns_hook_push(const wchar_t *from_src, const wchar_t *to_src); +void dns_hook_apply_hooks(HMODULE mod); diff --git a/hooklib/dvd.c b/common/hooklib/dvd.c similarity index 100% rename from hooklib/dvd.c rename to common/hooklib/dvd.c diff --git a/hooklib/dvd.h b/common/hooklib/dvd.h similarity index 100% rename from hooklib/dvd.h rename to common/hooklib/dvd.h diff --git a/hooklib/fdshark.c b/common/hooklib/fdshark.c similarity index 100% rename from hooklib/fdshark.c rename to common/hooklib/fdshark.c diff --git a/hooklib/fdshark.h b/common/hooklib/fdshark.h similarity index 100% rename from hooklib/fdshark.h rename to common/hooklib/fdshark.h diff --git a/hooklib/meson.build b/common/hooklib/meson.build similarity index 100% rename from hooklib/meson.build rename to common/hooklib/meson.build diff --git a/hooklib/path.c b/common/hooklib/path.c similarity index 99% rename from hooklib/path.c rename to common/hooklib/path.c index 82f97e2..1afb8a8 100644 --- a/hooklib/path.c +++ b/common/hooklib/path.c @@ -11,6 +11,8 @@ #include "hooklib/path.h" +#include + /* Helpers */ static void path_hook_init(void); @@ -533,6 +535,12 @@ static BOOL path_transform_w(wchar_t **out, const wchar_t *src) goto end; } +#if LOG_VFS + if (!wcsstr(src, L"AppUser")) { + dprintf("Path: %ls -> %ls\n", src, dest); + } +#endif + break; } diff --git a/hooklib/path.h b/common/hooklib/path.h similarity index 100% rename from hooklib/path.h rename to common/hooklib/path.h diff --git a/hooklib/printer.c b/common/hooklib/printer.c similarity index 100% rename from hooklib/printer.c rename to common/hooklib/printer.c diff --git a/hooklib/printer.h b/common/hooklib/printer.h similarity index 100% rename from hooklib/printer.h rename to common/hooklib/printer.h diff --git a/hooklib/reg.c b/common/hooklib/reg.c similarity index 100% rename from hooklib/reg.c rename to common/hooklib/reg.c diff --git a/hooklib/reg.h b/common/hooklib/reg.h similarity index 100% rename from hooklib/reg.h rename to common/hooklib/reg.h diff --git a/hooklib/setupapi.c b/common/hooklib/setupapi.c similarity index 100% rename from hooklib/setupapi.c rename to common/hooklib/setupapi.c diff --git a/hooklib/setupapi.h b/common/hooklib/setupapi.h similarity index 100% rename from hooklib/setupapi.h rename to common/hooklib/setupapi.h diff --git a/hooklib/spike.c b/common/hooklib/spike.c similarity index 100% rename from hooklib/spike.c rename to common/hooklib/spike.c diff --git a/hooklib/spike.h b/common/hooklib/spike.h similarity index 100% rename from hooklib/spike.h rename to common/hooklib/spike.h diff --git a/hooklib/touch.c b/common/hooklib/touch.c similarity index 100% rename from hooklib/touch.c rename to common/hooklib/touch.c diff --git a/hooklib/touch.h b/common/hooklib/touch.h similarity index 100% rename from hooklib/touch.h rename to common/hooklib/touch.h diff --git a/iccard/aime.c b/common/iccard/aime.c similarity index 100% rename from iccard/aime.c rename to common/iccard/aime.c diff --git a/iccard/aime.h b/common/iccard/aime.h similarity index 100% rename from iccard/aime.h rename to common/iccard/aime.h diff --git a/iccard/felica.c b/common/iccard/felica.c similarity index 100% rename from iccard/felica.c rename to common/iccard/felica.c diff --git a/iccard/felica.h b/common/iccard/felica.h similarity index 100% rename from iccard/felica.h rename to common/iccard/felica.h diff --git a/iccard/meson.build b/common/iccard/meson.build similarity index 100% rename from iccard/meson.build rename to common/iccard/meson.build diff --git a/iccard/mifare.h b/common/iccard/mifare.h similarity index 100% rename from iccard/mifare.h rename to common/iccard/mifare.h diff --git a/jvs/jvs-bus.c b/common/jvs/jvs-bus.c similarity index 100% rename from jvs/jvs-bus.c rename to common/jvs/jvs-bus.c diff --git a/jvs/jvs-bus.h b/common/jvs/jvs-bus.h similarity index 100% rename from jvs/jvs-bus.h rename to common/jvs/jvs-bus.h diff --git a/jvs/jvs-cmd.h b/common/jvs/jvs-cmd.h similarity index 100% rename from jvs/jvs-cmd.h rename to common/jvs/jvs-cmd.h diff --git a/jvs/jvs-frame.c b/common/jvs/jvs-frame.c similarity index 100% rename from jvs/jvs-frame.c rename to common/jvs/jvs-frame.c diff --git a/jvs/jvs-frame.h b/common/jvs/jvs-frame.h similarity index 100% rename from jvs/jvs-frame.h rename to common/jvs/jvs-frame.h diff --git a/jvs/jvs-util.c b/common/jvs/jvs-util.c similarity index 100% rename from jvs/jvs-util.c rename to common/jvs/jvs-util.c diff --git a/jvs/jvs-util.h b/common/jvs/jvs-util.h similarity index 100% rename from jvs/jvs-util.h rename to common/jvs/jvs-util.h diff --git a/jvs/meson.build b/common/jvs/meson.build similarity index 100% rename from jvs/meson.build rename to common/jvs/meson.build diff --git a/platform/amvideo.c b/common/platform/amvideo.c similarity index 100% rename from platform/amvideo.c rename to common/platform/amvideo.c diff --git a/platform/amvideo.h b/common/platform/amvideo.h similarity index 100% rename from platform/amvideo.h rename to common/platform/amvideo.h diff --git a/platform/clock.c b/common/platform/clock.c similarity index 100% rename from platform/clock.c rename to common/platform/clock.c diff --git a/platform/clock.h b/common/platform/clock.h similarity index 100% rename from platform/clock.h rename to common/platform/clock.h diff --git a/platform/config.c b/common/platform/config.c similarity index 99% rename from platform/config.c rename to common/platform/config.c index 2904019..c9777da 100644 --- a/platform/config.c +++ b/common/platform/config.c @@ -360,4 +360,5 @@ void epay_config_load(struct epay_config *cfg, const wchar_t *filename) assert(filename != NULL); cfg->enable = GetPrivateProfileIntW(L"epay", L"enable", 1, filename); + cfg->hook = GetPrivateProfileIntW(L"epay", L"hook", 0, filename); } diff --git a/platform/config.h b/common/platform/config.h similarity index 100% rename from platform/config.h rename to common/platform/config.h diff --git a/platform/dns.c b/common/platform/dns.c similarity index 100% rename from platform/dns.c rename to common/platform/dns.c diff --git a/platform/dns.h b/common/platform/dns.h similarity index 100% rename from platform/dns.h rename to common/platform/dns.h diff --git a/platform/epay.c b/common/platform/epay.c similarity index 79% rename from platform/epay.c rename to common/platform/epay.c index 4a231c2..6193a2d 100644 --- a/platform/epay.c +++ b/common/platform/epay.c @@ -7,10 +7,13 @@ #include "hook/table.h" +#include "hooklib/dns.h" #include "hooklib/reg.h" #include "platform/epay.h" +#include + #include "util/dprintf.h" static HRESULT misc_read_thinca_adapter(void *bytes, uint32_t *nbytes); @@ -119,15 +122,8 @@ static const struct hook_symbol epay_syms[] = { } }; -HRESULT epay_hook_init(const struct epay_config *cfg) { - HRESULT hr; - assert(cfg != NULL); - - if (!cfg->enable) { - return S_FALSE; - } - - hr = reg_hook_push_key( +HRESULT epay_apply_registry_hooks(){ + HRESULT hr = reg_hook_push_key( HKEY_LOCAL_MACHINE, L"SOFTWARE\\TFPaymentService\\ThincaRwAdapter", epay_adapter_keys, @@ -162,34 +158,69 @@ HRESULT epay_hook_init(const struct epay_config *cfg) { L"SOFTWARE\\TFPaymentService\\ThincaTcapClient\\URL1", epay_tcap_url1_keys, _countof(epay_tcap_url1_keys)); - - hook_table_apply( - NULL, - "ThincaPayment.dll", - epay_syms, - _countof(epay_syms)); - - thinca_stub = (struct thinca_main *)malloc(sizeof(struct thinca_main)); - thinca_stub->impl1 = (struct thinca_impl *)malloc(sizeof(struct thinca_impl)); - thinca_stub->impl1->unk8 = thinca_unk8; - thinca_stub->impl1->initialize = thinca_initialize; - thinca_stub->impl1->dispose = thinca_dispose; - thinca_stub->impl1->setResource = thinca_set_resource; - thinca_stub->impl1->setThincaPaymentLog = thinca_set_pay_log; - thinca_stub->impl1->setThincaEventInterface = thinca_set_evt_handler; - thinca_stub->impl1->setIcasClientLog = thinca_set_client_log; - thinca_stub->impl1->setIcasClientConfig = thinca_set_client_cfg; - thinca_stub->impl1->setGoodsCode = thinca_set_goods_code; - thinca_stub->impl1->setTerminalSerial = thinca_set_serial; - thinca_stub->impl1->setClientCertificate = thinca_set_cert; - thinca_stub->impl1->checkDeal = thinca_check_deal; - thinca_stub->impl1->cancelRequest = thinca_cancel; - thinca_stub->impl1->selectButton = thinca_select; - thinca_stub->impl1->unk220 = thinca_unk; - thinca_stub->impl1->unk228 = thinca_unk; - - dprintf("Epay: Init.\n"); + return hr; +} + +HRESULT epay_hook_init(const struct epay_config *cfg) { + HRESULT hr; + assert(cfg != NULL); + + if (!cfg->enable) { + return S_FALSE; + } + + hr = epay_apply_registry_hooks(); + if (FAILED(hr)){ + return hr; + } + + dprintf("EPay: Registry initialized\n"); + + // HACK:(?) the DLLs are loaded dynamically so we just preload it and apply DNS and VFS hooks to it + HMODULE thincahttpclient = LoadLibraryA("thincahttpclient.dll"); + if (thincahttpclient != NULL){ + dns_hook_apply_hooks(thincahttpclient); + path_hook_insert_hooks(thincahttpclient); + } + HMODULE thincapayment = LoadLibraryA("ThincaPayment.dll"); + if (thincapayment != NULL){ + path_hook_insert_hooks(thincapayment); + } + HMODULE thincatcapclient = LoadLibraryA("thincatcapclient.dll"); + if (thincatcapclient != NULL){ + path_hook_insert_hooks(thincatcapclient); + } + + if (cfg->hook) { + hook_table_apply( + NULL, + "ThincaPayment.dll", + epay_syms, + _countof(epay_syms)); + + thinca_stub = (struct thinca_main *) malloc(sizeof(struct thinca_main)); + thinca_stub->impl1 = (struct thinca_impl *) malloc(sizeof(struct thinca_impl)); + + thinca_stub->impl1->unk8 = thinca_unk8; + thinca_stub->impl1->initialize = thinca_initialize; + thinca_stub->impl1->dispose = thinca_dispose; + thinca_stub->impl1->setResource = thinca_set_resource; + thinca_stub->impl1->setThincaPaymentLog = thinca_set_pay_log; + thinca_stub->impl1->setThincaEventInterface = thinca_set_evt_handler; + thinca_stub->impl1->setIcasClientLog = thinca_set_client_log; + thinca_stub->impl1->setIcasClientConfig = thinca_set_client_cfg; + thinca_stub->impl1->setGoodsCode = thinca_set_goods_code; + thinca_stub->impl1->setTerminalSerial = thinca_set_serial; + thinca_stub->impl1->setClientCertificate = thinca_set_cert; + thinca_stub->impl1->checkDeal = thinca_check_deal; + thinca_stub->impl1->cancelRequest = thinca_cancel; + thinca_stub->impl1->selectButton = thinca_select; + thinca_stub->impl1->unk220 = thinca_unk; + thinca_stub->impl1->unk228 = thinca_unk; + + dprintf("Epay: Hooks initialized\n"); + } return hr; } diff --git a/platform/epay.h b/common/platform/epay.h similarity index 95% rename from platform/epay.h rename to common/platform/epay.h index 6b5659b..70aa886 100644 --- a/platform/epay.h +++ b/common/platform/epay.h @@ -7,6 +7,7 @@ #pragma pack(push,1) struct epay_config { bool enable; + bool hook; }; /* The functions in these structs are how clients like amdaemon interface @@ -61,4 +62,5 @@ struct thinca_main { }; #pragma pack(pop) -HRESULT epay_hook_init(const struct epay_config *cfg); \ No newline at end of file +HRESULT epay_hook_init(const struct epay_config *cfg); +HRESULT epay_apply_registry_hooks(); \ No newline at end of file diff --git a/platform/hwmon.c b/common/platform/hwmon.c similarity index 100% rename from platform/hwmon.c rename to common/platform/hwmon.c diff --git a/platform/hwmon.h b/common/platform/hwmon.h similarity index 100% rename from platform/hwmon.h rename to common/platform/hwmon.h diff --git a/platform/hwreset.c b/common/platform/hwreset.c similarity index 100% rename from platform/hwreset.c rename to common/platform/hwreset.c diff --git a/platform/hwreset.h b/common/platform/hwreset.h similarity index 100% rename from platform/hwreset.h rename to common/platform/hwreset.h diff --git a/platform/meson.build b/common/platform/meson.build similarity index 100% rename from platform/meson.build rename to common/platform/meson.build diff --git a/platform/misc.c b/common/platform/misc.c similarity index 100% rename from platform/misc.c rename to common/platform/misc.c diff --git a/platform/misc.h b/common/platform/misc.h similarity index 100% rename from platform/misc.h rename to common/platform/misc.h diff --git a/platform/netenv.c b/common/platform/netenv.c similarity index 100% rename from platform/netenv.c rename to common/platform/netenv.c diff --git a/platform/netenv.h b/common/platform/netenv.h similarity index 100% rename from platform/netenv.h rename to common/platform/netenv.h diff --git a/platform/nusec.c b/common/platform/nusec.c similarity index 100% rename from platform/nusec.c rename to common/platform/nusec.c diff --git a/platform/nusec.h b/common/platform/nusec.h similarity index 100% rename from platform/nusec.h rename to common/platform/nusec.h diff --git a/platform/pcbid.c b/common/platform/pcbid.c similarity index 100% rename from platform/pcbid.c rename to common/platform/pcbid.c diff --git a/platform/pcbid.h b/common/platform/pcbid.h similarity index 100% rename from platform/pcbid.h rename to common/platform/pcbid.h diff --git a/platform/platform.c b/common/platform/platform.c similarity index 100% rename from platform/platform.c rename to common/platform/platform.c index a769c97..c882760 100644 --- a/platform/platform.c +++ b/common/platform/platform.c @@ -82,13 +82,13 @@ HRESULT platform_hook_init( return hr; } - hr = system_init(&cfg->system, &cfg->vfs); + hr = epay_hook_init(&cfg->epay); if (FAILED(hr)) { return hr; } - hr = epay_hook_init(&cfg->epay); + hr = system_init(&cfg->system, &cfg->vfs); if (FAILED(hr)) { return hr; diff --git a/platform/platform.h b/common/platform/platform.h similarity index 100% rename from platform/platform.h rename to common/platform/platform.h diff --git a/platform/system.c b/common/platform/system.c similarity index 90% rename from platform/system.c rename to common/platform/system.c index 5879032..c9dd1fd 100644 --- a/platform/system.c +++ b/common/platform/system.c @@ -106,13 +106,14 @@ static void system_read_sysfile(const wchar_t *sys_file) { static void system_save_sysfile(const wchar_t *sys_file) { char block[BLOCK_SIZE]; + DWORD sysfile_bytes_written = 0; uint8_t system = 0; uint8_t freeplay = 0; - // open the sysfile.dat for writing in bytes mode - FILE *f = _wfopen(sys_file, L"rb+"); + // open the sysfile.dat for writing + HANDLE h_sysfile = CreateFileW(sys_file, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - if (f == NULL) { + if (h_sysfile == INVALID_HANDLE_VALUE) { return; } @@ -164,17 +165,10 @@ static void system_save_sysfile(const wchar_t *sys_file) { memcpy(system_info.data + 0x2800, block, BLOCK_SIZE); memcpy(system_info.data + 0x5800, block, BLOCK_SIZE); - // print the dip_switch_block in hex - /* - dprintf("System Block: "); - for (size_t i = 0; i < BLOCK_SIZE; i++) - { - dprintf("%02X ", ((uint8_t *)&system_info.dip_switch_block)[i]); + WriteFile(h_sysfile, system_info.data, 0x6000, &sysfile_bytes_written, NULL); + CloseHandle(h_sysfile); + + if (sysfile_bytes_written != 0x6000) { + dprintf("System: Only 0x%04lX bytes written out of 0x6000!\n", sysfile_bytes_written); } - dprintf("\n"); - */ - - fwrite(system_info.data, 1, 0x6000, f); - - fclose(f); } diff --git a/platform/system.h b/common/platform/system.h similarity index 100% rename from platform/system.h rename to common/platform/system.h diff --git a/platform/vfs.c b/common/platform/vfs.c similarity index 100% rename from platform/vfs.c rename to common/platform/vfs.c diff --git a/platform/vfs.h b/common/platform/vfs.h similarity index 100% rename from platform/vfs.h rename to common/platform/vfs.h diff --git a/unityhook/config.c b/common/unityhook/config.c similarity index 100% rename from unityhook/config.c rename to common/unityhook/config.c diff --git a/unityhook/config.h b/common/unityhook/config.h similarity index 94% rename from unityhook/config.h rename to common/unityhook/config.h index 6fca14a..6857c4b 100644 --- a/unityhook/config.h +++ b/common/unityhook/config.h @@ -1,12 +1,12 @@ -#pragma once - -#include - -#include - -struct unity_config { - bool enable; - wchar_t target_assembly[MAX_PATH]; -}; - -void unity_config_load(struct unity_config *cfg, const wchar_t *filename); +#pragma once + +#include + +#include + +struct unity_config { + bool enable; + wchar_t target_assembly[MAX_PATH]; +}; + +void unity_config_load(struct unity_config *cfg, const wchar_t *filename); diff --git a/unityhook/doorstop.c b/common/unityhook/doorstop.c similarity index 100% rename from unityhook/doorstop.c rename to common/unityhook/doorstop.c diff --git a/unityhook/doorstop.h b/common/unityhook/doorstop.h similarity index 83% rename from unityhook/doorstop.h rename to common/unityhook/doorstop.h index 8cc961e..2a44f33 100644 --- a/unityhook/doorstop.h +++ b/common/unityhook/doorstop.h @@ -1,5 +1,5 @@ -#pragma once - -#include "config.h" - +#pragma once + +#include "config.h" + void doorstop_mono_hook_init(const struct unity_config *cfg, HINSTANCE module); \ No newline at end of file diff --git a/unityhook/hook.c b/common/unityhook/hook.c similarity index 100% rename from unityhook/hook.c rename to common/unityhook/hook.c diff --git a/unityhook/hook.h b/common/unityhook/hook.h similarity index 96% rename from unityhook/hook.h rename to common/unityhook/hook.h index 7be6044..a7c75e1 100644 --- a/unityhook/hook.h +++ b/common/unityhook/hook.h @@ -1,9 +1,9 @@ -#pragma once - -#include - -#include "config.h" - -typedef void (*unity_hook_callback_func)(HMODULE, const wchar_t*); - -void unity_hook_init(const struct unity_config *cfg, HINSTANCE self, unity_hook_callback_func callback); +#pragma once + +#include + +#include "config.h" + +typedef void (*unity_hook_callback_func)(HMODULE, const wchar_t*); + +void unity_hook_init(const struct unity_config *cfg, HINSTANCE self, unity_hook_callback_func callback); diff --git a/unityhook/meson.build b/common/unityhook/meson.build similarity index 95% rename from unityhook/meson.build rename to common/unityhook/meson.build index 50d0488..f541c1e 100644 --- a/unityhook/meson.build +++ b/common/unityhook/meson.build @@ -1,19 +1,19 @@ -unityhook_lib = static_library( - 'unityhook', - include_directories: inc, - implicit_include_directories: false, - dependencies: [ - capnhook.get_variable('hook_dep'), - pathcch_lib - ], - sources: [ - 'mono.h', - 'config.c', - 'config.h', - 'doorstop.c', - 'doorstop.h', - 'hook.c', - 'hook.h', - 'util.h' - ], -) +unityhook_lib = static_library( + 'unityhook', + include_directories: inc, + implicit_include_directories: false, + dependencies: [ + capnhook.get_variable('hook_dep'), + pathcch_lib + ], + sources: [ + 'mono.h', + 'config.c', + 'config.h', + 'doorstop.c', + 'doorstop.h', + 'hook.c', + 'hook.h', + 'util.h' + ], +) diff --git a/unityhook/mono.h b/common/unityhook/mono.h similarity index 97% rename from unityhook/mono.h rename to common/unityhook/mono.h index 7056e75..39fdc01 100644 --- a/unityhook/mono.h +++ b/common/unityhook/mono.h @@ -1,100 +1,100 @@ -// SPDX-License-Identifier: CC0 -// https://github.com/NeighTools/UnityDoorstop -#pragma once - -#include - -// Here we define the pointers to some functions within mono.dll -// Note to C learners: these are not signature definitions, but rather "variable" -// definitions with the function pointer type. - -// Note: we use void* instead of the real intented structs defined in mono API -// This way we don't need to include or define any of Mono's structs, which saves space -// This, obviously, comes with a drawback of not being able to easily access the contents of the structs - -void * (*mono_thread_current)(); -void (*mono_thread_set_main)(void *); - -void *(*mono_jit_init_version)(const char *root_domain_name, const char *runtime_version); -void *(*mono_domain_assembly_open)(void *domain, const char *name); -void *(*mono_assembly_get_image)(void *assembly); -void *(*mono_runtime_invoke)(void *method, void *obj, void **params, void **exc); - -void *(*mono_method_desc_new)(const char *name, int include_namespace); -void* (*mono_method_desc_search_in_image)(void* desc, void* image); -void *(*mono_method_desc_search_in_class)(void *desc, void *klass); -void (*mono_method_desc_free)(void *desc); -void *(*mono_method_signature)(void *method); -UINT32 (*mono_signature_get_param_count)(void *sig); - -void (*mono_domain_set_config)(void *domain, char *base_dir, char *config_file_name); -void *(*mono_array_new)(void *domain, void *eclass, uintptr_t n); -void *(*mono_get_string_class)(); - -char *(*mono_assembly_getrootdir)(); - -// Additional funcs to bootstrap custom MONO -void (*mono_set_dirs)(const char* assembly_dir, const char* config_dir); -void (*mono_config_parse)(const char* filename); -void (*mono_set_assemblies_path)(const char* path); -void *(*mono_object_to_string)(void* obj, void** exc); -char *(*mono_string_to_utf8)(void* s); - -void *(*mono_image_open_from_data_with_name)(void *data, DWORD data_len, int need_copy, void *status, int refonly, - const char *name); - -void* (*mono_get_exception_class)(); -void* (*mono_object_get_virtual_method)(void* obj_raw, void* method); - -void* (*mono_jit_parse_options)(int argc, const char** argv); - -typedef enum { - MONO_DEBUG_FORMAT_NONE, - MONO_DEBUG_FORMAT_MONO, - /* Deprecated, the mdb debugger is not longer supported. */ - MONO_DEBUG_FORMAT_DEBUGGER -} MonoDebugFormat; - -void* (*mono_debug_init)(MonoDebugFormat format); -void* (*mono_debug_domain_create)(void* domain); - -/** -* \brief Loads Mono C API function pointers so that the above definitions can be called. -* \param mono_lib Mono.dll module. -*/ -void load_mono_functions(HMODULE mono_lib) { - // Enjoy the fact that C allows such sloppy casting - // In C++ you would have to cast to the precise function pointer type -#define GET_MONO_PROC(name) name = (void*)GetProcAddress(mono_lib, #name) - - // Find and assign all our functions that we are going to use - GET_MONO_PROC(mono_domain_assembly_open); - GET_MONO_PROC(mono_assembly_get_image); - GET_MONO_PROC(mono_runtime_invoke); - GET_MONO_PROC(mono_jit_init_version); - GET_MONO_PROC(mono_method_desc_new); - GET_MONO_PROC(mono_method_desc_search_in_class); - GET_MONO_PROC(mono_method_desc_search_in_image); - GET_MONO_PROC(mono_method_desc_free); - GET_MONO_PROC(mono_method_signature); - GET_MONO_PROC(mono_signature_get_param_count); - GET_MONO_PROC(mono_array_new); - GET_MONO_PROC(mono_get_string_class); - GET_MONO_PROC(mono_assembly_getrootdir); - GET_MONO_PROC(mono_thread_current); - GET_MONO_PROC(mono_thread_set_main); - GET_MONO_PROC(mono_domain_set_config); - GET_MONO_PROC(mono_set_dirs); - GET_MONO_PROC(mono_config_parse); - GET_MONO_PROC(mono_set_assemblies_path); - GET_MONO_PROC(mono_object_to_string); - GET_MONO_PROC(mono_string_to_utf8); - GET_MONO_PROC(mono_image_open_from_data_with_name); - GET_MONO_PROC(mono_get_exception_class); - GET_MONO_PROC(mono_object_get_virtual_method); - GET_MONO_PROC(mono_jit_parse_options); - GET_MONO_PROC(mono_debug_init); - GET_MONO_PROC(mono_debug_domain_create); - -#undef GET_MONO_PROC +// SPDX-License-Identifier: CC0 +// https://github.com/NeighTools/UnityDoorstop +#pragma once + +#include + +// Here we define the pointers to some functions within mono.dll +// Note to C learners: these are not signature definitions, but rather "variable" +// definitions with the function pointer type. + +// Note: we use void* instead of the real intented structs defined in mono API +// This way we don't need to include or define any of Mono's structs, which saves space +// This, obviously, comes with a drawback of not being able to easily access the contents of the structs + +void * (*mono_thread_current)(); +void (*mono_thread_set_main)(void *); + +void *(*mono_jit_init_version)(const char *root_domain_name, const char *runtime_version); +void *(*mono_domain_assembly_open)(void *domain, const char *name); +void *(*mono_assembly_get_image)(void *assembly); +void *(*mono_runtime_invoke)(void *method, void *obj, void **params, void **exc); + +void *(*mono_method_desc_new)(const char *name, int include_namespace); +void* (*mono_method_desc_search_in_image)(void* desc, void* image); +void *(*mono_method_desc_search_in_class)(void *desc, void *klass); +void (*mono_method_desc_free)(void *desc); +void *(*mono_method_signature)(void *method); +UINT32 (*mono_signature_get_param_count)(void *sig); + +void (*mono_domain_set_config)(void *domain, char *base_dir, char *config_file_name); +void *(*mono_array_new)(void *domain, void *eclass, uintptr_t n); +void *(*mono_get_string_class)(); + +char *(*mono_assembly_getrootdir)(); + +// Additional funcs to bootstrap custom MONO +void (*mono_set_dirs)(const char* assembly_dir, const char* config_dir); +void (*mono_config_parse)(const char* filename); +void (*mono_set_assemblies_path)(const char* path); +void *(*mono_object_to_string)(void* obj, void** exc); +char *(*mono_string_to_utf8)(void* s); + +void *(*mono_image_open_from_data_with_name)(void *data, DWORD data_len, int need_copy, void *status, int refonly, + const char *name); + +void* (*mono_get_exception_class)(); +void* (*mono_object_get_virtual_method)(void* obj_raw, void* method); + +void* (*mono_jit_parse_options)(int argc, const char** argv); + +typedef enum { + MONO_DEBUG_FORMAT_NONE, + MONO_DEBUG_FORMAT_MONO, + /* Deprecated, the mdb debugger is not longer supported. */ + MONO_DEBUG_FORMAT_DEBUGGER +} MonoDebugFormat; + +void* (*mono_debug_init)(MonoDebugFormat format); +void* (*mono_debug_domain_create)(void* domain); + +/** +* \brief Loads Mono C API function pointers so that the above definitions can be called. +* \param mono_lib Mono.dll module. +*/ +void load_mono_functions(HMODULE mono_lib) { + // Enjoy the fact that C allows such sloppy casting + // In C++ you would have to cast to the precise function pointer type +#define GET_MONO_PROC(name) name = (void*)GetProcAddress(mono_lib, #name) + + // Find and assign all our functions that we are going to use + GET_MONO_PROC(mono_domain_assembly_open); + GET_MONO_PROC(mono_assembly_get_image); + GET_MONO_PROC(mono_runtime_invoke); + GET_MONO_PROC(mono_jit_init_version); + GET_MONO_PROC(mono_method_desc_new); + GET_MONO_PROC(mono_method_desc_search_in_class); + GET_MONO_PROC(mono_method_desc_search_in_image); + GET_MONO_PROC(mono_method_desc_free); + GET_MONO_PROC(mono_method_signature); + GET_MONO_PROC(mono_signature_get_param_count); + GET_MONO_PROC(mono_array_new); + GET_MONO_PROC(mono_get_string_class); + GET_MONO_PROC(mono_assembly_getrootdir); + GET_MONO_PROC(mono_thread_current); + GET_MONO_PROC(mono_thread_set_main); + GET_MONO_PROC(mono_domain_set_config); + GET_MONO_PROC(mono_set_dirs); + GET_MONO_PROC(mono_config_parse); + GET_MONO_PROC(mono_set_assemblies_path); + GET_MONO_PROC(mono_object_to_string); + GET_MONO_PROC(mono_string_to_utf8); + GET_MONO_PROC(mono_image_open_from_data_with_name); + GET_MONO_PROC(mono_get_exception_class); + GET_MONO_PROC(mono_object_get_virtual_method); + GET_MONO_PROC(mono_jit_parse_options); + GET_MONO_PROC(mono_debug_init); + GET_MONO_PROC(mono_debug_domain_create); + +#undef GET_MONO_PROC } \ No newline at end of file diff --git a/unityhook/util.h b/common/unityhook/util.h similarity index 96% rename from unityhook/util.h rename to common/unityhook/util.h index 41def7b..9ad0a80 100644 --- a/unityhook/util.h +++ b/common/unityhook/util.h @@ -1,20 +1,20 @@ -#pragma once - -#include - -wchar_t *widen(const char *str) { - const int reqsz = MultiByteToWideChar(CP_UTF8, 0, str, -1, NULL, 0); - wchar_t *result = malloc(reqsz * sizeof(wchar_t)); - - MultiByteToWideChar(CP_UTF8, 0, str, -1, result, reqsz); - return result; -} - -char *narrow(const wchar_t *str) { - const int reqsz = WideCharToMultiByte(CP_UTF8, 0, str, -1, NULL, 0, NULL, NULL); - char *result = malloc(reqsz * sizeof(char)); - - WideCharToMultiByte(CP_UTF8, 0, str, -1, result, reqsz, NULL, NULL); - return result; -} - +#pragma once + +#include + +wchar_t *widen(const char *str) { + const int reqsz = MultiByteToWideChar(CP_UTF8, 0, str, -1, NULL, 0); + wchar_t *result = malloc(reqsz * sizeof(wchar_t)); + + MultiByteToWideChar(CP_UTF8, 0, str, -1, result, reqsz); + return result; +} + +char *narrow(const wchar_t *str) { + const int reqsz = WideCharToMultiByte(CP_UTF8, 0, str, -1, NULL, 0, NULL, NULL); + char *result = malloc(reqsz * sizeof(char)); + + WideCharToMultiByte(CP_UTF8, 0, str, -1, result, reqsz, NULL, NULL); + return result; +} + diff --git a/util/async.c b/common/util/async.c similarity index 100% rename from util/async.c rename to common/util/async.c diff --git a/util/async.h b/common/util/async.h similarity index 100% rename from util/async.h rename to common/util/async.h diff --git a/util/crc.c b/common/util/crc.c similarity index 100% rename from util/crc.c rename to common/util/crc.c diff --git a/util/crc.h b/common/util/crc.h similarity index 100% rename from util/crc.h rename to common/util/crc.h diff --git a/util/dll-bind.c b/common/util/dll-bind.c similarity index 100% rename from util/dll-bind.c rename to common/util/dll-bind.c diff --git a/util/dll-bind.h b/common/util/dll-bind.h similarity index 100% rename from util/dll-bind.h rename to common/util/dll-bind.h diff --git a/util/dprintf.c b/common/util/dprintf.c similarity index 100% rename from util/dprintf.c rename to common/util/dprintf.c diff --git a/util/dprintf.h b/common/util/dprintf.h similarity index 100% rename from util/dprintf.h rename to common/util/dprintf.h diff --git a/util/dump.c b/common/util/dump.c similarity index 100% rename from util/dump.c rename to common/util/dump.c diff --git a/util/dump.h b/common/util/dump.h similarity index 100% rename from util/dump.h rename to common/util/dump.h diff --git a/util/env.c b/common/util/env.c similarity index 100% rename from util/env.c rename to common/util/env.c diff --git a/util/env.h b/common/util/env.h similarity index 100% rename from util/env.h rename to common/util/env.h diff --git a/util/get_function_ordinal.c b/common/util/get_function_ordinal.c similarity index 100% rename from util/get_function_ordinal.c rename to common/util/get_function_ordinal.c diff --git a/util/get_function_ordinal.h b/common/util/get_function_ordinal.h similarity index 100% rename from util/get_function_ordinal.h rename to common/util/get_function_ordinal.h diff --git a/util/lib.c b/common/util/lib.c similarity index 100% rename from util/lib.c rename to common/util/lib.c diff --git a/util/lib.h b/common/util/lib.h similarity index 100% rename from util/lib.h rename to common/util/lib.h diff --git a/util/meson.build b/common/util/meson.build similarity index 93% rename from util/meson.build rename to common/util/meson.build index 0274ad5..58782d3 100644 --- a/util/meson.build +++ b/common/util/meson.build @@ -21,6 +21,8 @@ util_lib = static_library( 'get_function_ordinal.h', 'lib.c', 'lib.h', + 'slurp.c', + 'slurp.h', 'str.c', 'str.h', 'env.c', diff --git a/common/util/slurp.c b/common/util/slurp.c new file mode 100644 index 0000000..1af73a4 --- /dev/null +++ b/common/util/slurp.c @@ -0,0 +1,67 @@ +#include +#include +#include +/* + * 'slurp' reads the file identified by 'path' into a character buffer + * pointed at by 'buf', optionally adding a terminating NUL if + * 'add_nul' is true. On success, the size of the file is returned; on + * failure, -1 is returned and ERRNO is set by the underlying system + * or library call that failed. + * + * WARNING: 'slurp' malloc()s memory to '*buf' which must be freed by + * the caller. + */ +long wslurp(const wchar_t* path, char **buf, bool add_nul) +{ + FILE *fp; + size_t fsz; + long off_end; + int rc; + + /* Open the file */ + fp = _wfopen(path, L"rb"); + if( NULL == fp ) { + return -1L; + } + + /* Seek to the end of the file */ + rc = fseek(fp, 0L, SEEK_END); + if( 0 != rc ) { + return -1L; + } + + /* Byte offset to the end of the file (size) */ + if( 0 > (off_end = ftell(fp)) ) { + return -1L; + } + fsz = (size_t)off_end; + + /* Allocate a buffer to hold the whole file */ + *buf = malloc( fsz+(int)add_nul ); + if( NULL == *buf ) { + return -1L; + } + + /* Rewind file pointer to start of file */ + rewind(fp); + + /* Slurp file into buffer */ + if( fsz != fread(*buf, 1, fsz, fp) ) { + free(*buf); + return -1L; + } + + /* Close the file */ + if( EOF == fclose(fp) ) { + free(*buf); + return -1L; + } + + if( add_nul ) { + /* Make sure the buffer is NUL-terminated, just in case */ + buf[fsz] = '\0'; + } + + /* Return the file size */ + return (long)fsz; +} \ No newline at end of file diff --git a/common/util/slurp.h b/common/util/slurp.h new file mode 100644 index 0000000..407a2d8 --- /dev/null +++ b/common/util/slurp.h @@ -0,0 +1,12 @@ +#include +/* + * 'slurp' reads the file identified by 'path' into a character buffer + * pointed at by 'buf', optionally adding a terminating NUL if + * 'add_nul' is true. On success, the size of the file is returned; on + * failure, -1 is returned and ERRNO is set by the underlying system + * or library call that failed. + * + * WARNING: 'slurp' malloc()s memory to '*buf' which must be freed by + * the caller. + */ +long wslurp(const wchar_t* path, char **buf, bool add_nul); \ No newline at end of file diff --git a/util/str.c b/common/util/str.c similarity index 100% rename from util/str.c rename to common/util/str.c diff --git a/util/str.h b/common/util/str.h similarity index 100% rename from util/str.h rename to common/util/str.h diff --git a/dist/carol/segatools.ini b/dist/carol/segatools.ini index e75f1cd..ea465ed 100644 --- a/dist/carol/segatools.ini +++ b/dist/carol/segatools.ini @@ -54,11 +54,20 @@ addrSuffix=11 dipsw1=1 [keychip] +; Keychip serial number. Keychip serials observed in the wild follow this +; pattern: `A\d{2}(E|X)-(01|20)[ABCDU]\d{8}`. +id=A69E-01A88888888 + ; The /24 LAN subnet that the emulated keychip will tell the game to expect. ; If you disable netenv then you must set this to your LAN's IP subnet, and ; that subnet must start with 192.168. subnet=192.168.126.0 +[pcbid] +; Set the Windows host name. This should be an ALLS MAIN ID, without the +; hyphen (which is not a valid character in a Windows host name). +serialNo=ACAE01A99999999 + ; ----------------------------------------------------------------------------- ; Misc. hooks settings ; ----------------------------------------------------------------------------- @@ -72,6 +81,8 @@ windowed=1 framed=1 ; Select the monitor to run the game on. (Fullscreen only, 0 =primary screen) monitor=0 +; Enable DPI awareness for the game process, preventing Windows from stretching the game window if a DPI scaling higher than 100% is used +dpiAware=1 ; ----------------------------------------------------------------------------- ; Custom IO settings diff --git a/dist/chuni/segatools.ini b/dist/chuni/segatools.ini index 3e87cb0..88c6171 100644 --- a/dist/chuni/segatools.ini +++ b/dist/chuni/segatools.ini @@ -46,11 +46,20 @@ addrSuffix=11 ; ----------------------------------------------------------------------------- [keychip] +; Keychip serial number. Keychip serials observed in the wild follow this +; pattern: `A\d{2}(E|X)-(01|20)[ABCDU]\d{8}`. +id=A69E-01A88888888 + ; The /24 LAN subnet that the emulated keychip will tell the game to expect. ; If you disable netenv then you must set this to your LAN's IP subnet, and ; that subnet must start with 192.168. subnet=192.168.139.0 +[pcbid] +; Set the Windows host name. This should be an ALLS MAIN ID, without the +; hyphen (which is not a valid character in a Windows host name). +serialNo=ACAE01A99999999 + ; ----------------------------------------------------------------------------- ; Misc. hooks settings ; ----------------------------------------------------------------------------- @@ -64,6 +73,8 @@ windowed=1 framed=1 ; Select the monitor to run the game on. (Fullscreen only, 0 =primary screen) monitor=0 +; Enable DPI awareness for the game process, preventing Windows from stretching the game window if a DPI scaling higher than 100% is used +dpiAware=1 ; ----------------------------------------------------------------------------- ; LED settings diff --git a/dist/chusan/segatools.ini b/dist/chusan/segatools.ini index 7ff4d0a..e204bb6 100644 --- a/dist/chusan/segatools.ini +++ b/dist/chusan/segatools.ini @@ -54,11 +54,20 @@ addrSuffix=11 ; ----------------------------------------------------------------------------- [keychip] +; Keychip serial number. Keychip serials observed in the wild follow this +; pattern: `A\d{2}(E|X)-(01|20)[ABCDU]\d{8}`. +id=A69E-01A88888888 + ; The /24 LAN subnet that the emulated keychip will tell the game to expect. ; If you disable netenv then you must set this to your LAN's IP subnet, and ; that subnet must start with 192.168. subnet=192.168.139.0 +[pcbid] +; Set the Windows host name. This should be an ALLS MAIN ID, without the +; hyphen (which is not a valid character in a Windows host name). +serialNo=ACAE01A99999999 + [system] ; Enable ALLS system settings. enable=1 @@ -90,6 +99,8 @@ windowed=1 framed=0 ; Select the monitor to run the game on. (Fullscreen only, 0 =primary screen) monitor=0 +; Enable DPI awareness for the game process, preventing Windows from stretching the game window if a DPI scaling higher than 100% is used +dpiAware=1 ; ----------------------------------------------------------------------------- ; LED settings diff --git a/dist/cm/segatools.ini b/dist/cm/segatools.ini index cd42cd6..653529c 100644 --- a/dist/cm/segatools.ini +++ b/dist/cm/segatools.ini @@ -47,11 +47,20 @@ enable=1 ; ----------------------------------------------------------------------------- [keychip] +; Keychip serial number. Keychip serials observed in the wild follow this +; pattern: `A\d{2}(E|X)-(01|20)[ABCDU]\d{8}`. +id=A69E-01A88888888 + ; The /24 LAN subnet that the emulated keychip will tell the game to expect. ; If you disable netenv then you must set this to your LAN's IP subnet, and ; that subnet must start with 192.168. subnet=192.168.165.0 +[pcbid] +; Set the Windows host name. This should be an ALLS MAIN ID, without the +; hyphen (which is not a valid character in a Windows host name). +serialNo=ACAE01A99999999 + [system] ; Enable ALLS system settings. enable=1 diff --git a/dist/cxb/segatools.ini b/dist/cxb/segatools.ini index 40589de..c15d5b5 100644 --- a/dist/cxb/segatools.ini +++ b/dist/cxb/segatools.ini @@ -54,6 +54,10 @@ enable=1 ; ----------------------------------------------------------------------------- [keychip] +; Keychip serial number. Keychip serials observed in the wild follow this +; pattern: `A\d{2}(E|X)-(01|20)[ABCDU]\d{8}`. +id=A69E-01A88888888 + ; The /24 LAN subnet that the emulated keychip will tell the game to expect. ; If you disable netenv then you must set this to your LAN's IP subnet, and ; that subnet must start with 192.168. @@ -62,6 +66,11 @@ billingCa=../DEVICE/ca.crt billingPub=../DEVICE/billing.pub billingType=0 +[pcbid] +; Set the Windows host name. This should be an ALLS MAIN ID, without the +; hyphen (which is not a valid character in a Windows host name). +serialNo=ACAE01A99999999 + [eeprom] ; See above path=../DEVICE/eeprom.bin @@ -83,6 +92,8 @@ windowed=1 framed=1 ; Select the monitor to run the game on. (Fullscreen only, 0 =primary screen) monitor=0 +; Enable DPI awareness for the game process, preventing Windows from stretching the game window if a DPI scaling higher than 100% is used +dpiAware=1 ; ----------------------------------------------------------------------------- ; Custom IO settings diff --git a/dist/diva/segatools.ini b/dist/diva/segatools.ini index e8db667..3864299 100644 --- a/dist/diva/segatools.ini +++ b/dist/diva/segatools.ini @@ -53,11 +53,20 @@ addrSuffix=11 dipsw1=1 [keychip] +; Keychip serial number. Keychip serials observed in the wild follow this +; pattern: `A\d{2}(E|X)-(01|20)[ABCDU]\d{8}`. +id=A69E-01A88888888 + ; The /24 LAN subnet that the emulated keychip will tell the game to expect. ; If you disable netenv then you must set this to your LAN's IP subnet, and ; that subnet must start with 192.168. subnet=192.168.78.0 +[pcbid] +; Set the Windows host name. This should be an ALLS MAIN ID, without the +; hyphen (which is not a valid character in a Windows host name). +serialNo=ACAE01A99999999 + ; ----------------------------------------------------------------------------- ; Misc. hooks settings ; ----------------------------------------------------------------------------- @@ -69,6 +78,9 @@ enable=1 windowed=1 ; Add a frame to the game window if running windowed. framed=0 +; Enable DPI awareness for the game process, preventing Windows from stretching the game window if a DPI scaling higher than 100% is used +dpiAware=1 + ; ----------------------------------------------------------------------------- ; Custom IO settings diff --git a/dist/fgo/launch.bat b/dist/fgo/launch.bat index 3be4f8a..1b76197 100644 --- a/dist/fgo/launch.bat +++ b/dist/fgo/launch.bat @@ -1,6 +1,6 @@ @echo off -cd /d %~dp0 +pushd %~dp0 inject -d -k fgohook.dll ago.exe diff --git a/dist/fgo/segatools.ini b/dist/fgo/segatools.ini index 4e846ee..1256d6c 100644 --- a/dist/fgo/segatools.ini +++ b/dist/fgo/segatools.ini @@ -67,11 +67,20 @@ addrSuffix=11 ; ----------------------------------------------------------------------------- [keychip] +; Keychip serial number. Keychip serials observed in the wild follow this +; pattern: `A\d{2}(E|X)-(01|20)[ABCDU]\d{8}`. +id=A69E-01A88888888 + ; The /24 LAN subnet that the emulated keychip will tell the game to expect. ; If you disable netenv then you must set this to your LAN's IP subnet, and ; that subnet must start with 192.168. subnet=192.168.167.0 +[pcbid] +; Set the Windows host name. This should be an ALLS MAIN ID, without the +; hyphen (which is not a valid character in a Windows host name). +serialNo=ACAE01A99999999 + [system] ; Enable ALLS system settings. enable=1 @@ -92,6 +101,8 @@ enable=1 windowed=0 ; Add a frame to the game window if running windowed. framed=0 +; Enable DPI awareness for the game process, preventing Windows from stretching the game window if a DPI scaling higher than 100% is used +dpiAware=1 [touch] ; WinTouch emulation setting. @@ -156,8 +167,11 @@ coin=0x72 ; : : AIME. : : ; '·:..............................................:·' ; -; Only XInput is currently supported. +; Select the input mode. "xinput" for controller, "keyboard" for keyboard. +mode=xinput + +[xinput] ; XInput bindings ; ; Left Stick Joystick @@ -166,3 +180,27 @@ coin=0x72 ; Left Shoulder Switch Target ; A/B Attack ; X/Y Noble Phantasm + +; Configure deadzones for the left thumbsticks. +; The default value for the left stick is 7849, max value is 32767. +stickDeadzone=7849 + +[keyboard] +; Keyboard bindings: + +; Stick controls (default: WASD) +up=0x57 +left=0x41 +down=0x53 +right=0x44 + +; Attack (default: Space) +attack=0x20 +; Dash (default: LSHIFT) +dash=0xa0 +; Change Target (default: J) +target=0x4A +; Re-center camera (default: K) +camera=0x4B +; Noble Phantasm (default: L) +np=0x4C diff --git a/dist/idac/segatools.ini b/dist/idac/segatools.ini index a2387af..f556c40 100644 --- a/dist/idac/segatools.ini +++ b/dist/idac/segatools.ini @@ -41,6 +41,10 @@ enable=1 ; ----------------------------------------------------------------------------- [keychip] +; Keychip serial number. Keychip serials observed in the wild follow this +; pattern: `A\d{2}(E|X)-(01|20)[ABCDU]\d{8}`. +id=A69E-01A88888888 + ; The /24 LAN subnet that the emulated keychip will tell the game to expect. ; If you disable netenv then you must set this to your LAN's IP subnet, and ; that subnet must start with 192.168. Set it to your LAN's subnet if you @@ -54,6 +58,11 @@ subnet=192.168.158.0 ; 1: JPN: Japan, 4: EXP: Export (for Asian markets) region=4 +[pcbid] +; Set the Windows host name. This should be an ALLS MAIN ID, without the +; hyphen (which is not a valid character in a Windows host name). +serialNo=ACAE01A99999999 + [system] ; Enable ALLS system settings. enable=1 diff --git a/dist/idz/segatools.ini b/dist/idz/segatools.ini index e617de2..18d5f1e 100644 --- a/dist/idz/segatools.ini +++ b/dist/idz/segatools.ini @@ -49,11 +49,20 @@ enable=1 ; ----------------------------------------------------------------------------- [keychip] +; Keychip serial number. Keychip serials observed in the wild follow this +; pattern: `A\d{2}(E|X)-(01|20)[ABCDU]\d{8}`. +id=A69E-01A88888888 + ; The /24 LAN subnet that the emulated keychip will tell the game to expect. ; If you disable netenv then you must set this to your LAN's IP subnet, and ; that subnet must start with 192.168. subnet=192.168.158.0 +[pcbid] +; Set the Windows host name. This should be an ALLS MAIN ID, without the +; hyphen (which is not a valid character in a Windows host name). +serialNo=ACAE01A99999999 + [ds] ; Region code on the emulated AMEX board DS EEPROM. ; 1: Japan @@ -97,6 +106,9 @@ windowed=0 framed=1 ; Select the monitor to run the game on. (Fullscreen only, 0=primary screen) monitor=0 +; Enable DPI awareness for the game process, preventing Windows from stretching the game window if a DPI scaling higher than 100% is used +dpiAware=1 + ; ----------------------------------------------------------------------------- ; Custom IO settings diff --git a/dist/kemono/segatools.ini b/dist/kemono/segatools.ini index 5f6186e..0bc8b87 100644 --- a/dist/kemono/segatools.ini +++ b/dist/kemono/segatools.ini @@ -51,11 +51,20 @@ addrSuffix=11 ; ----------------------------------------------------------------------------- [keychip] +; Keychip serial number. Keychip serials observed in the wild follow this +; pattern: `A\d{2}(E|X)-(01|20)[ABCDU]\d{8}`. +id=A69E-01A88888888 + ; The /24 LAN subnet that the emulated keychip will tell the game to expect. ; If you disable netenv then you must set this to your LAN's IP subnet, and ; that subnet must start with 192.168. subnet=192.168.179.0 +[pcbid] +; Set the Windows host name. This should be an ALLS MAIN ID, without the +; hyphen (which is not a valid character in a Windows host name). +serialNo=ACAE01A99999999 + [gpio] ; Emulated Nu DIP switch for Distribution Server setting. ; diff --git a/dist/mai2/segatools.ini b/dist/mai2/segatools.ini index dde853f..59673a9 100644 --- a/dist/mai2/segatools.ini +++ b/dist/mai2/segatools.ini @@ -51,11 +51,20 @@ addrSuffix=11 ; ----------------------------------------------------------------------------- [keychip] +; Keychip serial number. Keychip serials observed in the wild follow this +; pattern: `A\d{2}(E|X)-(01|20)[ABCDU]\d{8}`. +id=A69E-01A88888888 + ; The /24 LAN subnet that the emulated keychip will tell the game to expect. ; If you disable netenv then you must set this to your LAN's IP subnet, and ; that subnet must start with 192.168. subnet=192.168.172.0 +[pcbid] +; Set the Windows host name. This should be an ALLS MAIN ID, without the +; hyphen (which is not a valid character in a Windows host name). +serialNo=ACAE01A99999999 + [system] ; Enable ALLS system settings. enable=1 diff --git a/dist/mercury/segatools.ini b/dist/mercury/segatools.ini index 5e10634..38cdd70 100644 --- a/dist/mercury/segatools.ini +++ b/dist/mercury/segatools.ini @@ -51,11 +51,20 @@ addrSuffix=11 ; ----------------------------------------------------------------------------- [keychip] +; Keychip serial number. Keychip serials observed in the wild follow this +; pattern: `A\d{2}(E|X)-(01|20)[ABCDU]\d{8}`. +id=A69E-01A88888888 + ; The /24 LAN subnet that the emulated keychip will tell the game to expect. ; If you disable netenv then you must set this to your LAN's IP subnet, and ; that subnet must start with 192.168. subnet=192.168.174.0 +[pcbid] +; Set the Windows host name. This should be an ALLS MAIN ID, without the +; hyphen (which is not a valid character in a Windows host name). +serialNo=ACAE01A99999999 + [system] ; Enable ALLS system settings. enable=1 @@ -76,6 +85,9 @@ dipsw1=1 [gfx] ; Enables the graphics hook. enable=1 +; Enable DPI awareness for the game process, preventing Windows from stretching the game window if a DPI scaling higher than 100% is used +dpiAware=1 + ; Hooks related to the touch boards [touch] diff --git a/dist/mu3/segatools.ini b/dist/mu3/segatools.ini index 43fef6e..0ef991f 100644 --- a/dist/mu3/segatools.ini +++ b/dist/mu3/segatools.ini @@ -47,11 +47,20 @@ enable=1 ; ----------------------------------------------------------------------------- [keychip] +; Keychip serial number. Keychip serials observed in the wild follow this +; pattern: `A\d{2}(E|X)-(01|20)[ABCDU]\d{8}`. +id=A69E-01A88888888 + ; The /24 LAN subnet that the emulated keychip will tell the game to expect. ; If you disable netenv then you must set this to your LAN's IP subnet, and ; that subnet must start with 192.168. subnet=192.168.162.0 +[pcbid] +; Set the Windows host name. This should be an ALLS MAIN ID, without the +; hyphen (which is not a valid character in a Windows host name). +serialNo=ACAE01A99999999 + [system] ; Enable ALLS system settings. enable=1 @@ -72,6 +81,9 @@ dipsw1=1 [gfx] ; Enables the graphics hook. enable=1 +; Enable DPI awareness for the game process, preventing Windows from stretching the game window if a DPI scaling higher than 100% is used +dpiAware=1 + [unity] ; Enable Unity hook. This will allow you to run custom .NET code before the game diff --git a/dist/swdc/segatools.ini b/dist/swdc/segatools.ini index 1b24a74..0e6fe0f 100644 --- a/dist/swdc/segatools.ini +++ b/dist/swdc/segatools.ini @@ -51,11 +51,20 @@ addrSuffix=11 ; ----------------------------------------------------------------------------- [keychip] +; Keychip serial number. Keychip serials observed in the wild follow this +; pattern: `A\d{2}(E|X)-(01|20)[ABCDU]\d{8}`. +id=A69E-01A88888888 + ; The /24 LAN subnet that the emulated keychip will tell the game to expect. ; You must set this to your LAN's IP subnet, and that subnet must start with 192.168, ; in order to find the MAIN cabinet. subnet=192.168.160.0 +[pcbid] +; Set the Windows host name. This should be an ALLS MAIN ID, without the +; hyphen (which is not a valid character in a Windows host name). +serialNo=ACAE01A99999999 + [system] ; Enable ALLS system settings. enable=1 diff --git a/dist/tokyo/segatools.ini b/dist/tokyo/segatools.ini index 8c68b53..d48727f 100644 --- a/dist/tokyo/segatools.ini +++ b/dist/tokyo/segatools.ini @@ -37,6 +37,10 @@ addrSuffix=205 ; ----------------------------------------------------------------------------- [keychip] +; Keychip serial number. Keychip serials observed in the wild follow this +; pattern: `A\d{2}(E|X)-(01|20)[ABCDU]\d{8}`. +id=A69E-01A88888888 + ; The /24 LAN subnet that the emulated keychip will tell the game to expect. ; If you disable netenv then you must set this to your LAN's IP subnet, and ; that subnet must start with 192.168. @@ -52,6 +56,11 @@ subnet=192.168.149.0 ; with English language. region=1 +[pcbid] +; Set the Windows host name. This should be an ALLS MAIN ID, without the +; hyphen (which is not a valid character in a Windows host name). +serialNo=ACAE01A99999999 + [system] ; Enable ALLS system settings. enable=1 diff --git a/doc/config/common.md b/doc/config/common.md index 89c48c6..1485feb 100644 --- a/doc/config/common.md +++ b/doc/config/common.md @@ -101,6 +101,18 @@ emulates an IC card in its proximity. A variety of different IC cards can be emulated; the exact choice of card that is emulated depends on the presence or absence of the configured card ID files. +### `proxyFlag` + +Default: `2` + +The "proxy flag" of the emulated Thinca authentication card. This should be 2 if no proxy is used, and 3 if it is. Invalid values will break Thinca authentication card reading. This information can be obtained by checking for the presence of "use_proxy: true" `tfps-res-pro\env.json`. + +### `authdataPath` + +Default: `DEVICE\authdata.bin` + +Path to the binary file containing data for a Thinca authentication card (see `emoney.txt`) + ## `[vfd]` Controls emulation of the VFD GP1232A02A FUTABA assembly. @@ -342,6 +354,38 @@ Nu chassis DIP switch settings: - `111`: 1920x1080 - Switch 8: Game-specific. Not used in any shipping game. +## `[gfx]` + +### `enable` + +Default: `1` + +Enables graphic hooks. + +### `windowed` + +Default: `0` + +Force the game to run windowed. + +### `framed` + +Default: `0` + +Add a frame to the game window if running windowed. + +### `monitor` + +Default: `0` + +Select the monitor to run the game on. (Fullscreen only, 0 = primary screen) + +### `dpiAware` + +Default: `1` + +Sets the game to be DPI-aware. This prevents Windows automatically scaling the game window by your desktop's scaling factor, which may cause blurry graphics. + ## `[hwmon]` Configure stub implementation of the platform hardware monitor driver. The @@ -604,3 +648,19 @@ Default: Empty string Configure the location of the "Option" data mount point. This mount point is optional (hence the name, probably) and contains directories which contain minor over-the-air content updates. + +## `[epay]` + +Configure Thinca Payment (E-Money) emulation and hooks. + +### `enable` + +Default: `1` + +Enables the Thinca emulation. This will allow you to enable E-Money on compatible servers. + +### `hook` + +Default: `0` + +Enables hooking of respective Thinca DLL functions to emulate the existence of E-Money. This cannot be used with a real E-Money server. \ No newline at end of file diff --git a/doc/emoney.md b/doc/emoney.md new file mode 100644 index 0000000..05a6192 --- /dev/null +++ b/doc/emoney.md @@ -0,0 +1,213 @@ +# E-Money Authentication Procedure +by Haruka Akechi + +### SETTING UP + +1) Obtain the 64 byte long authentication card encryption key. `amdaemon.exe` holds the secrets. + +2) Inside the `emoney\` folder, install the python modules and launch the generator script: + +```shell +python -m pip install -r requirements.txt +python authcardgen.py --key +``` + +``` +Usage: authcardgen.py [OPTIONS] + +Options: + --cardid TEXT Card ID (64 hex characters) + --key TEXT Key (128 hex characters, required) [required] + --store-card-id TEXT Store Card ID (padded to 16 bytes) + --merchant-code TEXT Merchant Code (padded to 20 bytes) + --store-branch-id TEXT Store Branch ID (padded to 12 bytes) + --passphrase TEXT Passphrase, used for the pfx password (padded to 16 bytes) + --output TEXT Output filename + --help Show this message and exit. +``` + +3) Place the generated `authcard.bin` in your `DEVICE\` folder. + +4) Check `tfps-res-pro\env.json` for your game. If it contains a `"use_proxy": true` statement, add to segatools.ini: + +```ini +[aime] +proxy_flag=3 +``` + +5) Replace the two URLs in `tfps-res-pro\resource.xml` to your servers'. This is to ensure the Host header will match the certificate's. + +6) Where amdaemon.exe is located, there should be a `ca.pem`. Replace this file with either [this](https://curl.se/ca/cacert.pem) for the most common CA's (including Let's Encrypt), or whatever CA the server is using (your server will provide this). + +7) Run your game and enter the test menu, and navigate to E-Money Settings. + +8) Select "Terminal Authentication" + +9) Hold your key for scanning a card (default: RETURN) + +10) If your shop name shows up, everything was done succesfully. Otherwise, check the VFD. + +### TECHNICAL INFO + +For debugging anything e-money related, I highly recommend setting "emoney.log.level" to 4 in your game's amdaemon config.json. This should create a `\emoney_log\thincapayment.log`. + +When terminal authentication is started from the test menu, the game will check for an Aime reader of at least generation 3. If that is not fulfilled, the VFD will display "unsupported card reader" and abort. If the card reader is good, the VFD will prompt for a card to be touched, and the reader will start scanning for a MIFARE card, which from this point we call "Thinca Authentication Card". This card contains one unencrypted block (3) which contains: + +[0] = 0x54 // T + +[1] = 0x43 // C + +[2] = proxy_type + +[3] = 0x01 + +Afterwards, a number of encrypted blocks are read, namely the blocks 5,6,8,9,10,12,13 and 14. These blocks together form a 130 byte long binary blob that contains the authentication data. + +This data is encrypted as following: + +Given a fixed 0x40 byte long encryption key and a fixed 0x20 byte long static "card ID", both of which can be found in amdaemon: +XOR every byte of the encryption key with 0x1C. +Calculate a 0x20 bytes long HMAC-SHA-256 of the card ID with the XOR'ed encryption key as the key. +Calculate the needed IV by XORing the lower 0x10 bytes of the HMAC with the upper 0x10 bytes of the HMAC: + +``` +byte[] iv = new byte[16]; +for (int i = 0; i < 16; i++) { + iv[i] = (byte) (hmac[i + 16] ^ hmac[i]); +} +``` + +With this IV, and the HMAC as the key, finally encrypt the data with AES/CBC/PKCS5Padding. + +Now what is actually stored on such a card? This: + +``` ++---------------+---------------+-----------------+------------+----------+ +| Store Card ID | Merchant Code | Store Branch ID | Passphrase | NULL | ++---------------+---------------+-----------------+------------+----------+ +| 0x10 bytes | 0x14 bytes | 0xC bytes | 0x10 bytes | 0x1 byte | +| char* | char* | uint128_t | char* | NULL | ++---------------+---------------+-----------------+------------+----------+ +``` + +Only two things really matter here. The Store Branch ID must be non-zero, otherwise amdaemon will reject it, and the passphrase, which is the PFX key password (passphrase during authcard creation) for the certificate returned in the network response (see below). + +Technically with the Store Card ID you could bind different auth cards to different users, but for home usage, it really doesn't matter. + +That's the Thinca Authentication Card out of the way, so continue on to: + +### NETWORK + +First, a regular HTTP(S) connection will be made to the URL specified in tfps-res-pro\env.json, tasms.root_endpoint. + +Request Data: +`{"modelName":"ACA","serialNumber":"ACAE01A9999","merchantCode":"NOTSEGA","storeBranchNumber":11111,"storeCardId":"FAKESTORE"}` + +Note that the serialNumber here actually isn't the keychip ID, but rather the PCBID. The three other values are read from the Thinca Authentication Card. + +Response Headers: +`x-certificate-md5: ` + +Response Data: +``` +{ + "certificate": "", + "initSettings": { + "endpoints": { + "terminals": { + "uri": "https://localhost/emoney/terminals" + }, + "statuses": { + "uri": "https://localhost/emoney/statuses" + }, + "sales": { + "uri": "https://localhost/emoney/sales" + }, + "counters": { + "uri": "https://localhost/emoney/counters" + } + }, + "intervals": { + "checkSetting": 60, + "sendStatus": 60 + }, + "settigsType": "AmusementTerminalSettings", // sic + "status": "1", // a string + "terminalId": "536453645364536453645364536453", // must be exactly 30 characters + "version": "2024-01-01T01:01:01", // a timestamp + "availableElectronicMoney": [ + 1, + 2, + 3, + 5, + 6, + 8, + 9, + 91, // aimepay + 101 // "cash" ??? + ], + "cashAvailability": true, + "productCode": 1337 + } +} +``` + +Next up, we will connect to the TLAM service to get the URL for the TCAP service. Everything from this point on requires not only HTTPS, but also client certificate validation (which is the certificate returned from the previous request). Technically you don't need to validate it, but you must accept a client certificate or the client HTTPS library will not be happy. + +The client certificate itself must be signed with the same key than the server's HTTPS certificate. + +The client AND server certificate must have it's CA included in the "ca.pem" file in amdaemon's directory. You can freely replace this file with https://curl.se/ca/cacert.pem to allow Let's Encrypt and whatever else. + +At this point, "ThincaPayment::setClientCertificate(). ErrCode 203" means that the downloaded file couldn't be found, or the certificate password is wrong. + +[Warn ] TCAP communicate error 06514086 means the ca.pem has no entry for the given server CA. + +TLAM: +The TLAM url comes from tftp-res-pro\resource.xml, commonPrimaryUri. + +/initauth.jsp + +Request Data: + +Response Headers: +`Content-Type: application/x-tlam` +Response Data: +`SERV=https://localhost/emoney/tcap` + +TCAP: +Here be dragons. + +Is it this?? https://en.wikipedia.org/wiki/Transaction_Capabilities_Application_Part +Maybe thincatcapclient.dll holds the secrets? + +Request Data: +``` +02 05 01 00 ba 00 00 00 21 00 00 00 00 00 25 00 ....º... !.....%. +9f 00 01 00 00 07 47 65 6e 65 72 69 63 06 43 4c ......Ge neric.CL +49 45 4e 54 00 02 00 00 07 47 65 6e 65 72 69 63 IENT.... .Generic +06 53 54 41 54 55 53 00 03 00 00 07 47 65 6e 65 .STATUS. ....Gene +72 69 63 06 4f 50 54 49 4f 4e 00 04 00 00 06 46 ric.OPTI ON.....F +65 6c 69 43 61 03 52 2f 57 00 05 00 00 07 47 65 eliCa.R/ W.....Ge +6e 65 72 69 63 09 52 2f 57 5f 45 56 45 4e 54 00 neric.R/ W_EVENT. +06 00 00 07 47 65 6e 65 72 69 63 0a 52 2f 57 5f ....Gene ric.R/W_ +53 54 41 54 55 53 00 07 00 00 07 47 65 6e 65 72 STATUS.. ...Gener +69 63 0a 52 2f 57 5f 4f 50 54 49 4f 4e 00 08 00 ic.R/W_O PTION... +00 07 47 65 6e 65 72 69 63 06 4e 46 43 5f 52 57 ..Generi c.NFC_RW +00 00 00 26 00 03 02 05 00 00 00 00 22 00 00 ...&.... ....".. +``` + +and +``` +02 05 03 00 17 00 00 00 21 00 11 34 34 20 30 30 ........ !..44 00 +20 30 31 20 32 31 20 30 30 20 30 30 01 21 0 0 00 +``` + +Response Headers: +``` +Content-Type: application/x-tcap +Transfer-Encoding: chunked +``` +Response Data: +???? + +To be continued ... \ No newline at end of file diff --git a/emoney/authcardgen.py b/emoney/authcardgen.py new file mode 100644 index 0000000..ae821be --- /dev/null +++ b/emoney/authcardgen.py @@ -0,0 +1,131 @@ +import hmac +import hashlib +import click + +from Crypto.Cipher import AES +from Crypto.Util.Padding import pad, unpad +from pathlib import Path + + +class CardEncryptor: + def __init__( + self, + cardid_hex, + key_hex, + store_card_id_str="FAKESTORE", + merchant_code_str="NOTSEGA", + store_branch_id_str="11111", + passphrase_str="573", + output_file="authdata.bin", + ): + self.cardid = bytes.fromhex(cardid_hex) + self.key = bytearray.fromhex(key_hex) + self.output_file = output_file + + if len(self.cardid) != 0x20: + raise ValueError("Card ID must be 32 bytes (64 hex characters)") + if len(self.key) != 0x40: + raise ValueError("Key must be 64 bytes (128 hex characters)") + + # XOR the key with 0x1C as in original Java + for i in range(len(self.key)): + self.key[i] ^= 0x1C + + self.store_card_id = self._str_to_bytes(store_card_id_str, 0x10) + self.merchant_code = self._str_to_bytes(merchant_code_str, 0x14) + self.store_branch_id = self._str_to_bytes(store_branch_id_str, 0x0C) + self.passphrase = self._str_to_bytes(passphrase_str, 0x10) + + # Construct full data payload + self.data = ( + self.store_card_id + + self.merchant_code + + self.store_branch_id + + self.passphrase + + bytes([0x00]) # +1 null terminator / padding byte + ) + + def _str_to_bytes(self, s, length): + b = bytearray(length) + b[: len(s)] = s.encode() + return bytes(b) + + def _bytes_to_str(self, b): + return b.decode() + + def _bytes_to_hex(self, b): + return b.hex().upper() + + def _calculate_hmac_sha256(self, key, data, length): + h = hmac.new(key, data, hashlib.sha256) + return h.digest()[:length] + + def _aes_cbc_encrypt(self, key, data, iv): + cipher = AES.new(key, AES.MODE_CBC, iv) + return cipher.encrypt(pad(data, AES.block_size)) + + def _aes_cbc_decrypt(self, key, data, iv): + cipher = AES.new(key, AES.MODE_CBC, iv) + return unpad(cipher.decrypt(data), AES.block_size) + + def run(self): + print("Card ID:\t\t", self._bytes_to_hex(self.cardid)) + print("Store Card ID:\t\t", self._bytes_to_str(self.store_card_id)) + print("Merchant Code:\t\t", self._bytes_to_str(self.merchant_code)) + print("Store Branch ID:\t", self._bytes_to_str(self.store_branch_id)) + print("Passphrase:\t\t", self._bytes_to_str(self.passphrase)) + + hmac_output = self._calculate_hmac_sha256(self.key, self.cardid, 0x20) + # print("HMAC:\t\t", self._bytes_to_hex(hmac_output)) + + iv = bytes([hmac_output[i + 16] ^ hmac_output[i] for i in range(16)]) + # print("IV:\t\t", self._bytes_to_hex(iv)) + + encrypted = self._aes_cbc_encrypt(hmac_output, self.data, iv) + # print("ENCRYPTED:\t", self._bytes_to_hex(encrypted)) + Path(self.output_file).write_bytes(encrypted) + + decrypted = self._aes_cbc_decrypt(hmac_output, encrypted, iv) + # print("DECRYPTED:\t", self._bytes_to_hex(decrypted)) + + +@click.command() +@click.option( + "--cardid", + default="0102030401020304010203040102030401020304010203040102030401020304", + help="Card ID (64 hex characters)", +) +@click.option( + "--key", + required=True, + help="Key (128 hex characters, required)", +) +@click.option( + "--store-card-id", default="FAKESTORE", help="Store Card ID (padded to 16 bytes)" +) +@click.option( + "--merchant-code", default="NOTSEGA", help="Merchant Code (padded to 20 bytes)" +) +@click.option( + "--store-branch-id", default="11111", help="Store Branch ID (padded to 12 bytes)" +) +@click.option("--passphrase", default="573", help="Passphrase, used for the pfx password (padded to 16 bytes)") +@click.option("--output", default="authdata.bin", help="Output filename") +def cli(cardid, key, store_card_id, merchant_code, store_branch_id, passphrase, output): + if len(key) != 128 or not all(c in "0123456789abcdefABCDEF" for c in key): + raise click.BadParameter("The key must be a 128-character hexadecimal string.") + + encryptor = CardEncryptor( + cardid, + key, + store_card_id_str=store_card_id, + merchant_code_str=merchant_code, + store_branch_id_str=store_branch_id, + passphrase_str=passphrase, + output_file=output, + ) + encryptor.run() + + +if __name__ == "__main__": + cli() diff --git a/emoney/requirements.txt b/emoney/requirements.txt new file mode 100644 index 0000000..b21ba16 --- /dev/null +++ b/emoney/requirements.txt @@ -0,0 +1,2 @@ +click +pycryptodome diff --git a/fgoio/config.c b/fgoio/config.c deleted file mode 100644 index 6270391..0000000 --- a/fgoio/config.c +++ /dev/null @@ -1,20 +0,0 @@ -#include - -#include -#include -#include - -#include "fgoio/config.h" - - -void fgo_io_config_load( - struct fgo_io_config *cfg, - const wchar_t *filename) -{ - assert(cfg != NULL); - assert(filename != NULL); - - cfg->vk_test = GetPrivateProfileIntW(L"io4", L"test", VK_F1, filename); - cfg->vk_service = GetPrivateProfileIntW(L"io4", L"service", VK_F2, filename); - cfg->vk_coin = GetPrivateProfileIntW(L"io4", L"coin", VK_F3, filename); -} diff --git a/fgoio/config.h b/fgoio/config.h deleted file mode 100644 index 835e5e8..0000000 --- a/fgoio/config.h +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -#include -#include - -#include - -struct fgo_io_config { - uint8_t vk_test; - uint8_t vk_service; - uint8_t vk_coin; -}; - -void fgo_io_config_load( - struct fgo_io_config *cfg, - const wchar_t *filename); diff --git a/fgoio/fgoio.c b/fgoio/fgoio.c deleted file mode 100644 index 4a362a0..0000000 --- a/fgoio/fgoio.c +++ /dev/null @@ -1,152 +0,0 @@ -#include -#include -#include - -#include -#include - -#include "fgoio/fgoio.h" -#include "fgoio/config.h" -#include "util/dprintf.h" -#include "util/env.h" - -static uint8_t fgo_opbtn; -static uint8_t fgo_gamebtn; -static int16_t fgo_stick_x; -static int16_t fgo_stick_y; -static struct fgo_io_config fgo_io_cfg; -static bool fgo_io_coin; - -uint16_t fgo_io_get_api_version(void) -{ - return 0x0100; -} - -HRESULT fgo_io_init(void) -{ - fgo_io_config_load(&fgo_io_cfg, get_config_path()); - - return S_OK; -} - -HRESULT fgo_io_poll(void) -{ - XINPUT_STATE xi; - WORD xb; - - fgo_opbtn = 0; - fgo_gamebtn = 0; - fgo_stick_x = 0; - fgo_stick_y = 0; - - if (GetAsyncKeyState(fgo_io_cfg.vk_test) & 0x8000) { - fgo_opbtn |= FGO_IO_OPBTN_TEST; - } - - if (GetAsyncKeyState(fgo_io_cfg.vk_service) & 0x8000) { - fgo_opbtn |= FGO_IO_OPBTN_SERVICE; - } - - if (GetAsyncKeyState(fgo_io_cfg.vk_coin) & 0x8000) { - if (!fgo_io_coin) { - fgo_io_coin = true; - fgo_opbtn |= FGO_IO_OPBTN_COIN; - } - } else { - fgo_io_coin = false; - } - - memset(&xi, 0, sizeof(xi)); - XInputGetState(0, &xi); - xb = xi.Gamepad.wButtons; - - if (xi.Gamepad.bLeftTrigger > 64) { - fgo_gamebtn |= FGO_IO_GAMEBTN_SPEED_UP; - } - - if (xb & XINPUT_GAMEPAD_LEFT_SHOULDER) { - fgo_gamebtn |= FGO_IO_GAMEBTN_TARGET; - } - - if (xb & XINPUT_GAMEPAD_A || xb & XINPUT_GAMEPAD_B) { - fgo_gamebtn |= FGO_IO_GAMEBTN_ATTACK; - } - - if (xb & XINPUT_GAMEPAD_Y || xb & XINPUT_GAMEPAD_X) { - fgo_gamebtn |= FGO_IO_GAMEBTN_NOBLE_PHANTASHM; - } - - if (xb & XINPUT_GAMEPAD_LEFT_THUMB) { - fgo_gamebtn |= FGO_IO_GAMEBTN_CAMERA; - } - - float LX = xi.Gamepad.sThumbLX; - float LY = xi.Gamepad.sThumbLY; - - // determine how far the controller is pushed - float magnitude = sqrt(LX*LX + LY*LY); - - // determine the direction the controller is pushed - float normalizedLX = LX / magnitude; - float normalizedLY = LY / magnitude; - - float normalizedMagnitude = 0; - - // check if the controller is outside a circular dead zone - if (magnitude > XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE) - { - // clip the magnitude at its expected maximum value - if (magnitude > 32767) magnitude = 32767; - - // adjust magnitude relative to the end of the dead zone - magnitude -= XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE; - - // optionally normalize the magnitude with respect to its expected range - // giving a magnitude value of 0.0 to 1.0 - normalizedMagnitude = magnitude / (32767 - XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE); - } else // if the controller is in the deadzone zero out the magnitude - { - magnitude = 0.0; - normalizedMagnitude = 0.0; - } - - fgo_stick_x = (int16_t)(normalizedLX * normalizedMagnitude * 32767); - fgo_stick_y = (int16_t)(normalizedLY * normalizedMagnitude * 32767); - - return S_OK; -} - -void fgo_io_get_opbtns(uint8_t *opbtn) -{ - if (opbtn != NULL) { - *opbtn = fgo_opbtn; - } -} - -void fgo_io_get_gamebtns(uint8_t *btn) -{ - if (btn != NULL) { - *btn = fgo_gamebtn; - } -} - -void fgo_io_get_analogs(int16_t *stick_x, int16_t *stick_y) -{ - if (stick_x != NULL) { - *stick_x = fgo_stick_x; - } - - if (stick_y != NULL) { - *stick_y = fgo_stick_y; - } -} - -HRESULT fgo_io_led_init(void) -{ - return S_OK; -} - -void fgo_io_led_set_colors(uint8_t board, uint8_t *rgb) -{ - return; -} diff --git a/carolhook/carol-dll.c b/games/carolhook/carol-dll.c similarity index 100% rename from carolhook/carol-dll.c rename to games/carolhook/carol-dll.c diff --git a/carolhook/carol-dll.h b/games/carolhook/carol-dll.h similarity index 100% rename from carolhook/carol-dll.h rename to games/carolhook/carol-dll.h diff --git a/carolhook/carolhook.def b/games/carolhook/carolhook.def similarity index 100% rename from carolhook/carolhook.def rename to games/carolhook/carolhook.def diff --git a/carolhook/config.c b/games/carolhook/config.c similarity index 100% rename from carolhook/config.c rename to games/carolhook/config.c diff --git a/carolhook/config.h b/games/carolhook/config.h similarity index 100% rename from carolhook/config.h rename to games/carolhook/config.h diff --git a/carolhook/controlbd.c b/games/carolhook/controlbd.c similarity index 100% rename from carolhook/controlbd.c rename to games/carolhook/controlbd.c diff --git a/carolhook/controlbd.h b/games/carolhook/controlbd.h similarity index 100% rename from carolhook/controlbd.h rename to games/carolhook/controlbd.h diff --git a/carolhook/dllmain.c b/games/carolhook/dllmain.c similarity index 97% rename from carolhook/dllmain.c rename to games/carolhook/dllmain.c index 762b33d..35fc7f0 100644 --- a/carolhook/dllmain.c +++ b/games/carolhook/dllmain.c @@ -74,8 +74,6 @@ static DWORD CALLBACK carol_pre_startup(void) HMODULE dbghelp; dprintf("--- Begin carol_pre_startup ---\n"); - if ( !SetProcessDPIAware() ) - dprintf("Failed to set process DPI awareness level!\n"); /* Pin the D3D shader compiler. This makes startup much faster. */ diff --git a/carolhook/jvs.c b/games/carolhook/jvs.c similarity index 100% rename from carolhook/jvs.c rename to games/carolhook/jvs.c diff --git a/carolhook/jvs.h b/games/carolhook/jvs.h similarity index 100% rename from carolhook/jvs.h rename to games/carolhook/jvs.h diff --git a/carolhook/ledbd.c b/games/carolhook/ledbd.c similarity index 100% rename from carolhook/ledbd.c rename to games/carolhook/ledbd.c diff --git a/carolhook/ledbd.h b/games/carolhook/ledbd.h similarity index 100% rename from carolhook/ledbd.h rename to games/carolhook/ledbd.h diff --git a/carolhook/meson.build b/games/carolhook/meson.build similarity index 100% rename from carolhook/meson.build rename to games/carolhook/meson.build diff --git a/carolhook/touch.c b/games/carolhook/touch.c similarity index 100% rename from carolhook/touch.c rename to games/carolhook/touch.c diff --git a/carolhook/touch.h b/games/carolhook/touch.h similarity index 100% rename from carolhook/touch.h rename to games/carolhook/touch.h diff --git a/carolio/carolio.c b/games/carolio/carolio.c similarity index 100% rename from carolio/carolio.c rename to games/carolio/carolio.c diff --git a/carolio/carolio.h b/games/carolio/carolio.h similarity index 100% rename from carolio/carolio.h rename to games/carolio/carolio.h diff --git a/carolio/config.c b/games/carolio/config.c similarity index 100% rename from carolio/config.c rename to games/carolio/config.c diff --git a/carolio/config.h b/games/carolio/config.h similarity index 100% rename from carolio/config.h rename to games/carolio/config.h diff --git a/carolio/meson.build b/games/carolio/meson.build similarity index 100% rename from carolio/meson.build rename to games/carolio/meson.build diff --git a/chunihook/chuni-dll.c b/games/chunihook/chuni-dll.c similarity index 100% rename from chunihook/chuni-dll.c rename to games/chunihook/chuni-dll.c diff --git a/chunihook/chuni-dll.h b/games/chunihook/chuni-dll.h similarity index 100% rename from chunihook/chuni-dll.h rename to games/chunihook/chuni-dll.h diff --git a/chunihook/chunihook.def b/games/chunihook/chunihook.def similarity index 100% rename from chunihook/chunihook.def rename to games/chunihook/chunihook.def diff --git a/chunihook/config.c b/games/chunihook/config.c similarity index 100% rename from chunihook/config.c rename to games/chunihook/config.c diff --git a/chunihook/config.h b/games/chunihook/config.h similarity index 100% rename from chunihook/config.h rename to games/chunihook/config.h diff --git a/chunihook/dllmain.c b/games/chunihook/dllmain.c similarity index 100% rename from chunihook/dllmain.c rename to games/chunihook/dllmain.c diff --git a/chunihook/jvs.c b/games/chunihook/jvs.c similarity index 100% rename from chunihook/jvs.c rename to games/chunihook/jvs.c diff --git a/chunihook/jvs.h b/games/chunihook/jvs.h similarity index 100% rename from chunihook/jvs.h rename to games/chunihook/jvs.h diff --git a/chunihook/meson.build b/games/chunihook/meson.build similarity index 100% rename from chunihook/meson.build rename to games/chunihook/meson.build diff --git a/chunihook/slider.c b/games/chunihook/slider.c similarity index 100% rename from chunihook/slider.c rename to games/chunihook/slider.c diff --git a/chunihook/slider.h b/games/chunihook/slider.h similarity index 100% rename from chunihook/slider.h rename to games/chunihook/slider.h diff --git a/chuniio/chu2to3.c b/games/chuniio/chu2to3.c similarity index 100% rename from chuniio/chu2to3.c rename to games/chuniio/chu2to3.c diff --git a/chuniio/chu2to3.h b/games/chuniio/chu2to3.h similarity index 100% rename from chuniio/chu2to3.h rename to games/chuniio/chu2to3.h diff --git a/chuniio/chuniio.c b/games/chuniio/chuniio.c similarity index 100% rename from chuniio/chuniio.c rename to games/chuniio/chuniio.c diff --git a/chuniio/chuniio.h b/games/chuniio/chuniio.h similarity index 100% rename from chuniio/chuniio.h rename to games/chuniio/chuniio.h diff --git a/chuniio/config.c b/games/chuniio/config.c similarity index 100% rename from chuniio/config.c rename to games/chuniio/config.c diff --git a/chuniio/config.h b/games/chuniio/config.h similarity index 100% rename from chuniio/config.h rename to games/chuniio/config.h diff --git a/chuniio/leddata.h b/games/chuniio/leddata.h similarity index 100% rename from chuniio/leddata.h rename to games/chuniio/leddata.h diff --git a/chuniio/ledoutput.c b/games/chuniio/ledoutput.c similarity index 100% rename from chuniio/ledoutput.c rename to games/chuniio/ledoutput.c diff --git a/chuniio/ledoutput.h b/games/chuniio/ledoutput.h similarity index 100% rename from chuniio/ledoutput.h rename to games/chuniio/ledoutput.h diff --git a/chuniio/meson.build b/games/chuniio/meson.build similarity index 100% rename from chuniio/meson.build rename to games/chuniio/meson.build diff --git a/chuniio/pipeimpl.c b/games/chuniio/pipeimpl.c similarity index 100% rename from chuniio/pipeimpl.c rename to games/chuniio/pipeimpl.c diff --git a/chuniio/pipeimpl.h b/games/chuniio/pipeimpl.h similarity index 100% rename from chuniio/pipeimpl.h rename to games/chuniio/pipeimpl.h diff --git a/chuniio/serialimpl.c b/games/chuniio/serialimpl.c similarity index 100% rename from chuniio/serialimpl.c rename to games/chuniio/serialimpl.c diff --git a/chuniio/serialimpl.h b/games/chuniio/serialimpl.h similarity index 100% rename from chuniio/serialimpl.h rename to games/chuniio/serialimpl.h diff --git a/chusanhook/chuni-dll.c b/games/chusanhook/chuni-dll.c similarity index 100% rename from chusanhook/chuni-dll.c rename to games/chusanhook/chuni-dll.c diff --git a/chusanhook/chuni-dll.h b/games/chusanhook/chuni-dll.h similarity index 100% rename from chusanhook/chuni-dll.h rename to games/chusanhook/chuni-dll.h diff --git a/chusanhook/chusanhook.def b/games/chusanhook/chusanhook.def similarity index 100% rename from chusanhook/chusanhook.def rename to games/chusanhook/chusanhook.def diff --git a/chusanhook/config.c b/games/chusanhook/config.c similarity index 100% rename from chusanhook/config.c rename to games/chusanhook/config.c diff --git a/chusanhook/config.h b/games/chusanhook/config.h similarity index 100% rename from chusanhook/config.h rename to games/chusanhook/config.h diff --git a/chusanhook/dllmain.c b/games/chusanhook/dllmain.c similarity index 100% rename from chusanhook/dllmain.c rename to games/chusanhook/dllmain.c diff --git a/chusanhook/io4.c b/games/chusanhook/io4.c similarity index 100% rename from chusanhook/io4.c rename to games/chusanhook/io4.c diff --git a/chusanhook/io4.h b/games/chusanhook/io4.h similarity index 100% rename from chusanhook/io4.h rename to games/chusanhook/io4.h diff --git a/chusanhook/meson.build b/games/chusanhook/meson.build similarity index 100% rename from chusanhook/meson.build rename to games/chusanhook/meson.build diff --git a/chusanhook/slider.c b/games/chusanhook/slider.c similarity index 100% rename from chusanhook/slider.c rename to games/chusanhook/slider.c diff --git a/chusanhook/slider.h b/games/chusanhook/slider.h similarity index 100% rename from chusanhook/slider.h rename to games/chusanhook/slider.h diff --git a/cmhook/cm-dll.c b/games/cmhook/cm-dll.c similarity index 100% rename from cmhook/cm-dll.c rename to games/cmhook/cm-dll.c diff --git a/cmhook/cm-dll.h b/games/cmhook/cm-dll.h similarity index 100% rename from cmhook/cm-dll.h rename to games/cmhook/cm-dll.h diff --git a/cmhook/cmhook.def b/games/cmhook/cmhook.def similarity index 100% rename from cmhook/cmhook.def rename to games/cmhook/cmhook.def diff --git a/cmhook/config.c b/games/cmhook/config.c similarity index 100% rename from cmhook/config.c rename to games/cmhook/config.c diff --git a/cmhook/config.h b/games/cmhook/config.h similarity index 100% rename from cmhook/config.h rename to games/cmhook/config.h diff --git a/cmhook/dllmain.c b/games/cmhook/dllmain.c similarity index 100% rename from cmhook/dllmain.c rename to games/cmhook/dllmain.c diff --git a/cmhook/io4.c b/games/cmhook/io4.c similarity index 100% rename from cmhook/io4.c rename to games/cmhook/io4.c diff --git a/cmhook/io4.h b/games/cmhook/io4.h similarity index 100% rename from cmhook/io4.h rename to games/cmhook/io4.h diff --git a/cmhook/meson.build b/games/cmhook/meson.build similarity index 100% rename from cmhook/meson.build rename to games/cmhook/meson.build diff --git a/cmio/cmio.c b/games/cmio/cmio.c similarity index 100% rename from cmio/cmio.c rename to games/cmio/cmio.c diff --git a/cmio/cmio.h b/games/cmio/cmio.h similarity index 100% rename from cmio/cmio.h rename to games/cmio/cmio.h diff --git a/cmio/config.c b/games/cmio/config.c similarity index 100% rename from cmio/config.c rename to games/cmio/config.c diff --git a/cmio/config.h b/games/cmio/config.h similarity index 100% rename from cmio/config.h rename to games/cmio/config.h diff --git a/cmio/meson.build b/games/cmio/meson.build similarity index 100% rename from cmio/meson.build rename to games/cmio/meson.build diff --git a/cxbhook/config.c b/games/cxbhook/config.c similarity index 100% rename from cxbhook/config.c rename to games/cxbhook/config.c diff --git a/cxbhook/config.h b/games/cxbhook/config.h similarity index 100% rename from cxbhook/config.h rename to games/cxbhook/config.h diff --git a/cxbhook/cxb-dll.c b/games/cxbhook/cxb-dll.c similarity index 100% rename from cxbhook/cxb-dll.c rename to games/cxbhook/cxb-dll.c diff --git a/cxbhook/cxb-dll.h b/games/cxbhook/cxb-dll.h similarity index 100% rename from cxbhook/cxb-dll.h rename to games/cxbhook/cxb-dll.h diff --git a/cxbhook/cxbhook.def b/games/cxbhook/cxbhook.def similarity index 100% rename from cxbhook/cxbhook.def rename to games/cxbhook/cxbhook.def diff --git a/cxbhook/dllmain.c b/games/cxbhook/dllmain.c similarity index 100% rename from cxbhook/dllmain.c rename to games/cxbhook/dllmain.c diff --git a/cxbhook/led.c b/games/cxbhook/led.c similarity index 100% rename from cxbhook/led.c rename to games/cxbhook/led.c diff --git a/cxbhook/led.h b/games/cxbhook/led.h similarity index 100% rename from cxbhook/led.h rename to games/cxbhook/led.h diff --git a/cxbhook/meson.build b/games/cxbhook/meson.build similarity index 100% rename from cxbhook/meson.build rename to games/cxbhook/meson.build diff --git a/cxbhook/revio.c b/games/cxbhook/revio.c similarity index 100% rename from cxbhook/revio.c rename to games/cxbhook/revio.c diff --git a/cxbhook/revio.h b/games/cxbhook/revio.h similarity index 100% rename from cxbhook/revio.h rename to games/cxbhook/revio.h diff --git a/cxbio/config.c b/games/cxbio/config.c similarity index 100% rename from cxbio/config.c rename to games/cxbio/config.c diff --git a/cxbio/config.h b/games/cxbio/config.h similarity index 100% rename from cxbio/config.h rename to games/cxbio/config.h diff --git a/cxbio/cxbio.c b/games/cxbio/cxbio.c similarity index 100% rename from cxbio/cxbio.c rename to games/cxbio/cxbio.c diff --git a/cxbio/cxbio.h b/games/cxbio/cxbio.h similarity index 100% rename from cxbio/cxbio.h rename to games/cxbio/cxbio.h diff --git a/cxbio/meson.build b/games/cxbio/meson.build similarity index 100% rename from cxbio/meson.build rename to games/cxbio/meson.build diff --git a/divahook/config.c b/games/divahook/config.c similarity index 100% rename from divahook/config.c rename to games/divahook/config.c diff --git a/divahook/config.h b/games/divahook/config.h similarity index 100% rename from divahook/config.h rename to games/divahook/config.h diff --git a/divahook/diva-dll.c b/games/divahook/diva-dll.c similarity index 100% rename from divahook/diva-dll.c rename to games/divahook/diva-dll.c diff --git a/divahook/diva-dll.h b/games/divahook/diva-dll.h similarity index 100% rename from divahook/diva-dll.h rename to games/divahook/diva-dll.h diff --git a/divahook/divahook.def b/games/divahook/divahook.def similarity index 100% rename from divahook/divahook.def rename to games/divahook/divahook.def diff --git a/divahook/dllmain.c b/games/divahook/dllmain.c similarity index 100% rename from divahook/dllmain.c rename to games/divahook/dllmain.c diff --git a/divahook/jvs.c b/games/divahook/jvs.c similarity index 100% rename from divahook/jvs.c rename to games/divahook/jvs.c diff --git a/divahook/jvs.h b/games/divahook/jvs.h similarity index 100% rename from divahook/jvs.h rename to games/divahook/jvs.h diff --git a/divahook/meson.build b/games/divahook/meson.build similarity index 100% rename from divahook/meson.build rename to games/divahook/meson.build diff --git a/divahook/slider.c b/games/divahook/slider.c similarity index 100% rename from divahook/slider.c rename to games/divahook/slider.c diff --git a/divahook/slider.h b/games/divahook/slider.h similarity index 100% rename from divahook/slider.h rename to games/divahook/slider.h diff --git a/divaio/config.c b/games/divaio/config.c similarity index 100% rename from divaio/config.c rename to games/divaio/config.c diff --git a/divaio/config.h b/games/divaio/config.h similarity index 100% rename from divaio/config.h rename to games/divaio/config.h diff --git a/divaio/divaio.c b/games/divaio/divaio.c similarity index 100% rename from divaio/divaio.c rename to games/divaio/divaio.c diff --git a/divaio/divaio.h b/games/divaio/divaio.h similarity index 100% rename from divaio/divaio.h rename to games/divaio/divaio.h diff --git a/divaio/meson.build b/games/divaio/meson.build similarity index 100% rename from divaio/meson.build rename to games/divaio/meson.build diff --git a/fgohook/config.c b/games/fgohook/config.c similarity index 100% rename from fgohook/config.c rename to games/fgohook/config.c diff --git a/fgohook/config.h b/games/fgohook/config.h similarity index 100% rename from fgohook/config.h rename to games/fgohook/config.h diff --git a/fgohook/deck.c b/games/fgohook/deck.c similarity index 100% rename from fgohook/deck.c rename to games/fgohook/deck.c diff --git a/fgohook/deck.h b/games/fgohook/deck.h similarity index 100% rename from fgohook/deck.h rename to games/fgohook/deck.h diff --git a/fgohook/dllmain.c b/games/fgohook/dllmain.c similarity index 100% rename from fgohook/dllmain.c rename to games/fgohook/dllmain.c diff --git a/fgohook/fgo-dll.c b/games/fgohook/fgo-dll.c similarity index 100% rename from fgohook/fgo-dll.c rename to games/fgohook/fgo-dll.c diff --git a/fgohook/fgo-dll.h b/games/fgohook/fgo-dll.h similarity index 100% rename from fgohook/fgo-dll.h rename to games/fgohook/fgo-dll.h diff --git a/fgohook/fgohook.def b/games/fgohook/fgohook.def similarity index 100% rename from fgohook/fgohook.def rename to games/fgohook/fgohook.def diff --git a/fgohook/ftdi.c b/games/fgohook/ftdi.c similarity index 100% rename from fgohook/ftdi.c rename to games/fgohook/ftdi.c diff --git a/fgohook/ftdi.h b/games/fgohook/ftdi.h similarity index 100% rename from fgohook/ftdi.h rename to games/fgohook/ftdi.h diff --git a/fgohook/io4.c b/games/fgohook/io4.c similarity index 97% rename from fgohook/io4.c rename to games/fgohook/io4.c index b2deb5f..67dfba4 100644 --- a/fgohook/io4.c +++ b/games/fgohook/io4.c @@ -87,7 +87,7 @@ static HRESULT fgo_io4_poll(void *ctx, struct io4_state *state) state->buttons[0] |= 1 << 1; } - if (gamebtn & FGO_IO_GAMEBTN_NOBLE_PHANTASHM) { + if (gamebtn & FGO_IO_GAMEBTN_NOBLE_PHANTASM) { state->buttons[0] |= 1 << 0; } diff --git a/fgohook/io4.h b/games/fgohook/io4.h similarity index 100% rename from fgohook/io4.h rename to games/fgohook/io4.h diff --git a/fgohook/meson.build b/games/fgohook/meson.build similarity index 100% rename from fgohook/meson.build rename to games/fgohook/meson.build diff --git a/games/fgoio/backend.h b/games/fgoio/backend.h new file mode 100644 index 0000000..578bda4 --- /dev/null +++ b/games/fgoio/backend.h @@ -0,0 +1,10 @@ +#pragma once + +#include + +#include "fgoio/fgoio.h" + +struct fgo_io_backend { + void (*get_gamebtns)(uint8_t *gamebtn); + void (*get_analogs)(int16_t *x, int16_t *y); +}; diff --git a/games/fgoio/config.c b/games/fgoio/config.c new file mode 100644 index 0000000..437b7be --- /dev/null +++ b/games/fgoio/config.c @@ -0,0 +1,58 @@ +#include + +#include +#include +#include + +#include "fgoio/config.h" + +#include + + +void fgo_kb_config_load( + struct fgo_kb_config *cfg, + const wchar_t *filename) { + + cfg->vk_attack = GetPrivateProfileIntW(L"keyboard", L"attack", ' ', filename); + cfg->vk_dash = GetPrivateProfileIntW(L"keyboard", L"dash", VK_LSHIFT, filename); + cfg->vk_target = GetPrivateProfileIntW(L"keyboard", L"target", 'J', filename); + cfg->vk_camera = GetPrivateProfileIntW(L"keyboard", L"camera", 'K', filename); + cfg->vk_np = GetPrivateProfileIntW(L"keyboard", L"np", 'L', filename); + + // Standard WASD + cfg->vk_right = GetPrivateProfileIntW(L"keyboard", L"right", 'D', filename); + cfg->vk_left = GetPrivateProfileIntW(L"keyboard", L"left", 'A', filename); + cfg->vk_down = GetPrivateProfileIntW(L"keyboard", L"down", 'S', filename); + cfg->vk_up = GetPrivateProfileIntW(L"keyboard", L"up", 'W', filename); +} + +void fgo_xi_config_load( + struct fgo_xi_config *cfg, + const wchar_t *filename) { + + cfg->stick_deadzone = GetPrivateProfileIntW(L"xinput", L"stickDeadzone", XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE, filename); + +} + +void fgo_io_config_load( + struct fgo_io_config *cfg, + const wchar_t *filename) +{ + assert(cfg != NULL); + assert(filename != NULL); + + cfg->vk_test = GetPrivateProfileIntW(L"io4", L"test", VK_F1, filename); + cfg->vk_service = GetPrivateProfileIntW(L"io4", L"service", VK_F2, filename); + cfg->vk_coin = GetPrivateProfileIntW(L"io4", L"coin", VK_F3, filename); + + GetPrivateProfileStringW( + L"io4", + L"mode", + L"xinput", + cfg->mode, + _countof(cfg->mode), + filename); + + fgo_xi_config_load(&cfg->xi, filename); + fgo_kb_config_load(&cfg->kb, filename); +} diff --git a/games/fgoio/config.h b/games/fgoio/config.h new file mode 100644 index 0000000..d824ff5 --- /dev/null +++ b/games/fgoio/config.h @@ -0,0 +1,38 @@ +#pragma once + +#include +#include + +#include + +struct fgo_kb_config { + uint8_t vk_np; + uint8_t vk_target; + uint8_t vk_dash; + uint8_t vk_attack; + uint8_t vk_camera; + uint8_t vk_right; + uint8_t vk_left; + uint8_t vk_down; + uint8_t vk_up; +}; + +struct fgo_xi_config { + uint16_t stick_deadzone; +}; + +struct fgo_io_config { + uint8_t vk_test; + uint8_t vk_service; + uint8_t vk_coin; + + wchar_t mode[12]; + struct fgo_kb_config kb; + struct fgo_xi_config xi; +}; + +void fgo_kb_config_load(struct fgo_kb_config *cfg, const wchar_t *filename); +void fgo_xi_config_load(struct fgo_xi_config *cfg, const wchar_t *filename); +void fgo_io_config_load( + struct fgo_io_config *cfg, + const wchar_t *filename); diff --git a/games/fgoio/fgoio.c b/games/fgoio/fgoio.c new file mode 100644 index 0000000..4817bc0 --- /dev/null +++ b/games/fgoio/fgoio.c @@ -0,0 +1,103 @@ +#include +#include +#include + +#include + +#include "fgoio/fgoio.h" + +#include + +#include "keyboard.h" +#include "xi.h" +#include "fgoio/config.h" +#include "util/dprintf.h" +#include "util/env.h" +#include "util/str.h" + +static uint8_t fgo_opbtn; +static uint8_t fgo_gamebtn; +static int16_t fgo_stick_x; +static int16_t fgo_stick_y; +static struct fgo_io_config fgo_io_cfg; +static const struct fgo_io_backend* fgo_io_backend; +static bool fgo_io_coin; + +uint16_t fgo_io_get_api_version(void) { + return 0x0100; +} + +HRESULT fgo_io_init(void) { + fgo_io_config_load(&fgo_io_cfg, get_config_path()); + + HRESULT hr; + + if (wstr_ieq(fgo_io_cfg.mode, L"keyboard")) { + hr = fgo_kb_init(&fgo_io_cfg.kb, &fgo_io_backend); + } else if (wstr_ieq(fgo_io_cfg.mode, L"xinput")) { + hr = fgo_xi_init(&fgo_io_cfg.xi, &fgo_io_backend); + } else { + hr = E_INVALIDARG; + dprintf("FGO IO: Invalid IO mode \"%S\", use keyboard or xinput\n", + fgo_io_cfg.mode); + } + + return hr; +} + +HRESULT fgo_io_poll(void) { + assert(fgo_io_backend != NULL); + + fgo_opbtn = 0; + fgo_gamebtn = 0; + fgo_stick_x = 0; + fgo_stick_y = 0; + + if (GetAsyncKeyState(fgo_io_cfg.vk_test) & 0x8000) { + fgo_opbtn |= FGO_IO_OPBTN_TEST; + } + + if (GetAsyncKeyState(fgo_io_cfg.vk_service) & 0x8000) { + fgo_opbtn |= FGO_IO_OPBTN_SERVICE; + } + + if (GetAsyncKeyState(fgo_io_cfg.vk_coin) & 0x8000) { + if (!fgo_io_coin) { + fgo_io_coin = true; + fgo_opbtn |= FGO_IO_OPBTN_COIN; + } + } else { + fgo_io_coin = false; + } + + return S_OK; +} + +void fgo_io_get_opbtns(uint8_t* opbtn) { + if (opbtn != NULL) { + *opbtn = fgo_opbtn; + } +} + +void fgo_io_get_gamebtns(uint8_t* btn) { + assert(fgo_io_backend != NULL); + assert(btn != NULL); + + fgo_io_backend->get_gamebtns(btn); +} + +void fgo_io_get_analogs(int16_t* stick_x, int16_t* stick_y) { + assert(fgo_io_backend != NULL); + assert(stick_x != NULL); + assert(stick_y != NULL); + + fgo_io_backend->get_analogs(stick_x, stick_y); +} + +HRESULT fgo_io_led_init(void) { + return S_OK; +} + +void fgo_io_led_set_colors(uint8_t board, uint8_t* rgb) { + return; +} diff --git a/fgoio/fgoio.h b/games/fgoio/fgoio.h similarity index 98% rename from fgoio/fgoio.h rename to games/fgoio/fgoio.h index c5b5fd8..65a11b0 100644 --- a/fgoio/fgoio.h +++ b/games/fgoio/fgoio.h @@ -14,7 +14,7 @@ enum { FGO_IO_GAMEBTN_SPEED_UP = 0x01, FGO_IO_GAMEBTN_TARGET = 0x02, FGO_IO_GAMEBTN_ATTACK = 0x04, - FGO_IO_GAMEBTN_NOBLE_PHANTASHM = 0x08, + FGO_IO_GAMEBTN_NOBLE_PHANTASM = 0x08, FGO_IO_GAMEBTN_CAMERA = 0x10, }; diff --git a/games/fgoio/keyboard.c b/games/fgoio/keyboard.c new file mode 100644 index 0000000..6d403dd --- /dev/null +++ b/games/fgoio/keyboard.c @@ -0,0 +1,82 @@ +#include + +#include +#include +#include +#include + +#include "fgoio/backend.h" +#include "fgoio/config.h" +#include "fgoio/fgoio.h" +#include "fgoio/keyboard.h" + +#include "util/dprintf.h" + +static void fgo_kb_get_gamebtns(uint8_t* gamebtn_out); +static void fgo_kb_get_analogs(int16_t* x, int16_t* y); + +static const struct fgo_io_backend fgo_kb_backend = { + .get_gamebtns = fgo_kb_get_gamebtns, + .get_analogs = fgo_kb_get_analogs +}; + +static struct fgo_kb_config config; + +HRESULT fgo_kb_init(const struct fgo_kb_config* cfg, const struct fgo_io_backend** backend) { + assert(cfg != NULL); + assert(backend != NULL); + + dprintf("Keyboard: Using keyboard input\n"); + *backend = &fgo_kb_backend; + config = *cfg; + + return S_OK; +} + +static void fgo_kb_get_gamebtns(uint8_t* gamebtn_out) { + assert(gamebtn_out != NULL); + + uint8_t gamebtn = 0; + + if (GetAsyncKeyState(config.vk_np) & 0x8000) { + gamebtn |= FGO_IO_GAMEBTN_NOBLE_PHANTASM; + } + + if (GetAsyncKeyState(config.vk_target) & 0x8000) { + gamebtn |= FGO_IO_GAMEBTN_TARGET; + } + + if (GetAsyncKeyState(config.vk_dash) & 0x8000) { + gamebtn |= FGO_IO_GAMEBTN_SPEED_UP; + } + + if (GetAsyncKeyState(config.vk_attack) & 0x8000) { + gamebtn |= FGO_IO_GAMEBTN_ATTACK; + } + + if (GetAsyncKeyState(config.vk_camera) & 0x8000) { + gamebtn |= FGO_IO_GAMEBTN_CAMERA; + } + + *gamebtn_out = gamebtn; +} + +static void fgo_kb_get_analogs(int16_t* x, int16_t* y) { + assert(x != NULL); + assert(y != NULL); + + if (GetAsyncKeyState(config.vk_left) & 0x8000) { + *x = SHRT_MIN + 1; + } else if (GetAsyncKeyState(config.vk_right) & 0x8000) { + *x = SHRT_MAX - 1; + } else { + *x = 0; + } + if (GetAsyncKeyState(config.vk_down) & 0x8000) { + *y = SHRT_MIN + 1; + } else if (GetAsyncKeyState(config.vk_up) & 0x8000) { + *y = SHRT_MAX - 1; + } else { + *y = 0; + } +} diff --git a/games/fgoio/keyboard.h b/games/fgoio/keyboard.h new file mode 100644 index 0000000..1b46a64 --- /dev/null +++ b/games/fgoio/keyboard.h @@ -0,0 +1,8 @@ +#pragma once + +#include + +#include "fgoio/backend.h" +#include "fgoio/config.h" + +HRESULT fgo_kb_init(const struct fgo_kb_config *cfg, const struct fgo_io_backend **backend); diff --git a/fgoio/meson.build b/games/fgoio/meson.build similarity index 74% rename from fgoio/meson.build rename to games/fgoio/meson.build index eed2fd3..5847686 100644 --- a/fgoio/meson.build +++ b/games/fgoio/meson.build @@ -11,5 +11,10 @@ fgoio_lib = static_library( 'fgoio.h', 'config.c', 'config.h', + 'backend.h', + 'keyboard.c', + 'keyboard.h', + 'xi.c', + 'xi.h', ], ) diff --git a/games/fgoio/xi.c b/games/fgoio/xi.c new file mode 100644 index 0000000..91a78a8 --- /dev/null +++ b/games/fgoio/xi.c @@ -0,0 +1,132 @@ +#include +#include + +#include +#include +#include + +#include "fgoio/backend.h" +#include "fgoio/config.h" +#include "fgoio/fgoio.h" +#include "fgoio/xi.h" + +#include "util/dprintf.h" + +static void fgo_xi_get_gamebtns(uint8_t* gamebtn_out); +static void fgo_xi_get_analogs(int16_t* x, int16_t* y); +static HRESULT fgo_xi_config_apply(const struct fgo_xi_config* cfg); + +static const struct fgo_io_backend fgo_xi_backend = { + .get_gamebtns = fgo_xi_get_gamebtns, + .get_analogs = fgo_xi_get_analogs +}; + +static float fgo_xi_stick_deadzone; + +const uint16_t max_stick_value = 32767; + +HRESULT fgo_xi_init(const struct fgo_xi_config* cfg, const struct fgo_io_backend** backend) { + assert(cfg != NULL); + assert(backend != NULL); + + HRESULT hr = fgo_xi_config_apply(cfg); + + if (FAILED(hr)) { + return hr; + } + + dprintf("XInput: Using XInput controller\n"); + *backend = &fgo_xi_backend; + + return S_OK; +} + +static HRESULT fgo_xi_config_apply(const struct fgo_xi_config* cfg) { + /* Deadzone check */ + if (cfg->stick_deadzone > 32767 || cfg->stick_deadzone < 0) { + dprintf("XInput: Stick deadzone is too large or negative\n"); + return E_INVALIDARG; + } + + dprintf("XInput: --- Begin configuration ---\n"); + dprintf("XInput: Left Deadzone . . . . : %i\n", cfg->stick_deadzone); + dprintf("XInput: --- End configuration ---\n"); + + fgo_xi_stick_deadzone = cfg->stick_deadzone; + + return S_OK; +} + +static void fgo_xi_get_gamebtns(uint8_t* gamebtn_out) { + assert(gamebtn_out != NULL); + + XINPUT_STATE xi; + memset(&xi, 0, sizeof(xi)); + XInputGetState(0, &xi); + + uint8_t gamebtn = 0; + WORD xb = xi.Gamepad.wButtons; + + if (xi.Gamepad.bLeftTrigger > 64) { + gamebtn |= FGO_IO_GAMEBTN_SPEED_UP; + } + + if (xb & XINPUT_GAMEPAD_LEFT_SHOULDER) { + gamebtn |= FGO_IO_GAMEBTN_TARGET; + } + + if (xb & XINPUT_GAMEPAD_A || xb & XINPUT_GAMEPAD_B) { + gamebtn |= FGO_IO_GAMEBTN_ATTACK; + } + + if (xb & XINPUT_GAMEPAD_Y || xb & XINPUT_GAMEPAD_X) { + gamebtn |= FGO_IO_GAMEBTN_NOBLE_PHANTASM; + } + + if (xb & XINPUT_GAMEPAD_LEFT_THUMB) { + gamebtn |= FGO_IO_GAMEBTN_CAMERA; + } + + *gamebtn_out = gamebtn; +} + +static void fgo_xi_get_analogs(int16_t* x, int16_t* y) { + + assert(x != NULL); + assert(y != NULL); + + XINPUT_STATE xi; + memset(&xi, 0, sizeof(xi)); + XInputGetState(0, &xi); + + float LX = xi.Gamepad.sThumbLX; + float LY = xi.Gamepad.sThumbLY; + + // determine how far the controller is pushed + float magnitude = sqrt(LX * LX + LY * LY); + + // determine the direction the controller is pushed + float normalizedLX = LX / magnitude; + float normalizedLY = LY / magnitude; + + float normalizedMagnitude = 0; + + // check if the controller is outside a circular dead zone + if (magnitude > fgo_xi_stick_deadzone) { + // clip the magnitude at its expected maximum value + if (magnitude > 32767) magnitude = 32767; + + // adjust magnitude relative to the end of the dead zone + magnitude -= fgo_xi_stick_deadzone; + + // optionally normalize the magnitude with respect to its expected range + // giving a magnitude value of 0.0 to 1.0 + normalizedMagnitude = magnitude / (32767 - fgo_xi_stick_deadzone); + } else // if the controller is in the deadzone zero out the magnitude + { + normalizedMagnitude = 0; + } + + *x = (int16_t) (normalizedLX * normalizedMagnitude * 32767); + *y = (int16_t) (normalizedLY * normalizedMagnitude * 32767); +} diff --git a/games/fgoio/xi.h b/games/fgoio/xi.h new file mode 100644 index 0000000..ebb8859 --- /dev/null +++ b/games/fgoio/xi.h @@ -0,0 +1,10 @@ +#pragma once + +/* Can't call this xinput.h or it will conflict with */ + +#include + +#include "fgoio/backend.h" +#include "fgoio/config.h" + +HRESULT fgo_xi_init(const struct fgo_xi_config *cfg, const struct fgo_io_backend **backend); diff --git a/idachook/config.c b/games/idachook/config.c similarity index 100% rename from idachook/config.c rename to games/idachook/config.c diff --git a/idachook/config.h b/games/idachook/config.h similarity index 100% rename from idachook/config.h rename to games/idachook/config.h diff --git a/idachook/dllmain.c b/games/idachook/dllmain.c similarity index 100% rename from idachook/dllmain.c rename to games/idachook/dllmain.c diff --git a/idachook/ffb.c b/games/idachook/ffb.c similarity index 100% rename from idachook/ffb.c rename to games/idachook/ffb.c diff --git a/idachook/ffb.h b/games/idachook/ffb.h similarity index 100% rename from idachook/ffb.h rename to games/idachook/ffb.h diff --git a/idachook/idac-dll.c b/games/idachook/idac-dll.c similarity index 100% rename from idachook/idac-dll.c rename to games/idachook/idac-dll.c diff --git a/idachook/idac-dll.h b/games/idachook/idac-dll.h similarity index 100% rename from idachook/idac-dll.h rename to games/idachook/idac-dll.h diff --git a/idachook/idachook.def b/games/idachook/idachook.def similarity index 100% rename from idachook/idachook.def rename to games/idachook/idachook.def diff --git a/idachook/indrun.c b/games/idachook/indrun.c similarity index 100% rename from idachook/indrun.c rename to games/idachook/indrun.c diff --git a/idachook/indrun.h b/games/idachook/indrun.h similarity index 100% rename from idachook/indrun.h rename to games/idachook/indrun.h diff --git a/idachook/io4.c b/games/idachook/io4.c similarity index 100% rename from idachook/io4.c rename to games/idachook/io4.c diff --git a/idachook/io4.h b/games/idachook/io4.h similarity index 100% rename from idachook/io4.h rename to games/idachook/io4.h diff --git a/idachook/meson.build b/games/idachook/meson.build similarity index 100% rename from idachook/meson.build rename to games/idachook/meson.build diff --git a/idachook/zinput.c b/games/idachook/zinput.c similarity index 100% rename from idachook/zinput.c rename to games/idachook/zinput.c diff --git a/idachook/zinput.h b/games/idachook/zinput.h similarity index 100% rename from idachook/zinput.h rename to games/idachook/zinput.h diff --git a/idacio/backend.h b/games/idacio/backend.h similarity index 100% rename from idacio/backend.h rename to games/idacio/backend.h diff --git a/idacio/config.c b/games/idacio/config.c similarity index 100% rename from idacio/config.c rename to games/idacio/config.c diff --git a/idacio/config.h b/games/idacio/config.h similarity index 100% rename from idacio/config.h rename to games/idacio/config.h diff --git a/idacio/di-dev.c b/games/idacio/di-dev.c similarity index 100% rename from idacio/di-dev.c rename to games/idacio/di-dev.c diff --git a/idacio/di-dev.h b/games/idacio/di-dev.h similarity index 100% rename from idacio/di-dev.h rename to games/idacio/di-dev.h diff --git a/idacio/di.c b/games/idacio/di.c similarity index 100% rename from idacio/di.c rename to games/idacio/di.c diff --git a/idacio/di.h b/games/idacio/di.h similarity index 100% rename from idacio/di.h rename to games/idacio/di.h diff --git a/idacio/dllmain.c b/games/idacio/dllmain.c similarity index 100% rename from idacio/dllmain.c rename to games/idacio/dllmain.c diff --git a/idacio/idacio.def b/games/idacio/idacio.def similarity index 100% rename from idacio/idacio.def rename to games/idacio/idacio.def diff --git a/idacio/idacio.h b/games/idacio/idacio.h similarity index 100% rename from idacio/idacio.h rename to games/idacio/idacio.h diff --git a/idacio/meson.build b/games/idacio/meson.build similarity index 100% rename from idacio/meson.build rename to games/idacio/meson.build diff --git a/idacio/shifter.c b/games/idacio/shifter.c similarity index 100% rename from idacio/shifter.c rename to games/idacio/shifter.c diff --git a/idacio/shifter.h b/games/idacio/shifter.h similarity index 100% rename from idacio/shifter.h rename to games/idacio/shifter.h diff --git a/idacio/wnd.c b/games/idacio/wnd.c similarity index 100% rename from idacio/wnd.c rename to games/idacio/wnd.c diff --git a/idacio/wnd.h b/games/idacio/wnd.h similarity index 100% rename from idacio/wnd.h rename to games/idacio/wnd.h diff --git a/idacio/xi.c b/games/idacio/xi.c similarity index 100% rename from idacio/xi.c rename to games/idacio/xi.c diff --git a/idacio/xi.h b/games/idacio/xi.h similarity index 100% rename from idacio/xi.h rename to games/idacio/xi.h diff --git a/idzhook/config.c b/games/idzhook/config.c similarity index 100% rename from idzhook/config.c rename to games/idzhook/config.c diff --git a/idzhook/config.h b/games/idzhook/config.h similarity index 100% rename from idzhook/config.h rename to games/idzhook/config.h diff --git a/idzhook/dllmain.c b/games/idzhook/dllmain.c similarity index 100% rename from idzhook/dllmain.c rename to games/idzhook/dllmain.c diff --git a/idzhook/ffb.c b/games/idzhook/ffb.c similarity index 100% rename from idzhook/ffb.c rename to games/idzhook/ffb.c diff --git a/idzhook/ffb.h b/games/idzhook/ffb.h similarity index 100% rename from idzhook/ffb.h rename to games/idzhook/ffb.h diff --git a/idzhook/idz-dll.c b/games/idzhook/idz-dll.c similarity index 100% rename from idzhook/idz-dll.c rename to games/idzhook/idz-dll.c diff --git a/idzhook/idz-dll.h b/games/idzhook/idz-dll.h similarity index 100% rename from idzhook/idz-dll.h rename to games/idzhook/idz-dll.h diff --git a/idzhook/idzhook.def b/games/idzhook/idzhook.def similarity index 100% rename from idzhook/idzhook.def rename to games/idzhook/idzhook.def diff --git a/idzhook/jvs.c b/games/idzhook/jvs.c similarity index 100% rename from idzhook/jvs.c rename to games/idzhook/jvs.c diff --git a/idzhook/jvs.h b/games/idzhook/jvs.h similarity index 100% rename from idzhook/jvs.h rename to games/idzhook/jvs.h diff --git a/idzhook/meson.build b/games/idzhook/meson.build similarity index 100% rename from idzhook/meson.build rename to games/idzhook/meson.build diff --git a/idzhook/zinput.c b/games/idzhook/zinput.c similarity index 100% rename from idzhook/zinput.c rename to games/idzhook/zinput.c diff --git a/idzhook/zinput.h b/games/idzhook/zinput.h similarity index 100% rename from idzhook/zinput.h rename to games/idzhook/zinput.h diff --git a/idzio/backend.h b/games/idzio/backend.h similarity index 100% rename from idzio/backend.h rename to games/idzio/backend.h diff --git a/idzio/config.c b/games/idzio/config.c similarity index 100% rename from idzio/config.c rename to games/idzio/config.c diff --git a/idzio/config.h b/games/idzio/config.h similarity index 100% rename from idzio/config.h rename to games/idzio/config.h diff --git a/idzio/di-dev.c b/games/idzio/di-dev.c similarity index 100% rename from idzio/di-dev.c rename to games/idzio/di-dev.c diff --git a/idzio/di-dev.h b/games/idzio/di-dev.h similarity index 100% rename from idzio/di-dev.h rename to games/idzio/di-dev.h diff --git a/idzio/di.c b/games/idzio/di.c similarity index 100% rename from idzio/di.c rename to games/idzio/di.c diff --git a/idzio/di.h b/games/idzio/di.h similarity index 100% rename from idzio/di.h rename to games/idzio/di.h diff --git a/idzio/dllmain.c b/games/idzio/dllmain.c similarity index 100% rename from idzio/dllmain.c rename to games/idzio/dllmain.c diff --git a/idzio/idzio.def b/games/idzio/idzio.def similarity index 100% rename from idzio/idzio.def rename to games/idzio/idzio.def diff --git a/idzio/idzio.h b/games/idzio/idzio.h similarity index 100% rename from idzio/idzio.h rename to games/idzio/idzio.h diff --git a/idzio/meson.build b/games/idzio/meson.build similarity index 100% rename from idzio/meson.build rename to games/idzio/meson.build diff --git a/idzio/shifter.c b/games/idzio/shifter.c similarity index 100% rename from idzio/shifter.c rename to games/idzio/shifter.c diff --git a/idzio/shifter.h b/games/idzio/shifter.h similarity index 100% rename from idzio/shifter.h rename to games/idzio/shifter.h diff --git a/idzio/wnd.c b/games/idzio/wnd.c similarity index 100% rename from idzio/wnd.c rename to games/idzio/wnd.c diff --git a/idzio/wnd.h b/games/idzio/wnd.h similarity index 100% rename from idzio/wnd.h rename to games/idzio/wnd.h diff --git a/idzio/xi.c b/games/idzio/xi.c similarity index 100% rename from idzio/xi.c rename to games/idzio/xi.c diff --git a/idzio/xi.h b/games/idzio/xi.h similarity index 100% rename from idzio/xi.h rename to games/idzio/xi.h diff --git a/kemonohook/config.c b/games/kemonohook/config.c similarity index 100% rename from kemonohook/config.c rename to games/kemonohook/config.c diff --git a/kemonohook/config.h b/games/kemonohook/config.h similarity index 100% rename from kemonohook/config.h rename to games/kemonohook/config.h diff --git a/kemonohook/dllmain.c b/games/kemonohook/dllmain.c similarity index 100% rename from kemonohook/dllmain.c rename to games/kemonohook/dllmain.c diff --git a/kemonohook/hooks.c b/games/kemonohook/hooks.c similarity index 100% rename from kemonohook/hooks.c rename to games/kemonohook/hooks.c diff --git a/kemonohook/hooks.h b/games/kemonohook/hooks.h similarity index 100% rename from kemonohook/hooks.h rename to games/kemonohook/hooks.h diff --git a/kemonohook/jvs.c b/games/kemonohook/jvs.c similarity index 100% rename from kemonohook/jvs.c rename to games/kemonohook/jvs.c diff --git a/kemonohook/jvs.h b/games/kemonohook/jvs.h similarity index 100% rename from kemonohook/jvs.h rename to games/kemonohook/jvs.h diff --git a/kemonohook/kemono-dll.c b/games/kemonohook/kemono-dll.c similarity index 100% rename from kemonohook/kemono-dll.c rename to games/kemonohook/kemono-dll.c diff --git a/kemonohook/kemono-dll.h b/games/kemonohook/kemono-dll.h similarity index 100% rename from kemonohook/kemono-dll.h rename to games/kemonohook/kemono-dll.h diff --git a/kemonohook/kemonohook.def b/games/kemonohook/kemonohook.def similarity index 100% rename from kemonohook/kemonohook.def rename to games/kemonohook/kemonohook.def diff --git a/kemonohook/meson.build b/games/kemonohook/meson.build similarity index 100% rename from kemonohook/meson.build rename to games/kemonohook/meson.build diff --git a/kemonoio/config.c b/games/kemonoio/config.c similarity index 100% rename from kemonoio/config.c rename to games/kemonoio/config.c diff --git a/kemonoio/config.h b/games/kemonoio/config.h similarity index 100% rename from kemonoio/config.h rename to games/kemonoio/config.h diff --git a/kemonoio/kemonoio.c b/games/kemonoio/kemonoio.c similarity index 100% rename from kemonoio/kemonoio.c rename to games/kemonoio/kemonoio.c diff --git a/kemonoio/kemonoio.h b/games/kemonoio/kemonoio.h similarity index 100% rename from kemonoio/kemonoio.h rename to games/kemonoio/kemonoio.h diff --git a/kemonoio/meson.build b/games/kemonoio/meson.build similarity index 100% rename from kemonoio/meson.build rename to games/kemonoio/meson.build diff --git a/mai2hook/config.c b/games/mai2hook/config.c similarity index 100% rename from mai2hook/config.c rename to games/mai2hook/config.c diff --git a/mai2hook/config.h b/games/mai2hook/config.h similarity index 100% rename from mai2hook/config.h rename to games/mai2hook/config.h diff --git a/mai2hook/dllmain.c b/games/mai2hook/dllmain.c similarity index 100% rename from mai2hook/dllmain.c rename to games/mai2hook/dllmain.c diff --git a/mai2hook/io4.c b/games/mai2hook/io4.c similarity index 100% rename from mai2hook/io4.c rename to games/mai2hook/io4.c diff --git a/mai2hook/io4.h b/games/mai2hook/io4.h similarity index 100% rename from mai2hook/io4.h rename to games/mai2hook/io4.h diff --git a/mai2hook/mai2-dll.c b/games/mai2hook/mai2-dll.c similarity index 100% rename from mai2hook/mai2-dll.c rename to games/mai2hook/mai2-dll.c diff --git a/mai2hook/mai2-dll.h b/games/mai2hook/mai2-dll.h similarity index 100% rename from mai2hook/mai2-dll.h rename to games/mai2hook/mai2-dll.h diff --git a/mai2hook/mai2hook.def b/games/mai2hook/mai2hook.def similarity index 100% rename from mai2hook/mai2hook.def rename to games/mai2hook/mai2hook.def diff --git a/mai2hook/meson.build b/games/mai2hook/meson.build similarity index 100% rename from mai2hook/meson.build rename to games/mai2hook/meson.build diff --git a/mai2hook/touch.c b/games/mai2hook/touch.c similarity index 100% rename from mai2hook/touch.c rename to games/mai2hook/touch.c diff --git a/mai2hook/touch.h b/games/mai2hook/touch.h similarity index 100% rename from mai2hook/touch.h rename to games/mai2hook/touch.h diff --git a/mai2io/config.c b/games/mai2io/config.c similarity index 100% rename from mai2io/config.c rename to games/mai2io/config.c diff --git a/mai2io/config.h b/games/mai2io/config.h similarity index 100% rename from mai2io/config.h rename to games/mai2io/config.h diff --git a/mai2io/mai2io.c b/games/mai2io/mai2io.c similarity index 100% rename from mai2io/mai2io.c rename to games/mai2io/mai2io.c diff --git a/mai2io/mai2io.h b/games/mai2io/mai2io.h similarity index 100% rename from mai2io/mai2io.h rename to games/mai2io/mai2io.h diff --git a/mai2io/meson.build b/games/mai2io/meson.build similarity index 100% rename from mai2io/meson.build rename to games/mai2io/meson.build diff --git a/mercuryhook/config.c b/games/mercuryhook/config.c similarity index 100% rename from mercuryhook/config.c rename to games/mercuryhook/config.c diff --git a/mercuryhook/config.h b/games/mercuryhook/config.h similarity index 100% rename from mercuryhook/config.h rename to games/mercuryhook/config.h diff --git a/mercuryhook/dllmain.c b/games/mercuryhook/dllmain.c similarity index 100% rename from mercuryhook/dllmain.c rename to games/mercuryhook/dllmain.c diff --git a/mercuryhook/elisabeth.c b/games/mercuryhook/elisabeth.c similarity index 100% rename from mercuryhook/elisabeth.c rename to games/mercuryhook/elisabeth.c diff --git a/mercuryhook/elisabeth.h b/games/mercuryhook/elisabeth.h similarity index 100% rename from mercuryhook/elisabeth.h rename to games/mercuryhook/elisabeth.h diff --git a/mercuryhook/io4.c b/games/mercuryhook/io4.c similarity index 100% rename from mercuryhook/io4.c rename to games/mercuryhook/io4.c diff --git a/mercuryhook/io4.h b/games/mercuryhook/io4.h similarity index 100% rename from mercuryhook/io4.h rename to games/mercuryhook/io4.h diff --git a/mercuryhook/mercury-dll.c b/games/mercuryhook/mercury-dll.c similarity index 100% rename from mercuryhook/mercury-dll.c rename to games/mercuryhook/mercury-dll.c diff --git a/mercuryhook/mercury-dll.h b/games/mercuryhook/mercury-dll.h similarity index 100% rename from mercuryhook/mercury-dll.h rename to games/mercuryhook/mercury-dll.h diff --git a/mercuryhook/mercuryhook.def b/games/mercuryhook/mercuryhook.def similarity index 100% rename from mercuryhook/mercuryhook.def rename to games/mercuryhook/mercuryhook.def diff --git a/mercuryhook/meson.build b/games/mercuryhook/meson.build similarity index 100% rename from mercuryhook/meson.build rename to games/mercuryhook/meson.build diff --git a/mercuryhook/touch.c b/games/mercuryhook/touch.c similarity index 100% rename from mercuryhook/touch.c rename to games/mercuryhook/touch.c diff --git a/mercuryhook/touch.h b/games/mercuryhook/touch.h similarity index 100% rename from mercuryhook/touch.h rename to games/mercuryhook/touch.h diff --git a/mercuryio/config.c b/games/mercuryio/config.c similarity index 100% rename from mercuryio/config.c rename to games/mercuryio/config.c diff --git a/mercuryio/config.h b/games/mercuryio/config.h similarity index 100% rename from mercuryio/config.h rename to games/mercuryio/config.h diff --git a/mercuryio/mercuryio.c b/games/mercuryio/mercuryio.c similarity index 100% rename from mercuryio/mercuryio.c rename to games/mercuryio/mercuryio.c diff --git a/mercuryio/mercuryio.def b/games/mercuryio/mercuryio.def similarity index 100% rename from mercuryio/mercuryio.def rename to games/mercuryio/mercuryio.def diff --git a/mercuryio/mercuryio.h b/games/mercuryio/mercuryio.h similarity index 100% rename from mercuryio/mercuryio.h rename to games/mercuryio/mercuryio.h diff --git a/mercuryio/meson.build b/games/mercuryio/meson.build similarity index 100% rename from mercuryio/meson.build rename to games/mercuryio/meson.build diff --git a/mu3hook/config.c b/games/mu3hook/config.c similarity index 100% rename from mu3hook/config.c rename to games/mu3hook/config.c diff --git a/mu3hook/config.h b/games/mu3hook/config.h similarity index 100% rename from mu3hook/config.h rename to games/mu3hook/config.h diff --git a/mu3hook/dllmain.c b/games/mu3hook/dllmain.c similarity index 100% rename from mu3hook/dllmain.c rename to games/mu3hook/dllmain.c diff --git a/mu3hook/io4.c b/games/mu3hook/io4.c similarity index 100% rename from mu3hook/io4.c rename to games/mu3hook/io4.c diff --git a/mu3hook/io4.h b/games/mu3hook/io4.h similarity index 100% rename from mu3hook/io4.h rename to games/mu3hook/io4.h diff --git a/mu3hook/meson.build b/games/mu3hook/meson.build similarity index 100% rename from mu3hook/meson.build rename to games/mu3hook/meson.build diff --git a/mu3hook/mu3-dll.c b/games/mu3hook/mu3-dll.c similarity index 100% rename from mu3hook/mu3-dll.c rename to games/mu3hook/mu3-dll.c diff --git a/mu3hook/mu3-dll.h b/games/mu3hook/mu3-dll.h similarity index 100% rename from mu3hook/mu3-dll.h rename to games/mu3hook/mu3-dll.h diff --git a/mu3hook/mu3hook.def b/games/mu3hook/mu3hook.def similarity index 100% rename from mu3hook/mu3hook.def rename to games/mu3hook/mu3hook.def diff --git a/mu3io/config.c b/games/mu3io/config.c similarity index 100% rename from mu3io/config.c rename to games/mu3io/config.c diff --git a/mu3io/config.h b/games/mu3io/config.h similarity index 100% rename from mu3io/config.h rename to games/mu3io/config.h diff --git a/mu3io/leddata.h b/games/mu3io/leddata.h similarity index 100% rename from mu3io/leddata.h rename to games/mu3io/leddata.h diff --git a/mu3io/ledoutput.c b/games/mu3io/ledoutput.c similarity index 100% rename from mu3io/ledoutput.c rename to games/mu3io/ledoutput.c diff --git a/mu3io/ledoutput.h b/games/mu3io/ledoutput.h similarity index 100% rename from mu3io/ledoutput.h rename to games/mu3io/ledoutput.h diff --git a/mu3io/meson.build b/games/mu3io/meson.build similarity index 100% rename from mu3io/meson.build rename to games/mu3io/meson.build diff --git a/mu3io/mu3io.c b/games/mu3io/mu3io.c similarity index 100% rename from mu3io/mu3io.c rename to games/mu3io/mu3io.c diff --git a/mu3io/mu3io.h b/games/mu3io/mu3io.h similarity index 100% rename from mu3io/mu3io.h rename to games/mu3io/mu3io.h diff --git a/mu3io/pipeimpl.c b/games/mu3io/pipeimpl.c similarity index 100% rename from mu3io/pipeimpl.c rename to games/mu3io/pipeimpl.c diff --git a/mu3io/pipeimpl.h b/games/mu3io/pipeimpl.h similarity index 100% rename from mu3io/pipeimpl.h rename to games/mu3io/pipeimpl.h diff --git a/mu3io/serialimpl.c b/games/mu3io/serialimpl.c similarity index 100% rename from mu3io/serialimpl.c rename to games/mu3io/serialimpl.c diff --git a/mu3io/serialimpl.h b/games/mu3io/serialimpl.h similarity index 100% rename from mu3io/serialimpl.h rename to games/mu3io/serialimpl.h diff --git a/swdchook/config.c b/games/swdchook/config.c similarity index 100% rename from swdchook/config.c rename to games/swdchook/config.c diff --git a/swdchook/config.h b/games/swdchook/config.h similarity index 100% rename from swdchook/config.h rename to games/swdchook/config.h diff --git a/swdchook/dllmain.c b/games/swdchook/dllmain.c similarity index 100% rename from swdchook/dllmain.c rename to games/swdchook/dllmain.c diff --git a/swdchook/ffb.c b/games/swdchook/ffb.c similarity index 100% rename from swdchook/ffb.c rename to games/swdchook/ffb.c diff --git a/swdchook/ffb.h b/games/swdchook/ffb.h similarity index 100% rename from swdchook/ffb.h rename to games/swdchook/ffb.h diff --git a/swdchook/io4.c b/games/swdchook/io4.c similarity index 100% rename from swdchook/io4.c rename to games/swdchook/io4.c diff --git a/swdchook/io4.h b/games/swdchook/io4.h similarity index 100% rename from swdchook/io4.h rename to games/swdchook/io4.h diff --git a/swdchook/meson.build b/games/swdchook/meson.build similarity index 100% rename from swdchook/meson.build rename to games/swdchook/meson.build diff --git a/swdchook/swdc-dll.c b/games/swdchook/swdc-dll.c similarity index 100% rename from swdchook/swdc-dll.c rename to games/swdchook/swdc-dll.c diff --git a/swdchook/swdc-dll.h b/games/swdchook/swdc-dll.h similarity index 100% rename from swdchook/swdc-dll.h rename to games/swdchook/swdc-dll.h diff --git a/swdchook/swdchook.def b/games/swdchook/swdchook.def similarity index 100% rename from swdchook/swdchook.def rename to games/swdchook/swdchook.def diff --git a/swdchook/zinput.c b/games/swdchook/zinput.c similarity index 100% rename from swdchook/zinput.c rename to games/swdchook/zinput.c diff --git a/swdchook/zinput.h b/games/swdchook/zinput.h similarity index 100% rename from swdchook/zinput.h rename to games/swdchook/zinput.h diff --git a/swdcio/backend.h b/games/swdcio/backend.h similarity index 100% rename from swdcio/backend.h rename to games/swdcio/backend.h diff --git a/swdcio/config.c b/games/swdcio/config.c similarity index 100% rename from swdcio/config.c rename to games/swdcio/config.c diff --git a/swdcio/config.h b/games/swdcio/config.h similarity index 100% rename from swdcio/config.h rename to games/swdcio/config.h diff --git a/swdcio/di-dev.c b/games/swdcio/di-dev.c similarity index 100% rename from swdcio/di-dev.c rename to games/swdcio/di-dev.c diff --git a/swdcio/di-dev.h b/games/swdcio/di-dev.h similarity index 100% rename from swdcio/di-dev.h rename to games/swdcio/di-dev.h diff --git a/swdcio/di.c b/games/swdcio/di.c similarity index 100% rename from swdcio/di.c rename to games/swdcio/di.c diff --git a/swdcio/di.h b/games/swdcio/di.h similarity index 100% rename from swdcio/di.h rename to games/swdcio/di.h diff --git a/swdcio/dllmain.c b/games/swdcio/dllmain.c similarity index 100% rename from swdcio/dllmain.c rename to games/swdcio/dllmain.c diff --git a/swdcio/meson.build b/games/swdcio/meson.build similarity index 100% rename from swdcio/meson.build rename to games/swdcio/meson.build diff --git a/swdcio/swdcio.def b/games/swdcio/swdcio.def similarity index 100% rename from swdcio/swdcio.def rename to games/swdcio/swdcio.def diff --git a/swdcio/swdcio.h b/games/swdcio/swdcio.h similarity index 100% rename from swdcio/swdcio.h rename to games/swdcio/swdcio.h diff --git a/swdcio/wnd.c b/games/swdcio/wnd.c similarity index 100% rename from swdcio/wnd.c rename to games/swdcio/wnd.c diff --git a/swdcio/wnd.h b/games/swdcio/wnd.h similarity index 100% rename from swdcio/wnd.h rename to games/swdcio/wnd.h diff --git a/swdcio/xi.c b/games/swdcio/xi.c similarity index 100% rename from swdcio/xi.c rename to games/swdcio/xi.c diff --git a/swdcio/xi.h b/games/swdcio/xi.h similarity index 100% rename from swdcio/xi.h rename to games/swdcio/xi.h diff --git a/tokyohook/config.c b/games/tokyohook/config.c similarity index 100% rename from tokyohook/config.c rename to games/tokyohook/config.c diff --git a/tokyohook/config.h b/games/tokyohook/config.h similarity index 100% rename from tokyohook/config.h rename to games/tokyohook/config.h diff --git a/tokyohook/dllmain.c b/games/tokyohook/dllmain.c similarity index 100% rename from tokyohook/dllmain.c rename to games/tokyohook/dllmain.c diff --git a/tokyohook/io4.c b/games/tokyohook/io4.c similarity index 100% rename from tokyohook/io4.c rename to games/tokyohook/io4.c diff --git a/tokyohook/io4.h b/games/tokyohook/io4.h similarity index 100% rename from tokyohook/io4.h rename to games/tokyohook/io4.h diff --git a/tokyohook/meson.build b/games/tokyohook/meson.build similarity index 100% rename from tokyohook/meson.build rename to games/tokyohook/meson.build diff --git a/tokyohook/tokyo-dll.c b/games/tokyohook/tokyo-dll.c similarity index 100% rename from tokyohook/tokyo-dll.c rename to games/tokyohook/tokyo-dll.c diff --git a/tokyohook/tokyo-dll.h b/games/tokyohook/tokyo-dll.h similarity index 100% rename from tokyohook/tokyo-dll.h rename to games/tokyohook/tokyo-dll.h diff --git a/tokyohook/tokyohook.def b/games/tokyohook/tokyohook.def similarity index 100% rename from tokyohook/tokyohook.def rename to games/tokyohook/tokyohook.def diff --git a/tokyohook/zinput.c b/games/tokyohook/zinput.c similarity index 100% rename from tokyohook/zinput.c rename to games/tokyohook/zinput.c diff --git a/tokyohook/zinput.h b/games/tokyohook/zinput.h similarity index 100% rename from tokyohook/zinput.h rename to games/tokyohook/zinput.h diff --git a/tokyoio/backend.h b/games/tokyoio/backend.h similarity index 100% rename from tokyoio/backend.h rename to games/tokyoio/backend.h diff --git a/tokyoio/config.c b/games/tokyoio/config.c similarity index 100% rename from tokyoio/config.c rename to games/tokyoio/config.c diff --git a/tokyoio/config.h b/games/tokyoio/config.h similarity index 100% rename from tokyoio/config.h rename to games/tokyoio/config.h diff --git a/tokyoio/dllmain.c b/games/tokyoio/dllmain.c similarity index 100% rename from tokyoio/dllmain.c rename to games/tokyoio/dllmain.c diff --git a/tokyoio/kb.c b/games/tokyoio/kb.c similarity index 100% rename from tokyoio/kb.c rename to games/tokyoio/kb.c diff --git a/tokyoio/kb.h b/games/tokyoio/kb.h similarity index 100% rename from tokyoio/kb.h rename to games/tokyoio/kb.h diff --git a/tokyoio/meson.build b/games/tokyoio/meson.build similarity index 100% rename from tokyoio/meson.build rename to games/tokyoio/meson.build diff --git a/tokyoio/tokyoio.h b/games/tokyoio/tokyoio.h similarity index 100% rename from tokyoio/tokyoio.h rename to games/tokyoio/tokyoio.h diff --git a/tokyoio/xi.c b/games/tokyoio/xi.c similarity index 100% rename from tokyoio/xi.c rename to games/tokyoio/xi.c diff --git a/tokyoio/xi.h b/games/tokyoio/xi.h similarity index 100% rename from tokyoio/xi.h rename to games/tokyoio/xi.h diff --git a/meson.build b/meson.build index aada974..b21d194 100644 --- a/meson.build +++ b/meson.build @@ -82,6 +82,9 @@ endif if get_option('log_all') or get_option('log_clock') add_project_arguments('-DLOG_CLOCK', language: 'c') endif +if get_option('log_all') or get_option('log_vfs') + add_project_arguments('-DLOG_VFS', language: 'c') +endif shlwapi_lib = cc.find_library('shlwapi') dinput8_lib = cc.find_library('dinput8') @@ -91,49 +94,48 @@ pathcch_lib = cc.find_library('pathcch') imagehlp_lib = cc.find_library('imagehlp') ws2_32_lib = cc.find_library('ws2_32') -inc = include_directories('.') +inc = include_directories('common', 'games') capnhook = subproject('capnhook') -subdir('amex') -subdir('iccard') -subdir('board') -subdir('hooklib') -subdir('jvs') -subdir('platform') -subdir('util') +subdir('common/amex') +subdir('common/iccard') +subdir('common/board') +subdir('common/hooklib') +subdir('common/jvs') +subdir('common/platform') +subdir('common/util') +subdir('common/aimeio') -subdir('gfxhook') -subdir('unityhook') +subdir('common/gfxhook') +subdir('common/unityhook') -subdir('aimeio') -subdir('chuniio') -subdir('divaio') -subdir('carolio') -subdir('idzio') -subdir('idacio') -subdir('swdcio') -subdir('mu3io') -subdir('mai2io') -subdir('cmio') -subdir('mercuryio') -subdir('cxbio') -subdir('tokyoio') -subdir('fgoio') -subdir('kemonoio') +subdir('games/chuniio') +subdir('games/divaio') +subdir('games/carolio') +subdir('games/idzio') +subdir('games/idacio') +subdir('games/swdcio') +subdir('games/mu3io') +subdir('games/mai2io') +subdir('games/cmio') +subdir('games/mercuryio') +subdir('games/cxbio') +subdir('games/tokyoio') +subdir('games/fgoio') +subdir('games/kemonoio') -subdir('chunihook') -subdir('divahook') -subdir('carolhook') -subdir('idzhook') -subdir('idachook') -subdir('swdchook') -subdir('minihook') -subdir('chusanhook') -subdir('mu3hook') -subdir('mai2hook') -subdir('cmhook') -subdir('mercuryhook') -subdir('cxbhook') -subdir('tokyohook') -subdir('fgohook') -subdir('kemonohook') +subdir('games/chunihook') +subdir('games/divahook') +subdir('games/carolhook') +subdir('games/idzhook') +subdir('games/idachook') +subdir('games/swdchook') +subdir('games/chusanhook') +subdir('games/mu3hook') +subdir('games/mai2hook') +subdir('games/cmhook') +subdir('games/mercuryhook') +subdir('games/cxbhook') +subdir('games/tokyohook') +subdir('games/fgohook') +subdir('games/kemonohook') diff --git a/meson_options.txt b/meson_options.txt index de9aefc..b6989f4 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -69,7 +69,12 @@ option('log_mercury_slider', description : 'Enable debug logging for the WACCA Slider' ) option('log_clock', - type : 'boolean', - value : false, - description : 'Enable debug logging for clock APIs' + type : 'boolean', + value : false, + description : 'Enable debug logging for clock APIs' +) +option('log_vfs', + type : 'boolean', + value : false, + description : 'Enable debug logging for file system redirections' ) diff --git a/minihook/dllmain.c b/minihook/dllmain.c deleted file mode 100644 index c72609f..0000000 --- a/minihook/dllmain.c +++ /dev/null @@ -1,76 +0,0 @@ -#include - -#include - -#include "amex/config.h" -#include "amex/ds.h" - -#include "hook/process.h" - -#include "hooklib/spike.h" - -#include "platform/clock.h" -#include "platform/config.h" -#include "platform/nusec.h" - -#include "util/dprintf.h" -#include "util/env.h" - -static process_entry_t app_startup; - -static DWORD CALLBACK app_pre_startup(void) -{ - struct clock_config clock_cfg; - struct ds_config ds_cfg; - struct nusec_config nusec_cfg; - HRESULT hr; - - dprintf("--- Begin %s ---\n", __func__); - - clock_config_load(&clock_cfg, get_config_path()); - ds_config_load(&ds_cfg, get_config_path()); - nusec_config_load(&nusec_cfg, get_config_path()); - spike_hook_init(get_config_path()); - - hr = clock_hook_init(&clock_cfg); - - if (FAILED(hr)) { - goto fail; - } - - hr = nusec_hook_init(&nusec_cfg, "SSSS", "AAV0"); - - if (FAILED(hr)) { - goto fail; - } - - hr = ds_hook_init(&ds_cfg); - - if (FAILED(hr)) { - goto fail; - } - - dprintf("--- End %s ---\n", __func__); - - return app_startup(); - -fail: - ExitProcess(EXIT_FAILURE); -} - -BOOL WINAPI DllMain(HMODULE mod, DWORD cause, void *ctx) -{ - HRESULT hr; - - if (cause != DLL_PROCESS_ATTACH) { - return TRUE; - } - - hr = process_hijack_startup(app_pre_startup, &app_startup); - - if (!SUCCEEDED(hr)) { - dprintf("Failed to hijack process startup: %x\n", (int) hr); - } - - return SUCCEEDED(hr); -} diff --git a/minihook/meson.build b/minihook/meson.build deleted file mode 100644 index 7de7f6c..0000000 --- a/minihook/meson.build +++ /dev/null @@ -1,18 +0,0 @@ -shared_library( - 'minihook', - name_prefix : '', - include_directories: inc, - implicit_include_directories : false, - dependencies : [ - capnhook.get_variable('hook_dep'), - ], - link_with : [ - amex_lib, - hooklib_lib, - platform_lib, - util_lib, - ], - sources : [ - 'dllmain.c', - ], -) diff --git a/msvc-build.bat b/msvc-build.bat index fac3925..460b5fd 100644 --- a/msvc-build.bat +++ b/msvc-build.bat @@ -4,6 +4,8 @@ setlocal enabledelayedexpansion set BUILD_DIR=build set BUILD_DIR_32=%BUILD_DIR%\build32 set BUILD_DIR_64=%BUILD_DIR%\build64 +set BUILD_DIR_GAMES_32=%BUILD_DIR_32%\games +set BUILD_DIR_GAMES_64=%BUILD_DIR_64%\games set BUILD_DIR_ZIP=%BUILD_DIR%\zip set DIST_DIR=dist set DOC_DIR=doc diff --git a/package.ps1 b/package.ps1 index bae0e6c..d2f0316 100644 --- a/package.ps1 +++ b/package.ps1 @@ -2,6 +2,8 @@ if ($null -eq $env:BUILD_DIR) { $BUILD_DIR="build" $BUILD_DIR_32="$BUILD_DIR\build32" $BUILD_DIR_64="$BUILD_DIR\build64" + $BUILD_DIR_GAMES_32="$BUILD_DIR_32\games" + $BUILD_DIR_GAMES_64="$BUILD_DIR_64\games" $BUILD_DIR_ZIP="$BUILD_DIR\zip" $DIST_DIR="dist" $DOC_DIR="doc" @@ -9,6 +11,8 @@ if ($null -eq $env:BUILD_DIR) { $BUILD_DIR = $env:BUILD_DIR; $BUILD_DIR_32 = $env:BUILD_DIR_32; $BUILD_DIR_64 = $env:BUILD_DIR_64; + $BUILD_DIR_GAMES_32 = $env:BUILD_DIR_GAMES_32; + $BUILD_DIR_GAMES_64 = $env:BUILD_DIR_GAMES_64; $BUILD_DIR_ZIP = $env:BUILD_DIR_ZIP; $DIST_DIR = $env:DIST_DIR; $DOC_DIR = $env:DOC_DIR; @@ -26,6 +30,8 @@ cat .\Package.mk | % { Replace('$(BUILD_DIR)', $BUILD_DIR). Replace('$(BUILD_DIR_32)', $BUILD_DIR_32). Replace('$(BUILD_DIR_64)', $BUILD_DIR_64). + Replace('$(BUILD_DIR_GAMES_32)', $BUILD_DIR_GAMES_32). + Replace('$(BUILD_DIR_GAMES_64)', $BUILD_DIR_GAMES_64). Replace('$(BUILD_DIR_ZIP)', $BUILD_DIR_ZIP). Replace('$(DIST_DIR)', $DIST_DIR). Replace('$(DOC_DIR)', $DOC_DIR). diff --git a/reg/chunithm.reg b/reg/chunithm.reg deleted file mode 100644 index f7c1240..0000000 --- a/reg/chunithm.reg +++ /dev/null @@ -1,27 +0,0 @@ -Windows Registry Editor Version 5.00 - -[HKEY_LOCAL_MACHINE\SYSTEM\SEGA] - -[HKEY_LOCAL_MACHINE\SYSTEM\SEGA\SystemProperty] - -[HKEY_LOCAL_MACHINE\SYSTEM\SEGA\SystemProperty\keychip] -"systemFlag"=dword:00000064 -"modelType"=dword:00000001 -"region"=dword:00000001 -"serverIpIpv4"=hex:c0,a8,8b,00 -"keychipId"=hex:41,36,39,45,2d,30,31,41,39,39,39,39,39,39,39,39 -"platformId"=hex:41,41,56 -"gameId"=hex:53,42,5a,56 - -[HKEY_LOCAL_MACHINE\SYSTEM\SEGA\SystemProperty\static] -"CpuTempWarning"=dword:0000003c -"CpuTempError"=dword:00000050 -"PlatformId"=hex:41,41,56 - -[HKEY_LOCAL_MACHINE\SYSTEM\SEGA\SystemProperty\wirelessNetwork] -"main_nic"=dword:00000000 - -[HKEY_LOCAL_MACHINE\SYSTEM\SEGA\SystemProperty\mount] -"AMFS"="E:\\" -"APPDATA"="Y:\\" -