public VCSNES GetBase(string path) { try { ValidateBase(path, false); RPXSNES vc = ValidateRPX(path); return(VCSNES.GetVC(vc.CRCsSum)); } catch { return(null); } }
private void DeterminateBase(string path) { NusContent.Format format = NusContent.GetFormat(path); if (format == NusContent.Format.Decrypted) { NESInjector nesI = new NESInjector(); SNESInjector snesI = new SNESInjector(); N64Injector n64I = new N64Injector(); GBAInjector gbaI = new GBAInjector(); NDSInjector ndsI = new NDSInjector(); VCNES vcnes = nesI.GetBase(path); if (vcnes != null) { Cll.Log.WriteLine("Base format: NES"); } VCSNES vcsnes = snesI.GetBase(path); if (vcsnes != null) { Cll.Log.WriteLine("Base format: SNES"); } VCN64 vcn64 = n64I.GetBase(path); if (vcn64 != null) { Cll.Log.WriteLine("Base format: N64"); } VCGBA vcgba = gbaI.GetBase(path); if (vcgba != null) { Cll.Log.WriteLine("Base format: GBA"); } VCNDS vcnds = ndsI.GetBase(path); if (vcnds != null) { Cll.Log.WriteLine("Base format: NDS"); } /*ValidateBase(path); * * if (Directory.Exists(BasePath)) * { * Directory.Delete(BasePath, true); * Base = null; * } * * if (Useful.DirectoryCopy(path, BasePath, true)) * Base = GetLoadedBase(); * else * throw new Exception("Could not load base \"" + path + "\".");*/ } else if (format == NusContent.Format.Encrypted) { /*ValidateEncryptedBase(path); * * if (Directory.Exists(BasePath)) * { * Directory.Delete(BasePath, true); * Base = null; * } * * Directory.CreateDirectory(BasePath); * NusContent.Decrypt(path, BasePath); * Base = GetLoadedBase();*/ } else { StringBuilder strBuilder = new StringBuilder(); strBuilder.AppendLine("The folder not contains a valid NUS content."); strBuilder.AppendLine("If it is an unpackaged (decrypted) NUS content, then:"); strBuilder.AppendLine("The \"" + path + "\\code\" folder not exist."); strBuilder.AppendLine("Or \"" + path + "\\content\" folder not exist."); strBuilder.AppendLine("Or \"" + path + "\\meta\" folder not exist."); strBuilder.AppendLine("If it is an packaged (encrypted) NUS content, then:"); strBuilder.AppendLine("The \"" + path + "\\title.tmd\" file not exist."); strBuilder.AppendLine("Or \"" + path + "\\title.tik\" file not exist."); strBuilder.AppendLine("Or \"" + path + "\\title.cert\" file not exist."); throw new Exception(strBuilder.ToString()); } }
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); }