I cast null reference exception

This commit is contained in:
Ape committed 2026-01-23 00:41:37 +01:00
1 parent 79425e5fb8
commit 21dec84e64
4 files changed
+72 -56

No files matched your search

+14 -7
View File
@@ -14,6 +14,10 @@ internal static class ChatControllerUpdatePatch
public static void Postfix(ChatController __instance)
{
if (__instance == null || __instance.freeChatField == null || __instance.freeChatField.textArea == null || __instance.freeChatField.background == null || __instance.freeChatField.textArea.compoText == null || __instance.freeChatField.textArea.outputText == null) return;
if (__instance.quickChatField == null || __instance.quickChatField.background == null || __instance.quickChatField.text == null) return;
if (Main.DarkTheme.Value)
{
__instance.freeChatField.background.color = new Color32(40, 40, 40, byte.MaxValue);
@@ -40,6 +44,8 @@ internal static class ChatBubbleSetNamePatch
{
public static void Postfix(ChatBubble __instance, [HarmonyArgument(2)] bool voted)
{
if (__instance == null || __instance.playerInfo == null || __instance.playerInfo.Object == null || __instance.playerInfo?.Object?.Data == null || __instance.TextArea == null) return;
PlayerControl seer = PlayerControl.LocalPlayer;
PlayerControl target = __instance.playerInfo.Object;
@@ -47,6 +53,7 @@ internal static class ChatBubbleSetNamePatch
{
__instance.Background.color = new(0.1f, 0.1f, 0.1f, 1f);
__instance.TextArea.color = Color.white;
if (__instance.playerInfo.Object.Data.IsDead && Utils.InGame) __instance.Background.color = new(0.1f, 0.1f, 0.1f, 0.7f);
}
}
@@ -55,14 +62,14 @@ internal static class ChatBubbleSetNamePatch
[HarmonyPatch(typeof(ChatController), nameof(ChatController.SendChat))]
internal static class SendChatPatch
{
public static string noKcdMode = "0 Kill Cooldown:\n\nImpostors have no kill cooldown, Crewmates have low tasks\nThink fast and pay attention!";
public static string SnSModeOne = "Shift and Seek:\n\nImpostors can only kill someone while shapeshifted as them\nSabotages & Meetings = Off";
public static string SnSModeTwo = $"Crew wins by tasks/surviving {Options.CrewAutoWinsGameAfter.GetInt()}s\nImp wins by killing\nOne wrong kill = Can't kill for {Options.CantKillTime.GetInt()}s\n{Utils.BasicIntToWord(Options.MisfiresToSuicide.GetInt())} wrong kills = suicide";
public static string speedrunMode = $"Speedrun:\n\nEveryone is a crewmate The 1st player to finish tasks wins the game Game auto ends after {Options.GameAutoEndsAfter.GetInt()}s";
public static string noKcdMode => "0 Kill Cooldown:\n\nImpostors have no kill cooldown, Crewmates have low tasks\nThink fast and pay attention!";
public static string SnSModeOne => "Shift and Seek:\n\nImpostors can only kill someone while shapeshifted as them\nSabotages & Meetings = Off";
public static string SnSModeTwo => $"Crew wins by tasks/surviving {Options.CrewAutoWinsGameAfter.GetInt()}s\nImp wins by killing\nOne wrong kill = Can't kill for {Options.CantKillTime.GetInt()}s\n{Utils.BasicIntToWord(Options.MisfiresToSuicide.GetInt())} wrong kills = suicide";
public static string speedrunMode => $"Speedrun:\n\nEveryone is a crewmate The 1st player to finish tasks wins the game Game auto ends after {Options.GameAutoEndsAfter.GetInt()}s";
public static string allCommandsFull = "Commands:\n/r - Current mode description\n/0kc, /sns, /sp - Specific mode description\n/l - Shows last winner info\n/kick, /ban - Bans or kicks a player by name\n/ckick, /cban - Bans or kicks a player by color";
public static string allCommandsOne = "Commands:\n/r - Current mode description\n/0kc, /sns, /sp - Specific mode description\n/l - Shows last winner info";
public static string allCommandsTwo = "/kick, /ban - Bans or kicks a player by name\n/ckick, /cban - Bans or kicks a player by color";
public static string allCommandsFull => "Commands:\n/r - Current mode description\n/0kc, /sns, /sp - Specific mode description\n/l - Shows last winner info\n/kick, /ban - Bans or kicks a player by name\n/ckick, /cban - Bans or kicks a player by color";
public static string allCommandsOne => "Commands:\n/r - Current mode description\n/0kc, /sns, /sp - Specific mode description\n/l - Shows last winner info";
public static string allCommandsTwo => "/kick, /ban - Bans or kicks a player by name\n/ckick, /cban - Bans or kicks a player by color";
public static bool Prefix(ChatController __instance)
{
+55 -48
View File
@@ -12,22 +12,23 @@ public static class GameStartManagerUpdatePatch
public static void Prefix(GameStartManager __instance)
{
if (!GameStartManager.InstanceExists || AmongUsClient.Instance == null || !AmongUsClient.Instance.AmHost) return;
if (__instance == null) return;
if (AmongUsClient.Instance == null || !AmongUsClient.Instance.AmHost) return;
var data = GameData.Instance;
// Only run our custom logic when safe
if (__instance.StartButton == null || __instance.GameStartText == null) return;
__instance.MinPlayers = 1;
if (Main.AutoStart.Value && OnGameJoinedPatch.AutoStartCheck && GameStartManager.InstanceExists && GameStartManager.Instance.startState != GameStartManager.StartingStates.Countdown && data != null && data.PlayerCount >= Options.PlayerAutoStart.GetInt())
if (Main.AutoStart.Value &&
OnGameJoinedPatch.AutoStartCheck &&
GameStartManager.InstanceExists &&
__instance.startState != GameStartManager.StartingStates.Countdown &&
GameData.Instance?.PlayerCount >= Options.PlayerAutoStart.GetInt())
{
GameStartManager.Instance.startState = GameStartManager.StartingStates.Countdown;
GameStartManager.Instance.countDownTimer = Options.AutoStartTimer.GetFloat();
var sb = GameStartManager.Instance?.StartButton;
if (sb != null)
{
sb.gameObject.SetActive(false);
}
__instance.startState = GameStartManager.StartingStates.Countdown;
__instance.countDownTimer = Options.AutoStartTimer.GetFloat();
__instance.StartButton.gameObject.SetActive(false);
Autostarting = true;
}
@@ -35,7 +36,6 @@ public static class GameStartManagerUpdatePatch
{
__instance.countDownTimer = Options.StartCountdown.GetInt();
CustomTimerApplied = true;
}
if (__instance.startState != GameStartManager.StartingStates.Countdown)
@@ -66,54 +66,61 @@ public static class GameStartManagerUpdatePatch
if (__instance.GameStartText != null)
{
__instance.GameStartText.transform.localPosition = new Vector3(__instance.GameStartText.transform.localPosition.x, 2f, __instance.GameStartText.transform.localPosition.z);
__instance.GameStartText.transform.localPosition =
new Vector3(__instance.GameStartText.transform.localPosition.x, 2f, __instance.GameStartText.transform.localPosition.z);
}
if (GameStartManagerStartPatch.cancelButton != null)
{
GameStartManagerStartPatch.cancelButton.gameObject.SetActive(__instance.startState == GameStartManager.StartingStates.Countdown);
GameStartManagerStartPatch.cancelButton.gameObject.SetActive(
__instance.startState == GameStartManager.StartingStates.Countdown);
}
}
}
[HarmonyPatch(typeof(GameStartManager), nameof(GameStartManager.Start))]
public class GameStartManagerStartPatch
{
public static TextMeshPro warningText;
private static Vector3 GameStartTextlocalPosition;
public static PassiveButton cancelButton;
public static void Postfix(GameStartManager __instance)
[HarmonyPatch(typeof(GameStartManager), nameof(GameStartManager.Start))]
public class GameStartManagerStartPatch
{
warningText = UnityEngine.Object.Instantiate(__instance.GameStartText, __instance.transform.parent);
warningText.name = "WarningText";
warningText.transform.localPosition = new(0f, __instance.transform.localPosition.y + 3f, -1f);
warningText.gameObject.SetActive(false);
public static TextMeshPro warningText;
public static PassiveButton cancelButton;
cancelButton = UnityEngine.Object.Instantiate(__instance.StartButton, __instance.transform);
cancelButton.name = "CancelButton";
var cancelLabel = cancelButton.buttonText;
cancelLabel.DestroyTranslator();
cancelLabel.text = "Cancel";
//cancelButton.transform.localScale = new(0.5f, 0.5f, 1f);
var cancelButtonInactiveRenderer = cancelButton.inactiveSprites.GetComponent<SpriteRenderer>();
cancelButtonInactiveRenderer.color = new(0.8f, 0f, 0f, 1f);
var cancelButtonActiveRenderer = cancelButton.activeSprites.GetComponent<SpriteRenderer>();
cancelButtonActiveRenderer.color = Color.red;
var cancelButtonInactiveShine = cancelButton.inactiveSprites.transform.Find("Shine");
if (cancelButtonInactiveShine)
public static bool Prefix(GameStartManager __instance)
{
cancelButtonInactiveShine.gameObject.SetActive(false);
// If we are not in lobby, skip vanilla Start
if (__instance == null) return false;
if (!Utils.IsLobby) return false;
// Ensure all required objects exist
if (__instance.GameStartText == null || __instance.StartButton == null)
return false;
return true;
}
cancelButton.activeTextColor = cancelButton.inactiveTextColor = Color.white;
//cancelButton.transform.localPosition = new(2f, 0.13f, 0f);
GameStartTextlocalPosition = __instance.GameStartText.transform.localPosition;
cancelButton.OnClick = new();
cancelButton.OnClick.AddListener((UnityEngine.Events.UnityAction)(() =>
public static void Postfix(GameStartManager __instance)
{
__instance.ResetStartState();
}));
cancelButton.gameObject.SetActive(false);
if (__instance == null || !Utils.IsLobby) return;
warningText = UnityEngine.Object.Instantiate(__instance.GameStartText, __instance.transform.parent);
warningText.name = "WarningText";
warningText.transform.localPosition = new Vector3(0f, __instance.transform.localPosition.y + 3f, -1f);
warningText.gameObject.SetActive(false);
cancelButton = UnityEngine.Object.Instantiate(__instance.StartButton, __instance.transform);
cancelButton.name = "CancelButton";
var cancelLabel = cancelButton.buttonText;
cancelLabel.DestroyTranslator();
cancelLabel.text = "Cancel";
cancelButton.activeTextColor = cancelButton.inactiveTextColor = Color.white;
cancelButton.gameObject.SetActive(false);
cancelButton.OnClick = new();
cancelButton.OnClick.AddListener((UnityEngine.Events.UnityAction)(() =>
{
__instance.ResetStartState();
}));
}
}
}
+2
View File
@@ -14,6 +14,8 @@ internal static class OnGameJoinedPatch
public static bool AutoStartCheck;
public static void Postfix()
{
Logger.Info(" -------- JOINED GAME --------", "OnGameJoined");
if (!AmongUsClient.Instance.AmHost) return;
WaitingForChat = false;
+1 -1
View File
@@ -21,7 +21,7 @@ internal static class AddVotePatch
Logger.Info($" Kicked {target.Data.PlayerName}, {target.Data.FriendCode}", "KickPatch");
}
return false;
return true;
}
}