public static void EscribirBanner(string salida, Estructuras.Banner banner) { BinaryWriter bw = new BinaryWriter(new FileStream(salida, FileMode.Create)); Console.Write("Banner..."); bw.Write(banner.version); bw.Write(banner.CRC16); bw.Write(banner.reserved); bw.Write(banner.tileData); bw.Write(banner.palette); bw.Write(StringToTitle(banner.japaneseTitle)); bw.Write(StringToTitle(banner.englishTitle)); bw.Write(StringToTitle(banner.frenchTitle)); bw.Write(StringToTitle(banner.germanTitle)); bw.Write(StringToTitle(banner.italianTitle)); bw.Write(StringToTitle(banner.spanishTitle)); bw.Flush(); int rem = (int)bw.BaseStream.Position % 0x200; if (rem != 0) { while (rem < 0x200) { bw.Write((byte)0xFF); rem++; } } bw.Flush(); Console.WriteLine(Tools.Helper.GetTranslation("Messages", "S09"), bw.BaseStream.Length); bw.Close(); }
public static ushort[] SortByOffset(Estructuras.sFAT[] fat) { List<OffsetID> lfat = new List<OffsetID>(); lfat.Sort(Sort); for (ushort i = 0; i < fat.Length; i++) lfat.Add(new OffsetID { offset = fat[i].offset, id = i }); lfat.Sort(Sort); ushort[] ids = new ushort[fat.Length]; for (int i = 0; i < fat.Length; i++) ids[i] = lfat[i].id; return ids; }
public static void EscribirCabecera(string salida, Estructuras.ROMHeader cabecera, string romFile) { BinaryWriter bw = new BinaryWriter(File.OpenWrite(salida)); BinaryReader br = new BinaryReader(File.OpenRead(romFile)); br.BaseStream.Position = 0xC0; Console.Write(Tools.Helper.GetTranslation("Messages", "S0A")); bw.Write(cabecera.gameTitle); bw.Write(cabecera.gameCode); bw.Write(cabecera.makerCode); bw.Write(cabecera.unitCode); bw.Write(cabecera.encryptionSeed); bw.Write((byte)(Math.Log(cabecera.tamaño, 2) - 17)); bw.Write(cabecera.reserved); bw.Write(cabecera.ROMversion); bw.Write(cabecera.internalFlags); bw.Write(cabecera.ARM9romOffset); bw.Write(cabecera.ARM9entryAddress); bw.Write(cabecera.ARM9ramAddress); bw.Write(cabecera.ARM9size); bw.Write(cabecera.ARM7romOffset); bw.Write(cabecera.ARM7entryAddress); bw.Write(cabecera.ARM7ramAddress); bw.Write(cabecera.ARM7size); bw.Write(cabecera.fileNameTableOffset); bw.Write(cabecera.fileNameTableSize); bw.Write(cabecera.FAToffset); bw.Write(cabecera.FATsize); bw.Write(cabecera.ARM9overlayOffset); bw.Write(cabecera.ARM9overlaySize); bw.Write(cabecera.ARM7overlayOffset); bw.Write(cabecera.ARM7overlaySize); bw.Write(cabecera.flagsRead); bw.Write(cabecera.flagsInit); bw.Write(cabecera.bannerOffset); bw.Write(cabecera.secureCRC16); bw.Write(cabecera.ROMtimeout); bw.Write(cabecera.ARM9autoload); bw.Write(cabecera.ARM7autoload); bw.Write(cabecera.secureDisable); bw.Write(cabecera.ROMsize); bw.Write(cabecera.headerSize); bw.Write(cabecera.reserved2); bw.Write(br.ReadBytes(0x9C)); bw.Write(cabecera.logoCRC16); bw.Write(cabecera.headerCRC16); bw.Write(cabecera.debug_romOffset); bw.Write(cabecera.debug_size); bw.Write(cabecera.debug_ramAddress); bw.Write(cabecera.reserved3); bw.Flush(); int relleno = (int)(cabecera.headerSize - bw.BaseStream.Length); br.BaseStream.Position = bw.BaseStream.Position; for (int i = 0; i < relleno; i++) bw.Write(br.ReadByte()); bw.Flush(); bw.Close(); br.Close(); Console.WriteLine(Tools.Helper.GetTranslation("Messages", "S09"), new FileInfo(salida).Length); }
public static sFile[] ReadBasicOverlays(string romFile, UInt32 offset, UInt32 size, bool arm9, Estructuras.sFAT[] fat) { sFile[] overlays = new sFile[size / 0x20]; BinaryReader br = new BinaryReader(File.OpenRead(romFile)); 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(); 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; overlays[i].path = romFile; } br.Close(); return overlays; }
public static sFolder ReadFNT(string romFile, uint fntOffset, Estructuras.sFAT[] fat, Acciones accion) { sFolder root = new sFolder(); root.files = new List<sFile>(); List<Estructuras.MainFNT> mains = new List<Estructuras.MainFNT>(); BinaryReader br = new BinaryReader(File.OpenRead(romFile)); 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++) { Estructuras.MainFNT main = new Estructuras.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; // Posición guardada donde empieza la siguienta maintable br.BaseStream.Position = fntOffset + main.offset; // SubTable correspondiente // SubTable byte id = br.ReadByte(); // Byte que identifica si es carpeta o archivo. ushort idFile = main.idFirstFile; while (id != 0x0) // Indicador de fin de la SubTable { 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("shift_jis").GetChars(br.ReadBytes(lengthName))); currFile.id = idFile; idFile++; // FAT part currFile.offset = fat[currFile.id].offset; currFile.size = fat[currFile.id].size; currFile.path = romFile; // Temporaly, for plugins (Get_Format): root.files.Add(currFile); accion.Root = root; // Get the format long pos = br.BaseStream.Position; br.BaseStream.Position = currFile.offset; currFile.format = accion.Get_Format(br.BaseStream, currFile.name, currFile.id, currFile.size); br.BaseStream.Position = pos; main.subTable.files.Add(currFile); } if (id > 0x80) // Directorio { 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("shift_jis").GetChars(br.ReadBytes(lengthName))); currFolder.id = br.ReadUInt16(); main.subTable.folders.Add(currFolder); } id = br.ReadByte(); } mains.Add(main); br.BaseStream.Position = currOffset; } // Clear previous values root = new sFolder(); accion.Root = new sFolder(); root = Jerarquizar_Carpetas(mains, 0, "root"); root.id = number_directories; br.Close(); return root; }