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/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..e16d4991 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; + } + /* 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