From 474d9df0142cb314234ec75340db9ce3731700eb Mon Sep 17 00:00:00 2001 From: Diavolo Date: Sun, 3 Jul 2022 21:46:42 +0200 Subject: [PATCH 1/7] [Logger] Add new line. Remove gren text --- src/Components/Modules/Logger.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Components/Modules/Logger.cpp b/src/Components/Modules/Logger.cpp index 19f29235..3acd6f93 100644 --- a/src/Components/Modules/Logger.cpp +++ b/src/Components/Modules/Logger.cpp @@ -54,7 +54,7 @@ namespace Components const auto msg = std::vformat(fmt, args); const auto out = std::format("Debug:\n {}\nFile: {}\nLine: {}\n", msg, loc.file_name(), loc.line()); #else - const auto out = "^2" + std::vformat(fmt, args); + const auto out = std::vformat(fmt, args) + "\n"; #endif Logger::MessagePrint(Game::CON_CHANNEL_DONT_FILTER, out); From abe2380040e99e184acfeb7e71c5e940e64283b7 Mon Sep 17 00:00:00 2001 From: Diavolo Date: Mon, 4 Jul 2022 12:10:45 +0200 Subject: [PATCH 2/7] [Structs] Use static_assert --- src/Game/Structs.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Game/Structs.hpp b/src/Game/Structs.hpp index 007c39e5..aaa59f7a 100644 --- a/src/Game/Structs.hpp +++ b/src/Game/Structs.hpp @@ -7070,6 +7070,8 @@ namespace Game entityState_s noDeltaEntities[1024]; }; + static_assert(sizeof(clientStatic_t) == 0xA7AEC); + struct ConDrawInputGlob { char autoCompleteChoice[64]; From a3d92939ad194737403b9803b50c21e45b286a0b Mon Sep 17 00:00:00 2001 From: Diavolo Date: Mon, 4 Jul 2022 21:09:26 +0200 Subject: [PATCH 3/7] [Logger] Filter out coloured strings for stdout --- src/Components/Modules/Ceg.cpp | 2 +- src/Components/Modules/Logger.cpp | 19 ++++++++++++++----- src/Components/Modules/Logger.hpp | 2 +- src/Utils/Hooking.cpp | 2 +- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/Components/Modules/Ceg.cpp b/src/Components/Modules/Ceg.cpp index 907a9e20..da0c2432 100644 --- a/src/Components/Modules/Ceg.cpp +++ b/src/Components/Modules/Ceg.cpp @@ -4,7 +4,7 @@ namespace Components { Ceg::Ceg() { - Utils::Hook::Signature signature(0x401000, 0x740000); + Utils::Hook::Signature signature(0x401000, 0x340000); // Generic killer caller. signature.add({ diff --git a/src/Components/Modules/Logger.cpp b/src/Components/Modules/Logger.cpp index 3acd6f93..0c5ee6cf 100644 --- a/src/Components/Modules/Logger.cpp +++ b/src/Components/Modules/Logger.cpp @@ -26,25 +26,33 @@ namespace Components void Logger::MessagePrint(const int channel, const std::string& msg) { + std::string out = msg; + + // Filter out coloured strings + if (out[0] == '^' && out[1] != '\0') + { + out = out.substr(2); + } + if (Flags::HasFlag("stdout") || Loader::IsPerformingUnitTests()) { - printf("%s", msg.data()); + printf("%s", out.data()); fflush(stdout); return; } if (!Logger::IsConsoleReady()) { - OutputDebugStringA(msg.data()); + OutputDebugStringA(out.data()); } if (!Game::Sys_IsMainThread()) { - Logger::EnqueueMessage(msg); + Logger::EnqueueMessage(out); } else { - Game::Com_PrintMessage(channel, msg.data(), 0); + Game::Com_PrintMessage(channel, out.data(), 0); } } @@ -54,7 +62,8 @@ namespace Components const auto msg = std::vformat(fmt, args); const auto out = std::format("Debug:\n {}\nFile: {}\nLine: {}\n", msg, loc.file_name(), loc.line()); #else - const auto out = std::vformat(fmt, args) + "\n"; + const auto msg = std::vformat(fmt, args); + const auto out = std::format("^2{}\n", msg); #endif Logger::MessagePrint(Game::CON_CHANNEL_DONT_FILTER, out); diff --git a/src/Components/Modules/Logger.hpp b/src/Components/Modules/Logger.hpp index 88f9f1da..cd281624 100644 --- a/src/Components/Modules/Logger.hpp +++ b/src/Components/Modules/Logger.hpp @@ -16,7 +16,6 @@ namespace Components static void Flush(); - static void MessagePrint(int channel, const std::string& msg); static void PrintInternal(int channel, std::string_view fmt, std::format_args&& args); static void ErrorInternal(Game::errorParm_t error, std::string_view fmt, std::format_args&& args); static void PrintErrorInternal(int channel, std::string_view fmt, std::format_args&& args); @@ -99,6 +98,7 @@ namespace Components static std::vector LoggingAddresses[2]; static void(*PipeCallback)(const std::string&); + static void MessagePrint(int channel, const std::string& msg); static void Frame(); static void G_LogPrintfStub(const char* fmt, ...); static void PrintMessageStub(); diff --git a/src/Utils/Hooking.cpp b/src/Utils/Hooking.cpp index e996e4f7..3b2f4544 100644 --- a/src/Utils/Hooking.cpp +++ b/src/Utils/Hooking.cpp @@ -9,7 +9,7 @@ namespace Utils { if (this->signatures.empty()) return; - char* _start = reinterpret_cast(this->start); + char* _start = static_cast(this->start); unsigned int sigCount = this->signatures.size(); Hook::Signature::Container* containers = this->signatures.data(); From 7841df29825f830a84425f1767fd0dcab66684b3 Mon Sep 17 00:00:00 2001 From: Diavolo Date: Tue, 5 Jul 2022 18:43:24 +0200 Subject: [PATCH 4/7] [Ceg] Remove check in the registry --- src/Components/Modules/Ceg.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Components/Modules/Ceg.cpp b/src/Components/Modules/Ceg.cpp index da0c2432..a975c5a8 100644 --- a/src/Components/Modules/Ceg.cpp +++ b/src/Components/Modules/Ceg.cpp @@ -45,5 +45,8 @@ namespace Components Utils::Hook::Set(0x4F4CF0, 0xC3); Utils::Hook::Set(0x432180, 0xC3); Utils::Hook::Set(0x461930, 0xC3); + + // Looking for stuff in the registry + Utils::Hook::Nop(0x4826F8, 5); } } From a0c1e4e464d949732f3624fbf72444c36d0775ce Mon Sep 17 00:00:00 2001 From: Diavolo Date: Fri, 8 Jul 2022 18:40:09 +0200 Subject: [PATCH 5/7] [Ceg] Remove very expensive function from Live_Init --- src/Components/Modules/Ceg.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Components/Modules/Ceg.cpp b/src/Components/Modules/Ceg.cpp index a975c5a8..4941656c 100644 --- a/src/Components/Modules/Ceg.cpp +++ b/src/Components/Modules/Ceg.cpp @@ -48,5 +48,8 @@ namespace Components // Looking for stuff in the registry Utils::Hook::Nop(0x4826F8, 5); + + // Live_Init + Utils::Hook::Nop(0x420937, 5); } } From 2a21f754e04b2a518456f67529bd7dbfbfb18288 Mon Sep 17 00:00:00 2001 From: Diavolo Date: Fri, 8 Jul 2022 18:42:09 +0200 Subject: [PATCH 6/7] [PlayerName] Fix format --- src/Components/Modules/PlayerName.cpp | 80 +++++++++++++-------------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/src/Components/Modules/PlayerName.cpp b/src/Components/Modules/PlayerName.cpp index 3233c279..74d02168 100644 --- a/src/Components/Modules/PlayerName.cpp +++ b/src/Components/Modules/PlayerName.cpp @@ -2,57 +2,57 @@ namespace Components { - Dvar::Var PlayerName::sv_allowColoredNames; + Dvar::Var PlayerName::sv_allowColoredNames; - void PlayerName::UserInfoCopy(char* buffer, const char* name, const size_t size) - { - if (!sv_allowColoredNames.get()) - { - char nameBuffer[64] = {0}; - TextRenderer::StripColors(name, nameBuffer, sizeof(nameBuffer)); - TextRenderer::StripAllTextIcons(nameBuffer, buffer, size); - } - else - { - TextRenderer::StripAllTextIcons(name, buffer, size); - } + void PlayerName::UserInfoCopy(char* buffer, const char* name, const size_t size) + { + if (!sv_allowColoredNames.get()) + { + char nameBuffer[64] = {0}; + TextRenderer::StripColors(name, nameBuffer, sizeof(nameBuffer)); + TextRenderer::StripAllTextIcons(nameBuffer, buffer, size); + } + else + { + TextRenderer::StripAllTextIcons(name, buffer, size); + } - std::string readablePlayerName(buffer); - readablePlayerName = Utils::String::Trim(readablePlayerName); + std::string readablePlayerName(buffer); + readablePlayerName = Utils::String::Trim(readablePlayerName); - if (readablePlayerName.size() < 3) - { - strncpy(buffer, "Unknown Soldier", size); - } - } + if (readablePlayerName.size() < 3) + { + strncpy(buffer, "Unknown Soldier", size); + } + } - __declspec(naked) void PlayerName::ClientCleanName() - { - __asm - { - mov eax, [esp + 4h] // length + __declspec(naked) void PlayerName::ClientCleanName() + { + __asm + { + mov eax, [esp + 4h] // length - push eax + push eax - push ecx // name - push edx // buffer + push ecx // name + push edx // buffer - call UserInfoCopy + call UserInfoCopy - add esp, 0Ch - retn - } - } + add esp, 0Ch + retn + } + } - char* PlayerName::GetClientName(int localClientNum, int index, char* buf, size_t size) - { - Game::CL_GetClientName(localClientNum, index, buf, size); + char* PlayerName::GetClientName(int localClientNum, int index, char* buf, size_t size) + { + Game::CL_GetClientName(localClientNum, index, buf, size); - // Append clantag to username & remove the colors - strncpy_s(buf, size, TextRenderer::StripColors(ClanTags::GetUserClantag(index, buf)).data(), size); + // Append clantag to username & remove the colors + strncpy_s(buf, size, TextRenderer::StripColors(ClanTags::GetUserClantag(index, buf)).data(), size); - return buf; - } + return buf; + } char* PlayerName::CleanStrStub(char* string) { From 25a3b8f4850300b1b841cdffe9c8af73d65794cc Mon Sep 17 00:00:00 2001 From: Diavolo Date: Sat, 9 Jul 2022 23:07:58 +0200 Subject: [PATCH 7/7] [Debug] Com_Assert_f for the memes --- src/Components/Modules/Debug.cpp | 7 +++++++ src/Components/Modules/Debug.hpp | 2 ++ 2 files changed, 9 insertions(+) diff --git a/src/Components/Modules/Debug.cpp b/src/Components/Modules/Debug.cpp index 2821d58c..9a2fc119 100644 --- a/src/Components/Modules/Debug.cpp +++ b/src/Components/Modules/Debug.cpp @@ -213,6 +213,11 @@ namespace Components } } + void Debug::Com_Assert_f() + { + assert(("a", false)); + } + void Debug::CL_InitDebugDvars() { static const char* debugOverlayNames_0[] = @@ -236,5 +241,7 @@ namespace Components // Hook end of CG_DrawDebugOverlays (This is to ensure some checks are done before our hook is executed). Utils::Hook(0x49CB0A, CG_DrawDebugOverlays_Hk, HOOK_JUMP).install()->quick(); + + Utils::Hook::Set(0x60BCEA, Com_Assert_f); } } diff --git a/src/Components/Modules/Debug.hpp b/src/Components/Modules/Debug.hpp index 5f031cfe..a3d9dfcf 100644 --- a/src/Components/Modules/Debug.hpp +++ b/src/Components/Modules/Debug.hpp @@ -31,6 +31,8 @@ namespace Components static void CG_DrawDebugOverlays_Hk(int localClientNum); + static void Com_Assert_f(); + static void CL_InitDebugDvars(); }; }