/// <summary> /// Patches files into a rom, where file VROM mappings are identical /// </summary> /// <param name="OutputFilename"></param> /// <param name="hostRom"></param> /// <param name="UpdateFiles"></param> /// <param name="GetFile"></param> private static void PatchFiles_SameVrom_Compressed(Stream output, ORom hostRom, Dictionary <long, string> UpdateFiles, GetFileDelegate GetFile) { List <FileRecord> newDmaTable = new List <FileRecord>(); foreach (FileRecord record in hostRom.Files) { long physicalStart = output.Position; long vromFilesize; long romFilesize; Stream file; //if the file is being replaced with a custom file if (UpdateFiles.ContainsKey(record.VRom.Start)) { //get source file file = GetFile(UpdateFiles[record.VRom.Start]); //Get virtual file size if (record.IsCompressed) { Yaz.DecodeSize(file, out vromFilesize); } else { vromFilesize = Align.To16(file.Length); } //get the physical file size with padding romFilesize = Align.To16(file.Length); } else //copy a source rom file. { vromFilesize = record.VRom.Size; romFilesize = record.Data.Size; if (romFilesize > 0x800000) { throw new Exception("Internal file too large"); } file = hostRom.Files.GetPhysicalFile(record.VRom.Start); } //copy file file.CopyTo(output); file.Close(); //pad out output.PadToLength(physicalStart + romFilesize); //generate a new file table record newDmaTable.Add(new FileRecord( new FileAddress(record.VRom.Start, record.VRom.Start + vromFilesize), new FileAddress(physicalStart, (record.IsCompressed) ? physicalStart + romFilesize : 0))); } output.PadToLength(0x2000000); WriteFileTable(output, hostRom.Files.GetDmaDataStart(), newDmaTable); //write crc CRC.Write(output); }