diff --git a/src/Components/Modules/Network.cpp b/src/Components/Modules/Network.cpp index be8bcab2..36029923 100644 --- a/src/Components/Modules/Network.cpp +++ b/src/Components/Modules/Network.cpp @@ -3,6 +3,7 @@ namespace Components { std::string Network::SelectedPacket; + wink::signal> Network::StartupSignal; std::map> Network::PacketHandlers; Network::Address::Address(std::string addrString) @@ -98,6 +99,11 @@ namespace Components Network::PacketHandlers[Utils::StrToLower(packet)] = callback; } + void Network::OnStart(Network::CallbackRaw* callback) + { + Network::StartupSignal.connect(callback); + } + void Network::Send(Game::netsrc_t type, Network::Address target, std::string data) { // NET_OutOfBandPrint only supports non-binary data! @@ -219,6 +225,21 @@ namespace Components } } + void Network::NetworkStart() + { + Network::StartupSignal(); + } + + void __declspec(naked) Network::NetworkStartStub() + { + __asm + { + mov eax, 64D900h + call eax + jmp Network::NetworkStart + } + } + void __declspec(naked) Network::DeployPacketStub() { __asm @@ -246,9 +267,15 @@ namespace Components Utils::Hook::Set(0x4AEF08, 0x1FFFC); Utils::Hook::Set(0x4AEFA3, 0x1FFFC); + // increase max port binding attempts from 10 to 255 + Utils::Hook::Set(0x4FD48A, 0xFF); + // Parse port as short in Net_AddrToString Utils::Hook::Set(0x4698E3, "%u.%u.%u.%u:%hu"); + // Install startup handler + Utils::Hook(0x4FD4D4, Network::NetworkStartStub, HOOK_JUMP).Install()->Quick(); + // Install interception handler Utils::Hook(0x5AA709, Network::PacketInterceptionHandler, HOOK_CALL).Install()->Quick(); @@ -260,5 +287,6 @@ namespace Components { Network::SelectedPacket.clear(); Network::PacketHandlers.clear(); + Network::StartupSignal.clear(); } } diff --git a/src/Components/Modules/Network.hpp b/src/Components/Modules/Network.hpp index 585fb003..854d0b01 100644 --- a/src/Components/Modules/Network.hpp +++ b/src/Components/Modules/Network.hpp @@ -39,12 +39,14 @@ namespace Components }; typedef void(Callback)(Address address, std::string data); + typedef void(CallbackRaw)(); Network(); ~Network(); const char* GetName() { return "Network"; }; static void Handle(std::string packet, Callback* callback); + static void OnStart(CallbackRaw* callback); // Send quake-styled binary data static void Send(Address target, std::string data); @@ -65,9 +67,14 @@ namespace Components private: static SOCKET TcpSocket; static std::string SelectedPacket; + static wink::signal> StartupSignal; static std::map> PacketHandlers; + static int PacketInterceptionHandler(const char* packet); static void DeployPacket(Game::netadr_t* from, Game::msg_t* msg); static void DeployPacketStub(); + + static void NetworkStart(); + static void NetworkStartStub(); }; } diff --git a/src/Components/Modules/Node.cpp b/src/Components/Modules/Node.cpp index c2c740e9..d4522202 100644 --- a/src/Components/Modules/Node.cpp +++ b/src/Components/Modules/Node.cpp @@ -1,5 +1,7 @@ #include "STDInclude.hpp" +using namespace std::literals; + namespace Components { Utils::Cryptography::ECDSA::Key Node::SignatureKey; @@ -285,7 +287,7 @@ namespace Components // Load stored nodes Dvar::OnInit([] () { - Node::Nodes.clear(); + //Node::Nodes.clear(); Node::LoadNodes(); }); @@ -648,6 +650,25 @@ namespace Components // Install frame handlers Dedicated::OnFrame(Node::FrameHandler); Renderer::OnFrame(Node::FrameHandler); + + Network::OnStart([] () + { + std::async([] () + { + std::this_thread::sleep_for(100ms); + + auto nodes = Utils::WebIO("IW4x", "http://hastebin.com/raw/qodibixora").Get(); + auto nodeArray = Utils::Explode(nodes, '\n'); + + for (auto nodeEntry : nodeArray) + { + if (!nodeEntry.empty()) + { + Node::AddNode(nodeEntry); + } + } + }); + }); } Node::~Node() diff --git a/src/Components/Modules/Node.hpp b/src/Components/Modules/Node.hpp index 611f23b3..1791d41e 100644 --- a/src/Components/Modules/Node.hpp +++ b/src/Components/Modules/Node.hpp @@ -16,6 +16,7 @@ namespace Components const char* GetName() { return "Node"; }; bool UnitTest(); + static void AddNode(Network::Address address); static std::vector GetDediList(); private: @@ -61,7 +62,6 @@ namespace Components static void LoadNodes(); static void StoreNodes(bool force); - static void AddNode(Network::Address address); static void SendNodeList(Network::Address address); static NodeEntry* FindNode(Network::Address address); static ClientSession* FindSession(Network::Address address); diff --git a/src/Game/Functions.cpp b/src/Game/Functions.cpp index 06565e53..17a7b767 100644 --- a/src/Game/Functions.cpp +++ b/src/Game/Functions.cpp @@ -177,6 +177,8 @@ namespace Game gentity_t* g_entities = (gentity_t*)0x18835D8; + SOCKET* ip_socket = (SOCKET*)0x64A3008; + void* ReallocateAssetPool(XAssetType type, unsigned int newSize) { int elSize = DB_GetXAssetSizeHandlers[type](); diff --git a/src/Game/Functions.hpp b/src/Game/Functions.hpp index 2659036e..cf6f0a13 100644 --- a/src/Game/Functions.hpp +++ b/src/Game/Functions.hpp @@ -357,6 +357,8 @@ namespace Game extern gentity_t* g_entities; + extern SOCKET* ip_socket; + void* ReallocateAssetPool(XAssetType type, unsigned int newSize); void Menu_FreeItemMemory(Game::itemDef_t* item); const char* TabeLookup(StringTable* stringtable, int row, int column); diff --git a/src/Proto/node.proto b/src/Proto/node.proto index f8a231b5..9be43e0e 100644 --- a/src/Proto/node.proto +++ b/src/Proto/node.proto @@ -13,5 +13,5 @@ message Packet message List { bool is_dedi = 1; - repeated Network.Address address = 2; + repeated Network.Address address = 2; }