Merge remote-tracking branch 'origin/main' into dedicated

This commit is contained in:
m 2022-02-28 11:40:42 -06:00
commit b4aef80e5a
4 changed files with 56 additions and 70 deletions

View File

@ -128,7 +128,7 @@ namespace auth
const auto offset = sizeof("connect") + 4; const auto offset = sizeof("connect") + 4;
proto::network::connect_info info; 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'); network::send(*from, "error", "Invalid connect data!", '\n');
return; return;
@ -159,6 +159,7 @@ namespace auth
key.set(info.publickey()); key.set(info.publickey());
const auto xuid = strtoull(steam_id.data(), nullptr, 16); const auto xuid = strtoull(steam_id.data(), nullptr, 16);
if (xuid != key.get_hash()) if (xuid != key.get_hash())
{ {
//MessageBoxA(nullptr, steam_id.data(), std::to_string(key.get_hash()).data(), 0); //MessageBoxA(nullptr, steam_id.data(), std::to_string(key.get_hash()).data(), 0);
@ -228,6 +229,8 @@ namespace auth
// Check for sending connect packet // Check for sending connect packet
utils::hook::set(0x14059A6E0, 0xC301B0); utils::hook::set(0x14059A6E0, 0xC301B0);
// Don't instantly timeout the connecting client ? not sure about this
utils::hook::set(0x14025136B, 0xC3);
} }
command::add("guid", []() command::add("guid", []()

View File

@ -11,8 +11,6 @@
namespace network namespace network
{ {
SOCKET sock;
namespace 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 // 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."); 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<void>(0x1404F6580, net_interface, &address);
}
address.sin_family = AF_INET;
address.sin_port = ntohs(static_cast<short>(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<sockaddr*>(&address), sizeof(address)) != -1)
{
return sock;
}
closesocket(sock);
return 0;
}
} }
void on(const std::string& command, const callback& callback) void on(const std::string& command, const callback& callback)
@ -113,7 +140,7 @@ namespace network
{ {
sockaddr s = {}; sockaddr s = {};
game::NetadrToSockadr(a3, &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) 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.push_back(separator);
packet.append(data); packet.append(data);
#ifdef DEBUG
console::info("[Network] Sending command %s\n", command.data());
#endif
send_data(address, packet); send_data(address, packet);
} }
@ -192,53 +215,6 @@ namespace network
return dvar; 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 class component final : public component_interface
{ {
public: public:
@ -250,9 +226,6 @@ namespace network
return; return;
} }
// creating our own variable for socket use
bind_socket_hook.create(0x140512B40, bind_socket_stub);
// redirect dw_sendto to raw socket // redirect dw_sendto to raw socket
//utils::hook::jump(0x1404D850A, reinterpret_cast<void*>(0x1404D849A)); //utils::hook::jump(0x1404D850A, reinterpret_cast<void*>(0x1404D849A));
utils::hook::call(0x140513467, dw_send_to_stub); // H1MP64(1.4) utils::hook::call(0x140513467, dw_send_to_stub); // H1MP64(1.4)
@ -340,6 +313,10 @@ namespace network
const std::string message{data}; const std::string message{data};
console::info(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);
} }
} }
}; };

View File

@ -71,12 +71,11 @@ namespace party
perform_game_initialization(); perform_game_initialization();
// exit from virtuallobby // exit from virtuallobby
reinterpret_cast<void(*)()>(0x140256D40)(); utils::hook::invoke<void>(0x140256D40, 1);
// CL_ConnectFromParty // CL_ConnectFromParty
char session_info[0x100] = {}; char session_info[0x100] = {};
reinterpret_cast<void(*)(int, char*, const game::netadr_s*, const char*, const char*)>(0x140251560)( utils::hook::invoke<void>(0x140251560, 0, session_info, &target, mapname.data(), gametype.data());
0, session_info, &target, mapname.data(), gametype.data());
} }
std::string get_dvar_string(const std::string& dvar) std::string get_dvar_string(const std::string& dvar)
@ -141,7 +140,7 @@ namespace party
utils::hook::detour cldisconnect_hook; utils::hook::detour cldisconnect_hook;
void cldisconnect_stub(int a1) void cl_disconnect_stub(int a1)
{ {
party::sv_motd.clear(); party::sv_motd.clear();
cldisconnect_hook.invoke<void>(a1); cldisconnect_hook.invoke<void>(a1);
@ -153,6 +152,12 @@ namespace party
a.mov(ecx, 2); a.mov(ecx, 2);
a.jmp(0x140251F78); a.jmp(0x140251F78);
}); });
void menu_error(const std::string& error)
{
utils::hook::invoke<void>(0x1400DACC0, error.data(), "MENU_NOTICE");
utils::hook::set(0x142C1DA98, 1);
}
} }
int get_client_num_by_name(const std::string& name) int get_client_num_by_name(const std::string& name)
@ -301,7 +306,7 @@ namespace party
utils::hook::jump(0x1402521C7, disconnect_stub); utils::hook::jump(0x1402521C7, disconnect_stub);
// detour CL_Disconnect to clear motd // detour CL_Disconnect to clear motd
cldisconnect_hook.create(0x140252060, cldisconnect_stub); cldisconnect_hook.create(0x140252060, cl_disconnect_stub);
if (game::environment::is_mp()) if (game::environment::is_mp())
{ {
@ -309,6 +314,7 @@ namespace party
utils::hook::nop(0x140251EFB, 13); utils::hook::nop(0x140251EFB, 13);
utils::hook::jump(0x140251EFB, drop_reason_stub, true); utils::hook::jump(0x140251EFB, drop_reason_stub, true);
} }
// enable custom kick reason in GScr_KickPlayer // enable custom kick reason in GScr_KickPlayer
utils::hook::set<uint8_t>(0x140376A1D, 0xEB); utils::hook::set<uint8_t>(0x140376A1D, 0xEB);
@ -562,7 +568,7 @@ namespace party
{ {
const auto str = "Invalid challenge."; const auto str = "Invalid challenge.";
printf("%s\n", str); printf("%s\n", str);
game::Com_Error(game::ERR_DROP, str); menu_error(str);
return; return;
} }
@ -571,7 +577,7 @@ namespace party
{ {
const auto str = "Invalid gamename."; const auto str = "Invalid gamename.";
printf("%s\n", str); printf("%s\n", str);
game::Com_Error(game::ERR_DROP, str); menu_error(str);
return; return;
} }
@ -580,7 +586,7 @@ namespace party
{ {
const auto str = "Invalid playmode."; const auto str = "Invalid playmode.";
printf("%s\n", str); printf("%s\n", str);
game::Com_Error(game::ERR_DROP, str); menu_error(str);
return; return;
} }
@ -589,7 +595,7 @@ namespace party
{ {
const auto str = "Server not running."; const auto str = "Server not running.";
printf("%s\n", str); printf("%s\n", str);
game::Com_Error(game::ERR_DROP, str); menu_error(str);
return; return;
} }
@ -598,7 +604,7 @@ namespace party
{ {
const auto str = "Invalid map."; const auto str = "Invalid map.";
printf("%s\n", str); printf("%s\n", str);
game::Com_Error(game::ERR_DROP, str); menu_error(str);
return; return;
} }
@ -607,7 +613,7 @@ namespace party
{ {
const auto str = "Invalid gametype."; const auto str = "Invalid gametype.";
printf("%s\n", str); printf("%s\n", str);
game::Com_Error(game::ERR_DROP, str); menu_error(str);
return; return;
} }

View File

@ -280,7 +280,7 @@ namespace patches
game::Dvar_RegisterInt(0, "scr_game_spectatetype", 1, 0, 99, game::DVAR_FLAG_REPLICATED); 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 // 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 // Prevent clients from sending invalid reliableAcknowledge
// utils::hook::call(0x1404899C6, sv_execute_client_message_stub); // H1(1.4) // utils::hook::call(0x1404899C6, sv_execute_client_message_stub); // H1(1.4)