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