[Network]: Better patch (#1032)

This commit is contained in:
Edo 2023-05-12 22:35:31 +01:00 committed by GitHub
parent 2805c3fb2f
commit 9e036e5174
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 34 deletions

View File

@ -319,33 +319,6 @@ namespace Components
}
}
int Network::Sys_StringToSockaddr_Hk(const char* s, sockaddr* sadr)
{
hostent* h;
ZeroMemory(sadr, sizeof(*sadr));
((sockaddr_in*)sadr)->sin_family = AF_INET;
((sockaddr_in*)sadr)->sin_port = 0;
if (Game::I_isdigit(*s))
{
// ReSharper disable once CppDeprecatedEntity
*(int*)&((sockaddr_in*)sadr)->sin_addr = static_cast<int>(::inet_addr(s));
}
else
{
// ReSharper disable once CppDeprecatedEntity
if ((h = ::gethostbyname(s)) == nullptr)
{
return false;
}
*(int*)&((sockaddr_in*)sadr)->sin_addr = *(int*)h->h_addr_list[0];
}
return true;
}
Network::Network()
{
AssertSize(Game::netadr_t, 20);
@ -376,10 +349,6 @@ namespace Components
// Handle client packets
Utils::Hook(0x5AA703, CL_HandleCommandStub, HOOK_JUMP).install()->quick();
// Use the version of Sys_StringToSockaddr made by 3arc
Utils::Hook(0x44E23C, Sys_StringToSockaddr_Hk, HOOK_CALL).install()->quick();
Utils::Hook(0x64D480, Sys_StringToSockaddr_Hk, HOOK_CALL).install()->quick();
// Disable unused OOB packets handlers just to be sure
Utils::Hook::Set<std::uint8_t>(0x5AA5B6, 0xEB); // CL_SteamServerAuth
Utils::Hook::Set<std::uint8_t>(0x5AA69F, 0xEB); // echo
@ -411,8 +380,13 @@ namespace Components
// Do not run UPNP stuff at all
Utils::Hook::Set<std::uint8_t>(0x48A135, 0xC3);
Utils::Hook::Nop(0x48A135 + 1, 4);
Utils::Hook::Set<std::uint8_t>(0x48A151, 0xC3);
Utils::Hook::Nop(0x684080, 5); // Don't spam the console
Utils::Hook::Nop(0x48A151 + 1, 4);
// Don't spam the console
Utils::Hook(0x684080, Game::Com_DPrintf, HOOK_CALL).install()->quick();
// Disable the IWNet IP detection (default 'got ipdetect' flag to 1)
Utils::Hook::Set<std::uint8_t>(0x649D6F0, 1);

View File

@ -81,8 +81,6 @@ namespace Components
static bool CL_HandleCommand(Game::netadr_t* address, const char* command, Game::msg_t* message);
static void CL_HandleCommandStub();
static int Sys_StringToSockaddr_Hk(const char* s, sockaddr* sadr);
};
}

View File

@ -9,6 +9,7 @@ namespace Game
Com_Error_t Com_Error = Com_Error_t(0x4B22D0);
Com_Printf_t Com_Printf = Com_Printf_t(0x402500);
Com_DPrintf_t Com_DPrintf = Com_DPrintf_t(0x413490);
Com_PrintError_t Com_PrintError = Com_PrintError_t(0x4F8C70);
Com_PrintWarning_t Com_PrintWarning = Com_PrintWarning_t(0x4E0200);
Com_PrintMessage_t Com_PrintMessage = Com_PrintMessage_t(0x4AA830);

View File

@ -20,6 +20,9 @@ namespace Game
typedef void(*Com_Printf_t)(int channel, const char* fmt, ...);
extern Com_Printf_t Com_Printf;
typedef void(*Com_DPrintf_t)(int channel, const char* fmt, ...);
extern Com_DPrintf_t Com_DPrintf;
typedef void(*Com_PrintError_t)(int channel, const char* fmt, ...);
extern Com_PrintError_t Com_PrintError;