示例#1
0
        private static CharacterTableInfo ReadCharacterTableInfo(BinaryReader br)
        {
            var chrTableInfo = new CharacterTableInfo
            {
                StartCharacter     = br.ReadInt32(),
                CharacterCount     = br.ReadInt16(),
                CharacterHeight    = br.ReadInt16(),
                WidthTableOffset   = br.ReadInt64(),
                PointerTableOffset = br.ReadInt64(),
                DataOffset         = br.ReadInt64()
            };

            return(chrTableInfo);
        }
示例#2
0
        public static IDictionary <int, Character> ReadGameFont(byte[] data)
        {
            var chars = new Dictionary <int, Character>();

            using (var ms = new MemoryStream(data))
                using (var br = new BinaryReader(ms))
                {
                    // Cabecera UFNF
                    var ufnfHeader = ReadHeader(br);
                    var utf8Header = ReadHeader(br);
                    var mfntHeader = ReadHeader(br);

                    var baseOffset = br.BaseStream.Position;

                    var unknown1 = br.ReadInt32(); // Es 0x00000003
                    var width    = br.ReadInt16();
                    var height   = br.ReadInt16();
                    var unknown2 = br.ReadInt64(); // Es 0x00000003
                    br.BaseStream.Seek(0x10, SeekOrigin.Current);

                    var characterTableOffset = br.ReadInt64();
                    var characterTableCount  = br.ReadInt32();
                    var characterCount       = br.ReadInt32(); // Número total de caracteres

                    br.BaseStream.Seek(baseOffset + characterTableOffset, SeekOrigin.Begin);
                    var characterTables = new CharacterTableInfo[characterTableCount];
                    for (var i = 0; i < characterTableCount; i++)
                    {
                        characterTables[i] = ReadCharacterTableInfo(br);
                        if (characterTables[i].CharacterHeight == 0)
                        {
                            characterTables[i].CharacterHeight = height;
                        }
                    }

                    foreach (var characterTable in characterTables)
                    {
                        var currentChars = ReadChars(br, characterTable, baseOffset);

                        foreach (var chr in currentChars)
                        {
                            chars.Add(chr.Index, chr);
                        }
                    }
                }

            return(chars);
        }
示例#3
0
        private static IList <Character> ReadChars(BinaryReader br, CharacterTableInfo characterTable, long baseOffset)
        {
            var result = new List <Character>();

            br.BaseStream.Seek(baseOffset + characterTable.WidthTableOffset, SeekOrigin.Begin);

            var widths = new byte[characterTable.CharacterCount];

            for (var i = 0; i < characterTable.CharacterCount; i++)
            {
                widths[i] = br.ReadByte();
            }

            br.BaseStream.Seek(baseOffset + characterTable.PointerTableOffset, SeekOrigin.Begin);
            var pointers = new int[characterTable.CharacterCount];
            var sizes    = new int[characterTable.CharacterCount];

            for (var i = 0; i < characterTable.CharacterCount; i++)
            {
                pointers[i] = br.ReadInt32();
            }

            for (var i = 0; i < characterTable.CharacterCount; i++)
            {
                sizes[i] = (int)Math.Ceiling(widths[i] / 2.0 * characterTable.CharacterHeight);
            }

            //br.BaseStream.Seek(baseOffset + characterTable.DataOffset, SeekOrigin.Begin);
            for (var index = 0; index < pointers.Length; index++)
            {
                br.BaseStream.Seek(baseOffset + characterTable.DataOffset + pointers[index], SeekOrigin.Begin);
                var chr = new Character
                {
                    Index  = characterTable.StartCharacter + index,
                    Width  = widths[index],
                    Height = characterTable.CharacterHeight,
                    Data   = br.ReadBytes(sizes[index])
                };

                result.Add(chr);
            }

            return(result);
        }