private void DetermineHeaderType()
        {
            // Read in the headers
            using (FileStream fs = new FileStream(rpxFile.DecompressedPath, FileMode.Open, FileAccess.Read))
            {
                using (BinaryReader br = new BinaryReader(fs, new ASCIIEncoding()))
                {
                    // Seek to the lorom header location and read the lorom data
                    br.BaseStream.Seek(romPosition + SNES_LOROM_HEADER_OFFSET, SeekOrigin.Begin);
                    snesLoRomHeader = br.ReadBytes(SNES_HEADER_LENGTH);

                    // Seek to the hirom header location and read the hirom data
                    br.BaseStream.Seek(romPosition + SNES_HIROM_HEADER_OFFSET, SeekOrigin.Begin);
                    snesHiRomHeader = br.ReadBytes(SNES_HEADER_LENGTH);
                }
            }

            // Check each header to verify which is correct
            if (IsValidHeader(snesLoRomHeader))
            {
                if (IsValidHeader(snesHiRomHeader))
                {
                    // Both appear to be valid, could not determine which is the correct header
                    headerType = SnesHeaderType.Unknown;
                }
                else
                {
                    headerType = SnesHeaderType.LoROM;
                }
            }
            else if (IsValidHeader(snesHiRomHeader))
            {
                headerType = SnesHeaderType.HiROM;
            }
        }
Beispiel #2
0
        private void DetermineHeaderType()
        {
            if (verbose)
            {
                Console.WriteLine("Determining SNES Rom header type (LoROM or HiROM)");
            }

            // Read in the headers
            using (FileStream fs = new FileStream(decompressedRomPath, FileMode.Open, FileAccess.Read))
            {
                using (BinaryReader br = new BinaryReader(fs, new ASCIIEncoding()))
                {
                    if (verbose)
                    {
                        Console.WriteLine("Seeking to 0x{0:X} to check for possible LoROM header.", romPosition + SNES_LOROM_HEADER_OFFSET);
                    }

                    // Seek to the lorom header location and read the lorom data
                    br.BaseStream.Seek(romPosition + SNES_LOROM_HEADER_OFFSET, SeekOrigin.Begin);
                    snesLoRomHeader = br.ReadBytes(SNES_HEADER_LENGTH);

                    if (verbose)
                    {
                        Console.WriteLine("Seeking to 0x{0:X} to check for possible HiROM header.", romPosition + SNES_HIROM_HEADER_OFFSET);
                    }

                    // Seek to the hirom header location and read the hirom data
                    br.BaseStream.Seek(romPosition + SNES_HIROM_HEADER_OFFSET, SeekOrigin.Begin);
                    snesHiRomHeader = br.ReadBytes(SNES_HEADER_LENGTH);
                }
            }

            // Check each header to verify which is correct
            if (IsValidHeader(snesLoRomHeader))
            {
                if (IsValidHeader(snesHiRomHeader))
                {
                    if (verbose)
                    {
                        Console.WriteLine("Could not determine header type since both HiROM and LoROM headers were valid.");
                    }
                    // Both appear to be valid, could not determine which is the correct header
                    headerType = SnesHeaderType.Unknown;
                }
                else
                {
                    headerType = SnesHeaderType.LoROM;
                }
            }
            else if (IsValidHeader(snesHiRomHeader))
            {
                headerType = SnesHeaderType.HiROM;
            }

            if (verbose)
            {
                Console.WriteLine("SNES header type is " + headerType.ToString());
            }
        }
Beispiel #3
0
        private void DetermineHeaderType()
        {
            if (this.verbose)
            {
                Console.WriteLine("Determining SNES Rom header type (LoROM or HiROM)");
            }

            // Read in the headers
            using (FileStream fs = new FileStream(this.decompressedRomPath, FileMode.Open, FileAccess.Read))
            {
                using BinaryReader br = new BinaryReader(fs, new ASCIIEncoding());
                if (this.verbose)
                {
                    Console.WriteLine("Seeking to 0x{0:X} to check for possible LoROM header.", this.romPosition + SnesLoRomHeaderOffset);
                }

                // Seek to the lorom header location and read the lorom data
                br.BaseStream.Seek(this.romPosition + SnesLoRomHeaderOffset, SeekOrigin.Begin);
                this.snesLoRomHeader = br.ReadBytes(SnesHeaderLength);

                if (this.verbose)
                {
                    Console.WriteLine("Seeking to 0x{0:X} to check for possible HiROM header.", this.romPosition + SnesHiRomHeaderOffset);
                }

                // Seek to the hirom header location and read the hirom data
                br.BaseStream.Seek(this.romPosition + SnesHiRomHeaderOffset, SeekOrigin.Begin);
                this.snesHiRomHeader = br.ReadBytes(SnesHeaderLength);
            }

            // Check each header to verify which is correct
            if (this.IsValidHeader(this.snesLoRomHeader))
            {
                if (this.IsValidHeader(this.snesHiRomHeader))
                {
                    if (this.verbose)
                    {
                        Console.WriteLine("Could not determine header type since both HiROM and LoROM headers were valid, defaulting to LoROM.");
                    }

                    // Both appear to be valid, use LoROM by default
                    this.headerType = SnesHeaderType.LoROM;
                }
                else
                {
                    this.headerType = SnesHeaderType.LoROM;
                }
            }
            else if (this.IsValidHeader(this.snesHiRomHeader))
            {
                this.headerType = SnesHeaderType.HiROM;
            }

            if (this.verbose)
            {
                Console.WriteLine("SNES header type is " + this.headerType.ToString());
            }
        }
        public SnesVcExtractor(string dumpPath, RpxFile rpxFile)
        {
            string snesDictionaryPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, SNES_DICTIONARY_CSV_PATH);

            snesDictionary  = new RomNameDictionary(snesDictionaryPath);
            snesLoRomHeader = new byte[SNES_HEADER_LENGTH];
            snesHiRomHeader = new byte[SNES_HEADER_LENGTH];
            headerType      = SnesHeaderType.NotDetermined;
            romPosition     = 0;
            vcNamePosition  = 0;

            this.rpxFile = rpxFile;
        }
Beispiel #5
0
        public SnesVcExtractor(string decompressedRomPath, bool verbose = false)
        {
            this.verbose = verbose;
            string snesDictionaryPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, SNES_DICTIONARY_CSV_PATH);
            string snesSizePath       = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, SNES_SIZE_CSV_PATH);

            snesDictionary     = new RomNameDictionary(snesDictionaryPath);
            snesSizeDictionary = new RomSizeDictionary(snesSizePath);
            snesLoRomHeader    = new byte[SNES_HEADER_LENGTH];
            snesHiRomHeader    = new byte[SNES_HEADER_LENGTH];
            headerType         = SnesHeaderType.NotDetermined;
            romPosition        = 0;
            vcNamePosition     = 0;

            this.decompressedRomPath = decompressedRomPath;
        }
Beispiel #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SnesVcExtractor"/> class.
        /// </summary>
        /// <param name="decompressedRomPath">path to the decompressed rom.</param>
        /// <param name="verbose">whether to provide verbose output.</param>
        public SnesVcExtractor(string decompressedRomPath, bool verbose = false)
        {
            this.verbose = verbose;
            string snesDictionaryPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, SnesDictionaryCsvPath);
            string snesSizePath       = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, SnesSizeCsvPath);

            this.snesDictionary      = new RomNameDictionary(snesDictionaryPath);
            this.snesSizeDictionary  = new RomSizeDictionary(snesSizePath);
            this.snesLoRomHeader     = new byte[SnesHeaderLength];
            this.snesHiRomHeader     = new byte[SnesHeaderLength];
            this.headerType          = SnesHeaderType.NotDetermined;
            this.romPosition         = 0;
            this.vcNamePosition      = 0;
            this.sdd1Offset          = 0;
            this.sdd1OffsetPosition  = 0;
            this.fileSize            = 0;
            this.fileSizePosition    = 0;
            this.decompressedRomPath = decompressedRomPath;
        }