Esempio n. 1
0
        public static void Init()
        {
            collectThread = new Thread(PacketCollectionThread);
            collectThread.Start();

            RPCSerializer.Init();

            CustomRPC.DocAllRPCAttributes();
        }
Esempio n. 2
0
        private void Awake()
        {
            CommandManager.Instance.AddConsoleCommand(new BlockingRPCCommand());

            BlockingRPC = NetworkManager.Instance.AddRPC(
                "blocking", BlockingRPC_OnServerReceive, BlockingRPC_OnClientReceive);

            CommandManager.Instance.AddConsoleCommand(new NonblockingRPCommand());

            NonblockingRPC = NetworkManager.Instance.AddRPC(
                "nonblocking", NonblockingRPC_OnServerReceive, NonblockingRPC_OnClientReceive1);
        }
Esempio n. 3
0
        /// <summary>
        ///     Get the <see cref="CustomRPC"/> for a given mod.
        /// </summary>
        /// <param name="sourceMod">Reference to the <see cref="BepInPlugin"/> which added this entity</param>
        /// <param name="name">Unique name for your RPC</param>
        /// <param name="serverReceive">Delegate which gets called on client instances when packages are received</param>
        /// <param name="clientReceive">Delegate which gets called on server instances when packages are received</param>
        /// <returns>Existing or newly created <see cref="CustomRPC"/>.</returns>
        internal CustomRPC AddRPC(BepInPlugin sourceMod, string name, CoroutineHandler serverReceive, CoroutineHandler clientReceive)
        {
            var ret = RPCs.FirstOrDefault(x => x.SourceMod == sourceMod && x.Name == name);

            if (ret != null)
            {
                return(ret);
            }

            ret = new CustomRPC(sourceMod, name, serverReceive, clientReceive);
            RPCs.Add(ret);
            return(ret);
        }
Esempio n. 4
0
        public static void Gen(Type T, List <PlayerControl> crewmates, CustomRPC rpc)
        {
            //System.Console.WriteLine(nameof(rpc));
            //System.Console.WriteLine(crewmates.Count);
            if (crewmates.Count <= 0)
            {
                return;
            }
            var rand = UnityEngine.Random.RandomRangeInt(0, crewmates.Count);
            //var rand = 0;
            var pc = crewmates[rand];

            var role     = Activator.CreateInstance(T, new object[] { pc });
            var playerId = pc.PlayerId;

            crewmates.Remove(pc);

            var writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte)rpc,
                                                                    SendOption.Reliable, -1);

            writer.Write(playerId);
            AmongUsClient.Instance.FinishRpcImmediately(writer);
        }
Esempio n. 5
0
        /// <summary>
        ///     Manager's main init
        /// </summary>
        public void Init()
        {
            // Register RPCs and the admin watchdog
            ConfigRPC = NetworkManager.Instance.AddRPC(
                Main.Instance.Info.Metadata, "ConfigSync", ConfigRPC_OnServerReceive, ConfigRPC_OnClientReceive);

            AdminRPC = NetworkManager.Instance.AddRPC(
                Main.Instance.Info.Metadata, "AdminStatus", null, AdminRPC_OnClientReceive);

            Main.Harmony.PatchAll(typeof(Patches));

            // Hook start scene to reset config
            SceneManager.sceneLoaded += SceneManager_sceneLoaded;

            // Find Configuration manager plugin and add to DisplayingWindowChanged event
            if (!ConfigurationManager)
            {
                Logger.LogDebug("Trying to hook config manager");

                ConfigurationManager = Object.FindObjectsOfType(typeof(BaseUnityPlugin)).Cast <BaseUnityPlugin>().ToArray()
                                       .FirstOrDefault(x => x.Info?.Metadata?.GUID == "com.bepis.bepinex.configurationmanager");

                if (ConfigurationManager)
                {
                    Logger.LogDebug("Configuration manager found, trying to hook DisplayingWindowChanged");
                    var eventinfo = ConfigurationManager.GetType().GetEvent("DisplayingWindowChanged");
                    if (eventinfo != null)
                    {
                        Action <object, object> local = ConfigurationManager_DisplayingWindowChanged;
                        var converted = Delegate.CreateDelegate(eventinfo.EventHandlerType, local.Target, local.Method);

                        eventinfo.AddEventHandler(ConfigurationManager, converted);
                    }
                }
            }
        }
Esempio n. 6
0
 public static void Send(CustomRPC CustomRPC)
 {
     Network.Send((byte)CustomRPC);
 }
Esempio n. 7
0
 public static void Send(CustomRPC CustomRPC, Action <MessageWriter> WriteData)
 {
     Network.Send((byte)CustomRPC, WriteData);
 }