public static VehicleData ReadUnoccupiedVehicleSync(byte[] array)
        {
            var r    = new BitReader(array);
            var data = new VehicleData();

            // Read vehicle's nethandle.
            data.VehicleHandle = r.ReadInt32();

            // 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 vehicle health
            data.VehicleHealth = r.ReadInt16();

            // Read is dead
            if (r.ReadBoolean())
            {
                data.Flag = (short)VehicleDataFlags.VehicleDead;
            }
            else
            {
                data.Flag = 0;
            }

            // Read tyre states
            data.PlayerHealth = r.ReadByte();

            // Read vehicle damage model
            data.DamageModel               = new VehicleDamageModel();
            data.DamageModel.BrokenDoors   = r.ReadByte();
            data.DamageModel.BrokenWindows = r.ReadByte();

            return(data);
        }
        public static VehicleData ReadLightVehicleSync(byte[] array)
        {
            var data = new VehicleData();
            var r    = new BitReader(array);

            // Read player nethandle
            data.NetHandle = r.ReadInt32();

            // read model
            data.PedModelHash = r.ReadInt32();

            // read vehicle handle
            data.VehicleHandle = r.ReadInt32();

            // read vehicle seat
            data.VehicleSeat = (sbyte)r.ReadByte();

            // read gun model.
            data.WeaponHash = r.ReadInt32();

            // Read vehicle damage model
            if (r.ReadBoolean())
            {
                data.DamageModel               = new VehicleDamageModel();
                data.DamageModel.BrokenDoors   = r.ReadByte();
                data.DamageModel.BrokenWindows = r.ReadByte();
                data.DamageModel.BrokenLights  = r.ReadInt32();
            }

            // Does he have a traielr?
            if (r.ReadBoolean())
            {
                Vector3 trailerPos = new Vector3();

                trailerPos.X = r.ReadSingle();
                trailerPos.Y = r.ReadSingle();
                trailerPos.Z = r.ReadSingle();

                data.Trailer = trailerPos;
            }

            // Try to read latency
            if (r.CanRead(2))
            {
                var latency = r.ReadInt16();
                data.Latency = latency / 1000f;
            }

            return(data);
        }
        public static PedData ReadLightPedSync(byte[] array)
        {
            var data = new PedData();
            var r    = new BitReader(array);

            // Read player nethandle
            data.NetHandle = r.ReadInt32();

            // Read player model
            data.PedModelHash = r.ReadInt32();

            // If we can, read latency

            if (r.CanRead(2))
            {
                var latency = r.ReadInt16();

                data.Latency = latency / 1000f;
            }

            return(data);
        }
        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);
        }