Compare commits

..
Author SHA1 Message Date
Atony 245f2e6919 Merge pull request #83 from All-Of-Us-Mods/dev
## What's Changed
- Guardian Angel protection is checked properly.
- The Options Menu no longer throws errors on Android
- Framerate slider applies properly on PC again
- StateMachineWrapper now allows overriding existing states and returns for Coroutines.
2026-04-18 08:41:18 -05:00
22 changed files with 121 additions and 479 deletions

No files matched your search

@@ -4,7 +4,6 @@ using System.Linq;
using HarmonyLib;
using Il2CppInterop.Runtime.Attributes;
using MiraAPI.LocalSettings;
using MiraAPI.Utilities;
using MiraAPI.Utilities.Assets;
using Reactor.Utilities.Attributes;
using Reactor.Utilities.Extensions;
@@ -138,7 +137,7 @@ public class ModifierDisplayComponent(nint cppPtr) : MonoBehaviour(cppPtr)
internal void DestroyComponent(ModifierUiComponent component)
{
_modifiers.Remove(component.Modifier!);
component.gameObject.DeepDestroy();
component.gameObject.DestroyImmediate();
RefreshModifiers();
}
@@ -208,7 +207,7 @@ public class ModifierDisplayComponent(nint cppPtr) : MonoBehaviour(cppPtr)
continue;
}
mod.Value.gameObject.DeepDestroy();
mod.Value.gameObject.Destroy();
_modifiers.Remove(mod.Key);
}
+1 -2
View File
@@ -276,9 +276,8 @@ public static class TaskAdderPatches
__instance.transform.FindChild("TitleText_TMP")?.gameObject.DestroyImmediate();
}
__instance.ActiveItems.ToArray().Do(x => x.gameObject.DeepDestroy(false));
__instance.ActiveItems.ToArray().Do(x => x.gameObject.Destroy());
__instance.ActiveItems.Clear();
Utilities.Extensions.ClearGarbageCollector();
float num = 0f;
float num2 = 0f;
+7 -8
View File
@@ -52,7 +52,12 @@ public static class HudManagerPatches
continue;
}
if (aspect.gameObject.name.Contains("TopRight"))
if (aspect.gameObject.transform.parent.name == "TopRight")
{
continue;
}
if (aspect.gameObject.transform.parent.transform.parent.name == "TopRight")
{
continue;
}
@@ -84,11 +89,6 @@ public static class HudManagerPatches
continue;
}
if (arrange.gameObject.name.Contains("TopRight"))
{
continue;
}
arrange.gameObject.SetActive(!arrange.isActiveAndEnabled);
arrange.CellSize = new Vector2(scaleFactor, scaleFactor);
arrange.gameObject.SetActive(!arrange.isActiveAndEnabled);
@@ -143,9 +143,8 @@ public static class HudManagerPatches
foreach (var t in BottomLeft.GetComponentsInChildren<ActionButton>(true))
{
t.gameObject.DeepDestroy(false);
t.gameObject.Destroy();
}
Utilities.Extensions.ClearGarbageCollector();
var gridArrange = BottomLeft.GetComponent<GridArrange>();
var aspectPosition = BottomLeft.GetComponent<AspectPosition>();
+4 -11
View File
@@ -11,6 +11,8 @@ using Reactor.Utilities;
using Reactor.Utilities.Extensions;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
using Object = UnityEngine.Object;
namespace MiraAPI.Patches.Menu;
@@ -39,10 +41,6 @@ public static class HatsTabPatches
[HarmonyPrefix]
public static bool OnEnablePrefix(HatsTab __instance)
{
if (!AddressablesLoader.AddressableHatsExist)
{
return true;
}
__instance.currentHat = HatManager.Instance.GetHatById(DataManager.Player.Customization.Hat);
var allHats = HatManager.Instance.GetUnlockedHats().ToImmutableList();
@@ -68,10 +66,6 @@ public static class HatsTabPatches
[HarmonyPrefix]
public static void UpdatePrefix(HatsTab __instance)
{
if (!AddressablesLoader.AddressableHatsExist)
{
return;
}
if (sortedHats.Count == 0) return;
if (Input.GetKeyDown(KeyCode.LeftControl) || Input.GetKeyDown(KeyCode.RightControl) || Input.GetKeyDown(KeyCode.LeftArrow))
@@ -92,10 +86,9 @@ public static class HatsTabPatches
if (loadRoutine != null) Coroutines.Stop(loadRoutine);
hatIndex = 0;
foreach (var instanceColorChip in __instance.ColorChips) instanceColorChip.gameObject.DeepDestroy(false);
foreach (var instanceColorChip in __instance.ColorChips) instanceColorChip.gameObject.Destroy();
__instance.ColorChips.Clear();
__instance.scroller.Inner.GetComponentsInChildren<TextMeshPro>().Do(x => x.gameObject.DeepDestroy(false));
Utilities.Extensions.ClearGarbageCollector();
__instance.scroller.Inner.GetComponentsInChildren<TextMeshPro>().Do(x => x.gameObject.Destroy());
var groupNameText = __instance.GetComponentInChildren<TextMeshPro>(false);
+2 -12
View File
@@ -6,7 +6,6 @@ using Reactor.Utilities.Extensions;
using System;
using System.Collections.Generic;
using System.Linq;
using MiraAPI.Utilities.Assets;
using TMPro;
using UnityEngine;
using Object = UnityEngine.Object;
@@ -45,10 +44,6 @@ public static class NameplatesTabPatches
[HarmonyPrefix]
public static bool OnEnablePrefix(NameplatesTab __instance)
{
if (!AddressablesLoader.AddressableNameplatesExist)
{
return true;
}
__instance.plateId = HatManager.Instance.GetNamePlateById(DataManager.Player.Customization.namePlate).ProdId;
if (!SortedNameplates.ContainsKey("Vanilla")) AddRange(DestroyableSingleton<HatManager>.Instance.GetUnlockedNamePlates().Select(x => ("Vanilla", x)));
@@ -65,10 +60,6 @@ public static class NameplatesTabPatches
public static void UpdatePrefix(NameplatesTab __instance)
{
if (!AddressablesLoader.AddressableNameplatesExist)
{
return;
}
if (Input.GetKeyDown(KeyCode.LeftControl) || Input.GetKeyDown(KeyCode.RightControl) || Input.GetKeyDown(KeyCode.LeftArrow))
{
PreviousPage(__instance);
@@ -81,10 +72,9 @@ public static class NameplatesTabPatches
private static void GenerateHats(NameplatesTab __instance, int page)
{
foreach (var instanceColorChip in __instance.ColorChips) instanceColorChip.gameObject.DeepDestroy(false);
foreach (ColorChip instanceColorChip in __instance.ColorChips) instanceColorChip.gameObject.Destroy();
__instance.ColorChips.Clear();
__instance.scroller.Inner.GetComponentsInChildren<TextMeshPro>().Do(x => x.gameObject.DeepDestroy(false));
Utilities.Extensions.ClearGarbageCollector();
__instance.scroller.Inner.GetComponentsInChildren<TextMeshPro>().Do(x => x.gameObject.Destroy());
var groupNameText = __instance.GetComponentInChildren<TextMeshPro>(false);
+2 -12
View File
@@ -6,7 +6,6 @@ using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using MiraAPI.Utilities.Assets;
using TMPro;
using UnityEngine;
using Object = UnityEngine.Object;
@@ -37,10 +36,6 @@ public static class SkinsTabPatches
[HarmonyPrefix]
public static bool OnEnablePrefix(SkinsTab __instance)
{
if (!AddressablesLoader.AddressableSkinsExist)
{
return true;
}
__instance.skinId = HatManager.Instance.GetSkinById(DataManager.Player.Customization.Skin).ProdId;
var allSkins = HatManager.Instance.GetUnlockedSkins().ToImmutableList();
@@ -67,10 +62,6 @@ public static class SkinsTabPatches
public static void UpdatePrefix(SkinsTab __instance)
{
if (!AddressablesLoader.AddressableSkinsExist)
{
return;
}
if (Input.GetKeyDown(KeyCode.LeftControl) || Input.GetKeyDown(KeyCode.RightControl) || Input.GetKeyDown(KeyCode.LeftArrow))
{
PreviousPage(__instance);
@@ -83,10 +74,9 @@ public static class SkinsTabPatches
private static void GenerateHats(SkinsTab __instance, int page)
{
foreach (var instanceColorChip in __instance.ColorChips) instanceColorChip.gameObject.DeepDestroy(false);
foreach (ColorChip instanceColorChip in __instance.ColorChips) instanceColorChip.gameObject.Destroy();
__instance.ColorChips.Clear();
__instance.scroller.Inner.GetComponentsInChildren<TextMeshPro>().Do(x => x.gameObject.DeepDestroy(false));
Utilities.Extensions.ClearGarbageCollector();
__instance.scroller.Inner.GetComponentsInChildren<TextMeshPro>().Do(x => x.gameObject.Destroy());
var groupNameText = __instance.GetComponentInChildren<TextMeshPro>(false);
+2 -12
View File
@@ -5,7 +5,6 @@ using Reactor.Utilities.Extensions;
using System;
using System.Collections.Generic;
using System.Linq;
using MiraAPI.Utilities.Assets;
using TMPro;
using UnityEngine;
using Object = UnityEngine.Object;
@@ -45,10 +44,6 @@ public static class VisorsTabPatches
[HarmonyPrefix]
public static bool OnEnablePrefix(VisorsTab __instance)
{
if (!AddressablesLoader.AddressableVisorsExist)
{
return true;
}
__instance.visorId = HatManager.Instance.GetVisorById(DataManager.Player.Customization.Visor).ProdId;
if (!SortedVisors.ContainsKey("Vanilla")) AddRange(DestroyableSingleton<HatManager>.Instance.GetUnlockedVisors().Select(x => ("Vanilla", x)));
@@ -65,10 +60,6 @@ public static class VisorsTabPatches
public static void UpdatePrefix(VisorsTab __instance)
{
if (!AddressablesLoader.AddressableVisorsExist)
{
return;
}
if (Input.GetKeyDown(KeyCode.LeftControl) || Input.GetKeyDown(KeyCode.RightControl) || Input.GetKeyDown(KeyCode.LeftArrow))
{
PreviousPage(__instance);
@@ -81,10 +72,9 @@ public static class VisorsTabPatches
private static void GenerateHats(VisorsTab __instance, int page)
{
foreach (var instanceColorChip in __instance.ColorChips) instanceColorChip.gameObject.DeepDestroy(false);
foreach (ColorChip instanceColorChip in __instance.ColorChips) instanceColorChip.gameObject.Destroy();
__instance.ColorChips.Clear();
__instance.scroller.Inner.GetComponentsInChildren<TextMeshPro>().Do(x => x.gameObject.DeepDestroy(false));
Utilities.Extensions.ClearGarbageCollector();
__instance.scroller.Inner.GetComponentsInChildren<TextMeshPro>().Do(x => x.gameObject.Destroy());
var groupNameText = __instance.GetComponentInChildren<TextMeshPro>(false);
+17 -67
View File
@@ -139,25 +139,11 @@ internal static class GameOptionsMenuPatch
private static void CustomMenuOneCreate(GameOptionsMenu menu)
{
var existing = GameSettingMenuPatches.CachedGameSettings.FirstOrDefault(x => x.ModId == GameSettingMenuPatches.SelectedModIdx && x.Category == MenuCategory.CustomOne);
if (existing != null)
var groups = GameSettingMenuPatches.SelectedMod?.InternalOptionGroups
.Where(x => x.ParentMenu == MenuCategory.CustomOne) ?? [];
foreach (var group in groups)
{
GameSettingMenuPatches.ShowGameOptions(existing, menu);
}
else
{
var groups = GameSettingMenuPatches.SelectedMod?.InternalOptionGroups
.Where(x => x.ParentMenu == MenuCategory.CustomOne) ?? [];
foreach (var group in groups)
{
CreateGroup(menu, group);
}
GameSettingMenuPatches.AddGameSettings(
MenuCategory.CustomOne,
menu.Children,
menu.settingsContainer
.GetComponentsInChildren<CategoryHeaderMasked>()
.ToList());
CreateGroup(menu, group);
}
}
@@ -174,25 +160,11 @@ internal static class GameOptionsMenuPatch
private static void CustomMenuTwoCreate(GameOptionsMenu menu)
{
var existing = GameSettingMenuPatches.CachedGameSettings.FirstOrDefault(x => x.ModId == GameSettingMenuPatches.SelectedModIdx && x.Category == MenuCategory.CustomTwo);
if (existing != null)
var groups = GameSettingMenuPatches.SelectedMod?.InternalOptionGroups
.Where(x => x.ParentMenu == MenuCategory.CustomTwo) ?? [];
foreach (var group in groups)
{
GameSettingMenuPatches.ShowGameOptions(existing, menu);
}
else
{
var groups = GameSettingMenuPatches.SelectedMod?.InternalOptionGroups
.Where(x => x.ParentMenu == MenuCategory.CustomTwo) ?? [];
foreach (var group in groups)
{
CreateGroup(menu, group);
}
GameSettingMenuPatches.AddGameSettings(
MenuCategory.CustomTwo,
menu.Children,
menu.settingsContainer
.GetComponentsInChildren<CategoryHeaderMasked>()
.ToList());
CreateGroup(menu, group);
}
}
@@ -209,25 +181,11 @@ internal static class GameOptionsMenuPatch
private static void ModifiersCreate(GameOptionsMenu menu)
{
var existing = GameSettingMenuPatches.CachedGameSettings.FirstOrDefault(x => x.ModId == GameSettingMenuPatches.SelectedModIdx && x.Category == MenuCategory.Modifiers);
if (existing != null)
var groups = GameSettingMenuPatches.SelectedMod?.InternalOptionGroups
.Where(x => x.ShowInModifiersMenu || x.OptionableType?.IsAssignableTo(typeof(BaseModifier)) == true) ?? [];
foreach (var group in groups)
{
GameSettingMenuPatches.ShowGameOptions(existing, menu);
}
else
{
var groups = GameSettingMenuPatches.SelectedMod?.InternalOptionGroups
.Where(x => x.ShowInModifiersMenu || x.OptionableType?.IsAssignableTo(typeof(BaseModifier)) == true) ?? [];
foreach (var group in groups)
{
CreateGroup(menu, group);
}
GameSettingMenuPatches.AddGameSettings(
MenuCategory.Modifiers,
menu.Children,
menu.settingsContainer
.GetComponentsInChildren<CategoryHeaderMasked>()
.ToList());
CreateGroup(menu, group);
}
}
@@ -259,20 +217,12 @@ internal static class GameOptionsMenuPatch
return false;
}
var existing = GameSettingMenuPatches.CachedGameSettings.FirstOrDefault(x => x.ModId == GameSettingMenuPatches.SelectedModIdx && x.Category == MenuCategory.Game);
if (existing != null)
{
GameSettingMenuPatches.ShowGameOptions(existing, __instance);
}
else
{
var filteredGroups = GameSettingMenuPatches.SelectedMod?.InternalOptionGroups
.Where(x => x.OptionableType == null && !x.ShowInModifiersMenu && x.ParentMenu == MenuCategory.Roles) ?? [];
var filteredGroups = GameSettingMenuPatches.SelectedMod?.InternalOptionGroups
.Where(x => x.OptionableType == null && !x.ShowInModifiersMenu && x.ParentMenu == MenuCategory.Roles) ?? [];
foreach (var group in filteredGroups)
{
CreateGroup(__instance, group);
}
foreach (var group in filteredGroups)
{
CreateGroup(__instance, group);
}
return false;
@@ -262,7 +262,7 @@ internal static class GamePresetsTabPatches
iconSpriteRend.sprite = MiraAssets.RefreshIcon.LoadAsset();
Helpers.DivideSize(refreshButton.gameObject, 2f);
refreshButton.buttonText.gameObject.DeepDestroy();
refreshButton.buttonText.gameObject.Destroy();
refreshButton.OnClick = new Button.ButtonClickedEvent();
refreshButton.OnClick.AddListener((UnityAction)Refresh);
+38 -146
View File
@@ -6,7 +6,6 @@ using MiraAPI.GameOptions;
using MiraAPI.Modifiers;
using MiraAPI.PluginLoading;
using MiraAPI.Presets;
using MiraAPI.Utilities;
using MiraAPI.Utilities.Assets;
using Reactor.Utilities.Extensions;
using TMPro;
@@ -41,140 +40,6 @@ internal static class GameSettingMenuPatches
private static PassiveButton? _customTwoButton;
private static GameObject? _nextModButton;
private static GameObject? _previousModButton;
public static List<GameSettingsCache> CachedGameSettings { get; } = [];
public static List<RoleSettingsCache> CachedRoleSettings { get; } = [];
public sealed class GameSettingsCache
{
public int ModId { get; set; }
public MenuCategory Category { get; set; } = MenuCategory.Game;
public Il2CppSystem.Collections.Generic.List<OptionBehaviour> Options { get; set; }
public List<CategoryHeaderMasked> CategoryHeaders { get; set; }
public GameObject CacheHolder { get; set; }
}
public static GameSettingsCache GetCurrentSettings(MenuCategory category)
{
var existing = CachedGameSettings.FirstOrDefault(x => x.ModId == SelectedModIdx && x.Category == category);
if (existing != null)
{
return existing;
}
var menu = category switch
{
MenuCategory.Modifiers => _modifiersTab!,
MenuCategory.CustomOne => _customOneTab!,
MenuCategory.CustomTwo => _customTwoTab!,
_ => GameSettingMenu.Instance.GameSettingsTab,
};
return AddGameSettings(
category,
menu.Children,
menu.settingsContainer
.GetComponentsInChildren<CategoryHeaderMasked>()
.ToList());
}
public static GameSettingsCache AddGameSettings(MenuCategory category, Il2CppSystem.Collections.Generic.List<OptionBehaviour> options, List<CategoryHeaderMasked> categoryHeaders)
{
var modName = SelectedMod?.MiraPlugin.OptionsTitleText ?? "Vanilla";
var newHolder = new GameObject($"{modName} {category}");
newHolder.DontUnload().DontDestroy();
newHolder.SetActive(false);
var newCache = new GameSettingsCache
{
ModId = SelectedModIdx,
Category = category,
Options = options,
CategoryHeaders = categoryHeaders,
CacheHolder = newHolder,
};
CachedGameSettings.Add(newCache);
return newCache;
}
public static void HideGameOptions(GameSettingsCache cached, GameOptionsMenu gameOptMenu)
{
foreach (var obj in gameOptMenu.scrollBar.Inner.GetComponentsInChildren<Transform>())
{
if (obj.gameObject.name == "MapPicker" || !obj.gameObject)
{
continue;
}
obj.SetParent(cached.CacheHolder.transform);
}
}
public static void ShowGameOptions(GameSettingsCache cached, GameOptionsMenu gameOptMenu)
{
foreach (var obj in cached.CacheHolder.GetComponentsInChildren<Transform>())
{
if (!obj.gameObject)
{
continue;
}
obj.SetParent(gameOptMenu.scrollBar.Inner);
}
}
public sealed class RoleSettingsCache
{
public int ModId { get; set; }
public Il2CppSystem.Collections.Generic.List<OptionBehaviour> Options { get; set; }
public List<CategoryHeaderEditRole> RoleHeaders { get; set; }
public List<RoleOptionSetting> RoleOptions { get; set; }
public List<CategoryHeaderEditRole> CategoryHeaders { get; set; }
public GameObject CacheHolder { get; set; }
}
public static RoleSettingsCache GetCurrentRoleSettings()
{
var existing = CachedRoleSettings.FirstOrDefault(x => x.ModId == SelectedModIdx);
if (existing != null)
{
return existing;
}
var menu = GameSettingMenu.Instance.RoleSettingsTab;
return AddRoleSettings(
menu.advancedSettingChildren,
menu.RoleChancesSettings
.GetComponentsInChildren<CategoryHeaderEditRole>()
.ToList());
}
public static RoleSettingsCache AddRoleSettings(Il2CppSystem.Collections.Generic.List<OptionBehaviour> options, List<CategoryHeaderEditRole> categoryHeaders)
{
var modName = SelectedMod?.MiraPlugin.OptionsTitleText ?? "Vanilla";
var newHolder = new GameObject($"{modName} Roles");
newHolder.DontUnload().DontDestroy();
newHolder.SetActive(false);
var newCache = new RoleSettingsCache
{
ModId = SelectedModIdx,
Options = options,
CategoryHeaders = categoryHeaders,
CacheHolder = newHolder,
};
CachedRoleSettings.Add(newCache);
return newCache;
}
public static void HideRoleOptions(RoleSettingsCache cached, RolesSettingsMenu gameOptMenu)
{
foreach (var obj in gameOptMenu.scrollBar.Inner.GetComponentsInChildren<Transform>())
{
if (obj.gameObject.name == "MapPicker" || !obj.gameObject)
{
continue;
}
obj.SetParent(cached.CacheHolder.transform);
}
}
public static void ShowRoleOptions(RoleSettingsCache cached, RolesSettingsMenu gameOptMenu)
{
foreach (var obj in cached.CacheHolder.GetComponentsInChildren<Transform>())
{
if (!obj.gameObject)
{
continue;
}
obj.SetParent(gameOptMenu.scrollBar.Inner);
}
}
private static Dictionary<int, Vector3> OptionsPositions { get; } = [];
private static Dictionary<int, Vector3> ModifiersPositions { get; } = [];
@@ -699,6 +564,21 @@ internal static class GameSettingMenuPatches
CleanupTab(settings, roles);
}
private static void ClearOptions(Il2CppSystem.Collections.Generic.List<OptionBehaviour> options)
{
foreach (var child in options)
{
if (child.TryCast<GameOptionsMapPicker>() || !child.gameObject)
{
continue;
}
child.gameObject.DestroyImmediate();
}
options.Clear();
}
private static void CleanupTab(GameOptionsMenu settings, RolesSettingsMenu roles)
{
if (roles.roleChances != null)
@@ -728,10 +608,24 @@ internal static class GameSettingMenuPatches
void CleanupRoleSettings(RolesSettingsMenu rolesMenu)
{
HideRoleOptions(GetCurrentRoleSettings(), rolesMenu);
rolesMenu.advancedSettingChildren = null;
if (rolesMenu.advancedSettingChildren != null)
{
ClearOptions(rolesMenu.advancedSettingChildren);
rolesMenu.advancedSettingChildren = null;
}
rolesMenu.roleChances.Clear();
rolesMenu.RoleChancesSettings
.transform
.GetComponentsInChildren<CategoryHeaderEditRole>()
.ToList()
.ForEach(header => header.gameObject.DestroyImmediate());
foreach (var role in rolesMenu.roleChances)
{
role.gameObject.DestroyImmediate();
}
rolesMenu.roleChances?.Clear();
rolesMenu.AdvancedRolesSettings.gameObject.SetActive(false);
rolesMenu.RoleChancesSettings.gameObject.SetActive(true);
@@ -749,16 +643,14 @@ internal static class GameSettingMenuPatches
void CleanupSettings(GameOptionsMenu gameOptMenu, MenuCategory menuCategory = MenuCategory.Roles)
{
if (menuCategory is MenuCategory.Roles)
{
HideRoleOptions(GetCurrentRoleSettings(), gameOptMenu.RolesMenu);
}
else
{
HideGameOptions(GetCurrentSettings(menuCategory), gameOptMenu);
}
ClearOptions(gameOptMenu.Children);
gameOptMenu.Children = null;
gameOptMenu.settingsContainer
.GetComponentsInChildren<CategoryHeaderMasked>()
.ToList()
.ForEach(header => header.gameObject.DestroyImmediate());
gameOptMenu.Initialize();
var positions = OptionsPositions;
switch (menuCategory)
@@ -41,6 +41,12 @@ public static class RoleSettingMenuPatches
{
HudManager.Instance.PlayerCam.OverrideScreenShakeEnabled = false;
}
[HarmonyPostfix]
[HarmonyPatch(nameof(RolesSettingsMenu.OnDisable))]
public static void ClosePatch(RolesSettingsMenu __instance)
{
HudManager.Instance.PlayerCam.OverrideScreenShakeEnabled = true;
}
[HarmonyPostfix]
[HarmonyPatch(nameof(RolesSettingsMenu.SetQuotaTab))]
@@ -53,11 +59,9 @@ public static class RoleSettingMenuPatches
[HarmonyPatch(nameof(RolesSettingsMenu.SetQuotaTab))]
public static bool SetQuotaTabPatch(RolesSettingsMenu __instance)
{
GameSettingMenuPatches.HideRoleOptions(GameSettingMenuPatches.GetCurrentRoleSettings(), __instance);
__instance.advancedSettingChildren = null;
Headers.ForEach(Object.Destroy);
RoleOptionSettings.ForEach(Object.Destroy);
Headers.Clear();
__instance.roleChances.Clear();
RoleOptionSettings.Clear();
CurrentRole = null;
CurrentRoleOptions = null;
@@ -135,7 +139,6 @@ public static class RoleSettingMenuPatches
num3++;
}
Utilities.Extensions.ClearGarbageCollector();
return false;
}
@@ -157,7 +160,6 @@ public static class RoleSettingMenuPatches
if (roleGroups is null)
{
Utilities.Extensions.ClearGarbageCollector();
return false;
}
@@ -208,9 +210,9 @@ public static class RoleSettingMenuPatches
var blankLabel = quotaInst.transform.FindChild("BlankLabel").gameObject;
var chanceLabel = quotaInst.transform.FindChild("Chance Label").gameObject;
var countLabel = quotaInst.transform.FindChild("# Label").gameObject;
blankLabel.DeepDestroy(false);
chanceLabel.DeepDestroy(false);
countLabel.DeepDestroy(false);
blankLabel.Destroy();
chanceLabel.Destroy();
countLabel.Destroy();
categoryHeaderMasked.Background.sprite = MiraAssets.CategoryHeader.LoadAsset();
categoryHeaderMasked.Background.sprite.texture.filterMode = FilterMode.Bilinear;
@@ -293,10 +295,15 @@ public static class RoleSettingMenuPatches
{
RoleGroupHidden[group] = !groupHidden;
}
GameSettingMenuPatches.HideRoleOptions(GameSettingMenuPatches.GetCurrentRoleSettings(), __instance);
__instance.advancedSettingChildren = null;
foreach (var header in Headers)
{
header.Destroy();
}
Headers.Clear();
__instance.roleChances.Clear();
foreach (var option in RoleOptionSettings)
{
option.gameObject.Destroy();
}
RoleOptionSettings.Clear();
__instance.SetQuotaTab();
}));
@@ -307,7 +314,6 @@ public static class RoleSettingMenuPatches
ScrollerNum -= 0.4f;
}
}
Utilities.Extensions.ClearGarbageCollector();
__instance.scrollBar.SetScrollBounds(__instance);
return false;
@@ -422,9 +428,8 @@ public static class RoleSettingMenuPatches
{
foreach (var optBehaviour in __instance.AdvancedRolesSettings.GetComponentsInChildren<OptionBehaviour>())
{
optBehaviour.gameObject.DeepDestroy(false);
optBehaviour.gameObject.DestroyImmediate();
}
Utilities.Extensions.ClearGarbageCollector();
CurrentRole = role;
__instance.advancedSettingChildren.Clear();
@@ -619,7 +624,7 @@ public static class RoleSettingMenuPatches
var newButton = Object.Instantiate(roleOptionSetting.buttons[0], roleOptionSetting.transform);
newButton.name = "ConfigButton";
newButton.transform.localPosition = new Vector3(0.4473f, -0.3f, -2f);
newButton.transform.FindChild("Text_TMP").gameObject.DeepDestroy();
newButton.transform.FindChild("Text_TMP").gameObject.DestroyImmediate();
newButton.activeSprites.Destroy();
var btnRend = newButton.transform.FindChild("ButtonSprite").GetComponent<SpriteRenderer>();
+13 -28
View File
@@ -22,18 +22,22 @@ internal static class HowToPlayPatch
__instance.startPage.SetActive(false);
if (__instance.roleButtonsParent.childCount == 0)
{
foreach (var role in RoleManager.Instance.AllRoles.ToArray().Where(x => !x.IsCustomRole()))
using (IEnumerator<RoleBehaviour> enumerator = RoleManager.Instance.AllRoles.ToArray().Where(x => !x.IsCustomRole()).GetEnumerator())
{
if (!role.IsSimpleRole && role.Role != RoleTypes.CrewmateGhost && role.Role != RoleTypes.ImpostorGhost)
while (enumerator.MoveNext())
{
HowToPlayRoleButton component = Object.Instantiate(__instance.roleButtonPrefab, __instance.roleButtonsParent).GetComponent<HowToPlayRoleButton>();
Sprite roleIcon = __instance.rolesScenes.ToArray().First(r => r.role == role.Role).roleIcon;
component.SetRoleInfo(role, roleIcon);
component.SetButtonAction((Il2CppSystem.Action)(() =>
RoleBehaviour role = enumerator.Current;
if (!role.IsSimpleRole && role.Role != RoleTypes.CrewmateGhost && role.Role != RoleTypes.ImpostorGhost)
{
OpenRolePage(__instance, role.Role);
}));
__instance.controllerSelectables.Add(component.GetComponent<PassiveButton>());
HowToPlayRoleButton component = Object.Instantiate(__instance.roleButtonPrefab, __instance.roleButtonsParent).GetComponent<HowToPlayRoleButton>();
Sprite roleIcon = __instance.rolesScenes.ToArray().First(r => r.role == role.Role).roleIcon;
component.SetRoleInfo(role, roleIcon);
component.SetButtonAction((Il2CppSystem.Action)(() =>
{
__instance.OpenRolePage(role.Role);
}));
__instance.controllerSelectables.Add(component.GetComponent<PassiveButton>());
}
}
}
foreach (UiElement uiElement in __instance.controllerSelectables)
@@ -46,23 +50,4 @@ internal static class HowToPlayPatch
__instance.roleSelectionScene.SetActive(true);
ControllerManager.Instance.SetDefaultSelection(__instance.defaultButtonSelected, null);
}
public static void OpenRolePage(HowToPlayScene instance, RoleTypes roleType)
{
instance.category = HowToPlayScene.HowToPlayCategory.Roles;
var newList = instance.rolesScenes.ToArray().ToList();
var buttonList = instance.roleButtons;
instance.sceneIndex = newList.FindIndex(r => r.role == roleType);
if (roleType != RoleTypes.Crewmate)
{
foreach (var button in buttonList)
{
if (button.GetRole().Role == roleType)
{
instance.previouslySelectedRoleButton = button.GetComponent<PassiveButton>();
}
}
}
instance.SetupDots(instance.rolesScenes[instance.sceneIndex].rolePages.Count);
instance.ChangeScene(0);
}
}
+2 -4
View File
@@ -1,9 +1,7 @@
using HarmonyLib;
using InnerNet;
using MiraAPI.Roles;
using MiraAPI.Utilities;
using Reactor.Utilities.Extensions;
using UnityEngine;
namespace MiraAPI.Patches.Roles;
@@ -71,9 +69,9 @@ public static class HudManagerPatches
CustomRoleManager.UpdateRoleTab(RoleTab, customRole);
}
else if (RoleTab != null)
else if (RoleTab)
{
RoleTab.gameObject.DeepDestroy();
RoleTab?.gameObject.Destroy();
}
}
}
+1 -2
View File
@@ -6,7 +6,6 @@ using MiraAPI.Events;
using MiraAPI.Events.Vanilla.Gameplay;
using MiraAPI.Modifiers;
using MiraAPI.Roles;
using MiraAPI.Utilities;
using UnityEngine;
namespace MiraAPI.Patches.Roles;
@@ -33,7 +32,7 @@ public static class RoleManagerPatches
if (data.Role)
{
data.Role.Deinitialize(targetPlayer);
data.Role.gameObject.DeepDestroy();
Object.Destroy(data.Role.gameObject);
}
var roleBehaviour = Object.Instantiate<RoleBehaviour>(__instance.AllRoles.ToArray().First(r => r.Role == roleType), data.gameObject.transform);
roleBehaviour.Initialize(targetPlayer);
+1 -1
View File
@@ -28,7 +28,7 @@ internal static class VentCanUsePatch
var @object = pc.Object;
var role = @object.Data.Role;
var canVent = role is ICustomRole customRole ? customRole.Configuration.CanUseVent || customRole.Configuration.GetsVentData : role.CanVent;
var canVent = role is ICustomRole customRole ? customRole.Configuration.CanUseVent : role.CanVent;
couldUse = canVent;
var modifiers = @object.GetModifierComponent().ActiveModifiers;
+1 -3
View File
@@ -4,7 +4,6 @@ using System.Linq;
using BepInEx.Configuration;
using MiraAPI.PluginLoading;
using MiraAPI.Roles;
using MiraAPI.Utilities;
using Reactor.Utilities;
using UnityEngine;
@@ -62,10 +61,9 @@ public static class PresetManager
{
if (btn != null)
{
btn.DeepDestroy(false);
Object.DestroyImmediate(btn);
}
}
Utilities.Extensions.ClearGarbageCollector();
plugin.InternalPresets.Clear();
if (!Directory.Exists(PresetDirectory))
+1 -1
View File
@@ -26,7 +26,7 @@ public class SavePresetPopup(nint cppPtr) : Minigame(cppPtr)
// Cleanup holder object
public void OnDestroy()
{
transform.parent.gameObject.DeepDestroy();
transform.parent.gameObject.Destroy();
}
public override void Close()
+1 -6
View File
@@ -109,15 +109,10 @@ public record struct CustomRoleConfiguration
public bool UseVanillaKillButton { get; set; }
/// <summary>
/// Gets or sets a value indicating whether the role can use vents. Also sends vanilla vent data.
/// Gets or sets a value indicating whether the role can use vents.
/// </summary>
public bool CanUseVent { get; set; }
/// <summary>
/// Gets or sets a value indicating whether the role can receive vanilla vent data.
/// </summary>
public bool GetsVentData { get; set; }
/// <summary>
/// Gets or sets a value indicating whether the role can use the sabotage button.
/// </summary>
+2 -2
View File
@@ -123,7 +123,7 @@ public static class CustomRoleManager
if (roleBehaviour is not ICustomRole customRole)
{
roleBehaviour.gameObject.DeepDestroy();
roleBehaviour.gameObject.Destroy();
return null;
}
@@ -139,7 +139,7 @@ public static class CustomRoleManager
roleBehaviour.CanBeKilled = customRole.Configuration.CanGetKilled;
roleBehaviour.CanUseKillButton = customRole.Configuration.UseVanillaKillButton;
roleBehaviour.TasksCountTowardProgress = customRole.Configuration.TasksCountForProgress;
roleBehaviour.CanVent = customRole.Configuration.CanUseVent || customRole.Configuration.GetsVentData;
roleBehaviour.CanVent = customRole.Configuration.CanUseVent;
roleBehaviour.DefaultGhostRole = customRole.Configuration.GhostRole;
roleBehaviour.MaxCount = customRole.Configuration.MaxRoleCount;
roleBehaviour.RoleScreenshot = customRole.Configuration.OptionsScreenshot?.LoadAsset();
@@ -24,26 +24,6 @@ public static class AddressablesLoader
private static readonly List<(string, string)> RegisteredNameplateKeys = [];
private static readonly List<string> RegisteredSkinKeys = [];
/// <summary>
/// Gets a value indicating whether hats have been loaded by the addressables system.
/// </summary>
public static bool AddressableHatsExist { get; private set; }
/// <summary>
/// Gets a value indicating whether visors have been loaded by the addressables system.
/// </summary>
public static bool AddressableVisorsExist { get; private set; }
/// <summary>
/// Gets a value indicating whether nameplates have been loaded by the addressables system.
/// </summary>
public static bool AddressableNameplatesExist { get; private set; }
/// <summary>
/// Gets a value indicating whether skins have been loaded by the addressables system.
/// </summary>
public static bool AddressableSkinsExist { get; private set; }
/// <summary>
/// Registers a specific addressables package to load asynchronously at the start of the game, when possible.
/// </summary>
@@ -72,7 +52,6 @@ public static class AddressablesLoader
return;
}
AddressableHatsExist = true;
RegisteredHatKeys.Add(addressablesKey);
}
@@ -88,7 +67,6 @@ public static class AddressablesLoader
return;
}
AddressableSkinsExist = true;
RegisteredSkinKeys.Add(addressablesKey);
}
@@ -105,7 +83,6 @@ public static class AddressablesLoader
return;
}
AddressableNameplatesExist = true;
RegisteredNameplateKeys.Add((addressablesKey, groupTitle));
}
@@ -122,7 +99,6 @@ public static class AddressablesLoader
return;
}
AddressableVisorsExist = true;
RegisteredVisorKeys.Add((addressablesKey, groupTitle));
}
+1 -117
View File
@@ -1,5 +1,4 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
@@ -54,7 +53,7 @@ public static class Extensions
bool isComplete;
if (self.amClosing == Minigame.CloseState.Closing)
{
self.gameObject.DeepDestroy();
UnityEngine.Object.Destroy(self.gameObject);
return;
}
if (self.CloseSound && Constants.ShouldPlaySfx())
@@ -220,121 +219,6 @@ public static class Extensions
return Mathf.Approximately(number, Mathf.Round(number));
}
/// <summary>
/// Destroys the object properly.
/// </summary>
/// <param name="obj">The object to destroy.</param>
/// <param name="clearGc">Whether to run the garbage collector immediately.</param>
public static void DeepDestroy(this GameObject? obj, bool clearGc = true)
{
Coroutines.Start(Nuke(obj, clearGc));
}
private static IEnumerator Nuke(GameObject? go, bool clearGc)
{
if (go == null)
yield break;
try
{
go.transform.SetParent(null, false);
}
catch
{
// ignored
}
try
{
go.SetActive(false);
}
catch
{
// ignored
}
foreach (var mb in go.GetComponentsInChildren<MonoBehaviour>(true))
{
if (mb == null)
continue;
try
{
mb.StopAllCoroutines();
}
catch
{
// ignored
}
try
{
mb.enabled = false;
}
catch
{
// ignored
}
}
foreach (var renderer in go.GetComponentsInChildren<Renderer>(true))
{
if (renderer == null)
continue;
try
{
foreach (var mat in renderer.materials)
{
if (mat != null)
UnityEngine.Object.Destroy(mat);
}
}
catch
{
// ignored
}
}
foreach (var filter in go.GetComponentsInChildren<MeshFilter>(true))
{
if (filter == null)
continue;
try
{
var mesh = filter.mesh;
if (mesh != null)
UnityEngine.Object.Destroy(mesh);
}
catch
{
// ignored
}
}
UnityEngine.Object.Destroy(go);
yield return null;
if (clearGc)
{
yield return CoFreeResources();
}
}
public static void ClearGarbageCollector()
{
Coroutines.Start(CoFreeResources());
}
private static IEnumerator CoFreeResources()
{
yield return Resources.UnloadUnusedAssets();
GC.Collect(0, GCCollectionMode.Forced, blocking: true);
GC.WaitForPendingFinalizers();
GC.Collect(0, GCCollectionMode.Forced, blocking: true);
}
/// <summary>
/// Gets a cache of player's vote data components to improve performance.
/// </summary>
+1 -1
View File
@@ -539,7 +539,7 @@ public static class Helpers
}
/// <summary>
/// Returns whether the role is blacklisted from appearing and spawning. Only applicable to vanilla roles.
/// Returns whether the role is blacklisted from appearing and spawning. (Only applicable to vanilla roles)
/// </summary>
/// <param name="role">The role to check.</param>
/// <returns>The role's blacklist status.</returns>