Fix null ref on game start for Android

This commit is contained in:
D1GQ committed 2026-03-18 14:24:58 -05:00
1 parent 7f39f16cfc
commit d5072155bf
2 files changed
+18 -16

No files matched your search

+18 -3
View File
@@ -19,6 +19,8 @@ internal static class LobbyPatch
OptionPlayerItem.ResetAllValues(); OptionPlayerItem.ResetAllValues();
} }
private static Transform? GameStartObj;
// Disable annoying lobby music if setting is enabled // Disable annoying lobby music if setting is enabled
[HarmonyPatch(typeof(LobbyBehaviour), nameof(LobbyBehaviour.Update))] [HarmonyPatch(typeof(LobbyBehaviour), nameof(LobbyBehaviour.Update))]
[HarmonyPostfix] [HarmonyPostfix]
@@ -26,6 +28,19 @@ internal static class LobbyPatch
{ {
if (BAUConfigs.DisableLobbyTheme.Value) if (BAUConfigs.DisableLobbyTheme.Value)
SoundManager.instance.StopSound(LobbyBehaviour.Instance.MapTheme); SoundManager.instance.StopSound(LobbyBehaviour.Instance.MapTheme);
// Adjust GameStartManager position for better UI layout
if (GameStartObj == null)
{
if (HudManager.InstanceExists)
{
GameStartObj = HudManager.Instance.transform.Find("GameStartManager");
}
}
else
{
GameStartObj.SetLocalY(-2.8f);
}
} }
[HarmonyPatch(typeof(LobbyBehaviour), nameof(LobbyBehaviour.RpcExtendLobbyTimer))] [HarmonyPatch(typeof(LobbyBehaviour), nameof(LobbyBehaviour.RpcExtendLobbyTimer))]
@@ -99,7 +114,7 @@ internal static class LobbyPatch
__instance.GameStartTextParent.SetActive(false); __instance.GameStartTextParent.SetActive(false);
__instance.StartButton.gameObject.SetActive(true); __instance.StartButton.gameObject.SetActive(true);
if (__instance.startState == GameStartManager.StartingStates.Countdown) if (__instance.startState == global::GameStartManager.StartingStates.Countdown)
{ {
// Show cancel button with countdown // Show cancel button with countdown
__instance.StartButton.buttonText.text = string.Format("{0}: {1}", Translator.GetString(StringNames.Cancel), (int)__instance.countDownTimer + 1); __instance.StartButton.buttonText.text = string.Format("{0}: {1}", Translator.GetString(StringNames.Cancel), (int)__instance.countDownTimer + 1);
@@ -118,7 +133,7 @@ internal static class LobbyPatch
if (BAUModdedSupportFlags.HasFlag(BAUModdedSupportFlags.Disable_CancelStartingGame)) return true; if (BAUModdedSupportFlags.HasFlag(BAUModdedSupportFlags.Disable_CancelStartingGame)) return true;
// If countdown is active, clicking cancels the start // If countdown is active, clicking cancels the start
if (__instance.startState == GameStartManager.StartingStates.Countdown) if (__instance.startState == global::GameStartManager.StartingStates.Countdown)
{ {
SoundManager.instance.StopSound(__instance.gameStartSound); SoundManager.instance.StopSound(__instance.gameStartSound);
__instance.ResetStartState(); __instance.ResetStartState();
@@ -128,7 +143,7 @@ internal static class LobbyPatch
// Shift+click starts game immediately (bypasses countdown) // Shift+click starts game immediately (bypasses countdown)
if (Input.GetKey(KeyCode.LeftShift)) if (Input.GetKey(KeyCode.LeftShift))
{ {
__instance.startState = GameStartManager.StartingStates.Countdown; __instance.startState = global::GameStartManager.StartingStates.Countdown;
__instance.FinallyBegin(); __instance.FinallyBegin();
return false; return false;
} }
@@ -3,7 +3,6 @@ using BetterAmongUs.Helpers;
using BetterAmongUs.Managers; using BetterAmongUs.Managers;
using BetterAmongUs.Modules; using BetterAmongUs.Modules;
using HarmonyLib; using HarmonyLib;
using UnityEngine;
namespace BetterAmongUs.Patches.Gameplay.Managers; namespace BetterAmongUs.Patches.Gameplay.Managers;
@@ -38,22 +37,10 @@ internal static class HudManagerPatch
}, 1f, shouldLog: false); }, 1f, shouldLog: false);
} }
private static GameObject? gameStart;
[HarmonyPatch(typeof(HudManager), nameof(HudManager.Update))] [HarmonyPatch(typeof(HudManager), nameof(HudManager.Update))]
[HarmonyPostfix] [HarmonyPostfix]
private static void HudManager_Update_Postfix(HudManager __instance) private static void HudManager_Update_Postfix(HudManager __instance)
{ {
// Adjust GameStartManager position for better UI layout
if (gameStart == null)
{
gameStart = GameObject.Find("GameStartManager");
}
if (gameStart != null)
{
gameStart.transform.SetLocalY(-2.8f);
}
// Manage in-game chat visibility based on settings and game state // Manage in-game chat visibility based on settings and game state
if (GameState.InGame) if (GameState.InGame)
{ {