Exemple #1
0
        public static sFile[] ReadBasicOverlays(Stream input, uint offset, uint size, bool arm9, sFAT[] fat)
        {
            using (var br = new BinaryReaderX(input, true))
            {
                sFile[] overlays = new sFile[size / 0x20];

                br.BaseStream.Position = offset;

                for (int i = 0; i < overlays.Length; i++)
                {
                    overlays[i]      = new sFile();
                    overlays[i].name = "overlay" + (arm9 ? '9' : '7') + '_' + br.ReadUInt32() + ".bin";
                    br.ReadBytes(20);
                    overlays[i].id = (ushort)br.ReadUInt32();
                    br.ReadBytes(4);
                    overlays[i].offset = fat[overlays[i].id].offset;
                    overlays[i].size   = fat[overlays[i].id].size;
                }

                return(overlays);
            }
        }
Exemple #2
0
        public static sFolder ReadFNT(Stream input, uint fntOffset, uint fntSize, sFAT[] fat)
        {
            using (var br = new BinaryReaderX(input, true))
            {
                sFolder root = new sFolder();
                root.files = new List <sFile>();
                List <MainFNT> mains = new List <MainFNT>();

                br.BaseStream.Position = fntOffset;

                br.BaseStream.Position += 6;
                ushort number_directories = br.ReadUInt16();  // Get the total number of directories (mainTables)
                br.BaseStream.Position = fntOffset;

                for (int i = 0; i < number_directories; i++)
                {
                    MainFNT main = new MainFNT();
                    main.offset         = br.ReadUInt32();
                    main.idFirstFile    = br.ReadUInt16();
                    main.idParentFolder = br.ReadUInt16();

                    if (i != 0)
                    {
                        if (br.BaseStream.Position > fntOffset + mains[0].offset)
                        {                                      //  Error, in some cases the number of directories is wrong
                            number_directories--;              // Found in FF Four Heroes of Light, Tetris Party deluxe
                            i--;
                            continue;
                        }
                    }

                    long currOffset = br.BaseStream.Position;
                    br.BaseStream.Position = fntOffset + main.offset;

                    // SubTable
                    byte   id     = br.ReadByte();
                    ushort idFile = main.idFirstFile;

                    while (id != 0x0)   // identifies subTable end
                    {
                        if (id < 0x80)  // File
                        {
                            sFile currFile = new sFile();

                            if (!(main.subTable.files is List <sFile>))
                            {
                                main.subTable.files = new List <sFile>();
                            }

                            int lengthName = id;
                            currFile.name = new String(Encoding.GetEncoding("SJIS").GetChars(br.ReadBytes(lengthName)));
                            currFile.id   = idFile; idFile++;

                            // FAT part
                            currFile.offset = fat[currFile.id].offset;
                            currFile.size   = fat[currFile.id].size;

                            // Add to root
                            root.files.Add(currFile);

                            main.subTable.files.Add(currFile);
                        }
                        if (id > 0x80)  //Directory
                        {
                            sFolder currFolder = new sFolder();

                            if (!(main.subTable.folders is List <sFolder>))
                            {
                                main.subTable.folders = new List <sFolder>();
                            }

                            int lengthName = id - 0x80;
                            currFolder.name = new String(Encoding.GetEncoding("SJIS").GetChars(br.ReadBytes(lengthName))) + "/";
                            currFolder.id   = br.ReadUInt16();

                            main.subTable.folders.Add(currFolder);
                        }

                        id = br.ReadByte();
                    }

                    mains.Add(main);
                    br.BaseStream.Position = currOffset;
                }

                root    = MakeFolderStructure(mains, 0, "root");
                root.id = number_directories;

                return(root);
            }
        }
Exemple #3
0
        public static sFolder AddSystemFiles(Stream input, sFAT[] fatTable, int lastFileID, int lastFolderID, RomHeader header)
        {
            sFolder system = new sFolder();

            system.name = "fw_sys/";
            system.id   = (ushort)lastFolderID;
            lastFolderID++;
            system.files = new List <sFile>();
            system.files.AddRange(ReadBasicOverlays(input, header.ARM9overlayOffset, header.ARM9overlaySize, true, fatTable));
            system.files.AddRange(ReadBasicOverlays(input, header.ARM7overlayOffset, header.ARM7overlaySize, false, fatTable));

            sFile fnt = new sFile();

            fnt.name   = "fileNameTable.bin";
            fnt.offset = header.fileNameTableOffset;
            fnt.size   = header.fileNameTableSize;
            fnt.id     = (ushort)lastFolderID;
            lastFolderID++;
            system.files.Add(fnt);

            sFile fat = new sFile();

            fat.name   = "fileAccessTable.bin";
            fat.offset = header.FAToffset;
            fat.size   = header.FATsize;
            fat.id     = (ushort)lastFolderID;
            lastFolderID++;
            system.files.Add(fat);

            sFile banner = new sFile();

            banner.name   = "banner.bin";
            banner.offset = header.bannerOffset;
            banner.size   = 0x840;
            banner.id     = (ushort)lastFolderID;
            lastFolderID++;
            system.files.Add(banner);

            sFile arm9 = new sFile();

            arm9.name   = "arm9.bin";
            arm9.offset = header.ARM9romOffset;
            arm9.size   = header.ARM9size;
            arm9.id     = (ushort)lastFolderID;
            lastFolderID++;
            system.files.Add(arm9);

            sFile arm7 = new sFile();

            arm7.name   = "arm7.bin";
            arm7.offset = header.ARM7romOffset;
            arm7.size   = header.ARM7size;
            arm7.id     = (ushort)lastFolderID;
            lastFolderID++;
            system.files.Add(arm7);

            if (header.ARM9overlaySize != 0)
            {
                sFile y9 = new sFile();
                y9.name   = "y9.bin";
                y9.offset = header.ARM9overlayOffset;
                y9.size   = header.ARM9overlaySize;
                y9.id     = (ushort)lastFolderID;
                lastFolderID++;
                system.files.Add(y9);
            }

            if (header.ARM7overlaySize != 0)
            {
                sFile y7 = new sFile();
                y7.name   = "y7.bin";
                y7.offset = header.ARM7overlayOffset;
                y7.size   = header.ARM7overlaySize;
                y7.id     = (ushort)lastFolderID;
                lastFolderID++;
                system.files.Add(y7);
            }

            return(system);
        }