diff --git a/Assets/Mirror/Editor/Weaver/Processors/ServerClientAttributeProcessor.cs b/Assets/Mirror/Editor/Weaver/Processors/ServerClientAttributeProcessor.cs index 96280db1b..38abb18fb 100644 --- a/Assets/Mirror/Editor/Weaver/Processors/ServerClientAttributeProcessor.cs +++ b/Assets/Mirror/Editor/Weaver/Processors/ServerClientAttributeProcessor.cs @@ -6,22 +6,22 @@ namespace Mirror.Weaver { static class ServerClientAttributeProcessor { - public static bool Process(TypeDefinition td) + public static bool Process(WeaverTypes weaverTypes, TypeDefinition td) { bool modified = false; foreach (MethodDefinition md in td.Methods) { - modified |= ProcessSiteMethod(md); + modified |= ProcessSiteMethod(weaverTypes, md); } foreach (TypeDefinition nested in td.NestedTypes) { - modified |= Process(nested); + modified |= Process(weaverTypes, nested); } return modified; } - static bool ProcessSiteMethod(MethodDefinition md) + static bool ProcessSiteMethod(WeaverTypes weaverTypes, MethodDefinition md) { if (md.Name == ".cctor" || md.Name == NetworkBehaviourProcessor.ProcessedFunctionName || @@ -40,7 +40,7 @@ static bool ProcessSiteMethod(MethodDefinition md) if (md.Body != null && md.Body.Instructions != null) { - return ProcessMethodAttributes(md); + return ProcessMethodAttributes(weaverTypes, md); } return false; } @@ -63,50 +63,50 @@ public static bool HasServerClientAttribute(MethodDefinition md) return false; } - public static bool ProcessMethodAttributes(MethodDefinition md) + public static bool ProcessMethodAttributes(WeaverTypes weaverTypes, MethodDefinition md) { if (md.HasCustomAttribute()) - InjectServerGuard(md, true); + InjectServerGuard(weaverTypes, md, true); else if (md.HasCustomAttribute()) - InjectServerGuard(md, false); + InjectServerGuard(weaverTypes, md, false); else if (md.HasCustomAttribute()) - InjectClientGuard(md, true); + InjectClientGuard(weaverTypes, md, true); else if (md.HasCustomAttribute()) - InjectClientGuard(md, false); + InjectClientGuard(weaverTypes, md, false); else return false; return true; } - static void InjectServerGuard(MethodDefinition md, bool logWarning) + static void InjectServerGuard(WeaverTypes weaverTypes, MethodDefinition md, bool logWarning) { ILProcessor worker = md.Body.GetILProcessor(); Instruction top = md.Body.Instructions[0]; - worker.InsertBefore(top, worker.Create(OpCodes.Call, Weaver.weaverTypes.NetworkServerGetActive)); + worker.InsertBefore(top, worker.Create(OpCodes.Call, weaverTypes.NetworkServerGetActive)); worker.InsertBefore(top, worker.Create(OpCodes.Brtrue, top)); if (logWarning) { worker.InsertBefore(top, worker.Create(OpCodes.Ldstr, $"[Server] function '{md.FullName}' called when server was not active")); - worker.InsertBefore(top, worker.Create(OpCodes.Call, Weaver.weaverTypes.logWarningReference)); + worker.InsertBefore(top, worker.Create(OpCodes.Call, weaverTypes.logWarningReference)); } InjectGuardParameters(md, worker, top); InjectGuardReturnValue(md, worker, top); worker.InsertBefore(top, worker.Create(OpCodes.Ret)); } - static void InjectClientGuard(MethodDefinition md, bool logWarning) + static void InjectClientGuard(WeaverTypes weaverTypes, MethodDefinition md, bool logWarning) { ILProcessor worker = md.Body.GetILProcessor(); Instruction top = md.Body.Instructions[0]; - worker.InsertBefore(top, worker.Create(OpCodes.Call, Weaver.weaverTypes.NetworkClientGetActive)); + worker.InsertBefore(top, worker.Create(OpCodes.Call, weaverTypes.NetworkClientGetActive)); worker.InsertBefore(top, worker.Create(OpCodes.Brtrue, top)); if (logWarning) { worker.InsertBefore(top, worker.Create(OpCodes.Ldstr, $"[Client] function '{md.FullName}' called when client was not active")); - worker.InsertBefore(top, worker.Create(OpCodes.Call, Weaver.weaverTypes.logWarningReference)); + worker.InsertBefore(top, worker.Create(OpCodes.Call, weaverTypes.logWarningReference)); } InjectGuardParameters(md, worker, top); diff --git a/Assets/Mirror/Editor/Weaver/Weaver.cs b/Assets/Mirror/Editor/Weaver/Weaver.cs index cc6fde339..0ea765f7c 100644 --- a/Assets/Mirror/Editor/Weaver/Weaver.cs +++ b/Assets/Mirror/Editor/Weaver/Weaver.cs @@ -101,7 +101,7 @@ static bool WeaveModule(ModuleDefinition moduleDefinition) if (td.IsClass && td.BaseType.CanBeResolved()) { modified |= WeaveNetworkBehavior(td); - modified |= ServerClientAttributeProcessor.Process(td); + modified |= ServerClientAttributeProcessor.Process(weaverTypes, td); } } watch.Stop();