fix(core): Serialization issues (#350)

- [X] Fixes IPAddresses not having enough space
- [X] Streamlines some code
- [X] Fixes base escortables to not load destination tables in a dangerous way.
- [X] Fixes some bad assumptions about resizing buffers
- [X] Fixes little endian issue with circular buffer writer

This doesn't seem to address #349. That issue requires more investigation because I am not seeing where the issue would be.

Closes #347
Closes #322
This commit is contained in:
Kamron Batman 2020-12-13 13:15:48 -08:00 • committed by GitHub
parent 3acb1414dd
commit e17413af21
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 186 additions and 222 deletions

View file

@ -528,15 +528,15 @@ namespace Server
var bin = new BinaryFileWriter(binPath, true);
idx.Write(entities.Count);
foreach (var mob in entities.Values)
foreach (var e in entities.Values)
{
long start = bin.Position;
idx.Write(mob.TypeRef);
idx.Write(mob.Serial);
idx.Write(e.TypeRef);
idx.Write(e.Serial);
idx.Write(start);
mob.SerializeTo(bin);
e.SerializeTo(bin);
idx.Write((int)(bin.Position - start));
}
@ -775,7 +775,7 @@ namespace Server
public static void SerializeTo(this ISerializable entity, IGenericWriter writer)
{
var saveBuffer = entity.SaveBuffer;
writer.Write(saveBuffer.Buffer, (int)saveBuffer.Position);
writer.Write(saveBuffer.Buffer.AsSpan(0, (int)saveBuffer.Position));
// Resize to exact buffer size
entity.SaveBuffer.Resize((int)entity.SaveBuffer.Position);