fix: Cmds can be called from child classes in other assemblies

fix #1108
This commit is contained in:
Paul Pacheco 2019-09-30 20:51:34 -05:00 committed by GitHub
parent 3831cbddbe
commit d8a98d8d99
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 7 deletions

View File

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

View File

@ -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;
}
}
}