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
+18 -7

No files matched your search

+4
View File
@@ -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
/// <summary>
/// Gets or sets the Sprite used for the Role Options menu screenshot.
/// </summary>
[HideFromIl2Cpp]
public LoadableAsset<Sprite>? OptionsScreenshot { get; set; } = null;
/// <summary>
/// Gets or sets the Sprite used for the Role Icon.
/// </summary>
[HideFromIl2Cpp]
public LoadableAsset<Sprite>? Icon { get; set; } = null;
/// <summary>
/// Gets or sets the Intro sound for the Role.
/// </summary>
[HideFromIl2Cpp]
public LoadableAsset<AudioClip>? IntroSound { get; set; } = null;
/// <summary>
+14 -7
View File
@@ -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();