Merge pull request #608 from diamante0018/develop

[General]: Correct function definition
This commit is contained in:
Edo 2022-11-28 22:14:05 +00:00 committed by GitHub
commit 9689682432
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 41 additions and 27 deletions

View File

@ -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);

View File

@ -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<int>();
const int scrollDelayRest = gpad_menu_scroll_delay_rest.get<int>();
@ -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);

View File

@ -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<void()>& 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();
}
}

View File

@ -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<std::string, UIScriptHandler> UIScripts;
static std::unordered_map<int, std::function<void()>> UIOwnerDraws;
};

View File

@ -58,4 +58,10 @@ namespace Game
return cl_voiceCommunication;
}
clientUIActive_t* CL_GetLocalClientUIGlobals(const int localClientNum)
{
AssertIn(localClientNum, MAX_LOCAL_CLIENTS);
return &clientUIActives[localClientNum];
}
}

View File

@ -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);
}

View File

@ -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);

View File

@ -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)();