public UnsafeCustomRpc Register(UnsafeCustomRpc customRpc) { customRpc.Id = List.Count(x => x.UnsafePlugin == customRpc.UnsafePlugin); _list.Add(customRpc); _map[customRpc.InnerNetObjectType].Add(customRpc); return(customRpc); }
public void UnsafeSend(InnerNetObject netObject, UnsafeCustomRpc customRpc, object data, bool immediately = false, int targetClientId = -1) { if (netObject == null) { throw new ArgumentNullException(nameof(netObject)); } if (customRpc == null) { throw new ArgumentNullException(nameof(customRpc)); } if (data == null) { throw new ArgumentNullException(nameof(data)); } if (customRpc.Id == null) { throw new InvalidOperationException("Can't send unregistered CustomRpc"); } if (customRpc.LocalHandling == RpcLocalHandling.Before) { customRpc.UnsafeHandle(netObject, data); } var writer = immediately switch { false => AmongUsClient.Instance.StartRpc(netObject.NetId, CallId, SendOption.Reliable), true => AmongUsClient.Instance.StartRpcImmediately(netObject.NetId, CallId, SendOption.Reliable, targetClientId) }; if (PluginIdMap.TryGetValue(customRpc.PluginId, out var pluginId)) { writer.WritePacked(pluginId); } else { writer.Write(customRpc.PluginId); } writer.WritePacked(customRpc.Id !.Value); customRpc.UnsafeWrite(writer, data); if (immediately) { AmongUsClient.Instance.FinishRpcImmediately(writer); } else { writer.EndMessage(); } if (customRpc.LocalHandling == RpcLocalHandling.After) { customRpc.UnsafeHandle(netObject, data); } }
public UnsafeCustomRpc Register(UnsafeCustomRpc customRpc) { customRpc.Manager = this; customRpc.Id = List.Count(x => x.UnsafePlugin == customRpc.UnsafePlugin); _list.Add(customRpc); _map[customRpc.InnerNetObjectType].Add(customRpc); typeof(Rpc <>).MakeGenericType(customRpc.GetType()).GetProperty("Instance") !.SetValue(null, customRpc); return(customRpc); }