diff --git a/src/client/component/auth.cpp b/src/client/component/auth.cpp index ceb96188..5ea40d9c 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,7 @@ namespace auth key.set(info.publickey()); const auto xuid = strtoull(steam_id.data(), nullptr, 16); + if (xuid != key.get_hash()) { //MessageBoxA(nullptr, steam_id.data(), std::to_string(key.get_hash()).data(), 0); @@ -228,6 +229,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 b12f3c92..480a187b 100644 --- a/src/client/component/network.cpp +++ b/src/client/component/network.cpp @@ -11,8 +11,6 @@ namespace network { - SOCKET sock; - namespace { @@ -102,6 +100,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) + { + // Sys_StringToSockaddr + utils::hook::invoke(0x1404F6580, net_interface, &address); + } + + address.sin_family = AF_INET; + address.sin_port = ntohs(static_cast(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) @@ -113,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) @@ -123,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); } @@ -192,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: @@ -250,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) @@ -340,6 +313,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); } } }; diff --git a/src/client/component/party.cpp b/src/client/component/party.cpp index 7b901bb4..6f711490 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); @@ -153,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) @@ -301,7 +306,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 +314,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); @@ -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; } 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)