From bf8850b899da6b65f596a26d558d948f397622d1 Mon Sep 17 00:00:00 2001 From: RD42 <42702181+dashr9230@users.noreply.github.com> Date: Sun, 6 Oct 2024 22:26:53 +0800 Subject: [PATCH] [bot] Implement/match `CNetGame::Packet_PlayerSync(...)` * Update `CNetGame::UpdateNetwork()` --- bot/main.h | 18 ++++++++-- bot/net/netgame.cpp | 86 +++++++++++++++++++++++++++++++++++++++++++++ bot/net/netgame.h | 1 + 3 files changed, 102 insertions(+), 3 deletions(-) diff --git a/bot/main.h b/bot/main.h index 4d59b77..42d12a0 100644 --- a/bot/main.h +++ b/bot/main.h @@ -69,6 +69,17 @@ char* strlwr(char* str); #define SPECIAL_ACTION_NONE 0 +#define PLAYER_STATE_NONE 0 +#define PLAYER_STATE_ONFOOT 1 +#define PLAYER_STATE_DRIVER 2 +#define PLAYER_STATE_PASSENGER 3 +#define PLAYER_STATE_EXIT_VEHICLE 4 +#define PLAYER_STATE_ENTER_VEHICLE_DRIVER 5 +#define PLAYER_STATE_ENTER_VEHICLE_PASSENGER 6 +#define PLAYER_STATE_WASTED 7 +#define PLAYER_STATE_SPAWNED 8 +#define PLAYER_STATE_SPECTATING 9 + #pragma pack(1) typedef struct _PLAYER_SPAWN_INFO { @@ -94,9 +105,10 @@ typedef struct _ONFOOT_SYNC_DATA BYTE byteCurrentWeapon : 6; BYTE byteSpecialKey : 2; BYTE byteSpecialAction; - - char _gap26[30]; - + VECTOR vecMoveSpeed; + VECTOR vecSurfOffsets; + WORD wSurfInfo; + DWORD field_40; } ONFOOT_SYNC_DATA; #pragma pack(1) diff --git a/bot/net/netgame.cpp b/bot/net/netgame.cpp index 986f113..fbf369a 100644 --- a/bot/net/netgame.cpp +++ b/bot/net/netgame.cpp @@ -646,6 +646,9 @@ void CNetGame::UpdateNetwork() case ID_CONNECTION_REQUEST_ACCEPTED: Packet_ConnectionSucceeded(pkt); break; + case ID_PLAYER_SYNC: + Packet_PlayerSync(pkt); + break; case ID_PASSENGER_SYNC: Packet_PassengerSync(pkt); break; @@ -665,6 +668,89 @@ void CNetGame::UpdateNetwork() // PACKET HANDLERS INTERNAL //---------------------------------------------------- +void CNetGame::Packet_PlayerSync(Packet *p) +{ + RakNet::BitStream bsPlayerSync((PCHAR)p->data, p->length, false); + ONFOOT_SYNC_DATA ofSync; + BYTE bytePacketID=0; + PLAYERID playerId=0; + + bool bHasLR,bHasUD; + bool bHasSurfingInfo; + bool bUnk; + + if(GetGameState() != GAMESTATE_CONNECTED) return; + + memset(&ofSync,0,sizeof(ONFOOT_SYNC_DATA)); + + bsPlayerSync.Read(bytePacketID); + bsPlayerSync.Read(playerId); + + // LEFT/RIGHT KEYS + bsPlayerSync.Read(bHasLR); + if(bHasLR) bsPlayerSync.Read(ofSync.lrAnalog); + + // UP/DOWN KEYS + bsPlayerSync.Read(bHasUD); + if(bHasUD) bsPlayerSync.Read(ofSync.udAnalog); + + // GENERAL KEYS + bsPlayerSync.Read(ofSync.wKeys); + + // VECTOR POS + bsPlayerSync.Read((char*)&ofSync.vecPos,sizeof(VECTOR)); + + // ROTATION + bsPlayerSync.ReadNormQuat(ofSync.quatRotation.W,ofSync.quatRotation.X,ofSync.quatRotation.Y,ofSync.quatRotation.Z); + + // HEALTH/ARMOUR (COMPRESSED INTO 1 BYTE) + BYTE byteHealthArmour; + BYTE byteArmTemp=0,byteHlTemp=0; + + bsPlayerSync.Read(byteHealthArmour); + byteArmTemp = (byteHealthArmour & 0x0F); + byteHlTemp = (byteHealthArmour >> 4); + + if(byteArmTemp == 0xF) ofSync.byteArmour = 100; + else if(byteArmTemp == 0) ofSync.byteArmour = 0; + else ofSync.byteArmour = byteArmTemp * 7; + + if(byteHlTemp == 0xF) ofSync.byteHealth = 100; + else if(byteHlTemp == 0) ofSync.byteHealth = 0; + else ofSync.byteHealth = byteHlTemp * 7; + + // CURRENT WEAPON + BYTE byteCurrentWeapon=0; + bsPlayerSync.Read(byteCurrentWeapon); + ofSync.byteCurrentWeapon = byteCurrentWeapon; + + // Special Action + bsPlayerSync.Read(ofSync.byteSpecialAction); + + // READ MOVESPEED VECTORS + bsPlayerSync.ReadVector(ofSync.vecMoveSpeed.X,ofSync.vecMoveSpeed.Y,ofSync.vecMoveSpeed.Z); + + bsPlayerSync.Read(bHasSurfingInfo); + if(bHasSurfingInfo) { + bsPlayerSync.Read(ofSync.wSurfInfo); + bsPlayerSync.Read((char*)&ofSync.vecSurfOffsets,sizeof(VECTOR)); + } else { + ofSync.wSurfInfo = 0xFFFF; + } + + bsPlayerSync.Read(bUnk); + if(bUnk) bsPlayerSync.Read(ofSync.field_40); + else ofSync.field_40 = 0; + + if(playerId < MAX_PLAYERS) + { + memcpy(&unnamed_3[playerId],&ofSync,sizeof(ONFOOT_SYNC_DATA)); + bytePlayerState[playerId] = PLAYER_STATE_ONFOOT; + } +} + +//---------------------------------------------------- + void CNetGame::Packet_AimSync(Packet *p) { RakNet::BitStream bsAimSync((PCHAR)p->data, p->length, false); diff --git a/bot/net/netgame.h b/bot/net/netgame.h index 264a750..70c400e 100644 --- a/bot/net/netgame.h +++ b/bot/net/netgame.h @@ -23,6 +23,7 @@ private: // Packet handlers void Packet_AimSync(Packet *p); + void Packet_PlayerSync(Packet *p); void Packet_PassengerSync(Packet *p); void Packet_ConnectionSucceeded(Packet *p); void Packet_RSAPublicKeyMismatch(Packet* packet);