diff --git a/Modules/CustomRolesHelper.cs b/Modules/CustomRolesHelper.cs index 7f316dd8f..92f9599c6 100644 --- a/Modules/CustomRolesHelper.cs +++ b/Modules/CustomRolesHelper.cs @@ -669,11 +669,6 @@ internal static class CustomRolesHelper CustomRoles.Pestilence; } - public static bool IsSnitchTarget(this CustomRoles role) - { - return role.IsNK() || role.Is(Team.Impostor) || (role.IsCoven() && Snitch.CanFindCoven); - } - public static bool IsGhostRole(this CustomRoles role) { return role == CustomRoles.EvilSpirit || GhostRolesManager.CreateGhostRoleInstance(role, true) != null; diff --git a/Modules/EAC.cs b/Modules/EAC.cs index c2c848823..23c7ac825 100644 --- a/Modules/EAC.cs +++ b/Modules/EAC.cs @@ -61,7 +61,7 @@ internal static class EAC break; } - case RpcCalls.SendChat when !pc.IsHost(): + case RpcCalls.SendChat when !pc.IsNonHostModdedClient(): { string text = sr.ReadString(); @@ -183,7 +183,7 @@ internal static class EAC break; } - case RpcCalls.CheckColor when !pc.IsHost(): + case RpcCalls.CheckColor when !pc.IsNonHostModdedClient(): { if (!GameStates.IsLobby) { @@ -299,7 +299,7 @@ internal static class EAC } break; } - case RpcCalls.Shapeshift when !pc.IsHost(): + case RpcCalls.Shapeshift when !pc.IsNonHostModdedClient(): { Report(pc, "Directly Shapeshift"); MessageWriter swriter = AmongUsClient.Instance.StartRpcImmediately(pc.NetId, (byte)RpcCalls.Shapeshift, SendOption.Reliable); @@ -759,8 +759,8 @@ internal static class EAC break; } - case 7 when !pc.IsHost(): - case 8 when !pc.IsHost(): + case 7 when !pc.IsNonHostModdedClient(): + case 8 when !pc.IsNonHostModdedClient(): { if (!GameStates.IsLobby) { @@ -773,7 +773,7 @@ internal static class EAC break; } - case 5 when !pc.IsHost(): + case 5 when !pc.IsNonHostModdedClient(): { sr.ReadString(); @@ -801,7 +801,7 @@ internal static class EAC break; } - case 38 when !pc.IsHost(): + case 38 when !pc.IsNonHostModdedClient(): { if (GameStates.IsInGame) { @@ -814,11 +814,11 @@ internal static class EAC break; } - case 39 when !pc.IsHost(): - case 40 when !pc.IsHost(): - case 41 when !pc.IsHost(): - case 42 when !pc.IsHost(): - case 43 when !pc.IsHost(): + case 39 when !pc.IsNonHostModdedClient(): + case 40 when !pc.IsNonHostModdedClient(): + case 41 when !pc.IsNonHostModdedClient(): + case 42 when !pc.IsNonHostModdedClient(): + case 43 when !pc.IsNonHostModdedClient(): { if (GameStates.IsInGame) { diff --git a/Modules/ExtendedPlayerControl.cs b/Modules/ExtendedPlayerControl.cs index d63be19ee..7b5034c8f 100644 --- a/Modules/ExtendedPlayerControl.cs +++ b/Modules/ExtendedPlayerControl.cs @@ -2043,7 +2043,7 @@ internal static class ExtendedPlayerControl public static bool IsSnitchTarget(this PlayerControl player) { - return player.Is(CustomRoles.Bloodlust) || Framer.FramedPlayers.Contains(player.PlayerId) || Enchanter.EnchantedPlayers.Contains(player.PlayerId) || player.GetCustomRole().IsSnitchTarget(); + return player.Is(CustomRoles.Bloodlust) || Framer.FramedPlayers.Contains(player.PlayerId) || Enchanter.EnchantedPlayers.Contains(player.PlayerId) || Snitch.IsSnitchTarget(player); } public static bool IsMadmate(this PlayerControl player) diff --git a/Patches/PetActionsPatch.cs b/Patches/PetActionsPatch.cs index 7ab7fa141..43bbbae3e 100644 --- a/Patches/PetActionsPatch.cs +++ b/Patches/PetActionsPatch.cs @@ -149,9 +149,13 @@ internal static class ExternalRpcPetPatch if (target != null) hasKillTarget = true; CustomRoles role = pc.GetCustomRole(); + + if (Options.UsePhantomBasis.GetBool() && (!role.IsNK() || Options.UsePhantomBasisForNKs.GetBool()) && role.SimpleAbilityTrigger()) return; + bool alwaysPetRole = role is CustomRoles.Necromancer or CustomRoles.Deathknight or CustomRoles.Refugee or CustomRoles.Sidekick; - if (!pc.CanUseKillButton() && !alwaysPetRole) hasKillTarget = false; + if (!pc.CanUseKillButton() && !alwaysPetRole) + hasKillTarget = false; if (role.UsesPetInsteadOfKill() && hasKillTarget && (pc.Data.RoleType != RoleTypes.Impostor || alwaysPetRole)) { diff --git a/Patches/PlayerControlPatch.cs b/Patches/PlayerControlPatch.cs index 99cfc1c0f..a500be68e 100644 --- a/Patches/PlayerControlPatch.cs +++ b/Patches/PlayerControlPatch.cs @@ -1421,7 +1421,6 @@ internal static class FixedUpdatePatch private static readonly Dictionary LastAddAbilityTime = []; private static long LastErrorTS; private static long LastSelfNameUpdateTS; - private static readonly Dictionary RoleTextTMPs = []; public static void Postfix(PlayerControl __instance, bool lowLoad) { @@ -1699,23 +1698,13 @@ internal static class FixedUpdatePatch player.RpcSetName(name); } - if (GameStates.IsEnded || !Main.IntroDestroyed || GameStates.IsMeeting || ExileController.Instance || AntiBlackout.SkipTasks) - { - RoleTextTMPs.Clear(); - return; - } - - if (!RoleTextTMPs.TryGetValue(__instance.PlayerId, out TextMeshPro roleText) || roleText == null) - { - Transform roleTextTransform = __instance.cosmetics.nameText.transform.Find("RoleText"); - RoleTextTMPs[__instance.PlayerId] = roleText = roleTextTransform.GetComponent(); - } + if (GameStates.IsEnded || !Main.IntroDestroyed || GameStates.IsMeeting || ExileController.Instance || AntiBlackout.SkipTasks) return; bool self = lpId == __instance.PlayerId; bool shouldUpdateRegardlessOfLowLoad = self && GameStates.InGame && PlayerControl.LocalPlayer.IsAlive() && ((PlayerControl.AllPlayerControls.Count > 30 && LastSelfNameUpdateTS != now && Options.CurrentGameMode is CustomGameMode.MoveAndStop or CustomGameMode.HotPotato or CustomGameMode.Speedrun or CustomGameMode.RoomRush or CustomGameMode.KingOfTheZones or CustomGameMode.Quiz) || DirtyName.Remove(lpId)); - if (roleText == null || __instance == null || (lowLoad && !shouldUpdateRegardlessOfLowLoad)) return; + if (__instance == null || (lowLoad && !shouldUpdateRegardlessOfLowLoad)) return; if (self) LastSelfNameUpdateTS = now; @@ -1739,33 +1728,30 @@ internal static class FixedUpdatePatch if (GameStates.IsInGame) { - if (!AmongUsClient.Instance.AmHost && Options.CurrentGameMode != CustomGameMode.Standard) - { - roleText.text = string.Empty; - roleText.enabled = false; - return; - } + if (!AmongUsClient.Instance.AmHost && Options.CurrentGameMode != CustomGameMode.Standard) return; bool shouldSeeTargetAddons = playerId == lpId || new[] { PlayerControl.LocalPlayer, player }.All(x => x.Is(Team.Impostor)); - (string, Color) roleTextData = GetRoleText(lpId, playerId, seeTargetBetrayalAddons: shouldSeeTargetAddons); - roleText.text = roleTextData.Item1; - roleText.color = roleTextData.Item2; + string roleText; - if (Options.CurrentGameMode is not CustomGameMode.Standard and not CustomGameMode.HideAndSeek) roleText.text = string.Empty; - - roleText.enabled = IsRoleTextEnabled(__instance); + if (Options.CurrentGameMode is not CustomGameMode.Standard and not CustomGameMode.HideAndSeek || !IsRoleTextEnabled(__instance)) + roleText = string.Empty; + else + { + (string, Color) roleTextData = GetRoleText(lpId, playerId, seeTargetBetrayalAddons: shouldSeeTargetAddons); + roleText = ColorString(roleTextData.Item2, roleTextData.Item1); + } if (PlayerControl.LocalPlayer.IsAlive() && PlayerControl.LocalPlayer.IsRevealedPlayer(__instance) && __instance.Is(CustomRoles.Trickster)) { - roleText.text = Farseer.RandomRole[lpId]; - roleText.text += Farseer.GetTaskState(); + roleText = Farseer.RandomRole[lpId]; + roleText += Farseer.GetTaskState(); } if (!AmongUsClient.Instance.IsGameStarted && AmongUsClient.Instance.NetworkMode != NetworkModes.FreePlay) { - roleText.enabled = false; + roleText = string.Empty; if (!__instance.AmOwner) __instance.cosmetics.nameText.text = __instance?.Data?.PlayerName; } @@ -1782,8 +1768,8 @@ internal static class FixedUpdatePatch if (Main.VisibleTasksCount) { - if (moveandstop) roleText.text = roleText.text.Insert(0, progressText); - else roleText.text += progressText; + if (moveandstop) roleText = roleText.Insert(0, progressText); + else roleText += progressText; } PlayerControl seer = PlayerControl.LocalPlayer; @@ -1792,14 +1778,12 @@ internal static class FixedUpdatePatch if (target.Is(CustomRoles.Car)) { target.cosmetics.nameText.text = Car.Name; - roleText.enabled = false; return; } if (Main.PlayerStates.TryGetValue(target.PlayerId, out var targetState) && targetState.Role is Tree { TreeSpriteActive: true }) { target.cosmetics.nameText.text = Tree.Sprite; - roleText.enabled = false; return; } @@ -2023,54 +2007,18 @@ internal static class FixedUpdatePatch if (!self && Options.CurrentGameMode == CustomGameMode.KingOfTheZones && Main.IntroDestroyed && !KingOfTheZones.GameGoing) realName = EmptyMessage; + if (!Options.LargerRoleTextSize.GetBool()) + roleText = $"{roleText}\n"; + else + roleText += "\n"; + string newLineBeforeSuffix = !(Options.CurrentGameMode == CustomGameMode.BedWars && !self && GameStates.InGame) ? "\r\n" : " - "; string deathReason = !seer.IsAlive() && seer.KnowDeathReason(target) ? $"{newLineBeforeSuffix}『{ColorString(GetRoleColor(CustomRoles.Doctor), GetVitalText(target.PlayerId))}』" : string.Empty; string currentText = target.cosmetics.nameText.text; - var changeTo = $"{realName}{deathReason}{Mark}{newLineBeforeSuffix}{Suffix}"; + var changeTo = $"{roleText}{realName}{deathReason}{Mark}{newLineBeforeSuffix}{Suffix}"; bool needUpdate = currentText != changeTo; - - if (needUpdate) - { - target.cosmetics.nameText.text = changeTo; - - var offset = 0.1f; - - if (self && NameNotifyManager.GetNameNotify(seer, out string notify) && notify.Contains('\n')) - { - int count = notify.Count(x => x == '\n'); - for (var i = 0; i < count; i++) offset += 0.15f; - } - - if (Suffix.ToString() != string.Empty) - { - offset += moveandstop ? 0.15f : 0.2f; - offset += moveandstop ? 0f : Suffix.ToString().Count(x => x == '\n') * 0.15f; - } - - if (!seer.IsAlive()) - offset += 0.1f; - - if (isProgressTextLong) - offset += 0.3f; - - if (moveandstop) - offset += 0.3f; - - if (Suffix.ToString().Contains(GetString("MoveAndStop_Tutorial"))) - offset += 0.8f; - - if (Options.LargerRoleTextSize.GetBool()) - offset += 0.05f; - - roleText.transform.SetLocalY(offset); - target.cosmetics.colorBlindText.transform.SetLocalY(-(offset + 0.2f)); - } - } - else - { - // Restoring the position text coordinates to their initial values - roleText.transform.SetLocalY(0.1f); + if (needUpdate) target.cosmetics.nameText.text = changeTo; } } @@ -2114,25 +2062,6 @@ internal static class FixedUpdatePatch } } -[HarmonyPatch(typeof(PlayerControl._Start_d__82), nameof(PlayerControl._Start_d__82.MoveNext))] -internal static class PlayerStartPatch -{ - public static void Postfix(PlayerControl._Start_d__82 __instance, ref bool __result) - { - try - { - if (__result || __instance == null || __instance.__4__this == null || __instance.__4__this.PlayerId >= 254 || __instance.__4__this.cosmetics == null) return; - TextMeshPro nameText = __instance.__4__this.cosmetics.nameText; - TextMeshPro roleText = Object.Instantiate(nameText, nameText.transform, true); - if (!Options.LargerRoleTextSize.GetBool()) roleText.fontSize -= 0.9f; - roleText.text = "RoleText"; - roleText.gameObject.name = "RoleText"; - roleText.enabled = false; - } - catch { } - } -} - [HarmonyPatch(typeof(Vent), nameof(Vent.ExitVent))] internal static class ExitVentPatch { diff --git a/Roles/Crewmate/Snitch.cs b/Roles/Crewmate/Snitch.cs index 3f8262419..ea85fbbf3 100644 --- a/Roles/Crewmate/Snitch.cs +++ b/Roles/Crewmate/Snitch.cs @@ -93,7 +93,7 @@ public class Snitch : RoleBase return IsExposed[snitchId]; } - private static bool IsSnitchTarget(PlayerControl target) + public static bool IsSnitchTarget(PlayerControl target) { return (target.Is(CustomRoleTypes.Impostor) && !target.Is(CustomRoles.Trickster)) || (target.IsNeutralKiller() && CanFindNeutralKiller) || (target.Is(CustomRoleTypes.Coven) && CanFindCoven) || (target.Is(CustomRoles.Madmate) && CanFindMadmate) || (target.Is(CustomRoles.Rascal) && CanFindMadmate); } diff --git a/Roles/Crewmate/Tree.cs b/Roles/Crewmate/Tree.cs index 6d79470b2..902d68828 100644 --- a/Roles/Crewmate/Tree.cs +++ b/Roles/Crewmate/Tree.cs @@ -67,9 +67,8 @@ public class Tree : RoleBase LateTask.New(() => { - if (!GameStates.IsInTask || ExileController.Instance || AntiBlackout.SkipTasks || pc == null || !pc.IsAlive()) return; - Main.AllPlayerSpeed[pc.PlayerId] = Main.RealOptionsData.GetFloat(FloatOptionNames.PlayerSpeedMod); + if (!GameStates.IsInTask || ExileController.Instance || AntiBlackout.SkipTasks || pc == null || !pc.IsAlive()) return; pc.MarkDirtySettings(); if (treeSpriteVisible) @@ -77,7 +76,8 @@ public class Tree : RoleBase TreeSpriteActive = false; Utils.NotifyRoles(SpecifyTarget: pc); } - else pc.RpcMakeVisible(); + else + pc.RpcMakeVisible(); int chance = FallKillChance.GetInt(); @@ -91,8 +91,8 @@ public class Tree : RoleBase LateTask.New(() => { - if (!GameStates.IsInTask || ExileController.Instance || AntiBlackout.SkipTasks || pc == null || !pc.IsAlive()) return; Main.AllPlayerSpeed[x.PlayerId] = Main.RealOptionsData.GetFloat(FloatOptionNames.PlayerSpeedMod); + if (!GameStates.IsInTask || ExileController.Instance || AntiBlackout.SkipTasks || pc == null || !pc.IsAlive()) return; x.MarkDirtySettings(); }, FallStunDuration.GetFloat(), log: false); } diff --git a/Roles/Impostor/Sans.cs b/Roles/Impostor/Sans.cs index dae69988b..3f441f129 100644 --- a/Roles/Impostor/Sans.cs +++ b/Roles/Impostor/Sans.cs @@ -124,6 +124,11 @@ public class Sans : RoleBase return CanVent; } + public override bool CanUseKillButton(PlayerControl pc) + { + return pc.IsAlive(); + } + public override void OnMurder(PlayerControl killer, PlayerControl target) { NowCooldown = Math.Clamp(NowCooldown - ReduceKCD, MinKCD, DefaultKCD);