示例#1
0
        public static void CompressRomOptimized(ORom uncompressedRom, ORom refRom, Stream sw)
        {
            int filesProcessed = 0;
            int filesTotal;
            List <FileRecord> newDmaTable = new List <FileRecord>();

            filesTotal = uncompressedRom.Files.Count();

            foreach (FileRecord record in uncompressedRom.Files)
            {
                Stream outstream = GetFile_CompressedOptimized(uncompressedRom, refRom, record, out bool IsCompressed);
                AppendFile(sw, newDmaTable, outstream, record, IsCompressed);


                //writes progress to console window
                filesProcessed++;
                Console.Write(processedFiles, filesProcessed, filesTotal);
            }

            sw.PadToLength(0x2000000);
            WriteFileTable(sw, uncompressedRom.Files.GetDmaDataStart(), newDmaTable);
            CRC.Write(sw);
        }
示例#2
0
        public static void DecompressRom(Rom compressedRom, Stream sw)
        {
            List <FileRecord> newDmaTable = new List <FileRecord>();
            FileAddress       addr; //current address


            int filesProcessed = 0;
            int filesTotal;

            filesTotal = compressedRom.Files.Count();

            foreach (FileRecord record in compressedRom.Files.OrderBy(x => x.VirtualAddress.Start))
            {
                addr = record.VirtualAddress;

                sw.PadToLength(addr.Start);

                //MM Check
                if (record.PhysicalAddress.Start == -1)
                {
                    newDmaTable.Add(new FileRecord(addr, new FileAddress(record.PhysicalAddress.Start, 0), record.Index));
                }
                else
                {
                    var file = compressedRom.Files.GetFile(addr);
                    ((Stream)file).CopyTo(sw);
                    newDmaTable.Add(new FileRecord(addr, new FileAddress(addr.Start, 0), record.Index));
                }

                //writes progress to console window
                filesProcessed++;
                Console.Write(processedFiles, filesProcessed, filesTotal);
            }
            sw.PadToLength(0x4000000);
            WriteFileTable(sw, compressedRom.Files.GetDmaDataStart(), newDmaTable.OrderBy(x => x.Index).ToList());
            CRC.Write(sw);
        }
示例#3
0
        /// <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);
        }