예제 #1
0
        public void ImportCodes(string AFileName, bool AQuiet = false)
        {
            if (File.Exists(AFileName))
            {
                XmlDocument  lXml       = new XmlDocument();
                XmlNodeList  lCodes     = null;
                XmlNode      lCodeNode  = null;
                XmlAttribute lAttribute = null;

                lXml.Load(AFileName);
                lCodes = lXml.SelectNodes("//genie/..");

                FModified = true;

                XmlNode lDeleteNode = GameNode.FirstChild;
                while (lDeleteNode != null)
                {
                    GameNode.RemoveChild(GameNode.FirstChild);
                    lDeleteNode = GameNode.FirstChild;
                }
                GameCodes.Clear();

                string lGameFileName = Path.Combine(Path.Combine(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "games"), FGame.Code), FGame.Code + ".nes");
                foreach (XmlNode lCurCode in lCodes)
                {
                    NesFile lGame = new NesFile(lGameFileName);
                    try
                    {
                        lGame.PRG = GameGenie.Patch(lGame.PRG, lCurCode["genie"].InnerText);

                        lCodeNode = FXml.CreateElement("gamegenie");
                        GameNode.AppendChild(lCodeNode);

                        lAttribute       = FXml.CreateAttribute("code");
                        lAttribute.Value = lCurCode["genie"].InnerText.ToUpper().Trim();
                        lCodeNode.Attributes.Append(lAttribute);

                        lAttribute       = FXml.CreateAttribute("description");
                        lAttribute.Value = lCurCode["description"].InnerText;
                        lCodeNode.Attributes.Append(lAttribute);

                        GameCodes.Add(new GameGenieCode(lCurCode["genie"].InnerText.ToUpper().Trim(), lCurCode["description"].InnerText));
                    }
                    catch (GameGenieFormatException)
                    {
                        if (!AQuiet)
                        {
                            MessageBox.Show(string.Format(Resources.GameGenieFormatError, lCurCode["genie"].InnerText, FGame.Name), Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    catch (GameGenieNotFoundException)
                    {
                        if (!AQuiet)
                        {
                            MessageBox.Show(string.Format(Resources.GameGenieNotFound, lCurCode["genie"].InnerText, FGame.Name), Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                }
            }
        }
예제 #2
0
        public static void ActiveGameGenie()
        {
            if (!NesEmu.EmulationON)
            {
                Program.VIDEO.WriteNotification("Game Genie can't be enabled while emulation is OFF.", 200, System.Drawing.Color.Red);
                return;
            }
            string filePath = Path.Combine(Settings.Folder_GameGenieCodes,
                                           Path.GetFileNameWithoutExtension(Program.CurrentGameFile) + ".ggc");

            if (File.Exists(filePath))
            {
                string[] lines = File.ReadAllLines(filePath);
                // Clear all
                if (lines.Length > 0)
                {
                    GameGenie            gameGenie = new GameGenie();
                    List <GameGenieCode> codes     = new List <GameGenieCode>();
                    // Add code by code
                    for (int i = 0; i < lines.Length; i++)
                    {
                        GameGenieCode newcode = new GameGenieCode();
                        newcode.Enabled = true;
                        newcode.Name    = lines[i];

                        if (lines[i].Length == 6)
                        {
                            newcode.Address   = gameGenie.GetGGAddress(gameGenie.GetCodeAsHEX(lines[i]), 6) | 0x8000;
                            newcode.Value     = gameGenie.GetGGValue(gameGenie.GetCodeAsHEX(lines[i]), 6);
                            newcode.IsCompare = false;
                        }
                        else
                        {
                            newcode.Address   = gameGenie.GetGGAddress(gameGenie.GetCodeAsHEX(lines[i]), 8) | 0x8000;
                            newcode.Value     = gameGenie.GetGGValue(gameGenie.GetCodeAsHEX(lines[i]), 8);
                            newcode.Compare   = gameGenie.GetGGCompareValue(gameGenie.GetCodeAsHEX(lines[i]));
                            newcode.IsCompare = true;
                        }
                        codes.Add(newcode);
                    }
                    if (codes.Count > 0)
                    {
                        NesEmu.SetupGameGenie(true, codes.ToArray());
                        Program.VIDEO.WriteNotification("Game Genie File Loaded; Game Genie enabled.", 200, System.Drawing.Color.Lime);
                    }
                    else
                    {
                        Program.VIDEO.WriteNotification("There is no Game Genie code to load.", 200, System.Drawing.Color.Red);
                    }
                }
                else
                {
                    Program.VIDEO.WriteNotification("Game Genie file is empty.", 200, System.Drawing.Color.Red);
                }
            }
            else
            {
                Program.VIDEO.WriteNotification("Game Genie file is not found.", 200, System.Drawing.Color.Red);
            }
        }
예제 #3
0
        public FormGameGenie(Emulator emulator)
        {
            this.emulator       = emulator;
            this.emulationState = this.emulator.emulationState;

            InitializeComponent();
            if (!emulationState.EmulationON)
            {
                MessageBox.Show(Program.ResourceManager.GetString("Message_NesIsOff"));
                Close();
                return;
            }
            gameGenie = new GameGenie();
            textBox2.SelectAll();
            //load list if found
            if (this.emulator.GameGenieCodes != null)
            {
                foreach (GameGenieCode code in this.emulator.GameGenieCodes)
                {
                    listView1.Items.Add(code.Name);
                    listView1.Items[listView1.Items.Count - 1].Checked = code.Enabled;
                    listView1.Items[listView1.Items.Count - 1].SubItems.Add(code.Descreption);
                }
            }
            checkBox1.Checked = this.emulator.IsGameGenieActive;
        }
예제 #4
0
 public Room_GameGenie()
     : base()
 {
     gameGenie = new GameGenie();
     Items.Add(new MenuItem_EnableGameGenie());
     Items[Items.Count - 1].SpaceAfter = true;
     Items.Add(new MenuItem_AddCode(this));
     Items.Add(new MenuItem_RemoveCode(this));
     Items[Items.Count - 1].SpaceAfter = true;
     Items.Add(new MenuItem_CurrentCodeIndex());
     Items.Add(new MenuItem_TheCode(this));
     Items.Add(new MenuItem_Address());
     Items.Add(new MenuItem_Value());
     Items.Add(new MenuItem_Compare());
     Items[Items.Count - 1].SpaceAfter = true;
     Items.Add(new MenuItem_SaveFile(this));
     Items.Add(new MenuItem_LoadFile(this));
     Items[Items.Count - 1].SpaceAfter = true;
     Items.Add(new MenuItem_ApplySettings(this));
     Items.Add(new MenuItem_DiscardSettings());
 }
예제 #5
0
 public bool ApplyGameGenie(out byte[] gameFileData)
 {
     gameFileData = null;
     if (!string.IsNullOrEmpty(GameGenie))
     {
         var    codes        = GameGenie.Split(new char[] { ',', '\t', ' ', ';' }, StringSplitOptions.RemoveEmptyEntries);
         string gameFilePath = GameFilePath;
         if (gameFilePath != null)
         {
             byte[] data = GameFileData;
             if (data != null)
             {
                 var nesFile = new NesFile(data);
                 foreach (var code in codes)
                 {
                     nesFile.PRG = GameGeniePatcherNes.Patch(nesFile.PRG, code.Trim());
                 }
                 gameFileData = nesFile.GetRaw();
                 return(true);
             }
         }
     }
     return(false);
 }
예제 #6
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));
                }
            }
        }
예제 #7
0
 public Dialog_AddGameGenieCode()
 {
     this.Build();
     gameGenie = new GameGenie();
 }
예제 #8
0
 public MenuItem_LoadFile(Room_GameGenie page)
     : base()
 {
     this.page = page;
     gameGenie = new GameGenie();
 }
예제 #9
0
 public MenuItem_ApplySettings(Room_GameGenie page)
     : base()
 {
     this.page = page;
     gameGenie = new GameGenie();
 }