Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed some Profile Mode Issues. #1442

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions UndertaleModTool/Editors/UndertaleCodeEditor.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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}";
}
}
Expand All @@ -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}";
}
}
Expand Down Expand Up @@ -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;

Expand Down
3 changes: 2 additions & 1 deletion UndertaleModTool/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
Height="450" Width="800" Loaded="Window_Loaded"
AllowDrop="True" Drop="Window_Drop">
<Window.Title>
<MultiBinding StringFormat="{}{0} - {1} [{2}]">
<MultiBinding StringFormat="{}{0} - {1} [{2}] {3}">
<Binding Path="TitleMain"/>
<Binding Path="Data.GeneralInfo" FallbackValue="No game loaded"/>
<Binding Path="FilePath"/>
<Binding Path="CurrentProfileName"/>
</MultiBinding>
</Window.Title>
<Window.Resources>
Expand Down
71 changes: 70 additions & 1 deletion UndertaleModTool/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -237,6 +241,10 @@ public void RaiseOnSelectedChanged()

public MainWindow()
{
if (ProfileHash != "Unknown")
_ProfileModeEnabled = true;
else
_ProfileModeEnabled = false;
InitializeComponent();
this.DataContext = this;

Expand All @@ -245,6 +253,9 @@ public MainWindow()

TitleMain = "UndertaleModTool by krzys_h v:" + Version;

if (_ProfileModeEnabled == false)
CurrentProfileName = "";

CanSave = false;
CanSafelySave = false;

Expand Down Expand Up @@ -3924,6 +3935,64 @@ 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.Delete(FileDir, true);
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 MD5DirName = BitConverter.ToString(MD5CurrentlyLoaded).Replace("-", "").ToLowerInvariant();
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))
{
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
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
Expand Down
104 changes: 90 additions & 14 deletions UndertaleModTool/ProfileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using UndertaleModLib.Models;
using UndertaleModLib.Decompiler;
using System.Threading.Tasks;
using System.Text;

namespace UndertaleModTool
{
Expand Down Expand Up @@ -225,15 +226,40 @@ await Task.Run(() =>
{
MD5CurrentlyLoaded = md5Instance.ComputeHash(stream);
MD5PreviouslyLoaded = MD5CurrentlyLoaded;
ProfileHash = BitConverter.ToString(MD5PreviouslyLoaded).Replace("-", "").ToLowerInvariant();
remMD5 = MD5PreviouslyLoaded;
String Input_text = "";
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;
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 + "\"";
}
}
});

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);
Expand Down Expand Up @@ -316,6 +342,23 @@ public async Task ProfileSaveEvent(UndertaleData data, string filename)

try
{
String Input_text = "";
if (SettingsWindow.ProfileModeEnabled == true && 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(() =>
Expand All @@ -325,7 +368,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;
}
Expand All @@ -338,6 +386,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;
}
Expand All @@ -351,6 +404,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();
Expand All @@ -359,6 +424,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))
{
Expand All @@ -367,23 +433,33 @@ 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);
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)
{
Expand Down
1 change: 1 addition & 0 deletions UndertaleModTool/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions UndertaleModTool/Windows/SettingsWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@
<Separator Grid.Row="18" Grid.ColumnSpan="4" Margin="10"/>
<local:ButtonDark Grid.Row="19" Grid.Column="0" Grid.ColumnSpan="1" Margin="5" Click="AppDataButton_Click">Open application data folder</local:ButtonDark>
<local:ButtonDark Grid.Row="19" Grid.Column="2" Grid.ColumnSpan="2" Margin="5" Click="UpdateAppButton_Click" x:Name="UpdateAppButton" HorizontalAlignment="Right" Width="223">Update app to latest commit</local:ButtonDark>
<TextBlock Grid.Row="17" Grid.Column="2" Margin="25,0,2,0" VerticalAlignment="Center" Text="Ask Profile name on load" ToolTip="Lets you set a custom name for a Profile. Only useful if you have Profile mode on." Grid.ColumnSpan="2"/>
<CheckBox Grid.Row="17" Grid.Column="2" Margin="3,2,3,0" VerticalAlignment="Top" Content="" IsChecked="{Binding CustomProfileName}"/>
<local:ButtonDark Grid.Row="19" Grid.ColumnSpan="3" Margin="254,5,276,5" Click="ProfileButtonImport_Click" Content="Import Current Profile"/>
<local:ButtonDark Grid.Row="19" Grid.Column="2" Margin="27,5,127,5" Click="ProfileButtonExport_Click" Content="Export Current Profile"/>
</Grid>
</ScrollViewer>
</Window>
21 changes: 21 additions & 0 deletions UndertaleModTool/Windows/SettingsWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Diagnostics;
using System.Linq;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}

}
}
Loading