Example #1
0
            public static bool Prefix(GameStartManager __instance)
            {
                // Block game start if not everyone has the same mod version
                bool continueStart = true;

                if (AmongUsClient.Instance.AmHost)
                {
                    foreach (InnerNet.ClientData client in AmongUsClient.Instance.allClients)
                    {
                        if (client.Character == null)
                        {
                            continue;
                        }
                        var dummyComponent = client.Character.GetComponent <DummyBehaviour>();
                        if (dummyComponent != null && dummyComponent.enabled)
                        {
                            continue;
                        }

                        if (!playerVersions.ContainsKey(client.Id))
                        {
                            continueStart = false;
                            break;
                        }

                        PlayerVersion PV   = playerVersions[client.Id];
                        int           diff = TheOtherRolesPlugin.Version.CompareTo(PV.version);
                        if (diff != 0 || !PV.GuidMatches())
                        {
                            continueStart = false;
                            break;
                        }
                    }

                    if (CustomOptionHolder.uselessOptions.getBool() && CustomOptionHolder.dynamicMap.getBool() && continueStart)
                    {
                        // 0 = Skeld
                        // 1 = Mira HQ
                        // 2 = Polus
                        // 3 = Dleks - deactivated
                        // 4 = Airship
                        List <byte> possibleMaps = new List <byte>();
                        if (CustomOptionHolder.dynamicMapEnableSkeld.getBool())
                        {
                            possibleMaps.Add(0);
                        }
                        if (CustomOptionHolder.dynamicMapEnableMira.getBool())
                        {
                            possibleMaps.Add(1);
                        }
                        if (CustomOptionHolder.dynamicMapEnablePolus.getBool())
                        {
                            possibleMaps.Add(2);
                        }
                        // if (CustomOptionHolder.dynamicMapEnableDleks.getBool())
                        //     possibleMaps.Add(3);
                        if (CustomOptionHolder.dynamicMapEnableAirShip.getBool())
                        {
                            possibleMaps.Add(4);
                        }
                        if (CustomOptionHolder.dynamicMapEnableSubmerged.getBool())
                        {
                            possibleMaps.Add(5);
                        }
                        byte chosenMapId = possibleMaps[TheOtherRoles.rnd.Next(possibleMaps.Count)];

                        MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte)CustomRPC.DynamicMapOption, Hazel.SendOption.Reliable, -1);
                        writer.Write(chosenMapId);
                        AmongUsClient.Instance.FinishRpcImmediately(writer);
                        RPCProcedure.dynamicMapOption(chosenMapId);
                    }
                }
                return(continueStart);
            }