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); }