diff --git a/Projects/Server/Serialization/BinaryFileWriter.cs b/Projects/Server/Serialization/BinaryFileWriter.cs index 01570e921..750ad0f24 100644 --- a/Projects/Server/Serialization/BinaryFileWriter.cs +++ b/Projects/Server/Serialization/BinaryFileWriter.cs @@ -47,6 +47,32 @@ public class BinaryFileWriter : BufferWriter, IDisposable _file.Write(Buffer, 0, (int)Index); Index = 0; } + else + { + base.Flush(); // Increase buffer size + } + } + + public override void Write(byte[] bytes) => Write(bytes, 0, bytes.Length); + + public override void Write(byte[] bytes, int offset, int count) + { + if (Index > 0) + { + Flush(); + } + + _file.Write(bytes, offset, count); + } + + public override void Write(ReadOnlySpan bytes) + { + if (Index > 0) + { + Flush(); + } + + _file.Write(bytes); } public override void Close() @@ -61,7 +87,10 @@ public class BinaryFileWriter : BufferWriter, IDisposable public override long Seek(long offset, SeekOrigin origin) { - Flush(); + if (Index > 0) + { + Flush(); + } return _position = _file.Seek(offset, origin); } diff --git a/Projects/Server/Serialization/BufferWriter.cs b/Projects/Server/Serialization/BufferWriter.cs index f682e9dc1..065e61f28 100644 --- a/Projects/Server/Serialization/BufferWriter.cs +++ b/Projects/Server/Serialization/BufferWriter.cs @@ -122,7 +122,11 @@ public class BufferWriter : IGenericWriter } } - public void Write(ReadOnlySpan bytes) + public virtual void Write(byte[] bytes) => Write(bytes.AsSpan()); + + public virtual void Write(byte[] bytes, int offset, int count) => Write(bytes.AsSpan(offset, count)); + + public virtual void Write(ReadOnlySpan bytes) { var length = bytes.Length; diff --git a/Projects/Server/Serialization/GenericEntityPersistence.cs b/Projects/Server/Serialization/GenericEntityPersistence.cs index 0a147aced..283e96d64 100644 --- a/Projects/Server/Serialization/GenericEntityPersistence.cs +++ b/Projects/Server/Serialization/GenericEntityPersistence.cs @@ -64,7 +64,7 @@ public class GenericEntityPersistence : Persistence, IGenericEntityPersistenc public override void WriteSnapshot(string basePath) { IIndexInfo indexInfo = new EntityTypeIndex(_name); - EntityPersistence.WriteEntities(indexInfo, EntitiesBySerial, basePath,World.SerializedTypes, out _); + EntityPersistence.WriteEntities(indexInfo, EntitiesBySerial, basePath,World.SerializedTypes); } public virtual void DeserializeIndexes(string savePath, Dictionary typesDb) diff --git a/Projects/Server/Serialization/IGenericWriter.cs b/Projects/Server/Serialization/IGenericWriter.cs index 9c3469ccd..72cabe8c7 100644 --- a/Projects/Server/Serialization/IGenericWriter.cs +++ b/Projects/Server/Serialization/IGenericWriter.cs @@ -121,6 +121,8 @@ public interface IGenericWriter } void Write(Map value) => Write((byte)(value?.MapIndex ?? 0xFF)); void Write(Race value) => Write((byte)(value?.RaceIndex ?? 0xFF)); + void Write(byte[] bytes); + void Write(byte[] bytes, int offset, int count); void Write(ReadOnlySpan bytes); unsafe void WriteEnum(T value) where T : unmanaged, Enum { diff --git a/Projects/Server/World/EntityPersistence.cs b/Projects/Server/World/EntityPersistence.cs index 88016eef6..4656d8c73 100644 --- a/Projects/Server/World/EntityPersistence.cs +++ b/Projects/Server/World/EntityPersistence.cs @@ -28,12 +28,9 @@ public static class EntityPersistence IIndexInfo indexInfo, Dictionary entities, string savePath, - ConcurrentQueue types, - out Dictionary counts + ConcurrentQueue types ) where T : class, ISerializable { - counts = new Dictionary(); - var typeName = indexInfo.TypeName; var path = Path.Combine(savePath, typeName); @@ -61,12 +58,6 @@ public static class EntityPersistence e.SerializeTo(bin); idx.Write((int)(bin.Position - start)); - - var type = e.GetType().FullName; - if (type != null) - { - counts[type] = (counts.TryGetValue(type, out var count) ? count : 0) + 1; - } } } diff --git a/Projects/UOContent/Mobiles/Vendors/GenericBuy.cs b/Projects/UOContent/Mobiles/Vendors/GenericBuy.cs index 513aa9f15..3be1f35d0 100644 --- a/Projects/UOContent/Mobiles/Vendors/GenericBuy.cs +++ b/Projects/UOContent/Mobiles/Vendors/GenericBuy.cs @@ -257,10 +257,11 @@ namespace Server.Mobiles var version = reader.ReadInt(); - List entities = new (Items); + List entities = [..Items]; entities.AddRange(reader.ReadEntityList()); m_Mobiles = new List(); // This cannot be null in case it is referenced before disposing + m_Table = new Dictionary(); Timer.StartTimer(() => { @@ -268,19 +269,17 @@ namespace Server.Mobiles { entity.Delete(); } + + if (m_Cache == null) + { + m_Cache = this; + } + else + { + Delete(); + } } ); - - m_Table = new Dictionary(); - - if (m_Cache == null) - { - m_Cache = this; - } - else - { - Delete(); - } } } }