mirror of
https://github.com/dashr9230/SA-MP.git
synced 2024-12-22 14:37:29 +08:00
[bot] Implement/match CNetGame::Packet_PlayerSync(...)
* Update `CNetGame::UpdateNetwork()`
This commit is contained in:
parent
3828fa9c01
commit
bf8850b899
18
bot/main.h
18
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)
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user