Exemplo n.º 1
0
 public void UpdateSpellsByAttackStopPacket(AttackStopPacket attackPacket)
 {
     Parallel.ForEach(castedSpells, spell =>
     {
         spell.Value.SetConeDelayIfNeeded(attackPacket);
     });
 }
Exemplo n.º 2
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 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);
        }
        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);
        }
Exemplo n.º 5
0
 public static void AddSourceFromAttackStopPacket(this SortedDictionary <long, Packet> dict, AttackStopPacket attackStopPacket, long index)
 {
     foreach (var packet in dict.Values.Where(packet => packet.packetType == Packet.PacketTypes.SMSG_ATTACK_STOP && packet.index == index))
     {
         packet.parsedPacketsList.Add(attackStopPacket);
         packet.UsedGuids.Add(attackStopPacket.creatureGuid);
         return;
     }
 }