From 0321753278101ec159eb388ae17d8872a2dcbf46 Mon Sep 17 00:00:00 2001 From: Federico Cecchetto Date: Mon, 28 Feb 2022 15:01:30 +0100 Subject: [PATCH 1/6] More network fixes --- src/client/component/auth.cpp | 11 ++++++++++- src/client/component/network.cpp | 31 +++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/client/component/auth.cpp b/src/client/component/auth.cpp index ceb96188..3eb7103b 100644 --- a/src/client/component/auth.cpp +++ b/src/client/component/auth.cpp @@ -128,7 +128,7 @@ namespace auth const auto offset = sizeof("connect") + 4; proto::network::connect_info info; - if (!info.ParseFromArray(msg->data + offset, msg->cursize - offset)) + if (msg->cursize < offset || !info.ParseFromArray(msg->data + offset, msg->cursize - offset)) { network::send(*from, "error", "Invalid connect data!", '\n'); return; @@ -159,6 +159,13 @@ namespace auth key.set(info.publickey()); const auto xuid = strtoull(steam_id.data(), nullptr, 16); + + if (xuid == auth::get_guid()) + { + network::send(*from, "error", "You are already connected to this server!", '\n'); + return; + } + if (xuid != key.get_hash()) { //MessageBoxA(nullptr, steam_id.data(), std::to_string(key.get_hash()).data(), 0); @@ -228,6 +235,8 @@ namespace auth // Check for sending connect packet utils::hook::set(0x14059A6E0, 0xC301B0); + // Don't instantly timeout the connecting client ? not sure about this + utils::hook::set(0x14025136B, 0xC3); } command::add("guid", []() diff --git a/src/client/component/network.cpp b/src/client/component/network.cpp index 5df17798..c0529c5f 100644 --- a/src/client/component/network.cpp +++ b/src/client/component/network.cpp @@ -96,6 +96,33 @@ namespace network // Rather than try and let the player in, just tell them they are a duplicate player and reject connection game::NET_OutOfBandPrint(game::NS_SERVER, from, "error\nYou are already connected to the server."); } + SOCKET create_socket(const char* net_interface, int port, int protocol) + { + sockaddr_in address{}; + + if (net_interface && net_interface != "localhost"s) + { + // Sys_StringToSockaddr + utils::hook::invoke(0x1404F6580, net_interface, &address); + } + + address.sin_family = AF_INET; + address.sin_port = ntohs(port); + + const auto sock = ::socket(AF_INET, SOCK_DGRAM, protocol); + + u_long arg = 1; + ioctlsocket(sock, FIONBIO, &arg); + char optval[4] = {1}; + setsockopt(sock, 0xFFFF, 32, optval, 4); + + if (bind(sock, reinterpret_cast(&address), sizeof(address)) != -1) + { + return sock; + } + + closesocket(sock); + return 0; } void on(const std::string& command, const callback& callback) @@ -280,6 +307,10 @@ namespace network const std::string message{data}; console::info(message.data()); }); + + // Use our own socket since the game's socket doesn't work with non localhost addresses + // why? no idea + utils::hook::jump(0x140512B40, create_socket); } } }; From 63644a11844fe6ece510386bc3e3b7ceb35bf60f Mon Sep 17 00:00:00 2001 From: Federico Cecchetto Date: Mon, 28 Feb 2022 15:07:22 +0100 Subject: [PATCH 2/6] Fix --- src/client/component/network.cpp | 50 +++++++++++++++++--------------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/src/client/component/network.cpp b/src/client/component/network.cpp index 335255d7..4baa57b2 100644 --- a/src/client/component/network.cpp +++ b/src/client/component/network.cpp @@ -102,33 +102,35 @@ namespace network // Rather than try and let the player in, just tell them they are a duplicate player and reject connection game::NET_OutOfBandPrint(game::NS_SERVER, from, "error\nYou are already connected to the server."); } - SOCKET create_socket(const char* net_interface, int port, int protocol) - { - sockaddr_in address{}; - if (net_interface && net_interface != "localhost"s) + SOCKET create_socket(const char* net_interface, int port, int protocol) { - // Sys_StringToSockaddr - utils::hook::invoke(0x1404F6580, net_interface, &address); + sockaddr_in address{}; + + if (net_interface && net_interface != "localhost"s) + { + // Sys_StringToSockaddr + utils::hook::invoke(0x1404F6580, net_interface, &address); + } + + address.sin_family = AF_INET; + address.sin_port = ntohs(port); + + const auto sock = ::socket(AF_INET, SOCK_DGRAM, protocol); + + u_long arg = 1; + ioctlsocket(sock, FIONBIO, &arg); + char optval[4] = { 1 }; + setsockopt(sock, 0xFFFF, 32, optval, 4); + + if (bind(sock, reinterpret_cast(&address), sizeof(address)) != -1) + { + return sock; + } + + closesocket(sock); + return 0; } - - address.sin_family = AF_INET; - address.sin_port = ntohs(port); - - const auto sock = ::socket(AF_INET, SOCK_DGRAM, protocol); - - u_long arg = 1; - ioctlsocket(sock, FIONBIO, &arg); - char optval[4] = {1}; - setsockopt(sock, 0xFFFF, 32, optval, 4); - - if (bind(sock, reinterpret_cast(&address), sizeof(address)) != -1) - { - return sock; - } - - closesocket(sock); - return 0; } void on(const std::string& command, const callback& callback) From 30f7b0f2bf287c5bdeb98d53074887e314092792 Mon Sep 17 00:00:00 2001 From: Federico Cecchetto Date: Mon, 28 Feb 2022 15:13:03 +0100 Subject: [PATCH 3/6] More fixes --- src/client/component/auth.cpp | 6 ---- src/client/component/network.cpp | 60 ++------------------------------ 2 files changed, 2 insertions(+), 64 deletions(-) diff --git a/src/client/component/auth.cpp b/src/client/component/auth.cpp index 3eb7103b..5ea40d9c 100644 --- a/src/client/component/auth.cpp +++ b/src/client/component/auth.cpp @@ -160,12 +160,6 @@ namespace auth const auto xuid = strtoull(steam_id.data(), nullptr, 16); - if (xuid == auth::get_guid()) - { - network::send(*from, "error", "You are already connected to this server!", '\n'); - return; - } - if (xuid != key.get_hash()) { //MessageBoxA(nullptr, steam_id.data(), std::to_string(key.get_hash()).data(), 0); diff --git a/src/client/component/network.cpp b/src/client/component/network.cpp index 4baa57b2..480a187b 100644 --- a/src/client/component/network.cpp +++ b/src/client/component/network.cpp @@ -11,8 +11,6 @@ namespace network { - SOCKET sock; - namespace { @@ -114,7 +112,7 @@ namespace network } address.sin_family = AF_INET; - address.sin_port = ntohs(port); + address.sin_port = ntohs(static_cast(port)); const auto sock = ::socket(AF_INET, SOCK_DGRAM, protocol); @@ -142,7 +140,7 @@ namespace network { sockaddr s = {}; game::NetadrToSockadr(a3, &s); - return sendto(sock, src, size, 0, &s, 16) >= 0; + return sendto(*game::query_socket, src, size, 0, &s, 16) >= 0; } void send(const game::netadr_s& address, const std::string& command, const std::string& data, const char separator) @@ -152,10 +150,6 @@ namespace network packet.push_back(separator); packet.append(data); -#ifdef DEBUG - console::info("[Network] Sending command %s\n", command.data()); -#endif - send_data(address, packet); } @@ -221,53 +215,6 @@ namespace network return dvar; } - utils::hook::detour bind_socket_hook; - - SOCKET bind_socket_stub(const char* net_interface, u_short port, int protocol) - { -#ifdef DEBUG - printf("[Socket] Attempting to create socket\n"); -#endif - - sock = socket(2, 2, protocol); - u_long argp; - char optval; - struct sockaddr name; - - memset(&name, 0, sizeof(name)); - name.sa_family = 2; - - if (sock == -1) - { -#ifdef DEBUG - printf("[Socket] Error creating socket\n"); -#endif - WSAGetLastError(); - return 0; - } - - argp = 1; - optval = 1; - if (ioctlsocket(sock, -2147195266, &argp) == -1 || setsockopt(sock, 0xFFFF, 32, &optval, 4) == -1) - return 0; - - *(WORD*)name.sa_data = ntohs(port); - - if (bind(sock, &name, 16) != -1) - { -#ifdef DEBUG - printf("[Socket] Socket binded!\n"); -#endif - return sock; - } - -#ifdef DEBUG - printf("[Socket] Closing socket\n"); -#endif - closesocket(sock); - return 0; - } - class component final : public component_interface { public: @@ -279,9 +226,6 @@ namespace network return; } - // creating our own variable for socket use - bind_socket_hook.create(0x140512B40, bind_socket_stub); - // redirect dw_sendto to raw socket //utils::hook::jump(0x1404D850A, reinterpret_cast(0x1404D849A)); utils::hook::call(0x140513467, dw_send_to_stub); // H1MP64(1.4) From 0b4f42752211f8c4e85e74b1e2c874ff3674131b Mon Sep 17 00:00:00 2001 From: Federico Cecchetto Date: Mon, 28 Feb 2022 15:22:04 +0100 Subject: [PATCH 4/6] More party fixes --- src/client/component/party.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/client/component/party.cpp b/src/client/component/party.cpp index fc84d928..138f9b74 100644 --- a/src/client/component/party.cpp +++ b/src/client/component/party.cpp @@ -71,12 +71,11 @@ namespace party perform_game_initialization(); // exit from virtuallobby - reinterpret_cast(0x140256D40)(); + utils::hook::invoke(0x140256D40, 1); // CL_ConnectFromParty char session_info[0x100] = {}; - reinterpret_cast(0x140251560)( - 0, session_info, &target, mapname.data(), gametype.data()); + utils::hook::invoke(0x140251560, 0, session_info, &target, mapname.data(), gametype.data()); } std::string get_dvar_string(const std::string& dvar) @@ -141,7 +140,7 @@ namespace party utils::hook::detour cldisconnect_hook; - void cldisconnect_stub(int a1) + void cl_disconnect_stub(int a1) { party::sv_motd.clear(); cldisconnect_hook.invoke(a1); @@ -301,7 +300,7 @@ namespace party utils::hook::jump(0x1402521C7, disconnect_stub); // detour CL_Disconnect to clear motd - cldisconnect_hook.create(0x140252060, cldisconnect_stub); + cldisconnect_hook.create(0x140252060, cl_disconnect_stub); if (game::environment::is_mp()) { @@ -309,6 +308,7 @@ namespace party utils::hook::nop(0x140251EFB, 13); utils::hook::jump(0x140251EFB, drop_reason_stub, true); } + // enable custom kick reason in GScr_KickPlayer utils::hook::set(0x140376A1D, 0xEB); @@ -530,7 +530,7 @@ namespace party { utils::info_string info{}; info.set("challenge", std::string{data}); - info.set("gamename", "S1"); + info.set("gamename", "H1"); info.set("hostname", get_dvar_string("sv_hostname")); info.set("gametype", get_dvar_string("g_gametype")); info.set("sv_motd", get_dvar_string("sv_motd")); @@ -567,7 +567,7 @@ namespace party } const auto gamename = info.get("gamename"); - if (gamename != "S1"s) + if (gamename != "H1"s) { const auto str = "Invalid gamename."; printf("%s\n", str); From b4aab6e3db5d0aa68528bc0d56a18c6956265171 Mon Sep 17 00:00:00 2001 From: Federico Cecchetto Date: Mon, 28 Feb 2022 15:25:30 +0100 Subject: [PATCH 5/6] Remove this for now --- src/client/component/patches.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/component/patches.cpp b/src/client/component/patches.cpp index 73c43a24..f0c7c315 100644 --- a/src/client/component/patches.cpp +++ b/src/client/component/patches.cpp @@ -280,7 +280,7 @@ namespace patches game::Dvar_RegisterInt(0, "scr_game_spectatetype", 1, 0, 99, game::DVAR_FLAG_REPLICATED); // Prevent clients from ending the game as non host by sending 'end_game' lui notification - cmd_lui_notify_server_hook.create(0x140335A70, cmd_lui_notify_server_stub); // H1(1.4) + // cmd_lui_notify_server_hook.create(0x140335A70, cmd_lui_notify_server_stub); // H1(1.4) // Prevent clients from sending invalid reliableAcknowledge // utils::hook::call(0x1404899C6, sv_execute_client_message_stub); // H1(1.4) From ced51f723be0f42bdb9e1c7a6d272a309e67c69e Mon Sep 17 00:00:00 2001 From: Federico Cecchetto Date: Mon, 28 Feb 2022 18:11:09 +0100 Subject: [PATCH 6/6] Dont Com_Error in infoResponse --- src/client/component/party.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/client/component/party.cpp b/src/client/component/party.cpp index 138f9b74..6f711490 100644 --- a/src/client/component/party.cpp +++ b/src/client/component/party.cpp @@ -152,6 +152,12 @@ namespace party a.mov(ecx, 2); a.jmp(0x140251F78); }); + + void menu_error(const std::string& error) + { + utils::hook::invoke(0x1400DACC0, error.data(), "MENU_NOTICE"); + utils::hook::set(0x142C1DA98, 1); + } } int get_client_num_by_name(const std::string& name) @@ -562,7 +568,7 @@ namespace party { const auto str = "Invalid challenge."; printf("%s\n", str); - game::Com_Error(game::ERR_DROP, str); + menu_error(str); return; } @@ -571,7 +577,7 @@ namespace party { const auto str = "Invalid gamename."; printf("%s\n", str); - game::Com_Error(game::ERR_DROP, str); + menu_error(str); return; } @@ -580,7 +586,7 @@ namespace party { const auto str = "Invalid playmode."; printf("%s\n", str); - game::Com_Error(game::ERR_DROP, str); + menu_error(str); return; } @@ -589,7 +595,7 @@ namespace party { const auto str = "Server not running."; printf("%s\n", str); - game::Com_Error(game::ERR_DROP, str); + menu_error(str); return; } @@ -598,7 +604,7 @@ namespace party { const auto str = "Invalid map."; printf("%s\n", str); - game::Com_Error(game::ERR_DROP, str); + menu_error(str); return; } @@ -607,7 +613,7 @@ namespace party { const auto str = "Invalid gametype."; printf("%s\n", str); - game::Com_Error(game::ERR_DROP, str); + menu_error(str); return; }