complete two todos + minor improvements

This commit is contained in:
Az committed 2026-11-04 15:00:54 -05:00
1 parent 1c44653a8d
commit 1bd96041ee
5 files changed
+95 -67

No files matched your search

@@ -1,19 +0,0 @@
using HarmonyLib;
using GameModesEnum = AmongUs.GameOptions.GameModes;
namespace MiraAPI.Patches.GameModes;
[HarmonyPatch(typeof(CreateOptionsPicker), nameof(CreateOptionsPicker.SetGameMode))]
internal static class CreateOptionsPatch
{
public static bool Prefix(CreateOptionsPicker __instance, GameModesEnum mode)
{
if (mode <= GameModesEnum.SeekFools)
{
return true;
}
// TODO: finish this
return false;
}
}
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using HarmonyLib;
@@ -70,7 +71,7 @@ public static class OptionsMenuPatches
_currentPage = 1;
TabButtons.Clear();
float yOffset = 0;
var yOffset = 0f;
var i = 0;
var tabIdx = 0;
var page = 1;
@@ -144,9 +145,9 @@ public static class OptionsMenuPatches
UpdatePages();
}));
button.OnMouseOver = new UnityEvent();
button.OnMouseOver.AddListener((UnityAction)(() => rollover.DoMouseOver()));
button.OnMouseOver.AddListener((Action)rollover.DoMouseOver);
button.OnMouseOut = new UnityEvent();
button.OnMouseOut.AddListener((UnityAction)(() => rollover.DoMouseOut()));
button.OnMouseOut.AddListener((Action)rollover.DoMouseOut);
}
private static void ChangePage(int increase)
@@ -207,14 +208,17 @@ public static class OptionsMenuPatches
private static void CustomOpen(LocalSettingsTab tab)
{
if (tab.TabButton?.Button)
tab.TabButton!.Button.color = tab.TabAppearance.TabButtonHoverColor;
if (tab.TabButton)
{
if (tab.TabButton!.Button)
tab.TabButton.Button.color = tab.TabAppearance.TabButtonHoverColor;
if (tab.TabButton?.Rollover)
tab.TabButton!.Rollover.OutColor = tab.TabAppearance.TabButtonHoverColor;
if (tab.TabButton.Rollover)
tab.TabButton.Rollover.OutColor = tab.TabAppearance.TabButtonHoverColor;
if (tab.TabButton?.Content)
tab.TabButton!.Content.SetActive(true);
if (tab.TabButton.Content)
tab.TabButton.Content.SetActive(true);
}
if (background != null)
background.color = tab.TabAppearance.TabColor;
@@ -224,14 +228,17 @@ public static class OptionsMenuPatches
private static void CustomClose(LocalSettingsTab tab)
{
if (tab.TabButton?.Button)
tab.TabButton!.Button.color = tab.TabAppearance.TabButtonColor;
if (tab.TabButton)
{
if (tab.TabButton!.Button)
tab.TabButton.Button.color = tab.TabAppearance.TabButtonColor;
if (tab.TabButton?.Rollover)
tab.TabButton!.Rollover.OutColor = tab.TabAppearance.TabButtonColor;
if (tab.TabButton.Rollover)
tab.TabButton.Rollover.OutColor = tab.TabAppearance.TabButtonColor;
if (tab.TabButton?.Content)
tab.TabButton!.Content.SetActive(false);
if (tab.TabButton.Content)
tab.TabButton.Content.SetActive(false);
}
if (background != null)
background.color = Color.white;
@@ -1,6 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using AmongUs.GameOptions;
using BepInEx.Unity.IL2CPP.Utils.Collections;
@@ -12,6 +13,7 @@ using MiraAPI.Roles;
using MiraAPI.Translation;
using MiraAPI.Utilities;
using MiraAPI.Utilities.Assets;
using MiraAPI.Utilities.Components;
using Reactor.Networking.Rpc;
using Reactor.Utilities.Extensions;
using TMPro;
@@ -23,15 +25,24 @@ using Object = UnityEngine.Object;
namespace MiraAPI.Patches.Options;
[HarmonyPatch(typeof(RolesSettingsMenu))]
[SuppressMessage("Critical Code Smell", "S2223:Non-constant static fields should not be visible", Justification = "Is internal code. Property-level protections are not required.")]
[SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:Fields should be private", Justification = "Read above.")]
public static class RoleSettingMenuPatches
{
private static readonly Dictionary<RoleOptionsGroup, bool> RoleGroupHidden = [];
private static RoleBehaviour? currentRole;
private static List<IModdedOption>? currentRoleOptions;
internal static RoleBehaviour? CurrentRole;
internal static List<IModdedOption>? CurrentRoleOptions;
private static float scrollerNum = 0.522f;
[HarmonyPostfix]
[HarmonyPatch(nameof(RolesSettingsMenu.Awake))]
public static void OnAwake(RolesSettingsMenu __instance)
{
__instance.gameObject.AddComponent<RoleSettingsMenuUpdater>();
}
[HarmonyPostfix]
[HarmonyPatch(nameof(RolesSettingsMenu.OnEnable))]
public static void OpenPatch()
@@ -41,8 +52,8 @@ public static class RoleSettingMenuPatches
private static IEnumerator CoQuotaTabPatch(RolesSettingsMenu roleMenu)
{
currentRole = null;
currentRoleOptions = null;
CurrentRole = null;
CurrentRoleOptions = null;
roleMenu.QuotaTabSelectables.Clear();
roleMenu.roleChances.Clear();
@@ -91,7 +102,7 @@ public static class RoleSettingMenuPatches
Object.Destroy(child.gameObject);
}
yield return new WaitForEndOfFrame();
yield return null;
MenuState.Instance.QueuedRoleMenuRefresh[MenuState.Instance.CurrentModIdx] = false;
}
@@ -186,7 +197,7 @@ public static class RoleSettingMenuPatches
Object.Destroy(child.gameObject);
}
yield return new WaitForEndOfFrame();
yield return null;
var roleGroups = MenuState.Instance.CurrentMod.InternalRoles.Values.OfType<ICustomRole>()
.ToLookup(x => x.RoleOptionsGroup);
@@ -431,32 +442,12 @@ public static class RoleSettingMenuPatches
scroller.SetYBoundsMax(-scrollerNum - 2);
}
// TODO: turn this into a fixed update
// Completed: turn this into a fixed update
[HarmonyPrefix]
[HarmonyPatch(nameof(RolesSettingsMenu.Update))]
public static bool UpdatePatch(RolesSettingsMenu __instance)
{
if (MenuState.Instance.CurrentModIdx == 0) return true;
if (currentRole == null || currentRoleOptions == null) return false;
var hasImage = currentRole.RoleScreenshot != null;
var num = hasImage ? -0.872f : -1;
foreach (var opt in currentRoleOptions)
{
if (opt.OptionBehaviour == null) continue;
if (!opt.Visible.Invoke())
{
opt.OptionBehaviour.gameObject.SetActive(false);
continue;
}
opt.OptionBehaviour.transform.localPosition = new Vector3(hasImage ? 2.17f : 1.1f, num, -2f);
opt.OptionBehaviour.gameObject.SetActive(true);
num += -0.45f;
}
__instance.scrollBar.SetYBoundsMax(-num - 3);
// See RoleSettingsMenuUpdater.FixedUpdate in Utilities/Components/RoleSettingsMenuUpdater.cs
return false;
}
@@ -508,7 +499,7 @@ public static class RoleSettingMenuPatches
optBehaviour.gameObject.Destroy();
}
currentRole = role;
CurrentRole = role;
__instance.advancedSettingChildren.Clear();
// TODO: create sub groups under the role settings.
@@ -547,7 +538,7 @@ public static class RoleSettingMenuPatches
newOpt.Initialize();
}
currentRoleOptions = filteredOptions;
CurrentRoleOptions = filteredOptions;
}
[HarmonyPrefix]
+2 -2
View File
@@ -68,7 +68,7 @@ public sealed class MiraPluginManager
MiraApiPluginInfo = info;
registrationTimer.Stop();
Info($"Registering Mira API as mod in {registrationTimer.ElapsedMilliseconds}ms.");
Info($"Registered Mira API as mod in {registrationTimer.ElapsedMilliseconds}ms.");
}
IL2CPPChainloader.Instance.PluginLoad += (pluginInfo, assembly, plugin) =>
@@ -81,7 +81,7 @@ public sealed class MiraPluginManager
var registrationTimer = Stopwatch.StartNew();
RegisterPlugin(assembly, miraPlugin, pluginInfo, plugin, false);
registrationTimer.Stop();
Info($"Registering mod {pluginInfo.Metadata.Name} with Mira API in {registrationTimer.ElapsedMilliseconds}ms.");
Info($"Registered mod {pluginInfo.Metadata.Name} with Mira API in {registrationTimer.ElapsedMilliseconds}ms.");
};
IL2CPPChainloader.Instance.Finished += () =>
@@ -0,0 +1,49 @@
using System.Diagnostics.CodeAnalysis;
using MiraAPI.Patches.Options;
using Reactor.Utilities.Attributes;
using UnityEngine;
namespace MiraAPI.Utilities.Components;
/// <summary>
/// Updates the visuals of the <see cref="RolesSettingsMenu"/> in a fixed update loop.
/// </summary>
/// <param name="cppPtr">The C++ pointer to the object.</param>
[RegisterInIl2Cpp]
[SuppressMessage("Style", "IDE0051:Remove unused private members", Justification = "Unity convention.")]
public sealed class RoleSettingsMenuUpdater(nint cppPtr) : MonoBehaviour(cppPtr)
{
private RolesSettingsMenu menu;
private void Awake()
{
menu = GetComponent<RolesSettingsMenu>();
}
private void FixedUpdate()
{
if (MenuState.Instance.CurrentModIdx == 0) return;
if (menu == null || RoleSettingMenuPatches.CurrentRole == null || RoleSettingMenuPatches.CurrentRoleOptions == null) return;
var hasImage = RoleSettingMenuPatches.CurrentRole.RoleScreenshot != null;
var num = hasImage ? -0.872f : -1;
foreach (var opt in RoleSettingMenuPatches.CurrentRoleOptions)
{
var behaviour = opt.OptionBehaviour;
if (behaviour == null) continue;
if (!opt.Visible())
{
behaviour.gameObject.SetActive(false);
continue;
}
behaviour.transform.localPosition = new Vector3(hasImage ? 2.17f : 1.1f, num, -2f);
behaviour.gameObject.SetActive(true);
num += -0.45f;
}
menu.scrollBar.SetYBoundsMax(-num - 3);
}
}