mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 11:00:32 +00:00
fix: Cmds can be called from child classes in other assemblies
fix #1108
This commit is contained in:
parent
3831cbddbe
commit
d8a98d8d99
@ -37,7 +37,12 @@ public static MethodDefinition ProcessCommandCall(TypeDefinition td, MethodDefin
|
|||||||
cmd.Parameters.Add(new ParameterDefinition(pd.Name, ParameterAttributes.None, pd.ParameterType));
|
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);
|
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.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(cmdWorker.Create(OpCodes.Ret));
|
||||||
cmdWorker.Append(localClientLabel);
|
cmdWorker.Append(localClientLabel);
|
||||||
|
|
||||||
@ -104,7 +109,7 @@ protected static void InvokeCmdCmdThrust(NetworkBehaviour obj, NetworkReader rea
|
|||||||
((ShipControl)obj).CmdThrust(reader.ReadSingle(), (int)reader.ReadPackedUInt32());
|
((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,
|
MethodDefinition cmd = new MethodDefinition(CmdPrefix + md.Name,
|
||||||
MethodAttributes.Family | MethodAttributes.Static | MethodAttributes.HideBySig,
|
MethodAttributes.Family | MethodAttributes.Static | MethodAttributes.HideBySig,
|
||||||
@ -123,7 +128,7 @@ public static MethodDefinition ProcessCommandInvoke(TypeDefinition td, MethodDef
|
|||||||
return null;
|
return null;
|
||||||
|
|
||||||
// invoke actual command function
|
// invoke actual command function
|
||||||
cmdWorker.Append(cmdWorker.Create(OpCodes.Callvirt, md));
|
cmdWorker.Append(cmdWorker.Create(OpCodes.Callvirt, cmdCallFunc));
|
||||||
cmdWorker.Append(cmdWorker.Create(OpCodes.Ret));
|
cmdWorker.Append(cmdWorker.Create(OpCodes.Ret));
|
||||||
|
|
||||||
NetworkBehaviourProcessor.AddInvokeParameters(cmd.Parameters);
|
NetworkBehaviourProcessor.AddInvokeParameters(cmd.Parameters);
|
||||||
|
@ -841,17 +841,17 @@ void ProcessCommand(HashSet<string> names, MethodDefinition md, CustomAttribute
|
|||||||
names.Add(md.Name);
|
names.Add(md.Name);
|
||||||
commands.Add(md);
|
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)
|
if (cmdFunc != null)
|
||||||
{
|
{
|
||||||
commandInvocationFuncs.Add(cmdFunc);
|
commandInvocationFuncs.Add(cmdFunc);
|
||||||
}
|
}
|
||||||
|
|
||||||
MethodDefinition cmdCallFunc = CommandProcessor.ProcessCommandCall(netBehaviourSubclass, md, ca);
|
|
||||||
if (cmdCallFunc != null)
|
if (cmdCallFunc != null)
|
||||||
{
|
{
|
||||||
commandCallFuncs.Add(cmdCallFunc);
|
commandCallFuncs.Add(cmdCallFunc);
|
||||||
Weaver.WeaveLists.replaceMethods[md.FullName] = cmdCallFunc;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user