Merge pull request #555 from diamante0018/main

network: improve a patch
This commit is contained in:
Maurice Heumann 2023-04-18 12:35:40 +02:00 committed by GitHub
commit 213a2632d4
4 changed files with 86 additions and 63 deletions

View File

@ -163,7 +163,6 @@ namespace network
: 0;
}
uint64_t ret2()
{
return 2;
@ -173,6 +172,15 @@ namespace network
{
return 0;
}
void com_error_oob_stub(const char* file, int line, int code, [[maybe_unused]] const char* fmt, const char* error)
{
char buffer[1024]{};
strncpy_s(buffer, error, _TRUNCATE);
game::Com_Error_(file, line, code, "%s", buffer);
}
}
void on(const std::string& command, const callback& callback)
@ -321,10 +329,21 @@ namespace network
// NA_IP -> NA_RAWIP in NetAdr_ToString
utils::hook::set<uint8_t>(game::select(0x142172ED4, 0x140515864), game::NA_RAWIP);
// Kill 'echo' OOB handler
utils::hook::set<uint8_t>(game::select(0x14134D0FB, 0x14018EE82), 0xEB);
if (game::is_server())
{
// Remove restrictions for rcon commands
utils::hook::call(0x140538D5C_g, &con_restricted_execute_buf_stub); // SVC_RemoteCommand
utils::hook::call(0x140538D5C_g, con_restricted_execute_buf_stub); // SVC_RemoteCommand
// Kill 'error' OOB handler on the dedi
utils::hook::nop(0x14018EF8B_g, 5);
}
else
{
// Truncate error string to make sure there are no buffer overruns later
utils::hook::call(0x14134D206_g, com_error_oob_stub);
}
// TODO: Fix that

View File

@ -1,66 +1,68 @@
#include <std_include.hpp>
#include "loader/component_loader.hpp"
#include <game/game.hpp>
#include <game/utils.hpp>
#include "scheduler.hpp"
#include <utils/hook.hpp>
namespace patches
{
namespace
{
utils::hook::detour sv_executeclientmessages_hook;
#include <std_include.hpp>
#include "loader/component_loader.hpp"
void sv_executeclientmessages_stub(game::client_s* client, game::msg_t* msg)
{
#include <game/game.hpp>
#include <game/utils.hpp>
#include "network.hpp"
#include "scheduler.hpp"
#include <utils/hook.hpp>
namespace patches
{
namespace
{
utils::hook::detour sv_execute_client_messages_hook;
void sv_execute_client_messages_stub(game::client_s* client, game::msg_t* msg)
{
if (client->reliableAcknowledge < 0)
{
client->reliableAcknowledge = client->reliableSequence;
network::send(client->address, "error", "EXE_LOSTRELIABLECOMMANDS");
return;
}
sv_executeclientmessages_hook.invoke<void>(client, msg);
sv_execute_client_messages_hook.invoke<void>(client, msg);
}
void script_errors_stub(const char* file, int line, unsigned int code, const char* fmt, ...)
{
char buffer[0x1000];
{
va_list ap;
va_start(ap, fmt);
vsnprintf_s(buffer, sizeof(buffer), _TRUNCATE, fmt, ap);
va_end(ap);
}
game::Com_Error(game::ERROR_SCRIPT_DROP, "%s", buffer);
}
}
struct component final : generic_component
{
void post_unpack() override
{
// don't make script errors fatal error
utils::hook::call(game::select(0x1412CAC4D, 0x140158EB2), script_errors_stub);
// Change 4 character name limit to 3 characters
utils::hook::set<uint8_t>(game::select(0x14224DA53, 0x140531143), 3);
utils::hook::set<uint8_t>(game::select(0x14224DBB4, 0x1405312A8), 3);
void script_errors_stub(const char* file, int line, unsigned int code, const char* fmt, ...)
{
char buffer[0x1000];
{
va_list ap;
va_start(ap, fmt);
vsnprintf_s(buffer, sizeof(buffer), _TRUNCATE, fmt, ap);
va_end(ap);
}
game::Com_Error(game::ERROR_SCRIPT_DROP, "%s", buffer);
}
}
struct component final : generic_component
{
void post_unpack() override
{
// don't make script errors fatal error
utils::hook::call(game::select(0x1412CAC4D, 0x140158EB2), script_errors_stub);
// Change 4 character name limit to 3 characters
utils::hook::set<uint8_t>(game::select(0x14224DA53, 0x140531143), 3);
utils::hook::set<uint8_t>(game::select(0x14224DBB4, 0x1405312A8), 3);
utils::hook::set<uint8_t>(game::select(0x14224DF8C, 0x1405316DC), 3);
// make sure client's reliableAck are not negative
sv_executeclientmessages_hook.create(game::select(0x14224A460, 0x14052F840), sv_executeclientmessages_stub);
scheduler::once([]
{
game::register_dvar_string("password", "", game::DVAR_USERINFO, "password");
}, scheduler::pipeline::main);
}
};
}
REGISTER_COMPONENT(patches::component)
sv_execute_client_messages_hook.create(game::select(0x14224A460, 0x14052F840), sv_execute_client_messages_stub);
scheduler::once([]
{
game::register_dvar_string("password", "", game::DVAR_USERINFO, "password");
}, scheduler::pipeline::main);
}
};
}
REGISTER_COMPONENT(patches::component)

View File

@ -1583,20 +1583,20 @@ namespace game
int client_state;
char __pad0[0x28];
netadr_t address;
char gap_3C[20468];
char __pad1[20468];
int reliableSequence;
int reliableAcknowledge;
char gap_5038[4];
char __pad2[4];
int messageAcknowledge;
char gap_5040[1416];
uint64_t xuid;
char __pad2[0xB5D84];
char __pad3[0xB5D84];
int guid;
char __pad3[0x8];
char __pad4[0x8];
bool bIsTestClient;
char gap_BB361[3];
char __pad5[3];
int serverId;
char gap_BB368[171432];
char __pad6[171432];
};

View File

@ -78,6 +78,8 @@ namespace game
// G
WEAK symbol<void()> G_ClearVehicleInputs{0x1423812E0, 0x1405C1200};
WEAK symbol<qboolean(void* ent)> StuckInClient{0x1415A8360, 0x14023BFE0};
// Live
WEAK symbol<bool(uint64_t, int*, bool)> Live_GetConnectivityInformation{0x141E0C380};