Move playername related patches from TextRenderer to PlayerName component
This commit is contained in:
parent
1821d9072e
commit
26f2403418
@ -116,7 +116,7 @@ namespace Components
|
||||
|
||||
mov [esp + 100h + 10h], eax
|
||||
|
||||
jmp TextRenderer::CleanStrStub
|
||||
jmp PlayerName::CleanStrStub
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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 (index < 0 || index >= 18) return 0;
|
||||
return strncpy_s(buf, size, PlayerName::PlayerNames[index].data(), PlayerName::PlayerNames[index].size()) == 0;
|
||||
if (!sv_allowColoredNames.get<bool>())
|
||||
{
|
||||
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)
|
||||
{
|
||||
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<bool>("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<BYTE>(0x6258D0, 0xC3);
|
||||
|
||||
//const char* clanname = "ZOB";
|
||||
//Utils::Hook::Set<const char*>(0x497656, clanname);
|
||||
//Utils::Hook::Set<const char*>(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();
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
};
|
||||
}
|
||||
|
@ -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<bool>())
|
||||
{
|
||||
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<char>(0x535629, limit); // DrawText2d
|
||||
@ -853,12 +802,6 @@ namespace Components
|
||||
Utils::Hook::Set<char>(0x5A2733, static_cast<char>(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<bool>("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<bool>("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<BYTE>(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);
|
||||
}
|
||||
}
|
@ -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();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user