* Fix issue #219

pass the invoker class from the weaver when invoking rpcs so that it can produce the same hash they registered
This commit is contained in:
Paul Pacheco 2019-01-01 17:27:49 -06:00 committed by GitHub
parent 07b73dea26
commit b5eb487c65
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 26 additions and 18 deletions

View File

@ -77,7 +77,7 @@ protected void InitSyncObject(SyncObject syncObject)
// ----------------------------- Commands --------------------------------
[EditorBrowsable(EditorBrowsableState.Never)]
protected void SendCommandInternal(string cmdName, NetworkWriter writer, int channelId)
protected void SendCommandInternal(Type invokeClass, string cmdName, NetworkWriter writer, int channelId)
{
// local players can always send commands, regardless of authority, other objects must have authority.
if (!(isLocalPlayer || hasAuthority))
@ -96,7 +96,7 @@ protected void SendCommandInternal(string cmdName, NetworkWriter writer, int cha
CommandMessage message = new CommandMessage();
message.netId = netId;
message.componentIndex = ComponentIndex;
message.cmdHash = (GetType() + ":" + cmdName).GetStableHashCode(); // type+func so Inventory.RpcUse != Equipment.RpcUse
message.cmdHash = (invokeClass + ":" + cmdName).GetStableHashCode(); // type+func so Inventory.RpcUse != Equipment.RpcUse
message.payload = writer.ToArray();
ClientScene.readyConnection.Send((short)MsgType.Command, message, channelId);
@ -111,7 +111,7 @@ public virtual bool InvokeCommand(int cmdHash, NetworkReader reader)
// ----------------------------- Client RPCs --------------------------------
[EditorBrowsable(EditorBrowsableState.Never)]
protected void SendRPCInternal(string rpcName, NetworkWriter writer, int channelId)
protected void SendRPCInternal(Type invokeClass, string rpcName, NetworkWriter writer, int channelId)
{
// This cannot use NetworkServer.active, as that is not specific to this object.
if (!isServer)
@ -124,14 +124,14 @@ protected void SendRPCInternal(string rpcName, NetworkWriter writer, int channel
RpcMessage message = new RpcMessage();
message.netId = netId;
message.componentIndex = ComponentIndex;
message.rpcHash = (GetType() + ":" + rpcName).GetStableHashCode(); // type+func so Inventory.RpcUse != Equipment.RpcUse
message.rpcHash = (invokeClass + ":" + rpcName).GetStableHashCode(); // type+func so Inventory.RpcUse != Equipment.RpcUse
message.payload = writer.ToArray();
NetworkServer.SendToReady(gameObject, (short)MsgType.Rpc, message, channelId);
}
[EditorBrowsable(EditorBrowsableState.Never)]
protected void SendTargetRPCInternal(NetworkConnection conn, string rpcName, NetworkWriter writer, int channelId)
protected void SendTargetRPCInternal(NetworkConnection conn, Type invokeClass, string rpcName, NetworkWriter writer, int channelId)
{
// This cannot use NetworkServer.active, as that is not specific to this object.
if (!isServer)
@ -144,7 +144,7 @@ protected void SendTargetRPCInternal(NetworkConnection conn, string rpcName, Net
RpcMessage message = new RpcMessage();
message.netId = netId;
message.componentIndex = ComponentIndex;
message.rpcHash = (GetType() + ":" + rpcName).GetStableHashCode(); // type+func so Inventory.RpcUse != Equipment.RpcUse
message.rpcHash = (invokeClass + ":" + rpcName).GetStableHashCode(); // type+func so Inventory.RpcUse != Equipment.RpcUse
message.payload = writer.ToArray();
conn.Send((short)MsgType.Rpc, message, channelId);
@ -159,7 +159,7 @@ public virtual bool InvokeRPC(int rpcHash, NetworkReader reader)
// ----------------------------- Sync Events --------------------------------
[EditorBrowsable(EditorBrowsableState.Never)]
protected void SendEventInternal(string eventName, NetworkWriter writer, int channelId)
protected void SendEventInternal(Type invokeClass, string eventName, NetworkWriter writer, int channelId)
{
if (!NetworkServer.active)
{
@ -171,7 +171,7 @@ protected void SendEventInternal(string eventName, NetworkWriter writer, int cha
SyncEventMessage message = new SyncEventMessage();
message.netId = netId;
message.componentIndex = ComponentIndex;
message.eventHash = (GetType() + ":" + eventName).GetStableHashCode(); // type+func so Inventory.RpcUse != Equipment.RpcUse
message.eventHash = (invokeClass + ":" + eventName).GetStableHashCode(); // type+func so Inventory.RpcUse != Equipment.RpcUse
message.payload = writer.ToArray();
NetworkServer.SendToReady(gameObject, (short)MsgType.SyncEvent, message, channelId);

View File

@ -32,7 +32,7 @@ public void CallCmdThrust(float thrusting, int spin)
base.SendCommandInternal(cmdName, networkWriter, cmdName);
}
*/
public static MethodDefinition ProcessCommandCall(MethodDefinition md, CustomAttribute ca)
public static MethodDefinition ProcessCommandCall(TypeDefinition td, MethodDefinition md, CustomAttribute ca)
{
MethodDefinition cmd = new MethodDefinition("Call" + md.Name, MethodAttributes.Public |
MethodAttributes.HideBySig,
@ -89,6 +89,8 @@ public static MethodDefinition ProcessCommandCall(MethodDefinition md, CustomAtt
// invoke interal send and return
cmdWorker.Append(cmdWorker.Create(OpCodes.Ldarg_0)); // load 'base.' to call the SendCommand function with
cmdWorker.Append(cmdWorker.Create(OpCodes.Ldtoken, td));
cmdWorker.Append(cmdWorker.Create(OpCodes.Call, Weaver.getTypeFromHandleReference)); // invokerClass
cmdWorker.Append(cmdWorker.Create(OpCodes.Ldstr, cmdName));
cmdWorker.Append(cmdWorker.Create(OpCodes.Ldloc_0)); // writer
cmdWorker.Append(cmdWorker.Create(OpCodes.Ldc_I4, NetworkBehaviourProcessor.GetChannelId(ca)));

View File

@ -797,7 +797,7 @@ void ProcessMethods()
m_CmdInvocationFuncs.Add(cmdFunc);
}
MethodDefinition cmdCallFunc = CommandProcessor.ProcessCommandCall(md, ca);
MethodDefinition cmdCallFunc = CommandProcessor.ProcessCommandCall(m_td, md, ca);
if (cmdCallFunc != null)
{
m_CmdCallFuncs.Add(cmdCallFunc);
@ -827,7 +827,7 @@ void ProcessMethods()
m_TargetRpcInvocationFuncs.Add(rpcFunc);
}
MethodDefinition rpcCallFunc = TargetRpcProcessor.ProcessTargetRpcCall(md, ca);
MethodDefinition rpcCallFunc = TargetRpcProcessor.ProcessTargetRpcCall(m_td, md, ca);
if (rpcCallFunc != null)
{
m_TargetRpcCallFuncs.Add(rpcCallFunc);
@ -857,7 +857,7 @@ void ProcessMethods()
m_RpcInvocationFuncs.Add(rpcFunc);
}
MethodDefinition rpcCallFunc = RpcProcessor.ProcessRpcCall(md, ca);
MethodDefinition rpcCallFunc = RpcProcessor.ProcessRpcCall(m_td, md, ca);
if (rpcCallFunc != null)
{
m_RpcCallFuncs.Add(rpcCallFunc);

View File

@ -43,11 +43,11 @@ public void CallRpcTest (int param)
} else {
NetworkWriter writer = new NetworkWriter ();
writer.WritePackedUInt32((uint)param);
base.SendRPCInternal("RpcTest", writer, 0);
base.SendRPCInternal(typeof(class),"RpcTest", writer, 0);
}
}
*/
public static MethodDefinition ProcessRpcCall(MethodDefinition md, CustomAttribute ca)
public static MethodDefinition ProcessRpcCall(TypeDefinition td, MethodDefinition md, CustomAttribute ca)
{
MethodDefinition rpc = new MethodDefinition("Call" + md.Name, MethodAttributes.Public |
MethodAttributes.HideBySig,
@ -81,6 +81,8 @@ public static MethodDefinition ProcessRpcCall(MethodDefinition md, CustomAttribu
// invoke SendInternal and return
rpcWorker.Append(rpcWorker.Create(OpCodes.Ldarg_0)); // this
rpcWorker.Append(rpcWorker.Create(OpCodes.Ldtoken, td));
rpcWorker.Append(rpcWorker.Create(OpCodes.Call, Weaver.getTypeFromHandleReference)); // invokerClass
rpcWorker.Append(rpcWorker.Create(OpCodes.Ldstr, rpcName));
rpcWorker.Append(rpcWorker.Create(OpCodes.Ldloc_0)); // writer
rpcWorker.Append(rpcWorker.Create(OpCodes.Ldc_I4, NetworkBehaviourProcessor.GetChannelId(ca)));

View File

@ -64,7 +64,7 @@ public static MethodDefinition ProcessEventInvoke(TypeDefinition td, EventDefini
return cmd;
}
public static MethodDefinition ProcessEventCall(EventDefinition ed, CustomAttribute ca)
public static MethodDefinition ProcessEventCall(TypeDefinition td, EventDefinition ed, CustomAttribute ca)
{
MethodReference invoke = Weaver.ResolveMethod(ed.EventType, "Invoke");
MethodDefinition evt = new MethodDefinition("Call" + ed.Name, MethodAttributes.Public |
@ -91,6 +91,8 @@ public static MethodDefinition ProcessEventCall(EventDefinition ed, CustomAttrib
// invoke interal send and return
evtWorker.Append(evtWorker.Create(OpCodes.Ldarg_0)); // this
evtWorker.Append(evtWorker.Create(OpCodes.Ldtoken, td));
evtWorker.Append(evtWorker.Create(OpCodes.Call, Weaver.getTypeFromHandleReference)); // invokerClass
evtWorker.Append(evtWorker.Create(OpCodes.Ldstr, ed.Name));
evtWorker.Append(evtWorker.Create(OpCodes.Ldloc_0)); // writer
evtWorker.Append(evtWorker.Create(OpCodes.Ldc_I4, NetworkBehaviourProcessor.GetChannelId(ca)));
@ -136,7 +138,7 @@ public static void ProcessEvents(TypeDefinition td, List<EventDefinition> events
Weaver.DLog(td, "ProcessEvent " + ed);
MethodDefinition eventCallFunc = SyncEventProcessor.ProcessEventCall(ed, ca);
MethodDefinition eventCallFunc = SyncEventProcessor.ProcessEventCall(td, ed, ca);
td.Methods.Add(eventCallFunc);
Weaver.lists.replacedEvents.Add(ed);

View File

@ -49,11 +49,11 @@ public void CallTargetTest (NetworkConnection conn, int param)
} else {
NetworkWriter writer = new NetworkWriter ();
writer.WritePackedUInt32 ((uint)param);
base.SendTargetRPCInternal (conn, "TargetTest", val);
base.SendTargetRPCInternal (conn, typeof(class), "TargetTest", val);
}
}
*/
public static MethodDefinition ProcessTargetRpcCall(MethodDefinition md, CustomAttribute ca)
public static MethodDefinition ProcessTargetRpcCall(TypeDefinition td, MethodDefinition md, CustomAttribute ca)
{
MethodDefinition rpc = new MethodDefinition("Call" + md.Name, MethodAttributes.Public |
MethodAttributes.HideBySig,
@ -100,6 +100,8 @@ public static MethodDefinition ProcessTargetRpcCall(MethodDefinition md, CustomA
// invoke SendInternal and return
rpcWorker.Append(rpcWorker.Create(OpCodes.Ldarg_0)); // this
rpcWorker.Append(rpcWorker.Create(OpCodes.Ldarg_1)); // connection
rpcWorker.Append(rpcWorker.Create(OpCodes.Ldtoken, td));
rpcWorker.Append(rpcWorker.Create(OpCodes.Call, Weaver.getTypeFromHandleReference)); // invokerClass
rpcWorker.Append(rpcWorker.Create(OpCodes.Ldstr, rpcName));
rpcWorker.Append(rpcWorker.Create(OpCodes.Ldloc_0)); // writer
rpcWorker.Append(rpcWorker.Create(OpCodes.Ldc_I4, NetworkBehaviourProcessor.GetChannelId(ca)));