/// <summary> /// The progress timer elapsed for uninstalling mods. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="args"> /// The args. /// </param> private void UninstallProgressTimerElapsed(object sender, EventArgs args) { if (this.rewriter == null) { this.progressTimer.Stop(); return; } this.rewriter.ProgressMutex.WaitOne(); this.TotalProgressLabel.Text = this.rewriter.TotalProgressMessage + " " + this.rewriter.BundleProgressMessage; this.BundleProgress.Value = this.rewriter.BundleProgressPercentage; int totalPercentage = this.rewriter.TotalProgressPercentage; if (totalPercentage == -1) { this.TotalProgress.Style = ProgressBarStyle.Marquee; } else { this.TotalProgress.Style = ProgressBarStyle.Blocks; this.TotalProgress.Value = totalPercentage; } if (this.rewriter.Done) { if (this.rewriter.Error != null) { MessageBox.Show("Error occured during modding of bundle files: " + this.rewriter.Error, "Error!"); } this.rewriter.ProgressMutex.ReleaseMutex(); this.progressTimer.Enabled = false; this.progressTimer.Stop(); this.rewriter = null; this.ApplyButton.Enabled = this.savedStateApplyMod; this.OpenModButton.Enabled = this.savedStateOpenMod; foreach (ListViewItem lvi in this.availiableMods_listView.Items) { if (((BundleMod)lvi.Tag).actionStatus == BundleMod.ModActionStatus.Remove) { this.mods_db.RemoveInstalledMod((BundleMod)lvi.Tag); } } this.mods_db.SaveModBackups(); return; } this.rewriter.ProgressMutex.ReleaseMutex(); }
/// <summary> /// The apply button_ click. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The e. /// </param> private void ApplyButtonClick(object sender, EventArgs e) { if (!String.IsNullOrEmpty(StaticStorage.settings.GameProcess)) { Process[] pname = Process.GetProcessesByName(StaticStorage.settings.GameProcess); if (pname.Length != 0) { MessageBox.Show(StaticStorage.settings.Game + " is currently running, cannot patch.\nPlease close the game before applying mods."); return; } } if (!this.TestAssetsFolder()) { MessageBox.Show("Your assets folder appears to be invalid. Please select a valid assets folder in Options.", "Invalid assets folder."); return; } if (this.rewriter != null) return; if (this.ExtractTimer != null) { if (this.ExtractTimer.Enabled) { MessageBox.Show("Cannot perform 2 actions at once"); return; } } this.TotalProgressLabel.Text = "Preparing to Apply Changes"; this.savedStateApplyMod = this.ApplyButton.Enabled; this.savedStateOpenMod = this.OpenModButton.Enabled; this.savedStateRefreshButton = this.refreshButton.Enabled; this.savedStateFileControlButton = this.filecontrol_button.Enabled; this.availiableMods_listView.Enabled = false; this.availiableModsSearch_textbox.Enabled = false; this.ApplyButton.Enabled = false; this.OpenModButton.Enabled = false; this.refreshButton.Enabled = false; this.filecontrol_button.Enabled = false; this.ExtraOptions1.Enabled = false; List<BundleMod> uninstall = new List<BundleMod>(); List<BundleMod> reinstall = new List<BundleMod>(); List<BundleMod> install = new List<BundleMod>(); List<BundleMod> install_combo = new List<BundleMod>(); Queue<BundleRewriteItem> mix_bri = new Queue<BundleRewriteItem>(); BundleMod mix = new BundleMod(); // 0 = Nothing, 1 = Marked for install (limegreen), 2 = Marked for removal (red), 3 = Marked for reinstallation (yellow), 4 = Dictionary<string, BundleMod> modsList = this.mods_db.modsList; install = modsList.Values.Where(mod => mod.actionStatus == BundleMod.ModActionStatus.Install).ToList(); reinstall = modsList.Values.Where(mod => mod.actionStatus == BundleMod.ModActionStatus.Reinstall || mod.actionStatus == BundleMod.ModActionStatus.ForcedReinstall).ToList(); uninstall = modsList.Values.Where(mod => mod.actionStatus == BundleMod.ModActionStatus.Remove).ToList(); //Perform other actions //Generate install/reinstall/uninstall mods if (uninstall.Count > 0) { //Generate Bundle Mod foreach (BundleMod uninstMod in uninstall) { if (uninstMod.type == BundleMod.ModType.lua) { Directory.Delete(uninstMod.file, true); } else { foreach (BundleRewriteItem bri in uninstMod.ItemQueue) { if (uninstMod.type == BundleMod.ModType.mod_override) { if (bri.isOverrideable() //&& !bri.ReplacementFile.EndsWith(".script") ) { if (!string.IsNullOrEmpty(StaticStorage.Known_Index.GetPath(bri.BundlePath)) && !string.IsNullOrEmpty(StaticStorage.Known_Index.GetExtension(bri.BundleExtension))) { string extrname = ""; extrname += StaticStorage.Known_Index.GetPath(bri.BundlePath); extrname += "." + StaticStorage.Known_Index.GetExtension(bri.BundleExtension); string modName = bri.ModName; modName = Path.GetInvalidFileNameChars().Aggregate(modName, (current, c) => current.Replace(c.ToString(), "_")); if (File.Exists(Path.Combine(StaticStorage.settings.AssetsFolder, "mod_overrides", modName))) { if (File.Exists(Path.Combine(StaticStorage.settings.AssetsFolder, "mod_overrides", modName, extrname))) { File.Delete(Path.Combine(StaticStorage.settings.AssetsFolder, "mod_overrides", modName, extrname)); DeleteEmptyDirs(Path.Combine(StaticStorage.settings.AssetsFolder, "mod_overrides", modName)); } } } } } else { if (!mix_bri.Contains(bri)) { BundleRewriteItem newBri = bri; newBri.toRemove = true; mix_bri.Enqueue(newBri); } } } if (File.Exists(Path.Combine(StaticStorage.settings.AssetsFolder, "mod_overrides", uninstMod.getEscapedName(), "mod.txt"))) { File.Delete(Path.Combine(StaticStorage.settings.AssetsFolder, "mod_overrides", uninstMod.getEscapedName(), "mod.txt")); } } } } if (reinstall.Count > 0) { //Generate Bundle Mod foreach (BundleMod bm in reinstall) { foreach (BundleRewriteItem bri in bm.ItemQueue) { if (!bri.ReplacementFile.EndsWith(".script") && filecontrolSelectedDictionary.ContainsKey(bri.getBundleEntryPath())) { if (filecontrolSelectedDictionary[bri.getBundleEntryPath()] != bm.Name) { BundleRewriteItem newBri = bri; newBri.toRemove = true; mix_bri.Enqueue(newBri); continue; } } if (bri.toReinstall && !mix_bri.Contains(bri)) { BundleRewriteItem newBri = bri; newBri.toRemove = false; mix_bri.Enqueue(newBri); } } if (bm.UtilizesOverride) { if (File.Exists(Path.Combine(StaticStorage.settings.AssetsFolder, "mod_overrides", bm.getEscapedName())) && File.Exists(Path.Combine(StaticStorage.settings.AssetsFolder, "mod_overrides", bm.getEscapedName(), "mod.txt"))) { using (StreamWriter modsw = File.CreateText(Path.Combine(StaticStorage.settings.AssetsFolder, "mod_overrides", bm.getEscapedName(), "mod.txt"))) { modsw.Write(OverrideMod.Serialize(new OverrideMod(bm.Name, bm.Author, bm.Description))); } } } } } if (install.Count > 0) { //Generate Bundle Mod foreach (BundleMod bm in install) { foreach (BundleRewriteItem bri in bm.ItemQueue) { if (!bri.ReplacementFile.EndsWith(".script") && filecontrolSelectedDictionary.ContainsKey(bri.getBundleEntryPath())) { if (filecontrolSelectedDictionary[bri.getBundleEntryPath()] != bm.Name) continue; } if (!mix_bri.Contains(bri)) { BundleRewriteItem newBri = bri; newBri.toRemove = false; mix_bri.Enqueue(newBri); } } if (bm.UtilizesOverride) { if (!Directory.Exists(Path.Combine(StaticStorage.settings.AssetsFolder, "mod_overrides", bm.getEscapedName()))) Directory.CreateDirectory(Path.Combine(StaticStorage.settings.AssetsFolder, "mod_overrides", bm.getEscapedName())); using (StreamWriter modsw = File.CreateText(Path.Combine(StaticStorage.settings.AssetsFolder, "mod_overrides", bm.getEscapedName(), "mod.txt"))) { modsw.Write(OverrideMod.Serialize(new OverrideMod(bm.Name, bm.Author, bm.Description))); } } } } install_combo.AddRange(install); install_combo.AddRange(reinstall); mix.ItemQueue = new HashSet<BundleRewriteItem>(mix_bri.ToList()); int BufferSize; if (!Int32.TryParse(this.patchingBufferSize.Text, out BufferSize)) { BufferSize = 4096; } this.rewriter = new BundleRewriter( "", mix, BufferSize, StaticStorage.settings.AssetsFolder, StaticStorage.settings.BackupType, StaticStorage.settings.OverrideFolder, StaticStorage.settings.OverrideFolderDummies, StaticStorage.settings.OverrideFolderShared, true, false); this.progressTimer = new Timer(); this.progressTimer.Interval = 500; this.progressTimer.Tick += this.MultiProgressTimerElapsed; this.progressTimer.Enabled = true; this.progressTimer.Start(); rewriterThread = new Thread(() => this.rewriter.ApplyChanges(install_combo.ToArray(), false)); rewriterThread.IsBackground = true; rewriterThread.Start(); }
private void runCorruptedCheckButton_Click(object sender, EventArgs e) { if (!this.TestAssetsFolder()) { MessageBox.Show( "Your assets folder appears to be invalid. Please select a valid assets folder in Options.", "Invalid assets folder."); return; } if (this.rewriter != null) return; this.checkedDate = DateTime.Now; this.checkedBundlesReport.Clear(); this.repairCorruptedBundlesCheckCheckBox.Enabled = false; this.verifyCorruptedBundlesCheckCheckBox.Enabled = false; this.corruptedShowOnlyCorrupted_checkbox.Enabled = false; this.attemptRepair_button.Enabled = false; this.savedStateApplyMod = this.ApplyButton.Enabled; this.savedStateOpenMod = this.OpenModButton.Enabled; this.ApplyButton.Enabled = false; this.OpenModButton.Enabled = false; int BufferSize; if (!Int32.TryParse(this.patchingBufferSize.Text, out BufferSize)) { BufferSize = 4096; } this.rewriter = new BundleRewriter( "", new BundleMod(), BufferSize, StaticStorage.settings.AssetsFolder, StaticStorage.settings.BackupType, StaticStorage.settings.OverrideFolder, StaticStorage.settings.OverrideFolderDummies, StaticStorage.settings.OverrideFolderShared, true, false); this.progressTimer = new Timer(); this.progressTimer.Interval = 500; this.progressTimer.Tick += this.BundleCheckProgressTimerElapsed; this.progressTimer.Enabled = true; this.progressTimer.Start(); rewriterThread = new Thread(() => this.rewriter.CheckBundles(this.repairCorruptedBundlesCheckCheckBox.Checked)); rewriterThread.IsBackground = true; rewriterThread.Start(); }
/// <summary> /// The progress timer elapsed. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="args"> /// The args. /// </param> private void ProgressTimerElapsed(object sender, EventArgs args) { if (this.rewriter == null) { this.progressTimer.Stop(); return; } this.rewriter.ProgressMutex.WaitOne(); this.TotalProgressLabel.Text = this.rewriter.TotalProgressMessage + " " + this.rewriter.BundleProgressMessage; this.BundleProgress.Value = this.rewriter.BundleProgressPercentage; int totalPercentage = this.rewriter.TotalProgressPercentage; if (totalPercentage == -1) { this.TotalProgress.Style = ProgressBarStyle.Marquee; } else { this.TotalProgress.Style = ProgressBarStyle.Blocks; this.TotalProgress.Value = totalPercentage; } if (this.rewriter.allowBackup) { this.mods_db.RemoveInstalledMod(this.rewriter.backupEntry); this.mods_db.AddInstalledMod(this.rewriter.backupEntry); this.mods_db.SaveModBackups(); this.rewriter.allowBackup = false; } if (this.rewriter.Done) { if (this.rewriter.Error != null) MessageBox.Show("Error occured during modding of bundle files: " + this.rewriter.Error, "Error!"); this.rewriter.ProgressMutex.ReleaseMutex(); this.progressTimer.Enabled = false; this.progressTimer.Stop(); this.rewriter = null; this.ApplyButton.Enabled = this.savedStateApplyMod; this.OpenModButton.Enabled = this.savedStateOpenMod; return; } this.rewriter.ProgressMutex.ReleaseMutex(); }
/// <summary> /// The progress timer elapsed for multiple mods. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="args"> /// The args. /// </param> private void MultiProgressTimerElapsed(object sender, EventArgs args) { if (this.rewriter == null) { this.progressTimer.Stop(); return; } this.rewriter.ProgressMutex.WaitOne(); double SpeedTimeTaken = (((this.rewriter.SpeedElapsedTime.ElapsedMilliseconds / 1000L) < 1L ? 1.0d : (this.rewriter.SpeedElapsedTime.ElapsedMilliseconds / 1000L)) * 1.0d); double PatchSpeed = (this.rewriter.SpeedEntryCount * 1.0d) / SpeedTimeTaken; double TimeTaken = (((this.rewriter.TotalElapsedTime.ElapsedMilliseconds / 1000L) < 1L ? 1.0d : (this.rewriter.TotalElapsedTime.ElapsedMilliseconds / 1000L)) * 1.0d); double AvgPatchSpeed = (this.rewriter.CurrentEntryCount * 1.0d) / TimeTaken; lock ((object)this.rewriter.SpeedEntryCount) { this.rewriter.SpeedEntryCount = 0L; } this.rewriter.SpeedElapsedTime.Restart(); this.patchingTimeDetails.Text = "Current Bundle: " + this.rewriter.CurrentBundle + " Buffer: " + this.rewriter.bufferSize + "\r\n" + "Speed: " + PatchSpeed.ToString("0.##") + " Entries/Sec \r\n" + "Avg. Speed: " + AvgPatchSpeed.ToString("0.##") + " Entries/Sec || Est. Time left: " + (((TimeTaken / this.rewriter.CurrentEntryCount) * (this.rewriter.TotalEntryCount - this.rewriter.CurrentEntryCount)) < 60.0 ? ((TimeTaken / this.rewriter.CurrentEntryCount) * (this.rewriter.TotalEntryCount - this.rewriter.CurrentEntryCount)).ToString("0.##") + " seconds" : ((TimeTaken / this.rewriter.CurrentEntryCount) * (this.rewriter.TotalEntryCount - this.rewriter.CurrentEntryCount) / 60).ToString("0") + " minute" + ((int)((TimeTaken / this.rewriter.CurrentEntryCount) * (this.rewriter.TotalEntryCount - this.rewriter.CurrentEntryCount) / 60) > 1 ? "s" : "") + ((int)((TimeTaken / this.rewriter.CurrentEntryCount) * (this.rewriter.TotalEntryCount - this.rewriter.CurrentEntryCount) % 60.0) > 0 ? " " + ((TimeTaken / this.rewriter.CurrentEntryCount) * (this.rewriter.TotalEntryCount - this.rewriter.CurrentEntryCount) % 60).ToString("0") + " seconds" : "")); this.TotalProgressLabel.Text = this.rewriter.TotalProgressMessage + " " + this.rewriter.BundleProgressMessage; this.BundleProgress.Value = this.rewriter.BundleProgressPercentage; int totalPercentage = this.rewriter.TotalProgressPercentage; if (totalPercentage == -1) { this.TotalProgress.Style = ProgressBarStyle.Marquee; } else { this.TotalProgress.Style = ProgressBarStyle.Blocks; this.TotalProgress.Value = totalPercentage; } if (TaskbarManager.IsPlatformSupported) { TaskbarManager.Instance.SetProgressState(TaskbarProgressBarState.Normal); TaskbarManager.Instance.SetProgressValue(this.rewriter.CurrentBundlesCount, this.rewriter.TotalBundlesCount); } if (this.rewriter.allowBackup) { foreach (BackupEntry be in this.rewriter.backupEntries) { this.mods_db.RemoveInstalledMod(be); this.mods_db.AddInstalledMod(be); } this.mods_db.SaveModBackups(); this.rewriter.allowBackup = false; } if (this.rewriter.Error != null) { if (TaskbarManager.IsPlatformSupported) TaskbarManager.Instance.SetProgressState(TaskbarProgressBarState.Error); MessageBox.Show("Error occured during modding of bundle files: " + this.rewriter.Error, "Error!"); this.rewriter.Done = true; } if (this.rewriter.Done) { //if (this.rewriter.Error != null) // MessageBox.Show("Error occured during modding of bundle files: " + this.rewriter.Error, "Error!"); if (TaskbarManager.IsPlatformSupported) TaskbarManager.Instance.SetProgressState(TaskbarProgressBarState.NoProgress); if (StaticStorage.settings.PlaySoundOnCompletion) System.Media.SystemSounds.Beep.Play(); this.availiableMods_listView.Enabled = true; this.availiableModsSearch_textbox.Enabled = true; this.ApplyButton.Enabled = this.savedStateApplyMod; this.OpenModButton.Enabled = this.savedStateOpenMod; this.refreshButton.Enabled = this.savedStateRefreshButton; this.filecontrol_button.Enabled = this.savedStateFileControlButton; this.ExtraOptions1.Enabled = true; if (this.rewriter.Error == null) { foreach (ListViewItem lvi in this.availiableMods_listView.Items) { if (((BundleMod)lvi.Tag).actionStatus == BundleMod.ModActionStatus.Remove) { this.mods_db.RemoveInstalledMod((BundleMod)lvi.Tag); } } if (StaticStorage.settings.RunGameOnCompletion) { System.Diagnostics.Process.Start("steam://run/" + StaticStorage.settings.GameSteamID); } } this.mods_db.SaveModBackups(); this.mods_db.LoadMods(true); this.updateModsListView(); this.rewriter.ProgressMutex.ReleaseMutex(); this.progressTimer.Enabled = false; this.progressTimer.Stop(); this.rewriter = null; return; } this.rewriter.ProgressMutex.ReleaseMutex(); }
private void ConfigureReplacementButton_Click(object sender, EventArgs e) { /* * File Replacement * Patch Script * Strings Patch * Sound Bank Patch */ ulong path, extension; uint language; switch(this.fileReplacementType_ComboBox.Text) { case ("File Replacement"): return; case ("Strings Patch"): if (!this.CheckBundleFileName(this.BundleFileName.Text.ToLower().Replace('\\', '/'), out path, out extension, out language)) { return; } BundleRewriteItem tempBRI = new BundleRewriteItem(path, language, extension); tempBRI.IsLanguageSpecific = (Path.GetFileName(this.BundleFileName.Text).Split('.').Length == 3); BundleRewriter br = new BundleRewriter(StaticStorage.settings.AssetsFolder); MemoryStream stringsStream = new MemoryStream(); br.RetrieveFile(tempBRI, out stringsStream); DieselStrings ds = new DieselStrings(stringsStream); ManageStrings msForm = new ManageStrings(ds); msForm.ShowDialog(this); /* FileControl filecontrolForm = new FileControl(); filecontrolForm.filecontrolDictionary = filecontrolDictionary; filecontrolForm.filecontrolSelectedDictionary = filecontrolSelectedDictionary; filecontrolForm.ShowDialog(this); filecontrolSelectedDictionary = filecontrolForm.filecontrolSelectedDictionary; */ break; case ("Sound Bank Patch"): if (!this.CheckBundleFileName(this.BundleFileName.Text.ToLower().Replace('\\', '/'), out path, out extension, out language)) { return; } BundleRewriteItem soundtempBRI = new BundleRewriteItem(path, language, extension); soundtempBRI.IsLanguageSpecific = (Path.GetFileName(this.BundleFileName.Text).Split('.').Length == 3); BundleRewriter soundbr = new BundleRewriter(StaticStorage.settings.AssetsFolder); MemoryStream soundStream = new MemoryStream(); soundbr.RetrieveFile(soundtempBRI, out soundStream); SoundPatch spForm = new SoundPatch(Path.GetFileNameWithoutExtension(this.BundleFileName.Text.ToLower()), soundStream); spForm.ShowDialog(this); break; default: break; } }
/// <summary> /// The progress timer elapsed for checking bundles. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="args"> /// The args. /// </param> private void BundleCheckProgressTimerElapsed(object sender, EventArgs args) { if (this.rewriter == null) { this.progressTimer.Stop(); return; } this.rewriter.ProgressMutex.WaitOne(); this.progressTextCorruptedBundlesCheck.Text = "Current progress: " + this.rewriter.TotalProgressMessage + " Corrupted: " + this.rewriter.checkBundlesReport.Count(e => e.Value != String.Empty); this.progressCorruptedBundlesCheck.Value = this.rewriter.TotalProgressPercentage; if (TaskbarManager.IsPlatformSupported) { TaskbarManager.Instance.SetProgressState(TaskbarProgressBarState.Normal); TaskbarManager.Instance.SetProgressValue(this.rewriter.CurrentBundlesCount, this.rewriter.TotalBundlesCount); } if (this.rewriter.Done) { if (this.rewriter.Error != null) { if (TaskbarManager.IsPlatformSupported) TaskbarManager.Instance.SetProgressState(TaskbarProgressBarState.Error); MessageBox.Show("Error occured during modding of bundle files: " + this.rewriter.Error, "Error!"); } if (TaskbarManager.IsPlatformSupported) TaskbarManager.Instance.SetProgressState(TaskbarProgressBarState.NoProgress); this.checkedBundlesReport = new Dictionary<string, string>(this.rewriter.checkBundlesReport); this.generateCorruptedReport(); this.rewriter.ProgressMutex.ReleaseMutex(); this.progressTimer.Enabled = false; this.progressTimer.Stop(); this.rewriter = null; this.ApplyButton.Enabled = this.savedStateApplyMod; this.OpenModButton.Enabled = this.savedStateOpenMod; if (this.verifyCorruptedBundlesCheckCheckBox.Checked) { System.Diagnostics.Process.Start("steam://validate/" + StaticStorage.settings.GameSteamID); } this.repairCorruptedBundlesCheckCheckBox.Enabled = true; this.verifyCorruptedBundlesCheckCheckBox.Enabled = true; this.corruptedShowOnlyCorrupted_checkbox.Enabled = true; this.attemptRepair_button.Enabled = true; return; } this.rewriter.ProgressMutex.ReleaseMutex(); }