Further work on WSA after spending a lot of time debugging the proxy

This commit is contained in:
Louvenarde 2026-08-08 13:48:10 +02:00
parent f50b457a8a
commit 9c5c7eab59
4 changed files with 38 additions and 10 deletions

View file

@ -126,7 +126,9 @@ typedef struct netpacket_s
{
netadr_t adr; // sender address
// int source; // received source
char unk[10];
char unk[2];
uint32_t sockIndex;
uint32_t unk3;
double received_time;
unsigned char* data; // pointer to raw packet data
void* message; // easy bitbuf data access // 'inpacket.message' etc etc (pointer)
@ -141,6 +143,22 @@ typedef struct netpacket_s
} netpacket_t;
#pragma pack(pop)
static_assert(offsetof(netpacket_s, sockIndex) == 24);
#pragma pack(push, 1)
struct netsocket_t
{
char pad[8];
uint32_t receiveSocket;
uint32_t sendSocket;
uint64_t unk1;
};
#pragma pack(pop)
static_assert(offsetof(netsocket_t, receiveSocket) == 8);
static_assert(offsetof(netsocket_t, sendSocket) == 12);
static_assert(sizeof(netsocket_t) == 24);
// #56169 $DB69 PData size
// #512 $200 Trailing data
// #100 $64 Safety buffer

View file

@ -255,6 +255,18 @@ ON_DLL_LOAD("engine.dll", EngineProxy, (CModule module))
if (g_LanMode->Enabled())
{
g_originProxy = new OriginProxy;
// "Return NULLPTR" on a function that is a prerequisite to all HTTP CURL requests
module.Offset(0x16F250 + 0xC00).Patch({0x33, 0xC0, 0xC3});
#if DEBUG
// Extensive net task logging, not sure how to turn it on "the normal way"
module.Offset(0x25F5BC + 0xC00).NOP(2);
module.Offset(0x27839E + 0xC00).NOP(6);
module.Offset(0x25F51F + 0xC00).NOP(2);
module.Offset(0x2628E9 + 0xC00).NOP(2);
module.Offset(0x262FD1 + 0xC00).NOP(2);
module.Offset(0x265BCB + 0xC00).NOP(2);
#endif
}
}
@ -262,6 +274,8 @@ OriginProxy::OriginProxy()
{
CModule engineModule("engine.dll");
this->originLastErrorPtr = engineModule.Offset(0x13978264).RCast<const OriginProxy::OriginError_t*>();
this->g_wsaLastError = module.Offset(0x7FFB2C652DD0 - 0x7FFB186B0000).RCast<uint32_t*>();
// Windows-centric username, is there another way?
{

View file

@ -137,6 +137,8 @@ private:
const OriginError_t* originLastErrorPtr = nullptr;
const uint32_t* g_wsaLastError = nullptr;
static_assert(offsetof(OriginGetProfileResult_t, PersonaId) == 8);
static_assert(offsetof(OriginGetProfileResult_t, Persona) == 16); // 64 chars
static_assert(offsetof(OriginGetProfileResult_t, AvatarId) == 24); // 260 Chars

View file

@ -453,23 +453,16 @@ bool, __fastcall, (void* a1))
// Pasted from R1Delta: (https://github.com/r1delta/r1delta/blob/f04cc67e6247c5e15633b95f84fc69eca7252dc6/engine/security_fixes.cpp#L811)
// (thanks wanderer)
// clang-format off
AUTOHOOK(NET_ReceiveDatagram, engine.dll + 0x21B520, bool, __fastcall, (SOCKET sock, netpacket_t* packet, bool encrypted))
AUTOHOOK(NET_ReceiveDatagram, engine.dll + 0x21B520, bool, __fastcall, (uint32_t sockIndex, netpacket_t* packet, bool encrypted))
// clang-format on
{
sockaddr name {};
int nameLength;
getsockname(sock, &name, &nameLength);
if (WSAGetLastError() == 10038)
{
return false;
}
for (int i = Cvar_ns_recvfrom_per_frame_limit->GetInt(); i > 0; i--)
{
if (net_error)
*net_error = 0;
if (NET_ReceiveDatagram(sock, packet, encrypted))
if (NET_ReceiveDatagram(sockIndex, packet, encrypted))
return true;
if (net_error && *net_error)
@ -482,6 +475,7 @@ AUTOHOOK(NET_ReceiveDatagram, engine.dll + 0x21B520, bool, __fastcall, (SOCKET s
ON_DLL_LOAD("engine.dll", EngineExploitFixes, (CModule module))
{
AUTOHOOK_DISPATCH_MODULE(engine.dll)
g_ExecutionMarkerCount = module.Offset(0x130DE8F0).RCast<int*>();
net_error = module.Offset(0x13FA2DD0).RCast<int*>();