Ejemplo n.º 1
0
        public static ChatLogItem DecodeAutoTranslate(this byte[] rawMessage)
        {
            //List<byte[]> result = new List<byte[]>();
            List <byte> rawResult = new List <byte>();
            var         test      = Encoding.UTF8.GetBytes("[定型文]");

            /*
             * \u0002 \002E \u0004 \u0002 \u00F0 \u00CF \u0003
             * \u0002 \002E \u0003 \u0002 \u00CA \u0003
             * \u0002 \002E \u0005 \u0004 \u00F2 \u0001 \u0095 \u0003
             */
            for (int i = 0; i < rawMessage.Length; i++)
            {
                if (rawMessage[i].Equals(0x02)) // STX
                {
                    if (i + 1 == rawMessage.Length)
                    {// Bound check
                        rawResult.Add(rawMessage[i]);
                        continue;
                    }
                    if (!rawMessage[i + 1].Equals(0x2E))
                    {// it should be char '.'(=0x2E)
                        rawResult.Add(rawMessage[i]);
                        continue;
                    }
                    byte range = rawMessage[i + 2];
                    if (i + range > rawMessage.Length)
                    {
                        rawResult.Add(rawMessage[i]);
                        continue;
                    }

                    if (rawMessage[i + range + 2].Equals(0x03)) // ETX
                    {                                           // Found AutoTranslate block
                        byte[] autoTranslate = new byte[range - 1];
                        Array.Copy(rawMessage, i + 3, autoTranslate, 0, range - 1);
                        //result.Add(autoTranslate);
                        rawResult.AddRange(test);
                        i = i + range + 2;
                    }
                    else
                    {
                        rawResult.Add(rawMessage[i]);
                    }
                }
                else
                {
                    rawResult.Add(rawMessage[i]);
                }
            }

            return(ChatEntry.Process(rawResult.ToArray()));
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
        public ChatLogResult GetChatLog(int previousArrayIndex = 0, int previousOffset = 0)
        {
            ChatLogResult result = new ChatLogResult();

            if (!this.CanGetChatLog() || !this._memoryHandler.IsAttached)
            {
                return(result);
            }

            this._chatLogReader.PreviousArrayIndex = previousArrayIndex;
            this._chatLogReader.PreviousOffset     = previousOffset;

            IntPtr chatPointerAddress = this._memoryHandler.Scanner.Locations[Signatures.CHATLOG_KEY];

            if (chatPointerAddress.ToInt64() <= 20)
            {
                return(result);
            }

            List <byte[]> bufferList = new List <byte[]>();

            try {
                this._chatLogReader.ChatLogPointers = new ChatLogPointers {
                    LineCount        = this._memoryHandler.GetUInt32(chatPointerAddress),
                    OffsetArrayStart = this._memoryHandler.GetInt64(chatPointerAddress, this._memoryHandler.Structures.ChatLogPointers.OffsetArrayStart),
                    OffsetArrayPos   = this._memoryHandler.GetInt64(chatPointerAddress, this._memoryHandler.Structures.ChatLogPointers.OffsetArrayPos),
                    OffsetArrayEnd   = this._memoryHandler.GetInt64(chatPointerAddress, this._memoryHandler.Structures.ChatLogPointers.OffsetArrayEnd),
                    LogStart         = this._memoryHandler.GetInt64(chatPointerAddress, this._memoryHandler.Structures.ChatLogPointers.LogStart),
                    LogNext          = this._memoryHandler.GetInt64(chatPointerAddress, this._memoryHandler.Structures.ChatLogPointers.LogNext),
                    LogEnd           = this._memoryHandler.GetInt64(chatPointerAddress, this._memoryHandler.Structures.ChatLogPointers.LogEnd),
                };

                long currentArrayIndex = (this._chatLogReader.ChatLogPointers.OffsetArrayPos - this._chatLogReader.ChatLogPointers.OffsetArrayStart) / 4;
                if (this._chatLogReader.ChatLogFirstRun)
                {
                    this._chatLogReader.EnsureArrayIndexes();
                    this._chatLogReader.ChatLogFirstRun    = false;
                    this._chatLogReader.PreviousOffset     = this._chatLogReader.Indexes[(int)currentArrayIndex - 1];
                    this._chatLogReader.PreviousArrayIndex = (int)currentArrayIndex - 1;
                }
                else
                {
                    if (currentArrayIndex < this._chatLogReader.PreviousArrayIndex)
                    {
                        IEnumerable <byte[]> bufferEntries = this._chatLogReader.ResolveEntries(this._chatLogReader.PreviousArrayIndex, 1000);
                        bufferList.AddRange(bufferEntries);
                        this._chatLogReader.PreviousOffset     = 0;
                        this._chatLogReader.PreviousArrayIndex = 0;
                    }

                    if (this._chatLogReader.PreviousArrayIndex < currentArrayIndex)
                    {
                        IEnumerable <byte[]> bufferEntries = this._chatLogReader.ResolveEntries(this._chatLogReader.PreviousArrayIndex, (int)currentArrayIndex);
                        bufferList.AddRange(bufferEntries);
                    }

                    this._chatLogReader.PreviousArrayIndex = (int)currentArrayIndex;
                }
            }
            catch (Exception ex) {
                this._memoryHandler.RaiseException(Logger, ex);
            }

            foreach (byte[] bytes in bufferList)
            {
                if (!bytes.Any())
                {
                    continue;
                }

                try {
                    ChatLogItem chatLogEntry = ChatEntry.Process(bytes);

                    // assign logged user for this instance to chatLogEntry
                    chatLogEntry.PlayerCharacterName = this._pcWorkerDelegate.CurrentUser?.Name ?? UNRESOLVED;

                    if (Regex.IsMatch(chatLogEntry.Combined, @"[\w\d]{4}::?.+"))
                    {
                        result.ChatLogItems.Enqueue(chatLogEntry);
                    }
                }
                catch (Exception ex) {
                    this._memoryHandler.RaiseException(Logger, ex);
                }
            }

            result.PreviousArrayIndex = this._chatLogReader.PreviousArrayIndex;
            result.PreviousOffset     = this._chatLogReader.PreviousOffset;

            return(result);
        }