Compare commits

...
30 changed files with 542 additions and 131 deletions

No files matched your search

+2 -2
View File
@@ -1,8 +1,8 @@
<Project>
<ItemGroup>
<PackageReference Include="Reactor" Version="2.3.1" />
<PackageReference Include="Reactor" Version="2.5.0-ci.371" />
<PackageReference Include="BepInEx.Unity.IL2CPP" Version="6.0.0-be.735" Private="false" ExcludeAssets="runtime;native" />
<PackageReference Include="AmongUs.GameLibs.Steam" Version="2025.10.14" PrivateAssets="all" />
<PackageReference Include="AmongUs.GameLibs.Steam" Version="2026.3.31" PrivateAssets="all" />
<PackageReference Include="BepInEx.AutoPlugin" Version="1.1.0" PrivateAssets="all" />
<PackageReference Include="BepInEx.IL2CPP.MSBuild" Version="2.1.0-rc.1" PrivateAssets="all" ExcludeAssets="runtime" />
+1 -1
View File
@@ -8,7 +8,7 @@
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
<VersionPrefix>0.3.8</VersionPrefix>
<VersionPrefix>0.4.0</VersionPrefix>
<VersionSuffix>dev</VersionSuffix>
<Authors>All Of Us, XtraCube, Angxl</Authors>
@@ -4,6 +4,7 @@ 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;
@@ -137,7 +138,7 @@ public class ModifierDisplayComponent(nint cppPtr) : MonoBehaviour(cppPtr)
internal void DestroyComponent(ModifierUiComponent component)
{
_modifiers.Remove(component.Modifier!);
component.gameObject.DestroyImmediate();
component.gameObject.DeepDestroy();
RefreshModifiers();
}
@@ -207,7 +208,7 @@ public class ModifierDisplayComponent(nint cppPtr) : MonoBehaviour(cppPtr)
continue;
}
mod.Value.gameObject.Destroy();
mod.Value.gameObject.DeepDestroy();
_modifiers.Remove(mod.Key);
}
+12 -1
View File
@@ -93,11 +93,21 @@ public static class CustomMurderRpc
beforeMurderEvent.Cancel();
}
if (beforeMurderEvent.IsCancelled)
if (target.ProtectedByGa())
{
beforeMurderEvent.Cancel();
murderResultFlags = MurderResultFlags.FailedProtected;
}
else if (beforeMurderEvent.IsCancelled)
{
murderResultFlags = MurderResultFlags.FailedError;
}
if (beforeMurderEvent.IsCancelled && source.AmOwner)
{
source.isKilling = true;
}
if (!PlayerControl.LocalPlayer.IsHost())
{
return;
@@ -141,6 +151,7 @@ public static class CustomMurderRpc
{
if (LobbyBehaviour.Instance || !host.IsHost() || target.Data.IsDead || target.Data.Disconnected)
{
source.isKilling = false;
return;
}
+2 -1
View File
@@ -276,8 +276,9 @@ public static class TaskAdderPatches
__instance.transform.FindChild("TitleText_TMP")?.gameObject.DestroyImmediate();
}
__instance.ActiveItems.ToArray().Do(x => x.gameObject.Destroy());
__instance.ActiveItems.ToArray().Do(x => x.gameObject.DeepDestroy(false));
__instance.ActiveItems.Clear();
Utilities.Extensions.ClearGarbageCollector();
float num = 0f;
float num2 = 0f;
+8 -7
View File
@@ -52,12 +52,7 @@ public static class HudManagerPatches
continue;
}
if (aspect.gameObject.transform.parent.name == "TopRight")
{
continue;
}
if (aspect.gameObject.transform.parent.transform.parent.name == "TopRight")
if (aspect.gameObject.name.Contains("TopRight"))
{
continue;
}
@@ -89,6 +84,11 @@ 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,8 +143,9 @@ public static class HudManagerPatches
foreach (var t in BottomLeft.GetComponentsInChildren<ActionButton>(true))
{
t.gameObject.Destroy();
t.gameObject.DeepDestroy(false);
}
Utilities.Extensions.ClearGarbageCollector();
var gridArrange = BottomLeft.GetComponent<GridArrange>();
var aspectPosition = BottomLeft.GetComponent<AspectPosition>();
@@ -16,8 +16,15 @@ public static class OptionsMenuBehaviourPatch
private static void OpenPostfix(OptionsMenuBehaviour __instance)
{
_remap_rollover = GameObject.Find("Remap Controls")?.GetComponent<ButtonRolloverHandler>()!;
_remap_background = _remap_rollover.transform.FindChild("Background").GetComponent<SpriteRenderer>();
_remap_background.color = _conflicts ? Color.red : Color.white;
try
{
_remap_background = _remap_rollover.transform.FindChild("Background").GetComponent<SpriteRenderer>();
_remap_background.color = _conflicts ? Color.red : Color.white;
}
catch
{
// ignored, this normally breaks when on mobile since there's no remap button screen.
}
}
[HarmonyPostfix]
+11 -4
View File
@@ -11,8 +11,6 @@ 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;
@@ -41,6 +39,10 @@ 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();
@@ -66,6 +68,10 @@ 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))
@@ -86,9 +92,10 @@ public static class HatsTabPatches
if (loadRoutine != null) Coroutines.Stop(loadRoutine);
hatIndex = 0;
foreach (var instanceColorChip in __instance.ColorChips) instanceColorChip.gameObject.Destroy();
foreach (var instanceColorChip in __instance.ColorChips) instanceColorChip.gameObject.DeepDestroy(false);
__instance.ColorChips.Clear();
__instance.scroller.Inner.GetComponentsInChildren<TextMeshPro>().Do(x => x.gameObject.Destroy());
__instance.scroller.Inner.GetComponentsInChildren<TextMeshPro>().Do(x => x.gameObject.DeepDestroy(false));
Utilities.Extensions.ClearGarbageCollector();
var groupNameText = __instance.GetComponentInChildren<TextMeshPro>(false);
+11 -1
View File
@@ -1,6 +1,8 @@
using HarmonyLib;
using System.Collections;
using HarmonyLib;
using MiraAPI.LocalSettings;
using MiraAPI.Utilities.Assets;
using Reactor.Utilities;
using UnityEngine;
namespace MiraAPI.Patches.Menu;
@@ -19,6 +21,14 @@ public static class MainMenuManagerPatches
public static void AwakePostfix()
{
AddressablesLoader.LoadAll();
Coroutines.Start(SetFps());
}
private static IEnumerator SetFps()
{
Application.targetFrameRate = (int)LocalSettingsTabSingleton<MiraApiSettings>.Instance.SetFpsSlider.Value;
yield return new WaitForSeconds(1f);
Application.targetFrameRate = (int)LocalSettingsTabSingleton<MiraApiSettings>.Instance.SetFpsSlider.Value;
}
}
+12 -2
View File
@@ -6,6 +6,7 @@ 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;
@@ -44,6 +45,10 @@ 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)));
@@ -60,6 +65,10 @@ 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);
@@ -72,9 +81,10 @@ public static class NameplatesTabPatches
private static void GenerateHats(NameplatesTab __instance, int page)
{
foreach (ColorChip instanceColorChip in __instance.ColorChips) instanceColorChip.gameObject.Destroy();
foreach (var instanceColorChip in __instance.ColorChips) instanceColorChip.gameObject.DeepDestroy(false);
__instance.ColorChips.Clear();
__instance.scroller.Inner.GetComponentsInChildren<TextMeshPro>().Do(x => x.gameObject.Destroy());
__instance.scroller.Inner.GetComponentsInChildren<TextMeshPro>().Do(x => x.gameObject.DeepDestroy(false));
Utilities.Extensions.ClearGarbageCollector();
var groupNameText = __instance.GetComponentInChildren<TextMeshPro>(false);
+12 -2
View File
@@ -6,6 +6,7 @@ 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;
@@ -36,6 +37,10 @@ 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();
@@ -62,6 +67,10 @@ 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);
@@ -74,9 +83,10 @@ public static class SkinsTabPatches
private static void GenerateHats(SkinsTab __instance, int page)
{
foreach (ColorChip instanceColorChip in __instance.ColorChips) instanceColorChip.gameObject.Destroy();
foreach (var instanceColorChip in __instance.ColorChips) instanceColorChip.gameObject.DeepDestroy(false);
__instance.ColorChips.Clear();
__instance.scroller.Inner.GetComponentsInChildren<TextMeshPro>().Do(x => x.gameObject.Destroy());
__instance.scroller.Inner.GetComponentsInChildren<TextMeshPro>().Do(x => x.gameObject.DeepDestroy(false));
Utilities.Extensions.ClearGarbageCollector();
var groupNameText = __instance.GetComponentInChildren<TextMeshPro>(false);
+12 -2
View File
@@ -5,6 +5,7 @@ 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;
@@ -44,6 +45,10 @@ 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)));
@@ -60,6 +65,10 @@ 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);
@@ -72,9 +81,10 @@ public static class VisorsTabPatches
private static void GenerateHats(VisorsTab __instance, int page)
{
foreach (ColorChip instanceColorChip in __instance.ColorChips) instanceColorChip.gameObject.Destroy();
foreach (var instanceColorChip in __instance.ColorChips) instanceColorChip.gameObject.DeepDestroy(false);
__instance.ColorChips.Clear();
__instance.scroller.Inner.GetComponentsInChildren<TextMeshPro>().Do(x => x.gameObject.Destroy());
__instance.scroller.Inner.GetComponentsInChildren<TextMeshPro>().Do(x => x.gameObject.DeepDestroy(false));
Utilities.Extensions.ClearGarbageCollector();
var groupNameText = __instance.GetComponentInChildren<TextMeshPro>(false);
+67 -17
View File
@@ -139,11 +139,25 @@ internal static class GameOptionsMenuPatch
private static void CustomMenuOneCreate(GameOptionsMenu menu)
{
var groups = GameSettingMenuPatches.SelectedMod?.InternalOptionGroups
.Where(x => x.ParentMenu == MenuCategory.CustomOne) ?? [];
foreach (var group in groups)
var existing = GameSettingMenuPatches.CachedGameSettings.FirstOrDefault(x => x.ModId == GameSettingMenuPatches.SelectedModIdx && x.Category == MenuCategory.CustomOne);
if (existing != null)
{
CreateGroup(menu, group);
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());
}
}
@@ -160,11 +174,25 @@ internal static class GameOptionsMenuPatch
private static void CustomMenuTwoCreate(GameOptionsMenu menu)
{
var groups = GameSettingMenuPatches.SelectedMod?.InternalOptionGroups
.Where(x => x.ParentMenu == MenuCategory.CustomTwo) ?? [];
foreach (var group in groups)
var existing = GameSettingMenuPatches.CachedGameSettings.FirstOrDefault(x => x.ModId == GameSettingMenuPatches.SelectedModIdx && x.Category == MenuCategory.CustomTwo);
if (existing != null)
{
CreateGroup(menu, group);
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());
}
}
@@ -181,11 +209,25 @@ internal static class GameOptionsMenuPatch
private static void ModifiersCreate(GameOptionsMenu menu)
{
var groups = GameSettingMenuPatches.SelectedMod?.InternalOptionGroups
.Where(x => x.ShowInModifiersMenu || x.OptionableType?.IsAssignableTo(typeof(BaseModifier)) == true) ?? [];
foreach (var group in groups)
var existing = GameSettingMenuPatches.CachedGameSettings.FirstOrDefault(x => x.ModId == GameSettingMenuPatches.SelectedModIdx && x.Category == MenuCategory.Modifiers);
if (existing != null)
{
CreateGroup(menu, group);
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());
}
}
@@ -217,12 +259,20 @@ internal static class GameOptionsMenuPatch
return false;
}
var filteredGroups = GameSettingMenuPatches.SelectedMod?.InternalOptionGroups
.Where(x => x.OptionableType == null && !x.ShowInModifiersMenu && x.ParentMenu == MenuCategory.Roles) ?? [];
foreach (var group in filteredGroups)
var existing = GameSettingMenuPatches.CachedGameSettings.FirstOrDefault(x => x.ModId == GameSettingMenuPatches.SelectedModIdx && x.Category == MenuCategory.Game);
if (existing != null)
{
CreateGroup(__instance, group);
GameSettingMenuPatches.ShowGameOptions(existing, __instance);
}
else
{
var filteredGroups = GameSettingMenuPatches.SelectedMod?.InternalOptionGroups
.Where(x => x.OptionableType == null && !x.ShowInModifiersMenu && x.ParentMenu == MenuCategory.Roles) ?? [];
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.Destroy();
refreshButton.buttonText.gameObject.DeepDestroy();
refreshButton.OnClick = new Button.ButtonClickedEvent();
refreshButton.OnClick.AddListener((UnityAction)Refresh);
+146 -38
View File
@@ -6,6 +6,7 @@ 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;
@@ -40,6 +41,140 @@ 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; } = [];
@@ -564,21 +699,6 @@ 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)
@@ -608,24 +728,10 @@ internal static class GameSettingMenuPatches
void CleanupRoleSettings(RolesSettingsMenu rolesMenu)
{
if (rolesMenu.advancedSettingChildren != null)
{
ClearOptions(rolesMenu.advancedSettingChildren);
rolesMenu.advancedSettingChildren = null;
}
HideRoleOptions(GetCurrentRoleSettings(), rolesMenu);
rolesMenu.advancedSettingChildren = null;
rolesMenu.RoleChancesSettings
.transform
.GetComponentsInChildren<CategoryHeaderEditRole>()
.ToList()
.ForEach(header => header.gameObject.DestroyImmediate());
foreach (var role in rolesMenu.roleChances)
{
role.gameObject.DestroyImmediate();
}
rolesMenu.roleChances?.Clear();
rolesMenu.roleChances.Clear();
rolesMenu.AdvancedRolesSettings.gameObject.SetActive(false);
rolesMenu.RoleChancesSettings.gameObject.SetActive(true);
@@ -643,14 +749,16 @@ internal static class GameSettingMenuPatches
void CleanupSettings(GameOptionsMenu gameOptMenu, MenuCategory menuCategory = MenuCategory.Roles)
{
ClearOptions(gameOptMenu.Children);
if (menuCategory is MenuCategory.Roles)
{
HideRoleOptions(GetCurrentRoleSettings(), gameOptMenu.RolesMenu);
}
else
{
HideGameOptions(GetCurrentSettings(menuCategory), gameOptMenu);
}
gameOptMenu.Children = null;
gameOptMenu.settingsContainer
.GetComponentsInChildren<CategoryHeaderMasked>()
.ToList()
.ForEach(header => header.gameObject.DestroyImmediate());
gameOptMenu.Initialize();
var positions = OptionsPositions;
switch (menuCategory)
@@ -41,12 +41,6 @@ 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))]
@@ -59,9 +53,11 @@ public static class RoleSettingMenuPatches
[HarmonyPatch(nameof(RolesSettingsMenu.SetQuotaTab))]
public static bool SetQuotaTabPatch(RolesSettingsMenu __instance)
{
Headers.ForEach(Object.Destroy);
RoleOptionSettings.ForEach(Object.Destroy);
GameSettingMenuPatches.HideRoleOptions(GameSettingMenuPatches.GetCurrentRoleSettings(), __instance);
__instance.advancedSettingChildren = null;
Headers.Clear();
__instance.roleChances.Clear();
RoleOptionSettings.Clear();
CurrentRole = null;
CurrentRoleOptions = null;
@@ -139,6 +135,7 @@ public static class RoleSettingMenuPatches
num3++;
}
Utilities.Extensions.ClearGarbageCollector();
return false;
}
@@ -160,6 +157,7 @@ public static class RoleSettingMenuPatches
if (roleGroups is null)
{
Utilities.Extensions.ClearGarbageCollector();
return false;
}
@@ -210,9 +208,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.Destroy();
chanceLabel.Destroy();
countLabel.Destroy();
blankLabel.DeepDestroy(false);
chanceLabel.DeepDestroy(false);
countLabel.DeepDestroy(false);
categoryHeaderMasked.Background.sprite = MiraAssets.CategoryHeader.LoadAsset();
categoryHeaderMasked.Background.sprite.texture.filterMode = FilterMode.Bilinear;
@@ -295,15 +293,10 @@ public static class RoleSettingMenuPatches
{
RoleGroupHidden[group] = !groupHidden;
}
foreach (var header in Headers)
{
header.Destroy();
}
GameSettingMenuPatches.HideRoleOptions(GameSettingMenuPatches.GetCurrentRoleSettings(), __instance);
__instance.advancedSettingChildren = null;
Headers.Clear();
foreach (var option in RoleOptionSettings)
{
option.gameObject.Destroy();
}
__instance.roleChances.Clear();
RoleOptionSettings.Clear();
__instance.SetQuotaTab();
}));
@@ -314,6 +307,7 @@ public static class RoleSettingMenuPatches
ScrollerNum -= 0.4f;
}
}
Utilities.Extensions.ClearGarbageCollector();
__instance.scrollBar.SetScrollBounds(__instance);
return false;
@@ -428,8 +422,9 @@ public static class RoleSettingMenuPatches
{
foreach (var optBehaviour in __instance.AdvancedRolesSettings.GetComponentsInChildren<OptionBehaviour>())
{
optBehaviour.gameObject.DestroyImmediate();
optBehaviour.gameObject.DeepDestroy(false);
}
Utilities.Extensions.ClearGarbageCollector();
CurrentRole = role;
__instance.advancedSettingChildren.Clear();
@@ -624,7 +619,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.DestroyImmediate();
newButton.transform.FindChild("Text_TMP").gameObject.DeepDestroy();
newButton.activeSprites.Destroy();
var btnRend = newButton.transform.FindChild("ButtonSprite").GetComponent<SpriteRenderer>();
+28 -13
View File
@@ -22,22 +22,18 @@ internal static class HowToPlayPatch
__instance.startPage.SetActive(false);
if (__instance.roleButtonsParent.childCount == 0)
{
using (IEnumerator<RoleBehaviour> enumerator = RoleManager.Instance.AllRoles.ToArray().Where(x => !x.IsCustomRole()).GetEnumerator())
foreach (var role in RoleManager.Instance.AllRoles.ToArray().Where(x => !x.IsCustomRole()))
{
while (enumerator.MoveNext())
if (!role.IsSimpleRole && role.Role != RoleTypes.CrewmateGhost && role.Role != RoleTypes.ImpostorGhost)
{
RoleBehaviour role = enumerator.Current;
if (!role.IsSimpleRole && role.Role != RoleTypes.CrewmateGhost && role.Role != RoleTypes.ImpostorGhost)
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)(() =>
{
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>());
}
OpenRolePage(__instance, role.Role);
}));
__instance.controllerSelectables.Add(component.GetComponent<PassiveButton>());
}
}
foreach (UiElement uiElement in __instance.controllerSelectables)
@@ -50,4 +46,23 @@ 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);
}
}
+4 -2
View File
@@ -1,7 +1,9 @@
using HarmonyLib;
using InnerNet;
using MiraAPI.Roles;
using MiraAPI.Utilities;
using Reactor.Utilities.Extensions;
using UnityEngine;
namespace MiraAPI.Patches.Roles;
@@ -69,9 +71,9 @@ public static class HudManagerPatches
CustomRoleManager.UpdateRoleTab(RoleTab, customRole);
}
else if (RoleTab)
else if (RoleTab != null)
{
RoleTab?.gameObject.Destroy();
RoleTab.gameObject.DeepDestroy();
}
}
}
+2 -1
View File
@@ -6,6 +6,7 @@ using MiraAPI.Events;
using MiraAPI.Events.Vanilla.Gameplay;
using MiraAPI.Modifiers;
using MiraAPI.Roles;
using MiraAPI.Utilities;
using UnityEngine;
namespace MiraAPI.Patches.Roles;
@@ -32,7 +33,7 @@ public static class RoleManagerPatches
if (data.Role)
{
data.Role.Deinitialize(targetPlayer);
Object.Destroy(data.Role.gameObject);
data.Role.gameObject.DeepDestroy();
}
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 : role.CanVent;
var canVent = role is ICustomRole customRole ? customRole.Configuration.CanUseVent || customRole.Configuration.GetsVentData : role.CanVent;
couldUse = canVent;
var modifiers = @object.GetModifierComponent().ActiveModifiers;
+2 -2
View File
@@ -6,6 +6,7 @@ using System.Linq;
using System.Reflection;
using BepInEx.Configuration;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using MiraAPI.Colors;
using MiraAPI.Events;
using MiraAPI.GameEnd;
@@ -21,7 +22,6 @@ using MiraAPI.Roles;
using MiraAPI.Utilities;
using Reactor.Networking;
using Reactor.Utilities;
using Rewired;
namespace MiraAPI.PluginLoading;
@@ -60,7 +60,7 @@ public sealed class MiraPluginManager
continue;
}
foreach (var method in type.GetMethods())
foreach (var method in AccessTools.GetDeclaredMethods(type))
{
var eventAttribute = method.GetCustomAttribute<RegisterEventAttribute>();
if (eventAttribute == null)
+3 -1
View File
@@ -4,6 +4,7 @@ using System.Linq;
using BepInEx.Configuration;
using MiraAPI.PluginLoading;
using MiraAPI.Roles;
using MiraAPI.Utilities;
using Reactor.Utilities;
using UnityEngine;
@@ -61,9 +62,10 @@ public static class PresetManager
{
if (btn != null)
{
Object.DestroyImmediate(btn);
btn.DeepDestroy(false);
}
}
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.Destroy();
transform.parent.gameObject.DeepDestroy();
}
public override void Close()
+6 -1
View File
@@ -109,10 +109,15 @@ public record struct CustomRoleConfiguration
public bool UseVanillaKillButton { get; set; }
/// <summary>
/// Gets or sets a value indicating whether the role can use vents.
/// Gets or sets a value indicating whether the role can use vents. Also sends vanilla vent data.
/// </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.Destroy();
roleBehaviour.gameObject.DeepDestroy();
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;
roleBehaviour.CanVent = customRole.Configuration.CanUseVent || customRole.Configuration.GetsVentData;
roleBehaviour.DefaultGhostRole = customRole.Configuration.GhostRole;
roleBehaviour.MaxCount = customRole.Configuration.MaxRoleCount;
roleBehaviour.RoleScreenshot = customRole.Configuration.OptionsScreenshot?.LoadAsset();
@@ -24,6 +24,26 @@ 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>
@@ -52,6 +72,7 @@ public static class AddressablesLoader
return;
}
AddressableHatsExist = true;
RegisteredHatKeys.Add(addressablesKey);
}
@@ -67,6 +88,7 @@ public static class AddressablesLoader
return;
}
AddressableSkinsExist = true;
RegisteredSkinKeys.Add(addressablesKey);
}
@@ -83,6 +105,7 @@ public static class AddressablesLoader
return;
}
AddressableNameplatesExist = true;
RegisteredNameplateKeys.Add((addressablesKey, groupTitle));
}
@@ -99,6 +122,7 @@ public static class AddressablesLoader
return;
}
AddressableVisorsExist = true;
RegisteredVisorKeys.Add((addressablesKey, groupTitle));
}
+127 -1
View File
@@ -1,4 +1,5 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
@@ -53,7 +54,7 @@ public static class Extensions
bool isComplete;
if (self.amClosing == Minigame.CloseState.Closing)
{
UnityEngine.Object.Destroy(self.gameObject);
self.gameObject.DeepDestroy();
return;
}
if (self.CloseSound && Constants.ShouldPlaySfx())
@@ -181,6 +182,16 @@ public static class Extensions
return TutorialManager.InstanceExists || AmongUsClient.Instance.HostId == playerControl.OwnerId;
}
/// <summary>
/// Checks if a PlayerControl is protected by a Guardian Angel.
/// </summary>
/// <param name="playerControl">The player you're checking for.</param>
/// <returns>If the player is protected, true, else false.</returns>
public static bool ProtectedByGa(this PlayerControl playerControl)
{
return playerControl.protectedByGuardianId > -1;
}
/// <summary>
/// Used to convert a System.Collections.Generic.List to Il2cppSystem.
/// </summary>
@@ -209,6 +220,121 @@ 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>
+16 -1
View File
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Reflection;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes;
using Object = Il2CppSystem.Object;
namespace MiraAPI.Utilities;
@@ -17,6 +18,7 @@ public class StateMachineWrapper<T> where T : Il2CppObjectBase
// normally it is fields, but IL2CPP turns them into properties
private readonly PropertyInfo _thisProperty;
private readonly PropertyInfo _stateProperty;
private readonly PropertyInfo _currentProperty;
private readonly Dictionary<string, PropertyInfo> _propertyCache;
private T? _parentInstance;
@@ -37,8 +39,9 @@ public class StateMachineWrapper<T> where T : Il2CppObjectBase
var 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)
if (_thisProperty == null || _stateProperty == null || _currentProperty == null)
{
throw new MissingMemberException($"Could not find required properties in type '{type}'.");
}
@@ -52,6 +55,18 @@ public class StateMachineWrapper<T> where T : Il2CppObjectBase
/// <returns>The current state as an integer.</returns>
public int GetState() => (int)_stateProperty.GetValue(_stateMachine)!;
/// <summary>
/// Sets the current state of the state machine.
/// </summary>
/// <param name="newState">The new state to use.</param>
public void SetState(int newState) => _stateProperty.SetValue(_stateMachine, newState);
/// <summary>
/// Sets the newest yield return of the state machine.
/// </summary>
/// <param name="newReturn">The new return to use.</param>
public void SetRecentReturn(Object newReturn) => _currentProperty.SetValue(_stateMachine, newReturn);
/// <summary>
/// Gets a parameter from the state machine by its name.
/// </summary>
Binary file not shown.