Skip to content

Commit

Permalink
fix: Fixes spawn entry deserialization (#1693)
Browse files Browse the repository at this point in the history
  • Loading branch information
kamronbatman committed Mar 3, 2024
1 parent 7a71e8b commit c42c20a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
27 changes: 22 additions & 5 deletions Projects/Server/AssemblyHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,9 @@ public static Type FindTypeByHash(ulong hash)

public class TypeCache
{
#if DEBUG_TYPES
private static ILogger logger = LogFactory.GetLogger(typeof(TypeCache));
#endif

private Dictionary<ulong, Type[]> _nameMap = new();
private Dictionary<ulong, Type[]> _nameMapInsensitive = new();
Expand Down Expand Up @@ -285,15 +287,15 @@ void addTypeToRefs(Type type, string typeName, string fullTypeName)
foreach (var (key, value) in fullNameMap)
{
var values = value.ToArray();
_fullNameMap[HashUtility.ComputeHash64(key)] = value.ToArray();
#if DEBUG
_fullNameMap[HashUtility.ComputeHash64(key)] = values;
#if DEBUG_TYPES
if (values.Length > 1)
{
for (var i = 0; i < values.Length; i++)
{
var type = values[i];
logger.Warning(
"Duplicate type {Type1} for {Name}.",
"Duplicate type {Type} for {Name}.",
type,
key
);
Expand All @@ -304,7 +306,22 @@ void addTypeToRefs(Type type, string typeName, string fullTypeName)

foreach (var (key, value) in fullNameMapInsensitive)
{
_fullNameMapInsensitive[HashUtility.ComputeHash64(key)] = value.ToArray();
var values = value.ToArray();
_fullNameMapInsensitive[HashUtility.ComputeHash64(key)] = values;
#if DEBUG_TYPES
if (values.Length > 1)
{
for (var i = 0; i < values.Length; i++)
{
var type = values[i];
logger.Warning(
"Duplicate type {Type} for {Name}.",
type,
key
);
}
}
#endif
}
}

Expand Down Expand Up @@ -337,7 +354,7 @@ private static void AddToRefs(Type type, string key, Dictionary<string, HashSet<

public ref struct TypeEnumerator
{
private Type[] _values;
private readonly Type[] _values;
private int _index;
private Type _current;

Expand Down
16 changes: 14 additions & 2 deletions Projects/UOContent/Engines/Spawners/SpawnerEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public partial class SpawnerEntry
[SerializedJsonPropertyName("parameters")]
private string _parameters;

[Tidy]
[SerializedJsonIgnore]
[SerializableField(5)]
private List<ISpawnable> _spawned;
Expand Down Expand Up @@ -95,10 +96,21 @@ private void Deserialize(IGenericReader reader, int version)
[AfterDeserialization]
private void AfterDeserialization()
{
foreach (var e in Spawned)
// This wasn't tidy in the original code, but it is after generating the code.
for (var i = Spawned.Count - 1; i >= 0; i--)
{
e.Spawner = _parent;
var e = Spawned[i];
if (e == null)
{
Spawned.RemoveAt(i);
}
else
{
e.Spawner = _parent;
}
}

Spawned.TrimExcess();
}

[JsonIgnore]
Expand Down
2 changes: 1 addition & 1 deletion Projects/UOContent/Misc/Email.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Speech Log
var created = logEntry.Created;
var speech = logEntry.Speech;
writer.WriteLine(
@$"{created.Hour}:{created.Minute:00}:{created.Second:00} - {fromName} ({fromAccount}): '{speech}'"
$"{created.Hour}:{created.Minute:00}:{created.Second:00} - {fromName} ({fromAccount}): '{speech}'"
);
}

Expand Down

0 comments on commit c42c20a

Please sign in to comment.