From cb2346b4780de6b43fbaec9256f12ee2968cd0d2 Mon Sep 17 00:00:00 2001 From: Diavolo Date: Tue, 31 May 2022 17:57:44 +0200 Subject: [PATCH] [Chat] add dvar to disable chat --- src/Components/Modules/CardTitles.cpp | 4 ++-- src/Components/Modules/Chat.cpp | 25 ++++++++++++++++++------ src/Components/Modules/Chat.hpp | 5 ++++- src/Components/Modules/Clantags.cpp | 2 +- src/Components/Modules/ClientCommand.cpp | 20 +++++++++---------- src/Components/Modules/Dedicated.cpp | 14 ++++++------- src/Game/Functions.hpp | 2 +- src/Game/Structs.hpp | 6 ++++++ 8 files changed, 50 insertions(+), 28 deletions(-) diff --git a/src/Components/Modules/CardTitles.cpp b/src/Components/Modules/CardTitles.cpp index e3ac4a5c..fdc3604e 100644 --- a/src/Components/Modules/CardTitles.cpp +++ b/src/Components/Modules/CardTitles.cpp @@ -173,8 +173,8 @@ namespace Components list.append(Utils::String::VA("\\%s\\%s", std::to_string(i).c_str(), playerTitle)); } - std::string command = Utils::String::VA("%c customTitles \"%s\"", 21, list.data()); - Game::SV_GameSendServerCommand(-1, 0, command.data()); + const auto* command = Utils::String::VA("%c customTitles \"%s\"", 21, list.data()); + Game::SV_GameSendServerCommand(-1, Game::SV_CMD_CAN_IGNORE, command); } void CardTitles::ParseCustomTitles(const char* msg) diff --git a/src/Components/Modules/Chat.cpp b/src/Components/Modules/Chat.cpp index 9979fb89..3d3789cf 100644 --- a/src/Components/Modules/Chat.cpp +++ b/src/Components/Modules/Chat.cpp @@ -2,8 +2,10 @@ namespace Components { - Game::dvar_t** Chat::cg_chatHeight = reinterpret_cast(0x7ED398); Dvar::Var Chat::cg_chatWidth; + Dvar::Var Chat::sv_disableChat; + + Game::dvar_t** Chat::cg_chatHeight = reinterpret_cast(0x7ED398); Game::dvar_t** Chat::cg_chatTime = reinterpret_cast(0x9F5DE8); bool Chat::SendChat; @@ -27,7 +29,7 @@ namespace Components { lock.unlock(); Chat::SendChat = false; - Game::SV_GameSendServerCommand(player->s.number, 0, + Game::SV_GameSendServerCommand(player->s.number, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"You are muted\"", 0x65)); } @@ -37,6 +39,13 @@ namespace Components lock.unlock(); } + if (Chat::sv_disableChat.get()) + { + Chat::SendChat = false; + Game::SV_GameSendServerCommand(player->s.number, Game::SV_CMD_CAN_IGNORE, + Utils::String::VA("%c \"Chat is disabled\"", 0x65)); + } + TextRenderer::StripMaterialTextIcons(text, text, strlen(text) + 1); Game::Scr_AddEntity(player); @@ -223,14 +232,14 @@ namespace Components lock.unlock(); Logger::Print("%s was muted\n", client->name); - Game::SV_GameSendServerCommand(client->gentity->s.number, 0, + Game::SV_GameSendServerCommand(client->gentity->s.number, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"You were muted\"", 0x65)); return; } lock.unlock(); Logger::Print("%s is already muted\n", client->name); - Game::SV_GameSendServerCommand(-1, 0, + Game::SV_GameSendServerCommand(-1, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"%s is already muted\"", 0x65, client->name)); } @@ -239,7 +248,7 @@ namespace Components Chat::UnmuteInternal(client->steamID); Logger::Print("%s was unmuted\n", client->name); - Game::SV_GameSendServerCommand(client->gentity->s.number, 0, + Game::SV_GameSendServerCommand(client->gentity->s.number, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"You were unmuted\"", 0x65)); } @@ -317,7 +326,11 @@ namespace Components { Dvar::OnInit([] { - cg_chatWidth = Dvar::Register("cg_chatWidth", 52, 1, std::numeric_limits::max(), Game::DVAR_ARCHIVE, "The normalized maximum width of a chat message"); + Chat::cg_chatWidth = Dvar::Register("cg_chatWidth", 52, 1, + std::numeric_limits::max(), Game::dvar_flag::DVAR_ARCHIVE, "The normalized maximum width of a chat message"); + Chat::sv_disableChat = Dvar::Register("sv_disableChat", false, + Game::dvar_flag::DVAR_NONE, "Disable chat messages from clients"); + Chat::AddChatCommands(); }); diff --git a/src/Components/Modules/Chat.hpp b/src/Components/Modules/Chat.hpp index 134efb37..a19469ae 100644 --- a/src/Components/Modules/Chat.hpp +++ b/src/Components/Modules/Chat.hpp @@ -9,8 +9,11 @@ namespace Components Chat(); private: - static Game::dvar_t** cg_chatHeight; static Dvar::Var cg_chatWidth; + static Dvar::Var sv_disableChat; + + // Game dvars + static Game::dvar_t** cg_chatHeight; static Game::dvar_t** cg_chatTime; static bool SendChat; diff --git a/src/Components/Modules/Clantags.cpp b/src/Components/Modules/Clantags.cpp index c23a3b62..8d127a5f 100644 --- a/src/Components/Modules/Clantags.cpp +++ b/src/Components/Modules/Clantags.cpp @@ -32,7 +32,7 @@ namespace Components } std::string command = Utils::String::VA("%c clantags \"%s\"", 22, list.data()); - Game::SV_GameSendServerCommand(-1, 0, command.data()); + Game::SV_GameSendServerCommand(-1, Game::SV_CMD_CAN_IGNORE, command.data()); } const char* ClanTags::GetUserClantag(std::uint32_t /*clientnum*/, const char* playername) diff --git a/src/Components/Modules/ClientCommand.cpp b/src/Components/Modules/ClientCommand.cpp index 7d8436da..66998e2b 100644 --- a/src/Components/Modules/ClientCommand.cpp +++ b/src/Components/Modules/ClientCommand.cpp @@ -11,14 +11,14 @@ namespace Components if (!Dvar::Var("sv_cheats").get()) { Logger::Print("CheatsOk: cheats are disabled!\n"); - Game::SV_GameSendServerCommand(entNum, 0, Utils::String::VA("%c \"GAME_CHEATSNOTENABLED\"", 0x65)); + Game::SV_GameSendServerCommand(entNum, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"GAME_CHEATSNOTENABLED\"", 0x65)); return false; } if (ent->health < 1) { Logger::Print("CheatsOk: entity %i must be alive to use this command!\n", entNum); - Game::SV_GameSendServerCommand(entNum, 0, Utils::String::VA("%c \"GAME_MUSTBEALIVECOMMAND\"", 0x65)); + Game::SV_GameSendServerCommand(entNum, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"GAME_MUSTBEALIVECOMMAND\"", 0x65)); return false; } @@ -66,7 +66,7 @@ namespace Components const auto entNum = ent->s.number; Logger::Print("Noclip toggled for entity %i\n", entNum); - Game::SV_GameSendServerCommand(entNum, 0, Utils::String::VA("%c \"%s\"", 0x65, + Game::SV_GameSendServerCommand(entNum, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"%s\"", 0x65, (ent->client->flags & Game::PLAYER_FLAG_NOCLIP) ? "GAME_NOCLIPON" : "GAME_NOCLIPOFF")); }); @@ -80,7 +80,7 @@ namespace Components const auto entNum = ent->s.number; Logger::Print("UFO toggled for entity %i\n", entNum); - Game::SV_GameSendServerCommand(entNum, 0, Utils::String::VA("%c \"%s\"", 0x65, + Game::SV_GameSendServerCommand(entNum, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"%s\"", 0x65, (ent->client->flags & Game::PLAYER_FLAG_UFO) ? "GAME_UFOON" : "GAME_UFOOFF")); }); @@ -94,7 +94,7 @@ namespace Components const auto entNum = ent->s.number; Logger::Print("God toggled for entity %i\n", entNum); - Game::SV_GameSendServerCommand(entNum, 0, Utils::String::VA("%c \"%s\"", 0x65, + Game::SV_GameSendServerCommand(entNum, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"%s\"", 0x65, (ent->flags & Game::FL_GODMODE) ? "GAME_GODMODE_ON" : "GAME_GODMODE_OFF")); }); @@ -108,7 +108,7 @@ namespace Components const auto entNum = ent->s.number; Logger::Print("Demigod toggled for entity %i\n", entNum); - Game::SV_GameSendServerCommand(entNum, 0, Utils::String::VA("%c \"%s\"", 0x65, + Game::SV_GameSendServerCommand(entNum, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"%s\"", 0x65, (ent->flags & Game::FL_DEMI_GODMODE) ? "GAME_DEMI_GODMODE_ON" : "GAME_DEMI_GODMODE_OFF")); }); @@ -122,7 +122,7 @@ namespace Components const auto entNum = ent->s.number; Logger::Print("Notarget toggled for entity %i\n", entNum); - Game::SV_GameSendServerCommand(entNum, 0, Utils::String::VA("%c \"%s\"", 0x65, + Game::SV_GameSendServerCommand(entNum, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"%s\"", 0x65, (ent->flags & Game::FL_NOTARGET) ? "GAME_NOTARGETON" : "GAME_NOTARGETOFF")); }); @@ -137,7 +137,7 @@ namespace Components if (params->size() < 4 || params->size() > 6) { - Game::SV_GameSendServerCommand(ent->s.number, 0, + Game::SV_GameSendServerCommand(ent->s.number, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"GAME_USAGE\x15: setviewpos x y z [yaw] [pitch]\n\"", 0x65)); return; } @@ -208,7 +208,7 @@ namespace Components strncpy_s(ent->client->visionName[visMode], sizeof(Game::gclient_t::visionName[0]) / sizeof(char), name, _TRUNCATE); - Game::SV_GameSendServerCommand(ent->s.number, 1, + Game::SV_GameSendServerCommand(ent->s.number, Game::SV_CMD_RELIABLE, Utils::String::VA("%c \"%s\" %i", Game::MY_CMDS[visMode], name, duration)); }); @@ -236,7 +236,7 @@ namespace Components strncpy_s(ent->client->visionName[visMode], sizeof(Game::gclient_t::visionName[0]) / sizeof(char), name, _TRUNCATE); - Game::SV_GameSendServerCommand(ent->s.number, 1, + Game::SV_GameSendServerCommand(ent->s.number, Game::SV_CMD_RELIABLE, Utils::String::VA("%c \"%s\" %i", Game::MY_CMDS[visMode], name, duration)); }); diff --git a/src/Components/Modules/Dedicated.cpp b/src/Components/Modules/Dedicated.cpp index 582bebb0..6d50b7cf 100644 --- a/src/Components/Modules/Dedicated.cpp +++ b/src/Components/Modules/Dedicated.cpp @@ -96,7 +96,7 @@ namespace Components } } - Game::SV_GameSendServerCommand(-1, 0, list.data()); + Game::SV_GameSendServerCommand(-1, Game::SV_CMD_CAN_IGNORE, list.data()); } void Dedicated::TimeWrapStub(Game::errorParm_t code, const char* message) @@ -415,12 +415,12 @@ namespace Components if (!name.empty()) { - Game::SV_GameSendServerCommand(-1, 0, Utils::String::VA("%c \"%s: %s\"", 104, name.data(), message.data())); + Game::SV_GameSendServerCommand(-1, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"%s: %s\"", 104, name.data(), message.data())); Game::Com_Printf(15, "%s: %s\n", name.data(), message.data()); } else { - Game::SV_GameSendServerCommand(-1, 0, Utils::String::VA("%c \"Console: %s\"", 104, message.data())); + Game::SV_GameSendServerCommand(-1, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"Console: %s\"", 104, message.data())); Game::Com_Printf(15, "Console: %s\n", message.data()); } }); @@ -436,12 +436,12 @@ namespace Components if (!name.empty()) { - Game::SV_GameSendServerCommand(client, 0, Utils::String::VA("%c \"%s: %s\"", 104, name.data(), message.data())); + Game::SV_GameSendServerCommand(client, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"%s: %s\"", 104, name.data(), message.data())); Game::Com_Printf(15, "%s -> %i: %s\n", name.data(), client, message.data()); } else { - Game::SV_GameSendServerCommand(client, 0, Utils::String::VA("%c \"Console: %s\"", 104, message.data())); + Game::SV_GameSendServerCommand(client, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"Console: %s\"", 104, message.data())); Game::Com_Printf(15, "Console -> %i: %s\n", client, message.data()); } }); @@ -452,7 +452,7 @@ namespace Components if (params->size() < 2) return; std::string message = params->join(1); - Game::SV_GameSendServerCommand(-1, 0, Utils::String::VA("%c \"%s\"", 104, message.data())); + Game::SV_GameSendServerCommand(-1, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"%s\"", 104, message.data())); Game::Com_Printf(15, "Raw: %s\n", message.data()); }); @@ -463,7 +463,7 @@ namespace Components int client = atoi(params->get(1)); std::string message = params->join(2); - Game::SV_GameSendServerCommand(client, 0, Utils::String::VA("%c \"%s\"", 104, message.data())); + Game::SV_GameSendServerCommand(client, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"%s\"", 104, message.data())); Game::Com_Printf(15, "Raw -> %i: %s\n", client, message.data()); }); }); diff --git a/src/Game/Functions.hpp b/src/Game/Functions.hpp index 672a6cc0..acd40682 100644 --- a/src/Game/Functions.hpp +++ b/src/Game/Functions.hpp @@ -834,7 +834,7 @@ namespace Game typedef int(__cdecl* SV_GameClientNum_Score_t)(int clientID); extern SV_GameClientNum_Score_t SV_GameClientNum_Score; - typedef void(__cdecl * SV_GameSendServerCommand_t)(int clientNum, /*svscmd_type*/int type, const char* text); + typedef void(__cdecl * SV_GameSendServerCommand_t)(int clientNum, svscmd_type type, const char* text); extern SV_GameSendServerCommand_t SV_GameSendServerCommand; typedef void(__cdecl * SV_Cmd_TokenizeString_t)(const char* string); diff --git a/src/Game/Structs.hpp b/src/Game/Structs.hpp index ec9595e3..a5ccaf19 100644 --- a/src/Game/Structs.hpp +++ b/src/Game/Structs.hpp @@ -336,6 +336,12 @@ namespace Game HITLOC_NUM } hitLocation_t; + enum svscmd_type + { + SV_CMD_CAN_IGNORE = 0x0, + SV_CMD_RELIABLE = 0x1, + }; + struct FxEffectDef; struct pathnode_t; struct pathnode_tree_t;