From def50477fb105acb68d8fb7b9a212ea20c5f12ed Mon Sep 17 00:00:00 2001 From: Edo Date: Sat, 27 Aug 2022 23:19:09 +0200 Subject: [PATCH] [Chat] Move chat commands here (#462) * [Chat] Move chat commands here * [General] Rename Cbuf_AddServerText to Cbuf_AddServerText_f --- src/Components/Modules/Chat.cpp | 61 ++++++++++++++++++++++++ src/Components/Modules/Chat.hpp | 1 + src/Components/Modules/Command.cpp | 2 +- src/Components/Modules/Debug.cpp | 8 +++- src/Components/Modules/Debug.hpp | 1 + src/Components/Modules/Dedicated.cpp | 68 --------------------------- src/Components/Modules/Dedicated.hpp | 2 - src/Components/Modules/Menus.cpp | 5 ++ src/Components/Modules/QuickPatch.cpp | 3 -- src/Game/Functions.cpp | 2 +- src/Game/Functions.hpp | 4 +- 11 files changed, 79 insertions(+), 78 deletions(-) diff --git a/src/Components/Modules/Chat.cpp b/src/Components/Modules/Chat.cpp index 7d75f277..45ee250c 100644 --- a/src/Components/Modules/Chat.cpp +++ b/src/Components/Modules/Chat.cpp @@ -5,6 +5,7 @@ namespace Components { Dvar::Var Chat::cg_chatWidth; Dvar::Var Chat::sv_disableChat; + Dvar::Var Chat::sv_sayName; Game::dvar_t** Chat::cg_chatHeight = reinterpret_cast(0x7ED398); Game::dvar_t** Chat::cg_chatTime = reinterpret_cast(0x9F5DE8); @@ -341,6 +342,66 @@ namespace Components UnmuteInternal(steamId); } }); + + Command::AddSV("say", [](Command::Params* params) + { + if (params->size() < 2) return; + + auto message = params->join(1); + auto name = sv_sayName.get(); + + if (!name.empty()) + { + Game::SV_GameSendServerCommand(-1, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"%s: %s\"", 0x68, name.data(), message.data())); + Logger::Print(Game::CON_CHANNEL_SERVER, "{}: {}\n", name, message); + } + else + { + Game::SV_GameSendServerCommand(-1, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"Console: %s\"", 0x68, message.data())); + Logger::Print(Game::CON_CHANNEL_SERVER, "Console: {}\n", message); + } + }); + + Command::AddSV("tell", [](Command::Params* params) + { + if (params->size() < 3) return; + + const auto client = std::atoi(params->get(1)); + auto message = params->join(2); + auto name = sv_sayName.get(); + + if (!name.empty()) + { + Game::SV_GameSendServerCommand(client, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"%s: %s\"", 0x68, name.data(), message.data())); + Logger::Print(Game::CON_CHANNEL_SERVER, "{} -> {}: {}\n", name, client, message); + } + else + { + Game::SV_GameSendServerCommand(client, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"Console: %s\"", 104, message.data())); + Logger::Print(Game::CON_CHANNEL_SERVER, "Console -> {}: {}\n", client, message); + } + }); + + Command::AddSV("sayraw", [](Command::Params* params) + { + if (params->size() < 2) return; + + auto message = params->join(1); + Game::SV_GameSendServerCommand(-1, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"%s\"", 0x68, message.data())); + Logger::Print(Game::CON_CHANNEL_SERVER, "Raw: {}\n", message); + }); + + Command::AddSV("tellraw", [](Command::Params* params) + { + if (params->size() < 3) return; + + const auto client = atoi(params->get(1)); + std::string message = params->join(2); + Game::SV_GameSendServerCommand(client, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"%s\"", 0x68, message.data())); + Logger::Print(Game::CON_CHANNEL_SERVER, "Raw -> {}: {}\n", client, message); + }); + + sv_sayName = Dvar::Register("sv_sayName", "^7Console", Game::DVAR_NONE, "The alias of the server when broadcasting a chat message"); } int Chat::GetCallbackReturn() diff --git a/src/Components/Modules/Chat.hpp b/src/Components/Modules/Chat.hpp index dc6b38fa..55a37738 100644 --- a/src/Components/Modules/Chat.hpp +++ b/src/Components/Modules/Chat.hpp @@ -11,6 +11,7 @@ namespace Components private: static Dvar::Var cg_chatWidth; static Dvar::Var sv_disableChat; + static Dvar::Var sv_sayName; // Game dvars static Game::dvar_t** cg_chatHeight; diff --git a/src/Components/Modules/Command.cpp b/src/Components/Modules/Command.cpp index fd5e2fe3..af2327e6 100644 --- a/src/Components/Modules/Command.cpp +++ b/src/Components/Modules/Command.cpp @@ -113,7 +113,7 @@ namespace Components Game::Cmd_AddServerCommand(name, callback, Command::Allocate()); // If the main command is registered as Cbuf_AddServerText, the command will be redirected to the SV handler - Command::AddRaw(name, Game::Cbuf_AddServerText, false); + Command::AddRaw(name, Game::Cbuf_AddServerText_f, false); } void Command::Execute(std::string command, bool sync) diff --git a/src/Components/Modules/Debug.cpp b/src/Components/Modules/Debug.cpp index 34411f98..a14983c5 100644 --- a/src/Components/Modules/Debug.cpp +++ b/src/Components/Modules/Debug.cpp @@ -261,7 +261,12 @@ namespace Components void Debug::Com_Assert_f() { - assert(("a", false)); + assert(0 && "a"); + } + + void Debug::Cbuf_AddServerText_f_Hk() + { + assert(0 && "Cbuf_AddServerText_f was called."); } void Debug::Com_Bug_f(Command::Params* params) @@ -336,6 +341,7 @@ namespace Components Utils::Hook(0x49CB0A, CG_DrawDebugOverlays_Hk, HOOK_JUMP).install()->quick(); Utils::Hook::Set(0x60BCEA, Com_Assert_f); + Utils::Hook(Game::Cbuf_AddServerText_f, Cbuf_AddServerText_f_Hk, HOOK_JUMP).install()->quick(); #ifdef _DEBUG Command::Add("bug", Com_Bug_f); diff --git a/src/Components/Modules/Debug.hpp b/src/Components/Modules/Debug.hpp index 3eaf8a78..3989f420 100644 --- a/src/Components/Modules/Debug.hpp +++ b/src/Components/Modules/Debug.hpp @@ -42,6 +42,7 @@ namespace Components static void CG_DrawDebugOverlays_Hk(int localClientNum); static void Com_Assert_f(); + static void Cbuf_AddServerText_f_Hk(); static void Com_Bug_f(Command::Params* params); static void CL_InitDebugDvars(); diff --git a/src/Components/Modules/Dedicated.cpp b/src/Components/Modules/Dedicated.cpp index b8bc3e11..5a06bb6b 100644 --- a/src/Components/Modules/Dedicated.cpp +++ b/src/Components/Modules/Dedicated.cpp @@ -138,71 +138,6 @@ namespace Components return Game::Dvar_RegisterInt(dvarName, 1000, min, 1000, Game::DVAR_NONE, description); } - void Dedicated::AddDedicatedCommands() - { - // Say command - Command::AddSV("say", [](Command::Params* params) - { - if (params->size() < 2) return; - - auto message = params->join(1); - auto name = Dvar::Var("sv_sayName").get(); - - if (!name.empty()) - { - Game::SV_GameSendServerCommand(-1, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"%s: %s\"", 104, name.data(), message.data())); - Logger::Print(Game::CON_CHANNEL_SERVER, "{}: {}\n", name, message); - } - else - { - Game::SV_GameSendServerCommand(-1, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"Console: %s\"", 104, message.data())); - Logger::Print(Game::CON_CHANNEL_SERVER, "Console: {}\n", message); - } - }); - - // Tell command - Command::AddSV("tell", [](Command::Params* params) - { - if (params->size() < 3) return; - - const auto client = atoi(params->get(1)); - auto message = params->join(2); - auto name = Dvar::Var("sv_sayName").get(); - - if (!name.empty()) - { - Game::SV_GameSendServerCommand(client, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"%s: %s\"", 104, name.data(), message.data())); - Logger::Print(Game::CON_CHANNEL_SERVER, "{} -> {}: {}\n", name, client, message); - } - else - { - Game::SV_GameSendServerCommand(client, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"Console: %s\"", 104, message.data())); - Logger::Print(Game::CON_CHANNEL_SERVER, "Console -> {}: {}\n", client, message); - } - }); - - // Sayraw command - Command::AddSV("sayraw", [](Command::Params* params) - { - if (params->size() < 2) return; - - auto message = params->join(1); - Game::SV_GameSendServerCommand(-1, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"%s\"", 104, message.data())); - Logger::Print(Game::CON_CHANNEL_SERVER, "Raw: {}\n", message); - }); - - // Tellraw command - Command::AddSV("tellraw", [](Command::Params* params) - { - if (params->size() < 3) return; - - const auto client = atoi(params->get(1)); - std::string message = params->join(2); - Game::SV_GameSendServerCommand(client, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"%s\"", 104, message.data())); - Logger::Print(Game::CON_CHANNEL_SERVER, "Raw -> {}: {}\n", client, message); - }); - } - Dedicated::Dedicated() { Dedicated::COMLogFilter = Dvar::Register("com_logFilter", true, @@ -281,12 +216,9 @@ namespace Components { Scheduler::Once([] { - Dvar::Register("sv_sayName", "^7Console", Game::DVAR_NONE, "The name to pose as for 'say' commands"); Dvar::Register("sv_motd", "", Game::DVAR_NONE, "A custom message of the day for servers"); }, Scheduler::Pipeline::MAIN); - Events::OnSVInit(Dedicated::AddDedicatedCommands); - // Post initialization point Utils::Hook(0x60BFBF, Dedicated::PostInitializationStub, HOOK_JUMP).install()->quick(); diff --git a/src/Components/Modules/Dedicated.hpp b/src/Components/Modules/Dedicated.hpp index ce4d0f43..d76d0f0a 100644 --- a/src/Components/Modules/Dedicated.hpp +++ b/src/Components/Modules/Dedicated.hpp @@ -26,7 +26,5 @@ namespace Components static void TimeWrapStub(Game::errorParm_t code, const char* message); static Game::dvar_t* Dvar_RegisterSVNetworkFps(const char* dvarName, int value, int min, int max, int flags, const char* description); - - static void AddDedicatedCommands(); }; } diff --git a/src/Components/Modules/Menus.cpp b/src/Components/Modules/Menus.cpp index ef726aed..ed403a63 100644 --- a/src/Components/Modules/Menus.cpp +++ b/src/Components/Modules/Menus.cpp @@ -859,6 +859,11 @@ namespace Components Menus::Add("ui_mp/resetclass.menu"); Menus::Add("ui_mp/popup_customtitle.menu"); Menus::Add("ui_mp/popup_customclan.menu"); + + Menus::Add("ui_mp/scriptmenus/callvote.menu"); + Menus::Add("ui_mp/scriptmenus/changegametype.menu"); + Menus::Add("ui_mp/scriptmenus/changemap.menu"); + Menus::Add("ui_mp/scriptmenus/kickplayer.menu"); } Menus::~Menus() diff --git a/src/Components/Modules/QuickPatch.cpp b/src/Components/Modules/QuickPatch.cpp index 2a472e84..4d7d7971 100644 --- a/src/Components/Modules/QuickPatch.cpp +++ b/src/Components/Modules/QuickPatch.cpp @@ -565,9 +565,6 @@ namespace Components } }); - // Ignore call to print 'Offhand class mismatch when giving weapon...' - Utils::Hook(0x5D9047, 0x4BB9B0, HOOK_CALL).install()->quick(); - Command::Add("unlockstats", QuickPatch::UnlockStats); Command::Add("dumptechsets", [](Command::Params* param) diff --git a/src/Game/Functions.cpp b/src/Game/Functions.cpp index 3cf775ab..56ce77eb 100644 --- a/src/Game/Functions.cpp +++ b/src/Game/Functions.cpp @@ -5,7 +5,7 @@ namespace Game { AngleVectors_t AngleVectors = AngleVectors_t(0x4691A0); - Cbuf_AddServerText_t Cbuf_AddServerText = Cbuf_AddServerText_t(0x4BB9B0); + Cbuf_AddServerText_f_t Cbuf_AddServerText_f = Cbuf_AddServerText_f_t(0x4BB9B0); Cbuf_AddText_t Cbuf_AddText = Cbuf_AddText_t(0x404B20); Cbuf_InsertText_t Cbuf_InsertText = Cbuf_InsertText_t(0x4940B0); diff --git a/src/Game/Functions.hpp b/src/Game/Functions.hpp index f2c1bc0f..d8f35765 100644 --- a/src/Game/Functions.hpp +++ b/src/Game/Functions.hpp @@ -6,8 +6,8 @@ namespace Game typedef void(*AngleVectors_t)(float* angles, float* forward, float* right, float* up); extern AngleVectors_t AngleVectors; - typedef void(*Cbuf_AddServerText_t)(); - extern Cbuf_AddServerText_t Cbuf_AddServerText; + typedef void(*Cbuf_AddServerText_f_t)(); + extern Cbuf_AddServerText_f_t Cbuf_AddServerText_f; typedef void(*Cbuf_AddText_t)(int localClientNum, const char* text); extern Cbuf_AddText_t Cbuf_AddText;