From 60515b110735120e74bba7c05e7a853709f60258 Mon Sep 17 00:00:00 2001 From: zivmaor Date: Wed, 9 Oct 2024 00:08:43 +0300 Subject: [PATCH 1/4] Fix GetReferencesOfObject for Bytecode version 15 Move check for language to only be done on bytecode version 16 and up. See https://github.com/UnderminersTeam/UndertaleModTool/wiki/Bytecode-version-differences. Fixes #1946. --- .../UndertaleResourceReferenceMethodsMap.cs | 31 +++++++++++++------ 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/UndertaleModTool/Windows/FindReferencesTypesDialog/UndertaleResourceReferenceMethodsMap.cs b/UndertaleModTool/Windows/FindReferencesTypesDialog/UndertaleResourceReferenceMethodsMap.cs index df8435851..1279208d2 100644 --- a/UndertaleModTool/Windows/FindReferencesTypesDialog/UndertaleResourceReferenceMethodsMap.cs +++ b/UndertaleModTool/Windows/FindReferencesTypesDialog/UndertaleResourceReferenceMethodsMap.cs @@ -560,15 +560,6 @@ IEnumerable GetExtnFunctions() outDict["Game options constants"] = new object[] { new GeneralInfoEditor(data.GeneralInfo, data.Options, data.Language) }; } - if (types.Contains(typeof(UndertaleLanguage))) - { - bool langsMatches = data.Language.EntryIDs.Contains(obj) - || data.Language.Languages.Any(x => x.Name == obj || x.Region == obj - || x.Entries.Contains(obj)); - if (langsMatches) - outDict["Languages"] = new object[] { new GeneralInfoEditor(data.GeneralInfo, data.Options, data.Language) }; - } - if (types.Contains(typeof(UndertalePath))) { var paths = data.Paths.Where(x => x.Name == obj); @@ -632,6 +623,28 @@ IEnumerable GetExtnFunctions() } }, new PredicateForVersion() + { + // Bytecode version 16 + Version = (16, uint.MaxValue, uint.MaxValue), + Predicate = (objSrc, types, checkOne) => + { + if (!types.Contains(typeof(UndertaleLanguage))) + return null; + + if (objSrc is not UndertaleString obj) + return null; + + bool langsMatches = data.Language.EntryIDs.Contains(obj) + || data.Language.Languages.Any(x => x.Name == obj || x.Region == obj + || x.Entries.Contains(obj)); + + if (langsMatches) + return new() { { "Languages", new object[] { new GeneralInfoEditor(data.GeneralInfo, data.Options, data.Language) } } }; + else + return null; + } + }, + new PredicateForVersion() { Version = (2, 0, 0), Predicate = (objSrc, types, checkOne) => From 992524c14ae167412de4797f1bb8d39e96743cc5 Mon Sep 17 00:00:00 2001 From: zivmaor Date: Wed, 9 Oct 2024 00:38:47 +0300 Subject: [PATCH 2/4] Add error handling to FindReferencesTypesDialog --- .../FindReferencesTypesDialog.xaml.cs | 36 +++++++++++++++---- .../UndertaleResourceReferenceMethodsMap.cs | 3 ++ 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/UndertaleModTool/Windows/FindReferencesTypesDialog/FindReferencesTypesDialog.xaml.cs b/UndertaleModTool/Windows/FindReferencesTypesDialog/FindReferencesTypesDialog.xaml.cs index 0194cc48d..627961876 100644 --- a/UndertaleModTool/Windows/FindReferencesTypesDialog/FindReferencesTypesDialog.xaml.cs +++ b/UndertaleModTool/Windows/FindReferencesTypesDialog/FindReferencesTypesDialog.xaml.cs @@ -22,6 +22,8 @@ namespace UndertaleModTool.Windows /// public partial class FindReferencesTypesDialog : Window { + private static readonly MainWindow mainWindow = Application.Current.MainWindow as MainWindow; + private readonly UndertaleResource sourceObj; private readonly UndertaleData data; private readonly bool dontShowWindow = false; @@ -140,9 +142,21 @@ private async void SearchButton_Click(object sender, RoutedEventArgs e) return; } - var results = UndertaleResourceReferenceMethodsMap.GetReferencesOfObject(sourceObj, data, typesList); - FindReferencesResults dialog = new(sourceObj, data, results); - dialog.Show(); + FindReferencesResults dialog = null; + try + { + var results = UndertaleResourceReferenceMethodsMap.GetReferencesOfObject(sourceObj, data, typesList); + dialog = new(sourceObj, data, results); + dialog.Show(); + } + catch (Exception ex) + { + mainWindow.ShowError("An error occured in the object references related window.\n" + + $"Please report this on GitHub.\n\n{ex}"); + dialog?.Close(); + + } + } else { @@ -173,9 +187,19 @@ private async void SearchButton_Click(object sender, RoutedEventArgs e) } Hide(); - var results = await UndertaleResourceReferenceMethodsMap.GetUnreferencedObjects(data, typesDict); - FindReferencesResults dialog = new(data, results); - dialog.Show(); + FindReferencesResults dialog = null; + try + { + var results = await UndertaleResourceReferenceMethodsMap.GetUnreferencedObjects(data, typesDict); + dialog = new(data, results); + dialog.Show(); + } + catch (Exception ex) + { + mainWindow.ShowError("An error occured in the object references related window.\n" + + $"Please report this on GitHub.\n\n{ex}"); + dialog?.Close(); + } } Close(); diff --git a/UndertaleModTool/Windows/FindReferencesTypesDialog/UndertaleResourceReferenceMethodsMap.cs b/UndertaleModTool/Windows/FindReferencesTypesDialog/UndertaleResourceReferenceMethodsMap.cs index 1279208d2..c1dab7c45 100644 --- a/UndertaleModTool/Windows/FindReferencesTypesDialog/UndertaleResourceReferenceMethodsMap.cs +++ b/UndertaleModTool/Windows/FindReferencesTypesDialog/UndertaleResourceReferenceMethodsMap.cs @@ -1590,6 +1590,9 @@ await Task.Run(() => funcReferences = null; variReferences = null; + await mainWindow.StopProgressBarUpdater(); + mainWindow.HideProgressBar(); + throw; } mainWindow.IsEnabled = true; From 08ad289f7eed863b2ca85b02500a5aa8cce9f7f2 Mon Sep 17 00:00:00 2001 From: zivmaor Date: Sun, 13 Oct 2024 15:40:45 +0300 Subject: [PATCH 3/4] Apple changes from 60515b1 to UndertaleResourceReferenceMap --- .../UndertaleResourceReferenceMap.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/UndertaleModTool/Windows/FindReferencesTypesDialog/UndertaleResourceReferenceMap.cs b/UndertaleModTool/Windows/FindReferencesTypesDialog/UndertaleResourceReferenceMap.cs index 2c4d15249..7f4a1ddd3 100644 --- a/UndertaleModTool/Windows/FindReferencesTypesDialog/UndertaleResourceReferenceMap.cs +++ b/UndertaleModTool/Windows/FindReferencesTypesDialog/UndertaleResourceReferenceMap.cs @@ -161,7 +161,6 @@ public static class UndertaleResourceReferenceMap (typeof(UndertaleGameObject), "Game objects"), (typeof(UndertaleGeneralInfo), "General info"), (typeof(UndertaleOptions.Constant), "Game options constants"), - (typeof(UndertaleLanguage), "Languages"), (typeof(UndertalePath), "Paths"), (typeof(UndertaleRoom), "Rooms"), (typeof(UndertaleScript), "Scripts"), @@ -179,6 +178,15 @@ public static class UndertaleResourceReferenceMap } }, new TypesForVersion + { + // Bytecode version 16 + Version = (16, uint.MaxValue, uint.MaxValue), + Types = new[] + { + (typeof(UndertaleLanguage), "Languages"), + } + }, + new TypesForVersion { Version = (2, 0, 0), Types = new[] From 54968e3ef8592b1a4cbf2894b31f01fd9e50fe49 Mon Sep 17 00:00:00 2001 From: zivmaor Date: Wed, 23 Oct 2024 17:29:49 +0300 Subject: [PATCH 4/4] minor code improvement --- .../UndertaleResourceReferenceMethodsMap.cs | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/UndertaleModTool/Windows/FindReferencesTypesDialog/UndertaleResourceReferenceMethodsMap.cs b/UndertaleModTool/Windows/FindReferencesTypesDialog/UndertaleResourceReferenceMethodsMap.cs index c1dab7c45..0a2e959e1 100644 --- a/UndertaleModTool/Windows/FindReferencesTypesDialog/UndertaleResourceReferenceMethodsMap.cs +++ b/UndertaleModTool/Windows/FindReferencesTypesDialog/UndertaleResourceReferenceMethodsMap.cs @@ -1579,26 +1579,17 @@ await Task.Run(() => } } } - - await mainWindow.StopProgressBarUpdater(); - mainWindow.HideProgressBar(); } - catch + finally { + await mainWindow.StopProgressBarUpdater(); + mainWindow.HideProgressBar(); + mainWindow.IsEnabled = true; stringReferences = null; funcReferences = null; variReferences = null; - - await mainWindow.StopProgressBarUpdater(); - mainWindow.HideProgressBar(); - - throw; } - mainWindow.IsEnabled = true; - stringReferences = null; - funcReferences = null; - variReferences = null; if (outDict.Count == 0) return null;