public static async Task <ChatLogResult> GetChatLog(int previousArrayIndex = 0, int previousOffset = 0) { var result = new ChatLogResult(); if (!CanGetChatLog() || !MemoryHandler.Instance.IsAttached) { return(result); } ChatLogReader.PreviousArrayIndex = previousArrayIndex; ChatLogReader.PreviousOffset = previousOffset; var chatPointerMap = (IntPtr)Scanner.Instance.Locations[Signatures.ChatLogKey]; if (chatPointerMap.ToInt64() <= 20) { return(result); } List <List <byte> > buffered = new List <List <byte> >(); try { ChatLogReader.Indexes.Clear(); ChatLogReader.ChatLogPointers = new ChatLogPointers { LineCount = (uint)MemoryHandler.Instance.GetPlatformUInt(chatPointerMap), OffsetArrayStart = MemoryHandler.Instance.GetPlatformUInt(chatPointerMap, MemoryHandler.Instance.Structures.ChatLogPointers.OffsetArrayStart), OffsetArrayPos = MemoryHandler.Instance.GetPlatformUInt(chatPointerMap, MemoryHandler.Instance.Structures.ChatLogPointers.OffsetArrayPos), OffsetArrayEnd = MemoryHandler.Instance.GetPlatformUInt(chatPointerMap, MemoryHandler.Instance.Structures.ChatLogPointers.OffsetArrayEnd), LogStart = MemoryHandler.Instance.GetPlatformUInt(chatPointerMap, MemoryHandler.Instance.Structures.ChatLogPointers.LogStart), LogNext = MemoryHandler.Instance.GetPlatformUInt(chatPointerMap, MemoryHandler.Instance.Structures.ChatLogPointers.LogNext), LogEnd = MemoryHandler.Instance.GetPlatformUInt(chatPointerMap, MemoryHandler.Instance.Structures.ChatLogPointers.LogEnd) }; ChatLogReader.EnsureArrayIndexes(); var currentArrayIndex = (ChatLogReader.ChatLogPointers.OffsetArrayPos - ChatLogReader.ChatLogPointers.OffsetArrayStart) / 4; if (ChatLogReader.ChatLogFirstRun) { ChatLogReader.ChatLogFirstRun = false; ChatLogReader.PreviousOffset = ChatLogReader.Indexes[(int)currentArrayIndex - 1]; ChatLogReader.PreviousArrayIndex = (int)currentArrayIndex - 1; } else { if (currentArrayIndex < ChatLogReader.PreviousArrayIndex) { buffered.AddRange(ChatLogReader.ResolveEntries(ChatLogReader.PreviousArrayIndex, 1000)); ChatLogReader.PreviousOffset = 0; ChatLogReader.PreviousArrayIndex = 0; } if (ChatLogReader.PreviousArrayIndex < currentArrayIndex) { buffered.AddRange(ChatLogReader.ResolveEntries(ChatLogReader.PreviousArrayIndex, (int)currentArrayIndex)); } ChatLogReader.PreviousArrayIndex = (int)currentArrayIndex; } } catch (Exception ex) { MemoryHandler.Instance.RaiseException(Logger, ex, true); } 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.ChatLogItems.Add(chatLogEntry); } } catch (Exception ex) { MemoryHandler.Instance.RaiseException(Logger, ex, true); } } result.PreviousArrayIndex = ChatLogReader.PreviousArrayIndex; result.PreviousOffset = ChatLogReader.PreviousOffset; return(result); }
public ChatLogResult GetChatLog(int previousArrayIndex = 0, int previousOffset = 0) { var result = new ChatLogResult(); if (!CanGetChatLog() || !MemoryHandler.IsAttached) { return(result); } _chatLogReader.PreviousArrayIndex = previousArrayIndex; _chatLogReader.PreviousOffset = previousOffset; var chatPointerMap = (IntPtr)Scanner.Locations[Signatures.ChatLogKey]; if (chatPointerMap.ToInt64() <= 20) { return(result); } var buffered = new List <List <byte> >(); try { _chatLogReader.ChatLogPointers = new ChatLogPointers { LineCount = (uint)MemoryHandler.GetPlatformUInt(chatPointerMap), OffsetArrayStart = MemoryHandler.GetPlatformUInt(chatPointerMap, MemoryHandler.Structures.ChatLogPointers.OffsetArrayStart), OffsetArrayPos = MemoryHandler.GetPlatformUInt(chatPointerMap, MemoryHandler.Structures.ChatLogPointers.OffsetArrayPos), OffsetArrayEnd = MemoryHandler.GetPlatformUInt(chatPointerMap, MemoryHandler.Structures.ChatLogPointers.OffsetArrayEnd), LogStart = MemoryHandler.GetPlatformUInt(chatPointerMap, MemoryHandler.Structures.ChatLogPointers.LogStart), LogNext = MemoryHandler.GetPlatformUInt(chatPointerMap, MemoryHandler.Structures.ChatLogPointers.LogNext), LogEnd = MemoryHandler.GetPlatformUInt(chatPointerMap, MemoryHandler.Structures.ChatLogPointers.LogEnd) }; var currentArrayIndex = (_chatLogReader.ChatLogPointers.OffsetArrayPos - _chatLogReader.ChatLogPointers.OffsetArrayStart) / 4; if (_chatLogFirstRun) { _chatLogFirstRun = false; _chatLogReader.EnsureArrayIndexes(); if (currentArrayIndex - 1 > 0 && _chatLogReader.Indexes.Count >= currentArrayIndex - 1) { _chatLogReader.PreviousOffset = _chatLogReader.Indexes[(int)currentArrayIndex - 1]; } else { _chatLogReader.PreviousOffset = 0; _chatLogReader.PreviousArrayIndex = 0; result.PreviousArrayIndex = _chatLogReader.PreviousArrayIndex; result.PreviousOffset = _chatLogReader.PreviousOffset; return(result); // The player is logged out. } _chatLogReader.PreviousArrayIndex = (int)currentArrayIndex - 1; } else { if (currentArrayIndex < _chatLogReader.PreviousArrayIndex) { _chatLogReader.PreviousOffset = 0; _chatLogReader.PreviousArrayIndex = 0; result.PreviousArrayIndex = _chatLogReader.PreviousArrayIndex; result.PreviousOffset = _chatLogReader.PreviousOffset; return(result); // The player logged out. } if (_chatLogReader.PreviousArrayIndex < currentArrayIndex) { buffered.AddRange(_chatLogReader.ResolveEntries(_chatLogReader.PreviousArrayIndex, (int)currentArrayIndex)); } _chatLogReader.PreviousArrayIndex = (int)currentArrayIndex; } } catch (Exception ex) { MemoryHandler?.RaiseException(ex); } foreach (var bytes in buffered.Where(b => b.Count > 0)) { try { var chatLogEntry = ChatEntry.Process(MemoryHandler, bytes.ToArray()); if (Regex.IsMatch(chatLogEntry.Combined, @"[\w\d]{4}::?.+")) { result.ChatLogItems.Add(chatLogEntry); } } catch (Exception ex) { MemoryHandler?.RaiseException(ex); } } result.PreviousArrayIndex = _chatLogReader.PreviousArrayIndex; result.PreviousOffset = _chatLogReader.PreviousOffset; return(result); }