Exemplo n.º 1
0
        public void ApplyGameGenie()
        {
            if (!string.IsNullOrEmpty(GameGenie))
            {
                bool wasCompressed = DecompressPossible().Length > 0;
                if (wasCompressed)
                {
                    Decompress();
                }

                var codes    = GameGenie.Split(new char[] { ',', '\t', ' ', ';' }, StringSplitOptions.RemoveEmptyEntries);
                var nesFiles = Directory.GetFiles(this.basePath, "*.nes", SearchOption.TopDirectoryOnly);
                foreach (var f in nesFiles)
                {
                    var nesFile = new NesFile(f);
                    foreach (var code in codes)
                    {
                        nesFile.PRG = GameGeniePatcherNes.Patch(nesFile.PRG, code.Trim());
                    }
                    nesFile.Save(f);
                }

                if (wasCompressed)
                {
                    Compress();
                }
            }
        }
Exemplo n.º 2
0
        public NesGame(string gamesDirectory, string nesFileName)
        {
            var nesFile = new NesFile(nesFileName);

            nesFile.CorrectRom();
            if (!supportedMappers.Contains(nesFile.Mapper))
            {
                throw new Exception(string.Format(Resources.MapperNotSupported, Path.GetFileName(nesFileName), nesFile.Mapper));
            }
            Code = string.Format("CLV-H-{0}{1}{2}{3}{4}",
                                 (char)('A' + (nesFile.CRC32 % 26)),
                                 (char)('A' + (nesFile.CRC32 >> 5) % 26),
                                 (char)('A' + ((nesFile.CRC32 >> 10) % 26)),
                                 (char)('A' + ((nesFile.CRC32 >> 15) % 26)),
                                 (char)('A' + ((nesFile.CRC32 >> 20) % 26)));
            GamePath   = Path.Combine(gamesDirectory, Code);
            ConfigPath = Path.Combine(GamePath, Code + ".desktop");
            Directory.CreateDirectory(GamePath);
            NesPath = Path.Combine(GamePath, Code + ".nes");
            nesFile.Save(NesPath);
            Name = Path.GetFileNameWithoutExtension(nesFileName);
            Name = Regex.Replace(Name, @" ?\(.*?\)", string.Empty).Trim();
            Name = Regex.Replace(Name, @" ?\[.*?\]", string.Empty).Trim();
            Name = Name.Replace(", The", "").Replace("_", " ").Replace("  ", " ").Trim();

            Players       = 1;
            ReleaseDate   = "1983-07-15";
            Publisher     = "Nintendo";
            Args          = "--guest-overscan-dimensions 0,0,9,3 --initial-fadein-durations 3,2 --volume 75 --enable-armet";
            IconPath      = Path.Combine(GamePath, Code + ".png");
            SmallIconPath = Path.Combine(GamePath, Code + "_small.png");
            SetImage(Resources.blank);
            Save();
        }
Exemplo n.º 3
0
        public NesGame(string gamesDirectory, string nesFileName, bool ignoreMapper = false)
        {
            if (!Path.GetExtension(nesFileName).ToLower().Equals(".fds"))
            {
                var nesFile = new NesFile(nesFileName);
                nesFile.CorrectRom();
                if (!supportedMappers.Contains(nesFile.Mapper) && !ignoreMapper)
                {
                    throw new UnsupportedMapperException(nesFile);
                }
                var crc32 = nesFile.CRC32;
                Code = string.Format("CLV-H-{0}{1}{2}{3}{4}",
                                     (char)('A' + (crc32 % 26)),
                                     (char)('A' + (crc32 >> 5) % 26),
                                     (char)('A' + ((crc32 >> 10) % 26)),
                                     (char)('A' + ((crc32 >> 15) % 26)),
                                     (char)('A' + ((crc32 >> 20) % 26)));
                GamePath   = Path.Combine(gamesDirectory, Code);
                ConfigPath = Path.Combine(GamePath, Code + ".desktop");
                Directory.CreateDirectory(GamePath);
                NesPath = Path.Combine(GamePath, Code + ".nes");
                nesFile.Save(NesPath);
            }
            else
            {
                var fdsData = File.ReadAllBytes(nesFileName);
                var crc32   = CRC32(fdsData);
                Code = string.Format("CLV-H-{0}{1}{2}{3}{4}",
                                     (char)('A' + (crc32 % 26)),
                                     (char)('A' + (crc32 >> 5) % 26),
                                     (char)('A' + ((crc32 >> 10) % 26)),
                                     (char)('A' + ((crc32 >> 15) % 26)),
                                     (char)('A' + ((crc32 >> 20) % 26)));
                GamePath   = Path.Combine(gamesDirectory, Code);
                ConfigPath = Path.Combine(GamePath, Code + ".desktop");
                Directory.CreateDirectory(GamePath);
                NesPath = Path.Combine(GamePath, Code + ".nes");
                File.WriteAllBytes(NesPath, fdsData);
            }

            Name          = Path.GetFileNameWithoutExtension(nesFileName);
            Name          = Regex.Replace(Name, @" ?\(.*?\)", string.Empty).Trim();
            Name          = Regex.Replace(Name, @" ?\[.*?\]", string.Empty).Trim();
            Name          = Name.Replace(", The", "").Replace("_", " ").Replace("  ", " ").Trim();
            Players       = 1;
            ReleaseDate   = "1983-07-15";
            Publisher     = "Nintendo";
            Args          = "--guest-overscan-dimensions 0,0,9,3 --initial-fadein-durations 3,2 --volume 75 --enable-armet";
            IconPath      = Path.Combine(GamePath, Code + ".png");
            SmallIconPath = Path.Combine(GamePath, Code + "_small.png");
            SetImage(Resources.blank);
            Save();
        }
Exemplo n.º 4
0
 public void ApplyGameGenie()
 {
     if (!string.IsNullOrEmpty(GameGenie))
     {
         var codes   = GameGenie.Split(new char[] { ',', '\t', ' ', ';' }, StringSplitOptions.RemoveEmptyEntries);
         var nesFile = new NesFile(NesPath);
         foreach (var code in codes)
         {
             nesFile.PRG = GameGeniePatcher.Patch(nesFile.PRG, code.Trim());
         }
         nesFile.Save(NesPath);
     }
 }
Exemplo n.º 5
0
 public void ApplyGameGenie()
 {
     if (!string.IsNullOrEmpty(GameGenie))
     {
         var codes    = GameGenie.Split(new char[] { ',', '\t', ' ', ';' }, StringSplitOptions.RemoveEmptyEntries);
         var nesFiles = Directory.GetFiles(this.GamePath, "*.nes", SearchOption.TopDirectoryOnly);
         foreach (var f in nesFiles)
         {
             var nesFile = new NesFile(f);
             foreach (var code in codes)
             {
                 nesFile.PRG = GameGeniePatcherNes.Patch(nesFile.PRG, code.Trim());
             }
             nesFile.Save(f);
         }
     }
 }
Exemplo n.º 6
0
 public LuaMapper()
 {
     script = new Script();
     script.Globals["ReadPrg"] = script.Globals["ReadCpu"] = (Func <UInt16, int, List <byte> >) delegate(UInt16 address, int length)
     {
         if (Verbose)
         {
             Console.WriteLine("Reading {0} bytes from CPU:${1:X4}", length, address);
         }
         var result = new List <byte>();
         result.AddRange(dumper.ReadCpu(address, length));
         return(result);
     };
     script.Globals["WritePrg"] = script.Globals["WriteCpu"] = (Action <UInt16, List <byte> >) delegate(UInt16 address, List <byte> data)
     {
         if (Verbose)
         {
             var a = address;
             foreach (var v in data)
             {
                 Console.WriteLine("CPU write ${0:X2} => ${1:X4}", v, a);
                 a++;
             }
         }
         dumper.WriteCpu(address, data.ToArray());
     };
     script.Globals["AddPrg"] = script.Globals["AddPrgResult"] = (Action <List <byte> >) delegate(List <byte> r)
     {
         resultPrg.AddRange(r);
     };
     script.Globals["ReadAddPrg"] = script.Globals["ReadAddCpu"] = (Action <UInt16, int>) delegate(UInt16 address, int length)
     {
         if (Verbose)
         {
             Console.WriteLine("Reading {0} bytes from CPU:${1:X4}", length, address);
         }
         resultPrg.AddRange(dumper.ReadCpu(address, length));
     };
     script.Globals["ReadChr"] = script.Globals["ReadPpu"] = (Func <UInt16, int, List <byte> >) delegate(UInt16 address, int length)
     {
         if (Verbose)
         {
             Console.WriteLine("Reading {0} bytes from PPU:${1:X4}", length, address);
         }
         var result = new List <byte>();
         result.AddRange(dumper.ReadPpu(address, length));
         return(result);
     };
     script.Globals["WriteChr"] = script.Globals["WritePpu"] = (Action <UInt16, List <byte> >) delegate(UInt16 address, List <byte> data)
     {
         if (Verbose)
         {
             var a = address;
             foreach (var v in data)
             {
                 Console.WriteLine("PPU write ${0:X2} => ${1:X4}", v, a);
                 a++;
             }
         }
         dumper.WritePpu(address, data.ToArray());
     };
     script.Globals["ReadAddChr"] = script.Globals["ReadAddPpu"] = (Action <UInt16, int>) delegate(UInt16 address, int length)
     {
         if (Verbose)
         {
             Console.WriteLine("Reading {0} bytes from PPU:${1:$X4}", length, address);
         }
         resultChr.AddRange(dumper.ReadPpu(address, length));
     };
     script.Globals["AddChr"] = script.Globals["AddChrResult"] = (Action <List <byte> >) delegate(List <byte> r)
     {
         resultChr.AddRange(r);
     };
     script.Globals["Reset"] = (Action) delegate
     {
         if (Verbose)
         {
             Console.Write("Reset... ");
         }
         dumper.Reset();
         if (Verbose)
         {
             Console.WriteLine("OK");
         }
     };
     script.Globals["WriteFile"] = (Action <string, List <byte> >) delegate(string filename, List <byte> data)
     {
         if (Verbose)
         {
             Console.Write("Writing data to \"{0}\"... ", Path.GetFileName(filename));
         }
         File.WriteAllBytes(filename, data.ToArray());
         if (Verbose)
         {
             Console.WriteLine("OK");
         }
     };
     script.Globals["WriteNes"] = (WriteNesDelegate) delegate(string filename, List <byte> prgData, List <byte> chrData, byte mapper, bool vertical)
     {
         if (Verbose)
         {
             Console.Write("Writing data to NES file \"{0}\" (mapper={1}, mirroring={2})... ", Path.GetFileName(filename), mapper, vertical ? "vertical" : "horizontal");
         }
         var nesFile = new NesFile();
         nesFile.PRG       = prgData.ToArray();
         nesFile.CHR       = chrData.ToArray();
         nesFile.Mapper    = 0;
         nesFile.Mirroring = vertical ? NesFile.MirroringType.Vertical : NesFile.MirroringType.Horizontal;
         nesFile.Save(filename);
         if (Verbose)
         {
             Console.WriteLine("OK");
         }
     };
     script.Globals["Error"] = (Action <string>) delegate(string message)
     {
         throw new Exception(message);
     };
 }
Exemplo n.º 7
0
        private void AddMenu(NesMenuCollection menuCollection, List <NesMenuCollection> allMenus = null)
        {
            if (allMenus == null)
            {
                allMenus = new List <NesMenuCollection>();
            }
            if (!allMenus.Contains(menuCollection))
            {
                allMenus.Add(menuCollection);
            }
            int    menuIndex = allMenus.IndexOf(menuCollection);
            string targetDirectory;

            if (menuIndex == 0)
            {
                targetDirectory = gamesDirectory;
            }
            else
            {
                targetDirectory = Path.Combine(gamesDirectory, string.Format("sub{0:D3}", menuIndex));
            }
            if (Directory.Exists(targetDirectory))
            {
                return;
            }
            foreach (var element in menuCollection)
            {
                if (element is NesGame)
                {
                    var game    = element as NesGame;
                    var gameDir = Path.Combine(targetDirectory, game.Code);
                    Debug.WriteLine(string.Format("Processing {0}/{1}", game.Code, game.Name));
                    DirectoryCopy(game.GamePath, gameDir, true);
                    if (!string.IsNullOrEmpty(game.GameGenie))
                    {
                        var codes          = game.GameGenie.Split(new char[] { ',', '\t', ' ', ';' }, StringSplitOptions.RemoveEmptyEntries);
                        var newNesFilePath = Path.Combine(gameDir, game.Code + ".nes");
                        try
                        {
                            var nesFile = new NesFile(newNesFilePath);
                            foreach (var code in codes)
                            {
                                try
                                {
                                    nesFile.PRG = GameGenie.Patch(nesFile.PRG, code.Trim());
                                }
                                catch (GameGenieFormatException)
                                {
                                    ShowError(new GameGenieFormatException(string.Format(Resources.GameGenieFormatError, code, game)), dontStop: true);
                                }
                                catch (GameGenieNotFoundException)
                                {
                                    ShowError(new GameGenieNotFoundException(string.Format(Resources.GameGenieNotFound, code, game.Name)), dontStop: true);
                                }
                            }
                            nesFile.Save(newNesFilePath);
                            var ggFilePath = Path.Combine(gameDir, NesGame.GameGenieFileName);
                            if (File.Exists(ggFilePath))
                            {
                                File.Delete(ggFilePath);
                            }
                        }
                        catch // in case of FDS game... just ignore
                        {
                        }
                    }
                }
                if (element is NesMenuFolder)
                {
                    var folder = element as NesMenuFolder;
                    if (!allMenus.Contains(folder.Child))
                    {
                        allMenus.Add(folder.Child);
                    }
                    int childIndex = allMenus.IndexOf(folder.Child);
                    var folderDir  = Path.Combine(targetDirectory, folder.Code);
                    folder.Save(folderDir, childIndex);
                    AddMenu(folder.Child, allMenus);
                }
                if (element is NesDefaultGame)
                {
                    var game      = element as NesDefaultGame;
                    var gfilePath = Path.Combine(gamesDirectory, string.Format("gpath-{0}-{1}", game.Code, menuIndex));
                    Directory.CreateDirectory(Path.GetDirectoryName(gfilePath));
                    File.WriteAllText(gfilePath, menuIndex == 0 ? "." : string.Format("sub{0:D3}", menuIndex));
                }
            }
        }