diff --git a/Assets/Mirage/Runtime/RemoteCalls/ClientRpcSender.cs b/Assets/Mirage/Runtime/RemoteCalls/ClientRpcSender.cs index 39e1e57b3f..fef0c08bb5 100644 --- a/Assets/Mirage/Runtime/RemoteCalls/ClientRpcSender.cs +++ b/Assets/Mirage/Runtime/RemoteCalls/ClientRpcSender.cs @@ -11,8 +11,9 @@ public static class ClientRpcSender { private static readonly ILogger logger = LogFactory.GetLogger(typeof(ClientRpcSender)); - public static void Send(NetworkBehaviour behaviour, int index, NetworkWriter writer, Channel channelId, bool excludeOwner) + public static void Send(NetworkBehaviour behaviour, int relativeIndex, NetworkWriter writer, Channel channelId, bool excludeOwner) { + var index = behaviour.Identity.RemoteCallCollection.GetIndexOffset(behaviour) + relativeIndex; var message = CreateMessage(behaviour, index, writer); // The public facing parameter is excludeOwner in [ClientRpc] @@ -21,8 +22,9 @@ public static void Send(NetworkBehaviour behaviour, int index, NetworkWriter wri behaviour.Identity.SendToRemoteObservers(message, includeOwner, channelId); } - public static void SendTarget(NetworkBehaviour behaviour, int index, NetworkWriter writer, Channel channelId, INetworkPlayer player) + public static void SendTarget(NetworkBehaviour behaviour, int relativeIndex, NetworkWriter writer, Channel channelId, INetworkPlayer player) { + var index = behaviour.Identity.RemoteCallCollection.GetIndexOffset(behaviour) + relativeIndex; var message = CreateMessage(behaviour, index, writer); // player parameter is optional. use owner if null diff --git a/Assets/Mirage/Runtime/RemoteCalls/RemoteCallHelper.cs b/Assets/Mirage/Runtime/RemoteCalls/RemoteCallHelper.cs index 5ab518466e..d05880f796 100644 --- a/Assets/Mirage/Runtime/RemoteCalls/RemoteCallHelper.cs +++ b/Assets/Mirage/Runtime/RemoteCalls/RemoteCallHelper.cs @@ -1,4 +1,5 @@ using System; +using System.Runtime.CompilerServices; using Cysharp.Threading.Tasks; using Mirage.Logging; using Mirage.Serialization; @@ -83,16 +84,19 @@ void CmdWrapper(NetworkBehaviour obj, NetworkReader reader, INetworkPlayer sende Register(index, name, cmdRequireAuthority, RpcInvokeType.ServerRpc, behaviour, CmdWrapper); } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public int GetIndexOffset(NetworkBehaviour behaviour) { return IndexOffset[behaviour.ComponentIndex]; } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public RemoteCall GetRelative(NetworkBehaviour behaviour, int index) { return RemoteCalls[GetIndexOffset(behaviour) + index]; } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public RemoteCall GetAbsolute(int index) { return RemoteCalls[index]; diff --git a/Assets/Mirage/Runtime/RemoteCalls/ServerRpcSender.cs b/Assets/Mirage/Runtime/RemoteCalls/ServerRpcSender.cs index 86a2c62e8b..1ab028fbd1 100644 --- a/Assets/Mirage/Runtime/RemoteCalls/ServerRpcSender.cs +++ b/Assets/Mirage/Runtime/RemoteCalls/ServerRpcSender.cs @@ -9,8 +9,9 @@ namespace Mirage.RemoteCalls /// public static class ServerRpcSender { - public static void Send(NetworkBehaviour behaviour, int index, NetworkWriter writer, Channel channelId, bool requireAuthority) + public static void Send(NetworkBehaviour behaviour, int relativeIndex, NetworkWriter writer, Channel channelId, bool requireAuthority) { + var index = behaviour.Identity.RemoteCallCollection.GetIndexOffset(behaviour) + relativeIndex; Validate(behaviour, index, requireAuthority); var message = new ServerRpcMessage @@ -23,8 +24,9 @@ public static void Send(NetworkBehaviour behaviour, int index, NetworkWriter wri behaviour.Client.Send(message, channelId); } - public static UniTask SendWithReturn(NetworkBehaviour behaviour, int index, NetworkWriter writer, Channel channelId, bool requireAuthority) + public static UniTask SendWithReturn(NetworkBehaviour behaviour, int relativeIndex, NetworkWriter writer, Channel channelId, bool requireAuthority) { + var index = behaviour.Identity.RemoteCallCollection.GetIndexOffset(behaviour) + relativeIndex; Validate(behaviour, index, requireAuthority); var message = new ServerRpcWithReplyMessage {