From 0642eed7bc80d25bb72fc46c9d0d639314f0f99c Mon Sep 17 00:00:00 2001 From: FutureRave Date: Mon, 28 Nov 2022 22:04:57 +0000 Subject: [PATCH] [General]: Correct function definition --- src/Components/Modules/ClanTags.cpp | 4 +--- src/Components/Modules/Gamepad.cpp | 12 +++++----- src/Components/Modules/UIScript.cpp | 35 +++++++++++++++++------------ src/Components/Modules/UIScript.hpp | 2 ++ src/Game/Client.cpp | 6 +++++ src/Game/Client.hpp | 1 + src/Game/Functions.cpp | 2 +- src/Game/Functions.hpp | 6 ++--- 8 files changed, 41 insertions(+), 27 deletions(-) diff --git a/src/Components/Modules/ClanTags.cpp b/src/Components/Modules/ClanTags.cpp index 7394e55d..2aa3d29d 100644 --- a/src/Components/Modules/ClanTags.cpp +++ b/src/Components/Modules/ClanTags.cpp @@ -70,9 +70,7 @@ namespace Components void ClanTags::CL_SanitizeClanName() { - char saneNameBuf[5]; - std::memset(saneNameBuf, 0, sizeof(saneNameBuf)); - + char saneNameBuf[5]{}; auto* saneName = saneNameBuf; assert(ClanName); diff --git a/src/Components/Modules/Gamepad.cpp b/src/Components/Modules/Gamepad.cpp index 4942ff58..e749053e 100644 --- a/src/Components/Modules/Gamepad.cpp +++ b/src/Components/Modules/Gamepad.cpp @@ -788,7 +788,7 @@ namespace Components bool Gamepad::CG_ShouldUpdateViewAngles(const int localClientNum) { - return !Game::Key_IsKeyCatcherActive(localClientNum, Game::KEYCATCH_MASK_ANY) || Game::UI_GetActiveMenu(localClientNum) == Game::UIMENU_SCOREBOARD; + return !Game::Key_IsCatcherActive(localClientNum, Game::KEYCATCH_MASK_ANY) || Game::UI_GetActiveMenu(localClientNum) == Game::UIMENU_SCOREBOARD; } float Gamepad::CL_GamepadAxisValue(const int gamePadIndex, const Game::GamepadVirtualAxis virtualAxis) @@ -1096,7 +1096,7 @@ namespace Components auto& gamePadGlobal = gamePadGlobals[gamePadIndex]; - if (Game::Key_IsKeyCatcherActive(gamePadIndex, Game::KEYCATCH_UI)) + if (Game::Key_IsCatcherActive(gamePadIndex, Game::KEYCATCH_UI)) { const int scrollDelayFirst = gpad_menu_scroll_delay_first.get(); const int scrollDelayRest = gpad_menu_scroll_delay_rest.get(); @@ -1149,7 +1149,7 @@ namespace Components if (pressedOrUpdated && CL_CheckForIgnoreDueToRepeat(gamePadIndex, key, keyState.keys[key].repeats, time)) return; - if (Game::Key_IsKeyCatcherActive(gamePadIndex, Game::KEYCATCH_LOCATION_SELECTION) && pressedOrUpdated) + if (Game::Key_IsCatcherActive(gamePadIndex, Game::KEYCATCH_LOCATION_SELECTION) && pressedOrUpdated) { if (key == Game::K_BUTTON_B || keyState.keys[key].binding && strcmp(keyState.keys[key].binding, "+actionslot 4") == 0) { @@ -1176,7 +1176,7 @@ namespace Components char cmd[1024]; if (pressedOrUpdated) { - if (Game::Key_IsKeyCatcherActive(gamePadIndex, Game::KEYCATCH_UI)) + if (Game::Key_IsCatcherActive(gamePadIndex, Game::KEYCATCH_UI)) { UI_GamepadKeyEvent(gamePadIndex, key, pressedOrUpdated); return; @@ -1203,7 +1203,7 @@ namespace Components Game::Cbuf_AddText(gamePadIndex, cmd); } - if (Game::Key_IsKeyCatcherActive(gamePadIndex, Game::KEYCATCH_UI)) + if (Game::Key_IsCatcherActive(gamePadIndex, Game::KEYCATCH_UI)) { UI_GamepadKeyEvent(gamePadIndex, key, pressedOrUpdated); } @@ -1218,7 +1218,7 @@ namespace Components gamePad.inUse = true; gpad_in_use.setRaw(true); - if (Game::Key_IsKeyCatcherActive(gamePadIndex, Game::KEYCATCH_UI)) + if (Game::Key_IsCatcherActive(gamePadIndex, Game::KEYCATCH_UI)) CL_GamepadResetMenuScrollTime(gamePadIndex, key, buttonEvent == Game::GPAD_BUTTON_PRESSED, time); diff --git a/src/Components/Modules/UIScript.cpp b/src/Components/Modules/UIScript.cpp index 835d4682..08534954 100644 --- a/src/Components/Modules/UIScript.cpp +++ b/src/Components/Modules/UIScript.cpp @@ -9,7 +9,7 @@ namespace Components { if (this->isValid()) { - return std::atoi(this->token); + return std::strtol(this->token, nullptr, 0); } return 0; @@ -49,22 +49,22 @@ namespace Components return &Game::uiInfoArray[localClientNum]; } - void UIScript::Add(const std::string& name, const UIScript::UIScriptHandler& callback) + void UIScript::Add(const std::string& name, const UIScriptHandler& callback) { - UIScript::UIScripts[name] = callback; + UIScripts[name] = callback; } void UIScript::AddOwnerDraw(int ownerdraw, const std::function& callback) { - UIScript::UIOwnerDraws[ownerdraw] = callback; + UIOwnerDraws[ownerdraw] = callback; } bool UIScript::RunMenuScript(const char* name, const char** args) { - if (const auto itr = UIScript::UIScripts.find(name); itr != UIScript::UIScripts.end()) + if (const auto itr = UIScripts.find(name); itr != UIScripts.end()) { - const auto* info = UIScript::UI_GetClientInfo(0); - itr->second(UIScript::Token(args), info); + const auto* info = UI_GetClientInfo(0); + itr->second(Token(args), info); return true; } @@ -75,7 +75,7 @@ namespace Components { if (key == 200 || key == 201) // mouse buttons { - for (auto i = UIScript::UIOwnerDraws.begin(); i != UIScript::UIOwnerDraws.end(); ++i) + for (auto i = UIOwnerDraws.begin(); i != UIOwnerDraws.end(); ++i) { if (i->first == ownerDraw) { @@ -93,12 +93,12 @@ namespace Components { mov eax, esp add eax, 8h - mov edx, eax // UIScript name + mov edx, eax // UIScript name mov eax, [esp + 0C10h] // UIScript args push eax push edx - call UIScript::RunMenuScript + call RunMenuScript add esp, 8h test al, al @@ -116,6 +116,11 @@ namespace Components } } + bool UIScript::CL_IsUIActive_Hk(const int localClientNum) + { + return Game::Key_IsCatcherActive(localClientNum, Game::KEYCATCH_UI) || Game::cgsArray->hardcore; + } + UIScript::UIScript() { AssertSize(Game::uiInfo_s, 0x22FC); @@ -123,15 +128,17 @@ namespace Components if (Dedicated::IsEnabled()) return; // Install handler - Utils::Hook::RedirectJump(0x45EC59, UIScript::RunMenuScriptStub); + Utils::Hook::RedirectJump(0x45EC59, RunMenuScriptStub); // Install ownerdraw handler - Utils::Hook(0x63D233, UIScript::OwnerDrawHandleKeyStub, HOOK_CALL).install()->quick(); + Utils::Hook(0x63D233, OwnerDrawHandleKeyStub, HOOK_CALL).install()->quick(); + + Utils::Hook(0x62B397, CL_IsUIActive_Hk, HOOK_CALL).install()->quick(); } UIScript::~UIScript() { - UIScript::UIScripts.clear(); - UIScript::UIOwnerDraws.clear(); + UIScripts.clear(); + UIOwnerDraws.clear(); } } diff --git a/src/Components/Modules/UIScript.hpp b/src/Components/Modules/UIScript.hpp index 553e15ab..dfbe2cee 100644 --- a/src/Components/Modules/UIScript.hpp +++ b/src/Components/Modules/UIScript.hpp @@ -36,6 +36,8 @@ namespace Components static bool RunMenuScript(const char* name, const char** args); static void RunMenuScriptStub(); + static bool CL_IsUIActive_Hk(int localClientNum); + static std::unordered_map UIScripts; static std::unordered_map> UIOwnerDraws; }; diff --git a/src/Game/Client.cpp b/src/Game/Client.cpp index 4798a21c..4f440e79 100644 --- a/src/Game/Client.cpp +++ b/src/Game/Client.cpp @@ -58,4 +58,10 @@ namespace Game return cl_voiceCommunication; } + + clientUIActive_t* CL_GetLocalClientUIGlobals(const int localClientNum) + { + AssertIn(localClientNum, MAX_LOCAL_CLIENTS); + return &clientUIActives[localClientNum]; + } } diff --git a/src/Game/Client.hpp b/src/Game/Client.hpp index 834d73fa..cb3606b9 100644 --- a/src/Game/Client.hpp +++ b/src/Game/Client.hpp @@ -67,4 +67,5 @@ namespace Game extern clientConnection_t* CL_GetLocalClientConnection(int localClientNum); extern connstate_t CL_GetLocalClientConnectionState(int localClientNum); extern voiceCommunication_t* CL_GetLocalClientVoiceCommunication(int localClientNum); + extern clientUIActive_t* CL_GetLocalClientUIGlobals(int localClientNum); } diff --git a/src/Game/Functions.cpp b/src/Game/Functions.cpp index 236719c8..f776c2a6 100644 --- a/src/Game/Functions.cpp +++ b/src/Game/Functions.cpp @@ -52,7 +52,7 @@ namespace Game Key_SetCatcher_t Key_SetCatcher = Key_SetCatcher_t(0x43BD00); Key_RemoveCatcher_t Key_RemoveCatcher = Key_RemoveCatcher_t(0x408260); - Key_IsKeyCatcherActive_t Key_IsKeyCatcherActive = Key_IsKeyCatcherActive_t(0x4DA010); + Key_IsCatcherActive_t Key_IsCatcherActive = Key_IsCatcherActive_t(0x4DA010); Key_SetBinding_t Key_SetBinding = Key_SetBinding_t(0x494C90); LargeLocalInit_t LargeLocalInit = LargeLocalInit_t(0x4A62A0); diff --git a/src/Game/Functions.hpp b/src/Game/Functions.hpp index e642bd77..e307ef42 100644 --- a/src/Game/Functions.hpp +++ b/src/Game/Functions.hpp @@ -104,10 +104,10 @@ namespace Game typedef void(*Key_RemoveCatcher_t)(int localClientNum, int andMask); extern Key_RemoveCatcher_t Key_RemoveCatcher; - typedef bool(*Key_IsKeyCatcherActive_t)(int localClientNum, int catcher); - extern Key_IsKeyCatcherActive_t Key_IsKeyCatcherActive; + typedef bool(*Key_IsCatcherActive_t)(int localClientNum, int mask); + extern Key_IsCatcherActive_t Key_IsCatcherActive; - typedef void(*Key_SetBinding_t)(int localClientNum, int keyNum, const char* binding); + typedef void(*Key_SetBinding_t)(int localClientNum, int keynum, const char* binding); extern Key_SetBinding_t Key_SetBinding; typedef void(*LargeLocalInit_t)();