From 0e73a8a200b82adfd23e7a3424afddba96d9a291 Mon Sep 17 00:00:00 2001 From: D1GQ Date: Sat, 27 Jul 2024 23:25:22 -0500 Subject: [PATCH] Reapply "null checks and error fixes" This reverts commit 2141a2c15fa4fd91bab2a2aae141c40f69ca8eac. --- Patches/PlayerControlPatch.cs | 4 +-- Patches/PlayerJoinAndLeftPatch.cs | 42 +++++++++++++++++-------------- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/Patches/PlayerControlPatch.cs b/Patches/PlayerControlPatch.cs index e75b017..c183cd5 100644 --- a/Patches/PlayerControlPatch.cs +++ b/Patches/PlayerControlPatch.cs @@ -70,7 +70,7 @@ class PlayerControlPatch public static void SetPlayerInfo(PlayerControl player) { - if (player == null) return; + if (player == null || player.Data == null) return; // Set player text info if (player.DataIsCollected() != true) @@ -203,7 +203,7 @@ class PlayerControlPatch string Role = $"{player.GetRoleName()}"; if (!player.IsImpostorTeammate()) { - if (PlayerControl.LocalPlayer.IsAlive() && player != PlayerControl.LocalPlayer) + if (PlayerControl.LocalPlayer != null && PlayerControl.LocalPlayer.IsAlive() && player != PlayerControl.LocalPlayer) { if (!DebugMenu.RevealRoles) { diff --git a/Patches/PlayerJoinAndLeftPatch.cs b/Patches/PlayerJoinAndLeftPatch.cs index 82d86d9..197e046 100644 --- a/Patches/PlayerJoinAndLeftPatch.cs +++ b/Patches/PlayerJoinAndLeftPatch.cs @@ -10,30 +10,34 @@ class OnGameJoinedPatch { public static void Postfix(/*AmongUsClient __instance*/) { - PlayerControlPatch.infotime = 0f; - - AntiCheat.PauseAntiCheat(); - - // Fix host icon in lobby on modded servers - if (!GameStates.IsVanillaServer) + try { - var host = AmongUsClient.Instance.GetHost().Character; - host.SetColor(-2); - host.SetColor(host.CurrentOutfit.ColorId); - } + PlayerControlPatch.infotime = 0f; - _ = new LateTask(() => - { - // Send Better Among Us Check RPC - if (GameStates.IsInGame) + AntiCheat.PauseAntiCheat(); + + // Fix host icon in lobby on modded servers + if (!GameStates.IsVanillaServer) { - MessageWriter messageWriter = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte)CustomRPC.BetterCheck, SendOption.None, -1); - messageWriter.Write((byte)PlayerControl.LocalPlayer.NetId); - AmongUsClient.Instance.FinishRpcImmediately(messageWriter); + var host = AmongUsClient.Instance.GetHost().Character; + host.SetColor(-2); + host.SetColor(host.CurrentOutfit.ColorId); } - }, 1.5f, "OnGameJoinedPatch"); - Logger.Log($"Successfully joined {GameCode.IntToGameName(AmongUsClient.Instance.GameId)}", "OnGameJoinedPatch"); + _ = new LateTask(() => + { + // Send Better Among Us Check RPC + if (GameStates.IsInGame) + { + MessageWriter messageWriter = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte)CustomRPC.BetterCheck, SendOption.None, -1); + messageWriter.Write((byte)PlayerControl.LocalPlayer.NetId); + AmongUsClient.Instance.FinishRpcImmediately(messageWriter); + } + }, 1.5f, "OnGameJoinedPatch"); + + Logger.Log($"Successfully joined {GameCode.IntToGameName(AmongUsClient.Instance.GameId)}", "OnGameJoinedPatch"); + } + catch { }; } } [HarmonyPatch(typeof(AmongUsClient), nameof(AmongUsClient.OnPlayerJoined))]