Skip to content

Commit

Permalink
fix: Cmds can be called from child classes in other assemblies
Browse files Browse the repository at this point in the history
fix #1108
  • Loading branch information
paulpach committed Oct 1, 2019
1 parent 3831cbd commit d8a98d8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
13 changes: 9 additions & 4 deletions Assets/Mirror/Editor/Weaver/Processors/CommandProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);

Expand Down Expand Up @@ -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,
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -841,17 +841,17 @@ void ProcessCommand(HashSet<string> 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;
}
}
}
Expand Down

0 comments on commit d8a98d8

Please sign in to comment.