From 40a3ecce083e021adaeb56daf2653fb89a0e08b0 Mon Sep 17 00:00:00 2001 From: Paul Pacheco Date: Tue, 1 Jan 2019 09:08:39 -0600 Subject: [PATCH] Revert "Don't generate OnSerialize/OnDeserialize if not needed (#199)" (#217) This reverts commit 6eec19b205938df356563238cb200864bdd89d4c. --- .../Processors/NetworkBehaviourProcessor.cs | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/Mirror/Weaver/Processors/NetworkBehaviourProcessor.cs b/Mirror/Weaver/Processors/NetworkBehaviourProcessor.cs index b74808a81..9cffa5093 100644 --- a/Mirror/Weaver/Processors/NetworkBehaviourProcessor.cs +++ b/Mirror/Weaver/Processors/NetworkBehaviourProcessor.cs @@ -348,12 +348,6 @@ void GenerateSerialization() return; } - if (m_SyncVars.Count == 0) - { - // nothing to sync, use base OnSerialize - return; - } - MethodDefinition serialize = new MethodDefinition("OnSerialize", MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.HideBySig, @@ -379,6 +373,15 @@ void GenerateSerialization() serWorker.Append(serWorker.Create(OpCodes.Stloc_0)); // set dirtyLocal to result of base.OnSerialize() } + if (m_SyncVars.Count == 0) + { + // generate: return dirtyLocal + serWorker.Append(serWorker.Create(OpCodes.Ldloc_0)); + serWorker.Append(serWorker.Create(OpCodes.Ret)); + m_td.Methods.Add(serialize); + return; + } + // Generates: if (forceAll); Instruction initialStateLabel = serWorker.Create(OpCodes.Nop); serWorker.Append(serWorker.Create(OpCodes.Ldarg_2)); // forceAll @@ -551,12 +554,6 @@ void GenerateDeSerialization() return; } - if (m_SyncVars.Count == 0) - { - // nothing to sync, base OnDeserialize is fine - return; - } - MethodDefinition serialize = new MethodDefinition("OnDeserialize", MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.HideBySig, @@ -575,6 +572,13 @@ void GenerateDeSerialization() serWorker.Append(serWorker.Create(OpCodes.Call, baseDeserialize)); } + if (m_SyncVars.Count == 0) + { + serWorker.Append(serWorker.Create(OpCodes.Ret)); + m_td.Methods.Add(serialize); + return; + } + // Generates: if (initialState); Instruction initialStateLabel = serWorker.Create(OpCodes.Nop);