From 94c996a0f30336fc8a8af487112ba9c7cdab859f Mon Sep 17 00:00:00 2001 From: sere Date: Sat, 2 Nov 2024 01:36:41 +0400 Subject: [PATCH 1/3] Implement th06::Controller::GetControllerState --- config/implemented.csv | 1 + config/stubbed.csv | 1 - src/Supervisor.cpp | 67 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 1 deletion(-) diff --git a/config/implemented.csv b/config/implemented.csv index 1d32f97f..8a03d8c2 100644 --- a/config/implemented.csv +++ b/config/implemented.csv @@ -284,6 +284,7 @@ th06::Supervisor::PlayAudio th06::Supervisor::StopAudio th06::Supervisor::SetupMidiPlayback th06::Supervisor::FadeOutMusic +th06::Controller::GetControllerState th06::GameWindow::InitD3dDevice th06::GameWindow::InitD3dRendering th06::ScreenEffect::Clear diff --git a/config/stubbed.csv b/config/stubbed.csv index 1c1bb225..84843322 100644 --- a/config/stubbed.csv +++ b/config/stubbed.csv @@ -29,5 +29,4 @@ th06::ReplayManager::StopRecording th06::ReplayManager::SaveReplay th06::ReplayManager::ValidateReplayData th06::ScreenEffect::DrawSquare -th06::Controller::GetControllerState th06::Pbg3Archive::Pbg3Archive diff --git a/src/Supervisor.cpp b/src/Supervisor.cpp index fe173db6..6cf368f9 100644 --- a/src/Supervisor.cpp +++ b/src/Supervisor.cpp @@ -1221,4 +1221,71 @@ ZunResult Supervisor::FadeOutMusic(f32 fadeOutSeconds) return ZUN_SUCCESS; } #pragma optimize("", on) + +DIFFABLE_STATIC_ARRAY(u8, (32*4), g_ControllerData) + +#pragma optimize("", on) +#pragma var_order(joyinfoex, joyButtonBit, joyButtonIndex, dires, dijoystate2, diRetryCount) +// This is for rebinding keys +u8 *th06::Controller::GetControllerState() +{ + JOYINFOEX joyinfoex; + u32 joyButtonBit; + u32 joyButtonIndex; + + i32 dires; + DIJOYSTATE2 dijoystate2; + i32 diRetryCount; + + memset(&g_ControllerData, 0, sizeof(g_ControllerData)); + if (g_Supervisor.controller == NULL) + { + memset(&joyinfoex, 0, sizeof(JOYINFOEX)); + joyinfoex.dwSize = sizeof(JOYINFOEX); + joyinfoex.dwFlags = JOY_RETURNALL; + if (joyGetPosEx(0, &joyinfoex) != JOYERR_NOERROR) + { + return g_ControllerData; + } + for (joyButtonBit = joyinfoex.dwButtons, joyButtonIndex = 0; joyButtonIndex < 32; joyButtonIndex += 1, joyButtonBit >>= 1) + { + if ((joyButtonBit & 1) != 0) + { + g_ControllerData[joyButtonIndex] = 0x80; + } + } + return g_ControllerData; + } + else + { + dires = g_Supervisor.controller->Poll(); + if (FAILED(dires)) + { + diRetryCount = 0; + utils::DebugPrint2("error : DIERR_INPUTLOST\n"); + dires = g_Supervisor.controller->Acquire(); + while (dires == DIERR_INPUTLOST) { + dires = g_Supervisor.controller->Acquire(); + utils::DebugPrint2("error : DIERR_INPUTLOST %d\n", diRetryCount); + diRetryCount++; + if (diRetryCount >= 400) { + return g_ControllerData; + } + } + return g_ControllerData; + } + else + { + /* dires = */ g_Supervisor.controller->GetDeviceState(sizeof(DIJOYSTATE2), &dijoystate2); + // TODO: seems ZUN forgot "dires =" above + if (FAILED(dires)) + { + return g_ControllerData; + } + memcpy(&g_ControllerData, dijoystate2.rgbButtons, sizeof(dijoystate2.rgbButtons)); + return g_ControllerData; + } + } +} +#pragma optimize("", on) }; // namespace th06 From 8e2515c1a656a178461dadce783c654d28c3315e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 1 Nov 2024 21:39:40 +0000 Subject: [PATCH 2/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/Supervisor.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/Supervisor.cpp b/src/Supervisor.cpp index 6cf368f9..b4429e39 100644 --- a/src/Supervisor.cpp +++ b/src/Supervisor.cpp @@ -1222,7 +1222,7 @@ ZunResult Supervisor::FadeOutMusic(f32 fadeOutSeconds) } #pragma optimize("", on) -DIFFABLE_STATIC_ARRAY(u8, (32*4), g_ControllerData) +DIFFABLE_STATIC_ARRAY(u8, (32 * 4), g_ControllerData) #pragma optimize("", on) #pragma var_order(joyinfoex, joyButtonBit, joyButtonIndex, dires, dijoystate2, diRetryCount) @@ -1232,11 +1232,11 @@ u8 *th06::Controller::GetControllerState() JOYINFOEX joyinfoex; u32 joyButtonBit; u32 joyButtonIndex; - + i32 dires; DIJOYSTATE2 dijoystate2; i32 diRetryCount; - + memset(&g_ControllerData, 0, sizeof(g_ControllerData)); if (g_Supervisor.controller == NULL) { @@ -1247,7 +1247,8 @@ u8 *th06::Controller::GetControllerState() { return g_ControllerData; } - for (joyButtonBit = joyinfoex.dwButtons, joyButtonIndex = 0; joyButtonIndex < 32; joyButtonIndex += 1, joyButtonBit >>= 1) + for (joyButtonBit = joyinfoex.dwButtons, joyButtonIndex = 0; joyButtonIndex < 32; + joyButtonIndex += 1, joyButtonBit >>= 1) { if ((joyButtonBit & 1) != 0) { @@ -1264,11 +1265,13 @@ u8 *th06::Controller::GetControllerState() diRetryCount = 0; utils::DebugPrint2("error : DIERR_INPUTLOST\n"); dires = g_Supervisor.controller->Acquire(); - while (dires == DIERR_INPUTLOST) { + while (dires == DIERR_INPUTLOST) + { dires = g_Supervisor.controller->Acquire(); utils::DebugPrint2("error : DIERR_INPUTLOST %d\n", diRetryCount); diRetryCount++; - if (diRetryCount >= 400) { + if (diRetryCount >= 400) + { return g_ControllerData; } } From 09e813cf6d5653670c3dc05aae526e35fb923a62 Mon Sep 17 00:00:00 2001 From: sere Date: Sat, 2 Nov 2024 02:13:52 +0400 Subject: [PATCH 3/3] small changes --- config/globals.csv | 1 + src/Supervisor.cpp | 13 +++++-------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/config/globals.csv b/config/globals.csv index ddc87d70..43369053 100644 --- a/config/globals.csv +++ b/config/globals.csv @@ -109,6 +109,7 @@ _g_NumOfFramesInputsWereHeld, 0x0069d910 _g_LastFileSize, 0x0069d914 _g_Chain, 0x0069d918 _g_GameErrorContext, 0x0069d998 +_g_ControllerData, 0x0069e1af _g_TextBufferSurface, 0x0069e230 _g_ItemManager, 0x0069e268 _g_GameWindow, 0x006c6bd4 diff --git a/src/Supervisor.cpp b/src/Supervisor.cpp index b4429e39..e16d4991 100644 --- a/src/Supervisor.cpp +++ b/src/Supervisor.cpp @@ -1277,17 +1277,14 @@ u8 *th06::Controller::GetControllerState() } return g_ControllerData; } - else + /* dires = */ g_Supervisor.controller->GetDeviceState(sizeof(DIJOYSTATE2), &dijoystate2); + // TODO: seems ZUN forgot "dires =" above + if (FAILED(dires)) { - /* dires = */ g_Supervisor.controller->GetDeviceState(sizeof(DIJOYSTATE2), &dijoystate2); - // TODO: seems ZUN forgot "dires =" above - if (FAILED(dires)) - { - return g_ControllerData; - } - memcpy(&g_ControllerData, dijoystate2.rgbButtons, sizeof(dijoystate2.rgbButtons)); return g_ControllerData; } + memcpy(&g_ControllerData, dijoystate2.rgbButtons, sizeof(dijoystate2.rgbButtons)); + return g_ControllerData; } } #pragma optimize("", on)