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") { Trace.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)) { Trace.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 if (ConfigIni.Instance.ConvertToSFROM) { bool convertedSuccessfully = false; if (ConfigIni.Instance.UseSFROMTool && SfromToolWrapper.IsInstalled) { try { SnesRomType romType; string gameTitle; SnesRomHeader romHeader = GetCorrectHeader(rawRomData, out romType, out gameTitle); if (romHeader.SramSize > 0) { saveCount = 3; } else { saveCount = 0; } } catch (Exception ex) { Trace.WriteLine("Error reading ROM header: " + ex.Message + ex.StackTrace); } Trace.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 { Trace.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 (ConfigIni.Instance.ConvertToSFROM) { Trace.WriteLine($"Trying to convert {inputFileName}"); bool problemGame = false; try { MakeSfrom(ref rawRomData, ref saveCount, out problemGame); } catch (Exception ex) { Tasks.ErrorForm.Show(MainForm.StaticRef, Resources.ImportGames, string.Format(Resources.ErrorImportingGame, Path.GetFileName(inputFileName)), ex.Message + ex.StackTrace, Resources.sign_error); return(false); } // Using 3rd party emulator for this ROM? outputFileName = Path.GetFileNameWithoutExtension(outputFileName) + ".sfrom"; if (problemGame && Need3rdPartyEmulator != true) { if (Need3rdPartyEmulator != false) { var result = Tasks.MessageForm.Show(ParentForm, Resources.AreYouSure, string.Format(Resources.Need3rdPartyEmulator, Path.GetFileName(inputFileName)), Resources.sign_warning, new Tasks.MessageForm.Button[] { Tasks.MessageForm.Button.YesToAll, Tasks.MessageForm.Button.Yes, Tasks.MessageForm.Button.No }, Tasks.MessageForm.DefaultButton.Button2); if (result == Tasks.MessageForm.Button.YesToAll) { Need3rdPartyEmulator = true; } if (result == Tasks.MessageForm.Button.No) { problemGame = false; } } else { problemGame = false; } } if (!problemGame) { application = "/bin/clover-canoe-shvc-wr -rom"; args = DefaultCanoeArgs; } } } } return(true); }
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); }