diff --git a/src/Components/Modules/Download.cpp b/src/Components/Modules/Download.cpp index 1c43324b..ae0d1c6c 100644 --- a/src/Components/Modules/Download.cpp +++ b/src/Components/Modules/Download.cpp @@ -697,7 +697,7 @@ namespace Components mg_mgr_init(&Mgr); - Network::OnStart([] + Events::OnNetworkInit([]() -> void { const auto* nc = mg_http_listen(&Mgr, Utils::String::VA(":%hu", Network::GetPort()), &EventHandler, &Mgr); if (!nc) @@ -709,7 +709,7 @@ namespace Components ServerRunning = true; Terminate = false; - ServerThread = Utils::Thread::CreateNamedThread("Mongoose", [] + ServerThread = Utils::Thread::CreateNamedThread("Mongoose", []() -> void { Com_InitThreadData(); @@ -722,7 +722,7 @@ namespace Components } else { - Events::OnDvarInit([] + Events::OnDvarInit([]() -> void { UIDlTimeLeft = Dvar::Register("ui_dl_timeLeft", "", Game::DVAR_NONE, ""); UIDlProgress = Dvar::Register("ui_dl_progress", "", Game::DVAR_NONE, ""); diff --git a/src/Components/Modules/Events.cpp b/src/Components/Modules/Events.cpp index 7d69b3a7..8d889a10 100644 --- a/src/Components/Modules/Events.cpp +++ b/src/Components/Modules/Events.cpp @@ -9,6 +9,7 @@ namespace Components Utils::Signal Events::ClientInitSignal; Utils::Signal Events::ServerInitSignal; Utils::Signal Events::DvarInitSignal; + Utils::Signal Events::NetworkInitSignal; void Events::OnClientDisconnect(const Utils::Slot& callback) { @@ -45,6 +46,11 @@ namespace Components DvarInitSignal.connect(callback); } + void Events::OnNetworkInit(const Utils::Slot& callback) + { + NetworkInitSignal.connect(callback); + } + /* * Should be called when a client drops from the server * but not "between levels" (Quake-III-Arena) @@ -101,6 +107,22 @@ namespace Components Utils::Hook::Call(0x60AD10)(); // Com_InitDvars } + void Events::NetworkStart() + { + NetworkInitSignal(); + NetworkInitSignal.clear(); + } + + __declspec(naked) void Events::NET_OpenSocks_Hk() + { + __asm + { + mov eax, 64D900h + call eax + jmp NetworkStart + } + } + Events::Events() { Utils::Hook(0x625235, ClientDisconnect_Hk, HOOK_CALL).install()->quick(); // SV_FreeClient @@ -117,5 +139,7 @@ namespace Components Utils::Hook(0x60BB3A, Com_InitDvars_Hk, HOOK_CALL).install()->quick(); // Com_Init_Try_Block_Function Utils::Hook(0x4D3665, SV_Init_Hk, HOOK_CALL).install()->quick(); // SV_Init + + Utils::Hook(0x4FD4D4, NET_OpenSocks_Hk, HOOK_JUMP).install()->quick(); // NET_OpenIP } } diff --git a/src/Components/Modules/Events.hpp b/src/Components/Modules/Events.hpp index c8d3e6a9..439ad120 100644 --- a/src/Components/Modules/Events.hpp +++ b/src/Components/Modules/Events.hpp @@ -30,6 +30,8 @@ namespace Components // Client & Server (triggered once) static void OnDvarInit(const Utils::Slot& callback); + static void OnNetworkInit(const Utils::Slot& callback); + private: static Utils::Signal ClientDisconnectSignal; static Utils::Signal ClientConnectSignal; @@ -38,6 +40,7 @@ namespace Components static Utils::Signal ClientInitSignal; static Utils::Signal ServerInitSignal; static Utils::Signal DvarInitSignal; + static Utils::Signal NetworkInitSignal; static void ClientDisconnect_Hk(int clientNum); static void SV_UserinfoChanged_Hk(Game::client_s* cl); @@ -46,5 +49,8 @@ namespace Components static void CL_InitOnceForAllClients_HK(); static void SV_Init_Hk(); static void Com_InitDvars_Hk(); + + static void NetworkStart(); + static void NET_OpenSocks_Hk(); }; } diff --git a/src/Components/Modules/Network.cpp b/src/Components/Modules/Network.cpp index 53e74399..cdc0e1db 100644 --- a/src/Components/Modules/Network.cpp +++ b/src/Components/Modules/Network.cpp @@ -2,7 +2,6 @@ namespace Components { - Utils::Signal Network::StartupSignal; // Packet interception std::unordered_map Network::CL_Callbacks; std::unordered_map Network::CL_RawCallbacks; @@ -152,11 +151,6 @@ namespace Components return (this->getType() != Game::NA_BAD && this->getType() >= Game::NA_BOT && this->getType() <= Game::NA_IP); } - void Network::OnStart(const Utils::Slot& callback) - { - StartupSignal.connect(callback); - } - void Network::Send(Game::netsrc_t type, const Address& target, const std::string& data) { // Do not use NET_OutOfBandPrint. It only supports non-binary data! @@ -228,12 +222,6 @@ namespace Components BroadcastRange(100, 65536, data); } - void Network::NetworkStart() - { - StartupSignal(); - StartupSignal.clear(); - } - std::uint16_t Network::GetPort() { assert((*Game::port)); @@ -241,16 +229,6 @@ namespace Components return static_cast((*Game::port)->current.unsignedInt); } - __declspec(naked) void Network::NetworkStartStub() - { - __asm - { - mov eax, 64D900h - call eax - jmp NetworkStart - } - } - __declspec(naked) void Network::PacketErrorCheck() { __asm @@ -392,9 +370,6 @@ namespace Components // Parse port as short in Net_AddrToString Utils::Hook::Set(0x4698E3, "%u.%u.%u.%u:%hu"); - // Install startup handler - Utils::Hook(0x4FD4D4, NetworkStartStub, HOOK_JUMP).install()->quick(); - // Prevent recvfrom error spam Utils::Hook(0x46531A, PacketErrorCheck, HOOK_JUMP).install()->quick(); diff --git a/src/Components/Modules/Network.hpp b/src/Components/Modules/Network.hpp index d9e2e020..838e9db8 100644 --- a/src/Components/Modules/Network.hpp +++ b/src/Components/Modules/Network.hpp @@ -46,16 +46,12 @@ namespace Components Game::netadr_t address; }; - typedef void(CallbackRaw)(); - using networkCallback = std::function; using networkRawCallback = std::function; Network(); static std::uint16_t GetPort(); - - static void OnStart(const Utils::Slot& callback); // Send quake-styled binary data static void Send(const Address& target, const std::string& data); @@ -77,13 +73,9 @@ namespace Components static void OnClientPacketRaw(const std::string& command, const networkRawCallback& callback); private: - static Utils::Signal StartupSignal; static std::unordered_map CL_Callbacks; static std::unordered_map CL_RawCallbacks; - static void NetworkStart(); - static void NetworkStartStub(); - static void PacketErrorCheck(); static bool CL_HandleCommand(Game::netadr_t* address, const char* command, Game::msg_t* message); diff --git a/src/Game/Zone.cpp b/src/Game/Zone.cpp index 2bc7155b..68ef430d 100644 --- a/src/Game/Zone.cpp +++ b/src/Game/Zone.cpp @@ -22,7 +22,7 @@ namespace Game assert((size >= 0)); #pragma warning(push) #pragma warning(disable: 6250) - [[maybe_unused]] const auto result = VirtualFree(ptr, size, MEM_DECOMMIT); + VirtualFree(ptr, size, MEM_DECOMMIT); #pragma warning(pop) }