Beispiel #1
0
 public VCSNES GetBase(string path)
 {
     try
     {
         ValidateBase(path, false);
         RPXSNES vc = ValidateRPX(path);
         return(VCSNES.GetVC(vc.CRCsSum));
     }
     catch
     {
         return(null);
     }
 }
Beispiel #2
0
        protected override byte[] GetNewRodata(uint crcsSum, byte[] rodata, string rom,
                                               byte speed, byte players, byte soundVolume, byte romType)
        {
            //int romOffset = ReadInt32(rodata, 0x28); //ROM offset (Always 0x00000030)
            int footerOffset = ReadInt32(rodata, 0x34); //Footer offset
            //int romSize = ReadInt32(rodata, footerOffset + 0x21); //ROM size
            VCSNES vc = VCSNES.GetVC(crcsSum);

            if (vc.ROMSize == -1)
            {
                throw new FormatException("The source RPXSNES is unknown.");
            }

            FileStream fs = File.Open(rom, FileMode.Open);

            byte[] romBytes = new byte[fs.Length];
            fs.Read(romBytes, 0, romBytes.Length);
            fs.Close();

            int smcHeaderSize;

            if (romBytes.Length % 1024 == 0)
            {
                smcHeaderSize = 0;
            }
            else if (romBytes.Length % 1024 == 0x200)
            {
                smcHeaderSize = 0x200;
            }
            else
            {
                throw new FormatException("The source ROM has an invalid size.");
            }

            if (romBytes.Length - smcHeaderSize > vc.ROMSize)
            {
                throw new FormatException("The source ROM is too large for this base.");
            }

            int paddingLength = vc.ROMSize - (romBytes.Length - smcHeaderSize);

            byte[] padding = new byte[paddingLength];

            MemoryStream ms = new MemoryStream(rodata);

            ms.Position = 0x50;//romOffset + 0x20;
            ms.Write(romBytes, smcHeaderSize, romBytes.Length - smcHeaderSize);
            ms.Write(padding, 0, padding.Length);
            ms.Position = footerOffset + 0x20;
            ms.WriteByte(speed);
            ms.Position = footerOffset + 0x2F;
            ms.WriteByte(players);
            if (vc.ExtendedFooter)
            {
                ms.WriteByte(soundVolume);
                ms.WriteByte(romType);
            }
            rodata = ms.ToArray();
            ms.Close();

            return(rodata);
        }