2016-01-04 14:58:00 -05:00
|
|
|
|
#include "STDInclude.hpp"
|
2015-12-23 08:45:53 -05:00
|
|
|
|
|
|
|
|
|
namespace Components
|
|
|
|
|
{
|
2015-12-23 10:56:02 -05:00
|
|
|
|
Dvar::Var Colors::NewColors;
|
|
|
|
|
|
2015-12-23 08:45:53 -05:00
|
|
|
|
void Colors::Strip(const char* in, char* out, int max)
|
|
|
|
|
{
|
2015-12-30 16:22:24 -05:00
|
|
|
|
if (!in || !out) return;
|
|
|
|
|
|
2015-12-23 08:45:53 -05:00
|
|
|
|
max--;
|
|
|
|
|
int current = 0;
|
|
|
|
|
while (*in != 0 && current < max)
|
|
|
|
|
{
|
|
|
|
|
if (!Q_IsColorString(in))
|
|
|
|
|
{
|
|
|
|
|
*out = *in;
|
|
|
|
|
out++;
|
|
|
|
|
current++;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-12-30 16:22:24 -05:00
|
|
|
|
in++;
|
2015-12-23 08:45:53 -05:00
|
|
|
|
}
|
2015-12-30 16:22:24 -05:00
|
|
|
|
in++;
|
2015-12-23 08:45:53 -05:00
|
|
|
|
}
|
|
|
|
|
*out = '\0';
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-02 09:19:34 -05:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-23 08:45:53 -05:00
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-01 11:36:47 -05:00
|
|
|
|
char* Colors::GetClientName(int localClientNum, int index, char *buf, size_t size)
|
2015-12-23 08:45:53 -05:00
|
|
|
|
{
|
2016-01-01 11:36:47 -05:00
|
|
|
|
Game::CL_GetClientName(localClientNum, index, buf, size);
|
2015-12-23 08:45:53 -05:00
|
|
|
|
|
|
|
|
|
// Remove the colors
|
2016-01-24 06:19:34 -05:00
|
|
|
|
strncpy(buf, Colors::Strip(buf).data(), size);
|
2015-12-23 08:45:53 -05:00
|
|
|
|
|
2016-01-01 11:36:47 -05:00
|
|
|
|
return buf;
|
2015-12-23 08:45:53 -05:00
|
|
|
|
}
|
|
|
|
|
|
2015-12-23 10:56:02 -05:00
|
|
|
|
void Colors::UpdateColorTable()
|
2015-12-23 08:45:53 -05:00
|
|
|
|
{
|
2015-12-23 10:56:02 -05:00
|
|
|
|
static int LastState = 2;
|
|
|
|
|
static DWORD DefaultTable[8] = { 0 };
|
|
|
|
|
DWORD* gColorTable = (DWORD*)0x78DC70;
|
|
|
|
|
|
|
|
|
|
if (LastState == 2)
|
|
|
|
|
{
|
|
|
|
|
memcpy(DefaultTable, gColorTable, sizeof(DefaultTable));
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-24 06:19:34 -05:00
|
|
|
|
if (Colors::NewColors.Get<bool>() && (0xF & static_cast<int>(Colors::NewColors.Get<bool>())) != LastState)
|
2015-12-23 10:56:02 -05:00
|
|
|
|
{
|
|
|
|
|
// 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<bool>();
|
|
|
|
|
}
|
2016-01-24 06:19:34 -05:00
|
|
|
|
else if (!Colors::NewColors.Get<bool>() && (0xF & static_cast<int>(Colors::NewColors.Get<bool>())) != LastState)
|
2015-12-23 10:56:02 -05:00
|
|
|
|
{
|
|
|
|
|
memcpy(gColorTable, DefaultTable, sizeof(DefaultTable));
|
2015-12-23 08:45:53 -05:00
|
|
|
|
|
2015-12-23 10:56:02 -05:00
|
|
|
|
LastState = Colors::NewColors.Get<bool>();
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-12-23 08:45:53 -05:00
|
|
|
|
|
2015-12-23 10:56:02 -05:00
|
|
|
|
Colors::Colors()
|
|
|
|
|
{
|
2015-12-23 08:45:53 -05:00
|
|
|
|
// Allow colored names ingame
|
|
|
|
|
Utils::Hook(0x5D8B40, Colors::ClientUserinfoChanged, HOOK_JUMP).Install()->Quick();
|
|
|
|
|
|
|
|
|
|
// Though, don't apply that to overhead names.
|
2016-01-01 11:36:47 -05:00
|
|
|
|
Utils::Hook(0x581932, Colors::GetClientName, HOOK_CALL).Install()->Quick();
|
2015-12-23 10:56:02 -05:00
|
|
|
|
|
|
|
|
|
// Set frame handler
|
|
|
|
|
Renderer::OnFrame(Colors::UpdateColorTable);
|
|
|
|
|
|
|
|
|
|
// Register dvar
|
2015-12-26 21:56:00 -05:00
|
|
|
|
Colors::NewColors = Dvar::Register<bool>("cg_newColors", true, Game::dvar_flag::DVAR_FLAG_SAVED, "Use Warfare<72> color code style.");
|
2015-12-23 08:45:53 -05:00
|
|
|
|
}
|
|
|
|
|
}
|