diff --git a/MiraAPI/GameModes/AbstractGameMode.cs b/MiraAPI/GameModes/AbstractGameMode.cs
index 83448394..8f90de2b 100644
--- a/MiraAPI/GameModes/AbstractGameMode.cs
+++ b/MiraAPI/GameModes/AbstractGameMode.cs
@@ -77,6 +77,8 @@ public abstract class AbstractGameMode : IOptionable
///
public virtual float DefaultImpostorKillCooldown => GameOptionsManager.Instance.CurrentGameOptions.GetFloat(FloatOptionNames.KillCooldown);
+ internal StringNames StringName { get; set; }
+
///
/// Called on GameManager.GetBodyType().
///
diff --git a/MiraAPI/GameModes/CustomGameModeManager.cs b/MiraAPI/GameModes/CustomGameModeManager.cs
index d5678012..acb0f51b 100644
--- a/MiraAPI/GameModes/CustomGameModeManager.cs
+++ b/MiraAPI/GameModes/CustomGameModeManager.cs
@@ -44,9 +44,10 @@ public static class CustomGameModeManager
if (mode.HideMode)
return true;
- IdToModeMap.Add(GetNextId(), mode);
- pluginInfo.GameModes.Add(lastId, mode);
- mode.ID = lastId;
+ var id = GetNextId();
+ mode.ID = id;
+ IdToModeMap.Add(id, mode);
+ pluginInfo.GameModes.Add(id, mode);
GameModeOption.AddOption(mode);
return true;
}
@@ -107,34 +108,31 @@ public static class CustomGameModeManager
internal static void RegisterDefaultMode()
{
- var defaultMode = new ClassicMode();
+ var defaultMode = new ClassicMode { ID = 0 };
IdToModeMap.Add(0, defaultMode);
+ GameModeOption.AddOption(defaultMode);
- // no need to add to game mode option as it already contains it
- // because we cannot have the option be created with no values
- defaultMode.ID = 0;
- var hnsMode = new HideAndSeekMode();
+ var hnsMode = new HideAndSeekMode() { ID = 1 };
if (hnsMode.HideMode)
return;
IdToModeMap.Add(1, hnsMode);
- hnsMode.ID = 1;
GameModeOption.AddOption(hnsMode);
lastId++;
}
internal static void GetAndSetGameMode()
{
- var id = (uint)GameModeOption.Value;
+ var index = GameModeOption.Value;
- if (IdToModeMap.TryGetValue(id, out var mode))
+ if ((uint)index < (uint)GameModeOption.Values.Count)
{
- ActiveMode = mode;
+ ActiveMode = GameModeOption.Values[index];
return;
}
ActiveMode = IdToModeMap[0];
- Warning($"Unable to find game mode of id {id}!");
+ Warning($"Unable to find game mode at index {index}!");
}
}
diff --git a/MiraAPI/GameModes/GameModeOption.cs b/MiraAPI/GameModes/GameModeOption.cs
index 79fccb28..a9c3bcbb 100644
--- a/MiraAPI/GameModes/GameModeOption.cs
+++ b/MiraAPI/GameModes/GameModeOption.cs
@@ -1,6 +1,5 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
-using System.Linq;
using HarmonyLib;
using MiraAPI.GameOptions;
using MiraAPI.Networking;
@@ -18,7 +17,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
{
///
@@ -27,113 +26,63 @@ public static class GameModeOption
///
public static int Value
{
- get =>
- OptionBehaviour != null
- ? OptionBehaviour.GetInt()
- : LastValue;
+ get => OptionBehaviour != null
+ ? OptionBehaviour.GetInt()
+ : LastValue;
private set
{
LastValue = value;
+
if (OptionBehaviour == null)
return;
+
OptionBehaviour.Value = value;
OptionBehaviour.UpdateValue();
- LastValue = value;
}
}
internal static readonly StringNames GamemodeName = MiraLocaleManager.GetOrCreateLocaleString("MiraApi.Gamemode");
internal static readonly StringNames CustomName = MiraLocaleManager.GetOrCreateLocaleString("Custom");
- internal static readonly Dictionary Values = new()
- {
- [0] = MiraLocaleManager.GetOrCreateLocaleString("MiraApi.Gamemode.Classic"),
- };
+ internal static readonly List Values = [];
internal static StringOption OptionBehaviour = null!;
internal static int LastValue;
internal static void AddOption(AbstractGameMode mode)
{
- if (!Values.ContainsKey(mode.ID))
- Values.Add(mode.ID, MiraLocaleManager.GetOrCreateLocaleString(mode.Name));
+ mode.StringName = MiraLocaleManager.GetOrCreateLocaleString(mode.Name);
+ Values.Add(mode);
}
- /*[HarmonyPatch(typeof(GameOptionsMenu), nameof(GameOptionsMenu.CreateSettings))]
- [HarmonyPostfix]
- private static void CreateSettingsPatch(GameOptionsMenu __instance)
- {
- if (MenuState.Instance.CurrentModIdx != 0 || GameManager.Instance.IsHideAndSeek() || CustomGameModeManager.ActiveMode == null)
- {
- return;
- }
-
- var num = 0.713f;
-
- foreach (var category in __instance.settingsContainer.GetComponentsInChildren())
- {
- if (category)
- category.gameObject.transform.localPosition -= new Vector3(0, 1.3f, 0);
- }
- CategoryHeaderMasked categoryHeaderMasked = Object.Instantiate(__instance.categoryHeaderOrigin, Vector3.zero, Quaternion.identity, __instance.settingsContainer);
- categoryHeaderMasked.SetHeader(CustomName, 20);
- categoryHeaderMasked.transform.localScale = Vector3.one * 0.63f;
- categoryHeaderMasked.transform.localPosition = new Vector3(-0.903f, num, -2f);
- OptionBehaviour = Object.Instantiate(
- __instance.stringOptionOrigin,
- Vector3.zero,
- Quaternion.identity,
- __instance.settingsContainer);
- num -= 0.63f;
- OptionBehaviour.transform.localPosition = new Vector3(0.952f, num, -2f);
- OptionBehaviour.SetClickMask(__instance.ButtonClickMask);
- StringGameSetting setting = ScriptableObject.CreateInstance();
- setting.Type = OptionTypes.MultipleChoice;
- setting.Title = GamemodeName;
- setting.Index = _lastValue;
- setting.Values = new Il2CppStructArray([Values[0]]);
- OptionBehaviour.SetUpFromData(setting, 20);
- Set(_lastValue);
- OptionBehaviour.TitleText.fontSize = 3;
- foreach (var optionBehaviour in __instance.Children.ToArray().Skip(1))
- {
- optionBehaviour.gameObject.transform.localPosition -= new Vector3(0, 1.3f, 0);
- }
- __instance.Children.Add(OptionBehaviour);
- for (var i = 1; i < Values.Count; i++)
- OptionBehaviour.Values = (Il2CppStructArray)OptionBehaviour.Values.Add(Values.ElementAt(i).Value);
- __instance.scrollBar.SetYBoundsMax(__instance.scrollBar.GetYBounds().max + 1);
- }*/
-
internal static void Set(int val)
{
Value = val;
var previousMode = CustomGameModeManager.ActiveMode;
CustomGameModeManager.GetAndSetGameMode();
- HudPatches.SetGameModeText(CustomGameModeManager.GetMode(Values.ElementAt(LastValue).Key).ColoredName);
+ HudPatches.SetGameModeText(Values[LastValue].ColoredName);
var gm = CustomGameModeManager.ActiveMode!;
- if (gm != previousMode)
- {
- ModdedOptionsManager.AddSettingsChangeMessage(
- HudManager.Instance.Notifier,
- GamemodeName,
- gm.ColoredName,
- new Color(0.7333f, 0.7333f, 0.7333f, 1),
- gm.TmpIcon);
- if (MenuState.Instance)
- {
- // should force reset roles for gamemodes properly
- foreach (var roleMenu in MenuState.Instance.QueuedRoleMenuRefresh)
- {
- MenuState.Instance.QueuedRoleMenuRefresh[roleMenu.Key] = true;
- }
- }
+ if (gm == previousMode)
+ return;
- GameOptionsMenuPatch.RefreshForGameMode();
- RoleGuidePatches.RefreshSettingsForGameMode();
+ ModdedOptionsManager.AddSettingsChangeMessage(
+ HudManager.Instance.Notifier,
+ GamemodeName,
+ gm.ColoredName,
+ new Color(0.7333f, 0.7333f, 0.7333f, 1),
+ gm.TmpIcon);
+
+ if (MenuState.Instance)
+ {
+ // should force reset roles for gamemodes properly
+ foreach (var roleMenu in MenuState.Instance.QueuedRoleMenuRefresh)
+ {
+ MenuState.Instance.QueuedRoleMenuRefresh[roleMenu.Key] = true;
+ }
}
- // TODO: could make Values a dict of AbstractGameMode too
+ GameOptionsMenuPatch.RefreshForGameMode();
+ RoleGuidePatches.RefreshSettingsForGameMode();
}
[HarmonyPatch(typeof(GameOptionsMenu), nameof(GameOptionsMenu.ValueChanged))]
@@ -150,8 +99,7 @@ public static class GameModeOption
}
[MethodRpc((uint)MiraRpc.SyncGamemodeOption)]
- [SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Intentionally unused because the main intent is for it to be used by dependent mods to add to a blacklist.")]
- internal static void RpcSyncGamemode(PlayerControl host, int data)
+ internal static void RpcSyncGamemode(PlayerControl _, int data)
{
Set(data);
}
diff --git a/MiraAPI/GameModes/HideAndSeekMode.cs b/MiraAPI/GameModes/HideAndSeekMode.cs
index 71146fe6..6e0666ac 100644
--- a/MiraAPI/GameModes/HideAndSeekMode.cs
+++ b/MiraAPI/GameModes/HideAndSeekMode.cs
@@ -92,9 +92,9 @@ public class HideAndSeekMode : AbstractGameMode
runOriginal = false;
CppCollections.List list = new();
AmongUsClient.Instance.GetAllClients(list);
- List list2 = [.. list.ToArray()
+ var list2 = list.ToArray()
.Where(c => c.Character != null && c.Character.Data != null && !c.Character.Data.Disconnected &&
- !c.Character.Data.IsDead).OrderBy(c => c.Id).Select(c => c.Character.Data),];
+ !c.Character.Data.IsDead).OrderBy(c => c.Id).Select(c => c.Character.Data).ToList();
foreach (var networkedPlayerInfo in GameData.Instance.AllPlayers)
{
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/Hud/CustomMultiSelectMenu.cs b/MiraAPI/Hud/CustomMultiSelectMenu.cs
index 50e2ff58..057b7205 100644
--- a/MiraAPI/Hud/CustomMultiSelectMenu.cs
+++ b/MiraAPI/Hud/CustomMultiSelectMenu.cs
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using MiraAPI.Patches.Stubs;
+using MiraAPI.Utilities;
using MiraAPI.Utilities.Assets;
using UnityEngine;
using UnityEngine.Events;
@@ -29,12 +30,7 @@ public abstract class CustomMultiSelectMenu : CustomPhoneMenu>? onSelection;
///
@@ -106,6 +102,7 @@ public abstract class CustomMultiSelectMenu : CustomPhoneMenu entries, Action?> onClick, int totalSelections, bool shouldConfirm, bool canRepeat = false)
{
MinigameStubs.Begin(Component, null);
+ MeetingVoteAreaVisibility.HideNameplates(Component);
this.totalSelections = totalSelections;
this.shouldConfirm = shouldConfirm;
@@ -116,6 +113,7 @@ public abstract class CustomMultiSelectMenu : CustomPhoneMenu
{
selectedEntries.Clear();
+ MeetingVoteAreaVisibility.Restore(Component);
onClick(null);
}));
@@ -177,6 +175,7 @@ public abstract class CustomMultiSelectMenu : CustomPhoneMenu e.SortKey.Contains(query, StringComparison.OrdinalIgnoreCase))
- .OrderByDescending(e => e.SortKey.Equals(query, StringComparison.OrdinalIgnoreCase))
- .ThenByDescending(e => e.SortKey.StartsWith(query, StringComparison.OrdinalIgnoreCase))
- .ThenByDescending(e => e.SortKey.Contains(query, StringComparison.OrdinalIgnoreCase))
- .ThenBy(e => e.SortKey, StringComparer.OrdinalIgnoreCase),];
+ return
+ [
+ .. MenuEntries
+ .Where(e => e.SortKey.Contains(query, StringComparison.OrdinalIgnoreCase))
+ .OrderByDescending(e => e.SortKey.Equals(query, StringComparison.OrdinalIgnoreCase))
+ .ThenByDescending(e => e.SortKey.StartsWith(query, StringComparison.OrdinalIgnoreCase))
+ .ThenByDescending(e => e.SortKey.Contains(query, StringComparison.OrdinalIgnoreCase))
+ .ThenBy(e => e.SortKey, StringComparer.OrdinalIgnoreCase),
+ ];
}
private static int GetTotalPages(int itemCount)
@@ -387,6 +390,7 @@ public abstract class CustomPaginableMenu : CustomPhoneMenu : CustomActionButton
}
}
- Targets = [.. newTargets
- .Where(IsTargetValid)
- .Take(MaxTargets),];
+ Targets =
+ [
+ .. newTargets
+ .Where(IsTargetValid)
+ .Take(MaxTargets),
+ ];
Targets.Do(t => SetOutline(t, true));
return base.CanUse() && Targets.Length > 0;
diff --git a/MiraAPI/LocalSettings/LocalSettingsTab.cs b/MiraAPI/LocalSettings/LocalSettingsTab.cs
index f5b22e77..5994bdd2 100644
--- a/MiraAPI/LocalSettings/LocalSettingsTab.cs
+++ b/MiraAPI/LocalSettings/LocalSettingsTab.cs
@@ -75,6 +75,7 @@ public abstract class LocalSettingsTab(ConfigFile config)
protected int TabIndex => LocalSettingsManager.Tabs.IndexOf(this) + 10;
private Scroller? scroller;
+ private float MaxScroll { get; set; }
///
/// Invoked when an option value is changed.
@@ -107,6 +108,17 @@ public abstract class LocalSettingsTab(ConfigFile config)
}
}
+ internal void RefreshScrollBounds()
+ {
+ if (scroller == null)
+ {
+ return;
+ }
+
+ scroller.SetBounds(new FloatRange(0, MaxScroll), new FloatRange(0, 0));
+ scroller.ScrollToTop();
+ }
+
///
/// Creates the tab and it's content.
///
@@ -119,11 +131,13 @@ public abstract class LocalSettingsTab(ConfigFile config)
tab.transform.DestroyChildren();
tab.gameObject.SetActive(false);
- if (scroller == null)
+ if (scroller == null || scroller.transform.parent != tab.transform)
{
scroller = Helpers.CreateScroller(tab.transform, OptionsMenuPatches.MaskCollider);
}
+ Labels.Clear();
+
if (TabButton != null)
{
TabButton.Content = tab.gameObject;
@@ -217,7 +231,11 @@ public abstract class LocalSettingsTab(ConfigFile config)
contentIndex++;
}
- scroller.SetBounds(new FloatRange(0, (Settings.Count + Buttons.Count) * 0.5f - 5f), new FloatRange(0, 0));
+ const float visibleHeight = 5f;
+ const float extraPadding = 0.25f;
+ var itemRange = (Settings.Count + Buttons.Count) * 0.5f - visibleHeight;
+ var offsetRange = contentOffset - visibleHeight + extraPadding;
+ MaxScroll = Mathf.Max(0f, itemRange, offsetRange);
return tab;
}
diff --git a/MiraAPI/LocalSettings/SettingTypes/LocalEnumSetting.cs b/MiraAPI/LocalSettings/SettingTypes/LocalEnumSetting.cs
index 91d2eeb1..5fcbb081 100644
--- a/MiraAPI/LocalSettings/SettingTypes/LocalEnumSetting.cs
+++ b/MiraAPI/LocalSettings/SettingTypes/LocalEnumSetting.cs
@@ -36,10 +36,13 @@ public class LocalEnumSetting(
///
/// Gets the values.
///
- public string[] Values { get; } = values ?? [.. Enum
- .GetValues(configEntry.SettingType)
- .Cast()
- .Select(x => x.ToDisplayString()),];
+ public string[] Values { get; } = values ??
+ [
+ .. Enum
+ .GetValues(configEntry.SettingType)
+ .Cast()
+ .Select(x => x.ToDisplayString()),
+ ];
private SpriteRenderer _highlight;
private TextMeshPro _btnText;
diff --git a/MiraAPI/Patches/GameModes/CreateOptionsPatch.cs b/MiraAPI/Patches/GameModes/CreateOptionsPatch.cs
deleted file mode 100644
index b33c1fd3..00000000
--- a/MiraAPI/Patches/GameModes/CreateOptionsPatch.cs
+++ /dev/null
@@ -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;
- }
-}
diff --git a/MiraAPI/Patches/LocalSettings/OptionsMenuPatches.cs b/MiraAPI/Patches/LocalSettings/OptionsMenuPatches.cs
index 6b64159e..f6aaaf45 100644
--- a/MiraAPI/Patches/LocalSettings/OptionsMenuPatches.cs
+++ b/MiraAPI/Patches/LocalSettings/OptionsMenuPatches.cs
@@ -1,6 +1,9 @@
-using System.Collections.Generic;
+using System;
+using System.Collections;
+using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
+using BepInEx.Unity.IL2CPP.Utils.Collections;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using MiraAPI.LocalSettings;
@@ -12,21 +15,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;
@@ -77,7 +73,7 @@ public static class OptionsMenuPatches
_currentPage = 1;
TabButtons.Clear();
- float yOffset = 0;
+ var yOffset = 0f;
var i = 0;
var tabIdx = 0;
var page = 1;
@@ -151,9 +147,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)
@@ -181,13 +177,15 @@ public static class OptionsMenuPatches
LocalSettingsManager.AvailableTabs.ForEach(CustomClose); // Close all mod tabs
// Tabs with index 10 and above are the mod settings tabs
- if (index >= 10)
+ if (index < 10)
{
- CustomOpen(LocalSettingsManager.AvailableTabs[index - 10]);
- return false;
+ return true;
}
- return true;
+ var tab = LocalSettingsManager.AvailableTabs[index - 10];
+ CustomOpen(tab);
+ __instance.StartCoroutine(RefreshScrollBoundsAfterOpen(__instance, tab).WrapToIl2Cpp());
+ return false;
}
///
@@ -214,14 +212,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;
@@ -229,16 +230,29 @@ public static class OptionsMenuPatches
tab.Open();
}
+ private static IEnumerator RefreshScrollBoundsAfterOpen(OptionsMenuBehaviour menu, LocalSettingsTab tab)
+ {
+ yield return new WaitForEndOfFrame();
+
+ if (menu && tab.TabButton && tab.TabButton!.Content && tab.TabButton.Content.activeInHierarchy)
+ {
+ tab.RefreshScrollBounds();
+ }
+ }
+
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;
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/Options/GameOptionsMenuPatch.cs b/MiraAPI/Patches/Options/GameOptionsMenuPatch.cs
index 9dacf030..0799bf2f 100644
--- a/MiraAPI/Patches/Options/GameOptionsMenuPatch.cs
+++ b/MiraAPI/Patches/Options/GameOptionsMenuPatch.cs
@@ -4,7 +4,6 @@ using System.Collections.Generic;
using System.Linq;
using BepInEx.Unity.IL2CPP.Utils.Collections;
using HarmonyLib;
-using Il2CppInterop.Runtime.InteropTypes.Arrays;
using MiraAPI.GameModes;
using MiraAPI.GameOptions;
using MiraAPI.Modifiers;
@@ -16,7 +15,6 @@ using Reactor.Utilities.Extensions;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
-using UnityEngine.ProBuilder;
using UnityEngine.UI;
using Object = UnityEngine.Object;
@@ -218,7 +216,7 @@ internal static class GameOptionsMenuPatch
{
if (!option || !option.gameObject.activeInHierarchy ||
option == menu.MapPicker ||
- (GameModeOption.OptionBehaviour && option == GameModeOption.OptionBehaviour) ||
+ option == GameModeOption.OptionBehaviour ||
!option.Data)
{
continue;
@@ -250,7 +248,6 @@ internal static class GameOptionsMenuPatch
private static void CreateSettings(GameOptionsMenu instance, Transform container)
{
- var num = 0.713f;
VanillaHeaders.Clear();
VanillaOptions.Clear();
MainOptions.Clear();
@@ -258,35 +255,36 @@ internal static class GameOptionsMenuPatch
GameModeOptions.Clear();
GameModeGroups.Clear();
- var gmCategory = Object.Instantiate(instance.categoryHeaderOrigin, Vector3.zero, Quaternion.identity, container);
+ var num = 0.713f;
+
+ var gmCategory = Object.Instantiate(instance.categoryHeaderOrigin, container);
gmCategory.SetHeader(GameModeOption.CustomName, 20);
gmCategory.transform.localScale = Vector3.one * 0.63f;
gmCategory.transform.localPosition = new Vector3(-0.903f, num, -2f);
- GameModeOption.OptionBehaviour = Object.Instantiate(instance.stringOptionOrigin, container);
+
num -= 0.63f;
+
+ GameModeOption.OptionBehaviour = Object.Instantiate(instance.stringOptionOrigin, container);
GameModeOption.OptionBehaviour.transform.localPosition = new Vector3(0.952f, num, -2f);
GameModeOption.OptionBehaviour.SetClickMask(instance.ButtonClickMask);
+
var setting = ScriptableObject.CreateInstance();
setting.Type = OptionTypes.MultipleChoice;
setting.Title = GameModeOption.GamemodeName;
setting.Index = GameModeOption.LastValue;
- setting.Values = new Il2CppStructArray([GameModeOption.Values[0]]);
+ setting.Values = GameModeOption.Values.Select(x => x.StringName).ToArray();
+
GameModeOption.OptionBehaviour.SetUpFromData(setting, 20);
GameModeOption.Set(GameModeOption.LastValue);
GameModeOption.OptionBehaviour.TitleText.fontSize = 3;
+
instance.Children.Add(GameModeOption.OptionBehaviour);
+
foreach (var optionBehaviour in instance.Children)
{
MainOptions.Add(optionBehaviour);
}
- for (var i = 1; i < GameModeOption.Values.Count; i++)
- {
- GameModeOption.OptionBehaviour.Values =
- (Il2CppStructArray)GameModeOption.OptionBehaviour.Values.Add(
- GameModeOption.Values.ElementAt(i).Value);
- }
-
var modeInfoHolder = new GameObject("GamemodeInfo")
{
transform =
@@ -298,7 +296,7 @@ internal static class GameOptionsMenuPatch
layer = container.gameObject.layer,
}.transform;
- var gamemodeBg = Object.Instantiate(GameModeOption.OptionBehaviour.transform.GetChild(0).gameObject, Vector3.zero, Quaternion.identity, modeInfoHolder);
+ var gamemodeBg = Object.Instantiate(GameModeOption.OptionBehaviour.transform.GetChild(0).gameObject, modeInfoHolder);
gamemodeBg.transform.localPosition = Vector3.zero;
gamemodeBg.transform.localScale = new Vector3(1.35f, 0.85f, 1);
gamemodeBg.name = "Background";
@@ -317,7 +315,7 @@ internal static class GameOptionsMenuPatch
_modIcon.sprite = MiraAssets.BlankSprite.LoadAsset();
_modIcon.material = gamemodeBg.gameObject.GetComponent().material;
- var gamemodeTextObj = Object.Instantiate(GameModeOption.OptionBehaviour.transform.GetChild(1).gameObject, Vector3.zero, Quaternion.identity, modeInfoHolder);
+ var gamemodeTextObj = Object.Instantiate(GameModeOption.OptionBehaviour.transform.GetChild(1).gameObject, modeInfoHolder);
gamemodeTextObj.transform.localPosition = new Vector3(0.3f, 0, -0.01f);
gamemodeTextObj.transform.localScale = new Vector3(2.12f, 2.12f, 1);
_gamemodeDescription = gamemodeTextObj.GetComponentInChildren();
@@ -469,11 +467,7 @@ internal static class GameOptionsMenuPatch
private static void CreateGroup(GameOptionsMenu menu, AbstractOptionGroup group, Transform container, ref float num, ref List optionBehaviours, ref List categoryHeaders)
{
- var categoryHeaderMasked = Object.Instantiate(
- menu.categoryHeaderOrigin,
- Vector3.zero,
- Quaternion.identity,
- container);
+ var categoryHeaderMasked = Object.Instantiate(menu.categoryHeaderOrigin, container);
categoryHeaderMasked.transform.localPosition = new Vector3(-0.903f, num + 1, -2f);
categoryHeaderMasked.transform.localScale = Vector3.one * 0.63f;
categoryHeaders.Add(categoryHeaderMasked);
@@ -510,12 +504,14 @@ internal static class GameOptionsMenuPatch
foreach (var newOpt in options)
{
newOpt.SetClickMask(menu.ButtonClickMask);
- SpriteRenderer[] componentsInChildren = newOpt.GetComponentsInChildren(true);
+ var componentsInChildren = newOpt.GetComponentsInChildren(true);
+
foreach (var renderer in componentsInChildren)
{
if (group.GroupColor != MiraApiPlugin.DefaultHeaderColor)
{
renderer.color = group.GroupColor.FindAlternateColor();
+
if (renderer.transform.parent.TryGetComponent(out var btn))
{
btn.interactableColor = group.GroupColor.FindAlternateColor();
diff --git a/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs b/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs
index 3d2ed2ec..aa6396df 100644
--- a/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs
+++ b/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs
@@ -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 RoleGroupHidden = [];
- private static RoleBehaviour? currentRole;
- private static List? currentRoleOptions;
+ internal static RoleBehaviour? CurrentRole;
+ internal static IModdedOption[]? CurrentRoleOptions;
private static float scrollerNum = 0.522f;
+ [HarmonyPostfix]
+ [HarmonyPatch(nameof(RolesSettingsMenu.Awake))]
+ public static void OnAwake(RolesSettingsMenu __instance)
+ {
+ __instance.gameObject.AddComponent();
+ }
+
[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()
.ToLookup(x => x.RoleOptionsGroup);
@@ -362,6 +373,7 @@ public static class RoleSettingMenuPatches
}
roleMenu.SetScrollBounds();
+ roleMenu.scrollBar.ScrollToTop();
_quotaTabCoroutine = null;
}
@@ -431,32 +443,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,14 +500,15 @@ public static class RoleSettingMenuPatches
optBehaviour.gameObject.Destroy();
}
- currentRole = role;
+ CurrentRole = role;
__instance.advancedSettingChildren.Clear();
// TODO: create sub groups under the role settings.
+ var type = role.GetType();
var filteredOptions = MenuState.Instance.CurrentMod.InternalOptionGroups
- .Where(x => x.GroupVisible() && x.OptionableType == role.GetType())
+ .Where(x => x.OptionableType == type && x.GroupVisible())
.SelectMany(x => x.Options)
- .ToList();
+ .ToArray();
foreach (var option in filteredOptions)
{
@@ -547,7 +540,7 @@ public static class RoleSettingMenuPatches
newOpt.Initialize();
}
- currentRoleOptions = filteredOptions;
+ CurrentRoleOptions = filteredOptions;
}
[HarmonyPrefix]
diff --git a/MiraAPI/Patches/RoleGuidePatches.cs b/MiraAPI/Patches/RoleGuidePatches.cs
index 929e5be8..dfb9bac4 100644
--- a/MiraAPI/Patches/RoleGuidePatches.cs
+++ b/MiraAPI/Patches/RoleGuidePatches.cs
@@ -279,6 +279,8 @@ public static class RoleGuidePatches
MapBehaviour.Instance.Close();
}
+ MeetingVoteAreaVisibility.HideNameplates(__instance);
+
if (HudManager.InstanceExists)
{
ConsoleJoystick.SetMode_MenuAdditive();
@@ -390,6 +392,13 @@ public static class RoleGuidePatches
return false;
}
+ [HarmonyPostfix]
+ [HarmonyPatch(typeof(MatchInfoGuide), nameof(MatchInfoGuide.Close))]
+ private static void ClosePostfix(MatchInfoGuide __instance)
+ {
+ MeetingVoteAreaVisibility.Restore(__instance);
+ }
+
private static void SetUpTabGrids(MatchInfoTabPos position)
{
tabButtonContainer.startCorner = GridLayoutGroup.Corner.UpperLeft;
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/Patches/Roles/SelectRolesPatch.cs b/MiraAPI/Patches/Roles/SelectRolesPatch.cs
index 204e1f9e..630402e3 100644
--- a/MiraAPI/Patches/Roles/SelectRolesPatch.cs
+++ b/MiraAPI/Patches/Roles/SelectRolesPatch.cs
@@ -45,9 +45,9 @@ public static class SelectRolesPatch
CppCollections.List list = new();
AmongUsClient.Instance.GetAllClients(list);
- List list2 = [.. list.ToArray()
+ var list2 = list.ToArray()
.Where(c => c.Character != null && c.Character.Data != null && !c.Character.Data.Disconnected &&
- !c.Character.Data.IsDead).OrderBy(c => c.Id).Select(c => c.Character.Data),];
+ !c.Character.Data.IsDead).OrderBy(c => c.Id).Select(c => c.Character.Data).ToList();
foreach (var networkedPlayerInfo in GameData.Instance.AllPlayers)
{
diff --git a/MiraAPI/Patches/Voting/MeetingHudPatches.cs b/MiraAPI/Patches/Voting/MeetingHudPatches.cs
index d0f02fbb..d9232f38 100644
--- a/MiraAPI/Patches/Voting/MeetingHudPatches.cs
+++ b/MiraAPI/Patches/Voting/MeetingHudPatches.cs
@@ -106,6 +106,7 @@ internal static class MeetingHudPatches
[HarmonyPatch(nameof(MeetingHud.OnDestroy))]
public static void OnDestroyPatch(MeetingHud __instance)
{
+ MeetingVoteAreaVisibility.RestoreAll();
MiraEventManager.InvokeEvent(new EndMeetingEvent(__instance));
}
@@ -113,6 +114,7 @@ internal static class MeetingHudPatches
[HarmonyPatch(nameof(MeetingHud.VotingComplete))]
public static void VotingCompletePatch(MeetingHud __instance)
{
+ MeetingVoteAreaVisibility.RestoreAll();
foreach (var meetingAbility in MeetingButtonManager.UntargetedButtons.Where(x => x.Enabled(PlayerControl.LocalPlayer.Data.Role) &&
(x.DisableUponVoting || x.HideUponWrapUp)))
{
@@ -269,7 +271,7 @@ internal static class MeetingHudPatches
[HarmonyPrefix]
[HarmonyPatch(nameof(MeetingHud.PopulateResults))]
- public static bool PopulateResultsPatch(ref Il2CppStructArray states)
+ public static bool PopulateResultsPatch(Il2CppStructArray states)
{
var votes = states.Select(x => new CustomVote(x.VoterId, x.VotedForId)).ToList();
diff --git a/MiraAPI/PluginLoading/MiraPluginManager.cs b/MiraAPI/PluginLoading/MiraPluginManager.cs
index c2f1caed..840d8926 100644
--- a/MiraAPI/PluginLoading/MiraPluginManager.cs
+++ b/MiraAPI/PluginLoading/MiraPluginManager.cs
@@ -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 += () =>
diff --git a/MiraAPI/Utilities/Components/RoleSettingsMenuUpdater.cs b/MiraAPI/Utilities/Components/RoleSettingsMenuUpdater.cs
new file mode 100644
index 00000000..219e4f28
--- /dev/null
+++ b/MiraAPI/Utilities/Components/RoleSettingsMenuUpdater.cs
@@ -0,0 +1,49 @@
+using System.Diagnostics.CodeAnalysis;
+using MiraAPI.Patches.Options;
+using Reactor.Utilities.Attributes;
+using UnityEngine;
+
+namespace MiraAPI.Utilities.Components;
+
+///
+/// Updates the visuals of the in a fixed update loop.
+///
+/// The C++ pointer to the object.
+[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();
+ }
+
+ 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);
+ }
+}
diff --git a/MiraAPI/Utilities/Extensions.cs b/MiraAPI/Utilities/Extensions.cs
index 868bef17..0446e84f 100644
--- a/MiraAPI/Utilities/Extensions.cs
+++ b/MiraAPI/Utilities/Extensions.cs
@@ -682,7 +682,7 @@ public static class Extensions
/// if the is for a custom options, otherwise.
public static bool IsCustom(this OptionBehaviour optionBehaviour)
{
- return ModdedOptionsManager.ModdedOptions.Values.Any(opt => opt.OptionBehaviour && opt.OptionBehaviour == optionBehaviour) || optionBehaviour.Equals(GameModeOption.OptionBehaviour);
+ return ModdedOptionsManager.ModdedOptions.Values.Any(opt => opt.OptionBehaviour == optionBehaviour) || optionBehaviour.Equals(GameModeOption.OptionBehaviour);
}
///
diff --git a/MiraAPI/Utilities/GuideOptionsPatches.cs b/MiraAPI/Utilities/GuideOptionsPatches.cs
index 4d4b046d..f44626a4 100644
--- a/MiraAPI/Utilities/GuideOptionsPatches.cs
+++ b/MiraAPI/Utilities/GuideOptionsPatches.cs
@@ -142,12 +142,15 @@ internal static class GuideOptionPages
}
}
- return [.. pages
- .OrderBy(page => page.MenuOrder)
- .ThenBy(page => page.GroupPriority)
- .ThenBy(page => page.Order)
- .ThenBy(page => page.Group.GroupName, StringComparer.OrdinalIgnoreCase)
- .ThenBy(page => page.ModAbbreviation, StringComparer.OrdinalIgnoreCase),];
+ return
+ [
+ .. pages
+ .OrderBy(page => page.MenuOrder)
+ .ThenBy(page => page.GroupPriority)
+ .ThenBy(page => page.Order)
+ .ThenBy(page => page.Group.GroupName, StringComparer.OrdinalIgnoreCase)
+ .ThenBy(page => page.ModAbbreviation, StringComparer.OrdinalIgnoreCase),
+ ];
}
private static int GetMenuOrder(MenuCategory menu)
@@ -184,12 +187,15 @@ internal static class GuideOptionPages
return [.. matchingModPages.SelectMany(page => page.Entries)];
}
- return [.. pageList
- .SelectMany(page => page.Entries
+ return
+ [
+ .. pageList
+ .SelectMany(page => page.Entries
.Select(entry => (Entry: entry, Rank: Rank(entry, query, cmp)))
.Where(result => result.Rank < int.MaxValue)
.OrderBy(result => result.Rank)
- .Select(result => result.Entry)),];
+ .Select(result => result.Entry)),
+ ];
}
private static string[] GetModSearchTerms(MiraPluginInfo plugin, AbstractOptionGroup group)
diff --git a/MiraAPI/Utilities/Helpers.cs b/MiraAPI/Utilities/Helpers.cs
index fe3b5020..823cdce4 100644
--- a/MiraAPI/Utilities/Helpers.cs
+++ b/MiraAPI/Utilities/Helpers.cs
@@ -370,7 +370,7 @@ public static class Helpers
public static LobbyNotificationMessage CreateAndShowNotification(string text, Color color, Vector3 localPos, AudioClip? clip = null, Sprite? spr = null)
{
var popper = HudManager.Instance.Notifier;
- var newMessage = Object.Instantiate(popper.notificationMessageOrigin, Vector3.zero, Quaternion.identity, popper.transform);
+ var newMessage = Object.Instantiate(popper.notificationMessageOrigin, popper.transform);
newMessage.transform.localPosition = localPos;
newMessage.SetUp(text, spr ?? null, color, new Action(() => popper.OnMessageDestroy(newMessage)));
popper.lastMessageKey = -1;
@@ -936,7 +936,7 @@ public static class Helpers
{
const float contentTop = 0.95f;
const float horizontalOffset = -0.2f;
- const float headerContentGap = 0.2f;
+ const float groupHeaderContentGap = 0.05f;
const int contentSortingOrder = 151;
columns = Mathf.Clamp(columns, 1, 6);
@@ -1024,7 +1024,7 @@ public static class Helpers
groupColumns[group] = i % columns;
bandHeights[band] = Mathf.Max(
bandHeights[band],
- rowPitch * (groupedSettings[i].Count() + 1) + headerContentGap + 0.25f);
+ rowPitch * (groupedSettings[i].Count() + 1) + groupHeaderContentGap + 0.25f);
}
var bandOffset = 0f;
@@ -1040,7 +1040,6 @@ public static class Helpers
}
}
- var contentBottom = float.PositiveInfinity;
var previousGroup = (AbstractOptionGroup?)null;
var rowIndex = 0;
var column = 0;
@@ -1089,12 +1088,12 @@ public static class Helpers
if (headerSource)
{
- const float headerScale = 0.46f;
+ const float groupHeaderScale = 0.42f;
var headerWidth = groupsAsColumns
- ? columnWidth / headerScale
- : (columns * columnWidth + (columns - 1) * columnGap) / headerScale;
+ ? columnWidth / groupHeaderScale
+ : (columns * columnWidth + (columns - 1) * columnGap) / groupHeaderScale;
var header = Object.Instantiate(headerSource!, page.transform, false);
- header.transform.localScale = Vector3.one * headerScale;
+ header.transform.localScale = Vector3.one * groupHeaderScale;
if (groupsAsColumns)
{
var totalWidth = columns * columnWidth + (columns - 1) * columnGap;
@@ -1155,12 +1154,6 @@ public static class Helpers
renderer.maskInteraction = SpriteMaskInteraction.VisibleInsideMask;
renderer.material.SetInt(PlayerMaterial.MaskLayer, 50);
renderer.sortingOrder = contentSortingOrder;
- if (renderer.enabled && renderer.sprite)
- {
- contentBottom = Mathf.Min(
- contentBottom,
- inner.InverseTransformPoint(renderer.bounds.min).y);
- }
}
foreach (var text in header.GetComponentsInChildren(true))
@@ -1171,9 +1164,6 @@ public static class Helpers
if (text.enabled)
{
text.ForceMeshUpdate();
- contentBottom = Mathf.Min(
- contentBottom,
- inner.InverseTransformPoint(text.bounds.min).y);
}
}
@@ -1191,7 +1181,7 @@ public static class Helpers
horizontalOffset;
var centerY = groupsAsColumns && settings[i].Group is { } rowGroup
? contentTop - groupTopOffsets[rowGroup] -
- (rowPitch * (groupRows[rowGroup] + 1)) - headerContentGap - (rowHeight / 2f)
+ (rowPitch * (groupRows[rowGroup] + 1)) - groupHeaderContentGap - (rowHeight / 2f)
: contentTop - (rowHeight / 2f) - (rowIndex * rowPitch) - groupSpacing;
var row = Object.Instantiate(rowPrefab, page.transform);
row.enabled = false;
@@ -1238,27 +1228,6 @@ public static class Helpers
renderer.maskInteraction = SpriteMaskInteraction.VisibleInsideMask;
renderer.material.SetInt(PlayerMaterial.MaskLayer, 50);
renderer.sortingOrder = contentSortingOrder;
- if (renderer.enabled &&
- renderer.sprite &&
- renderer.transform != row.PlusBtn.transform &&
- !renderer.transform.IsChildOf(row.PlusBtn.transform) &&
- renderer.transform != row.MinusBtn.transform &&
- !renderer.transform.IsChildOf(row.MinusBtn.transform))
- {
- contentBottom = Mathf.Min(
- contentBottom,
- inner.InverseTransformPoint(renderer.bounds.min).y);
- }
- }
-
- foreach (var text in row.GetComponentsInChildren(true))
- {
- if (text.enabled)
- {
- contentBottom = Mathf.Min(
- contentBottom,
- inner.InverseTransformPoint(text.bounds.min).y);
- }
}
row.gameObject.SetActive(true);
@@ -1277,6 +1246,26 @@ public static class Helpers
}
}
+ page.SetActive(true);
+ var contentBottom = float.PositiveInfinity;
+ foreach (var text in page.GetComponentsInChildren(true))
+ {
+ if (text.enabled && text.gameObject.activeInHierarchy)
+ {
+ text.ForceMeshUpdate();
+ }
+ }
+
+ foreach (var renderer in page.GetComponentsInChildren(true))
+ {
+ if (renderer.enabled && renderer.gameObject.activeInHierarchy)
+ {
+ contentBottom = Mathf.Min(
+ contentBottom,
+ inner.InverseTransformPoint(renderer.bounds.min).y);
+ }
+ }
+
var maskArea = parent.transform.FindChild("MaskArea")?.GetComponent();
var maskBottom = maskArea
? inner.InverseTransformPoint(maskArea!.bounds.min).y
@@ -1288,7 +1277,6 @@ public static class Helpers
? contentOverflow + 0.05f
: 0f;
parent.SetYBoundsMax(Mathf.Clamp(scrollRange, 0f, 999f));
- page.SetActive(true);
return page;
}
diff --git a/MiraAPI/Utilities/MeetingVoteAreaVisibility.cs b/MiraAPI/Utilities/MeetingVoteAreaVisibility.cs
new file mode 100644
index 00000000..9262485d
--- /dev/null
+++ b/MiraAPI/Utilities/MeetingVoteAreaVisibility.cs
@@ -0,0 +1,74 @@
+using System.Collections.Generic;
+using UnityEngine;
+
+namespace MiraAPI.Utilities;
+
+internal static class MeetingVoteAreaVisibility
+{
+ private static readonly Dictionary OriginalRendererStates = [];
+ private static readonly HashSet ActiveOwners = [];
+
+ internal static void HideNameplates(Object owner)
+ {
+ var meetingHud = MeetingHud.Instance;
+ if (!owner ||
+ !meetingHud ||
+ meetingHud.state is not (MeetingHud.MeetingStates.Discussion or
+ MeetingHud.MeetingStates.NotVoted or
+ MeetingHud.MeetingStates.Voted))
+ {
+ return;
+ }
+
+ ActiveOwners.Add(owner.GetInstanceID());
+ foreach (var playerVoteArea in meetingHud.playerStates)
+ {
+ if (!playerVoteArea)
+ {
+ continue;
+ }
+
+ var buttons = playerVoteArea.Buttons;
+ foreach (var renderer in playerVoteArea.GetComponentsInChildren(true))
+ {
+ if (!renderer ||
+ (buttons &&
+ (renderer.transform == buttons.transform || renderer.transform.IsChildOf(buttons.transform))))
+ {
+ continue;
+ }
+
+ if (!OriginalRendererStates.ContainsKey(renderer))
+ {
+ OriginalRendererStates.Add(renderer, renderer.enabled);
+ }
+
+ renderer.enabled = false;
+ }
+ }
+ }
+
+ internal static void Restore(Object owner)
+ {
+ if (!owner || !ActiveOwners.Remove(owner.GetInstanceID()) || ActiveOwners.Count > 0)
+ {
+ return;
+ }
+
+ RestoreAll();
+ }
+
+ internal static void RestoreAll()
+ {
+ ActiveOwners.Clear();
+ foreach (var rendererState in OriginalRendererStates)
+ {
+ if (rendererState.Key)
+ {
+ rendererState.Key.enabled = rendererState.Value;
+ }
+ }
+
+ OriginalRendererStates.Clear();
+ }
+}
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.