Exemplo n.º 1
0
        static IOrderedEnumerable <KeyValuePair <string, List <ushort> > > GetOrganizedHeadersByHashCount(HGame game, IReadOnlyDictionary <ushort, ASClass> messageClasses)
        {
            var unorganizedHeaders = new Dictionary <string, List <ushort> >();

            foreach (ushort header in messageClasses.Keys)
            {
                ASClass messageClass = messageClasses[header];
                string  messageHash  = game.GetMessageHash(messageClass);

                if (!unorganizedHeaders.ContainsKey(messageHash))
                {
                    unorganizedHeaders[messageHash] = new List <ushort>();
                }

                if (!unorganizedHeaders[messageHash].Contains(header))
                {
                    unorganizedHeaders[messageHash].Add(header);
                }
            }
            return(unorganizedHeaders.OrderBy(kvp => kvp.Value.Count));
        }
Exemplo n.º 2
0
        static string UpdateHeaders(string headersPath, HGame current, HGame previous, bool isUpdatingOutgoing)
        {
            IReadOnlyDictionary <ushort, ASClass> curMsgClasses =
                (isUpdatingOutgoing ? current.OutgoingMessages : current.IncomingMessages);

            IReadOnlyDictionary <ushort, ASClass> preMsgClasses =
                (isUpdatingOutgoing ? previous.OutgoingMessages : previous.IncomingMessages);

            string         value    = File.ReadAllText(headersPath);
            MatchEvaluator replacer =
                delegate(Match match)
            {
                bool   isOut       = isUpdatingOutgoing;
                string endValue    = match.Groups["end"].Value;
                string headerValue = match.Groups["header"].Value;

                ushort preHeader = 0;
                if (!ushort.TryParse(headerValue, out preHeader) ||
                    !preMsgClasses.ContainsKey(preHeader))
                {
                    if (headerValue != "0000")
                    {
                        return($"-1{endValue} //Invalid Header '{headerValue}'");
                    }
                    else
                    {
                        return("-1" + endValue);
                    }
                }

                ASClass msgClass = preMsgClasses[preHeader];
                string  hash     = previous.GetMessageHash(msgClass);

                bool   isDead = false;
                string result = string.Empty;
                IReadOnlyList <ASClass> curSimilars = current.GetMessages(hash);
                if (curSimilars == null)
                {
                    return($"-1{endValue} //No Matches {msgClass.Instance.QualifiedName.Name}[{headerValue}]");
                }
                else
                {
                    ASClass curMsgClass = curSimilars[0];
                    isDead = !current.IsMessageReferenced(curMsgClass);

                    if (curSimilars.Count == 1)
                    {
                        ushort curHeader = current.GetMessageHeader(curMsgClass);
                        result = $"{curHeader}{endValue} //{headerValue}";
                    }
                    else
                    {
                        result = $"-1{endValue} //Duplicate Matches {msgClass.Instance.QualifiedName.Name}[{headerValue}] | {hash}";
                    }
                }
                if (isDead)
                {
                    result +=
                        " | Dead Message(0 References)";
                }
                return(result);
            };

            value = Regex.Replace(value,
                                  "( |)//(.*?)\r\n", "\r\n", RegexOptions.Singleline).Trim();

            if (value.Contains("-1"))
            {
                value = Regex.Replace(value,
                                      @"-\b1\b", "0000", RegexOptions.Multiline);
            }

            value = Regex.Replace(value,
                                  @"(\b(?<header>\d{1,4})\b)(?<end>[^\r|$]*)", replacer, RegexOptions.Multiline);

            return(value);
        }
Exemplo n.º 3
0
        public void WritePacketLog(DataInterceptedEventArgs args, bool isOutgoing)
        {
            HMessage pkt  = args.Packet;
            HGame    game = MainUI.ConnectionPg.Game;

            ReadOnlyDictionary <ushort, ASClass> msgClasses = (isOutgoing ?
                                                               game.OutgoingMessages : game.IncomingMessages);

            ASClass msgClass = null;

            msgClasses.TryGetValue(pkt.Header, out msgClass);

            Color highlight = (isOutgoing ?
                               OutgoingHighlight : IncomingHighlight);

            if (DisplayTimestamp)
            {
                WriteHighlight($"[{DateTime.Now.ToLongTimeString()}]\r\n", SpecialHighlight);
            }

            if (DisplayHash)
            {
                string hash = game.GetMessageHash(msgClass);
                WriteHighlight($"[{hash}]\r\n", SpecialHighlight);
            }

            WriteHighlight((isOutgoing ?
                            "Outgoing" : "Incoming"), highlight);

            if (args.IsBlocked && DisplayBlocked)
            {
                WriteHighlight("[Blocked]", SpecialHighlight);
            }
            else if (!args.IsOriginal)
            {
                WriteHighlight("[Replaced]", SpecialHighlight);
            }

            string arrow = (isOutgoing ? "->" : "<-");

            WriteHighlight($"({pkt.Header}, {pkt.Length}", highlight);

            if (DisplayClassName && msgClass != null)
            {
                WriteHighlight(", ", highlight);
                WriteHighlight((msgClass?.Instance.Name.Name) ?? "???", SpecialHighlight);
            }
            if (!isOutgoing && DisplayParserName &&
                msgClass != null && !_invalidParsers.Contains(pkt.Header))
            {
                ASClass parserClass = game
                                      .GetIncomingMessageParser(msgClass);

                if (parserClass != null)
                {
                    WriteHighlight($", ", highlight);
                    WriteHighlight(parserClass.Instance.Name.Name, SpecialHighlight);
                }
                else
                {
                    _invalidParsers.Add(pkt.Header);
                }
            }
            WriteHighlight($") {arrow} {pkt}\r\n", highlight);

            if (DisplayStructure && isOutgoing)
            {
                WriteStructureLog(pkt, msgClass);
            }
        }