From 777215b90ac62e97722545ba3cd50b6cbb56e2ae Mon Sep 17 00:00:00 2001 From: Edo Date: Mon, 17 Apr 2023 14:47:29 +0200 Subject: [PATCH] [General]: Clean global headers (#941) --- src/Components/Loader.cpp | 13 ++++- src/Components/Loader.hpp | 11 ----- src/Components/Modules/Auth.cpp | 3 ++ src/Components/Modules/Chat.cpp | 1 + src/Components/Modules/ConnectProtocol.cpp | 1 + src/Components/Modules/Console.cpp | 1 + src/Components/Modules/Debug.cpp | 1 + src/Components/Modules/Discord.cpp | 1 + src/Components/Modules/Dvar.cpp | 3 ++ src/Components/Modules/Exception.cpp | 57 +++++++++------------- src/Components/Modules/Exception.hpp | 2 +- src/Components/Modules/Friends.cpp | 5 ++ src/Components/Modules/IPCPipe.cpp | 2 + src/Components/Modules/Materials.cpp | 1 + src/Components/Modules/ModList.cpp | 1 + src/Components/Modules/ModelSurfs.cpp | 1 + src/Components/Modules/Node.cpp | 1 + src/Components/Modules/Party.cpp | 3 ++ src/Components/Modules/PlayerName.cpp | 1 + src/Components/Modules/QuickPatch.cpp | 6 +++ src/Components/Modules/RawMouse.cpp | 1 + src/Components/Modules/ServerInfo.cpp | 1 + src/Components/Modules/ServerList.cpp | 3 ++ src/Components/Modules/TextRenderer.cpp | 1 + src/Components/Modules/Toast.cpp | 3 ++ src/Components/Modules/Window.cpp | 1 + src/Steam/Interfaces/SteamUser.cpp | 1 + 27 files changed, 80 insertions(+), 46 deletions(-) diff --git a/src/Components/Loader.cpp b/src/Components/Loader.cpp index de0f2420..cce1e935 100644 --- a/src/Components/Loader.cpp +++ b/src/Components/Loader.cpp @@ -2,6 +2,7 @@ #include #include "Modules/ArenaLength.hpp" +#include "Modules/Auth.hpp" #include "Modules/Bans.hpp" #include "Modules/Bots.hpp" #include "Modules/Branding.hpp" @@ -20,13 +21,20 @@ #include "Modules/Discovery.hpp" #include "Modules/Download.hpp" #include "Modules/Elevators.hpp" +#include "Modules/Exception.hpp" #include "Modules/FastFiles.hpp" +#include "Modules/Friends.hpp" #include "Modules/Gamepad.hpp" +#include "Modules/IPCPipe.hpp" #include "Modules/Lean.hpp" #include "Modules/MapDump.hpp" #include "Modules/MapRotation.hpp" +#include "Modules/Materials.hpp" +#include "Modules/ModList.hpp" +#include "Modules/ModelSurfs.hpp" #include "Modules/NetworkDebug.hpp" #include "Modules/News.hpp" +#include "Modules/Node.hpp" #include "Modules/Party.hpp" #include "Modules/PlayerMovement.hpp" #include "Modules/PlayerName.hpp" @@ -46,13 +54,16 @@ #include "Modules/Stats.hpp" #include "Modules/StringTable.hpp" #include "Modules/StructuredData.hpp" +#include "Modules/TextRenderer.hpp" #include "Modules/Theatre.hpp" #include "Modules/Threading.hpp" +#include "Modules/Toast.hpp" #include "Modules/UIFeeder.hpp" #include "Modules/VisionFile.hpp" #include "Modules/Voice.hpp" #include "Modules/Vote.hpp" #include "Modules/Weapon.hpp" +#include "Modules/Window.hpp" #include "Modules/BotLib/lPrecomp.hpp" @@ -97,7 +108,7 @@ namespace Components Register(new Logger()); Register(new UIScript()); Register(new ZoneBuilder()); - + Register(new ArenaLength()); Register(new AssetHandler()); Register(new Bans()); diff --git a/src/Components/Loader.hpp b/src/Components/Loader.hpp index dee129b3..d4282cdc 100644 --- a/src/Components/Loader.hpp +++ b/src/Components/Loader.hpp @@ -62,10 +62,8 @@ namespace Components } // Priority -#include "Modules/Auth.hpp" #include "Modules/Command.hpp" #include "Modules/Dvar.hpp" -#include "Modules/Exception.hpp" #include "Modules/Flags.hpp" #include "Modules/Network.hpp" #include "Modules/Logger.hpp" @@ -77,20 +75,11 @@ namespace Components #include "Modules/Dedicated.hpp" #include "Modules/Events.hpp" #include "Modules/FileSystem.hpp" -#include "Modules/Friends.hpp" -#include "Modules/IPCPipe.hpp" #include "Modules/Localization.hpp" #include "Modules/Maps.hpp" -#include "Modules/Materials.hpp" #include "Modules/Menus.hpp" -#include "Modules/ModList.hpp" -#include "Modules/ModelSurfs.hpp" -#include "Modules/Node.hpp" #include "Modules/Renderer.hpp" #include "Modules/Scheduler.hpp" -#include "Modules/TextRenderer.hpp" -#include "Modules/Toast.hpp" -#include "Modules/Window.hpp" #include "Modules/Zones.hpp" #include "Modules/GSC/GSC.hpp" diff --git a/src/Components/Modules/Auth.cpp b/src/Components/Modules/Auth.cpp index a0fae972..af3dbb3c 100644 --- a/src/Components/Modules/Auth.cpp +++ b/src/Components/Modules/Auth.cpp @@ -3,8 +3,11 @@ #include +#include "Auth.hpp" #include "Bans.hpp" #include "Bots.hpp" +#include "Friends.hpp" +#include "Toast.hpp" namespace Components { diff --git a/src/Components/Modules/Chat.cpp b/src/Components/Modules/Chat.cpp index 0b53f85e..d3aa5397 100644 --- a/src/Components/Modules/Chat.cpp +++ b/src/Components/Modules/Chat.cpp @@ -1,6 +1,7 @@ #include #include "Chat.hpp" #include "PlayerName.hpp" +#include "TextRenderer.hpp" #include "Voice.hpp" #include "GSC/Script.hpp" diff --git a/src/Components/Modules/ConnectProtocol.cpp b/src/Components/Modules/ConnectProtocol.cpp index 4a44ad34..1793b44a 100644 --- a/src/Components/Modules/ConnectProtocol.cpp +++ b/src/Components/Modules/ConnectProtocol.cpp @@ -1,5 +1,6 @@ #include #include "ConnectProtocol.hpp" +#include "IPCPipe.hpp" namespace Components { diff --git a/src/Components/Modules/Console.cpp b/src/Components/Modules/Console.cpp index c30824cd..56acd131 100644 --- a/src/Components/Modules/Console.cpp +++ b/src/Components/Modules/Console.cpp @@ -1,5 +1,6 @@ #include #include "Console.hpp" +#include "TextRenderer.hpp" #include "Terminus_4.49.1.ttf.hpp" diff --git a/src/Components/Modules/Debug.cpp b/src/Components/Modules/Debug.cpp index 5b8bcfcd..4e7b7c95 100644 --- a/src/Components/Modules/Debug.cpp +++ b/src/Components/Modules/Debug.cpp @@ -1,5 +1,6 @@ #include #include "Debug.hpp" +#include "TextRenderer.hpp" #include "Game/Engine/ScopedCriticalSection.hpp" diff --git a/src/Components/Modules/Discord.cpp b/src/Components/Modules/Discord.cpp index 9087d734..b487e106 100644 --- a/src/Components/Modules/Discord.cpp +++ b/src/Components/Modules/Discord.cpp @@ -1,6 +1,7 @@ #include #include "Discord.hpp" #include "Party.hpp" +#include "TextRenderer.hpp" #include diff --git a/src/Components/Modules/Dvar.cpp b/src/Components/Modules/Dvar.cpp index 8138faac..665abae7 100644 --- a/src/Components/Modules/Dvar.cpp +++ b/src/Components/Modules/Dvar.cpp @@ -1,5 +1,8 @@ #include +#include "Friends.hpp" +#include "TextRenderer.hpp" + namespace Components { Dvar::Var Dvar::Name; diff --git a/src/Components/Modules/Exception.cpp b/src/Components/Modules/Exception.cpp index 7860a375..0bb0db17 100644 --- a/src/Components/Modules/Exception.cpp +++ b/src/Components/Modules/Exception.cpp @@ -1,5 +1,8 @@ #include + #include "Console.hpp" +#include "Exception.hpp" +#include "Window.hpp" #include @@ -50,32 +53,39 @@ namespace Components Game::Sys_SuspendOtherThreads(); } - void Exception::CopyMessageToClipboard(const std::string& error) + void Exception::CopyMessageToClipboard(const char* error) { const auto hWndNewOwner = GetDesktopWindow(); const auto result = OpenClipboard(hWndNewOwner); if (result == FALSE) + { return; + } - EmptyClipboard(); - auto* hMem = GlobalAlloc(GMEM_MOVEABLE, error.size() + 1); - - if (hMem == nullptr) + const auto _0 = gsl::finally([] { CloseClipboard(); + }); + + EmptyClipboard(); + + const auto len = std::strlen(error); + auto* hMem = GlobalAlloc(GMEM_MOVEABLE, len + 1); + + if (!hMem) + { return; } auto* lock = GlobalLock(hMem); - if (lock != nullptr) + if (lock) { - std::memcpy(lock, error.data(), error.size() + 1); + std::memcpy(lock, error, len + 1); GlobalUnlock(hMem); - SetClipboardData(1, hMem); + SetClipboardData(CF_TEXT, hMem); } - CloseClipboard(); GlobalFree(hMem); } @@ -88,18 +98,18 @@ namespace Components return EXCEPTION_CONTINUE_EXECUTION; } - std::string errorStr; + const char* error; if (ExceptionInfo->ExceptionRecord->ExceptionCode == EXCEPTION_STACK_OVERFLOW) { - errorStr = "Termination because of a stack overflow.\nCopy exception address to clipboard?"; + error = "Termination because of a stack overflow.\nCopy exception address to clipboard?"; } else { - errorStr = Utils::String::VA("Fatal error (0x%08X) at 0x%08X.\nCopy exception address to clipboard?", ExceptionInfo->ExceptionRecord->ExceptionCode, ExceptionInfo->ExceptionRecord->ExceptionAddress); + error = Utils::String::VA("Fatal error (0x%08X) at 0x%08X.\nCopy exception address to clipboard?", ExceptionInfo->ExceptionRecord->ExceptionCode, ExceptionInfo->ExceptionRecord->ExceptionAddress); } // Message should be copied to the keyboard if no button is pressed - if (MessageBoxA(nullptr, errorStr.data(), nullptr, MB_YESNO | MB_ICONERROR) == IDYES) + if (MessageBoxA(nullptr, error, nullptr, MB_YESNO | MB_ICONERROR) == IDYES) { CopyMessageToClipboard(Utils::String::VA("0x%08X", ExceptionInfo->ExceptionRecord->ExceptionAddress)); } @@ -136,8 +146,8 @@ namespace Components MessageBoxA(nullptr, Utils::String::Format("There was an error creating the minidump ({})! Hit OK to close the program.", Utils::GetLastWindowsError()), "ERROR", MB_OK | MB_ICONERROR); #ifdef _DEBUG OutputDebugStringA("Failed to create new minidump!"); -#endif Utils::OutputDebugLastError(); +#endif TerminateProcess(GetCurrentProcess(), ExceptionInfo->ExceptionRecord->ExceptionCode); } @@ -190,25 +200,6 @@ namespace Components Utils::Hook(0x61F17D, LongJmp_Internal_Stub, HOOK_CALL).install()->quick(); Utils::Hook(0x61F248, LongJmp_Internal_Stub, HOOK_CALL).install()->quick(); Utils::Hook(0x61F5E7, LongJmp_Internal_Stub, HOOK_CALL).install()->quick(); - -#ifdef MAP_TEST - Command::Add("mapTest", [](Command::Params* params) - { - Game::UI_UpdateArenas(); - - std::string command; - for (auto i = 0; i < (params->size() >= 2 ? atoi(params->get(1)) : *Game::arenaCount); ++i) - { - const auto* mapName = ArenaLength::NewArenas[i % *Game::arenaCount].mapName; - - if (!(i % 2)) command.append("wait 250;disconnect;wait 750;"); // Test a disconnect - else command.append("wait 500;"); // Test direct map switch - command.append(Utils::String::VA("map %s;", mapName)); - } - - Command::Execute(command, false); - }); -#endif } Exception::~Exception() diff --git a/src/Components/Modules/Exception.hpp b/src/Components/Modules/Exception.hpp index 40b5e820..9967144d 100644 --- a/src/Components/Modules/Exception.hpp +++ b/src/Components/Modules/Exception.hpp @@ -17,7 +17,7 @@ namespace Components static LONG WINAPI ExceptionFilter(LPEXCEPTION_POINTERS ExceptionInfo); static __declspec(noreturn) void LongJmp_Internal_Stub(jmp_buf env, int status); - static void CopyMessageToClipboard(const std::string& error); + static void CopyMessageToClipboard(const char* error); static LPTOP_LEVEL_EXCEPTION_FILTER WINAPI SetUnhandledExceptionFilter_Stub(LPTOP_LEVEL_EXCEPTION_FILTER); diff --git a/src/Components/Modules/Friends.cpp b/src/Components/Modules/Friends.cpp index 900c2111..dea87d13 100644 --- a/src/Components/Modules/Friends.cpp +++ b/src/Components/Modules/Friends.cpp @@ -5,7 +5,12 @@ #include #pragma warning(pop) +#include "Friends.hpp" +#include "Materials.hpp" +#include "Node.hpp" #include "Party.hpp" +#include "TextRenderer.hpp" +#include "Toast.hpp" #include "UIFeeder.hpp" namespace Components diff --git a/src/Components/Modules/IPCPipe.cpp b/src/Components/Modules/IPCPipe.cpp index ea2f2980..64d9a31d 100644 --- a/src/Components/Modules/IPCPipe.cpp +++ b/src/Components/Modules/IPCPipe.cpp @@ -1,6 +1,8 @@ #include #include +#include "IPCPipe.hpp" + namespace Components { Pipe IPCPipe::ServerPipe; diff --git a/src/Components/Modules/Materials.cpp b/src/Components/Modules/Materials.cpp index 69176b08..16178a44 100644 --- a/src/Components/Modules/Materials.cpp +++ b/src/Components/Modules/Materials.cpp @@ -1,4 +1,5 @@ #include +#include "Materials.hpp" namespace Components { diff --git a/src/Components/Modules/ModList.cpp b/src/Components/Modules/ModList.cpp index 13f6c3ab..7782fb33 100644 --- a/src/Components/Modules/ModList.cpp +++ b/src/Components/Modules/ModList.cpp @@ -1,4 +1,5 @@ #include +#include "ModList.hpp" #include "UIFeeder.hpp" namespace Components diff --git a/src/Components/Modules/ModelSurfs.cpp b/src/Components/Modules/ModelSurfs.cpp index 4c5424a4..e7e888eb 100644 --- a/src/Components/Modules/ModelSurfs.cpp +++ b/src/Components/Modules/ModelSurfs.cpp @@ -1,4 +1,5 @@ #include +#include "ModelSurfs.hpp" namespace Components { diff --git a/src/Components/Modules/Node.cpp b/src/Components/Modules/Node.cpp index 7c796801..cb122cc7 100644 --- a/src/Components/Modules/Node.cpp +++ b/src/Components/Modules/Node.cpp @@ -4,6 +4,7 @@ #include +#include "Node.hpp" #include "ServerList.hpp" #include "Session.hpp" diff --git a/src/Components/Modules/Party.cpp b/src/Components/Modules/Party.cpp index 58c03510..efe579e0 100644 --- a/src/Components/Modules/Party.cpp +++ b/src/Components/Modules/Party.cpp @@ -1,8 +1,11 @@ #include #include +#include "Auth.hpp" #include "Download.hpp" +#include "Friends.hpp" #include "Gamepad.hpp" +#include "Node.hpp" #include "Party.hpp" #include "ServerList.hpp" #include "Stats.hpp" diff --git a/src/Components/Modules/PlayerName.cpp b/src/Components/Modules/PlayerName.cpp index f0d758e8..826b97d5 100644 --- a/src/Components/Modules/PlayerName.cpp +++ b/src/Components/Modules/PlayerName.cpp @@ -1,6 +1,7 @@ #include #include "ClanTags.hpp" #include "PlayerName.hpp" +#include "TextRenderer.hpp" namespace Components { diff --git a/src/Components/Modules/QuickPatch.cpp b/src/Components/Modules/QuickPatch.cpp index 41fc91b9..b4086ff9 100644 --- a/src/Components/Modules/QuickPatch.cpp +++ b/src/Components/Modules/QuickPatch.cpp @@ -2,6 +2,8 @@ #include #include "QuickPatch.hpp" +#include "TextRenderer.hpp" +#include "Toast.hpp" namespace Components { @@ -196,10 +198,14 @@ namespace Components void QuickPatch::CL_KeyEvent_OnEscape() { if (Game::Con_CancelAutoComplete()) + { return; + } if (TextRenderer::HandleFontIconAutocompleteKey(0, TextRenderer::FONT_ICON_ACI_CONSOLE, Game::K_ESCAPE)) + { return; + } // Close console Game::Key_RemoveCatcher(0, ~Game::KEYCATCH_CONSOLE); diff --git a/src/Components/Modules/RawMouse.cpp b/src/Components/Modules/RawMouse.cpp index bc046d7b..7a7ea662 100644 --- a/src/Components/Modules/RawMouse.cpp +++ b/src/Components/Modules/RawMouse.cpp @@ -1,6 +1,7 @@ #include #include "Gamepad.hpp" #include "RawMouse.hpp" +#include "Window.hpp" namespace Components { diff --git a/src/Components/Modules/ServerInfo.cpp b/src/Components/Modules/ServerInfo.cpp index 01efbf97..dfae403b 100644 --- a/src/Components/Modules/ServerInfo.cpp +++ b/src/Components/Modules/ServerInfo.cpp @@ -1,6 +1,7 @@ #include #include +#include "Friends.hpp" #include "Gamepad.hpp" #include "Party.hpp" #include "ServerInfo.hpp" diff --git a/src/Components/Modules/ServerList.cpp b/src/Components/Modules/ServerList.cpp index 2c0697ea..fa7b0e68 100644 --- a/src/Components/Modules/ServerList.cpp +++ b/src/Components/Modules/ServerList.cpp @@ -2,8 +2,11 @@ #include #include "Discovery.hpp" +#include "Node.hpp" #include "Party.hpp" #include "ServerList.hpp" +#include "TextRenderer.hpp" +#include "Toast.hpp" #include "UIFeeder.hpp" #include diff --git a/src/Components/Modules/TextRenderer.cpp b/src/Components/Modules/TextRenderer.cpp index 6c677179..dfc6d6f6 100644 --- a/src/Components/Modules/TextRenderer.cpp +++ b/src/Components/Modules/TextRenderer.cpp @@ -1,4 +1,5 @@ #include +#include "TextRenderer.hpp" namespace Game { diff --git a/src/Components/Modules/Toast.cpp b/src/Components/Modules/Toast.cpp index 80df444a..78c78ca0 100644 --- a/src/Components/Modules/Toast.cpp +++ b/src/Components/Modules/Toast.cpp @@ -1,5 +1,8 @@ #include +#include "Materials.hpp" +#include "Toast.hpp" + namespace Components { std::queue Toast::Queue; diff --git a/src/Components/Modules/Window.cpp b/src/Components/Modules/Window.cpp index 5ed7e497..395135dc 100644 --- a/src/Components/Modules/Window.cpp +++ b/src/Components/Modules/Window.cpp @@ -1,6 +1,7 @@ #include #include "FastFiles.hpp" +#include "Window.hpp" namespace Components { diff --git a/src/Steam/Interfaces/SteamUser.cpp b/src/Steam/Interfaces/SteamUser.cpp index 26f8ce43..46b42887 100644 --- a/src/Steam/Interfaces/SteamUser.cpp +++ b/src/Steam/Interfaces/SteamUser.cpp @@ -1,4 +1,5 @@ #include +#include "Components/Modules/Auth.hpp" STEAM_IGNORE_WARNINGS_START