Exemplo n.º 1
0
        /// <summary>
        /// Underscore actor ids and add sno names
        /// </summary>
        private void DisplayMessage(string text)
        {
            temp.Text  = text;
            output.Rtf = temp.Rtf;
            foreach (TreeNode tn in actors.Nodes)
            {
                int pos = temp.Find(tn.Tag as string);

                if (pos > -1)
                {
                    temp.Rtf = temp.Rtf.Replace(tn.Tag as string, tn.Text);
                    temp.Select(pos, tn.Text.Length);
                    temp.SelectionFont  = new Font(output.Font, FontStyle.Underline);
                    temp.SelectionColor = Color.Blue;
                }
            }

            temp.Size     = output.Size;
            temp.Location = output.Location;
            output.Rtf    = temp.Rtf;

            string[]      words    = output.Text.Split(new string[] { "0x", " ", "\n", ", " }, StringSplitOptions.RemoveEmptyEntries); // .Split(' ');
            List <string> usedKeys = new List <string>();

            // Bruteforce replacement of snos to their aliases
            if (trySNOAliasesToolStripMenuItem.Checked)
            {
                foreach (string word in words)
                {
                    if (word.Length > 5)  // "for hex values 0000FDC1 etc
                    {
                        try
                        {
                            //string raw = word.Replace("\n", "").Replace("0x", "");
                            int id = 0;
                            if (Int32.TryParse(word, System.Globalization.NumberStyles.HexNumber, null, out id))
                            {
                                if (usedKeys.Contains(id.ToString()) == false)
                                {
                                    usedKeys.Add(id.ToString());
                                    string alias = "";

                                    var aliases = Mooege.Core.GS.Common.Types.TagMap.TagMap.GetKeys(id);
                                    if (aliases.Count > 0)
                                    {
                                        alias = String.Join(" or ", aliases.Select(x => x.Name));

                                        output.Rtf = output.Rtf.Replace(word, word + ": TagKey." + alias);

                                        int pos = -1;
                                        while ((pos = output.Text.IndexOf(alias, pos + 1)) > 0)
                                        {
                                            output.SelectionStart  = pos;
                                            output.SelectionLength = alias.Length;
                                            output.SelectionColor  = Color.OrangeRed;
                                            output.SelectionLength = 0;
                                        }
                                    }

                                    alias = SNOAliases.GetAlias(id);
                                    if (alias != "")
                                    {
                                        output.Rtf = output.Rtf.Replace(word, word + ":" + alias);

                                        int pos = -1;
                                        while ((pos = output.Text.IndexOf(alias, pos + 1)) > 0)
                                        {
                                            output.SelectionStart  = pos;
                                            output.SelectionLength = alias.Length;
                                            output.SelectionColor  = Color.OrangeRed;
                                            output.SelectionLength = 0;
                                        }
                                    }

                                    alias = SNOAliases.GetGroup(id);
                                    if (alias != "")
                                    {
                                        output.Rtf = output.Rtf.Replace(word, word + ":" + alias);

                                        int pos = -1;
                                        while ((pos = output.Text.IndexOf(alias, pos + 1)) > 0)
                                        {
                                            output.SelectionStart  = pos;
                                            output.SelectionLength = alias.Length;
                                            output.SelectionColor  = Color.OrangeRed;
                                            output.SelectionLength = 0;
                                        }
                                    }
                                }
                            }
                        }
                        catch (Exception) { System.Diagnostics.Debugger.Break(); }
                    }
                }
            }
            output.Refresh();
        }
Exemplo n.º 2
0
        public bool Parse()
        {
            //allNodes.Clear();

            while (Buffer.IsPacketAvailable())
            {
                int end = Buffer.Position;
                end += Buffer.ReadInt(32) * 8;
                if (end < Buffer.Position)
                {
                    break;
                }

                while ((end - Buffer.Position) >= 9)
                {
                    int start = Buffer.Position;

                    #region Try parsing a message
                    try
                    {
                        GameMessage message = Buffer.ParseMessage();
                        if (message != null)
                        {
                            if (message is ACDEnterKnownMessage)
                            {
                                String hex = (message as ACDEnterKnownMessage).ActorID.ToString("X8");
                                //string name;
                                //SNOAliases.Aliases.TryGetValue((message as ACDEnterKnownMessage).ActorSNOId.ToString(), out name);
                                string name = SNOAliases.GetAlias((message as ACDEnterKnownMessage).ActorSNOId);
                                if (!actors.ContainsKey(hex))
                                {
                                    TreeNode actorNode = new TreeNode(hex + "  " + name);
                                    actors.Add(hex, actorNode);
                                    actorMap.Add((message as ACDEnterKnownMessage).ActorID, actorNode);
                                    actorNode.Tag = hex;
                                }
                            }

                            if (message is QuestUpdateMessage)
                            {
                                string name = SNOAliases.GetAlias((message as QuestUpdateMessage).snoQuest);
                                //SNOAliases.Aliases.TryGetValue(.ToString(), out name);
                                if (!quests.ContainsKey((message as QuestUpdateMessage).snoQuest.ToString("X8")))
                                {
                                    TreeNode questNode = new TreeNode(name);
                                    questNode.Tag = (message as QuestUpdateMessage).snoQuest.ToString("X8");
                                    quests.Add(questNode.Tag.ToString(), questNode);
                                }
                            }

                            MessageNode node = new MessageNode(message);
                            allNodes.Add(node);

                            /// THIS IS FOR QUICKER PARSING BUT IM TOO LAZY TO DO THAT FOR ALL MESSAGES
                            #region quickparse

                            // skip messages without actor or quest id
                            if (message is GameTickMessage ||
                                message is SNODataMessage ||
                                message is SNONameDataMessage ||
                                message is SimpleMessage ||
                                message is RevealSceneMessage ||
                                message is DestroySceneMessage ||
                                message is MapRevealSceneMessage
                                )
                            {
                                continue;
                            }

                            try
                            {
                                if (gg.ContainsKey(message.GetType()))
                                {
                                    gg[message.GetType()]++;
                                }
                                else
                                {
                                    gg.Add(message.GetType(), 1);
                                }

                                if (message is ANNDataMessage)
                                {
                                    if (actorMap.ContainsKey((uint)(message as ANNDataMessage).ActorID))
                                    {
                                        actorMap[(uint)(message as ANNDataMessage).ActorID].Nodes.Add(node.Clone());
                                    }
                                    continue;
                                }
                                if (message is ACDTranslateFacingMessage)
                                {
                                    actorMap[(uint)(message as ACDTranslateFacingMessage).ActorId].Nodes.Add(node.Clone());
                                    continue;
                                }

                                if (message is AttributeSetValueMessage)
                                {
                                    var msg = message as AttributeSetValueMessage;
                                    actorMap[(uint)(message as AttributeSetValueMessage).ActorID].Nodes.Add(node.Clone());

                                    if (msg.Field1.Attribute != GameAttribute.Attached_To_ACD &&
                                        msg.Field1.Attribute != GameAttribute.Attachment_ACD &&
                                        msg.Field1.Attribute != GameAttribute.Banner_ACDID &&
                                        msg.Field1.Attribute != GameAttribute.Follow_Target_ACDID &&
                                        msg.Field1.Attribute != GameAttribute.Forced_Enemy_ACDID &&
                                        msg.Field1.Attribute != GameAttribute.Gizmo_Operator_ACDID &&
                                        msg.Field1.Attribute != GameAttribute.Guard_Object_ACDID &&
                                        msg.Field1.Attribute != GameAttribute.Item_Bound_To_ACD &&
                                        msg.Field1.Attribute != GameAttribute.Last_Damage_ACD &&
                                        msg.Field1.Attribute != GameAttribute.Last_ACD_Attacked &&
                                        msg.Field1.Attribute != GameAttribute.Last_ACD_Attacked_By &&
                                        msg.Field1.Attribute != GameAttribute.Attached_To_ACD &&
                                        msg.Field1.Attribute != GameAttribute.Last_Blocked_ACD &&
                                        msg.Field1.Attribute != GameAttribute.Loading_Player_ACD &&
                                        msg.Field1.Attribute != GameAttribute.RootTargetACD &&
                                        msg.Field1.Attribute != GameAttribute.Script_Target_ACDID &&
                                        msg.Field1.Attribute != GameAttribute.Spawned_by_ACDID &&
                                        msg.Field1.Attribute != GameAttribute.Summoned_By_ACDID &&
                                        msg.Field1.Attribute != GameAttribute.Taunt_Target_ACD &&
                                        msg.Field1.Attribute != GameAttribute.Wizard_Slowtime_Proxy_ACD)
                                    {
                                        //actorMap[(uint)(message as AttributeSetValueMessage).Field1.Int].Nodes.Add(node.Clone());
                                        continue;
                                    }
                                }

                                if (message is NotifyActorMovementMessage)
                                {
                                    actorMap[(uint)(message as NotifyActorMovementMessage).ActorId].Nodes.Add(node.Clone());
                                    continue;
                                }
                                if (message is PlayerMovementMessage)
                                {
                                    // If the client sends a PlayerMoveMessage, but the actor is not yet in the
                                    // actor list, its due to a broken cap that starts too late...add the node for speed (and grouping)
                                    if (!actorMap.ContainsKey((uint)(message as PlayerMovementMessage).ActorId))
                                    {
                                        String hex = (message as PlayerMovementMessage).ActorId.ToString("X8");

                                        if (!actors.ContainsKey(hex))
                                        {
                                            TreeNode actorNode = new TreeNode(hex + " Capper");
                                            actorMap.Add((uint)(message as PlayerMovementMessage).ActorId, actorNode);
                                            actorNode.Tag = hex;
                                            actors.Add(hex, actorNode);
                                        }
                                    }

                                    actorMap[(uint)(message as PlayerMovementMessage).ActorId].Nodes.Add(node.Clone());
                                    continue;
                                }

                                if (message is ACDGroupMessage)
                                {
                                    actorMap[(uint)(message as ACDGroupMessage).ActorID].Nodes.Add(node.Clone());
                                    continue;
                                }
                                if (message is ACDCollFlagsMessage)
                                {
                                    actorMap[(uint)(message as ACDCollFlagsMessage).ActorID].Nodes.Add(node.Clone());
                                    continue;
                                }
                                if (message is AffixMessage)
                                {
                                    actorMap[(uint)(message as AffixMessage).ActorID].Nodes.Add(node.Clone());
                                    continue;
                                }
                                if (message is TrickleMessage)
                                {
                                    if (actorMap.ContainsKey((uint)(message as TrickleMessage).ActorId))
                                    {
                                        actorMap[(uint)(message as TrickleMessage).ActorId].Nodes.Add(node.Clone());
                                    }
                                    continue;
                                }
                                if (message is ACDEnterKnownMessage)
                                {
                                    actorMap[(uint)(message as ACDEnterKnownMessage).ActorID].Nodes.Add(node.Clone());
                                    continue;
                                }
                                if (message is ACDCreateActorMessage)
                                {
                                    actorMap[(uint)(message as ACDCreateActorMessage).ActorId].Nodes.Add(node.Clone());
                                    continue;
                                }
                                if (message is ACDDestroyActorMessage)
                                {
                                    actorMap[(uint)(message as ACDDestroyActorMessage).ActorId].Nodes.Add(node.Clone());
                                    continue;
                                }
                                if (message is ACDTranslateFixedMessage)
                                {
                                    actorMap[(uint)(message as ACDTranslateFixedMessage).ActorId].Nodes.Add(node.Clone());
                                    continue;
                                }
                                if (message is AttributesSetValuesMessage)
                                {
                                    actorMap[(uint)(message as AttributesSetValuesMessage).ActorID].Nodes.Add(node.Clone());
                                    continue;
                                }
                                if (message is SetIdleAnimationMessage)
                                {
                                    actorMap[(uint)(message as SetIdleAnimationMessage).ActorID].Nodes.Add(node.Clone());
                                    continue;
                                }
                                if (message is ACDWorldPositionMessage)
                                {
                                    actorMap[(uint)(message as ACDWorldPositionMessage).ActorID].Nodes.Add(node.Clone());
                                    continue;
                                }
                                if (message is PlayEffectMessage)
                                {
                                    actorMap[(uint)(message as PlayEffectMessage).ActorId].Nodes.Add(node.Clone());
                                    continue;
                                }
                                if (message is PlayAnimationMessage)
                                {
                                    actorMap[(uint)(message as PlayAnimationMessage).ActorID].Nodes.Add(node.Clone());
                                    continue;
                                }
                                if (message is FloatingNumberMessage)
                                {
                                    actorMap[(uint)(message as FloatingNumberMessage).ActorID].Nodes.Add(node.Clone());
                                    continue;
                                }
                                if (message is ACDTranslateSyncMessage)
                                {
                                    actorMap[(uint)(message as ACDTranslateSyncMessage).Field0].Nodes.Add(node.Clone());
                                    continue;
                                }
                                if (message is ACDTranslateDetPathMessage)
                                {
                                    actorMap[(uint)(message as ACDTranslateDetPathMessage).Field0].Nodes.Add(node.Clone());
                                    continue;
                                }
                                if (message is PlayHitEffectMessage)
                                {
                                    actorMap[(uint)(message as PlayHitEffectMessage).ActorID].Nodes.Add(node.Clone());
                                    continue;
                                }
                                if (message is AimTargetMessage)
                                {
                                    actorMap[(uint)(message as AimTargetMessage).Field0].Nodes.Add(node.Clone());
                                    if ((message as AimTargetMessage).Field2 != -1)
                                    {
                                        actorMap[(uint)(message as AimTargetMessage).Field2].Nodes.Add(node.Clone());
                                    }
                                    continue;
                                }
                                if (message is TargetMessage)
                                {
                                    if ((message as TargetMessage).TargetID != 0xFFFFFFFF)
                                    {
                                        actorMap[(uint)(message as TargetMessage).TargetID].Nodes.Add(node.Clone());
                                    }
                                    continue;
                                }
                            }
                            catch (Exception) {}

                            #endregion

                            // Bruteforce find actor ID and add to actor tree
                            string text = message.AsText();
                            foreach (TreeNode an in actors.Values)
                            {
                                if (text.Contains((string)an.Tag))
                                {
                                    MessageNode nodeb = node.Clone();
                                    nodeb.BackColor = this.BackColor;
                                    an.Nodes.Add(nodeb);
                                }
                            }

                            // Bruteforce find quest SNO and add to quest tree
                            foreach (TreeNode qn in quests.Values)
                            {
                                if (text.Contains(qn.Tag.ToString()))
                                {
                                    MessageNode nodeb = node.Clone();
                                    nodeb.BackColor = this.BackColor;
                                    qn.Nodes.Add(nodeb);
                                }
                            }
                        }
                        else
                        {
                            int pos = Buffer.Position;
                            Buffer.Position = start;
                            ErrorNode errorNode = new ErrorNode(String.Format("No message handler found for message id {0}", (Opcodes)Buffer.ReadInt(9)), "");
                            errorNode.BackColor = Color.Pink;
                            allNodes.Add(errorNode);
                            Buffer.Position = pos;
                        }
                    }

                    catch (Exception e)
                    {
                        int pos = Buffer.Position;
                        Buffer.Position = start;
                        ErrorNode errorNode = new ErrorNode(String.Format("Error parsing messsage {0}", (Opcodes)Buffer.ReadInt(9)), e.Message);
                        errorNode.BackColor = Color.Pink;
                        allNodes.Add(errorNode);
                        Buffer.Position = pos;
                    }
                    #endregion
                }

                Buffer.Position = end;
            }

            return(Buffer.Position != Buffer.Length);
        }