void loadDifferences() { // here we would query a website for latest patch rev. WzMapleVersion vrs = WzMapleVersion.GMS; // is classic old GMS?? string imgPath = textBox1.Text; string wzPath = textBox2.Text; Console.WriteLine("imgPath: " + imgPath + ", wzPath: " + wzPath); WzFile affected = new WzFile(wzPath, vrs); affected.ParseWzFile(); char[] split = { '\\', '/' }; string imgName = imgPath.Split(split)[imgPath.Split(split).Length - 1].Trim(); Console.WriteLine("imgName: " + imgName); WzImage toPatch = affected.WzDirectory.GetImageByName(imgName); FileStream stream = File.OpenRead(imgPath); WzImage img = new WzImage("-" + imgName, stream, vrs); img.ParseImage(); toPatch.ParseImage(); toPatch.ClearProperties(); toPatch.AddProperties(img.WzProperties); affected.WzDirectory.GetImageByName(imgName).changed = true; affected.SaveToDisk(wzPath + ".new"); affected.Dispose(); stream.Close(); while (!tryDelete(wzPath)) { Thread.Sleep(1000); // ensure that we can rename the file } File.Move(wzPath + ".new", wzPath); // rewrite w/ patched file button1.Text = "Done!"; }
private void saveButton_Click(object sender, EventArgs e) { if (versionBox.Value < 0) { Warning.Error(HaRepacker.Properties.Resources.SaveVersionError); return; } SaveFileDialog dialog = new SaveFileDialog() { Title = HaRepacker.Properties.Resources.SelectOutWz, Filter = string.Format("{0}|*.wz", HaRepacker.Properties.Resources.WzFilter) }; if (dialog.ShowDialog() != System.Windows.Forms.DialogResult.OK) { return; } if (wzf is WzFile && wzf.MapleVersion != (WzMapleVersion)encryptionBox.SelectedIndex) { PrepareAllImgs(((WzFile)wzf).WzDirectory); } wzf.MapleVersion = (WzMapleVersion)encryptionBox.SelectedIndex; if (wzf is WzFile) { ((WzFile)wzf).Version = (short)versionBox.Value; } if (wzf.FilePath != null && wzf.FilePath.ToLower() == dialog.FileName.ToLower()) { wzf.SaveToDisk(dialog.FileName + "$tmp"); wzNode.Delete(); File.Delete(dialog.FileName); File.Move(dialog.FileName + "$tmp", dialog.FileName); } else { wzf.SaveToDisk(dialog.FileName); wzNode.Delete(); } Program.WzMan.LoadWzFile(dialog.FileName, (WzMapleVersion)encryptionBox.SelectedIndex, panel); Close(); }
private void saveButton_Click(object sender, EventArgs e) { if (versionBox.Value < 0) { Warning.Error("Version must be above 0"); return; } SaveFileDialog dialog = new SaveFileDialog() { Title = "Select where to save the file", Filter = "WZ Files(*.wz)|*.wz" }; if (dialog.ShowDialog() != System.Windows.Forms.DialogResult.OK) { return; } if (wzf is WzFile && wzf.MapleVersion != (WzMapleVersion)encryptionBox.SelectedIndex) { PrepareAllImgs(((WzFile)wzf).WzDirectory); } wzf.MapleVersion = (WzMapleVersion)encryptionBox.SelectedIndex; if (wzf is WzFile) { ((WzFile)wzf).Version = (short)versionBox.Value; } if (wzf.FilePath != null && wzf.FilePath.ToLower() == dialog.FileName.ToLower()) { wzf.SaveToDisk(dialog.FileName + "$tmp"); wzNode.Delete(); File.Delete(dialog.FileName); File.Move(dialog.FileName + "$tmp", dialog.FileName); } else { wzf.SaveToDisk(dialog.FileName); wzNode.Delete(); } Program.WzMan.LoadWzFile(dialog.FileName, (WzMapleVersion)encryptionBox.SelectedIndex, panel); Close(); }
private void saveButton_Click(object sender, EventArgs e) { if (versionBox.Value < 0) { Warning.Error(HaRepacker.Properties.Resources.SaveVersionError); return; } using (SaveFileDialog dialog = new SaveFileDialog() { Title = HaRepacker.Properties.Resources.SelectOutWz, Filter = string.Format("{0}|*.wz", HaRepacker.Properties.Resources.WzFilter) }) { if (dialog.ShowDialog() != System.Windows.Forms.DialogResult.OK) { return; } WzMapleVersion wzMapleVersionSelected = (WzMapleVersion)encryptionBox.SelectedIndex; if (this.IsRegularWzFile) { if (wzf is WzFile && wzf.MapleVersion != wzMapleVersionSelected) { PrepareAllImgs(((WzFile)wzf).WzDirectory); } wzf.MapleVersion = (WzMapleVersion)encryptionBox.SelectedIndex; if (wzf is WzFile) { ((WzFile)wzf).Version = (short)versionBox.Value; } if (wzf.FilePath != null && wzf.FilePath.ToLower() == dialog.FileName.ToLower()) { wzf.SaveToDisk(dialog.FileName + "$tmp"); wzNode.Delete(); File.Delete(dialog.FileName); File.Move(dialog.FileName + "$tmp", dialog.FileName); } else { wzf.SaveToDisk(dialog.FileName); wzNode.Delete(); } // Reload the new file Program.WzMan.LoadWzFile(dialog.FileName, (WzMapleVersion)encryptionBox.SelectedIndex, panel); } else { byte[] WzIv = WzTool.GetIvByMapleVersion(wzMapleVersionSelected); // Save file string tmpFilePath = dialog.FileName + ".tmp"; string targetFilePath = dialog.FileName; using (FileStream oldfs = File.Open(tmpFilePath, FileMode.OpenOrCreate)) { using (WzBinaryWriter wzWriter = new WzBinaryWriter(oldfs, WzIv)) { wzImg.SaveImage(wzWriter, true); // Write to temp folder } } try { File.Copy(tmpFilePath, targetFilePath, true); File.Delete(tmpFilePath); } catch (Exception exp) { Debug.WriteLine(exp); // nvm, dont show to user } wzNode.Delete(); // Reload the new file WzImage img = Program.WzMan.LoadDataWzHotfixFile(dialog.FileName, wzMapleVersionSelected, panel); } } Close(); }
/// <summary> /// On save button clicked /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SaveButton_Click(object sender, EventArgs e) { if (versionBox.Value < 0) { Warning.Error(HaRepacker.Properties.Resources.SaveVersionError); return; } using (SaveFileDialog dialog = new SaveFileDialog() { Title = HaRepacker.Properties.Resources.SelectOutWz, FileName = wzNode.Text, Filter = string.Format("{0}|*.wz", HaRepacker.Properties.Resources.WzFilter) }) { if (dialog.ShowDialog() != System.Windows.Forms.DialogResult.OK) { return; } WzMapleVersion wzMapleVersionSelected = MainForm.GetWzMapleVersionByWzEncryptionBoxSelection(encryptionBox.SelectedIndex); // new encryption selected if (this.IsRegularWzFile) { if (wzf is WzFile file && wzf.MapleVersion != wzMapleVersionSelected) { PrepareAllImgs(file.WzDirectory); } wzf.MapleVersion = wzMapleVersionSelected; if (wzf is WzFile file1) { file1.Version = (short)versionBox.Value; } if (wzf.FilePath != null && wzf.FilePath.ToLower() == dialog.FileName.ToLower()) { wzf.SaveToDisk(dialog.FileName + "$tmp", wzMapleVersionSelected); wzNode.DeleteWzNode(); try { File.Delete(dialog.FileName); File.Move(dialog.FileName + "$tmp", dialog.FileName); }catch (IOException ex) { MessageBox.Show("Handle error overwriting WZ file", HaRepacker.Properties.Resources.Error); } } else { wzf.SaveToDisk(dialog.FileName, wzMapleVersionSelected); wzNode.DeleteWzNode(); } // Reload the new file WzFile loadedWzFile = Program.WzFileManager.LoadWzFile(dialog.FileName, wzMapleVersionSelected); if (loadedWzFile != null) { Program.WzFileManager.AddLoadedWzFileToMainPanel(loadedWzFile, panel); } } else { byte[] WzIv = WzTool.GetIvByMapleVersion(wzMapleVersionSelected); // Save file string tmpFilePath = dialog.FileName + ".tmp"; string targetFilePath = dialog.FileName; bool error_noAdminPriviledge = false; try { using (FileStream oldfs = File.Open(tmpFilePath, FileMode.OpenOrCreate)) { using (WzBinaryWriter wzWriter = new WzBinaryWriter(oldfs, WzIv)) { wzImg.SaveImage(wzWriter, true); // Write to temp folder } } try { File.Copy(tmpFilePath, targetFilePath, true); File.Delete(tmpFilePath); } catch (Exception exp) { Debug.WriteLine(exp); // nvm, dont show to user } wzNode.DeleteWzNode(); } catch (UnauthorizedAccessException) { error_noAdminPriviledge = true; } // Reload the new file WzImage img = Program.WzFileManager.LoadDataWzHotfixFile(dialog.FileName, wzMapleVersionSelected, panel); if (img == null || error_noAdminPriviledge) { MessageBox.Show(HaRepacker.Properties.Resources.MainFileOpenFail, HaRepacker.Properties.Resources.Error); } } } Close(); }
static void Main(string[] args) { Console.Title = $"{General.Name} (v{General.Version.ToString("0.0")})"; if (!File.Exists("Quest.wz")) { Console.WriteLine("Quest.wz is missing."); Console.ReadLine(); return; } bool silent = false; bool autoupdate = true; foreach (string arg in args) { switch (arg) { case "-silent": { silent = true; break; } case "-noupdate": { autoupdate = false; break; } case "-searchmode": { SearchMode(); return; } } } if (!silent) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine($"Welcome to {Console.Title}!" + Environment.NewLine); Console.ForegroundColor = ConsoleColor.White; } if (autoupdate) { AutoUpdater.StartUpdate(); } if (File.Exists("Quest.wz.patched")) { File.Delete("Quest.wz.patched"); } var exclusions = ReadExclusions(); if (!silent) { if (exclusions.Count == 0) { Console.WriteLine("--- No quests will be excluded."); } else { if (exclusions.Count > 50) { var fifty = exclusions.ToList(); fifty.RemoveRange(50, fifty.Count - 50); Console.WriteLine($"--- Excluded quests: {string.Join(", ", fifty)}... and {exclusions.Count - 50} more!"); } else { Console.WriteLine($"--- Excluded quests: {string.Join(", ", exclusions)}."); } } Console.WriteLine(Environment.NewLine + "About to iterate through Quest.wz now." + Environment.NewLine); } var delete = new List <string> { "Act.img", "Check.img", "Exclusive.img", "QuestDestination.img", "QuestExpByLevel.img", "QuestInfo.img", "QuestPerformByDay.img", "Say.img", "SQuest.img" }; using (var questwz = new WzFile("Quest.wz", WzMapleVersion.BMS)) // for some reason GMS uses the BMS format..? { questwz.ParseWzFile(); foreach (string image in delete) { var img = questwz.WzDirectory.GetImageByName(image); var original = img.WzProperties.ToList(); foreach (var prop in original) { if (!exclusions.Contains(int.Parse(prop.Name))) { img.WzProperties.Remove(prop); if (!img.Changed) { img.Changed = true; } } } if (!silent && img.Changed) { Console.WriteLine($"--- Cleaned {image} (entries: {original.Count - img.WzProperties.Count})"); } } questwz.WzDirectory.ParseImages(); if (File.Exists("Quest.wz.bak")) { File.Delete("Quest.wz.bak"); } File.Copy("Quest.wz", "Quest.wz.bak"); questwz.SaveToDisk("Quest.wz.patched"); if (!silent) { Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine(Environment.NewLine + "--- Saved patched file to Quest.wz.patched."); } } if (!silent) { Console.ForegroundColor = ConsoleColor.White; Console.Write(Environment.NewLine + "Finished patching!"); Console.ReadLine(); } }