From d8a98d8d996aeded693223b00b90f2eea5084c11 Mon Sep 17 00:00:00 2001 From: Paul Pacheco Date: Mon, 30 Sep 2019 20:51:34 -0500 Subject: [PATCH] fix: Cmds can be called from child classes in other assemblies fix #1108 --- .../Editor/Weaver/Processors/CommandProcessor.cs | 13 +++++++++---- .../Weaver/Processors/NetworkBehaviourProcessor.cs | 6 +++--- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/Assets/Mirror/Editor/Weaver/Processors/CommandProcessor.cs b/Assets/Mirror/Editor/Weaver/Processors/CommandProcessor.cs index 2a1688fd4..dfd4a2534 100644 --- a/Assets/Mirror/Editor/Weaver/Processors/CommandProcessor.cs +++ b/Assets/Mirror/Editor/Weaver/Processors/CommandProcessor.cs @@ -37,7 +37,12 @@ public static MethodDefinition ProcessCommandCall(TypeDefinition td, MethodDefin cmd.Parameters.Add(new ParameterDefinition(pd.Name, ParameterAttributes.None, pd.ParameterType)); } - ILProcessor cmdWorker = cmd.Body.GetILProcessor(); + // move the old body to the new function + MethodBody newBody = cmd.Body; + cmd.Body = md.Body; + md.Body = newBody; + + ILProcessor cmdWorker = md.Body.GetILProcessor(); NetworkBehaviourProcessor.WriteSetupLocals(cmdWorker); @@ -59,7 +64,7 @@ public static MethodDefinition ProcessCommandCall(TypeDefinition td, MethodDefin { cmdWorker.Append(cmdWorker.Create(OpCodes.Ldarg, i + 1)); } - cmdWorker.Append(cmdWorker.Create(OpCodes.Call, md)); + cmdWorker.Append(cmdWorker.Create(OpCodes.Call, cmd)); cmdWorker.Append(cmdWorker.Create(OpCodes.Ret)); cmdWorker.Append(localClientLabel); @@ -104,7 +109,7 @@ protected static void InvokeCmdCmdThrust(NetworkBehaviour obj, NetworkReader rea ((ShipControl)obj).CmdThrust(reader.ReadSingle(), (int)reader.ReadPackedUInt32()); } */ - public static MethodDefinition ProcessCommandInvoke(TypeDefinition td, MethodDefinition md) + public static MethodDefinition ProcessCommandInvoke(TypeDefinition td, MethodDefinition md, MethodDefinition cmdCallFunc) { MethodDefinition cmd = new MethodDefinition(CmdPrefix + md.Name, MethodAttributes.Family | MethodAttributes.Static | MethodAttributes.HideBySig, @@ -123,7 +128,7 @@ public static MethodDefinition ProcessCommandInvoke(TypeDefinition td, MethodDef return null; // invoke actual command function - cmdWorker.Append(cmdWorker.Create(OpCodes.Callvirt, md)); + cmdWorker.Append(cmdWorker.Create(OpCodes.Callvirt, cmdCallFunc)); cmdWorker.Append(cmdWorker.Create(OpCodes.Ret)); NetworkBehaviourProcessor.AddInvokeParameters(cmd.Parameters); diff --git a/Assets/Mirror/Editor/Weaver/Processors/NetworkBehaviourProcessor.cs b/Assets/Mirror/Editor/Weaver/Processors/NetworkBehaviourProcessor.cs index 0b12e03e2..69b2a24db 100644 --- a/Assets/Mirror/Editor/Weaver/Processors/NetworkBehaviourProcessor.cs +++ b/Assets/Mirror/Editor/Weaver/Processors/NetworkBehaviourProcessor.cs @@ -841,17 +841,17 @@ void ProcessCommand(HashSet names, MethodDefinition md, CustomAttribute names.Add(md.Name); commands.Add(md); - MethodDefinition cmdFunc = CommandProcessor.ProcessCommandInvoke(netBehaviourSubclass, md); + MethodDefinition cmdCallFunc = CommandProcessor.ProcessCommandCall(netBehaviourSubclass, md, ca); + + MethodDefinition cmdFunc = CommandProcessor.ProcessCommandInvoke(netBehaviourSubclass, md, cmdCallFunc); if (cmdFunc != null) { commandInvocationFuncs.Add(cmdFunc); } - MethodDefinition cmdCallFunc = CommandProcessor.ProcessCommandCall(netBehaviourSubclass, md, ca); if (cmdCallFunc != null) { commandCallFuncs.Add(cmdCallFunc); - Weaver.WeaveLists.replaceMethods[md.FullName] = cmdCallFunc; } } }