From bd87035f12577a7c6e32f752188d9db683231579 Mon Sep 17 00:00:00 2001 From: Kamron Batman <3953314+kamronbatman@users.noreply.github.com> Date: Sat, 6 Feb 2021 21:03:47 -0800 Subject: [PATCH] fix(core): Fixes ability to delete object type if it deserialized improperly (#475) --- Projects/Server/World/World.cs | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/Projects/Server/World/World.cs b/Projects/Server/World/World.cs index b777895dc..68db1eb45 100644 --- a/Projects/Server/World/World.cs +++ b/Projects/Server/World/World.cs @@ -329,15 +329,31 @@ namespace Server } bin.Read(buffer.AsSpan()); + string error; - t.Deserialize(br); - - if (br.Position != entry.Length) + try { - WriteConsoleLine($"***** Bad deserialize on {t.GetType()} *****"); - WriteConsoleLine( - $"Serialized object was {entry.Length} bytes, but {br.Position} bytes deserialized" - ); + t.Deserialize(br); + + error = br.Position != entry.Length + ? $"Serialized object was {entry.Length} bytes, but {br.Position} bytes deserialized" + : null; + } + catch (Exception e) + { + error = e.ToString(); + } + + if (error == null) + { + t.InitializeSaveBuffer(buffer); + } + else + { + Utility.PushColor(ConsoleColor.Red); + WriteConsoleLine($"***** Bad deserialize of {t.GetType()} *****"); + WriteConsoleLine(error); + Utility.PopColor(); WriteConsoleLine("Delete the object and continue? (y/n)"); @@ -347,10 +363,6 @@ namespace Server } t.Delete(); } - else - { - t.InitializeSaveBuffer(buffer); - } } }