コード例 #1
0
ファイル: ChatLogWorker.cs プロジェクト: svencent/ffxivapp
        /// <summary>
        /// </summary>
        /// <param name="sender"> </param>
        /// <param name="e"> </param>
        private void ScanTimerElapsed(object sender, ElapsedEventArgs e)
        {
            if (_isScanning)
            {
                return;
            }
            _isScanning = true;
            double refresh = 250;
            if (Double.TryParse(Settings.Default.ChatLogWorkerRefresh.ToString(CultureInfo.InvariantCulture), out refresh))
            {
                _scanTimer.Interval = refresh;
            }
            Func<bool> scannerWorker = delegate
            {
                if (MemoryHandler.Instance.SigScanner.Locations.ContainsKey("GAMEMAIN"))
                {
                    if (MemoryHandler.Instance.SigScanner.Locations.ContainsKey("CHATLOG"))
                    {
                        ChatPointerMap = MemoryHandler.Instance.SigScanner.Locations["CHATLOG"];
                        if (ChatPointerMap <= 20)
                        {
                            return false;
                        }
                        var buffered = new List<List<byte>>();
                        try
                        {
                            _indexes.Clear();

                            if (MemoryHandler.Instance.ProcessModel.IsWin64)
                            {
                                _chatLogPointers = new ChatLogPointers
                                {
                                    LineCount = (uint) MemoryHandler.Instance.GetPlatformUInt(ChatPointerMap),
                                    OffsetArrayStart = (uint) MemoryHandler.Instance.GetPlatformUInt(ChatPointerMap, 0x3C),
                                    OffsetArrayPos = (uint) MemoryHandler.Instance.GetPlatformUInt(ChatPointerMap, 0x44),
                                    OffsetArrayEnd = (uint) MemoryHandler.Instance.GetPlatformUInt(ChatPointerMap, 0x4C),
                                    LogStart = (uint) MemoryHandler.Instance.GetPlatformUInt(ChatPointerMap, 0x5C),
                                    LogNext = (uint) MemoryHandler.Instance.GetPlatformUInt(ChatPointerMap, 0x64),
                                    LogEnd = (uint) MemoryHandler.Instance.GetPlatformUInt(ChatPointerMap, 0x6C)
                                };
                            }
                            else
                            {
                                _chatLogPointers = new ChatLogPointers
                                {
                                    LineCount = (uint) MemoryHandler.Instance.GetPlatformUInt(ChatPointerMap),
                                    OffsetArrayStart = (uint) MemoryHandler.Instance.GetPlatformUInt(ChatPointerMap, 0x20),
                                    OffsetArrayPos = (uint) MemoryHandler.Instance.GetPlatformUInt(ChatPointerMap, 0x24),
                                    OffsetArrayEnd = (uint) MemoryHandler.Instance.GetPlatformUInt(ChatPointerMap, 0x28),
                                    LogStart = (uint) MemoryHandler.Instance.GetPlatformUInt(ChatPointerMap, 0x30),
                                    LogNext = (uint) MemoryHandler.Instance.GetPlatformUInt(ChatPointerMap, 0x34),
                                    LogEnd = (uint) MemoryHandler.Instance.GetPlatformUInt(ChatPointerMap, 0x38)
                                };
                            }

                            EnsureArrayIndexes();

                            var currentArrayIndex = (_chatLogPointers.OffsetArrayPos - _chatLogPointers.OffsetArrayStart) / 4;

                            if (FirstRun)
                            {
                                FirstRun = false;
                                _previousOffset = _indexes[(int) currentArrayIndex - 1];
                                _previousArrayIndex = (int) currentArrayIndex - 1;
                            }
                            else
                            {
                                if (currentArrayIndex < _previousArrayIndex)
                                {
                                    buffered.AddRange(ResolveEntries(_previousArrayIndex, _chatLimit));
                                    _previousOffset = 0;
                                    _previousArrayIndex = 0;
                                }
                                if (_previousArrayIndex < currentArrayIndex)
                                {
                                    buffered.AddRange(ResolveEntries(_previousArrayIndex, (int) currentArrayIndex));
                                }
                                _previousArrayIndex = (int) currentArrayIndex;
                            }
                        }
                        catch (Exception ex)
                        {
                        }
                        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}::?.+"))
                                {
                                    AppContextHelper.Instance.RaiseNewChatLogEntry(chatLogEntry);
                                }
                            }
                            catch (Exception ex)
                            {
                            }
                        }
                    }
                    else
                    {
                        try
                        {
                            ChatPointerMap = MemoryHandler.Instance.GetPlatformUInt(MemoryHandler.Instance.SigScanner.Locations["GAMEMAIN"]) + 20;
                            MemoryHandler.Instance.SigScanner.Locations.Add("CHATLOG", ChatPointerMap);
                        }
                        catch (Exception ex)
                        {
                        }
                    }
                }
                _isScanning = false;
                return true;
            };
            scannerWorker.BeginInvoke(delegate { }, scannerWorker);
        }
コード例 #2
0
ファイル: ChatLogWorker.cs プロジェクト: Yaguar666/ffxivapp
        /// <summary>
        /// </summary>
        /// <param name="sender"> </param>
        /// <param name="e"> </param>
        private void ScanTimerElapsed(object sender, ElapsedEventArgs e)
        {
            if (_isScanning)
            {
                return;
            }
            _isScanning = true;
            double refresh = 250;

            if (Double.TryParse(Settings.Default.ChatLogWorkerRefresh.ToString(CultureInfo.InvariantCulture), out refresh))
            {
                _scanTimer.Interval = refresh;
            }
            Func <bool> scannerWorker = delegate
            {
                if (MemoryHandler.Instance.SigScanner.Locations.ContainsKey("GAMEMAIN"))
                {
                    if (MemoryHandler.Instance.SigScanner.Locations.ContainsKey("CHATLOG"))
                    {
                        ChatPointerMap = MemoryHandler.Instance.SigScanner.Locations["CHATLOG"];
                        if (ChatPointerMap <= 20)
                        {
                            return(false);
                        }
                        var buffered = new List <List <byte> >();
                        try
                        {
                            _indexes.Clear();

                            if (MemoryHandler.Instance.ProcessModel.IsWin64)
                            {
                                _chatLogPointers = new ChatLogPointers
                                {
                                    LineCount        = (uint)MemoryHandler.Instance.GetPlatformUInt(ChatPointerMap),
                                    OffsetArrayStart = (uint)MemoryHandler.Instance.GetPlatformUInt(ChatPointerMap, 0x3C),
                                    OffsetArrayPos   = (uint)MemoryHandler.Instance.GetPlatformUInt(ChatPointerMap, 0x44),
                                    OffsetArrayEnd   = (uint)MemoryHandler.Instance.GetPlatformUInt(ChatPointerMap, 0x4C),
                                    LogStart         = (uint)MemoryHandler.Instance.GetPlatformUInt(ChatPointerMap, 0x5C),
                                    LogNext          = (uint)MemoryHandler.Instance.GetPlatformUInt(ChatPointerMap, 0x64),
                                    LogEnd           = (uint)MemoryHandler.Instance.GetPlatformUInt(ChatPointerMap, 0x6C)
                                };
                            }
                            else
                            {
                                _chatLogPointers = new ChatLogPointers
                                {
                                    LineCount        = (uint)MemoryHandler.Instance.GetPlatformUInt(ChatPointerMap),
                                    OffsetArrayStart = (uint)MemoryHandler.Instance.GetPlatformUInt(ChatPointerMap, 0x20),
                                    OffsetArrayPos   = (uint)MemoryHandler.Instance.GetPlatformUInt(ChatPointerMap, 0x24),
                                    OffsetArrayEnd   = (uint)MemoryHandler.Instance.GetPlatformUInt(ChatPointerMap, 0x28),
                                    LogStart         = (uint)MemoryHandler.Instance.GetPlatformUInt(ChatPointerMap, 0x30),
                                    LogNext          = (uint)MemoryHandler.Instance.GetPlatformUInt(ChatPointerMap, 0x34),
                                    LogEnd           = (uint)MemoryHandler.Instance.GetPlatformUInt(ChatPointerMap, 0x38)
                                };
                            }

                            EnsureArrayIndexes();

                            var currentArrayIndex = (_chatLogPointers.OffsetArrayPos - _chatLogPointers.OffsetArrayStart) / 4;

                            if (FirstRun)
                            {
                                FirstRun            = false;
                                _previousOffset     = _indexes[(int)currentArrayIndex - 1];
                                _previousArrayIndex = (int)currentArrayIndex - 1;
                            }
                            else
                            {
                                if (currentArrayIndex < _previousArrayIndex)
                                {
                                    buffered.AddRange(ResolveEntries(_previousArrayIndex, _chatLimit));
                                    _previousOffset     = 0;
                                    _previousArrayIndex = 0;
                                }
                                if (_previousArrayIndex < currentArrayIndex)
                                {
                                    buffered.AddRange(ResolveEntries(_previousArrayIndex, (int)currentArrayIndex));
                                }
                                _previousArrayIndex = (int)currentArrayIndex;
                            }
                        }
                        catch (Exception ex)
                        {
                        }
                        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}::?.+"))
                                {
                                    AppContextHelper.Instance.RaiseNewChatLogEntry(chatLogEntry);
                                }
                            }
                            catch (Exception ex)
                            {
                            }
                        }
                    }
                    else
                    {
                        try
                        {
                            ChatPointerMap = MemoryHandler.Instance.GetPlatformUInt(MemoryHandler.Instance.SigScanner.Locations["GAMEMAIN"]) + 20;
                            MemoryHandler.Instance.SigScanner.Locations.Add("CHATLOG", ChatPointerMap);
                        }
                        catch (Exception ex)
                        {
                        }
                    }
                }
                _isScanning = false;
                return(true);
            };

            scannerWorker.BeginInvoke(delegate { }, scannerWorker);
        }