public static ChatLogItem Process(byte[] raw)
        {
            var chatLogEntry = new ChatLogItem();

            try {
                chatLogEntry.Bytes     = raw;
                chatLogEntry.TimeStamp = UnixTimeStampToDateTime(int.Parse(ByteArrayToString(raw.Take(4).Reverse().ToArray()), NumberStyles.HexNumber));
                chatLogEntry.Code      = ByteArrayToString(raw.Skip(4).Take(2).Reverse().ToArray());
                chatLogEntry.Raw       = Encoding.UTF8.GetString(raw.ToArray());
                byte[] cleanable = raw.Skip(8).ToArray();
                var    cleaned   = new ChatCleaner(cleanable).Result;
                var    cut       = cleaned.Substring(1, 1) == ":"
                              ? 2
                              : 1;
                chatLogEntry.Line = cleaned.Substring(cut);//XMLCleaner.SanitizeXmlString(cleaned.Substring(cut));
                chatLogEntry.Line = new ChatCleaner(chatLogEntry.Line).Result;
                chatLogEntry.JP   = IsJapanese(chatLogEntry.Line);

                chatLogEntry.Combined = $"{chatLogEntry.Code}:{chatLogEntry.Line}";
            } catch (Exception) {
                chatLogEntry.Bytes    = Array.Empty <byte>();
                chatLogEntry.Raw      = string.Empty;
                chatLogEntry.Line     = string.Empty;
                chatLogEntry.Code     = string.Empty;
                chatLogEntry.Combined = string.Empty;
            }

            return(chatLogEntry);
        }
Esempio n. 2
0
        public override object GetData(HookProcess process)
        {
            var result = new SigChatLogData();

            chatReader.PreviousArrayIndex = previousArrayIndex;
            chatReader.PreviousOffset     = previousOffset;

            if (baseAddress.ToInt64() <= 20)
            {
                return(result);
            }

            List <List <byte> > buffered = new List <List <byte> >();

            try {
                chatReader.Indexes.Clear();
                chatReader.ChatLogPointers = new ChatLogPointers {
                    LineCount        = (uint)process.GetUInt(baseAddress),
                    OffsetArrayStart = process.GetUInt(baseAddress, Offsets["OffsetArrayStart"]),
                    OffsetArrayPos   = process.GetUInt(baseAddress, Offsets["OffsetArrayPos"]),
                    OffsetArrayEnd   = process.GetUInt(baseAddress, Offsets["OffsetArrayEnd"]),
                    LogStart         = process.GetUInt(baseAddress, Offsets["LogStart"]),
                    LogNext          = process.GetUInt(baseAddress, Offsets["LogNext"]),
                    LogEnd           = process.GetUInt(baseAddress, Offsets["LogEnd"]),
                };

                chatReader.EnsureArrayIndexes(process);

                // Convenience
                ChatLogPointers ptrs = chatReader.ChatLogPointers;

                var currentArrayIndex = (ptrs.OffsetArrayPos - ptrs.OffsetArrayStart) / 4;
                if (chatReader.ChatLogFirstRun)
                {
                    chatReader.ChatLogFirstRun    = false;
                    chatReader.PreviousOffset     = chatReader.Indexes[(int)currentArrayIndex - 1];
                    chatReader.PreviousArrayIndex = (int)currentArrayIndex - 1;
                }
                else
                {
                    if (currentArrayIndex < chatReader.PreviousArrayIndex)
                    {
                        buffered.AddRange(chatReader.ResolveEntries(process, chatReader.PreviousArrayIndex, 1000));
                        chatReader.PreviousOffset     = 0;
                        chatReader.PreviousArrayIndex = 0;
                    }

                    if (chatReader.PreviousArrayIndex < currentArrayIndex)
                    {
                        buffered.AddRange(chatReader.ResolveEntries(process, chatReader.PreviousArrayIndex, (int)currentArrayIndex));
                    }

                    chatReader.PreviousArrayIndex = (int)currentArrayIndex;
                }
            }
            catch (Exception ex) {
                return(null);
            }

            foreach (List <byte> bytes in buffered.Where(b => b.Count > 0))
            {
                try {
                    ChatLogItem chatLogEntry = ChatEntry.Process(bytes.ToArray());
                    if (Regex.IsMatch(chatLogEntry.Combined, @"[\w\d]{4}::?.+"))
                    {
                        result.chatMessages.Add(chatLogEntry);
                    }
                }
                catch (Exception ex) {
                }
            }

            previousArrayIndex = chatReader.PreviousArrayIndex;
            previousOffset     = chatReader.PreviousOffset;

            return(result);
        }