From 1de0b656a9c6a54a3d81522343ce35175ce374b9 Mon Sep 17 00:00:00 2001 From: Kamron Batman <3953314+kamronbatman@users.noreply.github.com> Date: Mon, 12 Jul 2021 00:03:46 -0700 Subject: [PATCH] fix(accounting): Fixes NPE when joining faction due to codegen (#658) --- Projects/UOContent/Accounting/Account.cs | 36 ++++++++++++++++++------ 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/Projects/UOContent/Accounting/Account.cs b/Projects/UOContent/Accounting/Account.cs index 918d7ffaa..fe9de870b 100644 --- a/Projects/UOContent/Accounting/Account.cs +++ b/Projects/UOContent/Accounting/Account.cs @@ -61,12 +61,32 @@ namespace Server.Accounting [SerializableField(9, "private", "private")] private Mobile[] _mobiles; - [SerializableField(10, setter: "private")] private List _comments; - [SerializableField(11, setter: "private")] + [SerializableField(10)] + public List Comments + { + get => _comments ??= new List(); + private set + { + _comments = value; + ((ISerializable)this).MarkDirty(); + } + } + private List _tags; + [SerializableField(11)] + public List Tags + { + get => _tags ??= new List(); + private set + { + _tags = value; + ((ISerializable)this).MarkDirty(); + } + } + [SerializableField(12)] private IPAddress[] _loginIPs; @@ -293,12 +313,12 @@ namespace Server.Accounting [AfterDeserialization] private void AfterDeserialization() { - if (_comments.Count == 0) + if (_comments?.Count == 0) { _comments = null; } - if (_tags.Count == 0) + if (_tags?.Count == 0) { _tags = null; } @@ -656,7 +676,7 @@ namespace Server.Accounting /// New tag value. public void AddTag(string name, string value) { - _tags.Add(new AccountTag(name, value)); + Tags.Add(new AccountTag(name, value)); ((ISerializable)this).MarkDirty(); } @@ -677,7 +697,7 @@ namespace Server.Accounting if (tag.Name == name) { - _tags.RemoveAt(i); + _tags?.RemoveAt(i); ((ISerializable)this).MarkDirty(); } } @@ -690,7 +710,7 @@ namespace Server.Accounting /// Tag value. public void SetTag(string name, string value) { - for (var i = 0; i < _tags.Count; ++i) + for (var i = 0; i < Tags.Count; ++i) { var tag = _tags[i]; @@ -711,7 +731,7 @@ namespace Server.Accounting /// Name of the desired tag value. public string GetTag(string name) { - for (var i = 0; i < _tags.Count; ++i) + for (var i = 0; i < Tags.Count; ++i) { var tag = _tags[i];