Example #1
0
        public static ChatLogReadResult GetChatLog(int previousArrayIndex = 0, int previousOffset = 0)
        {
            var result = new ChatLogReadResult();

            PreviousArrayIndex = previousArrayIndex;
            PreviousOffset     = previousOffset;

            if (!Scanner.Instance.Locations.ContainsKey("CHATLOG"))
            {
                return(result);
            }

            IntPtr chatPointerMap;

            try
            {
                switch (MemoryHandler.Instance.GameLanguage)
                {
                case "Korean":
                    chatPointerMap = (IntPtr)MemoryHandler.Instance.GetUInt32(Scanner.Instance.Locations["GAMEMAIN"]) + 20;
                    break;

                default:
                    chatPointerMap = Scanner.Instance.Locations["CHATLOG"];
                    break;
                }

                if (chatPointerMap.ToInt64() <= 20)
                {
                    return(result);
                }
            }
            catch (Exception)
            {
                return(result);
            }

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

            try
            {
                Indexes.Clear();
                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)
                };

                EnsureArrayIndexes();

                var currentArrayIndex = (ChatLogPointers.OffsetArrayPos - ChatLogPointers.OffsetArrayStart) / 4;
                if (ChatLogFirstRun)
                {
                    ChatLogFirstRun    = false;
                    PreviousOffset     = Indexes[(int)currentArrayIndex - 1];
                    PreviousArrayIndex = (int)currentArrayIndex - 1;
                }
                else
                {
                    if (currentArrayIndex < PreviousArrayIndex)
                    {
                        buffered.AddRange(ResolveEntries(PreviousArrayIndex, 1000));
                        PreviousOffset     = 0;
                        PreviousArrayIndex = 0;
                    }
                    if (PreviousArrayIndex < currentArrayIndex)
                    {
                        buffered.AddRange(ResolveEntries(PreviousArrayIndex, (int)currentArrayIndex));
                    }
                    PreviousArrayIndex = (int)currentArrayIndex;
                }
            }
            catch (Exception ex)
            {
                MemoryHandler.Instance.RaiseException(Logger, ex, true);
            }

            foreach (var bytes in buffered.Where(b => b.Count > 0))
            {
                try
                {
                    var chatLogEntry = ChatEntry.Process(bytes.ToArray());
                    if (Regex.IsMatch(chatLogEntry.Combined, @"[\w\d]{4}::?.+"))
                    {
                        result.ChatLogEntries.Add(chatLogEntry);
                    }
                }
                catch (Exception ex)
                {
                    MemoryHandler.Instance.RaiseException(Logger, ex, true);
                }
            }

            result.PreviousArrayIndex = PreviousArrayIndex;
            result.PreviousOffset     = PreviousOffset;

            return(result);
        }
Example #2
0
        public static ChatLogReadResult GetChatLog(int previousArrayIndex = 0, int previousOffset = 0)
        {
            var result = new ChatLogReadResult();

            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);
            }

            var 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 (var bytes in buffered.Where(b => b.Count > 0))
            {
                try
                {
                    var chatLogEntry = ChatEntry.Process(bytes.ToArray());
                    if (Regex.IsMatch(chatLogEntry.Combined, @"[\w\d]{4}::?.+"))
                    {
                        result.ChatLogEntries.Add(chatLogEntry);
                    }
                }
                catch (Exception ex)
                {
                    MemoryHandler.Instance.RaiseException(Logger, ex, true);
                }
            }

            result.PreviousArrayIndex = ChatLogReader.PreviousArrayIndex;
            result.PreviousOffset     = ChatLogReader.PreviousOffset;

            return(result);
        }