private static bool CheckChatEquality(ChatLogItem item1, ChatLogItem item2)
        {
            if (item1 == null && item2 == null)
            {
                return(true);
            }
            if (item1 == null || item2 == null)
            {
                return(false);
            }
            if (item1.Bytes == null && item2.Bytes == null)
            {
                return(true);
            }
            if (item1.Bytes == null || item2.Bytes == null)
            {
                return(false);
            }

            string str1 = item1.Line.Substring(item1.Line.IndexOf(':'));
            string str2 = item2.Line.Substring(item2.Line.IndexOf(':'));

            String onlyLetters1 = new String(str1.Where(Char.IsLetter).ToArray());
            String onlyLetters2 = new String(str2.Where(Char.IsLetter).ToArray());

            return(onlyLetters1 == onlyLetters2);
            //return str1 == str2;
        }
 public static void Process(ChatLogItem chatLogItem)
 {
     try { }
     catch (Exception ex) {
         Logging.Log(Logger, new LogItem(ex, true));
     }
 }
Beispiel #3
0
        public static void HandleCommands(ChatLogItem chatLogItem)
        {
            // process commands
            if (chatLogItem.Code == "0038")
            {
                Console.WriteLine("WOOOOOOW! got chatlog 0038...");
                Match commandsRegEx = CommandBuilder.CommandsRegEx.Match(chatLogItem.Line.Trim());
                if (!commandsRegEx.Success)
                {
                    return;
                }

                var command = commandsRegEx.Groups["command"].Success
                                  ? commandsRegEx.Groups["command"].Value
                                  : string.Empty;
                switch (command)
                {
                case "on":
                    Console.WriteLine("Lets go, time to parse!");
                    IsPaused = false;
                    break;

                case "off":
                    Console.WriteLine("OK! time to stop parsing!");
                    IsPaused = true;
                    break;

                case "reset":
                    ParseControl.Instance.Reset();
                    break;
                }
            }
        }
Beispiel #4
0
 // battle data
 public Line(ChatLogItem chatLogItem = null)
 {
     if (chatLogItem != null)
     {
         this.ChatLogItem = chatLogItem;
     }
 }
Beispiel #5
0
        public static void HandleCommands(ChatLogItem chatLogItem)
        {
            // process commands
            if (chatLogItem.Code == "0038")
            {
                Match commandsRegEx = CommandBuilder.CommandsRegEx.Match(chatLogItem.Line.Trim());
                if (!commandsRegEx.Success)
                {
                    return;
                }

                var command = commandsRegEx.Groups["command"].Success
                                  ? commandsRegEx.Groups["command"].Value
                                  : string.Empty;
                switch (command)
                {
                case "on":
                    IsPaused = false;
                    break;

                case "off":
                    IsPaused = true;
                    break;

                case "reset":
                    ParseControl.Instance.Reset();
                    break;
                }
            }
        }
Beispiel #6
0
        private static bool IsTextEmpty(this ChatLogItem chatLogItem)
        {
            bool result = true;

            if (chatLogItem == null)
            {
                return(result);
            }

            if (chatLogItem.Bytes == null || chatLogItem.Line == null)
            {
                return(result);
            }

            int indexOf = chatLogItem.Line.IndexOf(':');

            if (indexOf < 0)
            {
                return(result);
            }
            else
            {
                if (chatLogItem.Line.Length - 1 != indexOf)
                {
                    result = false;
                }
            }

            return(result);
        }
        private static void OnChatLogItemReceived(object sender, ChatLogItemEvent chatLogItemEvent)
        {
            // delegate event from chat log, not required to subsribe
            // this updates 100 times a second and only sends a line when it gets a new one
            if (sender == null)
            {
                return;
            }

            ChatLogItem chatLogEntry = chatLogItemEvent.ChatLogItem;

            Logging.Log(Logger, new LogItem(chatLogItemEvent.ChatLogItem.Code));
            Logging.Log(Logger, new LogItem(chatLogItemEvent.ChatLogItem.Bytes.ToString()));
            Logging.Log(Logger, new LogItem(chatLogItemEvent.ChatLogItem.Combined));
            Logging.Log(Logger, new LogItem(chatLogItemEvent.ChatLogItem.Line));
            Logging.Log(Logger, new LogItem(chatLogItemEvent.ChatLogItem.Raw));
            Logging.Log(Logger, new LogItem(chatLogItemEvent.ChatLogItem.TimeStamp.ToString("o")));
            try
            {
                LogPublisher.Process(chatLogEntry);
            }
            catch (Exception ex) {
                Logging.Log(Logger, new LogItem(ex, true));
            }
        }
Beispiel #8
0
        public virtual void RaiseChatLogItemReceived(ChatLogItem chatLogItem)
        {
            var raised = new ChatLogItemEvent(this, chatLogItem);
            EventHandler <ChatLogItemEvent> handler = this.ChatLogItemReceived;

            handler?.Invoke(this, raised);
        }
Beispiel #9
0
        private void Memory_OnChatReceived(object sender, ChatLogItem arg)
        {
            string format = BmpChatParser.Fixup(arg);

            if (!string.IsNullOrEmpty(format))
            {
                logger.Info(format);
                Console.WriteLine(format);
            }
        }
 public void ToastNotifyUser(ChatLogItem message)
 {
     // if our hooked copy of ffxiv isn't the foreground window, send a toast notification
     if (MainWindow.processHwid != MemoryHelper.GetForegroundWindow())
     {
         var notificationContent = new NotificationContent {
             Message = message.Line, Type = NotificationType.Information
         };
         _notificationManager.Show(notificationContent, onClick: () => MemoryHelper.SetForegroundWindow(MainWindow.processHwid));
     }
 }
        private void LogChatEntry(ChatLogItem message)
        {
            // need to use this whenever we're referencing UI elements from other threads
            Application.Current.Dispatcher.Invoke(() =>
            {
                if (txtblkLog.Text.Length > 5000)
                {
                    txtblkLog.Text = String.Empty;
                }

                txtblkLog.Text = txtblkLog.Text + Environment.NewLine + $"{message.Code} - {message.Line}";
                txtblkScrollViewer.ScrollToEnd();
            });
        }
Beispiel #12
0
        /// <summary>
        /// </summary>
        /// <param name="chatLogItem"></param>
        public void ParseAndPublish(ChatLogItem chatLogItem)
        {
            Event @event = this.Parse(chatLogItem);
            EventHandler <Event> eventHandler = @event.IsUnknown
                                                   ? this.OnUnknownLogEvent
                                                   : this.OnLogEvent;

            if (eventHandler == null)
            {
                return;
            }

            lock (eventHandler) {
                eventHandler(this, @event);
            }
        }
Beispiel #13
0
        /// <summary>
        /// </summary>
        /// <param name="chatLogItem"></param>
        /// <returns></returns>
        private Event Parse(ChatLogItem chatLogItem)
        {
            EventCode eventCode;
            var       code = Convert.ToUInt64(chatLogItem.Code, 16);

            if (this.EventCodes.TryGetValue(code, out eventCode))
            {
                return(new Event(eventCode, chatLogItem));
            }

            var unknownEventCode = new EventCode {
                Code = code,
            };

            return(new Event(unknownEventCode, chatLogItem));
        }
Beispiel #14
0
        private void Memory_OnChatReceived(ChatLogItem item)
        {
            string rtf = BmpChatParser.FormatChat(item);

            ChatLogAll.AppendRtf(rtf);

            Func <bool> cmdFunc = chatListener.GetChatCommand(item);

            if (cmdFunc != null)
            {
                ChatLogCmd.AppendRtf(rtf);
                if (cmdFunc())
                {
                    // successful command?
                }
            }
        }
        private static bool CheckRepetition(System.Collections.Concurrent.ConcurrentQueue <ChatLogItem> Log, ChatLogItem item)
        {
            if (item == null)
            {
                return(false);
            }
            if (item.Bytes == null)
            {
                return(false);
            }

            bool repetitonFlag = true;

            if (item.Line.Length > 1)
            {
                ChatLogItem previusChatLogItem = null;

                if (Log.TryPeek(out previusChatLogItem))
                {
                    if (!CheckChatEquality(previusChatLogItem, item))
                    {
                        while (Log.TryDequeue(out previusChatLogItem))
                        {
                            ;
                        }

                        //result.ChatLogItems.Add(chatLogItem);
                        repetitonFlag = false;

                        Log.Enqueue(item);
                    }
                }
                else
                {
                    Log.Enqueue(item);

                    //result.ChatLogItems.Add(chatLogItem);
                    repetitonFlag = false;
                }
            }

            /*if (repetitonFlag)
             *  item = null;//*/
            return(repetitonFlag);
        }
Beispiel #16
0
        private static void OnChatLogItemReceived(object sender, ChatLogItemEvent chatLogItemEvent)
        {
            // delegate event from chat log, not required to subsribe
            // this updates 100 times a second and only sends a line when it gets a new one
            if (sender == null)
            {
                return;
            }

            ChatLogItem chatLogItem = chatLogItemEvent.ChatLogItem;

            try {
                LogPublisher.Process(chatLogItem);
            }
            catch (Exception ex) {
                Logging.Log(Logger, new LogItem(ex, true));
            }
        }
Beispiel #17
0
        /// <summary>
        /// </summary>
        /// <param name="chatLogItem"></param>
        public void ParseAndPublish(ChatLogItem chatLogItem)
        {
            Event @event = this.Parse(chatLogItem);
            EventHandler <Event> eventHandler = @event.IsUnknown
                                                   ? this.OnUnknownLogEvent
                                                   : this.OnLogEvent;

            Console.WriteLine("ParseAndPublish eventHandler...");
            if (eventHandler == null)
            {
                return;
            }

            Console.WriteLine("   LOCKING AND CALLING!!!! ParseAndPublish eventHandler...");
            lock (eventHandler) {
                eventHandler(this, @event);
            }
        }
Beispiel #18
0
        public static void Process(ChatLogItem chatLogItem)
        {
            if (IsPaused)
            {
                return;
            }

            try {
                chatLogItem.Line = chatLogItem.Line.Replace("  ", " ");
                if (Constants.NeedGreed.Any(chatLogItem.Line.Contains))
                {
                    NeedGreedHistory.Add(chatLogItem.Line);
                }

                DispatcherHelper.Invoke(() => EventParser.Instance.ParseAndPublish(chatLogItem));
                HandleCommands(chatLogItem);
            }
            catch (Exception ex) {
                Logging.Log(Logger, new LogItem(ex, true));
            }
        }
Beispiel #19
0
        public Func <bool> GetChatCommand(ChatLogItem item)
        {
            if (GetCommand(item.Line, out Command command))
            {
                command.code = item.Code;

                if (!string.IsNullOrEmpty(command.target))
                {
                    if (Reader.CanGetPlayerInfo())
                    {
                        CurrentPlayerResult res = Reader.GetCurrentPlayer();
                        if (!command.target.Equals(res.CurrentPlayer.Name))
                        {
                            return(null);
                        }
                    }
                }

                return(new Func <bool>(() => FindChatCommand(command.command).Invoke(command)));
            }
            return(null);
        }
Beispiel #20
0
        public static void AppendChatLogItem(MemoryHandler memoryHandler, ChatLogItem chatLogItem, FlowDocumentReader reader)
        {
            DispatcherHelper.Invoke(
                () => {
                Span process = new Span(new Run($"[{memoryHandler.Configuration.ProcessModel.ProcessID}] "))
                {
                    Foreground = (Brush)_converter.Convert("#FFFFFFFF"),
                    FontWeight = FontWeights.Bold,
                };
                Span time = new Span(new Run(chatLogItem.TimeStamp.ToString("[HH:mm:ss] ")))
                {
                    Foreground = Brushes.MediumPurple,
                    FontWeight = FontWeights.Bold,
                };
                string lineColor = AppViewModel.Instance.ChatCodes.FirstOrDefault(code => code.Code.Equals(chatLogItem.Code))?.Color ?? "FFFFFF";
                Span line        = new Span(new Run(chatLogItem.Message))
                {
                    Foreground = (Brush)_converter.Convert($@"#{lineColor}"),
                };
                Paragraph paragraph = new Paragraph();
                paragraph.Inlines.Add(process);
                paragraph.Inlines.Add(time);
                if (!string.IsNullOrWhiteSpace(chatLogItem.PlayerName))
                {
                    Span playerLine = new Span(new Run($"[{chatLogItem.PlayerName}] "))
                    {
                        Foreground = (Brush)_converter.Convert("#FFFF00FF"),
                    };
                    paragraph.Inlines.Add(playerLine);
                }

                paragraph.Inlines.Add(line);
                reader.Document.Blocks.Add(paragraph);
                if (reader.Document.Blocks.LastBlock != null)
                {
                    reader.Document.Blocks.LastBlock.Loaded += MessageAdded;
                }
            });
        }
Beispiel #21
0
        public static ChatLogItem Process(byte[] raw)
        {
            ChatLogItem 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();
                string cleaned   = ChatCleaner.ProcessFullLine(chatLogEntry.Code, cleanable);
                if (cleaned.StartsWith(STARTS_WITH_CHECK))
                {
                    cleaned = cleaned.Substring(1);
                }

                int cut = cleaned.Substring(0, 2) == CLEANED_SUBSTRING_CHECK
                              ? 2
                              : 1;
                chatLogEntry.Message         = chatLogEntry.Line = XMLCleaner.SanitizeXmlString(cleaned.Substring(cut));
                chatLogEntry.IsInternational = IsInternational(chatLogEntry.Line);

                chatLogEntry.Combined = $"{chatLogEntry.Code}:{chatLogEntry.Line}";

                if (Constants.ChatPublic.Contains(chatLogEntry.Code))
                {
                    chatLogEntry.PlayerName = chatLogEntry.Line.Substring(0, chatLogEntry.Line.IndexOf(INDEX_CHECK, StringComparison.OrdinalIgnoreCase));
                    chatLogEntry.Message    = chatLogEntry.Message.Replace($"{chatLogEntry.PlayerName}: ", string.Empty);
                }
            }
            catch (Exception) {
                // IGNORED
            }

            return(chatLogEntry);
        }
        public static void Process(ChatLogItem chatLogItem)
        {
            try {
                var line = chatLogItem.Line.Replace("  ", " ");
                foreach (LogEvent item in PluginViewModel.Instance.Events.Where(e => e.Enabled))
                {
                    var resuccess = false;
                    var arguments = item.Arguments;
                    var tts       = item.TTS;
                    if (SharedRegEx.IsValidRegex(item.RegEx))
                    {
                        Match reg = Regex.Match(line, item.RegEx);
                        if (reg.Success)
                        {
                            resuccess = true;
                            arguments = reg.Result(item.Arguments);
                            tts       = reg.Result(tts);
                        }
                    }
                    else
                    {
                        resuccess = item.RegEx == line;
                    }

                    if (!resuccess)
                    {
                        continue;
                    }

                    ExecutLogEvent(item, arguments, tts);
                }
            }
            catch (Exception ex) {
                Logging.Log(Logger, new LogItem(ex, true));
            }
        }
Beispiel #23
0
        public static ChatLogItem GetDialogPanel()
        {
            var result = new ChatLogItem();

            if (!CanGetDialogPanel() || !MemoryHandler.Instance.IsAttached)
            {
                return(result);
            }

            Int16 chatCode   = 0x003d;
            byte  colonBytes = Convert.ToByte(':');

            byte[] chatCodeBytes = BitConverter.GetBytes(chatCode);

            var dialogPanelNamePointer       = (IntPtr)Scanner.Instance.Locations[Signatures.DialogPanelName];
            var dialogPanelNameLengthPointer = IntPtr.Subtract(dialogPanelNamePointer, MemoryHandler.Instance.Structures.DialogPanelPointers.LengtsOffset);

            var dialogPanelTextPointer = (IntPtr)Scanner.Instance.Locations[Signatures.DialogPanelText];
            var dialogPanelText        = new IntPtr(MemoryHandler.Instance.GetPlatformUInt(dialogPanelTextPointer));

            var dialogPanelTextLegthPointer = IntPtr.Add(dialogPanelTextPointer, MemoryHandler.Instance.Structures.DialogPanelPointers.TextLengthOffset);

            int nameLength = (int)MemoryHandler.Instance.GetPlatformInt(dialogPanelNameLengthPointer);
            int textLength = (int)MemoryHandler.Instance.GetPlatformInt(dialogPanelTextLegthPointer);

            if (textLength > 1 && nameLength > 1)
            {
                if (textLength > 512)
                {
                    textLength = 512;
                }
                if (nameLength > 128)
                {
                    nameLength = 128;
                }

                byte[] npcNameBytes = MemoryHandler.Instance.GetByteArray(dialogPanelNamePointer, nameLength);
                byte[] textBytes    = MemoryHandler.Instance.GetByteArray(dialogPanelText, textLength);

                nameLength = GetRealTextLength(ref npcNameBytes);
                textLength = GetRealTextLength(ref textBytes);

                Int32  unixTimestamp      = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
                byte[] unixTimestampBytes = BitConverter.GetBytes(unixTimestamp).ToArray();

                List <byte> rawBytesList = new List <byte>(unixTimestampBytes.Length + chatCodeBytes.Length + 1 +
                                                           npcNameBytes.Length + 1 + textBytes.Length);

                rawBytesList.AddRange(unixTimestampBytes);
                rawBytesList.AddRange(chatCodeBytes);
                rawBytesList.AddRange(new Byte[] { 0x00, 0x00 });
                rawBytesList.Add(colonBytes);
                rawBytesList.AddRange(npcNameBytes);
                rawBytesList.Add(colonBytes);
                rawBytesList.AddRange(textBytes);


                ChatLogItem chatLogItem = ChatEntry.Process(rawBytesList.ToArray());

                String onlyLettersLine = new String(chatLogItem.Line.Where(Char.IsLetter).ToArray());

                if (onlyLettersLine.Length > chatLogItem.Line.Length / GlobalSettings.LineLettersCoefficient)
                {
                    result = chatLogItem;
                }
            }
            return(result);
        }
Beispiel #24
0
        public static ChatLogItem GetCutsceneText()
        {
            ChatLogItem result = new ChatLogItem();

            if (!CanGetCutScene() || !MemoryHandler.Instance.IsAttached)
            {
                return(result);
            }

            Int16 chatCode   = 0x0044;
            byte  colonBytes = Convert.ToByte(':');
            byte  dotBytes   = Convert.ToByte('.');
            byte  spaceBytes = Convert.ToByte(' ');

            byte[] chatCodeBytes = BitConverter.GetBytes(chatCode);

            try
            {
                var cutsceneTextPointer1 = (IntPtr)Scanner.Instance.Locations[Signatures.CutsceneText1];

                var cutsceneTextLengthPointer = (IntPtr)Scanner.Instance.Locations[Signatures.CutsceneTextLength];
                var cutsceneDetector          = (IntPtr)Scanner.Instance.Locations[Signatures.CutsceneDetector];

                int textLength = (int)MemoryHandler.Instance.GetPlatformInt(cutsceneTextLengthPointer);
                int isCutscene = (int)MemoryHandler.Instance.GetPlatformInt(cutsceneDetector);

                if (textLength < 2 || isCutscene == 1)
                {
                    return(result);
                }


                byte[] cutsceneBytesRaw1 = MemoryHandler.Instance.GetByteArray(cutsceneTextPointer1, 256);

                int textEnd1 = GetRealTextLength(ref cutsceneBytesRaw1);

                if (textEnd1 > 2)
                {
                    byte[] cutsceneBytes1 = cutsceneBytesRaw1;

                    Int32  unixTimestamp      = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
                    byte[] unixTimestampBytes = BitConverter.GetBytes(unixTimestamp).ToArray();


                    byte[] npcNameBytes = new byte[3];
                    npcNameBytes[0] = dotBytes;
                    npcNameBytes[1] = dotBytes;
                    npcNameBytes[2] = dotBytes;

                    List <byte> rawBytesList = new List <byte>(unixTimestampBytes.Length + chatCodeBytes.Length + 1 +
                                                               npcNameBytes.Length + 1 + cutsceneBytes1.Length);

                    rawBytesList.AddRange(unixTimestampBytes);
                    rawBytesList.AddRange(chatCodeBytes);
                    rawBytesList.AddRange(new Byte[] { 0x00, 0x00 });
                    rawBytesList.Add(colonBytes);
                    rawBytesList.AddRange(npcNameBytes);
                    rawBytesList.Add(colonBytes);
                    rawBytesList.AddRange(cutsceneBytes1);

                    ChatLogItem chatLogItem = ChatEntry.Process(rawBytesList.ToArray());

                    if (textEnd1 > 2)
                    {
                        String onlyLettersLine = new String(chatLogItem.Line.Where(Char.IsLetter).ToArray());

                        if (onlyLettersLine.Length > chatLogItem.Line.Length / GlobalSettings.LineLettersCoefficient)
                        {
                            result = chatLogItem;
                        }
                    }
                }

                if (result?.Line != null)
                {
                    if (result.Line.Contains("]") && result.Line.Contains("["))
                    {
                        return(new ChatLogItem());
                    }
                }
            }
            catch (Exception)
            {
                result = new ChatLogItem();
            }

            return(result);
        }
Beispiel #25
0
        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);
        }
Beispiel #26
0
        private void Memory_OnChatReceived(ChatLogItem item)
        {
            string rtf = BmpChatParser.FormatChat(item);

            ChatLogAll.AppendRtf(rtf);
        }
Beispiel #27
0
 public void RaiseChatLogItemReceived(ChatLogItem chatLogItem)
 {
     PluginHost.Instance.RaiseChatLogItemReceived(chatLogItem);
 }
 public ChatLogItemEvent(object sender, ChatLogItem chatLogItem)
 {
     this.Sender      = sender;
     this.ChatLogItem = chatLogItem;
 }
Beispiel #29
0
        private void UpdateChatbox(object state)
        {
            if (ChatQueue.q.Any())
            {// Should q be locked?
                var chat = ChatQueue.q.Take();
                int.TryParse(chat.Code, System.Globalization.NumberStyles.HexNumber, null, out var intCode);
                ChatCode code = (ChatCode)intCode;
                if (code <= ChatCode.CWLinkShell8)
                {// For now, CWLinkShell8(0x6B) is upper bound of chat related code.
                    if (ironworksSettings.Chat.ChannelVisibility.TryGetValue(code, out bool show))
                    {
                        if (show)
                        {
                            string      line        = chat.Line;
                            ChatLogItem decodedChat = chat.Bytes.DecodeAutoTranslate();
                            Log.Debug("Chat: {@Chat}", decodedChat);

                            if (code == ChatCode.Recruitment || code == ChatCode.System || code == ChatCode.Error ||
                                code == ChatCode.Notice || code == ChatCode.Emote || code == ChatCode.MarketSold)
                            {
                                if (!ContainsNativeLanguage(decodedChat.Line))
                                {
                                    var translated = ironworksContext.TranslateChat(decodedChat.Line, ironworksSettings.Chat.ChannelLanguage[code]);

                                    Application.Current.Dispatcher.Invoke(() =>
                                    {
                                        TranslatedChatBox.Text +=
#if DEBUG
                                            $"[{decodedChat.Code}]{translated}{Environment.NewLine}";
#else
                                            $"{translated}{Environment.NewLine}";
#endif
                                    });
                                }
                            }
                            else
                            {
                                var author   = decodedChat.Line.RemoveAfter(":");
                                var sentence = decodedChat.Line.RemoveBefore(":");
                                if (!ContainsNativeLanguage(decodedChat.Line))
                                {
                                    var translated = ironworksContext.TranslateChat(sentence, ironworksSettings.Chat.ChannelLanguage[code]);

                                    Application.Current.Dispatcher.Invoke(() =>
                                    {
                                        TranslatedChatBox.Text +=
#if DEBUG
                                            $"[{decodedChat.Code}]{author}:{translated}{Environment.NewLine}";
#else
                                            $"{author}:{translated}{Environment.NewLine}";
#endif
                                    });
                                }
                            }
                        }
                    }
                    else
                    {
                        Log.Information("Unexpected {@Code} when translating {@Message}", intCode, chat.Line);
                        //Application.Current.Dispatcher.Invoke(() =>
                        //{
                        //    TranslatedChatBox.Text +=
                        //$"[모르는 채널-제보요망][{chat.Code}]{chat.Line}{Environment.NewLine}";
                        //});
                    }
                }
                else
                {
                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        TranslatedChatBox.Text +=
#if DEBUG
                            $"[???][{chat.Code}]{chat.Line}{Environment.NewLine}";
#else
                            $"[???]{chat.Line}{Environment.NewLine}";
#endif
                    });
                }
                Application.Current.Dispatcher.Invoke(() =>
                {
                    TranslatedChatBox.ScrollToEnd();
                    //TranslatedChatBox.ScrollToVerticalOffset(double.MaxValue);
                });
            }
        }
Beispiel #30
0
        public static string Fixup(ChatLogItem item)
        {
            Regex  rgx    = new Regex("^([^ ]+ [^:]+):(.+)");
            string format = rgx.Replace(item.Line, "$1: $2");

            switch (item.Code)
            {
            case "000E": {                     // Party
                int pid = (int)(format[0] & 0xF) + 1;
                format = string.Format("[{0}] {1}", pid, format.Substring(1));
                break;
            }

            case "000D": {                     // PM receive
                if (format.IndexOf(": ") != -1)
                {
                    format = format.Replace(": ", " >> ");
                }
                break;
            }

            case "000C": {                     // PM Send
                if (format.IndexOf(": ") != -1)
                {
                    format = ">> " + format;
                }
                break;
            }

            case "001B": {                     // Novice Network
                format = "[NN] " + format;
                break;
            }

            case "001C": {                     // Custom Emote
                if (format.IndexOf(": ") != -1)
                {
                    format = format.Replace(": ", "");
                }
                break;
            }

            case "001D": {                     // Standard Emote
                if (format.IndexOf(": ") != -1)
                {
                    format = format.Substring(format.IndexOf(": ") + 2);
                }
                break;
            }

            case "0018": {                     // FC
                format = string.Format("<FC> {0}", format);
                break;
            }

            case "0010":
            case "0011":
            case "0012":
            case "0013":
            case "0014":
            case "0015":
            case "0016":
            case "0017": {                     // LS
                int ls = int.Parse(item.Code.Substring(3)) + 1;
                format = string.Format("[{0}] {1}", ls, format);
                break;
            }

            default: {
                break;
            }
            }
            return(format);
        }