コード例 #1
0
 protected void WriteByteSeq(StreamHandler writer, byte b)
 {
     writer.FlushUnalignedBits();
     if (b != 0)
     {
         writer.WriteByte((byte)(b ^ 1));
     }
 }
コード例 #2
0
 protected override void ElementWrite(StreamHandler writer, int index)
 {
     if (index == -2)
     {
         writer.FlushUnalignedBits();
         writer.WriteUInt32(this.NewValue);
     }
     else
         base.ElementWrite(writer, index);
 }
コード例 #3
0
 protected override void WriteElement(StreamHandler writer, RegularMovementPacket.MovementStatusElements element, MovementStatus status, byte[] guid, byte[] tguid)
 {
     if (element == MovementStatusElements.GenericDword2)
     {
         writer.FlushUnalignedBits();
         writer.WriteSingle(this.NewValue);
     }
     else
         base.WriteElement(writer, element, status, guid, tguid);
 }
コード例 #4
0
ファイル: ForceAckPacket.cs プロジェクト: SkyFire/Kamilla.Wow
 protected override void WriteElement(StreamHandler writer, RegularMovementPacket.MovementStatusElements element, MovementStatus status, byte[] guid, byte[] tguid)
 {
     if (element == MovementStatusElements.GenericDword0)
     {
         writer.FlushUnalignedBits();
         writer.WriteUInt32(this.ChangeCounter);
     }
     else
         base.WriteElement(writer, element, status, guid, tguid);
 }
コード例 #5
0
ファイル: ForcePacket.cs プロジェクト: SkyFire/Kamilla.Wow
 protected override void ElementWrite(StreamHandler writer, int index)
 {
     if (index == -1)
     {
         writer.FlushUnalignedBits();
         writer.WriteUInt32(this.ChangeCounter);
     }
     else
         throw new InvalidOperationException("Unknown write element: " + index);
 }
コード例 #6
0
 protected override void WriteElement(StreamHandler writer, RegularMovementPacket.MovementStatusElements element, MovementStatus status, byte[] guid, byte[] tguid)
 {
     if (element == MovementStatusElements.GenericDword0)
     {
         writer.FlushUnalignedBits();
         writer.WriteUInt32(this.ChangeCounter);
     }
     else
     {
         base.WriteElement(writer, element, status, guid, tguid);
     }
 }
コード例 #7
0
 protected override void ElementWrite(StreamHandler writer, int index)
 {
     if (index == -2)
     {
         writer.FlushUnalignedBits();
         writer.WriteUInt32(this.NewValue);
     }
     else
     {
         base.ElementWrite(writer, index);
     }
 }
コード例 #8
0
ファイル: ForcePacket.cs プロジェクト: Torpedoes/Kamilla.Wow
 protected override void ElementWrite(StreamHandler writer, int index)
 {
     if (index == -1)
     {
         writer.FlushUnalignedBits();
         writer.WriteUInt32(this.ChangeCounter);
     }
     else
     {
         throw new InvalidOperationException("Unknown write element: " + index);
     }
 }
コード例 #9
0
 protected void WriteByteSeq(StreamHandler writer, byte b)
 {
     writer.FlushUnalignedBits();
     if (b != 0)
         writer.WriteByte((byte)(b ^ 1));
 }
コード例 #10
0
ファイル: MovementInfo.cs プロジェクト: CarlosX/Kamilla.Wow
        public unsafe void Save(StreamHandler Writer)
        {
            var guid = this.Guid;

            Writer
                .UnalignedWriteBit(this.HaveAttackingTarget)
                .UnalignedWriteBit(guid.Bytes[2] != 0)
                .UnalignedWriteBit(this.HaveVehicleData)
                .UnalignedWriteBit(guid.Bytes[1] != 0)
                .UnalignedWriteBit(guid.Bytes[4] != 0)
                .UnalignedWriteBit(guid.Bytes[3] != 0)
                .UnalignedWriteBit(this.HaveTransportTime)
                .UnalignedWriteBit(this.HaveGameObjectPosition)
                .UnalignedWriteBit(false) // TODO
                .UnalignedWriteBit(false) // TODO
                .UnalignedWriteBit(this.HaveGameObjectRotation)
                .UnalignedWriteBit(this.Living)
                .UnalignedWriteBit(this.HavePosition)
                .UnalignedWriteInt((uint)this.UnkUInt32.Length, 24)
                .UnalignedWriteBit(guid.Bytes[0] != 0)
                ;

            var p_guid = this.Guid;

            if (this.Living)
            {
                Writer.UnalignedWriteBit(this.HaveTransportData);
                if (this.HaveTransportData)
                {
                    fixed (byte* bytes = this.TransportGuid.Bytes)
                    {
                        Writer
                            .UnalignedWriteBit(bytes[2] != 0)
                            .UnalignedWriteBit(bytes[7] != 0)
                            .UnalignedWriteBit(bytes[5] != 0)
                            .UnalignedWriteBit(this.HaveTransportTime3)
                            .UnalignedWriteBit(bytes[3] != 0)
                            .UnalignedWriteBit(bytes[0] != 0)
                            .UnalignedWriteBit(bytes[4] != 0)
                            .UnalignedWriteBit(bytes[1] != 0)
                            .UnalignedWriteBit(this.HaveTransportTime2)
                            .UnalignedWriteBit(bytes[6] != 0);
                    }
                }

                Writer
                    .UnalignedWriteBit(this.HaveSpline2)
                    .UnalignedWriteBit(p_guid.Bytes[7] != 0)
                    .UnalignedWriteBit(p_guid.Bytes[6] != 0)
                    .UnalignedWriteBit(p_guid.Bytes[5] != 0)
                    .UnalignedWriteBit(p_guid.Bytes[2] != 0)
                    .UnalignedWriteBit(p_guid.Bytes[4] != 0)
                    .UnalignedWriteBit(!(this.Flags != 0))
                    .UnalignedWriteBit(p_guid.Bytes[1] != 0)
                    .UnalignedWriteBit(this.SelfTarget)
                    .UnalignedWriteBit(!(this.TimeStamp != 0))
                    .UnalignedWriteBit(!(this.Flags2 != 0));

                if (this.HaveSpline2)
                {
                    Writer.UnalignedWriteBit(this.HaveSpline);
                    if (this.HaveSpline)
                    {
                        Writer
                            .UnalignedWriteBit(this.Spline.HaveDurationMultiplier)
                            .UnalignedWriteInt((uint)this.Spline.Flags, 25)
                            .UnalignedWriteInt((byte)this.Spline.SplineMode, 2)
                            .UnalignedWriteBit(this.Spline.HaveUnknown1)
                            .UnalignedWriteInt((uint)this.Spline.Points.Count, 22);

                        byte v;
                        switch (this.Spline.SplineType)
                        {
                            case SplineType.FacingSpot:
                                v = 0;
                                break;
                            case SplineType.Normal:
                                v = 1;
                                break;
                            case SplineType.FacingTarget:
                                v = 2;
                                break;
                            case SplineType.FacingAngle:
                                v = 3;
                                break;
                            default:
                                throw new InvalidOperationException();
                        }
                        Writer.UnalignedWriteInt(v, 2);

                        if (this.Spline.SplineType == SplineType.FacingTarget)
                        {
                            fixed (byte* bytes = this.Spline.FacingTarget.Bytes)
                            {
                                Writer
                                    .UnalignedWriteBit(bytes[7] != 0)
                                    .UnalignedWriteBit(bytes[3] != 0)
                                    .UnalignedWriteBit(bytes[4] != 0)
                                    .UnalignedWriteBit(bytes[2] != 0)
                                    .UnalignedWriteBit(bytes[1] != 0)
                                    .UnalignedWriteBit(bytes[6] != 0)
                                    .UnalignedWriteBit(bytes[0] != 0)
                                    .UnalignedWriteBit(bytes[5] != 0);
                            }
                        }
                    }
                }

                Writer
                    .UnalignedWriteBit(p_guid.Bytes[3] != 0);

                if (this.Flags != 0)
                    Writer.UnalignedWriteInt((uint)this.Flags, 30);

                Writer
                    .UnalignedWriteBit(!this.HavePitch)
                    .UnalignedWriteBit(this.HaveFallData);
                if (this.Flags2 != 0)
                    Writer.UnalignedWriteInt((ushort)this.Flags2, 12);
                Writer
                    .UnalignedWriteBit(p_guid.Bytes[0] != 0)
                    .UnalignedWriteBit(!(this.Orientation != 0.0f)); // !haveOrient

                if (this.HaveFallData)
                    Writer.UnalignedWriteBit(this.HaveFallDirection);

                Writer.UnalignedWriteBit(!this.HaveSplineElevation);
            }

            if (this.HaveGameObjectPosition)
            {
                fixed (byte* bytes = this.TransportGuid.Bytes)
                {
                    Writer
                        .UnalignedWriteBit(bytes[1] != 0)
                        .UnalignedWriteBit(this.HaveTransportTime3)
                        .UnalignedWriteBit(bytes[3] != 0)
                        .UnalignedWriteBit(bytes[2] != 0)
                        .UnalignedWriteBit(bytes[6] != 0)
                        .UnalignedWriteBit(bytes[5] != 0)
                        .UnalignedWriteBit(bytes[0] != 0)
                        .UnalignedWriteBit(bytes[4] != 0)
                        .UnalignedWriteBit(this.HaveTransportTime2)
                        .UnalignedWriteBit(bytes[7] != 0);
                }
            }

            // TODO: shorts here

            if (this.HaveAttackingTarget)
            {
                fixed (byte* bytes = this.AttackingTarget.Bytes)
                {
                    Writer
                        .UnalignedWriteBit(bytes[3] != 0)
                        .UnalignedWriteBit(bytes[4] != 0)
                        .UnalignedWriteBit(bytes[6] != 0)
                        .UnalignedWriteBit(bytes[0] != 0)
                        .UnalignedWriteBit(bytes[1] != 0)
                        .UnalignedWriteBit(bytes[7] != 0)
                        .UnalignedWriteBit(bytes[5] != 0)
                        .UnalignedWriteBit(bytes[2] != 0);
                }
            }

            Writer.FlushUnalignedBits();

            foreach (var val in this.UnkUInt32)
                Writer.WriteUInt32(val);

            if (this.HavePosition)
            {
                Writer
                    .WriteSingle(this.Position.Z)
                    .WriteSingle(this.Orientation)
                    .WriteSingle(this.Position.X)
                    .WriteSingle(this.Position.Y);
            }

            if (this.HaveVehicleData)
            {
                Writer
                    .WriteUInt32(this.VehicleId)
                    .WriteSingle(this.VehicleAimAdjustement);
            }

            if (this.HaveGameObjectPosition)
            {
                fixed (byte* bytes = this.TransportGuid.Bytes)
                {
                    Writer
                        .WriteXorByte(bytes[1])
                        .WriteXorByte(bytes[4])
                        .WriteSingle(this.TransportPosition.Z);

                    if (this.HaveTransportTime3)
                        Writer.WriteUInt32(this.TransportTime3);

                    Writer.WriteUInt32(this.TransportTime);

                    Writer
                        .WriteXorByte(bytes[5])
                        .WriteXorByte(bytes[6])
                        .WriteSingle(this.TransportPosition.X)
                        .WriteXorByte(bytes[2]);

                    if (this.HaveTransportTime2)
                        Writer.WriteUInt32(this.TransportTime2);

                    Writer
                        .WriteSByte(this.TransportSeat)
                        .WriteXorByte(bytes[3])
                        .WriteSingle(this.TransportPosition.Y)
                        .WriteSingle(this.TransportFacing)
                        .WriteXorByte(bytes[7])
                        .WriteXorByte(bytes[0]);
                }
            }

            if (this.Living)
            {
                if (this.HaveSpline2)
                {
                    if (this.HaveSpline)
                    {
                        foreach (var point in this.Spline.Points)
                            Writer.WriteSingle(point.Y).WriteSingle(point.X).WriteSingle(point.Z);

                        if (this.Spline.HaveDurationMultiplier)
                        {
                            Writer.WriteSingle(this.Spline.DurationMultiplier);
                        }

                        Writer.WriteSingle(this.Spline.UnknownFloat2);

                        if (this.Spline.SplineType == SplineType.FacingTarget)
                        {
                            fixed (byte* bytes = this.Spline.FacingTarget.Bytes)
                            {
                                Writer
                                    .WriteXorByte(bytes[3])
                                    .WriteXorByte(bytes[4])
                                    .WriteXorByte(bytes[5])
                                    .WriteXorByte(bytes[7])
                                    .WriteXorByte(bytes[2])
                                    .WriteXorByte(bytes[0])
                                    .WriteXorByte(bytes[6])
                                    .WriteXorByte(bytes[1]);
                            }
                        }

                        if (this.Spline.HaveUnknown1)
                        {
                            Writer.WriteUInt32(this.Spline.Unknown1);
                        }

                        Writer.WriteSingle(this.Spline.UnknownFloat3);
                        Writer.WriteUInt32(this.Spline.Unknown2);

                        if (this.Spline.SplineType == SplineType.FacingSpot)
                        {
                            Writer
                                .WriteSingle(this.Spline.FacingSpot.Y)
                                .WriteSingle(this.Spline.FacingSpot.Z)
                                .WriteSingle(this.Spline.FacingSpot.X);
                        }

                        Writer.WriteUInt32(this.Spline.CurrentTime);

                        if (this.Spline.SplineType == SplineType.FacingAngle)
                            Writer.WriteSingle(this.Spline.FacingAngle);
                    }

                    Writer
                        .WriteSingle(this.Spline.EndPoint.Z)
                        .WriteSingle(this.Spline.EndPoint.Y)
                        .WriteUInt32(this.Spline.FullTime)
                        .WriteSingle(this.Spline.EndPoint.X);
                }

                Writer.WriteSingle(this.Speeds[8]);

                // Transport Data
                if (this.HaveTransportData)
                {
                    fixed (byte* bytes = this.TransportGuid.Bytes)
                    {
                        Writer
                            .WriteXorByte(bytes[4])
                            .WriteSingle(this.TransportPosition.Z)
                            .WriteXorByte(bytes[7])
                            .WriteXorByte(bytes[5])
                            .WriteXorByte(bytes[1])
                            .WriteSingle(this.TransportPosition.X)
                            .WriteXorByte(bytes[3])
                            .WriteXorByte(bytes[6]);

                        if (this.HaveTransportTime3)
                            Writer.WriteUInt32(this.TransportTime3);

                        Writer
                            .WriteSingle(this.TransportPosition.Y)
                            .WriteSByte(this.TransportSeat)
                            .WriteSingle(this.TransportFacing);

                        if (this.HaveTransportTime2)
                            Writer.WriteUInt32(this.TransportTime2);

                        Writer
                            .WriteXorByte(bytes[2])
                            .WriteUInt32(this.TransportTime)
                            .WriteXorByte(bytes[0]);
                    }
                }

                Writer
                    .WriteSingle(this.Speeds[7])
                    .WriteSingle(this.Position.X);

                if (this.HavePitch)
                    Writer.WriteSingle(this.Pitch);

                // Fall Data
                if (this.HaveFallData)
                {
                    Writer.WriteUInt32(this.FallTime);
                    if (this.HaveFallDirection)
                    {
                        Writer
                            .WriteSingle(this.FallSinAngle)
                            .WriteSingle(this.FallHorizontalSpeed)
                            .WriteSingle(this.FallCosAngle);
                    }
                    Writer.WriteSingle(this.FallVerticalSpeed);
                }

                Writer
                    .WriteXorByte(p_guid.Bytes[7])
                    .WriteSingle(this.Speeds[4])
                    .WriteXorByte(p_guid.Bytes[0])
                    .WriteXorByte(p_guid.Bytes[5]);

                if (this.TimeStamp != 0)
                    Writer.WriteUInt32(this.TimeStamp);

                Writer
                    .WriteSingle(this.Position.Z)
                    .WriteSingle(this.Speeds[6])
                    .WriteXorByte(p_guid.Bytes[1])
                    .WriteSingle(this.Speeds[2])
                    .WriteSingle(this.Speeds[5])
                    .WriteSingle(this.Speeds[3])
                    .WriteSingle(this.Speeds[0])
                    .WriteXorByte(p_guid.Bytes[3])
                    .WriteXorByte(p_guid.Bytes[4])
                    .WriteXorByte(p_guid.Bytes[2])
                    .WriteXorByte(p_guid.Bytes[6]);

                if (this.HaveSplineElevation)
                    Writer.WriteSingle(this.SplineElevation);

                Writer.WriteSingle(this.Position.Y);
                if (this.Orientation != 0.0f)
                    Writer.WriteSingle(this.Orientation);
                Writer.WriteSingle(this.Speeds[1]);
            }

            // floats here

            // transport time
            if (this.HaveTransportTime)
                Writer.WriteUInt32(this.TransportTime);

            // shorts here

            // go rotation?
            if (this.HaveGameObjectRotation)
                Writer.WriteUInt64(this.GameObjectRotation.Pack());

            // target guid?
            if (this.HaveAttackingTarget)
            {
                fixed (byte* bytes = this.AttackingTarget.Bytes)
                {
                    Writer
                        .WriteXorByte(bytes[3])
                        .WriteXorByte(bytes[5])
                        .WriteXorByte(bytes[0])
                        .WriteXorByte(bytes[7])
                        .WriteXorByte(bytes[2])
                        .WriteXorByte(bytes[4])
                        .WriteXorByte(bytes[6])
                        .WriteXorByte(bytes[1]);
                }
            }
        }
コード例 #11
0
        public sealed override void Save(StreamHandler writer)
        {
            var seq_b = ByteSequence;
            var seq_m = MaskSequence;
            var b_xor = ByteXorValue;

            int size = seq_m.Count(x => x >= 0);

            if (size != seq_m.Length && this.IsMaskSequenceSwapped)
            {
                throw new InvalidOperationException("Cannot have elements in swapped MaskSequence.");
            }
            CheckSequences(seq_b, seq_m);

            if (this.IsMaskSequenceSwapped)
            {
                var seq_m_copy = new int[seq_m.Length];
                for (int i = 0; i < seq_m.Length;)
                {
                    var t = i;
                    for (int j = t + 8 - 1; j >= t; --j, ++i)
                    {
                        seq_m_copy[j] = seq_m[i];
                    }
                }
                seq_m = seq_m_copy;
            }

            byte[] data = new byte[size];
            PackedSave(data);

            var mask = new BitArray(size);

            for (int i = 0; i < size; ++i)
            {
                var el = seq_m[i];
                if (el < 0)
                {
                    ElementWrite(writer, el);
                }
                else
                {
                    writer.UnalignedWriteBit(data[el] != 0);
                }
            }

            writer.FlushUnalignedBits();

            for (int i = 0; i < seq_b.Length; ++i)
            {
                var el = seq_b[i];

                if (el < 0)
                {
                    ElementWrite(writer, el);
                }
                else if (data[el] != 0)
                {
                    writer.WriteByte((byte)(data[el] ^ b_xor));
                }
            }
        }
コード例 #12
0
ファイル: PackedData.cs プロジェクト: SkyFire/Kamilla.Wow
        public sealed override void Save(StreamHandler writer)
        {
            var seq_b = ByteSequence;
            var seq_m = MaskSequence;
            var b_xor = ByteXorValue;

            int size = seq_m.Count(x => x >= 0);
            if (size != seq_m.Length && this.IsMaskSequenceSwapped)
                throw new InvalidOperationException("Cannot have elements in swapped MaskSequence.");
            CheckSequences(seq_b, seq_m);

            if (this.IsMaskSequenceSwapped)
            {
                var seq_m_copy = new int[seq_m.Length];
                for (int i = 0; i < seq_m.Length; )
                {
                    var t = i;
                    for (int j = t + 8 - 1; j >= t; --j, ++i)
                        seq_m_copy[j] = seq_m[i];
                }
                seq_m = seq_m_copy;
            }

            byte[] data = new byte[size];
            PackedSave(data);

            var mask = new BitArray(size);

            for (int i = 0; i < size; ++i)
            {
                var el = seq_m[i];
                if (el < 0)
                    ElementWrite(writer, el);
                else
                    writer.UnalignedWriteBit(data[el] != 0);
            }

            writer.FlushUnalignedBits();

            for (int i = 0; i < seq_b.Length; ++i)
            {
                var el = seq_b[i];

                if (el < 0)
                    ElementWrite(writer, el);
                else if (data[el] != 0)
                    writer.WriteByte((byte)(data[el] ^ b_xor));
            }
        }
コード例 #13
0
ファイル: MovementInfo.cs プロジェクト: Torpedoes/Kamilla.Wow
        public unsafe void Save(StreamHandler Writer)
        {
            var guid = this.Guid;

            Writer
            .UnalignedWriteBit(this.HaveAttackingTarget)
            .UnalignedWriteBit(guid.Bytes[2] != 0)
            .UnalignedWriteBit(this.HaveVehicleData)
            .UnalignedWriteBit(guid.Bytes[1] != 0)
            .UnalignedWriteBit(guid.Bytes[4] != 0)
            .UnalignedWriteBit(guid.Bytes[3] != 0)
            .UnalignedWriteBit(this.HaveTransportTime)
            .UnalignedWriteBit(this.HaveGameObjectPosition)
            .UnalignedWriteBit(false)     // TODO
            .UnalignedWriteBit(false)     // TODO
            .UnalignedWriteBit(this.HaveGameObjectRotation)
            .UnalignedWriteBit(this.Living)
            .UnalignedWriteBit(this.HavePosition)
            .UnalignedWriteInt((uint)this.UnkUInt32.Length, 24)
            .UnalignedWriteBit(guid.Bytes[0] != 0)
            ;

            var p_guid = this.Guid;

            if (this.Living)
            {
                Writer.UnalignedWriteBit(this.HaveTransportData);
                if (this.HaveTransportData)
                {
                    fixed(byte *bytes = this.TransportGuid.Bytes)
                    {
                        Writer
                        .UnalignedWriteBit(bytes[2] != 0)
                        .UnalignedWriteBit(bytes[7] != 0)
                        .UnalignedWriteBit(bytes[5] != 0)
                        .UnalignedWriteBit(this.HaveTransportTime3)
                        .UnalignedWriteBit(bytes[3] != 0)
                        .UnalignedWriteBit(bytes[0] != 0)
                        .UnalignedWriteBit(bytes[4] != 0)
                        .UnalignedWriteBit(bytes[1] != 0)
                        .UnalignedWriteBit(this.HaveTransportTime2)
                        .UnalignedWriteBit(bytes[6] != 0);
                    }
                }

                Writer
                .UnalignedWriteBit(this.HaveSpline2)
                .UnalignedWriteBit(p_guid.Bytes[7] != 0)
                .UnalignedWriteBit(p_guid.Bytes[6] != 0)
                .UnalignedWriteBit(p_guid.Bytes[5] != 0)
                .UnalignedWriteBit(p_guid.Bytes[2] != 0)
                .UnalignedWriteBit(p_guid.Bytes[4] != 0)
                .UnalignedWriteBit(!(this.Flags != 0))
                .UnalignedWriteBit(p_guid.Bytes[1] != 0)
                .UnalignedWriteBit(this.SelfTarget)
                .UnalignedWriteBit(!(this.TimeStamp != 0))
                .UnalignedWriteBit(!(this.Flags2 != 0));

                if (this.HaveSpline2)
                {
                    Writer.UnalignedWriteBit(this.HaveSpline);
                    if (this.HaveSpline)
                    {
                        Writer
                        .UnalignedWriteBit(this.Spline.HaveDurationMultiplier)
                        .UnalignedWriteInt((uint)this.Spline.Flags, 25)
                        .UnalignedWriteInt((byte)this.Spline.SplineMode, 2)
                        .UnalignedWriteBit(this.Spline.HaveUnknown1)
                        .UnalignedWriteInt((uint)this.Spline.Points.Count, 22);

                        byte v;
                        switch (this.Spline.SplineType)
                        {
                        case SplineType.FacingSpot:
                            v = 0;
                            break;

                        case SplineType.Normal:
                            v = 1;
                            break;

                        case SplineType.FacingTarget:
                            v = 2;
                            break;

                        case SplineType.FacingAngle:
                            v = 3;
                            break;

                        default:
                            throw new InvalidOperationException();
                        }
                        Writer.UnalignedWriteInt(v, 2);

                        if (this.Spline.SplineType == SplineType.FacingTarget)
                        {
                            fixed(byte *bytes = this.Spline.FacingTarget.Bytes)
                            {
                                Writer
                                .UnalignedWriteBit(bytes[7] != 0)
                                .UnalignedWriteBit(bytes[3] != 0)
                                .UnalignedWriteBit(bytes[4] != 0)
                                .UnalignedWriteBit(bytes[2] != 0)
                                .UnalignedWriteBit(bytes[1] != 0)
                                .UnalignedWriteBit(bytes[6] != 0)
                                .UnalignedWriteBit(bytes[0] != 0)
                                .UnalignedWriteBit(bytes[5] != 0);
                            }
                        }
                    }
                }

                Writer
                .UnalignedWriteBit(p_guid.Bytes[3] != 0);

                if (this.Flags != 0)
                {
                    Writer.UnalignedWriteInt((uint)this.Flags, 30);
                }

                Writer
                .UnalignedWriteBit(!this.HavePitch)
                .UnalignedWriteBit(this.HaveFallData);
                if (this.Flags2 != 0)
                {
                    Writer.UnalignedWriteInt((ushort)this.Flags2, 12);
                }
                Writer
                .UnalignedWriteBit(p_guid.Bytes[0] != 0)
                .UnalignedWriteBit(!(this.Orientation != 0.0f));     // !haveOrient

                if (this.HaveFallData)
                {
                    Writer.UnalignedWriteBit(this.HaveFallDirection);
                }

                Writer.UnalignedWriteBit(!this.HaveSplineElevation);
            }

            if (this.HaveGameObjectPosition)
            {
                fixed(byte *bytes = this.TransportGuid.Bytes)
                {
                    Writer
                    .UnalignedWriteBit(bytes[1] != 0)
                    .UnalignedWriteBit(this.HaveTransportTime3)
                    .UnalignedWriteBit(bytes[3] != 0)
                    .UnalignedWriteBit(bytes[2] != 0)
                    .UnalignedWriteBit(bytes[6] != 0)
                    .UnalignedWriteBit(bytes[5] != 0)
                    .UnalignedWriteBit(bytes[0] != 0)
                    .UnalignedWriteBit(bytes[4] != 0)
                    .UnalignedWriteBit(this.HaveTransportTime2)
                    .UnalignedWriteBit(bytes[7] != 0);
                }
            }

            // TODO: shorts here

            if (this.HaveAttackingTarget)
            {
                fixed(byte *bytes = this.AttackingTarget.Bytes)
                {
                    Writer
                    .UnalignedWriteBit(bytes[3] != 0)
                    .UnalignedWriteBit(bytes[4] != 0)
                    .UnalignedWriteBit(bytes[6] != 0)
                    .UnalignedWriteBit(bytes[0] != 0)
                    .UnalignedWriteBit(bytes[1] != 0)
                    .UnalignedWriteBit(bytes[7] != 0)
                    .UnalignedWriteBit(bytes[5] != 0)
                    .UnalignedWriteBit(bytes[2] != 0);
                }
            }

            Writer.FlushUnalignedBits();

            foreach (var val in this.UnkUInt32)
            {
                Writer.WriteUInt32(val);
            }

            if (this.HavePosition)
            {
                Writer
                .WriteSingle(this.Position.Z)
                .WriteSingle(this.Orientation)
                .WriteSingle(this.Position.X)
                .WriteSingle(this.Position.Y);
            }

            if (this.HaveVehicleData)
            {
                Writer
                .WriteUInt32(this.VehicleId)
                .WriteSingle(this.VehicleAimAdjustement);
            }

            if (this.HaveGameObjectPosition)
            {
                fixed(byte *bytes = this.TransportGuid.Bytes)
                {
                    Writer
                    .WriteXorByte(bytes[1])
                    .WriteXorByte(bytes[4])
                    .WriteSingle(this.TransportPosition.Z);

                    if (this.HaveTransportTime3)
                    {
                        Writer.WriteUInt32(this.TransportTime3);
                    }

                    Writer.WriteUInt32(this.TransportTime);

                    Writer
                    .WriteXorByte(bytes[5])
                    .WriteXorByte(bytes[6])
                    .WriteSingle(this.TransportPosition.X)
                    .WriteXorByte(bytes[2]);

                    if (this.HaveTransportTime2)
                    {
                        Writer.WriteUInt32(this.TransportTime2);
                    }

                    Writer
                    .WriteSByte(this.TransportSeat)
                    .WriteXorByte(bytes[3])
                    .WriteSingle(this.TransportPosition.Y)
                    .WriteSingle(this.TransportFacing)
                    .WriteXorByte(bytes[7])
                    .WriteXorByte(bytes[0]);
                }
            }

            if (this.Living)
            {
                if (this.HaveSpline2)
                {
                    if (this.HaveSpline)
                    {
                        foreach (var point in this.Spline.Points)
                        {
                            Writer.WriteSingle(point.Y).WriteSingle(point.X).WriteSingle(point.Z);
                        }

                        if (this.Spline.HaveDurationMultiplier)
                        {
                            Writer.WriteSingle(this.Spline.DurationMultiplier);
                        }

                        Writer.WriteSingle(this.Spline.UnknownFloat2);

                        if (this.Spline.SplineType == SplineType.FacingTarget)
                        {
                            fixed(byte *bytes = this.Spline.FacingTarget.Bytes)
                            {
                                Writer
                                .WriteXorByte(bytes[3])
                                .WriteXorByte(bytes[4])
                                .WriteXorByte(bytes[5])
                                .WriteXorByte(bytes[7])
                                .WriteXorByte(bytes[2])
                                .WriteXorByte(bytes[0])
                                .WriteXorByte(bytes[6])
                                .WriteXorByte(bytes[1]);
                            }
                        }

                        if (this.Spline.HaveUnknown1)
                        {
                            Writer.WriteUInt32(this.Spline.Unknown1);
                        }

                        Writer.WriteSingle(this.Spline.UnknownFloat3);
                        Writer.WriteUInt32(this.Spline.Unknown2);

                        if (this.Spline.SplineType == SplineType.FacingSpot)
                        {
                            Writer
                            .WriteSingle(this.Spline.FacingSpot.Y)
                            .WriteSingle(this.Spline.FacingSpot.Z)
                            .WriteSingle(this.Spline.FacingSpot.X);
                        }

                        Writer.WriteUInt32(this.Spline.CurrentTime);

                        if (this.Spline.SplineType == SplineType.FacingAngle)
                        {
                            Writer.WriteSingle(this.Spline.FacingAngle);
                        }
                    }

                    Writer
                    .WriteSingle(this.Spline.EndPoint.Z)
                    .WriteSingle(this.Spline.EndPoint.Y)
                    .WriteUInt32(this.Spline.FullTime)
                    .WriteSingle(this.Spline.EndPoint.X);
                }

                Writer.WriteSingle(this.Speeds[8]);

                // Transport Data
                if (this.HaveTransportData)
                {
                    fixed(byte *bytes = this.TransportGuid.Bytes)
                    {
                        Writer
                        .WriteXorByte(bytes[4])
                        .WriteSingle(this.TransportPosition.Z)
                        .WriteXorByte(bytes[7])
                        .WriteXorByte(bytes[5])
                        .WriteXorByte(bytes[1])
                        .WriteSingle(this.TransportPosition.X)
                        .WriteXorByte(bytes[3])
                        .WriteXorByte(bytes[6]);

                        if (this.HaveTransportTime3)
                        {
                            Writer.WriteUInt32(this.TransportTime3);
                        }

                        Writer
                        .WriteSingle(this.TransportPosition.Y)
                        .WriteSByte(this.TransportSeat)
                        .WriteSingle(this.TransportFacing);

                        if (this.HaveTransportTime2)
                        {
                            Writer.WriteUInt32(this.TransportTime2);
                        }

                        Writer
                        .WriteXorByte(bytes[2])
                        .WriteUInt32(this.TransportTime)
                        .WriteXorByte(bytes[0]);
                    }
                }

                Writer
                .WriteSingle(this.Speeds[7])
                .WriteSingle(this.Position.X);

                if (this.HavePitch)
                {
                    Writer.WriteSingle(this.Pitch);
                }

                // Fall Data
                if (this.HaveFallData)
                {
                    Writer.WriteUInt32(this.FallTime);
                    if (this.HaveFallDirection)
                    {
                        Writer
                        .WriteSingle(this.FallSinAngle)
                        .WriteSingle(this.FallHorizontalSpeed)
                        .WriteSingle(this.FallCosAngle);
                    }
                    Writer.WriteSingle(this.FallVerticalSpeed);
                }

                Writer
                .WriteXorByte(p_guid.Bytes[7])
                .WriteSingle(this.Speeds[4])
                .WriteXorByte(p_guid.Bytes[0])
                .WriteXorByte(p_guid.Bytes[5]);

                if (this.TimeStamp != 0)
                {
                    Writer.WriteUInt32(this.TimeStamp);
                }

                Writer
                .WriteSingle(this.Position.Z)
                .WriteSingle(this.Speeds[6])
                .WriteXorByte(p_guid.Bytes[1])
                .WriteSingle(this.Speeds[2])
                .WriteSingle(this.Speeds[5])
                .WriteSingle(this.Speeds[3])
                .WriteSingle(this.Speeds[0])
                .WriteXorByte(p_guid.Bytes[3])
                .WriteXorByte(p_guid.Bytes[4])
                .WriteXorByte(p_guid.Bytes[2])
                .WriteXorByte(p_guid.Bytes[6]);

                if (this.HaveSplineElevation)
                {
                    Writer.WriteSingle(this.SplineElevation);
                }

                Writer.WriteSingle(this.Position.Y);
                if (this.Orientation != 0.0f)
                {
                    Writer.WriteSingle(this.Orientation);
                }
                Writer.WriteSingle(this.Speeds[1]);
            }

            // floats here

            // transport time
            if (this.HaveTransportTime)
            {
                Writer.WriteUInt32(this.TransportTime);
            }

            // shorts here

            // go rotation?
            if (this.HaveGameObjectRotation)
            {
                Writer.WriteUInt64(this.GameObjectRotation.Pack());
            }

            // target guid?
            if (this.HaveAttackingTarget)
            {
                fixed(byte *bytes = this.AttackingTarget.Bytes)
                {
                    Writer
                    .WriteXorByte(bytes[3])
                    .WriteXorByte(bytes[5])
                    .WriteXorByte(bytes[0])
                    .WriteXorByte(bytes[7])
                    .WriteXorByte(bytes[2])
                    .WriteXorByte(bytes[4])
                    .WriteXorByte(bytes[6])
                    .WriteXorByte(bytes[1]);
                }
            }
        }