From 93ac6329478290fab4f80c7a9a30bcb33d342409 Mon Sep 17 00:00:00 2001 From: D1GQ Date: Mon, 22 Jun 2026 21:59:58 -0500 Subject: [PATCH] Add null check when moving player data, fix game crashing --- src/Commands/BaseCommand.cs | 2 +- src/Patches/Client/ClientPatch.cs | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Commands/BaseCommand.cs b/src/Commands/BaseCommand.cs index b2643b1..123617b 100644 --- a/src/Commands/BaseCommand.cs +++ b/src/Commands/BaseCommand.cs @@ -26,7 +26,7 @@ internal abstract class BaseCommand internal abstract string Name { get; } /// - /// Gets the short names (aliases) for the command. + /// Gets the short names for the command. /// internal virtual string[] ShortNames => []; diff --git a/src/Patches/Client/ClientPatch.cs b/src/Patches/Client/ClientPatch.cs index c36d851..9bb05d6 100644 --- a/src/Patches/Client/ClientPatch.cs +++ b/src/Patches/Client/ClientPatch.cs @@ -1,15 +1,15 @@ using BepInEx.Unity.IL2CPP.Utils; -using BetterAmongUs.Utilities; using BetterAmongUs.Managers; using BetterAmongUs.Modules; using BetterAmongUs.Modules.Support; using BetterAmongUs.Patches.Gameplay.UI.Chat; +using BetterAmongUs.Utilities; +using BetterAmongUs.Utilities.Extension; using HarmonyLib; using InnerNet; using System.Collections; using UnityEngine; using UnityEngine.SceneManagement; -using BetterAmongUs.Utilities.Extension; namespace BetterAmongUs.Patches.Client; @@ -96,6 +96,9 @@ internal static class ClientPatch // Preserve all player GameObjects during scene transitions foreach (var data in GameData.Instance.AllPlayers) { + if (data == null || data.gameObject == null) + continue; + UnityEngine.Object.DontDestroyOnLoad(data.gameObject); } @@ -104,6 +107,9 @@ internal static class ClientPatch { foreach (var data in GameData.Instance.AllPlayers) { + if (data == null || data.gameObject == null) + continue; + SceneManager.MoveGameObjectToScene(data.gameObject, SceneManager.GetActiveScene()); } }, 0.6f, shouldLog: false);