slight project cleanup

This commit is contained in:
Az committed 2026-11-04 14:12:06 -05:00
1 parent f18e375122
commit 1c44653a8d
7 files changed
+27 -37

No files matched your search

+1 -1
View File
@@ -18,7 +18,7 @@ namespace MiraAPI.GameModes;
/// </summary>
[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
{
/// <summary>
@@ -12,7 +12,7 @@ namespace MiraAPI.GameOptions.Attributes;
/// <param name="modeType">Optional parameter to specify a game mode Type.</param>
[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,
/// <summary>
/// Gets the role type of the option.
/// </summary>
protected Type? RoleType { get; private set; } = roleType;
protected Type? RoleType => roleType;
/// <summary>
/// Gets the game mode type of the option.
/// </summary>
protected Type? ModeType { get; private set; } = modeType;
protected Type? ModeType => modeType;
internal abstract IModdedOption? CreateOption(object? value, PropertyInfo property);
}
@@ -13,7 +13,7 @@ namespace MiraAPI.GameOptions.Attributes;
/// <param name="title">The title of the options.</param>
[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;
@@ -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<int, List<GameObject>> 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;
@@ -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;
/// <summary>
/// A postfix on <see cref="MainMenuManager.Awake"/> to load all the addressables registered.
@@ -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;
/// </summary>
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<int, Type>();
var baseAssembly = typeof(RoleBehaviour).Assembly;
var baseTypes = AccessTools.GetTypesFromAssembly(baseAssembly);
var collections = baseTypes.Where(x => x.Name.Contains("RoleOptionsCollectionV")).ToArray();
var pairings = new Dictionary<int, Type>();
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))));
+1 -1
View File
@@ -23,7 +23,7 @@ public class PlayerVoteData(nint cppPtr) : MonoBehaviour(cppPtr)
/// Gets the list of <see cref="CustomVote"/>s the owner has.
/// </summary>
[HideFromIl2Cpp]
public List<CustomVote> Votes { get; private set; } = [];
public List<CustomVote> Votes { get; } = [];
/// <summary>
/// Gets or sets the amount of votes the owner has left.