From 28ab4c6e373690dd2587a4aadfd660e9249701ad Mon Sep 17 00:00:00 2001 From: Kevin Trocolli Date: Mon, 22 Apr 2024 21:11:03 -0400 Subject: [PATCH] sao: working USIO, add clock enable toggle --- platform/clock.c | 3 +++ platform/clock.h | 1 + platform/config.c | 1 + saohook/sao-dll.c | 7 ++++-- saohook/sao-dll.h | 3 ++- saohook/saohook.def | 3 ++- saohook/unity.c | 14 ++++++++++- saohook/usio.c | 37 ++++++++++++++++++++-------- saoio/config.c | 18 ++++++++------ saoio/config.h | 20 +++++++++------ saoio/saoio.c | 59 ++++++++++++++++++++++++++------------------- saoio/saoio.def | 3 ++- saoio/saoio.h | 18 +++++++------- 13 files changed, 121 insertions(+), 66 deletions(-) diff --git a/platform/clock.c b/platform/clock.c index f2cc41a..cb5b529 100644 --- a/platform/clock.c +++ b/platform/clock.c @@ -250,6 +250,9 @@ static BOOL WINAPI my_AdjustTokenPrivileges( HRESULT clock_hook_init(const struct clock_config *cfg) { assert(cfg != NULL); + if (!cfg->enable) { + return S_FALSE; + } clock_time_warp = cfg->timewarp; diff --git a/platform/clock.h b/platform/clock.h index 4d67754..c18d78c 100644 --- a/platform/clock.h +++ b/platform/clock.h @@ -5,6 +5,7 @@ #include struct clock_config { + bool enable; bool timezone; bool timewarp; bool writeable; diff --git a/platform/config.c b/platform/config.c index cef5717..df820a9 100644 --- a/platform/config.c +++ b/platform/config.c @@ -84,6 +84,7 @@ void clock_config_load(struct clock_config *cfg, const wchar_t *filename) assert(cfg != NULL); assert(filename != NULL); + cfg->enable = GetPrivateProfileIntW(L"clock", L"enable", 1, filename); cfg->timezone = GetPrivateProfileIntW(L"clock", L"timezone", 1, filename); cfg->timewarp = GetPrivateProfileIntW(L"clock", L"timewarp", 0, filename); cfg->writeable = GetPrivateProfileIntW( diff --git a/saohook/sao-dll.c b/saohook/sao-dll.c index 7037e59..0e0f787 100644 --- a/saohook/sao-dll.c +++ b/saohook/sao-dll.c @@ -19,8 +19,11 @@ const struct dll_bind_sym sao_dll_syms[] = { .sym = "sao_io_get_opbtns", .off = offsetof(struct sao_dll, get_opbtns), }, { - .sym = "sao_io_get_drum_analog", - .off = offsetof(struct sao_dll, get_drum_analog), + .sym = "sao_io_get_analog", + .off = offsetof(struct sao_dll, get_analog), + }, { + .sym = "sao_io_get_gamebtns", + .off = offsetof(struct sao_dll, get_gamebtns), } }; diff --git a/saohook/sao-dll.h b/saohook/sao-dll.h index dfc3209..a9850eb 100644 --- a/saohook/sao-dll.h +++ b/saohook/sao-dll.h @@ -10,7 +10,8 @@ struct sao_dll { HRESULT (*poll)(void); void (*read_coin_counter)(uint16_t *coins, uint16_t *services); void (*get_opbtns)(uint8_t *opbtn); - void (*get_drum_analog)(uint8_t *gamebtn); + void (*get_gamebtns)(uint8_t *gamebtns); + void (*get_analog)(uint8_t *x, uint8_t *y); }; struct sao_dll_config { diff --git a/saohook/saohook.def b/saohook/saohook.def index c8fb6f5..d9bfa74 100644 --- a/saohook/saohook.def +++ b/saohook/saohook.def @@ -4,5 +4,6 @@ EXPORTS sao_io_get_api_version sao_io_init sao_io_read_coin_counter - sao_io_get_drum_analog + sao_io_get_analog + sao_io_get_gamebtns sao_io_get_opbtns \ No newline at end of file diff --git a/saohook/unity.c b/saohook/unity.c index cb40449..9ff961d 100644 --- a/saohook/unity.c +++ b/saohook/unity.c @@ -21,13 +21,19 @@ static void dll_hook_insert_hooks(HMODULE target); static HMODULE WINAPI my_LoadLibraryW(const wchar_t *name); static HMODULE (WINAPI *next_LoadLibraryW)(const wchar_t *name); +static HMODULE WINAPI my_LoadLibraryExW(const wchar_t *name, HANDLE hFile, DWORD dwFlags); +static HMODULE (WINAPI *next_LoadLibraryExW)(const wchar_t *name, HANDLE hFile, DWORD dwFlags); static const struct hook_symbol unity_kernel32_syms[] = { { .name = "LoadLibraryW", .patch = my_LoadLibraryW, .link = (void **) &next_LoadLibraryW, - }, + },{ + .name = "LoadLibraryExW", + .patch = my_LoadLibraryExW, + .link = (void **) &next_LoadLibraryExW, + } }; static const wchar_t *target_modules[] = { @@ -58,6 +64,12 @@ static void dll_hook_insert_hooks(HMODULE target) _countof(unity_kernel32_syms)); } +static HMODULE WINAPI my_LoadLibraryExW(const wchar_t *name, HANDLE hFile, DWORD dwFlags) +{ + //dprintf("Unity: LoadLibraryExW %ls\n", name); + return my_LoadLibraryW(name); +} + static HMODULE WINAPI my_LoadLibraryW(const wchar_t *name) { const wchar_t *name_end; diff --git a/saohook/usio.c b/saohook/usio.c index 94bcf02..ed09267 100644 --- a/saohook/usio.c +++ b/saohook/usio.c @@ -39,12 +39,16 @@ HRESULT sao_usio_hook_init(const struct usio_config *cfg) static HRESULT sao_usio_poll(void *ctx, struct usio_state *state) { uint8_t opbtn_out = 0; - uint8_t analog_out = 0; + uint8_t gamebtn_out = 0; + uint8_t x = 128; + uint8_t y = 128; uint16_t coin_ct = 0; uint16_t service_ct = 0; + sao_dll.get_opbtns(&opbtn_out); - sao_dll.get_drum_analog(&analog_out); + sao_dll.get_analog(&x, &y); sao_dll.read_coin_counter(&coin_ct, &service_ct); + sao_dll.get_gamebtns(&gamebtn_out); state->op_btns = 0; state->p1_btns = 0; @@ -66,17 +70,30 @@ static HRESULT sao_usio_poll(void *ctx, struct usio_state *state) state->p1_btns |= 0x02; // Enter } - for (int i = 0; i < _countof(state->analog); i++) { - if (analog_out & 1 << i) { - state->analog[i] = 0x3FFF; - } else { - state->analog[i] = 0x00; - } - + if (gamebtn_out & 0x01) { + state->p1_btns |= 0x2000; } + if (gamebtn_out & 0x02) { + state->p1_btns |= 0x1000; + } + if (gamebtn_out & 0x04) { + state->p1_btns |= 0x0800; + } + if (gamebtn_out & 0x08) { + state->p1_btns |= 0x4000; + } + if (gamebtn_out & 0x10) { + state->p1_btns |= 0x01; + } + if (gamebtn_out & 0x20) { + state->p1_btns |= 0x8000; + } + + state->analog[0] = x << 8; + state->analog[1] = y << 8; state->coins[0].current_coin_count = coin_ct; state->service.current_coin_count = service_ct; return S_OK; -} \ No newline at end of file +} diff --git a/saoio/config.c b/saoio/config.c index 8123953..5e60fd0 100644 --- a/saoio/config.c +++ b/saoio/config.c @@ -15,13 +15,15 @@ void sao_io_config_load(struct sao_input_config *cfg, const wchar_t *filename) cfg->down = GetPrivateProfileIntW(L"usio", L"down", VK_DOWN, filename); cfg->enter = GetPrivateProfileIntW(L"usio", L"enter", VK_RETURN, filename); - cfg->p1_rim_l = GetPrivateProfileIntW(L"drum", L"p1_rim_l", 'Z', filename); - cfg->p1_center_l = GetPrivateProfileIntW(L"usio", L"p1_center_l", 'X', filename); - cfg->p1_center_r = GetPrivateProfileIntW(L"usio", L"p1_center_r", 'C', filename); - cfg->p1_rim_r = GetPrivateProfileIntW(L"usio", L"p1_rim_r", 'V', filename); + cfg->stick_up = GetPrivateProfileIntW(L"usio", L"stick_up", 'W', filename); + cfg->stick_left = GetPrivateProfileIntW(L"usio", L"stick_left", 'A', filename); + cfg->stick_down = GetPrivateProfileIntW(L"usio", L"stick_down", 'S', filename); + cfg->stick_right = GetPrivateProfileIntW(L"usio", L"stick_right", 'D', filename); + cfg->stick_btn1 = GetPrivateProfileIntW(L"usio", L"stick_btn1", 'R', filename); + cfg->stick_btn2 = GetPrivateProfileIntW(L"usio", L"stick_btn2", 'F', filename); + cfg->stick_btn3 = GetPrivateProfileIntW(L"usio", L"stick_btn3", 'V', filename); - cfg->p2_rim_l = GetPrivateProfileIntW(L"drum", L"p2_rim_l", 'U', filename); - cfg->p2_center_l = GetPrivateProfileIntW(L"usio", L"p2_center_l", 'I', filename); - cfg->p2_center_r = GetPrivateProfileIntW(L"usio", L"p2_center_r", 'O', filename); - cfg->p2_rim_r = GetPrivateProfileIntW(L"usio", L"p2_rim_r", 'P', filename); + cfg->btn1 = GetPrivateProfileIntW(L"usio", L"btn1", '1', filename); + cfg->btn2 = GetPrivateProfileIntW(L"usio", L"btn2", '2', filename); + cfg->btn3 = GetPrivateProfileIntW(L"usio", L"btn3", '3', filename); } \ No newline at end of file diff --git a/saoio/config.h b/saoio/config.h index 84e4e0d..25ee432 100644 --- a/saoio/config.h +++ b/saoio/config.h @@ -12,14 +12,18 @@ struct sao_input_config { uint8_t enter; uint8_t coin; - uint8_t p1_rim_l; - uint8_t p1_center_l; - uint8_t p1_center_r; - uint8_t p1_rim_r; - uint8_t p2_rim_l; - uint8_t p2_center_l; - uint8_t p2_center_r; - uint8_t p2_rim_r; + uint8_t stick_up; + uint8_t stick_down; + uint8_t stick_left; + uint8_t stick_right; + + uint8_t stick_btn1; + uint8_t stick_btn2; + uint8_t stick_btn3; + + uint8_t btn1; + uint8_t btn2; + uint8_t btn3; }; #pragma pack(pop) diff --git a/saoio/saoio.c b/saoio/saoio.c index fe5c550..8d8792d 100644 --- a/saoio/saoio.c +++ b/saoio/saoio.c @@ -62,38 +62,47 @@ void sao_io_get_opbtns(uint8_t *opbtn) } } -void sao_io_get_drum_analog(uint8_t *gamebtn) +void sao_io_get_gamebtns(uint8_t *gamebtns) { - if (GetAsyncKeyState(cfg.p1_rim_l) & 0x8000) { - *gamebtn |= SAO_IO_P1_RIM_L; + *gamebtns = 0; + if (GetAsyncKeyState(cfg.btn1) & 0x8000) { + *gamebtns |= SAO_IO_GAMEBTN_1; + } + if (GetAsyncKeyState(cfg.btn2) & 0x8000) { + *gamebtns |= SAO_IO_GAMEBTN_2; + } + if (GetAsyncKeyState(cfg.btn3) & 0x8000) { + *gamebtns |= SAO_IO_GAMEBTN_3; + } + if (GetAsyncKeyState(cfg.stick_btn1) & 0x8000) { + *gamebtns |= SAO_IO_GAMEBTN_STICK1; + } + if (GetAsyncKeyState(cfg.stick_btn2) & 0x8000) { + *gamebtns |= SAO_IO_GAMEBTN_STICK2; + } + if (GetAsyncKeyState(cfg.stick_btn3) & 0x8000) { + *gamebtns |= SAO_IO_GAMEBTN_STICK3; + } +} + +void sao_io_get_analog(uint8_t *x, uint8_t *y) +{ + *x = 128; + *y = 128; + if (GetAsyncKeyState(cfg.stick_up) & 0x8000) { + *y += 127; } - if (GetAsyncKeyState(cfg.p1_center_l) & 0x8000) { - *gamebtn |= SAO_IO_P1_CENTER_L; + if (GetAsyncKeyState(cfg.stick_down) & 0x8000) { + *y -= 128; } - if (GetAsyncKeyState(cfg.p1_center_r) & 0x8000) { - *gamebtn |= SAO_IO_P1_CENTER_R; + if (GetAsyncKeyState(cfg.stick_right) & 0x8000) { + *x += 127; } - if (GetAsyncKeyState(cfg.p1_rim_r) & 0x8000) { - *gamebtn |= SAO_IO_P1_RIM_R; - } - - if (GetAsyncKeyState(cfg.p2_rim_l) & 0x8000) { - *gamebtn |= SAO_IO_P2_RIM_L; - } - - if (GetAsyncKeyState(cfg.p2_center_l) & 0x8000) { - *gamebtn |= SAO_IO_P2_CENTER_L; - } - - if (GetAsyncKeyState(cfg.p2_center_r) & 0x8000) { - *gamebtn |= SAO_IO_P2_CENTER_R; - } - - if (GetAsyncKeyState(cfg.p2_rim_r) & 0x8000) { - *gamebtn |= SAO_IO_P2_RIM_R; + if (GetAsyncKeyState(cfg.stick_left) & 0x8000) { + *x -= 128; } } diff --git a/saoio/saoio.def b/saoio/saoio.def index c8fb6f5..d9bfa74 100644 --- a/saoio/saoio.def +++ b/saoio/saoio.def @@ -4,5 +4,6 @@ EXPORTS sao_io_get_api_version sao_io_init sao_io_read_coin_counter - sao_io_get_drum_analog + sao_io_get_analog + sao_io_get_gamebtns sao_io_get_opbtns \ No newline at end of file diff --git a/saoio/saoio.h b/saoio/saoio.h index cfa0c40..a981f9e 100644 --- a/saoio/saoio.h +++ b/saoio/saoio.h @@ -15,14 +15,12 @@ enum { }; enum { - SAO_IO_P1_RIM_L = 0x0001, - SAO_IO_P1_CENTER_L = 0x0002, - SAO_IO_P1_CENTER_R = 0x0004, - SAO_IO_P1_RIM_R = 0x0008, - SAO_IO_P2_RIM_L = 0x0100, - SAO_IO_P2_CENTER_L = 0x0200, - SAO_IO_P2_CENTER_R = 0x1000, - SAO_IO_P2_RIM_R = 0x2000, + SAO_IO_GAMEBTN_1 = 0x0001, + SAO_IO_GAMEBTN_2 = 0x0002, + SAO_IO_GAMEBTN_3 = 0x0004, + SAO_IO_GAMEBTN_STICK1 = 0x0008, + SAO_IO_GAMEBTN_STICK2 = 0x0010, + SAO_IO_GAMEBTN_STICK3 = 0x0020, }; /* Get the version of the Pokken IO API that this DLL supports. This @@ -62,6 +60,8 @@ void sao_io_get_opbtns(uint8_t *opbtn); Minimum API version: 0x0100 */ -void sao_io_get_drum_analog(uint8_t *gamebtn); +void sao_io_get_analog(uint8_t *x, uint8_t *y); + +void sao_io_get_gamebtns(uint8_t *gamebtns); void sao_io_read_coin_counter(uint16_t *coins, uint16_t *services); \ No newline at end of file