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

Fix of the "Pizza Tower D3" load error. #1266

Merged
merged 1 commit into from
Apr 2, 2023
Merged
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
20 changes: 20 additions & 0 deletions UndertaleModLib/Models/UndertaleRoom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<GameObject> Instances { get; private set; } = new();

public bool AreInstancesUnresolved()
{
return InstanceIds.Length > 0 && Instances.Count == 0;
}

/// <inheritdoc />
public void Serialize(UndertaleWriter writer)
{
Expand Down
8 changes: 8 additions & 0 deletions UndertaleModTool/Editors/UndertaleRoomEditor.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down