mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
* Codebase restructured to SourceSDK codebase style and .cpp/.h assertion paths in the game executable. * Document most functions with valve style 'Purpose' blocks. * Rename variables to match the rest of the codebase and Valve's naming convention. * Dedicated DLL and the SDKLauncher now share the same codebase as the DevSDK. * Obtain globals or pointers directly instead of waiting for runtime initialized data. * Dynamically search for all functions and globals (this doesn't count for dedicated yet!). * Initialize most in-SDK variables. * Move certain prints and other utilities under ConVars to reduce verbosity and increase performance. * Print all pattern scan results through a virtual function to make it easier to add and debug new patterns in the future. * Type global var pointers appropriately if class or type is known and implemented. * Forward declare 'CClient' class to avoid having 2 'g_pClient' copies. * Add IDA's pseudo definitions for easier prototyping with decompiled assembly code. * RPAK decompress Command callback implementation. * Load decompressed RPaks from 'paks\Win32\' overriding the ones in 'paks\Win64\' (the decompress callback will automatically fix the header and write it to 'paks\Win32\'). * VPK decompress Command callback implementation. * Move CRC32 ands Adler32 to implementation files. * Server will print out more details about the connecting client. * Upgrade ImGui lib to v1.86. * Don't compile id3dx.h for dedicated. * Don't compile id3dx.cpp for dedicated * Implement DevMsg print function allowing to print information to the in-game VGUI/RUI console overlay, ImGui console overlay and the external windows console * Fixed bug where the Error function would not properly terminate the process when an error is called. This caused access violations for critical/non-recoverable errors. * Fixed bug where the game would crash if the console or server browser was enabled while the game was still starting up. * Several bug fixes for the dedicated server (warning: dedicated is still considered work-in-progress!).
118 lines
3.1 KiB
C++
118 lines
3.1 KiB
C++
// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
|
|
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
|
#pragma once
|
|
|
|
#include <chrono>
|
|
#include <type_traits>
|
|
#include <iterator>
|
|
#include <thirdparty/spdlog/include/fmt/fmt.h>
|
|
#include <thirdparty/spdlog/include/common.h>
|
|
|
|
// Some fmt helpers to efficiently format and pad ints and strings
|
|
namespace spdlog {
|
|
namespace details {
|
|
namespace fmt_helper {
|
|
|
|
inline spdlog::string_view_t to_string_view(const memory_buf_t &buf) SPDLOG_NOEXCEPT
|
|
{
|
|
return spdlog::string_view_t{buf.data(), buf.size()};
|
|
}
|
|
|
|
inline void append_string_view(spdlog::string_view_t view, memory_buf_t &dest)
|
|
{
|
|
auto *buf_ptr = view.data();
|
|
dest.append(buf_ptr, buf_ptr + view.size());
|
|
}
|
|
|
|
template<typename T>
|
|
inline void append_int(T n, memory_buf_t &dest)
|
|
{
|
|
fmt::format_int i(n);
|
|
dest.append(i.data(), i.data() + i.size());
|
|
}
|
|
|
|
template<typename T>
|
|
inline unsigned int count_digits(T n)
|
|
{
|
|
using count_type = typename std::conditional<(sizeof(T) > sizeof(uint32_t)), uint64_t, uint32_t>::type;
|
|
return static_cast<unsigned int>(fmt::
|
|
// fmt 7.0.0 renamed the internal namespace to detail.
|
|
// See: https://github.com/fmtlib/fmt/issues/1538
|
|
#if FMT_VERSION < 70000
|
|
internal
|
|
#else
|
|
detail
|
|
#endif
|
|
::count_digits(static_cast<count_type>(n)));
|
|
}
|
|
|
|
inline void pad2(int n, memory_buf_t &dest)
|
|
{
|
|
if (n >= 0 && n < 100) // 0-99
|
|
{
|
|
dest.push_back(static_cast<char>('0' + n / 10));
|
|
dest.push_back(static_cast<char>('0' + n % 10));
|
|
}
|
|
else // unlikely, but just in case, let fmt deal with it
|
|
{
|
|
fmt::format_to(std::back_inserter(dest), "{:02}", n);
|
|
}
|
|
}
|
|
|
|
template<typename T>
|
|
inline void pad_uint(T n, unsigned int width, memory_buf_t &dest)
|
|
{
|
|
static_assert(std::is_unsigned<T>::value, "pad_uint must get unsigned T");
|
|
for (auto digits = count_digits(n); digits < width; digits++)
|
|
{
|
|
dest.push_back('0');
|
|
}
|
|
append_int(n, dest);
|
|
}
|
|
|
|
template<typename T>
|
|
inline void pad3(T n, memory_buf_t &dest)
|
|
{
|
|
static_assert(std::is_unsigned<T>::value, "pad3 must get unsigned T");
|
|
if (n < 1000)
|
|
{
|
|
dest.push_back(static_cast<char>(n / 100 + '0'));
|
|
n = n % 100;
|
|
dest.push_back(static_cast<char>((n / 10) + '0'));
|
|
dest.push_back(static_cast<char>((n % 10) + '0'));
|
|
}
|
|
else
|
|
{
|
|
append_int(n, dest);
|
|
}
|
|
}
|
|
|
|
template<typename T>
|
|
inline void pad6(T n, memory_buf_t &dest)
|
|
{
|
|
pad_uint(n, 6, dest);
|
|
}
|
|
|
|
template<typename T>
|
|
inline void pad9(T n, memory_buf_t &dest)
|
|
{
|
|
pad_uint(n, 9, dest);
|
|
}
|
|
|
|
// return fraction of a second of the given time_point.
|
|
// e.g.
|
|
// fraction<std::milliseconds>(tp) -> will return the millis part of the second
|
|
template<typename ToDuration>
|
|
inline ToDuration time_fraction(log_clock::time_point tp)
|
|
{
|
|
using std::chrono::duration_cast;
|
|
using std::chrono::seconds;
|
|
auto duration = tp.time_since_epoch();
|
|
auto secs = duration_cast<seconds>(duration);
|
|
return duration_cast<ToDuration>(duration) - duration_cast<ToDuration>(secs);
|
|
}
|
|
|
|
} // namespace fmt_helper
|
|
} // namespace details
|
|
} // namespace spdlog
|