breaking: CmdDelegate renamed to RemoteCallDelegate

This commit is contained in:
vis2k 2022-01-17 19:30:54 +08:00
parent 40b8886c48
commit 6738ede014
4 changed files with 17 additions and 17 deletions

View File

@ -364,7 +364,7 @@ void GenerateRegisterRemoteDelegate(ILProcessor worker, MethodReference register
worker.Emit(OpCodes.Ldnull); worker.Emit(OpCodes.Ldnull);
worker.Emit(OpCodes.Ldftn, func); worker.Emit(OpCodes.Ldftn, func);
worker.Emit(OpCodes.Newobj, weaverTypes.CmdDelegateConstructor); worker.Emit(OpCodes.Newobj, weaverTypes.RemoteCallDelegateConstructor);
// //
worker.Emit(OpCodes.Call, registerMethod); worker.Emit(OpCodes.Call, registerMethod);
} }
@ -380,7 +380,7 @@ void GenerateRegisterCommandDelegate(ILProcessor worker, MethodReference registe
worker.Emit(OpCodes.Ldnull); worker.Emit(OpCodes.Ldnull);
worker.Emit(OpCodes.Ldftn, func); worker.Emit(OpCodes.Ldftn, func);
worker.Emit(OpCodes.Newobj, weaverTypes.CmdDelegateConstructor); worker.Emit(OpCodes.Newobj, weaverTypes.RemoteCallDelegateConstructor);
// requiresAuthority ? 1 : 0 // requiresAuthority ? 1 : 0
worker.Emit(requiresAuthority ? OpCodes.Ldc_I4_1 : OpCodes.Ldc_I4_0); worker.Emit(requiresAuthority ? OpCodes.Ldc_I4_1 : OpCodes.Ldc_I4_0);

View File

@ -16,7 +16,7 @@ public class WeaverTypes
public MethodReference NetworkClientConnectionReference; public MethodReference NetworkClientConnectionReference;
public MethodReference CmdDelegateConstructor; public MethodReference RemoteCallDelegateConstructor;
public MethodReference NetworkServerGetActive; public MethodReference NetworkServerGetActive;
public MethodReference NetworkServerGetLocalClientActive; public MethodReference NetworkServerGetLocalClientActive;
@ -78,8 +78,8 @@ public WeaverTypes(AssemblyDefinition assembly, Logger Log, ref bool WeavingFail
TypeReference NetworkClientType = Import(typeof(NetworkClient)); TypeReference NetworkClientType = Import(typeof(NetworkClient));
NetworkClientGetActive = Resolvers.ResolveMethod(NetworkClientType, assembly, Log, "get_active", ref WeavingFailed); NetworkClientGetActive = Resolvers.ResolveMethod(NetworkClientType, assembly, Log, "get_active", ref WeavingFailed);
TypeReference cmdDelegateReference = Import<RemoteCalls.CmdDelegate>(); TypeReference RemoteCallDelegateType = Import<RemoteCalls.RemoteCallDelegate>();
CmdDelegateConstructor = Resolvers.ResolveMethod(cmdDelegateReference, assembly, Log, ".ctor", ref WeavingFailed); RemoteCallDelegateConstructor = Resolvers.ResolveMethod(RemoteCallDelegateType, assembly, Log, ".ctor", ref WeavingFailed);
TypeReference NetworkBehaviourType = Import<NetworkBehaviour>(); TypeReference NetworkBehaviourType = Import<NetworkBehaviour>();
TypeReference RemoteProcedureCallsType = Import(typeof(RemoteCalls.RemoteProcedureCalls)); TypeReference RemoteProcedureCallsType = Import(typeof(RemoteCalls.RemoteProcedureCalls));

View File

@ -4,17 +4,17 @@
namespace Mirror.RemoteCalls namespace Mirror.RemoteCalls
{ {
// command function delegate // remote call function delegate
public delegate void CmdDelegate(NetworkBehaviour obj, NetworkReader reader, NetworkConnectionToClient senderConnection); public delegate void RemoteCallDelegate(NetworkBehaviour obj, NetworkReader reader, NetworkConnectionToClient senderConnection);
class Invoker class Invoker
{ {
public Type invokeClass; public Type invokeClass;
public MirrorInvokeType invokeType; public MirrorInvokeType invokeType;
public CmdDelegate invokeFunction; public RemoteCallDelegate invokeFunction;
public bool cmdRequiresAuthority; public bool cmdRequiresAuthority;
public bool AreEqual(Type invokeClass, MirrorInvokeType invokeType, CmdDelegate invokeFunction) public bool AreEqual(Type invokeClass, MirrorInvokeType invokeType, RemoteCallDelegate invokeFunction)
{ {
return (this.invokeClass == invokeClass && return (this.invokeClass == invokeClass &&
this.invokeType == invokeType && this.invokeType == invokeType &&
@ -43,7 +43,7 @@ internal static int GetMethodHash(Type invokeClass, string methodName)
} }
} }
internal static int RegisterDelegate(Type invokeClass, string cmdName, MirrorInvokeType invokerType, CmdDelegate func, bool cmdRequiresAuthority = true) internal static int RegisterDelegate(Type invokeClass, string cmdName, MirrorInvokeType invokerType, RemoteCallDelegate func, bool cmdRequiresAuthority = true)
{ {
// type+func so Inventory.RpcUse != Equipment.RpcUse // type+func so Inventory.RpcUse != Equipment.RpcUse
int cmdHash = GetMethodHash(invokeClass, cmdName); int cmdHash = GetMethodHash(invokeClass, cmdName);
@ -67,7 +67,7 @@ internal static int RegisterDelegate(Type invokeClass, string cmdName, MirrorInv
return cmdHash; return cmdHash;
} }
static bool CheckIfDeligateExists(Type invokeClass, MirrorInvokeType invokerType, CmdDelegate func, int cmdHash) static bool CheckIfDeligateExists(Type invokeClass, MirrorInvokeType invokerType, RemoteCallDelegate func, int cmdHash)
{ {
if (cmdHandlerDelegates.ContainsKey(cmdHash)) if (cmdHandlerDelegates.ContainsKey(cmdHash))
{ {
@ -85,12 +85,12 @@ static bool CheckIfDeligateExists(Type invokeClass, MirrorInvokeType invokerType
return false; return false;
} }
public static void RegisterCommandDelegate(Type invokeClass, string cmdName, CmdDelegate func, bool requiresAuthority) public static void RegisterCommandDelegate(Type invokeClass, string cmdName, RemoteCallDelegate func, bool requiresAuthority)
{ {
RegisterDelegate(invokeClass, cmdName, MirrorInvokeType.Command, func, requiresAuthority); RegisterDelegate(invokeClass, cmdName, MirrorInvokeType.Command, func, requiresAuthority);
} }
public static void RegisterRpcDelegate(Type invokeClass, string rpcName, CmdDelegate func) public static void RegisterRpcDelegate(Type invokeClass, string rpcName, RemoteCallDelegate func)
{ {
RegisterDelegate(invokeClass, rpcName, MirrorInvokeType.ClientRpc, func); RegisterDelegate(invokeClass, rpcName, MirrorInvokeType.ClientRpc, func);
} }
@ -139,7 +139,7 @@ internal static CommandInfo GetCommandInfo(int cmdHash, NetworkBehaviour invokin
} }
/// <summary>Gets the handler function by hash. Useful for profilers and debuggers.</summary> /// <summary>Gets the handler function by hash. Useful for profilers and debuggers.</summary>
public static CmdDelegate GetDelegate(int cmdHash) public static RemoteCallDelegate GetDelegate(int cmdHash)
{ {
if (cmdHandlerDelegates.TryGetValue(cmdHash, out Invoker invoker)) if (cmdHandlerDelegates.TryGetValue(cmdHash, out Invoker invoker))
{ {

View File

@ -224,12 +224,12 @@ public void GetDelegate()
// get handler // get handler
int cmdHash = RemoteProcedureCalls.GetMethodHash(typeof(NetworkBehaviourDelegateComponent), nameof(NetworkBehaviourDelegateComponent.Delegate)); int cmdHash = RemoteProcedureCalls.GetMethodHash(typeof(NetworkBehaviourDelegateComponent), nameof(NetworkBehaviourDelegateComponent.Delegate));
CmdDelegate func = RemoteProcedureCalls.GetDelegate(cmdHash); RemoteCallDelegate func = RemoteProcedureCalls.GetDelegate(cmdHash);
CmdDelegate expected = NetworkBehaviourDelegateComponent.Delegate; RemoteCallDelegate expected = NetworkBehaviourDelegateComponent.Delegate;
Assert.That(func, Is.EqualTo(expected)); Assert.That(func, Is.EqualTo(expected));
// invalid hash should return null handler // invalid hash should return null handler
CmdDelegate funcNull = RemoteProcedureCalls.GetDelegate(1234); RemoteCallDelegate funcNull = RemoteProcedureCalls.GetDelegate(1234);
Assert.That(funcNull, Is.Null); Assert.That(funcNull, Is.Null);
// clean up // clean up