From 6604fb345afc8dfe46a63c673068061f9f380a1b Mon Sep 17 00:00:00 2001 From: XtraCube <72575280+XtraCube@users.noreply.github.com> Date: Fri, 23 Aug 2024 15:18:06 -0400 Subject: [PATCH] make null checks on unity objects better --- MiraAPI/GameOptions/OptionTypes/ModdedEnumOption.cs | 2 +- MiraAPI/GameOptions/OptionTypes/ModdedNumberOption.cs | 2 +- MiraAPI/GameOptions/OptionTypes/ModdedStringOption.cs | 2 +- MiraAPI/GameOptions/OptionTypes/ModdedToggleOption.cs | 2 +- MiraAPI/Patches/HudManagerPatches.cs | 4 ++-- MiraAPI/Patches/Roles/NameTagPatch.cs | 2 +- MiraAPI/Patches/Roles/RoleManagerPatches.cs | 2 +- MiraAPI/Patches/Roles/TaskPanelPatch.cs | 2 +- 8 files changed, 9 insertions(+), 9 deletions(-) diff --git a/MiraAPI/GameOptions/OptionTypes/ModdedEnumOption.cs b/MiraAPI/GameOptions/OptionTypes/ModdedEnumOption.cs index 96499b56..30de2656 100644 --- a/MiraAPI/GameOptions/OptionTypes/ModdedEnumOption.cs +++ b/MiraAPI/GameOptions/OptionTypes/ModdedEnumOption.cs @@ -63,7 +63,7 @@ public class ModdedEnumOption : ModdedOption public override void OnValueChanged(int newValue) { DestroyableSingleton.Instance.Notifier.AddSettingsChangeMessage(StringName, Data.GetValueString(newValue), false); - if (OptionBehaviour is null) + if (!OptionBehaviour) { return; } diff --git a/MiraAPI/GameOptions/OptionTypes/ModdedNumberOption.cs b/MiraAPI/GameOptions/OptionTypes/ModdedNumberOption.cs index a9593132..51e350e8 100644 --- a/MiraAPI/GameOptions/OptionTypes/ModdedNumberOption.cs +++ b/MiraAPI/GameOptions/OptionTypes/ModdedNumberOption.cs @@ -90,7 +90,7 @@ public class ModdedNumberOption : ModdedOption Value = Mathf.Clamp(newValue, Min, Max); DestroyableSingleton.Instance.Notifier.AddSettingsChangeMessage(StringName, Data.GetValueString(Value), false); - if (OptionBehaviour is null) + if (!OptionBehaviour) { return; } diff --git a/MiraAPI/GameOptions/OptionTypes/ModdedStringOption.cs b/MiraAPI/GameOptions/OptionTypes/ModdedStringOption.cs index be6e2d1f..484126f2 100644 --- a/MiraAPI/GameOptions/OptionTypes/ModdedStringOption.cs +++ b/MiraAPI/GameOptions/OptionTypes/ModdedStringOption.cs @@ -63,7 +63,7 @@ public class ModdedStringOption : ModdedOption public override void OnValueChanged(int newValue) { DestroyableSingleton.Instance.Notifier.AddSettingsChangeMessage(StringName, Data.GetValueString(newValue), false); - if (OptionBehaviour is null) + if (!OptionBehaviour) { return; } diff --git a/MiraAPI/GameOptions/OptionTypes/ModdedToggleOption.cs b/MiraAPI/GameOptions/OptionTypes/ModdedToggleOption.cs index 60683eda..a29e6482 100644 --- a/MiraAPI/GameOptions/OptionTypes/ModdedToggleOption.cs +++ b/MiraAPI/GameOptions/OptionTypes/ModdedToggleOption.cs @@ -55,7 +55,7 @@ public class ModdedToggleOption : ModdedOption public override void OnValueChanged(bool newValue) { DestroyableSingleton.Instance.Notifier.AddSettingsChangeMessage(StringName, newValue ? "On" : "Off", false); - if (OptionBehaviour is null) + if (!OptionBehaviour) { return; } diff --git a/MiraAPI/Patches/HudManagerPatches.cs b/MiraAPI/Patches/HudManagerPatches.cs index 1b60a8ce..7631523b 100644 --- a/MiraAPI/Patches/HudManagerPatches.cs +++ b/MiraAPI/Patches/HudManagerPatches.cs @@ -40,7 +40,7 @@ public static class HudManagerPatches if (customRole.SetTabText() != null) { - if (_roleTab == null) + if (!_roleTab) { _roleTab = CustomRoleManager.CreateRoleTab(customRole); } @@ -114,7 +114,7 @@ public static class HudManagerPatches [HarmonyPatch(nameof(HudManager.SetHudActive), typeof(PlayerControl), typeof(RoleBehaviour), typeof(bool))] public static void SetHudActivePostfix(HudManager __instance, [HarmonyArgument(0)] PlayerControl player, [HarmonyArgument(1)] RoleBehaviour roleBehaviour, [HarmonyArgument(2)] bool isActive) { - if (player.Data == null) + if (!player.Data) { return; } diff --git a/MiraAPI/Patches/Roles/NameTagPatch.cs b/MiraAPI/Patches/Roles/NameTagPatch.cs index 929ccaf9..b4271129 100644 --- a/MiraAPI/Patches/Roles/NameTagPatch.cs +++ b/MiraAPI/Patches/Roles/NameTagPatch.cs @@ -23,7 +23,7 @@ public static class NameTagPatch return true; } - if (PlayerControl.LocalPlayer == null || PlayerControl.LocalPlayer.Data == null || PlayerControl.LocalPlayer.Data.Role == null || otherPlayerRole == null) + if (!PlayerControl.LocalPlayer || !PlayerControl.LocalPlayer.Data || !PlayerControl.LocalPlayer.Data.Role || !otherPlayerRole) { __result = Color.white; } diff --git a/MiraAPI/Patches/Roles/RoleManagerPatches.cs b/MiraAPI/Patches/Roles/RoleManagerPatches.cs index a7cd8676..e1139dd9 100644 --- a/MiraAPI/Patches/Roles/RoleManagerPatches.cs +++ b/MiraAPI/Patches/Roles/RoleManagerPatches.cs @@ -12,7 +12,7 @@ public static class RoleManagerPatches [HarmonyPatch(nameof(RoleManager.AssignRoleOnDeath))] public static bool AssignRoleOnDeath(RoleManager __instance, [HarmonyArgument(0)] PlayerControl plr) { - if (plr == null || !plr.Data.IsDead) + if (!plr || !plr.Data.IsDead) { return false; } diff --git a/MiraAPI/Patches/Roles/TaskPanelPatch.cs b/MiraAPI/Patches/Roles/TaskPanelPatch.cs index 24c2a759..e93ab100 100644 --- a/MiraAPI/Patches/Roles/TaskPanelPatch.cs +++ b/MiraAPI/Patches/Roles/TaskPanelPatch.cs @@ -35,7 +35,7 @@ public static class TaskPanelPatch vector2.x += vector.x * 2f; __instance.tab.transform.localPosition = vector2; - if (GameManager.Instance == null) + if (!GameManager.Instance) { return false; }