RpcLocalHandling

This commit is contained in:
js6pak committed 2021-01-19 17:06:01 +01:00
1 parent 96a1b3ec47
commit 2a25c84167
3 files changed
+19 -7

No files matched your search

+1 -1
View File
@@ -19,7 +19,7 @@ namespace Reactor.Example
}
}
public override bool ShouldHandleLocally => true;
public override RpcLocalHandling LocalHandling => RpcLocalHandling.Before;
public override void Write(MessageWriter writer, Data data)
{
+15 -3
View File
@@ -9,6 +9,13 @@ using Hazel;
namespace Reactor
{
public enum RpcLocalHandling
{
None,
Before,
After
}
public abstract class UnsafeCustomRpc
{
public int? Id { get; internal set; }
@@ -18,7 +25,7 @@ namespace Reactor
public abstract Type InnerNetObjectType { get; }
public abstract bool ShouldHandleLocally { get; }
public abstract RpcLocalHandling LocalHandling { get; }
protected UnsafeCustomRpc(BasePlugin plugin)
{
@@ -106,7 +113,7 @@ namespace Reactor
throw new InvalidOperationException("Can't send unregistered CustomRpc");
}
if (customRpc.ShouldHandleLocally)
if (customRpc.LocalHandling == RpcLocalHandling.Before)
{
customRpc.UnsafeHandle(netObject, data);
}
@@ -118,7 +125,7 @@ namespace Reactor
};
writer.Write(customRpc.PluginId);
writer.Write(customRpc.Id.Value);
writer.Write(customRpc.Id!.Value);
customRpc.UnsafeWrite(writer, data);
if (immediately)
@@ -129,6 +136,11 @@ namespace Reactor
{
writer.EndMessage();
}
if (customRpc.LocalHandling == RpcLocalHandling.After)
{
customRpc.UnsafeHandle(netObject, data);
}
}
[HarmonyPatch]
+3 -3
View File
@@ -64,10 +64,10 @@ namespace Reactor.Patches
handshake.WritePacked(plugins.Count);
foreach (var plugin in plugins)
foreach (var (pluginId, plugin) in plugins)
{
handshake.Write(plugin.Key);
handshake.Write(plugin.Value.Metadata.Version.ToString());
handshake.Write(pluginId);
handshake.Write(plugin.Metadata.Version.ToString());
}
__result = handshake.ToByteArray(false);