diff --git a/Assets/Mirror/Editor/Weaver/Processors/NetworkBehaviourProcessor.cs b/Assets/Mirror/Editor/Weaver/Processors/NetworkBehaviourProcessor.cs index b7467bea1..682fe82ea 100644 --- a/Assets/Mirror/Editor/Weaver/Processors/NetworkBehaviourProcessor.cs +++ b/Assets/Mirror/Editor/Weaver/Processors/NetworkBehaviourProcessor.cs @@ -442,7 +442,7 @@ void GenerateSerialization() // generate a writer call for any dirty variable in this class // start at number of syncvars in parent - int dirtyBit = Weaver.GetSyncVarStart(netBehaviourSubclass.BaseType.FullName); + int dirtyBit = Weaver.WeaveLists.GetSyncVarStart(netBehaviourSubclass.BaseType.FullName); foreach (FieldDefinition syncVar in syncVars) { Instruction varLabel = worker.Create(OpCodes.Nop); @@ -775,7 +775,7 @@ void GenerateDeSerialization() // conditionally read each syncvar // start at number of syncvars in parent - int dirtyBit = Weaver.GetSyncVarStart(netBehaviourSubclass.BaseType.FullName); + int dirtyBit = Weaver.WeaveLists.GetSyncVarStart(netBehaviourSubclass.BaseType.FullName); foreach (FieldDefinition syncVar in syncVars) { Instruction varLabel = serWorker.Create(OpCodes.Nop); diff --git a/Assets/Mirror/Editor/Weaver/Processors/SyncVarProcessor.cs b/Assets/Mirror/Editor/Weaver/Processors/SyncVarProcessor.cs index 6843fe5e0..9bcac1d7c 100644 --- a/Assets/Mirror/Editor/Weaver/Processors/SyncVarProcessor.cs +++ b/Assets/Mirror/Editor/Weaver/Processors/SyncVarProcessor.cs @@ -311,7 +311,7 @@ public static (List syncVars, Dictionary syncVars, Dictionary numSyncVars = new Dictionary(); public HashSet ProcessedMessages = new HashSet(); + + + public int GetSyncVarStart(string className) + { + return numSyncVars.ContainsKey(className) + ? numSyncVars[className] + : 0; + } + + public void SetNumSyncVars(string className, int num) + { + numSyncVars[className] = num; + } + + public void ConfirmGeneratedCodeClass() + { + if (generateContainerClass == null) + { + generateContainerClass = new TypeDefinition("Mirror", "GeneratedNetworkCode", + TypeAttributes.BeforeFieldInit | TypeAttributes.Class | TypeAttributes.AnsiClass | TypeAttributes.Public | TypeAttributes.AutoClass, + WeaverTypes.Import()); + + const MethodAttributes methodAttributes = MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName; + MethodDefinition method = new MethodDefinition(".ctor", methodAttributes, WeaverTypes.Import(typeof(void))); + method.Body.Instructions.Add(Instruction.Create(OpCodes.Ldarg_0)); + method.Body.Instructions.Add(Instruction.Create(OpCodes.Call, Resolvers.ResolveMethod(WeaverTypes.Import(), Weaver.CurrentAssembly, ".ctor"))); + method.Body.Instructions.Add(Instruction.Create(OpCodes.Ret)); + + generateContainerClass.Methods.Add(method); + } + } } internal static class Weaver @@ -64,35 +95,6 @@ public static void Warning(string message, MemberReference mr) Log.Warning($"{message} (at {mr})"); } - public static int GetSyncVarStart(string className) - { - return WeaveLists.numSyncVars.ContainsKey(className) - ? WeaveLists.numSyncVars[className] - : 0; - } - - public static void SetNumSyncVars(string className, int num) - { - WeaveLists.numSyncVars[className] = num; - } - - internal static void ConfirmGeneratedCodeClass() - { - if (WeaveLists.generateContainerClass == null) - { - WeaveLists.generateContainerClass = new TypeDefinition("Mirror", "GeneratedNetworkCode", - TypeAttributes.BeforeFieldInit | TypeAttributes.Class | TypeAttributes.AnsiClass | TypeAttributes.Public | TypeAttributes.AutoClass, - WeaverTypes.Import()); - - const MethodAttributes methodAttributes = MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName; - MethodDefinition method = new MethodDefinition(".ctor", methodAttributes, WeaverTypes.Import(typeof(void))); - method.Body.Instructions.Add(Instruction.Create(OpCodes.Ldarg_0)); - method.Body.Instructions.Add(Instruction.Create(OpCodes.Call, Resolvers.ResolveMethod(WeaverTypes.Import(), CurrentAssembly, ".ctor"))); - method.Body.Instructions.Add(Instruction.Create(OpCodes.Ret)); - - WeaveLists.generateContainerClass.Methods.Add(method); - } - } static void CheckMonoBehaviour(TypeDefinition td) { diff --git a/Assets/Mirror/Editor/Weaver/Writers.cs b/Assets/Mirror/Editor/Weaver/Writers.cs index 1e4f66433..7b7a7db55 100644 --- a/Assets/Mirror/Editor/Weaver/Writers.cs +++ b/Assets/Mirror/Editor/Weaver/Writers.cs @@ -27,7 +27,7 @@ static void RegisterWriteFunc(string name, MethodDefinition newWriterFunc) writeFuncs[name] = newWriterFunc; Weaver.WeaveLists.generatedWriteFunctions.Add(newWriterFunc); - Weaver.ConfirmGeneratedCodeClass(); + Weaver.WeaveLists.ConfirmGeneratedCodeClass(); Weaver.WeaveLists.generateContainerClass.Methods.Add(newWriterFunc); }