Ejemplo n.º 1
0
        /// <summary>
        /// <para>Compare two dictionaries (of the same types) and creates SQL inserts
        ///  or updates accordingly.</para>
        /// <remarks>Second dictionary can be null (only inserts queries will be produced)</remarks>
        /// </summary>
        /// <typeparam name="T">Type of the primary key (uint)</typeparam>
        /// <typeparam name="TK">Type of the WDB struct (field names and types must match DB field name and types)</typeparam>
        /// <param name="dict1">Dictionary retrieved from  parser</param>
        /// <param name="dict2">Dictionary retrieved from  DB</param>
        /// <param name="tableName">The name of the table in DB</param>
        /// <param name="storeType">Are we dealing with Spells, Quests, Units, ...?</param>
        /// <param name="primaryKeyName">The name of the primary key, usually "entry"</param>
        /// <returns>A string containing full SQL queries</returns>
        public static string CompareDicts <T, TK>(IDictionary <T, TK> dict1, IDictionary <T, TK> dict2, StoreNameType storeType, string primaryKeyName = "entry")
        {
            var tableAttrs = (DBTableNameAttribute[])typeof(TK).GetCustomAttributes(typeof(DBTableNameAttribute), false);

            if (tableAttrs.Length <= 0)
            {
                return(string.Empty);
            }
            var tableName = tableAttrs[0].Name;

            var fields = Utilities.GetFieldsAndAttribute <TK, DBFieldNameAttribute>();

            if (fields == null)
            {
                return(string.Empty);
            }

            var rowsIns = new List <QueryBuilder.SQLInsertRow>();
            var rowsUpd = new List <QueryBuilder.SQLUpdateRow>();

            foreach (var elem1 in dict1)
            {
                if (dict2 != null && dict2.ContainsKey(elem1.Key)) // update
                {
                    var row = new QueryBuilder.SQLUpdateRow();

                    foreach (var field in fields)
                    {
                        var elem2 = dict2[elem1.Key];

                        var val1 = field.Item1.GetValue(elem1.Value);
                        var val2 = field.Item1.GetValue(elem2);

                        if (val1 is Array) // && val2 is Array
                        {
                            var arr1 = (Array)val1;
                            var arr2 = (Array)val2;

                            var isString = arr1.GetType().GetElementType() == typeof(string);

                            for (var i = 0; i < field.Item2.Count; i++)
                            {
                                var value1 = i >= arr1.Length ? (isString ? (object)string.Empty : 0) : arr1.GetValue(i);
                                var value2 = i >= arr2.Length ? (isString ? (object)string.Empty : 0) : arr2.GetValue(i);

                                if (!Utilities.EqualValues(value1, value2))
                                {
                                    row.AddValue(field.Item2.Name + (field.Item2.StartAtZero ? i : i + 1), value1);
                                }
                            }

                            continue;
                        }

                        if (!Utilities.EqualValues(val1, val2))
                        {
                            row.AddValue(field.Item2.Name, val1);
                        }
                    }

                    var key = Convert.ToUInt32(elem1.Key);

                    row.AddWhere(primaryKeyName, key);
                    row.Comment = StoreGetters.GetName(storeType, (int)key, false);
                    row.Table   = tableName;

                    if (row.ValueCount != 0)
                    {
                        rowsUpd.Add(row);
                    }
                }
                else // insert new
                {
                    var row = new QueryBuilder.SQLInsertRow();
                    row.AddValue(primaryKeyName, elem1.Key);
                    row.Comment = StoreGetters.GetName(storeType, Convert.ToInt32(elem1.Key), false);

                    foreach (var field in fields)
                    {
                        if (field.Item1.FieldType.BaseType == typeof(Array))
                        {
                            var arr = (Array)field.Item1.GetValue(elem1.Value);
                            for (var i = 0; i < arr.Length; i++)
                            {
                                row.AddValue(field.Item2.Name + (field.Item2.StartAtZero ? i : i + 1), arr.GetValue(i));
                            }

                            continue;
                        }

                        row.AddValue(field.Item2.Name, field.Item1.GetValue(elem1.Value));
                    }
                    rowsIns.Add(row);
                }
            }

            var result = new QueryBuilder.SQLInsert(tableName, rowsIns).Build() +
                         new QueryBuilder.SQLUpdate(rowsUpd).Build();

            return(result);
        }
Ejemplo n.º 2
0
        public static void HandlePetSpells(Packet packet)
        {
            WowGuid guid = packet.ReadGuid("GUID");

            // Equal to "Clear spells" pre cataclysm
            if (guid.IsEmpty())
            {
                return;
            }

            if (ClientVersion.AddedInVersion(ClientVersionBuild.V3_1_0_9767))
            {
                packet.ReadUInt16E <CreatureFamily>("Pet Family"); // vehicles -> 0
            }
            if (ClientVersion.AddedInVersion(ClientVersionBuild.V5_1_0_16309))
            {
                packet.ReadUInt16("Unk UInt16");
            }

            packet.ReadUInt32("Expiration Time");

            ReadPetFlags(packet);

            bool      isPet             = guid.GetHighType() == HighGuidType.Pet;
            bool      isVehicle         = guid.GetHighType() == HighGuidType.Vehicle;
            bool      isMinion          = guid.GetHighType() == HighGuidType.Creature;
            const int maxCreatureSpells = 10;
            var       spells            = new List <uint?>(maxCreatureSpells);

            for (int i = 0; i < maxCreatureSpells; i++) // Read pet/vehicle spell ids
            {
                ushort spell16 = packet.ReadUInt16();
                byte   spell8  = packet.ReadByte();
                int    spellId = spell16 + (spell8 << 16);
                byte   slot    = packet.ReadByte("Slot", i);

                if (spellId <= 4)
                {
                    packet.AddValue("Action", spellId, i);
                }
                else
                {
                    packet.AddValue("Spell", StoreGetters.GetName(StoreNameType.Spell, spellId), i);
                }

                // Spells for pets are on DBCs; also no entry in guid
                // We don't need the actions sent for minions (slots lower than 8)
                if (!isPet && (isVehicle || (isMinion && slot >= 8)))
                {
                    spells.Add((uint)spellId);
                }
            }

            if (spells.Count != 0)
            {
                if (!Storage.SpellsX.ContainsKey(guid.GetEntry()))
                {
                    Storage.SpellsX.Add(guid.GetEntry(), spells);
                }
            }

            byte spellCount = packet.ReadByte("Spell Count"); // vehicles -> 0, pets -> != 0. Could this be auras?

            for (int i = 0; i < spellCount; i++)
            {
                packet.ReadUInt16 <SpellId>("Spell", i);
                packet.ReadInt16("Active", i);
            }

            byte cdCount = packet.ReadByte("Cooldown count");

            for (int i = 0; i < cdCount; i++)
            {
                if (ClientVersion.AddedInVersion(ClientVersionBuild.V3_1_0_9767))
                {
                    packet.ReadUInt32 <SpellId>("Spell", i);
                }
                else
                {
                    packet.ReadUInt16 <SpellId>("Spell", i);
                }

                packet.ReadUInt16("Category", i);
                packet.ReadUInt32("Cooldown", i);
                packet.ReadUInt32("Category Cooldown", i);
            }

            if (ClientVersion.AddedInVersion(ClientVersionBuild.V5_1_0_16309))
            {
                byte unkLoopCounter = packet.ReadByte("Unk count");
                for (int i = 0; i < unkLoopCounter; i++)
                {
                    packet.ReadUInt32("Unk UInt32 1", i);
                    packet.ReadByte("Unk Byte", i);
                    packet.ReadUInt32("Unk UInt32 2", i);
                }
            }
        }
Ejemplo n.º 3
0
        public static void HandleQuestQueryResponse(Packet packet)
        {
            var id = packet.ReadEntry("Quest ID");

            if (id.Value) // entry is masked
            {
                return;
            }

            var quest = new QuestTemplate
            {
                Method = packet.ReadEnum <QuestMethod>("Method", TypeCode.Int32),
                Level  = packet.ReadInt32("Level")
            };

            if (ClientVersion.AddedInVersion(ClientVersionBuild.V3_3_0_10958))
            {
                quest.MinLevel = packet.ReadInt32("Min Level");
            }

            quest.ZoneOrSort = packet.ReadEnum <QuestSort>("Sort", TypeCode.Int32);

            quest.Type = packet.ReadEnum <QuestType>("Type", TypeCode.Int32);

            quest.SuggestedPlayers = packet.ReadUInt32("Suggested Players");

            quest.RequiredFactionId    = new uint[2];
            quest.RequiredFactionValue = new int[2];
            for (var i = 0; i < 2; i++)
            {
                quest.RequiredFactionId[i]    = packet.ReadUInt32("Required Faction ID", i);
                quest.RequiredFactionValue[i] = packet.ReadInt32("Required Faction Rep", i);
            }

            quest.NextQuestIdChain = (uint)packet.ReadEntryWithName <Int32>(StoreNameType.Quest, "Next Chain Quest");

            if (ClientVersion.AddedInVersion(ClientVersionBuild.V3_3_0_10958))
            {
                quest.RewardXPId = packet.ReadUInt32("Quest XP ID");
            }

            quest.RewardOrRequiredMoney = packet.ReadInt32("Reward/Required Money");

            quest.RewardMoneyMaxLevel = packet.ReadUInt32("Reward Money Max Level");

            quest.RewardSpell = (uint)packet.ReadEntryWithName <Int32>(StoreNameType.Spell, "Reward Spell");

            quest.RewardSpellCast = (uint)packet.ReadEntryWithName <Int32>(StoreNameType.Spell, "Reward Spell Cast");

            quest.RewardHonor = packet.ReadUInt32("Reward Honor");

            if (ClientVersion.AddedInVersion(ClientVersionBuild.V3_3_0_10958))
            {
                quest.RewardHonorMultiplier = packet.ReadSingle("Reward Honor Multiplier");
            }

            quest.SourceItemId = packet.ReadEntryWithName <Int32>(StoreNameType.Item, "Source Item ID");

            quest.Flags = packet.ReadEnum <QuestFlags>("Flags", TypeCode.Int32);

            if (ClientVersion.AddedInVersion(ClientVersionBuild.V4_0_1_13164))
            {
                quest.MinimapTargetMark = packet.ReadUInt32("Minimap Target Mark"); // missing enum. 1- Skull, 16 - Unknown, but exist
            }
            if (ClientVersion.AddedInVersion(ClientVersionBuild.V2_4_0_8089))
            {
                quest.RewardTitleId = packet.ReadUInt32("Reward Title ID");
            }

            if (ClientVersion.AddedInVersion(ClientVersionBuild.V3_0_2_9056))
            {
                quest.RequiredPlayerKills = packet.ReadUInt32("Required Player Kills");
                quest.RewardTalents       = packet.ReadUInt32("Bonus Talents");
            }

            if (ClientVersion.AddedInVersion(ClientVersionBuild.V3_3_0_10958))
            {
                quest.RewardArenaPoints = packet.ReadUInt32("Bonus Arena Points");
            }

            if (ClientVersion.AddedInVersion(ClientVersionBuild.V4_0_1_13164))
            {
                quest.RewardSkillId        = packet.ReadUInt32("RewSkillId");
                quest.RewardSkillPoints    = packet.ReadUInt32("RewSkillPoints");
                quest.RewardReputationMask = packet.ReadUInt32("RewRepMask");
                quest.QuestGiverPortrait   = packet.ReadUInt32("QuestGiverPortrait");
                quest.QuestTurnInPortrait  = packet.ReadUInt32("QuestTurnInPortrait");
            }

            quest.RewardItemId    = new uint[4];
            quest.RewardItemCount = new uint[4];
            for (var i = 0; i < 4; i++)
            {
                quest.RewardItemId[i]    = (uint)packet.ReadEntryWithName <Int32>(StoreNameType.Item, "Reward Item ID", i);
                quest.RewardItemCount[i] = packet.ReadUInt32("Reward Item Count", i);
            }

            quest.RewardChoiceItemId    = new uint[6];
            quest.RewardChoiceItemCount = new uint[6];
            for (var i = 0; i < 6; i++)
            {
                quest.RewardChoiceItemId[i]    = (uint)packet.ReadEntryWithName <Int32>(StoreNameType.Item, "Reward Choice Item ID", i);
                quest.RewardChoiceItemCount[i] = packet.ReadUInt32("Reward Choice Item Count", i);
            }

            const int repCount = 5;

            quest.RewardFactionId              = new uint[repCount];
            quest.RewardFactionValueId         = new int[repCount];
            quest.RewardFactionValueIdOverride = new uint[repCount];
            if (ClientVersion.AddedInVersion(ClientVersionBuild.V3_3_0_10958))
            {
                for (var i = 0; i < repCount; i++)
                {
                    quest.RewardFactionId[i] = packet.ReadUInt32("Reward Faction ID", i);
                }

                for (var i = 0; i < repCount; i++)
                {
                    quest.RewardFactionValueId[i] = packet.ReadInt32("Reward Reputation ID", i);
                }

                for (var i = 0; i < repCount; i++)
                {
                    quest.RewardFactionValueIdOverride[i] = packet.ReadUInt32("Reward Reputation ID Override", i);
                }
            }

            quest.PointMapId = packet.ReadUInt32("Point Map ID");

            quest.PointX = packet.ReadSingle("Point X");

            quest.PointY = packet.ReadSingle("Point Y");

            quest.PointOption = packet.ReadUInt32("Point Opt");

            quest.Title = packet.ReadCString("Title");

            quest.Objectives = packet.ReadCString("Objectives");

            quest.Details = packet.ReadCString("Details");

            quest.EndText = packet.ReadCString("End Text");

            if (ClientVersion.AddedInVersion(ClientVersionBuild.V3_3_0_10958))
            {
                quest.CompletedText = packet.ReadCString("Return Text");
            }

            var reqId = new KeyValuePair <int, bool> [4];

            quest.RequiredNpcOrGo         = new int[4];
            quest.RequiredNpcOrGoCount    = new uint[4];
            quest.RequiredSourceItemId    = new uint[4];
            quest.RequiredSourceItemCount = new uint[4];
            var reqItemFieldCount = ClientVersion.AddedInVersion(ClientVersionBuild.V3_0_8_9464) ? 6 : 4;

            quest.RequiredItemId    = new uint[reqItemFieldCount];
            quest.RequiredItemCount = new uint[reqItemFieldCount];

            for (var i = 0; i < 4; i++)
            {
                reqId[i] = packet.ReadEntry();
                quest.RequiredNpcOrGo[i] = reqId[i].Key;
                var isGo = reqId[i].Value;

                packet.WriteLine("[" + i + "] Required " + (isGo ? "GO" : "NPC") +
                                 " ID: " + StoreGetters.GetName(isGo ? StoreNameType.GameObject : StoreNameType.Unit, reqId[i].Key));

                quest.RequiredNpcOrGoCount[i] = packet.ReadUInt32("Required Count", i);

                if (ClientVersion.AddedInVersion(ClientVersionBuild.V3_0_2_9056))
                {
                    quest.RequiredSourceItemId[i] = (uint)packet.ReadEntryWithName <Int32>(StoreNameType.Item, "Required Source Item ID", i);
                }

                if (ClientVersion.AddedInVersion(ClientVersionBuild.V3_3_0_10958))
                {
                    quest.RequiredSourceItemCount[i] = packet.ReadUInt32("Source Item Count", i);
                }

                if (ClientVersion.RemovedInVersion(ClientVersionBuild.V3_0_8_9464))
                {
                    quest.RequiredItemId[i]    = (uint)packet.ReadEntryWithName <Int32>(StoreNameType.Item, "Required Item ID", i);
                    quest.RequiredItemCount[i] = packet.ReadUInt32("Required Item Count", i);
                }
            }

            if (ClientVersion.AddedInVersion(ClientVersionBuild.V3_0_8_9464))
            {
                for (var i = 0; i < reqItemFieldCount; i++)
                {
                    quest.RequiredItemId[i] = (uint)packet.ReadEntryWithName <Int32>(StoreNameType.Item, "Required Item ID", i);
                    quest.RequiredItemId[i] = packet.ReadUInt32("Required Item Count", i);
                }
            }

            if (ClientVersion.AddedInVersion(ClientVersionBuild.V4_0_1_13164))
            {
                quest.RequiredSpell = (uint)packet.ReadEntryWithName <UInt32>(StoreNameType.Spell, "Required Spell");
            }

            quest.ObjectiveText = new string[4];
            for (var i = 0; i < 4; i++)
            {
                quest.ObjectiveText[i] = packet.ReadCString("Objective Text", i);
            }

            quest.RewardCurrencyId      = new uint[4];
            quest.RewardCurrencyCount   = new uint[4];
            quest.RequiredCurrencyId    = new uint[4];
            quest.RequiredCurrencyCount = new uint[4];
            if (ClientVersion.AddedInVersion(ClientVersionBuild.V4_0_1_13164))
            {
                for (var i = 0; i < 4; ++i)
                {
                    quest.RewardCurrencyId[i]    = packet.ReadUInt32("Reward Currency ID", i);
                    quest.RewardCurrencyCount[i] = packet.ReadUInt32("Reward Currency Count", i);
                }

                for (var i = 0; i < 4; ++i)
                {
                    quest.RequiredCurrencyId[i]    = packet.ReadUInt32("Required Currency ID", i);
                    quest.RequiredCurrencyCount[i] = packet.ReadUInt32("Required Currency Count", i);
                }

                quest.QuestGiverTextWindow = packet.ReadCString("QuestGiver Text Window");
                quest.QuestGiverTargetName = packet.ReadCString("QuestGiver Target Name");
                quest.QuestTurnTextWindow  = packet.ReadCString("QuestTurn Text Window");
                quest.QuestTurnTargetName  = packet.ReadCString("QuestTurn Target Name");

                quest.SoundAccept = packet.ReadUInt32("Sound Accept");
                quest.SoundTurnIn = packet.ReadUInt32("Sound TurnIn");
            }

            packet.AddSniffData(StoreNameType.Quest, id.Key, "QUERY_RESPONSE");

            Storage.QuestTemplates.TryAdd((uint)id.Key, quest);
        }
Ejemplo n.º 4
0
        public static void HandlePetSpells(Packet packet)
        {
            var guid64 = packet.ReadUInt64();

            // Equal to "Clear spells" pre cataclysm
            if (guid64 == 0)
            {
                return;
            }

            var guid = new Guid(guid64);

            packet.Writer.WriteLine("GUID: " + guid);
            var isPet = guid.GetHighType() == HighGuidType.Pet;

            if (ClientVersion.AddedInVersion(ClientVersionBuild.V3_1_0_9767))
            {
                packet.ReadEnum <CreatureFamily>("Pet Family", TypeCode.UInt16); // vehicles -> 0
            }
            packet.ReadUInt32("Unknown 1");

            // Following int8,int8,int16 is sent like int32
            /*var reactState = */ packet.ReadByte("React state");               // 1
            /*var commandState = */ packet.ReadByte("Command state");           // 1
            packet.ReadUInt16("Unknown 2");                                     // pets -> 0, vehicles -> 0x800 (2048)

            for (var i = 1; i <= (int)MiscConstants.CreatureMaxSpells + 2; i++) // Read pet/vehicle spell ids
            {
                var spell16 = packet.ReadUInt16();
                var spell8  = packet.ReadByte();
                var slotid  = packet.ReadByte();
                var spellId = spell16 + (spell8 << 16);
                if (!isPet) // cleanup vehicle spells (start at 1 instead 8,
                {           // and do not print spells with id 0)
                    slotid -= (int)MiscConstants.PetSpellsOffset - 1;
                    if (spellId == 0)
                    {
                        continue;
                    }
                }

                packet.Writer.WriteLine("Spell " + slotid + ": " + StoreGetters.GetName(StoreNameType.Spell, spellId));
            }

            var spellCount = packet.ReadByte(); // vehicles -> 0, pets -> != 0. Could this be auras?

            packet.Writer.WriteLine("Spell count: " + spellCount);

            for (var i = 0; i < spellCount; i++)
            {
                // Sent as int32
                var spellId = packet.ReadUInt16();
                var active  = packet.ReadInt16();
                packet.Writer.WriteLine("Spell " + i + ": " + StoreGetters.GetName(StoreNameType.Spell, spellId) + ", active: " + active);
            }

            var cdCount = packet.ReadByte();

            packet.Writer.WriteLine("Cooldown count: " + cdCount);

            for (var i = 0; i < cdCount; i++)
            {
                int spellId;
                if (ClientVersion.AddedInVersion(ClientVersionBuild.V3_1_0_9767))
                {
                    spellId = packet.ReadInt32();
                }
                else
                {
                    spellId = packet.ReadUInt16();
                }

                var category         = packet.ReadUInt16();
                var cooldown         = packet.ReadUInt32();
                var categoryCooldown = packet.ReadUInt32();

                packet.Writer.WriteLine("Cooldown: Spell: " + StoreGetters.GetName(StoreNameType.Spell, spellId) + " category: " + category +
                                        " cooldown: " + cooldown + " category cooldown: " + categoryCooldown);
            }
        }
Ejemplo n.º 5
0
        public static void HandlePetSpells(Packet packet)
        {
            var guid = new byte[8];

            guid[7] = packet.ReadBit();
            guid[4] = packet.ReadBit();
            var bits44 = (int)packet.ReadBits(21);
            var bits28 = (int)packet.ReadBits(22);

            guid[2] = packet.ReadBit();
            var bits10 = (int)packet.ReadBits(20);

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

            const int maxCreatureSpells = 10;
            var       spells            = new List <uint>(maxCreatureSpells);

            for (var i = 0; i < maxCreatureSpells; i++) // Read pet/vehicle spell ids
            {
                var spell16 = packet.ReadUInt16();
                var spell8  = packet.ReadByte();
                var spellId = spell16 + (spell8 << 16);
                var slot    = packet.ReadByte();

                if (spellId <= 4)
                {
                    packet.AddValue("Action", spellId, i);
                }
                else
                {
                    packet.AddValue("Spell", StoreGetters.GetName(StoreNameType.Spell, spellId), i);
                }
            }

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

            packet.ReadXORByte(guid, 2);
            for (var i = 0; i < bits28; ++i)
            {
                packet.ReadInt32("IntED", i);
            }

            packet.ReadXORByte(guid, 7);
            packet.ReadXORByte(guid, 0);
            packet.ReadXORByte(guid, 3);
            packet.ReadInt16("Family");

            for (var i = 0; i < bits44; ++i)
            {
                packet.ReadInt32("Int48", i);
                packet.ReadByte("Byte48", i);
                packet.ReadInt32("Int48", i);
            }

            packet.ReadInt16("Int40");
            packet.ReadXORByte(guid, 1);
            packet.ReadXORByte(guid, 4);
            packet.ReadXORByte(guid, 6);
            packet.ReadInt32("Int24");
            packet.ReadXORByte(guid, 5);
            packet.ReadInt32("Int20");

            packet.WriteGuid("Guid", guid);
        }
Ejemplo n.º 6
0
        public static string CreatureTemplateAddon(Dictionary <WowGuid, Unit> units)
        {
            if (units.Count == 0)
            {
                return(string.Empty);
            }

            if (!Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.creature_template_addon))
            {
                return(string.Empty);
            }

            var addons = new DataBag <CreatureTemplateAddon>();

            foreach (var unit in units)
            {
                var npc = unit.Value;

                if (Settings.AreaFilters.Length > 0)
                {
                    if (!(npc.Area.ToString(CultureInfo.InvariantCulture).MatchesFilters(Settings.AreaFilters)))
                    {
                        continue;
                    }
                }

                if (Settings.MapFilters.Length > 0)
                {
                    if (!(npc.Map.ToString(CultureInfo.InvariantCulture).MatchesFilters(Settings.MapFilters)))
                    {
                        continue;
                    }
                }

                var auras        = string.Empty;
                var commentAuras = string.Empty;
                if (npc.Auras != null && npc.Auras.Count != 0)
                {
                    foreach (var aura in npc.Auras.Where(aura =>
                                                         aura != null &&
                                                         (ClientVersion.AddedInVersion(ClientType.MistsOfPandaria) ?
                                                          aura.AuraFlags.HasAnyFlag(AuraFlagMoP.NoCaster) :
                                                          aura.AuraFlags.HasAnyFlag(AuraFlag.NotCaster))))
                    {
                        auras        += aura.SpellId + " ";
                        commentAuras += StoreGetters.GetName(StoreNameType.Spell, (int)aura.SpellId, false) + ", ";
                    }
                    auras        = auras.TrimEnd(' ');
                    commentAuras = commentAuras.TrimEnd(',', ' ');
                }

                var addon = new CreatureTemplateAddon
                {
                    Entry           = unit.Key.GetEntry(),
                    PathID          = 0,
                    MountID         = (uint)npc.UnitData.MountDisplayID,
                    Bytes1          = npc.Bytes1,
                    Bytes2          = npc.Bytes2,
                    Emote           = 0,
                    AIAnimKit       = npc.AIAnimKit.GetValueOrDefault(0),
                    MovementAnimKit = npc.MovementAnimKit.GetValueOrDefault(0),
                    MeleeAnimKit    = npc.MeleeAnimKit.GetValueOrDefault(0),
                    Auras           = auras,
                    CommentAuras    = commentAuras
                };

                if (addons.ContainsKey(addon))
                {
                    continue;
                }

                addons.Add(addon);
            }

            var addonsDb = SQLDatabase.Get(addons);

            return(SQLUtil.Compare(addons, addonsDb,
                                   addon =>
            {
                var comment = StoreGetters.GetName(StoreNameType.Unit, (int)addon.Entry.GetValueOrDefault());
                if (!string.IsNullOrEmpty(addon.CommentAuras))
                {
                    comment += " - " + addon.CommentAuras;
                }
                return comment;
            }));
        }
Ejemplo n.º 7
0
        public static void HandleDBReply(Packet packet)
        {
            var entry = (uint)packet.ReadInt32("Entry");

            var type = packet.ReadEnum <DB2Hash>("DB2 File", TypeCode.UInt32);

            packet.ReadTime("Hotfix date");

            var size    = packet.ReadInt32("Size");
            var data    = packet.ReadBytes(size);
            var db2File = new Packet(data, packet.Opcode, packet.Time, packet.Direction, packet.Number, packet.Writer, packet.FileName);

            if ((int)entry < 0)
            {
                packet.WriteLine("Row {0} has been removed.", -(int)entry);
                return;
            }

            switch (type)
            {
            case DB2Hash.BroadcastText:
            {
                var broadcastText = new BroadcastText();

                var Id = db2File.ReadEntry("Id");
                broadcastText.language = db2File.ReadUInt32("Language");
                if (db2File.ReadUInt16() > 0)
                {
                    broadcastText.MaleText = db2File.ReadCString("Male Text");
                }
                if (db2File.ReadUInt16() > 0)
                {
                    broadcastText.FemaleText = db2File.ReadCString("Female Text");
                }

                broadcastText.EmoteID    = new uint[3];
                broadcastText.EmoteDelay = new uint[3];
                for (var i = 0; i < 3; ++i)
                {
                    broadcastText.EmoteID[i] = (uint)db2File.ReadInt32("Emote ID", i);
                }
                for (var i = 0; i < 3; ++i)
                {
                    broadcastText.EmoteDelay[i] = (uint)db2File.ReadInt32("Emote Delay", i);
                }

                broadcastText.soundId = db2File.ReadUInt32("Sound Id");
                broadcastText.unk1    = db2File.ReadUInt32("Unk MoP 1");  // unk emote
                broadcastText.unk2    = db2File.ReadUInt32("Unk MoP 2");  // kind of type?

                Storage.BroadcastTexts.Add((uint)Id.Key, broadcastText, packet.TimeSpan);
                packet.AddSniffData(StoreNameType.BroadcastText, Id.Key, "BROADCAST_TEXT");
                break;
            }

            case DB2Hash.Creature:     // New structure - 5.4.0
            {
                db2File.ReadUInt32("Creature Id");
                db2File.ReadUInt32("Item Id 1");
                db2File.ReadUInt32("Item Id 2");
                db2File.ReadUInt32("Item Id 3");
                db2File.ReadUInt32("Mount");
                for (var i = 0; i < 4; ++i)
                {
                    db2File.ReadInt32("Display Id", i);
                }

                for (var i = 0; i < 4; ++i)
                {
                    db2File.ReadSingle("Display Id Probability", i);
                }

                if (db2File.ReadUInt16() > 0)
                {
                    db2File.ReadCString("Name");
                }

                if (db2File.ReadUInt16() > 0)
                {
                    db2File.ReadCString("SubName");
                }

                if (db2File.ReadUInt16() > 0)
                {
                    db2File.ReadCString("Female SubName");
                }

                db2File.ReadUInt32("Rank");
                db2File.ReadUInt32("Inhabit Type");
                break;
            }

            case DB2Hash.CreatureDifficulty:
            {
                var creatureDifficulty = new CreatureDifficulty();

                db2File.ReadUInt32("Id");
                var Id = db2File.ReadEntry("Creature Id");
                creatureDifficulty.faction   = db2File.ReadUInt32("Faction Template Id");
                creatureDifficulty.Expansion = db2File.ReadInt32("Expansion");
                creatureDifficulty.MinLevel  = db2File.ReadInt32("Min Level");
                creatureDifficulty.MaxLevel  = db2File.ReadInt32("Max Level");
                db2File.ReadUInt32("Unk MoP 1");
                db2File.ReadUInt32("Unk MoP 2");
                db2File.ReadUInt32("Unk MoP 3");
                db2File.ReadUInt32("Unk MoP 4");
                db2File.ReadUInt32("Unk MoP 5");

                Storage.CreatureDifficultys.Add((uint)Id.Key, creatureDifficulty, packet.TimeSpan);
                break;
            }

            case DB2Hash.GameObjects:
            {
                var gameObjectTemplateDB2         = new GameObjectTemplateDB2();
                var gameObjectTemplatePositionDB2 = new GameObjectTemplatePositionDB2();

                var Id = db2File.ReadEntry("GameObject Id");

                gameObjectTemplatePositionDB2.map = db2File.ReadUInt32("Map");

                gameObjectTemplateDB2.DisplayId = db2File.ReadUInt32("Display Id");

                gameObjectTemplatePositionDB2.positionX = db2File.ReadSingle("Position X");
                gameObjectTemplatePositionDB2.positionY = db2File.ReadSingle("Position Y");
                gameObjectTemplatePositionDB2.positionZ = db2File.ReadSingle("Position Z");
                gameObjectTemplatePositionDB2.rotationX = db2File.ReadSingle("Rotation X");
                gameObjectTemplatePositionDB2.rotationY = db2File.ReadSingle("Rotation Y");
                gameObjectTemplatePositionDB2.rotationZ = db2File.ReadSingle("Rotation Z");
                gameObjectTemplatePositionDB2.rotationW = db2File.ReadSingle("Rotation W");

                gameObjectTemplateDB2.Size = db2File.ReadSingle("Size");
                gameObjectTemplateDB2.Type = db2File.ReadEnum <GameObjectType>("Type", TypeCode.Int32);

                gameObjectTemplateDB2.Data = new int[4];
                for (var i = 0; i < gameObjectTemplateDB2.Data.Length; i++)
                {
                    gameObjectTemplateDB2.Data[i] = db2File.ReadInt32("Data", i);
                }

                if (db2File.ReadUInt16() > 0)
                {
                    gameObjectTemplateDB2.Name = db2File.ReadCString("Name");
                }

                Storage.GameObjectTemplateDB2s.Add((uint)Id.Key, gameObjectTemplateDB2, packet.TimeSpan);
                if (gameObjectTemplatePositionDB2.positionX != 0.0f &&
                    gameObjectTemplatePositionDB2.positionY != 0.0f &&
                    gameObjectTemplatePositionDB2.positionZ != 0.0f)
                {
                    Storage.GameObjectTemplatePositionDB2s.Add((uint)Id.Key, gameObjectTemplatePositionDB2,
                                                               packet.TimeSpan);
                }
                break;
            }

            case DB2Hash.Item:
            {
                var item = Storage.ItemTemplates.ContainsKey(entry)
                        ? Storage.ItemTemplates[entry].Item1
                        : new ItemTemplate();

                db2File.ReadEntryWithName <UInt32>(StoreNameType.Item, "Item Entry");
                item.Class    = db2File.ReadEnum <ItemClass>("Class", TypeCode.Int32);
                item.SubClass = db2File.ReadUInt32("Sub Class");
                item.SoundOverrideSubclass = db2File.ReadInt32("Sound Override Subclass");
                item.Material      = db2File.ReadEnum <Material>("Material", TypeCode.Int32);
                item.DisplayId     = db2File.ReadUInt32("Display ID");
                item.InventoryType = db2File.ReadEnum <InventoryType>("Inventory Type", TypeCode.UInt32);
                item.SheathType    = db2File.ReadEnum <SheathType>("Sheath Type", TypeCode.Int32);

                Storage.ItemTemplates.Add(entry, item, packet.TimeSpan);
                packet.AddSniffData(StoreNameType.Item, (int)entry, "DB_REPLY");
                break;
            }

            case DB2Hash.ItemExtendedCost:
            {
                db2File.ReadUInt32("Item Extended Cost Entry");
                db2File.ReadUInt32("Required Honor Points");
                db2File.ReadUInt32("Required Arena Points");
                db2File.ReadUInt32("Required Arena Slot");
                for (var i = 0; i < 5; ++i)
                {
                    db2File.ReadUInt32("Required Item", i);
                }

                for (var i = 0; i < 5; ++i)
                {
                    db2File.ReadUInt32("Required Item Count", i);
                }

                db2File.ReadUInt32("Required Personal Arena Rating");
                db2File.ReadUInt32("Item Purchase Group");
                for (var i = 0; i < 5; ++i)
                {
                    db2File.ReadUInt32("Required Currency", i);
                }

                for (var i = 0; i < 5; ++i)
                {
                    db2File.ReadUInt32("Required Currency Count", i);
                }

                db2File.ReadUInt32("Required Faction Id");
                db2File.ReadUInt32("Required Faction Standing");
                db2File.ReadUInt32("Requirement Flags");
                db2File.ReadUInt32("Required Guild Level");
                db2File.ReadUInt32("Required Achievement");
                break;
            }

            case DB2Hash.Item_sparse:
            {
                var item = Storage.ItemTemplates.ContainsKey(entry)
                        ? Storage.ItemTemplates[entry].Item1
                        : new ItemTemplate();

                db2File.ReadEntryWithName <UInt32>(StoreNameType.Item, "Item Sparse Entry");
                item.Quality            = db2File.ReadEnum <ItemQuality>("Quality", TypeCode.Int32);
                item.Flags1             = db2File.ReadEnum <ItemProtoFlags>("Flags 1", TypeCode.UInt32);
                item.Flags2             = db2File.ReadEnum <ItemFlagExtra>("Flags 2", TypeCode.Int32);
                item.Flags3             = db2File.ReadUInt32("Flags 3");
                item.Unk430_1           = db2File.ReadSingle("Unk430_1");
                item.Unk430_2           = db2File.ReadSingle("Unk430_2");
                item.BuyCount           = db2File.ReadUInt32("Buy count");
                item.BuyPrice           = db2File.ReadUInt32("Buy Price");
                item.SellPrice          = db2File.ReadUInt32("Sell Price");
                item.InventoryType      = db2File.ReadEnum <InventoryType>("Inventory Type", TypeCode.Int32);
                item.AllowedClasses     = db2File.ReadEnum <ClassMask>("Allowed Classes", TypeCode.Int32);
                item.AllowedRaces       = db2File.ReadEnum <RaceMask>("Allowed Races", TypeCode.Int32);
                item.ItemLevel          = db2File.ReadUInt32("Item Level");
                item.RequiredLevel      = db2File.ReadUInt32("Required Level");
                item.RequiredSkillId    = db2File.ReadUInt32("Required Skill ID");
                item.RequiredSkillLevel = db2File.ReadUInt32("Required Skill Level");
                item.RequiredSpell      = (uint)db2File.ReadEntryWithName <Int32>(StoreNameType.Spell, "Required Spell");
                item.RequiredHonorRank  = db2File.ReadUInt32("Required Honor Rank");
                item.RequiredCityRank   = db2File.ReadUInt32("Required City Rank");
                item.RequiredRepFaction = db2File.ReadUInt32("Required Rep Faction");
                item.RequiredRepValue   = db2File.ReadUInt32("Required Rep Value");
                item.MaxCount           = db2File.ReadInt32("Max Count");
                item.MaxStackSize       = db2File.ReadInt32("Max Stack Size");
                item.ContainerSlots     = db2File.ReadUInt32("Container Slots");

                item.StatTypes = new ItemModType[10];
                for (var i = 0; i < 10; i++)
                {
                    var statType = db2File.ReadEnum <ItemModType>("Stat Type", TypeCode.Int32, i);
                    item.StatTypes[i] = statType == ItemModType.None ? ItemModType.Mana : statType;     // TDB
                }

                item.StatValues = new int[10];
                for (var i = 0; i < 10; i++)
                {
                    item.StatValues[i] = db2File.ReadInt32("Stat Value", i);
                }

                item.StatUnk1 = new int[10];
                for (var i = 0; i < 10; i++)
                {
                    item.StatUnk1[i] = db2File.ReadInt32("Unk UInt32 1", i);
                }

                item.StatUnk2 = new int[10];
                for (var i = 0; i < 10; i++)
                {
                    item.StatUnk2[i] = db2File.ReadInt32("Unk UInt32 2", i);
                }

                item.ScalingStatDistribution = db2File.ReadInt32("Scaling Stat Distribution");
                item.DamageType = db2File.ReadEnum <DamageType>("Damage Type", TypeCode.Int32);
                item.Delay      = db2File.ReadUInt32("Delay");
                item.RangedMod  = db2File.ReadSingle("Ranged Mod");

                item.TriggeredSpellIds = new int[5];
                for (var i = 0; i < 5; i++)
                {
                    item.TriggeredSpellIds[i] = db2File.ReadEntryWithName <Int32>(StoreNameType.Spell,
                                                                                  "Triggered Spell ID", i);
                }

                item.TriggeredSpellTypes = new ItemSpellTriggerType[5];
                for (var i = 0; i < 5; i++)
                {
                    item.TriggeredSpellTypes[i] = db2File.ReadEnum <ItemSpellTriggerType>("Trigger Spell Type",
                                                                                          TypeCode.Int32, i);
                }

                item.TriggeredSpellCharges = new int[5];
                for (var i = 0; i < 5; i++)
                {
                    item.TriggeredSpellCharges[i] = db2File.ReadInt32("Triggered Spell Charges", i);
                }

                item.TriggeredSpellCooldowns = new int[5];
                for (var i = 0; i < 5; i++)
                {
                    item.TriggeredSpellCooldowns[i] = db2File.ReadInt32("Triggered Spell Cooldown", i);
                }

                item.TriggeredSpellCategories = new uint[5];
                for (var i = 0; i < 5; i++)
                {
                    item.TriggeredSpellCategories[i] = db2File.ReadUInt32("Triggered Spell Category", i);
                }

                item.TriggeredSpellCategoryCooldowns = new int[5];
                for (var i = 0; i < 5; i++)
                {
                    item.TriggeredSpellCategoryCooldowns[i] = db2File.ReadInt32(
                        "Triggered Spell Category Cooldown", i);
                }

                item.Bonding = db2File.ReadEnum <ItemBonding>("Bonding", TypeCode.Int32);

                if (db2File.ReadUInt16() > 0)
                {
                    item.Name = db2File.ReadCString("Name", 0);
                }

                for (var i = 1; i < 4; ++i)
                {
                    if (db2File.ReadUInt16() > 0)
                    {
                        db2File.ReadCString("Name", i);
                    }
                }

                if (db2File.ReadUInt16() > 0)
                {
                    item.Description = db2File.ReadCString("Description");
                }

                item.PageText      = db2File.ReadUInt32("Page Text");
                item.Language      = db2File.ReadEnum <Language>("Language", TypeCode.Int32);
                item.PageMaterial  = db2File.ReadEnum <PageMaterial>("Page Material", TypeCode.Int32);
                item.StartQuestId  = (uint)db2File.ReadEntryWithName <Int32>(StoreNameType.Quest, "Start Quest");
                item.LockId        = db2File.ReadUInt32("Lock ID");
                item.Material      = db2File.ReadEnum <Material>("Material", TypeCode.Int32);
                item.SheathType    = db2File.ReadEnum <SheathType>("Sheath Type", TypeCode.Int32);
                item.RandomPropery = db2File.ReadInt32("Random Property");
                item.RandomSuffix  = db2File.ReadUInt32("Random Suffix");
                item.ItemSet       = db2File.ReadUInt32("Item Set");
                item.AreaId        = (uint)db2File.ReadEntryWithName <UInt32>(StoreNameType.Area, "Area");
                // In this single (?) case, map 0 means no map
                var map = db2File.ReadInt32();
                item.MapId = map;
                db2File.WriteLine("Map ID: " +
                                  (map != 0 ? StoreGetters.GetName(StoreNameType.Map, map) : map + " (No map)"));
                item.BagFamily     = db2File.ReadEnum <BagFamilyMask>("Bag Family", TypeCode.Int32);
                item.TotemCategory = db2File.ReadEnum <TotemCategory>("Totem Category", TypeCode.Int32);

                item.ItemSocketColors = new ItemSocketColor[3];
                for (var i = 0; i < 3; i++)
                {
                    item.ItemSocketColors[i] = db2File.ReadEnum <ItemSocketColor>("Socket Color", TypeCode.Int32, i);
                }

                item.SocketContent = new uint[3];
                for (var i = 0; i < 3; i++)
                {
                    item.SocketContent[i] = db2File.ReadUInt32("Socket Item", i);
                }

                item.SocketBonus               = db2File.ReadInt32("Socket Bonus");
                item.GemProperties             = db2File.ReadInt32("Gem Properties");
                item.ArmorDamageModifier       = db2File.ReadSingle("Armor Damage Modifier");
                item.Duration                  = db2File.ReadUInt32("Duration");
                item.ItemLimitCategory         = db2File.ReadInt32("Limit Category");
                item.HolidayId                 = db2File.ReadEnum <Holiday>("Holiday", TypeCode.Int32);
                item.StatScalingFactor         = db2File.ReadSingle("Stat Scaling Factor");
                item.CurrencySubstitutionId    = db2File.ReadUInt32("Currency Substitution Id");
                item.CurrencySubstitutionCount = db2File.ReadUInt32("Currency Substitution Count");

                Storage.ObjectNames.Add(entry, new ObjectName {
                        ObjectType = ObjectType.Item, Name = item.Name
                    },
                                        packet.TimeSpan);
                packet.AddSniffData(StoreNameType.Item, (int)entry, "DB_REPLY");
                break;
            }

            case DB2Hash.KeyChain:
            {
                db2File.ReadUInt32("Key Chain Id");
                db2File.WriteLine("Key: {0}", Utilities.ByteArrayToHexString(db2File.ReadBytes(32)));
                break;
            }

            case DB2Hash.SceneScript:     // lua ftw!
            {
                db2File.ReadUInt32("Scene Script Id");
                if (db2File.ReadUInt16() > 0)
                {
                    db2File.ReadCString("Name");
                }

                if (db2File.ReadUInt16() > 0)
                {
                    db2File.ReadCString("Script");
                }
                db2File.ReadUInt32("Previous Scene Script Part");
                db2File.ReadUInt32("Next Scene Script Part");
                break;
            }

            case DB2Hash.Vignette:
            {
                db2File.ReadUInt32("Vignette Entry");
                if (db2File.ReadUInt16() > 0)
                {
                    db2File.ReadCString("Name");
                }

                db2File.ReadUInt32("Icon");
                db2File.ReadUInt32("Flag");     // not 100% sure (8 & 32 as values only) - todo verify with more data
                db2File.ReadSingle("Unk Float 1");
                db2File.ReadSingle("Unk Float 2");
                break;
            }

            case DB2Hash.WbAccessControlList:
            {
                db2File.ReadUInt32("Id");

                if (db2File.ReadUInt16() > 0)
                {
                    db2File.ReadCString("Address");
                }

                db2File.ReadUInt32("Unk MoP 1");
                db2File.ReadUInt32("Unk MoP 2");
                db2File.ReadUInt32("Unk MoP 3");
                db2File.ReadUInt32("Unk MoP 4");     // flags?
                break;
            }

            default:
            {
                db2File.WriteLine("Unknown DB2 file type: {0} (0x{0:x})", type);
                for (var i = 0;; ++i)
                {
                    if (db2File.Length - 4 >= db2File.Position)
                    {
                        var    blockVal = db2File.ReadUpdateField();
                        string key      = "Block Value " + i;
                        string value    = blockVal.UInt32Value + "/" + blockVal.SingleValue;
                        packet.WriteLine(key + ": " + value);
                    }
                    else
                    {
                        var left = db2File.Length - db2File.Position;
                        for (var j = 0; j < left; ++j)
                        {
                            string key   = "Byte Value " + i;
                            var    value = db2File.ReadByte();
                            packet.WriteLine(key + ": " + value);
                        }
                        break;
                    }
                }
                break;
            }
            }

            db2File.ClosePacket();
        }
Ejemplo n.º 8
0
        public static void HandleGroupList(Packet packet)
        {
            var grouptype = packet.ReadEnum <GroupTypeFlag>("Group Type", TypeCode.Byte);

            packet.ReadByte("Sub Group");
            packet.ReadEnum <GroupUpdateFlag>("Flags", TypeCode.Byte);
            packet.ReadByte("Player Roles Assigned");

            if (grouptype.HasFlag(GroupTypeFlag.LookingForDungeon))
            {
                packet.ReadEnum <InstanceStatus>("Group Type Status", TypeCode.Byte);
                packet.ReadLfgEntry("LFG Entry");
                if (ClientVersion.AddedInVersion(ClientVersionBuild.V4_2_2_14545))
                {
                    packet.ReadBoolean("Unk bool");
                }
            }

            packet.ReadGuid("Group GUID");

            if (ClientVersion.AddedInVersion(ClientVersionBuild.V3_3_0_10958))
            {
                packet.ReadInt32("Counter");
            }

            var numFields = packet.ReadInt32("Member Count");

            for (var i = 0; i < numFields; i++)
            {
                var name = packet.ReadCString("Name", i);
                var guid = packet.ReadGuid("GUID", i);
                StoreGetters.AddName(guid, name);
                packet.ReadEnum <GroupMemberStatusFlag>("Status", TypeCode.Byte, i);
                packet.ReadByte("Sub Group", i);
                packet.ReadEnum <GroupUpdateFlag>("Update Flags", TypeCode.Byte, i);

                if (ClientVersion.AddedInVersion(ClientVersionBuild.V3_3_0_10958))
                {
                    packet.ReadEnum <LfgRoleFlag>("Role", TypeCode.Byte, i);
                }
            }

            packet.ReadGuid("Leader GUID");

            if (numFields <= 0)
            {
                return;
            }

            packet.ReadEnum <LootMethod>("Loot Method", TypeCode.Byte);
            packet.ReadGuid("Looter GUID");
            packet.ReadEnum <ItemQuality>("Loot Threshold", TypeCode.Byte);

            if (ClientVersion.AddedInVersion(ClientVersionBuild.V3_2_0_10192))
            {
                packet.ReadEnum <MapDifficulty>("Dungeon Difficulty", TypeCode.Byte);
            }

            packet.ReadEnum <MapDifficulty>("Raid Difficulty", TypeCode.Byte);

            if (ClientVersion.AddedInVersion(ClientVersionBuild.V3_3_0_10958) &&
                ClientVersion.RemovedInVersion(ClientVersionBuild.V4_0_6a_13623))
            {
                packet.ReadByte("Unk Byte"); // Has something to do with difficulty too
            }
        }
Ejemplo n.º 9
0
        public static void HandleCharEnum(Packet packet)
        {
            var count = packet.ReadByte("Count");

            for (var i = 0; i < count; i++)
            {
                var guid = packet.ReadGuid("GUID");
                var name = packet.ReadCString("Name");
                StoreGetters.AddName(guid, name);
                var race = packet.ReadEnum <Race>("Race", TypeCode.Byte);
                var clss = packet.ReadEnum <Class>("Class", TypeCode.Byte);
                packet.ReadEnum <Gender>("Gender", TypeCode.Byte);

                packet.ReadByte("Skin");
                packet.ReadByte("Face");
                packet.ReadByte("Hair Style");
                packet.ReadByte("Hair Color");
                packet.ReadByte("Facial Hair");

                var level = packet.ReadByte("Level");
                var zone  = packet.ReadEntryWithName <UInt32>(StoreNameType.Zone, "Zone Id");
                var mapId = packet.ReadEntryWithName <Int32>(StoreNameType.Map, "Map Id");

                var pos = packet.ReadVector3("Position");
                if (ClientVersion.AddedInVersion(ClientVersionBuild.V4_0_3_13329))
                {
                    packet.ReadGuid("Guild GUID");
                }
                else
                {
                    packet.ReadInt32("Guild Id");
                }
                packet.ReadEnum <CharacterFlag>("Character Flags", TypeCode.Int32);

                if (ClientVersion.AddedInVersion(ClientVersionBuild.V3_0_2_9056))
                {
                    packet.ReadEnum <CustomizationFlag>("Customization Flags", TypeCode.Int32);
                }

                var firstLogin = packet.ReadBoolean("First Login");
                packet.ReadInt32("Pet Display Id");
                packet.ReadInt32("Pet Level");
                packet.ReadEnum <CreatureFamily>("Pet Family", TypeCode.Int32);

                for (var j = 0; j < 19; j++)
                {
                    packet.ReadInt32("Equip Display Id");
                    packet.ReadEnum <InventoryType>("Equip Inventory Type", TypeCode.Byte);
                    packet.ReadInt32("Equip Aura Id");
                }

                int bagCount = ClientVersion.AddedInVersion(ClientVersionBuild.V3_3_3_11685) ? 4 : 1;
                for (var j = 0; j < bagCount; j++)
                {
                    packet.ReadInt32("Bag Display Id");
                    packet.ReadEnum <InventoryType>("Bag Inventory Type", TypeCode.Byte);
                    packet.ReadInt32("Bag Aura Id");
                }

                if (firstLogin)
                {
                    var startPos = new StartPosition {
                        Map = mapId, Position = pos, Zone = zone
                    };
                    Storage.StartPositions.Add(new Tuple <Race, Class>(race, clss), startPos, packet.TimeSpan);
                }

                var playerInfo = new Player {
                    Race = race, Class = clss, Name = name, FirstLogin = firstLogin, Level = level
                };

                if (Storage.Objects.ContainsKey(guid))
                {
                    Storage.Objects[guid] = new Tuple <WoWObject, TimeSpan?>(playerInfo, packet.TimeSpan);
                }
                else
                {
                    Storage.Objects.Add(guid, playerInfo, packet.TimeSpan);
                }
                StoreGetters.AddName(guid, name);
            }
        }
Ejemplo n.º 10
0
        private static Dictionary <int, UpdateField> ReadValuesUpdateBlock(Packet packet, ObjectType type, object index, bool isCreating)
        {
            var maskSize = packet.ReadByte();

            var updateMask = new int[maskSize];

            for (var i = 0; i < maskSize; i++)
            {
                updateMask[i] = packet.ReadInt32();
            }

            var mask = new BitArray(updateMask);
            var dict = new Dictionary <int, UpdateField>();

            int objectEnd = UpdateFields.GetUpdateField(ObjectField.OBJECT_END);

            for (var i = 0; i < mask.Count; ++i)
            {
                if (!mask[i])
                {
                    continue;
                }

                var blockVal = packet.ReadUpdateField();

                // Don't spam 0 values at create
                if (isCreating && blockVal.UInt32Value == 0)
                {
                    continue;
                }

                string key   = "Block Value " + i;
                string value = blockVal.UInt32Value + "/" + blockVal.SingleValue;

                if (i < objectEnd)
                {
                    key = UpdateFields.GetUpdateFieldName <ObjectField>(i);
                }
                else
                {
                    switch (type)
                    {
                    case ObjectType.Container:
                    {
                        if (i < UpdateFields.GetUpdateField(ItemField.ITEM_END))
                        {
                            goto case ObjectType.Item;
                        }

                        key = UpdateFields.GetUpdateFieldName <ContainerField>(i);
                        break;
                    }

                    case ObjectType.Item:
                    {
                        key = UpdateFields.GetUpdateFieldName <ItemField>(i);
                        break;
                    }

                    case ObjectType.Player:
                    {
                        if (i < UpdateFields.GetUpdateField(UnitField.UNIT_END) || i < UpdateFields.GetUpdateField(UnitField.UNIT_FIELD_END))
                        {
                            goto case ObjectType.Unit;
                        }

                        key = UpdateFields.GetUpdateFieldName <PlayerField>(i);
                        break;
                    }

                    case ObjectType.Unit:
                    {
                        key = UpdateFields.GetUpdateFieldName <UnitField>(i);
                        break;
                    }

                    case ObjectType.GameObject:
                    {
                        key = UpdateFields.GetUpdateFieldName <GameObjectField>(i);
                        break;
                    }

                    case ObjectType.DynamicObject:
                    {
                        key = UpdateFields.GetUpdateFieldName <DynamicObjectField>(i);
                        break;
                    }

                    case ObjectType.Corpse:
                    {
                        key = UpdateFields.GetUpdateFieldName <CorpseField>(i);
                        break;
                    }

                    case ObjectType.AreaTrigger:
                    {
                        key = UpdateFields.GetUpdateFieldName <AreaTriggerField>(i);
                        break;
                    }

                    case ObjectType.SceneObject:
                    {
                        key = UpdateFields.GetUpdateFieldName <SceneObjectField>(i);
                        break;
                    }

                    case ObjectType.Conversation:
                    {
                        key = UpdateFields.GetUpdateFieldName <ConversationField>(i);
                        break;
                    }
                    }
                }

                // HACK...
                if (key == UnitField.UNIT_FIELD_SCALING_LEVEL_DELTA.ToString())
                {
                    value = (int)blockVal.UInt32Value + "/" + blockVal.SingleValue;
                }

                if (key == UnitField.UNIT_FIELD_FACTIONTEMPLATE.ToString())
                {
                    packet.AddValue(key, value + $" ({ StoreGetters.GetName(StoreNameType.Faction, (int)blockVal.UInt32Value, false) })", index);
                }
                else
                {
                    packet.AddValue(key, value, index);
                }

                dict.Add(i, blockVal);
            }

            return(dict);
        }
Ejemplo n.º 11
0
        public static string QuestPOIWoD()
        {
            if (Storage.QuestPOIWoDs.IsEmpty())
            {
                return(String.Empty);
            }

            var sql = string.Empty;

            if (Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.quest_poi))
            {
                var entries = Storage.QuestPOIWoDs.Keys();
                var poiDb   = SQLDatabase.GetDict <uint, uint, QuestPOIWoD>(entries, "QuestID", "Idx1");

                sql = SQLUtil.CompareDicts(Storage.QuestPOIWoDs, poiDb, StoreNameType.Quest, StoreNameType.None, "QuestID", "Idx1");
            }

            // TODO: fix this piece of code so it compares with db
            //var points = new StoreMulti<Tuple<uint, uint>, QuestPOIPoint>();
            //
            //foreach (KeyValuePair<Tuple<uint, uint>, Tuple<QuestPOI, TimeSpan?>> pair in Storage.QuestPOIs)
            //    foreach (var point in pair.Value.Item1.Points)
            //        points.Add(pair.Key, point, pair.Value.Item2);
            //
            //var entries2 = points.Keys();
            //var poiPointsDb = SQLDatabase.GetDictMulti<uint, uint, QuestPOIPoint>(entries2, "questid", "id");

            const string tableName2 = "quest_poi_points";

            if (Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.quest_poi_points))
            {
                var rows = new List <QueryBuilder.SQLInsertRow>();
                foreach (var quest in Storage.QuestPOIWoDs.OrderBy(blub => blub.Key.Item1))
                {
                    var questPOI = quest.Value.Item1;

                    if (questPOI.Points != null) // Needed?
                    {
                        foreach (var point in questPOI.Points)
                        {
                            var row = new QueryBuilder.SQLInsertRow();

                            row.AddValue("QuestID", quest.Key.Item1);
                            row.AddValue("BlobIndex", quest.Value.Item1.BlobIndex);
                            row.AddValue("Idx1", point.Value);      // Not on sniffs
                            row.AddValue("Idx2", point.Key.Index);  // Not on sniffs
                            row.AddValue("X", point.Key.X);
                            row.AddValue("Y", point.Key.Y);
                            row.AddValue("VerifiedBuild", point.Key.VerifiedBuild);
                            row.Comment = StoreGetters.GetName(StoreNameType.Quest, (int)quest.Key.Item1, false);

                            rows.Add(row);
                        }
                    }
                }

                sql += new QueryBuilder.SQLInsert(tableName2, rows, 2).Build();
            }

            return(sql);
        }
Ejemplo n.º 12
0
        public static void HandleCharEnum(Packet packet)
        {
            packet.ReadBit("Unk bit");

            var unkCounter = packet.ReadBits("Unk Counter", 21);
            var count      = packet.ReadBits("Char count", 16);

            var charGuids   = new byte[count][];
            var guildGuids  = new byte[count][];
            var firstLogins = new bool[count];
            var nameLenghts = new uint[count];

            for (int c = 0; c < count; ++c)
            {
                charGuids[c]  = new byte[8];
                guildGuids[c] = new byte[8];

                guildGuids[c][4] = packet.ReadBit();
                charGuids[c][0]  = packet.ReadBit();
                charGuids[c][3]  = packet.ReadBit();
                charGuids[c][6]  = packet.ReadBit();
                guildGuids[c][1] = packet.ReadBit();
                charGuids[c][1]  = packet.ReadBit();
                guildGuids[c][2] = packet.ReadBit();
                guildGuids[c][3] = packet.ReadBit();
                firstLogins[c]   = packet.ReadBit();
                charGuids[c][2]  = packet.ReadBit();
                guildGuids[c][0] = packet.ReadBit();
                guildGuids[c][7] = packet.ReadBit();
                nameLenghts[c]   = packet.ReadBits(6);
                packet.ReadBit("Unkt Bit");
                guildGuids[c][6] = packet.ReadBit();
                charGuids[c][4]  = packet.ReadBit();
                guildGuids[c][5] = packet.ReadBit();
                charGuids[c][5]  = packet.ReadBit();
                charGuids[c][7]  = packet.ReadBit();
            }

            packet.ResetBitReader();

            for (int c = 0; c < count; ++c)
            {
                var pos = new Vector3();

                packet.ReadByte("Face", c);

                packet.ReadXORByte(guildGuids[c], 7);

                var race = packet.ReadEnum <Race>("Race", TypeCode.Byte, c);

                packet.ReadXORByte(charGuids[c], 5);
                packet.ReadXORByte(guildGuids[c], 2);
                packet.ReadXORByte(charGuids[c], 6);

                packet.ReadEnum <CharacterFlag>("CharacterFlag", TypeCode.Int32, c);
                var zone = packet.ReadEntry <UInt32>(StoreNameType.Zone, "Zone Id", c);

                packet.ReadXORByte(guildGuids[c], 3);

                packet.ReadInt32("Pet Level", c);      // v4+112
                packet.ReadInt32("Pet Display ID", c); //v4+108
                packet.ReadUInt32("Unk 1", c);
                packet.ReadUInt32("Unk 2", c);

                packet.ReadXORByte(charGuids[c], 3);
                packet.ReadXORByte(charGuids[c], 0);

                packet.ReadByte("Facial Hair", c);
                packet.ReadEnum <Gender>("Gender", TypeCode.Byte, c);

                packet.ReadXORByte(guildGuids[c], 0);

                packet.ReadByte("HairStyle", c);
                var level = packet.ReadByte("Level", c);

                for (int j = 0; j < 23; ++j)
                {
                    packet.ReadInt32("Item DisplayID", c, j);
                    packet.ReadInt32("Item EnchantID", c, j);
                    packet.ReadEnum <InventoryType>("Item InventoryType", TypeCode.Byte, c, j);
                }

                pos.Z = packet.ReadSingle();

                packet.ReadXORByte(guildGuids[c], 1);

                pos.Y = packet.ReadSingle();
                packet.ReadByte("Skin", c);
                packet.ReadByte("List Order", c); //v4+57

                packet.ReadXORByte(guildGuids[c], 5);
                packet.ReadXORByte(charGuids[c], 1);

                packet.ReadUInt32("Unk 3", c);
                pos.X = packet.ReadSingle();
                var name  = packet.ReadWoWString("Name", (int)nameLenghts[c], c);
                var mapId = packet.ReadInt32("Map", c);
                packet.ReadInt32("Pet Family", c); // v4+116
                packet.ReadByte("Hair Color", c);
                var Class = packet.ReadEnum <Class>("Class", TypeCode.Byte, c);

                packet.ReadXORByte(guildGuids[c], 4);
                packet.ReadXORByte(charGuids[c], 2);

                packet.ReadEnum <CustomizationFlag>("CustomizationFlag", TypeCode.UInt32, c);

                packet.ReadXORByte(charGuids[c], 7);
                packet.ReadXORByte(guildGuids[c], 6);
                packet.ReadXORByte(charGuids[c], 4);

                var playerGuid = new WowGuid(BitConverter.ToUInt64(charGuids[c], 0));

                packet.AddValue("Position", pos, c);
                packet.WriteGuid("Character GUID", charGuids[c], c);
                packet.WriteGuid("Guild GUID", guildGuids[c], c);

                if (firstLogins[c])
                {
                    var startPos = new StartPosition {
                        Map = mapId, Position = pos, Zone = (int)zone
                    };

                    Storage.StartPositions.Add(new Tuple <Race, Class>(race, Class), startPos, packet.TimeSpan);
                }

                var playerInfo = new Player {
                    Race = race, Class = Class, Name = name, FirstLogin = firstLogins[c], Level = level
                };
                if (Storage.Objects.ContainsKey(playerGuid))
                {
                    Storage.Objects[playerGuid] = new Tuple <WoWObject, TimeSpan?>(playerInfo, packet.TimeSpan);
                }
                else
                {
                    Storage.Objects.Add(playerGuid, playerInfo, packet.TimeSpan);
                }
                StoreGetters.AddName(playerGuid, name);
            }

            for (var i = 0; i < unkCounter; ++i)
            {
                packet.ReadUInt32("Unk int", i);
                packet.ReadByte("Unk byte", i);
            }
        }
Ejemplo n.º 13
0
        public static string Creature(Dictionary <WowGuid, Unit> units)
        {
            if (units.Count == 0)
            {
                return(string.Empty);
            }

            if (!Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.creature))
            {
                return(string.Empty);
            }

            const string tableName      = "creature";
            const string addonTableName = "creature_addon";

            uint count     = 0;
            var  rows      = new List <QueryBuilder.SQLInsertRow>();
            var  addonRows = new List <QueryBuilder.SQLInsertRow>();

            foreach (var unit in units)
            {
                var row          = new QueryBuilder.SQLInsertRow();
                var badTransport = false;

                var creature = unit.Value;

                if (Settings.AreaFilters.Length > 0)
                {
                    if (!(creature.Area.ToString(CultureInfo.InvariantCulture).MatchesFilters(Settings.AreaFilters)))
                    {
                        continue;
                    }
                }

                if (Settings.MapFilters.Length > 0)
                {
                    if (!(creature.Map.ToString(CultureInfo.InvariantCulture).MatchesFilters(Settings.MapFilters)))
                    {
                        continue;
                    }
                }

                UpdateField uf;
                if (!creature.UpdateFields.TryGetValue(UpdateFields.GetUpdateField(ObjectField.OBJECT_FIELD_ENTRY), out uf))
                {
                    continue;   // broken entry, nothing to spawn
                }
                var entry = uf.UInt32Value;

                var movementType = 0;
                var spawnDist    = 0;

                if (creature.Movement.HasWpsOrRandMov)
                {
                    movementType = 1;
                    spawnDist    = 10;
                }


                row.AddValue("guid", "@CGUID+" + count, noQuotes: true);
                row.AddValue("id", entry);
                if (!creature.IsOnTransport())
                {
                    row.AddValue("map", creature.Map);
                }
                else
                {
                    int mapId;
                    badTransport = !GetTransportMap(creature, out mapId);
                    row.AddValue("map", mapId);
                }

                row.AddValue("spawnMask", creature.GetDefaultSpawnMask());
                row.AddValue("phaseMask", creature.PhaseMask);

                if (ClientVersion.AddedInVersion(ClientVersionBuild.V4_3_4_15595) && creature.Phases != null)
                {
                    row.AddValue("phaseId", string.Join(" - ", creature.Phases));
                }

                if (!creature.IsOnTransport())
                {
                    row.AddValue("position_x", creature.Movement.Position.X);
                    row.AddValue("position_y", creature.Movement.Position.Y);
                    row.AddValue("position_z", creature.Movement.Position.Z);
                    row.AddValue("orientation", creature.Movement.Orientation);
                }
                else
                {
                    row.AddValue("position_x", creature.Movement.TransportOffset.X);
                    row.AddValue("position_y", creature.Movement.TransportOffset.Y);
                    row.AddValue("position_z", creature.Movement.TransportOffset.Z);
                    row.AddValue("orientation", creature.Movement.TransportOffset.O);
                }

                row.AddValue("spawntimesecs", creature.GetDefaultSpawnTime());
                row.AddValue("spawndist", spawnDist);
                row.AddValue("MovementType", movementType);

                row.Comment  = StoreGetters.GetName(StoreNameType.Unit, (int)unit.Key.GetEntry(), false);
                row.Comment += " (Area: " + StoreGetters.GetName(StoreNameType.Area, creature.Area, false) + ")";


                var auras        = string.Empty;
                var commentAuras = string.Empty;
                if (creature.Auras != null && creature.Auras.Count() != 0)
                {
                    foreach (var aura in creature.Auras)
                    {
                        if (aura == null)
                        {
                            continue;
                        }

                        // usually "template auras" do not have caster
                        if (ClientVersion.AddedInVersion(ClientType.MistsOfPandaria) ? !aura.AuraFlags.HasAnyFlag(AuraFlagMoP.NoCaster) : !aura.AuraFlags.HasAnyFlag(AuraFlag.NotCaster))
                        {
                            continue;
                        }

                        auras        += aura.SpellId + " ";
                        commentAuras += aura.SpellId + " - " + StoreGetters.GetName(StoreNameType.Spell, (int)aura.SpellId, false) + ", ";
                    }

                    auras        = auras.TrimEnd(' ');
                    commentAuras = commentAuras.TrimEnd(',', ' ');

                    row.Comment += " (Auras: " + commentAuras + ")";
                }

                var addonRow = new QueryBuilder.SQLInsertRow();
                if (Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.creature_addon))
                {
                    addonRow.AddValue("guid", "@CGUID+" + count, noQuotes: true);
                    addonRow.AddValue("mount", creature.Mount);
                    addonRow.AddValue("bytes1", creature.Bytes1, true);
                    addonRow.AddValue("bytes2", creature.Bytes2, true);
                    addonRow.AddValue("auras", auras);
                    addonRow.Comment += StoreGetters.GetName(StoreNameType.Unit, (int)unit.Key.GetEntry(), false);
                    if (!String.IsNullOrWhiteSpace(auras))
                    {
                        addonRow.Comment += " - " + commentAuras;
                    }
                    addonRows.Add(addonRow);
                }

                if (creature.IsTemporarySpawn())
                {
                    row.CommentOut = true;
                    row.Comment   += " - !!! might be temporary spawn !!!";
                }
                else if (creature.IsOnTransport() && badTransport)
                {
                    row.CommentOut = true;
                    row.Comment   += " - !!! on transport - transport template not found !!!";
                }
                else
                {
                    ++count;
                }

                if (creature.Movement.HasWpsOrRandMov)
                {
                    row.Comment += " (possible waypoints or random movement)";
                }

                rows.Add(row);
            }

            var result = new StringBuilder();

            if (count > 0)
            {
                // delete query for GUIDs
                var delete = new QueryBuilder.SQLDelete(Tuple.Create("@CGUID+0", "@CGUID+" + --count), "guid", tableName);
                result.Append(delete.Build());
                var sql = new QueryBuilder.SQLInsert(tableName, rows, withDelete: false);
                result.Append(sql.Build());

                if (Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.creature_addon))
                {
                    var addonDelete = new QueryBuilder.SQLDelete(Tuple.Create("@CGUID+0", "@CGUID+" + count), "guid", addonTableName);
                    result.Append(addonDelete.Build());
                    var addonSql = new QueryBuilder.SQLInsert(addonTableName, addonRows, withDelete: false);
                    result.Append(addonSql.Build());
                }
            }

            return(result.ToString());
        }
Ejemplo n.º 14
0
        public static string GameObject(Dictionary <WowGuid, GameObject> gameObjects)
        {
            if (gameObjects.Count == 0)
            {
                return(string.Empty);
            }

            if (!Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.gameobject))
            {
                return(string.Empty);
            }

            const string tableName = "gameobject";

            uint count = 0;
            var  rows  = new List <QueryBuilder.SQLInsertRow>();

            foreach (var gameobject in gameObjects)
            {
                var row = new QueryBuilder.SQLInsertRow();

                var go = gameobject.Value;

                if (Settings.AreaFilters.Length > 0)
                {
                    if (!(go.Area.ToString(CultureInfo.InvariantCulture).MatchesFilters(Settings.AreaFilters)))
                    {
                        continue;
                    }
                }

                if (Settings.MapFilters.Length > 0)
                {
                    if (!(go.Map.ToString(CultureInfo.InvariantCulture).MatchesFilters(Settings.MapFilters)))
                    {
                        continue;
                    }
                }

                uint        animprogress = 0;
                uint        state        = 0;
                UpdateField uf;
                if (!go.UpdateFields.TryGetValue(UpdateFields.GetUpdateField(ObjectField.OBJECT_FIELD_ENTRY), out uf))
                {
                    continue;   // broken entry, nothing to spawn
                }
                var entry        = uf.UInt32Value;
                var badTransport = false;

                if (go.UpdateFields.TryGetValue(UpdateFields.GetUpdateField(GameObjectField.GAMEOBJECT_BYTES_1), out uf))
                {
                    var bytes = uf.UInt32Value;
                    state        = (bytes & 0x000000FF);
                    animprogress = Convert.ToUInt32((bytes & 0xFF000000) >> 24);
                }

                row.AddValue("guid", "@OGUID+" + count, noQuotes: true);
                row.AddValue("id", entry);
                if (!go.IsOnTransport())
                {
                    row.AddValue("map", go.Map);
                }
                else
                {
                    int mapId;
                    badTransport = !GetTransportMap(go, out mapId);
                    row.AddValue("map", mapId);
                }

                row.AddValue("spawnMask", go.GetDefaultSpawnMask());
                row.AddValue("phaseMask", go.PhaseMask);

                if (ClientVersion.AddedInVersion(ClientVersionBuild.V4_3_4_15595) && go.Phases != null)
                {
                    row.AddValue("phaseId", string.Join(" - ", go.Phases));
                }

                if (!go.IsOnTransport())
                {
                    row.AddValue("position_x", go.Movement.Position.X);
                    row.AddValue("position_y", go.Movement.Position.Y);
                    row.AddValue("position_z", go.Movement.Position.Z);
                    row.AddValue("orientation", go.Movement.Orientation);
                }
                else
                {
                    row.AddValue("position_x", go.Movement.TransportOffset.X);
                    row.AddValue("position_y", go.Movement.TransportOffset.Y);
                    row.AddValue("position_z", go.Movement.TransportOffset.Z);
                    row.AddValue("orientation", go.Movement.TransportOffset.O);
                }

                var rotation = go.GetRotation();
                if (rotation != null && rotation.Length == 4)
                {
                    row.AddValue("rotation0", rotation[0]);
                    row.AddValue("rotation1", rotation[1]);
                    row.AddValue("rotation2", rotation[2]);
                    row.AddValue("rotation3", rotation[3]);
                }
                else
                {
                    row.AddValue("rotation0", 0);
                    row.AddValue("rotation1", 0);
                    row.AddValue("rotation2", 0);
                    row.AddValue("rotation3", 0);
                }

                row.AddValue("spawntimesecs", go.GetDefaultSpawnTime());
                row.AddValue("animprogress", animprogress);
                row.AddValue("state", state);
                row.Comment  = StoreGetters.GetName(StoreNameType.GameObject, (int)gameobject.Key.GetEntry(), false);
                row.Comment += " (Area: " + StoreGetters.GetName(StoreNameType.Area, go.Area, false) + ")";

                if (go.IsTemporarySpawn())
                {
                    row.CommentOut = true;
                    row.Comment   += " - !!! might be temporary spawn !!!";
                }
                else if (go.IsTransport())
                {
                    row.CommentOut = true;
                    row.Comment   += " - !!! transport !!!";
                }
                else if (go.IsOnTransport() && badTransport)
                {
                    row.CommentOut = true;
                    row.Comment   += " - !!! on transport - transport template not found !!!";
                }
                else
                {
                    ++count;
                }

                rows.Add(row);
            }

            var result = new StringBuilder();

            if (count > 0)
            {
                // delete query for GUIDs
                var delete = new QueryBuilder.SQLDelete(Tuple.Create("@OGUID+0", "@OGUID+" + --count), "guid", tableName);
                result.Append(delete.Build());
            }

            var sql = new QueryBuilder.SQLInsert(tableName, rows, withDelete: false);

            result.Append(sql.Build());
            return(result.ToString());
        }
Ejemplo n.º 15
0
        // Non-WDB data but nevertheless data that should be saved to creature_template
        public static string NpcTemplateNonWDB(Dictionary <Guid, Unit> units)
        {
            if (units.Count == 0)
            {
                return(string.Empty);
            }

            const string tableName = "creature_template";

            var rows = new List <QueryBuilder.SQLUpdateRow>();
            ICollection <uint> key = new Collection <uint>();

            foreach (var unit in units)
            {
                // don't save duplicates
                if (key.Contains(unit.Key.GetEntry()))
                {
                    continue;
                }

                var row = new QueryBuilder.SQLUpdateRow();
                var npc = unit.Value;

                var name = StoreGetters.GetName(StoreNameType.Unit, (int)unit.Key.GetEntry(), false);

                // Only movement flags in 335 are being read correctly - fix them and remove this if
                if (ClientVersion.Build == ClientVersionBuild.V3_3_5a_12340)
                {
                    if (npc.Movement.Flags.HasAnyFlag(MovementFlag.CanFly) && npc.Movement.Flags.HasAnyFlag(MovementFlag.WalkMode))
                    {
                        row.AddValue("InhabitType", InhabitType.Ground | InhabitType.Air, true);
                    }
                    else if (npc.Movement.Flags.HasAnyFlag(MovementFlag.DisableGravity))
                    {
                        row.AddValue("InhabitType", InhabitType.Air, true);
                    }
                }

                row.AddValue("HoverHeight", npc.HoverHeight, 1);
                row.AddValue("WalkSpeed", npc.Movement.WalkSpeed, 1);
                row.AddValue("RunSpeed", npc.Movement.RunSpeed, 1.142857);
                row.AddValue("VehicleId", npc.Movement.VehicleId, 0u);
                row.AddValue("Size", npc.Size, 1u);
                row.AddValue("Level", npc.Level, 1u);      // min/max
                row.AddValue("Faction", npc.Faction, 35u); // faction_A, faction_H
                row.AddValue("UnitFlags", npc.UnitFlags, UnitFlags.None, true);
                row.AddValue("BaseAttackTime", npc.MeleeTime, 2000u);
                row.AddValue("RangeAttackTime", npc.RangedTime, 0u); // 2000?
                row.AddValue("Model", npc.Model, 0u);                // model1, model2, ...
                row.AddValue("DynamicFlags", npc.DynamicFlags, UnitDynamicFlags.None, true);
                row.AddValue("NpcFlags", npc.NpcFlags, NPCFlags.None, true);

                if (npc.Resistances != null)
                {
                    for (var i = 1; i < npc.Resistances.Length; ++i) // No armor
                    {
                        row.AddValue("Resistances" + i, npc.Resistances[i], 0u);
                    }
                }

                // row.AddValue("ManaMod", npc.ManaMod, 1); this is not mod, it needs to be calculated
                // row.AddValue("HealthMod", npc.HealthMod, 1);
                row.AddValue("Class", npc.Class, Class.Warrior);
                //row.AddValue("Race", npc.Race, Race.None);

                row.AddWhere("entry", unit.Key.GetEntry());
                row.Table   = tableName;
                row.Comment = name;

                rows.Add(row);
                key.Add(unit.Key.GetEntry());
            }

            return(new QueryBuilder.SQLUpdate(rows).Build());
        }
Ejemplo n.º 16
0
        public static void HandleCharEnum422(Packet packet)
        {
            packet.ReadByte("Unk Flag");
            int count = packet.ReadInt32("Char Count");

            packet.ReadInt32("Unk Count");

            var bits = new bool[count, 17];

            for (int c = 0; c < count; c++)
            {
                for (int j = 0; j < 17; j++)
                {
                    bits[c, j] = packet.ReadBit();
                }
            }

            for (int c = 0; c < count; c++)
            {
                var low   = new byte[8];
                var guild = new byte[8];
                var name  = packet.ReadCString("Name", c);

                if (bits[c, 0])
                {
                    guild[5] = (byte)(packet.ReadByte() ^ 1);
                }

                packet.ReadByte("Face", c);
                var mapId = packet.ReadInt32("Map", c);

                if (bits[c, 12])
                {
                    low[1] = (byte)(packet.ReadByte() ^ 1);
                }

                if (bits[c, 1])
                {
                    low[4] = (byte)(packet.ReadByte() ^ 1);
                }

                if (bits[c, 10])
                {
                    guild[4] = (byte)(packet.ReadByte() ^ 1);
                }

                if (bits[c, 15])
                {
                    guild[0] = (byte)(packet.ReadByte() ^ 1);
                }

                var pos = packet.ReadVector3("Position", c);

                if (bits[c, 11])
                {
                    low[0] = (byte)(packet.ReadByte() ^ 1);
                }

                var zone = packet.ReadEntryWithName <Int32>(StoreNameType.Zone, "Zone Id", c);
                packet.ReadInt32("Pet Level", c);

                if (bits[c, 8])
                {
                    low[3] = (byte)(packet.ReadByte() ^ 1);
                }

                if (bits[c, 14])
                {
                    low[7] = (byte)(packet.ReadByte() ^ 1);
                }

                packet.ReadByte("Facial Hair", c);
                packet.ReadByte("Skin", c);
                var clss = packet.ReadEnum <Class>("Class", TypeCode.Byte, c);
                packet.ReadInt32("Pet Family", c);
                packet.ReadEnum <CharacterFlag>("CharacterFlag", TypeCode.Int32, c);

                if (bits[c, 9])
                {
                    low[2] = (byte)(packet.ReadByte() ^ 1);
                }

                packet.ReadInt32("Pet Display ID", c);

                if (bits[c, 3])
                {
                    guild[7] = (byte)(packet.ReadByte() ^ 1);
                }

                var level = packet.ReadByte("Level", c);

                if (bits[c, 7])
                {
                    low[6] = (byte)(packet.ReadByte() ^ 1);
                }

                packet.ReadByte("Hair Style", c);

                if (bits[c, 13])
                {
                    guild[2] = (byte)(packet.ReadByte() ^ 1);
                }

                var race = packet.ReadEnum <Race>("Race", TypeCode.Byte, c);
                packet.ReadByte("Hair Color", c);

                if (bits[c, 5])
                {
                    guild[6] = (byte)(packet.ReadByte() ^ 1);
                }

                packet.ReadEnum <Gender>("Gender", TypeCode.Byte, c);

                if (bits[c, 6])
                {
                    low[5] = (byte)(packet.ReadByte() ^ 1);
                }

                if (bits[c, 2])
                {
                    guild[3] = (byte)(packet.ReadByte() ^ 1);
                }

                packet.ReadByte("List Order", c);

                for (int itm = 0; itm < 19; itm++)
                {
                    packet.ReadInt32("Item EnchantID", c, itm);
                    packet.ReadEnum <InventoryType>("Item InventoryType", TypeCode.Byte, c, itm);
                    packet.ReadInt32("Item DisplayID", c, itm);
                }

                for (int itm = 0; itm < 4; itm++)
                {
                    packet.ReadInt32("Bag EnchantID", c, itm);
                    packet.ReadEnum <InventoryType>("Bag InventoryType", TypeCode.Byte, c, itm);
                    packet.ReadInt32("Bag DisplayID", c, itm);
                }

                packet.ReadEnum <CustomizationFlag>("CustomizationFlag", TypeCode.UInt32, c);

                if (bits[c, 4])
                {
                    guild[1] = (byte)(packet.ReadByte() ^ 1);
                }

                var playerGuid = new Guid(BitConverter.ToUInt64(low, 0));

                packet.WriteLine("[{0}] Character GUID: {1}", c, playerGuid);
                packet.WriteLine("[{0}] Guild GUID: {1}", c, new Guid(BitConverter.ToUInt64(guild, 0)));

                var firstLogin = bits[c, 16];
                if (firstLogin)
                {
                    var startPos = new StartPosition {
                        Map = mapId, Position = pos, Zone = zone
                    };

                    Storage.StartPositions.Add(new Tuple <Race, Class>(race, clss), startPos, packet.TimeSpan);
                }

                var playerInfo = new Player {
                    Race = race, Class = clss, Name = name, FirstLogin = firstLogin, Level = level
                };
                if (Storage.Objects.ContainsKey(playerGuid))
                {
                    Storage.Objects[playerGuid] = new Tuple <WoWObject, TimeSpan?>(playerInfo, packet.TimeSpan);
                }
                else
                {
                    Storage.Objects.Add(playerGuid, playerInfo, packet.TimeSpan);
                }
                StoreGetters.AddName(playerGuid, name);
            }
        }
Ejemplo n.º 17
0
        public static void HandleCharEnum(Packet packet)
        {
            //var unkCounter = packet.ReadBits("Unk Counter", 21);
            packet.ReadBit("Unk bit");
            var count = packet.ReadBits("Char count", 16);

            var charGuids   = new byte[count][];
            var guildGuids  = new byte[count][];
            var firstLogins = new bool[count];
            var nameLenghts = new uint[count];

            for (int c = 0; c < count; ++c)
            {
                charGuids[c]  = new byte[8];
                guildGuids[c] = new byte[8];

                charGuids[c][1]  = packet.ReadBit();
                guildGuids[c][5] = packet.ReadBit();
                guildGuids[c][7] = packet.ReadBit();
                guildGuids[c][6] = packet.ReadBit();
                charGuids[c][5]  = packet.ReadBit();
                guildGuids[c][3] = packet.ReadBit();
                charGuids[c][2]  = packet.ReadBit();
                guildGuids[c][4] = packet.ReadBit();
                charGuids[c][7]  = packet.ReadBit();
                nameLenghts[c]   = packet.ReadBits(6);
                firstLogins[c]   = packet.ReadBit();
                guildGuids[c][1] = packet.ReadBit();
                charGuids[c][4]  = packet.ReadBit();
                guildGuids[c][2] = packet.ReadBit();
                guildGuids[c][0] = packet.ReadBit();
                charGuids[c][6]  = packet.ReadBit();
                charGuids[c][3]  = packet.ReadBit();
                charGuids[c][0]  = packet.ReadBit();
            }

            packet.ReadBits("RIDBIT21", 21);
            packet.ResetBitReader();

            for (int c = 0; c < count; ++c)
            {
                Vector3 pos = new Vector3();

                packet.ReadXORByte(charGuids[c], 4);
                var race = packet.ReadByteE <Race>("Race", c);
                packet.ReadXORByte(charGuids[c], 6);
                packet.ReadXORByte(guildGuids[c], 1);
                packet.ReadByte("List Order", c);
                packet.ReadByte("Hair Style", c);
                packet.ReadXORByte(guildGuids[c], 6);
                packet.ReadXORByte(charGuids[c], 3);
                pos.X = packet.ReadSingle("Position X", c);
                packet.ReadInt32E <CharacterFlag>("CharacterFlag", c);
                packet.ReadXORByte(guildGuids[c], 0);
                packet.ReadInt32("Pet Level", c);
                var mapId = packet.ReadInt32 <MapId>("Map Id", c);
                packet.ReadXORByte(guildGuids[c], 7);
                packet.ReadUInt32E <CustomizationFlag>("CustomizationFlag", c);
                packet.ReadXORByte(guildGuids[c], 4);
                packet.ReadXORByte(charGuids[c], 2);
                packet.ReadXORByte(charGuids[c], 5);
                pos.Y = packet.ReadSingle("Position Y", c);
                packet.ReadInt32("Pet Family", c);
                var name = packet.ReadWoWString("Name", (int)nameLenghts[c], c);
                packet.ReadInt32("Pet Display ID", c);
                packet.ReadXORByte(guildGuids[c], 3);
                packet.ReadXORByte(charGuids[c], 7);
                var level = packet.ReadByte("Level", c);
                packet.ReadXORByte(charGuids[c], 1);
                packet.ReadXORByte(guildGuids[c], 2);

                for (int j = 0; j < 23; ++j)
                {
                    packet.ReadInt32("Item EnchantID", c, j);
                    packet.ReadInt32("Item DisplayID", c, j);
                    packet.ReadByteE <InventoryType>("Item InventoryType", c, j);
                }

                pos.Z = packet.ReadSingle("Position Z", c);
                var zone = packet.ReadUInt32 <ZoneId>("Zone Id", c);
                packet.ReadByte("Facial Hair", c);
                var klass = packet.ReadByteE <Class>("Class", c);
                packet.ReadXORByte(guildGuids[c], 5);
                packet.ReadByte("Skin", c);
                packet.ReadByteE <Gender>("Gender", c);
                packet.ReadByte("Face", c);
                packet.ReadXORByte(charGuids[c], 0);
                packet.ReadByte("Hair Color", c);

                var playerGuid = new WowGuid64(BitConverter.ToUInt64(charGuids[c], 0));

                packet.WriteGuid("Character GUID", charGuids[c], c);
                packet.WriteGuid("Guild GUID", guildGuids[c], c);

                if (firstLogins[c])
                {
                    PlayerCreateInfo startPos = new PlayerCreateInfo {
                        Race = race, Class = klass, Map = (uint)mapId, Zone = zone, Position = pos, Orientation = 0
                    };
                    Storage.StartPositions.Add(startPos, packet.TimeSpan);
                }

                var playerInfo = new Player {
                    Race = race, Class = klass, Name = name, FirstLogin = firstLogins[c], Level = level
                };
                if (Storage.Objects.ContainsKey(playerGuid))
                {
                    Storage.Objects[playerGuid] = new Tuple <WoWObject, TimeSpan?>(playerInfo, packet.TimeSpan);
                }
                else
                {
                    Storage.Objects.Add(playerGuid, playerInfo, packet.TimeSpan);
                }

                StoreGetters.AddName(playerGuid, name);
            }
        }
Ejemplo n.º 18
0
        public static void HandleCharEnum434(Packet packet)
        {
            var unkCounter = packet.ReadBits("Unk Counter", 23);

            packet.ReadBit("Unk bit");
            var count = packet.ReadBits("Char count", 17);

            var charGuids   = new byte[count][];
            var guildGuids  = new byte[count][];
            var firstLogins = new bool[count];
            var nameLenghts = new uint[count];

            for (var c = 0; c < count; ++c)
            {
                charGuids[c]  = new byte[8];
                guildGuids[c] = new byte[8];

                charGuids[c][3]  = (byte)(packet.ReadBit() ? 1 : 0);
                guildGuids[c][1] = (byte)(packet.ReadBit() ? 1 : 0);
                guildGuids[c][7] = (byte)(packet.ReadBit() ? 1 : 0);
                guildGuids[c][2] = (byte)(packet.ReadBit() ? 1 : 0);
                nameLenghts[c]   = packet.ReadBits(7);
                charGuids[c][4]  = (byte)(packet.ReadBit() ? 1 : 0);
                charGuids[c][7]  = (byte)(packet.ReadBit() ? 1 : 0);
                guildGuids[c][3] = (byte)(packet.ReadBit() ? 1 : 0);
                charGuids[c][5]  = (byte)(packet.ReadBit() ? 1 : 0);
                guildGuids[c][6] = (byte)(packet.ReadBit() ? 1 : 0);
                charGuids[c][1]  = (byte)(packet.ReadBit() ? 1 : 0);
                guildGuids[c][5] = (byte)(packet.ReadBit() ? 1 : 0);
                guildGuids[c][4] = (byte)(packet.ReadBit() ? 1 : 0);
                firstLogins[c]   = packet.ReadBit();
                charGuids[c][0]  = (byte)(packet.ReadBit() ? 1 : 0);
                charGuids[c][2]  = (byte)(packet.ReadBit() ? 1 : 0);
                charGuids[c][6]  = (byte)(packet.ReadBit() ? 1 : 0);
                guildGuids[c][0] = (byte)(packet.ReadBit() ? 1 : 0);
            }

            for (int c = 0; c < count; ++c)
            {
                var clss = packet.ReadEnum <Class>("Class", TypeCode.Byte, c);

                for (var itm = 0; itm < 19; ++itm)
                {
                    packet.ReadEnum <InventoryType>("Item InventoryType", TypeCode.Byte, c, itm);
                    packet.ReadInt32("Item DisplayID", c, itm);
                    packet.ReadInt32("Item EnchantID", c, itm);
                }

                for (var itm = 0; itm < 4; ++itm)
                {
                    packet.ReadEnum <InventoryType>("Bag InventoryType", TypeCode.Byte, c, itm);
                    packet.ReadInt32("Bag DisplayID", c, itm);
                    packet.ReadInt32("Bag EnchantID", c, itm);
                }

                packet.ReadInt32("Pet Family", c);

                if (guildGuids[c][2] != 0)
                {
                    guildGuids[c][2] ^= packet.ReadByte();
                }

                packet.ReadByte("List Order", c);
                packet.ReadByte("Hair Style", c);
                if (guildGuids[c][3] != 0)
                {
                    guildGuids[c][3] ^= packet.ReadByte();
                }

                packet.ReadInt32("Pet Display ID", c);
                packet.ReadEnum <CharacterFlag>("CharacterFlag", TypeCode.Int32, c);
                packet.ReadByte("Hair Color", c);

                if (charGuids[c][4] != 0)
                {
                    charGuids[c][4] ^= packet.ReadByte();
                }

                var mapId = packet.ReadInt32("Map", c);
                if (guildGuids[c][5] != 0)
                {
                    guildGuids[c][5] ^= packet.ReadByte();
                }

                var z = packet.ReadSingle("Position Z", c);
                if (guildGuids[c][6] != 0)
                {
                    guildGuids[c][6] ^= packet.ReadByte();
                }

                packet.ReadInt32("Pet Level", c);

                if (charGuids[c][3] != 0)
                {
                    charGuids[c][3] ^= packet.ReadByte();
                }

                var y = packet.ReadSingle("Position Y", c);

                packet.ReadEnum <CustomizationFlag>("CustomizationFlag", TypeCode.UInt32, c);
                packet.ReadByte("Facial Hair", c);

                if (charGuids[c][7] != 0)
                {
                    charGuids[c][7] ^= packet.ReadByte();
                }

                packet.ReadEnum <Gender>("Gender", TypeCode.Byte, c);
                var name = packet.ReadWoWString("Name", (int)nameLenghts[c], c);
                packet.ReadByte("Face", c);

                if (charGuids[c][0] != 0)
                {
                    charGuids[c][0] ^= packet.ReadByte();
                }

                if (charGuids[c][2] != 0)
                {
                    charGuids[c][2] ^= packet.ReadByte();
                }

                if (guildGuids[c][1] != 0)
                {
                    guildGuids[c][1] ^= packet.ReadByte();
                }

                if (guildGuids[c][7] != 0)
                {
                    guildGuids[c][7] ^= packet.ReadByte();
                }

                var x = packet.ReadSingle("Position X", c);
                packet.ReadByte("Skin", c);
                var race  = packet.ReadEnum <Race>("Race", TypeCode.Byte, c);
                var level = packet.ReadByte("Level", c);
                if (charGuids[c][6] != 0)
                {
                    charGuids[c][6] ^= packet.ReadByte();
                }

                if (guildGuids[c][4] != 0)
                {
                    guildGuids[c][4] ^= packet.ReadByte();
                }

                if (guildGuids[c][0] != 0)
                {
                    guildGuids[c][0] ^= packet.ReadByte();
                }

                if (charGuids[c][5] != 0)
                {
                    charGuids[c][5] ^= packet.ReadByte();
                }

                if (charGuids[c][1] != 0)
                {
                    charGuids[c][1] ^= packet.ReadByte();
                }

                var zone = packet.ReadEntryWithName <UInt32>(StoreNameType.Zone, "Zone Id", c);

                var playerGuid = new Guid(BitConverter.ToUInt64(charGuids[c], 0));

                packet.WriteLine("[{0}] Character GUID: {1}", c, playerGuid);
                packet.WriteLine("[{0}] Guild GUID: {1}", c, new Guid(BitConverter.ToUInt64(guildGuids[c], 0)));

                if (firstLogins[c])
                {
                    var startPos = new StartPosition();
                    startPos.Map      = mapId;
                    startPos.Position = new Vector3(x, y, z);
                    startPos.Zone     = zone;

                    Storage.StartPositions.Add(new Tuple <Race, Class>(race, clss), startPos, packet.TimeSpan);
                }

                var playerInfo = new Player {
                    Race = race, Class = clss, Name = name, FirstLogin = firstLogins[c], Level = level
                };
                if (Storage.Objects.ContainsKey(playerGuid))
                {
                    Storage.Objects[playerGuid] = new Tuple <WoWObject, TimeSpan?>(playerInfo, packet.TimeSpan);
                }
                else
                {
                    Storage.Objects.Add(playerGuid, playerInfo, packet.TimeSpan);
                }
                StoreGetters.AddName(playerGuid, name);
            }

            for (var i = 0; i < unkCounter; ++i)
            {
                packet.ReadByte("Unk byte", i);
                packet.ReadUInt32("Unk int", i);
            }
        }
Ejemplo n.º 19
0
        public static string CreatureText()
        {
            if (Storage.CreatureTexts.IsEmpty() || !Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.creature_text))
            {
                return(string.Empty);
            }

            // For each sound and emote, if the time they were send is in the +1/-1 seconds range of
            // our texts, add that sound and emote to our Storage.CreatureTexts

            foreach (var text in Storage.CreatureTexts)
            {
                // For each text
                foreach (var textValue in text.Value)
                {
                    // For each emote
                    var text1  = text;
                    var value1 = textValue;
                    foreach (var emoteValue in from emote in Storage.Emotes where emote.Key.GetEntry() == text1.Key from emoteValue in emote.Value let timeSpan = value1.Item2 - emoteValue.Item2 where timeSpan != null && timeSpan.Value.Duration() <= TimeSpan.FromSeconds(1) select emoteValue)
                    {
                        textValue.Item1.Emote = emoteValue.Item1;
                    }

                    // For each sound
                    var value = textValue;
                    foreach (var sound in from sound in Storage.Sounds let timeSpan = value.Item2 - sound.Item2 where timeSpan != null && timeSpan.Value.Duration() <= TimeSpan.FromSeconds(1) select sound)
                    {
                        textValue.Item1.Sound = sound.Item1;
                    }

                    List <int> textList;
                    if (SQLDatabase.BroadcastTexts.TryGetValue(textValue.Item1.Text, out textList) ||
                        SQLDatabase.BroadcastText1s.TryGetValue(textValue.Item1.Text, out textList))
                    {
                        if (textList.Count == 1)
                        {
                            textValue.Item1.BroadcastTextID = (uint)textList.First();
                        }
                        else
                        {
                            textValue.Item1.BroadcastTextID        = "PLEASE_SET_A_BROADCASTTEXT_ID";
                            textValue.Item1.BroadcastTextIDHelper  = "BroadcastTextID: ";
                            textValue.Item1.BroadcastTextIDHelper += string.Join(" - ", textList);
                        }
                    }

                    // Set comment
                    string from = null, to = null;
                    if (!textValue.Item1.SenderGUID.IsEmpty())
                    {
                        if (textValue.Item1.SenderGUID.GetObjectType() == ObjectType.Player)
                        {
                            from = "Player";
                        }
                        else
                        {
                            from = !string.IsNullOrEmpty(textValue.Item1.SenderName) ? textValue.Item1.SenderName : StoreGetters.GetName(StoreNameType.Unit, (int)textValue.Item1.SenderGUID.GetEntry(), false);
                        }
                    }

                    if (!textValue.Item1.ReceiverGUID.IsEmpty())
                    {
                        if (textValue.Item1.ReceiverGUID.GetObjectType() == ObjectType.Player)
                        {
                            to = "Player";
                        }
                        else
                        {
                            to = !string.IsNullOrEmpty(textValue.Item1.ReceiverName) ? textValue.Item1.ReceiverName : StoreGetters.GetName(StoreNameType.Unit, (int)textValue.Item1.ReceiverGUID.GetEntry(), false);
                        }
                    }

                    Trace.Assert(text.Key == textValue.Item1.SenderGUID.GetEntry() ||
                                 text.Key == textValue.Item1.ReceiverGUID.GetEntry());

                    if (from != null && to != null)
                    {
                        textValue.Item1.Comment = from + " to " + to;
                    }
                    else if (from != null)
                    {
                        textValue.Item1.Comment = from;
                    }
                    else
                    {
                        Trace.Assert(false);
                    }
                }
            }

            /* can't use compare DB without knowing values of groupid or id
             * var entries = Storage.CreatureTexts.Keys.ToList();
             * var creatureTextDb = SQLDatabase.GetDict<uint, CreatureText>(entries);
             */

            var rows = new RowList <CreatureText>();
            Dictionary <uint, uint> entryCount = new Dictionary <uint, uint>();

            foreach (var text in Storage.CreatureTexts.OrderBy(t => t.Key))
            {
                foreach (var textValue in text.Value)
                {
                    var count = entryCount.ContainsKey(text.Key) ? entryCount[text.Key] : 0;

                    if (rows.Where(text2 => text2.Data.Entry == text.Key && text2.Data.Text == textValue.Item1.Text).Count() != 0)
                    {
                        continue;
                    }

                    var row = new Row <CreatureText>
                    {
                        Data = new CreatureText
                        {
                            Entry           = text.Key,
                            GroupId         = "@GROUP_ID+" + count,
                            ID              = "@ID+",
                            Text            = textValue.Item1.Text,
                            Type            = textValue.Item1.Type,
                            Language        = textValue.Item1.Language,
                            Probability     = 100.0f,
                            Emote           = (textValue.Item1.Emote != null ? textValue.Item1.Emote : 0),
                            Duration        = 0,
                            Sound           = (textValue.Item1.Sound != null ? textValue.Item1.Sound : 0),
                            BroadcastTextID = textValue.Item1.BroadcastTextID,
                            Comment         = textValue.Item1.Comment
                        },

                        Comment = textValue.Item1.BroadcastTextIDHelper
                    };

                    if (!entryCount.ContainsKey(text.Key))
                    {
                        entryCount.Add(text.Key, count + 1);
                    }
                    else
                    {
                        entryCount[text.Key] = count + 1;
                    }

                    rows.Add(row);
                }
            }

            return(new SQLInsert <CreatureText>(rows, false).Build());
        }
Ejemplo n.º 20
0
        public static string GameObject(Dictionary <WowGuid, GameObject> gameObjects)
        {
            if (gameObjects.Count == 0)
            {
                return(string.Empty);
            }

            if (!Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.gameobject))
            {
                return(string.Empty);
            }

            uint count     = 0;
            var  rows      = new RowList <GameObjectModel>();
            var  addonRows = new RowList <GameObjectAddon>();

            foreach (var gameobject in gameObjects)
            {
                Row <GameObjectModel> row = new Row <GameObjectModel>();

                GameObject go = gameobject.Value;

                if (Settings.AreaFilters.Length > 0)
                {
                    if (!(go.Area.ToString(CultureInfo.InvariantCulture).MatchesFilters(Settings.AreaFilters)))
                    {
                        continue;
                    }
                }

                if (Settings.MapFilters.Length > 0)
                {
                    if (!(go.Map.ToString(CultureInfo.InvariantCulture).MatchesFilters(Settings.MapFilters)))
                    {
                        continue;
                    }
                }

                uint entry = (uint)go.ObjectData.EntryID;
                if (entry == 0)
                {
                    continue;   // broken entry, nothing to spawn
                }
                bool badTransport = false;

                row.Data.GUID = "@OGUID+" + count;

                row.Data.ID = entry;
                if (!go.IsOnTransport())
                {
                    row.Data.Map = go.Map;
                }
                else
                {
                    int mapId;
                    badTransport = !GetTransportMap(go, out mapId);
                    if (mapId != -1)
                    {
                        row.Data.Map = (uint)mapId;
                    }
                }

                row.Data.ZoneID = 0;
                row.Data.AreaID = 0;

                if (go.Area != -1)
                {
                    row.Data.AreaID = (uint)go.Area;
                }

                if (go.Zone != -1)
                {
                    row.Data.ZoneID = (uint)go.Zone;
                }

                row.Data.SpawnMask = (uint)go.GetDefaultSpawnMask();


                if (ClientVersion.AddedInVersion(ClientVersionBuild.V7_0_3_22248))
                {
                    string data = string.Join(",", go.GetDefaultSpawnDifficulties());
                    if (string.IsNullOrEmpty(data))
                    {
                        data = "0";
                    }

                    row.Data.spawnDifficulties = data;
                }

                row.Data.PhaseMask = go.PhaseMask;

                if (ClientVersion.AddedInVersion(ClientVersionBuild.V4_3_4_15595) && go.Phases != null)
                {
                    string data = string.Join(" - ", go.Phases);
                    if (string.IsNullOrEmpty(data) || Settings.ForcePhaseZero)
                    {
                        data = "0";
                    }

                    row.Data.PhaseID = data;
                }

                if (!go.IsOnTransport())
                {
                    row.Data.PositionX   = go.Movement.Position.X;
                    row.Data.PositionY   = go.Movement.Position.Y;
                    row.Data.PositionZ   = go.Movement.Position.Z;
                    row.Data.Orientation = go.Movement.Orientation;
                }
                else
                {
                    row.Data.PositionX   = go.Movement.Transport.Offset.X;
                    row.Data.PositionY   = go.Movement.Transport.Offset.Y;
                    row.Data.PositionZ   = go.Movement.Transport.Offset.Z;
                    row.Data.Orientation = go.Movement.Transport.Offset.O;
                }

                var rotation = go.GetStaticRotation();
                row.Data.Rotation = new float?[] { rotation.X, rotation.Y, rotation.Z, rotation.W };

                bool add      = false;
                var  addonRow = new Row <GameObjectAddon>();
                if (Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.gameobject_addon))
                {
                    addonRow.Data.GUID = "@OGUID+" + count;

                    var parentRotation = go.GetParentRotation();

                    if (parentRotation != null)
                    {
                        addonRow.Data.parentRot0 = parentRotation.Value.X;
                        addonRow.Data.parentRot1 = parentRotation.Value.Y;
                        addonRow.Data.parentRot2 = parentRotation.Value.Z;
                        addonRow.Data.parentRot3 = parentRotation.Value.W;

                        if (addonRow.Data.parentRot0 != 0.0f ||
                            addonRow.Data.parentRot1 != 0.0f ||
                            addonRow.Data.parentRot2 != 0.0f ||
                            addonRow.Data.parentRot3 != 1.0f)
                        {
                            add = true;
                        }
                    }

                    addonRow.Data.WorldEffectID = go.WorldEffectID.GetValueOrDefault(0);
                    addonRow.Data.AIAnimKitID   = go.AIAnimKitID.GetValueOrDefault(0);

                    if (go.WorldEffectID != null || go.AIAnimKitID != null)
                    {
                        add = true;
                    }

                    addonRow.Comment += StoreGetters.GetName(StoreNameType.GameObject, (int)gameobject.Key.GetEntry(), false);

                    if (add)
                    {
                        addonRows.Add(addonRow);
                    }
                }

                row.Data.SpawnTimeSecs = go.GetDefaultSpawnTime(go.DifficultyID);
                row.Data.AnimProgress  = go.GameObjectData.PercentHealth;
                row.Data.State         = (uint)go.GameObjectData.State;

                // set some defaults
                row.Data.PhaseGroup = 0;

                row.Comment  = StoreGetters.GetName(StoreNameType.GameObject, (int)gameobject.Key.GetEntry(), false);
                row.Comment += " (Area: " + StoreGetters.GetName(StoreNameType.Area, go.Area, false) + " - ";
                row.Comment += "Difficulty: " + StoreGetters.GetName(StoreNameType.Difficulty, (int)go.DifficultyID, false) + ")";

                if (go.IsTemporarySpawn() && !Settings.SaveTempSpawns)
                {
                    row.CommentOut = true;
                    row.Comment   += " - !!! might be temporary spawn !!!";
                    if (Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.gameobject_addon))
                    {
                        addonRow.CommentOut = true;
                        addonRow.Comment   += " - !!! might be temporary spawn !!!";
                    }
                }
                else if (go.IsTransport())
                {
                    row.CommentOut = true;
                    row.Comment   += " - !!! transport !!!";
                    if (Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.gameobject_addon))
                    {
                        addonRow.CommentOut = true;
                        addonRow.Comment   += " - !!! transport !!!";
                    }
                }
                else if (go.IsOnTransport() && badTransport)
                {
                    row.CommentOut = true;
                    row.Comment   += " - !!! on transport - transport template not found !!!";
                    if (Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.gameobject_addon))
                    {
                        addonRow.CommentOut = true;
                        addonRow.Comment   += " - !!! on transport - transport template not found !!!";
                    }
                }
                else
                {
                    ++count;
                }

                rows.Add(row);
            }

            if (count == 0)
            {
                return(String.Empty);
            }

            StringBuilder result = new StringBuilder();
            // delete query for GUIDs
            var delete = new SQLDelete <GameObjectModel>(Tuple.Create("@OGUID+0", "@OGUID+" + --count));

            result.Append(delete.Build());

            var sql = new SQLInsert <GameObjectModel>(rows, false);

            result.Append(sql.Build());

            if (Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.gameobject_addon))
            {
                var addonDelete = new SQLDelete <GameObjectAddon>(Tuple.Create("@OGUID+0", "@OGUID+" + count));
                result.Append(addonDelete.Build());
                var addonSql = new SQLInsert <GameObjectAddon>(addonRows, false);
                result.Append(addonSql.Build());
            }

            return(result.ToString());
        }
Ejemplo n.º 21
0
        public static void ReadSpellTargetData(Packet packet, PacketSpellData?packetSpellData, uint spellID, params object[] idx)
        {
            packet.ResetBitReader();

            if (ClientVersion.AddedInVersion(ClientVersionBuild.V8_1_5_29683))
            {
                packet.ReadBitsE <TargetFlag>("Flags", 26, idx);
            }
            else
            {
                packet.ReadBitsE <TargetFlag>("Flags", 25, idx);
            }

            var hasSrcLoc  = packet.ReadBit("HasSrcLocation", idx);
            var hasDstLoc  = packet.ReadBit("HasDstLocation", idx);
            var hasOrient  = packet.ReadBit("HasOrientation", idx);
            var hasMapID   = packet.ReadBit("hasMapID ", idx);
            var nameLength = packet.ReadBits(7);

            var targetUnit = packet.ReadPackedGuid128("Unit", idx);

            if (packetSpellData != null)
            {
                packetSpellData.TargetUnit = targetUnit;
            }
            packet.ReadPackedGuid128("Item", idx);

            if (hasSrcLoc)
            {
                V6_0_2_19033.Parsers.SpellHandler.ReadLocation(packet, "SrcLocation");
            }

            Vector3?dstLocation = null;

            if (hasDstLoc)
            {
                dstLocation = V6_0_2_19033.Parsers.SpellHandler.ReadLocation(packet, "DstLocation");
                if (packetSpellData != null)
                {
                    packetSpellData.DstLocation = dstLocation;
                }
            }

            if (hasOrient)
            {
                packet.ReadSingle("Orientation", idx);
            }

            int mapID = -1;

            if (hasMapID)
            {
                mapID = (ushort)packet.ReadInt32("MapID", idx);
            }

            if (Settings.UseDBC && dstLocation != null && mapID != -1)
            {
                for (uint i = 0; i < 32; i++)
                {
                    var tuple = Tuple.Create(spellID, i);
                    if (DBC.SpellEffectStores.ContainsKey(tuple))
                    {
                        var effect = DBC.SpellEffectStores[tuple];
                        if ((Targets)effect.ImplicitTarget[0] == Targets.TARGET_DEST_DB || (Targets)effect.ImplicitTarget[1] == Targets.TARGET_DEST_DB)
                        {
                            string effectHelper = $"Spell: { StoreGetters.GetName(StoreNameType.Spell, (int)spellID) } Efffect: { effect.Effect } ({ (SpellEffects)effect.Effect })";

                            var spellTargetPosition = new SpellTargetPosition
                            {
                                ID           = spellID,
                                EffectIndex  = (byte)i,
                                PositionX    = dstLocation.Value.X,
                                PositionY    = dstLocation.Value.Y,
                                PositionZ    = dstLocation.Value.Z,
                                MapID        = (ushort)mapID,
                                EffectHelper = effectHelper
                            };

                            if (!Storage.SpellTargetPositions.ContainsKey(spellTargetPosition))
                            {
                                Storage.SpellTargetPositions.Add(spellTargetPosition);
                            }
                        }
                    }
                }
            }

            packet.ReadWoWString("Name", nameLength, idx);
        }
Ejemplo n.º 22
0
        public static string Creature(Dictionary <WowGuid, Unit> units)
        {
            if (units.Count == 0)
            {
                return(string.Empty);
            }

            if (!Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.creature))
            {
                return(string.Empty);
            }

            uint          count        = 0;
            CreatureAddon addonDefault = null;

            if (Settings.DBEnabled && Settings.SkipRowsWithFallbackValues)
            {
                addonDefault = SQLUtil.GetDefaultObject <CreatureAddon>();
            }
            var dbFields  = SQLUtil.GetDBFields <CreatureAddon>(false);
            var rows      = new RowList <Creature>();
            var addonRows = new RowList <CreatureAddon>();

            foreach (var unit in units)
            {
                Row <Creature> row          = new Row <Creature>();
                bool           badTransport = false;

                Unit creature = unit.Value;

                if (Settings.AreaFilters.Length > 0)
                {
                    if (!(creature.Area.ToString(CultureInfo.InvariantCulture).MatchesFilters(Settings.AreaFilters)))
                    {
                        continue;
                    }
                }

                if (Settings.MapFilters.Length > 0)
                {
                    if (!(creature.Map.ToString(CultureInfo.InvariantCulture).MatchesFilters(Settings.MapFilters)))
                    {
                        continue;
                    }
                }

                uint entry = (uint)creature.ObjectData.EntryID;
                if (entry == 0)
                {
                    continue;   // broken entry, nothing to spawn
                }
                uint movementType   = 0;
                int  wanderDistance = 0;
                row.Data.AreaID = 0;
                row.Data.ZoneID = 0;

                if (creature.Movement.HasWpsOrRandMov)
                {
                    movementType   = 1;
                    wanderDistance = 10;
                }

                row.Data.GUID = "@CGUID+" + count;

                row.Data.ID = entry;
                if (!creature.IsOnTransport())
                {
                    row.Data.Map = creature.Map;
                }
                else
                {
                    int mapId;
                    badTransport = !GetTransportMap(creature, out mapId);
                    if (mapId != -1)
                    {
                        row.Data.Map = (uint)mapId;
                    }
                }

                if (creature.Area != -1)
                {
                    row.Data.AreaID = (uint)creature.Area;
                }

                if (creature.Zone != -1)
                {
                    row.Data.ZoneID = (uint)creature.Zone;
                }

                row.Data.SpawnMask = (uint)creature.GetDefaultSpawnMask();

                if (ClientVersion.AddedInVersion(ClientVersionBuild.V7_0_3_22248))
                {
                    string data = string.Join(",", creature.GetDefaultSpawnDifficulties());
                    if (string.IsNullOrEmpty(data))
                    {
                        data = "0";
                    }

                    row.Data.spawnDifficulties = data;
                }

                row.Data.PhaseMask = creature.PhaseMask;

                if (ClientVersion.AddedInVersion(ClientVersionBuild.V4_3_4_15595) && creature.Phases != null)
                {
                    string data = string.Join(" - ", creature.Phases);
                    if (string.IsNullOrEmpty(data) || Settings.ForcePhaseZero)
                    {
                        data = "0";
                    }

                    row.Data.PhaseID = data;
                }

                if (SQLDatabase.CreatureEquipments.TryGetValue(entry, out var equipList))
                {
                    var equip = equipList.FirstOrDefault(x => x.EquipEqual(creature.UnitData.VirtualItems));
                    if (equip != null) // in case creature_equip_template parsing is disabled this is null for new equips
                    {
                        row.Data.EquipmentID = (int)equip.ID;
                    }
                }

                if (!creature.IsOnTransport())
                {
                    row.Data.PositionX   = creature.Movement.Position.X;
                    row.Data.PositionY   = creature.Movement.Position.Y;
                    row.Data.PositionZ   = creature.Movement.Position.Z;
                    row.Data.Orientation = creature.Movement.Orientation;
                }
                else
                {
                    row.Data.PositionX   = creature.Movement.Transport.Offset.X;
                    row.Data.PositionY   = creature.Movement.Transport.Offset.Y;
                    row.Data.PositionZ   = creature.Movement.Transport.Offset.Z;
                    row.Data.Orientation = creature.Movement.Transport.Offset.O;
                }

                row.Data.SpawnTimeSecs  = creature.GetDefaultSpawnTime(creature.DifficultyID);
                row.Data.WanderDistance = wanderDistance;
                row.Data.MovementType   = movementType;

                // set some defaults
                row.Data.PhaseGroup      = 0;
                row.Data.ModelID         = 0;
                row.Data.CurrentWaypoint = 0;
                row.Data.CurHealth       = (uint)creature.UnitData.MaxHealth;
                row.Data.CurMana         = (uint)creature.UnitData.MaxPower[0];
                row.Data.NpcFlag         = 0;
                row.Data.UnitFlag        = 0;
                row.Data.DynamicFlag     = 0;

                row.Comment  = StoreGetters.GetName(StoreNameType.Unit, (int)unit.Key.GetEntry(), false);
                row.Comment += " (Area: " + StoreGetters.GetName(StoreNameType.Area, creature.Area, false) + " - ";
                row.Comment += "Difficulty: " + StoreGetters.GetName(StoreNameType.Difficulty, (int)creature.DifficultyID, false) + ")";

                string auras        = string.Empty;
                string commentAuras = string.Empty;
                if (creature.Auras != null && creature.Auras.Count != 0)
                {
                    foreach (Aura aura in creature.Auras)
                    {
                        if (aura == null)
                        {
                            continue;
                        }

                        // usually "template auras" do not have caster
                        if (ClientVersion.AddedInVersion(ClientType.MistsOfPandaria) ? !aura.AuraFlags.HasAnyFlag(AuraFlagMoP.NoCaster) : !aura.AuraFlags.HasAnyFlag(AuraFlag.NotCaster))
                        {
                            continue;
                        }

                        auras        += aura.SpellId + " ";
                        commentAuras += aura.SpellId + " - " + StoreGetters.GetName(StoreNameType.Spell, (int)aura.SpellId, false) + ", ";
                    }

                    auras        = auras.TrimEnd(' ');
                    commentAuras = commentAuras.TrimEnd(',', ' ');

                    row.Comment += " (Auras: " + commentAuras + ")";
                }

                var addonRow = new Row <CreatureAddon>();
                if (Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.creature_addon))
                {
                    addonRow.Data.PathID                 = 0;
                    addonRow.Data.Mount                  = (uint)creature.UnitData.MountDisplayID;
                    addonRow.Data.Bytes1                 = creature.Bytes1;
                    addonRow.Data.Bytes2                 = creature.Bytes2;
                    addonRow.Data.Emote                  = 0;
                    addonRow.Data.Auras                  = auras;
                    addonRow.Data.AIAnimKit              = creature.AIAnimKit.GetValueOrDefault(0);
                    addonRow.Data.MovementAnimKit        = creature.MovementAnimKit.GetValueOrDefault(0);
                    addonRow.Data.MeleeAnimKit           = creature.MeleeAnimKit.GetValueOrDefault(0);
                    addonRow.Data.VisibilityDistanceType = creature.VisibilityDistanceType;

                    if (addonDefault == null || !SQLUtil.AreDBFieldsEqual(addonDefault, addonRow.Data, dbFields))
                    {
                        addonRow.Data.GUID = $"@CGUID+{count}";
                        addonRow.Comment  += StoreGetters.GetName(StoreNameType.Unit, (int)unit.Key.GetEntry(), false);
                        if (!string.IsNullOrWhiteSpace(auras))
                        {
                            addonRow.Comment += $" - {commentAuras}";
                        }
                        addonRows.Add(addonRow);
                    }
                }

                if (creature.IsTemporarySpawn() && !Settings.SaveTempSpawns)
                {
                    row.CommentOut = true;
                    row.Comment   += " - !!! might be temporary spawn !!!";
                    if (Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.creature_addon))
                    {
                        addonRow.CommentOut = true;
                        addonRow.Comment   += " - !!! might be temporary spawn !!!";
                    }
                }
                else if (creature.IsOnTransport() && badTransport)
                {
                    row.CommentOut = true;
                    row.Comment   += " - !!! on transport - transport template not found !!!";
                    if (Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.creature_addon))
                    {
                        addonRow.CommentOut = true;
                        addonRow.Comment   += " - !!! on transport - transport template not found !!!";
                    }
                }
                ++count;

                if (creature.Movement.HasWpsOrRandMov)
                {
                    row.Comment += " (possible waypoints or random movement)";
                }

                rows.Add(row);
            }

            if (count == 0)
            {
                return(string.Empty);
            }

            StringBuilder result = new StringBuilder();
            // delete query for GUIDs
            var delete = new SQLDelete <Creature>(Tuple.Create("@CGUID+0", "@CGUID+" + --count));

            result.Append(delete.Build());
            var sql = new SQLInsert <Creature>(rows, false);

            result.Append(sql.Build());

            if (Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.creature_addon))
            {
                var addonDelete = new SQLDelete <CreatureAddon>(Tuple.Create("@CGUID+0", "@CGUID+" + count));
                result.Append(addonDelete.Build());
                var addonSql = new SQLInsert <CreatureAddon>(addonRows, false);
                result.Append(addonSql.Build());
            }

            return(result.ToString());
        }
Ejemplo n.º 23
0
        public static string QuestPOI()
        {
            if (Storage.QuestPOIs.IsEmpty())
            {
                return(String.Empty);
            }

            const string tableName1 = "quest_poi";
            const string tableName2 = "quest_poi_points";

            // `quest_poi`
            var rows = new List <QueryBuilder.SQLInsertRow>();

            foreach (var quest in Storage.QuestPOIs)
            {
                var questPOI = quest.Value.Item1;

                var row = new QueryBuilder.SQLInsertRow();

                row.AddValue("questId", quest.Key.Item1);
                row.AddValue("id", quest.Key.Item2);
                row.AddValue("objIndex", questPOI.ObjectiveIndex);
                row.AddValue("mapid", questPOI.Map);
                row.AddValue("WorldMapAreaId", questPOI.WorldMapAreaId);
                row.AddValue("FloorId", questPOI.FloorId);
                row.AddValue("unk3", questPOI.UnkInt1);
                row.AddValue("unk4", questPOI.UnkInt2);
                row.Comment = StoreGetters.GetName(StoreNameType.Quest, (int)quest.Key.Item1, false);

                rows.Add(row);
            }

            var result = new QueryBuilder.SQLInsert(tableName1, rows, 2).Build();

            // `quest_poi_points`
            rows = new List <QueryBuilder.SQLInsertRow>();
            foreach (var quest in Storage.QuestPOIs)
            {
                var questPOI = quest.Value.Item1;

                if (questPOI.Points != null) // Needed?
                {
                    foreach (var point in questPOI.Points)
                    {
                        var row = new QueryBuilder.SQLInsertRow();

                        row.AddValue("questId", quest.Key.Item1);
                        row.AddValue("id", quest.Key.Item2);
                        row.AddValue("idx", point.Index); // Not on sniffs
                        row.AddValue("x", point.X);
                        row.AddValue("y", point.Y);
                        row.Comment = StoreGetters.GetName(StoreNameType.Quest, (int)quest.Key.Item1, false);

                        rows.Add(row);
                    }
                }
            }

            result += new QueryBuilder.SQLInsert(tableName2, rows, 2).Build();

            return(result);
        }
Ejemplo n.º 24
0
        public static void HandleDBReply(Packet packet)
        {
            var type = packet.ReadEnum <DB2Hash>("DB2 File", TypeCode.UInt32);

            packet.ReadTime("Hotfix date");
            var size = packet.ReadInt32("Size");

            var data    = packet.ReadBytes(size);
            var db2File = new Packet(data, packet.Opcode, packet.Time, packet.Direction, packet.Number, packet.Writer, packet.FileName);
            var entry   = (uint)packet.ReadInt32("Entry");

            if ((int)entry < 0)
            {
                packet.WriteLine("Row {0} has been removed.", -(int)entry);
                return;
            }

            switch (type)
            {
            case DB2Hash.Item:        // Item.db2
            {
                var item = Storage.ItemTemplates.ContainsKey(entry) ? Storage.ItemTemplates[entry].Item1 : new ItemTemplate();

                db2File.ReadEntryWithName <UInt32>(StoreNameType.Item, "Entry");
                item.Class    = db2File.ReadEnum <ItemClass>("Class", TypeCode.Int32);
                item.SubClass = db2File.ReadUInt32("Sub Class");
                item.SoundOverrideSubclass = db2File.ReadInt32("Sound Override Subclass");
                item.Material      = db2File.ReadEnum <Material>("Material", TypeCode.Int32);
                item.DisplayId     = db2File.ReadUInt32("Display ID");
                item.InventoryType = db2File.ReadEnum <InventoryType>("Inventory Type", TypeCode.UInt32);
                item.SheathType    = db2File.ReadEnum <SheathType>("Sheath Type", TypeCode.Int32);

                Storage.ItemTemplates.Add(entry, item, packet.TimeSpan);
                packet.AddSniffData(StoreNameType.Item, (int)entry, "DB_REPLY");
                break;
            }

            case DB2Hash.Item_sparse:        // Item-sparse.db2
            {
                var item = Storage.ItemTemplates.ContainsKey(entry) ? Storage.ItemTemplates[entry].Item1 : new ItemTemplate();

                db2File.ReadEntryWithName <UInt32>(StoreNameType.Item, "Entry");
                item.Quality            = db2File.ReadEnum <ItemQuality>("Quality", TypeCode.Int32);
                item.Flags              = db2File.ReadEnum <ItemProtoFlags>("Flags", TypeCode.UInt32);
                item.ExtraFlags         = db2File.ReadEnum <ItemFlagExtra>("Extra Flags", TypeCode.Int32);
                item.Unk430_1           = db2File.ReadSingle("Unk430_1");
                item.Unk430_2           = db2File.ReadSingle("Unk430_2");
                item.Unk530_1           = db2File.ReadSingle("Unk530_1");
                item.BuyCount           = db2File.ReadUInt32("Buy count");
                item.BuyPrice           = db2File.ReadUInt32("Buy Price");
                item.SellPrice          = db2File.ReadUInt32("Sell Price");
                item.InventoryType      = db2File.ReadEnum <InventoryType>("Inventory Type", TypeCode.Int32);
                item.AllowedClasses     = db2File.ReadEnum <ClassMask>("Allowed Classes", TypeCode.Int32);
                item.AllowedRaces       = db2File.ReadEnum <RaceMask>("Allowed Races", TypeCode.Int32);
                item.ItemLevel          = db2File.ReadUInt32("Item Level");
                item.RequiredLevel      = db2File.ReadUInt32("Required Level");
                item.RequiredSkillId    = db2File.ReadUInt32("Required Skill ID");
                item.RequiredSkillLevel = db2File.ReadUInt32("Required Skill Level");
                item.RequiredSpell      = (uint)db2File.ReadEntryWithName <Int32>(StoreNameType.Spell, "Required Spell");
                item.RequiredHonorRank  = db2File.ReadUInt32("Required Honor Rank");
                item.RequiredCityRank   = db2File.ReadUInt32("Required City Rank");
                item.RequiredRepFaction = db2File.ReadUInt32("Required Rep Faction");
                item.RequiredRepValue   = db2File.ReadUInt32("Required Rep Value");
                item.MaxCount           = db2File.ReadInt32("Max Count");
                item.MaxStackSize       = db2File.ReadInt32("Max Stack Size");
                item.ContainerSlots     = db2File.ReadUInt32("Container Slots");

                item.StatTypes = new ItemModType[10];
                for (var i = 0; i < 10; i++)
                {
                    var statType = db2File.ReadEnum <ItemModType>("Stat Type", TypeCode.Int32, i);
                    item.StatTypes[i] = statType == ItemModType.None ? ItemModType.Mana : statType;         // TDB
                }

                item.StatValues = new int[10];
                for (var i = 0; i < 10; i++)
                {
                    item.StatValues[i] = db2File.ReadInt32("Stat Value", i);
                }

                item.StatUnk1 = new int[10];
                for (var i = 0; i < 10; i++)
                {
                    item.StatUnk1[i] = db2File.ReadInt32("Unk UInt32 1", i);
                }

                item.StatUnk2 = new int[10];
                for (var i = 0; i < 10; i++)
                {
                    item.StatUnk2[i] = db2File.ReadInt32("Unk UInt32 2", i);
                }

                item.ScalingStatDistribution = db2File.ReadInt32("Scaling Stat Distribution");
                item.DamageType = db2File.ReadEnum <DamageType>("Damage Type", TypeCode.Int32);
                item.Delay      = db2File.ReadUInt32("Delay");
                item.RangedMod  = db2File.ReadSingle("Ranged Mod");

                item.TriggeredSpellIds = new int[5];
                for (var i = 0; i < 5; i++)
                {
                    item.TriggeredSpellIds[i] = db2File.ReadEntryWithName <Int32>(StoreNameType.Spell, "Triggered Spell ID", i);
                }

                item.TriggeredSpellTypes = new ItemSpellTriggerType[5];
                for (var i = 0; i < 5; i++)
                {
                    item.TriggeredSpellTypes[i] = db2File.ReadEnum <ItemSpellTriggerType>("Trigger Spell Type", TypeCode.Int32, i);
                }

                item.TriggeredSpellCharges = new int[5];
                for (var i = 0; i < 5; i++)
                {
                    item.TriggeredSpellCharges[i] = db2File.ReadInt32("Triggered Spell Charges", i);
                }

                item.TriggeredSpellCooldowns = new int[5];
                for (var i = 0; i < 5; i++)
                {
                    item.TriggeredSpellCooldowns[i] = db2File.ReadInt32("Triggered Spell Cooldown", i);
                }

                item.TriggeredSpellCategories = new uint[5];
                for (var i = 0; i < 5; i++)
                {
                    item.TriggeredSpellCategories[i] = db2File.ReadUInt32("Triggered Spell Category", i);
                }

                item.TriggeredSpellCategoryCooldowns = new int[5];
                for (var i = 0; i < 5; i++)
                {
                    item.TriggeredSpellCategoryCooldowns[i] = db2File.ReadInt32("Triggered Spell Category Cooldown", i);
                }

                item.Bonding = db2File.ReadEnum <ItemBonding>("Bonding", TypeCode.Int32);

                if (db2File.ReadUInt16() > 0)
                {
                    item.Name = db2File.ReadCString("Name", 0);
                }

                for (var i = 1; i < 4; ++i)
                {
                    if (db2File.ReadUInt16() > 0)
                    {
                        db2File.ReadCString("Name", i);
                    }
                }

                if (db2File.ReadUInt16() > 0)
                {
                    item.Description = db2File.ReadCString("Description");
                }

                item.PageText      = db2File.ReadUInt32("Page Text");
                item.Language      = db2File.ReadEnum <Language>("Language", TypeCode.Int32);
                item.PageMaterial  = db2File.ReadEnum <PageMaterial>("Page Material", TypeCode.Int32);
                item.StartQuestId  = (uint)db2File.ReadEntryWithName <Int32>(StoreNameType.Quest, "Start Quest");
                item.LockId        = db2File.ReadUInt32("Lock ID");
                item.Material      = db2File.ReadEnum <Material>("Material", TypeCode.Int32);
                item.SheathType    = db2File.ReadEnum <SheathType>("Sheath Type", TypeCode.Int32);
                item.RandomPropery = db2File.ReadInt32("Random Property");
                item.RandomSuffix  = db2File.ReadUInt32("Random Suffix");
                item.ItemSet       = db2File.ReadUInt32("Item Set");
                item.AreaId        = (uint)db2File.ReadEntryWithName <UInt32>(StoreNameType.Area, "Area");
                // In this single (?) case, map 0 means no map
                var map = db2File.ReadInt32();
                item.MapId = map;
                db2File.WriteLine("Map ID: " + (map != 0 ? StoreGetters.GetName(StoreNameType.Map, map) : map + " (No map)"));
                item.BagFamily     = db2File.ReadEnum <BagFamilyMask>("Bag Family", TypeCode.Int32);
                item.TotemCategory = db2File.ReadEnum <TotemCategory>("Totem Category", TypeCode.Int32);

                item.ItemSocketColors = new ItemSocketColor[3];
                for (var i = 0; i < 3; i++)
                {
                    item.ItemSocketColors[i] = db2File.ReadEnum <ItemSocketColor>("Socket Color", TypeCode.Int32, i);
                }

                item.SocketContent = new uint[3];
                for (var i = 0; i < 3; i++)
                {
                    item.SocketContent[i] = db2File.ReadUInt32("Socket Item", i);
                }

                item.SocketBonus               = db2File.ReadInt32("Socket Bonus");
                item.GemProperties             = db2File.ReadInt32("Gem Properties");
                item.ArmorDamageModifier       = db2File.ReadSingle("Armor Damage Modifier");
                item.Duration                  = db2File.ReadUInt32("Duration");
                item.ItemLimitCategory         = db2File.ReadInt32("Limit Category");
                item.HolidayId                 = db2File.ReadEnum <Holiday>("Holiday", TypeCode.Int32);
                item.StatScalingFactor         = db2File.ReadSingle("Stat Scaling Factor");
                item.CurrencySubstitutionId    = db2File.ReadUInt32("Currency Substitution Id");
                item.CurrencySubstitutionCount = db2File.ReadUInt32("Currency Substitution Count");

                Storage.ObjectNames.Add(entry, new ObjectName {
                        ObjectType = ObjectType.Item, Name = item.Name
                    }, packet.TimeSpan);
                packet.AddSniffData(StoreNameType.Item, (int)entry, "DB_REPLY");
                break;
            }

            case DB2Hash.KeyChain:     // KeyChain.db2
            {
                db2File.ReadUInt32("Key Chain Id");
                db2File.WriteLine("Key: {0}", Utilities.ByteArrayToHexString(db2File.ReadBytes(32)));
                break;
            }

            case DB2Hash.Creature:     // Creature.db2
            {
                db2File.ReadUInt32("Npc Entry");
                db2File.ReadUInt32("Item Entry 1");
                db2File.ReadUInt32("Item Entry 2");
                db2File.ReadUInt32("Item Entry 3");
                db2File.ReadUInt32("Projectile Entry 1");
                db2File.ReadUInt32("Projectile Entry 2");
                db2File.ReadUInt32("Mount");
                db2File.ReadUInt32("Display Id 1");
                db2File.ReadUInt32("Display Id 2");
                db2File.ReadUInt32("Display Id 3");
                db2File.ReadUInt32("Display Id 4");
                db2File.ReadSingle("Float1");
                db2File.ReadSingle("Float2");
                db2File.ReadSingle("Float3");
                db2File.ReadSingle("Float4");
                if (db2File.ReadUInt16() > 0)
                {
                    db2File.ReadCString("Name");
                }

                db2File.ReadUInt32("InhabitType");
                break;
            }

            case DB2Hash.BroadcastText:
            {
                db2File.ReadUInt32("Broadcast Text Entry");
                db2File.ReadUInt32("Language");
                if (db2File.ReadUInt16() > 0)
                {
                    db2File.ReadCString("Male Text");
                }
                if (db2File.ReadUInt16() > 0)
                {
                    db2File.ReadCString("Female Text");
                }

                for (var i = 0; i < 3; ++i)
                {
                    db2File.ReadInt32("Emote ID", i);
                }
                for (var i = 0; i < 3; ++i)
                {
                    db2File.ReadInt32("Emote Delay", i);
                }

                db2File.ReadUInt32("Sound Id");
                db2File.ReadUInt32("Unk0");
                db2File.ReadUInt32("Unk1");         // kind of type?
                break;
            }

            default:
            {
                db2File.WriteLine("Unknown DB2 file type: {0} (0x{0:x})", type);
                for (var i = 0; ; ++i)
                {
                    if (db2File.Length - 4 >= db2File.Position)
                    {
                        var    blockVal = db2File.ReadUpdateField();
                        string key      = "Block Value " + i;
                        string value    = blockVal.UInt32Value + "/" + blockVal.SingleValue;
                        packet.WriteLine(key + ": " + value);
                    }
                    else
                    {
                        var left = db2File.Length - db2File.Position;
                        for (var j = 0; j < left; ++j)
                        {
                            string key   = "Byte Value " + i;
                            var    value = db2File.ReadByte();
                            packet.WriteLine(key + ": " + value);
                        }
                        break;
                    }
                }
                break;
            }
            }
        }
Ejemplo n.º 25
0
        public static void HandlePetSpells(Packet packet)
        {
            var guid = packet.ReadGuid("GUID");

            // Equal to "Clear spells" pre cataclysm
            if (guid.Full == 0)
            {
                return;
            }

            if (ClientVersion.AddedInVersion(ClientVersionBuild.V3_1_0_9767))
            {
                packet.ReadEnum <CreatureFamily>("Pet Family", TypeCode.UInt16); // vehicles -> 0
            }
            if (ClientVersion.AddedInVersion(ClientVersionBuild.V5_1_0_16309))
            {
                packet.ReadUInt16("Unk UInt16");
            }

            packet.ReadUInt32("Expiration Time");

            ReadPetFlags(ref packet);

            var       isPet             = guid.GetHighType() == HighGuidType.Pet;
            var       isVehicle         = guid.GetHighType() == HighGuidType.Vehicle;
            var       isMinion          = guid.GetHighType() == HighGuidType.Unit;
            const int maxCreatureSpells = 10;
            var       spells            = new List <uint>(maxCreatureSpells);

            for (var i = 0; i < maxCreatureSpells; i++) // Read pet/vehicle spell ids
            {
                var spell16 = packet.ReadUInt16();
                var spell8  = packet.ReadByte();
                var spellId = spell16 + (spell8 << 16);
                var slot    = packet.ReadByte();

                var s = new StringBuilder("[");
                s.Append(i).Append("] ").Append("Spell/Action: ");
                if (spellId <= 4)
                {
                    s.Append(spellId);
                }
                else
                {
                    s.Append(StoreGetters.GetName(StoreNameType.Spell, spellId));
                }
                s.Append(" slot: ").Append(slot);
                packet.WriteLine(s.ToString());

                // Spells for pets are on DBCs; also no entry in guid
                // We don't need the actions sent for minions (slots lower than 8)
                if (!isPet && (isVehicle || (isMinion && slot >= 8)))
                {
                    spells.Add((uint)spellId);
                }
            }

            if (spells.Count != 0)
            {
                SpellsX spellsCr;
                spellsCr.Spells = spells.ToArray();
                Storage.SpellsX.Add(guid.GetEntry(), spellsCr, packet.TimeSpan);
            }

            var spellCount = packet.ReadByte("Spell Count"); // vehicles -> 0, pets -> != 0. Could this be auras?

            for (var i = 0; i < spellCount; i++)
            {
                packet.ReadEntryWithName <UInt16>(StoreNameType.Spell, "Spell", i);
                packet.ReadInt16("Active", i);
            }

            var cdCount = packet.ReadByte("Cooldown count");

            for (var i = 0; i < cdCount; i++)
            {
                if (ClientVersion.AddedInVersion(ClientVersionBuild.V3_1_0_9767))
                {
                    packet.ReadEntryWithName <UInt32>(StoreNameType.Spell, "Spell", i);
                }
                else
                {
                    packet.ReadEntryWithName <UInt16>(StoreNameType.Spell, "Spell", i);
                }

                packet.ReadUInt16("Category", i);
                packet.ReadUInt32("Cooldown", i);
                packet.ReadUInt32("Category Cooldown", i);
            }

            if (ClientVersion.AddedInVersion(ClientVersionBuild.V5_1_0_16309))
            {
                var unkLoopCounter = packet.ReadByte("Unk count");
                for (var i = 0; i < unkLoopCounter; i++)
                {
                    packet.ReadUInt32("Unk UInt32 1", i);
                    packet.ReadByte("Unk Byte", i);
                    packet.ReadUInt32("Unk UInt32 2", i);
                }
            }
        }
Ejemplo n.º 26
0
        public static void HandleDBReply(Packet packet)
        {
            var id   = packet.ReadUInt32("Entry");
            var type = packet.ReadUInt32("Type"); // See DB2Hash enum. Left like this for now to see some numbers pop. ^^

            packet.ReadTime("Hotfix date");
            var size = packet.ReadUInt32("Size");

            if (size == 0 || id < 0)
            {
                return;
            }

            var HashType = (DB2Hash)type;
            var itemId   = (uint)id;

            switch (HashType)
            {
            case DB2Hash.Item:        // Items
            {
                var item = Storage.ItemTemplates.ContainsKey(itemId) ? Storage.ItemTemplates[itemId].Item1 : new ItemTemplate();

                packet.ReadEntryWithName <UInt32>(StoreNameType.Item, "Entry");
                item.Class    = packet.ReadEnum <ItemClass>("Class", TypeCode.Int32);
                item.SubClass = packet.ReadUInt32("Sub Class");
                item.SoundOverrideSubclass = packet.ReadInt32("Sound Override Subclass");
                item.Material      = packet.ReadEnum <Material>("Material", TypeCode.Int32);
                item.DisplayId     = packet.ReadUInt32("Display ID");
                item.InventoryType = packet.ReadEnum <InventoryType>("Inventory Type", TypeCode.UInt32);
                item.SheathType    = packet.ReadEnum <SheathType>("Sheath Type", TypeCode.Int32);

                Storage.ItemTemplates.Add(itemId, item, packet.TimeSpan);
                break;
            }

            case DB2Hash.Item_sparse:        // Item-sparse
            {
                var item = Storage.ItemTemplates.ContainsKey(itemId) ? Storage.ItemTemplates[itemId].Item1 : new ItemTemplate();

                packet.ReadEntryWithName <UInt32>(StoreNameType.Item, "Entry");
                item.Quality            = packet.ReadEnum <ItemQuality>("Quality", TypeCode.Int32);
                item.Flags              = packet.ReadEnum <ItemProtoFlags>("Flags", TypeCode.UInt32);
                item.ExtraFlags         = packet.ReadEnum <ItemFlagExtra>("Extra Flags", TypeCode.Int32);
                item.Unk430_1           = packet.ReadSingle("Unk430_1");
                item.Unk430_2           = packet.ReadSingle("Unk430_2");
                item.BuyCount           = packet.ReadUInt32("Buy count");
                item.BuyPrice           = packet.ReadUInt32("Buy Price");
                item.SellPrice          = packet.ReadUInt32("Sell Price");
                item.InventoryType      = packet.ReadEnum <InventoryType>("Inventory Type", TypeCode.Int32);
                item.AllowedClasses     = packet.ReadEnum <ClassMask>("Allowed Classes", TypeCode.Int32);
                item.AllowedRaces       = packet.ReadEnum <RaceMask>("Allowed Races", TypeCode.Int32);
                item.ItemLevel          = packet.ReadUInt32("Item Level");
                item.RequiredLevel      = packet.ReadUInt32("Required Level");
                item.RequiredSkillId    = packet.ReadUInt32("Required Skill ID");
                item.RequiredSkillLevel = packet.ReadUInt32("Required Skill Level");
                item.RequiredSpell      = (uint)packet.ReadEntryWithName <Int32>(StoreNameType.Spell, "Required Spell");
                item.RequiredHonorRank  = packet.ReadUInt32("Required Honor Rank");
                item.RequiredCityRank   = packet.ReadUInt32("Required City Rank");
                item.RequiredRepFaction = packet.ReadUInt32("Required Rep Faction");
                item.RequiredRepValue   = packet.ReadUInt32("Required Rep Value");
                item.MaxCount           = packet.ReadInt32("Max Count");
                item.MaxStackSize       = packet.ReadInt32("Max Stack Size");
                item.ContainerSlots     = packet.ReadUInt32("Container Slots");

                item.StatTypes = new ItemModType[10];
                for (var i = 0; i < 10; i++)
                {
                    var statType = packet.ReadEnum <ItemModType>("Stat Type", TypeCode.Int32, i);
                    item.StatTypes[i] = statType == ItemModType.None ? ItemModType.Mana : statType;     // TDB
                }

                item.StatValues = new int[10];
                for (var i = 0; i < 10; i++)
                {
                    item.StatValues[i] = packet.ReadInt32("Stat Value", i);
                }

                item.StatUnk1 = new int[10];
                for (var i = 0; i < 10; i++)
                {
                    item.StatUnk1[i] = packet.ReadInt32("Unk UInt32 1", i);
                }

                item.StatUnk2 = new int[10];
                for (var i = 0; i < 10; i++)
                {
                    item.StatUnk2[i] = packet.ReadInt32("Unk UInt32 2", i);
                }

                item.ScalingStatDistribution = packet.ReadInt32("Scaling Stat Distribution");
                item.DamageType = packet.ReadEnum <DamageType>("Damage Type", TypeCode.Int32);
                item.Delay      = packet.ReadUInt32("Delay");
                item.RangedMod  = packet.ReadSingle("Ranged Mod");

                item.TriggeredSpellIds = new int[5];
                for (var i = 0; i < 5; i++)
                {
                    item.TriggeredSpellIds[i] = packet.ReadEntryWithName <Int32>(StoreNameType.Spell, "Triggered Spell ID", i);
                }

                item.TriggeredSpellTypes = new ItemSpellTriggerType[5];
                for (var i = 0; i < 5; i++)
                {
                    item.TriggeredSpellTypes[i] = packet.ReadEnum <ItemSpellTriggerType>("Trigger Spell Type", TypeCode.Int32, i);
                }

                item.TriggeredSpellCharges = new int[5];
                for (var i = 0; i < 5; i++)
                {
                    item.TriggeredSpellCharges[i] = packet.ReadInt32("Triggered Spell Charges", i);
                }

                item.TriggeredSpellCooldowns = new int[5];
                for (var i = 0; i < 5; i++)
                {
                    item.TriggeredSpellCooldowns[i] = packet.ReadInt32("Triggered Spell Cooldown", i);
                }

                item.TriggeredSpellCategories = new uint[5];
                for (var i = 0; i < 5; i++)
                {
                    item.TriggeredSpellCategories[i] = packet.ReadUInt32("Triggered Spell Category", i);
                }

                item.TriggeredSpellCategoryCooldowns = new int[5];
                for (var i = 0; i < 5; i++)
                {
                    item.TriggeredSpellCategoryCooldowns[i] = packet.ReadInt32("Triggered Spell Category Cooldown", i);
                }

                item.Bonding = packet.ReadEnum <ItemBonding>("Bonding", TypeCode.Int32);

                if (packet.ReadUInt16() > 0)
                {
                    item.Name = packet.ReadCString("Name", 0);
                }

                for (var i = 1; i < 4; ++i)
                {
                    if (packet.ReadUInt16() > 0)
                    {
                        packet.ReadCString("Name", i);
                    }
                }

                if (packet.ReadUInt16() > 0)
                {
                    item.Description = packet.ReadCString("Description");
                }

                item.PageText      = packet.ReadUInt32("Page Text");
                item.Language      = packet.ReadEnum <Language>("Language", TypeCode.Int32);
                item.PageMaterial  = packet.ReadEnum <PageMaterial>("Page Material", TypeCode.Int32);
                item.StartQuestId  = (uint)packet.ReadEntryWithName <Int32>(StoreNameType.Quest, "Start Quest");
                item.LockId        = packet.ReadUInt32("Lock ID");
                item.Material      = packet.ReadEnum <Material>("Material", TypeCode.Int32);
                item.SheathType    = packet.ReadEnum <SheathType>("Sheath Type", TypeCode.Int32);
                item.RandomPropery = packet.ReadInt32("Random Property");
                item.RandomSuffix  = packet.ReadUInt32("Random Suffix");
                item.ItemSet       = packet.ReadUInt32("Item Set");
                item.AreaId        = (uint)packet.ReadEntryWithName <UInt32>(StoreNameType.Area, "Area");
                // In this single (?) case, map 0 means no map
                var map = packet.ReadInt32();
                item.MapId = map;
                packet.WriteLine("Map ID: " + (map != 0 ? StoreGetters.GetName(StoreNameType.Map, map) : map + " (No map)"));
                item.BagFamily     = packet.ReadEnum <BagFamilyMask>("Bag Family", TypeCode.Int32);
                item.TotemCategory = packet.ReadEnum <TotemCategory>("Totem Category", TypeCode.Int32);

                item.ItemSocketColors = new ItemSocketColor[3];
                for (var i = 0; i < 3; i++)
                {
                    item.ItemSocketColors[i] = packet.ReadEnum <ItemSocketColor>("Socket Color", TypeCode.Int32, i);
                }

                item.SocketContent = new uint[3];
                for (var i = 0; i < 3; i++)
                {
                    item.SocketContent[i] = packet.ReadUInt32("Socket Item", i);
                }

                item.SocketBonus               = packet.ReadInt32("Socket Bonus");
                item.GemProperties             = packet.ReadInt32("Gem Properties");
                item.ArmorDamageModifier       = packet.ReadSingle("Armor Damage Modifier");
                item.Duration                  = packet.ReadUInt32("Duration");
                item.ItemLimitCategory         = packet.ReadInt32("Limit Category");
                item.HolidayId                 = packet.ReadEnum <Holiday>("Holiday", TypeCode.Int32);
                item.StatScalingFactor         = packet.ReadSingle("Stat Scaling Factor");
                item.CurrencySubstitutionId    = packet.ReadUInt32("Currency Substitution Id");
                item.CurrencySubstitutionCount = packet.ReadUInt32("Currency Substitution Count");

                Storage.ObjectNames.Add(itemId, new ObjectName {
                        ObjectType = ObjectType.Item, Name = item.Name
                    }, packet.TimeSpan);
                break;
            }

            case DB2Hash.KeyChain:     // KeyChain
            {
                packet.ReadUInt32("Key Chain Id");
                packet.WriteLine("Key: {0}", Utilities.ByteArrayToHexString(packet.ReadBytes(32)));
                break;
            }

            // Cases need correction, the other DB2's need implementation etc.
            default: break;
            }

            if (HashType == DB2Hash.Item || HashType == DB2Hash.Item_sparse) // Add item data.
            {
                packet.AddSniffData(StoreNameType.Item, (int)itemId, "DB_REPLY");
            }

            packet.ReadToEnd();
        }
Ejemplo n.º 27
0
        public static void HandleNameQueryResponse(Packet packet)
        {
            PacketQueryPlayerNameResponse response = packet.Holder.QueryPlayerNameResponse = new();
            WowGuid guid;

            if (ClientVersion.AddedInVersion(ClientVersionBuild.V3_1_0_9767))
            {
                response.PlayerGuid = guid = packet.ReadPackedGuid("GUID");
                var end = packet.ReadByte("Result");

                /*
                 * if (end == 1)
                 *  DenyItem(&WDB_CACHE_NAME, v11, v12);
                 * if (end == 2)
                 *  RetryItem(&WDB_CACHE_NAME, v11, v12);
                 * if (end == 3)
                 * {
                 *  AddItem(&WDB_CACHE_NAME, (int)&v8, v11, v12);
                 *  SetTemporary(&WDB_CACHE_NAME, v11, v12);
                 * }
                 */
                if (end != 0)
                {
                    return;
                }
            }
            else
            {
                response.PlayerGuid = guid = packet.ReadGuid("GUID");
            }

            response.HasData = true;
            var name = packet.ReadCString("Name");

            response.PlayerName = name;
            StoreGetters.AddName(guid, name);
            packet.ReadCString("Realm Name");

            if (ClientVersion.AddedInVersion(ClientVersionBuild.V3_1_0_9767))
            {
                response.Race   = (uint)packet.ReadByteE <Race>("Race");
                response.Gender = (uint)packet.ReadByteE <Gender>("Gender");
                response.Class  = (uint)packet.ReadByteE <Class>("Class");
            }
            else
            {
                response.Race   = (uint)packet.ReadInt32E <Race>("Race");
                response.Gender = (uint)packet.ReadInt32E <Gender>("Gender");
                response.Class  = (uint)packet.ReadInt32E <Class>("Class");
            }

            if (!packet.ReadBool("Name Declined"))
            {
                return;
            }

            for (var i = 0; i < 5; i++)
            {
                packet.ReadCString("Declined Name", i);
            }

            var objectName = new ObjectName
            {
                ObjectType = StoreNameType.Player,
                ID         = (int)guid.GetLow(),
                Name       = name
            };

            Storage.ObjectNames.Add(objectName, packet.TimeSpan);
        }
Ejemplo n.º 28
0
        public static string Gossip()
        {
            // TODO: This should be rewritten

            if (Storage.Gossips.IsEmpty())
            {
                return(String.Empty);
            }

            // `creature_template`
            var gossipIds = new Dictionary <uint, UnitGossip>();

            foreach (var gossip in Storage.Gossips)
            {
                if (gossip.Value.Item1.ObjectType != ObjectType.Unit)
                {
                    continue;
                }
                // no support for entries with multiple gossips (i.e changed by script)
                if (gossipIds.ContainsKey(gossip.Value.Item1.ObjectEntry))
                {
                    continue;
                }

                gossipIds.Add(gossip.Value.Item1.ObjectEntry, new UnitGossip {
                    GossipId = gossip.Key.Item1
                });
            }

            var entries     = gossipIds.Keys.ToList();
            var gossipIdsDb = SQLDatabase.GetDict <uint, UnitGossip>(entries);
            var result      = SQLUtil.CompareDicts(new StoreDictionary <uint, UnitGossip>(gossipIds), gossipIdsDb, StoreNameType.Unit);

            // `gossip`
            if (SQLConnector.Enabled)
            {
                var query = new StringBuilder(string.Format("SELECT `entry`,`text_id` FROM {0}.`gossip_menu` WHERE ", Settings.TDBDatabase));
                foreach (Tuple <uint, uint> gossip in Storage.Gossips.Keys())
                {
                    query.Append("(`entry`=").Append(gossip.Item1).Append(" AND ");
                    query.Append("`text_id`=").Append(gossip.Item2).Append(") OR ");
                }
                query.Remove(query.Length - 4, 4).Append(";");

                var rows = new List <QueryBuilder.SQLInsertRow>();
                using (var reader = SQLConnector.ExecuteQuery(query.ToString()))
                {
                    if (reader != null)
                    {
                        while (reader.Read())
                        {
                            var values = new object[2];
                            var count  = reader.GetValues(values);
                            if (count != 2)
                            {
                                break; // error in query
                            }
                            var entry  = Convert.ToUInt32(values[0]);
                            var textId = Convert.ToUInt32(values[1]);

                            // our table is small, 2 fields and both are PKs; no need for updates
                            if (!Storage.Gossips.ContainsKey(Tuple.Create(entry, textId)))
                            {
                                var row = new QueryBuilder.SQLInsertRow();
                                row.AddValue("entry", entry);
                                row.AddValue("text_id", textId);
                                row.Comment = StoreGetters.GetName(StoreNameType.Unit, // BUG: GOs can send gossips too
                                                                   (int)entry, false);
                                rows.Add(row);
                            }
                        }
                    }
                }
                result += new QueryBuilder.SQLInsert("gossip_menu", rows, 2).Build();
            }
            else
            {
                var rows = new List <QueryBuilder.SQLInsertRow>();
                foreach (var gossip in Storage.Gossips)
                {
                    var row = new QueryBuilder.SQLInsertRow();

                    row.AddValue("entry", gossip.Key.Item1);
                    row.AddValue("text_id", gossip.Key.Item2);
                    row.Comment = StoreGetters.GetName(Utilities.ObjectTypeToStore(gossip.Value.Item1.ObjectType),
                                                       (int)gossip.Value.Item1.ObjectEntry, false);

                    rows.Add(row);
                }

                result += new QueryBuilder.SQLInsert("gossip_menu", rows, 2).Build();
            }

            // `gossip_menu_option`
            if (SQLConnector.Enabled)
            {
                var rowsIns = new List <QueryBuilder.SQLInsertRow>();
                var rowsUpd = new List <QueryBuilder.SQLUpdateRow>();

                foreach (var gossip in Storage.Gossips)
                {
                    if (gossip.Value.Item1.GossipOptions == null)
                    {
                        continue;
                    }
                    foreach (var gossipOption in gossip.Value.Item1.GossipOptions)
                    {
                        var query =       //         0     1       2         3         4        5         6
                                    string.Format("SELECT menu_id,id,option_icon,box_coded,box_money,box_text,option_text " +
                                                  "FROM {2}.gossip_menu_option WHERE menu_id={0} AND id={1};", gossip.Key.Item1,
                                                  gossipOption.Index, Settings.TDBDatabase);
                        using (var reader = SQLConnector.ExecuteQuery(query))
                        {
                            if (reader.HasRows) // possible update
                            {
                                while (reader.Read())
                                {
                                    var row = new QueryBuilder.SQLUpdateRow();

                                    if (!Utilities.EqualValues(reader.GetValue(2), gossipOption.OptionIcon))
                                    {
                                        row.AddValue("option_icon", gossipOption.OptionIcon);
                                    }

                                    if (!Utilities.EqualValues(reader.GetValue(3), gossipOption.Box))
                                    {
                                        row.AddValue("box_coded", gossipOption.Box);
                                    }

                                    if (!Utilities.EqualValues(reader.GetValue(4), gossipOption.RequiredMoney))
                                    {
                                        row.AddValue("box_money", gossipOption.RequiredMoney);
                                    }

                                    if (!Utilities.EqualValues(reader.GetValue(5), gossipOption.BoxText))
                                    {
                                        row.AddValue("box_text", gossipOption.BoxText);
                                    }

                                    if (!Utilities.EqualValues(reader.GetValue(6), gossipOption.OptionText))
                                    {
                                        row.AddValue("option_text", gossipOption.OptionText);
                                    }

                                    row.AddWhere("menu_id", gossip.Key.Item1);
                                    row.AddWhere("id", gossipOption.Index);

                                    row.Comment =
                                        StoreGetters.GetName(Utilities.ObjectTypeToStore(gossip.Value.Item1.ObjectType),
                                                             (int)gossip.Value.Item1.ObjectEntry, false);

                                    row.Table = "gossip_menu_option";

                                    if (row.ValueCount != 0)
                                    {
                                        rowsUpd.Add(row);
                                    }
                                }
                            }
                            else // insert
                            {
                                var row = new QueryBuilder.SQLInsertRow();

                                row.AddValue("menu_id", gossip.Key.Item1);
                                row.AddValue("id", gossipOption.Index);
                                row.AddValue("option_icon", gossipOption.OptionIcon);
                                row.AddValue("option_text", gossipOption.OptionText);
                                row.AddValue("box_coded", gossipOption.Box);
                                row.AddValue("box_money", gossipOption.RequiredMoney);
                                row.AddValue("box_text", gossipOption.BoxText);

                                row.Comment = StoreGetters.GetName(Utilities.ObjectTypeToStore(gossip.Value.Item1.ObjectType),
                                                                   (int)gossip.Value.Item1.ObjectEntry, false);

                                rowsIns.Add(row);
                            }
                        }
                    }
                }
                result += new QueryBuilder.SQLInsert("gossip_menu_option", rowsIns, 2).Build() +
                          new QueryBuilder.SQLUpdate(rowsUpd).Build();
            }
            else
            {
                var rows = new List <QueryBuilder.SQLInsertRow>();
                foreach (var gossip in Storage.Gossips)
                {
                    if (gossip.Value.Item1.GossipOptions != null)
                    {
                        foreach (var gossipOption in gossip.Value.Item1.GossipOptions)
                        {
                            var row = new QueryBuilder.SQLInsertRow();

                            row.AddValue("menu_id", gossip.Key.Item1);
                            row.AddValue("id", gossipOption.Index);
                            row.AddValue("option_icon", gossipOption.OptionIcon);
                            row.AddValue("option_text", gossipOption.OptionText);
                            row.AddValue("box_coded", gossipOption.Box);
                            row.AddValue("box_money", gossipOption.RequiredMoney);
                            row.AddValue("box_text", gossipOption.BoxText);

                            row.Comment = StoreGetters.GetName(Utilities.ObjectTypeToStore(gossip.Value.Item1.ObjectType),
                                                               (int)gossip.Value.Item1.ObjectEntry, false);

                            rows.Add(row);
                        }
                    }
                }

                result += new QueryBuilder.SQLInsert("gossip_menu_option", rows, 2).Build();
            }

            return(result);
        }
Ejemplo n.º 29
0
        /// <summary>
        /// <para>Compare two dictionaries (of the same types) and creates SQL inserts
        ///  or updates accordingly.</para>
        /// <remarks>Second dictionary can be null (only inserts queries will be produced)</remarks>
        /// <remarks>Use DBTableName and DBFieldName attributes to specify table and field names, in TK</remarks>
        /// </summary>
        /// <typeparam name="T">Type of the primary key (uint)</typeparam>
        /// <typeparam name="TK">Type of the WDB struct (field types must match DB field)</typeparam>
        /// <param name="dict1">Dictionary retrieved from  parser</param>
        /// <param name="dict2">Dictionary retrieved from  DB</param>
        /// <param name="storeType">Are we dealing with Spells, Quests, Units, ...?</param>
        /// <param name="primaryKeyName">The name of the primary key, usually "entry"</param>
        /// <returns>A string containing full SQL queries</returns>
        public static string CompareDicts <T, TK>(StoreDictionary <T, TK> dict1, StoreDictionary <T, TK> dict2, StoreNameType storeType, string primaryKeyName = "entry")
        {
            var tableAttrs = (DBTableNameAttribute[])typeof(TK).GetCustomAttributes(typeof(DBTableNameAttribute), false);

            if (tableAttrs.Length <= 0)
            {
                return(string.Empty);
            }
            var tableName = tableAttrs[0].Name;

            var fields = Utilities.GetFieldsAndAttribute <TK, DBFieldNameAttribute>();

            if (fields == null)
            {
                return(string.Empty);
            }

            fields.RemoveAll(field => field.Item2.Name == null);

            var rowsIns = new List <QueryBuilder.SQLInsertRow>();
            var rowsUpd = new List <QueryBuilder.SQLUpdateRow>();

            foreach (var elem1 in dict1)
            {
                if (dict2 != null && dict2.ContainsKey(elem1.Key)) // update
                {
                    var row = new QueryBuilder.SQLUpdateRow();

                    foreach (var field in fields)
                    {
                        var elem2 = dict2[elem1.Key];

                        var val1 = field.Item1.GetValue(elem1.Value.Item1);
                        var val2 = field.Item1.GetValue(elem2.Item1);

                        var arr1 = val1 as Array;
                        if (arr1 != null)
                        {
                            var arr2 = (Array)val2;

                            var isString = arr1.GetType().GetElementType() == typeof(string);

                            for (var i = 0; i < field.Item2.Count; i++)
                            {
                                var value1 = i >= arr1.Length ? (isString ? (object)string.Empty : 0) : arr1.GetValue(i);
                                var value2 = i >= arr2.Length ? (isString ? (object)string.Empty : 0) : arr2.GetValue(i);

                                if (!Utilities.EqualValues(value1, value2))
                                {
                                    row.AddValue(field.Item2.Name + (field.Item2.StartAtZero ? i : i + 1), value1);
                                }
                            }

                            continue;
                        }

                        if ((val2 is Array) && val1 == null)
                        {
                            continue;
                        }

                        if (!Utilities.EqualValues(val1, val2))
                        {
                            row.AddValue(field.Item2.Name, val1);
                        }
                    }

                    var key = Convert.ToUInt32(elem1.Key);

                    row.AddWhere(primaryKeyName, key);
                    row.Comment = StoreGetters.GetName(storeType, (int)key, false);
                    row.Table   = tableName;

                    if (row.ValueCount == 0)
                    {
                        continue;
                    }

                    var lastField = fields[fields.Count - 1];
                    if (lastField.Item2.Name == "VerifiedBuild")
                    {
                        var buildvSniff = (int)lastField.Item1.GetValue(elem1.Value.Item1);
                        var buildvDB    = (int)lastField.Item1.GetValue(dict2[elem1.Key].Item1);

                        if (buildvDB > buildvSniff) // skip update if DB already has a VerifiedBuild higher than this one
                        {
                            continue;
                        }
                    }

                    rowsUpd.Add(row);
                }
                else // insert new
                {
                    var row = new QueryBuilder.SQLInsertRow();
                    row.AddValue(primaryKeyName, elem1.Key);
                    row.Comment = StoreGetters.GetName(storeType, Convert.ToInt32(elem1.Key), false);

                    foreach (var field in fields)
                    {
                        if (field.Item1.FieldType.BaseType == typeof(Array))
                        {
                            var arr = (Array)field.Item1.GetValue(elem1.Value.Item1);
                            if (arr == null)
                            {
                                continue;
                            }

                            for (var i = 0; i < arr.Length; i++)
                            {
                                row.AddValue(field.Item2.Name + (field.Item2.StartAtZero ? i : i + 1), arr.GetValue(i));
                            }

                            continue;
                        }

                        var val = field.Item1.GetValue(elem1.Value.Item1);
                        if (val == null && field.Item1.FieldType == typeof(string))
                        {
                            val = string.Empty;
                        }

                        row.AddValue(field.Item2.Name, val);
                    }
                    rowsIns.Add(row);
                }
            }

            var result = new QueryBuilder.SQLInsert(tableName, rowsIns, deleteDuplicates: false).Build() +
                         new QueryBuilder.SQLUpdate(rowsUpd).Build();

            return(result);
        }
Ejemplo n.º 30
0
        public static string StartInformation()
        {
            var result = String.Empty;

            if (!Storage.StartActions.IsEmpty())
            {
                var rows = new List <QueryBuilder.SQLInsertRow>();
                foreach (KeyValuePair <Tuple <Race, Class>, Tuple <StartAction, TimeSpan?> > startActions in Storage.StartActions)
                {
                    var comment = new QueryBuilder.SQLInsertRow();
                    comment.HeaderComment = startActions.Key.Item1 + " - " + startActions.Key.Item2;
                    rows.Add(comment);

                    foreach (var action in startActions.Value.Item1.Actions)
                    {
                        var row = new QueryBuilder.SQLInsertRow();

                        row.AddValue("race", startActions.Key.Item1);
                        row.AddValue("class", startActions.Key.Item2);
                        row.AddValue("button", action.Button);
                        row.AddValue("action", action.Id);
                        row.AddValue("type", action.Type);
                        if (action.Type == ActionButtonType.Spell)
                        {
                            row.Comment = StoreGetters.GetName(StoreNameType.Spell, (int)action.Id, false);
                        }
                        if (action.Type == ActionButtonType.Item)
                        {
                            row.Comment = StoreGetters.GetName(StoreNameType.Item, (int)action.Id, false);
                        }

                        rows.Add(row);
                    }
                }

                result = new QueryBuilder.SQLInsert("playercreateinfo_action", rows, 2).Build();
            }

            if (!Storage.StartPositions.IsEmpty())
            {
                var rows = new List <QueryBuilder.SQLInsertRow>();
                foreach (KeyValuePair <Tuple <Race, Class>, Tuple <StartPosition, TimeSpan?> > startPosition in Storage.StartPositions)
                {
                    var comment = new QueryBuilder.SQLInsertRow();
                    comment.HeaderComment = startPosition.Key.Item1 + " - " + startPosition.Key.Item2;
                    rows.Add(comment);

                    var row = new QueryBuilder.SQLInsertRow();

                    row.AddValue("race", startPosition.Key.Item1);
                    row.AddValue("class", startPosition.Key.Item2);
                    row.AddValue("map", startPosition.Value.Item1.Map);
                    row.AddValue("zone", startPosition.Value.Item1.Zone);
                    row.AddValue("position_x", startPosition.Value.Item1.Position.X);
                    row.AddValue("position_y", startPosition.Value.Item1.Position.Y);
                    row.AddValue("position_z", startPosition.Value.Item1.Position.Z);

                    row.Comment = StoreGetters.GetName(StoreNameType.Map, startPosition.Value.Item1.Map, false) + " - " +
                                  StoreGetters.GetName(StoreNameType.Zone, startPosition.Value.Item1.Zone, false);

                    rows.Add(row);
                }

                result += new QueryBuilder.SQLInsert("playercreateinfo", rows, 2).Build();
            }

            if (!Storage.StartSpells.IsEmpty())
            {
                var rows = new List <QueryBuilder.SQLInsertRow>();
                foreach (var startSpells in Storage.StartSpells)
                {
                    var comment = new QueryBuilder.SQLInsertRow();
                    comment.HeaderComment = startSpells.Key.Item1 + " - " + startSpells.Key.Item2;
                    rows.Add(comment);

                    foreach (var spell in startSpells.Value.Item1.Spells)
                    {
                        var row = new QueryBuilder.SQLInsertRow();

                        row.AddValue("race", startSpells.Key.Item1);
                        row.AddValue("class", startSpells.Key.Item2);
                        row.AddValue("Spell", spell);
                        row.AddValue("Note", StoreGetters.GetName(StoreNameType.Spell, (int)spell, false));

                        rows.Add(row);
                    }
                }

                result = new QueryBuilder.SQLInsert("playercreateinfo_spell", rows, 2).Build();
            }

            return(result);
        }