diff --git a/MiraAPI/MiraApiPlugin.cs b/MiraAPI/MiraApiPlugin.cs index 54d23ce..d68a87d 100644 --- a/MiraAPI/MiraApiPlugin.cs +++ b/MiraAPI/MiraApiPlugin.cs @@ -1,8 +1,5 @@ using System; using System.Globalization; -using System.Linq; -using System.Reflection; -using AmongUs.GameOptions; using BepInEx; using BepInEx.Configuration; using BepInEx.Unity.IL2CPP; diff --git a/MiraAPI/Patches/Menu/HatsTabPatches.cs b/MiraAPI/Patches/Menu/HatsTabPatches.cs index dc2e805..e9cebd8 100644 --- a/MiraAPI/Patches/Menu/HatsTabPatches.cs +++ b/MiraAPI/Patches/Menu/HatsTabPatches.cs @@ -2,6 +2,7 @@ using System.Collections; using System.Collections.Generic; using System.Collections.Immutable; +using System.Diagnostics.CodeAnalysis; using System.Linq; using AmongUs.Data; using HarmonyLib; @@ -38,6 +39,7 @@ public static class HatsTabPatches [HarmonyPatch(nameof(HatsTab.OnEnable))] [HarmonyPrefix] + [SuppressMessage("Style", "IDE0028:Collection initialization can be simplified", Justification = "Preview feature.")] public static bool OnEnablePrefix(HatsTab __instance) { if (!AddressablesLoader.AddressableHatsExist) diff --git a/MiraAPI/Patches/Menu/NameplatesTabPatches.cs b/MiraAPI/Patches/Menu/NameplatesTabPatches.cs index cc2778c..c105eb1 100644 --- a/MiraAPI/Patches/Menu/NameplatesTabPatches.cs +++ b/MiraAPI/Patches/Menu/NameplatesTabPatches.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Linq; using AmongUs.Data; using HarmonyLib; @@ -16,6 +17,7 @@ namespace MiraAPI.Patches.Menu; [HarmonyPatch(typeof(NameplatesTab))] public static class NameplatesTabPatches { + [SuppressMessage("Style", "IDE0028:Collection initialization can be simplified", Justification = "Preview feature.")] private static readonly SortedList> SortedNameplates = new(new ControllableComparer(["vanilla"], [], StringComparer.InvariantCulture)); private static int currentPage; diff --git a/MiraAPI/Patches/Menu/SkinsTabPatches.cs b/MiraAPI/Patches/Menu/SkinsTabPatches.cs index 3ca3578..08bfe8c 100644 --- a/MiraAPI/Patches/Menu/SkinsTabPatches.cs +++ b/MiraAPI/Patches/Menu/SkinsTabPatches.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Collections.Immutable; +using System.Diagnostics.CodeAnalysis; using System.Linq; using AmongUs.Data; using HarmonyLib; @@ -35,6 +36,7 @@ public static class SkinsTabPatches [HarmonyPatch(nameof(SkinsTab.OnEnable))] [HarmonyPrefix] + [SuppressMessage("Style", "IDE0028:Collection initialization can be simplified", Justification = "Preview feature.")] public static bool OnEnablePrefix(SkinsTab __instance) { if (!AddressablesLoader.AddressableSkinsExist) diff --git a/MiraAPI/Patches/Menu/VisorsTabPatches.cs b/MiraAPI/Patches/Menu/VisorsTabPatches.cs index 04c41d0..cc37c28 100644 --- a/MiraAPI/Patches/Menu/VisorsTabPatches.cs +++ b/MiraAPI/Patches/Menu/VisorsTabPatches.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Linq; using AmongUs.Data; using HarmonyLib; @@ -15,6 +16,7 @@ namespace MiraAPI.Patches.Menu; [HarmonyPatch(typeof(VisorsTab))] public static class VisorsTabPatches { + [SuppressMessage("Style", "IDE0028:Collection initialization can be simplified", Justification = "Preview feature.")] private static readonly SortedList> SortedVisors = new(new ControllableComparer(["vanilla"], [], StringComparer.InvariantCulture)); private static int currentPage; diff --git a/MiraAPI/Patches/Roles/RoleOptionsCollectionPatch.cs b/MiraAPI/Patches/Roles/RoleOptionsCollectionPatch.cs index 1fc0046..0e856ef 100644 --- a/MiraAPI/Patches/Roles/RoleOptionsCollectionPatch.cs +++ b/MiraAPI/Patches/Roles/RoleOptionsCollectionPatch.cs @@ -19,51 +19,54 @@ public static class RoleOptionsCollectionPatch { var assembly = Array.Find( AppDomain.CurrentDomain.GetAssemblies(), - ass => ass.GetName().Name == "Assembly-CSharp" - ); - if (assembly != null) + ass => ass.GetName().Name == "Assembly-CSharp"); + + if (assembly == null) + return; + + var compatType = typeof(RoleOptionsCollectionPatch); + BaseAssembly = assembly; + BaseTypes = AccessTools.GetTypesFromAssembly(assembly); + var collections = BaseTypes.Where(x => x.Name.Contains("RoleOptionsCollectionV")).ToArray(); + var pairings = new System.Collections.Generic.Dictionary(); + var newestId = 0; + foreach (var collection in collections) { - var compatType = typeof(RoleOptionsCollectionPatch); - BaseAssembly = assembly; - BaseTypes = AccessTools.GetTypesFromAssembly(assembly); - var collections = BaseTypes.Where(x => x.Name.Contains("RoleOptionsCollectionV")).ToArray(); - var pairings = new System.Collections.Generic.Dictionary(); - var newestId = 0; - foreach (var collection in collections) + var remainder = collection.Name.Replace("RoleOptionsCollectionV", string.Empty); + if (!int.TryParse(remainder, out var id)) { - var remainer = collection.Name.Replace("RoleOptionsCollectionV", string.Empty); - if (int.TryParse(remainer, out var id)) - { - pairings.Add(id, collection); - if (newestId < id) - { - newestId = id; - } - } + continue; } - if (pairings.TryGetValue(newestId, out var typeToGet)) + pairings.Add(id, collection); + if (newestId < id) { - CollectionsType = typeToGet; + newestId = id; } - - var anyRolesEnabledMethod = AccessTools.Method(CollectionsType, "AnyRolesEnabled"); - harmony.Patch( - anyRolesEnabledMethod, - new HarmonyMethod(AccessTools.Method(compatType, nameof(AnyRolesEnabledPrefix)))); - - var chancePerGameMethod = AccessTools.Method(CollectionsType, "GetChancePerGame"); - harmony.Patch( - chancePerGameMethod, - new HarmonyMethod(AccessTools.Method(compatType, nameof(GetChancePrefix)))); - - var numPerGameMethod = AccessTools.Method(CollectionsType, "GetNumPerGame"); - harmony.Patch( - numPerGameMethod, - new HarmonyMethod(AccessTools.Method(compatType, nameof(GetNumPrefix)))); - Info($"Patched methods for RoleOptionsCollectionV{newestId}"); } + + if (pairings.TryGetValue(newestId, out var typeToGet)) + { + CollectionsType = typeToGet; + } + + var anyRolesEnabledMethod = AccessTools.Method(CollectionsType, "AnyRolesEnabled"); + harmony.Patch( + anyRolesEnabledMethod, + new HarmonyMethod(AccessTools.Method(compatType, nameof(AnyRolesEnabledPrefix)))); + + var chancePerGameMethod = AccessTools.Method(CollectionsType, "GetChancePerGame"); + harmony.Patch( + chancePerGameMethod, + new HarmonyMethod(AccessTools.Method(compatType, nameof(GetChancePrefix)))); + + var numPerGameMethod = AccessTools.Method(CollectionsType, "GetNumPerGame"); + harmony.Patch( + numPerGameMethod, + new HarmonyMethod(AccessTools.Method(compatType, nameof(GetNumPrefix)))); + Info($"Patched methods for RoleOptionsCollectionV{newestId}"); } + /// /// This patch fixes being inlined (2025.9.9) in the original code. /// diff --git a/MiraAPI/Roles/ICustomRole.cs b/MiraAPI/Roles/ICustomRole.cs index 7af4287..0030024 100644 --- a/MiraAPI/Roles/ICustomRole.cs +++ b/MiraAPI/Roles/ICustomRole.cs @@ -9,7 +9,6 @@ using MiraAPI.Translation; using MiraAPI.Utilities; using TMPro; using UnityEngine; -using Object = UnityEngine.Object; namespace MiraAPI.Roles; diff --git a/MiraAPI/Utilities/Helpers.cs b/MiraAPI/Utilities/Helpers.cs index e3525b9..eded3d3 100644 --- a/MiraAPI/Utilities/Helpers.cs +++ b/MiraAPI/Utilities/Helpers.cs @@ -563,6 +563,17 @@ public static class Helpers // This should be patchable by mods when a vanilla role is meant to be replaced by a custom role. return false; } + + /// + /// Creates a tab in the advanced wiki. + /// + /// The guide panel to attach the tab to. + /// The name of the tab. + /// The title of the tab. + /// The description of the tab. + /// The instance of the title. + /// The instance of the description. + /// The of the tab. public static GameObject CreateAdvancedWikiTab(MatchInfoGuide guide, string objName, string title, string description, TextMeshPro titleTmp, out TextMeshPro descriptionTmp) { var obj = new GameObject(objName);