From b6df13a2de602a956c2f1193aa68fe65b867601d Mon Sep 17 00:00:00 2001 From: Sanc-6231 <3060085687@qq.com> Date: Wed, 4 Nov 2026 18:10:14 +0800 Subject: [PATCH 1/9] fix:restore vanilla button layout when returning to the Main page. --- MiraAPI/Patches/Options/MenuState.cs | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/MiraAPI/Patches/Options/MenuState.cs b/MiraAPI/Patches/Options/MenuState.cs index 66876991..11d203d9 100644 --- a/MiraAPI/Patches/Options/MenuState.cs +++ b/MiraAPI/Patches/Options/MenuState.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Il2CppInterop.Runtime.Attributes; +using Il2CppInterop.Runtime.Attributes; using MiraAPI.GameModes; using MiraAPI.GameOptions; using MiraAPI.Modifiers; @@ -12,10 +9,15 @@ using MiraAPI.Translation; using MiraAPI.Utilities.Assets; using Reactor.Utilities.Attributes; using Reactor.Utilities.Extensions; +using System; +using System.Collections.Generic; +using System.Linq; using TMPro; using UnityEngine; using UnityEngine.Events; using UnityEngine.UI; +using static UnityEngine.ProBuilder.AutoUnwrapSettings; +using static UnityEngine.UI.Image; namespace MiraAPI.Patches.Options; @@ -50,7 +52,8 @@ public class MenuState(IntPtr cppPtr) : MonoBehaviour(cppPtr) private readonly Dictionary _smallButtons = []; private readonly Dictionary _largeButtons = []; - + private Vector3 _gameSettingsButtonOrig; + private Vector3 _roleSettingsButtonOrig; [HideFromIl2Cpp] public Dictionary> Containers { get; } = new() { @@ -145,6 +148,10 @@ public class MenuState(IntPtr cppPtr) : MonoBehaviour(cppPtr) // Create menu buttons _largeButtons[(int)MenuButton.Roles] = Gsm.RoleSettingsButton; + // cache + _gameSettingsButtonOrig = Gsm.GameSettingsButton.transform.localPosition; + _roleSettingsButtonOrig = Gsm.RoleSettingsButton.transform.localPosition; + // modifiers button var mBtn = Instantiate(Gsm.RoleSettingsButton, Gsm.RoleSettingsButton.transform.parent); _largeButtons[MenuButton.Modifiers] = mBtn; @@ -409,6 +416,11 @@ public class MenuState(IntPtr cppPtr) : MonoBehaviour(cppPtr) btn.gameObject.SetActive(false); } + // The mod options page moves RoleSettingsButton as needed. + // But when hasOptions == false, it leaves the button at the GameSettingsButton spot. + // So before each re-layout, always put the original button back into the prefab slot first. + RestoreButtonLayout(); + if (CurrentModIdx == 0) { Gsm.GameSettingsButton.gameObject.SetActive(true); @@ -532,6 +544,12 @@ public class MenuState(IntPtr cppPtr) : MonoBehaviour(cppPtr) } } + private void RestoreButtonLayout() + { + Gsm.GameSettingsButton.transform.localPosition = _gameSettingsButtonOrig; + Gsm.RoleSettingsButton.transform.localPosition = _roleSettingsButtonOrig; + } + internal void ChangeTabPatch(GameSettingMenu menu, int tabNum, bool previewOnly) { Info($"Changed tab to {(MenuCategory)tabNum} (previewOnly: {previewOnly}) for mod {CurrentModIdx}"); From 6b8ff627a187860432c6746628be4cb0ae7d6006 Mon Sep 17 00:00:00 2001 From: Az <56699741+AlchlcDvl@users.noreply.github.com> Date: Thu, 5 Nov 2026 20:24:28 -0500 Subject: [PATCH 2/9] quick player menu fix Co-Authored-By: IdkImNeil <69025896+idkimneil@users.noreply.github.com> --- MiraAPI/Hud/CustomPlayerMenu.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/MiraAPI/Hud/CustomPlayerMenu.cs b/MiraAPI/Hud/CustomPlayerMenu.cs index 26c3b94b..e0c0a777 100644 --- a/MiraAPI/Hud/CustomPlayerMenu.cs +++ b/MiraAPI/Hud/CustomPlayerMenu.cs @@ -89,6 +89,22 @@ public class CustomPlayerMenu : CustomMultiSelectMenu { var flag = PlayerControl.LocalPlayer.Data.Role.NameColor == entry.Data.Role.NameColor; panel.SetPlayer(i, entry.Data, (Il2CppSystem.Action)onClick); + var outfit = entry.Data.DefaultOutfit; + + if (entry.Data.IsDead) + { + var currentOutfit = entry.CurrentOutfit; + + if (!string.IsNullOrEmpty(currentOutfit.SkinId)) + { + outfit = currentOutfit; + } + } + + panel.PlayerIcon.cosmetics.SetSkin(outfit.SkinId, outfit.ColorId); + panel.PlayerIcon.cosmetics.SetHat(outfit.HatId, outfit.ColorId); + panel.PlayerIcon.cosmetics.SetVisor(outfit.VisorId, outfit.ColorId); + panel.NameText.color = flag ? entry.Data.Role.NameColor : Color.white; } } From 01925d94e40558cd2f8884fa766f5592b1076172 Mon Sep 17 00:00:00 2001 From: Atony <75191600+AtonyGit@users.noreply.github.com> Date: Thu, 5 Nov 2026 21:18:14 -0600 Subject: [PATCH 3/9] meet potential fix --- MiraAPI/Patches/RoleGuidePatches.cs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/MiraAPI/Patches/RoleGuidePatches.cs b/MiraAPI/Patches/RoleGuidePatches.cs index dfb9bac4..8cc2a67d 100644 --- a/MiraAPI/Patches/RoleGuidePatches.cs +++ b/MiraAPI/Patches/RoleGuidePatches.cs @@ -1168,11 +1168,21 @@ public static class RoleGuidePatches { ComputeCounts(entry); entry.Visible = entry.CanShow && MatchesSearch(entry, searchText); + + // This *was* using dynamic, but we believe it's crashing android. if (entry.Panel) { - dynamic entryType = entry.Modifier != null ? entry.Modifier : entry.Role!; - var text = GetPanelCountText(entryType, entry.Amount, entry.Chance, entry.ModId); - SetPanelCount(entry.Panel!, text); + if (entry.Modifier != null) + { + var text = GetPanelCountText(entry.Modifier, entry.Amount, entry.Chance, entry.ModId); + SetPanelCount(entry.Panel!, text); + } + else + { + var text = GetPanelCountText(entry.Role!, entry.Amount, entry.Chance, entry.ModId); + SetPanelCount(entry.Panel!, text); + } + if (!entry.Visible && entry.Panel!.gameObject.activeSelf) { entry.Panel.gameObject.SetActive(false); From 115e5fde5de8859a45d9740bea45373b9ea9c2b5 Mon Sep 17 00:00:00 2001 From: Atony <75191600+AtonyGit@users.noreply.github.com> Date: Thu, 5 Nov 2026 21:29:55 -0600 Subject: [PATCH 4/9] Revert "meet potential fix" This reverts commit 01925d94e40558cd2f8884fa766f5592b1076172. --- MiraAPI/Patches/RoleGuidePatches.cs | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/MiraAPI/Patches/RoleGuidePatches.cs b/MiraAPI/Patches/RoleGuidePatches.cs index 8cc2a67d..dfb9bac4 100644 --- a/MiraAPI/Patches/RoleGuidePatches.cs +++ b/MiraAPI/Patches/RoleGuidePatches.cs @@ -1168,21 +1168,11 @@ public static class RoleGuidePatches { ComputeCounts(entry); entry.Visible = entry.CanShow && MatchesSearch(entry, searchText); - - // This *was* using dynamic, but we believe it's crashing android. if (entry.Panel) { - if (entry.Modifier != null) - { - var text = GetPanelCountText(entry.Modifier, entry.Amount, entry.Chance, entry.ModId); - SetPanelCount(entry.Panel!, text); - } - else - { - var text = GetPanelCountText(entry.Role!, entry.Amount, entry.Chance, entry.ModId); - SetPanelCount(entry.Panel!, text); - } - + dynamic entryType = entry.Modifier != null ? entry.Modifier : entry.Role!; + var text = GetPanelCountText(entryType, entry.Amount, entry.Chance, entry.ModId); + SetPanelCount(entry.Panel!, text); if (!entry.Visible && entry.Panel!.gameObject.activeSelf) { entry.Panel.gameObject.SetActive(false); From 9874713ec8e2783b5cb5e1a075e41a124a732109 Mon Sep 17 00:00:00 2001 From: Az <56699741+AlchlcDvl@users.noreply.github.com> Date: Thu, 5 Nov 2026 22:41:55 -0500 Subject: [PATCH 5/9] experimental settings sync fix + improvements --- MiraAPI/Patches/AmongUsClientSyncPatch.cs | 27 +++++++++++++---- MiraAPI/Patches/Options/SettingPatches.cs | 4 +-- MiraAPI/Patches/RoleGuidePatches.cs | 2 +- MiraAPI/Utilities/Helpers.cs | 36 ++++++++++------------- MiraAPI/Utilities/StateMachineWrapper.cs | 15 +++++----- 5 files changed, 48 insertions(+), 36 deletions(-) diff --git a/MiraAPI/Patches/AmongUsClientSyncPatch.cs b/MiraAPI/Patches/AmongUsClientSyncPatch.cs index 926004d6..9fb6cbb6 100644 --- a/MiraAPI/Patches/AmongUsClientSyncPatch.cs +++ b/MiraAPI/Patches/AmongUsClientSyncPatch.cs @@ -1,23 +1,35 @@ -using HarmonyLib; +using System.Reflection; +using HarmonyLib; +using Il2CppInterop.Runtime.InteropTypes; using InnerNet; using MiraAPI.Events; using MiraAPI.Events.Vanilla.Player; using MiraAPI.GameModes; using MiraAPI.GameOptions; using MiraAPI.Roles; +using MiraAPI.Utilities; namespace MiraAPI.Patches; /// /// Sync all settings to the player when they join the game. /// -[HarmonyPatch(typeof(AmongUsClient))] +[HarmonyPatch] internal static class AmongUsClientSyncPatch { - [HarmonyPostfix] - [HarmonyPatch(typeof(AmongUsClient), nameof(AmongUsClient.CreatePlayer))] - public static void CreatePlayerPatch(ClientData clientData) + public static MethodBase TargetMethod() { + return Helpers.GetStateMachineMoveNext(nameof(AmongUsClient.CreatePlayer))!; + } + + [HarmonyPostfix] + public static void CreatePlayerPatch(Il2CppObjectBase __instance, bool __result) + { + if (__result) + return; + + var wrapper = new StateMachineWrapper(__instance); + var clientData = wrapper.GetParameter("clientData"); var joinEvent = new PlayerJoinEvent(clientData); MiraEventManager.InvokeEvent(joinEvent); @@ -35,9 +47,12 @@ internal static class AmongUsClientSyncPatch CustomRoleManager.SyncAllRoleSettings(clientData.Id); GameModeOption.RpcSyncGamemode(PlayerControl.LocalPlayer, GameModeOption.Value); } +} +[HarmonyPatch(typeof(AmongUsClient), nameof(AmongUsClient.OnPlayerLeft))] +internal static class AmongUsClientSyncPatch2 +{ [HarmonyPrefix] - [HarmonyPatch(typeof(AmongUsClient), nameof(AmongUsClient.OnPlayerLeft))] public static void PlayerLeftPatch(ClientData data, DisconnectReasons reason) { var leftEvent = new PlayerLeaveEvent(data, reason); diff --git a/MiraAPI/Patches/Options/SettingPatches.cs b/MiraAPI/Patches/Options/SettingPatches.cs index 1ef854b5..df2a31c7 100644 --- a/MiraAPI/Patches/Options/SettingPatches.cs +++ b/MiraAPI/Patches/Options/SettingPatches.cs @@ -52,7 +52,7 @@ public static class SettingPatches MiraNumberSuffixes.None => part, MiraNumberSuffixes.Multiplier => part + "x", MiraNumberSuffixes.Percent => part + "%", - MiraNumberSuffixes.Distance => string.Concat(part, " ", MiraApiPlugin.DistanceSuffix.Value), + MiraNumberSuffixes.Distance => part + MiraApiPlugin.DistanceSuffix.Value, _ => TranslationController.Instance.GetString(StringNames.GameSecondsAbbrev, part), }; } @@ -69,7 +69,7 @@ public static class SettingPatches MiraNumberSuffixes.None => part, MiraNumberSuffixes.Multiplier => part + "x", MiraNumberSuffixes.Percent => part + "%", - MiraNumberSuffixes.Distance => string.Concat(part, " ", MiraApiPlugin.DistanceSuffix.Value), + MiraNumberSuffixes.Distance => part + MiraApiPlugin.DistanceSuffix.Value, _ => TranslationController.Instance.GetString(StringNames.GameSecondsAbbrev, part), }; } diff --git a/MiraAPI/Patches/RoleGuidePatches.cs b/MiraAPI/Patches/RoleGuidePatches.cs index 8cc2a67d..198e2774 100644 --- a/MiraAPI/Patches/RoleGuidePatches.cs +++ b/MiraAPI/Patches/RoleGuidePatches.cs @@ -296,7 +296,7 @@ public static class RoleGuidePatches if (_titleText) { _titleText.transform.localPosition += new Vector3(0.5f, 0); - _titleText.transform.GetComponent().Destroy(); + _titleText.GetComponent().Destroy(); } } diff --git a/MiraAPI/Utilities/Helpers.cs b/MiraAPI/Utilities/Helpers.cs index 823cdce4..638c41a4 100644 --- a/MiraAPI/Utilities/Helpers.cs +++ b/MiraAPI/Utilities/Helpers.cs @@ -177,7 +177,7 @@ public static class Helpers { var keybindIcon = Object.Instantiate(HudManager.Instance.AbilityButton.usesRemainingSprite.gameObject, button.transform); keybindIcon.GetComponent().sprite = MiraAssets.KeybindButton.LoadAsset(); - keybindIcon.transform.GetComponentInChildren().text = keyCode.ToString(); + keybindIcon.GetComponentInChildren().text = keyCode.ToString(); keybindIcon.name = "KeybindIcon"; keybindIcon.transform.localPosition = localPos; return keybindIcon; @@ -191,26 +191,21 @@ public static class Helpers /// THe corresponding method to patch. public static MethodBase? GetStateMachineMoveNext(string methodName) { - var typeName = typeof(T).FullName; - var showRoleStateMachine = - typeof(T) - .GetNestedTypes() - .FirstOrDefault(x => x.Name.Contains(methodName)); + var stateMachine = typeof(T).GetNestedTypes().FirstOrDefault(x => x.Name.Contains(methodName, StringComparison.Ordinal)); - if (showRoleStateMachine == null) + if (stateMachine == null) { - Error($"Failed to find {methodName} state machine for {typeName}"); + Error($"Failed to find {methodName} state machine for {typeof(T).FullName}"); return null; } - var moveNext = AccessTools.Method(showRoleStateMachine, "MoveNext"); + var moveNext = AccessTools.Method(stateMachine, "MoveNext"); + if (moveNext == null) - { - Error($"Failed to find MoveNext method for {typeName}.{methodName}"); - return null; - } + Error($"Failed to find MoveNext method for {typeof(T).FullName}.{methodName}"); + else + Info($"Found {methodName}.MoveNext"); - Info($"Found {methodName}.MoveNext"); return moveNext; } @@ -619,6 +614,7 @@ public static class Helpers MiraNumberSuffixes.Multiplier => "x", MiraNumberSuffixes.Seconds => "s", MiraNumberSuffixes.Percent => "%", + MiraNumberSuffixes.Distance => MiraApiPlugin.DistanceSuffix.Value, _ => string.Empty, }; } @@ -653,14 +649,14 @@ public static class Helpers /// The formatted value. public static string FormatValue(float value, MiraNumberSuffixes suffix = MiraNumberSuffixes.None, string formatString = "0.0") { + var part = value.ToString(formatString, NumberFormatInfo.InvariantInfo); return suffix switch { - MiraNumberSuffixes.None => value.ToString(formatString, NumberFormatInfo.InvariantInfo), - MiraNumberSuffixes.Multiplier => value.ToString(formatString, NumberFormatInfo.InvariantInfo) + "x", - MiraNumberSuffixes.Percent => value.ToString(formatString, NumberFormatInfo.InvariantInfo) + "%", - _ => TranslationController.Instance.GetString( - StringNames.GameSecondsAbbrev, - (Il2CppSystem.Object[])[value.ToString(formatString, CultureInfo.InvariantCulture)]), + MiraNumberSuffixes.None => part, + MiraNumberSuffixes.Percent => part + "%", + MiraNumberSuffixes.Multiplier => part + "x", + MiraNumberSuffixes.Distance => part + MiraApiPlugin.DistanceSuffix.Value, + _ => TranslationController.Instance.GetString(StringNames.GameSecondsAbbrev, part), }; } diff --git a/MiraAPI/Utilities/StateMachineWrapper.cs b/MiraAPI/Utilities/StateMachineWrapper.cs index 6b9d683d..cfe5d8a1 100644 --- a/MiraAPI/Utilities/StateMachineWrapper.cs +++ b/MiraAPI/Utilities/StateMachineWrapper.cs @@ -21,6 +21,7 @@ public class StateMachineWrapper private readonly PropertyInfo _stateProperty; private readonly PropertyInfo _currentProperty; private readonly Dictionary _propertyCache; + private readonly Type _type; private T? _parentInstance; @@ -37,14 +38,14 @@ public class StateMachineWrapper { _stateMachine = stateMachine; - var type = _stateMachine.GetType(); - _thisProperty = AccessTools.Property(type, "__4__this"); - _stateProperty = AccessTools.Property(type, "__1__state"); - _currentProperty = AccessTools.Property(type, "__2__current"); + _type = _stateMachine.GetType(); + _thisProperty = AccessTools.Property(_type, "__4__this"); + _stateProperty = AccessTools.Property(_type, "__1__state"); + _currentProperty = AccessTools.Property(_type, "__2__current"); if (_thisProperty == null || _stateProperty == null || _currentProperty == null) { - throw new MissingMemberException($"Could not find required properties in type '{type}'."); + throw new MissingMemberException($"Could not find required properties in type '{_type}'."); } _propertyCache = []; @@ -91,8 +92,8 @@ public class StateMachineWrapper return (TField)property.GetValue(_stateMachine)!; } - property = AccessTools.Property(_stateMachine.GetType(), parameterName) - ?? throw new MissingFieldException($"Could not find parameter '{parameterName}' in state machine of type '{_stateMachine.GetType()}'."); + property = AccessTools.Property(_type, parameterName) + ?? throw new MissingFieldException($"Could not find parameter '{parameterName}' in state machine of type '{_type.Name}'."); _propertyCache[parameterName] = property; return (TField)property.GetValue(_stateMachine)!; From f06562a28106a92d57d53b6590b97ff6e11ac0fe Mon Sep 17 00:00:00 2001 From: Az <56699741+AlchlcDvl@users.noreply.github.com> Date: Thu, 5 Nov 2026 23:05:03 -0500 Subject: [PATCH 6/9] remove useless `.gameObject` uses --- MiraAPI/Hud/CustomPaginableMenu.cs | 8 ++++---- .../ModifierDisplay/ModifierUiComponent.cs | 2 +- .../Patches/Options/GameOptionsMenuPatch.cs | 4 ++-- .../Patches/Options/GamePresetsTabPatches.cs | 4 ++-- .../Patches/Options/GameSettingMenuPatches.cs | 5 +++-- .../Patches/Options/LobbyViewPanePatches.cs | 6 +++--- MiraAPI/Patches/Options/MenuState.cs | 20 +++++++++---------- .../Patches/Options/RoleSettingMenuPatches.cs | 2 +- MiraAPI/Patches/RoleGuidePatches.cs | 13 +++--------- MiraAPI/Roles/CustomRoleManager.cs | 4 ++-- MiraAPI/Utilities/Extensions.cs | 15 ++++++++++++++ MiraAPI/Utilities/Helpers.cs | 2 +- 12 files changed, 47 insertions(+), 38 deletions(-) diff --git a/MiraAPI/Hud/CustomPaginableMenu.cs b/MiraAPI/Hud/CustomPaginableMenu.cs index aca20b53..c8ef1cef 100644 --- a/MiraAPI/Hud/CustomPaginableMenu.cs +++ b/MiraAPI/Hud/CustomPaginableMenu.cs @@ -72,18 +72,18 @@ public abstract class CustomPaginableMenu : CustomPhoneMenu().sprite = MiraAssets.NextButton.LoadAsset(); - nextButton.gameObject.GetComponent().DestroyImmediate(); + nextButton.GetComponent().DestroyImmediate(); - var passiveButton = nextButton.gameObject.GetComponent(); + var passiveButton = nextButton.GetComponent(); passiveButton.OnClick = new Button.ButtonClickedEvent(); passiveButton.OnClick.AddListener((UnityAction)customMenu.NextPage); var backButton = Object.Instantiate(nextButton, customMenu.transform).gameObject; backButton.transform.localPosition = new Vector3(-1.85f, -2.185f, customMenu.MenuDepth); backButton.name = "LeftArrowButton"; - backButton.gameObject.GetComponent().Destroy(); + backButton.GetComponent().Destroy(); backButton.GetComponent().flipX = true; - var prevPassive = backButton.gameObject.GetComponent(); + var prevPassive = backButton.GetComponent(); prevPassive.OnClick.AddListener((UnityAction)customMenu.PreviousPage); customMenu.PhoneUI.GetChild(0).GetComponent().material = diff --git a/MiraAPI/Modifiers/ModifierDisplay/ModifierUiComponent.cs b/MiraAPI/Modifiers/ModifierDisplay/ModifierUiComponent.cs index 3c66358b..8638f75e 100644 --- a/MiraAPI/Modifiers/ModifierDisplay/ModifierUiComponent.cs +++ b/MiraAPI/Modifiers/ModifierDisplay/ModifierUiComponent.cs @@ -37,7 +37,7 @@ public class ModifierUiComponent(nint cppPtr) : MonoBehaviour(cppPtr) icon = modBg.transform.GetChild(1).GetComponent(); var nameBg = transform.GetChild(1); nameText = nameBg.GetChild(0).GetComponent(); - descRect = desc.gameObject.GetComponent(); + descRect = desc.GetComponent(); nameText.font = desc.font = HudManager.Instance.TaskPanel.taskText.font; nameText.fontMaterial = desc.fontMaterial = HudManager.Instance.TaskPanel.taskText.fontMaterial; diff --git a/MiraAPI/Patches/Options/GameOptionsMenuPatch.cs b/MiraAPI/Patches/Options/GameOptionsMenuPatch.cs index 0799bf2f..3d19f0f6 100644 --- a/MiraAPI/Patches/Options/GameOptionsMenuPatch.cs +++ b/MiraAPI/Patches/Options/GameOptionsMenuPatch.cs @@ -313,7 +313,7 @@ internal static class GameOptionsMenuPatch }; _modIcon = modIconObj.AddComponent(); _modIcon.sprite = MiraAssets.BlankSprite.LoadAsset(); - _modIcon.material = gamemodeBg.gameObject.GetComponent().material; + _modIcon.material = gamemodeBg.GetComponent().material; var gamemodeTextObj = Object.Instantiate(GameModeOption.OptionBehaviour.transform.GetChild(1).gameObject, modeInfoHolder); gamemodeTextObj.transform.localPosition = new Vector3(0.3f, 0, -0.01f); @@ -739,7 +739,7 @@ internal static class GameOptionsMenuPatch var newText = Object.Instantiate(categoryHeaderMasked.Title, categoryHeaderMasked.transform); newText.text = $"({"MiraApi.GameSetting.Global.ClickToClose".Translate()})"; newText.transform.localPosition = new Vector3(2.6249f, -0.165f, 0f); - newText.gameObject.GetComponent().Destroy(); + newText.GetComponent().Destroy(); var boxCol = categoryHeaderMasked.gameObject.AddComponent(); boxCol.size = new Vector2(7, 0.7f); diff --git a/MiraAPI/Patches/Options/GamePresetsTabPatches.cs b/MiraAPI/Patches/Options/GamePresetsTabPatches.cs index 4bf0cf83..a759cc1e 100644 --- a/MiraAPI/Patches/Options/GamePresetsTabPatches.cs +++ b/MiraAPI/Patches/Options/GamePresetsTabPatches.cs @@ -164,7 +164,7 @@ internal static class GamePresetsTabPatches return; } - var tmpTranslator = presetTab.PresetDescriptionText.gameObject.GetComponent(); + var tmpTranslator = presetTab.PresetDescriptionText.GetComponent(); if (tmpTranslator) { tmpTranslator.Destroy(); @@ -282,7 +282,7 @@ internal static class GamePresetsTabPatches _folderButton.name = "OpenFolderButton"; _folderButton.transform.localPosition = new Vector3(3.55f, 1.1f, -2); - var folderRend = openFolderButton.transform.FindChild("Sprite").gameObject.GetComponent(); + var folderRend = openFolderButton.transform.FindChild("Sprite").GetComponent(); folderRend.sprite = MiraAssets.FolderIcon.LoadAsset(); folderRend.transform.localScale = new Vector3(0.4f, 0.4f, 1); diff --git a/MiraAPI/Patches/Options/GameSettingMenuPatches.cs b/MiraAPI/Patches/Options/GameSettingMenuPatches.cs index 6c1ede7a..47c45a06 100644 --- a/MiraAPI/Patches/Options/GameSettingMenuPatches.cs +++ b/MiraAPI/Patches/Options/GameSettingMenuPatches.cs @@ -20,9 +20,10 @@ internal static class GameSettingMenuPatches } // Add Menu State object - if (!__instance.gameObject.GetComponent()) + __instance.gameObject.GetOrAddComponent(out var existed); + + if (!existed) { - __instance.gameObject.AddComponent(); Info("MenuState component added to GameSettingMenu."); } else diff --git a/MiraAPI/Patches/Options/LobbyViewPanePatches.cs b/MiraAPI/Patches/Options/LobbyViewPanePatches.cs index c77f93d1..79315f3a 100644 --- a/MiraAPI/Patches/Options/LobbyViewPanePatches.cs +++ b/MiraAPI/Patches/Options/LobbyViewPanePatches.cs @@ -72,7 +72,7 @@ public static class LobbyViewPanePatches // create modifiers button modifiersTabButton = Object.Instantiate(__instance.rolesTabButton, __instance.rolesTabButton.transform.parent); - modifiersTabButton.buttonText.gameObject.GetComponent().Destroy(); + modifiersTabButton.buttonText.GetComponent().Destroy(); modifiersTabButton.name = "ModifiersTabButton"; var pos = modifiersTabButton.transform.localPosition; pos.x = 2.1f; @@ -101,7 +101,7 @@ public static class LobbyViewPanePatches hover.transform.localPosition = new Vector3(0, 0f, 0.3f); hover.sprite = MiraAssets.NextButtonActive.LoadAsset(); - var passiveButton = nextButton.gameObject.GetComponent(); + var passiveButton = nextButton.GetComponent(); passiveButton.OnClick = new Button.ButtonClickedEvent(); passiveButton.OnClick.AddListener( (UnityAction)(() => @@ -123,7 +123,7 @@ public static class LobbyViewPanePatches = backButton.transform.FindChild("Hover").gameObject.GetComponentInChildren().flipX = true; - var passiveButton2 = backButton.gameObject.GetComponent(); + var passiveButton2 = backButton.GetComponent(); passiveButton2.OnClick = new Button.ButtonClickedEvent(); passiveButton2.OnClick.AddListener( (UnityAction)(() => diff --git a/MiraAPI/Patches/Options/MenuState.cs b/MiraAPI/Patches/Options/MenuState.cs index 66876991..ee3c75f9 100644 --- a/MiraAPI/Patches/Options/MenuState.cs +++ b/MiraAPI/Patches/Options/MenuState.cs @@ -121,24 +121,24 @@ public class MenuState(IntPtr cppPtr) : MonoBehaviour(cppPtr) var nextButton = Instantiate(Gsm.BackButton, Gsm.BackButton.transform.parent).gameObject; nextButton.transform.localPosition = new Vector3(-2.2663f, 1.5272f, -25f); nextButton.name = "RightArrowButton"; - nextButton.transform.FindChild("Inactive").gameObject.GetComponent().sprite = + nextButton.transform.FindChild("Inactive").GetComponent().sprite = MiraAssets.NextButton.LoadAsset(); - nextButton.transform.FindChild("Active").gameObject.GetComponent().sprite = + nextButton.transform.FindChild("Active").GetComponent().sprite = MiraAssets.NextButtonActive.LoadAsset(); - nextButton.gameObject.GetComponent().DestroyImmediate(); + nextButton.GetComponent().DestroyImmediate(); - var nextPassiveButton = nextButton.gameObject.GetComponent(); + var nextPassiveButton = nextButton.GetComponent(); nextPassiveButton.OnClick = new Button.ButtonClickedEvent(); nextPassiveButton.OnClick.AddListener((UnityAction)NextMod); var previousButton = Instantiate(nextButton, Gsm.BackButton.transform.parent).gameObject; previousButton.transform.localPosition = new Vector3(-4.4209f, 1.5272f, -25f); previousButton.name = "LeftArrowButton"; - previousButton.gameObject.GetComponent().Destroy(); - previousButton.transform.FindChild("Active").gameObject.GetComponent().flipX = - previousButton.transform.FindChild("Inactive").gameObject.GetComponent().flipX = true; + previousButton.GetComponent().Destroy(); + previousButton.transform.FindChild("Active").GetComponent().flipX = + previousButton.transform.FindChild("Inactive").GetComponent().flipX = true; - var prevPassiveButton = previousButton.gameObject.GetComponent(); + var prevPassiveButton = previousButton.GetComponent(); prevPassiveButton.OnClick = new Button.ButtonClickedEvent(); prevPassiveButton.OnClick.AddListener((UnityAction)PreviousMod); @@ -149,7 +149,7 @@ public class MenuState(IntPtr cppPtr) : MonoBehaviour(cppPtr) var mBtn = Instantiate(Gsm.RoleSettingsButton, Gsm.RoleSettingsButton.transform.parent); _largeButtons[MenuButton.Modifiers] = mBtn; mBtn.name = "ModifiersButton"; - mBtn.buttonText.gameObject.GetComponent().Destroy(); + mBtn.buttonText.GetComponent().Destroy(); mBtn.buttonText.text = "Modifiers".Translate(); mBtn.OnClick = new Button.ButtonClickedEvent(); mBtn.OnClick.AddListener( @@ -168,7 +168,7 @@ public class MenuState(IntPtr cppPtr) : MonoBehaviour(cppPtr) var c1Btn = Instantiate(mBtn, mBtn.transform.parent); _largeButtons[MenuButton.CustomOne] = c1Btn; c1Btn.name = "CustomOneButton"; - c1Btn.buttonText.gameObject.GetComponent().Destroy(); + c1Btn.buttonText.GetComponent().Destroy(); c1Btn.OnClick = new Button.ButtonClickedEvent(); c1Btn.OnClick.AddListener( (UnityAction)(() => diff --git a/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs b/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs index aa6396df..41e376d3 100644 --- a/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs +++ b/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs @@ -309,7 +309,7 @@ public static class RoleSettingMenuPatches var newText = Object.Instantiate(categoryHeaderMasked.Title, categoryHeaderMasked.transform); newText.text = $"{label}"; newText.transform.localPosition = new Vector3(2.6249f, -0.165f, 0f); - newText.gameObject.GetComponent().Destroy(); + newText.GetComponent().Destroy(); scrollerNum -= 0.422f; diff --git a/MiraAPI/Patches/RoleGuidePatches.cs b/MiraAPI/Patches/RoleGuidePatches.cs index 198e2774..239e3115 100644 --- a/MiraAPI/Patches/RoleGuidePatches.cs +++ b/MiraAPI/Patches/RoleGuidePatches.cs @@ -1575,20 +1575,13 @@ public static class RoleGuidePatches private static void SetupPanelButton(MatchInfoRolePanel panel, Action onClick) { - var collider = panel.roleIcon.gameObject.GetComponent(); - if (!collider) - { - collider = panel.roleIcon.gameObject.AddComponent(); - } + var collider = panel.roleIcon.gameObject.GetOrAddComponent(); collider.size = new Vector2(0.13f, 0.13f); collider.offset = new Vector2(0, 0); collider.enabled = true; - var passiveButton = panel.roleIcon.gameObject.GetComponent(); - if (!passiveButton) - { - passiveButton = panel.roleIcon.gameObject.AddComponent(); - } + + var passiveButton = panel.roleIcon.gameObject.GetOrAddComponent(); passiveButton.enabled = true; passiveButton.ClickSound = HudManager.Instance.MapButton.ClickSound; diff --git a/MiraAPI/Roles/CustomRoleManager.cs b/MiraAPI/Roles/CustomRoleManager.cs index d89e40a9..3b48087c 100644 --- a/MiraAPI/Roles/CustomRoleManager.cs +++ b/MiraAPI/Roles/CustomRoleManager.cs @@ -239,7 +239,7 @@ public static class CustomRoleManager internal static TaskPanelBehaviour CreateRoleTab(ICustomRole role) { - var ogPanel = HudManager.Instance.TaskStuff.transform.FindChild("TaskPanel").gameObject.GetComponent(); + var ogPanel = HudManager.Instance.TaskStuff.transform.FindChild("TaskPanel").GetComponent(); var clonePanel = Object.Instantiate(ogPanel.gameObject, ogPanel.transform.parent); clonePanel.name = "RolePanel"; @@ -258,7 +258,7 @@ public static class CustomRoleManager internal static void UpdateRoleTab(TaskPanelBehaviour panel, ICustomRole role) { var tabText = panel.tab.gameObject.GetComponentInChildren(); - var ogPanel = HudManager.Instance.TaskStuff.transform.FindChild("TaskPanel").gameObject.GetComponent(); + var ogPanel = HudManager.Instance.TaskStuff.transform.FindChild("TaskPanel").GetComponent(); if (tabText.text != role.RoleName) { tabText.text = role.RoleName; diff --git a/MiraAPI/Utilities/Extensions.cs b/MiraAPI/Utilities/Extensions.cs index 0446e84f..d3a0fbae 100644 --- a/MiraAPI/Utilities/Extensions.cs +++ b/MiraAPI/Utilities/Extensions.cs @@ -843,6 +843,21 @@ public static class Extensions return comp ? comp : go.AddComponent(); } + /// + /// Gets a component that is attached to the provided , attaching and returning the component if it wasn't found, and returns a bool that indicates if the component already existed before. + /// + /// The component type. + /// The to get the component from. + /// When this method returns true if the component already existed; otherwise false. + /// The component. + public static T GetOrAddComponent(this GameObject go, out bool exists) + where T : Component + { + var comp = go.GetComponent(); + exists = comp; + return exists ? comp : go.AddComponent(); + } + /// /// The type of the attribute. /// true if a custom attribute of type is applied to element; otherwise, false. diff --git a/MiraAPI/Utilities/Helpers.cs b/MiraAPI/Utilities/Helpers.cs index 638c41a4..f5d7d25d 100644 --- a/MiraAPI/Utilities/Helpers.cs +++ b/MiraAPI/Utilities/Helpers.cs @@ -304,7 +304,7 @@ public static class Helpers { var prefab = Object.FindObjectOfType(true); var arrow = Object.Instantiate(prefab, parent); - arrow.image = arrow.gameObject.GetComponent(); + arrow.image = arrow.GetComponent(); arrow.image.color = color; arrow.gameObject.layer = 5; arrow.gameObject.SetActive(true); From ca285d4af665eb3d75454fa8a3a9345784fe5735 Mon Sep 17 00:00:00 2001 From: Az <56699741+AlchlcDvl@users.noreply.github.com> Date: Thu, 5 Nov 2026 23:48:28 -0500 Subject: [PATCH 7/9] removing even more useless calls --- MiraAPI/Hud/CustomPhoneMenu.cs | 4 ++-- MiraAPI/MeetingAbilities/TargetedMeetingButton.cs | 2 +- MiraAPI/MiraApiSettings.cs | 12 ++++++------ MiraAPI/Patches/Freeplay/TaskAdderPatches.cs | 3 +-- MiraAPI/Patches/GameModes/HudPatches.cs | 4 ++-- MiraAPI/Patches/HudManagerPatches.cs | 10 +++++----- MiraAPI/Patches/Options/GamePresetsTabPatches.cs | 2 +- MiraAPI/Patches/Options/MenuState.cs | 4 ++-- MiraAPI/Patches/Options/RoleSettingMenuPatches.cs | 4 ++-- MiraAPI/Patches/PlayerControlPatches.cs | 4 ++-- MiraAPI/Patches/Roles/RoleManagerPatches.cs | 2 +- MiraAPI/Patches/Roles/TaskPanelPatch.cs | 2 +- MiraAPI/Presets/SavePresetPopup.cs | 2 +- MiraAPI/Roles/CustomRoleManager.cs | 2 +- 14 files changed, 28 insertions(+), 29 deletions(-) diff --git a/MiraAPI/Hud/CustomPhoneMenu.cs b/MiraAPI/Hud/CustomPhoneMenu.cs index 1f636f73..55af740f 100644 --- a/MiraAPI/Hud/CustomPhoneMenu.cs +++ b/MiraAPI/Hud/CustomPhoneMenu.cs @@ -260,7 +260,7 @@ public abstract class CustomPhoneMenu : ICustomMenu MenuEntries.Add(menuEntry); var button = shapeshifterPanel.Button; - var nameplate = shapeshifterPanel.gameObject.transform.FindChild("Nameplate"); + var nameplate = shapeshifterPanel.transform.FindChild("Nameplate"); var highlight = nameplate.FindChild("Highlight").GetComponent(); var icon = highlight.transform.GetChild(0).GetComponent(); @@ -317,7 +317,7 @@ public abstract class CustomPhoneMenu : ICustomMenu { ShapeshifterPanel panel = menuEntry.Panel; - var nameplate = panel.gameObject.transform.FindChild("Nameplate"); + var nameplate = panel.transform.FindChild("Nameplate"); var highlight = nameplate.FindChild("Highlight").GetComponent(); var icon = highlight.transform.GetChild(0).GetComponent(); if (sprite != null) diff --git a/MiraAPI/MeetingAbilities/TargetedMeetingButton.cs b/MiraAPI/MeetingAbilities/TargetedMeetingButton.cs index 2d4766e4..aeeeedd8 100644 --- a/MiraAPI/MeetingAbilities/TargetedMeetingButton.cs +++ b/MiraAPI/MeetingAbilities/TargetedMeetingButton.cs @@ -89,7 +89,7 @@ public abstract class TargetedMeetingButton if (MeetingHud.Instance == null) return null!; var btn = Object.Instantiate(MeetingHud.Instance.PlayerButtonPrefab.ConfirmButton).GetComponent(); - btn.gameObject.name = Name + "Button"; + btn.name = Name + "Button"; var spriteRenderer = btn.GetComponent(); spriteRenderer.sprite = Sprite.LoadAsset(); diff --git a/MiraAPI/MiraApiSettings.cs b/MiraAPI/MiraApiSettings.cs index 2240d0c1..ce722351 100644 --- a/MiraAPI/MiraApiSettings.cs +++ b/MiraAPI/MiraApiSettings.cs @@ -144,15 +144,15 @@ public class MiraApiSettings(ConfigFile config) : LocalSettingsTab(config) if (button.transform.name.Contains("Friends List Button")) { - button.gameObject.transform.localScale = new Vector3(0.2675f * actualScaleVal, 0.2675f * actualScaleVal, 1); + button.transform.localScale = new Vector3(0.2675f * actualScaleVal, 0.2675f * actualScaleVal, 1); continue; } - button.gameObject.transform.localScale = actualScale; + button.transform.localScale = actualScale; } baseGrid.CellSize = new Vector2(alteredScale, alteredScale); - if (baseGrid.gameObject.transform.childCount != 0) + if (baseGrid.transform.childCount != 0) { baseGrid.ArrangeChilds(); } @@ -175,15 +175,15 @@ public class MiraApiSettings(ConfigFile config) : LocalSettingsTab(config) if (button.transform.name.Contains("Modifiers")) { - button.gameObject.transform.localScale = new Vector3(0.65f * scaleFactor, 0.65f * scaleFactor, 1); + button.transform.localScale = new Vector3(0.65f * scaleFactor, 0.65f * scaleFactor, 1); continue; } - button.gameObject.transform.localScale = actualScale; + button.transform.localScale = actualScale; } extraGrid.CellSize = new Vector2(alteredScale, alteredScale); - if (extraGrid.gameObject.transform.childCount != 0) + if (extraGrid.transform.childCount != 0) { extraGrid.ArrangeChilds(); } diff --git a/MiraAPI/Patches/Freeplay/TaskAdderPatches.cs b/MiraAPI/Patches/Freeplay/TaskAdderPatches.cs index 6a97687f..a4ba9cbd 100644 --- a/MiraAPI/Patches/Freeplay/TaskAdderPatches.cs +++ b/MiraAPI/Patches/Freeplay/TaskAdderPatches.cs @@ -111,8 +111,7 @@ public static class TaskAdderPatches if (plugin.InternalModifiers.Exists(x => x.ShowInFreeplay)) { - __instance.CreateFolder(plugin.PluginInfo.Metadata.Name, modifiersFolder) - .gameObject.name = plugin.PluginId; + __instance.CreateFolder(plugin.PluginInfo.Metadata.Name, modifiersFolder).name = plugin.PluginId; } } diff --git a/MiraAPI/Patches/GameModes/HudPatches.cs b/MiraAPI/Patches/GameModes/HudPatches.cs index 3c2d815d..325d193d 100644 --- a/MiraAPI/Patches/GameModes/HudPatches.cs +++ b/MiraAPI/Patches/GameModes/HudPatches.cs @@ -34,8 +34,8 @@ internal static class HudPatches yield return new WaitUntil((Il2CppSystem.Func)(() => GameManager.Instance != null)); if (GameManager.Instance.IsHideAndSeek()) yield return null; - var infoPane = instance.gameObject.transform.FindChild("LobbyInfoPane"); - var aspect = infoPane.gameObject.transform.Find("AspectSize"); + var infoPane = instance.transform.FindChild("LobbyInfoPane"); + var aspect = infoPane.transform.Find("AspectSize"); var modeLabel = aspect!.Find("ModeLabel"); var modeValue = aspect.Find("ModeValue"); var modelText = modeLabel!.Find("Text_TMP").gameObject; diff --git a/MiraAPI/Patches/HudManagerPatches.cs b/MiraAPI/Patches/HudManagerPatches.cs index 75b0e5e7..a6959ead 100644 --- a/MiraAPI/Patches/HudManagerPatches.cs +++ b/MiraAPI/Patches/HudManagerPatches.cs @@ -47,9 +47,9 @@ public static class HudManagerPatches { if (!aspect.gameObject) continue; - if (aspect.gameObject.transform.parent.name == "TopRight") continue; + if (aspect.transform.parent.name == "TopRight") continue; - if (aspect.gameObject.name.Contains("TopRight")) continue; + if (aspect.name.Contains("TopRight")) continue; aspect.gameObject.SetActive(!aspect.isActiveAndEnabled); aspect.DistanceFromEdge *= new Vector2(scaleFactor, scaleFactor); @@ -62,7 +62,7 @@ public static class HudManagerPatches if (!button.gameObject) continue; button.gameObject.SetActive(!button.isActiveAndEnabled); - button.gameObject.transform.localScale *= scaleFactor; + button.transform.localScale *= scaleFactor; button.gameObject.SetActive(!button.isActiveAndEnabled); } @@ -71,12 +71,12 @@ public static class HudManagerPatches { if (!arrange.gameObject || !arrange.transform) continue; - if (arrange.gameObject.name.Contains("TopRight")) continue; + if (arrange.name.Contains("TopRight")) continue; arrange.gameObject.SetActive(!arrange.isActiveAndEnabled); arrange.CellSize = new Vector2(scaleFactor, scaleFactor); arrange.gameObject.SetActive(!arrange.isActiveAndEnabled); - if (!arrange.isActiveAndEnabled || arrange.gameObject.transform.childCount == 0) continue; + if (!arrange.isActiveAndEnabled || arrange.transform.childCount == 0) continue; try { arrange.ArrangeChilds(); diff --git a/MiraAPI/Patches/Options/GamePresetsTabPatches.cs b/MiraAPI/Patches/Options/GamePresetsTabPatches.cs index a759cc1e..fe6ac117 100644 --- a/MiraAPI/Patches/Options/GamePresetsTabPatches.cs +++ b/MiraAPI/Patches/Options/GamePresetsTabPatches.cs @@ -184,7 +184,7 @@ internal static class GamePresetsTabPatches { saveButton = Object.Instantiate(prefab, presetTab.transform); _saveButton = saveButton.gameObject; - _saveButton.gameObject.name = "SaveButton"; + _saveButton.name = "SaveButton"; _saveButton.transform.localPosition = new Vector3(3.2f, 1.7f, -2); // set the button text and alignment diff --git a/MiraAPI/Patches/Options/MenuState.cs b/MiraAPI/Patches/Options/MenuState.cs index ee3c75f9..cd5e6c87 100644 --- a/MiraAPI/Patches/Options/MenuState.cs +++ b/MiraAPI/Patches/Options/MenuState.cs @@ -322,7 +322,7 @@ public class MenuState(IntPtr cppPtr) : MonoBehaviour(cppPtr) // Create game options container var gameContainer = Containers[MenuCategory.Game][idx + 1] = Instantiate( Gsm.GameSettingsTab.settingsContainer.gameObject, - Gsm.GameSettingsTab.settingsContainer.gameObject.transform.parent); + Gsm.GameSettingsTab.settingsContainer.transform.parent); gameContainer.name = $"GameSettings_{mod.PluginInfo.Metadata.Name}"; gameContainer.transform.DestroyChildren(); gameContainer.SetActive(false); @@ -340,7 +340,7 @@ public class MenuState(IntPtr cppPtr) : MonoBehaviour(cppPtr) { var cont = Containers[i][idx + 1] = Instantiate( Gsm.GameSettingsTab.settingsContainer.gameObject, - Gsm.GameSettingsTab.settingsContainer.gameObject.transform.parent); + Gsm.GameSettingsTab.settingsContainer.transform.parent); cont.name = $"{i}_{mod.PluginInfo.Metadata.Name}"; cont.transform.DestroyChildren(); cont.SetActive(false); diff --git a/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs b/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs index 41e376d3..b6372387 100644 --- a/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs +++ b/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs @@ -604,14 +604,14 @@ public static class RoleSettingMenuPatches var categoryHeaderMasked = __instance.AdvancedRolesSettings.transform.Find("CategoryHeaderMasked").GetComponent(); - if (categoryHeaderMasked.Title.gameObject.TryGetComponent(out var comp)) + if (categoryHeaderMasked.Title.TryGetComponent(out var comp)) { comp.Destroy(); } categoryHeaderMasked.Title.text = "MiraApi.ReturnToRoleSettings".Translate(); - if (!categoryHeaderMasked.gameObject.TryGetComponent(out _)) + if (!categoryHeaderMasked.TryGetComponent(out _)) { var boxCol = categoryHeaderMasked.gameObject.AddComponent(); boxCol.size = new Vector2(7, 0.7f); diff --git a/MiraAPI/Patches/PlayerControlPatches.cs b/MiraAPI/Patches/PlayerControlPatches.cs index 791334d8..89c78e36 100644 --- a/MiraAPI/Patches/PlayerControlPatches.cs +++ b/MiraAPI/Patches/PlayerControlPatches.cs @@ -22,12 +22,12 @@ internal static class PlayerControlPatches [HarmonyPatch(nameof(PlayerControl.Start))] public static void PlayerControlStartPostfix(PlayerControl __instance) { - if (__instance.gameObject.TryGetComponent(out var modifierComp)) + if (__instance.TryGetComponent(out var modifierComp)) { modifierComp.DestroyImmediate(); } - if (__instance.gameObject.TryGetComponent(out var voteComp)) + if (__instance.TryGetComponent(out var voteComp)) { voteComp.DestroyImmediate(); } diff --git a/MiraAPI/Patches/Roles/RoleManagerPatches.cs b/MiraAPI/Patches/Roles/RoleManagerPatches.cs index 82e937fc..82cf9911 100644 --- a/MiraAPI/Patches/Roles/RoleManagerPatches.cs +++ b/MiraAPI/Patches/Roles/RoleManagerPatches.cs @@ -37,7 +37,7 @@ public static class RoleManagerPatches Object.Destroy(data.Role.gameObject); } - var roleBehaviour = Object.Instantiate(__instance.AllRoles.ToArray().First(r => r.Role == roleType), data.gameObject.transform); + var roleBehaviour = Object.Instantiate(__instance.AllRoles.ToArray().First(r => r.Role == roleType), data.transform); roleBehaviour.Initialize(targetPlayer); targetPlayer.Data.Role = roleBehaviour; targetPlayer.Data.RoleType = roleType; diff --git a/MiraAPI/Patches/Roles/TaskPanelPatch.cs b/MiraAPI/Patches/Roles/TaskPanelPatch.cs index c858d9f0..e97646da 100644 --- a/MiraAPI/Patches/Roles/TaskPanelPatch.cs +++ b/MiraAPI/Patches/Roles/TaskPanelPatch.cs @@ -15,7 +15,7 @@ internal static class TaskPanelPatch [HarmonyPatch(nameof(TaskPanelBehaviour.Update))] public static bool UpdatePrefix(TaskPanelBehaviour __instance) { - if (__instance.gameObject.name != "RolePanel") + if (__instance.name != "RolePanel") { return true; } diff --git a/MiraAPI/Presets/SavePresetPopup.cs b/MiraAPI/Presets/SavePresetPopup.cs index 9405e83b..d2db31ba 100644 --- a/MiraAPI/Presets/SavePresetPopup.cs +++ b/MiraAPI/Presets/SavePresetPopup.cs @@ -70,7 +70,7 @@ public class SavePresetPopup(nint cppPtr) : Minigame(cppPtr) foreach (var tmp in gameObject.GetComponentsInChildren()) { - if (tmp.gameObject.transform.parent.name == "Textbox") + if (tmp.transform.parent.name == "Textbox") { continue; } diff --git a/MiraAPI/Roles/CustomRoleManager.cs b/MiraAPI/Roles/CustomRoleManager.cs index 3b48087c..d9325e6a 100644 --- a/MiraAPI/Roles/CustomRoleManager.cs +++ b/MiraAPI/Roles/CustomRoleManager.cs @@ -257,7 +257,7 @@ public static class CustomRoleManager internal static void UpdateRoleTab(TaskPanelBehaviour panel, ICustomRole role) { - var tabText = panel.tab.gameObject.GetComponentInChildren(); + var tabText = panel.tab.GetComponentInChildren(); var ogPanel = HudManager.Instance.TaskStuff.transform.FindChild("TaskPanel").GetComponent(); if (tabText.text != role.RoleName) { From 82c8c0e043af662231406444fa00367db870f0b4 Mon Sep 17 00:00:00 2001 From: Az <56699741+AlchlcDvl@users.noreply.github.com> Date: Fri, 6 Nov 2026 03:22:38 -0500 Subject: [PATCH 8/9] fix android crashing on trying to open the wiki --- MiraAPI/Patches/RoleGuidePatches.cs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/MiraAPI/Patches/RoleGuidePatches.cs b/MiraAPI/Patches/RoleGuidePatches.cs index 797e2a42..edaf0910 100644 --- a/MiraAPI/Patches/RoleGuidePatches.cs +++ b/MiraAPI/Patches/RoleGuidePatches.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.Linq; +using System.Reflection; using AmongUs.GameOptions; using HarmonyLib; using Innersloth.Assets; @@ -656,7 +657,7 @@ public static class RoleGuidePatches _searchBoxTmp.Pipe.transform.localPosition = new Vector3( outputText.transform.localPosition.x - (outputText.rectTransform.sizeDelta.x * outputText.rectTransform.pivot.x), - outputText.transform.localPosition.y + _searchBoxTmp.caretYOffset, + outputText.transform.localPosition.y + GetCaretYOffset(_searchBoxTmp), -0.3f); } @@ -831,6 +832,25 @@ public static class RoleGuidePatches button.gameObject.AddComponent(); } + private static float GetCaretYOffset(TextBoxTMP box) + { + try + { + var prop = typeof(TextBoxTMP).GetProperty("caretYOffset", BindingFlags.Instance | BindingFlags.Public); + + if (prop == null) + { + return 0f; + } + + return Convert.ToSingle(prop.GetValue(box), CultureInfo.InvariantCulture); + } + catch + { + return 0f; + } + } + private static void SetupSearchButton(PassiveButton button, string objName, Action onClick, Sprite inactive, Sprite hover, Vector3 pos, out SpriteRenderer inactiveSprite, out SpriteRenderer hoverSprite) { button.name = objName; From 1ac55197e9fb674158cd416b647b71579625ba60 Mon Sep 17 00:00:00 2001 From: Az <56699741+AlchlcDvl@users.noreply.github.com> Date: Fri, 6 Nov 2026 17:01:40 -0500 Subject: [PATCH 9/9] clear some warnings --- MiraAPI/Patches/Options/MenuState.cs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/MiraAPI/Patches/Options/MenuState.cs b/MiraAPI/Patches/Options/MenuState.cs index a88f3e68..9d3a38ab 100644 --- a/MiraAPI/Patches/Options/MenuState.cs +++ b/MiraAPI/Patches/Options/MenuState.cs @@ -1,4 +1,7 @@ -using Il2CppInterop.Runtime.Attributes; +using System; +using System.Collections.Generic; +using System.Linq; +using Il2CppInterop.Runtime.Attributes; using MiraAPI.GameModes; using MiraAPI.GameOptions; using MiraAPI.Modifiers; @@ -9,15 +12,10 @@ using MiraAPI.Translation; using MiraAPI.Utilities.Assets; using Reactor.Utilities.Attributes; using Reactor.Utilities.Extensions; -using System; -using System.Collections.Generic; -using System.Linq; using TMPro; using UnityEngine; using UnityEngine.Events; using UnityEngine.UI; -using static UnityEngine.ProBuilder.AutoUnwrapSettings; -using static UnityEngine.UI.Image; namespace MiraAPI.Patches.Options;