From 4d0ef542792f18b64f33dd1b182763a6cbed6afc Mon Sep 17 00:00:00 2001 From: Dniel97 Date: Sun, 2 Mar 2025 00:23:53 +0100 Subject: [PATCH] system: add dip switch label configurations --- chusanhook/dllmain.c | 39 ++++++++-------------- cmhook/dllmain.c | 8 +++++ dist/fgo/segatools.ini | 2 +- hooklib/meson.build | 2 +- idachook/dllmain.c | 12 +++++++ mai2hook/dllmain.c | 8 +++++ mercuryhook/dllmain.c | 8 +++++ meson.build | 2 +- mu3hook/dllmain.c | 8 +++++ platform/system.c | 75 +++++++++++++++++++++--------------------- platform/system.h | 10 ++++++ tokyohook/dllmain.c | 10 ++++++ 12 files changed, 117 insertions(+), 67 deletions(-) diff --git a/chusanhook/dllmain.c b/chusanhook/dllmain.c index e29bf7f..6e3308f 100644 --- a/chusanhook/dllmain.c +++ b/chusanhook/dllmain.c @@ -86,11 +86,18 @@ static DWORD CALLBACK chusan_pre_startup(void) { /* Initialize emulation hooks */ - hr = platform_hook_init( - &chusan_hook_cfg.platform, - "SDHD", - "ACA2", - chusan_hook_mod); + struct dipsw_config new_dipsw_config[8] = { + {L"Delivery Server", L"Server", L"Client"}, + {L"Monitor Type", L"60FPS", L"120FPS"}, + {L"Cabinet Type", L"CVT", L"SP"}, + }; + + // Set the system dip switch configuration + memcpy(chusan_hook_cfg.platform.system.dipsw_config, new_dipsw_config, + sizeof(new_dipsw_config)); + + hr = platform_hook_init(&chusan_hook_cfg.platform, "SDHD", "ACA2", + chusan_hook_mod); if (FAILED(hr)) { goto fail; @@ -114,27 +121,7 @@ static DWORD CALLBACK chusan_pre_startup(void) { goto fail; } - bool *dipsw = &chusan_hook_cfg.platform.system.dipsw[0]; - bool is_cvt = dipsw[2]; - - for (int i = 0; i < 3; i++) { - switch (i) { - case 0: - dprintf("DipSw: NetInstall: %s\n", dipsw[0] ? "Server" : "Client"); - break; - - case 1: - dprintf("DipSw: Monitor Type: %dFPS\n", dipsw[1] ? 60 : 120); - break; - - case 2: - dprintf("DipSw: Cab Type: %s\n", is_cvt ? "CVT" : "SP"); - - break; - } - } - - unsigned int first_port = is_cvt ? 2 : 20; + bool is_cvt = chusan_hook_cfg.platform.system.dipsw[2]; if (!is_cvt) { hr = vfd_hook_init(&chusan_hook_cfg.vfd, 2); diff --git a/cmhook/dllmain.c b/cmhook/dllmain.c index 03ace58..29d93af 100644 --- a/cmhook/dllmain.c +++ b/cmhook/dllmain.c @@ -63,6 +63,14 @@ static DWORD CALLBACK cm_pre_startup(void) /* Initialize emulation hooks */ + struct dipsw_config new_dipsw_config[8] = { + {L"Delivery Server", L"Client", L"Server"}, + }; + + // Set the system dip switch configuration + memcpy(cm_hook_cfg.platform.system.dipsw_config, new_dipsw_config, + sizeof(new_dipsw_config)); + hr = platform_hook_init( &cm_hook_cfg.platform, "SDED", diff --git a/dist/fgo/segatools.ini b/dist/fgo/segatools.ini index e9c7c20..4e846ee 100644 --- a/dist/fgo/segatools.ini +++ b/dist/fgo/segatools.ini @@ -41,7 +41,7 @@ portNo=17 ; 837-15093-06 LED board emulation setting. enable=1 ; COM port number for the LED board. Has to be the same as the FTDI port. -portNo=17 +portNo1=17 ; ----------------------------------------------------------------------------- ; Network settings diff --git a/hooklib/meson.build b/hooklib/meson.build index e6908d6..b0ad6c2 100644 --- a/hooklib/meson.build +++ b/hooklib/meson.build @@ -4,7 +4,7 @@ hooklib_lib = static_library( implicit_include_directories : false, dependencies : [ capnhook.get_variable('hook_dep'), - Ws2_32_lib + ws2_32_lib ], sources : [ 'cursor.c', diff --git a/idachook/dllmain.c b/idachook/dllmain.c index 71a4ccd..a7b3c86 100644 --- a/idachook/dllmain.c +++ b/idachook/dllmain.c @@ -60,6 +60,18 @@ static DWORD CALLBACK idac_pre_startup(void) /* Initialize emulation hooks */ + struct dipsw_config new_dipsw_config[8] = { + {L"Delivery Server", L"Server", L"Client"}, + {L"Cabinet Type", L"SWDC CVT", L"DZero CVT"}, + {L"Single Seat", L"ON", L"OFF"}, + {L"Seat Setting 1", L"ON", L"OFF"}, + {L"Seat Setting 2", L"ON", L"OFF"}, + }; + + // Set the system dip switch configuration + memcpy(idac_hook_cfg.platform.system.dipsw_config, new_dipsw_config, + sizeof(new_dipsw_config)); + hr = platform_hook_init( &idac_hook_cfg.platform, "SDGT", diff --git a/mai2hook/dllmain.c b/mai2hook/dllmain.c index cb8a240..cecc01e 100644 --- a/mai2hook/dllmain.c +++ b/mai2hook/dllmain.c @@ -66,6 +66,14 @@ static DWORD CALLBACK mai2_pre_startup(void) /* Initialize emulation hooks */ + struct dipsw_config new_dipsw_config[8] = { + {L"Delivery Server", L"Server", L"Client"}, + }; + + // Set the system dip switch configuration + memcpy(mai2_hook_cfg.platform.system.dipsw_config, new_dipsw_config, + sizeof(new_dipsw_config)); + hr = platform_hook_init( &mai2_hook_cfg.platform, "SDEZ", diff --git a/mercuryhook/dllmain.c b/mercuryhook/dllmain.c index 64b5707..37030d3 100644 --- a/mercuryhook/dllmain.c +++ b/mercuryhook/dllmain.c @@ -64,6 +64,14 @@ static DWORD CALLBACK mercury_pre_startup(void) /* Initialize emulation hooks */ + struct dipsw_config new_dipsw_config[8] = { + {L"Delivery Server", L"Server", L"Client"}, + }; + + // Set the system dip switch configuration + memcpy(mercury_hook_cfg.platform.system.dipsw_config, new_dipsw_config, + sizeof(new_dipsw_config)); + hr = platform_hook_init( &mercury_hook_cfg.platform, "SDFE", diff --git a/meson.build b/meson.build index 6bb86fc..aada974 100644 --- a/meson.build +++ b/meson.build @@ -89,7 +89,7 @@ dxguid_lib = cc.find_library('dxguid') xinput_lib = cc.find_library('xinput') pathcch_lib = cc.find_library('pathcch') imagehlp_lib = cc.find_library('imagehlp') -Ws2_32_lib = cc.find_library('Ws2_32') +ws2_32_lib = cc.find_library('ws2_32') inc = include_directories('.') capnhook = subproject('capnhook') diff --git a/mu3hook/dllmain.c b/mu3hook/dllmain.c index 4b35aa3..1b57e5d 100644 --- a/mu3hook/dllmain.c +++ b/mu3hook/dllmain.c @@ -65,6 +65,14 @@ static DWORD CALLBACK mu3_pre_startup(void) /* Initialize emulation hooks */ + struct dipsw_config new_dipsw_config[8] = { + {L"Delivery Server", L"Server", L"Client"}, + }; + + // Set the system dip switch configuration + memcpy(mu3_hook_cfg.platform.system.dipsw_config, new_dipsw_config, + sizeof(new_dipsw_config)); + hr = platform_hook_init( &mu3_hook_cfg.platform, "SDDT", diff --git a/platform/system.c b/platform/system.c index dbc832f..4928e05 100644 --- a/platform/system.c +++ b/platform/system.c @@ -1,40 +1,37 @@ -#include +#include "platform/system.h" #include -#include +#include #include +#include #include +#include -#include "platform/system.h" #include "platform/vfs.h" - +#include "util/crc.h" #include "util/dprintf.h" #include "util/str.h" -#include "util/crc.h" #define DATA_SIZE 503 #define BLOCK_SIZE (sizeof(uint32_t) + 4 + 1 + DATA_SIZE) #pragma pack(push, 1) -typedef struct -{ +typedef struct { uint32_t checksum; char padding[6]; uint8_t freeplay; char data[DATA_SIZE - 2]; } CreditBlock; -typedef struct -{ +typedef struct { uint32_t checksum; char padding[4]; uint8_t dip_switches; char data[DATA_SIZE]; } DipSwBlock; -typedef struct -{ +typedef struct { CreditBlock credit_block; DipSwBlock dip_switch_block; char *data; @@ -50,16 +47,15 @@ static struct vfs_config vfs_config; static void system_read_sysfile(const wchar_t *sys_file); static void system_save_sysfile(const wchar_t *sys_file); -HRESULT system_init(const struct system_config *cfg, const struct vfs_config *vfs_cfg) -{ +HRESULT system_init(const struct system_config *cfg, + const struct vfs_config *vfs_cfg) { HRESULT hr; wchar_t sys_file_path[MAX_PATH]; assert(cfg != NULL); assert(vfs_cfg != NULL); - if (!cfg->enable) - { + if (!cfg->enable) { return S_FALSE; } @@ -78,13 +74,13 @@ HRESULT system_init(const struct system_config *cfg, const struct vfs_config *vf return S_OK; } -static void system_read_sysfile(const wchar_t *sys_file) -{ +static void system_read_sysfile(const wchar_t *sys_file) { FILE *f = _wfopen(sys_file, L"r"); - if (f == NULL) - { - dprintf("System: First run detected, system settings can only be applied AFTER the first run\n"); + if (f == NULL) { + dprintf( + "System: First run detected, system settings can only be applied " + "AFTER the first run\n"); return; } @@ -92,8 +88,7 @@ static void system_read_sysfile(const wchar_t *sys_file) long file_size = ftell(f); fseek(f, 0, SEEK_SET); - if (file_size != 0x6000) - { + if (file_size != 0x6000) { dprintf("System: Invalid sysfile.dat file size\n"); fclose(f); @@ -106,11 +101,11 @@ static void system_read_sysfile(const wchar_t *sys_file) // copy the credit_block and dip_switch_block from the sysfile.dat memcpy(&system_info.credit_block, system_info.data, BLOCK_SIZE); - memcpy(&system_info.dip_switch_block, system_info.data + 0x2800, BLOCK_SIZE); + memcpy(&system_info.dip_switch_block, system_info.data + 0x2800, + BLOCK_SIZE); } -static void system_save_sysfile(const wchar_t *sys_file) -{ +static void system_save_sysfile(const wchar_t *sys_file) { char block[BLOCK_SIZE]; uint8_t system = 0; uint8_t freeplay = 0; @@ -118,24 +113,28 @@ static void system_save_sysfile(const wchar_t *sys_file) // open the sysfile.dat for writing in bytes mode FILE *f = _wfopen(sys_file, L"rb+"); - if (f == NULL) - { + if (f == NULL) { return; } // write the system_config.system to the dip_switch_block - for (int i = 0; i < 8; i++) - { - if (system_config.dipsw[i]) - { - // print which system is enabled + for (int i = 0; i < 8; i++) { + // print the dip switch configuration with labels if present + if (system_config.dipsw_config[i].label[0] != L'\0') { + dprintf("System: %ls: %ls\n", system_config.dipsw_config[i].label, + system_config.dipsw[i] ? system_config.dipsw_config[i].on + : system_config.dipsw_config[i].off); + } else if (system_config.dipsw[i]) { dprintf("System: DipSw%d=1 set\n", i + 1); + } + + // set the system variable to the dip switch configuration + if (system_config.dipsw[i]) { system |= (1 << i); } } - if (system_config.freeplay) - { + if (system_config.freeplay) { // print that freeplay is enabled dprintf("System: Freeplay enabled\n"); freeplay = 1; @@ -149,10 +148,10 @@ static void system_save_sysfile(const wchar_t *sys_file) // calculate the new checksum, skip the old crc32 value // which is at the beginning of the block, thats's why the +4 // conver the struct to chars in order for the crc32 calculation to work - system_info.credit_block.checksum = crc32( - (char *)&system_info.credit_block + 4, BLOCK_SIZE - 4, 0); - system_info.dip_switch_block.checksum = crc32( - (char *)&system_info.dip_switch_block + 4, BLOCK_SIZE - 4, 0); + system_info.credit_block.checksum = + crc32((char *)&system_info.credit_block + 4, BLOCK_SIZE - 4, 0); + system_info.dip_switch_block.checksum = + crc32((char *)&system_info.dip_switch_block + 4, BLOCK_SIZE - 4, 0); // build the new credit block memcpy(block, (char *)&system_info.credit_block, BLOCK_SIZE); diff --git a/platform/system.h b/platform/system.h index ba0f2a6..e69ce90 100644 --- a/platform/system.h +++ b/platform/system.h @@ -7,10 +7,20 @@ #include "platform/vfs.h" + +struct dipsw_config +{ + wchar_t label[MAX_PATH]; + wchar_t on[MAX_PATH]; + wchar_t off[MAX_PATH]; +}; + + struct system_config { bool enable; bool freeplay; bool dipsw[8]; + struct dipsw_config dipsw_config[8]; }; HRESULT system_init(const struct system_config *cfg, const struct vfs_config *vfs_cfg); diff --git a/tokyohook/dllmain.c b/tokyohook/dllmain.c index 3ba9b36..5f46615 100644 --- a/tokyohook/dllmain.c +++ b/tokyohook/dllmain.c @@ -50,6 +50,16 @@ static DWORD CALLBACK tokyo_pre_startup(void) /* Initialize emulation hooks */ + struct dipsw_config new_dipsw_config[8] = { + {L"Delivery Server", L"Server", L"Client"}, + {L"Cabinet ID Setting", L"ON", L"OFF"}, + {L"Cabinet ID Setting", L"ON", L"OFF"}, + }; + + // Set the system dip switch configuration + memcpy(tokyo_hook_cfg.platform.system.dipsw_config, new_dipsw_config, + sizeof(new_dipsw_config)); + hr = platform_hook_init( &tokyo_hook_cfg.platform, "SDFV",