add exception handling around role registration

This commit is contained in:
XtraCube committed 2025-12-31 22:38:01 -05:00
1 parent 067859b9fd
commit 5c2e95376d
2 files changed
+11

No files matched your search

+4
View File
@@ -1,5 +1,6 @@
using AmongUs.GameOptions; using AmongUs.GameOptions;
using System; using System;
using Il2CppInterop.Runtime.Attributes;
using MiraAPI.Patches.Freeplay; using MiraAPI.Patches.Freeplay;
using MiraAPI.Utilities.Assets; using MiraAPI.Utilities.Assets;
using UnityEngine; using UnityEngine;
@@ -77,16 +78,19 @@ public record struct CustomRoleConfiguration
/// <summary> /// <summary>
/// Gets or sets the Sprite used for the Role Options menu screenshot. /// Gets or sets the Sprite used for the Role Options menu screenshot.
/// </summary> /// </summary>
[HideFromIl2Cpp]
public LoadableAsset<Sprite>? OptionsScreenshot { get; set; } = null; public LoadableAsset<Sprite>? OptionsScreenshot { get; set; } = null;
/// <summary> /// <summary>
/// Gets or sets the Sprite used for the Role Icon. /// Gets or sets the Sprite used for the Role Icon.
/// </summary> /// </summary>
[HideFromIl2Cpp]
public LoadableAsset<Sprite>? Icon { get; set; } = null; public LoadableAsset<Sprite>? Icon { get; set; } = null;
/// <summary> /// <summary>
/// Gets or sets the Intro sound for the Role. /// Gets or sets the Intro sound for the Role.
/// </summary> /// </summary>
[HideFromIl2Cpp]
public LoadableAsset<AudioClip>? IntroSound { get; set; } = null; public LoadableAsset<AudioClip>? IntroSound { get; set; } = null;
/// <summary> /// <summary>
+7
View File
@@ -88,6 +88,8 @@ public static class CustomRoleManager
pluginInfo.PluginConfig.SaveOnConfigSet = false; pluginInfo.PluginConfig.SaveOnConfigSet = false;
foreach (var roleType in roles) foreach (var roleType in roles)
{
try
{ {
ClassInjector.RegisterTypeInIl2Cpp(roleType); ClassInjector.RegisterTypeInIl2Cpp(roleType);
@@ -99,6 +101,11 @@ public static class CustomRoleManager
pluginInfo.InternalRoles.Add((ushort)role.Role, role); pluginInfo.InternalRoles.Add((ushort)role.Role, role);
} }
catch (Exception ex)
{
Error($"Failed to register role type {roleType.Name}: {ex}");
}
}
pluginInfo.PluginConfig.Save(); pluginInfo.PluginConfig.Save();
pluginInfo.PluginConfig.SaveOnConfigSet = oldConfigSetting; pluginInfo.PluginConfig.SaveOnConfigSet = oldConfigSetting;