From 601be011e18098dcda1306eeacb02fe4d3eee9ba Mon Sep 17 00:00:00 2001 From: Maurice Heumann Date: Mon, 10 Apr 2023 15:05:23 +0200 Subject: [PATCH] Prepare sendpacket fixes --- src/client/component/network.cpp | 35 ++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/client/component/network.cpp b/src/client/component/network.cpp index 9a722405..c517e862 100644 --- a/src/client/component/network.cpp +++ b/src/client/component/network.cpp @@ -256,6 +256,38 @@ namespace network return a.port == b.port && a.addr == b.addr; } + int net_sendpacket_stub(const game::netsrc_t sock, const int length, const char* data, const game::netadr_t* to) + { + printf("Sending packet of size: %X\n", length); + + if (to->type != game::NA_RAWIP) + { + printf("NET_SendPacket: bad address type\n"); + return 0; + } + + const auto s = *game::ip_socket; + if (!s || sock > game::NS_MAXCLIENTS) + { + return 0; + } + + sockaddr_in address{}; + address.sin_family = AF_INET; + address.sin_port = htons(to->port); + address.sin_addr.s_addr = htonl(((to->ipv4.c | ((to->ipv4.b | (to->ipv4.a << 8)) << 8)) << 8) | to->ipv4.d); + + const auto size = static_cast(length); + + std::vector buffer{}; + buffer.resize(size + 1); + buffer[0] = static_cast((static_cast(sock) & 0xF) | ((to->localNetID & 0xF) << 4)); + memcpy(buffer.data() + 1, data, size); + + return sendto(s, buffer.data(), static_cast(buffer.size()), 0, reinterpret_cast(&address), + sizeof(address)); + } + struct component final : generic_component { void post_unpack() override @@ -268,6 +300,9 @@ namespace network // skip checksum verification utils::hook::set(game::select(0x14233249E, 0x140596F2E), 0); // don't add checksum to packet + // Recreate NET_SendPacket to increase max packet size + utils::hook::jump(game::select(0x1423323B0, 0x140596E40), net_sendpacket_stub); + utils::hook::set(game::select(0x14134C6E0, 0x14018E574), 5); // set initial connection state to challenging