From cdd9bfa49e7afb501887c69e7ad6828827de1b2c Mon Sep 17 00:00:00 2001 From: Lol124 <95558254+Romualdo666@users.noreply.github.com> Date: Thu, 20 Jul 2023 12:15:45 -0300 Subject: [PATCH 1/3] Profile Mode Improved. The current profile's name is shown on the main window, Profiles names can be custom and added buttons to export profiles to the current data.win's folder, and import them back to the appdata. --- UndertaleModTool/MainWindow.xaml | 3 +- UndertaleModTool/MainWindow.xaml.cs | 61 ++++++++++++- UndertaleModTool/ProfileSystem.cs | 91 ++++++++++++++++--- UndertaleModTool/Settings.cs | 1 + UndertaleModTool/Windows/SettingsWindow.xaml | 4 + .../Windows/SettingsWindow.xaml.cs | 21 +++++ 6 files changed, 166 insertions(+), 15 deletions(-) diff --git a/UndertaleModTool/MainWindow.xaml b/UndertaleModTool/MainWindow.xaml index 181344326..750b1eddb 100644 --- a/UndertaleModTool/MainWindow.xaml +++ b/UndertaleModTool/MainWindow.xaml @@ -14,10 +14,11 @@ Height="450" Width="800" Loaded="Window_Loaded" AllowDrop="True" Drop="Window_Drop"> - + + diff --git a/UndertaleModTool/MainWindow.xaml.cs b/UndertaleModTool/MainWindow.xaml.cs index 4f0a29f87..74f2e749d 100644 --- a/UndertaleModTool/MainWindow.xaml.cs +++ b/UndertaleModTool/MainWindow.xaml.cs @@ -64,7 +64,7 @@ public partial class MainWindow : Window, INotifyPropertyChanged, IScriptInterfa /// It does that on code compilation. private Tab _currentTab; - + public string CurrentProfileName { get; set; } public UndertaleData Data { get; set; } public string FilePath { get; set; } public string ScriptPath { get; set; } // For the scripting interface specifically @@ -197,11 +197,15 @@ public void RaiseOnSelectedChanged() // Related to profile system and appdata public byte[] MD5PreviouslyLoaded = new byte[13]; public byte[] MD5CurrentlyLoaded = new byte[15]; + public byte[] remMD5 = new byte[15]; + public String CurProfileName = "null"; + public bool is_string = false; public static string AppDataFolder => Settings.AppDataFolder; public static string ProfilesFolder = Path.Combine(Settings.AppDataFolder, "Profiles"); public static string CorrectionsFolder = Path.Combine(Program.GetExecutableDirectory(), "Corrections"); public string ProfileHash = "Unknown"; public bool CrashedWhileEditing = false; + public bool _ProfileModeEnabled = true; // Scripting interface-related private ScriptOptions scriptOptions; @@ -237,6 +241,10 @@ public void RaiseOnSelectedChanged() public MainWindow() { + if (ProfileHash != "Unknown") + _ProfileModeEnabled = true; + else + _ProfileModeEnabled = false; InitializeComponent(); this.DataContext = this; @@ -245,6 +253,9 @@ public MainWindow() TitleMain = "UndertaleModTool by krzys_h v:" + Version; + if (_ProfileModeEnabled == false) + CurrentProfileName = ""; + CanSave = false; CanSafelySave = false; @@ -3924,6 +3935,54 @@ public bool HasEditorForAsset(object asset) return false; } + + public void ExportProfileFolder() + { + if (CurProfileName != "null") + { + var MD5DirName = BitConverter.ToString(MD5CurrentlyLoaded).Replace("-", "").ToLowerInvariant(); + var MD5DirPath = Path.Combine(ProfilesFolder, MD5DirName); + var FileDir = ""; + string[] iwishiwasbetteratnames = FilePath.Split(new char[] { '\\' }); + var directoriesamt = iwishiwasbetteratnames.Length; + for (var i = 0; i < directoriesamt - 1; i++) + { + FileDir += iwishiwasbetteratnames[i] + "\\"; + } + FileDir += "Profiles\\" + MD5DirName; + Directory.CreateDirectory(FileDir); + DirectoryCopy(MD5DirPath, FileDir, true); + this.ShowMessage("Done!"); + File.WriteAllText(FileDir + "\\" + CurProfileName + ".txt", "This is just to let you know the Profile's name.\nThat's all."); + } + else + { + this.ShowMessage("You have to load a Profile beforehand!"); + } + } + public void ImportProfileFolder() + { + if (CanSave == true) + { + var FileDir = ""; + string[] iwishiwasbetteratnames = FilePath.Split(new char[] { '\\' }); + var directoriesamt = iwishiwasbetteratnames.Length; + for (var i = 0; i < directoriesamt - 1; i++) + { + FileDir += iwishiwasbetteratnames[i] + "\\"; + } + FileDir += "Profiles"; + if (Directory.Exists(FileDir)) + { + DirectoryCopy(FileDir, ProfilesFolder, true); + this.ShowMessage("Done!"); + } + else + this.ShowMessage("You have to export a Profile folder to your current data.win's path beforehand!"); + } + else + this.ShowMessage("You have to open a data.win beforehand!"); + } } public class GeneralInfoEditor diff --git a/UndertaleModTool/ProfileSystem.cs b/UndertaleModTool/ProfileSystem.cs index 7d3e5c038..f54128fdd 100644 --- a/UndertaleModTool/ProfileSystem.cs +++ b/UndertaleModTool/ProfileSystem.cs @@ -10,6 +10,7 @@ using UndertaleModLib.Models; using UndertaleModLib.Decompiler; using System.Threading.Tasks; +using System.Text; namespace UndertaleModTool { @@ -225,7 +226,27 @@ await Task.Run(() => { MD5CurrentlyLoaded = md5Instance.ComputeHash(stream); MD5PreviouslyLoaded = MD5CurrentlyLoaded; - ProfileHash = BitConverter.ToString(MD5PreviouslyLoaded).Replace("-", "").ToLowerInvariant(); + remMD5 = MD5PreviouslyLoaded; + String Input_text = ""; + if (SettingsWindow.CustomProfileName == true) + Input_text = SimpleTextInput("Loading Profile, please enter a Profile name.", "(Leaving this blank will name the profile with the data's MD5 hash.)", Input_text, true); + ProfileHash = Input_text; + CurProfileName = ProfileHash; + if (ProfileHash == "") + { + ProfileHash = BitConverter.ToString(MD5PreviouslyLoaded).Replace("-", "").ToLowerInvariant(); + CurProfileName = ProfileHash; + is_string = false; + } + else + { + byte[] idk = Encoding.ASCII.GetBytes(Input_text); + MD5PreviouslyLoaded = idk; + MD5CurrentlyLoaded = idk; + ProfileHash = BitConverter.ToString(MD5PreviouslyLoaded).Replace("-", "").ToLowerInvariant(); + is_string = true; + } + CurrentProfileName = "- Current Profile: " + "\"" + CurProfileName + "\""; } } }); @@ -316,6 +337,23 @@ public async Task ProfileSaveEvent(UndertaleData data, string filename) try { + String Input_text = ""; + if (SettingsWindow.CustomProfileName == true) + { + if (this.ShowQuestion("Do you want to save to the current Profile?") == MessageBoxResult.No) + { + Input_text = SimpleTextInput("Saving Profile, please enter a Profile name.", "(Leaving this blank will name the profile with the data's MD5 hash.)", Input_text, true); + } + else + { + Input_text = CurProfileName; + } + } + is_string = false; + if (Input_text != "") + is_string = true; + byte[] __name = Encoding.ASCII.GetBytes(CurProfileName); + MD5PreviouslyLoaded = __name; string deleteIfModeActive = BitConverter.ToString(MD5PreviouslyLoaded).Replace("-", "").ToLowerInvariant(); bool copyProfile = false; await Task.Run(() => @@ -325,7 +363,12 @@ await Task.Run(() => using (var stream = File.OpenRead(filename)) { MD5CurrentlyLoaded = md5Instance.ComputeHash(stream); - if (BitConverter.ToString(MD5PreviouslyLoaded).Replace("-", "").ToLowerInvariant() != BitConverter.ToString(MD5CurrentlyLoaded).Replace("-", "").ToLowerInvariant()) + if (is_string == true) + { + byte[] idk = Encoding.ASCII.GetBytes(Input_text); + MD5CurrentlyLoaded = idk; + } + if (deleteIfModeActive != BitConverter.ToString(MD5CurrentlyLoaded).Replace("-", "").ToLowerInvariant()) { copyProfile = true; } @@ -338,6 +381,11 @@ await Task.Run(() => if (!SettingsWindow.ProfileModeEnabled || data.IsYYC()) { MD5PreviouslyLoaded = MD5CurrentlyLoaded; + if (is_string == true) + { + byte[] idk = Encoding.ASCII.GetBytes(CurProfileName); + MD5PreviouslyLoaded = idk; + } ProfileHash = BitConverter.ToString(MD5PreviouslyLoaded).Replace("-", "").ToLowerInvariant(); return; } @@ -351,6 +399,18 @@ await Task.Run(() => string MD5DirPathOldTemp; string MD5DirNameNew; string MD5DirPathNew; + string MD5DirPathNewTemp; + bool old_is_string = is_string; + // Get the subdirectories for the specified directory. + MD5DirNameOld = BitConverter.ToString(MD5PreviouslyLoaded).Replace("-", "").ToLowerInvariant(); + MD5DirPathOld = Path.Combine(ProfilesFolder, MD5DirNameOld); + MD5DirPathOldMain = Path.Combine(MD5DirPathOld, "Main"); + MD5DirPathOldTemp = Path.Combine(MD5DirPathOld, "Temp"); + if ((Directory.Exists(MD5DirPathOldMain)) && (Directory.Exists(MD5DirPathOldTemp)) && copyProfile) + { + Directory.Delete(MD5DirPathOldMain, true); + } + DirectoryCopy(MD5DirPathOldTemp, MD5DirPathOldMain, true); if (copyProfile) { MD5DirNameOld = BitConverter.ToString(MD5PreviouslyLoaded).Replace("-", "").ToLowerInvariant(); @@ -359,6 +419,7 @@ await Task.Run(() => MD5DirPathOldTemp = Path.Combine(MD5DirPathOld, "Temp"); MD5DirNameNew = BitConverter.ToString(MD5CurrentlyLoaded).Replace("-", "").ToLowerInvariant(); MD5DirPathNew = Path.Combine(ProfilesFolder, MD5DirNameNew); + MD5DirPathNewTemp = Path.Combine(MD5DirPathNew, "Temp"); DirectoryCopy(MD5DirPathOld, MD5DirPathNew, true); if (Directory.Exists(MD5DirPathOldMain) && Directory.Exists(MD5DirPathOldTemp)) { @@ -367,23 +428,27 @@ await Task.Run(() => DirectoryCopy(MD5DirPathOldMain, MD5DirPathOldTemp, true); } MD5PreviouslyLoaded = MD5CurrentlyLoaded; - // Get the subdirectories for the specified directory. - MD5DirNameOld = BitConverter.ToString(MD5CurrentlyLoaded).Replace("-", "").ToLowerInvariant(); - MD5DirPathOld = Path.Combine(ProfilesFolder, MD5DirNameOld); - MD5DirPathOldMain = Path.Combine(MD5DirPathOld, "Main"); - MD5DirPathOldTemp = Path.Combine(MD5DirPathOld, "Temp"); - if ((Directory.Exists(MD5DirPathOldMain)) && (Directory.Exists(MD5DirPathOldTemp)) && copyProfile) + ProfileHash = Input_text; + CurProfileName = ProfileHash; + if (ProfileHash == "") { - Directory.Delete(MD5DirPathOldMain, true); + ProfileHash = BitConverter.ToString(MD5PreviouslyLoaded).Replace("-", "").ToLowerInvariant(); + CurProfileName = ProfileHash; + is_string = false; } - DirectoryCopy(MD5DirPathOldTemp, MD5DirPathOldMain, true); - - ProfileHash = BitConverter.ToString(MD5PreviouslyLoaded).Replace("-", "").ToLowerInvariant(); + else + { + byte[] idk = Encoding.ASCII.GetBytes(Input_text); + MD5PreviouslyLoaded = idk; + ProfileHash = BitConverter.ToString(MD5PreviouslyLoaded).Replace("-", "").ToLowerInvariant(); + is_string = true; + } + CurrentProfileName = "- Current Profile: " + "\"" + CurProfileName + "\""; profDir = Path.Combine(ProfilesFolder, ProfileHash); Directory.CreateDirectory(profDir); Directory.CreateDirectory(Path.Combine(profDir, "Main")); Directory.CreateDirectory(Path.Combine(profDir, "Temp")); - this.ShowMessage("Profile saved successfully to " + ProfileHash); + this.ShowMessage("Profile saved successfully to " + "\"" + CurProfileName + "\""); } if (SettingsWindow.DeleteOldProfileOnSave && copyProfile) { diff --git a/UndertaleModTool/Settings.cs b/UndertaleModTool/Settings.cs index bb8d26825..d094efe00 100644 --- a/UndertaleModTool/Settings.cs +++ b/UndertaleModTool/Settings.cs @@ -39,6 +39,7 @@ public class Settings // This comment should be cleared in the event that the remedies described are implemented. public bool DeleteOldProfileOnSave { get; set; } = false; + public bool CustomProfileName { get; set; } = false; public bool WarnOnClose { get; set; } = true; private double _globalGridWidth = 20; diff --git a/UndertaleModTool/Windows/SettingsWindow.xaml b/UndertaleModTool/Windows/SettingsWindow.xaml index dcdc08c04..21809569a 100644 --- a/UndertaleModTool/Windows/SettingsWindow.xaml +++ b/UndertaleModTool/Windows/SettingsWindow.xaml @@ -95,6 +95,10 @@ Open application data folder Update app to latest commit + + + + diff --git a/UndertaleModTool/Windows/SettingsWindow.xaml.cs b/UndertaleModTool/Windows/SettingsWindow.xaml.cs index f0d7aa257..e18529366 100644 --- a/UndertaleModTool/Windows/SettingsWindow.xaml.cs +++ b/UndertaleModTool/Windows/SettingsWindow.xaml.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Configuration; using System.Diagnostics; using System.Linq; @@ -111,6 +112,16 @@ public static bool DeleteOldProfileOnSave Settings.Save(); } } + public static bool CustomProfileName + { + get => Settings.Instance.CustomProfileName; + set + { + Settings.Instance.CustomProfileName = value; + Settings.Save(); + } + } + public static bool WarnOnClose { get => Settings.Instance.WarnOnClose; @@ -239,5 +250,15 @@ private void UpdateAppButton_Click(object sender, RoutedEventArgs e) { ((MainWindow)Owner).UpdateApp(this); } + + private void ProfileButtonExport_Click(object sender, RoutedEventArgs e) + { + ((MainWindow)Owner).ExportProfileFolder(); + } + private void ProfileButtonImport_Click(object sender, RoutedEventArgs e) + { + ((MainWindow)Owner).ImportProfileFolder(); + } + } } From b7880bc893092535a7721cec38b198c01f5a1d5a Mon Sep 17 00:00:00 2001 From: Lol124 <95558254+Romualdo666@users.noreply.github.com> Date: Fri, 21 Jul 2023 00:26:06 -0300 Subject: [PATCH 2/3] Fixed two Profile mode bugs. Fixed the issue where automatic comments would duplicate and the one where the custom Profile name window would show up even if Profile mode weren't enabled. --- UndertaleModTool/Editors/UndertaleCodeEditor.xaml.cs | 6 +++--- UndertaleModTool/ProfileSystem.cs | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/UndertaleModTool/Editors/UndertaleCodeEditor.xaml.cs b/UndertaleModTool/Editors/UndertaleCodeEditor.xaml.cs index bd9fa9849..eaec381a5 100644 --- a/UndertaleModTool/Editors/UndertaleCodeEditor.xaml.cs +++ b/UndertaleModTool/Editors/UndertaleCodeEditor.xaml.cs @@ -690,7 +690,7 @@ private async Task DecompileCode(UndertaleCode code, bool first, LoaderDialog ex { if (match.Success) { - if (gettext.TryGetValue(match.Groups[1].Value, out string text)) + if (gettext.TryGetValue(match.Groups[1].Value, out string text) && !decompiled.Contains($" // {text}")) decompiledLines[i] += $" // {text}"; } } @@ -707,7 +707,7 @@ private async Task DecompileCode(UndertaleCode code, bool first, LoaderDialog ex { if (match.Success) { - if (gettextJSON.TryGetValue(match.Groups[^1].Value, out string text)) + if (gettextJSON.TryGetValue(match.Groups[^1].Value, out string text) && !decompiled.Contains($" // {text}")) decompiledLines[i] += $" // {text}"; } } @@ -1187,7 +1187,7 @@ public class NameGenerator : VisualLineElementGenerator private static readonly SolidColorBrush GlobalBrush = new(Color.FromRgb(0xF9, 0x7B, 0xF9)); private static readonly SolidColorBrush ConstantBrush = new(Color.FromRgb(0xFF, 0x80, 0x80)); private static readonly SolidColorBrush InstanceBrush = new(Color.FromRgb(0x58, 0xE3, 0x5A)); - private static readonly SolidColorBrush LocalBrush = new(Color.FromRgb(0xFF, 0xF8, 0x99)); + private static readonly SolidColorBrush LocalBrush = new(Color.FromRgb(0xFF, 0xF8, 0x99)); // new(Color.FromRgb(0x58, 0xF8, 0x99)); -> this color is pretty cool private static ContextMenuDark contextMenu; diff --git a/UndertaleModTool/ProfileSystem.cs b/UndertaleModTool/ProfileSystem.cs index f54128fdd..9d8f3022f 100644 --- a/UndertaleModTool/ProfileSystem.cs +++ b/UndertaleModTool/ProfileSystem.cs @@ -228,7 +228,7 @@ await Task.Run(() => MD5PreviouslyLoaded = MD5CurrentlyLoaded; remMD5 = MD5PreviouslyLoaded; String Input_text = ""; - if (SettingsWindow.CustomProfileName == true) + if (SettingsWindow.ProfileModeEnabled && SettingsWindow.CustomProfileName == true) Input_text = SimpleTextInput("Loading Profile, please enter a Profile name.", "(Leaving this blank will name the profile with the data's MD5 hash.)", Input_text, true); ProfileHash = Input_text; CurProfileName = ProfileHash; @@ -338,7 +338,7 @@ public async Task ProfileSaveEvent(UndertaleData data, string filename) try { String Input_text = ""; - if (SettingsWindow.CustomProfileName == true) + if (SettingsWindow.ProfileModeEnabled == true && SettingsWindow.CustomProfileName == true) { if (this.ShowQuestion("Do you want to save to the current Profile?") == MessageBoxResult.No) { From d7f04257a912cce6274b3aebfa8d9260db86bfdd Mon Sep 17 00:00:00 2001 From: Lol124 <95558254+Romualdo666@users.noreply.github.com> Date: Fri, 21 Jul 2023 12:41:53 -0300 Subject: [PATCH 3/3] More Profile Mode Improvements. When opening a data.win, all the code in the Temp Profile folder is replaced with the main, and when saving, all the main is replaced with the temp. this, to avoid wrong overwriting. Also, exporting profiles will actually overwrite the already exported profiles, and importing too. Fixed the issue where Importing Profiles wouldn't edit the dissasembly code. --- UndertaleModTool/MainWindow.xaml.cs | 10 ++++++++++ UndertaleModTool/ProfileSystem.cs | 13 ++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/UndertaleModTool/MainWindow.xaml.cs b/UndertaleModTool/MainWindow.xaml.cs index 74f2e749d..1f1f1d1e5 100644 --- a/UndertaleModTool/MainWindow.xaml.cs +++ b/UndertaleModTool/MainWindow.xaml.cs @@ -3950,6 +3950,7 @@ public void ExportProfileFolder() FileDir += iwishiwasbetteratnames[i] + "\\"; } FileDir += "Profiles\\" + MD5DirName; + Directory.Delete(FileDir, true); Directory.CreateDirectory(FileDir); DirectoryCopy(MD5DirPath, FileDir, true); this.ShowMessage("Done!"); @@ -3964,6 +3965,7 @@ public void ImportProfileFolder() { if (CanSave == true) { + var MD5DirName = BitConverter.ToString(MD5CurrentlyLoaded).Replace("-", "").ToLowerInvariant(); var FileDir = ""; string[] iwishiwasbetteratnames = FilePath.Split(new char[] { '\\' }); var directoriesamt = iwishiwasbetteratnames.Length; @@ -3974,7 +3976,15 @@ public void ImportProfileFolder() FileDir += "Profiles"; if (Directory.Exists(FileDir)) { + if (Directory.Exists(ProfilesFolder + "\\" + MD5DirName)) + Directory.Delete(ProfilesFolder + "\\" + MD5DirName, true); DirectoryCopy(FileDir, ProfilesFolder, true); + string[] Files = Directory.GetFiles(FileDir + "\\" + MD5DirName + "\\Main"); + for (var i = 0; i < Files.Length; i++) + { + if (Files[i].EndsWith(".gml")) + ImportCodeFromFile(Files[i], true, false, false, true); + } this.ShowMessage("Done!"); } else diff --git a/UndertaleModTool/ProfileSystem.cs b/UndertaleModTool/ProfileSystem.cs index 9d8f3022f..3ad84c39f 100644 --- a/UndertaleModTool/ProfileSystem.cs +++ b/UndertaleModTool/ProfileSystem.cs @@ -254,7 +254,12 @@ await Task.Run(() => string profDir = Path.Combine(ProfilesFolder, ProfileHash); string profDirTemp = Path.Combine(profDir, "Temp"); string profDirMain = Path.Combine(profDir, "Main"); - + string[] Files = Directory.GetFiles(profDir + "\\Temp"); + for (var i = 0; i < Files.Length; i++) + { + File.Delete(Files[i]); + } + DirectoryCopy(Path.Combine(profDir, "Main"), Path.Combine(profDir, "Temp"), true); if (SettingsWindow.ProfileModeEnabled) { Directory.CreateDirectory(ProfilesFolder); @@ -448,6 +453,12 @@ await Task.Run(() => Directory.CreateDirectory(profDir); Directory.CreateDirectory(Path.Combine(profDir, "Main")); Directory.CreateDirectory(Path.Combine(profDir, "Temp")); + string[] Files = Directory.GetFiles(profDir + "\\Main"); + for (var i = 0; i < Files.Length; i++) + { + File.Delete(Files[i]); + } + DirectoryCopy(Path.Combine(profDir, "Temp"), Path.Combine(profDir, "Main"), true); this.ShowMessage("Profile saved successfully to " + "\"" + CurProfileName + "\""); } if (SettingsWindow.DeleteOldProfileOnSave && copyProfile)