From 55555604f3cd55540a77c625341b088884194e08 Mon Sep 17 00:00:00 2001
From: XtraCube <72575280+XtraCube@users.noreply.github.com>
Date: Sat, 28 Jun 2025 22:57:04 -0400
Subject: [PATCH] error proof buttons
---
MiraAPI/Patches/Hud/ButtonResetPatches.cs | 36 ++++++++---------------
MiraAPI/Patches/HudManagerPatches.cs | 19 ++++++++++--
MiraAPI/Patches/PlayerControlPatches.cs | 16 +++++++---
3 files changed, 41 insertions(+), 30 deletions(-)
diff --git a/MiraAPI/Patches/Hud/ButtonResetPatches.cs b/MiraAPI/Patches/Hud/ButtonResetPatches.cs
index 0859bea..29b190d 100644
--- a/MiraAPI/Patches/Hud/ButtonResetPatches.cs
+++ b/MiraAPI/Patches/Hud/ButtonResetPatches.cs
@@ -1,37 +1,25 @@
using HarmonyLib;
using MiraAPI.Hud;
+using Reactor.Utilities;
namespace MiraAPI.Patches.Hud;
-///
-/// Reset button patches.
-///
-[HarmonyPatch]
+[HarmonyPatch(typeof(MeetingHud), nameof(MeetingHud.Start))]
+[HarmonyPatch(typeof(ExileController), nameof(ExileController.ReEnableGameplay))]
public static class ButtonResetPatches
{
- ///
- /// Resets the cooldown and effect of all custom buttons when the meeting starts.
- ///
- [HarmonyPostfix]
- [HarmonyPatch(typeof(MeetingHud), nameof(MeetingHud.Start))]
- public static void MeetingHudStartPostfix()
+ public static void Postfix()
{
foreach (var customActionButton in CustomButtonManager.CustomButtons)
{
- customActionButton.ResetCooldownAndOrEffect();
- }
- }
-
- ///
- /// Resets the cooldown and effect of all custom buttons after the exile screen is closed.
- ///
- [HarmonyPostfix]
- [HarmonyPatch(typeof(ExileController), nameof(ExileController.ReEnableGameplay))]
- public static void ExileControllerReEnableGameplayPostfix()
- {
- foreach (var customActionButton in CustomButtonManager.CustomButtons)
- {
- customActionButton.ResetCooldownAndOrEffect();
+ try
+ {
+ customActionButton.ResetCooldownAndOrEffect();
+ }
+ catch (System.Exception ex)
+ {
+ Logger.Error($"Error resetting cooldown and effect for button {customActionButton.GetType().Name}: {ex}");
+ }
}
}
}
diff --git a/MiraAPI/Patches/HudManagerPatches.cs b/MiraAPI/Patches/HudManagerPatches.cs
index 27a8026..14c2444 100644
--- a/MiraAPI/Patches/HudManagerPatches.cs
+++ b/MiraAPI/Patches/HudManagerPatches.cs
@@ -1,5 +1,6 @@
using HarmonyLib;
using MiraAPI.Hud;
+using Reactor.Utilities;
using Reactor.Utilities.Extensions;
using UnityEngine;
using Object = UnityEngine.Object;
@@ -77,7 +78,14 @@ public static class HudManagerPatches
continue;
}
- button.CreateButton(location);
+ try
+ {
+ button.CreateButton(location);
+ }
+ catch (System.Exception e)
+ {
+ Logger.Error($"Failed to create custom button {button.GetType().Name}: {e}");
+ }
}
gridArrange.Start();
@@ -105,7 +113,14 @@ public static class HudManagerPatches
foreach (var button in CustomButtonManager.CustomButtons)
{
- button.SetActive(isActive, role);
+ try
+ {
+ button.SetActive(isActive, role);
+ }
+ catch (System.Exception e)
+ {
+ Logger.Error($"Failed to set custom button {button.GetType().Name} active: {e}");
+ }
}
}
}
diff --git a/MiraAPI/Patches/PlayerControlPatches.cs b/MiraAPI/Patches/PlayerControlPatches.cs
index c93aa6d..a0b88cd 100644
--- a/MiraAPI/Patches/PlayerControlPatches.cs
+++ b/MiraAPI/Patches/PlayerControlPatches.cs
@@ -7,6 +7,7 @@ using MiraAPI.Hud;
using MiraAPI.Modifiers;
using MiraAPI.Utilities;
using MiraAPI.Voting;
+using Reactor.Utilities;
using Reactor.Utilities.Extensions;
namespace MiraAPI.Patches;
@@ -94,12 +95,19 @@ internal static class PlayerControlPatches
continue;
}
- if (!button.Enabled(__instance.Data?.Role))
+ try
{
- continue;
- }
+ if (!button.Enabled(__instance.Data?.Role))
+ {
+ continue;
+ }
- button.FixedUpdateHandler(__instance);
+ button.FixedUpdateHandler(__instance);
+ }
+ catch (System.Exception e)
+ {
+ Logger.Error($"Failed to update custom button {button.GetType().Name}: {e}");
+ }
}
}
}