コード例 #1
0
        /// <summary>
        ///     Gets a generic section from the file.
        /// </summary>
        /// <param name="input">BinaryReader of the data</param>
        /// <returns></returns>
        private static List <sectionEntry> getSection(BinaryReader input)
        {
            uint baseAddress = (uint)input.BaseStream.Position;

            input.BaseStream.Seek(0x10, SeekOrigin.Current); //Section magic number (padded with 0x0)
            uint addressCount = input.ReadUInt32();

            baseAddress += input.ReadUInt32();
            uint addressSectionLength = input.ReadUInt32();

            input.ReadUInt32(); //Padding

            List <sectionEntry> sections = new List <sectionEntry>();

            for (int i = 0; i < addressCount; i++)
            {
                sectionEntry entry = new sectionEntry();

                entry.offset = input.ReadUInt32() + baseAddress;
                entry.length = input.ReadUInt32();

                sections.Add(entry);
            }

            return(sections);
        }
コード例 #2
0
        /// <summary>
        ///     Reads FPT0 containers from Dragon Quest VII.
        /// </summary>
        /// <param name="data">Stream with container data</param>
        /// <returns></returns>
        public static OContainer load(Stream data)
        {
            BinaryReader input  = new BinaryReader(data);
            OContainer   output = new OContainer();

            data.Seek(8, SeekOrigin.Begin);
            uint entries     = input.ReadUInt32();
            uint baseAddress = 0x10 + (entries * 0x20) + 0x80;

            input.ReadUInt32();

            List <sectionEntry> files = new List <sectionEntry>();

            for (int i = 0; i < entries; i++)
            {
                sectionEntry entry = new sectionEntry();

                entry.name = IOUtils.readString(input, (uint)(0x10 + (i * 0x20)));
                data.Seek(0x20 + (i * 0x20), SeekOrigin.Begin);
                input.ReadUInt32(); //Memory address?
                entry.offset = input.ReadUInt32() + baseAddress;
                entry.length = input.ReadUInt32();
                input.ReadUInt32(); //Padding?

                files.Add(entry);
            }

            foreach (sectionEntry file in files)
            {
                OContainer.fileEntry entry = new OContainer.fileEntry();

                data.Seek(file.offset, SeekOrigin.Begin);
                byte[] buffer = new byte[file.length];
                input.Read(buffer, 0, buffer.Length);
                entry.data = buffer;
                entry.name = file.name;

                output.content.Add(entry);
            }

            data.Close();

            return(output);
        }
コード例 #3
0
ファイル: FPT0.cs プロジェクト: PokeD/Ohana3DS-Rebirth
        /// <summary>
        ///     Reads FPT0 containers from Dragon Quest VII.
        /// </summary>
        /// <param name="data">Stream with container data</param>
        /// <returns></returns>
        public static GenericContainer.OContainer load(Stream data)
        {
            BinaryReader input = new BinaryReader(data);
            GenericContainer.OContainer output = new GenericContainer.OContainer();

            output.fileIdentifier = IOUtils.readString(input, 0, 4); //FPT0 magic
            input.ReadUInt32();
            uint entries = input.ReadUInt32();
            uint baseAddress = 0x10 + (entries * 0x20) + 0x80;
            input.ReadUInt32();

            List<sectionEntry> files = new List<sectionEntry>();
            for (int i = 0; i < entries; i++)
            {
                sectionEntry entry = new sectionEntry();

                entry.name = IOUtils.readString(input, (uint)(0x10 + (i * 0x20)));
                data.Seek(0x20 + (i * 0x20), SeekOrigin.Begin);
                input.ReadUInt32(); //Memory address?
                entry.offset = input.ReadUInt32() + baseAddress;
                entry.length = input.ReadUInt32();
                input.ReadUInt32(); //Padding?

                files.Add(entry);
            }

            foreach (sectionEntry file in files)
            {
                GenericContainer.OContainerEntry entry = new GenericContainer.OContainerEntry();

                data.Seek(file.offset, SeekOrigin.Begin);
                byte[] buffer = new byte[file.length];
                input.Read(buffer, 0, buffer.Length);
                entry.data = buffer;
                entry.name = file.name;

                output.content.Add(entry);
            }

            data.Close();

            return output;
        }
コード例 #4
0
        /// <summary>
        ///     Gets a generic section from the file.
        /// </summary>
        /// <param name="input">BinaryReader of the data</param>
        /// <returns></returns>
        private static List<sectionEntry> getSection(BinaryReader input)
        {
            uint baseAddress = (uint)input.BaseStream.Position;
            input.BaseStream.Seek(0x10, SeekOrigin.Current); //Section magic number (padded with 0x0)
            uint addressCount = input.ReadUInt32();
            baseAddress += input.ReadUInt32();
            uint addressSectionLength = input.ReadUInt32();
            input.ReadUInt32(); //Padding

            List<sectionEntry> sections = new List<sectionEntry>();
            for (int i = 0; i < addressCount; i++)
            {
                sectionEntry entry = new sectionEntry();

                entry.offset = input.ReadUInt32() + baseAddress;
                entry.length = input.ReadUInt32();

                sections.Add(entry);
            }

            return sections;
        }