Exemplo n.º 1
0
        protected static bool FindPatch(ref byte[] rawRomData, string inputFileName, uint crc32 = 0)
        {
            string patch            = null;
            var    patchesDirectory = System.IO.Path.Combine(Program.BaseDirectoryExternal, "patches");

            Directory.CreateDirectory(patchesDirectory);
            if (!string.IsNullOrEmpty(inputFileName))
            {
                if (crc32 != 0)
                {
                    var patches = Directory.GetFiles(patchesDirectory, string.Format("{0:X8}*.*", crc32), SearchOption.AllDirectories);
                    if (patches.Length > 0)
                    {
                        patch = patches[0];
                    }
                }
                var patchesPath = System.IO.Path.Combine(patchesDirectory, System.IO.Path.GetFileNameWithoutExtension(inputFileName) + ".ips");
                if (File.Exists(patchesPath))
                {
                    patch = patchesPath;
                }
                patchesPath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(inputFileName), System.IO.Path.GetFileNameWithoutExtension(inputFileName) + ".ips");
                if (File.Exists(patchesPath))
                {
                    patch = patchesPath;
                }
            }

            if (!string.IsNullOrEmpty(patch))
            {
                if (NeedPatch != true)
                {
                    if (NeedPatch != false)
                    {
                        var r = WorkerForm.MessageBoxFromThread(ParentForm,
                                                                string.Format(Resources.PatchQ, System.IO.Path.GetFileName(inputFileName)),
                                                                Resources.PatchAvailable,
                                                                MessageBoxButtons.AbortRetryIgnore,
                                                                MessageBoxIcon.Question,
                                                                MessageBoxDefaultButton.Button2, true);
                        if (r == DialogResult.Abort)
                        {
                            NeedPatch = true;
                        }
                        if (r == DialogResult.Ignore)
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
                IpsPatcher.Patch(patch, ref rawRomData);
                return(true);
            }
            return(false);
        }
Exemplo n.º 2
0
        public static bool Patch(string inputFileName, ref byte[] rawRomData, ref char prefix, ref string application, ref string outputFileName, ref string args, ref Image cover, ref byte saveCount, ref uint crc32)
        {
            var ext = Path.GetExtension(inputFileName);

            if ((ext.ToLower() == ".smc") && ((rawRomData.Length % 1024) != 0))
            {
                Debug.WriteLine("Removing SMC header");
                var stripped = new byte[rawRomData.Length - 512];
                Array.Copy(rawRomData, 512, stripped, 0, stripped.Length);
                rawRomData = stripped;
                crc32      = CRC32(rawRomData);
            }
            FindPatch(ref rawRomData, inputFileName, crc32);
            if (inputFileName.Contains("(E)") || inputFileName.Contains("(J)"))
            {
                cover = Resources.blank_snes_eu_jp;
            }
            if (ConfigIni.ConsoleType == MainForm.ConsoleType.SNES || ConfigIni.ConsoleType == MainForm.ConsoleType.SuperFamicom)
            {
                application = "/bin/clover-canoe-shvc-wr -rom";
                args        = DefaultArgs;
                if (ext.ToLower() != ".sfrom") // Need to patch for canoe
                {
                    Debug.WriteLine($"Trying to convert {inputFileName}");
                    bool problemGame = false;
                    MakeSfrom(ref rawRomData, ref saveCount, out problemGame);
                    outputFileName = Path.GetFileNameWithoutExtension(outputFileName) + ".sfrom";
                    // Using 3rd party emulator for this ROM
                    if (problemGame && Need3rdPartyEmulator != true)
                    {
                        if (Need3rdPartyEmulator != false)
                        {
                            var r = WorkerForm.MessageBoxFromThread(ParentForm,
                                                                    string.Format(Resources.Need3rdPartyEmulator, Path.GetFileName(inputFileName)),
                                                                    Resources.AreYouSure,
                                                                    MessageBoxButtons.AbortRetryIgnore,
                                                                    MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2, true);
                            if (r == DialogResult.Abort)
                            {
                                Need3rdPartyEmulator = true;
                            }
                            if (r == DialogResult.Ignore)
                            {
                                problemGame = false;
                            }
                        }
                        else
                        {
                            problemGame = false;
                        }
                    }
                    if (problemGame)
                    {
                        application = "/bin/snes";
                        args        = "";
                    }
                }
            }
            else
            {
                application = "/bin/snes";
            }

            return(true);
        }
Exemplo n.º 3
0
        public static bool Patch(string inputFileName, ref byte[] rawRomData, ref char prefix, ref string application, ref string outputFileName, ref string args, ref Image cover, ref byte saveCount, ref uint crc32)
        {
            // Try to patch before mapper check, maybe it will patch mapper
            var     patched = FindPatch(ref rawRomData, inputFileName, crc32);
            NesFile nesFile;

            try
            {
                nesFile = new NesFile(rawRomData);
            }
            catch
            {
                application = "/bin/nes";
                return(true);
            }
            crc32 = nesFile.CRC32;
            // Also search for patch using internal CRC32
            if (!patched)
            {
                if (FindPatch(ref rawRomData, inputFileName, crc32))
                {
                    nesFile = new NesFile(rawRomData);
                }
            }
            nesFile.CorrectRom();

            if (ConfigIni.ConsoleType == MainForm.ConsoleType.NES || ConfigIni.ConsoleType == MainForm.ConsoleType.Famicom)
            {
                application = "/bin/clover-kachikachi-wr";
                args        = DefaultArgs;
            }
            else
            {
                application = "/bin/nes";
            }

            //if (nesFile.Mapper == 71) nesFile.Mapper = 2; // games by Codemasters/Camerica - this is UNROM clone. One exception - Fire Hawk
            //if (nesFile.Mapper == 88) nesFile.Mapper = 4; // Compatible with MMC3... sometimes
            //if (nesFile.Mapper == 95) nesFile.Mapper = 4; // Compatible with MMC3
            //if (nesFile.Mapper == 206) nesFile.Mapper = 4; // Compatible with MMC3
            if (!supportedMappers.Contains(nesFile.Mapper) &&
                (ConfigIni.ConsoleType == MainForm.ConsoleType.NES || ConfigIni.ConsoleType == MainForm.ConsoleType.Famicom) &&
                (IgnoreMapper != true))
            {
                if (IgnoreMapper != false)
                {
                    var r = WorkerForm.MessageBoxFromThread(ParentForm,
                                                            string.Format(Resources.MapperNotSupported, System.IO.Path.GetFileName(inputFileName), nesFile.Mapper),
                                                            Resources.AreYouSure,
                                                            MessageBoxButtons.AbortRetryIgnore,
                                                            MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2, true);
                    if (r == DialogResult.Abort)
                    {
                        IgnoreMapper = true;
                    }
                    if (r == DialogResult.Ignore)
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }
            if ((nesFile.Mirroring == NesFile.MirroringType.FourScreenVram) &&
                (ConfigIni.ConsoleType == MainForm.ConsoleType.NES || ConfigIni.ConsoleType == MainForm.ConsoleType.Famicom) &&
                (IgnoreMapper != true))
            {
                var r = WorkerForm.MessageBoxFromThread(ParentForm,
                                                        string.Format(Resources.FourScreenNotSupported, System.IO.Path.GetFileName(inputFileName)),
                                                        Resources.AreYouSure,
                                                        MessageBoxButtons.AbortRetryIgnore,
                                                        MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2, true);
                if (r == DialogResult.Abort)
                {
                    IgnoreMapper = true;
                }
                if (r == DialogResult.No)
                {
                    return(false);
                }
            }

            // TODO: Make trainer check. I think that the NES Mini doesn't support it.
            rawRomData = nesFile.GetRaw();
            if (inputFileName.Contains("(J)"))
            {
                cover = Resources.blank_jp;
            }

            if (nesFile.Battery)
            {
                saveCount = 3;
            }

            return(true);
        }
Exemplo n.º 4
0
        public static bool Patch(string inputFileName, ref byte[] rawRomData, ref char prefix, ref string application, ref string outputFileName, ref string args, ref Image cover, ref byte saveCount, ref uint crc32)
        {
            var ext = Path.GetExtension(inputFileName);

            if (inputFileName.Contains("(E)") || inputFileName.Contains("(J)"))
            {
                cover = Resources.blank_snes_eu_jp;
            }

            // already in sfrom?
            if (ext.ToLower() == ".sfrom")
            {
                Debug.WriteLine("ROM is already in SFROM format, no conversion needed");
                application = "/bin/clover-canoe-shvc-wr -rom";
                args        = DefaultCanoeArgs;
                return(true);
            }

            // header removal
            if ((ext.ToLower() == ".smc") && ((rawRomData.Length % 1024) != 0))
            {
                Debug.WriteLine("Removing SMC header");
                var stripped = new byte[rawRomData.Length - 512];
                Array.Copy(rawRomData, 512, stripped, 0, stripped.Length);
                rawRomData = stripped;
                crc32      = Shared.CRC32(rawRomData);
            }

            // check if we can use sfrom tool
            bool convertedSuccessfully = false;
            bool isSnesSystem          = ConfigIni.Instance.ConsoleType == MainForm.ConsoleType.SNES || ConfigIni.Instance.ConsoleType == MainForm.ConsoleType.SuperFamicom;

            if (isSnesSystem && ConfigIni.Instance.UseSFROMTool && SfromToolWrapper.IsInstalled)
            {
                Debug.WriteLine($"Convert with SFROM Tool: {inputFileName}");
                if (SfromToolWrapper.ConvertROMtoSFROM(ref rawRomData))
                {
                    outputFileName        = Path.GetFileNameWithoutExtension(outputFileName) + ".sfrom";
                    application           = "/bin/clover-canoe-shvc-wr -rom";
                    args                  = DefaultCanoeArgs;
                    convertedSuccessfully = true;
                }
                else
                {
                    Debug.WriteLine("SFROM Tool conversion failed, attempting the built-in SFROM conversion");
                    convertedSuccessfully = false;
                }
            }

            if (!convertedSuccessfully)
            {
                // fallback method, with patching
                FindPatch(ref rawRomData, inputFileName, crc32);
                if (isSnesSystem)
                {
                    Debug.WriteLine($"Trying to convert {inputFileName}");
                    bool problemGame = false;
                    MakeSfrom(ref rawRomData, ref saveCount, out problemGame);
                    outputFileName = Path.GetFileNameWithoutExtension(outputFileName) + ".sfrom";

                    // Using 3rd party emulator for this ROM
                    if (problemGame && Need3rdPartyEmulator != true)
                    {
                        if (Need3rdPartyEmulator != false)
                        {
                            var r = WorkerForm.MessageBoxFromThread(ParentForm,
                                                                    string.Format(Resources.Need3rdPartyEmulator, Path.GetFileName(inputFileName)),
                                                                    Resources.AreYouSure,
                                                                    MessageBoxButtons.AbortRetryIgnore,
                                                                    MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2, true);
                            if (r == DialogResult.Abort)
                            {
                                Need3rdPartyEmulator = true;
                            }
                            if (r == DialogResult.Ignore)
                            {
                                problemGame = false;
                            }
                        }
                        else
                        {
                            problemGame = false;
                        }
                    }
                    if (problemGame)
                    {
                        //application = "/bin/snes";
                        //args = "";
                    }
                    else
                    {
                        application = "/bin/clover-canoe-shvc-wr -rom";
                        args        = DefaultCanoeArgs;
                    }
                }
                else
                {
                    //application = "/bin/snes";
                }
            }

            return(true);
        }