diff --git a/src/Components/Modules/Gamepad.cpp b/src/Components/Modules/Gamepad.cpp index 2ec0e24d..d9d8371c 100644 --- a/src/Components/Modules/Gamepad.cpp +++ b/src/Components/Modules/Gamepad.cpp @@ -169,8 +169,8 @@ namespace Components {Game::K_APAD_RIGHT, Game::K_RIGHTARROW}, }; - Gamepad::GamePad Gamepad::gamePads[Game::MAX_GAMEPADS]{}; - Gamepad::GamePadGlobals Gamepad::gamePadGlobals[Game::MAX_GAMEPADS]{{}}; + Gamepad::GamePad Gamepad::gamePads[Game::MAX_GPAD_COUNT]{}; + Gamepad::GamePadGlobals Gamepad::gamePadGlobals[Game::MAX_GPAD_COUNT]{{}}; int Gamepad::gamePadBindingsModifiedFlags = 0; Dvar::Var Gamepad::gpad_enabled; @@ -314,7 +314,8 @@ namespace Components bool Gamepad::GPad_Check(const int gamePadIndex, const int portIndex) { - assert(gamePadIndex < Game::MAX_GAMEPADS); + assert((portIndex >= 0) && (portIndex < Game::MAX_GPAD_COUNT)); + auto& gamePad = gamePads[gamePadIndex]; if (XInputGetCapabilities(portIndex, XINPUT_FLAG_GAMEPAD, &gamePad.caps) == ERROR_SUCCESS) @@ -332,7 +333,7 @@ namespace Components { auto currentGamePadNum = 0; - for (auto currentPort = 0; currentPort < XUSER_MAX_COUNT && currentGamePadNum < Game::MAX_GAMEPADS; currentPort++) + for (auto currentPort = 0; currentPort < XUSER_MAX_COUNT && currentGamePadNum < Game::MAX_GPAD_COUNT; currentPort++) { if (GPad_Check(currentGamePadNum, currentPort)) currentGamePadNum++; @@ -366,7 +367,7 @@ namespace Components bool Gamepad::AimAssist_IsPlayerUsingOffhand(Game::AimAssistPlayerState* ps) { // Check offhand flag - if ((ps->weapFlags & 2) == 0) + if ((ps->weapFlags & Game::PWF_USING_OFFHAND) == 0) return false; // If offhand weapon has no id we are not using one @@ -421,7 +422,8 @@ namespace Components bool Gamepad::AimAssist_IsLockonActive(const int gamePadIndex) { - assert(gamePadIndex < Game::MAX_GAMEPADS); + assert(gamePadIndex < Game::MAX_GPAD_COUNT); + auto& aaGlob = Game::aaGlobArray[gamePadIndex]; if (!aim_lockon_enabled.get() || !gpad_lockon_enabled.get()) @@ -439,7 +441,9 @@ namespace Components void Gamepad::AimAssist_ApplyLockOn(const Game::AimInput* input, Game::AimOutput* output) { assert(input); - assert(input->localClientNum < Game::MAX_GAMEPADS); + assert(output); + AssertIn(input->localClientNum, Game::STATIC_MAX_LOCAL_CLIENTS); + auto& aaGlob = Game::aaGlobArray[input->localClientNum]; const auto prevTargetEnt = aaGlob.lockOnTargetEnt; @@ -554,10 +558,11 @@ namespace Components void Gamepad::AimAssist_CalcSlowdown(const Game::AimInput* input, float* pitchScale, float* yawScale) { assert(input); - assert(input->localClientNum < Game::MAX_GAMEPADS); - auto& aaGlob = Game::aaGlobArray[input->localClientNum]; assert(pitchScale); assert(yawScale); + AssertIn(input->localClientNum, Game::STATIC_MAX_LOCAL_CLIENTS); + + auto& aaGlob = Game::aaGlobArray[input->localClientNum]; *pitchScale = 1.0f; *yawScale = 1.0f; @@ -586,7 +591,10 @@ namespace Components void Gamepad::AimAssist_ApplyTurnRates(const Game::AimInput* input, Game::AimOutput* output) { - assert(input->localClientNum < Game::MAX_GAMEPADS); + assert(input); + assert(output); + AssertIn(input->localClientNum, Game::STATIC_MAX_LOCAL_CLIENTS); + auto& aaGlob = Game::aaGlobArray[input->localClientNum]; auto slowdownPitchScale = 0.0f; @@ -649,7 +657,8 @@ namespace Components void Gamepad::AimAssist_UpdateGamePadInput(const Game::AimInput* input, Game::AimOutput* output) { - assert(input->localClientNum < Game::MAX_GAMEPADS); + AssertIn(input->localClientNum, Game::STATIC_MAX_LOCAL_CLIENTS); + auto& aaGlob = Game::aaGlobArray[input->localClientNum]; output->pitch = input->pitch; @@ -784,8 +793,8 @@ namespace Components float Gamepad::CL_GamepadAxisValue(const int gamePadIndex, const Game::GamepadVirtualAxis virtualAxis) { - assert(gamePadIndex < Game::MAX_GAMEPADS); assert(virtualAxis > Game::GPAD_VIRTAXIS_NONE && virtualAxis < Game::GPAD_VIRTAXIS_COUNT); + const auto& gamePadGlobal = gamePadGlobals[gamePadIndex]; const auto& [physicalAxis, mapType] = gamePadGlobal.axes.virtualAxes[virtualAxis]; @@ -818,7 +827,8 @@ namespace Components void Gamepad::CL_GamepadMove(const int gamePadIndex, Game::usercmd_s* cmd, const float frameTimeBase) { - assert(gamePadIndex < Game::MAX_GAMEPADS); + assert(gamePadIndex < Game::MAX_GPAD_COUNT); + auto& gamePad = gamePads[gamePadIndex]; auto& clientActive = Game::clients[gamePadIndex]; @@ -960,7 +970,8 @@ namespace Components void Gamepad::CL_GamepadResetMenuScrollTime(const int gamePadIndex, const int key, const bool down, const unsigned time) { - assert(gamePadIndex < Game::MAX_GAMEPADS); + assert(gamePadIndex < Game::MAX_GPAD_COUNT); + auto& gamePadGlobal = gamePadGlobals[gamePadIndex]; if (!down) @@ -979,8 +990,8 @@ namespace Components void Gamepad::CL_GamepadGenerateAPad(const int gamePadIndex, const Game::GamepadPhysicalAxis physicalAxis, unsigned time) { - assert(gamePadIndex < Game::MAX_GAMEPADS); - assert(physicalAxis < Game::GPAD_PHYSAXIS_COUNT && physicalAxis >= 0); + assert(gamePadIndex < Game::MAX_GPAD_COUNT); + assert(physicalAxis >= 0 && physicalAxis < Game::GPAD_PHYSAXIS_COUNT); auto& gamePad = gamePads[gamePadIndex]; @@ -1014,8 +1025,8 @@ namespace Components void Gamepad::CL_GamepadEvent(const int gamePadIndex, const Game::GamepadPhysicalAxis physicalAxis, const float value, const unsigned time) { - assert(gamePadIndex < Game::MAX_GAMEPADS); - assert(physicalAxis < Game::GPAD_PHYSAXIS_COUNT && physicalAxis >= 0); + assert(gamePadIndex < Game::MAX_GPAD_COUNT); + assert(physicalAxis >= 0 && physicalAxis < Game::GPAD_PHYSAXIS_COUNT); auto& gamePad = gamePads[gamePadIndex]; auto& gamePadGlobal = gamePadGlobals[gamePadIndex]; @@ -1054,7 +1065,8 @@ namespace Components bool Gamepad::Scoreboard_HandleInput(int gamePadIndex, int key) { - assert(gamePadIndex < Game::MAX_GAMEPADS); + AssertIn(gamePadIndex, Game::STATIC_MAX_LOCAL_CLIENTS); + auto& keyState = Game::playerKeys[gamePadIndex]; if (keyState.keys[key].binding && strcmp(keyState.keys[key].binding, "togglescores") == 0) @@ -1080,7 +1092,8 @@ namespace Components bool Gamepad::CL_CheckForIgnoreDueToRepeat(const int gamePadIndex, const int key, const int repeatCount, const unsigned time) { - assert(gamePadIndex < Game::MAX_GAMEPADS); + AssertIn(gamePadIndex, Game::STATIC_MAX_LOCAL_CLIENTS); + auto& gamePadGlobal = gamePadGlobals[gamePadIndex]; if (Game::Key_IsKeyCatcherActive(gamePadIndex, Game::KEYCATCH_UI)) @@ -1113,7 +1126,7 @@ namespace Components void Gamepad::CL_GamepadButtonEvent(const int gamePadIndex, const int key, const Game::GamePadButtonEvent buttonEvent, const unsigned time) { - assert(gamePadIndex < Game::MAX_GAMEPADS); + assert(gamePadIndex < Game::MAX_GPAD_COUNT); const auto pressed = buttonEvent == Game::GPAD_BUTTON_PRESSED; const auto pressedOrUpdated = pressed || buttonEvent == Game::GPAD_BUTTON_UPDATE; @@ -1199,7 +1212,7 @@ namespace Components void Gamepad::CL_GamepadButtonEventForPort(const int gamePadIndex, const int key, const Game::GamePadButtonEvent buttonEvent, const unsigned time) { - assert(gamePadIndex < Game::MAX_GAMEPADS); + assert(gamePadIndex < Game::MAX_GPAD_COUNT); auto& gamePad = gamePads[gamePadIndex]; gamePad.inUse = true; @@ -1244,7 +1257,9 @@ namespace Components float Gamepad::GPad_GetStick(const int gamePadIndex, const Game::GamePadStick stick) { - assert(gamePadIndex < Game::MAX_GAMEPADS); + assert(gamePadIndex < Game::MAX_GPAD_COUNT); + assert(stick & Game::GPAD_STICK_MASK); + auto& gamePad = gamePads[gamePadIndex]; return gamePad.sticks[stick]; @@ -1252,7 +1267,7 @@ namespace Components float Gamepad::GPad_GetButton(const int gamePadIndex, Game::GamePadButton button) { - assert(gamePadIndex < Game::MAX_GAMEPADS); + assert(gamePadIndex < Game::MAX_GPAD_COUNT); auto& gamePad = gamePads[gamePadIndex]; float value = 0.0f; @@ -1276,7 +1291,9 @@ namespace Components bool Gamepad::GPad_IsButtonPressed(const int gamePadIndex, Game::GamePadButton button) { - assert(gamePadIndex < Game::MAX_GAMEPADS); + assert(gamePadIndex < Game::MAX_GPAD_COUNT); + assert(button & (Game::GPAD_DIGITAL_MASK | Game::GPAD_ANALOG_MASK)); + auto& gamePad = gamePads[gamePadIndex]; bool down = false; @@ -1310,7 +1327,8 @@ namespace Components bool Gamepad::GPad_IsButtonReleased(int gamePadIndex, Game::GamePadButton button) { - assert(gamePadIndex < Game::MAX_GAMEPADS); + assert(gamePadIndex < Game::MAX_GPAD_COUNT); + auto& gamePad = gamePads[gamePadIndex]; bool down = false; @@ -1340,7 +1358,8 @@ namespace Components void Gamepad::GPad_UpdateSticksDown(const int gamePadIndex) { - assert(gamePadIndex < Game::MAX_GAMEPADS); + assert(gamePadIndex < Game::MAX_GPAD_COUNT); + auto& gamePad = gamePads[gamePadIndex]; for (auto stickIndex = 0u; stickIndex < std::extent_v; stickIndex++) @@ -1371,7 +1390,7 @@ namespace Components void Gamepad::GPad_UpdateSticks(const int gamePadIndex, const XINPUT_GAMEPAD& state) { - assert(gamePadIndex < Game::MAX_GAMEPADS); + assert(gamePadIndex < Game::MAX_GPAD_COUNT); auto& gamePad = gamePads[gamePadIndex]; @@ -1403,7 +1422,7 @@ namespace Components void Gamepad::GPad_UpdateDigitals(const int gamePadIndex, const XINPUT_GAMEPAD& state) { - assert(gamePadIndex < Game::MAX_GAMEPADS); + assert(gamePadIndex < Game::MAX_GPAD_COUNT); auto& gamePad = gamePads[gamePadIndex]; @@ -1425,7 +1444,7 @@ namespace Components void Gamepad::GPad_UpdateAnalogs(const int gamePadIndex, const XINPUT_GAMEPAD& state) { - assert(gamePadIndex < Game::MAX_GAMEPADS); + assert(gamePadIndex < Game::MAX_GPAD_COUNT); auto& gamePad = gamePads[gamePadIndex]; @@ -1452,7 +1471,7 @@ namespace Components { GPad_RefreshAll(); - for (auto currentGamePadIndex = 0; currentGamePadIndex < Game::MAX_GAMEPADS; currentGamePadIndex++) + for (auto currentGamePadIndex = 0; currentGamePadIndex < Game::MAX_GPAD_COUNT; currentGamePadIndex++) { const auto& gamePad = gamePads[currentGamePadIndex]; if (!gamePad.enabled) @@ -1477,7 +1496,7 @@ namespace Components const auto time = Game::Sys_Milliseconds(); bool gpadPresent = false; - for (auto gamePadIndex = 0; gamePadIndex < Game::MAX_GAMEPADS; gamePadIndex++) + for (auto gamePadIndex = 0; gamePadIndex < Game::MAX_GPAD_COUNT; gamePadIndex++) { const auto& gamePad = gamePads[gamePadIndex]; @@ -1540,7 +1559,8 @@ namespace Components void Gamepad::Gamepad_WriteBindings(const int gamePadIndex, const int handle) { - assert(gamePadIndex < Game::MAX_GAMEPADS); + assert(gamePadIndex < Game::MAX_GPAD_COUNT); + auto& gamePadGlobal = gamePadGlobals[gamePadIndex]; Game::FS_Printf(handle, "unbindallaxis\n"); @@ -1584,7 +1604,7 @@ namespace Components push 0x60B26E retn - endMethod: + endMethod: push 0x60B298 retn } @@ -1592,7 +1612,7 @@ namespace Components void Gamepad::Gamepad_BindAxis(const int gamePadIndex, const Game::GamepadPhysicalAxis realIndex, const Game::GamepadVirtualAxis axisIndex, const Game::GamepadMapping mapType) { - assert(gamePadIndex < Game::MAX_GAMEPADS); + assert(gamePadIndex < Game::MAX_GPAD_COUNT); assert(realIndex > Game::GPAD_PHYSAXIS_NONE && realIndex < Game::GPAD_PHYSAXIS_COUNT); assert(axisIndex > Game::GPAD_VIRTAXIS_NONE && axisIndex < Game::GPAD_VIRTAXIS_COUNT); assert(mapType > Game::GPAD_MAP_NONE && mapType < Game::GPAD_MAP_COUNT); diff --git a/src/Components/Modules/Gamepad.hpp b/src/Components/Modules/Gamepad.hpp index 11fb17d8..45969762 100644 --- a/src/Components/Modules/Gamepad.hpp +++ b/src/Components/Modules/Gamepad.hpp @@ -62,8 +62,8 @@ namespace Components static Game::keyname_t combinedLocalizedKeyNamesPs3[]; static ControllerMenuKeyMapping controllerMenuKeyMappings[]; - static GamePad gamePads[Game::MAX_GAMEPADS]; - static GamePadGlobals gamePadGlobals[Game::MAX_GAMEPADS]; + static GamePad gamePads[Game::MAX_GPAD_COUNT]; + static GamePadGlobals gamePadGlobals[Game::MAX_GPAD_COUNT]; static int gamePadBindingsModifiedFlags; diff --git a/src/Game/Structs.hpp b/src/Game/Structs.hpp index 53da9032..852aec3b 100644 --- a/src/Game/Structs.hpp +++ b/src/Game/Structs.hpp @@ -7615,7 +7615,7 @@ namespace Game static_assert(sizeof(cg_s) == 0xFD540); - static constexpr auto MAX_GAMEPADS = 1; + static constexpr auto MAX_GPAD_COUNT = 1; static constexpr auto GPAD_VALUE_MASK = 0xFFFFFFFu; static constexpr auto GPAD_DPAD_MASK = XINPUT_GAMEPAD_DPAD_UP | XINPUT_GAMEPAD_DPAD_DOWN | XINPUT_GAMEPAD_DPAD_LEFT | XINPUT_GAMEPAD_DPAD_RIGHT;