diff --git a/MiraAPI/GameModes/GameModeOption.cs b/MiraAPI/GameModes/GameModeOption.cs index 0c189ea..e65f3db 100644 --- a/MiraAPI/GameModes/GameModeOption.cs +++ b/MiraAPI/GameModes/GameModeOption.cs @@ -1,7 +1,9 @@ using System.Collections.Generic; +using System.Linq; using HarmonyLib; using Il2CppInterop.Runtime.InteropTypes.Arrays; using Il2CppSystem; +using MiraAPI.Patches.GameModes; using Reactor.Localization.Utilities; using UnityEngine; using UnityEngine.ProBuilder; @@ -31,21 +33,23 @@ public static class GameModeOption return; OptionBehaviour.Value = value; OptionBehaviour.UpdateValue(); + _lastValue = value; } } + private static int _lastValue; internal static StringOption OptionBehaviour { get; private set; } = null!; - private static readonly List Queue = []; + private static readonly Dictionary Values = new() + { + ["Default"] = CustomStringName.CreateAndRegister("Default"), + }; + // loading takes place before option creation internal static void AddOption(string opt) { - if (OptionBehaviour == null) - { - Queue.Add(opt); - return; - } - OptionBehaviour.Values = (Il2CppStructArray)OptionBehaviour.Values.Add(CustomStringName.CreateAndRegister(opt)); + if (!Values.ContainsKey(opt)) + Values.Add(opt, CustomStringName.CreateAndRegister(opt)); } [HarmonyPatch(typeof(GameOptionsMenu), nameof(GameOptionsMenu.CreateSettings))] [HarmonyPostfix] @@ -75,20 +79,21 @@ public static class GameModeOption StringGameSetting setting = ScriptableObject.CreateInstance(); setting.Type = OptionTypes.MultipleChoice; setting.Title = CustomStringName.CreateAndRegister("Gamemode"); - setting.Index = 0; - setting.Values = new Il2CppStructArray([CustomStringName.CreateAndRegister("Default")]); + setting.Index = _lastValue; + setting.Values = new Il2CppStructArray([Values["Default"]]); OptionBehaviour.SetUpFromData(setting, 20); OptionBehaviour.TitleText.fontSize = 3; OptionBehaviour.OnValueChanged = (Action) ((OptionBehaviour opt) => { - CustomGameModeManager.SetGameMode((uint)opt.GetInt()); + _lastValue = opt.GetInt(); + CustomGameModeManager.SetGameMode((uint)_lastValue); + HudPatches.SetGameModeText(Values.ElementAt(_lastValue).Key); }); num -= 0.37f; // scrollbar offset __instance.Children.Add(OptionBehaviour); __instance.scrollBar.SetYBoundsMax(-num - 1.65f); - foreach (var str in Queue) - AddOption(str); - Queue.Clear(); + for (var i = 1; i < Values.Count; i++) + OptionBehaviour.Values = (Il2CppStructArray)OptionBehaviour.Values.Add(Values.ElementAt(i).Value); } [HarmonyPatch(typeof(GameOptionsMenu), nameof(GameOptionsMenu.ValueChanged))] diff --git a/MiraAPI/Patches/GameModes/HudPatches.cs b/MiraAPI/Patches/GameModes/HudPatches.cs index e232920..4cb5076 100644 --- a/MiraAPI/Patches/GameModes/HudPatches.cs +++ b/MiraAPI/Patches/GameModes/HudPatches.cs @@ -1,5 +1,7 @@ using HarmonyLib; using MiraAPI.GameModes; +using TMPro; +using UnityEngine; namespace MiraAPI.Patches.GameModes; @@ -11,4 +13,33 @@ internal static class HudPatches [HarmonyPostfix, HarmonyPatch(nameof(HudManager.Update))] public static void HudUpdatePatch(HudManager __instance) => CustomGameModeManager.ActiveMode?.HudUpdate(__instance); + + [HarmonyPatch(typeof(HudManager), nameof(HudManager.Start))] + [HarmonyPostfix] + public static void PostHudStart(HudManager __instance) + { + if (GameManager.Instance.IsHideAndSeek()) + return; + var infoPane = __instance.gameObject.transform.FindChild("LobbyInfoPane"); + var aspect = infoPane.gameObject.transform.Find("AspectSize"); + var modeLabel = aspect!.Find("ModeLabel"); + var modeValue = aspect.Find("ModeValue"); + var modelText = modeLabel!.Find("Text_TMP").gameObject; + var modelTextClone = Object.Instantiate(modelText, modeLabel); + Object.Destroy(modelTextClone.GetComponent()); + modelTextClone.GetComponent().text = "Gamemode"; + var gmText = modeValue!.Find("GameModeText").gameObject; + var gmTextClone = Object.Instantiate(gmText, modeValue); + gmText.SetActive(false); + modelText.SetActive(false); + _text = gmTextClone.GetComponent(); + _text.text = "Default"; + } + + private static TextMeshPro? _text; + internal static void SetGameModeText(string text) + { + if (_text != null) + _text.text = text; + } }