cleaning code is a sisyphean task

This commit is contained in:
Az committed 2026-09-24 20:27:19 -04:00
1 parent 458ca6e13d
commit 832d9fe7eb
8 files changed
+59 -41

No files matched your search

-3
View File
@@ -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;
+2
View File
@@ -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)
@@ -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<string, List<NamePlateData>> SortedNameplates = new(new ControllableComparer<string>(["vanilla"], [], StringComparer.InvariantCulture));
private static int currentPage;
+2
View File
@@ -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)
+2
View File
@@ -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<string, List<VisorData>> SortedVisors = new(new ControllableComparer<string>(["vanilla"], [], StringComparer.InvariantCulture));
private static int currentPage;
@@ -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<int, Type>();
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<int, Type>();
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}");
}
/// <summary>
/// This patch fixes <see cref="RoleOptionsCollectionV11.GetNumPerGame(RoleTypes)"/> being inlined (2025.9.9) in the original code.
/// </summary>
-1
View File
@@ -9,7 +9,6 @@ using MiraAPI.Translation;
using MiraAPI.Utilities;
using TMPro;
using UnityEngine;
using Object = UnityEngine.Object;
namespace MiraAPI.Roles;
+11
View File
@@ -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;
}
/// <summary>
/// Creates a tab in the advanced wiki.
/// </summary>
/// <param name="guide">The guide panel to attach the tab to.</param>
/// <param name="objName">The name of the tab.</param>
/// <param name="title">The title of the tab.</param>
/// <param name="description">The description of the tab.</param>
/// <param name="titleTmp">The <see cref="TextMeshPro"/> instance of the title.</param>
/// <param name="descriptionTmp">The <see cref="TextMeshPro"/> instance of the description.</param>
/// <returns>The <see cref="GameObject"/> of the tab.</returns>
public static GameObject CreateAdvancedWikiTab(MatchInfoGuide guide, string objName, string title, string description, TextMeshPro titleTmp, out TextMeshPro descriptionTmp)
{
var obj = new GameObject(objName);