mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 11:00:32 +00:00
Simplify adding substitute methods
This commit is contained in:
parent
9c4d172664
commit
97fe7a0a01
@ -33,7 +33,7 @@ correctly in dependent assemblies
|
||||
*/
|
||||
public static MethodDefinition ProcessCommandCall(TypeDefinition td, MethodDefinition md, CustomAttribute ca)
|
||||
{
|
||||
MethodDefinition cmd = MethodProcessor.SubstituteMethod(md, "Call" + md.Name);
|
||||
MethodDefinition cmd = MethodProcessor.SubstituteMethod(td, md, "Call" + md.Name);
|
||||
|
||||
ILProcessor cmdWorker = md.Body.GetILProcessor();
|
||||
|
||||
@ -112,7 +112,7 @@ public static MethodDefinition ProcessCommandInvoke(TypeDefinition td, MethodDef
|
||||
cmdWorker.Append(cmdWorker.Create(OpCodes.Ret));
|
||||
|
||||
NetworkBehaviourProcessor.AddInvokeParameters(cmd.Parameters);
|
||||
|
||||
td.Methods.Add(cmd);
|
||||
return cmd;
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,7 @@ public static class MethodProcessor
|
||||
//
|
||||
// the original method definition loses all code
|
||||
// this returns the newly created method with all the user provided code
|
||||
public static MethodDefinition SubstituteMethod(MethodDefinition md, string newName)
|
||||
public static MethodDefinition SubstituteMethod(TypeDefinition td, MethodDefinition md, string newName)
|
||||
{
|
||||
MethodDefinition cmd = new MethodDefinition(newName,md.Attributes, md.ReturnType);
|
||||
|
||||
@ -53,6 +53,7 @@ public static MethodDefinition SubstituteMethod(MethodDefinition md, string newN
|
||||
|
||||
(md.DebugInformation.Scope, cmd.DebugInformation.Scope) = (cmd.DebugInformation.Scope, md.DebugInformation.Scope);
|
||||
|
||||
td.Methods.Add(cmd);
|
||||
return cmd;
|
||||
}
|
||||
}
|
||||
|
@ -841,8 +841,10 @@ void ProcessMethods()
|
||||
{
|
||||
HashSet<string> names = new HashSet<string>();
|
||||
|
||||
// copy the list of methods because we will be adding methods in the loop
|
||||
List<MethodDefinition> methods = new List<MethodDefinition>(netBehaviourSubclass.Methods);
|
||||
// find command and RPC functions
|
||||
foreach (MethodDefinition md in netBehaviourSubclass.Methods)
|
||||
foreach (MethodDefinition md in methods)
|
||||
{
|
||||
foreach (CustomAttribute ca in md.CustomAttributes)
|
||||
{
|
||||
@ -865,34 +867,6 @@ void ProcessMethods()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// cmds
|
||||
foreach (MethodDefinition md in commandInvocationFuncs)
|
||||
{
|
||||
netBehaviourSubclass.Methods.Add(md);
|
||||
}
|
||||
foreach (MethodDefinition md in commandCallFuncs)
|
||||
{
|
||||
netBehaviourSubclass.Methods.Add(md);
|
||||
}
|
||||
|
||||
// rpcs
|
||||
foreach (MethodDefinition md in clientRpcInvocationFuncs)
|
||||
{
|
||||
netBehaviourSubclass.Methods.Add(md);
|
||||
}
|
||||
foreach (MethodDefinition md in targetRpcInvocationFuncs)
|
||||
{
|
||||
netBehaviourSubclass.Methods.Add(md);
|
||||
}
|
||||
foreach (MethodDefinition md in clientRpcCallFuncs)
|
||||
{
|
||||
netBehaviourSubclass.Methods.Add(md);
|
||||
}
|
||||
foreach (MethodDefinition md in targetRpcCallFuncs)
|
||||
{
|
||||
netBehaviourSubclass.Methods.Add(md);
|
||||
}
|
||||
}
|
||||
|
||||
void ProcessClientRpc(HashSet<string> names, MethodDefinition md, CustomAttribute ca)
|
||||
|
@ -31,7 +31,7 @@ public static MethodDefinition ProcessRpcInvoke(TypeDefinition td, MethodDefinit
|
||||
rpcWorker.Append(rpcWorker.Create(OpCodes.Ret));
|
||||
|
||||
NetworkBehaviourProcessor.AddInvokeParameters(rpc.Parameters);
|
||||
|
||||
td.Methods.Add(rpc);
|
||||
return rpc;
|
||||
}
|
||||
|
||||
@ -59,7 +59,7 @@ correctly in dependent assemblies
|
||||
*/
|
||||
public static MethodDefinition ProcessRpcCall(TypeDefinition td, MethodDefinition md, CustomAttribute ca)
|
||||
{
|
||||
MethodDefinition rpc = MethodProcessor.SubstituteMethod(md, "Call" + md.Name);
|
||||
MethodDefinition rpc = MethodProcessor.SubstituteMethod(td, md, "Call" + md.Name);
|
||||
|
||||
ILProcessor rpcWorker = md.Body.GetILProcessor();
|
||||
|
||||
|
@ -48,7 +48,7 @@ public static MethodDefinition ProcessTargetRpcInvoke(TypeDefinition td, MethodD
|
||||
rpcWorker.Append(rpcWorker.Create(OpCodes.Ret));
|
||||
|
||||
NetworkBehaviourProcessor.AddInvokeParameters(rpc.Parameters);
|
||||
|
||||
td.Methods.Add(rpc);
|
||||
return rpc;
|
||||
}
|
||||
|
||||
@ -87,7 +87,7 @@ correctly in dependent assemblies
|
||||
*/
|
||||
public static MethodDefinition ProcessTargetRpcCall(TypeDefinition td, MethodDefinition md, CustomAttribute ca)
|
||||
{
|
||||
MethodDefinition rpc = MethodProcessor.SubstituteMethod(md, "Call" + md.Name);
|
||||
MethodDefinition rpc = MethodProcessor.SubstituteMethod(td, md, "Call" + md.Name);
|
||||
|
||||
ILProcessor rpcWorker = md.Body.GetILProcessor();
|
||||
|
||||
|
@ -470,8 +470,8 @@ public void CommandCantBeStatic()
|
||||
[Test]
|
||||
public void ClientRpcValid()
|
||||
{
|
||||
Assert.That(CompilationFinishedHook.WeaveFailed, Is.False);
|
||||
Assert.That(weaverErrors, Is.Empty);
|
||||
Assert.That(CompilationFinishedHook.WeaveFailed, Is.False);
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
Loading…
Reference in New Issue
Block a user