mirror of
https://github.com/XLabsProject/iw6x-client.git
synced 2023-08-02 15:02:12 +02:00
[Utils] Refactor
This commit is contained in:
parent
1c4682b6e8
commit
67e40add09
@ -257,7 +257,7 @@ filter {}
|
||||
filter "configurations:Release"
|
||||
optimize "Size"
|
||||
buildoptions {"/GL"}
|
||||
linkoptions { "/IGNORE:4702", "/LTCG" }
|
||||
linkoptions {"/IGNORE:4702", "/LTCG"}
|
||||
defines {"NDEBUG"}
|
||||
flags {"FatalCompileWarnings"}
|
||||
filter {}
|
||||
|
@ -81,7 +81,7 @@ namespace colors
|
||||
|
||||
char* i_clean_str_stub(char* string)
|
||||
{
|
||||
utils::string::strip(string, string, static_cast<int>(strlen(string)) + 1);
|
||||
utils::string::strip(string, string, std::strlen(string) + 1);
|
||||
|
||||
return string;
|
||||
}
|
||||
|
@ -54,11 +54,10 @@ namespace dedicated_info
|
||||
}
|
||||
}
|
||||
|
||||
std::string cleaned_hostname;
|
||||
cleaned_hostname.resize(static_cast<int>(strlen(sv_hostname->current.string) + 1));
|
||||
std::string cleaned_hostname = sv_hostname->current.string;
|
||||
|
||||
utils::string::strip(sv_hostname->current.string, cleaned_hostname.data(),
|
||||
static_cast<int>(strlen(sv_hostname->current.string)) + 1);
|
||||
cleaned_hostname.size() + 1);
|
||||
|
||||
console::set_title(utils::string::va("%s on %s [%d/%d] (%d)", cleaned_hostname.data(),
|
||||
mapname->current.string, client_count,
|
||||
|
@ -39,7 +39,7 @@ namespace discord
|
||||
discord_presence.details = utils::string::va("%s on %s", gametype, map);
|
||||
|
||||
auto* const host_name = reinterpret_cast<char*>(0x14187EBC4);
|
||||
utils::string::strip(host_name, host_name, static_cast<int>(strlen(host_name)) + 1);
|
||||
utils::string::strip(host_name, host_name, std::strlen(host_name) + 1);
|
||||
|
||||
discord_presence.state = host_name;
|
||||
|
||||
|
@ -40,14 +40,7 @@ namespace utils::flags
|
||||
parsed = true;
|
||||
}
|
||||
|
||||
for (const auto& entry : enabled_flags)
|
||||
{
|
||||
if (string::to_lower(entry) == string::to_lower(flag))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return std::ranges::any_of(enabled_flags.cbegin(), enabled_flags.cend(),
|
||||
[flag](const auto& elem) { return elem == flag; });
|
||||
}
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ namespace utils
|
||||
return value->second;
|
||||
}
|
||||
|
||||
return "";
|
||||
return {};
|
||||
}
|
||||
|
||||
void info_string::parse(std::string buffer)
|
||||
@ -36,7 +36,7 @@ namespace utils
|
||||
buffer = buffer.substr(1);
|
||||
}
|
||||
|
||||
auto key_values = string::split(buffer, '\\');
|
||||
const auto key_values = string::split(buffer, '\\');
|
||||
for (size_t i = 0; !key_values.empty() && i < (key_values.size() - 1); i += 2)
|
||||
{
|
||||
const auto& key = key_values[i];
|
||||
@ -49,14 +49,14 @@ namespace utils
|
||||
{
|
||||
//auto first = true;
|
||||
std::string info_string;
|
||||
for (auto i = this->key_value_pairs_.begin(); i != this->key_value_pairs_.end(); ++i)
|
||||
for (const auto& [key, val] : key_value_pairs_)
|
||||
{
|
||||
//if (first) first = false;
|
||||
/*else*/ info_string.append("\\");
|
||||
|
||||
info_string.append(i->first); // Key
|
||||
info_string.append(key); // Key
|
||||
info_string.append("\\");
|
||||
info_string.append(i->second); // Value
|
||||
info_string.append(val); // Value
|
||||
}
|
||||
|
||||
return info_string;
|
||||
|
@ -32,7 +32,7 @@ namespace utils::io
|
||||
|
||||
if (stream.is_open())
|
||||
{
|
||||
stream.write(data.data(), data.size());
|
||||
stream.write(data.data(), static_cast<std::streamsize>(data.size()));
|
||||
stream.close();
|
||||
return true;
|
||||
}
|
||||
@ -64,7 +64,7 @@ namespace utils::io
|
||||
if (size > -1)
|
||||
{
|
||||
data->resize(static_cast<uint32_t>(size));
|
||||
stream.read(const_cast<char*>(data->data()), size);
|
||||
stream.read(data->data(), size);
|
||||
stream.close();
|
||||
return true;
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ namespace utils
|
||||
{
|
||||
std::lock_guard _(this->mutex_);
|
||||
|
||||
for (auto& data : this->pool_)
|
||||
for (const auto& data : this->pool_)
|
||||
{
|
||||
memory::free(data);
|
||||
}
|
||||
@ -115,6 +115,7 @@ namespace utils
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -130,13 +131,14 @@ namespace utils
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool memory::is_rdata_ptr(void* pointer)
|
||||
bool memory::is_rdata_ptr(void* ptr)
|
||||
{
|
||||
const std::string rdata = ".rdata";
|
||||
const auto pointer_lib = utils::nt::library::get_by_address(pointer);
|
||||
const auto pointer_lib = utils::nt::library::get_by_address(ptr);
|
||||
|
||||
for (const auto& section : pointer_lib.get_section_headers())
|
||||
{
|
||||
@ -147,7 +149,7 @@ namespace utils
|
||||
|
||||
if (name == rdata)
|
||||
{
|
||||
const auto target = size_t(pointer);
|
||||
const auto target = size_t(ptr);
|
||||
const size_t source_start = size_t(pointer_lib.get_ptr()) + section->PointerToRawData;
|
||||
const size_t source_end = source_start + section->SizeOfRawData;
|
||||
|
||||
|
@ -22,13 +22,13 @@ namespace utils
|
||||
void* allocate(size_t length);
|
||||
|
||||
template <typename T>
|
||||
inline T* allocate()
|
||||
T* allocate()
|
||||
{
|
||||
return this->allocate_array<T>(1);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline T* allocate_array(const size_t count = 1)
|
||||
T* allocate_array(const size_t count = 1)
|
||||
{
|
||||
return static_cast<T*>(this->allocate(count * sizeof(T)));
|
||||
}
|
||||
@ -45,13 +45,13 @@ namespace utils
|
||||
static void* allocate(size_t length);
|
||||
|
||||
template <typename T>
|
||||
static inline T* allocate()
|
||||
static T* allocate()
|
||||
{
|
||||
return allocate_array<T>(1);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static inline T* allocate_array(const size_t count = 1)
|
||||
static T* allocate_array(const size_t count = 1)
|
||||
{
|
||||
return static_cast<T*>(allocate(count * sizeof(T)));
|
||||
}
|
||||
|
@ -103,6 +103,7 @@ namespace utils::string
|
||||
GlobalUnlock(clipboard_data);
|
||||
}
|
||||
}
|
||||
|
||||
CloseClipboard();
|
||||
|
||||
return data;
|
||||
@ -110,12 +111,12 @@ namespace utils::string
|
||||
return {};
|
||||
}
|
||||
|
||||
void strip(const char* in, char* out, int max)
|
||||
void strip(const char* in, char* out, size_t max)
|
||||
{
|
||||
if (!in || !out) return;
|
||||
|
||||
max--;
|
||||
auto current = 0;
|
||||
auto current = 0u;
|
||||
while (*in != 0 && current < max)
|
||||
{
|
||||
const auto color_index = (*(in + 1) - 48) >= 0xC ? 7 : (*(in + 1) - 48);
|
||||
@ -133,17 +134,16 @@ namespace utils::string
|
||||
|
||||
++in;
|
||||
}
|
||||
|
||||
*out = '\0';
|
||||
}
|
||||
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable: 4100)
|
||||
std::string convert(const std::wstring& wstr)
|
||||
{
|
||||
std::string result;
|
||||
result.reserve(wstr.size());
|
||||
|
||||
for(const auto& chr : wstr)
|
||||
for (const auto& chr : wstr)
|
||||
{
|
||||
result.push_back(static_cast<char>(chr));
|
||||
}
|
||||
@ -156,14 +156,13 @@ namespace utils::string
|
||||
std::wstring result;
|
||||
result.reserve(str.size());
|
||||
|
||||
for(const auto& chr : str)
|
||||
for (const auto& chr : str)
|
||||
{
|
||||
result.push_back(static_cast<wchar_t>(chr));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
#pragma warning(pop)
|
||||
|
||||
std::string replace(std::string str, const std::string& from, const std::string& to)
|
||||
{
|
||||
|
@ -92,7 +92,7 @@ namespace utils::string
|
||||
|
||||
std::string get_clipboard_data();
|
||||
|
||||
void strip(const char* in, char* out, int max);
|
||||
void strip(const char* in, char* out, size_t max);
|
||||
|
||||
std::string convert(const std::wstring& wstr);
|
||||
std::wstring convert(const std::string& str);
|
||||
|
Loading…
Reference in New Issue
Block a user