public static void HandleItemEnchantTimeUpdate(Packet packet)
        {
            var itemGuid = new byte[8];
            var playerGuid = new byte[8];
            itemGuid[3] = packet.ReadBit();
            playerGuid[4] = packet.ReadBit();
            itemGuid[0] = packet.ReadBit();
            playerGuid[7] = packet.ReadBit();
            itemGuid[2] = packet.ReadBit();
            playerGuid[6] = packet.ReadBit();
            packet.StartBitStream(itemGuid, 6, 1);
            playerGuid[2] = packet.ReadBit();
            itemGuid[7] = packet.ReadBit();
            packet.StartBitStream(playerGuid, 3, 1);
            itemGuid[5] = packet.ReadBit();
            packet.StartBitStream(playerGuid, 5, 0);
            itemGuid[4] = packet.ReadBit();
            packet.ResetBitReader();

            packet.ReadUInt32("Duration");
            packet.ReadXORBytes(playerGuid, 2, 3);
            packet.ReadXORByte(itemGuid, 7);
            packet.ReadXORByte(playerGuid, 0);
            packet.ReadUInt32("Slot");
            packet.ReadXORByte(itemGuid, 3);
            packet.ReadXORByte(playerGuid, 6);
            packet.ReadXORBytes(itemGuid, 6, 4, 2);
            packet.ReadXORByte(playerGuid, 1);
            packet.ReadXORByte(itemGuid, 5);
            packet.ReadXORBytes(playerGuid, 5, 4, 7);
            packet.ReadXORBytes(itemGuid, 0, 1);

            packet.WriteGuid("Player GUID", playerGuid);
            packet.WriteGuid("Item GUID", itemGuid);
        }
        public static void HandleServerUpdateAccountData(Packet packet)
        {
            var guid = new byte[8];

            packet.ReadBitsE<AccountDataType>("Data Type", 3);

            packet.StartBitStream(guid, 5, 1, 3, 7, 0, 4, 2, 6);

            packet.ReadXORBytes(guid, 3, 1, 5);

            var decompCount = packet.ReadInt32();
            var compCount = packet.ReadInt32();

            var pkt = packet.Inflate(compCount, decompCount, false);
            var data = pkt.ReadWoWString(decompCount);
            pkt.ClosePacket(false);

            packet.AddValue("Account Data", data);

            packet.ReadXORBytes(guid, 7, 4, 0, 6, 2);

            packet.ReadTime("Login Time");

            packet.WriteGuid("GUID", guid);
        }
        public static void HandleGuildQueryResponse(Packet packet)
        {
            var guid1 = new byte[8];
            var guid2 = new byte[8];

            var hasData = packet.ReadBit();

            int nameLen = 0;
            int rankCount = 0;
            int[] rankName = null;
            if (hasData)
            {
                packet.StartBitStream(guid2, 1, 7);
                nameLen = (int)packet.ReadBits(7);
                packet.StartBitStream(guid2, 5, 0, 6, 3, 4, 2);
                rankCount = (int)packet.ReadBits(21);
                rankName = new int[rankCount];
                for (var i = 0; i < rankCount; ++i)
                    rankName[i] = (int)packet.ReadBits(7);
            }

            packet.StartBitStream(guid1, 2, 6, 7, 5, 4, 3, 0, 1);
            if (hasData)
            {
                packet.ReadWoWString("Guild Name", nameLen);
                packet.ReadXORByte(guid2, 5);
                for (var i = 0; i < rankCount; ++i)
                {
                    packet.ReadUInt32("Rights Order", i);
                    packet.ReadUInt32("Creation Order", i);
                    packet.ReadWoWString("Rank Name", rankName[i], i);
                }

                packet.ReadInt32("Emblem Border Color");
                packet.ReadXORBytes(guid2, 6, 0);
                packet.ReadInt32("Emblem Border Style");
                packet.ReadInt32("Emblem Style");
                packet.ReadXORByte(guid2, 4);
                packet.ReadInt32("Emblem Color");
                packet.ReadXORBytes(guid2, 7, 2, 3, 1);
                packet.ReadInt32("Emblem Background Color");
                packet.WriteGuid("Guid2", guid2);
            }

            packet.ParseBitStream(guid1, 1, 6, 3, 5, 4, 0, 2, 7);
            packet.WriteGuid("Guid1", guid1);
        }
 public static void HandleActivateTaxi(Packet packet)
 {
     packet.ReadUInt32("Node 2 ID"); // 28
     packet.ReadUInt32("Node 1y ID"); // 24
     var guid = packet.StartBitStream(4, 0, 1, 2, 5, 6, 7, 3);
     packet.ReadXORBytes(guid, 1, 0, 6, 5, 2, 4, 3, 7);
     packet.WriteGuid("Guid", guid);
 }
        public static void HandleCriteriaUpdate(Packet packet)
        {
            var counter = new byte[8];
            var guid2 = new byte[8];

            counter[1] = packet.ReadBit();
            guid2[2] = packet.ReadBit();
            packet.ReadBits("Flags", 4); // some flag... & 1 -> delete
            packet.StartBitStream(guid2, 4, 0, 7);
            counter[6] = packet.ReadBit();
            guid2[5] = packet.ReadBit();
            packet.StartBitStream(counter, 0, 2, 4);
            packet.StartBitStream(guid2, 3, 6);
            packet.StartBitStream(counter, 3, 5);
            guid2[1] = packet.ReadBit();
            counter[7] = packet.ReadBit();

            packet.ResetBitReader();

            packet.ReadPackedTime("Time");
            packet.ReadXORByte(counter, 1);
            packet.ReadXORByte(guid2, 2);
            packet.ReadXORByte(counter, 2);
            packet.ReadXORByte(guid2, 3);
            packet.ReadXORByte(counter, 5);
            packet.ReadXORBytes(guid2, 0, 4);

            packet.ReadUInt32("Timer 1");
            packet.ReadXORByte(guid2, 5);
            packet.ReadInt32("Criteria ID");
            packet.ReadXORByte(guid2, 1);
            packet.ReadXORBytes(counter, 7, 3, 6);
            packet.ReadXORByte(guid2, 7);
            packet.ReadXORBytes(counter, 0, 4);
            packet.ReadXORByte(guid2, 6);
            packet.ReadUInt32("Timer 2");

            packet.WriteLine("Counter: {0}", BitConverter.ToInt64(counter, 0));
            packet.WriteGuid("GUID2", guid2);
        }
        public static void HandlePetNameQuery(Packet packet)
        {
            var guid = new byte[8];
            var number = new byte[8];

            guid[5] = packet.ReadBit();
            number[3] = packet.ReadBit();
            guid[6] = packet.ReadBit();
            packet.StartBitStream(number, 5, 7);
            packet.StartBitStream(guid, 2, 4);
            number[2] = packet.ReadBit();
            guid[3] = packet.ReadBit();
            number[1] = packet.ReadBit();
            guid[7] = packet.ReadBit();
            number[6] = packet.ReadBit();
            packet.StartBitStream(guid, 1, 0);
            packet.StartBitStream(number, 4, 0);
            packet.ResetBitReader();

            packet.ReadXORByte(number, 5);
            packet.ReadXORBytes(guid, 4, 3);
            packet.ReadXORBytes(number, 7, 4);
            packet.ReadXORBytes(guid, 5, 2, 0, 6);
            packet.ReadXORBytes(number, 2, 0, 6);
            packet.ReadXORByte(guid, 1);
            packet.ReadXORByte(number, 3);
            packet.ReadXORByte(guid, 7);
            packet.ReadXORByte(number, 1);

            var GUID = new WowGuid64(BitConverter.ToUInt64(guid, 0));
            var Number = BitConverter.ToUInt64(number, 0);
            packet.WriteGuid("Guid", guid);
            packet.AddValue("Pet Number", Number);

            // Store temporary name (will be replaced in SMSG_QUERY_PET_NAME_RESPONSE)
            StoreGetters.AddName(GUID, Number.ToString(CultureInfo.InvariantCulture));
        }
        public static void HandleGOCustomAnim(Packet packet)
        {
            var guid = new byte[8];
            packet.ReadBit("Unk bit");
            packet.StartBitStream(guid, 6, 3, 4);
            var hasAnim = !packet.ReadBit();
            packet.StartBitStream(guid, 5, 1, 2, 0, 7);
            packet.ResetBitReader();

            packet.ReadXORBytes(guid, 0, 2, 5, 7, 4, 3, 1);
            if (hasAnim)
                packet.ReadInt32("Anim");

            packet.ReadXORByte(guid, 6);
            packet.WriteGuid("GUID", guid);
        }
        public static void HandleServerUpdateAccountData(Packet packet)
        {
            var guid = new byte[8];

            var decompCount = packet.ReadInt32();
            var compCount = packet.ReadInt32();

            var data = packet.Inflate(compCount, decompCount, false).ReadWoWString(decompCount);
            packet.WriteLine("Account Data {0}", data);

            packet.ReadTime("Login Time");
            guid[7] = packet.ReadBit();
            packet.ReadEnum<AccountDataType>("Data Type", 3);
            packet.StartBitStream(guid, 3, 6, 1, 5, 0, 4, 2);
            packet.ReadXORBytes(guid, 6, 7, 4, 1, 5, 0, 3, 2);

            packet.WriteGuid("GUID", guid);
        }
        public static void HandleDBQueryBulk(Packet packet)
        {
            packet.ReadEnum<DB2Hash>("DB2 File", TypeCode.Int32);
            var count = packet.ReadBits(21);

            var guids = new byte[count][];
            for (var i = 0; i < count; ++i)
            {
                guids[i] = new byte[8];
                packet.StartBitStream(guids[i], 5, 7, 6, 1, 4, 3, 2, 1);
            }

            packet.ResetBitReader();
            for (var i = 0; i < count; ++i)
            {
                packet.ReadXORBytes(guids[i], 3, 7, 1, 6, 4, 0, 5);
                packet.ReadInt32("Unk int", i);
                packet.ReadXORByte(guids[i], 2);
                packet.WriteGuid("Guid", guids[i], i);
            }
        }
        public static void HandleAuraUpdate(Packet packet)
        {
            var guid = new byte[8];
            var guid2 = new byte[8];
            var guid3 = new byte[8];
            byte[][] guid4;
            byte[][] guid5;
            var guid6 = new byte[8];
            byte[][] guid7;
            var guid8 = new byte[8];
            var guid9 = new byte[8];
            var guid10 = new byte[8];
            var guid11 = new byte[8];

            uint counter5 = 0;

            // main func sub_BF21FA
            guid10[5] = packet.ReadBit();
            var counter = packet.ReadBits(24); // field_74
            var bit476 = !packet.ReadBit("field_1DC");
            var bit404 = !packet.ReadBit("field_193");
            packet.ReadBit("field_A8");
            guid11[6] = packet.ReadBit();
            var bit432 = !packet.ReadBit("field_1B0");
            var counter3 = packet.ReadBits(20);
            packet.StartBitStream(guid, 2, 1, 0, 4, 5, 6, 3, 7);
            packet.StartBitStream(guid10, 0, 1, 3);

            guid7 = new byte[counter][];
            for (var i = 0; i < counter; ++i)
            {
                guid7[i] = new byte[8];
                packet.StartBitStream(guid7[i], 5, 6, 4, 7, 1, 2, 3, 0);
            }

            var bit452 = !packet.ReadBit("field_1C4");
            guid11[5] = packet.ReadBit();
            var bit385 = !packet.ReadBit("field_17F");
            var counter7 = packet.ReadBits(21); // field_16F
            var bit408 = !packet.ReadBit("field_197");
            var counter2 = packet.ReadBits(24); // field_64
            var bit16 = packet.ReadBit(); // field_10
            packet.StartBitStream(guid10, 6, 2);
            guid11[7] = packet.ReadBit();
            var counter6 = packet.ReadBits(3); // field_183
            var bit152 = !packet.ReadBit(); // field_95
            var bit176 = packet.ReadBit(); // field_B0

            if (bit16)
            {
                packet.StartBitStream(guid2, 7, 4, 5, 0, 2, 6, 3, 1);
                counter5 = packet.ReadBits(21); // field_2C
            }

            var bit412 = !packet.ReadBit(); // field_19B

            if (bit176)
                packet.StartBitStream(guid3, 6, 3, 0, 1, 4, 5, 2, 7);

            guid11[1] = packet.ReadBit();

            guid4 = new byte[counter2][];
            for (var i = 0; i < counter2; ++i)
            {
                guid4[i] = new byte[8];
                packet.StartBitStream(guid4[i], 6, 4, 1, 7, 5, 2, 3, 0);
            }

            guid5 = new byte[counter3][];
            for (var i = 0; i < counter3; ++i)
            {
                guid5[i] = new byte[8];
                packet.StartBitStream(guid5[i], 7, 6, 5, 0, 4, 3, 1, 2);
            }
            var bit416 = !packet.ReadBit(); // field_19F
            guid11[0] = packet.ReadBit();
            packet.ReadBits(12); // field_5C
            packet.StartBitStream(guid10, 7, 4);
            var bit208 = packet.ReadBit(); // field_CF

            if (bit208)
                packet.StartBitStream(guid6, 0, 2, 7, 6, 1, 4, 3, 5);

            var bit384 = !packet.ReadBit(); // field_17F
            var bit456 = !packet.ReadBit(); // field_1C8
            guid11[3] = packet.ReadBit();
            var bit420 = packet.ReadBit(); // field_1A3
            var bit472 = !packet.ReadBit(); // field_1D8
            guid11[4] = packet.ReadBit();
            var unkflag27 = packet.ReadBit(); // field_EF

            int bits7 = 0;
            if (!unkflag27)
                bits7 = (int)packet.ReadBits(7); // field_EF

            var counter4 = packet.ReadBits(25); // field_81
            guid11[2] = packet.ReadBit();

            for (var i = 0; i < counter4; ++i)
            {
                var bit136 = packet.ReadBits(4); // field_85

                if (bit136 == 11)
                    packet.ReadBits(4);
            }

            packet.ReadBit("unk464"); // field_1D0
            packet.StartBitStream(guid8, 7, 3, 6, 4, 2, 5, 0, 1);
            packet.ReadBit("unk160"); // field_9D
            packet.StartBitStream(guid9, 3, 5, 2, 1, 4, 0, 6, 7);

            if (bit152)
                packet.ReadBits(20); // field_95

            if (bit176)
            {
                var pos = new Vector3();
                packet.ReadXORBytes(guid3, 3, 7, 4);
                pos.X = packet.ReadSingle();
                packet.ReadXORBytes(guid3, 6, 5, 2);
                pos.Z = packet.ReadSingle();
                pos.Y = packet.ReadSingle();
                packet.ReadXORBytes(guid3, 0, 1);
                packet.WriteGuid("GUID3", guid3);
                packet.WriteLine("Position: {0}", pos);
            }

            for (var i = 0; i < counter3; ++i)
            {
                var pos = new Vector3();
                packet.ReadXORBytes(guid5[i], 4, 0, 7, 6, 2, 1);
                pos.X = packet.ReadSingle();
                packet.ReadXORBytes(guid5[i], 5, 3);
                pos.Y = packet.ReadSingle();
                pos.Z = packet.ReadSingle();
                packet.WriteGuid("GUID5", guid5[i], i);
                packet.WriteLine("Position: {0}", pos);
            }

            for (var i = 0; i < counter; ++i)
            {
                packet.ParseBitStream(guid7[i], 2, 1, 5, 3, 7, 0, 4, 6);
                packet.WriteGuid("GUID7", guid7[i], i);
            }

            if (bit208)
            {
                var pos = new Vector3();
                packet.ReadXORBytes(guid6, 1, 4);
                pos.Z = packet.ReadSingle();
                packet.ReadXORBytes(guid6, 0, 7, 3, 5);
                pos.Y = packet.ReadSingle();
                packet.ReadXORByte(guid6, 6);
                pos.X = packet.ReadSingle();
                packet.ReadXORByte(guid6, 2);
                packet.WriteGuid("GUID6", guid6);
                packet.WriteLine("Position: {0}", pos);
            }
            if (bit408)
                packet.ReadSingle("float198");

            if (bit416)
                packet.ReadByte("unk.416"); // field_19F

            packet.ParseBitStream(guid8, 5, 0, 2, 7, 6, 3, 4, 1);
            packet.WriteGuid("GUID8", guid8);

            for (var i = 0; i < counter2; ++i)
            {
                packet.ParseBitStream(guid4[i], 6, 3, 1, 0, 2, 4, 7, 5);
                packet.WriteGuid("GUID4", guid4[i], i);
            }

            if (bit16)
            {
                packet.ReadXORByte(guid2, 3);
                packet.ReadUInt32("Spell Power"); // field_28
                packet.ReadXORBytes(guid2, 6, 4, 7, 0);
                packet.ReadUInt32("Attack Power"); // field_24
                packet.ReadXORByte(guid2, 2);

                for (var i = 0; i < counter5; ++i)
                {
                    packet.ReadUInt32("uint32 60");
                    packet.ReadUInt32("uint32 48");
                }

                packet.ReadUInt32("Health");
                packet.ReadXORBytes(guid2, 1, 5);
                packet.WriteGuid("GUID2", guid2);
            }

            packet.ParseBitStream(guid9, 2, 3, 4, 7, 5, 1, 6, 0);
            packet.WriteGuid("GUID9", guid9);

            packet.ReadByte("Cast Count"); // field_50

            packet.ParseBitStream(guid, 0, 1, 4, 5, 7, 6, 2, 3);
            packet.WriteGuid("GUID", guid);

            packet.ReadXORByte(guid10, 7);
            if (bit476)
                packet.ReadByte("unk476"); // field_1DC

            if (bit472)
                packet.ReadUInt32("uint32 472"); // field_1D8

            packet.ReadXORByte(guid10, 3);

            packet.ReadWoWString("Text", bits7);

            if (bit404)
                packet.ReadUInt32("uint32 404"); // field_193

            if (bit456)
                packet.ReadUInt32("uint32 456"); // field_1C8

            packet.ReadXORByte(guid10, 2);
            packet.ReadXORByte(guid11, 0);

            if (bit420)
            {
                packet.ReadUInt32("uint32 424"); // field_1A8
                packet.ReadUInt32("uint32 428"); // field_1AC
            }

            if (bit412)
                packet.ReadUInt32("uint32 412"); // field_19B

            packet.ReadXORByte(guid11, 2);
            packet.ReadXORBytes(guid10, 0, 1);
            packet.ReadXORByte(guid11, 3);

            for (var i = 0; i < counter6; ++i) // field_183
                packet.ReadByte("unk392"); // field_187

            if (bit384)
                packet.ReadByte("unk384"); // field_17F

            packet.ReadXORByte(guid11, 1);
            packet.ReadXORByte(guid10, 4);
            packet.ReadEntryWithName<Int32>(StoreNameType.Spell, "Spell ID"); // field_54

            if (bit385)
                packet.ReadByte("Effect Count"); // field_17F

            packet.ReadXORByte(guid10, 6);
            packet.ReadXORByte(guid11, 5);
            packet.ReadUInt32("uint32 88"); // field_58
            packet.ReadXORByte(guid11, 4);
            packet.ReadUInt32("uint32 96"); // field_60

            for (var i = 0; i < counter7; ++i)
            {
                packet.ReadUInt32("uint32 372"); // field_173
                packet.ReadByte("unk380"); // field_173
            }
            packet.ReadXORByte(guid10, 5);
            packet.ReadXORByte(guid11, 6);

            if (bit452)
                packet.ReadUInt32("uint 452"); // field_1C4

            packet.ReadXORByte(guid11, 7);

            if (bit432)
                packet.ReadByte("unk432"); // field_1B0

            packet.WriteGuid("GUID10", guid10);
            packet.WriteGuid("GUID11", guid11);
        }
        public static void HandleLogXPGain(Packet packet)
        {
            var guid = new byte[8];
            packet.StartBitStream(guid, 1, 0, 3, 7);
            var hasBaseXP = !packet.ReadBit();
            packet.StartBitStream(guid, 4, 2, 6, 5);
            var hasGroupRate = !packet.ReadBit();
            packet.ReadBit("RAF Bonus");
            packet.ResetBitReader();

            packet.ReadXORBytes(guid, 5, 2);

            if (hasBaseXP)
                packet.ReadUInt32("Base XP");
            packet.ReadXORByte(guid, 4);
            packet.ReadUInt32("Total XP");
            packet.ReadXORBytes(guid, 6, 0, 3);
            packet.ReadByte("XP type");

            if (hasGroupRate)
                packet.ReadSingle("Group rate");
            packet.ReadXORBytes(guid, 1, 7);

            packet.WriteGuid("Guid", guid);
        }
        public static void HandlePlayObjectSound(Packet packet)
        {
            var guid1 = new byte[8];
            var guid2 = new byte[8];

            guid2[5] = packet.ReadBit();
            guid1[7] = packet.ReadBit();
            guid1[0] = packet.ReadBit();
            guid1[3] = packet.ReadBit();
            guid2[1] = packet.ReadBit();
            guid1[4] = packet.ReadBit();
            guid2[7] = packet.ReadBit();
            guid2[2] = packet.ReadBit();
            guid2[4] = packet.ReadBit();
            guid2[3] = packet.ReadBit();
            guid1[5] = packet.ReadBit();
            guid1[1] = packet.ReadBit();
            guid1[6] = packet.ReadBit();
            guid1[2] = packet.ReadBit();
            guid2[6] = packet.ReadBit();
            guid2[0] = packet.ReadBit();

            packet.ReadXORBytes(guid1, 6, 2);
            packet.ReadXORBytes(guid2, 2, 5);
            packet.ReadXORBytes(guid1, 7, 5, 3, 1);
            packet.ReadXORBytes(guid2, 3, 1);

            var sound = packet.ReadUInt32("Sound Id");

            packet.ReadXORByte(guid1, 4);
            packet.ReadXORBytes(guid2, 4, 7, 0, 6);
            packet.ReadXORByte(guid1, 0);

            packet.WriteGuid("Guid 1", guid1);
            packet.WriteGuid("Guid 2", guid2);

            Storage.Sounds.Add(sound, packet.TimeSpan);
        }
        private static MovementInfo ReadMovementUpdateBlock(Packet packet, WowGuid guid, object index)
        {
            var moveInfo = new MovementInfo();

            var guid1 = new byte[8];
            var transportGuid = new byte[8];
            var goTransportGuid = new byte[8];
            var attackingTargetGuid = new byte[8];
            var guid5 = new byte[8];
            var guid6 = new byte[8];
            var guid7 = new byte[8];

            var hasAnimKit1 = false;
            var hasAnimKit2 = false;
            var hasAnimKit3 = false;
            var hasFullSpline = false;
            var hasSplineStartTime = false;
            var hasSplineVerticalAcceleration = false;
            var hasMovementFlags = false;
            var hasMoveFlagsExtra = false;
            var hasTimestamp = false;
            var hasOrientation = false;
            var hasTransportData = false;
            var hasTransportTime2 = false;
            var hasTransportTime3 = false;
            var hasGOTransportTime2 = false;
            var hasGOTransportTime3 = false;
            var hasPitch = false;
            var hasFallData = false;
            var hasFallDirection = false;
            var hasSplineElevation = false;

            var bit134 = false;
            var bitA8 = false;
            var bit23C = false;
            var bit298 = false;
            var bit230 = false;
            var bit284 = false;
            var bit228 = false;
            var bit258 = false;
            var bit218 = false;
            var bit220 = false;

            var bits168 = 0u;
            var splineCount = 0u;
            var bits138 = 0u;
            var bits98 = 0u;
            var bits25C = 0u;
            var bits26C = 0u;
            var bits288 = 0u;
            var bits418 = 0u;
            var bits2AA = 0u;
            var splineType = SplineType.Stop;

            var bit2A4 = packet.ReadBit(); // 676
            var hasVehicleData = packet.ReadBit("Has Vehicle Data", index); // 488
            var bit414 = packet.ReadBit(); // 1044
            var hasGameObjectRotation = packet.ReadBit("Has GameObject Rotation", index); // 512
            packet.ReadBit(); // fake 0
            var isLiving = packet.ReadBit("Is Living", index); // 368
            var hasSceneObjectData = packet.ReadBit("Has Scene Object Data", index); // 1032
            packet.ReadBit(); // fake 2
            var bit29C = packet.ReadBit(); // 668
            var bit2A8 = packet.ReadBit(); // 680
            var bit2A9 = packet.ReadBit(); // 681
            packet.ReadBit(); // fake 1
            var hasTransportPosition = packet.ReadBit("Has Transport Position", index); // 424
            var bit1DC = packet.ReadBit(); // 476
            var hasAnimKits = packet.ReadBit("Has Anim Kits", index); // 498
            var hasStationaryPosition = packet.ReadBit("Has Stationary Position", index); // 448
            var hasAttackingTarget = packet.ReadBit("Has Attacking Target", index); // 464
            packet.ReadBit(); // fake 3
            var transportFrames = packet.ReadBits("Transport Frames Count", 22, index); // 1068
            var bit32A = packet.ReadBit(); // 810
            var bit428 = packet.ReadBit(); // 1064

            if (bit428)
                bits418 = packet.ReadBits(22);

            if (hasTransportPosition)
            {
                packet.StartBitStream(goTransportGuid, 3, 5, 2, 1, 4);
                hasGOTransportTime3 = packet.ReadBit();
                hasGOTransportTime2 = packet.ReadBit();
                packet.StartBitStream(goTransportGuid, 0, 6, 7);
            }

            if (isLiving)
            {
                hasTransportData = packet.ReadBit("Has Transport Data", index);
                if (hasTransportData)
                {
                    transportGuid[4] = packet.ReadBit();
                    transportGuid[0] = packet.ReadBit();
                    transportGuid[5] = packet.ReadBit();
                    transportGuid[2] = packet.ReadBit();
                    transportGuid[3] = packet.ReadBit();
                    hasTransportTime2 = packet.ReadBit();
                    transportGuid[7] = packet.ReadBit();
                    transportGuid[6] = packet.ReadBit();
                    transportGuid[1] = packet.ReadBit();
                    hasTransportTime3 = packet.ReadBit();
                }

                hasPitch = !packet.ReadBit("Has Pitch", index);
                packet.ReadBit();
                bits168 = packet.ReadBits(19);
                guid1[1] = packet.ReadBit();
                hasMoveFlagsExtra = !packet.ReadBit();
                packet.ReadBit();
                hasSplineElevation = !packet.ReadBit("Has SplineElevation", index);

                if (hasMoveFlagsExtra)
                    moveInfo.FlagsExtra = packet.ReadBitsE<MovementFlagExtra>("Extra Movement Flags", 13, index);

                hasOrientation = !packet.ReadBit();
                hasTimestamp = !packet.ReadBit();
                hasMovementFlags = !packet.ReadBit();
                bitA8 = !packet.ReadBit("bitA8", index);
                guid1[2] = packet.ReadBit();
                guid1[6] = packet.ReadBit();
                hasFallData = packet.ReadBit();
                guid1[5] = packet.ReadBit();
                guid1[4] = packet.ReadBit();
                guid1[0] = packet.ReadBit();

                if (hasMovementFlags)
                    moveInfo.Flags = packet.ReadBitsE<MovementFlag>("Movement Flags", 30, index);
                packet.ReadBit();
                if (hasFallData)
                    hasFallDirection = packet.ReadBit();
                bits98 = packet.ReadBits("bits98", 22, index);

                guid1[7] = packet.ReadBit();
                moveInfo.HasSplineData = packet.ReadBit();
                guid1[3] = packet.ReadBit();

                if (moveInfo.HasSplineData)
                {
                    hasFullSpline = packet.ReadBit();
                    if (hasFullSpline)
                    {
                        hasSplineVerticalAcceleration = packet.ReadBit();
                        packet.ReadBitsE<SplineMode>("Spline Mode", 2, index);
                        splineCount = packet.ReadBits(20);
                        packet.ReadBitsE<SplineFlag434>("Spline flags", 25, index);

                        hasSplineStartTime = packet.ReadBit();
                        bit134 = packet.ReadBit();
                        if (bit134)
                        {
                            bits138 = packet.ReadBits(21);
                            packet.ReadBits(2);
                        }
                    }
                }
            }

            if (bit29C)
            {
                bit230 = packet.ReadBit();
                bit258 = packet.ReadBit();
                packet.ReadBit("bit20E", index);
                packet.ReadBit("bit20F", index);
                bit228 = packet.ReadBit();
                packet.ReadBit("bit20C", index);
                bit218 = packet.ReadBit();
                packet.ReadBit("bit20D", index);
                bit284 = packet.ReadBit();

                if (bit284)
                {
                    bits25C = packet.ReadBits(21);
                    bits26C = packet.ReadBits(21);
                }

                bit298 = packet.ReadBit();

                if (bit298)
                    bits288 = packet.ReadBits(20);

                bit23C = packet.ReadBit();
                packet.ReadBit("bit210", index);
                bit220 = packet.ReadBit();
            }

            if (hasAttackingTarget)
                attackingTargetGuid = packet.StartBitStream(4, 6, 3, 5, 0, 2, 7, 1);

            if (hasAnimKits)
            {
                hasAnimKit1 = !packet.ReadBit();
                hasAnimKit2 = !packet.ReadBit();
                hasAnimKit3 = !packet.ReadBit();
            }

            if (bit32A)
                bits2AA = packet.ReadBits(7);

            packet.ResetBitReader();

            for (var i = 0; i < transportFrames; ++i)
                packet.ReadInt32("Transport frame", index, i);

            if (bit29C)
            {
                if (bit23C)
                {
                    packet.ReadSingle("Float234", index);
                    packet.ReadSingle("Float238", index);
                }

                if (bit284)
                {
                    for (var i = 0; i < bits26C; ++i)
                    {
                        packet.ReadSingle("Float270+0", index, i);
                        packet.ReadSingle("Float270+1", index, i);
                    }

                    packet.ReadSingle("Float27C", index);

                    for (var i = 0; i < bits25C; ++i)
                    {
                        packet.ReadSingle("Float260+0", index, i);
                        packet.ReadSingle("Float260+1", index, i);
                    }

                    packet.ReadSingle("Float280", index);
                }

                if (bit258)
                {
                    packet.ReadSingle("Float244", index);
                    packet.ReadSingle("Float250", index);
                    packet.ReadSingle("Float254", index);
                    packet.ReadSingle("Float248", index);
                    packet.ReadSingle("Float240", index);
                    packet.ReadSingle("Float24C", index);
                }

                packet.ReadInt32("Int208", index);

                if (bit298)
                {
                    for (var i = 0; i < bits288; ++i)
                    {
                        packet.ReadSingle("Float28C+0", index, i);
                        packet.ReadSingle("Float28C+1", index, i);
                        packet.ReadSingle("Float28C+2", index, i);
                    }
                }

                if (bit220)
                    packet.ReadInt32("int21C", index);

                if (bit218)
                    packet.ReadInt32("int214", index);

                if (bit230)
                    packet.ReadInt32("int22C", index);

                if (bit228)
                    packet.ReadInt32("int224", index);
            }

            if (isLiving)
            {
                if (hasFallData)
                {
                    if (hasFallDirection)
                    {
                        packet.ReadSingle("Jump Sin Angle", index);
                        packet.ReadSingle("Jump Cos Angle", index);
                        packet.ReadSingle("Jump XY Speed", index);
                    }

                    packet.ReadSingle("Jump Z Speed", index);
                    packet.ReadUInt32("Jump Fall Time", index);
                }

                if (moveInfo.HasSplineData)
                {
                    if (hasFullSpline)
                    {
                        packet.ReadSingle("Duration Mod Next", index);
                        for (uint i = 0; i < splineCount; i++)
                        {
                            Vector3 v = new Vector3();
                            v.Z = packet.ReadSingle();
                            v.Y = packet.ReadSingle();
                            v.X = packet.ReadSingle();

                            packet.AddValue("Spline", v, index);
                        }

                        var type = packet.ReadByte();
                        switch (type)
                        {
                            case 1:
                                splineType = SplineType.Normal;
                                break;
                            case 2:
                                splineType = SplineType.FacingSpot;
                                break;
                            case 3:
                                splineType = SplineType.FacingTarget;
                                break;
                            case 4:
                                splineType = SplineType.FacingAngle;
                                break;
                        }

                        packet.ReadSingle("Duration Mod", index);

                        //    NYI block here

                        if (splineType == SplineType.FacingSpot)
                            packet.ReadVector3("Facing spot", index);

                        if (hasSplineVerticalAcceleration)
                            packet.ReadSingle("Spline Vertical Acceleration", index);

                        if (splineType == SplineType.FacingAngle)
                            packet.ReadSingle("Facing Angle", index);

                        packet.ReadUInt32("Spline FULL Time", index);
                        if (hasSplineStartTime)
                            packet.ReadUInt32("Spline Start time", index);

                        packet.ReadUInt32("Spline Time", index);
                    }

                    packet.ReadUInt32("Spline ID", index);
                    packet.ReadVector3("Spline Endpoint", index);
                }

                /*for (var i = 0; i < 10; ++i)
                    packet.ReadSingle("unk float");
                if (bits98 > 0)
                    packet.ReadBits((int)bits98);*/
                //for (var i = 0; i < bits98; ++i)
                //    packet.ReadInt32("Int9C", index, i);

                moveInfo.Position.Z = packet.ReadSingle();
                moveInfo.Position.Y = packet.ReadSingle();
                packet.ReadSingle("Fly Speed", index);
                packet.ReadXORByte(guid1, 6);
                packet.ReadSingle("Fly Back Speed", index);

                if (hasTransportData)
                {
                    packet.ReadXORByte(transportGuid, 7);
                    packet.ReadXORByte(transportGuid, 4);

                    if (hasTransportTime3)
                        packet.ReadUInt32("Transport Time 3", index);

                    packet.ReadUInt32("Transport Time", index);

                    if (hasTransportTime2)
                        packet.ReadUInt32("Transport Time 2", index);

                    moveInfo.TransportOffset.O = packet.ReadSingle();
                    moveInfo.TransportOffset.X = packet.ReadSingle();
                    packet.ReadXORByte(transportGuid, 6);
                    packet.ReadXORByte(transportGuid, 3);
                    packet.ReadXORByte(transportGuid, 2);
                    moveInfo.TransportOffset.Z = packet.ReadSingle();
                    moveInfo.TransportOffset.Y = packet.ReadSingle();
                    var seat = packet.ReadSByte("Transport Seat", index);
                    packet.ReadXORByte(transportGuid, 1);
                    packet.ReadXORByte(transportGuid, 0);
                    packet.ReadXORByte(transportGuid, 5);

                    moveInfo.TransportGuid = new WowGuid64(BitConverter.ToUInt64(transportGuid, 0));
                    packet.AddValue("Transport GUID", moveInfo.TransportGuid, index);
                    packet.AddValue("Transport Position", moveInfo.TransportOffset, index);

                    if (moveInfo.TransportGuid.HasEntry() && moveInfo.TransportGuid.GetHighType() == HighGuidType.Vehicle &&
                        guid.HasEntry() && guid.GetHighType() == HighGuidType.Creature)
                    {
                        var vehicleAccessory = new VehicleTemplateAccessory
                        {
                            AccessoryEntry = guid.GetEntry(),
                            SeatId = seat
                        };

                        Storage.VehicleTemplateAccessorys.Add(moveInfo.TransportGuid.GetEntry(), vehicleAccessory, packet.TimeSpan);
                    }
                }

                moveInfo.Position.X = packet.ReadSingle();
                packet.AddValue("Position", moveInfo.Position, index);
                packet.ReadXORByte(guid1, 2);

                if (hasPitch)
                    packet.ReadSingle("Pitch", index);

                packet.ReadSingle("Swim Speed", index);
                packet.ReadXORByte(guid1, 1);
                packet.ReadSingle("Run Back Speed", index);
                packet.ReadSingle("Swim Back Speed", index);
                packet.ReadXORByte(guid1, 5);

                if (hasSplineElevation)
                    packet.ReadSingle("Spline Elevation", index);

                if (bitA8)
                    packet.ReadInt32("IntA8", index);

                packet.ReadSingle("Turn Speed", index);
                packet.ReadXORByte(guid1, 3);
                moveInfo.RunSpeed = packet.ReadSingle("Run Speed", index) / 7.0f;
                packet.ReadXORByte(guid1, 7);
                moveInfo.WalkSpeed = packet.ReadSingle("Walk Speed", index) / 2.5f;
                packet.ReadSingle("Pitch Speed", index);

                if (hasTimestamp)
                    packet.ReadUInt32("Time?", index);

                packet.ReadXORByte(guid1, 4);
                packet.ReadXORByte(guid1, 0);
                packet.WriteGuid("GUID2", guid1);

                if (hasOrientation)
                    moveInfo.Orientation = packet.ReadSingle("Orientation", index);
            }

            if (hasAttackingTarget)
            {
                packet.ParseBitStream(attackingTargetGuid, 5, 1, 2, 0, 3, 4, 6, 7);
                packet.WriteGuid("Attacking Target GUID", attackingTargetGuid, index);
            }

            if (hasStationaryPosition)
            {
                moveInfo.Orientation = packet.ReadSingle("Stationary Orientation", index);
                moveInfo.Position = packet.ReadVector3("Stationary Position", index);
            }

            if (hasTransportPosition)
            {
                packet.ReadSByte("Transport Seat", index);
                moveInfo.TransportOffset.X = packet.ReadSingle();
                packet.ReadXORBytes(goTransportGuid, 1, 0, 2, 6, 5, 4);

                if (hasGOTransportTime2)
                    packet.ReadUInt32("Transport Time 3", index);

                packet.ReadXORByte(goTransportGuid, 7);
                moveInfo.TransportOffset.O = packet.ReadSingle();
                moveInfo.TransportOffset.Z = packet.ReadSingle();
                moveInfo.TransportOffset.Y = packet.ReadSingle();

                if (hasGOTransportTime3)
                    packet.ReadUInt32("Transport Time 2", index);

                packet.ReadXORByte(goTransportGuid, 3);
                packet.ReadUInt32("Transport Time", index);

                moveInfo.TransportGuid = new WowGuid64(BitConverter.ToUInt64(goTransportGuid, 0));
                packet.AddValue("Transport GUID", moveInfo.TransportGuid, index);
                packet.AddValue("Transport Position", moveInfo.TransportOffset, index);
            }

            if (bit1DC)
                packet.ReadInt32("int1D8", index);

            if (bit2A4)
                packet.ReadInt32("int2A0", index);

            if (bit32A)
                packet.ReadBytes("Bytes", (int)bits2AA);

            if (hasGameObjectRotation)
                packet.ReadPackedQuaternion("GameObject Rotation", index);

            if (hasVehicleData)
            {
                moveInfo.VehicleId = packet.ReadUInt32("Vehicle Id", index);
                packet.ReadSingle("Vehicle Orientation", index);
            }

            if (bit414)
                packet.ReadInt32("int410", index);

            if (hasAnimKits)
            {
                if (hasAnimKit1)
                    packet.ReadUInt16("Anim Kit 1", index);
                if (hasAnimKit2)
                    packet.ReadUInt16("Anim Kit 2", index);
                if (hasAnimKit3)
                    packet.ReadUInt16("Anim Kit 3", index);
            }

            if (bit428)
                for (var i = 0; i < bits418; ++i)
                    packet.ReadInt32("Int3F8", index, i);

            if (isLiving && moveInfo.HasSplineData && hasFullSpline && splineType == SplineType.FacingTarget)
            {

                var facingTargetGuid = new byte[8];
                packet.StartBitStream(facingTargetGuid, 6, 7, 3, 0, 5, 1, 4, 2);
                packet.ParseBitStream(facingTargetGuid, 4, 2, 5, 6, 0, 7, 1, 3);
                packet.WriteGuid("Facing Target GUID", facingTargetGuid, index);
            }

            return moveInfo;
        }
        public static void HandleAuraUpdate(Packet packet)
        {
            var guid = new byte[8];
            var guid2 = new byte[8];

            guid[1] = packet.ReadBit();
            var hasPowerData = packet.ReadBit();

            uint bits3C = 0;
            if (hasPowerData)
            {
                packet.StartBitStream(guid2, 1, 5, 6);
                bits3C = packet.ReadBits(21);
                packet.StartBitStream(guid2, 2, 3, 7, 0, 4);
            }

            var bits4 = packet.ReadBits(24);
            guid[6] = packet.ReadBit();

            var hasAura = new bool[bits4];
            var hasCasterGUID = new bool[bits4];
            var hasDuration = new bool[bits4];
            var hasMaxDuration = new bool[bits4];
            var effectCount = new uint[bits4];
            var casterGUID = new byte[bits4][];
            for (var i = 0; i < bits4; ++i)
            {
                hasAura[i] = packet.ReadBit();
                if (hasAura[i])
                {
                    hasMaxDuration[i] = packet.ReadBit();
                    effectCount[i] = packet.ReadBits(22);
                    hasCasterGUID[i] = packet.ReadBit();
                    if (hasCasterGUID[i])
                    {
                        casterGUID[i] = new byte[8];
                        packet.StartBitStream(casterGUID[i], 5, 7, 4, 1, 6, 0, 3, 2);
                    }
                    hasDuration[i] = packet.ReadBit();
                }
            }
            packet.StartBitStream(guid, 2, 3, 7, 4);
            packet.ReadBit("Is AURA_UPDATE_ALL");
            packet.StartBitStream(guid, 0, 5);
            packet.ResetBitReader();

            var auras = new List<Aura>();
            for (var i = 0; i < bits4; ++i)
            {
                if (hasAura[i])
                {
                    var aura = new Aura();
                    if (hasCasterGUID[i])
                    {
                        packet.ParseBitStream(casterGUID[i], 2, 7, 6, 1, 4, 0, 5, 3);
                        packet.WriteGuid("Caster GUID", casterGUID[i], i);
                        aura.CasterGuid = new Guid(BitConverter.ToUInt64(casterGUID[i], 0));
                    }
                    else
                        aura.CasterGuid = new Guid();

                    aura.Charges = packet.ReadByte("Charges", i);

                    if (hasDuration[i])
                        aura.Duration = packet.ReadInt32("Duration", i);
                    else
                        aura.Duration = 0;

                    aura.SpellId = packet.ReadUInt32("Spell Id", i);
                    aura.AuraFlags = packet.ReadEnum<AuraFlagMoP>("Flags", TypeCode.Byte, i);

                    for (var j = 0; j < effectCount[i]; ++j)
                        packet.ReadSingle("Effect Value", i, j);
                    packet.ReadInt32("Effect Mask", i);

                    if (hasMaxDuration[i])
                        aura.MaxDuration = packet.ReadInt32("Max Duration", i);
                    else
                        aura.MaxDuration = 0;

                    aura.Level = packet.ReadUInt16("Caster Level", i);
                    auras.Add(aura);
                    packet.AddSniffData(StoreNameType.Spell, (int)aura.SpellId, "AURA_UPDATE");
                }
                packet.ReadByte("Slot", i);
            }

            if (hasPowerData)
            {
                packet.ReadXORBytes(guid2, 7, 0);
                for (var i = 0; i < bits3C; ++i)
                {
                    packet.ReadEnum<PowerType>("Power Type", TypeCode.UInt32, i);
                    packet.ReadInt32("Power Value", i);
                }
                packet.ReadXORBytes(guid2, 2, 5);
                packet.ReadInt32("Attack power");
                packet.ReadInt32("Spell power");
                packet.ReadXORBytes(guid2, 6, 4, 3, 1);
                packet.ReadInt32("Current Health");
                packet.WriteGuid("PowerUnitGUID", guid2);
            }
            packet.ParseBitStream(guid, 0, 5, 7, 2, 1, 4, 3, 6);
            packet.WriteGuid("Guid", guid);

            var GUID = new Guid(BitConverter.ToUInt64(guid, 0));
            if (Storage.Objects.ContainsKey(GUID))
            {
                var unit = Storage.Objects[GUID].Item1 as Unit;
                if (unit != null)
                {
                    // If this is the first packet that sends auras
                    // (hopefully at spawn time) add it to the "Auras" field,
                    // if not create another row of auras in AddedAuras
                    // (similar to ChangedUpdateFields)

                    if (unit.Auras == null)
                        unit.Auras = auras;
                    else if (unit.AddedAuras == null)
                        unit.AddedAuras = new List<List<Aura>> { auras };
                    else
                        unit.AddedAuras.Add(auras);
                }
            }
        }
        public static void HandleAttackStartStart(Packet packet)
        {
            var victimGUID = new byte[8];
            var attackerGUID = new byte[8];

            packet.StartBitStream(victimGUID, 6, 2, 1);
            attackerGUID[6] = packet.ReadBit();
            victimGUID[5] = packet.ReadBit();
            packet.StartBitStream(attackerGUID, 1, 3, 0);
            packet.StartBitStream(victimGUID, 0, 7);
            packet.StartBitStream(attackerGUID, 7, 5, 4);
            packet.StartBitStream(victimGUID, 4, 3);
            attackerGUID[2] = packet.ReadBit();

            packet.ReadXORByte(attackerGUID, 4);
            packet.ReadXORByte(victimGUID, 4);
            packet.ReadXORBytes(attackerGUID, 2, 6);
            packet.ReadXORByte(victimGUID, 7);
            packet.ReadXORByte(attackerGUID, 0);
            packet.ReadXORByte(victimGUID, 5);
            packet.ReadXORByte(attackerGUID, 1);
            packet.ReadXORBytes(victimGUID, 2, 6);
            packet.ReadXORByte(attackerGUID, 7);
            packet.ReadXORByte(victimGUID, 3);
            packet.ReadXORByte(attackerGUID, 5);
            packet.ReadXORByte(victimGUID, 0);
            packet.ReadXORByte(attackerGUID, 3);
            packet.ReadXORByte(victimGUID, 1);

            packet.WriteGuid("Attacker GUID", attackerGUID);
            packet.WriteGuid("Victim GUID", victimGUID);
        }
        public static void ReadClientMovementBlock(ref Packet packet)
        {
            var guid = new byte[8];
            var transportGUID = new byte[8];
            var pos = new Vector4();
            pos.Y = packet.ReadSingle();
            pos.Z = packet.ReadSingle();
            pos.X = packet.ReadSingle();

            guid[3] = packet.ReadBit();
            var hasSplineElevation = !packet.ReadBit();
            guid[0] = packet.ReadBit();
            var counter2 = packet.ReadBits(22);
            guid[2] = packet.ReadBit();
            var hasPitch = !packet.ReadBit();
            var hasOrientation = !packet.ReadBit();
            packet.ReadBit("bit9C");
            packet.ReadBit("bit85");
            guid[7] = packet.ReadBit();
            var isAlive = !packet.ReadBit();
            var hasFallData = packet.ReadBit();
            var hasExtraMovementFlags = !packet.ReadBit();
            var hasMovementFlags = !packet.ReadBit();
            var hastimestamp = !packet.ReadBit();
            packet.ReadBit("HasSpline");
            guid[6] = packet.ReadBit();
            guid[1] = packet.ReadBit();
            var hasTransportData = packet.ReadBit();
            guid[4] = packet.ReadBit();
            guid[5] = packet.ReadBit();

            bool hasTransportTime2 = false;
            bool hasTransportTime3 = false;
            bool hasFallDirection = false;
            if (hasTransportData)
            {
                packet.StartBitStream(transportGUID, 6, 3, 5);
                hasTransportTime2 = packet.ReadBit();
                packet.StartBitStream(transportGUID, 4, 7, 0, 1);
                hasTransportTime3 = packet.ReadBit();
                transportGUID[2] = packet.ReadBit();
            }

            if (hasMovementFlags)
                packet.ReadEnum<MovementFlag>("Movement Flags", 30);

            if (hasFallData)
                hasFallDirection = packet.ReadBit();

            if (hasExtraMovementFlags)
                packet.ReadEnum<MovementFlagExtra>("Extra Movement Flags", 13);

            packet.ResetBitReader();

            packet.ReadXORByte(guid, 0);
            for (var i = 0; i < counter2; ++i)
                packet.ReadInt32("Int8C", i);

            packet.ReadXORBytes(guid, 4, 1, 5, 6, 2, 3, 7);
            if (hasSplineElevation)
                packet.ReadSingle("Spline Elevation");

            if (hasTransportData)
            {
                var transPos = new Vector4();
                transPos.Y = packet.ReadSingle();
                packet.ReadXORBytes(transportGUID, 1, 4, 7);
                packet.ReadByte("Seat");
                packet.ReadInt32("Transport Time");
                transPos.X = packet.ReadSingle();
                packet.ReadXORBytes(transportGUID, 0, 6, 2);
                transPos.O = packet.ReadSingle();
                packet.ReadXORBytes(transportGUID, 3);
                if (hasTransportTime3)
                    packet.ReadInt32("Transport Time 3");

                packet.ReadXORBytes(transportGUID, 5);
                if (hasTransportTime2)
                    packet.ReadInt32("Transport Time 2");

                transPos.Z = packet.ReadSingle();
                packet.WriteGuid("Transport Guid", transportGUID);
                packet.WriteLine("Transport Position {0}", transPos);
            }

            if (hasOrientation)
                pos.O = packet.ReadSingle();

            if (hasFallData)
            {
                packet.ReadSingle("Velocity Speed");
                if (hasFallDirection)
                {
                    packet.ReadSingle("Horizontal Speed");
                    packet.ReadSingle("Fall Sin");
                    packet.ReadSingle("Fall Cos");
                }
                packet.ReadInt32("Fall Time");
            }

            if (hastimestamp)
                packet.ReadInt32("timestamp");

            if (hasPitch)
                packet.ReadSingle("Pitch");

            if (isAlive)
                packet.ReadInt32("time(isAlive)");

            packet.WriteGuid("Guid", guid);
            packet.WriteLine("Position: {0}", pos);
        }
        public static void HandleNpcGossipSelectOption(Packet packet)
        {
            var guid = new byte[8];
            var menuEntry = packet.ReadUInt32("Menu Id");
            var gossipId = packet.ReadUInt32("Gossip Id");
            packet.StartBitStream(guid, 2, 0, 6, 4, 1, 5, 3, 7);

            var bits8 = packet.ReadBits(8);

            packet.ReadXORByte(guid, 0);
            packet.ReadWoWString("Box Text", bits8);
            packet.ReadXORBytes(guid, 6, 5, 7, 4, 3, 2, 1);

            Storage.GossipSelects.Add(Tuple.Create(menuEntry, gossipId), null, packet.TimeSpan);
            packet.WriteGuid("GUID", guid);
        }
        private static MovementInfo ReadMovementUpdateBlock(ref Packet packet, WowGuid guid, object index)
        {
            var moveInfo = new MovementInfo();

            var guid1 = new byte[8];
            var transportGuid = new byte[8];
            var goTransportGuid = new byte[8];
            var attackingTargetGuid = new byte[8];
            var guid5 = new byte[8];
            var guid6 = new byte[8];
            var guid7 = new byte[8];

            var bit160 = false;
            var bit528 = false;
            var bit600 = false;
            var bit544 = false;
            var bit526 = false;
            var bit552 = false;
            var bit524 = false;
            var bit572 = false;
            var bit525 = false;
            var bit664 = false;
            var bit527 = false;
            var bit536 = false;
            var bit644 = false;
            var bit560 = false;

            var hasAnimKit1 = false;
            var hasAnimKit2 = false;
            var hasAnimKit3 = false;
            var hasFullSpline = false;
            var hasSplineStartTime = false;
            var hasSplineVerticalAcceleration = false;
            var hasMovementFlags = false;
            var hasMoveFlagsExtra = false;
            var hasTimestamp = false;
            var hasOrientation = false;
            var hasTransportData = false;
            var hasTransportTime2 = false;
            var hasTransportTime3 = false;
            var hasGOTransportTime2 = false;
            var hasGOTransportTime3 = false;
            var hasPitch = false;
            var hasFallData = false;
            var hasFallDirection = false;
            var hasSplineElevation = false;

            var bits168 = 0u;

            var splineCount = 0u;
            var bits138 = 0u;
            var bits98 = 0u;
            var bits25C = 0u;
            var bits26C = 0u;
            var bits288 = 0u;
            var bits418 = 0u;
            var bits2AA = 0u;
            var splineType = SplineType.Stop;

            var bit676 = packet.ReadBit("bit676", index);
            var hasAnimKits = packet.ReadBit("Has Anim Kits", index); // 498
            var isLiving = packet.ReadBit("Is Living", index); // 368
            var bit810 = packet.ReadBit("bit810", index);
            packet.ReadBit(); //fake bit
            var transportFrames = packet.ReadBits("Transport Frames Count", 22, index); // 1068
            var hasVehicleData = packet.ReadBit("Has Vehicle Data", index); // 488
            var bit1044 = packet.ReadBit("bit1044", index);
            packet.ReadBit(); //fake bit
            var bit476 = packet.ReadBit("bit476", index);
            var hasGameObjectRotation = packet.ReadBit("Has GameObject Rotation", index); // 512
            packet.ReadBit(); //fake bit
            var bit680 = packet.ReadBit("bit680", index);
            var hasAttackingTarget = packet.ReadBit("Has Attacking Target", index); // 464
            var hasSceneObjectData = packet.ReadBit("Has Scene Object Data", index); // 1032
            var bit1064 = packet.ReadBit("bit1064", index);
            packet.ReadBit(); //fake bit
            var bit668 = packet.ReadBit("bit668", index);
            var hasTransportPosition = packet.ReadBit("Has Transport Position", index); // 424
            var bit681 = packet.ReadBit("bit681", index);
            var hasStationaryPosition = packet.ReadBit("Has Stationary Position", index); // 448

            if (isLiving)
            {
                guid1[2] = packet.ReadBit();
                var bit140 = packet.ReadBit();
                hasPitch = !packet.ReadBit("Has Pitch", index); //104
                hasTransportData = packet.ReadBit("Has Transport Data", index); //96
                packet.ReadBit(); // 164 fake bit

                if (hasTransportData)
                {
                    transportGuid[4] = packet.ReadBit();
                    transportGuid[2] = packet.ReadBit();
                    hasTransportTime3 = packet.ReadBit();
                    transportGuid[0] = packet.ReadBit();
                    transportGuid[1] = packet.ReadBit();
                    transportGuid[3] = packet.ReadBit();
                    transportGuid[6] = packet.ReadBit();
                    transportGuid[7] = packet.ReadBit();
                    hasTransportTime2 = packet.ReadBit();
                    transportGuid[5] = packet.ReadBit();
                }
                hasTimestamp = !packet.ReadBit();
                guid1[6] = packet.ReadBit();
                guid1[4] = packet.ReadBit();
                guid1[3] = packet.ReadBit();
                hasOrientation = !packet.ReadBit(); //40
                bit160 = !packet.ReadBit();
                guid1[5] = packet.ReadBit();
                bits98 = packet.ReadBits("bits98", 22, index); //144
                hasMovementFlags = !packet.ReadBit();
                bits168 = packet.ReadBits(19); //352

                /*var bits356 = new uint[bits168];
                for (var i = 0; i < bits168; ++i)
                {
                    bits356[i] = packet.ReadBits(2);
                }*/

                hasFallData = packet.ReadBit(); //132

                if (hasMovementFlags)
                    moveInfo.Flags = packet.ReadEnum<MovementFlag>("Movement Flags", 30, index);

                hasSplineElevation = !packet.ReadBit("Has SplineElevation", index);//136
                moveInfo.HasSplineData = packet.ReadBit("Has SplineData", index);
                var bit141 = packet.ReadBit();
                guid1[0] = packet.ReadBit();
                guid1[7] = packet.ReadBit();
                guid1[1] = packet.ReadBit();

                if (moveInfo.HasSplineData)
                {
                    hasFullSpline = packet.ReadBit();
                    if (hasFullSpline)
                    {
                        hasSplineVerticalAcceleration = packet.ReadBit(); //260
                        hasSplineStartTime = packet.ReadBit(); //252
                        var bit304 = packet.ReadBit();

                        splineCount = packet.ReadBits(20);
                        packet.ReadEnum<SplineMode>("Spline Mode", 2, index);
                        packet.ReadEnum<SplineFlag434>("Spline flags", 25, index);

                        if (bit304)
                        {
                            bits138 = packet.ReadBits(21);
                            packet.ReadBits(2);
                        }
                    }
                }

                hasMoveFlagsExtra = !packet.ReadBit(); //20

                if (hasFallData)
                    hasFallDirection = packet.ReadBit(); //128

                if (hasMoveFlagsExtra)
                    moveInfo.FlagsExtra = packet.ReadEnum<MovementFlagExtra>("Extra Movement Flags", 13, index);

            }

            /*if (hasSceneObjectData)
            {

            }*/

            if (hasTransportPosition) //424
            {
                packet.StartBitStream(goTransportGuid, 4, 1, 0);
                hasGOTransportTime2 = packet.ReadBit(); // 420
                packet.StartBitStream(goTransportGuid, 6, 5, 3, 2, 7);
                hasGOTransportTime3 = packet.ReadBit(); // 412

            }

            if (bit668)
            {
                bit528 = packet.ReadBit();
                bit600 = packet.ReadBit();
                bit544 = packet.ReadBit();
                bit526 = packet.ReadBit();
                bit552 = packet.ReadBit();
                bit524 = packet.ReadBit();
                bit572 = packet.ReadBit();
                bit525 = packet.ReadBit();
                bit664 = packet.ReadBit();
                bit527 = packet.ReadBit();

                if (bit664)
                    bits288 = packet.ReadBits(20);

                bit536 = packet.ReadBit();
                bit644 = packet.ReadBit();
                bit560 = packet.ReadBit();

                if (bit664)
                {
                    bits25C = packet.ReadBits(21); //604
                    bits26C = packet.ReadBits(21); //624
                }
            }

            if (hasAnimKits)
            {
                hasAnimKit2 = !packet.ReadBit();
                hasAnimKit3 = !packet.ReadBit();
                hasAnimKit1 = !packet.ReadBit();
            }

            if (hasAttackingTarget)
                attackingTargetGuid = packet.StartBitStream(4, 6, 5, 2, 0, 1, 3, 7);

            if (bit1064)
                bits418 = packet.ReadBits(22);

            if (bit810)
                bits2AA = packet.ReadBits(7);

            packet.ResetBitReader();

            for (var i = 0; i < transportFrames; ++i)
                packet.ReadInt32("Transport frame", index, i);

            /*if (hasSceneObjectData)
            {
                until if ( *(_BYTE *)(v3 + 668) )
            }*/

            if (isLiving)
            {
                if (hasTransportData) //96
                {
                    packet.ReadXORByte(transportGuid, 7);
                    moveInfo.TransportOffset.X = packet.ReadSingle();

                    if (hasTransportTime3)
                        packet.ReadUInt32("Transport Time 3", index);

                    moveInfo.TransportOffset.O = packet.ReadSingle();
                    moveInfo.TransportOffset.Y = packet.ReadSingle();
                    packet.ReadXORByte(transportGuid, 4);
                    packet.ReadXORByte(transportGuid, 1);
                    packet.ReadXORByte(transportGuid, 3);
                    moveInfo.TransportOffset.Z = packet.ReadSingle();
                    packet.ReadXORByte(transportGuid, 5);

                    if (hasTransportTime2)
                        packet.ReadUInt32("Transport Time 2", index);

                    packet.ReadXORByte(transportGuid, 0);
                    var seat = packet.ReadSByte("Transport Seat", index); //72
                    packet.ReadXORByte(transportGuid, 6);
                    packet.ReadXORByte(transportGuid, 2);
                    packet.ReadUInt32("Transport Time", index); //76

                    moveInfo.TransportGuid = new WowGuid(BitConverter.ToUInt64(transportGuid, 0));
                    packet.AddValue("Transport GUID", moveInfo.TransportGuid, index);
                    packet.AddValue("Transport Position", moveInfo.TransportOffset, index);

                    if (moveInfo.TransportGuid.HasEntry() && moveInfo.TransportGuid.GetHighType() == HighGuidType.Vehicle &&
                        guid.HasEntry() && guid.GetHighType() == HighGuidType.Unit)
                    {
                        var vehicleAccessory = new VehicleTemplateAccessory();
                        vehicleAccessory.AccessoryEntry = guid.GetEntry();
                        vehicleAccessory.SeatId = seat;
                        Storage.VehicleTemplateAccessorys.Add(moveInfo.TransportGuid.GetEntry(), vehicleAccessory, packet.TimeSpan);
                    }
                }

                packet.ReadXORByte(guid1, 4);

                /*for (var i = 0; i < 10; ++i)
                    packet.ReadSingle("unk float");
                if (bits98 > 0)
                    packet.ReadBits((int)bits98);*/
                //for (var i = 0; i < bits98; ++i)
                //    packet.ReadInt32("Int9C", index, i);

                if (moveInfo.HasSplineData) //344
                {
                    if (hasFullSpline) //336
                    {
                        packet.ReadUInt32("Spline Time", index); //232
                        packet.ReadSingle("Duration Mod Next", index); //244

                        //    NYI block here
                        packet.ReadSingle("Duration Mod", index); //240

                        for (uint i = 0; i < splineCount; i++)
                        {
                            Vector3 v = new Vector3();
                            v.X = packet.ReadSingle(); //0
                            v.Z = packet.ReadSingle(); //8
                            v.Y = packet.ReadSingle(); //4

                            packet.AddValue("Spline", v, index);
                        }

                        if (hasSplineStartTime)
                            packet.ReadUInt32("Spline Start time", index); //256

                        var type = packet.ReadByte(); // 228

                        switch (type)
                        {
                            case 1:
                                splineType = SplineType.Normal;
                                break;
                            case 2:
                                splineType = SplineType.FacingSpot;
                                break;
                            case 3:
                                splineType = SplineType.FacingTarget;
                                break;
                            case 4:
                                splineType = SplineType.FacingAngle;
                                break;
                        }

                        if (splineType == SplineType.FacingAngle) // == 4
                            packet.ReadSingle("Facing Angle", index);

                        if (splineType == SplineType.FacingSpot) // == 2
                            packet.ReadVector3("Facing spot", index);

                        if (hasSplineVerticalAcceleration) //252
                            packet.ReadSingle("Spline Vertical Acceleration", index);

                        packet.ReadUInt32("Spline FULL Time", index); //236

                    }

                    moveInfo.Position.X = packet.ReadSingle(); //212
                    moveInfo.Position.Z = packet.ReadSingle(); //220
                    packet.ReadUInt32("Spline ID", index); //208
                    moveInfo.Position.Y = packet.ReadSingle(); //216
                }
                packet.ReadSingle("Fly Speed", index); //188

                if (bit160)
                    packet.ReadUInt32("unk160");

                packet.ReadXORByte(guid1, 2);

                if (hasFallData) //132
                {
                    if (hasFallDirection)//128
                    {
                        packet.ReadSingle("Jump Sin Angle", index); //124
                        packet.ReadSingle("Jump XY Speed", index); //116
                        packet.ReadSingle("Jump Cos Angle", index); //120

                    }
                    packet.ReadUInt32("Jump Fall Time", index); //108
                    packet.ReadSingle("Jump Z Speed", index); //112
                }
                packet.ReadXORByte(guid1, 1);
                packet.ReadSingle("Turn Speed", index);

                if (hasTimestamp)
                    packet.ReadUInt32("Time?", index);

                packet.ReadSingle("Swim Speed", index); //176

                if (hasSplineElevation) //136
                    packet.ReadSingle("Spline Elevation", index);//196

                packet.ReadXORByte(guid1, 7);
                packet.ReadSingle("Pitch Speed", index); //200

                for (var i = 0; i < bits98; ++i)
                    packet.ReadInt32("UNK counter", index, i);

                moveInfo.Position.X = packet.ReadSingle(); //28

                if (hasPitch)
                    packet.ReadSingle("Pitch", index); //104

                if (hasOrientation)
                    moveInfo.Orientation = packet.ReadSingle("Orientation", index); //40

                moveInfo.WalkSpeed = packet.ReadSingle("Walk Speed", index) / 2.5f; // 168
                moveInfo.Position.Y = packet.ReadSingle(); //32
                packet.ReadSingle("Fly Back Speed", index); //192
                packet.ReadXORByte(guid1, 3);
                packet.ReadXORByte(guid1, 5);
                packet.ReadXORByte(guid1, 6);
                packet.ReadXORByte(guid1, 0);
                packet.ReadSingle("Run Back Speed", index);//184
                moveInfo.RunSpeed = packet.ReadSingle("Run Speed", index) / 7.0f; //172
                packet.ReadSingle("Swim Back Speed", index);//180
                moveInfo.Position.Z = packet.ReadSingle(); //36
            }

            packet.AddValue("Position", moveInfo.Position, index);

            if (bit668)
            {
                if (bit664)
                {
                    for (var i = 0; i < bits288; ++i)
                    {
                        packet.ReadSingle("Float652+4", index, i);
                        packet.ReadSingle("Float652", index, i);
                        packet.ReadSingle("Float652+8", index, i);
                    }
                }

                if (bit600)
                {
                    packet.ReadSingle("Float584", index);
                    packet.ReadSingle("Float580", index);
                    packet.ReadSingle("Float596", index);
                    packet.ReadSingle("Float592", index);
                    packet.ReadSingle("Float576", index);
                    packet.ReadSingle("Float588", index);
                }

                if (bit644)
                {
                    for (var i = 0; i < bits25C; ++i)
                    {
                        packet.ReadSingle("Float608", index, i);
                        packet.ReadSingle("Float608+4", index, i);
                    }

                    for (var i = 0; i < bits26C; ++i)
                    {
                        packet.ReadSingle("Float260+0", index, i);
                        packet.ReadSingle("Float260+1", index, i);
                    }

                    packet.ReadSingle("Float624", index);
                    packet.ReadSingle("Float624+4", index);
                }

                packet.ReadUInt32("unk520", index);

                if (bit544)
                    packet.ReadUInt32("unk544", index);

                if (bit552)
                    packet.ReadUInt32("unk548", index);

                if (bit536)
                    packet.ReadUInt32("unk532", index);

                if (bit560)
                    packet.ReadUInt32("unk556", index);

                if (bit572)
                {
                    packet.ReadSingle("Float564", index);
                    packet.ReadSingle("Float568", index);
                }
            }

            if (hasTransportPosition)
            {
                if (hasGOTransportTime2)
                    packet.ReadUInt32("Transport Time 2", index);

                moveInfo.TransportOffset.Y = packet.ReadSingle(); //388
                packet.ReadSByte("Transport Seat", index); //400
                moveInfo.TransportOffset.X = packet.ReadSingle();//384

                packet.ReadXORBytes(goTransportGuid, 2, 4, 1);

                if (hasGOTransportTime3)
                    packet.ReadUInt32("Transport Time 3", index); //412

                packet.ReadUInt32("Transport Time", index); //404
                moveInfo.TransportOffset.O = packet.ReadSingle(); //396
                moveInfo.TransportOffset.Z = packet.ReadSingle(); //392

                packet.ReadXORBytes(goTransportGuid, 6, 0, 5, 3, 7);

                moveInfo.TransportGuid = new WowGuid(BitConverter.ToUInt64(goTransportGuid, 0));
                packet.AddValue("Transport GUID", moveInfo.TransportGuid, index);
                packet.AddValue("Transport Position", moveInfo.TransportOffset, index);
            }

            if (hasAttackingTarget)
            {
                packet.ParseBitStream(attackingTargetGuid, 7, 1, 5, 2, 6, 3, 0, 4);
                packet.WriteGuid("Attacking Target GUID", attackingTargetGuid, index);
            }

            if (hasVehicleData)
            {
                moveInfo.VehicleId = packet.ReadUInt32("Vehicle Id", index);
                packet.ReadSingle("Vehicle Orientation", index);
            }

            if (hasStationaryPosition)
            {
                moveInfo.Position.Y = packet.ReadSingle();
                moveInfo.Position.Z = packet.ReadSingle();
                moveInfo.Orientation = packet.ReadSingle("Stationary Orientation", index);
                moveInfo.Position.X = packet.ReadSingle();

                packet.AddValue("Stationary Position", moveInfo.Position, index);
            }

            if (bit676)
                packet.ReadUInt32("unk672");

            if (hasAnimKits)
            {
                if (hasAnimKit1)
                    packet.ReadUInt16("Anim Kit 1", index);
                if (hasAnimKit3)
                    packet.ReadUInt16("Anim Kit 3", index);
                if (hasAnimKit2)
                    packet.ReadUInt16("Anim Kit 2", index);
            }

            if (bit810)
                packet.ReadBytes("Bytes", (int)bits2AA);

            if (bit476)
                packet.ReadUInt32("unk472");

            if (bit1064)
            {
                for (var i = 0; i < bits418; ++i)
                    packet.ReadInt32("unk1052+4", index, i);
            }

            if (hasGameObjectRotation)
                packet.ReadPackedQuaternion("GameObject Rotation", index);

            if (bit1044)
                packet.ReadInt32("unk1040", index);

            if (isLiving && moveInfo.HasSplineData && hasFullSpline && splineType == SplineType.FacingTarget)
            {

                var facingTargetGuid = new byte[8];
                packet.StartBitStream(facingTargetGuid, 4, 7, 0, 5, 1, 2, 3, 6);
                packet.ParseBitStream(facingTargetGuid, 4, 2, 0, 5, 6, 3, 1, 7);
                packet.WriteGuid("Facing Target GUID", facingTargetGuid, index);
            }
            return moveInfo;
        }
        private static MovementInfo ReadMovementUpdateBlock(Packet packet, WowGuid guid, object index)
        {
            var moveInfo = new MovementInfo();

            var guid1 = new byte[8];
            var transportGuid = new byte[8];
            var goTransportGuid = new byte[8];
            var attackingTargetGuid = new byte[8];

            var hasAnimKit1 = false;
            var hasAnimKit2 = false;
            var hasAnimKit3 = false;
            var hasFullSpline = false;
            var hasSplineStartTime = false;
            var hasSplineVerticalAcceleration = false;
            var hasGOTransportTime2 = false;
            var hasGOTransportTime3 = false;
            var hasSplineElevation = false;
            var hasMovementFlags = false;
            var hasMoveFlagsExtra = false;
            var hasTimestamp = false;
            var hasOrientation = false;
            var hasTransportData = false;
            var hasTransportTime3 = false;
            var hasTransportTime2 = false;
            var hasPitch = false;
            var hasFallData = false;
            var hasFallDirection = false;

            var bit130 = false;
            var bitA0 = false;
            var bit23C = false;
            var bit298 = false;
            var bit230 = false;
            var bit284 = false;
            var bit228 = false;
            var bit258 = false;
            var bit218 = false;
            var bit220 = false;

            var bits160 = 0u;
            var splineCount = 0u;
            var bits11C = 0u;
            var bits90 = 0u;
            var bits25C = 0u;
            var bits26C = 0u;
            var bits288 = 0u;
            var bits418 = 0u;
            var bits2AA = 0u;
            SplineType splineType = SplineType.Stop;

            var bit2A9 = packet.ReadBit();
            var bit29C = packet.ReadBit();
            packet.ReadBit(); // fake 1
            var bit1DC = packet.ReadBit();
            var bit2A4 = packet.ReadBit();
            var bit2A8 = packet.ReadBit();
            packet.ReadBit(); // fake 0
            var hasAttackingTarget = packet.ReadBit("Has Attacking Target", index);
            var transportFrames = packet.ReadBits("Transport Frames Count", 22, index);
            var bit414 = packet.ReadBit();
            packet.ReadBit(); // fake 3
            var bit428 = packet.ReadBit();
            var bit32A = packet.ReadBit();
            var hasStationaryPosition = packet.ReadBit("Has Stationary Position", index);
            packet.ReadBit(); // fake 2
            var isLiving = packet.ReadBit("Is Living", index);
            var hasAnimKits = packet.ReadBit("Has Anim Kits", index);
            var hasVehicleData = packet.ReadBit("Has Vehicle Data", index);
            var hasGameObjectPosition = packet.ReadBit("Has GameObject Position", index);
            var hasSceneObjectData = packet.ReadBit("Has Scene Object Data", index);
            var hasGameObjectRotation = packet.ReadBit("Has GameObject Rotation", index);

            if (bit29C)
            {
                bit284 = packet.ReadBit();
                if (bit284)
                {
                    bits25C = packet.ReadBits(21);
                    bits26C = packet.ReadBits(21);
                }

                packet.ReadBit("bit20C", index);
                packet.ReadBit("bit210", index);
                bit23C = packet.ReadBit();
                bit298 = packet.ReadBit();
                packet.ReadBit("bit20F", index);
                packet.ReadBit("bit20E", index);
                bit218 = packet.ReadBit();
                bit220 = packet.ReadBit();
                if (bit298)
                    bits288 = packet.ReadBits(20);

                bit228 = packet.ReadBit();
                packet.ReadBit("bit20D", index);
                bit230 = packet.ReadBit();
                bit258 = packet.ReadBit();
            }

            if (bit428)
                bits418 = packet.ReadBits(22);

            if (isLiving)
            {
                guid1[4] = packet.ReadBit();
                guid1[1] = packet.ReadBit();
                bits160 = packet.ReadBits(19);
                for (var i = 0; i < bits160; ++i)
                    packet.ReadBits("bits164", 2, index, i);

                guid1[5] = packet.ReadBit();
                hasOrientation = !packet.ReadBit();
                guid1[7] = packet.ReadBit();
                bits90 = packet.ReadBits(22);
                moveInfo.HasSplineData = packet.ReadBit();
                hasSplineElevation = !packet.ReadBit();
                if (moveInfo.HasSplineData)
                {
                    hasFullSpline = packet.ReadBit();
                    if (hasFullSpline)
                    {
                        bit130 = packet.ReadBit();
                        hasSplineVerticalAcceleration = packet.ReadBit("has Spline Vertical Acceleration", index);
                        packet.ReadBitsE<SplineMode>("Spline Mode", 2, index);
                        if (bit130)
                        {
                            bits11C = packet.ReadBits(21);
                            packet.ReadBits("bits12C", 2, index);
                        }
                        packet.ReadBitsE<SplineFlag434>("Spline flags", 25, index);
                        hasSplineStartTime = packet.ReadBit("Has Spline Start Time", index);
                        splineCount = packet.ReadBits("SplineWaypointsCount", 20, index);
                    }
                }

                bitA0 = !packet.ReadBit();
                guid1[3] = packet.ReadBit();
                packet.ReadBit("bitA4", index);
                hasMovementFlags = !packet.ReadBit();
                if (hasMovementFlags)
                    moveInfo.Flags = packet.ReadBitsE<MovementFlag>("Movement Flags", 30, index);

                packet.ReadBit("bit8C", index);
                packet.ReadBit("bit8D", index);
                guid1[2] = packet.ReadBit();
                hasTimestamp = !packet.ReadBit();
                guid1[0] = packet.ReadBit();
                hasTransportData = packet.ReadBit();
                if (hasTransportData)
                {
                    packet.StartBitStream(transportGuid, 4, 7, 3, 1, 6);
                    hasTransportTime2 = packet.ReadBit();
                    packet.StartBitStream(transportGuid, 2, 0, 5);
                    hasTransportTime3 = packet.ReadBit();
                }

                guid1[6] = packet.ReadBit();
                hasFallData = packet.ReadBit();
                if (hasFallData)
                    hasFallDirection = packet.ReadBit();

                hasMoveFlagsExtra = !packet.ReadBit();
                hasPitch = !packet.ReadBit();
                if (hasMoveFlagsExtra)
                    moveInfo.FlagsExtra = packet.ReadBitsE<MovementFlagExtra>("Extra Movement Flags", 13, index);
            }

            if (hasGameObjectPosition)
            {
                packet.StartBitStream(goTransportGuid, 0, 7);
                hasGOTransportTime3 = packet.ReadBit();
                goTransportGuid[1] = packet.ReadBit();
                hasGOTransportTime2 = packet.ReadBit();
                packet.StartBitStream(goTransportGuid, 6, 5, 4, 3, 2);
            }

            if (bit32A)
                bits2AA = packet.ReadBits(7);

            if (hasAttackingTarget)
                packet.StartBitStream(attackingTargetGuid, 5, 4, 6, 0, 1, 7, 2, 3);

            // Sceneobject data
            var CreatorGUID = new byte[8];
            byte[][] guid358 = null;
            byte[][][] guid358_6 = null;
            uint[] bits358_10 = null;
            uint[][] bits358_6_84 = null;
            uint[][] bits358_6_94 = null;
            uint[][] bits358_6_31 = null;
            uint[][] bits358_6_74 = null;
            byte[][][] bit358_6_78_9 = null;
            byte[][][] bit358_6_88_10 = null;
            bool[][][] bit358_6_88_C = null;
            bool[][][] bit358_6_88_8 = null;
            bool[][] bit358_6_2E = null;
            bool[][] bit358_6_30 = null;
            bool[] bit358_20 = null;
            bool[] bit358_C = null;
            bool[] bit358_24 = null;

            var bit338 = false;
            var bit330 = false;
            var bit341 = false;
            var bit340 = false;
            var bit332 = false;
            var bit33C = false;

            uint[] bits388 = null;
            uint[] bits388_10 = null;
            byte[][] bit388_1_10 = null;
            bool[][] bit388_1_C = null;
            bool[][] bit388_1_8 = null;

            if (hasSceneObjectData)
            {
                guid358 = new byte[2][];
                guid358_6 = new byte[2][][];
                bits358_10 = new uint[2];
                bits358_6_84 = new uint[2][];
                bits358_6_94 = new uint[2][];
                bits358_6_31 = new uint[2][];
                bits358_6_74 = new uint[2][];
                bit358_6_78_9 = new byte[2][][];
                bit358_6_88_10 = new byte[2][][];
                bit358_6_88_C = new bool[2][][];
                bit358_6_88_8 = new bool[2][][];
                bit358_6_2E = new bool[2][];
                bit358_6_30 = new bool[2][];
                bit358_20 = new bool[2];
                bit358_C = new bool[2];
                bit358_24 = new bool[2];

                for (var i = 0; i < 2; ++i)
                {
                    guid358[i] = new byte[8];
                    packet.StartBitStream(guid358[i], 3, 4, 1, 0);
                    bits358_10[i] = packet.ReadBits(2);
                    bit358_20[i] = !packet.ReadBit();

                    guid358_6[i] = new byte[bits358_10[i]][];
                    bits358_6_84[i] = new uint[bits358_10[i]];
                    bits358_6_94[i] = new uint[bits358_10[i]];
                    bits358_6_31[i] = new uint[bits358_10[i]];
                    bits358_6_74[i] = new uint[bits358_10[i]];
                    bit358_6_78_9[i] = new byte[bits358_10[i]][];
                    bit358_6_88_10[i] = new byte[bits358_10[i]][];
                    bit358_6_88_C[i] = new bool[bits358_10[i]][];
                    bit358_6_88_8[i] = new bool[bits358_10[i]][];
                    bit358_6_2E[i] = new bool[bits358_10[i]];
                    bit358_6_30[i] = new bool[bits358_10[i]];

                    for (var j = 0; j < bits358_10[i]; ++j)
                    {
                        guid358_6[i][j] = new byte[8];
                        bits358_6_84[i][j] = packet.ReadBits(21);

                        bit358_6_88_8[i][j] = new bool[bits358_6_84[i][j]];
                        bit358_6_88_C[i][j] = new bool[bits358_6_84[i][j]];
                        bit358_6_88_10[i][j] = new byte[bits358_6_84[i][j]];
                        for (var k = 0; k < bits358_6_84[i][j]; ++k)
                        {
                            bit358_6_88_10[i][j][k] = (byte)(10 - packet.ReadBit());
                            bit358_6_88_C[i][j][k] = !packet.ReadBit();
                            bit358_6_88_8[i][j][k] = !packet.ReadBit();
                        }

                        packet.StartBitStream(guid358_6[i][j], 5, 3, 4, 1, 0, 6, 7);
                        bits358_6_31[i][j] = packet.ReadBits(7);
                        guid358_6[i][j][2] = packet.ReadBit();
                        bit358_6_2E[i][j] = !packet.ReadBit();
                        bits358_6_74[i][j] = packet.ReadBits(20);

                        bit358_6_78_9[i][j] = new byte[bits358_6_74[i][j]];
                        for (var k = 0; k < bits358_6_74[i][j]; ++k)
                            bit358_6_78_9[i][j][k] = (byte)(10 - packet.ReadBit());

                        bit358_6_30[i][j] = packet.ReadBit();
                        bits358_6_94[i][j] = packet.ReadBits(21);
                    }

                    guid358[i][6] = packet.ReadBit();
                    bit358_C[i] = !packet.ReadBit();
                    packet.StartBitStream(guid358[i], 2, 5);
                    bit358_24[i] = !packet.ReadBit();
                    guid358[i][7] = packet.ReadBit();
                }

                bit330 = !packet.ReadBit();
                bit340 = !packet.ReadBit();

                bits388 = new uint[3];
                bits388_10 = new uint[3];
                bit388_1_10 = new byte[3][];
                bit388_1_C = new bool[3][];
                bit388_1_8 = new bool[3][];

                for (var i = 0; i < 3; ++i)
                {
                    bits388_10[i] = packet.ReadBits(21);
                    bits388[i] = packet.ReadBits(21);
                    bit388_1_10[i] = new byte[bits388[i]];
                    bit388_1_C[i] = new bool[bits388[i]];
                    bit388_1_8[i] = new bool[bits388[i]];

                    for (var j = 0; j < bits388[i]; ++j)
                    {
                        bit388_1_8[i][j] = !packet.ReadBit();
                        bit388_1_10[i][j] = (byte)(10 - packet.ReadBit());
                        bit388_1_C[i][j] = !packet.ReadBit();
                    }
                }

                bit33C = !packet.ReadBit();
                bit341 = !packet.ReadBit();
                bit338 = !packet.ReadBit();
                bit332 = !packet.ReadBit();
                packet.ReadBit(); // fake bit
                packet.ReadBit("bit351", index);
                packet.ReadBit("bit350", index);
                packet.StartBitStream(CreatorGUID, 2, 7, 0, 5, 1, 3, 6, 4);
            }

            if (hasAnimKits)
            {
                hasAnimKit3 = !packet.ReadBit();
                hasAnimKit1 = !packet.ReadBit();
                hasAnimKit2 = !packet.ReadBit();
            }

            packet.ResetBitReader();

            for (var i = 0; i < transportFrames; ++i)
                packet.ReadInt32("Transport frame", index, i);

            if (hasSceneObjectData)
            {
                for (var i = 0; i < 2; ++i)
                {
                    for (var j = 0; j < bits358_10[i]; ++j)
                    {
                        for (var k = 0; k < bits358_6_74[i][j]; ++k)
                        {
                            packet.ReadInt32("int358+6+78+0", index, i, j, k);
                            packet.ReadInt16("short358+6+78+3", index, i, j, k);
                            packet.ReadByte("byte358+6+78+8", index, i, j, k);
                            packet.ReadInt16("short358+6+78+2", index, i, j, k);
                            if (bit358_6_78_9[i][j][k] != 9)
                                packet.ReadByte("byte358+6+78+9", index, i, j, k);
                        }

                        packet.ReadXORByte(guid358_6[i][j], 6);
                        for (var k = 0; k < bits358_6_84[i][j]; ++k)
                        {
                            packet.ReadInt32("int358+6+88+4", index, i, j, k);
                            packet.ReadInt32("int358+6+88+0", index, i, j, k);
                            if (bit358_6_88_8[i][j][k])
                                packet.ReadInt32("int358+6+88+8", index, i, j, k);

                            if (bit358_6_88_C[i][j][k])
                                packet.ReadInt32("int358+6+88+C", index, i, j, k);

                            if (bit358_6_88_10[i][j][k] != 9)
                                packet.ReadByte("byte358+6+88+10", index, i, j, k);
                        }

                        packet.ReadInt32("int358+6+28", index, i, j);
                        packet.ReadXORBytes(guid358_6[i][j], 5, 3);
                        packet.ReadInt32("int358+6+24", index, i, j);
                        packet.ReadXORByte(guid358_6[i][j], 1);
                        packet.ReadInt32("Int358+6+8", index, i, j);
                        packet.ReadInt16("short358+6+2C", index, i, j);
                        packet.ReadInt32("int358+6+C", index, i, j);
                        if (!bit358_6_30[i][j])
                            packet.ReadByte("byte358+6+30", index, i, j);

                        for (var k = 0; k < bits358_6_94[i][j]; ++k)
                        {
                            packet.ReadInt32("int358+6+98+4", index, i, j, k);
                            packet.ReadInt32("int358+6+98+0", index, i, j, k);
                        }

                        packet.ReadXORByte(guid358_6[i][j], 0);
                        packet.ReadWoWString("String358+6+31", (int)bits358_6_31[i][j], index, i, j);
                        packet.ReadInt32("int358+6+10", index, i, j);
                        packet.ReadInt16("short358+6+16", index, i, j);
                        packet.ReadInt16("short358+6+14", index, i, j);
                        packet.ReadXORByte(guid358_6[i][j], 2);
                        packet.ReadInt32("int358+6+18", index, i, j);
                        packet.ReadXORByte(guid358_6[i][j], 4);

                        if (bit358_6_2E[i][j])
                            packet.ReadInt16("short358+6+2E", index, i, j);

                        packet.ReadInt32("int358+6+1C", index, i, j);
                        packet.ReadInt32("int358+6+20", index, i, j);
                        packet.ReadXORByte(guid358_6[i][j], 7);

                        packet.WriteGuid("Guid 358_6", guid358_6[i][j], index, i, j);
                    }

                    packet.ReadXORBytes(guid358[i], 0, 7);
                    packet.ReadByte("byte358+25", index, i);
                    if (bit358_24[i])
                        packet.ReadInt32("int358+C", index, i);

                    packet.ReadXORBytes(guid358[i], 5, 4);
                    if (!bit358_20[i])
                        packet.ReadByte("byte358+24", index, i);

                    if (bit358_C[i])
                        packet.ReadInt16("Short358+10", index, i);

                    packet.ReadXORBytes(guid358[i], 1, 2, 3, 6);
                    packet.ReadInt32("int358+8", index, i);
                    packet.WriteGuid("Guid358", guid358[i], index, i);
                }

                for (var i = 0; i < 3; ++i)
                {
                    for (var j = 0; j < bits388_10[i]; ++j)
                    {
                        packet.ReadInt32("int388+6+4", index, i, j);
                        packet.ReadInt32("int388+6+0", index, i, j);
                    }

                    for (var j = 0; j < bits388[i]; ++j)
                    {
                        packet.ReadInt32("int388+1+0", index, i, j);
                        if (bit388_1_C[i][j])
                            packet.ReadInt32("int388+1+C", index, i, j);

                        if (bit388_1_8[i][j])
                            packet.ReadInt32("int388+1+8", index, i, j);

                        if (bit388_1_10[i][j] != 9)
                            packet.ReadByte("byte388+1+10", index, i, j);

                        packet.ReadInt32("int388+1+4", index, i, j);
                    }
                }

                if (bit338)
                    packet.ReadInt32("Int338", index);
                packet.ParseBitStream(CreatorGUID, 3, 5, 4, 2, 7, 6, 0, 1);

                if (bit33C)
                    packet.ReadInt32("Int33C", index);

                if (bit341)
                    packet.ReadByte("Byte341", index);

                if (bit340)
                    packet.ReadByte("Byte340", index);

                packet.ReadInt32("Int334", index);
                if (bit332)
                    packet.ReadInt16("Short332", index);

                if (bit330)
                    packet.ReadInt16("Short318", index);

                packet.WriteGuid("Creator GUID", CreatorGUID, index);
            }

            if (bit29C)
            {
                if (bit258)
                {
                    packet.ReadSingle("Float250", index);
                    packet.ReadSingle("Float254", index);
                    packet.ReadSingle("Float248", index);
                    packet.ReadSingle("Float24C", index);
                    packet.ReadSingle("Float240", index);
                    packet.ReadSingle("Float244", index);
                }

                if (bit284)
                {
                    packet.ReadSingle("Float280", index);
                    for (var i = 0; i < bits26C; ++i)
                    {
                        packet.ReadSingle("Float270+1", index, i);
                        packet.ReadSingle("Float270+0", index, i);
                    }

                    packet.ReadSingle("Float27C", index);
                    for (var i = 0; i < bits25C; ++i)
                    {
                        packet.ReadSingle("Float260+0", index, i);
                        packet.ReadSingle("Float260+1", index, i);
                    }
                }

                if (bit230)
                    packet.ReadInt32("int22C", index);

                if (bit220)
                    packet.ReadInt32("int21C", index);

                if (bit23C)
                {
                    packet.ReadSingle("Float238", index);
                    packet.ReadSingle("Float234", index);
                }

                if (bit298)
                {
                    for (var i = 0; i < bits288; ++i)
                    {
                        packet.ReadSingle("Float28C+0", index, i);
                        packet.ReadSingle("Float28C+2", index, i);
                        packet.ReadSingle("Float28C+1", index, i);
                    }
                }

                packet.ReadInt32("Int208", index);
                if (bit228)
                    packet.ReadInt32("int224", index);

                if (bit218)
                    packet.ReadInt32("int214", index);
            }

            if (isLiving)
            {
                moveInfo.Position.Y = packet.ReadSingle();
                if (moveInfo.HasSplineData)
                {
                    if (hasFullSpline)
                    {
                        for (var i = 0u; i < splineCount; ++i)
                        {
                            var wp = new Vector3
                            {
                                Z = packet.ReadSingle(),
                                X = packet.ReadSingle(),
                                Y = packet.ReadSingle()
                            };

                            packet.AddValue("Spline Waypoint", wp, index, i);
                        }

                        packet.ReadInt32("Spline Time", index); // if need swap with "Spline Full Time"
                        if (hasSplineVerticalAcceleration)
                            packet.ReadSingle("Spline Vertical Acceleration", index);

                        if (bit130)
                        {
                            for (var i = 0; i < bits11C; ++i)
                            {
                                packet.ReadSingle("Float13C+1", index, i);
                                packet.ReadSingle("Float13C+0", index, i);
                            }
                        }

                        packet.ReadInt32("Spline Full Time", index);

                        if (hasSplineStartTime)
                            packet.ReadInt32("Spline Start Time", index);

                        var type = packet.ReadByte();
                        switch (type)
                        {
                            case 1:
                                splineType = SplineType.Normal;
                                break;
                            case 2:
                                splineType = SplineType.FacingSpot;
                                break;
                            case 3:
                                splineType = SplineType.FacingTarget;
                                break;
                            case 4:
                                splineType = SplineType.FacingAngle;
                                break;
                        }

                        packet.ReadSingle("Spline Duration Multiplier", index); // if need swap with "Spline Duration Multiplier Next"
                        packet.ReadSingle("Spline Duration Multiplier Next", index);

                        if (splineType == SplineType.FacingSpot)
                        {
                            var point = new Vector3
                            {
                                Y = packet.ReadSingle(),
                                Z = packet.ReadSingle(),
                                X = packet.ReadSingle()
                            };

                            packet.AddValue("Facing Spot", point, index);
                        }

                        if (splineType == SplineType.FacingAngle)
                            packet.ReadSingle("Facing Angle", index);
                    }

                    moveInfo.Position.Y = packet.ReadSingle();
                    moveInfo.Position.Z = packet.ReadSingle();
                    moveInfo.Position.X = packet.ReadSingle();
                    packet.ReadInt32("Spline Id", index);
                }

                packet.ReadSingle("FloatBC", index);
                packet.ReadSingle("FloatAC", index);
                packet.ReadXORByte(guid1, 4);
                packet.ReadSingle("FloatA8", index);

                if (hasFallData)
                {
                    if (hasFallDirection)
                    {
                        packet.ReadSingle("Jump Velocity", index);
                        packet.ReadSingle("Jump Sin", index);
                        packet.ReadSingle("Jump Cos", index);
                    }

                    packet.ReadUInt32("Time Fallen", index);
                    packet.ReadSingle("Fall Start Velocity", index);
                }

                if (hasTransportData)
                {
                    packet.ReadXORByte(transportGuid, 5);
                    var seat = packet.ReadByte("Transport Seat", index);
                    packet.ReadXORByte(transportGuid, 2);
                    moveInfo.TransportOffset.O = packet.ReadSingle();
                    packet.ReadXORBytes(transportGuid, 4, 7);
                    if (hasTransportTime2)
                        packet.ReadUInt32("Transport Time 2", index);

                    packet.ReadUInt32("Transport Time", index);
                    moveInfo.TransportOffset.Y = packet.ReadSingle();
                    packet.ReadXORBytes(transportGuid, 3, 6);
                    moveInfo.TransportOffset.X = packet.ReadSingle();
                    packet.ReadXORByte(transportGuid, 0);
                    if (hasTransportTime3)
                        packet.ReadUInt32("Transport Time 3", index);
                    packet.ReadXORByte(transportGuid, 1);
                    moveInfo.TransportOffset.Z = packet.ReadSingle();

                    moveInfo.TransportGuid = new WowGuid64(BitConverter.ToUInt64(transportGuid, 0));
                    packet.AddValue("Transport GUID", moveInfo.TransportGuid, index);
                    packet.AddValue("Transport Position", moveInfo.TransportOffset, index);

                    if (moveInfo.TransportGuid.HasEntry() && moveInfo.TransportGuid.GetHighType() == HighGuidType.Vehicle &&
                        guid.HasEntry() && guid.GetHighType() == HighGuidType.Creature)
                    {
                        var vehicleAccessory = new VehicleTemplateAccessory();
                        vehicleAccessory.AccessoryEntry = guid.GetEntry();
                        vehicleAccessory.SeatId = seat;
                        Storage.VehicleTemplateAccessorys.Add(moveInfo.TransportGuid.GetEntry(), vehicleAccessory, packet.TimeSpan);
                    }
                }

                packet.ReadXORByte(guid1, 5);

                if (hasTimestamp)
                    packet.ReadUInt32("Time", index);

                for (var i = 0; i < bits90; ++i)
                    packet.ReadInt32("Int8C", index, i);

                if (bitA0)
                    packet.ReadInt32("Int98", index);

                packet.ReadXORByte(guid1, 1);
                packet.ReadSingle("FloatB0", index);
                packet.ReadSingle("FloatC0", index);
                packet.ReadXORByte(guid1, 6);
                packet.ReadSingle("FloatC4", index);

                for (var i = 0; i < bits160; ++i)
                {
                    packet.ReadSingle("Float16C+3", index, i);
                    packet.ReadSingle("Float16C+5", index, i);
                    packet.ReadSingle("Float16C+1", index, i);
                    packet.ReadInt32("Int16C+0", index, i);
                    packet.ReadInt32("Int16C+4", index, i);
                    packet.ReadSingle("Float16C+2", index, i);
                }

                moveInfo.Position.X = packet.ReadSingle();
                if (hasOrientation)
                    moveInfo.Orientation = packet.ReadSingle();

                packet.ReadSingle("FloatC8", index);
                packet.ReadSingle("FloatB4", index);
                if (hasSplineElevation)
                    packet.ReadSingle("Spline Elevation", index);

                packet.ReadXORByte(guid1, 3);
                if (hasPitch)
                    packet.ReadSingle("Pitch", index);

                packet.ReadSingle("FloatB8", index);
                packet.ReadXORBytes(guid1, 7, 2);
                moveInfo.Position.Z = packet.ReadSingle();
                packet.ReadXORByte(guid1, 0);

                packet.WriteGuid("GUID1", guid1, index);
                packet.AddValue("Position", moveInfo.Position, index);
                packet.AddValue("Orientation", moveInfo.Orientation, index);
            }

            if (hasStationaryPosition)
            {
                moveInfo.Position.X = packet.ReadSingle();
                moveInfo.Position.Z = packet.ReadSingle();
                moveInfo.Position.Y = packet.ReadSingle();
                moveInfo.Orientation = packet.ReadSingle("Stationary Orientation", index);

                packet.AddValue("Stationary Position", moveInfo.Position, index);
            }

            if (hasGameObjectPosition)
            {
                if (hasGOTransportTime2)
                    packet.ReadUInt32("GO Transport Time 2", index);

                packet.ReadXORBytes(goTransportGuid, 4, 2, 7, 3);
                packet.ReadUInt32("GO Transport Time", index);
                moveInfo.TransportOffset.Y = packet.ReadSingle();
                packet.ReadXORByte(goTransportGuid, 1);
                moveInfo.TransportOffset.Z = packet.ReadSingle();
                packet.ReadSByte("GO Transport Seat", index);
                if (hasGOTransportTime3)
                    packet.ReadUInt32("GO Transport Time 3", index);

                packet.ReadXORByte(goTransportGuid, 6);
                moveInfo.TransportOffset.O = packet.ReadSingle();
                packet.ReadXORBytes(goTransportGuid, 5, 0);
                moveInfo.TransportOffset.X = packet.ReadSingle();

                moveInfo.TransportGuid = new WowGuid64(BitConverter.ToUInt64(goTransportGuid, 0));
                packet.AddValue("GO Transport GUID", moveInfo.TransportGuid, index);
                packet.AddValue("GO Transport Position", moveInfo.TransportOffset, index);
            }

            if (hasGameObjectRotation)
                packet.ReadPackedQuaternion("GameObject Rotation", index);

            if (hasAttackingTarget)
            {
                packet.ParseBitStream(attackingTargetGuid, 4, 6, 3, 0, 7, 1, 2, 5);
                packet.WriteGuid("Attacking GUID", attackingTargetGuid, index);
            }

            if (hasAnimKits)
            {
                if (hasAnimKit3)
                    packet.ReadUInt16("Anim Kit 3", index);
                if (hasAnimKit1)
                    packet.ReadUInt16("Anim Kit 1", index);
                if (hasAnimKit2)
                    packet.ReadUInt16("Anim Kit 2", index);
            }

            if (bit1DC)
                packet.ReadInt32("int1D8", index);

            if (hasVehicleData)
            {
                moveInfo.VehicleId = packet.ReadUInt32("Vehicle Id", index);
                packet.ReadSingle("Vehicle Orientation", index);
            }

            if (bit2A4)
                packet.ReadInt32("int2A0", index);

            if (bit414)
                packet.ReadInt32("int410", index);

            if (bit32A)
                packet.ReadBytes("Bytes", (int)bits2AA);

            if (bit428)
                for (var i = 0; i < bits418; ++i)
                    packet.ReadInt32("Int3F8", index, i);

            if (isLiving && moveInfo.HasSplineData && hasFullSpline && splineType == SplineType.FacingTarget)
            {
                var facingTargetGuid = new byte[8];
                facingTargetGuid = packet.StartBitStream(5, 3, 6, 2, 7, 0, 1, 4);
                packet.ParseBitStream(facingTargetGuid, 7, 0, 1, 4, 2, 5, 3, 6);
                packet.WriteGuid("Facing Target GUID", facingTargetGuid, index);
            }

            return moveInfo;
        }
Exemple #20
0
        public static void HandleNpcGossipSelectOption(Packet packet)
        {
            var guid = new byte[8];
            var gossipId = packet.ReadUInt32("GossipMenu Id");
            var menuEntry = packet.ReadUInt32("Menu Id");
            guid[7] = packet.ReadBit();
            guid[6] = packet.ReadBit();
            guid[1] = packet.ReadBit();
            var bits8 = packet.ReadBits(8);
            guid[5] = packet.ReadBit();
            guid[2] = packet.ReadBit();
            guid[4] = packet.ReadBit();
            guid[3] = packet.ReadBit();
            guid[0] = packet.ReadBit();

            packet.ReadXORBytes(guid, 1, 0, 6, 3, 7, 5, 2);
            packet.ReadWoWString("Box Text", bits8);
            packet.ReadXORByte(guid, 4);

            Storage.GossipSelects.Add(Tuple.Create(menuEntry, gossipId), null, packet.TimeSpan);
            packet.WriteGuid("GUID", guid);
        }
 public static void HandleRequestPartyMemberStats(Packet packet)
 {
     packet.ReadByte("Flags");
     var guid = new byte[8];
     packet.StartBitStream(guid, 7, 4, 0, 1, 3, 6, 2, 5);
     packet.ReadXORBytes(guid, 3, 6, 5, 2, 1, 4, 0, 7);
     packet.WriteGuid("Guid", guid);
 }
        public static void HandleSpellGo(Packet packet)
        {
            var guid = new byte[8];
            var guid2 = new byte[8];
            var SourceTransportGUID = new byte[8];
            byte[][] guid4;
            byte[][] guid5;
            var DestinationTransportGUID = new byte[8];
            byte[][] guid7;
            var guid8 = new byte[8];
            var guid9 = new byte[8];
            var guid10 = new byte[8];
            var guid11 = new byte[8];

            uint powerCount = 0;

            guid10[5] = packet.ReadBit();
            var counter = packet.ReadBits(24);
            var hasPredictedType = !packet.ReadBit();
            var bit404 = !packet.ReadBit();
            packet.ReadBit("field_A8");
            guid11[6] = packet.ReadBit();
            var bit432 = !packet.ReadBit();
            var counter3 = packet.ReadBits(20);
            packet.StartBitStream(guid, 2, 1, 0, 4, 5, 6, 3, 7);
            packet.StartBitStream(guid10, 0, 1, 3);

            guid7 = new byte[counter][];
            for (var i = 0; i < counter; ++i)
            {
                guid7[i] = new byte[8];
                packet.StartBitStream(guid7[i], 5, 6, 4, 7, 1, 2, 3, 0);
            }

            var hasCastSchoolImmunities = !packet.ReadBit();
            guid11[5] = packet.ReadBit();
            var hasRuneStateBefore = !packet.ReadBit();
            var powerLeftSelf = packet.ReadBits(21);
            var bit408 = !packet.ReadBit();
            var counter2 = packet.ReadBits(24);
            var hasPowerData = packet.ReadBit();
            packet.StartBitStream(guid10, 6, 2);
            guid11[7] = packet.ReadBit();
            var RuneCooldownCount = packet.ReadBits(3);
            var hasTargetFlags = !packet.ReadBit();
            var hasSourceData = packet.ReadBit();

            if (hasPowerData)
            {
                packet.StartBitStream(guid2, 7, 4, 5, 0, 2, 6, 3, 1);
                powerCount = packet.ReadBits(21);
            }

            var bit412 = !packet.ReadBit();

            if (hasSourceData)
                packet.StartBitStream(SourceTransportGUID, 6, 3, 0, 1, 4, 5, 2, 7);

            guid11[1] = packet.ReadBit();

            guid4 = new byte[counter2][];
            for (var i = 0; i < counter2; ++i)
            {
                guid4[i] = new byte[8];
                packet.StartBitStream(guid4[i], 6, 4, 1, 7, 5, 2, 3, 0);
            }

            guid5 = new byte[counter3][];
            for (var i = 0; i < counter3; ++i)
            {
                guid5[i] = new byte[8];
                packet.StartBitStream(guid5[i], 7, 6, 5, 0, 4, 3, 1, 2);
            }
            var bit416 = !packet.ReadBit();
            guid11[0] = packet.ReadBit();
            packet.ReadBits("int5C", 12);
            packet.StartBitStream(guid10, 7, 4);
            var hasDestinationData = packet.ReadBit();

            if (hasDestinationData)
                packet.StartBitStream(DestinationTransportGUID, 0, 2, 7, 6, 1, 4, 3, 5);

            var hasRuneStateAfter = !packet.ReadBit();
            var hasCastImmunities = !packet.ReadBit();
            guid11[3] = packet.ReadBit();
            var bit420 = packet.ReadBit();
            var hasPredictedSpellId = !packet.ReadBit();
            guid11[4] = packet.ReadBit();
            var unkflag27 = packet.ReadBit();

            int bits7 = 0;
            if (!unkflag27)
                bits7 = (int)packet.ReadBits(7);

            var counter4 = packet.ReadBits(25);
            guid11[2] = packet.ReadBit();

            for (var i = 0; i < counter4; ++i)
            {
                var bits136 = packet.ReadBits("bits136", 4);

                if (bits136 == 11)
                    packet.ReadBits("bits140", 4);
            }

            packet.ReadBit("unk464");
            packet.StartBitStream(guid8, 7, 3, 6, 4, 2, 5, 0, 1);
            packet.ReadBit("unk160");
            packet.StartBitStream(guid9, 3, 5, 2, 1, 4, 0, 6, 7);

            if (hasTargetFlags)
                packet.ReadEnum<TargetFlag>("Target Flags", 20);

            if (hasSourceData)
            {
                var pos = new Vector3();
                packet.ReadXORBytes(SourceTransportGUID, 3, 7, 4);
                pos.X = packet.ReadSingle();
                packet.ReadXORBytes(SourceTransportGUID, 6, 5, 2);
                pos.Z = packet.ReadSingle();
                pos.Y = packet.ReadSingle();
                packet.ReadXORBytes(SourceTransportGUID, 0, 1);
                packet.WriteGuid("Source Transport GUID", SourceTransportGUID);
                packet.WriteLine("Source Position: {0}", pos);
            }

            for (var i = 0; i < counter3; ++i)
            {
                var pos = new Vector3();
                packet.ReadXORBytes(guid5[i], 4, 0, 7, 6, 2, 1);
                pos.X = packet.ReadSingle();
                packet.ReadXORBytes(guid5[i], 5, 3);
                pos.Y = packet.ReadSingle();
                pos.Z = packet.ReadSingle();
                packet.WriteGuid("GUID5", guid5[i], i);
                packet.WriteLine("Position: {0}", pos);
            }

            for (var i = 0; i < counter; ++i)
            {
                packet.ParseBitStream(guid7[i], 2, 1, 5, 3, 7, 0, 4, 6);
                packet.WriteGuid("GUID7", guid7[i], i);
            }

            if (hasDestinationData)
            {
                var pos = new Vector3();
                packet.ReadXORBytes(DestinationTransportGUID, 1, 4);
                pos.Z = packet.ReadSingle();
                packet.ReadXORBytes(DestinationTransportGUID, 0, 7, 3, 5);
                pos.Y = packet.ReadSingle();
                packet.ReadXORByte(DestinationTransportGUID, 6);
                pos.X = packet.ReadSingle();
                packet.ReadXORByte(DestinationTransportGUID, 2);
                packet.WriteGuid("Destination Transport GUID", DestinationTransportGUID);
                packet.WriteLine("Destination Position: {0}", pos);
            }
            if (bit408)
                packet.ReadSingle("float198");

            if (bit416)
                packet.ReadByte("unk.416");

            packet.ParseBitStream(guid8, 5, 0, 2, 7, 6, 3, 4, 1);
            packet.WriteGuid("GUID8", guid8);

            for (var i = 0; i < counter2; ++i)
            {
                packet.ParseBitStream(guid4[i], 6, 3, 1, 0, 2, 4, 7, 5);
                packet.WriteGuid("GUID4", guid4[i], i);
            }

            if (hasPowerData)
            {
                packet.ReadXORByte(guid2, 3);
                packet.ReadUInt32("Spell Power");
                packet.ReadXORBytes(guid2, 6, 4, 7, 0);
                packet.ReadUInt32("Attack Power");
                packet.ReadXORByte(guid2, 2);

                for (var i = 0; i < powerCount; ++i)
                {
                    packet.ReadUInt32("uint32 60");
                    packet.ReadUInt32("uint32 48");
                }

                packet.ReadUInt32("Current Health");
                packet.ReadXORBytes(guid2, 1, 5);
                packet.WriteGuid("GUID2", guid2);
            }

            packet.ParseBitStream(guid9, 2, 3, 4, 7, 5, 1, 6, 0);
            packet.WriteGuid("GUID9", guid9);

            packet.ReadByte("Cast Count");

            packet.ParseBitStream(guid, 0, 1, 4, 5, 7, 6, 2, 3);
            packet.WriteGuid("GUID", guid);

            packet.ReadXORByte(guid10, 7);
            if (hasPredictedType)
                packet.ReadByte("Predicted Type");

            if (hasPredictedSpellId)
                packet.ReadUInt32("Predicted Spell Id");

            packet.ReadXORByte(guid10, 3);

            var bytes = packet.ReadBytes(bits7);
            packet.WriteLine("Bytes {0}", Utilities.ByteArrayToHexString(bytes));

            if (bit404)
                packet.ReadUInt32("uint32 404");

            if (hasCastImmunities)
                packet.ReadUInt32("Cast Immunities");

            packet.ReadXORByte(guid10, 2);
            packet.ReadXORByte(guid11, 0);

            if (bit420)
            {
                packet.ReadUInt32("uint32 424");
                packet.ReadUInt32("uint32 428");
            }

            if (bit412)
                packet.ReadUInt32("uint32 412");

            packet.ReadXORByte(guid11, 2);
            packet.ReadXORBytes(guid10, 0, 1);
            packet.ReadXORByte(guid11, 3);

            for (var i = 0; i < RuneCooldownCount; ++i)
                packet.ReadByte("Rune Cooldown Passed", i);

            if (hasRuneStateAfter)
                packet.ReadByte("Rune State After");

            packet.ReadXORByte(guid11, 1);
            packet.ReadXORByte(guid10, 4);
            packet.ReadEntryWithName<Int32>(StoreNameType.Spell, "Spell ID");

            if (hasRuneStateBefore)
                packet.ReadByte("Rune State Before");

            packet.ReadXORByte(guid10, 6);
            packet.ReadXORByte(guid11, 5);
            packet.ReadUInt32("uint32 88"); // field_58
            packet.ReadXORByte(guid11, 4);
            packet.ReadUInt32("uint32 96"); // field_60

            for (var i = 0; i < powerLeftSelf; ++i)
            {
                packet.ReadInt32("Power Value", i);
                packet.ReadEnum<PowerType>("Power Type", TypeCode.Byte, i);
            }
            packet.ReadXORByte(guid10, 5);
            packet.ReadXORByte(guid11, 6);

            if (hasCastSchoolImmunities)
                packet.ReadUInt32("Cast School Immunities");

            packet.ReadXORByte(guid11, 7);

            if (bit432)
                packet.ReadByte("unk432");

            packet.WriteGuid("GUID10", guid10);
            packet.WriteGuid("GUID11", guid11);
        }
        public static void HandleCastSpell(Packet packet)
        {
            var counter = packet.ReadBits(2);
            var unk_bit = !packet.ReadBit();
            for (var i = 0; i < counter; ++i)
                packet.ReadBits("unk value0", 2, i);

            var HasCastCount = !packet.ReadBit();
            packet.ReadBit("Fake bit? Has TargetGUID"); // TargetGUID
            var hasbit1C = !packet.ReadBit();
            var hasMovment = packet.ReadBit();
            var hasbit78 = !packet.ReadBit();
            var hasbitF8 = !packet.ReadBit();
            var hasGUID2 = packet.ReadBit();
            var hasbitFC = !packet.ReadBit();
            var hasbit18 = !packet.ReadBit();
            var hasGUID3 = packet.ReadBit();
            packet.ReadBit("Fake bit? Has GUID0"); // GUID0
            var hasSpellId = !packet.ReadBit();

            var GUID0 = new byte[8];
            var TargetGUID = new byte[8];
            var GUID2 = new byte[8];
            var GUID3 = new byte[8];

            GUID0 = packet.StartBitStream(0, 5, 1, 7, 4, 3, 6, 2);
            if (hasGUID3)
                GUID3 = packet.StartBitStream(2, 5, 3, 7, 4, 1, 0, 6);

            if (hasGUID2)
                GUID2 = packet.StartBitStream(6, 2, 4, 7, 3, 5, 0, 1);

            TargetGUID = packet.StartBitStream(3, 0, 2, 7, 6, 4, 1, 5);

            if (unk_bit)
                packet.ReadEnum<CastFlag>("Cast Flags", 20);

            if (hasbit1C)
                packet.ReadBits("hasbit1C", 5);

            uint len78 = 0;
            if (hasbit78)
                len78 = packet.ReadBits("hasbit78", 7);
            packet.ResetBitReader();

            for (var i = 0; i < counter; ++i)
            {
                packet.ReadInt32("unk value1", i);
                packet.ReadInt32("unk value2", i);
            }

            if (hasGUID3)
            {
                var pos = new Vector3();
                packet.ReadXORBytes(GUID3, 7, 5, 3);
                pos.X = packet.ReadSingle();
                packet.ReadXORBytes(GUID3, 0, 2, 1, 4, 6);
                pos.Z = packet.ReadSingle();
                pos.Y = packet.ReadSingle();
                packet.WriteGuid("GUID3", GUID3);
                packet.WriteLine("Position: {0}", pos);
            }

            packet.ParseBitStream(TargetGUID, 2, 0, 5, 6, 7, 3, 4, 1);
            packet.WriteGuid("Target GUID", TargetGUID);

            if (hasGUID2)
            {
                var pos = new Vector3();
                packet.ReadXORBytes(GUID2, 5, 7);
                pos.Y = packet.ReadSingle();
                pos.X = packet.ReadSingle();
                packet.ReadXORBytes(GUID2, 3, 1);
                pos.Z = packet.ReadSingle();
                packet.ReadXORBytes(GUID2, 2, 6, 4, 0);
                packet.WriteGuid("GUID2", GUID2);
                packet.WriteLine("Position: {0}", pos);
            }

            packet.ParseBitStream(GUID0, 7, 2, 6, 4, 1, 0, 3, 5);
            packet.WriteGuid("GUID0", GUID0);

            if (hasbit78)
                packet.ReadWoWString("String", (int)len78);

            if (HasCastCount)
                packet.ReadByte("Cast Count");

            if (hasbit18)
                packet.ReadInt32("Int18");

            if (hasMovment)
                MovementHandler.ReadClientMovementBlock(ref packet);

            if (hasSpellId)
                packet.ReadInt32("SpellId");

            if (hasbitF8)
                packet.ReadSingle("FloatF8");

            if (hasbitFC)
                packet.ReadSingle("FloatFC");
        }
        public static void HandleServerTrainerList(Packet packet)
        {
            var guidBytes = new byte[8];
            var npcTrainer = new NpcTrainer();

            guidBytes[0] = packet.ReadBit();
            var count = (int)packet.ReadBits("Count", 19);
            packet.StartBitStream(guidBytes, 2, 6);
            var titleLen = packet.ReadBits(11);
            packet.StartBitStream(guidBytes, 3, 7, 1, 4, 5);
            packet.ResetBitReader();

            npcTrainer.TrainerSpells = new List<TrainerSpell>(count);
            for (var i = 0; i < count; ++i)
            {
                var trainerSpell = new TrainerSpell();
                trainerSpell.RequiredSkill = packet.ReadUInt32("Required Skill", i);
                trainerSpell.RequiredSkillLevel = packet.ReadUInt32("Required Skill Level", i);
                trainerSpell.Cost = packet.ReadUInt32("Cost", i);

                trainerSpell.RequiredLevel = packet.ReadByte("Required Level", i);
                packet.ReadInt32<SpellId>("Required Spell ID", i);
                packet.ReadInt32("Profession Dialog", i);
                packet.ReadInt32("Profession Button", i);

                trainerSpell.Spell = (uint)packet.ReadInt32<SpellId>("Spell ID", i);
                packet.ReadByteE<TrainerSpellState>("State", i);

                npcTrainer.TrainerSpells.Add(trainerSpell);
            }

            packet.ReadXORBytes(guidBytes, 3, 2);
            npcTrainer.Title = packet.ReadWoWString("Title", titleLen);
            packet.ReadXORBytes(guidBytes, 7, 6, 4, 1, 0, 5);

            npcTrainer.Type = packet.ReadInt32E<TrainerType>("Type");
            packet.ReadInt32("Unk Int32"); // Same unk exists in CMSG_TRAINER_BUY_SPELL

            var guid = packet.WriteGuid("GUID", guidBytes);
            Storage.NpcTrainers.Add(guid.GetEntry(), npcTrainer, packet.TimeSpan);
        }
        public static void HandleSpellGo(Packet packet)
        {
            //var CasterGUID1 = new byte[8]; // 14
            var CasterGUID2 = new byte[8]; // 112-119
            var guid3 = new byte[8]; // 24-31
            var guid4 = new byte[8]; // 16-23
            //var guid5 = new byte[8]; // 98
            var guid6 = new byte[8]; // 416-423
            var guid7 = new byte[8]; // 168-175
            var guid8 = new byte[8]; // 136-143
            //var guid9 = new byte[8]; // 18
            var TargetGUID = new byte[8];
            var PowerUnitGUID = new byte[8];

            var bits52 = packet.ReadBits("Bits52", 24);
            var CasterGUID1 = new byte[bits52][];
            for (var i = 0; i < bits52; ++i)
            {
                CasterGUID1[i] = new byte[8];
                packet.StartBitStream(CasterGUID1[i], 2, 5, 4, 7, 6, 0, 3, 1);
            }

            packet.ReadBit("bit28");
            var bit106 = !packet.ReadBit("bit106");
            packet.ReadBit("bit30");

            packet.StartBitStream(CasterGUID2, 5, 4, 7, 1, 0, 6, 3, 2);
            packet.StartBitStream(guid4, 5, 6);
            guid3[2] = packet.ReadBit();
            var bit372 = packet.ReadBit("bit372");
            packet.StartBitStream(TargetGUID, 0, 3, 1, 5, 6, 2, 7, 4);

            var HasPowerData = packet.ReadBit("HasPowerData"); // bit432
            uint PowerTypeCount = 0;
            if (HasPowerData)
            {
                packet.StartBitStream(PowerUnitGUID, 6, 7, 3, 5, 0, 4, 2, 1);
                PowerTypeCount = packet.ReadBits("bits460", 21);
            }
            packet.StartBitStream(guid3, 6, 0);
            var bit102 = !packet.ReadBit("bit102");
            var bit101 = !packet.ReadBit("bit101");
            guid4[0] = packet.ReadBit();
            var bits84 = packet.ReadBits("bits84", 25);
            guid3[7] = packet.ReadBit();
            var bit26 = !packet.ReadBit("bit26");
            var bit368 = !packet.ReadBit("bit368");
            var bit336 = !packet.ReadBit("bit336");
            guid4[4] = packet.ReadBit();
            guid3[4] = packet.ReadBit();
            var bit91 = !packet.ReadBit("bit91");
            var bits388 = packet.ReadBits("bits388", 20);

            var guid5 = new byte[bits388][];
            for (var i = 0; i < bits388; i++)
            {
                guid5[i] = new byte[8];
                packet.StartBitStream(guid5[i], 0, 5, 2, 7, 6, 4, 3, 1);

            }
            packet.ReadBit("bit104");
            var bit90 = !packet.ReadBit("bit90");

            for (var i = 0; i < bits84; ++i)
            {
                if (packet.ReadBits("bits22[0]", 4) == 11)
                    packet.ReadBits("bits22[1]", 4);
            }

            packet.StartBitStream(guid6, 2, 1, 7, 0, 6, 3, 5, 4);
            guid4[7] = packet.ReadBit();
            var bit160 = packet.ReadBit("bit160");
            var bit128 = packet.ReadBit("bit128");
            guid4[2] = packet.ReadBit();

            if (bit160)
                packet.StartBitStream(guid7, 3, 7, 1, 0, 5, 6, 4, 2);

            guid4[3] = packet.ReadBit();
            var bit89 = !packet.ReadBit("bit89");

            if (bit128)
                packet.StartBitStream(guid8, 5, 4, 3, 2, 0, 6, 7, 1);

            var bit48 = packet.ReadBit("bit48");

            if (bit26)
                packet.ReadBits("bits26", 20);

            var bit337 = !packet.ReadBit("bit337");

            int bits48 = 0;
            if (!bit48)
                bits48 = (int)packet.ReadBits("bits48", 7);

            var bit428 = !packet.ReadBit("bit428");
            guid3[3] = packet.ReadBit();
            var bits68 = packet.ReadBits("bits68", 24);
            guid3[1] = packet.ReadBit();

            var guid9 = new byte[bits68][];
            for (var i = 0; i < bits68; ++i)
            {
                guid9[i] = new byte[8];
                packet.StartBitStream(guid9[i], 3, 1, 2, 7, 5, 6, 4, 0);
            }

            var bit384 = !packet.ReadBit("bit384");
            guid3[5] = packet.ReadBit();
            guid4[1] = packet.ReadBit();
            var bits320 = packet.ReadBits("bits320", 21);
            var bits340 = packet.ReadBits("bits340", 3);
            packet.ReadBits("bits11", 12);

            if (bit160)
            {
                var pos = new Vector3();
                packet.ReadXORBytes(guid7, 0, 1);
                pos.Z = packet.ReadSingle();
                packet.ReadXORBytes(guid7, 5, 3);
                pos.Y = packet.ReadSingle();
                packet.ReadXORByte(guid7, 2);
                pos.X = packet.ReadSingle();
                packet.ReadXORBytes(guid7, 6, 7, 4);
                packet.WriteGuid("Destination Transport GUID", guid7);
                packet.WriteLine("Destination Position: {0}", pos);
            }
            packet.ParseBitStream(TargetGUID, 1, 0, 5, 2, 3, 4, 7, 6);
            packet.ReadXORByte(guid4, 3);
            packet.WriteGuid("TargetGUID", TargetGUID);
            if (bit372)
            {
                packet.ReadUInt32("unk95");
                packet.ReadUInt32("unk94");
            }

            for (var i = 0; i < bits68; ++i)
            {
                packet.ParseBitStream(guid9[i], 1, 4, 5, 6, 2, 7, 3, 0);
                packet.WriteGuid("GUID9", guid9[i], i);
            }

            for (var i = 0; i < bits52; ++i)
            {
                packet.ParseBitStream(CasterGUID1[i], 0, 4, 3, 2, 7, 1, 5, 6);
                packet.WriteGuid("CasterGUID1", CasterGUID1[i], i);
            }

            packet.ParseBitStream(CasterGUID2, 4, 5, 7, 0, 1, 3, 2, 6);
            packet.WriteGuid("CasterGUID2", CasterGUID2);

            for (var i = 0; i < bits320; ++i)
            {
                packet.ReadEnum<PowerType>("Power Type", TypeCode.Byte, i);
                packet.ReadInt32("Power Value", i);
            }

            if (HasPowerData)
            {
                packet.ReadXORByte(PowerUnitGUID, 0);
                packet.ReadInt32("Current Health");
                packet.ReadXORByte(PowerUnitGUID, 2);
                packet.ReadInt32("Spell power");
                packet.ReadXORByte(PowerUnitGUID, 5);
                packet.ReadInt32("Attack power");
                packet.ReadXORByte(PowerUnitGUID, 1);

                for (var i = 0; i < PowerTypeCount; ++i)
                {
                    packet.ReadEnum<PowerType>("Power Type", TypeCode.UInt32, i);
                    packet.ReadInt32("Power Value", i);
                }
                packet.ReadXORBytes(PowerUnitGUID, 6, 7, 4, 3);
                packet.WriteGuid("PowerUnitGUID", PowerUnitGUID);
            }

            if (bit89)
                packet.ReadUInt32("unk89");

            packet.ParseBitStream(guid6, 1, 7, 4, 3, 5, 2, 0, 6);
            packet.WriteGuid("GUID6", guid6);
            packet.ReadXORBytes(guid3, 3, 4);

            if (bit128)
            {
                var pos = new Vector3();
                packet.ReadXORBytes(guid8, 2, 4, 1);
                pos.Z = packet.ReadSingle();
                packet.ReadXORBytes(guid8, 0, 5, 3);
                pos.X = packet.ReadSingle();
                pos.Y = packet.ReadSingle();
                packet.ReadXORBytes(guid8, 7, 6);
                packet.WriteGuid("Source Transport GUID", guid8);
                packet.WriteLine("Source Position: {0}", pos);
            }

            for (var i = 0; i < bits340; ++i)
                packet.ReadByte("byte86");

            for (var i = 0; i < bits388; ++i)
            {
                var pos = new Vector3();
                packet.ReadXORBytes(guid5[i], 4, 2);
                pos.X = packet.ReadSingle();
                packet.ReadXORBytes(guid5[i], 5, 7, 0);
                pos.Y = packet.ReadSingle();
                packet.ReadXORBytes(guid5[i], 1, 3, 6);
                pos.Z = packet.ReadSingle();
                packet.WriteGuid("GUID5", guid5[i], i);
                packet.WriteLine("[{1}] Position: {0}", pos, i);
            }
            packet.ReadXORByte(guid4, 2);

            if (bit336)
                packet.ReadByte("byte336");

            if (bit90)
                packet.ReadSingle("float90");

            packet.ReadEnum<CastFlag>("Cast Flags", TypeCode.Int32);
            packet.ReadXORByte(guid3, 2);
            packet.ReadEntryWithName<Int32>(StoreNameType.Spell, "Spell ID");
            packet.ReadXORByte(guid4, 0);
            packet.ReadXORByte(guid3, 5);

            if (bit428)
                packet.ReadByte("byte428");

            packet.ReadXORBytes(guid3, 0, 6, 1);
            packet.ReadXORByte(guid4, 1);

            if (bit337)
                packet.ReadByte("byte337");

            if (bit101)
                packet.ReadUInt32("unk101");

            packet.ReadXORByte(guid4, 4);

            if (bit368)
                packet.ReadByte("byte368");

            if (bit384)
                packet.ReadByte("byte384");

            packet.ReadWoWString("String48:", bits48);

            packet.ReadXORByte(guid4, 7);
            packet.ReadByte("Cast Count");

            if (bit102)
                packet.ReadUInt32("unk102");

            packet.ReadXORByte(guid4, 6);

            if (bit106)
                packet.ReadUInt32("Heal");

            packet.ReadUInt32("Cast time");
            packet.ReadXORByte(guid4, 5);

            if (bit91)
                packet.ReadUInt32("unk91");

            packet.ReadXORByte(guid3, 7);
            packet.WriteGuid("GUID3", guid3);
            packet.WriteGuid("GUID4", guid4);
        }
        public static void HandleVendorInventoryList(Packet packet)
        {
            var npcVendor = new NpcVendor();
            var guidByts = new byte[8];

            packet.StartBitStream(guidByts, 5, 4, 7, 1, 2, 3);
            var itemCount = packet.ReadBits("Item Count", 18);

            var hasExtendedCost = new bool[itemCount];
            var hasCondition = new bool[itemCount];
            for (int i = 0; i < itemCount; ++i)
            {
                hasCondition[i] = !packet.ReadBit();
                hasExtendedCost[i] = !packet.ReadBit();
                packet.ReadBit("Unk bit", i);
            }

            packet.StartBitStream(guidByts, 6, 0);
            packet.ResetBitReader();
            packet.ReadXORBytes(guidByts, 3, 4);

            npcVendor.VendorItems = new List<VendorItem>((int)itemCount);
            for (int i = 0; i < itemCount; ++i)
            {
                var vendorItem = new VendorItem();

                vendorItem.ItemId = (uint)packet.ReadInt32<ItemId>("Item ID", i);
                vendorItem.Slot = packet.ReadUInt32("Item Position", i);
                packet.ReadInt32("Item Upgrade ID", i);
                packet.ReadInt32("Display ID", i);
                var maxCount = packet.ReadInt32("Max Count", i);
                var buyCount = packet.ReadUInt32("Buy Count", i);
                packet.ReadInt32("Price", i);

                if (hasCondition[i])
                    packet.ReadInt32("Condition ID", i);

                vendorItem.Type = packet.ReadUInt32("Type", i); // 1 - item, 2 - currency
                packet.ReadInt32("Max Durability", i);
                if (hasExtendedCost[i])
                    vendorItem.ExtendedCostId = packet.ReadUInt32("Extended Cost", i);

                vendorItem.MaxCount = maxCount == -1 ? 0 : maxCount; // TDB
                if (vendorItem.Type == 2)
                    vendorItem.MaxCount = (int)buyCount;

                npcVendor.VendorItems.Add(vendorItem);
            }

            packet.ReadXORBytes(guidByts, 1, 2, 7);
            packet.ReadByte("Unk Byte");
            packet.ReadXORBytes(guidByts, 6, 0, 5);

            var guid = packet.WriteGuid("GUID", guidByts);
            Storage.NpcVendors.Add(guid.GetEntry(), npcVendor, packet.TimeSpan);
        }
Exemple #27
0
        public static void HandleDBQueryBulk(Packet packet)
        {
            packet.ReadInt32E<DB2Hash>("DB2 File");
            var count = packet.ReadBits(21);

            var guids = new byte[count][];
            for (var i = 0; i < count; ++i)
            {
                guids[i] = new byte[8];
                packet.StartBitStream(guids[i], 1, 7, 2, 5, 0, 6, 3, 4);
            }

            packet.ResetBitReader();
            for (var i = 0; i < count; ++i)
            {
                packet.ReadXORBytes(guids[i], 4, 7, 6, 0, 2, 3);
                packet.ReadInt32("Entry", i);
                packet.ReadXORBytes(guids[i], 5, 1);
                packet.WriteGuid("Guid", guids[i], i);
            }
        }
        public static void HandleNpcGossip(Packet packet)
        {
            var guidBytes = new byte[8];

            packet.StartBitStream(guidBytes, 0, 1);
            var questgossips = packet.ReadBits("Amount of Quest gossips", 19);
            guidBytes[2] = packet.ReadBit();
            var amountOfOptions = packet.ReadBits("Amount of Options", 20);

            var titleLen = new uint[questgossips];
            for (var i = 0; i < questgossips; ++i)
            {
                packet.ReadBit("Change Icon", i);
                titleLen[i] = packet.ReadBits(9);
            }
            guidBytes[3] = packet.ReadBit();

            var optionTextLen = new uint[amountOfOptions];
            var boxTextLen = new uint[amountOfOptions];
            for (var i = 0; i < amountOfOptions; ++i)
            {
                boxTextLen[i] = packet.ReadBits(12);
                optionTextLen[i] = packet.ReadBits(12);
            }

            packet.StartBitStream(guidBytes, 5, 4, 6, 7);
            packet.ResetBitReader();
            packet.ReadXORByte(guidBytes, 6);

            var gossip = new Gossip();

            gossip.GossipOptions = new List<GossipOption>((int)amountOfOptions);
            for (var i = 0; i < amountOfOptions; ++i)
            {
                var gossipOption = new GossipOption
                {
                    OptionText = packet.ReadWoWString("Text", optionTextLen[i], i),
                    BoxText = packet.ReadWoWString("Box Text", boxTextLen[i], i),
                    RequiredMoney = packet.ReadUInt32("Required money", i),
                    OptionIcon = packet.ReadByteE<GossipOptionIcon>("Icon", i),
                    Box = packet.ReadBool("Box", i),
                    Index = packet.ReadUInt32("Index", i)
                };

                gossip.GossipOptions.Add(gossipOption);
            }
            packet.ReadXORByte(guidBytes, 0);

            for (var i = 0; i < questgossips; i++)
            {
                packet.ReadUInt32E<QuestFlags>("Flags", i);
                packet.ReadWoWString("Title", titleLen[i], i);
                packet.ReadUInt32("Icon", i);
                packet.ReadUInt32E<QuestFlags2>("Flags 2", i);
                packet.ReadInt32("Level", i);
                packet.ReadUInt32<QuestId>("Quest ID", i);
            }

            var textId = packet.ReadUInt32("Text Id");
            packet.ReadXORBytes(guidBytes, 4, 3);
            var menuId = packet.ReadUInt32("Menu Id");
            packet.ReadUInt32("Friendship Faction");
            packet.ReadXORBytes(guidBytes, 7, 1, 5, 2);
            var guid = packet.WriteGuid("GUID", guidBytes);

            gossip.ObjectType = guid.GetObjectType();
            gossip.ObjectEntry = guid.GetEntry();

            if (guid.GetObjectType() == ObjectType.Unit)
                if (Storage.Objects.ContainsKey(guid))
                    ((Unit)Storage.Objects[guid].Item1).GossipId = menuId;

            if (Storage.Gossips.ContainsKey(Tuple.Create(menuId, textId)))
            {
                var oldGossipOptions = Storage.Gossips[Tuple.Create(menuId, textId)];
                if (oldGossipOptions != null)
                {
                    foreach (var gossipOptions in gossip.GossipOptions)
                        oldGossipOptions.Item1.GossipOptions.Add(gossipOptions);
                }
            }
            else
                Storage.Gossips.Add(Tuple.Create(menuId, textId), gossip, packet.TimeSpan);

            packet.AddSniffData(StoreNameType.Gossip, (int)menuId, guid.GetEntry().ToString(CultureInfo.InvariantCulture));
        }
        public static void HandleAttackStartStop(Packet packet)
        {
            var victimGUID = new byte[8];
            var attackerGUID = new byte[8];

            victimGUID[4] = packet.ReadBit();
            packet.StartBitStream(attackerGUID, 1, 3, 0, 6, 5);
            victimGUID[1] = packet.ReadBit();
            attackerGUID[7] = packet.ReadBit();
            packet.StartBitStream(victimGUID, 5, 6, 0);
            packet.StartBitStream(attackerGUID, 2, 4);
            packet.StartBitStream(victimGUID, 7, 2);
            packet.ReadBit("Unk bit");
            victimGUID[3] = packet.ReadBit();

            packet.ReadXORBytes(victimGUID, 2, 0);
            packet.ReadXORBytes(attackerGUID, 5, 0, 4);
            packet.ReadXORBytes(victimGUID, 4, 6, 7);
            packet.ReadXORBytes(attackerGUID, 2, 3);
            packet.ReadXORBytes(victimGUID, 5, 1);
            packet.ReadXORBytes(attackerGUID, 1, 7);
            packet.ReadXORByte(victimGUID, 3);
            packet.ReadXORByte(attackerGUID, 6);

            packet.WriteGuid("Attacker GUID", attackerGUID);
            packet.WriteGuid("Victim GUID", victimGUID);
        }
        public static void HandleMonsterMove(Packet packet)
        {
            var ownerGUID = new byte[8];
            var guid2 = new byte[8];
            var factingTargetGUID = new byte[8];
            var pos = new Vector3();

            packet.ReadSingle("Float34");
            packet.ReadInt32("Move Ticks");
            pos.X = packet.ReadSingle();
            pos.Z = packet.ReadSingle();
            packet.ReadSingle("Float30");
            packet.ReadSingle("Float2C");
            pos.Y = packet.ReadSingle();

            packet.ReadBit("bit38");
            packet.ReadBit(); // fake bit
            var bit6C = !packet.ReadBit();
            ownerGUID[4] = packet.ReadBit();
            var hasTime = !packet.ReadBit();
            ownerGUID[1] = packet.ReadBit();
            var bit6D = !packet.ReadBit();
            ownerGUID[2] = packet.ReadBit();
            var bit4C = !packet.ReadBit();

            packet.StartBitStream(guid2, 6, 1, 3, 5, 2, 7, 4, 0);
            var bit8C = packet.ReadBit();
            ownerGUID[3] = packet.ReadBit();
            var hasFlags = !packet.ReadBit();
            var waypointCount = packet.ReadBits(22);
            packet.StartBitStream(ownerGUID, 5, 0);
            var hasAnimationTime = !packet.ReadBit();
            var hasParabolicTime = !packet.ReadBit();
            ownerGUID[6] = packet.ReadBit();

            var bits90 = 0u;
            if (bit8C)
            {
                bits90 = packet.ReadBits(22);
                packet.ReadBits("bitsA0", 2);
            }

            var hasAnimationState = !packet.ReadBit();
            var splineType = packet.ReadBits(3);
            var splineCount = packet.ReadBits(20);

            if (splineType == 3)
                packet.StartBitStream(factingTargetGUID, 5, 3, 6, 2, 1, 4, 7, 0);

            var hasParabolicSpeed = !packet.ReadBit();
            ownerGUID[7] = packet.ReadBit();
            var bit78 = packet.ReadBit();

            packet.ResetBitReader();
            packet.ReadXORByte(ownerGUID, 2);
            if (splineType == 3)
            {
                packet.ParseBitStream(factingTargetGUID, 1, 0, 6, 5, 3, 4, 7, 2);
                packet.WriteGuid("Facting Target GUID", factingTargetGUID);
            }

            if (bit6D)
                packet.ReadByte("byte6D");

            if (hasParabolicTime)
                packet.ReadInt32("Async-time in ms");

            if (hasAnimationState)
                packet.ReadEnum<MovementAnimationState>("Animation State", TypeCode.Byte);

            if (hasTime)
                packet.ReadInt32("Move Time in ms");

            packet.ReadXORBytes(ownerGUID, 7, 1);

            if (hasParabolicSpeed)
                packet.ReadSingle("Vertical Speed");

            packet.ReadXORByte(ownerGUID, 0);
            if (bit8C)
            {
                for (var i = 0; i < bits90; ++i)
                {
                    packet.ReadInt16("short94+2", i);
                    packet.ReadInt16("short94+0", i);
                }

                packet.ReadInt16("shortA8");
                packet.ReadInt16("shortB0");
                packet.ReadSingle("floatAC");
                packet.ReadSingle("floatA4");
            }

            if (hasFlags)
                packet.ReadEnum<SplineFlag434>("Spline Flags", TypeCode.Int32);

            if (splineType == 2)
                packet.ReadVector3("Facing Spot");

            if (bit6C)
                packet.ReadByte("byte6C");

            packet.ReadXORBytes(guid2, 4, 1, 0, 7, 5, 6, 3, 2);

            Vector3 endpos = new Vector3();
            for (var i = 0; i < splineCount; ++i)
            {
                // client always taking first point
                if (i == 0)
                    endpos = packet.ReadVector3("Spline Waypoint", i);
                else
                    packet.ReadVector3("Spline Waypoint", i);
            }

            packet.ReadXORBytes(ownerGUID, 6, 3, 5);
            if (bit4C)
                packet.ReadInt32("int4C");

            if (splineType == 4)
                packet.ReadSingle("Facing Angle");

            if (!bit78)
                packet.ReadByte("byte78");

            packet.ReadXORByte(ownerGUID, 4);
            if (hasAnimationTime)
                packet.ReadInt32("Asynctime in ms"); // Async-time in ms

            // Calculate mid pos
            var mid = new Vector3();
            mid.X = (pos.X + endpos.X) * 0.5f;
            mid.Y = (pos.Y + endpos.Y) * 0.5f;
            mid.Z = (pos.Z + endpos.Z) * 0.5f;
            for (var i = 0; i < waypointCount; ++i)
            {
                // sub_7D11B4(result& wp, int32(from packet), mid)
                var vec = packet.ReadPackedVector3();
                vec.X = mid.X - vec.X;
                vec.Y = mid.Y - vec.Y;
                vec.Z = mid.Z - vec.Z;
                packet.WriteLine("[{0}] Waypoint: {1}", i, vec);
            }

            packet.WriteGuid("Owner GUID", ownerGUID);
            packet.WriteGuid("GUID2", guid2);
            packet.WriteLine("Position: {0}", pos);
        }