From 3e2d4035ada7a91e0ecffd0fde050cf47fce0427 Mon Sep 17 00:00:00 2001 From: Jack <66967891+ASpoonPlaysGames@users.noreply.github.com> Date: Sun, 25 Aug 2024 21:49:45 +0100 Subject: [PATCH 1/4] Fix manual hooks storing their name badly (#774) Fix manual hooks storing their name wrong and move to just using std::string since it's much more convenient and this isn't C --- primedev/core/hooks.cpp | 22 ++++++---------------- primedev/core/hooks.h | 2 +- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/primedev/core/hooks.cpp b/primedev/core/hooks.cpp index 5026f837b..d8fad4094 100644 --- a/primedev/core/hooks.cpp +++ b/primedev/core/hooks.cpp @@ -85,19 +85,9 @@ void __fileAutohook::DispatchForModule(const char* pModuleName) hook->Dispatch(); } -ManualHook::ManualHook(const char* funcName, LPVOID func) : pHookFunc(func), ppOrigFunc(nullptr) -{ - const size_t iFuncNameStrlen = strlen(funcName); - pFuncName = new char[iFuncNameStrlen]; - memcpy(pFuncName, funcName, iFuncNameStrlen); -} +ManualHook::ManualHook(const char* funcName, LPVOID func) : svFuncName(funcName), pHookFunc(func), ppOrigFunc(nullptr) {} -ManualHook::ManualHook(const char* funcName, LPVOID* orig, LPVOID func) : pHookFunc(func), ppOrigFunc(orig) -{ - const size_t iFuncNameStrlen = strlen(funcName); - pFuncName = new char[iFuncNameStrlen]; - memcpy(pFuncName, funcName, iFuncNameStrlen); -} +ManualHook::ManualHook(const char* funcName, LPVOID* orig, LPVOID func) : svFuncName(funcName), pHookFunc(func), ppOrigFunc(orig) {} bool ManualHook::Dispatch(LPVOID addr, LPVOID* orig) { @@ -105,19 +95,19 @@ bool ManualHook::Dispatch(LPVOID addr, LPVOID* orig) ppOrigFunc = orig; if (!addr) - spdlog::error("Address for hook {} is invalid", pFuncName); + spdlog::error("Address for hook {} is invalid", svFuncName); else if (MH_CreateHook(addr, pHookFunc, ppOrigFunc) == MH_OK) { if (MH_EnableHook(addr) == MH_OK) { - spdlog::info("Enabling hook {}", pFuncName); + spdlog::info("Enabling hook {}", svFuncName); return true; } else - spdlog::error("MH_EnableHook failed for function {}", pFuncName); + spdlog::error("MH_EnableHook failed for function {}", svFuncName); } else - spdlog::error("MH_CreateHook failed for function {}", pFuncName); + spdlog::error("MH_CreateHook failed for function {}", svFuncName); return false; } diff --git a/primedev/core/hooks.h b/primedev/core/hooks.h index 2a2180dab..023b7411e 100644 --- a/primedev/core/hooks.h +++ b/primedev/core/hooks.h @@ -278,7 +278,7 @@ class __autohook class ManualHook { public: - char* pFuncName; + std::string svFuncName; LPVOID pHookFunc; LPVOID* ppOrigFunc; From f6915dc331685574289e7b45e5d2d36b530f50f3 Mon Sep 17 00:00:00 2001 From: Jack <66967891+ASpoonPlaysGames@users.noreply.github.com> Date: Mon, 26 Aug 2024 14:13:36 +0100 Subject: [PATCH 2/4] Format constructor initializers in a better way (#775) --- .clang-format | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.clang-format b/.clang-format index ecf9fec8b..fb7ca9cfe 100644 --- a/.clang-format +++ b/.clang-format @@ -35,5 +35,5 @@ IndentExternBlock: Indent PointerAlignment: Left SortIncludes: false NamespaceIndentation: All -PackConstructorInitializers: NextLine -BreakConstructorInitializersBeforeComma: true +PackConstructorInitializers: Never +BreakConstructorInitializers: BeforeComma From 6e9792f3651d1e0c7045c5d67312c10f91ce6962 Mon Sep 17 00:00:00 2001 From: Northstar Date: Mon, 26 Aug 2024 15:18:56 +0200 Subject: [PATCH 3/4] Format project --- primedev/client/localchatwriter.cpp | 10 ++++-- primedev/core/hooks.cpp | 14 ++++++-- primedev/core/hooks.h | 10 ++++-- primedev/core/math/vector.h | 42 +++++++++++++++++++---- primedev/logging/logging.h | 9 +++-- primedev/masterserver/masterserver.cpp | 7 +++- primedev/plugins/interfaces/interface.cpp | 3 +- primedev/plugins/plugins.cpp | 3 +- primedev/squirrel/squirrelclasstypes.h | 3 +- primedev/util/utils.h | 5 ++- 10 files changed, 86 insertions(+), 20 deletions(-) diff --git a/primedev/client/localchatwriter.cpp b/primedev/client/localchatwriter.cpp index 35cc065f4..042e77d9d 100644 --- a/primedev/client/localchatwriter.cpp +++ b/primedev/client/localchatwriter.cpp @@ -102,7 +102,10 @@ Color lightColors[8] = { class AnsiEscapeParser { public: - explicit AnsiEscapeParser(LocalChatWriter* writer) : m_writer(writer) {} + explicit AnsiEscapeParser(LocalChatWriter* writer) + : m_writer(writer) + { + } void HandleVal(unsigned long val) { @@ -257,7 +260,10 @@ class AnsiEscapeParser } }; -LocalChatWriter::LocalChatWriter(Context context) : m_context(context) {} +LocalChatWriter::LocalChatWriter(Context context) + : m_context(context) +{ +} void LocalChatWriter::Write(const char* str) { diff --git a/primedev/core/hooks.cpp b/primedev/core/hooks.cpp index d8fad4094..7ce98331b 100644 --- a/primedev/core/hooks.cpp +++ b/primedev/core/hooks.cpp @@ -85,9 +85,19 @@ void __fileAutohook::DispatchForModule(const char* pModuleName) hook->Dispatch(); } -ManualHook::ManualHook(const char* funcName, LPVOID func) : svFuncName(funcName), pHookFunc(func), ppOrigFunc(nullptr) {} +ManualHook::ManualHook(const char* funcName, LPVOID func) + : svFuncName(funcName) + , pHookFunc(func) + , ppOrigFunc(nullptr) +{ +} -ManualHook::ManualHook(const char* funcName, LPVOID* orig, LPVOID func) : svFuncName(funcName), pHookFunc(func), ppOrigFunc(orig) {} +ManualHook::ManualHook(const char* funcName, LPVOID* orig, LPVOID func) + : svFuncName(funcName) + , pHookFunc(func) + , ppOrigFunc(orig) +{ +} bool ManualHook::Dispatch(LPVOID addr, LPVOID* orig) { diff --git a/primedev/core/hooks.h b/primedev/core/hooks.h index 023b7411e..26d9483cd 100644 --- a/primedev/core/hooks.h +++ b/primedev/core/hooks.h @@ -140,7 +140,9 @@ class __autohook __autohook() = delete; __autohook(__fileAutohook* autohook, const char* funcName, LPVOID absoluteAddress, LPVOID* orig, LPVOID func) - : pHookFunc(func), ppOrigFunc(orig), iAbsoluteAddress(absoluteAddress) + : pHookFunc(func) + , ppOrigFunc(orig) + , iAbsoluteAddress(absoluteAddress) { iAddressResolutionMode = ABSOLUTE_ADDR; @@ -152,7 +154,8 @@ class __autohook } __autohook(__fileAutohook* autohook, const char* funcName, const char* addrString, LPVOID* orig, LPVOID func) - : pHookFunc(func), ppOrigFunc(orig) + : pHookFunc(func) + , ppOrigFunc(orig) { iAddressResolutionMode = OFFSET_STRING; @@ -168,7 +171,8 @@ class __autohook } __autohook(__fileAutohook* autohook, const char* funcName, const char* moduleName, const char* procName, LPVOID* orig, LPVOID func) - : pHookFunc(func), ppOrigFunc(orig) + : pHookFunc(func) + , ppOrigFunc(orig) { iAddressResolutionMode = PROCADDRESS; diff --git a/primedev/core/math/vector.h b/primedev/core/math/vector.h index 0face7328..ea1de65ec 100644 --- a/primedev/core/math/vector.h +++ b/primedev/core/math/vector.h @@ -13,9 +13,24 @@ class Vector3 public: float x, y, z; - Vector3(float _x, float _y, float _z) : x(_x), y(_y), z(_z) {} - Vector3(float _f) : x(_f), y(_f), z(_f) {} - Vector3() : x(0.0f), y(0.0f), z(0.0f) {} + Vector3(float _x, float _y, float _z) + : x(_x) + , y(_y) + , z(_z) + { + } + Vector3(float _f) + : x(_f) + , y(_f) + , z(_f) + { + } + Vector3() + : x(0.0f) + , y(0.0f) + , z(0.0f) + { + } inline bool IsValid() { return IsFinite(x) && IsFinite(y) && IsFinite(z); } @@ -302,9 +317,24 @@ class QAngle float y; float z; - QAngle(float _x, float _y, float _z) : x(_x), y(_y), z(_z) {} - QAngle(float _f) : x(_f), y(_f), z(_f) {} - QAngle() : x(0.0f), y(0.0f), z(0.0f) {} + QAngle(float _x, float _y, float _z) + : x(_x) + , y(_y) + , z(_z) + { + } + QAngle(float _f) + : x(_f) + , y(_f) + , z(_f) + { + } + QAngle() + : x(0.0f) + , y(0.0f) + , z(0.0f) + { + } Vector3 GetNormal() const; diff --git a/primedev/logging/logging.h b/primedev/logging/logging.h index be41cb39d..edfa20dc1 100644 --- a/primedev/logging/logging.h +++ b/primedev/logging/logging.h @@ -14,7 +14,11 @@ class ColoredLogger; struct custom_log_msg : spdlog::details::log_msg { public: - custom_log_msg(ColoredLogger* origin, spdlog::details::log_msg msg) : origin(origin), spdlog::details::log_msg(msg) {} + custom_log_msg(ColoredLogger* origin, spdlog::details::log_msg msg) + : origin(origin) + , spdlog::details::log_msg(msg) + { + } ColoredLogger* origin; }; @@ -38,7 +42,8 @@ class ColoredLogger : public spdlog::logger std::vector> custom_sinks_; - ColoredLogger(std::string name, Color color, bool first = false) : spdlog::logger(*spdlog::default_logger()) + ColoredLogger(std::string name, Color color, bool first = false) + : spdlog::logger(*spdlog::default_logger()) { name_ = std::move(name); if (!first) diff --git a/primedev/masterserver/masterserver.cpp b/primedev/masterserver/masterserver.cpp index e7bb11329..56ab608d2 100644 --- a/primedev/masterserver/masterserver.cpp +++ b/primedev/masterserver/masterserver.cpp @@ -992,7 +992,12 @@ void ConCommand_ns_fetchservers(const CCommand& args) g_pMasterServerManager->RequestServerList(); } -MasterServerManager::MasterServerManager() : m_pendingConnectionInfo {}, m_sOwnServerId {""}, m_sOwnClientAuthToken {""} {} +MasterServerManager::MasterServerManager() + : m_pendingConnectionInfo {} + , m_sOwnServerId {""} + , m_sOwnClientAuthToken {""} +{ +} ON_DLL_LOAD_RELIESON("engine.dll", MasterServer, (ConCommand, ServerPresence), (CModule module)) { diff --git a/primedev/plugins/interfaces/interface.cpp b/primedev/plugins/interfaces/interface.cpp index 4c006f2c7..bc9005421 100644 --- a/primedev/plugins/interfaces/interface.cpp +++ b/primedev/plugins/interfaces/interface.cpp @@ -3,7 +3,8 @@ InterfaceReg* s_pInterfaceRegs; -InterfaceReg::InterfaceReg(InstantiateInterfaceFn fn, const char* pName) : m_pName(pName) +InterfaceReg::InterfaceReg(InstantiateInterfaceFn fn, const char* pName) + : m_pName(pName) { m_CreateFn = fn; m_pNext = s_pInterfaceRegs; diff --git a/primedev/plugins/plugins.cpp b/primedev/plugins/plugins.cpp index 03dd2c9e2..f0a9c3c5f 100644 --- a/primedev/plugins/plugins.cpp +++ b/primedev/plugins/plugins.cpp @@ -22,7 +22,8 @@ bool isValidSquirrelIdentifier(std::string s) return true; } -Plugin::Plugin(std::string path) : m_location(path) +Plugin::Plugin(std::string path) + : m_location(path) { HMODULE pluginModule = GetModuleHandleA(path.c_str()); diff --git a/primedev/squirrel/squirrelclasstypes.h b/primedev/squirrel/squirrelclasstypes.h index 3a39c957e..55897b698 100644 --- a/primedev/squirrel/squirrelclasstypes.h +++ b/primedev/squirrel/squirrelclasstypes.h @@ -174,7 +174,8 @@ class SquirrelAsset { public: std::string path; - SquirrelAsset(std::string path) : path(path) {}; + SquirrelAsset(std::string path) + : path(path) {}; }; #pragma region TypeDefs diff --git a/primedev/util/utils.h b/primedev/util/utils.h index 4b7f57c80..c613d16dd 100644 --- a/primedev/util/utils.h +++ b/primedev/util/utils.h @@ -8,7 +8,10 @@ template class ScopeGuard auto operator=(ScopeGuard&) = delete; ScopeGuard(ScopeGuard&) = delete; - ScopeGuard(T callback) : m_callback(callback) {} + ScopeGuard(T callback) + : m_callback(callback) + { + } ~ScopeGuard() { if (!m_dismissed) From 932735e0500f6fc4d43ee949754c6a6a7c48d3e2 Mon Sep 17 00:00:00 2001 From: GeckoEidechse Date: Mon, 26 Aug 2024 15:23:42 +0200 Subject: [PATCH 4/4] Add formatting commit to git-blame-ignore-revs --- .git-blame-ignore-revs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs index b622bb573..c104bb382 100644 --- a/.git-blame-ignore-revs +++ b/.git-blame-ignore-revs @@ -8,3 +8,6 @@ f9bc3c9d1834cb8bd5f872b749b057c33e8b0102 # Clang format change: one-line inline functions 5b2c608b22ba272e4ab1a45adc1f43b60b1aea79 + +# Clang format change: see PR #775 +6e9792f3651d1e0c7045c5d67312c10f91ce6962