From 5c2e95376d2f9f0cf7bd2c4778d75785973b2a24 Mon Sep 17 00:00:00 2001
From: XtraCube <72575280+XtraCube@users.noreply.github.com>
Date: Wed, 31 Dec 2025 22:38:01 -0500
Subject: [PATCH] add exception handling around role registration
---
MiraAPI/Roles/CustomRoleConfiguration.cs | 4 ++++
MiraAPI/Roles/CustomRoleManager.cs | 21 ++++++++++++++-------
2 files changed, 18 insertions(+), 7 deletions(-)
diff --git a/MiraAPI/Roles/CustomRoleConfiguration.cs b/MiraAPI/Roles/CustomRoleConfiguration.cs
index de02f57..a11ddc0 100644
--- a/MiraAPI/Roles/CustomRoleConfiguration.cs
+++ b/MiraAPI/Roles/CustomRoleConfiguration.cs
@@ -1,5 +1,6 @@
using AmongUs.GameOptions;
using System;
+using Il2CppInterop.Runtime.Attributes;
using MiraAPI.Patches.Freeplay;
using MiraAPI.Utilities.Assets;
using UnityEngine;
@@ -77,16 +78,19 @@ public record struct CustomRoleConfiguration
///
/// Gets or sets the Sprite used for the Role Options menu screenshot.
///
+ [HideFromIl2Cpp]
public LoadableAsset? OptionsScreenshot { get; set; } = null;
///
/// Gets or sets the Sprite used for the Role Icon.
///
+ [HideFromIl2Cpp]
public LoadableAsset? Icon { get; set; } = null;
///
/// Gets or sets the Intro sound for the Role.
///
+ [HideFromIl2Cpp]
public LoadableAsset? IntroSound { get; set; } = null;
///
diff --git a/MiraAPI/Roles/CustomRoleManager.cs b/MiraAPI/Roles/CustomRoleManager.cs
index 922765e..0bbf4eb 100644
--- a/MiraAPI/Roles/CustomRoleManager.cs
+++ b/MiraAPI/Roles/CustomRoleManager.cs
@@ -89,15 +89,22 @@ public static class CustomRoleManager
foreach (var roleType in roles)
{
- ClassInjector.RegisterTypeInIl2Cpp(roleType);
-
- var role = RegisterRole(roleType, pluginInfo);
- if (role is null)
+ try
{
- continue;
- }
+ ClassInjector.RegisterTypeInIl2Cpp(roleType);
- pluginInfo.InternalRoles.Add((ushort)role.Role, role);
+ var role = RegisterRole(roleType, pluginInfo);
+ if (role is null)
+ {
+ continue;
+ }
+
+ pluginInfo.InternalRoles.Add((ushort)role.Role, role);
+ }
+ catch (Exception ex)
+ {
+ Error($"Failed to register role type {roleType.Name}: {ex}");
+ }
}
pluginInfo.PluginConfig.Save();