diff --git a/Source/Client/Syncing/Dict/SyncDictRimWorld.cs b/Source/Client/Syncing/Dict/SyncDictRimWorld.cs index 75c234b7..522b14b8 100644 --- a/Source/Client/Syncing/Dict/SyncDictRimWorld.cs +++ b/Source/Client/Syncing/Dict/SyncDictRimWorld.cs @@ -295,46 +295,15 @@ public static class SyncDictRimWorld (SyncWorker sync, ref Verb verb) => { if (sync.isWriting) { - if (verb.DirectOwner is Pawn pawn) { - sync.Write(VerbOwnerType.Pawn); - sync.Write(pawn); - } - else if (verb.DirectOwner is Ability ability) { - sync.Write(VerbOwnerType.Ability); - sync.Write(ability); - } - else if (verb.DirectOwner is ThingComp thingComp) { - sync.Write(VerbOwnerType.ThingComp); - sync.Write(thingComp); - } - else { - Log.Error($"Multiplayer :: SyncDictionary.Verb: Unknown DirectOwner {verb.loadID} {verb.DirectOwner}"); - sync.Write(VerbOwnerType.None); - return; - } - - sync.Write(verb.loadID); + sync.Write(verb.DirectOwner); + // No reason to sync loadID if the owner is null + if (verb.DirectOwner != null) + sync.Write(verb.loadID); } else { - var ownerType = sync.Read(); - if (ownerType == VerbOwnerType.None) { - return; - } - - IVerbOwner verbOwner = null; - if (ownerType == VerbOwnerType.Pawn) { - verbOwner = sync.Read(); - } - else if (ownerType == VerbOwnerType.Ability) { - verbOwner = sync.Read(); - } - else if (ownerType == VerbOwnerType.ThingComp) { - verbOwner = sync.Read() as IVerbOwner; - } - + var verbOwner = sync.Read(); if (verbOwner == null) { - Log.Error($"Multiplayer :: SyncDictionary.Verb: Unknown VerbOwnerType {ownerType}"); return; } @@ -348,6 +317,14 @@ public static class SyncDictRimWorld } }, true // implicit }, + { + (ByteWriter data, IVerbOwner obj) => { + WriteWithImpl(data, obj, supportedVerbOwnerTypes); + }, + (ByteReader data) => { + return ReadWithImpl(data, supportedVerbOwnerTypes); + }, true // Implicit + }, #endregion #region AI diff --git a/Source/Client/Syncing/Game/RwImplSerialization.cs b/Source/Client/Syncing/Game/RwImplSerialization.cs index 7016ab11..43911054 100644 --- a/Source/Client/Syncing/Game/RwImplSerialization.cs +++ b/Source/Client/Syncing/Game/RwImplSerialization.cs @@ -32,17 +32,19 @@ public static class RwImplSerialization typeof(WorldObjectComp) }; + internal static Type[] supportedVerbOwnerTypes = + { + typeof(Thing), + typeof(Ability), + typeof(ThingComp), + }; + // ReSharper disable once InconsistentNaming internal enum ISelectableImpl : byte { None, Thing, Zone, WorldObject } - internal enum VerbOwnerType : byte - { - None, Pawn, Ability, ThingComp - } - public static void Init() { storageParents = TypeUtil.AllImplementationsOrdered(typeof(IStoreSettingsParent));