3 Commits

3 changed files with 47 additions and 6 deletions

View File

@ -86,18 +86,28 @@ namespace colors
return string;
}
size_t get_client_name_stub(const int local_client_num, const int index, char* buf, const int size,
const size_t unk, const size_t unk2)
size_t get_client_name_stub(const int local_client_num, const int index, char* name_buf,
const int max_name_size, char* clan_buf, const int max_clan_size)
{
// CL_GetClientName (CL_GetClientNameAndClantag?)
const auto result = reinterpret_cast<size_t(*)(int, int, char*, int, size_t, size_t)>(0x1402CF790)(
local_client_num, index, buf, size, unk, unk2);
// CL_GetClientNameAndClanTag (wrapper for CL_GetClientNameAndClanTagColorize)
const auto result = reinterpret_cast<size_t(*)(int, int, char*, int, char*, int)>(0x1402CF790)(
local_client_num, index, name_buf, max_name_size, clan_buf, max_clan_size);
utils::string::strip(buf, buf, size);
utils::string::strip(name_buf, name_buf, static_cast<size_t>(max_name_size));
return result;
}
int clean_agent_name_stub(char* out, int max_size, const char* fmt, const char* in)
{
// format agent overhead name like [%s]
const auto length = sprintf_s(out, max_size, fmt, in);
utils::string::strip(in, out, std::min(static_cast<size_t>(length), static_cast<size_t>(max_size)));
return length;
}
void rb_lookup_color_stub(const char index, DWORD* color)
{
*color = RGB(255, 255, 255);
@ -143,6 +153,9 @@ namespace colors
// don't apply colors to overhead names
utils::hook::call(0x14025CE79, get_client_name_stub);
// don't apply colors to overhead names of agents (like dogs or juggernauts)
utils::hook::call(0x1402CF760, clean_agent_name_stub);
// patch I_CleanStr
utils::hook::jump(0x1404F63C0, i_clean_str_stub);
}

View File

@ -140,6 +140,32 @@ namespace utils::string
*out = '\0';
}
std::string strip(std::string_view sv, bool strip_default_color)
{
std::string in(sv);
for (std::size_t i = 0; i + 1 < in.size();)
{
if (in[i] == '^' && static_cast<std::size_t>(in[i + 1] - '0') < 0xC)
{
if (in[i + 1] != '7' || strip_default_color)
{
in.erase(in.begin() + i, in.begin() + i + 2);
}
else
{
i += 2;
}
}
else
{
i += 1;
}
}
return in;
}
std::string convert(const std::wstring& wstr)
{
std::string result;

View File

@ -1,6 +1,7 @@
#pragma once
#include "memory.hpp"
#include <cstdint>
#include <span>
template <class Type, size_t n>
constexpr auto ARRAY_COUNT(Type(&)[n]) { return n; }
@ -91,6 +92,7 @@ namespace utils::string
std::string get_clipboard_data();
void strip(const char* in, char* out, size_t max);
std::string strip(std::string_view sv, bool strip_default_color = false);
std::string convert(const std::wstring& wstr);
std::wstring convert(const std::string& str);