public static byte[] WriteLightSync(PedData data)
        {
            List <byte> byteArray = new List <byte>();

            // Write player's nethandle.
            if (data.NetHandle.HasValue)
            {
                byteArray.AddRange(GetBytes(data.NetHandle.Value));
            }
            else
            {
                byteArray.Add(0x00);
                byteArray.Add(0x00);
                byteArray.Add(0x00);
                byteArray.Add(0x00);
            }

            // Write player model
            byteArray.AddRange(GetBytes(data.PedModelHash.Value));

            // Write player's latency
            if (data.Latency.HasValue)
            {
                var latency = data.Latency.Value * 1000;
                byteArray.AddRange(GetBytes((short)latency));
            }

            return(byteArray.ToArray());
        }
        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 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);
        }
        public static byte[] WritePureSync(PedData data)
        {
            List <byte> byteArray = new List <byte>();

            // Write player's nethandle.
            if (data.NetHandle.HasValue)
            {
                byteArray.AddRange(GetBytes(data.NetHandle.Value));
            }
            else
            {
                byteArray.Add(0x00);
                byteArray.Add(0x00);
                byteArray.Add(0x00);
                byteArray.Add(0x00);
            }

            // Write the flag
            byteArray.AddRange(GetBytes(data.Flag.Value));

            // Write player's position, rotation, and velocity
            byteArray.AddRange(GetBytes(data.Position.X));
            byteArray.AddRange(GetBytes(data.Position.Y));
            byteArray.AddRange(GetBytes(data.Position.Z));

            // Only send roll & pitch if we're parachuting.
            if (CheckBit(data.Flag.Value, PedDataFlags.ParachuteOpen))
            {
                byteArray.AddRange(GetBytes(data.Quaternion.X));
                byteArray.AddRange(GetBytes(data.Quaternion.Y));
            }

            byteArray.AddRange(GetBytes(data.Quaternion.Z));

            byteArray.AddRange(GetBytes(data.Velocity.X));
            byteArray.AddRange(GetBytes(data.Velocity.Y));
            byteArray.AddRange(GetBytes(data.Velocity.Z));

            // Write player health, armor and walking speed
            byteArray.Add(data.PlayerHealth.Value);
            byteArray.Add(data.PedArmor.Value);
            byteArray.Add(data.Speed.Value);


            // Write current weapon hash.
            byteArray.AddRange(GetBytes(data.WeaponHash.Value));
            byteArray.AddRange(GetBytes(data.WeaponAmmo.Value));

            // Are we shooting?
            if (CheckBit(data.Flag.Value, PedDataFlags.Aiming) ||
                CheckBit(data.Flag.Value, PedDataFlags.Shooting) ||
                CheckBit(data.Flag.Value, PedDataFlags.HasAimData))
            {
                // Aim coordinates
                byteArray.AddRange(GetBytes(data.AimCoords.X));
                byteArray.AddRange(GetBytes(data.AimCoords.Y));
                byteArray.AddRange(GetBytes(data.AimCoords.Z));
            }

            // Are we entering a car?
            if (CheckBit(data.Flag.Value, PedDataFlags.EnteringVehicle))
            {
                // Add the car we are trying to enter
                byteArray.AddRange(GetBytes(data.VehicleTryingToEnter.Value));

                // Add the seat we are trying to enter
                byteArray.Add((byte)data.SeatTryingToEnter.Value);
            }

            return(byteArray.ToArray());
        }