/// <summary>
        /// Calls the InvalidateSetting method to get the values.
        /// </summary>
        public static void InitializeValues()
        {
            manager = new GFS();
            string settingsDirectory = Application.StartupPath + @"\Settings\";

            if (!Directory.Exists(settingsDirectory))
            {
                Directory.CreateDirectory(settingsDirectory);
            }

            string SettingFile = settingsDirectory + "applicationSettings.set";

            manager.SettingsDirectory = SettingFile;

            UniversalUsername = InvalidateSetting(_Username, "");
            UniversalPassword = InvalidateSetting(_Password, "");
            BrowserEngine     = BrowserEngineFromString(InvalidateSetting(_BrowserEngine, _cefSharp));
            SearchEngine      = SearchEngineFromString(InvalidateSetting(_SearchEngine, _google));
            HistorySettings   = HistoryEngineFromString(InvalidateSetting(_HistoryEngine, _SyncAll));
            UserAgent         = UserAgentFromString(InvalidateSetting(_UserAgent, _default));
            BuildVersion      = BuildVersionFromString(InvalidateSetting(_BuildVersion, _Public));
            SyncHistory       = bool.Parse(InvalidateSetting(_SyncHistory, true.ToString()));
            SyncBookmarks     = bool.Parse(InvalidateSetting(_SyncBookmarks, true.ToString()));
            SyncInterval      = int.Parse(InvalidateSetting(_SyncInterval, 10000.ToString()));
        }
示例#2
0
            public static ChatPacket ParseChatPacket(string[] lines, long index, BuildVersions buildVersion)
            {
                ChatPacket chatPacket = new ChatPacket("", 0, "", LineGetters.GetTimeSpanFromLine(lines[index]));

                if (IsCreatureText(lines[index + 1]))
                {
                    do
                    {
                        if (LineGetters.GetGuidFromLine(lines[index], buildVersion, senderGuid: true) != "")
                        {
                            chatPacket.creatureGuid = LineGetters.GetGuidFromLine(lines[index], buildVersion, senderGuid: true);
                        }

                        if (GetTextFromLine(lines[index]) != "")
                        {
                            chatPacket.creatureText = GetTextFromLine(lines[index]);
                        }

                        index++;
                    }while (lines[index] != "");

                    chatPacket.creatureEntry = CreatureScriptsCreator.GetCreatureEntryByGuid(chatPacket.creatureGuid);
                }

                return(chatPacket);
            }
示例#3
0
        public static bool IsTxtFileValidForParse(string fileName, string[] lines, BuildVersions buildVersion)
        {
            if (lines[0] != "# TrinityCore - WowPacketParser")
            {
                MessageBox.Show(fileName + " is not a valid TrinityCore parsed sniff file.", "File Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                return(false);
            }

            if (buildVersion == BuildVersions.BUILD_UNKNOWN)
            {
                MessageBox.Show(fileName + " has non-supported build.", "File Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                return(false);
            }

            return(true);
        }
        /// <summary>
        /// Get a String from BuildVersion
        /// </summary>
        /// <param name="buildVersion">BuildVersion to convert</param>
        /// <returns>String refers to BuildVersion</returns>
        public static string BuildVersionToString(BuildVersions buildVersion)
        {
            switch (buildVersion)
            {
            case BuildVersions.Public:
                return(_Public);

            case BuildVersions.Beta:
                return(_Beta);

            case BuildVersions.Alpha:
                return(_Alpha);
            }

            //Returns the default one
            return(_Public);
        }
        public bool GetPacketsFromDataFile(string fileName)
        {
            mainForm.toolStripStatusLabel_FileStatus.Text = "Current status: Getting packets from data file...";

            BinaryFormatter           binaryFormatter   = new BinaryFormatter();
            Dictionary <uint, object> dictFromSerialize = new Dictionary <uint, object>();

            using (FileStream fileStream = new FileStream(fileName, FileMode.OpenOrCreate))
            {
                dictFromSerialize = (Dictionary <uint, object>)binaryFormatter.Deserialize(fileStream);
            }

            creaturesDict     = (Dictionary <string, Creature>)dictFromSerialize[0];
            creatureTextsDict = (Dictionary <uint, List <CreatureText> >)dictFromSerialize[1];
            buildVersion      = (BuildVersions)dictFromSerialize[2];

            return(true);
        }
示例#6
0
            public static EmotePacket ParseEmotePacket(string[] lines, long index, BuildVersions buildVersion)
            {
                EmotePacket emotePacket = new EmotePacket("", 0, LineGetters.GetTimeSpanFromLine(lines[index]));

                do
                {
                    if (GetGuidFromLine(lines[index]) != "")
                    {
                        emotePacket.guid = GetGuidFromLine(lines[index]);
                    }

                    if (GetEmoteIdFromLine(lines[index]) != 0)
                    {
                        emotePacket.emoteId = GetEmoteIdFromLine(lines[index]);
                    }

                    index++;
                }while (lines[index] != "");

                return(emotePacket);
            }
        public static string GetGuidFromLine(string line, BuildVersions buidVersion, bool objectFieldGuid = false, bool unitGuid = false, bool senderGuid = false, bool moverGuid = false, bool attackerGuid = false, bool casterGuid = false, bool updateAuraGuid = false)
        {
            if (!line.Contains("Creature/0") && !line.Contains("Vehicle/0"))
            {
                return("");
            }

            if (objectFieldGuid && buidVersion == BuildVersions.BUILD_8_0_1)
            {
                Regex guidRegex = new Regex(@"OBJECT_FIELD_GUID: Full:{1}\s*\w{20,}");
                if (guidRegex.IsMatch(line))
                {
                    return(guidRegex.Match(line).ToString().Replace("OBJECT_FIELD_GUID: Full: ", ""));
                }
            }
            else if (unitGuid)
            {
                Regex guidRegex = new Regex(@"UnitGUID: Full:{1}\s*\w{20,}");
                if (guidRegex.IsMatch(line))
                {
                    return(guidRegex.Match(line).ToString().Replace("UnitGUID: Full: ", ""));
                }
            }
            else if (senderGuid)
            {
                Regex guidRegex = new Regex(@"SenderGUID: Full:{1}\s*\w{20,}");
                if (guidRegex.IsMatch(line))
                {
                    return(guidRegex.Match(line).ToString().Replace("SenderGUID: Full: ", ""));
                }
            }
            else if (moverGuid)
            {
                Regex guidRegex = new Regex(@"MoverGUID: Full:{1}\s*\w{20,}");
                if (guidRegex.IsMatch(line))
                {
                    return(guidRegex.Match(line).ToString().Replace("MoverGUID: Full: ", ""));
                }
            }
            else if (attackerGuid)
            {
                Regex guidRegex = new Regex(@"Attacker Guid: Full:{1}\s*\w{20,}");
                if (guidRegex.IsMatch(line))
                {
                    return(guidRegex.Match(line).ToString().Replace("Attacker Guid: Full: ", ""));
                }
            }
            else if (casterGuid)
            {
                Regex guidRegex = new Regex(@"CasterGUID: Full:{1}\s*\w{20,}");
                if (guidRegex.IsMatch(line))
                {
                    return(guidRegex.Match(line).ToString().Replace("CasterGUID: Full: ", ""));
                }
            }
            else
            {
                Regex guidRegex       = new Regex(@"ObjectGuid: Full:{1}\s*\w{20,}");
                Regex guidRegexSecond = new Regex(@"Object GUID: Full:{1}\s*\w{20,}");
                if (guidRegex.IsMatch(line))
                {
                    return(guidRegex.Match(line).ToString().Replace("ObjectGuid: Full: ", ""));
                }
                if (guidRegexSecond.IsMatch(line))
                {
                    return(guidRegexSecond.Match(line).ToString().Replace("Object GUID: Full: ", ""));
                }
            }

            return("");
        }
示例#8
0
            public static AIReactionPacket ParseAIReactionPacket(string[] lines, long index, BuildVersions buildVersion)
            {
                AIReactionPacket reactionPacket = new AIReactionPacket("", 0, LineGetters.GetTimeSpanFromLine(lines[index]));

                do
                {
                    if (LineGetters.GetGuidFromLine(lines[index], buildVersion, unitGuid: true) != "")
                    {
                        reactionPacket.creatureGuid = LineGetters.GetGuidFromLine(lines[index], buildVersion, unitGuid: true);
                    }

                    index++;
                }while (lines[index] != "");

                reactionPacket.creatureEntry = CreatureScriptsCreator.GetCreatureEntryByGuid(reactionPacket.creatureGuid);

                return(reactionPacket);
            }
示例#9
0
            public static AttackStopPacket ParseAttackStopkPacket(string[] lines, long index, BuildVersions buildVersion)
            {
                AttackStopPacket attackPacket = new AttackStopPacket("", false, LineGetters.GetTimeSpanFromLine(lines[index]));

                if (LineGetters.IsCreatureLine(lines[index + 1]))
                {
                    do
                    {
                        if (LineGetters.GetGuidFromLine(lines[index], buildVersion, attackerGuid: true) != "")
                        {
                            attackPacket.creatureGuid = LineGetters.GetGuidFromLine(lines[index], buildVersion, attackerGuid: true);
                        }

                        if (GetNowDeadFromLine(lines[index]))
                        {
                            attackPacket.nowDead = GetNowDeadFromLine(lines[index]);
                        }

                        index++;
                    }while (lines[index] != "");
                }

                return(attackPacket);
            }
        public bool GetDataFromSniffFile(string fileName)
        {
            mainForm.SetCurrentStatus("Loading DBC...");

            DBC.DBC.Load();

            mainForm.SetCurrentStatus("Getting lines...");

            var lines = File.ReadAllLines(fileName);
            SortedDictionary <long, Packet> updateObjectPacketsDict = new SortedDictionary <long, Packet>();
            SortedDictionary <long, Packet> movementPacketsDict     = new SortedDictionary <long, Packet>();
            SortedDictionary <long, Packet> spellPacketsDict        = new SortedDictionary <long, Packet>();
            SortedDictionary <long, Packet> auraPacketsDict         = new SortedDictionary <long, Packet>();
            SortedDictionary <long, Packet> emotePacketsDict        = new SortedDictionary <long, Packet>();

            buildVersion = LineGetters.GetBuildVersion(lines);
            if (buildVersion == BuildVersions.BUILD_UNKNOWN)
            {
                MessageBox.Show(fileName + " has non-supported build.", "File Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                return(false);
            }

            mainForm.SetCurrentStatus("Searching for packet indexes in lines...");

            Parallel.For(0, lines.Length, index =>
            {
                if (Packet.GetPacketTypeFromLine(lines[index]) == Packet.PacketTypes.SMSG_UPDATE_OBJECT)
                {
                    TimeSpan sendTime = LineGetters.GetTimeSpanFromLine(lines[index]);
                    if (sendTime != TimeSpan.Zero)
                    {
                        lock (updateObjectPacketsDict)
                        {
                            if (!updateObjectPacketsDict.ContainsKey(index))
                            {
                                updateObjectPacketsDict.Add(index, new Packet(Packet.PacketTypes.SMSG_UPDATE_OBJECT, sendTime, index, new List <object>()));
                            }
                        }
                    }
                }
                else if (Packet.GetPacketTypeFromLine(lines[index]) == Packet.PacketTypes.SMSG_ON_MONSTER_MOVE)
                {
                    TimeSpan sendTime = LineGetters.GetTimeSpanFromLine(lines[index]);
                    if (sendTime != TimeSpan.Zero)
                    {
                        lock (movementPacketsDict)
                        {
                            if (!movementPacketsDict.ContainsKey(index))
                            {
                                movementPacketsDict.Add(index, new Packet(Packet.PacketTypes.SMSG_ON_MONSTER_MOVE, sendTime, index, new List <object>()));
                            }
                        }
                    }
                }
                else if (Properties.Settings.Default.Scripts && Packet.GetPacketTypeFromLine(lines[index]) == Packet.PacketTypes.SMSG_SPELL_START)
                {
                    TimeSpan sendTime = LineGetters.GetTimeSpanFromLine(lines[index]);
                    if (sendTime != TimeSpan.Zero)
                    {
                        lock (spellPacketsDict)
                        {
                            if (!spellPacketsDict.ContainsKey(index))
                            {
                                spellPacketsDict.Add(index, new Packet(Packet.PacketTypes.SMSG_SPELL_START, sendTime, index, new List <object>()));
                            }
                        }
                    }
                }
                else if (Properties.Settings.Default.Scripts && Packet.GetPacketTypeFromLine(lines[index]) == Packet.PacketTypes.SMSG_AURA_UPDATE)
                {
                    TimeSpan sendTime = LineGetters.GetTimeSpanFromLine(lines[index]);
                    if (sendTime != TimeSpan.Zero)
                    {
                        lock (auraPacketsDict)
                        {
                            if (!auraPacketsDict.ContainsKey(index))
                            {
                                auraPacketsDict.Add(index, new Packet(Packet.PacketTypes.SMSG_AURA_UPDATE, sendTime, index, new List <object>()));
                            }
                        }
                    }
                }
                else if (Properties.Settings.Default.Scripts && Packet.GetPacketTypeFromLine(lines[index]) == Packet.PacketTypes.SMSG_EMOTE)
                {
                    TimeSpan sendTime = LineGetters.GetTimeSpanFromLine(lines[index]);
                    if (sendTime != TimeSpan.Zero)
                    {
                        lock (emotePacketsDict)
                        {
                            if (!emotePacketsDict.ContainsKey(index))
                            {
                                emotePacketsDict.Add(index, new Packet(Packet.PacketTypes.SMSG_EMOTE, sendTime, index, new List <object>()));
                            }
                        }
                    }
                }
            });

            creaturesDict.Clear();

            mainForm.SetCurrentStatus("Parsing SMSG_UPDATE_OBJECT packets...");

            Parallel.ForEach(updateObjectPacketsDict.Values.AsEnumerable(), packet =>
            {
                Parallel.ForEach(UpdateObjectPacket.ParseObjectUpdatePacket(lines, packet.index, buildVersion).AsEnumerable(), updatePacket =>
                {
                    lock (updateObjectPacketsDict)
                    {
                        updateObjectPacketsDict.AddSourceFromUpdatePacket(updatePacket, packet.index);
                    }

                    lock (creaturesDict)
                    {
                        if (!creaturesDict.ContainsKey(updatePacket.creatureGuid))
                        {
                            creaturesDict.Add(updatePacket.creatureGuid, new Creature(updatePacket));
                        }
                        else
                        {
                            creaturesDict[updatePacket.creatureGuid].UpdateCreature(updatePacket);
                        }
                    }
                });
            });

            mainForm.SetCurrentStatus("Parsing SMSG_ON_MONSTER_MOVE packets...");

            Parallel.ForEach(movementPacketsDict.Values.AsEnumerable(), packet =>
            {
                MonsterMovePacket movePacket = MonsterMovePacket.ParseMovementPacket(lines, packet.index, buildVersion);
                if (movePacket.creatureGuid != "" && (movePacket.HasWaypoints() || movePacket.HasOrientation() || movePacket.HasJump()))
                {
                    lock (movementPacketsDict)
                    {
                        movementPacketsDict.AddSourceFromMovementPacket(movePacket, packet.index);
                    }

                    lock (creaturesDict)
                    {
                        if (creaturesDict.ContainsKey(movePacket.creatureGuid))
                        {
                            Creature creature = creaturesDict[movePacket.creatureGuid];

                            if (!creature.HasWaypoints() && movePacket.HasWaypoints())
                            {
                                creature.AddWaypointsFromMovementPacket(movePacket);
                            }
                            else if (creature.HasWaypoints() && movePacket.HasOrientation() && !movePacket.HasWaypoints())
                            {
                                creature.SortWaypoints();
                                creature.waypoints.Last().SetOrientation(movePacket.creatureOrientation);
                                creature.waypoints.Last().SetOrientationSetTime(movePacket.packetSendTime);
                            }
                            else if (creature.HasWaypoints() && movePacket.HasWaypoints())
                            {
                                if (creature.waypoints.Last().HasOrientation())
                                {
                                    creature.waypoints.Last().SetDelay((uint)((movePacket.packetSendTime - creature.waypoints.Last().orientationSetTime).TotalMilliseconds));
                                }

                                creature.AddWaypointsFromMovementPacket(movePacket);
                            }
                        }
                    }
                }
            });

            if (Properties.Settings.Default.Scripts)
            {
                mainForm.SetCurrentStatus("Parsing SMSG_SPELL_START packets...");

                Parallel.ForEach(spellPacketsDict.Values.AsEnumerable(), packet =>
                {
                    SpellStartPacket spellPacket = SpellStartPacket.ParseSpellStartPacket(lines, packet.index, buildVersion);
                    if (spellPacket.spellId == 0)
                    {
                        return;
                    }

                    lock (spellPacketsDict)
                    {
                        spellPacketsDict.AddSourceFromSpellPacket(spellPacket, packet.index);
                    }
                });

                mainForm.SetCurrentStatus("Parsing SMSG_AURA_UPDATE packets...");

                Parallel.ForEach(auraPacketsDict.Values.AsEnumerable(), packet =>
                {
                    Parallel.ForEach(AuraUpdatePacket.ParseAuraUpdatePacket(lines, packet.index, buildVersion).AsEnumerable(), auraPacket =>
                    {
                        lock (auraPacketsDict)
                        {
                            auraPacketsDict.AddSourceFromAuraUpdatePacket(auraPacket, packet.index);
                        }

                        lock (creaturesDict)
                        {
                            if (creaturesDict.ContainsKey(auraPacket.unitGuid))
                            {
                                Creature creature = creaturesDict[auraPacket.unitGuid];

                                creature.auras.Add(new Aura((uint)auraPacket.slot, (bool)auraPacket.HasAura, auraPacket.packetSendTime, auraPacket.spellId));
                            }
                        }
                    });
                });

                mainForm.SetCurrentStatus("Parsing SMSG_EMOTE packets...");

                Parallel.ForEach(emotePacketsDict.Values.AsEnumerable(), packet =>
                {
                    EmotePacket emotePacket = EmotePacket.ParseEmotePacket(lines, packet.index, buildVersion);
                    if (emotePacket.guid == "" || emotePacket.emoteId == 0)
                    {
                        return;
                    }

                    lock (emotePacketsDict)
                    {
                        emotePacketsDict.AddSourceFromEmotePacket(emotePacket, packet.index);
                    }
                });

                mainForm.SetCurrentStatus("Creating waypoint scripts for creatures...");

                Parallel.ForEach(creaturesDict.Values.AsEnumerable(), creature =>
                {
                    if (creature.HasWaypoints())
                    {
                        SortedDictionary <long, Packet> creaturePacketsDict = new SortedDictionary <long, Packet>();

                        foreach (var packet in updateObjectPacketsDict.Values.Where(packet => packet.HasCreatureWithGuid(creature.guid)))
                        {
                            creaturePacketsDict.Add(packet.index, packet);
                        }

                        foreach (var packet in movementPacketsDict.Values.Where(packet => packet.HasCreatureWithGuid(creature.guid)))
                        {
                            creaturePacketsDict.Add(packet.index, packet);
                        }

                        foreach (var packet in spellPacketsDict.Values.Where(packet => packet.HasCreatureWithGuid(creature.guid)))
                        {
                            creaturePacketsDict.Add(packet.index, packet);
                        }

                        foreach (var packet in auraPacketsDict.Values.Where(packet => packet.HasCreatureWithGuid(creature.guid)))
                        {
                            creaturePacketsDict.Add(packet.index, packet);
                        }

                        foreach (var packet in emotePacketsDict.Values.Where(packet => packet.HasCreatureWithGuid(creature.guid)))
                        {
                            creaturePacketsDict.Add(packet.index, packet);
                        }

                        List <WaypointScript> scriptsList = new List <WaypointScript>();
                        MonsterMovePacket startMovePacket = new MonsterMovePacket();
                        bool scriptsParsingStarted        = false;

                        foreach (Packet packet in creaturePacketsDict.Values)
                        {
                            switch (packet.packetType)
                            {
                            case Packet.PacketTypes.SMSG_ON_MONSTER_MOVE:
                                {
                                    MonsterMovePacket movePacket = (MonsterMovePacket)packet.parsedPacketsList.First();
                                    if (movePacket.HasWaypoints() && !scriptsParsingStarted)
                                    {
                                        startMovePacket       = movePacket;
                                        scriptsParsingStarted = true;
                                    }
                                    else if (movePacket.HasWaypoints() && scriptsParsingStarted)
                                    {
                                        if (scriptsList.Count != 0)
                                        {
                                            creature.AddScriptsForWaypoints(scriptsList, startMovePacket, movePacket);
                                            scriptsList.Clear();
                                        }

                                        startMovePacket = movePacket;
                                    }
                                    else if ((movePacket.HasOrientation() || movePacket.HasJump()) && scriptsParsingStarted)
                                    {
                                        scriptsList.Add(WaypointScript.GetScriptsFromMovementPacket(movePacket));
                                    }

                                    break;
                                }

                            case Packet.PacketTypes.SMSG_UPDATE_OBJECT:
                                {
                                    if (scriptsParsingStarted && packet.parsedPacketsList.Count != 0)
                                    {
                                        if (packet.parsedPacketsList.GetUpdatePacketForCreatureWithGuid(creature.guid) != null)
                                        {
                                            UpdateObjectPacket updatePacket = (UpdateObjectPacket)packet.parsedPacketsList.GetUpdatePacketForCreatureWithGuid(creature.guid);

                                            List <WaypointScript> updateScriptsList = WaypointScript.GetScriptsFromUpdatePacket(updatePacket);
                                            if (updateScriptsList.Count != 0)
                                            {
                                                scriptsList.AddRange(updateScriptsList);
                                            }
                                        }
                                    }

                                    break;
                                }

                            case Packet.PacketTypes.SMSG_SPELL_START:
                                {
                                    if (scriptsParsingStarted)
                                    {
                                        SpellStartPacket spellPacket = (SpellStartPacket)packet.parsedPacketsList.First();
                                        scriptsList.Add(WaypointScript.GetScriptsFromSpellPacket(spellPacket));
                                    }

                                    break;
                                }

                            case Packet.PacketTypes.SMSG_AURA_UPDATE:
                                {
                                    if (scriptsParsingStarted)
                                    {
                                        AuraUpdatePacket auraPacket = (AuraUpdatePacket)packet.parsedPacketsList.First();
                                        if (auraPacket.HasAura == false)
                                        {
                                            scriptsList.Add(WaypointScript.GetScriptsFromAuraUpdatePacket(auraPacket, creature));
                                        }
                                    }

                                    break;
                                }

                            case Packet.PacketTypes.SMSG_EMOTE:
                                {
                                    if (scriptsParsingStarted)
                                    {
                                        EmotePacket emotePacket = (EmotePacket)packet.parsedPacketsList.First();
                                        scriptsList.Add(WaypointScript.GetScriptsFromEmotePacket(emotePacket));
                                    }

                                    break;
                                }
                            }
                        }
                    }
                });
            }

            mainForm.SetCurrentStatus("");
            return(true);
        }
        public bool GetDataFromSniffFile(string fileName)
        {
            mainForm.SetCurrentStatus("Loading DBC...");

            DBC.DBC.Load();

            mainForm.SetCurrentStatus("Getting lines...");

            var lines = File.ReadAllLines(fileName);
            Dictionary <long, Packet.PacketTypes> packetIndexes = new Dictionary <long, Packet.PacketTypes>();

            buildVersion = LineGetters.GetBuildVersion(lines);
            if (buildVersion == BuildVersions.BUILD_UNKNOWN)
            {
                MessageBox.Show(fileName + " has non-supported build.", "File Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                return(false);
            }

            creaturesDict.Clear();

            mainForm.SetCurrentStatus("Searching for packet indexes in lines...");

            Parallel.For(0, lines.Length, index =>
            {
                if (lines[index].Contains("SMSG_UPDATE_OBJECT") && !packetIndexes.ContainsKey(index))
                {
                    lock (packetIndexes)
                        packetIndexes.Add(index, Packet.PacketTypes.SMSG_UPDATE_OBJECT);
                }
                else if (lines[index].Contains("SMSG_AI_REACTION") && !packetIndexes.ContainsKey(index))
                {
                    lock (packetIndexes)
                        packetIndexes.Add(index, Packet.PacketTypes.SMSG_AI_REACTION);
                }
                else if (lines[index].Contains("SMSG_SPELL_START") && !packetIndexes.ContainsKey(index))
                {
                    lock (packetIndexes)
                        packetIndexes.Add(index, Packet.PacketTypes.SMSG_SPELL_START);
                }
                else if (lines[index].Contains("SMSG_CHAT") && !packetIndexes.ContainsKey(index))
                {
                    lock (packetIndexes)
                        packetIndexes.Add(index, Packet.PacketTypes.SMSG_CHAT);
                }
                else if (lines[index].Contains("SMSG_ON_MONSTER_MOVE") && !packetIndexes.ContainsKey(index))
                {
                    lock (packetIndexes)
                        packetIndexes.Add(index, Packet.PacketTypes.SMSG_ON_MONSTER_MOVE);
                }
                else if (lines[index].Contains("SMSG_ATTACK_STOP") && !packetIndexes.ContainsKey(index))
                {
                    lock (packetIndexes)
                        packetIndexes.Add(index, Packet.PacketTypes.SMSG_ATTACK_STOP);
                }
            });

            mainForm.SetCurrentStatus("Parsing SMSG_UPDATE_OBJECT packets...");

            Parallel.ForEach(packetIndexes.AsEnumerable(), value =>
            {
                if (value.Value == Packet.PacketTypes.SMSG_UPDATE_OBJECT)
                {
                    Parallel.ForEach(UpdateObjectPacket.ParseObjectUpdatePacket(lines, value.Key, buildVersion).AsEnumerable(), packet =>
                    {
                        lock (creaturesDict)
                        {
                            if (!creaturesDict.ContainsKey(packet.creatureGuid))
                            {
                                creaturesDict.Add(packet.creatureGuid, new Creature(packet));
                            }
                            else
                            {
                                creaturesDict[packet.creatureGuid].UpdateCreature(packet);
                            }
                        }
                    });
                }
            });

            mainForm.SetCurrentStatus("Parsing SMSG_SPELL_START packets...");

            Parallel.ForEach(packetIndexes.AsEnumerable(), value =>
            {
                if (value.Value == Packet.PacketTypes.SMSG_SPELL_START)
                {
                    SpellStartPacket spellPacket = SpellStartPacket.ParseSpellStartPacket(lines, value.Key, buildVersion);
                    if (spellPacket.spellId == 0)
                    {
                        return;
                    }

                    lock (creaturesDict)
                    {
                        if (creaturesDict.ContainsKey(spellPacket.casterGuid))
                        {
                            if (!creaturesDict[spellPacket.casterGuid].castedSpells.ContainsKey(spellPacket.spellId))
                            {
                                creaturesDict[spellPacket.casterGuid].castedSpells.Add(spellPacket.spellId, new Spell(spellPacket));
                            }
                            else
                            {
                                creaturesDict[spellPacket.casterGuid].UpdateSpells(spellPacket);
                            }
                        }
                    }
                }
            });

            mainForm.SetCurrentStatus("Parsing SMSG_AI_REACTION packets...");

            Parallel.ForEach(packetIndexes.AsEnumerable(), value =>
            {
                if (value.Value == Packet.PacketTypes.SMSG_AI_REACTION)
                {
                    AIReactionPacket reactionPacket = AIReactionPacket.ParseAIReactionPacket(lines, value.Key, buildVersion);
                    if (reactionPacket.creatureGuid == "")
                    {
                        return;
                    }

                    lock (creaturesDict)
                    {
                        if (creaturesDict.ContainsKey(reactionPacket.creatureGuid))
                        {
                            if (creaturesDict[reactionPacket.creatureGuid].combatStartTime == TimeSpan.Zero ||
                                creaturesDict[reactionPacket.creatureGuid].combatStartTime < reactionPacket.packetSendTime)
                            {
                                creaturesDict[reactionPacket.creatureGuid].combatStartTime = reactionPacket.packetSendTime;
                            }

                            creaturesDict[reactionPacket.creatureGuid].UpdateCombatSpells(reactionPacket);
                        }
                    }
                }
            });

            mainForm.SetCurrentStatus("Parsing SMSG_CHAT packets...");

            Parallel.ForEach(packetIndexes.AsEnumerable(), value =>
            {
                if (value.Value == Packet.PacketTypes.SMSG_CHAT)
                {
                    ChatPacket chatPacket = ChatPacket.ParseChatPacket(lines, value.Key, buildVersion);
                    if (chatPacket.creatureGuid == "")
                    {
                        return;
                    }

                    lock (creaturesDict)
                    {
                        Parallel.ForEach(creaturesDict, creature =>
                        {
                            if (creature.Value.entry == chatPacket.creatureEntry)
                            {
                                if (Math.Floor(creature.Value.combatStartTime.TotalSeconds) == Math.Floor(chatPacket.packetSendTime.TotalSeconds) ||
                                    Math.Floor(creature.Value.combatStartTime.TotalSeconds) == Math.Floor(chatPacket.packetSendTime.TotalSeconds) + 1 ||
                                    Math.Floor(creature.Value.combatStartTime.TotalSeconds) == Math.Floor(chatPacket.packetSendTime.TotalSeconds) - 1)
                                {
                                    if (creatureTextsDict.ContainsKey(chatPacket.creatureEntry))
                                    {
                                        if (!IsCreatureHasAggroText(chatPacket.creatureEntry))
                                        {
                                            lock (creatureTextsDict)
                                            {
                                                creatureTextsDict[chatPacket.creatureEntry].Add(new CreatureText(chatPacket, true));
                                            }
                                        }
                                    }
                                    else
                                    {
                                        lock (creatureTextsDict)
                                        {
                                            creatureTextsDict.Add(chatPacket.creatureEntry, new List <CreatureText>());
                                            creatureTextsDict[chatPacket.creatureEntry].Add(new CreatureText(chatPacket, true));
                                        }
                                    }
                                }

                                if (Math.Floor(creature.Value.deathTime.TotalSeconds) == Math.Floor(chatPacket.packetSendTime.TotalSeconds) ||
                                    Math.Floor(creature.Value.deathTime.TotalSeconds) == Math.Floor(chatPacket.packetSendTime.TotalSeconds) + 1 ||
                                    Math.Floor(creature.Value.deathTime.TotalSeconds) == Math.Floor(chatPacket.packetSendTime.TotalSeconds) - 1)
                                {
                                    if (creatureTextsDict.ContainsKey(chatPacket.creatureEntry))
                                    {
                                        if (!IsCreatureHasDeathText(chatPacket.creatureEntry))
                                        {
                                            lock (creatureTextsDict)
                                            {
                                                creatureTextsDict[chatPacket.creatureEntry].Add(new CreatureText(chatPacket, false, true));
                                            }
                                        }
                                    }
                                    else
                                    {
                                        lock (creatureTextsDict)
                                        {
                                            creatureTextsDict.Add(chatPacket.creatureEntry, new List <CreatureText>());
                                            creatureTextsDict[chatPacket.creatureEntry].Add(new CreatureText(chatPacket, false, true));
                                        }
                                    }
                                }
                            }
                        });
                    }
                }
            });

            mainForm.SetCurrentStatus("Parsing SMSG_ON_MONSTER_MOVE and SMSG_ATTACK_STOP packets...");

            Parallel.ForEach(packetIndexes.AsEnumerable(), value =>
            {
                switch (value.Value)
                {
                case Packet.PacketTypes.SMSG_ON_MONSTER_MOVE:
                    {
                        MonsterMovePacket movePacket = MonsterMovePacket.ParseMovementPacket(lines, value.Key, buildVersion);
                        if (movePacket.creatureGuid == "")
                        {
                            return;
                        }

                        lock (creaturesDict)
                        {
                            if (creaturesDict.ContainsKey(movePacket.creatureGuid))
                            {
                                creaturesDict[movePacket.creatureGuid].UpdateSpellsByMovementPacket(movePacket);
                            }
                        }

                        break;
                    }

                case Packet.PacketTypes.SMSG_ATTACK_STOP:
                    {
                        AttackStopPacket attackStopPacket = AttackStopPacket.ParseAttackStopkPacket(lines, value.Key, buildVersion);
                        if (attackStopPacket.creatureGuid == "")
                        {
                            return;
                        }

                        lock (creaturesDict)
                        {
                            if (creaturesDict.ContainsKey(attackStopPacket.creatureGuid))
                            {
                                creaturesDict[attackStopPacket.creatureGuid].UpdateSpellsByAttackStopPacket(attackStopPacket);

                                if (attackStopPacket.nowDead)
                                {
                                    creaturesDict[attackStopPacket.creatureGuid].deathTime = attackStopPacket.packetSendTime;
                                }
                            }
                        }

                        break;
                    }
                }
            });

            Parallel.ForEach(creaturesDict, creature =>
            {
                creature.Value.RemoveNonCombatCastTimes();
            });

            Parallel.ForEach(creaturesDict, creature =>
            {
                creature.Value.CreateCombatCastTimings();
            });

            Parallel.ForEach(creaturesDict, creature =>
            {
                creature.Value.CreateDeathSpells();
            });

            mainForm.SetCurrentStatus("");
            return(true);
        }
示例#12
0
            public static SpellStartPacket ParseSpellStartPacket(string[] lines, long index, BuildVersions buildVersion)
            {
                SpellStartPacket spellPacket = new SpellStartPacket("", 0, new TimeSpan(), LineGetters.GetTimeSpanFromLine(lines[index]), new Position());

                if (IsCreatureSpellCastLine(lines[index + 1]))
                {
                    do
                    {
                        if (LineGetters.GetGuidFromLine(lines[index], buildVersion, casterGuid: true) != "")
                        {
                            spellPacket.casterGuid = LineGetters.GetGuidFromLine(lines[index], buildVersion, casterGuid: true);
                        }

                        if (GetSpellIdFromLine(lines[index]) != 0)
                        {
                            spellPacket.spellId = GetSpellIdFromLine(lines[index]);
                        }

                        if (GetCastTimeFromLine(lines[index]) != TimeSpan.Zero)
                        {
                            spellPacket.spellCastTime = GetCastTimeFromLine(lines[index]);
                        }

                        if (GetSpellDestinationFromLine(lines[index]).IsValid())
                        {
                            spellPacket.spellDestination = GetSpellDestinationFromLine(lines[index]);
                        }

                        index++;
                    }while (lines[index] != "");
                }

                return(spellPacket);
            }
示例#13
0
            public static IEnumerable <AuraUpdatePacket> ParseAuraUpdatePacket(string[] lines, long index, BuildVersions buildVersion)
            {
                TimeSpan packetSendTime           = LineGetters.GetTimeSpanFromLine(lines[index]);
                List <AuraUpdatePacket> aurasList = new List <AuraUpdatePacket>();

                do
                {
                    if (lines[index].Contains("Slot:"))
                    {
                        AuraUpdatePacket auraUpdatePacket = new AuraUpdatePacket("", null, 0, null, packetSendTime);

                        do
                        {
                            if (GetAuraSlotFromLine(lines[index]) != null)
                            {
                                auraUpdatePacket.slot = GetAuraSlotFromLine(lines[index]);
                            }

                            if (GetHasAuraFromLine(lines[index]) != null)
                            {
                                auraUpdatePacket.HasAura = GetHasAuraFromLine(lines[index]);
                            }

                            if (SpellStartPacket.GetSpellIdFromLine(lines[index]) != 0)
                            {
                                auraUpdatePacket.spellId = SpellStartPacket.GetSpellIdFromLine(lines[index]);
                            }

                            if (LineGetters.GetGuidFromLine(lines[index], buildVersion, unitGuid: true) != "")
                            {
                                auraUpdatePacket.unitGuid = LineGetters.GetGuidFromLine(lines[index], buildVersion, unitGuid: true);
                            }

                            index++;
                        }while (IsLineValidForAuraUpdateParsing(lines[index]));

                        if (!auraUpdatePacket.IsValid())
                        {
                            continue;
                        }

                        aurasList.Add(auraUpdatePacket);

                        index--;
                    }

                    index++;
                }while (lines[index] != "");

                return(aurasList);
            }
示例#14
0
            public static string GetUnitGuidFromAuraUpdatePacket(string[] lines, long index, BuildVersions build)
            {
                do
                {
                    if (LineGetters.GetGuidFromLine(lines[index], build, unitGuid: true) != "")
                    {
                        return(LineGetters.GetGuidFromLine(lines[index], build, unitGuid: true));
                    }

                    index++;
                }while (lines[index] != "");

                return("");
            }
        public static string ParsePlayerCastedSpells(string fileName, string playerGuid)
        {
            if (!DBC.DBC.IsLoaded())
            {
                DBC.DBC.Load();
            }

            var lines = File.ReadAllLines(fileName);

            string outputLine = "";
            Dictionary <long, Packet.PacketTypes> packetIndexes = new Dictionary <long, Packet.PacketTypes>();
            List <SpellStartPacket> spellsList        = new List <SpellStartPacket>();
            Dictionary <uint, uint> spellsCastedCount = new Dictionary <uint, uint>();

            BuildVersions buildVersion = LineGetters.GetBuildVersion(lines);

            if (buildVersion == BuildVersions.BUILD_UNKNOWN)
            {
                MessageBox.Show(fileName + " has non-supported build.", "File Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                return("");
            }

            Parallel.For(0, lines.Length, index =>
            {
                if (lines[index].Contains("SMSG_SPELL_START") && !packetIndexes.ContainsKey(index))
                {
                    lock (packetIndexes)
                        packetIndexes.Add(index, Packet.PacketTypes.SMSG_SPELL_START);
                }
                else if (lines[index].Contains("SMSG_SPELL_GO") && !packetIndexes.ContainsKey(index))
                {
                    lock (packetIndexes)
                        packetIndexes.Add(index, Packet.PacketTypes.SMSG_SPELL_GO);
                }
            });

            Parallel.ForEach(packetIndexes.AsEnumerable(), value =>
            {
                if (value.Value == Packet.PacketTypes.SMSG_SPELL_START || value.Value == Packet.PacketTypes.SMSG_SPELL_GO)
                {
                    SpellStartPacket spellPacket = SpellStartPacket.ParseSpellStartPacket(lines, value.Key, buildVersion, true);
                    if (spellPacket.spellId == 0 || spellPacket.casterGuid != playerGuid)
                    {
                        return;
                    }

                    lock (spellsList)
                    {
                        int spellIndex = spellsList.FindIndex(x => x.spellId == spellPacket.spellId);

                        if (spellIndex == -1)
                        {
                            spellsList.Add(spellPacket);
                            spellsCastedCount.Add(spellPacket.spellId, 1);
                        }
                        else
                        {
                            if (spellsList[spellIndex].spellCastStartTime > spellPacket.spellCastStartTime)
                            {
                                spellsList.RemoveAt(spellIndex);
                                spellsList.Add(spellPacket);
                            }

                            spellsCastedCount[spellPacket.spellId] += 1;
                        }
                    }
                }
            });

            spellsList = spellsList.OrderBy(x => x.spellCastStartTime).ToList();

            outputLine += "Spells casted by player with guid \"" + playerGuid + "\"" + "\r\n";

            foreach (SpellStartPacket spell in spellsList)
            {
                outputLine += "Spell Id: " + spell.spellId + " (" + Spell.GetSpellName(spell.spellId) + "), Cast Time: " + spell.spellCastStartTime.ToFormattedStringWithMilliseconds() + ", Casted times: " + spellsCastedCount[spell.spellId] + "\r\n";
            }

            return(outputLine);
        }
示例#16
0
        public static void ParseSpellDestinations(string fileName, string spellId)
        {
            var lines = File.ReadAllLines(fileName);

            string outputLine = "";
            Dictionary <long, Packet.PacketTypes> packetIndexes = new Dictionary <long, Packet.PacketTypes>();
            List <Position> allDestPositions  = new List <Position>();
            List <Position> uniqDestPositions = new List <Position>();

            BuildVersions buildVersion = LineGetters.GetBuildVersion(lines);

            if (buildVersion == BuildVersions.BUILD_UNKNOWN)
            {
                MessageBox.Show(fileName + " has non-supported build.", "File Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                return;
            }

            Parallel.For(0, lines.Length, index =>
            {
                if (lines[index].Contains("SMSG_SPELL_START") && !packetIndexes.ContainsKey(index))
                {
                    lock (packetIndexes)
                        packetIndexes.Add(index, Packet.PacketTypes.SMSG_SPELL_START);
                }
                else if (lines[index].Contains("SMSG_SPELL_GO") && !packetIndexes.ContainsKey(index))
                {
                    lock (packetIndexes)
                        packetIndexes.Add(index, Packet.PacketTypes.SMSG_SPELL_GO);
                }
            });

            Parallel.ForEach(packetIndexes.AsEnumerable(), value =>
            {
                if (value.Value == Packet.PacketTypes.SMSG_SPELL_START || value.Value == Packet.PacketTypes.SMSG_SPELL_GO)
                {
                    SpellStartPacket spellPacket = SpellStartPacket.ParseSpellStartPacket(lines, value.Key, buildVersion);
                    if (spellPacket.spellId == 0 || spellPacket.spellId != Convert.ToUInt32(spellId))
                    {
                        return;
                    }

                    if (spellPacket.spellDestination.IsValid())
                    {
                        lock (allDestPositions)
                            allDestPositions.Add(spellPacket.spellDestination);

                        if (!uniqDestPositions.Contains(spellPacket.spellDestination))
                        {
                            lock (uniqDestPositions)
                                uniqDestPositions.Add(spellPacket.spellDestination);
                        }
                    }
                }
            });

            outputLine += "Spell destinations for spell " + spellId + "\n\n";

            outputLine += "All positions count " + allDestPositions.Count + "\n";

            foreach (Position pos in allDestPositions)
            {
                outputLine += "{ " + pos.x.ToString().Replace(",", ".") + "f, " + pos.y.ToString().Replace(",", ".") + "f, " + pos.z.ToString().Replace(",", ".") + "f },\n";
            }

            outputLine += "Unique positions count " + allDestPositions.Count + "\n";

            foreach (Position pos in uniqDestPositions)
            {
                outputLine += "{ " + pos.x.ToString().Replace(",", ".") + "f, " + pos.y.ToString().Replace(",", ".") + "f, " + pos.z.ToString().Replace(",", ".") + "f },\n";
            }

            Clipboard.SetText(outputLine);
            MessageBox.Show("Spell destinations has been successfully parsed and copied on your clipboard!");
        }
示例#17
0
        public static string GetGuidFromLine(string line, BuildVersions buidVersion, bool objectFieldGuid = false, bool unitGuid = false, bool senderGuid = false, bool moverGuid = false, bool attackerGuid = false, bool casterGuid = false, bool casterUnit = false, bool transportGuid = false, bool conversationActorGuid = false)
        {
            if (!line.Contains("TypeName: Creature; Full:") && !line.Contains("TypeName: Vehicle; Full:") && !line.Contains("TypeName: Player; Full:") && !line.Contains("TypeName: Transport; Full:"))
            {
                return("");
            }

            Regex objectTypeRegex = new Regex(@"[a-zA-Z]+;{1}\s{1}Full:{1}\s");

            if (objectFieldGuid && buidVersion == BuildVersions.BUILD_8_0_1)
            {
                Regex guidRegex = new Regex(@"OBJECT_FIELD_GUID: Full:{1}\s{1}[a-zA-Z]+;{1}\s{1}\w{20,}");
                if (guidRegex.IsMatch(line))
                {
                    return(guidRegex.Match(line).ToString().Replace("OBJECT_FIELD_GUID: ", "").Replace(objectTypeRegex.Match(line).ToString(), ""));
                }
            }
            else if (unitGuid)
            {
                Regex guidRegex = new Regex(@"UnitGUID: TypeName:{1}\s{1}[a-zA-Z]+;{1}\s{1}Full:{1}\s{1}\w{20,}");
                if (guidRegex.IsMatch(line))
                {
                    return(guidRegex.Match(line).ToString().Replace("UnitGUID: TypeName: ", "").Replace(objectTypeRegex.Match(line).ToString(), ""));
                }
            }
            else if (senderGuid)
            {
                Regex guidRegex = new Regex(@"SenderGUID: TypeName:{1}\s{1}[a-zA-Z]+;{1}\s{1}Full:{1}\s{1}\w{20,}");
                if (guidRegex.IsMatch(line))
                {
                    return(guidRegex.Match(line).ToString().Replace("SenderGUID: TypeName: ", "").Replace(objectTypeRegex.Match(line).ToString(), ""));
                }
            }
            else if (moverGuid)
            {
                Regex guidRegex = new Regex(@"MoverGUID: TypeName:{1}\s{1}[a-zA-Z]+;{1}\s{1}Full:{1}\s{1}\w{20,}");
                if (guidRegex.IsMatch(line))
                {
                    return(guidRegex.Match(line).ToString().Replace("MoverGUID: TypeName: ", "").Replace(objectTypeRegex.Match(line).ToString(), ""));
                }
            }
            else if (attackerGuid)
            {
                Regex guidRegex = new Regex(@"Attacker Guid: TypeName:{1}\s{1}[a-zA-Z]+;{1}\s{1}Full:{1}\s{1}\w{20,}");
                if (guidRegex.IsMatch(line))
                {
                    return(guidRegex.Match(line).ToString().Replace("Attacker Guid: TypeName: ", "").Replace(objectTypeRegex.Match(line).ToString(), ""));
                }
            }
            else if (casterGuid)
            {
                Regex guidRegex = new Regex(@"CasterGUID: TypeName:{1}\s{1}[a-zA-Z]+;{1}\s{1}Full:{1}\s{1}\w{20,}");
                if (guidRegex.IsMatch(line))
                {
                    return(guidRegex.Match(line).ToString().Replace("CasterGUID: TypeName: ", "").Replace(objectTypeRegex.Match(line).ToString(), ""));
                }
            }
            else if (casterUnit)
            {
                Regex guidRegex = new Regex(@"CasterUnit: TypeName:{1}\s{1}[a-zA-Z]+;{1}\s{1}Full:{1}\s{1}\w{20,}");
                if (guidRegex.IsMatch(line))
                {
                    return(guidRegex.Match(line).ToString().Replace("CasterUnit: TypeName: ", "").Replace(objectTypeRegex.Match(line).ToString(), ""));
                }
            }
            else if (transportGuid)
            {
                Regex guidRegex = new Regex(@"TransportGUID: TypeName:{1}\s{1}[a-zA-Z]+;{1}\s{1}Full:{1}\s{1}\w{20,}");
                if (guidRegex.IsMatch(line))
                {
                    return(guidRegex.Match(line).ToString().Replace("TransportGUID: TypeName: ", "").Replace(objectTypeRegex.Match(line).ToString(), ""));
                }
            }
            else if (conversationActorGuid)
            {
                Regex guidRegex = new Regex(@"ActorGUID: TypeName:{1}\s{1}[a-zA-Z]+;{1}\s{1}Full:{1}\s{1}\w{20,}");
                if (guidRegex.IsMatch(line))
                {
                    return(guidRegex.Match(line).ToString().Replace("ActorGUID: TypeName: ", "").Replace(objectTypeRegex.Match(line).ToString(), ""));
                }
            }
            else
            {
                Regex guidRegex = new Regex(@"ObjectGuid: TypeName:{1}\s{1}[a-zA-Z]+;{1}\s{1}Full:{1}\s{1}\w{20,}");
                if (guidRegex.IsMatch(line))
                {
                    return(guidRegex.Match(line).ToString().Replace("ObjectGuid: TypeName: ", "").Replace(objectTypeRegex.Match(line).ToString(), ""));
                }
            }

            return("");
        }
示例#18
0
            public static List <string> GetGuidsFromUpdatePacket(string[] lines, long index, BuildVersions build)
            {
                List <string> guidsList = new List <string>();

                do
                {
                    string guid = LineGetters.GetGuidFromLine(lines[index], build);
                    if (guid != "")
                    {
                        if (!guidsList.Contains(guid))
                        {
                            guidsList.Add(guid);
                        }
                    }

                    index++;
                }while (lines[index] != "");

                return(guidsList);
            }
示例#19
0
        public static string ParsePlayerCastedSpells(string fileName, string playerGuid)
        {
            if (!DBC.DBC.IsLoaded())
            {
                DBC.DBC.Load();
            }

            var lines = File.ReadAllLines(fileName);

            string outputLine = "";
            Dictionary <long, Packet.PacketTypes> packetIndexes    = new Dictionary <long, Packet.PacketTypes>();
            Dictionary <uint, TimeSpan>           spellsDictionary = new Dictionary <uint, TimeSpan>();

            BuildVersions buildVersion = LineGetters.GetBuildVersion(lines);

            if (buildVersion == BuildVersions.BUILD_UNKNOWN)
            {
                MessageBox.Show(fileName + " has non-supported build.", "File Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                return("");
            }

            Parallel.For(0, lines.Length, index =>
            {
                if (lines[index].Contains("SMSG_SPELL_START") && !packetIndexes.ContainsKey(index))
                {
                    lock (packetIndexes)
                        packetIndexes.Add(index, Packet.PacketTypes.SMSG_SPELL_START);
                }
                else if (lines[index].Contains("SMSG_SPELL_GO") && !packetIndexes.ContainsKey(index))
                {
                    lock (packetIndexes)
                        packetIndexes.Add(index, Packet.PacketTypes.SMSG_SPELL_GO);
                }
            });

            Parallel.ForEach(packetIndexes.AsEnumerable(), value =>
            {
                if (value.Value == Packet.PacketTypes.SMSG_SPELL_START || value.Value == Packet.PacketTypes.SMSG_SPELL_GO)
                {
                    SpellStartPacket spellPacket = SpellStartPacket.ParseSpellStartPacket(lines, value.Key, buildVersion, true);
                    if (spellPacket.spellId == 0 || spellPacket.casterGuid != playerGuid)
                    {
                        return;
                    }

                    lock (spellsDictionary)
                    {
                        if (!spellsDictionary.ContainsKey(spellPacket.spellId))
                        {
                            spellsDictionary.Add(spellPacket.spellId, spellPacket.spellCastStartTime);
                        }
                    }
                }
            });

            spellsDictionary = spellsDictionary.OrderBy(x => x.Value).ToDictionary(x => x.Key, x => x.Value);

            outputLine += "Spells casted by player with guid \"" + playerGuid + "\"" + "\r\n";

            foreach (var spell in spellsDictionary)
            {
                outputLine += "Spell Id: " + spell.Key + " (" + Spell.GetSpellName(spell.Key) + "), Cast Time: " + spell.Value.ToString() + "\r\n";
            }

            return(outputLine);
        }
示例#20
0
            public static IEnumerable <UpdateObjectPacket> ParseObjectUpdatePacket(string[] lines, long index, BuildVersions buildVersion)
            {
                TimeSpan packetSendTime = LineGetters.GetTimeSpanFromLine(lines[index]);
                List <UpdateObjectPacket> updatePacketsList = new List <UpdateObjectPacket>();

                do
                {
                    if ((lines[index].Contains("UpdateType: CreateObject1") || lines[index].Contains("UpdateType: CreateObject2")) && LineGetters.IsCreatureLine(lines[index + 1]))
                    {
                        UpdateObjectPacket updatePacket = new UpdateObjectPacket(0, "", "Unknown", -1, 0, packetSendTime, new Position(), null, new List <Waypoint>(), null, null, null, false);

                        do
                        {
                            if (MonsterMovePacket.GetPointPositionFromLine(lines[index]).IsValid())
                            {
                                uint pointId = 1;

                                do
                                {
                                    updatePacket.waypoints.Add(new Waypoint(MonsterMovePacket.GetPointPositionFromLine(lines[index]), 0.0f, 0, new Position(), 0, packetSendTime, new TimeSpan(), new List <WaypointScript>(), pointId));
                                    pointId++;
                                    index++;
                                }while (lines[index].Contains("Points:"));
                            }

                            if (GetMapIdFromLine(lines[index]) != null)
                            {
                                updatePacket.mapId = GetMapIdFromLine(lines[index]);
                            }

                            if (GetSpawnPositionFromLine(lines[index], lines[index + 1]).IsValid())
                            {
                                updatePacket.spawnPosition = GetSpawnPositionFromLine(lines[index], lines[index + 1]);
                            }

                            if (GetEntryFromLine(lines[index]) != 0)
                            {
                                updatePacket.creatureEntry = GetEntryFromLine(lines[index]);
                            }

                            if (LineGetters.GetGuidFromLine(lines[index], buildVersion, objectFieldGuid: true) != "")
                            {
                                updatePacket.creatureGuid = LineGetters.GetGuidFromLine(lines[index], buildVersion, objectFieldGuid: true);
                            }

                            if (GetMaxHealthFromLine(lines[index]) != 0)
                            {
                                updatePacket.creatureMaxHealth = GetMaxHealthFromLine(lines[index]);
                            }

                            if (GetDisableGravityFromLine(lines[index]))
                            {
                                updatePacket.hasDisableGravity = true;
                            }

                            index++;
                        }while (IsLineValidForObjectParse(lines[index]));

                        if (updatePacket.creatureEntry == 0 || updatePacket.creatureGuid == "")
                        {
                            continue;
                        }

                        updatePacket.creatureName = MainForm.GetCreatureNameByEntry(updatePacket.creatureEntry);

                        updatePacketsList.Add(updatePacket);

                        --index;
                    }
                    else if (lines[index].Contains("UpdateType: Values") && LineGetters.IsCreatureLine(lines[index + 1]))
                    {
                        UpdateObjectPacket updatePacket = new UpdateObjectPacket(0, "", "Unknown", -1, 0, packetSendTime, new Position(), null, new List <Waypoint>(), null, null, null, false);

                        do
                        {
                            if (LineGetters.GetGuidFromLine(lines[index], buildVersion) != "")
                            {
                                updatePacket.creatureGuid = LineGetters.GetGuidFromLine(lines[index], buildVersion);
                            }

                            if (GetHealthFromLine(lines[index]) == 0)
                            {
                                updatePacket.creatureCurrentHealth = GetHealthFromLine(lines[index]);
                            }

                            if (GetEmoteStateFromLine(lines[index]) != null)
                            {
                                updatePacket.emoteStateId = GetEmoteStateFromLine(lines[index]);
                            }

                            if (GetSheatheStateFromLine(lines[index]) != null)
                            {
                                updatePacket.sheatheState = GetSheatheStateFromLine(lines[index]);
                            }

                            if (GetStandStateFromLine(lines[index]) != null)
                            {
                                updatePacket.standState = GetStandStateFromLine(lines[index]);
                            }

                            if (GetDisableGravityFromLine(lines[index]))
                            {
                                updatePacket.hasDisableGravity = true;
                            }

                            index++;
                        }while (IsLineValidForObjectParse(lines[index]));

                        updatePacket.creatureName = MainForm.GetCreatureNameByEntry(updatePacket.creatureEntry);

                        if (updatePacket.creatureGuid == "")
                        {
                            continue;
                        }

                        updatePacketsList.Add(updatePacket);

                        --index;
                    }

                    index++;
                } while (lines[index] != "");

                return(updatePacketsList);
            }
        public bool GetDataFromTxtFile(string fileName, bool multiSelect)
        {
            mainForm.SetCurrentStatus("Getting lines...");

            var lines = File.ReadAllLines(fileName);
            Dictionary <long, Packet.PacketTypes> packetIndexes = new Dictionary <long, Packet.PacketTypes>();
            BuildVersions buildVersion = LineGetters.GetBuildVersion(lines);

            if (!IsTxtFileValidForParse(fileName, lines, buildVersion))
            {
                return(false);
            }

            if (!multiSelect)
            {
                creaturesDict.Clear();
            }

            mainForm.SetCurrentStatus("Searching for packet indexes in lines...");

            Parallel.For(0, lines.Length, index =>
            {
                Packet.PacketTypes packetType = Packet.GetPacketTypeFromLine(lines[index]);

                if (packetType == Packet.PacketTypes.SMSG_UPDATE_OBJECT && !packetIndexes.ContainsKey(index))
                {
                    lock (packetIndexes)
                        packetIndexes.Add(index, Packet.PacketTypes.SMSG_UPDATE_OBJECT);
                }
                else if (packetType == Packet.PacketTypes.SMSG_AI_REACTION && !packetIndexes.ContainsKey(index))
                {
                    lock (packetIndexes)
                        packetIndexes.Add(index, Packet.PacketTypes.SMSG_AI_REACTION);
                }
                else if (packetType == Packet.PacketTypes.SMSG_SPELL_START && !packetIndexes.ContainsKey(index))
                {
                    lock (packetIndexes)
                        packetIndexes.Add(index, Packet.PacketTypes.SMSG_SPELL_START);
                }
                else if (packetType == Packet.PacketTypes.SMSG_CHAT && !packetIndexes.ContainsKey(index))
                {
                    lock (packetIndexes)
                        packetIndexes.Add(index, Packet.PacketTypes.SMSG_CHAT);
                }
                else if (packetType == Packet.PacketTypes.SMSG_ON_MONSTER_MOVE && !packetIndexes.ContainsKey(index))
                {
                    lock (packetIndexes)
                        packetIndexes.Add(index, Packet.PacketTypes.SMSG_ON_MONSTER_MOVE);
                }
                else if (packetType == Packet.PacketTypes.SMSG_ATTACK_STOP && !packetIndexes.ContainsKey(index))
                {
                    lock (packetIndexes)
                        packetIndexes.Add(index, Packet.PacketTypes.SMSG_ATTACK_STOP);
                }
            });

            mainForm.SetCurrentStatus("Parsing SMSG_UPDATE_OBJECT packets...");

            foreach (var value in packetIndexes)
            {
                if (value.Value == Packet.PacketTypes.SMSG_UPDATE_OBJECT)
                {
                    Parallel.ForEach(UpdateObjectPacket.ParseObjectUpdatePacket(lines, value.Key, buildVersion, 0), packet =>
                    {
                        lock (creaturesDict)
                        {
                            if (!creaturesDict.ContainsKey(packet.guid))
                            {
                                creaturesDict.Add(packet.guid, new Creature(packet));
                            }
                            else
                            {
                                creaturesDict[packet.guid].UpdateCreature(packet);
                            }
                        }
                    });
                }
            }

            Parallel.ForEach(creaturesDict.Values, creature =>
            {
                creature.name = MainForm.GetCreatureNameByEntry(creature.entry);
            });

            mainForm.SetCurrentStatus("Parsing SMSG_SPELL_START packets...");

            Parallel.ForEach(packetIndexes, value =>
            {
                if (value.Value == Packet.PacketTypes.SMSG_SPELL_START)
                {
                    SpellStartPacket spellPacket = SpellStartPacket.ParseSpellStartPacket(lines, value.Key, buildVersion, value.Value);
                    if (spellPacket.spellId == 0)
                    {
                        return;
                    }

                    lock (creaturesDict)
                    {
                        if (creaturesDict.ContainsKey(spellPacket.casterGuid))
                        {
                            if (!creaturesDict[spellPacket.casterGuid].castedSpells.ContainsKey(spellPacket.spellId))
                            {
                                creaturesDict[spellPacket.casterGuid].castedSpells.Add(spellPacket.spellId, new Spell(spellPacket));
                            }
                            else
                            {
                                creaturesDict[spellPacket.casterGuid].UpdateSpells(spellPacket);
                            }
                        }
                    }
                }
            });

            mainForm.SetCurrentStatus("Parsing SMSG_AI_REACTION packets...");

            Parallel.ForEach(packetIndexes, value =>
            {
                if (value.Value == Packet.PacketTypes.SMSG_AI_REACTION)
                {
                    AIReactionPacket reactionPacket = AIReactionPacket.ParseAIReactionPacket(lines, value.Key, buildVersion);
                    if (reactionPacket.creatureGuid == "")
                    {
                        return;
                    }

                    lock (creaturesDict)
                    {
                        if (creaturesDict.ContainsKey(reactionPacket.creatureGuid))
                        {
                            if (creaturesDict[reactionPacket.creatureGuid].combatStartTime == TimeSpan.Zero ||
                                creaturesDict[reactionPacket.creatureGuid].combatStartTime < reactionPacket.packetSendTime)
                            {
                                creaturesDict[reactionPacket.creatureGuid].combatStartTime = reactionPacket.packetSendTime;
                            }

                            creaturesDict[reactionPacket.creatureGuid].UpdateCombatSpells(reactionPacket);
                        }
                    }
                }
            });

            mainForm.SetCurrentStatus("Parsing SMSG_CHAT packets...");

            Parallel.ForEach(packetIndexes, value =>
            {
                if (value.Value == Packet.PacketTypes.SMSG_CHAT)
                {
                    ChatPacket chatPacket = ChatPacket.ParseChatPacket(lines, value.Key, buildVersion);
                    if (chatPacket.creatureGuid == "")
                    {
                        return;
                    }

                    lock (creaturesDict)
                    {
                        Parallel.ForEach(creaturesDict, creature =>
                        {
                            if (creature.Value.entry == chatPacket.creatureEntry)
                            {
                                CreatureText text = new CreatureText(chatPacket, true);

                                if (Math.Floor(creature.Value.combatStartTime.TotalSeconds) == Math.Floor(chatPacket.packetSendTime.TotalSeconds) ||
                                    Math.Floor(creature.Value.combatStartTime.TotalSeconds) == Math.Floor(chatPacket.packetSendTime.TotalSeconds) + 1 ||
                                    Math.Floor(creature.Value.combatStartTime.TotalSeconds) == Math.Floor(chatPacket.packetSendTime.TotalSeconds) - 1)
                                {
                                    lock (creatureTextsDict)
                                    {
                                        if (creatureTextsDict.ContainsKey(chatPacket.creatureEntry) && creatureTextsDict[chatPacket.creatureEntry].Count(x => x.creatureText == text.creatureText) == 0)
                                        {
                                            creatureTextsDict[chatPacket.creatureEntry].Add(new CreatureText(chatPacket, true));
                                        }
                                        else if (!creatureTextsDict.ContainsKey(chatPacket.creatureEntry))
                                        {
                                            creatureTextsDict.Add(chatPacket.creatureEntry, new List <CreatureText>());
                                            creatureTextsDict[chatPacket.creatureEntry].Add(new CreatureText(chatPacket, true));
                                        }
                                    }
                                }

                                if (Math.Floor(creature.Value.deathTime.TotalSeconds) == Math.Floor(chatPacket.packetSendTime.TotalSeconds) ||
                                    Math.Floor(creature.Value.deathTime.TotalSeconds) == Math.Floor(chatPacket.packetSendTime.TotalSeconds) + 1 ||
                                    Math.Floor(creature.Value.deathTime.TotalSeconds) == Math.Floor(chatPacket.packetSendTime.TotalSeconds) - 1)
                                {
                                    lock (creatureTextsDict)
                                    {
                                        if (creatureTextsDict.ContainsKey(chatPacket.creatureEntry) && creatureTextsDict[chatPacket.creatureEntry].Count(x => x.creatureText == text.creatureText) == 0)
                                        {
                                            creatureTextsDict[chatPacket.creatureEntry].Add(new CreatureText(chatPacket, false, true));
                                        }
                                        else if (!creatureTextsDict.ContainsKey(chatPacket.creatureEntry))
                                        {
                                            creatureTextsDict.Add(chatPacket.creatureEntry, new List <CreatureText>());
                                            creatureTextsDict[chatPacket.creatureEntry].Add(new CreatureText(chatPacket, false, true));
                                        }
                                    }
                                }
                            }
                        });
                    }
                }
            });

            mainForm.SetCurrentStatus("Parsing SMSG_ON_MONSTER_MOVE and SMSG_ATTACK_STOP packets...");

            Parallel.ForEach(packetIndexes, value =>
            {
                switch (value.Value)
                {
                case Packet.PacketTypes.SMSG_ON_MONSTER_MOVE:
                    {
                        MonsterMovePacket movePacket = MonsterMovePacket.ParseMovementPacket(lines, value.Key, buildVersion, 0);
                        if (movePacket.creatureGuid == "")
                        {
                            return;
                        }

                        lock (creaturesDict)
                        {
                            if (creaturesDict.ContainsKey(movePacket.creatureGuid))
                            {
                                creaturesDict[movePacket.creatureGuid].UpdateSpellsByMovementPacket(movePacket);
                            }
                        }

                        break;
                    }

                case Packet.PacketTypes.SMSG_ATTACK_STOP:
                    {
                        AttackStopPacket attackStopPacket = AttackStopPacket.ParseAttackStopkPacket(lines, value.Key, buildVersion);
                        if (attackStopPacket.creatureGuid == "")
                        {
                            return;
                        }

                        lock (creaturesDict)
                        {
                            if (creaturesDict.ContainsKey(attackStopPacket.creatureGuid))
                            {
                                creaturesDict[attackStopPacket.creatureGuid].UpdateSpellsByAttackStopPacket(attackStopPacket);

                                if (attackStopPacket.nowDead)
                                {
                                    creaturesDict[attackStopPacket.creatureGuid].deathTime = attackStopPacket.packetSendTime;
                                }
                            }
                        }

                        break;
                    }
                }
            });

            Parallel.ForEach(creaturesDict, creature =>
            {
                creature.Value.RemoveNonCombatCastTimes();
            });

            Parallel.ForEach(creaturesDict, creature =>
            {
                creature.Value.CreateCombatCastTimings();
            });

            Parallel.ForEach(creaturesDict, creature =>
            {
                creature.Value.CreateDeathSpells();
            });

            if (mainForm.checkBox_CreatureScriptsCreator_CreateDataFile.Checked)
            {
                BinaryFormatter binaryFormatter = new BinaryFormatter();

                if (!multiSelect)
                {
                    using (FileStream fileStream = new FileStream(fileName.Replace("_parsed.txt", "_script_packets.dat"), FileMode.OpenOrCreate))
                    {
                        Dictionary <uint, object> dictToSerialize = new Dictionary <uint, object>
                        {
                            { 0, creaturesDict },
                            { 1, creatureTextsDict }
                        };

                        binaryFormatter.Serialize(fileStream, dictToSerialize);
                    }
                }
                else
                {
                    using (FileStream fileStream = new FileStream(fileName.Replace("_parsed.txt", "multi_selected_script_packets.dat"), FileMode.OpenOrCreate))
                    {
                        Dictionary <uint, object> dictToSerialize = new Dictionary <uint, object>
                        {
                            { 0, creaturesDict },
                            { 1, creatureTextsDict }
                        };

                        binaryFormatter.Serialize(fileStream, dictToSerialize);
                    }
                }
            }

            mainForm.SetCurrentStatus("");
            return(true);
        }
示例#22
0
            public static MonsterMovePacket ParseMovementPacket(string[] lines, long index, BuildVersions buildVersion)
            {
                MonsterMovePacket movePacket = new MonsterMovePacket("", 0.0f, LineGetters.GetTimeSpanFromLine(lines[index]), new List <Waypoint>(), 0, new Position(), new JumpInfo());

                if (LineGetters.IsCreatureLine(lines[index + 1]))
                {
                    Position lastPosition = new Position();

                    do
                    {
                        if (lines[index].Contains("FacingGUID: Full:"))
                        {
                            movePacket.creatureGuid = "";
                            break;
                        }

                        if (LineGetters.GetGuidFromLine(lines[index], buildVersion, moverGuid: true) != "")
                        {
                            movePacket.creatureGuid = LineGetters.GetGuidFromLine(lines[index], buildVersion, moverGuid: true);
                        }

                        if (GetStartPositionFromLine(lines[index]).IsValid())
                        {
                            movePacket.startPos = GetStartPositionFromLine(lines[index]);
                        }

                        if (GetMoveTimeFromLine(lines[index]) != 0)
                        {
                            movePacket.moveTime = GetMoveTimeFromLine(lines[index]);
                        }

                        if (GetFaceDirectionFromLine(lines[index]) != 0.0f)
                        {
                            movePacket.creatureOrientation = GetFaceDirectionFromLine(lines[index]);
                        }

                        if (GetPointPositionFromLine(lines[index]).IsValid())
                        {
                            if (ConsistsOfPoints(lines[index], lines[index + 1]))
                            {
                                uint pointId = 1;

                                do
                                {
                                    if (GetPointPositionFromLine(lines[index]).IsValid())
                                    {
                                        movePacket.waypoints.Add(new Waypoint(GetPointPositionFromLine(lines[index]), 0.0f, 0, movePacket.startPos, movePacket.moveTime, movePacket.packetSendTime, new TimeSpan(), new List <WaypointScript>(), pointId));
                                        pointId++;
                                    }

                                    index++;
                                }while (lines[index] != "");
                            }
                            else
                            {
                                if (GetPointPositionFromLine(lines[index]).IsValid())
                                {
                                    lastPosition = GetPointPositionFromLine(lines[index]);
                                }

                                uint pointId = 1;

                                do
                                {
                                    if (GetWayPointPositionFromLine(lines[index]).IsValid())
                                    {
                                        movePacket.waypoints.Add(new Waypoint(GetWayPointPositionFromLine(lines[index]), 0.0f, 0, movePacket.startPos, movePacket.moveTime, movePacket.packetSendTime, new TimeSpan(), new List <WaypointScript>(), pointId));
                                        pointId++;
                                    }

                                    if (GetJumpGravityFromLine(lines[index]) != 0.0f)
                                    {
                                        movePacket.jumpInfo.jumpGravity = GetJumpGravityFromLine(lines[index]);
                                    }

                                    index++;
                                }while (lines[index] != "");
                            }

                            if (lastPosition.IsValid())
                            {
                                if (movePacket.jumpInfo.jumpGravity != 0.0f)
                                {
                                    movePacket.jumpInfo.moveTime = movePacket.moveTime;
                                    movePacket.jumpInfo.jumpPos  = lastPosition;
                                }
                                else
                                {
                                    movePacket.waypoints.Add(new Waypoint(lastPosition, 0.0f, 0, movePacket.startPos, movePacket.moveTime, movePacket.packetSendTime, new TimeSpan(), new List <WaypointScript>(), (uint)(movePacket.waypoints.Count + 1)));
                                }
                            }

                            break;
                        }

                        index++;
                    }while (lines[index] != "");
                }

                return(movePacket);
            }