From 548cd0ab9dce49c66154b52b4eb1947255d1c7cc Mon Sep 17 00:00:00 2001 From: D1GQ Date: Mon, 29 Jul 2024 18:02:37 -0500 Subject: [PATCH] better host fixes --- Modules/BetterHostManager.cs | 29 ++++++++++++++++++++++------- Patches/GamePlayManagerPatch.cs | 24 ++++++++++++++++++++++++ Patches/RoleManagerPatch.cs | 7 ++++++- 3 files changed, 52 insertions(+), 8 deletions(-) diff --git a/Modules/BetterHostManager.cs b/Modules/BetterHostManager.cs index 007b259..0bcbcf5 100644 --- a/Modules/BetterHostManager.cs +++ b/Modules/BetterHostManager.cs @@ -1,4 +1,5 @@ -using Hazel; +using AmongUs.GameOptions; +using Hazel; using InnerNet; using System.Text; @@ -61,7 +62,7 @@ class BetterHostManager if (target != null) { - if (player.Data.Role is ShapeshifterRole && player.IsAlive() && player.IsImpostorTeam() && !player.inMovingPlat && !player.shapeshifting && !player.MyPhysics.Animations.IsPlayingAnyLadderAnimation()) + if (player.Data.RoleType == RoleTypes.Shapeshifter && player.IsAlive() && player.IsImpostorTeam() && !player.inMovingPlat && !player.shapeshifting && !player.MyPhysics.Animations.IsPlayingAnyLadderAnimation()) { if (!target.IsInVent() && flag == false) { @@ -79,9 +80,15 @@ class BetterHostManager case (byte)RpcCalls.CheckVanish: { - if (player.Data.Role is PhantomRole && player.IsAlive() && player.IsImpostorTeam() && !player.IsInVent() && !player.inMovingPlat && !player.MyPhysics.Animations.IsPlayingAnyLadderAnimation()) + if (player.Data.RoleType == RoleTypes.Phantom && player.IsAlive() && player.IsImpostorTeam() && !player.IsInVent() && !player.inMovingPlat && !player.MyPhysics.Animations.IsPlayingAnyLadderAnimation()) { + + if (AmongUsClient.Instance.AmClient) + { + player.SetRoleInvisibility(true, true, true); + } player.RpcVanish(); + break; } @@ -93,14 +100,19 @@ class BetterHostManager { bool flag = reader.ReadBoolean(); - if (player.Data.Role is PhantomRole && player.IsAlive() && player.IsImpostorTeam() && !player.inMovingPlat && !player.MyPhysics.Animations.IsPlayingAnyLadderAnimation()) + if (player.Data.RoleType == RoleTypes.Phantom && player.IsAlive() && player.IsImpostorTeam() && !player.inMovingPlat && !player.MyPhysics.Animations.IsPlayingAnyLadderAnimation()) { if (!player.IsInVent() && flag == false) { break; } + if (AmongUsClient.Instance.AmClient) + { + player.SetRoleInvisibility(false, !player.IsInVent(), true); + } player.RpcAppear(!player.IsInVent()); + break; } @@ -120,7 +132,7 @@ class BetterHostManager // Set player names for better host public static void SetPlayersInfoAsHost(PlayerControl player, bool forMeeting = false, bool force = false, bool IsBetterHost = true) { - if (player == null || !player.DataIsCollected()) return; + if (player == null) return; if (!Main.BetterHost.Value || forMeeting) { @@ -158,7 +170,7 @@ class BetterHostManager else if (GameStates.IsInGamePlay) { string Role = $"{player.GetRoleName()}"; - if (!player.IsImpostorTeam() && !target.IsImpostorTeam()) + if (player.IsImpostorTeam() is false || target.IsImpostorTeam() is false) { if (target.IsAlive() && player != target) { @@ -184,7 +196,10 @@ class BetterHostManager } } - NewName = $"{sbTopInfo}\n{NewName}"; + if (sbTopInfo.Length > 0) + NewName = $"{sbTopInfo}\n{NewName}"; + else + NewName = $"{NewName}"; // Don't send rpc if name is the same! if (LastPlayerName.TryGetValue(target.Data.PlayerId, out var playerNameDict)) diff --git a/Patches/GamePlayManagerPatch.cs b/Patches/GamePlayManagerPatch.cs index 220d695..9605793 100644 --- a/Patches/GamePlayManagerPatch.cs +++ b/Patches/GamePlayManagerPatch.cs @@ -1,4 +1,5 @@ using HarmonyLib; +using Hazel; namespace BetterAmongUs.Patches; @@ -16,6 +17,18 @@ class GamePlayManager AntiCheat.PauseAntiCheat(); } } + [HarmonyPatch(nameof(LobbyBehaviour.Start))] + [HarmonyPostfix] + private static void Postfix(/*LobbyBehaviour __instance*/) + { + _ = new LateTask(() => + { + if (GameStates.IsInGame) + { + RPC.SyncAllNames(force: true); + } + }, 1.5f, "LobbyBehaviourPatch SyncAllNames"); + } } [HarmonyPatch(typeof(GameManager))] @@ -34,4 +47,15 @@ class GamePlayManager } } } + + [HarmonyPatch(typeof(GameStartManager))] + public class GameStartManagerPatch + { + [HarmonyPatch(nameof(GameStartManager.Update))] + [HarmonyPrefix] + private static void Prefix(GameStartManager __instance) + { + __instance.MinPlayers = 1; + } + } } diff --git a/Patches/RoleManagerPatch.cs b/Patches/RoleManagerPatch.cs index 5200a0b..f5ca9f3 100644 --- a/Patches/RoleManagerPatch.cs +++ b/Patches/RoleManagerPatch.cs @@ -1,5 +1,6 @@ using AmongUs.GameOptions; using HarmonyLib; +using Hazel; namespace BetterAmongUs.Role; @@ -181,7 +182,11 @@ public class RoleManagerPatch } SetPlayerRole.Clear(); - RPC.SyncAllNames(); + + _ = new LateTask(() => + { + RPC.SyncAllNames(false, true, Main.BetterHost.Value); + }, 1f, "RoleManager SyncAllNames"); Logger.LogHeader($"Better Role Assignment Has Finished", "RoleManager");