mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-10-21 13:37:54 +00:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fecdd9f4f7 |
No files matched your search
+2
-2
@@ -1,8 +1,8 @@
|
||||
<Project>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Reactor" Version="2.5.0-ci.371" />
|
||||
<PackageReference Include="Reactor" Version="2.3.1" />
|
||||
<PackageReference Include="BepInEx.Unity.IL2CPP" Version="6.0.0-be.735" Private="false" ExcludeAssets="runtime;native" />
|
||||
<PackageReference Include="AmongUs.GameLibs.Steam" Version="2026.3.31" PrivateAssets="all" />
|
||||
<PackageReference Include="AmongUs.GameLibs.Steam" Version="2025.10.14" 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" />
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
|
||||
|
||||
<VersionPrefix>0.4.0</VersionPrefix>
|
||||
<VersionPrefix>0.3.8</VersionPrefix>
|
||||
<VersionSuffix>dev</VersionSuffix>
|
||||
|
||||
<Authors>All Of Us, XtraCube, Angxl</Authors>
|
||||
|
||||
@@ -21,6 +21,8 @@ namespace MiraAPI.GameOptions;
|
||||
public static class ModdedOptionsManager
|
||||
{
|
||||
private static readonly Dictionary<PropertyInfo, ModdedOptionAttribute> OptionAttributes = [];
|
||||
private static readonly Dictionary<MethodBase, ModdedOptionAttribute> SetterAttributes = [];
|
||||
private static readonly Dictionary<MethodBase, ModdedOptionAttribute> GetterAttributes = [];
|
||||
private static readonly Dictionary<Type, AbstractOptionGroup> TypeToGroup = [];
|
||||
|
||||
internal static readonly Dictionary<OptionBehaviour, ModdedPlayerOption> CreatedPlayerOptions = [];
|
||||
@@ -100,12 +102,20 @@ public static class ModdedOptionsManager
|
||||
}
|
||||
|
||||
var setterOriginal = property.GetSetMethod();
|
||||
var setterPatch = typeof(ModdedOptionsManager).GetMethod(nameof(PropertySetterPatch));
|
||||
PluginSingleton<MiraApiPlugin>.Instance.Harmony.Patch(setterOriginal, postfix: new HarmonyMethod(setterPatch));
|
||||
if (setterOriginal != null)
|
||||
{
|
||||
var setterPatch = typeof(ModdedOptionsManager).GetMethod(nameof(PropertySetterPatch));
|
||||
PluginSingleton<MiraApiPlugin>.Instance.Harmony.Patch(setterOriginal, postfix: new HarmonyMethod(setterPatch));
|
||||
SetterAttributes[setterOriginal] = attribute;
|
||||
}
|
||||
|
||||
var getterOriginal = property.GetGetMethod();
|
||||
var getterPatch = typeof(ModdedOptionsManager).GetMethod(nameof(PropertyGetterPatch));
|
||||
PluginSingleton<MiraApiPlugin>.Instance.Harmony.Patch(getterOriginal, prefix: new HarmonyMethod(getterPatch));
|
||||
if (getterOriginal != null)
|
||||
{
|
||||
var getterPatch = typeof(ModdedOptionsManager).GetMethod(nameof(PropertyGetterPatch));
|
||||
PluginSingleton<MiraApiPlugin>.Instance.Harmony.Patch(getterOriginal, prefix: new HarmonyMethod(getterPatch));
|
||||
GetterAttributes[getterOriginal] = attribute;
|
||||
}
|
||||
|
||||
OptionAttributes.Add(property, attribute);
|
||||
attribute.HolderOption = option;
|
||||
@@ -183,7 +193,11 @@ public static class ModdedOptionsManager
|
||||
public static void PropertySetterPatch(MethodBase __originalMethod, object value)
|
||||
#pragma warning restore CA1707
|
||||
{
|
||||
var attribute = OptionAttributes.First(pair => pair.Key.GetSetMethod() == __originalMethod).Value;
|
||||
if (!SetterAttributes.TryGetValue(__originalMethod, out var attribute))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
attribute.SetValue(value);
|
||||
}
|
||||
|
||||
@@ -198,7 +212,11 @@ public static class ModdedOptionsManager
|
||||
public static bool PropertyGetterPatch(MethodBase __originalMethod, ref object __result)
|
||||
#pragma warning restore CA1707
|
||||
{
|
||||
var attribute = OptionAttributes.First(pair => pair.Key.GetGetMethod() == __originalMethod).Value;
|
||||
if (!GetterAttributes.TryGetValue(__originalMethod, out var attribute))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
__result = attribute.GetValue();
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -93,21 +93,11 @@ public static class CustomMurderRpc
|
||||
beforeMurderEvent.Cancel();
|
||||
}
|
||||
|
||||
if (target.ProtectedByGa())
|
||||
{
|
||||
beforeMurderEvent.Cancel();
|
||||
murderResultFlags = MurderResultFlags.FailedProtected;
|
||||
}
|
||||
else if (beforeMurderEvent.IsCancelled)
|
||||
if (beforeMurderEvent.IsCancelled)
|
||||
{
|
||||
murderResultFlags = MurderResultFlags.FailedError;
|
||||
}
|
||||
|
||||
if (beforeMurderEvent.IsCancelled && source.AmOwner)
|
||||
{
|
||||
source.isKilling = true;
|
||||
}
|
||||
|
||||
if (!PlayerControl.LocalPlayer.IsHost())
|
||||
{
|
||||
return;
|
||||
@@ -151,7 +141,6 @@ public static class CustomMurderRpc
|
||||
{
|
||||
if (LobbyBehaviour.Instance || !host.IsHost() || target.Data.IsDead || target.Data.Disconnected)
|
||||
{
|
||||
source.isKilling = false;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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>();
|
||||
|
||||
@@ -16,15 +16,8 @@ public static class OptionsMenuBehaviourPatch
|
||||
private static void OpenPostfix(OptionsMenuBehaviour __instance)
|
||||
{
|
||||
_remap_rollover = GameObject.Find("Remap Controls")?.GetComponent<ButtonRolloverHandler>()!;
|
||||
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.
|
||||
}
|
||||
_remap_background = _remap_rollover.transform.FindChild("Background").GetComponent<SpriteRenderer>();
|
||||
_remap_background.color = _conflicts ? Color.red : Color.white;
|
||||
}
|
||||
|
||||
[HarmonyPostfix]
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
using System.Collections;
|
||||
using HarmonyLib;
|
||||
using HarmonyLib;
|
||||
using MiraAPI.LocalSettings;
|
||||
using MiraAPI.Utilities.Assets;
|
||||
using Reactor.Utilities;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.Patches.Menu;
|
||||
@@ -21,14 +19,6 @@ 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;
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -5,8 +5,6 @@ using HarmonyLib;
|
||||
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 +39,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; } = [];
|
||||
@@ -487,11 +351,6 @@ internal static class GameSettingMenuPatches
|
||||
|
||||
_modifierBtnOgPos = _modifiersButton.transform.localPosition;
|
||||
|
||||
foreach (var plugin in MiraPluginManager.Instance.RegisteredPlugins)
|
||||
{
|
||||
PresetManager.LoadPresets(plugin);
|
||||
}
|
||||
|
||||
UpdateText(__instance, __instance.GameSettingsTab, __instance.RoleSettingsTab);
|
||||
}
|
||||
|
||||
@@ -699,6 +558,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 +602,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 +637,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)
|
||||
|
||||
@@ -29,6 +29,7 @@ public static class RoleSettingMenuPatches
|
||||
private static Dictionary<RoleOptionsGroup, bool> RoleGroupHidden { get; set; } = [];
|
||||
private static List<GameObject> Headers { get; set; } = [];
|
||||
private static List<RoleOptionSetting> RoleOptionSettings { get; set; } = [];
|
||||
private static Dictionary<RoleBehaviour, Sprite> RoleScreenshotSprites { get; } = [];
|
||||
|
||||
private static float ScrollerNum { get; set; } = 0.522f;
|
||||
|
||||
@@ -41,6 +42,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 +60,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 +140,6 @@ public static class RoleSettingMenuPatches
|
||||
num3++;
|
||||
}
|
||||
|
||||
Utilities.Extensions.ClearGarbageCollector();
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -157,7 +161,6 @@ public static class RoleSettingMenuPatches
|
||||
|
||||
if (roleGroups is null)
|
||||
{
|
||||
Utilities.Extensions.ClearGarbageCollector();
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -208,9 +211,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 +296,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 +315,6 @@ public static class RoleSettingMenuPatches
|
||||
ScrollerNum -= 0.4f;
|
||||
}
|
||||
}
|
||||
Utilities.Extensions.ClearGarbageCollector();
|
||||
|
||||
__instance.scrollBar.SetScrollBounds(__instance);
|
||||
return false;
|
||||
@@ -422,9 +429,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();
|
||||
@@ -501,11 +507,17 @@ public static class RoleSettingMenuPatches
|
||||
__instance.roleDescriptionText.transform.parent.localScale = new Vector3(0.0675f, 0.1494f, 0.5687f);
|
||||
labelBg.transform.localPosition = new Vector3(1.082f, 0.1054f, -2.5f);
|
||||
|
||||
__instance.roleScreenshot.sprite = Sprite.Create(
|
||||
role.RoleScreenshot.texture,
|
||||
new Rect(0, 0, 370, 230),
|
||||
Vector2.one / 2,
|
||||
100);
|
||||
if (!RoleScreenshotSprites.TryGetValue(role, out var screenshotSprite) || screenshotSprite == null)
|
||||
{
|
||||
screenshotSprite = Sprite.Create(
|
||||
role.RoleScreenshot.texture,
|
||||
new Rect(0, 0, 370, 230),
|
||||
Vector2.one / 2,
|
||||
100);
|
||||
RoleScreenshotSprites[role] = screenshotSprite;
|
||||
}
|
||||
|
||||
__instance.roleScreenshot.sprite = screenshotSprite;
|
||||
__instance.roleScreenshot.drawMode = SpriteDrawMode.Sliced;
|
||||
}
|
||||
|
||||
@@ -619,7 +631,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>();
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -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,12 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using BepInEx.Configuration;
|
||||
using BepInEx.Unity.IL2CPP;
|
||||
using HarmonyLib;
|
||||
using MiraAPI.Colors;
|
||||
using MiraAPI.Events;
|
||||
using MiraAPI.GameEnd;
|
||||
@@ -22,6 +23,7 @@ using MiraAPI.Roles;
|
||||
using MiraAPI.Utilities;
|
||||
using Reactor.Networking;
|
||||
using Reactor.Utilities;
|
||||
using Rewired;
|
||||
|
||||
namespace MiraAPI.PluginLoading;
|
||||
|
||||
@@ -30,6 +32,9 @@ namespace MiraAPI.PluginLoading;
|
||||
/// </summary>
|
||||
public sealed class MiraPluginManager
|
||||
{
|
||||
private const BindingFlags DeclaredInstanceMembers = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly;
|
||||
private const BindingFlags DeclaredStaticMembers = BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly;
|
||||
|
||||
private readonly Dictionary<Assembly, MiraPluginInfo> _registeredPlugins = [];
|
||||
|
||||
internal MiraPluginInfo[] RegisteredPlugins { get; private set; } = null!;
|
||||
@@ -49,41 +54,24 @@ public sealed class MiraPluginManager
|
||||
|
||||
var info = new MiraPluginInfo(miraPlugin, pluginInfo);
|
||||
var roles = new List<Type>();
|
||||
var registrationTimer = Stopwatch.StartNew();
|
||||
|
||||
var oldConfigSetting = info.PluginConfig.SaveOnConfigSet;
|
||||
info.PluginConfig.SaveOnConfigSet = false;
|
||||
|
||||
foreach (var type in assembly.GetTypes())
|
||||
foreach (var type in GetAssemblyTypes(assembly))
|
||||
{
|
||||
if (type == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (type.GetCustomAttribute<MiraIgnoreAttribute>() != null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach (var method in AccessTools.GetDeclaredMethods(type))
|
||||
{
|
||||
var eventAttribute = method.GetCustomAttribute<RegisterEventAttribute>();
|
||||
if (eventAttribute == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!method.IsStatic)
|
||||
{
|
||||
Error($"Event method {method.Name} in {type.Name} must be static.");
|
||||
continue;
|
||||
}
|
||||
|
||||
var parameters = method.GetParameters();
|
||||
if (parameters.Length != 1 || !parameters[0].ParameterType.IsSubclassOf(typeof(MiraEvent)))
|
||||
{
|
||||
Error($"Invalid event registration method {method.Name} in {type.Name}");
|
||||
continue;
|
||||
}
|
||||
|
||||
var paramType = parameters[0].ParameterType;
|
||||
MiraEventManager.RegisterEventHandler(paramType, method, eventAttribute.Priority);
|
||||
}
|
||||
RegisterEvents(type);
|
||||
|
||||
if (RegisterModifier(type, info))
|
||||
{
|
||||
@@ -131,7 +119,9 @@ public sealed class MiraPluginManager
|
||||
info.SavePublicCollections();
|
||||
PresetManager.CreateDefaultPreset(info);
|
||||
PresetManager.LoadPresets(info);
|
||||
Info($"Registering mod {pluginInfo.Metadata.GUID} with Mira API.");
|
||||
|
||||
registrationTimer.Stop();
|
||||
Info($"Registering mod {pluginInfo.Metadata.GUID} with Mira API in {registrationTimer.ElapsedMilliseconds}ms.");
|
||||
};
|
||||
IL2CPPChainloader.Instance.Finished += PaletteManager.RegisterAllColors;
|
||||
IL2CPPChainloader.Instance.Finished += () =>
|
||||
@@ -159,6 +149,45 @@ public sealed class MiraPluginManager
|
||||
return Instance._registeredPlugins.Values.FirstOrDefault(plugin => plugin.PluginId == pluginId);
|
||||
}
|
||||
|
||||
private static void RegisterEvents(Type type)
|
||||
{
|
||||
foreach (var method in type.GetMethods(DeclaredStaticMembers))
|
||||
{
|
||||
var eventAttribute = method.GetCustomAttribute<RegisterEventAttribute>();
|
||||
if (eventAttribute == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var parameters = method.GetParameters();
|
||||
if (parameters.Length != 1 || !typeof(MiraEvent).IsAssignableFrom(parameters[0].ParameterType))
|
||||
{
|
||||
Error($"Invalid event registration method {method.Name} in {type.Name}");
|
||||
continue;
|
||||
}
|
||||
|
||||
MiraEventManager.RegisterEventHandler(parameters[0].ParameterType, method, eventAttribute.Priority);
|
||||
}
|
||||
}
|
||||
|
||||
private static Type?[] GetAssemblyTypes(Assembly assembly)
|
||||
{
|
||||
try
|
||||
{
|
||||
return assembly.GetTypes();
|
||||
}
|
||||
catch (ReflectionTypeLoadException exception)
|
||||
{
|
||||
return exception.Types;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool IsAutoPropertyBackingField(FieldInfo field)
|
||||
{
|
||||
return field.IsDefined(typeof(CompilerGeneratedAttribute), false) &&
|
||||
field.Name.Contains("k__BackingField", StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
private static bool RegisterGameOver(Type type)
|
||||
{
|
||||
try
|
||||
@@ -186,7 +215,7 @@ public sealed class MiraPluginManager
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (var property in type.GetProperties())
|
||||
foreach (var property in type.GetProperties(DeclaredInstanceMembers))
|
||||
{
|
||||
if (property.GetMethod?.IsStatic == true)
|
||||
{
|
||||
@@ -209,7 +238,7 @@ public sealed class MiraPluginManager
|
||||
ModdedOptionsManager.RegisterAttributeOption(type, attribute, property, pluginInfo);
|
||||
}
|
||||
|
||||
foreach (var field in type.GetFields().Where(f => f.FieldType.IsAssignableTo(typeof(IModdedOption))))
|
||||
foreach (var field in type.GetFields(DeclaredInstanceMembers).Where(f => !IsAutoPropertyBackingField(f) && f.FieldType.IsAssignableTo(typeof(IModdedOption))))
|
||||
{
|
||||
Error($"{field.Name} is a field, not a property. Use properties for options.");
|
||||
}
|
||||
@@ -264,7 +293,7 @@ public sealed class MiraPluginManager
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var property in type.GetProperties())
|
||||
foreach (var property in type.GetProperties(DeclaredStaticMembers))
|
||||
{
|
||||
if (property.PropertyType != typeof(CustomColor))
|
||||
{
|
||||
@@ -280,7 +309,7 @@ public sealed class MiraPluginManager
|
||||
PaletteManager.CustomColors.Add(color);
|
||||
}
|
||||
|
||||
foreach (var field in type.GetFields().Where(f => f.FieldType.IsAssignableTo(typeof(CustomColor))))
|
||||
foreach (var field in type.GetFields(DeclaredStaticMembers).Where(f => !IsAutoPropertyBackingField(f) && f.FieldType.IsAssignableTo(typeof(CustomColor))))
|
||||
{
|
||||
Error($"{field.Name} is a field, not a property. Use properties for colors.");
|
||||
}
|
||||
@@ -332,13 +361,13 @@ public sealed class MiraPluginManager
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (var property in type.GetProperties())
|
||||
if (!LocalSettingsManager.TypeToTab.TryGetValue(type, out var tabInstance))
|
||||
{
|
||||
if (LocalSettingsManager.TypeToTab[type] is not { } tabInstance)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (var property in type.GetProperties(DeclaredInstanceMembers))
|
||||
{
|
||||
if (property.GetCustomAttribute<LocalSettingsButtonAttribute>() != null &&
|
||||
property.PropertyType.IsAssignableTo(typeof(LocalSettingsButton)))
|
||||
{
|
||||
@@ -374,7 +403,7 @@ public sealed class MiraPluginManager
|
||||
attribute.CreateSetting(type, configEntry);
|
||||
}
|
||||
|
||||
foreach (var field in type.GetFields().Where(f => f.FieldType.IsAssignableTo(typeof(ConfigEntryBase)) && f.GetCustomAttribute<LocalSettingAttribute>() != null))
|
||||
foreach (var field in type.GetFields(DeclaredInstanceMembers).Where(f => !IsAutoPropertyBackingField(f) && f.FieldType.IsAssignableTo(typeof(ConfigEntryBase)) && f.GetCustomAttribute<LocalSettingAttribute>() != null))
|
||||
{
|
||||
Error($"{field.Name} is a field, not a property. Use properties for local settings.");
|
||||
}
|
||||
@@ -404,7 +433,7 @@ public sealed class MiraPluginManager
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var property in type.GetProperties())
|
||||
foreach (var property in type.GetProperties(DeclaredStaticMembers))
|
||||
{
|
||||
if (property.PropertyType != typeof(MiraKeybind))
|
||||
{
|
||||
@@ -428,7 +457,7 @@ public sealed class MiraPluginManager
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var field in type.GetFields().Where(f => f.FieldType.IsAssignableTo(typeof(MiraKeybind))))
|
||||
foreach (var field in type.GetFields(DeclaredStaticMembers).Where(f => !IsAutoPropertyBackingField(f) && f.FieldType.IsAssignableTo(typeof(MiraKeybind))))
|
||||
{
|
||||
Error($"{field.Name} is a field, not a property. Use properties for keybinds.");
|
||||
}
|
||||
|
||||
@@ -4,8 +4,6 @@ using System.Linq;
|
||||
using BepInEx.Configuration;
|
||||
using MiraAPI.PluginLoading;
|
||||
using MiraAPI.Roles;
|
||||
using MiraAPI.Utilities;
|
||||
using Reactor.Utilities;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.Presets;
|
||||
@@ -62,10 +60,9 @@ public static class PresetManager
|
||||
{
|
||||
if (btn != null)
|
||||
{
|
||||
btn.DeepDestroy(false);
|
||||
Object.DestroyImmediate(btn);
|
||||
}
|
||||
}
|
||||
Utilities.Extensions.ClearGarbageCollector();
|
||||
|
||||
plugin.InternalPresets.Clear();
|
||||
if (!Directory.Exists(PresetDirectory))
|
||||
@@ -81,8 +78,6 @@ public static class PresetManager
|
||||
|
||||
foreach (var file in Directory.GetFiles(pluginPresetPath, "*.cfg"))
|
||||
{
|
||||
var fileName = Path.GetFileName(file);
|
||||
Info($"Loading preset file {fileName}");
|
||||
var presetName = Path.GetFileNameWithoutExtension(file);
|
||||
var presetConfig = new ConfigFile(file, false)
|
||||
{
|
||||
@@ -133,9 +128,6 @@ public static class PresetManager
|
||||
|
||||
foreach (var file in Directory.GetFiles(pluginPresetPath, "*.cfg"))
|
||||
{
|
||||
var fileName = Path.GetFileName(file);
|
||||
Info($"Loading preset file {fileName}");
|
||||
var presetName = Path.GetFileNameWithoutExtension(file);
|
||||
var presetConfig = new ConfigFile(file, false)
|
||||
{
|
||||
SaveOnConfigSet = false,
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Resources;
|
||||
@@ -13,6 +14,8 @@ namespace MiraAPI.Utilities.Assets;
|
||||
/// <param name="path">The path of the wave file.</param>
|
||||
public class LoadableAudioResourceAsset(string path) : LoadableAsset<AudioClip>
|
||||
{
|
||||
private static readonly object CacheLock = new();
|
||||
private static readonly Dictionary<(Assembly Assembly, string Path), AudioClip> AudioClipCache = [];
|
||||
private readonly Assembly _assembly = Assembly.GetCallingAssembly();
|
||||
|
||||
/// <summary>
|
||||
@@ -23,6 +26,20 @@ public class LoadableAudioResourceAsset(string path) : LoadableAsset<AudioClip>
|
||||
/// <exception cref="MissingManifestResourceException">Stream failed to load. Check if the name of your asset was correct.</exception>
|
||||
public override AudioClip LoadAsset()
|
||||
{
|
||||
if (LoadedAsset != null)
|
||||
{
|
||||
return LoadedAsset;
|
||||
}
|
||||
|
||||
lock (CacheLock)
|
||||
{
|
||||
if (AudioClipCache.TryGetValue((_assembly, path), out var cachedClip) && cachedClip != null)
|
||||
{
|
||||
LoadedAsset = cachedClip;
|
||||
return cachedClip;
|
||||
}
|
||||
}
|
||||
|
||||
using var assetStream = _assembly.GetManifestResourceStream(path)
|
||||
?? throw new MissingManifestResourceException($"Stream failed to load. Check if the asset name is correct: {path}");
|
||||
|
||||
@@ -92,6 +109,13 @@ public class LoadableAudioResourceAsset(string path) : LoadableAsset<AudioClip>
|
||||
var audioClip = AudioClip.Create(path, samples.Length / channels, channels, sampleRate, false);
|
||||
audioClip.SetData(samples, 0);
|
||||
|
||||
LoadedAsset = audioClip;
|
||||
|
||||
lock (CacheLock)
|
||||
{
|
||||
AudioClipCache[(_assembly, path)] = audioClip;
|
||||
}
|
||||
|
||||
return audioClip;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Reactor.Utilities.Extensions;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -12,6 +13,9 @@ namespace MiraAPI.Utilities.Assets;
|
||||
/// <typeparam name="T">The type of the asset to be loaded.</typeparam>
|
||||
public class LoadableBundleAsset<T>(string name, AssetBundle bundle) : LoadableAsset<T> where T : UnityEngine.Object
|
||||
{
|
||||
private static readonly object CacheLock = new();
|
||||
private static readonly Dictionary<(int BundleId, Type AssetType, string Name), UnityEngine.Object> BundleAssetCache = [];
|
||||
|
||||
/// <summary>
|
||||
/// Loads the asset from the asset bundle.
|
||||
/// </summary>
|
||||
@@ -24,6 +28,16 @@ public class LoadableBundleAsset<T>(string name, AssetBundle bundle) : LoadableA
|
||||
return LoadedAsset;
|
||||
}
|
||||
|
||||
var cacheKey = (bundle.GetInstanceID(), typeof(T), name);
|
||||
lock (CacheLock)
|
||||
{
|
||||
if (BundleAssetCache.TryGetValue(cacheKey, out var cachedAsset) && cachedAsset is T typedAsset)
|
||||
{
|
||||
LoadedAsset = typedAsset;
|
||||
return typedAsset;
|
||||
}
|
||||
}
|
||||
|
||||
LoadedAsset = bundle.LoadAsset<T>(name);
|
||||
|
||||
if (LoadedAsset == null)
|
||||
@@ -31,6 +45,11 @@ public class LoadableBundleAsset<T>(string name, AssetBundle bundle) : LoadableA
|
||||
throw new InvalidOperationException($"INVALID ASSET: {name}");
|
||||
}
|
||||
|
||||
lock (CacheLock)
|
||||
{
|
||||
BundleAssetCache[cacheKey] = LoadedAsset;
|
||||
}
|
||||
|
||||
return LoadedAsset;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using Reactor.Utilities.Extensions;
|
||||
using UnityEngine;
|
||||
@@ -10,6 +11,10 @@ namespace MiraAPI.Utilities.Assets;
|
||||
/// </summary>
|
||||
public static class SpriteTools
|
||||
{
|
||||
private static readonly object CacheLock = new();
|
||||
private static readonly Dictionary<(Assembly Assembly, string ResourcePath), Texture2D> TextureCache = [];
|
||||
private static readonly Dictionary<(Assembly Assembly, string ResourcePath, float PixelsPerUnit), Sprite> SpriteCache = [];
|
||||
|
||||
/// <summary>
|
||||
/// Loads and returns a texture from a resource path using the specified assembly.
|
||||
/// </summary>
|
||||
@@ -19,11 +24,20 @@ public static class SpriteTools
|
||||
/// <exception cref="ArgumentException">Thrown when the resource cannot be found in the specified assembly.</exception>
|
||||
public static Texture2D LoadTextureFromResourcePath(string resourcePath, Assembly assembly)
|
||||
{
|
||||
lock (CacheLock)
|
||||
{
|
||||
if (TextureCache.TryGetValue((assembly, resourcePath), out var cachedTexture) && cachedTexture != null)
|
||||
{
|
||||
return cachedTexture;
|
||||
}
|
||||
}
|
||||
|
||||
var tex = new Texture2D(1, 1, TextureFormat.ARGB32, false)
|
||||
{
|
||||
wrapMode = TextureWrapMode.Clamp,
|
||||
};
|
||||
var myStream = assembly.GetManifestResourceStream(resourcePath);
|
||||
|
||||
using var myStream = assembly.GetManifestResourceStream(resourcePath);
|
||||
if (myStream != null)
|
||||
{
|
||||
var buttonTexture = myStream.ReadFully();
|
||||
@@ -35,6 +49,12 @@ public static class SpriteTools
|
||||
}
|
||||
|
||||
tex.name = resourcePath;
|
||||
|
||||
lock (CacheLock)
|
||||
{
|
||||
TextureCache[(assembly, resourcePath)] = tex;
|
||||
}
|
||||
|
||||
return tex;
|
||||
}
|
||||
|
||||
@@ -47,9 +67,23 @@ public static class SpriteTools
|
||||
/// <returns>A <see cref="Sprite"/> object created from the texture loaded from the specified resource path.</returns>
|
||||
public static Sprite LoadSpriteFromPath(string resourcePath, Assembly assembly, float pixelsPerUnit)
|
||||
{
|
||||
lock (CacheLock)
|
||||
{
|
||||
if (SpriteCache.TryGetValue((assembly, resourcePath, pixelsPerUnit), out var cachedSprite) && cachedSprite != null)
|
||||
{
|
||||
return cachedSprite;
|
||||
}
|
||||
}
|
||||
|
||||
var tex = LoadTextureFromResourcePath(resourcePath, assembly);
|
||||
var sprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), new Vector2(0.5f, 0.5f), pixelsPerUnit);
|
||||
sprite.name = resourcePath;
|
||||
|
||||
lock (CacheLock)
|
||||
{
|
||||
SpriteCache[(assembly, resourcePath, pixelsPerUnit)] = sprite;
|
||||
}
|
||||
|
||||
return sprite;
|
||||
}
|
||||
}
|
||||
@@ -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())
|
||||
@@ -182,16 +181,6 @@ 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>
|
||||
@@ -220,121 +209,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>
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -3,7 +3,6 @@ using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using HarmonyLib;
|
||||
using Il2CppInterop.Runtime.InteropTypes;
|
||||
using Object = Il2CppSystem.Object;
|
||||
|
||||
namespace MiraAPI.Utilities;
|
||||
|
||||
@@ -18,7 +17,6 @@ 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;
|
||||
@@ -39,9 +37,8 @@ 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 || _currentProperty == null)
|
||||
if (_thisProperty == null || _stateProperty == null)
|
||||
{
|
||||
throw new MissingMemberException($"Could not find required properties in type '{type}'.");
|
||||
}
|
||||
@@ -55,18 +52,6 @@ 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.
Reference in new issue
Block a user