private void OnPlayerCreated(CreatePlayerPacket p)
        {
            var uep = new UpdateObjectPacket {
                ObjectId = p.ObjectId
            };

            uep.Components.Add(p.Components);
            var go     = OnObjectUpdated(uep);
            var isSelf = false;

            foreach (var c in p.Components)
            {
                switch (c.TypeCase)
                {
                case Component.TypeOneofCase.NetworkBehaviour:
                    isSelf = c.NetworkBehaviour.OwnerToken == SessionManager.Instance.Client.Token;
                    break;
                }
            }
            // Only add camera, etc if it's self client, we don't want to have other clients view !
            if (isSelf)
            {
                go.AddComponent <Camera>().farClipPlane = 2000f;
                go.AddComponent <CameraController>();
                go.AddComponent <AudioListener>(); // No audio anyway ..
                go.AddComponent <TransformNetwork>().id = p.ObjectId;
                var cullingSize = 5000;            // TODO: config or something
                go.AddComponent <Cull>().size = new Vector3(cullingSize, cullingSize, cullingSize);
                go.tag = "MainCamera";
            }
        }
Exemple #2
0
        public static List <WaypointScript> GetScriptsFromUpdatePacket(UpdateObjectPacket updatePacket)
        {
            List <WaypointScript> waypointScripts = new List <WaypointScript>();

            if (updatePacket.emoteStateId != null)
            {
                waypointScripts.Add(new WaypointScript(0, 0, ScriptType.Emote, (uint)updatePacket.emoteStateId, 1, 0, 0.0f, 0.0f, 0.0f, 0.0f, 0, updatePacket.packetSendTime));
            }

            if (updatePacket.sheatheState != null)
            {
                waypointScripts.Add(new WaypointScript(0, 0, ScriptType.SetField, 160, (uint)updatePacket.sheatheState, 0, 0.0f, 0.0f, 0.0f, 0.0f, 0, updatePacket.packetSendTime));
            }

            if (updatePacket.standState != null)
            {
                waypointScripts.Add(new WaypointScript(0, 0, ScriptType.SetField, 117, (uint)updatePacket.standState, 0, 0.0f, 0.0f, 0.0f, 0.0f, 0, updatePacket.packetSendTime));
            }

            if (updatePacket.jumpInfo.IsValid())
            {
                waypointScripts.Add(new WaypointScript(0, 0, ScriptType.Jump, updatePacket.jumpInfo.moveTime, 0, 0, updatePacket.jumpInfo.jumpPos.x, updatePacket.jumpInfo.jumpPos.y, updatePacket.jumpInfo.jumpPos.z, updatePacket.jumpInfo.jumpGravity, 0, updatePacket.packetSendTime));
            }

            return(waypointScripts);
        }
Exemple #3
0
        public void UpdateGameObject(UpdateObjectPacket updatePacket)
        {
            if (guid == "" && updatePacket.guid != "")
            {
                guid = updatePacket.guid;
            }

            if (entry == 0 && updatePacket.entry != 0)
            {
                entry = updatePacket.entry;
            }
        }
Exemple #4
0
        public void UpdateCreature(UpdateObjectPacket updatePacket)
        {
            if (guid == "" && updatePacket.guid != "")
            {
                guid = updatePacket.guid;
            }

            if (entry == 0 && updatePacket.entry != 0)
            {
                entry = updatePacket.entry;
            }

            if (deathTime == TimeSpan.Zero && updatePacket.currentHealth == 0)
            {
                deathTime = updatePacket.packetSendTime;
            }

            if (maxhealth == 0 && updatePacket.maxHealth != 0)
            {
                maxhealth = updatePacket.maxHealth;
            }

            if (lastUpdatePacketTime > updatePacket.packetSendTime && updatePacket.spawnPosition.IsValid())
            {
                spawnPosition        = updatePacket.spawnPosition;
                lastUpdatePacketTime = updatePacket.packetSendTime;
            }

            if (mapId == null && updatePacket.mapId != null)
            {
                mapId = updatePacket.mapId;
            }

            if (updatePacket.HasWaypoints())
            {
                foreach (Waypoint wp in updatePacket.waypoints)
                {
                    waypoints.Add(wp);
                }
            }

            if (!hasDisableGravity && updatePacket.hasDisableGravity)
            {
                hasDisableGravity = updatePacket.hasDisableGravity;
            }

            if (transportGuid == "" && updatePacket.transportGuid != "")
            {
                transportGuid = updatePacket.transportGuid;
            }
        }
Exemple #5
0
        public void UpdateCreature(UpdateObjectPacket updatePacket)
        {
            if (guid == "" && updatePacket.creatureGuid != "")
            {
                guid = updatePacket.creatureGuid;
            }

            if (entry == 0 && updatePacket.creatureEntry != 0)
            {
                entry = updatePacket.creatureEntry;
            }

            if (name == "Unknown" && updatePacket.creatureName != "Unknown")
            {
                name = updatePacket.creatureName;
            }

            if (deathTime == TimeSpan.Zero && updatePacket.creatureCurrentHealth == 0)
            {
                deathTime = updatePacket.packetSendTime;
            }

            if (maxhealth == 0 && updatePacket.creatureMaxHealth != 0)
            {
                maxhealth = updatePacket.creatureMaxHealth;
            }

            if (lastUpdatePacketTime > updatePacket.packetSendTime && updatePacket.spawnPosition.IsValid())
            {
                spawnPosition        = updatePacket.spawnPosition;
                lastUpdatePacketTime = updatePacket.packetSendTime;
            }

            if (mapId == null && updatePacket.mapId != null)
            {
                mapId = updatePacket.mapId;
            }

            if (updatePacket.HasWaypoints())
            {
                foreach (Waypoint wp in updatePacket.waypoints)
                {
                    waypoints.Add(wp);
                }
            }

            if (!IsFlying && updatePacket.hasDisableGravity)
            {
                IsFlying = updatePacket.hasDisableGravity;
            }
        }
Exemple #6
0
 public Creature(UpdateObjectPacket updatePacket)
 {
     guid                 = updatePacket.creatureGuid;
     entry                = updatePacket.creatureEntry;
     name                 = updatePacket.creatureName;
     maxhealth            = updatePacket.creatureMaxHealth;
     deathTime            = updatePacket.creatureCurrentHealth == 0 ? updatePacket.packetSendTime : new TimeSpan();
     castedSpells         = new Dictionary <uint, Spell>();
     combatStartTime      = new TimeSpan();
     spawnPosition        = updatePacket.spawnPosition;
     mapId                = updatePacket.mapId;
     waypoints            = updatePacket.waypoints;
     auras                = new List <Aura>();
     lastUpdatePacketTime = updatePacket.packetSendTime;
     IsFlying             = updatePacket.hasDisableGravity;
 }
Exemple #7
0
        public static List <WaypointScript> GetScriptsFromUpdatePacket(UpdateObjectPacket updatePacket)
        {
            List <WaypointScript> waypointScripts = new List <WaypointScript>();

            if (updatePacket.emoteStateId != null)
            {
                waypointScripts.Add(new WaypointScript(0, 0, ScriptType.Emote, (uint)updatePacket.emoteStateId, 1, 0, 0.0f, 0.0f, 0.0f, 0.0f, 0, updatePacket.packetSendTime));
            }

            if (updatePacket.sheatheState != null)
            {
                waypointScripts.Add(new WaypointScript(0, 0, ScriptType.SetField, 160, (uint)updatePacket.sheatheState, 0, 0.0f, 0.0f, 0.0f, 0.0f, 0, updatePacket.packetSendTime));
            }

            if (updatePacket.standState != null)
            {
                waypointScripts.Add(new WaypointScript(0, 0, ScriptType.SetField, 117, (uint)updatePacket.standState, 0, 0.0f, 0.0f, 0.0f, 0.0f, 0, updatePacket.packetSendTime));
            }

            return(waypointScripts);
        }
Exemple #8
0
 public GameObject(UpdateObjectPacket updatePacket)
 {
     guid  = updatePacket.guid;
     entry = updatePacket.entry;
 }
        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 static void AddSourceFromUpdatePacket(this SortedDictionary <long, Packet> dict, UpdateObjectPacket updatePacket, long index)
 {
     foreach (var packet in dict.Values.Where(packet => packet.packetType == Packet.PacketTypes.SMSG_UPDATE_OBJECT && packet.index == index))
     {
         packet.parsedPacketsList.Add(updatePacket);
         return;
     }
 }
        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);
        }
Exemple #12
0
        private List <object> GetDataFromPackets(string[] lines, SynchronizedCollection <Packet> packets)
        {
            mainForm.toolStripStatusLabel_FileStatus.Text = "Current status: Getting data from packets...";
            mainForm.Update();

            List <object> packetsList = new List <object>();

            foreach (Packet packet in packets)
            {
                switch (packet.type)
                {
                case Packet.PacketTypes.SMSG_UPDATE_OBJECT:
                {
                    foreach (var updatePacket in UpdateObjectPacket.ParseObjectUpdatePacket(lines, packet))
                    {
                        packetsList.Add(updatePacket);
                    }

                    break;
                }

                case Packet.PacketTypes.SMSG_SPELL_START:
                case Packet.PacketTypes.SMSG_SPELL_GO:
                {
                    SpellStartPacket spellPacket = SpellStartPacket.ParseSpellStartPacket(lines, packet);

                    if (spellPacket.guid != "")
                    {
                        packetsList.Add(spellPacket);
                    }

                    break;
                }

                case Packet.PacketTypes.SMSG_ON_MONSTER_MOVE:
                {
                    MonsterMovePacket monsterMovePacket = MonsterMovePacket.ParseMovementPacket(lines, packet);

                    if (monsterMovePacket.guid != "" && (monsterMovePacket.waypoints.Count() != 0 || monsterMovePacket.HasJump() ||
                                                         monsterMovePacket.HasOrientation() || monsterMovePacket.hasFacingToPlayer))
                    {
                        packetsList.Add(monsterMovePacket);
                    }

                    break;
                }

                case Packet.PacketTypes.SMSG_PLAY_ONE_SHOT_ANIM_KIT:
                {
                    PlayOneShotAnimKit playOneShotAnimKitPacket = PlayOneShotAnimKit.ParsePlayOneShotAnimKitPacket(lines, packet);

                    if (playOneShotAnimKitPacket.guid != "")
                    {
                        packetsList.Add(playOneShotAnimKitPacket);
                    }

                    break;
                }

                case Packet.PacketTypes.SMSG_CHAT:
                {
                    ChatPacket chatPacket = ChatPacket.ParseChatPacket(lines, packet);

                    if (chatPacket.guid != "")
                    {
                        packetsList.Add(chatPacket);
                    }

                    break;
                }

                case Packet.PacketTypes.SMSG_EMOTE:
                {
                    EmotePacket emotePacket = EmotePacket.ParseEmotePacket(lines, packet);

                    if (emotePacket.guid != "")
                    {
                        packetsList.Add(emotePacket);
                    }

                    break;
                }

                case Packet.PacketTypes.SMSG_AURA_UPDATE:
                {
                    foreach (var auraPacket in AuraUpdatePacket.ParseAuraUpdatePacket(lines, packet))
                    {
                        packetsList.Add(auraPacket);
                    }

                    break;
                }

                case Packet.PacketTypes.SMSG_SET_AI_ANIM_KIT:
                {
                    SetAiAnimKit setAiAnimKitPacket = SetAiAnimKit.ParseSetAiAnimKitPacket(lines, packet);

                    if (setAiAnimKitPacket.guid != "")
                    {
                        packetsList.Add(setAiAnimKitPacket);
                    }

                    break;
                }

                case Packet.PacketTypes.SMSG_PLAY_SPELL_VISUAL_KIT:
                {
                    PlaySpellVisualKit playSpellVisualKitPacket = PlaySpellVisualKit.ParsePlaySpellVisualKitPacket(lines, packet);

                    if (playSpellVisualKitPacket.guid != "")
                    {
                        packetsList.Add(playSpellVisualKitPacket);
                    }

                    break;
                }

                default:
                    break;
                }
            }

            SpellStartPacket.FilterSpellPackets(packetsList);

            return(packetsList);
        }
        /// <summary>
        /// Update object (~=POST + PUT)
        /// </summary>
        /// <param name="packet"></param>
        private GameObject OnObjectUpdated(UpdateObjectPacket packet)
        {
            Object obj      = null;
            var    position = Vector3.zero;
            var    rotation = Quaternion.identity;
            var    scale    = Vector3.zero;
            var    colors   = new[] { Color.white };

            Protometry.Mesh mesh = null;

            // Update object case
            if (Objects.ContainsKey(packet.ObjectId))
            {
                obj = Objects[packet.ObjectId];
            }
            foreach (var c in packet.Components)
            {
                switch (c.TypeCase)
                {
                case Component.TypeOneofCase.Space:
                    position = c.Space.Position.ToVector3();
                    rotation = c.Space.Rotation.ToQuaternion();
                    scale    = c.Space.Scale.ToVector3();
                    break;

                case Component.TypeOneofCase.Render:
                    colors = c.Render.Colors.Select(col => col.ToColor()).ToArray();
                    mesh   = c.Render.Mesh;
                    break;

                case Component.TypeOneofCase.Health:
                    if (obj)
                    {
                        var rend = obj.GetComponent <Mesh>();
                        if (rend)
                        {
                            for (var i = 0; i < rend.colors.Length; i++)
                            {
                                rend.colors[i].r = Mathf.Clamp(4.0f * (float)c.Health.Life / 100f, 0.2f, 0.8f);
                            }
                        }
                    }
                    break;
                }
            }

            // Create object case
            if (!obj)
            {
                // Record.Log($"Creating object");
                // GameObject go;
                // if (_preloaded != null) {
                //     go = Pool.Spawn(_preloaded);
                //     go.GetComponent<MeshRenderer>().sharedMaterial.color = colors[0];
                //     go.GetComponent<MeshFilter>().mesh.colors = colors;
                //     _preloaded = go;
                // } else {
                //     go = InstanciateMesh(mesh, colors);
                //     Pool.Preload(go, 10);
                // }
                //
                // obj = go.AddComponent<Object>();
                obj = InstanciateMesh(mesh, colors).AddComponent <Object>();

                obj.Id = packet.ObjectId;
                obj.gameObject.name = $"{obj.Id}";
                Objects[obj.Id]     = obj;
            }
            //if (color.a < 1) {
            //    Record.Log($"packet {color} pos {position}");
            //}
            var transform1 = obj.transform;

            transform1.position   = position;
            transform1.rotation   = rotation;
            transform1.localScale = scale;
            obj.Components        = packet.Components;
            return(obj.gameObject);
        }
        /// <summary>
        /// UpdateObject is a client to server method to update an object
        /// </summary>
        /// <param name="objectId"></param>
        /// <param name="actualPosition"></param>
        /// <param name="actualRotation"></param>
        /// <param name="newPosition"></param>
        /// <param name="newRotation"></param>
        public void UpdateObject(ulong objectId,
                                 Protometry.Vector3 actualPosition, Protometry.Quaternion actualRotation,
                                 Protometry.Vector3 newPosition, Protometry.Quaternion newRotation)
        {
            var p = new Packet {
            };

            // Update
            if (Objects.ContainsKey(objectId))
            {
                var obj        = Objects[objectId];
                var trans      = obj.transform;
                var packetType = new UpdateSpaceRequestPacket {
                    ObjectId = objectId
                };
                foreach (var c in obj.Components)
                {
                    switch (c.TypeCase)
                    {
                    case Component.TypeOneofCase.Space:
                        packetType.ActualSpace = c.Space;
                        break;
                    }
                }

                // The requested new space will correspond to local client object's transform
                var newSpace = new Component.Types.SpaceComponent
                {
                    Position = newPosition,
                    Rotation = newRotation,
                    Scale    = trans.localScale.ToVector3()
                };

                packetType.ActualSpace.Position = actualPosition;
                packetType.ActualSpace.Rotation = actualRotation;
                packetType.NewSpace             = newSpace;
                p.UpdateSpaceRequest            = packetType;
                SessionManager.Instance.Client.Send(p);
            }
            else
            {
                // No id, create
                var packetType = new UpdateObjectPacket();

                // Create components from scratch
                packetType.Components.Add(new Component
                {
                    Space = new Component.Types.SpaceComponent
                    {
                        Position = actualPosition,
                        Rotation = actualRotation,
                        Scale    = new Protometry.Vector3 {
                            X = 1, Y = 1, Z = 1
                        }
                    }
                });
                packetType.Components.Add(new Component
                {
                    BehaviourType = new Component.Types.BehaviourTypeComponent
                    {
                        // TODO: hardcoded animal tag because we can only create animals yet
                        Tag = Component.Types.BehaviourTypeComponent.Types.Tag.Animal
                    }
                });
                p.UpdateObject = packetType;
                SessionManager.Instance.Client.Send(p);
            }
        }
Exemple #15
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);
            }
Exemple #16
0
 public static void AddSourceFromUpdatePacket(this Packet packet, UpdateObjectPacket updatePacket)
 {
     packet.parsedPacketsList.Add(updatePacket);
     packet.UsedGuids.Add(updatePacket.creatureGuid);
 }
        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);
        }
Exemple #18
0
        public void CreateScriptsForCreatureWithGuid(string guid)
        {
            if (guid == "")
            {
                return;
            }

            List <object> creaturePacketsList = packetsList.Where(x => ((Packet)x).guid == guid).ToList();

            foreach (UpdateObjectPacket updatePacket in packetsList.Where(x => typeof(UpdateObjectPacket) == x.GetType() && ((UpdateObjectPacket)x).objectType == UpdateObjectPacket.ObjectType.Conversation))
            {
                if (updatePacket.conversationActors.FirstOrDefault(x => x == guid) != null)
                {
                    creaturePacketsList.Add(updatePacket);
                }
            }

            creaturePacketsList.AddRange(packetsList.Where(x => x.GetType() == typeof(SpellStartPacket) && ((SpellStartPacket)x).guid != guid && ((SpellStartPacket)x).targetGuids != null && ((SpellStartPacket)x).targetGuids.Contains(guid)));
            AuraUpdatePacket.FilterAuraPacketsForCreature(creaturePacketsList);
            creaturePacketsList = creaturePacketsList.OrderBy(x => ((Packet)x).number).ToList();

            for (int i = 0; i < creaturePacketsList.Count; i++)
            {
                Packet packet = (Packet)creaturePacketsList[i];

                if (packet.type == Packet.PacketTypes.SMSG_EMOTE)
                {
                    bool emoteRelatedToChat = false;

                    foreach (Packet chatPacket in creaturePacketsList.Where(x => x.GetType() == typeof(ChatPacket)))
                    {
                        if ((Math.Round(packet.time.TotalSeconds) == Math.Round(chatPacket.time.TotalSeconds) || Math.Round(packet.time.TotalSeconds) + 1 == Math.Round(chatPacket.time.TotalSeconds)) &&
                            IsEmoteRelatedToText(((ChatPacket)chatPacket).creatureText, ((EmotePacket)packet).emoteId))
                        {
                            emoteRelatedToChat = true;
                            break;
                        }
                    }

                    if (emoteRelatedToChat)
                    {
                        creaturePacketsList.RemoveAt(i);
                    }
                }
            }

            uint   creatureEntry = GetCreatureEntryUsingGuid(packetsList, guid);
            string creatureName  = GetCreatureNameFromDb(creatureEntry);
            string output        = "";

            output += "Parsed packet sequence for " + creatureName + " (Entry: " + creatureEntry + ") " + "(Guid: " + guid + ")" + "\r\n\r\n";
            output += "/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*" + "\r\n";
            output += "/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*" + "\r\n";

            for (int i = 0; i < creaturePacketsList.Count; i++)
            {
                Packet packet = (Packet)creaturePacketsList[i];

                if (i > 0)
                {
                    output += "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" + "\r\n";
                    output += "Time passed after previous packet: " + (packet.time - ((Packet)creaturePacketsList[i - 1]).time).TotalSeconds + " -- " + "Time passed after first packet: " + (packet.time - ((Packet)creaturePacketsList[0]).time).TotalSeconds + "\r\n";
                }

                output += "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" + "\r\n";
                output += "Packet Type: " + packet.type.ToString() + " -- " + "Packet Number: " + packet.number + "\r\n";
                output += "Packet Time: " + packet.time.Hours + ":" + packet.time.Minutes + ":" + packet.time.Seconds + ":" + packet.time.Milliseconds + "\r\n";

                switch (packet.type)
                {
                case Packet.PacketTypes.SMSG_UPDATE_OBJECT:
                {
                    UpdateObjectPacket updateObjectPacket = (UpdateObjectPacket)packet;

                    if (updateObjectPacket.updateType == UpdateObjectPacket.UpdateType.CreateObject)
                    {
                        if (updateObjectPacket.objectType == UpdateObjectPacket.ObjectType.Creature)
                        {
                            output += "Spawn Position: " + updateObjectPacket.spawnPosition.ToString() + "\r\n";
                            output += "Position const g_" + ConverNameToCoreFormat(creatureName) + "SpawnPosition = { " + updateObjectPacket.spawnPosition.ToString() + " };" + "\r\n";

                            if (updateObjectPacket.isSummonedByPlayer)
                            {
                                if (updateObjectPacket.hasReplacedObject)
                                {
                                    output += "if (Creature* l_" + ConverNameToCoreFormat(creatureName) + " = " + "l_Player->SummonCreature(me->GetEntry(), me->GetPosition(), TempSummonType::TEMPSUMMON_TIMED_DESPAWN, " + GetDespawnTimerForCreatureWithGuid(guid) * 1000 + ", 0, " + "l_Player->GetObjectGuid()))" + "\r\n" + "{" + "\r\n" + AddSpacesCount(4) + "\r\n" + "}" + "\r\n";
                                }
                                else
                                {
                                    output += ConverNameToCoreFormat(creatureName) + " = " + creatureEntry + "\r\n";
                                    output += "if (Creature* l_" + ConverNameToCoreFormat(creatureName) + " = " + "l_Player->SummonCreature(eCreatures::" + ConverNameToCoreFormat(creatureName) + ", " + "Positions::g_" + ConverNameToCoreFormat(creatureName) + ", TempSummonType::TEMPSUMMON_TIMED_DESPAWN, " + GetDespawnTimerForCreatureWithGuid(guid) * 1000 + ", 0, " + "l_Player->GetObjectGuid()))" + "\r\n" + "{" + "\r\n" + AddSpacesCount(4) + "\r\n" + "}" + "\r\n";
                                }
                            }

                            if (updateObjectPacket.moveData.waypoints.Count() != 0)
                            {
                                output += "Move Time: " + updateObjectPacket.moveData.moveTime + "\r\n";

                                if (!updateObjectPacket.moveData.HasJump())
                                {
                                    output += "Velocity: " + Convert.ToString(updateObjectPacket.moveData.GetWaypointsVelocity()).Replace(",", ".") + "f" + "\r\n";
                                    output += updateObjectPacket.moveData.GetSetSpeedString() + "\r\n";

                                    if (updateObjectPacket.moveData.waypoints.Count() == 1)
                                    {
                                        switch (updateObjectPacket.moveData.moveType)
                                        {
                                        case MonsterMovePacket.MoveTypes.WALK:
                                        {
                                            output += "Position const g_" + ConverNameToCoreFormat(creatureName) + "MovePos = { " + updateObjectPacket.moveData.waypoints.First().ToString() + " };" + "\r\n";
                                            output += "me->GetMotionMaster()->MoveSmoothPath(ePoints::MoveEnd, Positions::g_" + ConverNameToCoreFormat(creatureName) + "MovePos" + ");" + "\r\n";
                                            break;
                                        }

                                        case MonsterMovePacket.MoveTypes.RUN:
                                        {
                                            output += "Position const g_" + ConverNameToCoreFormat(creatureName) + "MovePos = { " + updateObjectPacket.moveData.waypoints.First().ToString() + " };" + "\r\n";
                                            output += "me->GetMotionMaster()->MoveSmoothPath(ePoints::MoveEnd, Positions::g_" + ConverNameToCoreFormat(creatureName) + "MovePos" + ");" + "\r\n";
                                            break;
                                        }

                                        case MonsterMovePacket.MoveTypes.FLY:
                                        {
                                            output += "Position const g_" + ConverNameToCoreFormat(creatureName) + "FlyPos = { " + updateObjectPacket.moveData.waypoints.First().ToString() + " };" + "\r\n";
                                            output += "me->GetMotionMaster()->MoveSmoothFlyPath(ePoints::FlyEnd, Positions::g_" + ConverNameToCoreFormat(creatureName) + "FlyPos" + ");" + "\r\n";
                                            break;
                                        }

                                        default:
                                            break;
                                        }
                                    }
                                    else
                                    {
                                        switch (updateObjectPacket.moveData.moveType)
                                        {
                                        case MonsterMovePacket.MoveTypes.WALK:
                                        {
                                            output += "me->GetMotionMaster()->MoveSmoothPath(ePoints::MoveEnd, Waypoints::g_Path" + ConverNameToCoreFormat(creatureName) + ", true);" + "\r\n";
                                            break;
                                        }

                                        case MonsterMovePacket.MoveTypes.RUN:
                                        {
                                            output += "me->GetMotionMaster()->MoveSmoothPath(ePoints::MoveEnd, Waypoints::g_Path" + ConverNameToCoreFormat(creatureName) + ", false);" + "\r\n";
                                            break;
                                        }

                                        case MonsterMovePacket.MoveTypes.FLY:
                                        {
                                            output += "me->GetMotionMaster()->MoveSmoothFlyPath(ePoints::MoveEnd, Waypoints::g_Path" + ConverNameToCoreFormat(creatureName) + ");" + "\r\n";
                                            break;
                                        }

                                        default:
                                            break;
                                        }

                                        output += "std::vector<G3D::Vector3> const g_Path" + ConverNameToCoreFormat(creatureName) + " =" + "\r\n";
                                        output += "{" + "\r\n";

                                        for (int j = 0; j < updateObjectPacket.moveData.waypoints.Count; j++)
                                        {
                                            Position waypoint = updateObjectPacket.moveData.waypoints[j];

                                            if (j < (updateObjectPacket.moveData.waypoints.Count - 1))
                                            {
                                                output += "{ " + waypoint.x.GetValueWithoutComma() + "f, " + waypoint.y.GetValueWithoutComma() + "f, " + waypoint.z.GetValueWithoutComma() + "f },\r\n";
                                            }
                                            else
                                            {
                                                output += "{ " + waypoint.x.GetValueWithoutComma() + "f, " + waypoint.y.GetValueWithoutComma() + "f, " + waypoint.z.GetValueWithoutComma() + "f }\r\n";
                                            }
                                        }

                                        output += "};" + "\r\n";
                                    }
                                }
                                else
                                {
                                    output += "Position const g_" + ConverNameToCoreFormat(creatureName) + "JumpPos = { " + updateObjectPacket.moveData.jumpInfo.jumpPos.ToString() + " };" + "\r\n";
                                    output += "me->GetMotionMaster()->MoveReverseJump(g_" + ConverNameToCoreFormat(creatureName) + "JumpPos" + ", " + updateObjectPacket.moveData.moveTime + ", " + updateObjectPacket.moveData.jumpInfo.jumpGravity.GetValueWithoutComma() + "f, " + "ePoints::" + ConverNameToCoreFormat(creatureName) + "JumpEnd);" + "\r\n";
                                    break;
                                }

                                break;
                            }
                        }
                        else if (updateObjectPacket.objectType == Packets.UpdateObjectPacket.ObjectType.Conversation)
                        {
                            output += "Creature is part of conversation: " + updateObjectPacket.conversationEntry + " (" + updateObjectPacket.guid + ")" + "\r\n";
                        }
                    }
                    else if (updateObjectPacket.updateType == UpdateObjectPacket.UpdateType.Values)
                    {
                        if (updateObjectPacket.sheatheState != null)
                        {
                            output += "me->SetSheath(" + (UpdateObjectPacket.SheathState)updateObjectPacket.sheatheState + ");" + "\r\n";
                        }

                        if (updateObjectPacket.standState != null)
                        {
                            output += "me->SetStandState(" + (UpdateObjectPacket.UnitStandStateType)updateObjectPacket.standState + ");" + "\r\n";
                        }

                        if (updateObjectPacket.emoteStateId != null)
                        {
                            output += "me->SetEmoteState(" + (EmotePacket.Emote)updateObjectPacket.emoteStateId + ");" + "\r\n";
                        }
                    }
                    else if (updateObjectPacket.updateType == UpdateObjectPacket.UpdateType.Destroy)
                    {
                        output += "me->DespawnOrUnsummon();" + "\r\n";
                    }

                    break;
                }

                case Packet.PacketTypes.SMSG_SPELL_START:
                case Packet.PacketTypes.SMSG_SPELL_GO:
                {
                    SpellStartPacket spellStartPacket = (SpellStartPacket)packet;

                    if (spellStartPacket.guid != guid)
                    {
                        uint   entry     = GetCreatureEntryUsingGuid(packetsList, spellStartPacket.guid);
                        string spellName = GetSpellName(spellStartPacket.spellId);

                        output += "Hitted by spell: " + spellStartPacket.spellId + " (" + spellName + ")" + "\r\n";

                        if (spellName != "Unknown")
                        {
                            output += ConverNameToCoreFormat(spellName) + " = " + spellStartPacket.spellId + "\r\n";
                        }

                        if (entry != 0)
                        {
                            output += "Caster: " + GetCreatureNameFromDb(entry) + " (Entry: " + entry + ") " + "(Guid: " + spellStartPacket.guid + ")" + "\r\n";
                        }
                        else
                        {
                            output += "Caster: Player " + "(Guid: " + spellStartPacket.guid + ")" + "\r\n";
                        }
                    }
                    else
                    {
                        string spellName = GetSpellName(spellStartPacket.spellId);

                        output += "Spell Id: " + spellStartPacket.spellId + " (" + spellName + ")" + "\r\n";

                        if (spellName != "Unknown")
                        {
                            output += ConverNameToCoreFormat(spellName) + " = " + spellStartPacket.spellId + "\r\n";
                            output += "me->CastSpell(me, eSpells::" + ConverNameToCoreFormat(spellName) + ", true);" + "\r\n";
                        }

                        if (spellStartPacket.destination.IsValid())
                        {
                            output += "Destination: " + spellStartPacket.destination.ToString() + "\r\n";
                        }

                        if (spellStartPacket.targetGuids != null)
                        {
                            if (spellStartPacket.targetGuids.Count == 1 && spellStartPacket.targetGuids.First() == spellStartPacket.guid)
                            {
                                break;
                            }
                            else
                            {
                                for (int j = 0; j < spellStartPacket.targetGuids.Count; j++)
                                {
                                    uint entry = GetCreatureEntryUsingGuid(packetsList, spellStartPacket.targetGuids[j]);
                                    output += "Hit Target " + j + ": " + GetCreatureNameFromDb(entry) + " (Entry: " + entry + ") " + "(Guid: " + spellStartPacket.targetGuids[j] + ")" + "\r\n";
                                }
                            }
                        }
                    }

                    break;
                }

                case Packet.PacketTypes.SMSG_ON_MONSTER_MOVE:
                {
                    MonsterMovePacket monsterMovePacket = (MonsterMovePacket)packet;

                    if (monsterMovePacket.HasOrientation())
                    {
                        output += "me->SetFacingTo(" + monsterMovePacket.creatureOrientation.GetValueWithoutComma() + "f);" + "\r\n";
                    }

                    if (monsterMovePacket.hasFacingToPlayer)
                    {
                        output += "if (Unit* l_Owner = me->GetAnyOwner())" + "\r\n" + "{" + "\r\n" + AddSpacesCount(4) + "me->SetFacingToObject(l_Owner);" + "\r\n" + "}" + "\r\n";
                    }

                    if (monsterMovePacket.waypoints.Count() != 0)
                    {
                        output += "Move Time: " + monsterMovePacket.moveTime + "\r\n";

                        if (!monsterMovePacket.HasJump())
                        {
                            output += "Velocity: " + Convert.ToString(monsterMovePacket.GetWaypointsVelocity()).Replace(",", ".") + "f" + "\r\n";
                            output += monsterMovePacket.GetSetSpeedString() + "\r\n";

                            if (monsterMovePacket.waypoints.Count() == 1)
                            {
                                switch (monsterMovePacket.moveType)
                                {
                                case MonsterMovePacket.MoveTypes.WALK:
                                {
                                    output += "Position const g_" + ConverNameToCoreFormat(creatureName) + "MovePos = { " + monsterMovePacket.waypoints.First().ToString() + " };" + "\r\n";
                                    output += "me->GetMotionMaster()->MoveSmoothPath(ePoints::MoveEnd, Positions::g_" + ConverNameToCoreFormat(creatureName) + "MovePos" + ");" + "\r\n";
                                    break;
                                }

                                case MonsterMovePacket.MoveTypes.RUN:
                                {
                                    output += "Position const g_" + ConverNameToCoreFormat(creatureName) + "MovePos = { " + monsterMovePacket.waypoints.First().ToString() + " };" + "\r\n";
                                    output += "me->GetMotionMaster()->MoveSmoothPath(ePoints::MoveEnd, Positions::g_" + ConverNameToCoreFormat(creatureName) + "MovePos" + ");" + "\r\n";
                                    break;
                                }

                                case MonsterMovePacket.MoveTypes.FLY:
                                {
                                    output += "Position const g_" + ConverNameToCoreFormat(creatureName) + "FlyPos = { " + monsterMovePacket.waypoints.First().ToString() + " };" + "\r\n";
                                    output += "me->GetMotionMaster()->MoveSmoothFlyPath(ePoints::FlyEnd, Positions::g_" + ConverNameToCoreFormat(creatureName) + "FlyPos" + ");" + "\r\n";
                                    break;
                                }

                                default:
                                    break;
                                }
                            }
                            else
                            {
                                switch (monsterMovePacket.moveType)
                                {
                                case MonsterMovePacket.MoveTypes.WALK:
                                {
                                    output += "me->GetMotionMaster()->MoveSmoothPath(ePoints::MoveEnd, Waypoints::g_Path" + ConverNameToCoreFormat(creatureName) + ", true);" + "\r\n";
                                    break;
                                }

                                case MonsterMovePacket.MoveTypes.RUN:
                                {
                                    output += "me->GetMotionMaster()->MoveSmoothPath(ePoints::MoveEnd, Waypoints::g_Path" + ConverNameToCoreFormat(creatureName) + ", false);" + "\r\n";
                                    break;
                                }

                                case MonsterMovePacket.MoveTypes.FLY:
                                {
                                    output += "me->GetMotionMaster()->MoveSmoothFlyPath(ePoints::MoveEnd, Waypoints::g_Path" + ConverNameToCoreFormat(creatureName) + ");" + "\r\n";
                                    break;
                                }

                                default:
                                    break;
                                }

                                output += "std::vector<G3D::Vector3> const g_Path" + ConverNameToCoreFormat(creatureName) + " =" + "\r\n";
                                output += "{" + "\r\n";

                                for (int j = 0; j < monsterMovePacket.waypoints.Count; j++)
                                {
                                    Position waypoint = monsterMovePacket.waypoints[j];

                                    if (j < (monsterMovePacket.waypoints.Count - 1))
                                    {
                                        output += "{ " + waypoint.x.GetValueWithoutComma() + "f, " + waypoint.y.GetValueWithoutComma() + "f, " + waypoint.z.GetValueWithoutComma() + "f },\r\n";
                                    }
                                    else
                                    {
                                        output += "{ " + waypoint.x.GetValueWithoutComma() + "f, " + waypoint.y.GetValueWithoutComma() + "f, " + waypoint.z.GetValueWithoutComma() + "f }\r\n";
                                    }
                                }

                                output += "};" + "\r\n";
                            }
                        }
                        else
                        {
                            output += "Position const g_" + ConverNameToCoreFormat(creatureName) + "JumpPos = { " + monsterMovePacket.jumpInfo.jumpPos.ToString() + " };" + "\r\n";
                            output += "me->GetMotionMaster()->MoveReverseJump(g_" + ConverNameToCoreFormat(creatureName) + "JumpPos" + ", " + monsterMovePacket.moveTime + ", " + monsterMovePacket.jumpInfo.jumpGravity.GetValueWithoutComma() + "f, " + "ePoints::" + ConverNameToCoreFormat(creatureName) + "JumpEnd);" + "\r\n";
                            break;
                        }

                        break;
                    }

                    break;
                }

                case Packet.PacketTypes.SMSG_PLAY_ONE_SHOT_ANIM_KIT:
                {
                    PlayOneShotAnimKit monsterMovePacket = (PlayOneShotAnimKit)packet;

                    output += "me->PlayOneShotAnimKitId(" + monsterMovePacket.AnimKitId + ");" + "\r\n";
                    break;
                }

                case Packet.PacketTypes.SMSG_CHAT:
                {
                    ChatPacket chatPacket = (ChatPacket)packet;

                    output += "Text: " + chatPacket.creatureText + "\r\n";
                    break;
                }

                case Packet.PacketTypes.SMSG_EMOTE:
                {
                    EmotePacket emotePacket = (EmotePacket)packet;
                    output += "me->HandleEmoteCommand(" + (EmotePacket.Emote)emotePacket.emoteId + ");" + "\r\n";
                    break;
                }

                case Packet.PacketTypes.SMSG_AURA_UPDATE:
                {
                    AuraUpdatePacket auraPacket = (AuraUpdatePacket)packet;

                    string spellName = ConverNameToCoreFormat(GetSpellName(auraPacket.spellId));

                    output += spellName + " = " + auraPacket.spellId + "\r\n";
                    output += "me->RemoveAura(eSpells::" + spellName + ");" + "\r\n";
                    break;
                }

                case Packet.PacketTypes.SMSG_SET_AI_ANIM_KIT:
                {
                    SetAiAnimKit animKitPacket = (SetAiAnimKit)packet;

                    output += "me->SetAIAnimKitId(" + animKitPacket.AiAnimKitId + ");" + "\r\n";
                    break;
                }

                case Packet.PacketTypes.SMSG_PLAY_SPELL_VISUAL_KIT:
                {
                    PlaySpellVisualKit playSpellVisualKitPacket = (PlaySpellVisualKit)packet;

                    output += "me->SendPlaySpellVisualKit(" + playSpellVisualKitPacket.KitRecId + ", " + playSpellVisualKitPacket.KitType + ", " + playSpellVisualKitPacket.Duration + ");" + "\r\n";
                    break;
                }

                default:
                    break;
                }

                output += "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" + "\r\n";
                output += "/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*" + "\r\n";
                output += "/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*" + "\r\n";
            }

            mainForm.textBox_Output.Text = output;
        }