Пример #1
0
        public int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex)
        {
            int result = 0;

            while (byteCount > 0)
            {
                FFXIIITextTag tag = FFXIIITextTag.TryRead(bytes, ref byteIndex, ref byteCount);
                if (tag != null)
                {
                    result += tag.Write(chars, ref charIndex);
                    continue;
                }

                FFXIIITextReference reference = FFXIIITextReference.TryRead(bytes, ref byteIndex, ref byteCount);
                if (reference != null)
                {
                    result += reference.Write(chars, ref charIndex);
                    continue;
                }

                int value = bytes[byteIndex++];
                byteCount--;
                if (value >= 0x80)
                {
                    value = FFXIIIEncodingMap.ValueToIndex(value, bytes[byteIndex++]);
                    byteCount--;
                }
                chars[charIndex++] = _codepage[(short)value];
                result++;
            }

            return(result);
        }
        private static int GetEndingTags(string text, StringBuilder sb)
        {
            int index = text.Length - 1;

            if (index < 0)
            {
                return(0);
            }

            while (text[index] == '}')
            {
                index = text.LastIndexOf('{', index - 1) - 1;
                if (index < 0)
                {
                    break;
                }
            }

            if (index == text.Length - 1)
            {
                return(0);
            }

            char[] chars = index < 0 ? text.ToCharArray() : text.ToCharArray(index + 1, text.Length - index - 1);

            int           offset = 0;
            int           left   = chars.Length;
            int           result = left;
            FFXIIITextTag tag;

            while (left > 0 && (tag = FFXIIITextTag.TryRead(chars, ref offset, ref left)) != null)
            {
                switch (tag.Code)
                {
                case FFXIIITextTagCode.End:
                case FFXIIITextTagCode.Escape:
                case FFXIIITextTagCode.Text:
                    sb.Append(tag);
                    break;

                default:
                    result = left;
                    sb.Clear();
                    break;
                }
            }

            if (left != 0)
            {
                Log.Warning("[ArchiveEntryInjectorStringsToZtr.GetEndingTags] Unexpected escape sequence: {0}", text);
            }

            return(result);
        }
Пример #3
0
        public int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex)
        {
            int result = 0;

            while (charCount > 0)
            {
                FFXIIITextTag tag = FFXIIITextTag.TryRead(chars, ref charIndex, ref charCount);
                if (tag != null)
                {
                    result += tag.Write(bytes, ref byteIndex);
                    continue;
                }

                FFXIIITextReference reference = FFXIIITextReference.TryRead(chars, ref charIndex, ref charCount);
                if (reference != null)
                {
                    result += reference.Write(bytes, ref byteIndex);
                    continue;
                }

                short value = _codepage[chars[charIndex++]];

                int hight, low;
                FFXIIIEncodingMap.IndexToValue(value, out hight, out low);

                if (hight != 0)
                {
                    bytes[byteIndex++] = (byte)hight;
                    result++;
                }

                bytes[byteIndex++] = (byte)low;
                charCount--;
                result++;
            }

            return(result);
        }
Пример #4
0
        public int GetByteCount(char[] chars, int index, int count)
        {
            int result = 0;

            byte[] buff = new byte[2];
            while (count > 0)
            {
                FFXIIITextTag tag = FFXIIITextTag.TryRead(chars, ref index, ref count);
                if (tag != null)
                {
                    int offset = 0;
                    result += tag.Write(buff, ref offset);
                    continue;
                }

                FFXIIITextReference reference = FFXIIITextReference.TryRead(chars, ref index, ref count);
                if (reference != null)
                {
                    result += reference.SizeInBytes;
                    continue;
                }

                short value = _codepage[chars[index++]];

                int hight, low;
                FFXIIIEncodingMap.IndexToValue(value, out hight, out low);

                if (hight != 0)
                {
                    result++;
                }

                result++;
                count--;
            }

            return(result);
        }
Пример #5
0
        public int GetCharCount(byte[] bytes, int index, int count)
        {
            int result = 0;

            char[] buff = new char[FFXIIITextTag.MaxTagLength];
            while (count > 0)
            {
                FFXIIITextTag tag = FFXIIITextTag.TryRead(bytes, ref index, ref count);
                if (tag != null)
                {
                    int offset = 0;
                    result += tag.Write(buff, ref offset);
                    continue;
                }

                FFXIIITextReference reference = FFXIIITextReference.TryRead(bytes, ref index, ref count);
                if (reference != null)
                {
                    result += reference.SizeInChars;
                    continue;
                }

                byte value = bytes[index++];
                count--;

                if (value >= 0x80)
                {
                    index++;
                    count--;
                }

                result++;
            }

            return(result);
        }