/// <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())); }
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); } } }
/// <summary> /// Create a new ARM file from the info of the ROM header. /// </summary> /// <param name="str">Stream to read the unknown tail.</param> /// <param name="header">Header of the current ROM.</param> /// <param name="romPath">Path to the current ROM.</param> /// <param name="isArm9">Indicates if must create an ARM9 or ARM7 file.</param> /// <returns>ARM file.</returns> public static ArmFile FromStream(DataStream str, RomHeader header, bool isArm9) { ArmFile arm; if (isArm9) { arm = new ArmFile("ARM9.bin", new DataStream(str, header.Arm9Offset, header.Arm9Size)); arm.IsArm9 = true; arm.EntryAddress = header.Arm9EntryAddress; arm.Autoload = header.Arm9Autoload; arm.RamAddress = header.Arm9RamAddress; } else { arm = new ArmFile("ARM7.bin", new DataStream(str, header.Arm7Offset, header.Arm7Size)); arm.IsArm9 = false; arm.EntryAddress = header.Arm7EntryAddress; arm.Autoload = header.Arm7Autoload; arm.RamAddress = header.Arm7RamAddress; } // Set the unknown tail if (isArm9) { // It's after the ARM9 file. str.Seek(header.Arm9Offset + header.Arm9Size, SeekMode.Origin); // Read until reachs padding byte List <byte> tail = new List <byte>(); /*byte b = (byte)str.ReadByte(); * while (b != 0xFF) { * tail.Add(b); * b = (byte)str.ReadByte(); * }*/ arm.unknownTail = tail.ToArray(); } return(arm); }
/// <summary> /// Create a new ARM file from the info of the ROM header. /// </summary> /// <param name="str">Stream to read the unknown tail.</param> /// <param name="header">Header of the current ROM.</param> /// <param name="romPath">Path to the current ROM.</param> /// <param name="isArm9">Indicates if must create an ARM9 or ARM7 file.</param> /// <returns>ARM file.</returns> public static ArmFile FromStream(DataStream str, RomHeader header, bool isArm9) { ArmFile arm; if (isArm9) { arm = new ArmFile("ARM9.bin", new DataStream(str, header.Arm9Offset, header.Arm9Size)); arm.IsArm9 = true; arm.EntryAddress = header.Arm9EntryAddress; arm.Autoload = header.Arm9Autoload; arm.RamAddress = header.Arm9RamAddress; } else { arm = new ArmFile("ARM7.bin", new DataStream(str, header.Arm7Offset, header.Arm7Size)); arm.IsArm9 = false; arm.EntryAddress = header.Arm7EntryAddress; arm.Autoload = header.Arm7Autoload; arm.RamAddress = header.Arm7RamAddress; } // Set the unknown tail if (isArm9) { // It's after the ARM9 file. str.Seek(header.Arm9Offset + header.Arm9Size, SeekMode.Origin); // Read until reachs padding byte List<byte> tail = new List<byte>(); /*byte b = (byte)str.ReadByte(); while (b != 0xFF) { tail.Add(b); b = (byte)str.ReadByte(); }*/ arm.unknownTail = tail.ToArray(); } return arm; }