Esempio n. 1
0
        public static bool Prefix(KillButtonManager __instance)
        {
            if (!PlayerControl.LocalPlayer.Is(RoleEnum.Covert))
            {
                return(true);
            }

            if (
                !PlayerControl.LocalPlayer.CanMove ||
                PlayerControl.LocalPlayer.Data.IsDead
                )
            {
                return(false);
            }

            Covert role = Role.GetRole <Covert>(PlayerControl.LocalPlayer);

            if (__instance != role.CovertButton)
            {
                return(true);
            }

            if (
                __instance.isCoolingDown ||
                !__instance.isActiveAndEnabled ||
                role.CooldownTimer() != 0
                )
            {
                return(false);
            }

            MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId,
                                                                              (byte)CustomRPC.GoCovert, SendOption.Reliable, -1);

            writer.Write(PlayerControl.LocalPlayer.PlayerId);
            AmongUsClient.Instance.FinishRpcImmediately(writer);

            role.GoCovert();
            return(false);
        }
Esempio n. 2
0
            public static void Postfix([HarmonyArgument(0)] byte callId, [HarmonyArgument(1)] MessageReader reader)
            {
                //if (callId >= 43) //System.Console.WriteLine("Received " + callId);
                byte  readByte, readByte1, readByte2;
                sbyte readSByte, readSByte2;

                switch ((CustomRPC)callId)
                {
                case CustomRPC.SetMayor:
                    readByte = reader.ReadByte();
                    new Mayor(Utils.PlayerById(readByte));
                    break;

                case CustomRPC.SetJester:
                    readByte = reader.ReadByte();
                    new Jester(Utils.PlayerById(readByte));
                    break;

                case CustomRPC.SetSheriff:
                    readByte = reader.ReadByte();
                    new Sheriff(Utils.PlayerById(readByte));
                    break;

                case CustomRPC.SetEngineer:
                    readByte = reader.ReadByte();
                    new Engineer(Utils.PlayerById(readByte));
                    break;


                case CustomRPC.SetJanitor:
                    new Janitor(Utils.PlayerById(reader.ReadByte()));

                    break;

                case CustomRPC.SetSwapper:
                    readByte = reader.ReadByte();
                    new Swapper(Utils.PlayerById(readByte));
                    break;

                case CustomRPC.SetShifter:
                    readByte = reader.ReadByte();
                    new Shifter(Utils.PlayerById(readByte));
                    break;

                case CustomRPC.SetInvestigator:
                    readByte = reader.ReadByte();
                    new Investigator(Utils.PlayerById(readByte));
                    break;

                case CustomRPC.SetTimeLord:
                    readByte = reader.ReadByte();
                    new TimeLord(Utils.PlayerById(readByte));
                    break;

                case CustomRPC.SetTorch:
                    readByte = reader.ReadByte();
                    new Torch(Utils.PlayerById(readByte));
                    break;

                case CustomRPC.SetDiseased:
                    readByte = reader.ReadByte();
                    new Diseased(Utils.PlayerById(readByte));
                    break;

                case CustomRPC.SetFlash:
                    readByte = reader.ReadByte();
                    new Flash(Utils.PlayerById(readByte));
                    break;

                case CustomRPC.SetMedic:
                    readByte = reader.ReadByte();
                    new Medic(Utils.PlayerById(readByte));
                    break;

                case CustomRPC.SetMorphling:
                    readByte = reader.ReadByte();
                    new Morphling(Utils.PlayerById(readByte));
                    break;

                case CustomRPC.LoveWin:
                    var winnerlover = Utils.PlayerById(reader.ReadByte());
                    Role.GetRole <Lover>(winnerlover).Win();
                    break;


                case CustomRPC.JesterLose:
                    foreach (var role in Role.AllRoles)
                    {
                        if (role.RoleType == RoleEnum.Jester)
                        {
                            ((Jester)role).Loses();
                        }
                    }

                    break;

                case CustomRPC.PhantomLose:
                    foreach (var role in Role.AllRoles)
                    {
                        if (role.RoleType == RoleEnum.Phantom)
                        {
                            ((Phantom)role).Loses();
                        }
                    }

                    break;


                case CustomRPC.GlitchLose:
                    foreach (var role in Role.AllRoles)
                    {
                        if (role.RoleType == RoleEnum.Glitch)
                        {
                            ((Glitch)role).Loses();
                        }
                    }

                    break;

                case CustomRPC.ShifterLose:
                    foreach (var role in Role.AllRoles)
                    {
                        if (role.RoleType == RoleEnum.Shifter)
                        {
                            ((Shifter)role).Loses();
                        }
                    }

                    break;

                case CustomRPC.ExecutionerLose:
                    foreach (var role in Role.AllRoles)
                    {
                        if (role.RoleType == RoleEnum.Executioner)
                        {
                            ((Executioner)role).Loses();
                        }
                    }

                    break;

                case CustomRPC.NobodyWins:
                    Role.NobodyWinsFunc();
                    break;

                case CustomRPC.SetCouple:
                    byte id             = reader.ReadByte();
                    byte id2            = reader.ReadByte();
                    bool lovingImpostor = reader.ReadBoolean();
                    var  lover1         = Utils.PlayerById(id);
                    var  lover2         = Utils.PlayerById(id2);

                    var roleLover1 = new Lover(lover1, false, lovingImpostor);
                    var roleLover2 = new Lover(lover2, lovingImpostor, lovingImpostor);

                    roleLover1.OtherLover = roleLover2;
                    roleLover2.OtherLover = roleLover1;

                    break;

                case CustomRPC.Start:
                    Utils.ShowDeadBodies = false;
                    Murder.KilledPlayers.Clear();
                    Role.NobodyWins = false;
                    RecordRewind.points.Clear();
                    KillButtonTarget.DontRevive = byte.MaxValue;
                    break;

                case CustomRPC.JanitorClean:
                {
                    readByte1 = reader.ReadByte();
                    var janitorPlayer = Utils.PlayerById(readByte1);
                    var janitorRole   = Role.GetRole <Janitor>(janitorPlayer);
                    readByte = reader.ReadByte();
                    var deadBodies = Object.FindObjectsOfType <DeadBody>();
                    foreach (var body in deadBodies)
                    {
                        if (body.ParentId == readByte)
                        {
                            Coroutines.Start(Coroutine.CleanCoroutine(body, janitorRole));
                        }
                    }
                    break;
                }

                case CustomRPC.EngineerFix:
                    var engineer = Utils.PlayerById(reader.ReadByte());
                    Role.GetRole <Engineer>(engineer).UsedThisRound = true;
                    break;


                case CustomRPC.FixLights:
                    var lights = ShipStatus.Instance.Systems[SystemTypes.Electrical].Cast <SwitchSystem>();
                    lights.ActualSwitches = lights.ExpectedSwitches;
                    break;

                case CustomRPC.SetExtraVotes:

                    var mayor     = Utils.PlayerById(reader.ReadByte());
                    var mayorRole = Role.GetRole <Mayor>(mayor);
                    mayorRole.ExtraVotes = reader.ReadBytesAndSize().ToList();
                    if (!mayor.Is(RoleEnum.Mayor))
                    {
                        mayorRole.VoteBank -= mayorRole.ExtraVotes.Count;
                    }

                    break;

                case CustomRPC.SetSwaps:
                    readSByte       = reader.ReadSByte();
                    SwapVotes.Swap1 =
                        MeetingHud.Instance.playerStates.FirstOrDefault(x => x.TargetPlayerId == readSByte);
                    readSByte2      = reader.ReadSByte();
                    SwapVotes.Swap2 =
                        MeetingHud.Instance.playerStates.FirstOrDefault(x => x.TargetPlayerId == readSByte2);
                    PluginSingleton <TownOfUs> .Instance.Log.LogMessage("Bytes received - " + readSByte + " - " +
                                                                        readSByte2);

                    break;

                case CustomRPC.Shift:
                    readByte1 = reader.ReadByte();
                    readByte2 = reader.ReadByte();
                    var shifter = Utils.PlayerById(readByte1);
                    var other   = Utils.PlayerById(readByte2);
                    PerformKillButton.Shift(Role.GetRole <Shifter>(shifter), other);
                    break;

                case CustomRPC.Rewind:
                    readByte = reader.ReadByte();
                    var TimeLordPlayer = Utils.PlayerById(readByte);
                    var TimeLordRole   = Role.GetRole <TimeLord>(TimeLordPlayer);
                    StartStop.StartRewind(TimeLordRole);
                    break;

                case CustomRPC.Protect:
                    readByte1 = reader.ReadByte();
                    readByte2 = reader.ReadByte();

                    var medic  = Utils.PlayerById(readByte1);
                    var shield = Utils.PlayerById(readByte2);
                    Role.GetRole <Medic>(medic).ShieldedPlayer = shield;
                    Role.GetRole <Medic>(medic).UsedAbility    = true;
                    break;

                case CustomRPC.RewindRevive:
                    readByte = reader.ReadByte();
                    RecordRewind.ReviveBody(Utils.PlayerById(readByte));
                    break;

                case CustomRPC.AttemptSound:
                    var medicId = reader.ReadByte();
                    readByte = reader.ReadByte();
                    StopKill.BreakShield(medicId, readByte, CustomGameOptions.ShieldBreaks);
                    break;

                case CustomRPC.SetGlitch:
                    var GlitchId     = reader.ReadByte();
                    var GlitchPlayer = Utils.PlayerById(GlitchId);
                    new Glitch(GlitchPlayer);
                    break;

                case CustomRPC.BypassKill:
                    var killer = Utils.PlayerById(reader.ReadByte());
                    var target = Utils.PlayerById(reader.ReadByte());

                    Utils.MurderPlayer(killer, target);
                    break;

                case CustomRPC.AssassinKill:
                    var toDie = Utils.PlayerById(reader.ReadByte());
                    AssassinKill.MurderPlayer(toDie);
                    Assassin.AssassinState.RemainingKills--;
                    AddButton.MaybeHideButtons();
                    break;

                case CustomRPC.Teleport:
                    byte teleports = reader.ReadByte();
                    Dictionary <byte, Vector2> coordinates = new Dictionary <byte, Vector2>();
                    for (int i = 0; i < teleports; i++)
                    {
                        byte    playerId = reader.ReadByte();
                        Vector2 location = reader.ReadVector2();
                        coordinates.Add(playerId, location);
                    }
                    Teleporter.TeleportPlayersToCoordinates(coordinates);
                    break;

                case CustomRPC.Conceal:
                {
                    PlayerControl concealer = Utils.PlayerById(reader.ReadByte());
                    PlayerControl concealed = Utils.PlayerById(reader.ReadByte());
                    Concealer     role      = Role.GetRole <Concealer>(concealer);
                    role.StartConceal(concealed);
                    break;
                }

                case CustomRPC.GoCovert:
                {
                    PlayerControl covert = Utils.PlayerById(reader.ReadByte());
                    Covert        role   = Role.GetRole <Covert>(covert);
                    role.GoCovert();
                    break;
                }

                case CustomRPC.SetMimic:
                    var glitchPlayer = Utils.PlayerById(reader.ReadByte());
                    var mimicPlayer  = Utils.PlayerById(reader.ReadByte());
                    var glitchRole   = Role.GetRole <Glitch>(glitchPlayer);
                    glitchRole.MimicTarget  = mimicPlayer;
                    glitchRole.IsUsingMimic = true;
                    Utils.Morph(glitchPlayer, mimicPlayer);
                    break;

                case CustomRPC.RpcResetAnim:
                    var animPlayer    = Utils.PlayerById(reader.ReadByte());
                    var theGlitchRole = Role.GetRole <Glitch>(animPlayer);
                    theGlitchRole.MimicTarget  = null;
                    theGlitchRole.IsUsingMimic = false;
                    Utils.Unmorph(theGlitchRole.Player);
                    break;

                case CustomRPC.GlitchWin:
                    var theGlitch = Role.AllRoles.FirstOrDefault(x => x.RoleType == RoleEnum.Glitch);
                    ((Glitch)theGlitch)?.Wins();
                    break;

                case CustomRPC.SetHacked:
                    var hackPlayer = Utils.PlayerById(reader.ReadByte());
                    if (hackPlayer.PlayerId == PlayerControl.LocalPlayer.PlayerId)
                    {
                        var glitch = Role.AllRoles.FirstOrDefault(x => x.RoleType == RoleEnum.Glitch);
                        ((Glitch)glitch)?.SetHacked(hackPlayer);
                    }

                    break;

                case CustomRPC.Investigate:
                {
                    var  seer          = Utils.PlayerById(reader.ReadByte());
                    var  otherPlayer   = Utils.PlayerById(reader.ReadByte());
                    bool successfulSee = reader.ReadByte() == 1;     // TODO: Can this be readBoolean()?
                    Seer role          = Role.GetRole <Seer>(seer);
                    role.Investigated.Add(otherPlayer.PlayerId, successfulSee);
                    role.ResetCooldownTimer();
                    break;
                }

                case CustomRPC.SetSeer:
                    new Seer(Utils.PlayerById(reader.ReadByte()));
                    break;

                case CustomRPC.Morph:
                    var morphling   = Utils.PlayerById(reader.ReadByte());
                    var morphTarget = Utils.PlayerById(reader.ReadByte());
                    var morphRole   = Role.GetRole <Morphling>(morphling);
                    morphRole.TimeRemaining = CustomGameOptions.MorphlingDuration;
                    morphRole.MorphedPlayer = morphTarget;
                    break;

                case CustomRPC.SetExecutioner:
                    new Executioner(Utils.PlayerById(reader.ReadByte()));
                    break;

                case CustomRPC.SetTarget:
                    var executioner = Utils.PlayerById(reader.ReadByte());
                    var exeTarget   = Utils.PlayerById(reader.ReadByte());
                    var exeRole     = Role.GetRole <Executioner>(executioner);
                    exeRole.target = exeTarget;
                    break;

                case CustomRPC.SetCamouflager:
                    new Camouflager(Utils.PlayerById(reader.ReadByte()));
                    break;

                case CustomRPC.Camouflage:
                    var camouflager     = Utils.PlayerById(reader.ReadByte());
                    var camouflagerRole = Role.GetRole <Camouflager>(camouflager);
                    camouflagerRole.TimeRemaining = CustomGameOptions.CamouflagerDuration;
                    Utils.Camouflage();
                    break;

                case CustomRPC.SetSpy:
                    new Spy(Utils.PlayerById(reader.ReadByte()));
                    break;

                case CustomRPC.ExecutionerToJester:
                    TargetColor.ExeToJes(Utils.PlayerById(reader.ReadByte()));
                    break;

                case CustomRPC.SetSnitch:
                    new Snitch(Utils.PlayerById(reader.ReadByte()));
                    break;

                case CustomRPC.SetMiner:
                    new Miner(Utils.PlayerById(reader.ReadByte()));
                    break;

                case CustomRPC.Mine:
                    var ventId    = reader.ReadInt32();
                    var miner     = Utils.PlayerById(reader.ReadByte());
                    var minerRole = Role.GetRole <Miner>(miner);
                    var pos       = reader.ReadVector2();
                    var zAxis     = reader.ReadSingle();
                    PerformKill.SpawnVent(ventId, minerRole, pos, zAxis);
                    break;

                case CustomRPC.SetSwooper:
                    new Swooper(Utils.PlayerById(reader.ReadByte()));
                    break;

                case CustomRPC.Swoop:
                    var swooper     = Utils.PlayerById(reader.ReadByte());
                    var swooperRole = Role.GetRole <Swooper>(swooper);
                    swooperRole.TimeRemaining = CustomGameOptions.SwoopDuration;
                    swooperRole.Swoop();
                    break;

                case CustomRPC.SetGrenadier:
                    new Grenadier(Utils.PlayerById(reader.ReadByte()));
                    break;

                case CustomRPC.FlashGrenade:
                    PlayerControl grenadier     = Utils.PlayerById(reader.ReadByte());
                    Grenadier     grenadierRole = Role.GetRole <Grenadier>(grenadier);
                    grenadierRole.TimeRemaining = CustomGameOptions.GrenadeDuration;
                    grenadierRole.Flash();
                    break;

                case CustomRPC.SetTiebreaker:
                    new Tiebreaker(Utils.PlayerById(reader.ReadByte()));
                    break;

                case CustomRPC.SetDrunk:
                    new Drunk(Utils.PlayerById(reader.ReadByte()));
                    break;

                case CustomRPC.SetArsonist:
                    new Arsonist(Utils.PlayerById(reader.ReadByte()));
                    break;

                case CustomRPC.Douse:
                    var arsonist     = Utils.PlayerById(reader.ReadByte());
                    var douseTarget  = Utils.PlayerById(reader.ReadByte());
                    var arsonistRole = Role.GetRole <Arsonist>(arsonist);
                    arsonistRole.DousedPlayers.Add(douseTarget.PlayerId);
                    arsonistRole.ResetCooldownTimer();
                    break;

                case CustomRPC.Ignite:
                    var theArsonist     = Utils.PlayerById(reader.ReadByte());
                    var theArsonistRole = Role.GetRole <Arsonist>(theArsonist);
                    global::TownOfUs.NeutralRoles.ArsonistMod.PerformKill.Ignite(theArsonistRole);
                    break;

                case CustomRPC.ArsonistWin:
                    var theArsonistTheRole = Role.AllRoles.FirstOrDefault(x => x.RoleType == RoleEnum.Arsonist);
                    ((Arsonist)theArsonistTheRole)?.Wins();
                    break;

                case CustomRPC.ArsonistLose:
                    foreach (var role in Role.AllRoles)
                    {
                        if (role.RoleType == RoleEnum.Arsonist)
                        {
                            ((Arsonist)role).Loses();
                        }
                    }

                    break;

                case CustomRPC.SetImpostor:
                    new Impostor(Utils.PlayerById(reader.ReadByte()));
                    break;

                case CustomRPC.SetCrewmate:
                    new Crewmate(Utils.PlayerById(reader.ReadByte()));
                    break;

                case CustomRPC.SyncCustomSettings:
                    Rpc.ReceiveRpc(reader);
                    break;

                case CustomRPC.SetAltruist:
                    new Altruist(Utils.PlayerById(reader.ReadByte()));
                    break;

                case CustomRPC.SetProphet:
                    new Prophet(Utils.PlayerById(reader.ReadByte()));
                    break;

                case CustomRPC.SetCovert:
                    new Covert(Utils.PlayerById(reader.ReadByte()));
                    break;

                case CustomRPC.SetBigBoi:
                    new BigBoiModifier(Utils.PlayerById(reader.ReadByte()));
                    break;

                case CustomRPC.AltruistRevive:
                {
                    readByte1 = reader.ReadByte();
                    var altruistPlayer = Utils.PlayerById(readByte1);
                    var altruistRole   = Role.GetRole <Altruist>(altruistPlayer);
                    readByte = reader.ReadByte();
                    var theDeadBodies = Object.FindObjectsOfType <DeadBody>();
                    foreach (var body in theDeadBodies)
                    {
                        if (body.ParentId == readByte)
                        {
                            if (body.ParentId == PlayerControl.LocalPlayer.PlayerId)
                            {
                                Coroutines.Start(Utils.FlashCoroutine(altruistRole.Color,
                                                                      CustomGameOptions.ReviveDuration, 0.5f));
                            }

                            Coroutines.Start(
                                global::TownOfUs.CrewmateRoles.AltruistMod.Coroutine.AltruistRevive(body,
                                                                                                    altruistRole));
                        }
                    }

                    break;
                }

                case CustomRPC.FixAnimation:
                {
                    var player = Utils.PlayerById(reader.ReadByte());
                    player.MyPhysics.ResetMoveState();
                    player.Collider.enabled     = true;
                    player.moveable             = true;
                    player.NetTransform.enabled = true;
                    break;
                }

                case CustomRPC.SetButtonBarry:
                    new ButtonBarry(Utils.PlayerById(reader.ReadByte()));
                    break;

                case CustomRPC.SetCoroner:
                    new Coroner(Utils.PlayerById(reader.ReadByte()));
                    break;

                case CustomRPC.SetCarnivore:
                    new Carnivore(Utils.PlayerById(reader.ReadByte()));
                    break;

                case CustomRPC.BarryButton:
                    var buttonBarry = Utils.PlayerById(reader.ReadByte());
                    if (AmongUsClient.Instance.AmHost)
                    {
                        MeetingRoomManager.Instance.reporter = buttonBarry;
                        MeetingRoomManager.Instance.target   = null;
                        AmongUsClient.Instance.DisconnectHandlers.AddUnique(MeetingRoomManager.Instance
                                                                            .Cast <IDisconnectHandler>());
                        if (ShipStatus.Instance.CheckTaskCompletion())
                        {
                            return;
                        }

                        DestroyableSingleton <HudManager> .Instance.OpenMeetingRoom(buttonBarry);

                        buttonBarry.RpcStartMeeting(null);
                    }

                    break;

                case CustomRPC.CoronerReveal:
                {
                    PlayerControl player  = Utils.PlayerById(reader.ReadByte());
                    Coroner       coroner = Modifier.GetModifier <Coroner>(player);
                    byte          eatenId = reader.ReadByte();
                    coroner.Reveal(eatenId);
                    break;
                }

                case CustomRPC.CarnivoreEat:
                {
                    PlayerControl player    = Utils.PlayerById(reader.ReadByte());
                    Carnivore     carnivore = Modifier.GetModifier <Carnivore>(player);
                    byte          eatenId   = reader.ReadByte();
                    carnivore.Eat(eatenId);
                    break;
                }

                case CustomRPC.SetUndertaker:
                    new Undertaker(Utils.PlayerById(reader.ReadByte()));
                    break;

                case CustomRPC.Drag:
                {
                    readByte1 = reader.ReadByte();
                    var dienerPlayer = Utils.PlayerById(readByte1);
                    var dienerRole   = Role.GetRole <Undertaker>(dienerPlayer);
                    readByte = reader.ReadByte();
                    var dienerBodies = Object.FindObjectsOfType <DeadBody>();
                    foreach (var body in dienerBodies)
                    {
                        if (body.ParentId == readByte)
                        {
                            dienerRole.CurrentlyDragging = body;
                        }
                    }
                    break;
                }

                case CustomRPC.Drop:
                {
                    byte    undertakerId   = reader.ReadByte();
                    Vector2 deadBodyVector = reader.ReadVector2();
                    var     dienerPlayer2  = Utils.PlayerById(undertakerId);
                    var     dienerRole2    = Role.GetRole <Undertaker>(dienerPlayer2);
                    var     body           = dienerRole2.CurrentlyDragging;
                    dienerRole2.CurrentlyDragging = null;
                    body.TruePosition.Set(deadBodyVector.x, deadBodyVector.y);
                    break;
                }

                case CustomRPC.SetUnderdog:
                    new Underdog(Utils.PlayerById(reader.ReadByte()));
                    break;

                case CustomRPC.SetTeleporter:
                    new Teleporter(Utils.PlayerById(reader.ReadByte()));
                    break;

                case CustomRPC.SetConcealer:
                    new Concealer(Utils.PlayerById(reader.ReadByte()));
                    break;

                case CustomRPC.SetPhantom:
                    readByte = reader.ReadByte();
                    SetPhantom.WillBePhantom = readByte == byte.MaxValue ? null : Utils.PlayerById(readByte);
                    break;

                case CustomRPC.PhantomDied:
                    var phantom = SetPhantom.WillBePhantom;
                    Role.RoleDictionary.Remove(phantom.PlayerId);
                    var phantomRole = new Phantom(phantom);
                    phantomRole.RegenTask();
                    phantom.gameObject.layer = LayerMask.NameToLayer("Players");
                    SetPhantom.RemoveTasks(phantom);
                    SetPhantom.AddCollider(phantomRole);
                    PlayerControl.LocalPlayer.MyPhysics.ResetMoveState();
                    System.Console.WriteLine("Become Phantom - Users");
                    break;

                case CustomRPC.CatchPhantom:
                    var phantomPlayer = Utils.PlayerById(reader.ReadByte());
                    Role.GetRole <Phantom>(phantomPlayer).Caught = true;
                    break;

                case CustomRPC.PhantomWin:
                    Role.GetRole <Phantom>(Utils.PlayerById(reader.ReadByte())).CompletedTasks = true;
                    break;

                case CustomRPC.AddMayorVoteBank:
                    Role.GetRole <Mayor>(Utils.PlayerById(reader.ReadByte())).VoteBank += reader.ReadInt32();
                    break;
                }
            }