diff --git a/src/Components/Modules/Gamepad.cpp b/src/Components/Modules/Gamepad.cpp index 1112da9..c55aed3 100644 --- a/src/Components/Modules/Gamepad.cpp +++ b/src/Components/Modules/Gamepad.cpp @@ -174,6 +174,7 @@ namespace Components Gamepad::GamePad Gamepad::gamePads[Game::MAX_GPAD_COUNT]{}; Gamepad::GamePadGlobals Gamepad::gamePadGlobals[Game::MAX_GPAD_COUNT]{ {} }; int Gamepad::gamePadBindingsModifiedFlags = 0; + Gamepad::ButtonMappings Gamepad::buttonMappingLayout; Gamepad::GamePadGlobals::GamePadGlobals() : axes{}, @@ -186,6 +187,141 @@ namespace Components } } + void Gamepad::GetButtonLayout() + { + std::string gpadButtonConfig = Dvars::gpad_buttonConfig->current.string; + if (gpadButtonConfig == "buttons_default") + { + buttonMappingLayout.buttonA = "MENU_JUMP"; + buttonMappingLayout.buttonB = "MENU_CROUCH_PRONE"; + buttonMappingLayout.buttonX = "MENU_USE_RELOAD"; + buttonMappingLayout.buttonY = "MENU_SWITCH_WEAPON"; + buttonMappingLayout.buttonBlack = "MENU_THROW_SPECIAL_GRENADE"; + buttonMappingLayout.buttonWhite = "MENU_THROW_FRAG_GRENADE"; + buttonMappingLayout.buttonDown = "MENU_INVENTORY"; + buttonMappingLayout.buttonLTrig = "MENU_AIM_DOWN_SIGHT"; + buttonMappingLayout.buttonRTrig = "MENU_FIRE_WEAPON"; + buttonMappingLayout.buttonStart = "MENU_OBJECTIVES_MENU"; + buttonMappingLayout.buttonBack = "MENU_NOT_USED"; + buttonMappingLayout.buttonLStick = "MENU_SPRINT"; + buttonMappingLayout.buttonRStick = "MENU_MELEE_ATTACK"; + } + else if (gpadButtonConfig == "buttons_tactical") + { + buttonMappingLayout.buttonA = "MENU_JUMP"; + buttonMappingLayout.buttonB = "MENU_MELEE_ATTACK"; + buttonMappingLayout.buttonX = "MENU_USE_RELOAD"; + buttonMappingLayout.buttonY = "MENU_SWITCH_WEAPON"; + buttonMappingLayout.buttonBlack = "MENU_THROW_SPECIAL_GRENADE"; + buttonMappingLayout.buttonWhite = "MENU_THROW_FRAG_GRENADE"; + buttonMappingLayout.buttonDown = "MENU_INVENTORY"; + buttonMappingLayout.buttonLTrig = "MENU_AIM_DOWN_SIGHT"; + buttonMappingLayout.buttonRTrig = "MENU_FIRE_WEAPON"; + buttonMappingLayout.buttonStart = "MENU_OBJECTIVES_MENU"; + buttonMappingLayout.buttonBack = "MENU_NOT_USED"; + buttonMappingLayout.buttonLStick = "MENU_SPRINT"; + buttonMappingLayout.buttonRStick = "MENU_CROUCH_PRONE"; + } + else if (gpadButtonConfig == "buttons_lefty") + { + buttonMappingLayout.buttonA = "MENU_JUMP"; + buttonMappingLayout.buttonB = "MENU_CROUCH_PRONE"; + buttonMappingLayout.buttonX = "MENU_USE_RELOAD"; + buttonMappingLayout.buttonY = "MENU_SWITCH_WEAPON"; + buttonMappingLayout.buttonBlack = "MENU_THROW_FRAG_GRENADE"; + buttonMappingLayout.buttonWhite = "MENU_THROW_SPECIAL_GRENADE"; + buttonMappingLayout.buttonDown = "MENU_INVENTORY"; + buttonMappingLayout.buttonLTrig = "MENU_FIRE_WEAPON"; + buttonMappingLayout.buttonRTrig = "MENU_AIM_DOWN_SIGHT"; + buttonMappingLayout.buttonStart = "MENU_OBJECTIVES_MENU"; + buttonMappingLayout.buttonBack = "MENU_NOT_USED"; + buttonMappingLayout.buttonLStick = "MENU_SPRINT"; + buttonMappingLayout.buttonRStick = "MENU_MELEE_ATTACK"; + } + else if (gpadButtonConfig == "buttons_default_alt") + { + buttonMappingLayout.buttonA = "MENU_JUMP"; + buttonMappingLayout.buttonB = "MENU_CROUCH_PRONE"; + buttonMappingLayout.buttonX = "MENU_USE_RELOAD"; + buttonMappingLayout.buttonY = "MENU_SWITCH_WEAPON"; + buttonMappingLayout.buttonBlack = "MENU_AIM_DOWN_SIGHT"; + buttonMappingLayout.buttonWhite = "MENU_FIRE_WEAPON"; + buttonMappingLayout.buttonDown = "MENU_INVENTORY"; + buttonMappingLayout.buttonLTrig = "MENU_THROW_SPECIAL_GRENADE"; + buttonMappingLayout.buttonRTrig = "MENU_THROW_FRAG_GRENADE"; + buttonMappingLayout.buttonStart = "MENU_OBJECTIVES_MENU"; + buttonMappingLayout.buttonBack = "MENU_NOT_USED"; + buttonMappingLayout.buttonLStick = "MENU_SPRINT"; + buttonMappingLayout.buttonRStick = "MENU_MELEE_ATTACK"; + } + else if (gpadButtonConfig == "buttons_tactical_alt") + { + buttonMappingLayout.buttonA = "MENU_JUMP"; + buttonMappingLayout.buttonB = "MENU_MELEE_ATTACK"; + buttonMappingLayout.buttonX = "MENU_USE_RELOAD"; + buttonMappingLayout.buttonY = "MENU_SWITCH_WEAPON"; + buttonMappingLayout.buttonBlack = "MENU_AIM_DOWN_SIGHT"; + buttonMappingLayout.buttonWhite = "MENU_FIRE_WEAPON"; + buttonMappingLayout.buttonDown = "MENU_INVENTORY"; + buttonMappingLayout.buttonLTrig = "MENU_THROW_SPECIAL_GRENADE"; + buttonMappingLayout.buttonRTrig = "MENU_THROW_FRAG_GRENADE"; + buttonMappingLayout.buttonStart = "MENU_OBJECTIVES_MENU"; + buttonMappingLayout.buttonBack = "MENU_NOT_USED"; + buttonMappingLayout.buttonLStick = "MENU_SPRINT"; + buttonMappingLayout.buttonRStick = "MENU_CROUCH_PRONE"; + } + else if (gpadButtonConfig == "buttons_lefty_alt") + { + buttonMappingLayout.buttonA = "MENU_JUMP"; + buttonMappingLayout.buttonB = "MENU_CROUCH_PRONE"; + buttonMappingLayout.buttonX = "MENU_USE_RELOAD"; + buttonMappingLayout.buttonY = "MENU_SWITCH_WEAPON"; + buttonMappingLayout.buttonBlack = "MENU_FIRE_WEAPON"; + buttonMappingLayout.buttonWhite = "MENU_AIM_DOWN_SIGHT"; + buttonMappingLayout.buttonDown = "MENU_INVENTORY"; + buttonMappingLayout.buttonLTrig = "MENU_THROW_FRAG_GRENADE"; + buttonMappingLayout.buttonRTrig = "MENU_THROW_SPECIAL_GRENADE"; + buttonMappingLayout.buttonStart = "MENU_OBJECTIVES_MENU"; + buttonMappingLayout.buttonBack = "MENU_NOT_USED"; + buttonMappingLayout.buttonLStick = "MENU_SPRINT"; + buttonMappingLayout.buttonRStick = "MENU_MELEE_ATTACK"; + } + } + + // This solution is very bad, but it works and there's no need to create duplicate menus. + void Gamepad::UpdateTheButtonAHint() + { + // APPLYING CHANGES ON THE STOCK GAME ONLY!!! + if (Game::DB_IsZoneLoaded("mod")) + return; + + // Define button alignments + static const double mainButtonAlign_PC = -10.0; + static const double mainButtonAlign_Console = -22.0; + static const double settingButtonAlign_PC = -8.0; + static const double settingButtonAlign_Console = -20.0; + static const double popMenusButtonAlign_PC = -6.0; + static const double popMenusButtonAlign_Console = -18.0; + + // Loop through menus and items + for (auto i = 0; i < Game::uiInfo->uiDC.menuCount; i++) + { + for (auto a = 0; a < Game::uiInfo->uiDC.Menus[i]->itemCount; a++) + { + auto currentItem = Game::uiInfo->uiDC.Menus[i]->items[a]; + if (currentItem && (currentItem->type == Game::ITEM_TYPE_BUTTON || currentItem->type == Game::ITEM_TYPE_TEXT)) + { + // Update button alignments based on conditions + if (currentItem->textalignx == mainButtonAlign_PC || currentItem->textalignx == mainButtonAlign_Console) + currentItem->textalignx = IsGamePadInUse() ? mainButtonAlign_Console : mainButtonAlign_PC; + else if (currentItem->textalignx == settingButtonAlign_PC || currentItem->textalignx == settingButtonAlign_Console) + currentItem->textalignx = IsGamePadInUse() ? settingButtonAlign_Console : settingButtonAlign_PC; + else if (currentItem->textalignx == popMenusButtonAlign_PC || currentItem->textalignx == popMenusButtonAlign_Console) + currentItem->textalignx = IsGamePadInUse() ? popMenusButtonAlign_Console : popMenusButtonAlign_PC; + } + } + } + } void Gamepad::UpdateGamepadHint() { @@ -1627,7 +1763,7 @@ namespace Components if (Dvars::gpad_debug->current.enabled) Game::Com_Printf(0, "Buttons: {%hu}\n", gamePad.digitals); - } + } void Gamepad::GPad_UpdateAnalogs(const int localClientNum, const XINPUT_GAMEPAD& state) { @@ -1653,7 +1789,7 @@ namespace Components if (Dvars::gpad_debug->current.enabled) Game::Com_Printf(0, "Triggers: {%f} {%f}\n", gamePad.analogs[0], gamePad.analogs[1]); - } + } void Gamepad::GPad_UpdateAll() { @@ -1759,7 +1895,8 @@ namespace Components void Gamepad::IN_GamePadsMove() { - if (!Dvars::Functions::Dvar_FindVar("gpad_enabled")->current.enabled || Game::Key_IsCatcherActive(Game::KEYCATCH_CONSOLE)) + UpdateTheButtonAHint(); + if (!Dvars::gpad_enabled->current.enabled || Game::Key_IsCatcherActive(Game::KEYCATCH_CONSOLE)) return; @@ -2146,7 +2283,21 @@ namespace Components Command::Add("bindgpsticksconfigs", Bind_GP_SticksConfigs_f); Command::Add("bindgpbuttonsconfigs", Bind_GP_ButtonsConfigs_f); Command::Add("setaimassist", SetAimAssist_f); - Command::Add("togglemenu", PauseMenu_Toggle_f); + + Command::Add("togglescores", []() {}); //null is the current moment + + Command::Add("togglemenu", []() + { + // CheckForConsoleGuidePause + if (!Dvars::Functions::Dvar_FindVar("cl_paused")->current.enabled + && Dvars::Functions::Dvar_FindVar("sv_running")->current.enabled + && (!Game::R_Cinematic_IsStarted() || !Dvars::Functions::Dvar_FindVar("cg_cinematicFullscreen")->current.enabled) + && !Game::Key_IsCatcherActive(Game::KEYCATCH_UI)) + { + Game::UI_SetActiveMenu(Game::uiInfo->uiDC.localClientNum, Game::UIMENU_PAUSED); + return; + } + }); // Gamepad on frame hook Utils::Hook(0x594913, IN_Frame_Hk, HOOK_CALL).install()->quick(); @@ -2177,7 +2328,7 @@ namespace Components Utils::Hook(0x4402F7, CL_MouseMove_Stub, HOOK_JUMP).install()->quick(); UIScript::Add("gamepadFirstExecIfEnabled", []([[maybe_unused]] const UIScript::Token& token, [[maybe_unused]] const Game::uiInfo_s* info) - { + { if (Dvars::gpad_enabled->current.enabled) { std::string gpadSticksConfig = Dvars::gpad_sticksConfig->current.string; diff --git a/src/Components/Modules/Gamepad.hpp b/src/Components/Modules/Gamepad.hpp index 16c0f17..44ece62 100644 --- a/src/Components/Modules/Gamepad.hpp +++ b/src/Components/Modules/Gamepad.hpp @@ -54,7 +54,27 @@ namespace Components GamePadGlobals(); }; + struct ButtonMappings + { + const char* buttonA; + const char* buttonB; + const char* buttonX; + const char* buttonY; + const char* buttonBlack; + const char* buttonWhite; + const char* buttonDown; //D-pad + const char* buttonLTrig; + const char* buttonRTrig; + const char* buttonStart; + const char* buttonBack; + const char* buttonLStick; + const char* buttonRStick; + }; + public: + static ButtonMappings buttonMappingLayout; + static void GetButtonLayout(); + Gamepad(); ~Gamepad(); static void OnMouseMove(int x, int y, int dx, int dy); @@ -153,7 +173,6 @@ namespace Components static void Bind_GP_SticksConfigs_f(); static void Bind_GP_ButtonsConfigs_f(); static void SetAimAssist_f(); - static void PauseMenu_Toggle_f(); static const char* GetGamePadCommand(const char* command); static int Key_GetCommandAssignmentInternal(int localClientNum, const char* cmd, int(*keys)[2]); @@ -185,6 +204,7 @@ namespace Components static void Vibrate(int leftVal, int rightVal); static void UpdateGamepadHint(); + static void UpdateTheButtonAHint(); static bool HasGamepadStateChanged(bool currentState); }; } \ No newline at end of file