diff --git a/Reactor/Networking/Attributes/MethodRpcAttribute.cs b/Reactor/Networking/Attributes/MethodRpcAttribute.cs index bd5dc8a..5819752 100644 --- a/Reactor/Networking/Attributes/MethodRpcAttribute.cs +++ b/Reactor/Networking/Attributes/MethodRpcAttribute.cs @@ -33,6 +33,12 @@ public sealed class MethodRpcAttribute : Attribute /// public RpcLocalHandling LocalHandling { get; set; } = RpcLocalHandling.Before; + /// + /// Gets or sets a value indicating whether the rpc should be sent immediately. + /// + [Obsolete("Non-immediate RPCs were removed in 2025.5.20. All RPCs are immediate. This property will be removed in a future version.")] + public bool SendImmediately { get; set; } + /// /// Initializes a new instance of the class. /// @@ -66,7 +72,7 @@ public sealed class MethodRpcAttribute : Attribute try { - var customRpc = new MethodRpc(plugin, method, attribute.Id, attribute.SendOption, attribute.LocalHandling); + var customRpc = new MethodRpc(plugin, method, attribute.Id, attribute.SendOption, attribute.LocalHandling, attribute.SendImmediately); PluginSingleton.Instance.CustomRpcManager.Register(customRpc); } catch (Exception e) diff --git a/Reactor/Networking/Rpc/CustomRpc.cs b/Reactor/Networking/Rpc/CustomRpc.cs index 38aac99..fe161eb 100644 --- a/Reactor/Networking/Rpc/CustomRpc.cs +++ b/Reactor/Networking/Rpc/CustomRpc.cs @@ -56,10 +56,11 @@ public abstract class CustomRpc : UnsafeCustomR /// /// The to send the rpc on. /// The data to send. + /// Whether to send it immediately. /// The callback to invoke when this packet is acknowledged. - public void Send(InnerNetObject innerNetObject, TData data, Action? ackCallback = null) + public void Send(InnerNetObject innerNetObject, TData data, bool immediately = false, Action? ackCallback = null) { - UnsafeSend(innerNetObject, data, ackCallback: ackCallback); + UnsafeSend(innerNetObject, data, immediately, ackCallback: ackCallback); } /// @@ -71,7 +72,7 @@ public abstract class CustomRpc : UnsafeCustomR /// The callback to invoke when this packet is acknowledged. public void SendTo(InnerNetObject innerNetObject, int targetClientId, TData data, Action? ackCallback = null) { - UnsafeSend(innerNetObject, data, targetClientId, ackCallback); + UnsafeSend(innerNetObject, data, true, targetClientId, ackCallback); } } @@ -120,10 +121,11 @@ public abstract class CustomRpc : UnsafeCustomRpc wher /// Sends this custom rpc on the specified . /// /// The to send the rpc on. + /// Whether to send it immediately. /// The callback to invoke when this packet is acknowledged. - public void Send(InnerNetObject innerNetObject, Action? ackCallback = null) + public void Send(InnerNetObject innerNetObject, bool immediately = false, Action? ackCallback = null) { - UnsafeSend(innerNetObject, ackCallback); + UnsafeSend(innerNetObject, immediately, ackCallback: ackCallback); } /// @@ -134,6 +136,6 @@ public abstract class CustomRpc : UnsafeCustomRpc wher /// The callback to invoke when this packet is acknowledged. public void SendTo(InnerNetObject innerNetObject, int targetClientId, Action? ackCallback = null) { - UnsafeSend(innerNetObject, null, targetClientId, ackCallback); + UnsafeSend(innerNetObject, null, true, targetClientId, ackCallback); } } diff --git a/Reactor/Networking/Rpc/MethodRpc.cs b/Reactor/Networking/Rpc/MethodRpc.cs index 3f1bd61..dbf66f7 100644 --- a/Reactor/Networking/Rpc/MethodRpc.cs +++ b/Reactor/Networking/Rpc/MethodRpc.cs @@ -32,11 +32,13 @@ public class MethodRpc : UnsafeCustomRpc /// The id of the rpc. /// The send option of the rpc. /// The local handling method of the rpc. - public MethodRpc(BasePlugin plugin, MethodInfo method, uint id, SendOption option, RpcLocalHandling localHandling) : base(plugin, id) + /// The value indicating whether the rpc should be sent immediately. + public MethodRpc(BasePlugin plugin, MethodInfo method, uint id, SendOption option, RpcLocalHandling localHandling, bool sendImmediately) : base(plugin, id) { Method = method; LocalHandling = localHandling; SendOption = option; + SendImmediately = sendImmediately; var parameters = method.GetParameters(); @@ -86,6 +88,12 @@ public class MethodRpc : UnsafeCustomRpc /// public override SendOption SendOption { get; } + /// + /// Gets a value indicating whether the method rpc should be sent immediately. + /// + [Obsolete("Non-immediate RPCs were removed in 2025.5.20. All RPCs are immediate. This property will be removed in a future version.")] + public bool SendImmediately { get; } + /// public override void UnsafeWrite(MessageWriter writer, object? data) { @@ -127,7 +135,7 @@ public class MethodRpc : UnsafeCustomRpc /// The arguments to serialize and send. public void Send(InnerNetObject innerNetObject, object[] args) { - UnsafeSend(innerNetObject, args); + UnsafeSend(innerNetObject, args, SendImmediately); } private static readonly MethodInfo _sendMethod = AccessTools.Method(typeof(MethodRpc), nameof(Send)); diff --git a/Reactor/Networking/Rpc/PlayerCustomRpc.cs b/Reactor/Networking/Rpc/PlayerCustomRpc.cs index 77b2684..47c9d8a 100644 --- a/Reactor/Networking/Rpc/PlayerCustomRpc.cs +++ b/Reactor/Networking/Rpc/PlayerCustomRpc.cs @@ -19,10 +19,11 @@ public abstract class PlayerCustomRpc : CustomRpc. /// /// The data to send. + /// Whether to send it immediately. /// The callback to invoke when this packet is acknowledged. - public void Send(TData data, Action? ackCallback = null) + public void Send(TData data, bool immediately = false, Action? ackCallback = null) { - Send(PlayerControl.LocalPlayer, data, ackCallback); + Send(PlayerControl.LocalPlayer, data, immediately, ackCallback); } /// @@ -51,10 +52,11 @@ public abstract class PlayerCustomRpc : CustomRpc /// Sends this custom rpc on the local player. /// + /// Whether to send it immediately. /// The callback to invoke when this packet is acknowledged. - public void Send(Action? ackCallback = null) + public void Send(bool immediately = false, Action? ackCallback = null) { - Send(PlayerControl.LocalPlayer, ackCallback); + Send(PlayerControl.LocalPlayer, immediately, ackCallback); } /// diff --git a/Reactor/Networking/Rpc/UnsafeCustomRpc.cs b/Reactor/Networking/Rpc/UnsafeCustomRpc.cs index 3a7d65a..67fefb4 100644 --- a/Reactor/Networking/Rpc/UnsafeCustomRpc.cs +++ b/Reactor/Networking/Rpc/UnsafeCustomRpc.cs @@ -91,9 +91,10 @@ public abstract class UnsafeCustomRpc /// /// The to send the rpc on. /// The data to send. + /// Whether to send it immediately. /// Target client id, defaults to broadcast. /// The callback to invoke when this packet is acknowledged. - public void UnsafeSend(InnerNetObject innerNetObject, object? data, int targetClientId = -1, Action? ackCallback = null) + public void UnsafeSend(InnerNetObject innerNetObject, object? data, bool immediately = false, int targetClientId = -1, Action? ackCallback = null) { ArgumentNullException.ThrowIfNull(innerNetObject); @@ -107,7 +108,16 @@ public abstract class UnsafeCustomRpc UnsafeHandle(innerNetObject, data); } - var writer = AmongUsClient.Instance.StartRpcImmediately(innerNetObject.NetId, CustomRpcManager.CallId, SendOption, targetClientId); + if (immediately == false) + { + Warning("Non-immediate RPCs were removed in 2025.5.20! Reactor will now always send immediately!"); + } + + var writer = AmongUsClient.Instance.StartRpcImmediately( + innerNetObject.NetId, + CustomRpcManager.CallId, + SendOption, + targetClientId); writer.Write(Mod); writer.WritePacked(Id);