Add an Example

This commit is contained in:
Zirno authored and js6pak committed 2021-07-26 17:07:57 +02:00
1 parent eb7fce3350
commit 63fdde22c6
5 files changed
+23 -8

No files matched your search

+2 -1
View File
@@ -2,6 +2,7 @@ namespace Reactor.Example
{
public enum CustomRpcCalls : uint
{
Example
Example,
MethodRpcExample
}
}
+12
View File
@@ -3,6 +3,7 @@ using BepInEx;
using BepInEx.IL2CPP;
using Reactor.Extensions;
using Reactor.Networking;
using Reactor.Networking.MethodRpc;
using UnhollowerBaseLib.Attributes;
using UnityEngine;
@@ -43,7 +44,18 @@ namespace Reactor.Example
Rpc<ExampleRpc>.Instance.SendTo(AmongUsClient.Instance.HostId, new ExampleRpc.Data($"SendTo: from {name} to host"));
}
}
if (Input.GetKeyDown(KeyCode.F4) && AmongUsClient.Instance && PlayerControl.LocalPlayer)
{
RpcSay(PlayerControl.LocalPlayer, "Hello from method rpc");
}
}
}
[MethodRpc((uint) CustomRpcCalls.MethodRpcExample)]
public static void RpcSay(PlayerControl sender, string text)
{
Logger<ExamplePlugin>.Info($"{sender.Data.PlayerName} said: {text}");
}
}
}
@@ -11,11 +11,11 @@ namespace Reactor.Networking.MethodRpc
[AttributeUsage(AttributeTargets.Method)]
public class MethodRpcAttribute : Attribute
{
public byte id;
public uint id;
public SendOption option;
public RpcLocalHandling localHandling;
public MethodRpcAttribute( byte id, SendOption option = SendOption.Reliable, RpcLocalHandling localHandling = RpcLocalHandling.Before)
public MethodRpcAttribute( uint id, SendOption option = SendOption.Reliable, RpcLocalHandling localHandling = RpcLocalHandling.Before)
{
this.id = id;
this.option = option;
@@ -28,9 +28,13 @@ namespace Reactor.Networking
return true;
}
CustomMethodRpc methodRpc =
CustomMethodRpc.AllCustomMethodRpcs.FirstOrDefault(x => x.Method == originalMethod);
typeof(CustomMethodRpc).GetMethod(nameof(CustomMethodRpc.Send))?.Invoke(methodRpc,new object[]{list});
UnsafeCustomRpc methodRpc =
PluginSingleton<ReactorPlugin>.Instance.CustomRpcManager.List.FirstOrDefault(x => x is CustomMethodRpc && (x as CustomMethodRpc).Method == originalMethod);
if (methodRpc != null)
{
typeof(CustomMethodRpc).GetMethod(nameof(CustomMethodRpc.Send))?.Invoke((CustomMethodRpc)methodRpc, new object[] {list});
}
return false;
}
@@ -3,9 +3,7 @@ using System.Collections.Generic;
using System.Reflection;
using Hazel;
using InnerNet;
using Reactor;
using Reactor.Extensions;
using Reactor.Networking.MethodRpc;
using UnityEngine;
namespace Reactor.Networking