From a35ed9df2238e282309b3b3f4b5aa026185d5ba4 Mon Sep 17 00:00:00 2001 From: James Frowen Date: Tue, 12 Mar 2024 14:52:50 +0000 Subject: [PATCH] feat: adding excludeHost to ClientRpc can be used to avoid rpc being invoked locally on host --- Assets/Mirage/Runtime/CustomAttributes.cs | 2 ++ Assets/Mirage/Weaver/Processors/ClientRpcProcessor.cs | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Assets/Mirage/Runtime/CustomAttributes.cs b/Assets/Mirage/Runtime/CustomAttributes.cs index 58937d384f..c3942bc32b 100644 --- a/Assets/Mirage/Runtime/CustomAttributes.cs +++ b/Assets/Mirage/Runtime/CustomAttributes.cs @@ -114,6 +114,8 @@ public class ClientRpcAttribute : Attribute public Channel channel = Channel.Reliable; public RpcTarget target = RpcTarget.Observers; public bool excludeOwner; + /// stops method being called on host/server + public bool excludeHost; } /// diff --git a/Assets/Mirage/Weaver/Processors/ClientRpcProcessor.cs b/Assets/Mirage/Weaver/Processors/ClientRpcProcessor.cs index f53f6c4006..3af8bbcade 100644 --- a/Assets/Mirage/Weaver/Processors/ClientRpcProcessor.cs +++ b/Assets/Mirage/Weaver/Processors/ClientRpcProcessor.cs @@ -80,6 +80,7 @@ private MethodDefinition GenerateStub(MethodDefinition md, CustomAttribute clien var target = clientRpcAttr.GetField(nameof(ClientRpcAttribute.target), RpcTarget.Observers); var channel = clientRpcAttr.GetField(nameof(ClientRpcAttribute.channel), 0); var excludeOwner = clientRpcAttr.GetField(nameof(ClientRpcAttribute.excludeOwner), false); + var excludeHost = clientRpcAttr.GetField(nameof(ClientRpcAttribute.excludeHost), false); var rpc = SubstituteMethod(md); @@ -89,7 +90,8 @@ private MethodDefinition GenerateStub(MethodDefinition md, CustomAttribute clien // { // call the body // } - CallBody(worker, rpc, target, excludeOwner); + if (!excludeHost) + CallBody(worker, rpc, target, excludeOwner); // NetworkWriter writer = NetworkWriterPool.GetWriter() var writer = md.AddLocal();