public static void HandlePetNameQueryResponse(Packet packet)
        {
            var hasData = packet.ReadBit();
            if (!hasData)
            {
                packet.ReadUInt64("Pet number");
                return;
            }

            packet.ReadBit("Declined");

            const int maxDeclinedNameCases = 5;
            var declinedNameLen = new int[maxDeclinedNameCases];
            for (var i = 0; i < maxDeclinedNameCases; ++i)
                declinedNameLen[i] = (int)packet.ReadBits(7);

            var len = packet.ReadBits(8);

            for (var i = 0; i < maxDeclinedNameCases; ++i)
                if (declinedNameLen[i] != 0)
                    packet.ReadWoWString("Declined name", declinedNameLen[i], i);

            var petName = packet.ReadWoWString("Pet name", len);
            packet.ReadTime("Time");
            var number = packet.ReadUInt64("Pet number");

            var guidArray = (from pair in StoreGetters.NameDict where Equals(pair.Value, number) select pair.Key).ToList();
            foreach (var guid in guidArray)
                StoreGetters.NameDict[guid] = petName;
        }
 public static void HandleChatAddonMessageParty(Packet packet)
 {
     var len33 = packet.ReadBits(8);
     var len16 = packet.ReadBits(5);
     packet.ReadWoWString("Message", len33);
     packet.ReadWoWString("Prefix", len16);
 }
 public static void HandleChatAddonMessageInstanceChat(Packet packet)
 {
     var len272 = packet.ReadBits(5);
     var len16 = packet.ReadBits(8);
     packet.ReadWoWString("Message", len16);
     packet.ReadWoWString("Prefix", len272);
 }
        public static void HandleBattlePetModifyName(Packet packet)
        {
            var guid = new byte[8];
            guid[5] = packet.ReadBit(); // 93
            guid[7] = packet.ReadBit(); // 95
            guid[3] = packet.ReadBit(); // 91
            guid[0] = packet.ReadBit(); // 88
            guid[6] = packet.ReadBit(); // 94
            var len = packet.ReadBits("Len", 7);
            guid[2] = packet.ReadBit(); // 90
            guid[1] = packet.ReadBit(); // 89
            var hasDeclinedNames = packet.ReadBit("hasDeclNames"); // 421
            guid[4] = packet.ReadBit(); // 92

            var declinedNamesLen = new uint[5];

            if (hasDeclinedNames)
                for ( var i = 5; i > 0; i--)
                    declinedNamesLen[i-1] = packet.ReadBits(7);

            packet.ResetBitReader();

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

            packet.ReadWoWString("Nick", len);

            if (hasDeclinedNames)
                for (var i = 5; i > 0; i--)
                    packet.ReadWoWString("declNames", declinedNamesLen[i - 1], i);
        }
        public static void HandleGroupInvite(Packet packet)
        {
            var guid = new byte[8];

            packet.ReadInt32("Unk Int32"); // Non-zero in cross realm parties (1383)
            packet.ReadInt32("Unk Int32"); // Always 0
            packet.ReadByte("unk");

            guid[2] = packet.ReadBit();
            var strLen = packet.ReadBits(9);
            guid[0] = packet.ReadBit();

            guid[3] = packet.ReadBit();
            guid[4] = packet.ReadBit();
            guid[6] = packet.ReadBit();
            guid[7] = packet.ReadBit();
            guid[5] = packet.ReadBit();
            guid[1] = packet.ReadBit();

            var nameLen = packet.ReadBits(9);

            packet.ResetBitReader();

            packet.ReadXORByte(guid, 5);
            packet.ReadWoWString("Realm Name", strLen); // Non-empty in cross realm parties
            packet.ReadWoWString("Name", nameLen);
            packet.ReadXORByte(guid, 4);
            packet.ReadXORByte(guid, 0);
            packet.ReadXORByte(guid, 3);
            packet.ReadXORByte(guid, 6);
            packet.ReadXORByte(guid, 1);
            packet.ReadXORByte(guid, 2);
            packet.ReadXORByte(guid, 7);
            packet.WriteGuid("Guid", guid); // Non-zero in cross realm parties
        }
        public static void HandleChallengeModeAllMapStats(Packet packet)
        {
            var bits10 = 0;
            bits10 = (int)packet.ReadBits(19);

            var bits30 = new uint[bits10];
            for (var i = 0; i < bits10; ++i)
            {
                bits30[i] = packet.ReadBits(23);
            }

            for (var i = 0; i < bits10; ++i)
            {
                packet.ReadInt32("Int14", i);
                packet.ReadInt32("Int15", i);

                for (var j = 0; j < bits30[i]; ++j)
                {
                    packet.ReadInt16("Int16", i, j);
                }

                packet.ReadInt32("Int17", i);
                packet.ReadInt32("Int18", i);
            }
        }
        public static void HandleGMTicketCaseStatus(Packet packet)
        {
            if (ClientVersion.RemovedInVersion(ClientVersionBuild.V6_2_2_20444))
            {
                packet.ReadTime("OldestTicketTime");
                packet.ReadTime("UpdateTime");
            }

            var int24 = packet.ReadInt32("CasesCount");
            for (int i = 0; i < int24; i++)
            {
                packet.ReadInt32("CaseID", i);
                packet.ReadInt32("CaseOpened", i);
                packet.ReadInt32("CaseStatus", i);
                packet.ReadInt16("CfgRealmID", i);
                packet.ReadInt64("CharacterID", i);
                packet.ReadInt32("WaitTimeOverrideMinutes", i);

                packet.ResetBitReader();
                var bits12 = packet.ReadBits(11);
                var bits262 = packet.ReadBits(10);

                packet.ReadWoWString("Url", bits12, i);
                packet.ReadWoWString("WaitTimeOverrideMessage", bits262, i);
            }
        }
 public static void HandleChannelBan(Packet packet)
 {
     var channelLength = packet.ReadBits(8);
     var nameLength = packet.ReadBits(7);
     packet.ReadWoWString("Channel", channelLength);
     packet.ReadWoWString("Player to ban", nameLength);
 }
 public static void HandleServerAddonInfo(Packet packet)
 {
     var BannedAddonsCount = packet.ReadBits("Banned Addons Count", 18);
     var AddonsCount = packet.ReadBits("Addons Count", 23);
     uint[,] AddonsInfo = new uint[AddonsCount, 4];
     packet.ReadToEnd();
 }
        public static void HandleContactList(Packet packet)
        {
            packet.ReadInt32E<ContactListFlag>("List Flags");
            var bits6 = packet.ReadBits("ContactInfoCount", 8);

            for (var i = 0; i < bits6; i++)
            {
                packet.ReadPackedGuid128("Guid", i);
                packet.ReadPackedGuid128("WowAccount", i);

                packet.ReadInt32("VirtualRealmAddr", i);
                packet.ReadInt32("NativeRealmAddr", i);
                packet.ReadInt32("TypeFlags", i);

                packet.ReadByte("Status", i);

                packet.ReadInt32("AreaID", i);
                packet.ReadInt32("Level", i);
                packet.ReadInt32("ClassID", i);

                packet.ResetBitReader();

                var bits44 = packet.ReadBits(10);
                packet.ReadWoWString("Notes", bits44, i);
            }
        }
        public static void HandleGuildQueryResponse(Packet packet)
        {
            packet.ReadPackedGuid128("Guild Guid");

            var hasData = packet.ReadBit();
            if (hasData)
            {
                packet.ReadPackedGuid128("GuildGUID");
                packet.ReadInt32("VirtualRealmAddress");
                var rankCount = packet.ReadInt32("RankCount");
                packet.ReadInt32("EmblemColor");
                packet.ReadInt32("EmblemStyle");
                packet.ReadInt32("BorderColor");
                packet.ReadInt32("BorderStyle");
                packet.ReadInt32("BackgroundColor");

                packet.ResetBitReader();
                var nameLen = packet.ReadBits(7);

                for (var i = 0; i < rankCount; i++)
                {
                    packet.ReadInt32("RankID", i);
                    packet.ReadInt32("RankOrder", i);

                    packet.ResetBitReader();
                    var rankNameLen = packet.ReadBits(7);
                    packet.ReadWoWString("Rank Name", rankNameLen, i);
                }

                packet.ReadWoWString("Guild Name", nameLen);
            }
        }
 public static void HandleSetTimeZoneInformation(Packet packet)
 {
     var len1 = packet.ReadBits(7);
     var len2 = packet.ReadBits(7);
     packet.ReadWoWString("Server Location", len2);
     packet.ReadWoWString("Server Location", len1);
 }
        public static void HandleGroupInvite(Packet packet)
        {
            var crossRealmGuid = new byte[8];

            packet.ReadInt32("Int114");
            packet.ReadByte("Byte118");
            packet.ReadInt32("Int128");
            crossRealmGuid[7] = packet.ReadBit();
            var realmNameLen = packet.ReadBits(9);
            crossRealmGuid[3] = packet.ReadBit();
            var nameLen = packet.ReadBits(9);
            crossRealmGuid[2] = packet.ReadBit();
            crossRealmGuid[5] = packet.ReadBit();
            crossRealmGuid[4] = packet.ReadBit();
            crossRealmGuid[0] = packet.ReadBit();
            crossRealmGuid[1] = packet.ReadBit();
            crossRealmGuid[6] = packet.ReadBit();

            packet.ReadXORByte(crossRealmGuid, 7);
            packet.ReadXORByte(crossRealmGuid, 6);
            packet.ReadXORByte(crossRealmGuid, 0);
            packet.ReadXORByte(crossRealmGuid, 4);
            packet.ReadWoWString("Name", nameLen);
            packet.ReadXORByte(crossRealmGuid, 1);
            packet.ReadXORByte(crossRealmGuid, 2);
            packet.ReadXORByte(crossRealmGuid, 3);
            packet.ReadWoWString("Realm Name", realmNameLen);
            packet.ReadXORByte(crossRealmGuid, 5);

            packet.WriteGuid("crossRealmGuid", crossRealmGuid);
        }
        public static void HandleEquipmentSetList(Packet packet)
        {
            var count = packet.ReadInt32("Count");

            for (var i = 0; i < count; i++)
            {
                packet.ReadInt32("Type", i);
                packet.ReadUInt64("Guid", i);
                packet.ReadUInt32("SetID", i);
                uint ignoreMask = packet.ReadUInt32("IgnoreMask");

                for (var j = 0; j < NumSlots; j++)
                {
                    bool ignore = (ignoreMask & (1 << j)) != 0;
                    packet.ReadPackedGuid128("Pieces" + (ignore ? " (Ignored)" : ""), i, j);
                    packet.ReadInt32("Appearances", i);
                }

                for (var j = 0; j < 2; j++)
                    packet.ReadInt32("Enchants", i);

                packet.ResetBitReader();
                var setNameLen = packet.ReadBits(8);
                var setIconLen = packet.ReadBits(9);

                packet.ReadWoWString("SetName", setNameLen, i);
                packet.ReadWoWString("SetIcon", setIconLen, i);
            }
        }
 public static void HandleClientChatMessageAddon434(Packet packet)
 {
     var length1 = (int)packet.ReadBits(9);
     var length2 = (int)packet.ReadBits(5);
     packet.ReadWoWString("Message", length1);
     packet.ReadWoWString("Prefix", length2);
 }
        public static void HandleQuestPoiQueryResponse(Packet packet)
        {
            packet.ReadInt32("Count?");

            var count = packet.ReadBits("Count", 20);

            var POIcounter = new uint[count];
            var pointsSize = new uint[count][];

            for (var i = 0; i < count; ++i)
            {
                POIcounter[i] = packet.ReadBits("POI Counter", 18, i);
                pointsSize[i] = new uint[POIcounter[i]];

                for (var j = 0; j < POIcounter[i]; ++j)
                    pointsSize[i][j] = packet.ReadBits("Points Counter", 21, i, j);
            }

            for (var i = 0; i < count; ++i)
            {
                var questPOIs = new List<QuestPOI>();

                for (var j = 0; j < POIcounter[i]; ++j)
                {
                    var questPoi = new QuestPOI();
                    questPoi.Points = new List<QuestPOIPoint>((int)pointsSize[i][j]);

                    for (var k = 0u; k < pointsSize[i][j]; ++k)
                    {
                        var questPoiPoint = new QuestPOIPoint
                        {
                            Index = k,
                            X = packet.ReadInt32("Point X", i, j, (int)k),
                            Y = packet.ReadInt32("Point Y", i, j, (int)k)
                        };
                        questPoi.Points.Add(questPoiPoint);
                    }

                    packet.ReadInt32("Unk Int32 1", i, j);
                    packet.ReadInt32("Unk Int32 2", i, j);
                    packet.ReadInt32("Unk Int32 3", i, j);
                    questPoi.Map = (uint)packet.ReadEntry<UInt32>(StoreNameType.Map, "Map Id", i, j);
                    questPoi.ObjectiveIndex = packet.ReadInt32("Objective Index", i, j);
                    questPoi.WorldMapAreaId = packet.ReadUInt32("World Map Area ID", i, j);
                    packet.ReadInt32("Unk Int32 4", i, j);
                    packet.ReadInt32("World Effect ID", i, j);
                    questPoi.Idx = (uint)packet.ReadInt32("POI Index", i, j);
                    packet.ReadInt32("Player Condition ID", i, j);
                    questPoi.FloorId = packet.ReadUInt32("Floor Id", i, j);

                    questPOIs.Add(questPoi);
                }

                var questId = packet.ReadEntry<Int32>(StoreNameType.Quest, "Quest ID", i);
                packet.ReadInt32("POI Counter?", i);

                foreach (var questpoi in questPOIs)
                    Storage.QuestPOIs.Add(new Tuple<uint, uint>((uint)questId, questpoi.Idx), questpoi, packet.TimeSpan);
            }
        }
        public static void HandleCalendarSendEvent(Packet packet)
        {
            packet.ReadByte("EventType");
            packet.ReadPackedGuid128("OwnerGUID");
            packet.ReadInt64("EventID");
            packet.ReadByte("GetEventType");
            packet.ReadInt32("TextureID");
            packet.ReadUInt32("Flags");
            packet.ReadUInt32("Date");
            packet.ReadUInt32("LockDate");
            packet.ReadPackedGuid128("EventGuildID");

            var inviteCount = packet.ReadInt32("InviteCount");

            packet.ResetBitReader();

            var lenEventName = packet.ReadBits(8);
            var lenDescription = packet.ReadBits(11);

            packet.ResetBitReader();

            for (int i = 0; i < inviteCount; i++)
                V6_0_2_19033.Parsers.CalendarHandler.ReadCalendarEventInviteInfo(packet, "Invites", i);

            packet.ReadWoWString("EventName", lenEventName);
            packet.ReadWoWString("Description", lenDescription);
        }
        public static void HandleServerAddonInfo547(Packet packet)
        {
            var AddonsCount = packet.ReadBits("Addons Count", 23);
            uint[,] AddonsInfo = new uint[AddonsCount, 4];

            for (var i = 0; i < AddonsCount; ++i)
            {
                AddonsInfo[i, 0] = packet.ReadBit("Use CRC", i);
                AddonsInfo[i, 2] = packet.ReadBit("Has URL", i);
                AddonsInfo[i, 1] = packet.ReadBit("Has Public Key", i);
                if (AddonsInfo[i, 2] == 1)
                {
                    AddonsInfo[i, 3] = packet.ReadBits(8);
                }
                else
                {
                    AddonsInfo[i, 3] = 0;
                }
            }

            var BannedAddonsCount = packet.ReadBits("Banned Addons Count",18);

            for (var i = 0; i < AddonsCount; ++i)
            {
                if (AddonsInfo[i, 1] == 1)
                {
                    packet.ReadBytes(256);
                    // the bytes order isn't 1,2,3,4.. they are mangled
                }

                if (AddonsInfo[i, 0] == 1)
                {
                    packet.ReadUInt32("CRC Summ", i);
                    packet.ReadByte("Unk Byte1", i);
                }

                packet.ReadByte("Addon State", i);

                if (AddonsInfo[i, 2] == 1 && AddonsInfo[i, 3] > 0)
                {
                    packet.ReadWoWString("URL path", AddonsInfo[i, 3], i);
                }
            }

            for (var i = 0; i < BannedAddonsCount; ++i)
            {
                var NameMD5 = new byte[16];
                var VersionMD5 = new byte[16];

                for (uint j = 0; j < 16; j += 4)
                {
                    Array.Copy(packet.ReadBytes(4), 0, NameMD5, j, 4);
                    Array.Copy(packet.ReadBytes(4), 0, VersionMD5, j, 4);
                }

                packet.ReadUInt32("ID", i);
                packet.ReadUInt32("Timestamp", i);
                packet.ReadUInt32("Banned", i);
            }
        }
        public static void HandleChannelNotify(Packet packet)
        {
            var type = packet.ReadBitsE<ChatNotificationType>("Type", 6);
            var channelLength = packet.ReadBits(7);
            var senderLength = packet.ReadBits(6);

            packet.ReadPackedGuid128("SenderGuid");
            packet.ReadPackedGuid128("BnetAccountID");

            packet.ReadInt32("SenderVirtualRealm");

            packet.ReadPackedGuid128("TargetGuid");

            packet.ReadInt32("TargetVirtualRealm");
            packet.ReadInt32("ChatChannelID");

            if (type == ChatNotificationType.ModeChange)
            {
                packet.ReadByteE<ChannelMemberFlag>("OldFlags");
                packet.ReadByteE<ChannelMemberFlag>("NewFlags");
            }

            packet.ReadWoWString("Channel", channelLength);
            packet.ReadWoWString("Sender", senderLength);
        }
        public static void HandleLFGuildAddRecruit(Packet packet)
        {
            var guid = new byte[8];

            packet.ReadUInt32E<GuildFinderOptionsRoles>("Class Roles");
            packet.ReadUInt32E<GuildFinderOptionsInterest>("Guild Interests");
            packet.ReadUInt32E<GuildFinderOptionsAvailability>("Availability");

            guid[3] = packet.ReadBit();
            guid[0] = packet.ReadBit();
            guid[6] = packet.ReadBit();
            guid[1] = packet.ReadBit();
            var comment = packet.ReadBits(11);
            guid[5] = packet.ReadBit();
            guid[4] = packet.ReadBit();
            guid[7] = packet.ReadBit();
            var player = packet.ReadBits(7);
            guid[2] = packet.ReadBit();

            packet.ReadXORByte(guid, 4);
            packet.ReadXORByte(guid, 5);
            packet.ReadWoWString("Comment", comment);
            packet.ReadWoWString("Player name", player);
            packet.ReadXORByte(guid, 7);
            packet.ReadXORByte(guid, 2);
            packet.ReadXORByte(guid, 0);
            packet.ReadXORByte(guid, 6);
            packet.ReadXORByte(guid, 1);
            packet.ReadXORByte(guid, 3);

            packet.WriteGuid("Guild GUID", guid);
        }
 public static void HandleClientChatChannel(Packet packet)
 {
     packet.ReadInt32E<Language>("Language");
     var channelNameLen = packet.ReadBits(9);
     var msgLen = packet.ReadBits(8);
     packet.ReadWoWString("Message", msgLen);
     packet.ReadWoWString("Channel Name", channelNameLen);
 }
 public static void HandleClientChatMessageWhisper(Packet packet)
 {
     packet.ReadEnum<Language>("Language", TypeCode.Int32);
     var msgLen = packet.ReadBits(8);
     var recvName = packet.ReadBits(9);
     packet.ReadWoWString("Message", msgLen);
     packet.ReadWoWString("Receivers Name", recvName);
 }
 public static void HandleClientChatMessageChannel434(Packet packet)
 {
     packet.ReadEnum<Language>("Language", TypeCode.Int32);
     var channelNameLen = packet.ReadBits(9);
     var msgLen = packet.ReadBits(8);
     packet.ReadWoWString("Message", msgLen);
     packet.ReadWoWString("Channel Name", channelNameLen);
 }
        public static void HandleServerTimezone(Packet packet)
        {
            var Location2Lenght = packet.ReadBits(7);
            var Location1Lenght = packet.ReadBits(7);

            packet.ReadWoWString("Timezone Location1", Location1Lenght);
            packet.ReadWoWString("Timezone Location2", Location2Lenght);
        }
        public static void HandleChannelInvite434(Packet packet)
        {
            var nameLen = packet.ReadBits(7);
            var channelLen = packet.ReadBits(8);

            packet.ReadWoWString("Name", nameLen);
            packet.ReadWoWString("Channel Name", channelLen);
        }
        public static void HandleAddonMessage(Packet packet)
        {
            var prefixLen = packet.ReadBits(5);
            var testLen = packet.ReadBits(8);

            packet.ReadWoWString("Prefix", prefixLen);
            packet.ReadWoWString("Text", testLen);
        }
        public static void HandleChannelMisc1(Packet packet)
        {
            var lenChannelName = packet.ReadBits(7);
            var lenName = packet.ReadBits(9);

            packet.ReadWoWString("ChannelName", lenChannelName);
            packet.ReadWoWString("Name", lenName);
        }
        public static void HandleAddFriend(Packet packet)
        {
            var bits16 = packet.ReadBits(9);
            var bits10 = packet.ReadBits(10);

            packet.ReadWoWString("Name", bits16);
            packet.ReadWoWString("Notes", bits10);
        }
 public static void HandleArenaTeamCommandResult434(Packet packet)
 {
     var playerLength = packet.ReadBits(7);
     var teamLength = packet.ReadBits(8);
     packet.ReadWoWString("Player Name", playerLength);
     packet.ReadUInt32("Action");
     packet.ReadUInt32("ErrorId");
     packet.ReadWoWString("Team Name", teamLength);
 }
        public static void HandleClientChatMessageWhisper(Packet packet)
        {
            packet.ReadInt32E<Language>("Language");
            var recvName = packet.ReadBits(9);
            var msgLen = packet.ReadBits(8);

            packet.ReadWoWString("Target", recvName);
            packet.ReadWoWString("Text", msgLen);
        }