From 624daa858ef9a4ee5050b65b39a1ac29b9048706 Mon Sep 17 00:00:00 2001 From: Jan Date: Sun, 19 Sep 2021 13:13:46 +0200 Subject: [PATCH] Move Dedicated patches related to chat to new Chat component --- src/Components/Loader.cpp | 1 + src/Components/Loader.hpp | 1 + src/Components/Modules/Chat.cpp | 84 ++++++++++++++++++++++++++++ src/Components/Modules/Chat.hpp | 18 ++++++ src/Components/Modules/Dedicated.cpp | 77 ------------------------- src/Components/Modules/Dedicated.hpp | 7 --- 6 files changed, 104 insertions(+), 84 deletions(-) create mode 100644 src/Components/Modules/Chat.cpp create mode 100644 src/Components/Modules/Chat.hpp diff --git a/src/Components/Loader.cpp b/src/Components/Loader.cpp index a574c7f9..7b76cb02 100644 --- a/src/Components/Loader.cpp +++ b/src/Components/Loader.cpp @@ -102,6 +102,7 @@ namespace Components Loader::Register(new StartupMessages()); Loader::Register(new SoundMutexFix()); Loader::Register(new Gamepad()); + Loader::Register(new Chat()); Loader::Register(new TextRenderer()); Loader::Register(new Client()); diff --git a/src/Components/Loader.hpp b/src/Components/Loader.hpp index 27883be7..2265b729 100644 --- a/src/Components/Loader.hpp +++ b/src/Components/Loader.hpp @@ -130,6 +130,7 @@ namespace Components #include "Modules/StartupMessages.hpp" #include "Modules/Stats.hpp" #include "Modules/SoundMutexFix.hpp" +#include "Modules/Chat.hpp" #include "Modules/TextRenderer.hpp" #include "Modules/Gamepad.hpp" diff --git a/src/Components/Modules/Chat.cpp b/src/Components/Modules/Chat.cpp new file mode 100644 index 00000000..e4c5ce44 --- /dev/null +++ b/src/Components/Modules/Chat.cpp @@ -0,0 +1,84 @@ +#include "STDInclude.hpp" + +namespace Components +{ + bool Chat::SendChat; + + const char* Chat::EvaluateSay(char* text, Game::gentity_t* player) + { + SendChat = true; + + if (text[1] == '/') + { + SendChat = false; + text[1] = text[0]; + ++text; + } + + TextRenderer::StripMaterialTextIcons(text, text, strlen(text) + 1); + + Game::Scr_AddEntity(player); + Game::Scr_AddString(text + 1); + Game::Scr_NotifyLevel(Game::SL_GetString("say", 0), 2); + + return text; + } + + __declspec(naked) void Chat::PreSayStub() + { + __asm + { + mov eax, [esp + 100h + 10h] + + push eax + pushad + + push[esp + 100h + 28h] + push eax + call Chat::EvaluateSay + add esp, 8h + + mov[esp + 20h], eax + popad + pop eax + + mov[esp + 100h + 10h], eax + + jmp PlayerName::CleanStrStub + } + } + + __declspec(naked) void Chat::PostSayStub() + { + __asm + { + // eax is used by the callee + push eax + + xor eax, eax + mov al, Chat::SendChat + + test al, al + jnz return + + // Don't send the chat + pop eax + retn + + return: + pop eax + + // Jump to the target + push 5DF620h + retn + } + } + + Chat::Chat() + { + // Intercept chat sending + Utils::Hook(0x4D000B, PreSayStub, HOOK_CALL).install()->quick(); + Utils::Hook(0x4D00D4, PostSayStub, HOOK_CALL).install()->quick(); + Utils::Hook(0x4D0110, PostSayStub, HOOK_CALL).install()->quick(); + } +} diff --git a/src/Components/Modules/Chat.hpp b/src/Components/Modules/Chat.hpp new file mode 100644 index 00000000..9d76a710 --- /dev/null +++ b/src/Components/Modules/Chat.hpp @@ -0,0 +1,18 @@ +#pragma once + +namespace Components +{ + class Chat : public Component + { + public: + Chat(); + + private: + static bool SendChat; + + static const char* EvaluateSay(char* text, Game::gentity_t* player); + + static void PreSayStub(); + static void PostSayStub(); + }; +} diff --git a/src/Components/Modules/Dedicated.cpp b/src/Components/Modules/Dedicated.cpp index 12dc27b6..7ff6330c 100644 --- a/src/Components/Modules/Dedicated.cpp +++ b/src/Components/Modules/Dedicated.cpp @@ -4,8 +4,6 @@ namespace Components { SteamID Dedicated::PlayerGuids[18][2]; - bool Dedicated::SendChat; - bool Dedicated::IsEnabled() { static std::optional flag; @@ -76,76 +74,6 @@ namespace Components } } - const char* Dedicated::EvaluateSay(char* text, Game::gentity_t* player) - { - Dedicated::SendChat = true; - - if (text[1] == '/') - { - Dedicated::SendChat = false; - text[1] = text[0]; - ++text; - } - - TextRenderer::StripMaterialTextIcons(text, text, strlen(text) + 1); - - Game::Scr_AddEntity(player); - Game::Scr_AddString(text + 1); - Game::Scr_NotifyLevel(Game::SL_GetString("say", 0), 2); - - return text; - } - - __declspec(naked) void Dedicated::PreSayStub() - { - __asm - { - mov eax, [esp + 100h + 10h] - - push eax - pushad - - push [esp + 100h + 28h] - push eax - call Dedicated::EvaluateSay - add esp, 8h - - mov [esp + 20h], eax - popad - pop eax - - mov [esp + 100h + 10h], eax - - jmp PlayerName::CleanStrStub - } - } - - __declspec(naked) void Dedicated::PostSayStub() - { - __asm - { - // eax is used by the callee - push eax - - xor eax, eax - mov al, Dedicated::SendChat - - test al, al - jnz return - - // Don't send the chat - pop eax - retn - - return: - pop eax - - // Jump to the target - push 5DF620h - retn - } - } - void Dedicated::TransmitGuids() { std::string list = Utils::String::VA("%c", 20); @@ -306,11 +234,6 @@ namespace Components Dvar::Register("sv_dontrotate", false, Game::dvar_flag::DVAR_FLAG_CHEAT, ""); Dvar::Register("com_logFilter", true, Game::dvar_flag::DVAR_FLAG_LATCHED, "Removes ~95% of unneeded lines from the log"); - // Intercept chat sending - Utils::Hook(0x4D000B, Dedicated::PreSayStub, HOOK_CALL).install()->quick(); - Utils::Hook(0x4D00D4, Dedicated::PostSayStub, HOOK_CALL).install()->quick(); - Utils::Hook(0x4D0110, Dedicated::PostSayStub, HOOK_CALL).install()->quick(); - if (Dedicated::IsEnabled() || ZoneBuilder::IsEnabled()) { // Make sure all callbacks are handled diff --git a/src/Components/Modules/Dedicated.hpp b/src/Components/Modules/Dedicated.hpp index 002d28bb..162e1a8f 100644 --- a/src/Components/Modules/Dedicated.hpp +++ b/src/Components/Modules/Dedicated.hpp @@ -15,19 +15,12 @@ namespace Components static void Heartbeat(); private: - static bool SendChat; - static void MapRotate(); static void InitDedicatedServer(); static void PostInitialization(); static void PostInitializationStub(); - static const char* EvaluateSay(char* text, Game::gentity_t* player); - - static void PreSayStub(); - static void PostSayStub(); - static void FrameStub(); static void TransmitGuids();