diff --git a/MiraAPI.Example/ExampleEventHandlers.cs b/MiraAPI.Example/ExampleEventHandlers.cs index e2368f7..ed7748c 100644 --- a/MiraAPI.Example/ExampleEventHandlers.cs +++ b/MiraAPI.Example/ExampleEventHandlers.cs @@ -4,7 +4,10 @@ using MiraAPI.Events.Vanilla.Gameplay; using MiraAPI.Events.Vanilla.Map; using MiraAPI.Events.Vanilla.Player; using MiraAPI.Example.Buttons.Freezer; +using MiraAPI.Utilities.Assets; using Reactor.Utilities; +using TMPro; +using UnityEngine; namespace MiraAPI.Example; @@ -16,6 +19,8 @@ public static class ExampleEventHandlers MiraEventManager.RegisterEventHandler(@event => { Logger.Info($"{@event.Source.Data.PlayerName} is about to kill {@event.Target.Data.PlayerName}"); + var asset = new LoadableAddressableAsset("Assets/Prefabs/SomeText.prefab"); + Logger.Info($"{asset.LoadAsset().GetComponent().text}"); }); MiraEventManager.RegisterEventHandler(@event => diff --git a/MiraAPI.Example/ExamplePlugin.cs b/MiraAPI.Example/ExamplePlugin.cs index b3e3952..86c6cff 100644 --- a/MiraAPI.Example/ExamplePlugin.cs +++ b/MiraAPI.Example/ExamplePlugin.cs @@ -9,6 +9,7 @@ using Reactor.Networking; using Reactor.Networking.Attributes; using System.IO; using System.Reflection; +using UnityEngine; namespace MiraAPI.Example; @@ -28,7 +29,9 @@ public partial class ExamplePlugin : BasePlugin, IMiraPlugin Harmony.PatchAll(); var path = Path.GetDirectoryName(Assembly.GetAssembly(typeof(ExamplePlugin))!.Location) + "\\touhats.catalog"; - AddressablesLoader.RegisterToLoad(path); + AddressablesLoader.RegisterCatalog(path); AddressablesLoader.RegisterHats("touhats"); + + AddressablesLoader.RegisterCatalog("https://raw.githubusercontent.com/MyDragonBreath/MyDragonBreath/refs/heads/main/DONTUSEGITHUBASACDN/catalog.json"); } } diff --git a/MiraAPI/Patches/Menu/HatsTabPatches.cs b/MiraAPI/Patches/Menu/HatsTabPatches.cs index 6e6a6c4..20d86d5 100644 --- a/MiraAPI/Patches/Menu/HatsTabPatches.cs +++ b/MiraAPI/Patches/Menu/HatsTabPatches.cs @@ -54,8 +54,10 @@ public static class HatsTabPatches { hatIndex = (hatIndex + 4) / 5 * 5; // yes it looks redundant, but consider hatindex = 0, symbolically it would be 4, the computer calculates 0. var text = Object.Instantiate(groupNameText, __instance.scroller.Inner); + text.enabled = true; text.gameObject.transform.localScale = Vector3.one; text.GetComponent().Destroy(); + text.EnableStencilMasking(); text.text = $"{groupName}"; text.alignment = TextAlignmentOptions.Center; text.fontSize = 3f; @@ -87,7 +89,10 @@ public static class HatsTabPatches colorChip.Button.OnMouseOver.AddListener((Action)(() => __instance.SelectHat(hat))); colorChip.Button.OnMouseOut.AddListener((Action)(() => __instance.SelectHat(HatManager.Instance.GetHatById(DataManager.Player.Customization.Hat)))); colorChip.Inner.SetHat(hat, __instance.HasLocalPlayer() ? PlayerControl.LocalPlayer.Data.DefaultOutfit.ColorId : DataManager.Player.Customization.Color); - colorChip.Inner.transform.GetChild(0).GetComponent().maskInteraction = SpriteMaskInteraction.VisibleInsideMask; + colorChip.Button.ClickMask = __instance.scroller.Hitbox; + colorChip.SelectionHighlight.gameObject.SetActive(false); + __instance.UpdateMaterials(colorChip.Inner.FrontLayer, hat); + colorChip.Inner.SetMaskType(PlayerMaterial.MaskType.SimpleUI); colorChip.transform.localPosition = new Vector3(position.x, position.y, -1f); colorChip.Inner.transform.localPosition = hat.ChipOffset + new Vector2(0f, -0.3f); colorChip.Tag = hat; diff --git a/MiraAPI/Patches/Menu/MainMenuManagerPatches.cs b/MiraAPI/Patches/Menu/MainMenuManagerPatches.cs index 08b3963..6f44ac5 100644 --- a/MiraAPI/Patches/Menu/MainMenuManagerPatches.cs +++ b/MiraAPI/Patches/Menu/MainMenuManagerPatches.cs @@ -1,17 +1,17 @@ using HarmonyLib; using MiraAPI.Utilities.Assets; -using Reactor.Utilities; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace MiraAPI.Patches.Menu; +/// +/// General MainMenuManage patches. +/// [HarmonyPatch(typeof(MainMenuManager))] public static class MainMenuManagerPatches { + /// + /// A postifix on Awake to load all the addressables registered. + /// [HarmonyPatch(nameof(MainMenuManager.Awake))] [HarmonyPostfix] public static void AwakePostfix() diff --git a/MiraAPI/Patches/Menu/NameplatesTabPatches.cs b/MiraAPI/Patches/Menu/NameplatesTabPatches.cs new file mode 100644 index 0000000..e2a87c4 --- /dev/null +++ b/MiraAPI/Patches/Menu/NameplatesTabPatches.cs @@ -0,0 +1,102 @@ +using AmongUs.Data; +using HarmonyLib; +using Innersloth.Assets; +using MiraAPI.Utilities; +using Reactor.Utilities.Extensions; +using System; +using System.Collections.Generic; +using System.Linq; +using TMPro; +using UnityEngine; +using Object = UnityEngine.Object; + +namespace MiraAPI.Patches.Menu; + +[HarmonyPatch(typeof(NameplatesTab))] +public static class NameplatesTabPatches +{ + private static readonly SortedList> SortedNameplates = new(new ControllableComparer(["vanilla"], [], StringComparer.InvariantCulture)); + + internal static void AddRange(IEnumerable<(string Key, NamePlateData Visor)> data) + { + foreach (var item in data) + { + if (!SortedNameplates.ContainsKey(item.Key)) SortedNameplates.Add(item.Key, []); + SortedNameplates[item.Key].Add(item.Visor); + } + } + + [HarmonyPatch(nameof(NameplatesTab.OnEnable))] + [HarmonyPrefix] + public static bool OnEnablePrefix(NameplatesTab __instance) + { + __instance.plateId = HatManager.Instance.GetNamePlateById(DataManager.Player.Customization.namePlate).ProdId; + + if (!SortedNameplates.ContainsKey("Vanilla")) AddRange(DestroyableSingleton.Instance.GetUnlockedNamePlates().Select(x => ("Vanilla", x))); + GenerateHats(__instance); + + return false; + } + + private static void GenerateHats(NameplatesTab __instance) + { + foreach (ColorChip instanceColorChip in __instance.ColorChips) instanceColorChip.gameObject.Destroy(); + __instance.ColorChips.Clear(); + __instance.scroller.Inner.GetComponentsInChildren().Do(x => x.gameObject.Destroy()); + + var groupNameText = __instance.GetComponentInChildren(false); + + int hatIndex = 0; + + foreach ((string groupName, List visors) in SortedNameplates) + { + hatIndex = (hatIndex + 1) / 2 * 2; // yes it looks redundant, but consider hatindex = 0, symbolically it would be 4, the computer calculates 0. + var text = Object.Instantiate(groupNameText, __instance.scroller.Inner); + text.enabled = true; + text.gameObject.transform.localScale = Vector3.one; + text.GetComponent().Destroy(); + text.EnableStencilMasking(); + text.text = $"{groupName}"; + text.alignment = TextAlignmentOptions.Center; + text.fontSize = 3f; + text.fontSizeMax = 3f; + text.fontSizeMin = 0f; + float xLerp = __instance.XRange.Lerp(0.5f); + float yLerp = __instance.YStart - hatIndex / __instance.NumPerRow * __instance.YOffset; + text.transform.localPosition = new Vector3(xLerp, yLerp, -1f); + + hatIndex += 2; + foreach (var visor in visors.OrderBy(HatManager.Instance.allNamePlates.IndexOf)) + { + float hatXposition = __instance.XRange.Lerp(hatIndex % __instance.NumPerRow / (__instance.NumPerRow - 1f)); + float hatYposition = __instance.YStart - hatIndex / __instance.NumPerRow * __instance.YOffset; + GenerateColorChip(__instance, new Vector2(hatXposition, hatYposition), visor); + hatIndex += 1; + } + } + + __instance.scroller.ContentYBounds.max = -(__instance.YStart - (hatIndex + 1) / __instance.NumPerRow * __instance.YOffset) - 3f; + __instance.currentNameplateIsEquipped = true; + } + + private static void GenerateColorChip(NameplatesTab __instance, Vector2 position, NamePlateData namePlate) + { + var colorChip = Object.Instantiate(__instance.ColorTabPrefab, __instance.scroller.Inner); + colorChip.gameObject.name = namePlate.ProductId; + colorChip.Button.OnClick.AddListener((Action)(() => __instance.ClickEquip())); + colorChip.Button.OnMouseOver.AddListener((Action)(() => __instance.SelectNameplate(namePlate))); + colorChip.Button.OnMouseOut.AddListener((Action)(() => __instance.SelectNameplate(HatManager.Instance.GetNamePlateById(DataManager.Player.Customization.NamePlate)))); + colorChip.Button.ClickMask = __instance.scroller.Hitbox; + colorChip.ProductId = namePlate.ProdId; + + var x = (NamePlateViewData viewdata) => + { + colorChip.transform.GetChild(1).GetComponent().sprite = viewdata?.Image; + //(colorChip as NameplateChip).image.sprite = viewdata?.Image; + }; + __instance.StartCoroutine(AddressableAssetExtensions.CoLoadAssetAsync(__instance, namePlate.GetAssetReference(), x)); + colorChip.transform.localPosition = new Vector3(position.x, position.y, -1f); + colorChip.Tag = namePlate; + __instance.ColorChips.Add(colorChip); + } +} diff --git a/MiraAPI/Patches/Menu/SkinsTabPatches.cs b/MiraAPI/Patches/Menu/SkinsTabPatches.cs new file mode 100644 index 0000000..cd303bf --- /dev/null +++ b/MiraAPI/Patches/Menu/SkinsTabPatches.cs @@ -0,0 +1,101 @@ +using AmongUs.Data; +using HarmonyLib; +using MiraAPI.Utilities; +using Reactor.Utilities.Extensions; +using System; +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Linq; +using TMPro; +using UnityEngine; +using Object = UnityEngine.Object; + +namespace MiraAPI.Patches.Menu; + +[HarmonyPatch(typeof(SkinsTab))] +public static class SkinsTabPatches +{ + private static SortedList> sortedSkins = []; + + [HarmonyPatch(nameof(SkinsTab.OnEnable))] + [HarmonyPrefix] + public static bool OnEnablePrefix(SkinsTab __instance) + { + __instance.skinId = HatManager.Instance.GetSkinById(DataManager.Player.Customization.Skin).ProdId; + var allSkins = HatManager.Instance.GetUnlockedSkins().ToImmutableList(); + + if (sortedSkins.Count == 0) + { + var comparer = new ControllableComparer(["vanilla"], [], StringComparer.InvariantCulture); + sortedSkins = new SortedList>(comparer); + foreach (var skin in allSkins) + { + if (!sortedSkins.ContainsKey(skin.StoreName)) sortedSkins[skin.StoreName] = []; + sortedSkins[skin.StoreName].Add(skin); + } + } + + GenerateHats(__instance); + + return false; + } + + private static void GenerateHats(SkinsTab __instance) + { + foreach (ColorChip instanceColorChip in __instance.ColorChips) instanceColorChip.gameObject.Destroy(); + __instance.ColorChips.Clear(); + __instance.scroller.Inner.GetComponentsInChildren().Do(x => x.gameObject.Destroy()); + + var groupNameText = __instance.GetComponentInChildren(false); + + int hatIndex = 0; + + foreach ((string groupName, List skins) in sortedSkins) + { + hatIndex = (hatIndex + 4) / 5 * 5; // yes it looks redundant, but consider hatindex = 0, symbolically it would be 4, the computer calculates 0. + var text = Object.Instantiate(groupNameText, __instance.scroller.Inner); + text.enabled = true; + text.gameObject.transform.localScale = Vector3.one; + text.GetComponent().Destroy(); + text.EnableStencilMasking(); + text.text = $"{groupName}"; + text.alignment = TextAlignmentOptions.Center; + text.fontSize = 3f; + text.fontSizeMax = 3f; + text.fontSizeMin = 0f; + float xLerp = __instance.XRange.Lerp(0.5f); + float yLerp = __instance.YStart - hatIndex / __instance.NumPerRow * __instance.YOffset; + text.transform.localPosition = new Vector3(xLerp, yLerp, -1f); + + hatIndex += 5; + foreach (var skin in skins.OrderBy(HatManager.Instance.allSkins.IndexOf)) + { + float hatXposition = __instance.XRange.Lerp(hatIndex % __instance.NumPerRow / (__instance.NumPerRow - 1f)); + float hatYposition = __instance.YStart - hatIndex / __instance.NumPerRow * __instance.YOffset; + GenerateColorChip(__instance, new Vector2(hatXposition, hatYposition), skin); + hatIndex += 1; + } + } + + __instance.scroller.ContentYBounds.max = -(__instance.YStart - (hatIndex + 1) / __instance.NumPerRow * __instance.YOffset) - 3f; + __instance.currentSkinIsEquipped = true; + } + + private static void GenerateColorChip(SkinsTab __instance, Vector2 position, SkinData skin) + { + var colorChip = Object.Instantiate(__instance.ColorTabPrefab, __instance.scroller.Inner); + colorChip.gameObject.name = skin.ProductId; + colorChip.Button.OnClick.AddListener((Action)(() => __instance.ClickEquip())); + colorChip.Button.OnMouseOver.AddListener((Action)(() => __instance.SelectSkin(skin))); + colorChip.Button.OnMouseOut.AddListener((Action)(() => __instance.SelectSkin(HatManager.Instance.GetSkinById(DataManager.Player.Customization.Skin)))); + colorChip.Button.ClickMask = __instance.scroller.Hitbox; + colorChip.ProductId = skin.ProductId; + colorChip.SelectionHighlight.gameObject.SetActive(false); + __instance.UpdateMaterials(colorChip.Inner.FrontLayer, skin); + skin.SetPreview(colorChip.Inner.FrontLayer, __instance.HasLocalPlayer() ? PlayerControl.LocalPlayer.Data.DefaultOutfit.ColorId : DataManager.Player.Customization.Color); + colorChip.transform.localPosition = new Vector3(position.x, position.y, -1f); + colorChip.Inner.transform.localPosition = skin.ChipOffset + new Vector2(0f, -0.3f); + colorChip.Tag = skin; + __instance.ColorChips.Add(colorChip); + } +} diff --git a/MiraAPI/Patches/Menu/VisorsTabPatches.cs b/MiraAPI/Patches/Menu/VisorsTabPatches.cs new file mode 100644 index 0000000..d32cb6f --- /dev/null +++ b/MiraAPI/Patches/Menu/VisorsTabPatches.cs @@ -0,0 +1,98 @@ +using AmongUs.Data; +using HarmonyLib; +using MiraAPI.Utilities; +using Reactor.Utilities.Extensions; +using System; +using System.Collections.Generic; +using System.Linq; +using TMPro; +using UnityEngine; +using Object = UnityEngine.Object; + +namespace MiraAPI.Patches.Menu; + +[HarmonyPatch(typeof(VisorsTab))] +public static class VisorsTabPatches +{ + private static readonly SortedList> SortedVisors = new(new ControllableComparer(["vanilla"], [], StringComparer.InvariantCulture)); + + internal static void AddRange(IEnumerable<(string Key, VisorData Visor)> data) + { + foreach (var item in data) + { + if (!SortedVisors.ContainsKey(item.Key)) SortedVisors.Add(item.Key, []); + SortedVisors[item.Key].Add(item.Visor); + } + } + + [HarmonyPatch(nameof(VisorsTab.OnEnable))] + [HarmonyPrefix] + public static bool OnEnablePrefix(VisorsTab __instance) + { + __instance.visorId = HatManager.Instance.GetVisorById(DataManager.Player.Customization.Visor).ProdId; + + if (!SortedVisors.ContainsKey("Vanilla")) AddRange(DestroyableSingleton.Instance.GetUnlockedVisors().Select(x => ("Vanilla", x))); + GenerateHats(__instance); + + return false; + } + + private static void GenerateHats(VisorsTab __instance) + { + foreach (ColorChip instanceColorChip in __instance.ColorChips) instanceColorChip.gameObject.Destroy(); + __instance.ColorChips.Clear(); + __instance.scroller.Inner.GetComponentsInChildren().Do(x => x.gameObject.Destroy()); + + var groupNameText = __instance.GetComponentInChildren(false); + + int hatIndex = 0; + + foreach ((string groupName, List visors) in SortedVisors) + { + hatIndex = (hatIndex + 4) / 5 * 5; // yes it looks redundant, but consider hatindex = 0, symbolically it would be 4, the computer calculates 0. + var text = Object.Instantiate(groupNameText, __instance.scroller.Inner); + text.enabled = true; + text.gameObject.transform.localScale = Vector3.one; + text.GetComponent().Destroy(); + text.EnableStencilMasking(); + text.text = $"{groupName}"; + text.alignment = TextAlignmentOptions.Center; + text.fontSize = 3f; + text.fontSizeMax = 3f; + text.fontSizeMin = 0f; + float xLerp = __instance.XRange.Lerp(0.5f); + float yLerp = __instance.YStart - hatIndex / __instance.NumPerRow * __instance.YOffset; + text.transform.localPosition = new Vector3(xLerp, yLerp, -1f); + + hatIndex += 5; + foreach (var visor in visors.OrderBy(HatManager.Instance.allVisors.IndexOf)) + { + float hatXposition = __instance.XRange.Lerp(hatIndex % __instance.NumPerRow / (__instance.NumPerRow - 1f)); + float hatYposition = __instance.YStart - hatIndex / __instance.NumPerRow * __instance.YOffset; + GenerateColorChip(__instance, new Vector2(hatXposition, hatYposition), visor); + hatIndex += 1; + } + } + + __instance.scroller.ContentYBounds.max = -(__instance.YStart - (hatIndex + 1) / __instance.NumPerRow * __instance.YOffset) - 3f; + __instance.currentVisorIsEquipped = true; + } + + private static void GenerateColorChip(VisorsTab __instance, Vector2 position, VisorData visor) + { + var colorChip = Object.Instantiate(__instance.ColorTabPrefab, __instance.scroller.Inner); + colorChip.gameObject.name = visor.ProductId; + colorChip.Button.OnClick.AddListener((Action)(() => __instance.ClickEquip())); + colorChip.Button.OnMouseOver.AddListener((Action)(() => __instance.SelectVisor(visor))); + colorChip.Button.OnMouseOut.AddListener((Action)(() => __instance.SelectVisor(HatManager.Instance.GetVisorById(DataManager.Player.Customization.Visor)))); + colorChip.Button.ClickMask = __instance.scroller.Hitbox; + colorChip.ProductId = visor.ProductId; + colorChip.SelectionHighlight.gameObject.SetActive(false); + __instance.UpdateMaterials(colorChip.Inner.FrontLayer, visor); + visor.SetPreview(colorChip.Inner.FrontLayer, __instance.HasLocalPlayer() ? PlayerControl.LocalPlayer.Data.DefaultOutfit.ColorId : DataManager.Player.Customization.Color); + colorChip.transform.localPosition = new Vector3(position.x, position.y, -1f); + colorChip.Inner.transform.localPosition = visor.ChipOffset + new Vector2(0f, -0.3f); + colorChip.Tag = visor; + __instance.ColorChips.Add(colorChip); + } +} diff --git a/MiraAPI/Utilities/Assets/AddressablesLoader.cs b/MiraAPI/Utilities/Assets/AddressablesLoader.cs index 9dc92f1..2c9bdef 100644 --- a/MiraAPI/Utilities/Assets/AddressablesLoader.cs +++ b/MiraAPI/Utilities/Assets/AddressablesLoader.cs @@ -1,12 +1,9 @@ -using BepInEx.Unity.IL2CPP.Utils; -using Il2CppInterop.Runtime.Attributes; +using Il2CppInterop.Runtime.Attributes; +using MiraAPI.Patches.Menu; using Reactor.Utilities; -using Reactor.Utilities.Attributes; -using System; using System.Collections; using System.Collections.Generic; using System.Linq; -using UnityEngine; using UnityEngine.AddressableAssets; using UnityEngine.ResourceManagement.AsyncOperations; @@ -15,14 +12,14 @@ namespace MiraAPI.Utilities.Assets; /// /// The component for loading Addressables, and cosmetics. /// -public class AddressablesLoader +public static class AddressablesLoader { private static readonly List<(string Location, string ProviderSuffix)> CatalogLocations = []; private static readonly List LoadedLocations = []; private static readonly List RegisteredHatKeys = []; - private static readonly List RegisteredVisorKeys = []; - private static readonly List RegisteredNameplateKeys = []; + private static readonly List<(string, string)> RegisteredVisorKeys = []; + private static readonly List<(string, string)> RegisteredNameplateKeys = []; private static readonly List RegisteredSkinKeys = []; /// @@ -30,29 +27,47 @@ public class AddressablesLoader /// /// The location, remote or otherwise, of the addressables. /// The suffix of the provider for an addressables package. - public static void RegisterToLoad(string location, string providerSuffix = "") + public static void RegisterCatalog(string location, string providerSuffix = "") { CatalogLocations.Add((location, providerSuffix)); } + /// + /// Registers a specific addressables key as only containing 's to load. + /// + /// The key/label/group for a List . public static void RegisterHats(string addressables_key) { RegisteredHatKeys.Add(addressables_key); } + /// + /// Registers a specific addressables key as only containing 's to load. + /// + /// The key/label/group for a List . public static void RegisterSkins(string addressables_key) { RegisteredSkinKeys.Add(addressables_key); } - public static void RegisterNameplates(string addressables_key) + /// + /// Registers a specific addressables key as only containing 's to load. + /// + /// The key/label/group for a List . + /// /// The title of the group for visors. + public static void RegisterNameplates(string addressables_key, string group_title) { - RegisteredNameplateKeys.Add(addressables_key); + RegisteredNameplateKeys.Add((addressables_key, group_title)); } - public static void RegisterVisors(string addressables_key) + /// + /// Registers a specific addressables key as only containing 's to load. + /// + /// The key/label/group for a List . + /// The title of the group for visors. + public static void RegisterVisors(string addressables_key, string group_title) { - RegisteredVisorKeys.Add(addressables_key); + RegisteredVisorKeys.Add((addressables_key, group_title)); } internal static void LoadAll() @@ -89,8 +104,8 @@ public class AddressablesLoader var hatBehaviours = DiscoverData(RegisteredHatKeys); var skinBehaviours = DiscoverData(RegisteredSkinKeys); - var namePlateBehaviours = DiscoverData(RegisteredNameplateKeys); - var visorBehaviours = DiscoverData(RegisteredVisorKeys); + var namePlateBehaviours = DiscoverAndReportData(RegisteredNameplateKeys); + var visorBehaviours = DiscoverAndReportData(RegisteredVisorKeys); var hatData = new List(); hatData.AddRange(DestroyableSingleton.Instance.allHats); @@ -99,15 +114,18 @@ public class AddressablesLoader var skinData = new List(); skinData.AddRange(DestroyableSingleton.Instance.allSkins); + skinData.ForEach(x => x.StoreName = "Vanilla"); DestroyableSingleton.Instance.allSkins = PrepareArray(skinData, skinBehaviours); var visorData = new List(); visorData.AddRange(DestroyableSingleton.Instance.allVisors); - DestroyableSingleton.Instance.allVisors = PrepareArray(visorData, visorBehaviours); + VisorsTabPatches.AddRange(visorBehaviours); + DestroyableSingleton.Instance.allVisors = PrepareArray(visorData, visorBehaviours.Select(x=>x.Data).ToList()); var namePlateData = new List(); namePlateData.AddRange(DestroyableSingleton.Instance.allNamePlates); - DestroyableSingleton.Instance.allNamePlates = PrepareArray(namePlateData, namePlateBehaviours); + NameplatesTabPatches.AddRange(namePlateBehaviours); + DestroyableSingleton.Instance.allNamePlates = PrepareArray(namePlateData, namePlateBehaviours.Select(x => x.Data).ToList()); } private static T[] PrepareArray(List data, List behaviours) where T : CosmeticData @@ -141,4 +159,25 @@ public class AddressablesLoader } return behaviours; } + + private static List<(string Category, T Data)> DiscoverAndReportData(List<(string Tag, string Category)> tags) + { + var behaviours = new List<(string, T)>(); + + foreach (var tag in tags) + { + try + { + var all_locations = Addressables.LoadResourceLocationsAsync(tag.Tag).WaitForCompletion(); + var assets = Addressables.LoadAssetsAsync(all_locations, null, false).WaitForCompletion(); + var array = new Il2CppSystem.Collections.Generic.List(assets.Pointer); + behaviours.AddRange(array.ToArray().Select(x => (tag.Category, x))); + } + catch + { + Logger.Error($"Failed to find tag {tag}"); + } + } + return behaviours; + } } diff --git a/MiraAPI/Utilities/ControllableComparer.cs b/MiraAPI/Utilities/ControllableComparer.cs index 3e6c762..8c7806c 100644 --- a/MiraAPI/Utilities/ControllableComparer.cs +++ b/MiraAPI/Utilities/ControllableComparer.cs @@ -1,8 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace MiraAPI.Utilities; @@ -18,7 +16,8 @@ internal sealed class ControllableComparer : IComparer where T : IComparab _fallbackComparer = fallbackComparer; } - public int Compare(T x, T y) + /// + public int Compare(T? x, T? y) { if ((_forcedToBottom.Contains(x) && _forcedToBottom.Contains(y)) || (_forcedToTop.Contains(x) && _forcedToTop.Contains(y))) return _fallbackComparer.Compare(x, y);