From 8adec3e6789e64a89c959a30af6eac0d31c18048 Mon Sep 17 00:00:00 2001 From: Edo Date: Sat, 15 Oct 2022 21:31:16 +0100 Subject: [PATCH] [Monitor] Yeet (#529) --- src/Components/Loader.cpp | 1 - src/Components/Loader.hpp | 1 - src/Components/Modules/Auth.cpp | 2 +- src/Components/Modules/Console.cpp | 15 ++--- src/Components/Modules/Friends.cpp | 4 +- src/Components/Modules/IPCPipe.cpp | 2 +- src/Components/Modules/Monitor.cpp | 80 --------------------------- src/Components/Modules/Monitor.hpp | 15 ----- src/Components/Modules/Node.cpp | 21 ++----- src/Components/Modules/ServerList.cpp | 10 ++-- src/Components/Modules/ServerList.hpp | 2 +- src/Components/Modules/Singleton.cpp | 2 +- src/Components/Modules/Toast.cpp | 2 +- 13 files changed, 23 insertions(+), 134 deletions(-) delete mode 100644 src/Components/Modules/Monitor.cpp delete mode 100644 src/Components/Modules/Monitor.hpp diff --git a/src/Components/Loader.cpp b/src/Components/Loader.cpp index 014a0782..49a30a98 100644 --- a/src/Components/Loader.cpp +++ b/src/Components/Loader.cpp @@ -57,7 +57,6 @@ namespace Components Loader::Register(new IPCPipe()); Loader::Register(new MapDump()); Loader::Register(new ModList()); - Loader::Register(new Monitor()); Loader::Register(new Network()); Loader::Register(new Session()); Loader::Register(new Theatre()); diff --git a/src/Components/Loader.hpp b/src/Components/Loader.hpp index 71e3b530..ce687d14 100644 --- a/src/Components/Loader.hpp +++ b/src/Components/Loader.hpp @@ -80,7 +80,6 @@ namespace Components #include "Modules/Console.hpp" #include "Modules/UIScript.hpp" #include "Modules/ModList.hpp" -#include "Modules/Monitor.hpp" #include "Modules/Network.hpp" #include "Modules/Theatre.hpp" #include "Modules/QuickPatch.hpp" diff --git a/src/Components/Modules/Auth.cpp b/src/Components/Modules/Auth.cpp index 8bdc7536..e4c61044 100644 --- a/src/Components/Modules/Auth.cpp +++ b/src/Components/Modules/Auth.cpp @@ -277,7 +277,7 @@ namespace Components void Auth::StoreKey() { - if (!Dedicated::IsEnabled() && !ZoneBuilder::IsEnabled() && !Monitor::IsEnabled() && Auth::GuidKey.isValid()) + if (!Dedicated::IsEnabled() && !ZoneBuilder::IsEnabled() && Auth::GuidKey.isValid()) { Proto::Auth::Certificate cert; cert.set_token(Auth::GuidToken.toString()); diff --git a/src/Components/Modules/Console.cpp b/src/Components/Modules/Console.cpp index 4850b1a0..970b02a4 100644 --- a/src/Components/Modules/Console.cpp +++ b/src/Components/Modules/Console.cpp @@ -788,7 +788,7 @@ namespace Components void Console::FreeNativeConsole() { - if (!Monitor::IsEnabled() && !Flags::HasFlag("stdout") && (!Dedicated::IsEnabled() || Flags::HasFlag("console")) && !Loader::IsPerformingUnitTests()) + if (!Flags::HasFlag("stdout") && (!Dedicated::IsEnabled() || Flags::HasFlag("console")) && !Loader::IsPerformingUnitTests()) { FreeConsole(); } @@ -919,15 +919,10 @@ namespace Components if (Loader::IsPerformingUnitTests()) return; // External console - if (Flags::HasFlag("stdout") || Monitor::IsEnabled()) + if (Flags::HasFlag("stdout")) { -#ifndef DEBUG - if (!Monitor::IsEnabled()) -#endif - { - Utils::Hook(0x4B2080, Console::StdOutPrint, HOOK_JUMP).install()->quick(); - Utils::Hook(0x43D570, Console::StdOutError, HOOK_JUMP).install()->quick(); - } + Utils::Hook(0x4B2080, Console::StdOutPrint, HOOK_JUMP).install()->quick(); + Utils::Hook(0x43D570, Console::StdOutError, HOOK_JUMP).install()->quick(); } else if (Flags::HasFlag("console") || ZoneBuilder::IsEnabled()) // ZoneBuilder uses the game's console, until the native one is adapted. { @@ -936,7 +931,7 @@ namespace Components // Redirect input (]command) Utils::Hook(0x47025A, 0x4F5770, HOOK_CALL).install()->quick(); - Utils::Hook(0x60BB68, []() + Utils::Hook(0x60BB68, [] { Console::ShowAsyncConsole(); }, HOOK_CALL).install()->quick(); diff --git a/src/Components/Modules/Friends.cpp b/src/Components/Modules/Friends.cpp index 0ace8be5..29c3f77a 100644 --- a/src/Components/Modules/Friends.cpp +++ b/src/Components/Modules/Friends.cpp @@ -555,7 +555,7 @@ namespace Components { Friends::LoggedOn = false; - if (Dedicated::IsEnabled() || ZoneBuilder::IsEnabled() || Monitor::IsEnabled()) + if (Dedicated::IsEnabled() || ZoneBuilder::IsEnabled()) return; Friends::UIStreamFriendly = Dvar::Register("ui_streamFriendly", false, Game::DVAR_ARCHIVE, "Stream friendly UI"); @@ -720,7 +720,7 @@ namespace Components Friends::~Friends() { - if (Dedicated::IsEnabled() || ZoneBuilder::IsEnabled() || Monitor::IsEnabled()) return; + if (Dedicated::IsEnabled() || ZoneBuilder::IsEnabled()) return; Friends::StoreFriendsList(); diff --git a/src/Components/Modules/IPCPipe.cpp b/src/Components/Modules/IPCPipe.cpp index 76b4de01..1de08efb 100644 --- a/src/Components/Modules/IPCPipe.cpp +++ b/src/Components/Modules/IPCPipe.cpp @@ -204,7 +204,7 @@ namespace Components IPCPipe::IPCPipe() { - if (Dedicated::IsEnabled() || Monitor::IsEnabled() || Loader::IsPerformingUnitTests() || ZoneBuilder::IsEnabled()) return; + if (Dedicated::IsEnabled() || Loader::IsPerformingUnitTests() || ZoneBuilder::IsEnabled()) return; // Server pipe IPCPipe::ServerPipe.onConnect(IPCPipe::ConnectClient); diff --git a/src/Components/Modules/Monitor.cpp b/src/Components/Modules/Monitor.cpp deleted file mode 100644 index c3140377..00000000 --- a/src/Components/Modules/Monitor.cpp +++ /dev/null @@ -1,80 +0,0 @@ -#include -#undef getch -#undef ungetch -#include - -namespace Components -{ - bool Monitor::IsEnabled() - { - static std::optional flag; - - if (!flag.has_value()) - { - flag.emplace(Flags::HasFlag("monitor")); - } - - return flag.value(); - } - - int __stdcall Monitor::EntryPoint(HINSTANCE /*hInstance*/, HINSTANCE /*hPrevInstance*/, LPSTR /*lpCmdLine*/, int /*nShowCmd*/) - { - Utils::Hook::Call(0x4D8220)(); // Dvar_Init - Utils::Hook::Call(0x4D2280)(); // SL_Init - Utils::Hook::Call(0x47F390)(); // Swap_Init - Utils::Hook::Call(0x60AD10)(); // Com_InitDvars - Utils::Hook::Call(0x420830)(); // Com_InitHunkMemory - Utils::Hook::Call(0x4A62A0)(); // LargeLocalInit - Utils::Hook::Call(0x502580)(static_cast(__rdtsc())); // Netchan_Init - Game::NET_Init(); - - Utils::Time::Interval interval; - while (!interval.elapsed(15s)) - { - Utils::Hook::Call(0x49F0B0)(); // Com_ClientPacketEvent - //Session::RunFrame(); - Node::RunFrame(); - ServerList::Frame(); - - std::this_thread::sleep_for(10ms); - } - - auto list = ServerList::GetList(); - if (!list) - { - printf("1 IW4x player=0|server=0 Returned list was null\n"); - return 1; - } - - int servers = list->size(); - int players = 0; - - for (unsigned int i = 0; i < list->size(); ++i) - { - players += list->at(i).clients; - } - - printf("0 IW4x player=%d|server=%d Servers successfully parsed\n", players, servers); - - Utils::Hook::Call(0x430630)(); // LargeLocalReset - Utils::Hook::Call(0x4A0460)(); // Hunk_ClearTempMemory - Utils::Hook::Call(0x4AB3A0)(); // Hunk_ClearTempMemoryHigh - Utils::Hook::Call(0x4B3AD0)(); // SL_Shutdown - Utils::Hook::Call(0x502C50)(); // Dvar_Shutdown - - if (*Game::ip_socket && *Game::ip_socket != INVALID_SOCKET) - { - closesocket(*Game::ip_socket); - } - - WSACleanup(); - return 0; - } - - Monitor::Monitor() - { - if (!Monitor::IsEnabled()) return; - - Utils::Hook(0x4513DA, Monitor::EntryPoint, HOOK_JUMP).install()->quick(); - } -} diff --git a/src/Components/Modules/Monitor.hpp b/src/Components/Modules/Monitor.hpp deleted file mode 100644 index e26aa3bf..00000000 --- a/src/Components/Modules/Monitor.hpp +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once - -namespace Components -{ - class Monitor : public Component - { - public: - Monitor(); - - static bool IsEnabled(); - - private: - static int __stdcall EntryPoint(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd); - }; -} diff --git a/src/Components/Modules/Node.cpp b/src/Components/Modules/Node.cpp index 06a3d048..0ffc41cf 100644 --- a/src/Components/Modules/Node.cpp +++ b/src/Components/Modules/Node.cpp @@ -73,18 +73,10 @@ namespace Components { Proto::Node::List list; - if (Monitor::IsEnabled()) - { - std::string nodes = Utils::IO::ReadFile("players/nodes_default.dat"); - if (nodes.empty() || !list.ParseFromString(Utils::Compression::ZLib::Decompress(nodes))) return; - } - else - { - FileSystem::File defaultNodes("nodes_default.dat"); - if (!defaultNodes.exists() || !list.ParseFromString(Utils::Compression::ZLib::Decompress(defaultNodes.getBuffer()))) return; - } + FileSystem::File defaultNodes("nodes_default.dat"); + if (!defaultNodes.exists() || !list.ParseFromString(Utils::Compression::ZLib::Decompress(defaultNodes.getBuffer()))) return; - for (int i = 0; i < list.nodes_size(); ++i) + for (auto i = 0; i < list.nodes_size(); ++i) { const std::string& addr = list.nodes(i); @@ -171,7 +163,7 @@ namespace Components if (!Dedicated::IsEnabled()) { - if (ServerList::useMasterServer) return; // don't run node frame if master server is active + if (ServerList::UseMasterServer) return; // don't run node frame if master server is active if (*Game::clcState > 0) { @@ -251,7 +243,7 @@ namespace Components if (list.isnode() && (!list.port() || list.port() == address.getPort())) { - if (!Dedicated::IsEnabled() && ServerList::IsOnlineList() && !ServerList::useMasterServer && list.protocol() == PROTOCOL) + if (!Dedicated::IsEnabled() && ServerList::IsOnlineList() && !ServerList::UseMasterServer && list.protocol() == PROTOCOL) { Logger::Debug("Inserting {} into the serverlist", address.getString()); ServerList::InsertRequest(address); @@ -361,8 +353,7 @@ namespace Components Node::LoadNodes(); }; - if (Monitor::IsEnabled()) Network::OnStart(loadNodes); - else Scheduler::OnGameInitialized(loadNodes, Scheduler::Pipeline::MAIN); + Scheduler::OnGameInitialized(loadNodes, Scheduler::Pipeline::MAIN); Network::OnStart([] { diff --git a/src/Components/Modules/ServerList.cpp b/src/Components/Modules/ServerList.cpp index ec268831..36b0081b 100644 --- a/src/Components/Modules/ServerList.cpp +++ b/src/Components/Modules/ServerList.cpp @@ -19,7 +19,7 @@ namespace Components Dvar::Var ServerList::NETServerQueryLimit; Dvar::Var ServerList::NETServerFrames; - bool ServerList::useMasterServer = true; + bool ServerList::UseMasterServer = true; std::vector* ServerList::GetList() { @@ -51,7 +51,7 @@ namespace Components bool ServerList::IsOnlineList() { - return (Monitor::IsEnabled() || Dvar::Var("ui_netSource").get() == 1); + return (Dvar::Var("ui_netSource").get() == 1); } unsigned int ServerList::GetServerCount() @@ -299,13 +299,13 @@ namespace Components { Logger::Print("Could not resolve address for {}:{}", masterServerName, masterPort); Toast::Show("cardicon_headshot", "^1Error", Utils::String::VA("Could not resolve address for %s:%u", masterServerName, masterPort), 5000); - useMasterServer = false; + UseMasterServer = false; return; } Toast::Show("cardicon_headshot", "Server Browser", "Fetching servers...", 3000); - useMasterServer = true; + UseMasterServer = true; ServerList::RefreshContainer.awatingList = true; ServerList::RefreshContainer.awaitTime = Game::Sys_Milliseconds(); @@ -675,7 +675,7 @@ namespace Components Logger::Print("We haven't received a response from the master within {} seconds!\n", (Game::Sys_Milliseconds() - ServerList::RefreshContainer.awaitTime) / 1000); Toast::Show("cardicon_headshot", "^1Error", "Failed to reach master server, using node servers instead.", 5000); - useMasterServer = false; + UseMasterServer = false; Node::Synchronize(); } } diff --git a/src/Components/Modules/ServerList.hpp b/src/Components/Modules/ServerList.hpp index e82097e3..b65036e0 100644 --- a/src/Components/Modules/ServerList.hpp +++ b/src/Components/Modules/ServerList.hpp @@ -54,7 +54,7 @@ namespace Components static void UpdateVisibleInfo(); static bool GetMasterServer(const char* ip, int port, Game::netadr_t& address); - static bool useMasterServer; + static bool UseMasterServer; private: enum Column diff --git a/src/Components/Modules/Singleton.cpp b/src/Components/Modules/Singleton.cpp index da478a74..148bc825 100644 --- a/src/Components/Modules/Singleton.cpp +++ b/src/Components/Modules/Singleton.cpp @@ -20,7 +20,7 @@ namespace Components Console::FreeNativeConsole(); - if (Loader::IsPerformingUnitTests() || Dedicated::IsEnabled() || ZoneBuilder::IsEnabled() || Monitor::IsEnabled()) return; + if (Loader::IsPerformingUnitTests() || Dedicated::IsEnabled() || ZoneBuilder::IsEnabled()) return; Singleton::FirstInstance = (CreateMutexA(nullptr, FALSE, "iw4x_mutex") && GetLastError() != ERROR_ALREADY_EXISTS); diff --git a/src/Components/Modules/Toast.cpp b/src/Components/Modules/Toast.cpp index 4014f043..80df444a 100644 --- a/src/Components/Modules/Toast.cpp +++ b/src/Components/Modules/Toast.cpp @@ -144,7 +144,7 @@ namespace Components Toast::Toast() { - if (Dedicated::IsEnabled() || Monitor::IsEnabled() || ZoneBuilder::IsEnabled()) + if (Dedicated::IsEnabled() || ZoneBuilder::IsEnabled()) { return; }