From b4611ab7eb54456f2c940a924b683eeefb8e04a7 Mon Sep 17 00:00:00 2001 From: Kamron Batman <3953314+kamronbatman@users.noreply.github.com> Date: Sat, 20 Jul 2024 17:38:22 -0700 Subject: [PATCH] fix: Fixes link list not crashing when broken. (#1877) --- Projects/Server/Maps/Map.ClientEnumerator.cs | 10 +++++----- Projects/Server/Maps/Map.ItemEnumerator.cs | 10 +++++----- Projects/Server/Maps/Map.MobileEnumerator.cs | 10 +++++----- Projects/UOContent/Items/Resources/Tailor/Hides.cs | 1 - 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/Projects/Server/Maps/Map.ClientEnumerator.cs b/Projects/Server/Maps/Map.ClientEnumerator.cs index 82efbb07b..4321a0fc5 100644 --- a/Projects/Server/Maps/Map.ClientEnumerator.cs +++ b/Projects/Server/Maps/Map.ClientEnumerator.cs @@ -212,6 +212,11 @@ public partial class Map return false; } + if (!Unsafe.IsNullRef(in _linkList) && _linkList.Version != _currentVersion) + { + throw new InvalidOperationException(CollectionThrowStrings.InvalidOperation_EnumFailedVersion); + } + Mobile m; NetState current = _current; ref Rectangle2D bounds = ref _bounds; @@ -247,11 +252,6 @@ public partial class Map current = _linkList._first; } - if (_linkList.Version != _currentVersion) - { - throw new InvalidOperationException(CollectionThrowStrings.InvalidOperation_EnumFailedVersion); - } - m = current.Mobile; if (m?.Deleted == false && bounds.Contains(m.Location)) { diff --git a/Projects/Server/Maps/Map.ItemEnumerator.cs b/Projects/Server/Maps/Map.ItemEnumerator.cs index 7fec42b7e..9eab2effb 100644 --- a/Projects/Server/Maps/Map.ItemEnumerator.cs +++ b/Projects/Server/Maps/Map.ItemEnumerator.cs @@ -243,6 +243,11 @@ public partial class Map return false; } + if (!Unsafe.IsNullRef(in _linkList) && _linkList.Version != _currentVersion) + { + throw new InvalidOperationException(CollectionThrowStrings.InvalidOperation_EnumFailedVersion); + } + Item current = _current; ref Rectangle2D bounds = ref _bounds; var currentSectorX = _currentSectorX; @@ -277,11 +282,6 @@ public partial class Map current = _linkList._first; } - if (_linkList.Version != _currentVersion) - { - throw new InvalidOperationException(CollectionThrowStrings.InvalidOperation_EnumFailedVersion); - } - if (current is T { Deleted: false, Parent: null } o && bounds.Contains(o.Location)) { _current = o; diff --git a/Projects/Server/Maps/Map.MobileEnumerator.cs b/Projects/Server/Maps/Map.MobileEnumerator.cs index bced5e1a7..9e7edee15 100644 --- a/Projects/Server/Maps/Map.MobileEnumerator.cs +++ b/Projects/Server/Maps/Map.MobileEnumerator.cs @@ -242,6 +242,11 @@ public partial class Map return false; } + if (!Unsafe.IsNullRef(in _linkList) && _linkList.Version != _currentVersion) + { + throw new InvalidOperationException(CollectionThrowStrings.InvalidOperation_EnumFailedVersion); + } + Mobile current = _current; ref Rectangle2D bounds = ref _bounds; var currentSectorX = _currentSectorX; @@ -276,11 +281,6 @@ public partial class Map current = _linkList._first; } - if (_linkList.Version != _currentVersion) - { - throw new InvalidOperationException(CollectionThrowStrings.InvalidOperation_EnumFailedVersion); - } - if (current is T { Deleted: false } o && bounds.Contains(o.Location)) { _current = o; diff --git a/Projects/UOContent/Items/Resources/Tailor/Hides.cs b/Projects/UOContent/Items/Resources/Tailor/Hides.cs index 8068659b1..f9a6014c9 100644 --- a/Projects/UOContent/Items/Resources/Tailor/Hides.cs +++ b/Projects/UOContent/Items/Resources/Tailor/Hides.cs @@ -1,5 +1,4 @@ using ModernUO.Serialization; -using Server.Engines.Craft; namespace Server.Items;