예제 #1
0
        public void Read(BinaryReader br, int offset)
        {
            location = offset;
            br.BaseStream.Position = offset;

            version       = br.ReadInt16();
            charCount     = br.ReadInt16();
            charTableSize = br.ReadInt16();
            charDataSize  = br.ReadInt16();

            //read in table
            for (int i = 0; i < charCount; i++)
            {
                var _charindex = br.ReadUInt16();
                var _fontindex = br.ReadInt16();
                int _offset    = br.ReadInt32();

                charDatum datum = new charDatum()
                {
                    characterCode = _charindex, fontIndex = _fontindex
                };

                BlockCharEntry Index = new BlockCharEntry()
                {
                    index = datum, dataOffset = _offset
                };

                charTable.Add(Index);
            }

            //read in data
            for (int i = 0; i < charTable.Count; i++)
            {
                CharacterData charinfo = new CharacterData();
                charinfo.Read(br, (location + charTable[i].dataOffset));

                charData.Add(charinfo);
            }
        }
예제 #2
0
        /// <summary>
        /// Loads a font package from the given file.
        /// </summary>
        /// <returns>0 = success, 1 = bad header version, 2 = font count is zero</returns>
        public int Load(string filename)
        {
            FileStream   fs = new FileStream(filename, FileMode.Open);
            BinaryReader br = new BinaryReader(fs);

            ms = new MemoryStream(br.ReadBytes((int)br.BaseStream.Length));
            fs.Close();
            br = new BinaryReader(ms);

            br.BaseStream.Position = 0;

            //Make sure this is a font package
            var fileMagic = br.ReadUInt32();

            if (fileMagic != 0xC0000003)
            {
                ms.Close();
                br.Close();
                return(1);
            }

            int fontCount = br.ReadInt32();

            if (fontCount <= 0)
            {
                ms.Close();
                br.Close();
                return(2);
            }

            maxFontCount = 16;

            //check to see if package belongs to Halo 4
            var maxcounthack = br.ReadInt32();

            if (maxcounthack == 1048)
            {
                maxFontCount = 64;
            }

            //get the font headers info
            br.BaseStream.Position -= 4;
            for (int i = 0; i < maxFontCount; i++)
            {
                FontEntries.Add(new FontHeaderInfo()
                {
                    offset     = br.ReadInt32(),
                    size       = br.ReadInt32(),
                    startBlock = br.ReadInt16(),
                    blockCount = br.ReadInt16()
                });
            }

            //read engine ordering
            for (int i = 0; i < maxFontCount; i++)
            {
                OrderList.Add(br.ReadInt32());
            }

            int headerTableOffset = br.ReadInt32();
            int headerTableSize   = br.ReadInt32();

            BlockRangesOffset = br.ReadInt32();
            int blockCount = br.ReadInt32();

            br.BaseStream.Position = BlockRangesOffset;

            for (int i = 0; i < blockCount; i++)
            {
                var startchar = br.ReadUInt16();
                var startfont = br.ReadInt16();

                var endchar = br.ReadUInt16();
                var endfont = br.ReadInt16();

                charDatum start = new charDatum()
                {
                    characterCode = startchar, fontIndex = startfont
                };
                charDatum end = new charDatum()
                {
                    characterCode = endchar, fontIndex = endfont
                };

                BlockRange range = new BlockRange()
                {
                    startIndex = start, endIndex = end
                };

                BlockRanges.Add(range);
            }

            //read data blocks

            //set position for hax to check for h4b
            br.BaseStream.Position = 0x8000;

            ChunkSize = 0x8000;

            if (maxFontCount == 64 & br.ReadInt16() != 8)            //blocks seem to have a short value of 8 as some header or version
            {
                ChunkSize = 0xC000;
            }

            for (int i = 0; i < blockCount; i++)
            {
                Block dataBlock = new Block();
                dataBlock.Read(br, ChunkSize + (i * ChunkSize));

                Blocks.Add(dataBlock);
            }

            //read font headers and find its characters
            for (int i = 0; i < fontCount; i++)
            {
                var tempfont = new PackageFont();
                br.BaseStream.Position = FontEntries[i].offset;
                tempfont.ReadHeader(br);

                for (int bl = FontEntries[i].startBlock; bl < (FontEntries[i].startBlock + FontEntries[i].blockCount); bl++)
                {
                    for (int ch = 0; ch < Blocks[bl].charCount; ch++)
                    {
                        if (Blocks[bl].charTable[ch].index.fontIndex == i)
                        {
                            var tempchar = new FontCharacter(Blocks[bl].charTable[ch].index.characterCode, Blocks[bl].charData[ch]);

                            tempfont.Characters.Add(tempchar);
                        }
                    }
                }
                Fonts.Add(tempfont);
            }

            br.Close();
            ms.Close();
            return(0);
        }