From 5a92910c18418bf210b1958967f919fe3346212d Mon Sep 17 00:00:00 2001 From: Nesuwu Date: Sun, 2 Aug 2026 22:01:53 +0200 Subject: [PATCH] input: expose unmapped button state Everything on C_4JInput resolves through the joypad map, so a caller that wants to know which physical button moved - a rebinding screen, say - has nowhere to ask. GetGameJoypadMapsRaw is the same idea for the map itself. GetGameJoypadMaps applies the button swap on the way out, and for pad 0's setting regardless of which pad you asked about, which is wrong for anything copying maps around. --- impls/Windows_Libs/Input/inc/INP_Main.h | 6 ++++++ impls/Windows_Libs/Input/src/4J_Input.cpp | 20 ++++++++++++++++++++ impls/Windows_Libs/Input/src/INP_Main.cpp | 20 ++++++++++++++++++++ inc/4J_Input.h | 4 ++++ 4 files changed, 50 insertions(+) diff --git a/impls/Windows_Libs/Input/inc/INP_Main.h b/impls/Windows_Libs/Input/inc/INP_Main.h index 4394ac9..43a598d 100644 --- a/impls/Windows_Libs/Input/inc/INP_Main.h +++ b/impls/Windows_Libs/Input/inc/INP_Main.h @@ -100,6 +100,7 @@ public: void SetGameJoypadMaps(unsigned char ucMap, unsigned char ucAction, unsigned int uiActionVal); unsigned int GetGameJoypadMaps(unsigned char ucMap, unsigned char ucAction); + unsigned int GetGameJoypadMapsRaw(unsigned char ucMap, unsigned char ucAction); void SetJoypadMapVal(int iPad, unsigned char ucMap); unsigned char GetJoypadMapVal(int iPad); @@ -115,6 +116,11 @@ public: bool ButtonReleased(int iPad, unsigned char ucAction); // toggled bool ButtonDown(int iPad, unsigned char ucAction = 255); // button held down + // unmapped, unswapped button words - for anything that needs to know which physical + // button moved rather than which action fired + unsigned int GetRawButtons(int iPad); + unsigned int GetRawButtonsPressed(int iPad); + float GetJoypadStick_Menu_LX(unsigned char ucPad); float GetJoypadStick_Menu_LY(unsigned char ucPad); float GetJoypadStick_Menu_RX(unsigned char ucPad); diff --git a/impls/Windows_Libs/Input/src/4J_Input.cpp b/impls/Windows_Libs/Input/src/4J_Input.cpp index bfb262d..cef379b 100644 --- a/impls/Windows_Libs/Input/src/4J_Input.cpp +++ b/impls/Windows_Libs/Input/src/4J_Input.cpp @@ -54,6 +54,11 @@ unsigned int C_4JInput::GetGameJoypadMaps(unsigned char ucMap, unsigned char ucA return InternalInputManager.GetGameJoypadMaps(ucMap, ucAction); } +unsigned int C_4JInput::GetGameJoypadMapsRaw(unsigned char ucMap, unsigned char ucAction) +{ + return InternalInputManager.GetGameJoypadMapsRaw(ucMap, ucAction); +} + void C_4JInput::SetJoypadMapVal(int iPad, unsigned char ucMap) { InternalInputManager.SetJoypadMapVal(iPad, ucMap); @@ -89,6 +94,21 @@ bool C_4JInput::ButtonDown(int iPad, unsigned char ucAction) return InternalInputManager.ButtonDown(iPad, ucAction); } +unsigned int C_4JInput::GetRawButtons(int iPad) +{ + return InternalInputManager.GetRawButtons(iPad); +} + +unsigned int C_4JInput::GetRawButtonsPressed(int iPad) +{ + return InternalInputManager.GetRawButtonsPressed(iPad); +} + +unsigned int C_4JInput::ApplyButtonSwap(int iPad, unsigned int uiInput) +{ + return InternalInputManager.ApplyButtonSwap(iPad, uiInput); +} + void C_4JInput::SetJoypadStickAxisMap(int iPad, unsigned int uiFrom, unsigned int uiTo) { InternalInputManager.SetJoypadStickAxisMap(iPad, uiFrom, uiTo); diff --git a/impls/Windows_Libs/Input/src/INP_Main.cpp b/impls/Windows_Libs/Input/src/INP_Main.cpp index ae2d3a7..0187024 100644 --- a/impls/Windows_Libs/Input/src/INP_Main.cpp +++ b/impls/Windows_Libs/Input/src/INP_Main.cpp @@ -298,6 +298,26 @@ unsigned int CInput::GetGameJoypadMaps(unsigned char ucMap, unsigned char ucActi return ApplyButtonSwap(0, uiVal); } +unsigned int CInput::GetGameJoypadMapsRaw(unsigned char ucMap, unsigned char ucAction) +{ + assert(ucMap < m_ucJoypadMapC); + assert(ucAction < m_ucJoypadMapActionC); + + return m_JoypadMap[ucMap][ucAction]; +} + +unsigned int CInput::GetRawButtons(int iPad) +{ + if (iPad < 0 || iPad >= MAX_JOYPADS) return 0; + return m_Joypads[iPad].m_uiButtons; +} + +unsigned int CInput::GetRawButtonsPressed(int iPad) +{ + if (iPad < 0 || iPad >= MAX_JOYPADS) return 0; + return (unsigned int)m_Joypads[iPad].m_uiButtonsPressed; +} + void CInput::SetJoypadMapVal(int iPad, unsigned char ucMap) { m_bJoypadMapArrayIsSetup = true; diff --git a/inc/4J_Input.h b/inc/4J_Input.h index 1307a6f..63ee8d1 100644 --- a/inc/4J_Input.h +++ b/inc/4J_Input.h @@ -82,6 +82,7 @@ public: void SetDeadzoneAndMovementRange(unsigned int uiDeadzone, unsigned int uiMovementRangeMax); void SetGameJoypadMaps(unsigned char ucMap, unsigned char ucAction, unsigned int uiActionVal); unsigned int GetGameJoypadMaps(unsigned char ucMap, unsigned char ucAction); + unsigned int GetGameJoypadMapsRaw(unsigned char ucMap, unsigned char ucAction); void SetJoypadMapVal(int iPad, unsigned char ucMap); unsigned char GetJoypadMapVal(int iPad); void SetJoypadSensitivity(int iPad, float fSensitivity); @@ -89,6 +90,9 @@ public: bool ButtonPressed(int iPad, unsigned char ucAction = 255); // toggled bool ButtonReleased(int iPad, unsigned char ucAction); //toggled bool ButtonDown(int iPad, unsigned char ucAction = 255); // button held down + unsigned int GetRawButtons(int iPad); + unsigned int GetRawButtonsPressed(int iPad); + unsigned int ApplyButtonSwap(int iPad, unsigned int uiInput); // Functions to remap the axis and triggers for in-game (not menus) - SouthPaw, etc void SetJoypadStickAxisMap(int iPad, unsigned int uiFrom, unsigned int uiTo); void SetJoypadStickTriggerMap(int iPad, unsigned int uiFrom, unsigned int uiTo);