Exemplo n.º 1
0
        /// <summary>
        /// Only supports writing to an existing btx0 atm
        /// </summary>
        /// <param name="file"></param>
        public void WriteTo(string file)
        {
            using (var bw = new BinaryWriter(File.OpenWrite(file)))
            {
                var header = new GenericFileHeader
                {
                    MagicNumber     = MagicNumber,
                    ByteOrderMarker = 0xFEFF,
                    Version         = 1,
                    ChunkCount      = 1,
                    HeaderLength    = 0x10
                };

                // skip header section, to be written later
                bw.BaseStream.Seek(header.HeaderLength + 4 * header.ChunkCount, SeekOrigin.Begin);

                uint[] chunkOffsets = new uint[header.ChunkCount];

                // write TEX0
                chunkOffsets[0] = (uint)(bw.BaseStream.Position);
                Texture.WriteTo(bw);

                // return to start to write header
                var endOffset = bw.BaseStream.Position;
                bw.BaseStream.Position = 0;

                header.FileLength = (uint)endOffset;
                header.WriteTo(bw);
                foreach (var chunkOffset in chunkOffsets)
                {
                    bw.Write(chunkOffset);
                }
            }
        }
Exemplo n.º 2
0
        public NCLR(BinaryReader br)
        {
            long initOffset = br.BaseStream.Position;

            // first a typical file header
            var header = new GenericFileHeader(br);

            if (header.MagicNumber != MagicNumber)
            {
                throw new InvalidDataException($"Unexpected magic number in file header '{header.MagicNumber}' at offset 0x{initOffset:X} (expected: {MagicNumber})");
            }

            // read
            Palettes = new PLTT(br);

            br.BaseStream.Position = initOffset + header.FileLength;
        }
Exemplo n.º 3
0
        public NCER(BinaryReader br)
        {
            long initOffset = br.BaseStream.Position;

            // first a typical file header
            var header = new GenericFileHeader(br);

            if (header.MagicNumber != MagicNumber)
            {
                throw new InvalidDataException($"Unexpected magic number in file header '{header.MagicNumber}' at offset 0x{initOffset:X} (expected: {MagicNumber})");
            }


            // read
            CellBanks = new CEBK(br);
            Labels    = new LABL(br, CellBanks.Banks.Count);
            Unknown   = new UEXT(br);

            br.BaseStream.Position = initOffset + header.FileLength;
        }
Exemplo n.º 4
0
        public BTX0(string file)
        {
            using (var br = new BinaryReader(File.OpenRead(file)))
            {
                // first a typical file header
                var header = new GenericFileHeader(br);

                if (header.MagicNumber != MagicNumber)
                {
                    throw new InvalidDataException($"Unexpected magic number in file header '{header.MagicNumber}' (expected: {MagicNumber})");
                }

                // thing that this format does that other formats don't seem to do.
                uint[] chunkOffsets = new uint[header.ChunkCount];
                for (int i = 0; i < header.ChunkCount; i++)
                {
                    chunkOffsets[i] = br.ReadUInt32();
                }

                // read TEX0
                br.BaseStream.Position = chunkOffsets[0];
                Texture = new TEX0(br);
            }
        }