From 1c44653a8d752c194f3256064f22a18786512e1d Mon Sep 17 00:00:00 2001 From: Az <56699741+AlchlcDvl@users.noreply.github.com> Date: Wed, 4 Nov 2026 14:12:06 -0500 Subject: [PATCH] slight project cleanup --- MiraAPI/GameModes/GameModeOption.cs | 2 +- .../Attributes/ModdedOptionAttribute.cs | 6 ++-- .../OptionList/ModdedOptionListAttribute.cs | 2 +- .../LocalSettings/OptionsMenuPatches.cs | 13 ++----- .../Patches/Menu/MainMenuManagerPatches.cs | 5 ++- .../Roles/RoleOptionsCollectionPatch.cs | 34 ++++++++----------- MiraAPI/Voting/PlayerVoteData.cs | 2 +- 7 files changed, 27 insertions(+), 37 deletions(-) diff --git a/MiraAPI/GameModes/GameModeOption.cs b/MiraAPI/GameModes/GameModeOption.cs index 79fccb28..254c043c 100644 --- a/MiraAPI/GameModes/GameModeOption.cs +++ b/MiraAPI/GameModes/GameModeOption.cs @@ -18,7 +18,7 @@ namespace MiraAPI.GameModes; /// [HarmonyPatch] [SuppressMessage("Critical Code Smell", "S2223:Non-constant static fields should not be visible", Justification = "Internal behaviour that does not need property-level validation.")] -[SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:Fields should be private", Justification = "Read above.")] // why so many warnings??? +[SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:Fields should be private", Justification = "Read above.")] public static class GameModeOption { /// diff --git a/MiraAPI/GameOptions/Attributes/ModdedOptionAttribute.cs b/MiraAPI/GameOptions/Attributes/ModdedOptionAttribute.cs index 2a77afa6..79d5a3c3 100644 --- a/MiraAPI/GameOptions/Attributes/ModdedOptionAttribute.cs +++ b/MiraAPI/GameOptions/Attributes/ModdedOptionAttribute.cs @@ -12,7 +12,7 @@ namespace MiraAPI.GameOptions.Attributes; /// Optional parameter to specify a game mode Type. [AttributeUsage(AttributeTargets.Property)] [SuppressMessage("Critical Code Smell", "S2223:Non-constant static fields should not be visible", Justification = "Internal behaviour that does not need property-level validation.")] -[SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:Fields should be private", Justification = "Read above.")] // why so many warnings??? +[SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:Fields should be private", Justification = "Read above.")] public abstract class ModdedOptionAttribute(string title, Type? roleType = null, Type? modeType = null) : PropertyOptionAttribute { internal IModdedOption? HolderOption; @@ -26,12 +26,12 @@ public abstract class ModdedOptionAttribute(string title, Type? roleType = null, /// /// Gets the role type of the option. /// - protected Type? RoleType { get; private set; } = roleType; + protected Type? RoleType => roleType; /// /// Gets the game mode type of the option. /// - protected Type? ModeType { get; private set; } = modeType; + protected Type? ModeType => modeType; internal abstract IModdedOption? CreateOption(object? value, PropertyInfo property); } diff --git a/MiraAPI/GameOptions/Attributes/OptionList/ModdedOptionListAttribute.cs b/MiraAPI/GameOptions/Attributes/OptionList/ModdedOptionListAttribute.cs index f4d6933e..6881fcb3 100644 --- a/MiraAPI/GameOptions/Attributes/OptionList/ModdedOptionListAttribute.cs +++ b/MiraAPI/GameOptions/Attributes/OptionList/ModdedOptionListAttribute.cs @@ -13,7 +13,7 @@ namespace MiraAPI.GameOptions.Attributes; /// The title of the options. [AttributeUsage(AttributeTargets.Property)] [SuppressMessage("Critical Code Smell", "S2223:Non-constant static fields should not be visible", Justification = "Internal behaviour that does not need property-level validation.")] -[SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:Fields should be private", Justification = "Read above.")] // why so many warnings??? +[SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:Fields should be private", Justification = "Read above.")] public abstract class ModdedOptionListAttribute(string title) : PropertyOptionAttribute { internal IModdedOptionList? HolderOptionList; diff --git a/MiraAPI/Patches/LocalSettings/OptionsMenuPatches.cs b/MiraAPI/Patches/LocalSettings/OptionsMenuPatches.cs index 6b64159e..9e043cf6 100644 --- a/MiraAPI/Patches/LocalSettings/OptionsMenuPatches.cs +++ b/MiraAPI/Patches/LocalSettings/OptionsMenuPatches.cs @@ -12,21 +12,14 @@ using UnityEngine.UI; namespace MiraAPI.Patches.LocalSettings; [HarmonyPatch(typeof(OptionsMenuBehaviour))] +[SuppressMessage("Critical Code Smell", "S2223:Non-constant static fields should not be visible", Justification = "Internal behaviour that does not need property-level validation.")] +[SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:Fields should be private", Justification = "Read above.")] public static class OptionsMenuPatches { private static readonly Dictionary> TabButtons = []; private static int _currentPage = 1; - internal static OptionsMenuBehaviour? Instance { get; private set; } - - [SuppressMessage( - "Critical Code Smell", - "S2223:Non-constant static fields should not be visible", - Justification = "Internal behaviour that does not need property-level validation.")] - [SuppressMessage( - "StyleCop.CSharp.MaintainabilityRules", - "SA1401:Fields should be private", - Justification = "Read above.")] + internal static OptionsMenuBehaviour? Instance; internal static BoxCollider2D MaskCollider = null!; private static SpriteRenderer? background; diff --git a/MiraAPI/Patches/Menu/MainMenuManagerPatches.cs b/MiraAPI/Patches/Menu/MainMenuManagerPatches.cs index aff0906a..379bdcb6 100644 --- a/MiraAPI/Patches/Menu/MainMenuManagerPatches.cs +++ b/MiraAPI/Patches/Menu/MainMenuManagerPatches.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Diagnostics.CodeAnalysis; using HarmonyLib; using MiraAPI.LocalSettings; using Reactor.Utilities; @@ -13,7 +14,9 @@ namespace MiraAPI.Patches.Menu; [HarmonyPatch(typeof(MainMenuManager))] public static class MainMenuManagerPatches { - internal static bool NeedsDeepDestroy { get; private set; } + [SuppressMessage("Critical Code Smell", "S2223:Non-constant static fields should not be visible", Justification = "Internal behaviour that does not need property-level validation.")] + [SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:Fields should be private", Justification = "Read above.")] + internal static bool NeedsDeepDestroy; /// /// A postfix on to load all the addressables registered. diff --git a/MiraAPI/Patches/Roles/RoleOptionsCollectionPatch.cs b/MiraAPI/Patches/Roles/RoleOptionsCollectionPatch.cs index 0e856eff..84265321 100644 --- a/MiraAPI/Patches/Roles/RoleOptionsCollectionPatch.cs +++ b/MiraAPI/Patches/Roles/RoleOptionsCollectionPatch.cs @@ -1,6 +1,6 @@ using System; +using System.Collections.Generic; using System.Linq; -using System.Reflection; using AmongUs.GameOptions; using HarmonyLib; using MiraAPI.Roles; @@ -12,24 +12,14 @@ namespace MiraAPI.Patches.Roles; /// public static class RoleOptionsCollectionPatch { - internal static Assembly BaseAssembly { get; private set; } - internal static Type[] BaseTypes { get; private set; } - internal static Type CollectionsType { get; private set; } public static void PatchRoleMethods(Harmony harmony) { - var assembly = Array.Find( - AppDomain.CurrentDomain.GetAssemblies(), - 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 baseAssembly = typeof(RoleBehaviour).Assembly; + var baseTypes = AccessTools.GetTypesFromAssembly(baseAssembly); + var collections = baseTypes.Where(x => x.Name.Contains("RoleOptionsCollectionV")).ToArray(); + var pairings = new Dictionary(); var newestId = 0; + foreach (var collection in collections) { var remainder = collection.Name.Replace("RoleOptionsCollectionV", string.Empty); @@ -45,22 +35,26 @@ public static class RoleOptionsCollectionPatch } } + Type? collectionsType = null; + if (pairings.TryGetValue(newestId, out var typeToGet)) { - CollectionsType = typeToGet; + collectionsType = typeToGet; } - var anyRolesEnabledMethod = AccessTools.Method(CollectionsType, "AnyRolesEnabled"); + var compatType = typeof(RoleOptionsCollectionPatch); + + var anyRolesEnabledMethod = AccessTools.Method(collectionsType, "AnyRolesEnabled"); harmony.Patch( anyRolesEnabledMethod, new HarmonyMethod(AccessTools.Method(compatType, nameof(AnyRolesEnabledPrefix)))); - var chancePerGameMethod = AccessTools.Method(CollectionsType, "GetChancePerGame"); + var chancePerGameMethod = AccessTools.Method(collectionsType, "GetChancePerGame"); harmony.Patch( chancePerGameMethod, new HarmonyMethod(AccessTools.Method(compatType, nameof(GetChancePrefix)))); - var numPerGameMethod = AccessTools.Method(CollectionsType, "GetNumPerGame"); + var numPerGameMethod = AccessTools.Method(collectionsType, "GetNumPerGame"); harmony.Patch( numPerGameMethod, new HarmonyMethod(AccessTools.Method(compatType, nameof(GetNumPrefix)))); diff --git a/MiraAPI/Voting/PlayerVoteData.cs b/MiraAPI/Voting/PlayerVoteData.cs index 5fe32ee7..ad07aeb1 100644 --- a/MiraAPI/Voting/PlayerVoteData.cs +++ b/MiraAPI/Voting/PlayerVoteData.cs @@ -23,7 +23,7 @@ public class PlayerVoteData(nint cppPtr) : MonoBehaviour(cppPtr) /// Gets the list of s the owner has. /// [HideFromIl2Cpp] - public List Votes { get; private set; } = []; + public List Votes { get; } = []; /// /// Gets or sets the amount of votes the owner has left.