Пример #1
0
        /// <summary>
        /// Extracts the SNES rom.
        /// </summary>
        /// <returns>path to the extracted rom.</returns>
        public string ExtractRom()
        {
            // Quiet down the console during the extraction valid rom check
            var consoleOutputStream = Console.Out;

            Console.SetOut(TextWriter.Null);
            if (this.IsValidRom())
            {
                Console.SetOut(consoleOutputStream);

                byte[] header = new byte[SnesHeaderLength];

                switch (this.headerType)
                {
                case SnesHeaderType.HiROM:
                    header = this.snesHiRomHeader;
                    break;

                case SnesHeaderType.LoROM:
                    header = this.snesLoRomHeader;
                    break;
                }

                // Attempt to get the game title from the dictionary
                this.romName = this.snesDictionary.GetRomName(this.vcName);
                string romHeaderName = this.GetRomName(header);

                if (string.IsNullOrEmpty(this.romName))
                {
                    this.romName = romHeaderName;

                    // If a rom name could not be determined from the dictionary or rom, prompt the user
                    if (string.IsNullOrEmpty(this.romName))
                    {
                        Console.WriteLine("Could not determine SNES rom name, please enter your desired filename:");
                        this.romName = Console.ReadLine();
                    }
                }

                Console.WriteLine("Virtual Console Title: " + this.vcName);
                Console.WriteLine("SNES Title: " + this.romName);
                Console.WriteLine("SNES Header Name: " + romHeaderName);

                this.extractedRomPath = this.romName + ".sfc";

                Console.WriteLine("Getting size of rom...");
                int romSize = this.GetRomSize(header[HeaderRomSizeOffset]);

                if (this.verbose)
                {
                    Console.WriteLine("Rom size from header is {0} bytes.", romSize);
                }

                romSize = this.snesSizeDictionary.GetRomSize(romHeaderName, romSize);

                if (this.verbose)
                {
                    Console.WriteLine("Actual rom size is {0} bytes.", romSize);
                }

                Console.WriteLine("Total SNES rom size: " + romSize + " Bytes");

                Console.WriteLine("Getting rom data...");

                byte[] appendedData;

                // Browse to the romPosition in the file
                using (FileStream fs = new FileStream(this.decompressedRomPath, FileMode.Open, FileAccess.Read))
                {
                    using BinaryReader br = new BinaryReader(fs, new ASCIIEncoding());
                    if (this.verbose)
                    {
                        Console.WriteLine("Browsing to 0x{0:X} in {1} to read in the rom data...", this.romPosition, this.decompressedRomPath);
                    }

                    br.BaseStream.Seek(this.romPosition, SeekOrigin.Begin);

                    this.snesRomData = br.ReadBytes(romSize);

                    // Read in all data until the end of the file after the rom data based on parsed file size
                    appendedData = br.ReadBytes((int)(this.fileSize - (VcHeaderSize + romSize)));
                }

                SnesPcmExtractor pcmExtract = new SnesPcmExtractor(this.snesRomData, appendedData);
                this.snesRomData = pcmExtract.ExtractPcmData();

                if (this.sdd1DataOffset > 0)
                {
                    Console.WriteLine("Rom uses S-DD1, recompressing S-DD1 data...");
                    long appendedDataSdd1DataOffset = this.sdd1DataOffset - (VcHeaderSize + romSize);
                    SnesSdd1Extractor sdd1Extract   = new SnesSdd1Extractor(this.snesRomData, appendedData, appendedDataSdd1DataOffset);
                    this.snesRomData = sdd1Extract.ExtractSdd1Data();
                }
                else
                {
                    Console.WriteLine("Rom does not appear to use S-DD1");
                }

                Console.WriteLine("Writing to " + this.extractedRomPath + "...");

                using (BinaryWriter bw = new BinaryWriter(File.Open(this.extractedRomPath, FileMode.Create)))
                {
                    Console.WriteLine("Writing SNES rom data...");
                    bw.Write(this.snesRomData);
                }

                Console.WriteLine("SNES rom has been created successfully at " + this.extractedRomPath);
            }

            return(this.extractedRomPath);
        }
        public string ExtractRom()
        {
            // Quiet down the console during the extraction valid rom check
            var consoleOutputStream = Console.Out;

            Console.SetOut(TextWriter.Null);
            if (this.IsValidRom())
            {
                Console.SetOut(consoleOutputStream);

                byte[] header = new byte[SNES_HEADER_LENGTH];

                switch (headerType)
                {
                case SnesHeaderType.HiROM:
                    header = snesHiRomHeader;
                    break;

                case SnesHeaderType.LoROM:
                    header = snesLoRomHeader;
                    break;
                }

                // Attempt to get the game title from the dictionary
                romName = snesDictionary.getRomName(vcName);

                if (String.IsNullOrEmpty(romName))
                {
                    romName = GetRomName(header);

                    // If a rom name could not be determined from the dictionary or rom, prompt the user
                    if (String.IsNullOrEmpty(romName))
                    {
                        Console.WriteLine("Could not determine SNES rom name, please enter your desired filename:");
                        romName = Console.ReadLine();
                    }
                }

                Console.WriteLine("Virtual Console Title: " + vcName);
                Console.WriteLine("SNES Title: " + romName);

                extractedRomPath = romName + ".smc";

                Console.WriteLine("Getting size of rom...");
                int romSize = GetRomSize(header[HEADER_ROM_SIZE_OFFSET]);

                Console.WriteLine("Total SNES rom size: " + romSize + " Bytes");

                Console.WriteLine("Getting rom data...");

                byte[] pcmData;

                // Browse to the romPosition in the file
                using (FileStream fs = new FileStream(rpxFile.DecompressedPath, FileMode.Open, FileAccess.Read))
                {
                    using (BinaryReader br = new BinaryReader(fs, new ASCIIEncoding()))
                    {
                        br.BaseStream.Seek(romPosition, SeekOrigin.Begin);

                        snesRomData = br.ReadBytes(romSize);
                        pcmData     = br.ReadBytes((int)(br.BaseStream.Length - romPosition + romSize));
                    }
                }

                SnesPcmExtractor pcmExtract = new SnesPcmExtractor(snesRomData, pcmData);
                snesRomData = pcmExtract.ExtractPcmData();

                Console.WriteLine("Writing to " + extractedRomPath + "...");

                using (BinaryWriter bw = new BinaryWriter(File.Open(extractedRomPath, FileMode.Create)))
                {
                    Console.WriteLine("Writing SNES rom data...");
                    bw.Write(snesRomData);
                }

                Console.WriteLine("SNES rom has been created successfully at " + extractedRomPath);
            }

            return(extractedRomPath);
        }