mirror of
https://github.com/NuclearPowered/Reactor.git
synced 2026-10-19 15:51:54 +00:00
Revert API changes and add Obsolete attribute to SendImmediate
This commit is contained in:
1 parent
3229475361
commit
c58ccc1643
5 files changed
+43
-15
No files matched your search
@@ -33,6 +33,12 @@ public sealed class MethodRpcAttribute : Attribute
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public RpcLocalHandling LocalHandling { get; set; } = RpcLocalHandling.Before;
|
public RpcLocalHandling LocalHandling { get; set; } = RpcLocalHandling.Before;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets a value indicating whether the rpc should be sent immediately.
|
||||||
|
/// </summary>
|
||||||
|
[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; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="MethodRpcAttribute"/> class.
|
/// Initializes a new instance of the <see cref="MethodRpcAttribute"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -66,7 +72,7 @@ public sealed class MethodRpcAttribute : Attribute
|
|||||||
|
|
||||||
try
|
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<ReactorPlugin>.Instance.CustomRpcManager.Register(customRpc);
|
PluginSingleton<ReactorPlugin>.Instance.CustomRpcManager.Register(customRpc);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
|||||||
@@ -56,10 +56,11 @@ public abstract class CustomRpc<TPlugin, TInnerNetObject, TData> : UnsafeCustomR
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="innerNetObject">The <see cref="InnerNetObject"/> to send the rpc on.</param>
|
/// <param name="innerNetObject">The <see cref="InnerNetObject"/> to send the rpc on.</param>
|
||||||
/// <param name="data">The data to send.</param>
|
/// <param name="data">The data to send.</param>
|
||||||
|
/// <param name="immediately">Whether to send it immediately.</param>
|
||||||
/// <param name="ackCallback">The callback to invoke when this packet is acknowledged.</param>
|
/// <param name="ackCallback">The callback to invoke when this packet is acknowledged.</param>
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -71,7 +72,7 @@ public abstract class CustomRpc<TPlugin, TInnerNetObject, TData> : UnsafeCustomR
|
|||||||
/// <param name="ackCallback">The callback to invoke when this packet is acknowledged.</param>
|
/// <param name="ackCallback">The callback to invoke when this packet is acknowledged.</param>
|
||||||
public void SendTo(InnerNetObject innerNetObject, int targetClientId, TData data, Action? ackCallback = null)
|
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<TPlugin, TInnerNetObject> : UnsafeCustomRpc wher
|
|||||||
/// Sends this custom rpc on the specified <paramref name="innerNetObject"/>.
|
/// Sends this custom rpc on the specified <paramref name="innerNetObject"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="innerNetObject">The <see cref="InnerNetObject"/> to send the rpc on.</param>
|
/// <param name="innerNetObject">The <see cref="InnerNetObject"/> to send the rpc on.</param>
|
||||||
|
/// <param name="immediately">Whether to send it immediately.</param>
|
||||||
/// <param name="ackCallback">The callback to invoke when this packet is acknowledged.</param>
|
/// <param name="ackCallback">The callback to invoke when this packet is acknowledged.</param>
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -134,6 +136,6 @@ public abstract class CustomRpc<TPlugin, TInnerNetObject> : UnsafeCustomRpc wher
|
|||||||
/// <param name="ackCallback">The callback to invoke when this packet is acknowledged.</param>
|
/// <param name="ackCallback">The callback to invoke when this packet is acknowledged.</param>
|
||||||
public void SendTo(InnerNetObject innerNetObject, int targetClientId, Action? ackCallback = null)
|
public void SendTo(InnerNetObject innerNetObject, int targetClientId, Action? ackCallback = null)
|
||||||
{
|
{
|
||||||
UnsafeSend(innerNetObject, null, targetClientId, ackCallback);
|
UnsafeSend(innerNetObject, null, true, targetClientId, ackCallback);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -32,11 +32,13 @@ public class MethodRpc : UnsafeCustomRpc
|
|||||||
/// <param name="id">The id of the rpc.</param>
|
/// <param name="id">The id of the rpc.</param>
|
||||||
/// <param name="option">The send option of the rpc.</param>
|
/// <param name="option">The send option of the rpc.</param>
|
||||||
/// <param name="localHandling">The local handling method of the rpc.</param>
|
/// <param name="localHandling">The local handling method of the rpc.</param>
|
||||||
public MethodRpc(BasePlugin plugin, MethodInfo method, uint id, SendOption option, RpcLocalHandling localHandling) : base(plugin, id)
|
/// <param name="sendImmediately">The value indicating whether the rpc should be sent immediately.</param>
|
||||||
|
public MethodRpc(BasePlugin plugin, MethodInfo method, uint id, SendOption option, RpcLocalHandling localHandling, bool sendImmediately) : base(plugin, id)
|
||||||
{
|
{
|
||||||
Method = method;
|
Method = method;
|
||||||
LocalHandling = localHandling;
|
LocalHandling = localHandling;
|
||||||
SendOption = option;
|
SendOption = option;
|
||||||
|
SendImmediately = sendImmediately;
|
||||||
|
|
||||||
var parameters = method.GetParameters();
|
var parameters = method.GetParameters();
|
||||||
|
|
||||||
@@ -86,6 +88,12 @@ public class MethodRpc : UnsafeCustomRpc
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override SendOption SendOption { get; }
|
public override SendOption SendOption { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a value indicating whether the method rpc should be sent immediately.
|
||||||
|
/// </summary>
|
||||||
|
[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; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override void UnsafeWrite(MessageWriter writer, object? data)
|
public override void UnsafeWrite(MessageWriter writer, object? data)
|
||||||
{
|
{
|
||||||
@@ -127,7 +135,7 @@ public class MethodRpc : UnsafeCustomRpc
|
|||||||
/// <param name="args">The arguments to serialize and send.</param>
|
/// <param name="args">The arguments to serialize and send.</param>
|
||||||
public void Send(InnerNetObject innerNetObject, object[] args)
|
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));
|
private static readonly MethodInfo _sendMethod = AccessTools.Method(typeof(MethodRpc), nameof(Send));
|
||||||
|
|||||||
@@ -19,10 +19,11 @@ public abstract class PlayerCustomRpc<TPlugin, TData> : CustomRpc<TPlugin, Playe
|
|||||||
/// Sends this custom rpc on the local player with the specified <paramref name="data"/>.
|
/// Sends this custom rpc on the local player with the specified <paramref name="data"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="data">The data to send.</param>
|
/// <param name="data">The data to send.</param>
|
||||||
|
/// <param name="immediately">Whether to send it immediately.</param>
|
||||||
/// <param name="ackCallback">The callback to invoke when this packet is acknowledged.</param>
|
/// <param name="ackCallback">The callback to invoke when this packet is acknowledged.</param>
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -51,10 +52,11 @@ public abstract class PlayerCustomRpc<TPlugin> : CustomRpc<TPlugin, PlayerContro
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sends this custom rpc on the local player.
|
/// Sends this custom rpc on the local player.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <param name="immediately">Whether to send it immediately.</param>
|
||||||
/// <param name="ackCallback">The callback to invoke when this packet is acknowledged.</param>
|
/// <param name="ackCallback">The callback to invoke when this packet is acknowledged.</param>
|
||||||
public void Send(Action? ackCallback = null)
|
public void Send(bool immediately = false, Action? ackCallback = null)
|
||||||
{
|
{
|
||||||
Send(PlayerControl.LocalPlayer, ackCallback);
|
Send(PlayerControl.LocalPlayer, immediately, ackCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -91,9 +91,10 @@ public abstract class UnsafeCustomRpc
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="innerNetObject">The <see cref="InnerNetObject"/> to send the rpc on.</param>
|
/// <param name="innerNetObject">The <see cref="InnerNetObject"/> to send the rpc on.</param>
|
||||||
/// <param name="data">The data to send.</param>
|
/// <param name="data">The data to send.</param>
|
||||||
|
/// <param name="immediately">Whether to send it immediately.</param>
|
||||||
/// <param name="targetClientId">Target client id, defaults to broadcast.</param>
|
/// <param name="targetClientId">Target client id, defaults to broadcast.</param>
|
||||||
/// <param name="ackCallback">The callback to invoke when this packet is acknowledged.</param>
|
/// <param name="ackCallback">The callback to invoke when this packet is acknowledged.</param>
|
||||||
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);
|
ArgumentNullException.ThrowIfNull(innerNetObject);
|
||||||
|
|
||||||
@@ -107,7 +108,16 @@ public abstract class UnsafeCustomRpc
|
|||||||
UnsafeHandle(innerNetObject, data);
|
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.Write(Mod);
|
||||||
writer.WritePacked(Id);
|
writer.WritePacked(Id);
|
||||||
|
|||||||
Reference in new issue
Block a user