Program() { InitializeComponent(); string prevPath = (string)Properties.Settings.Default["SCPath"]; textBoxPath.Text = String.IsNullOrEmpty(prevPath) ? ExecutableUtils.GetDefaultPath() : prevPath; // Fill grid and after enable the `Changed` callback foreach (Patch patch in Enum.GetValues(typeof(Patch))) { PatchInfo info = PatchInfo.allPatches[patch]; string conflicts = String.Join(", ", info.ConflictingPatches.Select(p => p.ToString()).ToArray()); dataGridViewPatches.Rows.Add(false, info.Type, patch, info.Description, info.ConflictingPatches, conflicts); } this.dataGridViewPatches.CellValueChanged += this.dataGridViewPatches_CellValueChanged; // restore checkboxes StringCollection selectedPatches = (StringCollection)Properties.Settings.Default["SelectedPatches"]; if (selectedPatches != null) { foreach (DataGridViewRow row in dataGridViewPatches.Rows) { string patch = ((Patch)row.Cells["ColumnName"].Value).ToString(); row.Cells[0].Value = selectedPatches.Contains(patch); } } #if DEBUG checkBoxParanoia.Checked = true; #endif }
private void PatchExe() { if (enabledPatches.Count == 0) { MessageBox.Show("No patch selected"); return; } if (!File.Exists(currentExePath)) { MessageBox.Show("Can't find game executable in \"" + currentExePath + "\"!" + Environment.NewLine + "Please give the correct path in the \"Path\" box"); return; } if (!File.Exists(originalExePath) && ExecutableUtils.IsRecognizedExe(currentExePath)) { File.Copy(currentExePath, originalExePath); } if (!ExecutableUtils.IsRecognizedExe(originalExePath)) { MessageBox.Show("Unrecognized SpaceChem executable, patching will not be executed"); return; } bool isSteam = ExecutableUtils.IsSteamExe(originalExePath); using (ModuleDefinition spacechemAssembly = ModuleDefinition.ReadModule(originalExePath)) using (ModuleDefinition jsonAssembly = ModuleDefinition.ReadModule(Path.Combine(gameFolder, "Newtonsoft.Json.dll"))) using (ModuleDefinition ownAssembly = ModuleDefinition.ReadModule(System.Reflection.Assembly.GetExecutingAssembly().Location)) { Patcher patcher = new Patcher(ownAssembly, spacechemAssembly, jsonAssembly); ISymbolTranslator translator; if (isSteam) { translator = new NoOpSymbolTranslator(); } else { translator = new DictBasedSymbolTranslator(Equivalences.GOG_MAPPINGS); } patcher.ApplyPatches(enabledPatches, translator); spacechemAssembly.Write(patchedExePath); } File.Delete(currentExePath); File.Move(patchedExePath, currentExePath); string message = "Patching executed successfully, added:" + Environment.NewLine; foreach (Patch p in enabledPatches) { message += Environment.NewLine + p.ToString(); } MessageBox.Show(message); }
private void buttonRestore_Click(object sender, EventArgs e) { if (ExecutableUtils.IsRecognizedExe(currentExePath)) { MessageBox.Show("Original exe is already in place"); } else if (ExecutableUtils.IsRecognizedExe(originalExePath)) { File.Delete(currentExePath); File.Move(originalExePath, currentExePath); MessageBox.Show("Original exe restored successfully"); } else { MessageBox.Show("It was not possible to restore the original exe"); } }