diff --git a/src/Components/Modules/Dedicated.cpp b/src/Components/Modules/Dedicated.cpp index c2716002..9caea934 100644 --- a/src/Components/Modules/Dedicated.cpp +++ b/src/Components/Modules/Dedicated.cpp @@ -116,7 +116,7 @@ namespace Components mov [esp + 100h + 10h], eax - jmp TextRenderer::CleanStrStub + jmp PlayerName::CleanStrStub } } diff --git a/src/Components/Modules/PlayerName.cpp b/src/Components/Modules/PlayerName.cpp index 896853ee..79b3758d 100644 --- a/src/Components/Modules/PlayerName.cpp +++ b/src/Components/Modules/PlayerName.cpp @@ -2,37 +2,77 @@ namespace Components { - std::string PlayerName::PlayerNames[18]; + Dvar::Var PlayerName::sv_allowColoredNames; - int PlayerName::GetClientName(int /*localClientNum*/, int index, char *buf, int size) + void PlayerName::UserInfoCopy(char* buffer, const char* name, const size_t size) + { + if (!sv_allowColoredNames.get()) + { + char nameBuffer[64] = { 0 }; + TextRenderer::StripColors(name, nameBuffer, sizeof(nameBuffer)); + TextRenderer::StripAllTextIcons(nameBuffer, buffer, size); + } + else + { + TextRenderer::StripAllTextIcons(name, buffer, size); + } + + std::string readablePlayerName(buffer); + readablePlayerName = Utils::String::Trim(readablePlayerName); + + if (readablePlayerName.size() < 3) + { + strncpy(buffer, "Unknown Soldier", size); + } + } + + __declspec(naked) void PlayerName::ClientUserinfoChanged() + { + __asm + { + mov eax, [esp + 4h] // length + //sub eax, 1 + push eax + + push ecx // name + push edx // buffer + + call UserInfoCopy + + add esp, 0Ch + retn + } + } + + char* PlayerName::GetClientName(int localClientNum, int index, char* buf, size_t size) + { + Game::CL_GetClientName(localClientNum, index, buf, size); + + // Append clantag to username & remove the colors + strncpy_s(buf, size, TextRenderer::StripColors(ClanTags::GetUserClantag(index, buf)).data(), size); + + return buf; + } + char* PlayerName::CleanStrStub(char* string) { - if (index < 0 || index >= 18) return 0; - return strncpy_s(buf, size, PlayerName::PlayerNames[index].data(), PlayerName::PlayerNames[index].size()) == 0; + TextRenderer::StripColors(string, string, strlen(string) + 1); + return string; } PlayerName::PlayerName() { -#if(0) // Disabled for now - { - for (int i = 0; i < ARRAYSIZE(PlayerName::PlayerNames); ++i) - { - PlayerName::PlayerNames[i] = "mumu"; - } + sv_allowColoredNames = Dvar::Register("sv_allowColoredNames", true, Game::dvar_flag::DVAR_FLAG_NONE, "Allow colored names on the server"); - Utils::Hook(Game::CL_GetClientName, PlayerName::GetClientName, HOOK_JUMP).install()->quick(); - } -#endif + // Disable SV_UpdateUserinfo_f, to block changing the name ingame + Utils::Hook::Set(0x6258D0, 0xC3); - //const char* clanname = "ZOB"; - //Utils::Hook::Set(0x497656, clanname); - //Utils::Hook::Set(0x497679, clanname); - } + // Allow colored names ingame + Utils::Hook(0x5D8B40, ClientUserinfoChanged, HOOK_JUMP).install()->quick(); - PlayerName::~PlayerName() - { - for (int i = 0; i < ARRAYSIZE(PlayerName::PlayerNames); ++i) - { - PlayerName::PlayerNames[i].clear(); - } + // Though, don't apply that to overhead names. + Utils::Hook(0x581932, GetClientName, HOOK_CALL).install()->quick(); + + // Patch I_CleanStr + Utils::Hook(0x4AD470, CleanStrStub, HOOK_JUMP).install()->quick(); } } diff --git a/src/Components/Modules/PlayerName.hpp b/src/Components/Modules/PlayerName.hpp index 68c3c74d..8335afda 100644 --- a/src/Components/Modules/PlayerName.hpp +++ b/src/Components/Modules/PlayerName.hpp @@ -6,11 +6,14 @@ namespace Components { public: PlayerName(); - ~PlayerName(); + + static void UserInfoCopy(char* buffer, const char* name, size_t size); private: - static std::string PlayerNames[18]; + static Dvar::Var sv_allowColoredNames; - static int GetClientName(int localClientNum, int index, char *buf, int size); + static char* CleanStrStub(char* string); + static void ClientUserinfoChanged(); + static char* GetClientName(int localClientNum, int index, char* buf, size_t size); }; } diff --git a/src/Components/Modules/TextRenderer.cpp b/src/Components/Modules/TextRenderer.cpp index eda8ee13..80022711 100644 --- a/src/Components/Modules/TextRenderer.cpp +++ b/src/Components/Modules/TextRenderer.cpp @@ -38,7 +38,6 @@ namespace Components Dvar::Var TextRenderer::cg_newColors; Game::dvar_t* TextRenderer::sv_customTextColor; - Dvar::Var TextRenderer::sv_allowColoredNames; Dvar::Var TextRenderer::r_colorBlind; Game::dvar_t* TextRenderer::g_ColorBlind_MyTeam; Game::dvar_t* TextRenderer::g_ColorBlind_EnemyTeam; @@ -786,56 +785,6 @@ namespace Components return std::string(buffer); } - void TextRenderer::UserInfoCopy(char* buffer, const char* name, const size_t size) - { - if (!sv_allowColoredNames.get()) - { - char nameBuffer[64] = {0}; - StripColors(name, nameBuffer, sizeof(nameBuffer)); - StripAllTextIcons(nameBuffer, buffer, size); - } - else - { - StripAllTextIcons(name, buffer, size); - } - - std::string readablePlayerName(buffer); - readablePlayerName = Utils::String::Trim(readablePlayerName); - - if(readablePlayerName.size() < 3) - { - strncpy(buffer, "Unknown Soldier", size); - } - } - - __declspec(naked) void TextRenderer::ClientUserinfoChanged() - { - __asm - { - mov eax, [esp + 4h] // length - //sub eax, 1 - push eax - - push ecx // name - push edx // buffer - - call UserInfoCopy - - add esp, 0Ch - retn - } - } - - char* TextRenderer::GetClientName(int localClientNum, int index, char* buf, size_t size) - { - Game::CL_GetClientName(localClientNum, index, buf, size); - - // Append clantag to username & remove the colors - strncpy_s(buf, size, StripColors(ClanTags::GetUserClantag(index, buf)).data(), size); - - return buf; - } - void TextRenderer::PatchColorLimit(const char limit) { Utils::Hook::Set(0x535629, limit); // DrawText2d @@ -853,12 +802,6 @@ namespace Components Utils::Hook::Set(0x5A2733, static_cast(ColorIndexForChar(limit))); // No idea :P } - char* TextRenderer::CleanStrStub(char* string) - { - StripColors(string, string, strlen(string) + 1); - return string; - } - // Patches team overhead normally bool TextRenderer::Dvar_GetUnpackedColorByName(const char* name, float* expandedColor) { @@ -931,7 +874,6 @@ namespace Components cg_newColors = Dvar::Register("cg_newColors", true, Game::dvar_flag::DVAR_FLAG_SAVED, "Use Warfare 2 color code style."); sv_customTextColor = Game::Dvar_RegisterColor("sv_customTextColor", 1, 0.7f, 0, 1, Game::dvar_flag::DVAR_FLAG_REPLICATED, "Color for the extended color code."); - sv_allowColoredNames = Dvar::Register("sv_allowColoredNames", true, Game::dvar_flag::DVAR_FLAG_NONE, "Allow colored names on the server"); // Replace vanilla text drawing function with a reimplementation with extensions Utils::Hook(0x535410, DrawText2D, HOOK_JUMP).install()->quick(); @@ -952,18 +894,6 @@ namespace Components // Replace team colors with colorblind team colors when colorblind is enabled Utils::Hook(0x406530, GetUnpackedColorByNameStub, HOOK_JUMP).install()->quick(); - // Disable SV_UpdateUserinfo_f, to block changing the name ingame - Utils::Hook::Set(0x6258D0, 0xC3); - - // Allow colored names ingame - Utils::Hook(0x5D8B40, ClientUserinfoChanged, HOOK_JUMP).install()->quick(); - - // Though, don't apply that to overhead names. - Utils::Hook(0x581932, GetClientName, HOOK_CALL).install()->quick(); - - // Patch I_CleanStr - Utils::Hook(0x4AD470, CleanStrStub, HOOK_JUMP).install()->quick(); - PatchColorLimit(COLOR_LAST_CHAR); } } \ No newline at end of file diff --git a/src/Components/Modules/TextRenderer.hpp b/src/Components/Modules/TextRenderer.hpp index 84f4e818..619150d1 100644 --- a/src/Components/Modules/TextRenderer.hpp +++ b/src/Components/Modules/TextRenderer.hpp @@ -74,7 +74,6 @@ namespace Components static Dvar::Var cg_newColors; static Game::dvar_t* sv_customTextColor; - static Dvar::Var sv_allowColoredNames; static Dvar::Var r_colorBlind; static Game::dvar_t* g_ColorBlind_MyTeam; static Game::dvar_t* g_ColorBlind_EnemyTeam; @@ -89,17 +88,13 @@ namespace Components static std::string StripMaterialTextIcons(const std::string& in); static void StripAllTextIcons(const char* in, char* out, size_t max); static std::string StripAllTextIcons(const std::string& in); - static void UserInfoCopy(char* buffer, const char* name, size_t size); TextRenderer(); private: static unsigned HsvToRgb(HsvColor hsv); - static void ClientUserinfoChanged(); - static char* GetClientName(int localClientNum, int index, char* buf, size_t size); static void PatchColorLimit(char limit); - static char* CleanStrStub(char* string); static bool Dvar_GetUnpackedColorByName(const char* name, float* expandedColor); static void GetUnpackedColorByNameStub();