예제 #1
0
        /// <summary>
        /// Read the file system of the ROM and create the folder tree.
        /// </summary>
        /// <param name="str">Stream to read the file system.</param>
        public override void Read(DataStream str)
        {
            // Read File Allocation Table
            // I'm creating a new DataStream variable because Fat class needs to know its length.
            DataStream fatStr = new DataStream(str, this.header.FatOffset, this.header.FatSize);
            Fat        fat    = new Fat();

            fat.Read(fatStr);
            fatStr.Dispose();

            // Read File Name Table
            str.Seek(header.FntOffset, SeekMode.Origin);
            Fnt fnt = new Fnt();

            fnt.Read(str);

            // Get root folder
            this.root = fnt.CreateTree(fat.GetFiles());

            // Get ARM and Overlay files
            this.sysFolder = new GameFolder("System");

            this.sysFolder.AddFile(ArmFile.FromStream(str, this.header, true));
            this.sysFolder.AddFolder(OverlayFolder.FromTable(str, this.header, true, fat.GetFiles()));

            this.sysFolder.AddFile(ArmFile.FromStream(str, this.header, false));
            this.sysFolder.AddFolder(OverlayFolder.FromTable(str, this.header, false, fat.GetFiles()));
        }
예제 #2
0
        /// <summary>
        /// Create a folder with all the overlays of the same ARM.
        /// </summary>
        /// <param name="str">Stream to read the overlay table.</param>
        /// <param name="header">Header of the current ROM.</param>
        /// <param name="isArm9">If must read overlays from the ARM9 or ARM7.</param>
        /// <param name="listFiles">List with all the files in the ROM.</param>
        /// <returns>Folder with overlays.</returns>
        public static OverlayFolder FromTable(DataStream str, RomHeader header, bool isArm9, GameFile[] listFiles)
        {
            OverlayFolder overlays = new OverlayFolder(isArm9);

            int numOverlays;
            if (isArm9) {
                str.Seek(header.Ov9TableOffset, SeekMode.Origin);
                numOverlays = (int)(header.Ov9TableSize / OverlayFile.TableEntrySize);
            } else {
                str.Seek(header.Ov7TableOffset, SeekMode.Origin);
                numOverlays = (int)(header.Ov7TableSize / OverlayFile.TableEntrySize);
            }

            for (int i = 0; i < numOverlays; i++)
                overlays.AddFile(OverlayFile.FromTable(str, isArm9, listFiles));

            return overlays;
        }
예제 #3
0
        private void WriteArm(DataStream str, bool isArm9)
        {
            // Write the ARM file.
            foreach (GameFile file in this.sysFolder.Files)
            {
                ArmFile arm = file as ArmFile;
                if (arm == null || arm.IsArm9 != isArm9)
                {
                    continue;
                }

                // Writes to this Stream but sets the its address after RomHeader
                arm.UpdateAndWrite(str, this.header, this.header.HeaderSize);
                str.WritePadding(FileSystem.PaddingByte, FileSystem.PaddingAddress);
            }

            // Writes the overlay table and overlays
            foreach (GameFolder folder in this.sysFolder.Folders)
            {
                OverlayFolder overlayFolder = folder as OverlayFolder;
                if (overlayFolder == null || overlayFolder.IsArm9 != isArm9)
                {
                    continue;
                }

                // Writes overlay info
                overlayFolder.WriteTable(str, this.header, this.header.HeaderSize);
                str.WritePadding(FileSystem.PaddingByte, FileSystem.PaddingAddress);

                // Write overlays
                foreach (GameFile file in overlayFolder.Files)
                {
                    OverlayFile overlay = file as OverlayFile;
                    if (overlay == null)
                    {
                        continue;
                    }

                    overlay.WriteAddress = (uint)(this.header.HeaderSize + str.Position);
                    overlay.Stream.WriteTo(str);
                    str.WritePadding(FileSystem.PaddingByte, FileSystem.PaddingAddress);
                }
            }
        }
예제 #4
0
        private int CountOverlays(bool isArm9)
        {
            int count = 0;

            foreach (GameFolder folder in this.sysFolder.Folders)
            {
                OverlayFolder overlayFolder = folder as OverlayFolder;
                if (overlayFolder == null || overlayFolder.IsArm9 != isArm9)
                {
                    continue;
                }

                foreach (GameFile file in overlayFolder.Files)
                {
                    if (file is OverlayFile)
                    {
                        count++;
                    }
                }
            }

            return(count);
        }
예제 #5
0
        /// <summary>
        /// Create a folder with all the overlays of the same ARM.
        /// </summary>
        /// <param name="str">Stream to read the overlay table.</param>
        /// <param name="header">Header of the current ROM.</param>
        /// <param name="isArm9">If must read overlays from the ARM9 or ARM7.</param>
        /// <param name="listFiles">List with all the files in the ROM.</param>
        /// <returns>Folder with overlays.</returns>
        public static OverlayFolder FromTable(DataStream str, RomHeader header, bool isArm9, GameFile[] listFiles)
        {
            OverlayFolder overlays = new OverlayFolder(isArm9);

            int numOverlays;

            if (isArm9)
            {
                str.Seek(header.Ov9TableOffset, SeekMode.Origin);
                numOverlays = (int)(header.Ov9TableSize / OverlayFile.TableEntrySize);
            }
            else
            {
                str.Seek(header.Ov7TableOffset, SeekMode.Origin);
                numOverlays = (int)(header.Ov7TableSize / OverlayFile.TableEntrySize);
            }

            for (int i = 0; i < numOverlays; i++)
            {
                overlays.AddFile(OverlayFile.FromTable(str, isArm9, listFiles));
            }

            return(overlays);
        }