From 0d6055ac1d5ccfdf8187dd10be7aee815879d5bb Mon Sep 17 00:00:00 2001 From: VladiStep Date: Tue, 24 Jan 2023 12:10:59 +0300 Subject: [PATCH] Made "internalList" private, replaced "internalList.Add()" with "AddDirect()" --- UndertaleModLib/Models/UndertaleGameObject.cs | 2 +- UndertaleModLib/Models/UndertaleRoom.cs | 4 ++-- UndertaleModLib/UndertaleChunkTypes.cs | 2 +- UndertaleModLib/UndertaleLists.cs | 17 +++++++++++------ 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/UndertaleModLib/Models/UndertaleGameObject.cs b/UndertaleModLib/Models/UndertaleGameObject.cs index d751cf7e4..ae14b9b75 100644 --- a/UndertaleModLib/Models/UndertaleGameObject.cs +++ b/UndertaleModLib/Models/UndertaleGameObject.cs @@ -162,7 +162,7 @@ public UndertaleGameObject() { Events.SetCapacity(eventTypesLength); for (int i = 0; i < eventTypesLength; i++) - Events.internalList.Add(new UndertalePointerList()); + Events.AddDirect(new UndertalePointerList()); } /// diff --git a/UndertaleModLib/Models/UndertaleRoom.cs b/UndertaleModLib/Models/UndertaleRoom.cs index ed6f14dde..80bc315ed 100644 --- a/UndertaleModLib/Models/UndertaleRoom.cs +++ b/UndertaleModLib/Models/UndertaleRoom.cs @@ -258,9 +258,9 @@ public UndertaleRoom() Backgrounds.SetCapacity(8); Views.SetCapacity(8); for (int i = 0; i < 8; i++) - Backgrounds.internalList.Add(new Background()); + Backgrounds.AddDirect(new Background()); for (int i = 0; i < 8; i++) - Views.internalList.Add(new View()); + Views.AddDirect(new View()); if (Flags.HasFlag(RoomEntryFlags.EnableViews)) Views[0].Enabled = true; } diff --git a/UndertaleModLib/UndertaleChunkTypes.cs b/UndertaleModLib/UndertaleChunkTypes.cs index 20aa80c55..194203fad 100644 --- a/UndertaleModLib/UndertaleChunkTypes.cs +++ b/UndertaleModLib/UndertaleChunkTypes.cs @@ -237,7 +237,7 @@ internal override void UnserializeChunk(UndertaleReader reader) if (reader.ReadByte() != 0) throw new IOException("AlignUpdatedListChunk padding error"); } - List.internalList.Add(reader.ReadUndertaleObject()); + List.AddDirect(reader.ReadUndertaleObject()); } } } diff --git a/UndertaleModLib/UndertaleLists.cs b/UndertaleModLib/UndertaleLists.cs index 0732aa45c..60a25f082 100644 --- a/UndertaleModLib/UndertaleLists.cs +++ b/UndertaleModLib/UndertaleLists.cs @@ -10,7 +10,7 @@ namespace UndertaleModLib { public abstract class UndertaleListBase : ObservableCollection { - public readonly List internalList; + private readonly List internalList; public UndertaleListBase() { @@ -45,6 +45,11 @@ public void SetCapacity(int capacity) } } public void SetCapacity(uint capacity) => SetCapacity((int)capacity); + + public void AddDirect(T item) + { + internalList.Add(item); + } } public class UndertaleSimpleList : UndertaleListBase, UndertaleObject where T : UndertaleObject, new() @@ -76,7 +81,7 @@ public override void Unserialize(UndertaleReader reader) { try { - internalList.Add(reader.ReadUndertaleObject()); + AddDirect(reader.ReadUndertaleObject()); } catch (UndertaleSerializationException e) { @@ -115,7 +120,7 @@ public override void Unserialize(UndertaleReader reader) { try { - internalList.Add(reader.ReadUndertaleString()); + AddDirect(reader.ReadUndertaleString()); } catch (UndertaleSerializationException e) { @@ -160,7 +165,7 @@ public override void Unserialize(UndertaleReader reader) { try { - internalList.Add(reader.ReadUndertaleObject()); + AddDirect(reader.ReadUndertaleObject()); EnsureShortCount(); } catch (UndertaleSerializationException e) @@ -221,7 +226,7 @@ public override void Unserialize(UndertaleReader reader) { try { - internalList.Add(reader.ReadUndertaleObjectPointer()); + AddDirect(reader.ReadUndertaleObjectPointer()); } catch (UndertaleSerializationException e) { @@ -279,7 +284,7 @@ public void Unserialize(UndertaleReader reader, uint endPosition) { uint ptr = reader.ReadUInt32(); pointers.Add(ptr); - internalList.Add(reader.GetUndertaleObjectAtAddress(ptr)); + AddDirect(reader.GetUndertaleObjectAtAddress(ptr)); } catch (UndertaleSerializationException e) {