bool UploadGames() { var workerForm = new WorkerForm(); workerForm.Task = WorkerForm.Tasks.Memboot; workerForm.KernelDump = KernelDump; workerForm.Mod = "mod_transfer"; workerForm.OriginalGames = false; var games = new List <NesGame>(); foreach (var game in checkedListBoxGames.CheckedItems) { if (game is NesGame) { games.Add(game as NesGame); } else { workerForm.OriginalGames = true; } } workerForm.Games = games.ToArray(); workerForm.Start(); return(workerForm.DialogResult == DialogResult.OK); }
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); }
bool DoKernelDump() { var workerForm = new WorkerForm(); workerForm.Task = WorkerForm.Tasks.DumpKernel; //workerForm.UBootDump = UBootDump; workerForm.KernelDump = KernelDump; workerForm.Start(); return(workerForm.DialogResult == DialogResult.OK); }
bool FlashOriginalKernel() { var workerForm = new WorkerForm(); workerForm.Task = WorkerForm.Tasks.FlashKernel; workerForm.KernelDump = KernelDump; workerForm.Mod = null; workerForm.Start(); var result = workerForm.DialogResult == DialogResult.OK; if (result) { Settings.Default.CustomFlashed = false; Settings.Default.Save(); } return(result); }
bool FlashCustomKernel() { var workerForm = new WorkerForm(); workerForm.Task = WorkerForm.Tasks.FlashKernel; workerForm.KernelDump = KernelDump; workerForm.Mod = "mod_kernel"; workerForm.Start(); var result = workerForm.DialogResult == DialogResult.OK; if (result) { Settings.Default.CustomFlashed = true; Settings.Default.Save(); } return(result); }
void screenShotLoop() { while (true) { try { var screenshot = WorkerForm.TakeScreenshot(false); Invoke(new Action(delegate() { pictureBox.Image = screenshot; })); } catch (ThreadAbortException) { screenShotThread = null; return; } catch (Exception ex) { Debug.WriteLine("Error: " + ex.Message + ex.StackTrace); Thread.Sleep(1000); } } }
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); }
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); }
void LoadSaveStatesList() { try { while (!this.IsHandleCreated) { Thread.Sleep(100); } if (!(bool)Invoke(new Func <bool>(delegate { listViewSaves.Visible = false; exportToolStripMenuItem.Enabled = importToolStripMenuItem.Enabled = buttonExport.Enabled = buttonImport.Enabled = false; if (!WaitingClovershellForm.WaitForDevice(this)) { return(false); } return(true); }))) { Close(); return; } var clovershell = MainForm.Clovershell; WorkerForm.ShowSplashScreen(); var listSavesScript = "#!/bin/sh\n" + "savespath=/var/lib/clover/profiles/0\n" + "find $savespath -mindepth 1 -maxdepth 1 -type d -name \"CLV-*\" | sed 's#.*/##' | while read code ; do\n" + " flags=F\n" + " [ -f $savespath/$code/save.sram ] && flags=${flags}-S\n" + " [ -f $savespath/$code/cartridge.sram ] && [ $(wc -c <$savespath/$code/cartridge.sram) -gt 20 ] && flags=${flags}-S\n" + " [ -f $savespath/$code/1.state ] && flags=${flags}-1\n" + " [ -d $savespath/$code/suspendpoint1 ] && flags=${flags}-1\n" + " [ -f $savespath/$code/2.state ] && flags=${flags}-2\n" + " [ -d $savespath/$code/suspendpoint2 ] && flags=${flags}-2\n" + " [ -f $savespath/$code/3.state ] && flags=${flags}-3\n" + " [ -d $savespath/$code/suspendpoint3 ] && flags=${flags}-3\n" + " [ -f $savespath/$code/4.state ] && flags=${flags}-4\n" + " [ -d $savespath/$code/suspendpoint4 ] && flags=${flags}-4\n" + " if [ \"$flags\" != \"F\" ]; then\n" + " size=$(du -d 0 $savespath/$code | awk '{ print $1 }')\n" + " name=$(find /var/lib -type f -name \"$code.desktop\" -exec cat {} + | sed -n 's/Name=\\(.*\\)/\\1/p')\n" + " [ -z \"$name\" ] && name=UNKNOWN\n" + " echo $code $size $flags $name\n" + " unset flags\n" + " unset name\n" + " else\n" + " rm -rf $savespath/$code\n" + " fi\n" + "done"; var listSavesScriptStream = new MemoryStream(Encoding.UTF8.GetBytes(listSavesScript)); listSavesScriptStream.Seek(0, SeekOrigin.Begin); var output = new MemoryStream(); clovershell.Execute("sh", listSavesScriptStream, output, null, 10000, true); var lines = Encoding.UTF8.GetString(output.ToArray()).Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries); Invoke(new Action(delegate { listViewSaves.Items.Clear(); foreach (var line in lines) { var l = line; var code = l.Substring(0, l.IndexOf(' ')); l = l.Substring(l.IndexOf(' ') + 1); var size = l.Substring(0, l.IndexOf(' ')) + "KB"; l = l.Substring(l.IndexOf(' ') + 1); var flags = l.Substring(0, l.IndexOf(' ')).Replace("F-", "").Replace("-", " ").Trim(); l = l.Substring(l.IndexOf(' ') + 1); var name = l; if (name == "UNKNOWN") { if (gameNames.ContainsKey(code)) { name = gameNames[code]; } else { name = Resources.UnknownGame; } } listViewSaves.Items.Add(new ListViewItem(new ListViewItem.ListViewSubItem[] { new ListViewItem.ListViewSubItem() { Name = "colName", Text = name }, new ListViewItem.ListViewSubItem() { Name = "colCode", Text = code }, new ListViewItem.ListViewSubItem() { Name = "colSize", Text = size }, new ListViewItem.ListViewSubItem() { Name = "colFlags", Text = flags } }, 0)); listViewSaves.ListViewItemSorter = new SavesSorter(0, false); listViewSaves.Sort(); } listViewSaves.Visible = true; importToolStripMenuItem.Enabled = true; buttonImport.Enabled = true; })); } catch (ThreadAbortException) { } catch (ObjectDisposedException) { } catch (Exception ex) { Debug.WriteLine(ex.Message + ex.StackTrace); try { Invoke(new Action(delegate { MessageBox.Show(this, ex.Message, Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); Close(); })); } catch { } } }
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); }
public SelectModsForm(bool loadInstalledMods, bool allowDropMods, string[] filesToAdd = null) { InitializeComponent(); switch (ConfigIni.Instance.hmodListSort) { case HmodListSort.Category: categoryToolStripMenuItem.Checked = true; break; case HmodListSort.Creator: creatorToolStripMenuItem.Checked = true; break; } wbReadme.Document.BackColor = this.BackColor; usermodsDirectory = Path.Combine(Program.BaseDirectoryExternal, "user_mods"); var modsList = new List <string>(); if (loadInstalledMods && MainForm.Clovershell.IsOnline) { var modsstr = MainForm.Clovershell.ExecuteSimple("ls /var/lib/hakchi/hmod/uninstall-*", 2000, true); var installedMods = modsstr.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries); foreach (var mod in installedMods) { var modname = mod; int pos; while ((pos = modname.IndexOf("/")) >= 0) { modname = modname.Substring(pos + 1); } modname = modname.Substring("uninstall-".Length); if (MainForm.InternalMods.Contains(modname)) { continue; } modsList.Add(modname); } } else { if (Directory.Exists(usermodsDirectory)) { modsList.AddRange(from m in Directory.GetDirectories(usermodsDirectory, "*.hmod", SearchOption.TopDirectoryOnly) select Path.GetFileNameWithoutExtension(m)); modsList.AddRange(from m in Directory.GetFiles(usermodsDirectory, "*.hmod", SearchOption.TopDirectoryOnly) select Path.GetFileNameWithoutExtension(m)); } } using (WorkerForm worker = new WorkerForm()) { worker.Task = WorkerForm.Tasks.GetHmods; worker.HmodsToLoad = modsList.ToArray(); worker.Start(); hmods = worker.LoadedHmods; } populateList(); if (filesToAdd != null) { AddMods(filesToAdd); } this.AllowDrop = allowDropMods; }