public static VehicleData ReadPureVehicleSync(byte[] array) { var data = new VehicleData(); var r = new BitReader(array); // Read player nethandle data.NetHandle = r.ReadInt32(); // read health values data.PlayerHealth = r.ReadByte(); data.PedArmor = r.ReadByte(); // read flag data.Flag = r.ReadInt16(); // If we're shooting/aiming, read gun stuff if (CheckBit(data.Flag.Value, VehicleDataFlags.Shooting) || CheckBit(data.Flag.Value, VehicleDataFlags.HasAimData) || CheckBit(data.Flag.Value, VehicleDataFlags.Aiming)) { // read gun model data.WeaponHash = r.ReadInt32(); // read aim coordinates Vector3 aimCoords = new Vector3(); aimCoords.X = r.ReadSingle(); aimCoords.Y = r.ReadSingle(); aimCoords.Z = r.ReadSingle(); data.AimCoords = aimCoords; } // Are we the driver? if (CheckBit(data.Flag.Value, VehicleDataFlags.Driver)) { // Read position, rotation and velocity. Vector3 position = new Vector3(); Vector3 rotation = new Vector3(); Vector3 velocity = new Vector3(); position.X = r.ReadSingle(); position.Y = r.ReadSingle(); position.Z = r.ReadSingle(); rotation.X = r.ReadSingle(); rotation.Y = r.ReadSingle(); rotation.Z = r.ReadSingle(); velocity.X = r.ReadSingle(); velocity.Y = r.ReadSingle(); velocity.Z = r.ReadSingle(); data.Position = position; data.Quaternion = rotation; data.Velocity = velocity; // Read car health data.VehicleHealth = r.ReadInt16(); // read RPM & steering angle byte rpmCompressed = r.ReadByte(); data.RPM = rpmCompressed / (float)byte.MaxValue; byte angleCompressed = r.ReadByte(); var angleDenorm = 120f * (angleCompressed / (float)byte.MaxValue); data.Steering = angleDenorm - 60f; } return(data); }
public static PedData ReadPurePedSync(byte[] array) { var data = new PedData(); var r = new BitReader(array); // Read player nethandle data.NetHandle = r.ReadInt32(); // Read the flag data.Flag = r.ReadInt32(); // Read player position, rotation and velocity Vector3 position = new Vector3(); Vector3 rotation = new Vector3(); Vector3 velocity = new Vector3(); position.X = r.ReadSingle(); position.Y = r.ReadSingle(); position.Z = r.ReadSingle(); // Only read pitchand roll if he's ragdolling if (CheckBit(data.Flag.Value, PedDataFlags.ParachuteOpen)) { rotation.X = r.ReadSingle(); rotation.Y = r.ReadSingle(); } rotation.Z = r.ReadSingle(); velocity.X = r.ReadSingle(); velocity.Y = r.ReadSingle(); velocity.Z = r.ReadSingle(); data.Position = position; data.Quaternion = rotation; data.Velocity = velocity; // Read health, armor and speed data.PlayerHealth = r.ReadByte(); data.PedArmor = r.ReadByte(); data.Speed = r.ReadByte(); // read gun model and ammo data.WeaponHash = r.ReadInt32(); data.WeaponAmmo = r.ReadInt32(); // Is the player shooting? if (CheckBit(data.Flag.Value, PedDataFlags.Aiming) || CheckBit(data.Flag.Value, PedDataFlags.Shooting) || CheckBit(data.Flag.Value, PedDataFlags.HasAimData)) { // read where is he aiming Vector3 aimPoint = new Vector3(); aimPoint.X = r.ReadSingle(); aimPoint.Y = r.ReadSingle(); aimPoint.Z = r.ReadSingle(); data.AimCoords = aimPoint; } if (CheckBit(data.Flag.Value, PedDataFlags.EnteringVehicle)) { data.VehicleTryingToEnter = r.ReadInt32(); data.SeatTryingToEnter = (sbyte)r.ReadByte(); } return(data); }