3 Commits

3 changed files with 36 additions and 8 deletions

View File

@ -86,14 +86,14 @@ 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;
}

View File

@ -115,13 +115,13 @@ namespace utils::string
void strip(const char* in, char* out, size_t max)
{
if (!in || !out) return;
if (!in || !out || !max) return;
max--;
auto current = 0u;
while (*in != 0 && current < max)
{
const auto color_index = (*(in + 1) - 48) >= 0xC ? 7 : (*(in + 1) - 48);
const auto color_index = (static_cast<size_t>(*(in + 1) - 48)) >= 0xC ? 7 : (*(in + 1) - 48);
if (*in == '^' && (color_index != 7 || *(in + 1) == '7'))
{
@ -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);