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.Ldftn, func);
worker.Emit(OpCodes.Newobj, weaverTypes.CmdDelegateConstructor);
worker.Emit(OpCodes.Newobj, weaverTypes.RemoteCallDelegateConstructor);
//
worker.Emit(OpCodes.Call, registerMethod);
}
@ -380,7 +380,7 @@ void GenerateRegisterCommandDelegate(ILProcessor worker, MethodReference registe
worker.Emit(OpCodes.Ldnull);
worker.Emit(OpCodes.Ldftn, func);
worker.Emit(OpCodes.Newobj, weaverTypes.CmdDelegateConstructor);
worker.Emit(OpCodes.Newobj, weaverTypes.RemoteCallDelegateConstructor);
// requiresAuthority ? 1 : 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 CmdDelegateConstructor;
public MethodReference RemoteCallDelegateConstructor;
public MethodReference NetworkServerGetActive;
public MethodReference NetworkServerGetLocalClientActive;
@ -78,8 +78,8 @@ public WeaverTypes(AssemblyDefinition assembly, Logger Log, ref bool WeavingFail
TypeReference NetworkClientType = Import(typeof(NetworkClient));
NetworkClientGetActive = Resolvers.ResolveMethod(NetworkClientType, assembly, Log, "get_active", ref WeavingFailed);
TypeReference cmdDelegateReference = Import<RemoteCalls.CmdDelegate>();
CmdDelegateConstructor = Resolvers.ResolveMethod(cmdDelegateReference, assembly, Log, ".ctor", ref WeavingFailed);
TypeReference RemoteCallDelegateType = Import<RemoteCalls.RemoteCallDelegate>();
RemoteCallDelegateConstructor = Resolvers.ResolveMethod(RemoteCallDelegateType, assembly, Log, ".ctor", ref WeavingFailed);
TypeReference NetworkBehaviourType = Import<NetworkBehaviour>();
TypeReference RemoteProcedureCallsType = Import(typeof(RemoteCalls.RemoteProcedureCalls));

View File

@ -4,17 +4,17 @@
namespace Mirror.RemoteCalls
{
// command function delegate
public delegate void CmdDelegate(NetworkBehaviour obj, NetworkReader reader, NetworkConnectionToClient senderConnection);
// remote call function delegate
public delegate void RemoteCallDelegate(NetworkBehaviour obj, NetworkReader reader, NetworkConnectionToClient senderConnection);
class Invoker
{
public Type invokeClass;
public MirrorInvokeType invokeType;
public CmdDelegate invokeFunction;
public RemoteCallDelegate invokeFunction;
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 &&
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
int cmdHash = GetMethodHash(invokeClass, cmdName);
@ -67,7 +67,7 @@ internal static int RegisterDelegate(Type invokeClass, string cmdName, MirrorInv
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))
{
@ -85,12 +85,12 @@ static bool CheckIfDeligateExists(Type invokeClass, MirrorInvokeType invokerType
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);
}
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);
}
@ -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>
public static CmdDelegate GetDelegate(int cmdHash)
public static RemoteCallDelegate GetDelegate(int cmdHash)
{
if (cmdHandlerDelegates.TryGetValue(cmdHash, out Invoker invoker))
{

View File

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