From 8f1c94b59a31df7b030beaa7f51f933139f5723d Mon Sep 17 00:00:00 2001 From: VladiStep Date: Sun, 2 Apr 2023 15:20:27 +0300 Subject: [PATCH] Fixed #1265. --- UndertaleModLib/Models/UndertaleRoom.cs | 20 +++++++++++++++++++ .../Editors/UndertaleRoomEditor.xaml.cs | 8 ++++++++ 2 files changed, 28 insertions(+) diff --git a/UndertaleModLib/Models/UndertaleRoom.cs b/UndertaleModLib/Models/UndertaleRoom.cs index af20722da..18dc8ab68 100644 --- a/UndertaleModLib/Models/UndertaleRoom.cs +++ b/UndertaleModLib/Models/UndertaleRoom.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; +using System.Diagnostics; using System.Drawing; using System.Linq; using System.Runtime.CompilerServices; @@ -422,6 +423,20 @@ public void Unserialize(UndertaleReader reader) if (layer.InstancesData != null) { layer.InstancesData.Instances.Clear(); + if (GameObjects.Count > 0 && layer.InstancesData.InstanceIds.Length > 0 + && layer.InstancesData.InstanceIds[0] > GameObjects[^1].InstanceID) + { + // Make sure it's not a false positive + uint firstLayerInstID = layer.InstancesData.InstanceIds.OrderBy(x => x).First(); + uint lastInstID = GameObjects.OrderBy(x => x.InstanceID).Last().InstanceID; + if (firstLayerInstID > lastInstID) + { + Debug.WriteLine($"The first instance ID ({firstLayerInstID}) " + + $"of layer (ID {layer.LayerId}) is greater than the last game object ID ({lastInstID}) ?"); + continue; + } + } + foreach (var id in layer.InstancesData.InstanceIds) { GameObject gameObj = GameObjects.ByInstanceID(id); @@ -1563,6 +1578,11 @@ public class LayerInstancesData : LayerData internal uint[] InstanceIds { get; private set; } // 100000, 100001, 100002, 100003 - instance ids from GameObjects list in the room public ObservableCollection Instances { get; private set; } = new(); + public bool AreInstancesUnresolved() + { + return InstanceIds.Length > 0 && Instances.Count == 0; + } + /// public void Serialize(UndertaleWriter writer) { diff --git a/UndertaleModTool/Editors/UndertaleRoomEditor.xaml.cs b/UndertaleModTool/Editors/UndertaleRoomEditor.xaml.cs index c592608fb..f4dcdbecf 100644 --- a/UndertaleModTool/Editors/UndertaleRoomEditor.xaml.cs +++ b/UndertaleModTool/Editors/UndertaleRoomEditor.xaml.cs @@ -187,6 +187,14 @@ private void UndertaleRoomEditor_DataContextChanged(object sender, DependencyPro } else if (layer.LayerType == LayerType.Instances) { + if (layer.InstancesData.AreInstancesUnresolved()) + { + _ = mainWindow.Dispatcher.InvokeAsync(() => + { + mainWindow.ShowWarning($"The instances list of layer \"{layer.LayerName.Content}\" is empty, but the layer has the instances ID."); + }, DispatcherPriority.ContextIdle); + } + foreach (GameObject obj in layer.InstancesData.Instances) roomObjDict.TryAdd(obj.InstanceID, layer); }