Skip to content

Commit

Permalink
fix: TargetRpc now works accross assemblies (#1130)
Browse files Browse the repository at this point in the history
similar to #1128 but for TargetRpc
  • Loading branch information
paulpach committed Oct 1, 2019
1 parent 13dbcb9 commit 5ecd646
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -813,17 +813,17 @@ void ProcessTargetRpc(HashSet<string> names, MethodDefinition md, CustomAttribut
names.Add(md.Name);
targetRpcs.Add(md);

MethodDefinition rpcFunc = TargetRpcProcessor.ProcessTargetRpcInvoke(netBehaviourSubclass, md);
MethodDefinition rpcCallFunc = TargetRpcProcessor.ProcessTargetRpcCall(netBehaviourSubclass, md, ca);

MethodDefinition rpcFunc = TargetRpcProcessor.ProcessTargetRpcInvoke(netBehaviourSubclass, md, rpcCallFunc);
if (rpcFunc != null)
{
targetRpcInvocationFuncs.Add(rpcFunc);
}

MethodDefinition rpcCallFunc = TargetRpcProcessor.ProcessTargetRpcCall(netBehaviourSubclass, md, ca);
if (rpcCallFunc != null)
{
targetRpcCallFuncs.Add(rpcCallFunc);
Weaver.WeaveLists.replaceMethods[md.FullName] = rpcCallFunc;
}
}

Expand Down
11 changes: 8 additions & 3 deletions Assets/Mirror/Editor/Weaver/Processors/TargetRpcProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static bool HasNetworkConnectionParameter(MethodDefinition md)
md.Parameters[0].ParameterType.FullName == Weaver.NetworkConnectionType.FullName;
}

public static MethodDefinition ProcessTargetRpcInvoke(TypeDefinition td, MethodDefinition md)
public static MethodDefinition ProcessTargetRpcInvoke(TypeDefinition td, MethodDefinition md, MethodDefinition rpcCallFunc)
{
MethodDefinition rpc = new MethodDefinition(RpcProcessor.RpcPrefix + md.Name, MethodAttributes.Family |
MethodAttributes.Static |
Expand Down Expand Up @@ -44,7 +44,7 @@ public static MethodDefinition ProcessTargetRpcInvoke(TypeDefinition td, MethodD
return null;

// invoke actual command function
rpcWorker.Append(rpcWorker.Create(OpCodes.Callvirt, md));
rpcWorker.Append(rpcWorker.Create(OpCodes.Callvirt, rpcCallFunc));
rpcWorker.Append(rpcWorker.Create(OpCodes.Ret));

NetworkBehaviourProcessor.AddInvokeParameters(rpc.Parameters);
Expand Down Expand Up @@ -80,7 +80,12 @@ public static MethodDefinition ProcessTargetRpcCall(TypeDefinition td, MethodDef
rpc.Parameters.Add(new ParameterDefinition(pd.Name, ParameterAttributes.None, pd.ParameterType));
}

ILProcessor rpcWorker = rpc.Body.GetILProcessor();
// move the old body to the new function
MethodBody newBody = rpc.Body;
rpc.Body = md.Body;
md.Body = newBody;

ILProcessor rpcWorker = md.Body.GetILProcessor();

NetworkBehaviourProcessor.WriteSetupLocals(rpcWorker);

Expand Down

0 comments on commit 5ecd646

Please sign in to comment.