From cd26c179b99737abffc5208939984b92a02da8c9 Mon Sep 17 00:00:00 2001 From: Gurge44 Date: Thu, 20 Aug 2026 10:13:38 +0200 Subject: [PATCH] innersloth just wanted to use implicit conversions :skull: --- Patches/MeetingHudPatch.cs | 107 ++++++++++++++++++------------------- 1 file changed, 53 insertions(+), 54 deletions(-) diff --git a/Patches/MeetingHudPatch.cs b/Patches/MeetingHudPatch.cs index 9205ce300..6854864fa 100644 --- a/Patches/MeetingHudPatch.cs +++ b/Patches/MeetingHudPatch.cs @@ -113,8 +113,10 @@ internal static class CheckForEndVotingPatch if (!ShouldSkip && !__instance.playerStates.All(ps => { - if (!ps || Silencer.ForSilencer.Contains(ps.PlayerId) || !Main.PlayerStates.TryGetValue(ps.PlayerId, out PlayerState st) || st.IsDead || ps.AmDead || ps.DidVote) return true; - PlayerControl targetPlayer = Utils.GetPlayerById(ps.PlayerId); + if (!ps) return true; + byte playerId = ps.PlayerId.Value; + if (Silencer.ForSilencer.Contains(playerId) || !Main.PlayerStates.TryGetValue(playerId, out PlayerState st) || st.IsDead || ps.AmDead || ps.DidVote) return true; + PlayerControl targetPlayer = Utils.GetPlayerById(playerId); return !targetPlayer || !targetPlayer.Data || targetPlayer.Data.Disconnected; })) return false; @@ -126,8 +128,9 @@ internal static class CheckForEndVotingPatch { if (!ps) continue; - voteLog.Info($"{ps.PlayerId,-2}{$"({Utils.GetVoteName(ps.PlayerId)})".PadRightV2(40)}:{ps.VotedForId,-3}({Utils.GetVoteName(ps.VotedForId)})"); - PlayerControl voter = Utils.GetPlayerById(ps.PlayerId); + byte playerId = ps.PlayerId.Value; + voteLog.Info($"{playerId,-2}{$"({Utils.GetVoteName(playerId)})".PadRightV2(40)}:{ps.VotedForId,-3}({Utils.GetVoteName(ps.VotedForId)})"); + PlayerControl voter = Utils.GetPlayerById(playerId); if (!voter || !voter.Data || voter.Data.Disconnected) continue; if (Options.VoteMode.GetBool()) @@ -141,7 +144,7 @@ internal static class CheckForEndVotingPatch switch (Options.GetWhenSkipVote()) { case VoteMode.Suicide: - TryAddAfterMeetingDeathPlayers(PlayerState.DeathReason.SkippedVote, ps.PlayerId); + TryAddAfterMeetingDeathPlayers(PlayerState.DeathReason.SkippedVote, playerId); voteLog.Info($"{voter.GetNameWithRole()} Commit suicide for skipping voting"); break; case VoteMode.SelfVote: @@ -156,7 +159,7 @@ internal static class CheckForEndVotingPatch switch (Options.GetWhenNonVote()) { case VoteMode.Suicide: - TryAddAfterMeetingDeathPlayers(PlayerState.DeathReason.DidntVote, ps.PlayerId); + TryAddAfterMeetingDeathPlayers(PlayerState.DeathReason.DidntVote, playerId); voteLog.Info($"{voter.GetNameWithRole()} Committed suicide for not voting"); break; case VoteMode.SelfVote: @@ -172,23 +175,23 @@ internal static class CheckForEndVotingPatch } if (ps.VotedForId == 254 && voter.IsAlive() && voter.Is(CustomRoles.Compelled)) - TryAddAfterMeetingDeathPlayers(PlayerState.DeathReason.DidntVote, ps.PlayerId); + TryAddAfterMeetingDeathPlayers(PlayerState.DeathReason.DidntVote, playerId); - if (CheckRole(ps.PlayerId, CustomRoles.FortuneTeller) && FortuneTeller.HideVote.GetBool()) continue; - if (CheckRole(ps.PlayerId, CustomRoles.EvilEraser) && EvilEraser.HideVote.GetBool()) continue; - if (CheckRole(ps.PlayerId, CustomRoles.NiceEraser) && NiceEraser.HideVote.GetBool()) continue; - if (CheckRole(ps.PlayerId, CustomRoles.Scout) && Scout.HideVote.GetBool()) continue; - if (CheckRole(ps.PlayerId, CustomRoles.Oracle) && Oracle.HideVote.GetBool()) continue; + if (CheckRole(playerId, CustomRoles.FortuneTeller) && FortuneTeller.HideVote.GetBool()) continue; + if (CheckRole(playerId, CustomRoles.EvilEraser) && EvilEraser.HideVote.GetBool()) continue; + if (CheckRole(playerId, CustomRoles.NiceEraser) && NiceEraser.HideVote.GetBool()) continue; + if (CheckRole(playerId, CustomRoles.Scout) && Scout.HideVote.GetBool()) continue; + if (CheckRole(playerId, CustomRoles.Oracle) && Oracle.HideVote.GetBool()) continue; if (ps.PlayerId == ps.VotedForId && Options.MadmateSpawnMode.GetInt() == 2 && CustomRoles.Madmate.IsEnable() && MeetingStates.FirstMeeting) continue; - bool canVote = !(CheckRole(ps.PlayerId, CustomRoles.Glitch) && !Glitch.CanVote.GetBool()); - if (CheckRole(ps.PlayerId, CustomRoles.Shifter) && !Shifter.CanVote.GetBool()) canVote = false; + bool canVote = !(CheckRole(playerId, CustomRoles.Glitch) && !Glitch.CanVote.GetBool()); + if (CheckRole(playerId, CustomRoles.Shifter) && !Shifter.CanVote.GetBool()) canVote = false; if (ps.VotedForId.Value.GetPlayer() && CheckRole(ps.VotedForId, CustomRoles.Zombie)) canVote = false; - if (CheckRole(ps.PlayerId, CustomRoles.Degraded)) canVote = false; - if (Poache.PoachedPlayers != null && Poache.PoachedPlayers.Contains(ps.PlayerId)) canVote = false; - if (Silencer.ForSilencer.Contains(ps.PlayerId) && Main.AllAlivePlayerControlsCount > Silencer.MaxPlayersAliveForSilencedToVote.GetInt()) canVote = false; + if (CheckRole(playerId, CustomRoles.Degraded)) canVote = false; + if (Poache.PoachedPlayers != null && Poache.PoachedPlayers.Contains(playerId)) canVote = false; + if (Silencer.ForSilencer.Contains(playerId) && Main.AllAlivePlayerControlsCount > Silencer.MaxPlayersAliveForSilencedToVote.GetInt()) canVote = false; - switch (Main.PlayerStates[ps.PlayerId].Role) + switch (Main.PlayerStates[playerId].Role) { case Adventurer { IsEnable: true } av when av.ActiveWeapons.Contains(Adventurer.Weapon.Proxy): AddVote(); @@ -209,25 +212,25 @@ internal static class CheckForEndVotingPatch if (canVote) AddVote(); - if (CheckRole(ps.PlayerId, CustomRoles.Magistrate) && Magistrate.CallCourtNextMeeting) Loop.Times(Magistrate.ExtraVotes.GetInt(), _ => AddVote()); - if (CheckRole(ps.PlayerId, CustomRoles.Vindicator) && !Options.VindicatorHideVote.GetBool()) Loop.Times(Options.VindicatorAdditionalVote.GetInt(), _ => AddVote()); - if (CheckRole(ps.PlayerId, CustomRoles.Knighted)) AddVote(); + if (CheckRole(playerId, CustomRoles.Magistrate) && Magistrate.CallCourtNextMeeting) Loop.Times(Magistrate.ExtraVotes.GetInt(), _ => AddVote()); + if (CheckRole(playerId, CustomRoles.Vindicator) && !Options.VindicatorHideVote.GetBool()) Loop.Times(Options.VindicatorAdditionalVote.GetInt(), _ => AddVote()); + if (CheckRole(playerId, CustomRoles.Knighted)) AddVote(); - if (CheckRole(ps.PlayerId, CustomRoles.Schizophrenic) && Options.DualVotes.GetBool()) + if (CheckRole(playerId, CustomRoles.Schizophrenic) && Options.DualVotes.GetBool()) { - int count = StatesList.Count(x => x.VoterId == ps.PlayerId && x.VotedForId == ps.VotedForId); + int count = StatesList.Count(x => x.VoterId == playerId && x.VotedForId == ps.VotedForId); Loop.Times(count, _ => AddVote()); } - if (CheckRole(ps.PlayerId, CustomRoles.Stealer)) + if (CheckRole(playerId, CustomRoles.Stealer)) { - var count = (int)(Main.EnumeratePlayerControls().Count(x => x.GetRealKiller()?.PlayerId == ps.PlayerId) * Options.VotesPerKill.GetFloat()); + var count = (int)(Main.EnumeratePlayerControls().Count(x => x.GetRealKiller()?.PlayerId == playerId) * Options.VotesPerKill.GetFloat()); Loop.Times(count, _ => AddVote()); } - if (CheckRole(ps.PlayerId, CustomRoles.Pickpocket)) + if (CheckRole(playerId, CustomRoles.Pickpocket)) { - var count = (int)(Main.EnumeratePlayerControls().Count(x => x.GetRealKiller()?.PlayerId == ps.PlayerId) * Pickpocket.VotesPerKill.GetFloat()); + var count = (int)(Main.EnumeratePlayerControls().Count(x => x.GetRealKiller()?.PlayerId == playerId) * Pickpocket.VotesPerKill.GetFloat()); Loop.Times(count, _ => AddVote()); } @@ -236,7 +239,7 @@ internal static class CheckForEndVotingPatch void AddVote() => StatesList.Add(new() { - VoterId = ps.PlayerId, + VoterId = playerId, VotedForId = ps.VotedForId }); } @@ -351,14 +354,9 @@ internal static class CheckForEndVotingPatch { wasOverruled = true; overruleNonce = winningOverrule.OverruleNonce; - if (overruledPlayerInfo.Role.TeamType == RoleTeamTypes.Impostor) // Only vanilla impostor, need change code for EHR Impostors - { - exiledPlayer = GameData.Instance.GetPlayerById(winningOverrule.OverruledPlayerId); - } - else - { - exiledPlayer = judgePlayerInfo; - } + exiledPlayer = overruledPlayerInfo.Object.GetTeam() is Team.Impostor or Team.Coven || overruledPlayerInfo.Object.GetCustomRole().GetNeutralRoleCategory() is RoleOptionType.Neutral_Evil or RoleOptionType.Neutral_Pariah or RoleOptionType.Neutral_Killing + ? GameData.Instance.GetPlayerById(winningOverrule.OverruledPlayerId) + : judgePlayerInfo; } __instance.RpcVotingComplete(States.ToArray(), exiledPlayer, tie, wasOverruled, overruleNonce); @@ -621,8 +619,7 @@ internal static class CheckForEndVotingPatch private static PlayerControl PickRevengeTarget(PlayerControl exiledplayer /*, PlayerState.DeathReason deathReason*/) { - List targetList = []; - targetList.AddRange(Main.EnumerateAlivePlayerControls().Where(candidate => candidate != exiledplayer && !Main.AfterMeetingDeathPlayers.ContainsKey(candidate.PlayerId))); + List targetList = [.. Main.EnumerateAlivePlayerControls().Where(candidate => candidate != exiledplayer && !Main.AfterMeetingDeathPlayers.ContainsKey(candidate.PlayerId))]; if (targetList.Count == 0) return null; @@ -648,6 +645,7 @@ internal static class ExtendedMeetingHud { var voteNum = 1; + byte psPlayerId = ps.PlayerId.Value; PlayerControl target = Utils.GetPlayerById(ps.VotedForId); if (target) @@ -655,7 +653,7 @@ internal static class ExtendedMeetingHud if (target.Is(CustomRoles.Zombie) || (target.Is(CustomRoles.Shifter) && !Shifter.CanBeVoted.GetBool())) voteNum = 0; - if (CheckForEndVotingPatch.CheckRole(ps.PlayerId, CustomRoles.Tiebreaker)) + if (CheckForEndVotingPatch.CheckRole(psPlayerId, CustomRoles.Tiebreaker)) { if (!Main.TiebreakerVoteFor.Contains(target.PlayerId)) Main.TiebreakerVoteFor.Add(target.PlayerId); @@ -664,15 +662,15 @@ internal static class ExtendedMeetingHud Collector.CollectorVotes(target, ps); } - if (Poache.PoachedPlayers != null && Poache.PoachedPlayers.Contains(ps.PlayerId)) voteNum = 0; - if (Silencer.ForSilencer.Contains(ps.PlayerId) && Main.AllAlivePlayerControlsCount > Silencer.MaxPlayersAliveForSilencedToVote.GetInt()) voteNum = 0; + if (Poache.PoachedPlayers != null && Poache.PoachedPlayers.Contains(psPlayerId)) voteNum = 0; + if (Silencer.ForSilencer.Contains(psPlayerId) && Main.AllAlivePlayerControlsCount > Silencer.MaxPlayersAliveForSilencedToVote.GetInt()) voteNum = 0; - if (CheckForEndVotingPatch.CheckRole(ps.PlayerId, CustomRoles.Knighted)) voteNum += 1; - if (CheckForEndVotingPatch.CheckRole(ps.PlayerId, CustomRoles.Degraded)) voteNum -= 1; - if (CheckForEndVotingPatch.CheckRole(ps.PlayerId, CustomRoles.Schizophrenic) && Options.DualVotes.GetBool()) voteNum += voteNum; - if (CheckForEndVotingPatch.CheckRole(ps.PlayerId, CustomRoles.Stealer)) voteNum += (int)(Main.EnumeratePlayerControls().Count(x => x.GetRealKiller()?.PlayerId == ps.PlayerId) * Options.VotesPerKill.GetFloat()); + if (CheckForEndVotingPatch.CheckRole(psPlayerId, CustomRoles.Knighted)) voteNum += 1; + if (CheckForEndVotingPatch.CheckRole(psPlayerId, CustomRoles.Degraded)) voteNum -= 1; + if (CheckForEndVotingPatch.CheckRole(psPlayerId, CustomRoles.Schizophrenic) && Options.DualVotes.GetBool()) voteNum += voteNum; + if (CheckForEndVotingPatch.CheckRole(psPlayerId, CustomRoles.Stealer)) voteNum += (int)(Main.EnumeratePlayerControls().Count(x => x.GetRealKiller()?.PlayerId == psPlayerId) * Options.VotesPerKill.GetFloat()); - switch (Main.PlayerStates[ps.PlayerId].Role) + switch (Main.PlayerStates[psPlayerId].Role) { case Dad { IsEnable: true } dad when dad.UsingAbilities.Contains(Dad.Ability.GoForMilk): case Shifter when !Shifter.CanVote.GetBool(): @@ -692,7 +690,7 @@ internal static class ExtendedMeetingHud voteNum += Survivor.AdditionalVote.GetInt(); break; case Pickpocket: - voteNum += (int)(Main.EnumeratePlayerControls().Count(x => x.GetRealKiller()?.PlayerId == ps.PlayerId) * Pickpocket.VotesPerKill.GetFloat()); + voteNum += (int)(Main.EnumeratePlayerControls().Count(x => x.GetRealKiller()?.PlayerId == psPlayerId) * Pickpocket.VotesPerKill.GetFloat()); break; case Vindicator: voteNum += Options.VindicatorAdditionalVote.GetInt(); @@ -702,7 +700,7 @@ internal static class ExtendedMeetingHud break; } - if (ps.PlayerId == ps.VotedForId && Options.MadmateSpawnMode.GetInt() == 2 && CustomRoles.Madmate.IsEnable() && MeetingStates.FirstMeeting) voteNum = 0; + if (psPlayerId == ps.VotedForId && Options.MadmateSpawnMode.GetInt() == 2 && CustomRoles.Madmate.IsEnable() && MeetingStates.FirstMeeting) voteNum = 0; dic[ps.VotedForId] = !dic.TryGetValue(ps.VotedForId, out int num) ? voteNum : num + voteNum; } @@ -802,8 +800,7 @@ internal static class MeetingHudStartPatch if (pc.Is(CustomRoles.Workaholic)) Workaholic.WorkaholicAlive.Add(pc.PlayerId); - List workaholicAliveList = []; - workaholicAliveList.AddRange(Workaholic.WorkaholicAlive.Select(whId => Main.AllPlayerNames[whId])); + List workaholicAliveList = [.. Workaholic.WorkaholicAlive.Select(whId => Main.AllPlayerNames[whId])]; string separator = TranslationController.Instance.currentLanguage.languageID is SupportedLangs.English or SupportedLangs.Russian ? "], [" : "】, 【"; AddMsg(string.Format(GetString("WorkaholicAdviceAlive"), string.Join(separator, workaholicAliveList)), 255, CustomRoles.Workaholic.ColoredTextByRole(GetString("WorkaholicAliveTitle"))); @@ -816,8 +813,7 @@ internal static class MeetingHudStartPatch if (pc.Is(CustomRoles.Bait)) Main.BaitAlive.Add(pc.PlayerId); - List baitAliveList = []; - baitAliveList.AddRange(Main.BaitAlive.Select(whId => Main.AllPlayerNames[whId])); + List baitAliveList = [.. Main.BaitAlive.Select(whId => Main.AllPlayerNames[whId])]; string separator = TranslationController.Instance.currentLanguage.languageID is SupportedLangs.English or SupportedLangs.Russian ? "], [" : "】, 【"; AddMsg(string.Format(GetString("BaitAdviceAlive"), string.Join(separator, baitAliveList)), 255, CustomRoles.Bait.ColoredTextByRole(GetString("BaitAliveTitle"))); @@ -1426,10 +1422,12 @@ internal static class MeetingHudCastVotePatch { public static readonly Dictionary ShouldCancelVoteList = []; - public static bool Prefix(MeetingHud __instance, [HarmonyArgument(0)] PlayerId srcPlayerId, [HarmonyArgument(1)] PlayerId suspectPlayerId) + public static bool Prefix(MeetingHud __instance, [HarmonyArgument(0)] PlayerId srcPlayerIdStruct, [HarmonyArgument(1)] PlayerId suspectPlayerIdStruct) { if (!AmongUsClient.Instance.AmHost) return true; + byte srcPlayerId = srcPlayerIdStruct.Value; + byte suspectPlayerId = suspectPlayerIdStruct.Value; PlayerVoteArea pvaSrc = null; PlayerVoteArea pvaTarget = null; var skip = false; @@ -1492,8 +1490,9 @@ internal static class MeetingHudCastVotePatch return skip || !voteCanceled; // skips and invalid votes are never canceled } - public static void Postfix([HarmonyArgument(0)] PlayerId srcPlayerId) + public static void Postfix([HarmonyArgument(0)] PlayerId srcPlayerIdStruct) { + byte srcPlayerId = srcPlayerIdStruct.Value; if (!ShouldCancelVoteList.TryGetValue(srcPlayerId, out (MeetingHud MeetingHud, PlayerVoteArea SourcePVA, PlayerControl SourcePC) info)) return; try