From 7b7dd2bef15728cfe8c2da84c8b13724e16b4c36 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Tue, 5 Nov 2024 16:07:29 +1000 Subject: [PATCH] AnalogController: Reset state on analog->digital switch But only when the game does not support analog mode. Tomb Raider's game selector menu puts the controller into configuration mode, and we're supposed to respond with a 0x00 header byte if the user switches the pad to digital mode. Problem is, the game itself doesn't understand this mode switch nor configuration mode. So the status byte gets stuck at 0x00 if the user toggles analog mode, and the game thinks no pad is connected. Work around this by resetting the whole state if the game does not support analog mode. --- src/core/analog_controller.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/core/analog_controller.cpp b/src/core/analog_controller.cpp index 5f28482be..09f22815d 100644 --- a/src/core/analog_controller.cpp +++ b/src/core/analog_controller.cpp @@ -331,8 +331,25 @@ void AnalogController::ProcessAnalogModeToggle() SetAnalogMode(!m_analog_mode, true); ResetRumbleConfig(); + // Set status byte to 0 if we were previously in configuration mode, so that the game knows about the mode change. if (m_dualshock_enabled) - m_status_byte = 0x00; + { + // However, the problem with doing this unconditionally is that games like Tomb Raider have the loader menu + // put the pad into configuration mode, but not analog mode. So if the user toggles analog mode, the status + // byte ends up stuck at 0x00. As a workaround, clear out config/dualshock mode when the game isn't flagged + // as supporting the dualshock. + if (!m_analog_mode && !CanStartInAnalogMode(ControllerType::AnalogController)) + { + WARNING_LOG("Resetting pad on digital->analog switch."); + m_configuration_mode = false; + m_dualshock_enabled = false; + m_status_byte = 0x5A; + } + else + { + m_status_byte = 0x00; + } + } } }