Move Dedicated patches related to chat to new Chat component

This commit is contained in:
Jan 2021-09-19 13:13:46 +02:00
parent fa40711ee8
commit 624daa858e
6 changed files with 104 additions and 84 deletions

View File

@ -102,6 +102,7 @@ namespace Components
Loader::Register(new StartupMessages()); Loader::Register(new StartupMessages());
Loader::Register(new SoundMutexFix()); Loader::Register(new SoundMutexFix());
Loader::Register(new Gamepad()); Loader::Register(new Gamepad());
Loader::Register(new Chat());
Loader::Register(new TextRenderer()); Loader::Register(new TextRenderer());
Loader::Register(new Client()); Loader::Register(new Client());

View File

@ -130,6 +130,7 @@ namespace Components
#include "Modules/StartupMessages.hpp" #include "Modules/StartupMessages.hpp"
#include "Modules/Stats.hpp" #include "Modules/Stats.hpp"
#include "Modules/SoundMutexFix.hpp" #include "Modules/SoundMutexFix.hpp"
#include "Modules/Chat.hpp"
#include "Modules/TextRenderer.hpp" #include "Modules/TextRenderer.hpp"
#include "Modules/Gamepad.hpp" #include "Modules/Gamepad.hpp"

View File

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

View File

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

View File

@ -4,8 +4,6 @@ namespace Components
{ {
SteamID Dedicated::PlayerGuids[18][2]; SteamID Dedicated::PlayerGuids[18][2];
bool Dedicated::SendChat;
bool Dedicated::IsEnabled() bool Dedicated::IsEnabled()
{ {
static std::optional<bool> flag; static std::optional<bool> 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() void Dedicated::TransmitGuids()
{ {
std::string list = Utils::String::VA("%c", 20); std::string list = Utils::String::VA("%c", 20);
@ -306,11 +234,6 @@ namespace Components
Dvar::Register<bool>("sv_dontrotate", false, Game::dvar_flag::DVAR_FLAG_CHEAT, ""); Dvar::Register<bool>("sv_dontrotate", false, Game::dvar_flag::DVAR_FLAG_CHEAT, "");
Dvar::Register<bool>("com_logFilter", true, Game::dvar_flag::DVAR_FLAG_LATCHED, "Removes ~95% of unneeded lines from the log"); Dvar::Register<bool>("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()) if (Dedicated::IsEnabled() || ZoneBuilder::IsEnabled())
{ {
// Make sure all callbacks are handled // Make sure all callbacks are handled

View File

@ -15,19 +15,12 @@ namespace Components
static void Heartbeat(); static void Heartbeat();
private: private:
static bool SendChat;
static void MapRotate(); static void MapRotate();
static void InitDedicatedServer(); static void InitDedicatedServer();
static void PostInitialization(); static void PostInitialization();
static void PostInitializationStub(); static void PostInitializationStub();
static const char* EvaluateSay(char* text, Game::gentity_t* player);
static void PreSayStub();
static void PostSayStub();
static void FrameStub(); static void FrameStub();
static void TransmitGuids(); static void TransmitGuids();