From cb2e24a52f38189d6564634f6f383e6ba1be75b0 Mon Sep 17 00:00:00 2001 From: Jan Date: Sat, 4 Sep 2021 11:15:34 +0200 Subject: [PATCH] Make gamepad scoreboard toggable and scrollable --- src/Components/Modules/Gamepad.cpp | 45 ++++++++++++++++++++++++++++++ src/Components/Modules/Gamepad.hpp | 2 ++ src/Game/Functions.cpp | 4 +++ src/Game/Functions.hpp | 12 ++++++++ src/Game/Structs.hpp | 13 +++++---- 5 files changed, 70 insertions(+), 6 deletions(-) diff --git a/src/Components/Modules/Gamepad.cpp b/src/Components/Modules/Gamepad.cpp index 424a781e..49d3b70d 100644 --- a/src/Components/Modules/Gamepad.cpp +++ b/src/Components/Modules/Gamepad.cpp @@ -1042,6 +1042,32 @@ namespace Components // Game::UI_KeyEvent(gamePadIndex, key, down); } + bool Gamepad::Scoreboard_HandleInput(int gamePadIndex, int key) + { + assert(gamePadIndex < Game::MAX_GAMEPADS); + auto& keyState = Game::playerKeys[gamePadIndex]; + + if (keyState.keys[key].binding && strcmp(keyState.keys[key].binding, "togglescores") == 0) + { + Game::Cbuf_AddText(gamePadIndex, "togglescores\n"); + return true; + } + + switch (key) + { + case Game::K_DPAD_UP: + Game::CG_ScrollScoreboardUp(Game::cgArray); + return true; + + case Game::K_DPAD_DOWN: + Game::CG_ScrollScoreboardDown(Game::cgArray); + return true; + + default: + return false; + } + } + bool Gamepad::CL_CheckForIgnoreDueToRepeat(const int gamePadIndex, const int key, const int repeatCount, const unsigned time) { assert(gamePadIndex < Game::MAX_GAMEPADS); @@ -1113,6 +1139,13 @@ namespace Components return; } + const auto activeMenu = Game::UI_GetActiveMenu(gamePadIndex); + if(activeMenu == Game::UIMENU_SCOREBOARD) + { + if (buttonEvent == Game::GPAD_BUTTON_PRESSED && Scoreboard_HandleInput(gamePadIndex, key)) + return; + } + keyState.locSelInputState = Game::LOC_SEL_INPUT_NONE; const auto* keyBinding = keyState.keys[key].binding; @@ -1663,6 +1696,17 @@ namespace Components Game::Cbuf_AddText(0, Utils::String::VA("exec %s\n", buttonConfigName)); } + void Gamepad::Scores_Toggle_f(Command::Params*) + { + if(Game::cgArray[0].nextSnap) + { + if (Game::UI_GetActiveMenu(0) != Game::UIMENU_SCOREBOARD) + Game::CG_ScoresDown_f(); + else + Game::CG_ScoresUp_f(); + } + } + void Gamepad::InitDvars() { gpad_enabled = Dvar::Register("gpad_enabled", false, Game::DVAR_FLAG_SAVED, "Game pad enabled"); @@ -1851,6 +1895,7 @@ namespace Components Command::Add("unbindallaxis", Axis_Unbindall_f); Command::Add("bindgpsticksconfigs", Bind_GP_SticksConfigs_f); Command::Add("bindgpbuttonsconfigs", Bind_GP_ButtonsConfigs_f); + Command::Add("togglescores", Scores_Toggle_f); if (Dedicated::IsEnabled()) return; diff --git a/src/Components/Modules/Gamepad.hpp b/src/Components/Modules/Gamepad.hpp index 21106886..09488a78 100644 --- a/src/Components/Modules/Gamepad.hpp +++ b/src/Components/Modules/Gamepad.hpp @@ -364,6 +364,7 @@ namespace Components static bool Key_IsValidGamePadChar(int key); static void CL_GamepadResetMenuScrollTime(int gamePadIndex, int key, bool down, unsigned int time); + static bool Scoreboard_HandleInput(int gamePadIndex, int key); static bool CL_CheckForIgnoreDueToRepeat(int gamePadIndex, int key, int repeatCount, unsigned int time); static void UI_GamepadKeyEvent(int gamePadIndex, int key, bool down); static void CL_GamepadGenerateAPad(int gamePadIndex, Game::GamepadPhysicalAxis physicalAxis, unsigned time); @@ -401,6 +402,7 @@ namespace Components static void Axis_Unbindall_f(Command::Params* params); static void Bind_GP_SticksConfigs_f(Command::Params* params); static void Bind_GP_ButtonsConfigs_f(Command::Params* params); + static void Scores_Toggle_f(Command::Params* params); static void InitDvars(); static void IN_Init_Hk(); diff --git a/src/Game/Functions.cpp b/src/Game/Functions.cpp index c9edb167..1ac39bc9 100644 --- a/src/Game/Functions.cpp +++ b/src/Game/Functions.cpp @@ -39,6 +39,10 @@ namespace Game CG_GetClientNum_t CG_GetClientNum = CG_GetClientNum_t(0x433700); CG_PlayBoltedEffect_t CG_PlayBoltedEffect = CG_PlayBoltedEffect_t(0x00430E10); CG_GetBoneIndex_t CG_GetBoneIndex = CG_GetBoneIndex_t(0x00504F20); + CG_ScoresDown_f_t CG_ScoresDown_f = CG_ScoresDown_f_t(0x580370); + CG_ScoresUp_f_t CG_ScoresUp_f = CG_ScoresUp_f_t(0x5802C0); + CG_ScrollScoreboardUp_t CG_ScrollScoreboardUp = CG_ScrollScoreboardUp_t(0x47A5C0); + CG_ScrollScoreboardDown_t CG_ScrollScoreboardDown = CG_ScrollScoreboardDown_t(0x493B50); CL_GetClientName_t CL_GetClientName = CL_GetClientName_t(0x4563D0); CL_IsCgameInitialized_t CL_IsCgameInitialized = CL_IsCgameInitialized_t(0x43EB20); diff --git a/src/Game/Functions.hpp b/src/Game/Functions.hpp index 1f762b72..6e97fc7c 100644 --- a/src/Game/Functions.hpp +++ b/src/Game/Functions.hpp @@ -60,6 +60,18 @@ namespace Game typedef std::int32_t(__cdecl* CG_GetBoneIndex_t)(std::int32_t, std::uint32_t name, char* index); extern CG_GetBoneIndex_t CG_GetBoneIndex; + + typedef void(__cdecl * CG_ScoresDown_f_t)(); + extern CG_ScoresDown_f_t CG_ScoresDown_f; + + typedef void(__cdecl * CG_ScoresUp_f_t)(); + extern CG_ScoresUp_f_t CG_ScoresUp_f; + + typedef void(__cdecl * CG_ScrollScoreboardUp_t)(cg_s* cgameGlob); + extern CG_ScrollScoreboardUp_t CG_ScrollScoreboardUp; + + typedef void(__cdecl * CG_ScrollScoreboardDown_t)(cg_s* cgameGlob); + extern CG_ScrollScoreboardDown_t CG_ScrollScoreboardDown; typedef char*(__cdecl * CL_GetClientName_t)(int localClientNum, int index, char *buf, size_t size); extern CL_GetClientName_t CL_GetClientName; diff --git a/src/Game/Structs.hpp b/src/Game/Structs.hpp index 18710994..a73b370d 100644 --- a/src/Game/Structs.hpp +++ b/src/Game/Structs.hpp @@ -6169,21 +6169,22 @@ namespace Game struct __declspec(align(8)) cg_s { playerState_s predictedPlayerState; - char _pad0[0x67638]; + char _pad0[0x254]; + void* snap; + void* nextSnap; + char _pad1[0x673DC]; int frametime; // + 0x6A754 - char _pad1[0x960C]; // + 0x6A758 + char _pad2[0x960C]; // + 0x6A758 float compassMapWorldSize[2]; // + 0x73D64 - char _pad2[0x74]; // + 0x73D6C + char _pad3[0x74]; // + 0x73D6C float selectedLocation[2]; // + 0x73DE0 float selectedLocationAngle; float selectedAngleLocation[2]; float selectedLocationPrev[2]; float selectedLocationAnglePrev; - char _pad3[0x89740]; + char _pad4[0x89740]; }; - constexpr auto aaaaaaa1 = sizeof(cg_s); - #pragma endregion #ifndef IDA