#include "STDInclude.hpp" namespace Components { Dvar::Var Colors::NewColors; void Colors::Strip(const char* in, char* out, int max) { if (!in || !out) return; max--; int current = 0; while (*in != 0 && current < max) { if (!Q_IsColorString(in)) { *out = *in; out++; current++; } else { in++; } in++; } *out = '\0'; } std::string Colors::Strip(std::string in) { char buffer[1000] = { 0 }; // Should be more than enough Colors::Strip(in.data(), buffer, sizeof(buffer)); return std::string(buffer); } void __declspec(naked) Colors::ClientUserinfoChanged(int length) { __asm { mov eax, [esp + 4h] // length sub eax, 1 push eax push ecx // name push edx // buffer call strncpy add esp, 0Ch retn } } char* Colors::GetClientName(int localClientNum, int index, char *buf, size_t size) { Game::CL_GetClientName(localClientNum, index, buf, size); // Remove the colors strncpy(buf, Colors::Strip(buf).data(), size); return buf; } void Colors::UpdateColorTable() { static int LastState = 2; static DWORD DefaultTable[8] = { 0 }; DWORD* gColorTable = (DWORD*)0x78DC70; if (LastState == 2) { memcpy(DefaultTable, gColorTable, sizeof(DefaultTable)); } if (Colors::NewColors.Get() && (0xF & static_cast(Colors::NewColors.Get())) != LastState) { // Apply NTA's W² colors :3 (slightly modified though^^) gColorTable[1] = RGB(255, 49, 49); gColorTable[2] = RGB(134, 192, 0); gColorTable[3] = RGB(255, 173, 34); gColorTable[4] = RGB(0, 135, 193); gColorTable[5] = RGB(32, 197, 255); gColorTable[6] = RGB(151, 80, 221); LastState = Colors::NewColors.Get(); } else if (!Colors::NewColors.Get() && (0xF & static_cast(Colors::NewColors.Get())) != LastState) { memcpy(gColorTable, DefaultTable, sizeof(DefaultTable)); LastState = Colors::NewColors.Get(); } } Colors::Colors() { // Allow colored names ingame Utils::Hook(0x5D8B40, Colors::ClientUserinfoChanged, HOOK_JUMP).Install()->Quick(); // Though, don't apply that to overhead names. Utils::Hook(0x581932, Colors::GetClientName, HOOK_CALL).Install()->Quick(); // Set frame handler Renderer::OnFrame(Colors::UpdateColorTable); // Register dvar Colors::NewColors = Dvar::Register("cg_newColors", true, Game::dvar_flag::DVAR_FLAG_SAVED, "Use Warfare² color code style."); } }