From 50d7111c49c76599ddd7df481e25bfe0f9ce71e6 Mon Sep 17 00:00:00 2001 From: Atony <75191600+AtonyGit@users.noreply.github.com> Date: Mon, 27 Apr 2026 10:08:52 -0500 Subject: [PATCH] Warn other plugins that try to add cosmetics --- MiraAPI/Patches/Menu/HatsTabPatches.cs | 163 ----------------- MiraAPI/Patches/Menu/InventoryUtility.cs | 54 ------ .../Patches/Menu/MainMenuManagerPatches.cs | 1 - MiraAPI/Patches/Menu/NameplatesTabPatches.cs | 142 --------------- MiraAPI/Patches/Menu/SkinsTabPatches.cs | 139 -------------- MiraAPI/Patches/Menu/VisorsTabPatches.cs | 139 -------------- .../Utilities/Assets/AddressablesLoader.cs | 170 +----------------- 7 files changed, 6 insertions(+), 802 deletions(-) delete mode 100644 MiraAPI/Patches/Menu/HatsTabPatches.cs delete mode 100644 MiraAPI/Patches/Menu/InventoryUtility.cs delete mode 100644 MiraAPI/Patches/Menu/NameplatesTabPatches.cs delete mode 100644 MiraAPI/Patches/Menu/SkinsTabPatches.cs delete mode 100644 MiraAPI/Patches/Menu/VisorsTabPatches.cs diff --git a/MiraAPI/Patches/Menu/HatsTabPatches.cs b/MiraAPI/Patches/Menu/HatsTabPatches.cs deleted file mode 100644 index 8cd2bfd..0000000 --- a/MiraAPI/Patches/Menu/HatsTabPatches.cs +++ /dev/null @@ -1,163 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Collections.Immutable; -using System.Linq; -using AmongUs.Data; -using HarmonyLib; -using MiraAPI.Utilities; -using MiraAPI.Utilities.Assets; -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; - -[HarmonyPatch(typeof(HatsTab))] -public static class HatsTabPatches -{ - private static SortedList> sortedHats = []; - private static int currentPage; - - private static void PreviousPage(HatsTab hatsTab) - { - currentPage--; - currentPage = currentPage < 0 ? sortedHats.Count - 1 : currentPage; - GenerateHats(hatsTab, currentPage); - } - - private static void NextPage(HatsTab hatsTab) - { - currentPage++; - currentPage = currentPage > sortedHats.Count - 1 ? 0 : currentPage; - GenerateHats(hatsTab, currentPage); - } - - [HarmonyPatch(nameof(HatsTab.OnEnable))] - [HarmonyPrefix] - public static bool OnEnablePrefix(HatsTab __instance) - { - __instance.currentHat = HatManager.Instance.GetHatById(DataManager.Player.Customization.Hat); - var allHats = HatManager.Instance.GetUnlockedHats().ToImmutableList(); - - if (sortedHats.Count == 0) - { - var comparer = new ControllableComparer(["vanilla"], [], StringComparer.InvariantCulture); - sortedHats = new SortedList>(comparer); - foreach (var hat in allHats) - { - if (!sortedHats.ContainsKey(hat.StoreName)) sortedHats[hat.StoreName] = []; - sortedHats[hat.StoreName].Add(hat); - } - } - - InventoryUtility.CreateNextBackButtons(__instance, PreviousPage, NextPage); - - GenerateHats(__instance, currentPage); - - return false; - } - - [HarmonyPatch(typeof(HatsTab), nameof(HatsTab.Update))] - [HarmonyPrefix] - public static void UpdatePrefix(HatsTab __instance) - { - if (sortedHats.Count == 0) return; - - if (Input.GetKeyDown(KeyCode.LeftControl) || Input.GetKeyDown(KeyCode.RightControl) || Input.GetKeyDown(KeyCode.LeftArrow)) - { - PreviousPage(__instance); - } - else if (Input.GetKeyDown(KeyCode.Tab) || Input.GetKeyDown(KeyCode.RightArrow)) - { - NextPage(__instance); - } - } - - private static IEnumerator? loadRoutine; - private static int hatIndex; - - private static void GenerateHats(HatsTab __instance, int page) - { - if (loadRoutine != null) Coroutines.Stop(loadRoutine); - - hatIndex = 0; - foreach (var instanceColorChip in __instance.ColorChips) instanceColorChip.gameObject.Destroy(); - __instance.ColorChips.Clear(); - __instance.scroller.Inner.GetComponentsInChildren().Do(x => x.gameObject.Destroy()); - - var groupNameText = __instance.GetComponentInChildren(false); - - var (groupName, hats) = sortedHats.ToArray()[page]; - 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} ({currentPage + 1}/{sortedHats.Count})"; - text.alignment = TextAlignmentOptions.Center; - text.fontSize = 5f; - text.fontSizeMax = 5f; - text.fontSizeMin = 0f; - var xLerp = __instance.XRange.Lerp(0.5f); - var yLerp = __instance.YStart - hatIndex / __instance.NumPerRow * __instance.YOffset; - text.transform.localPosition = new Vector3(xLerp, yLerp, -1f); - - hatIndex += 5; - loadRoutine = Coroutines.Start(CoGenerateChips(__instance, hats)); - } - - private static IEnumerator CoGenerateChips(HatsTab __instance, List hats) - { - __instance.scroller.ScrollToTop(); - var batchSize = 5; - for (var i = 0; i < hats.Count; i += batchSize) - { - var batch = hats.Skip(i).Take(batchSize).ToList(); - - foreach (var hat in batch.OrderBy(HatManager.Instance.allHats.IndexOf)) - { - var hatXposition = __instance.XRange.Lerp(hatIndex % __instance.NumPerRow / (__instance.NumPerRow - 1f)); - var hatYposition = __instance.YStart - hatIndex / __instance.NumPerRow * __instance.YOffset; - GenerateColorChip(__instance, new Vector2(hatXposition, hatYposition), hat); - hatIndex += 1; - yield return null; - } - - __instance.SetScrollerBounds(); - yield return new WaitForSeconds(0.01f); - } - __instance.currentHatIsEquipped = true; - loadRoutine = null; - } - - private static void GenerateColorChip(HatsTab __instance, Vector2 position, HatData hat) - { - var colorChip = Object.Instantiate(__instance.ColorTabPrefab, __instance.scroller.Inner); - colorChip.gameObject.name = hat.ProductId; - if (ActiveInputManager.currentControlType == ActiveInputManager.InputType.Keyboard) - { - colorChip.Button.OnClick.AddListener((Action)__instance.ClickEquip); - colorChip.Button.OnMouseOver.AddListener((Action)(() => __instance.SelectHat(hat))); - colorChip.Button.OnMouseOut.AddListener((Action)(() => __instance.SelectHat(HatManager.Instance.GetHatById(DataManager.Player.Customization.Hat)))); - } - else - { - colorChip.Button.OnClick.AddListener((Action)(() => __instance.SelectHat(hat))); - } - - colorChip.Inner.SetHat(hat, __instance.HasLocalPlayer() ? PlayerControl.LocalPlayer.Data.DefaultOutfit.ColorId : DataManager.Player.Customization.Color); - 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; - __instance.ColorChips.Add(colorChip); - } -} diff --git a/MiraAPI/Patches/Menu/InventoryUtility.cs b/MiraAPI/Patches/Menu/InventoryUtility.cs deleted file mode 100644 index 95004d0..0000000 --- a/MiraAPI/Patches/Menu/InventoryUtility.cs +++ /dev/null @@ -1,54 +0,0 @@ -using System; -using MiraAPI.Utilities.Assets; -using TMPro; -using UnityEngine; -using UnityEngine.Events; -using UnityEngine.UI; -using Object = UnityEngine.Object; - -namespace MiraAPI.Patches.Menu; - -public static class InventoryUtility -{ - public static void CreateNextBackButtons(T tab, Action previousPage, Action nextPage) where T : InventoryTab - { - var title = tab.transform.FindChild("Text"); - title.localPosition = new Vector3(.9123f, -.23f, -55); - title.GetComponent().alignment = TextAlignmentOptions.Center; - - tab.scroller.Hitbox.transform.localScale -= new Vector3(0, 0.1f, 0); - tab.scroller.Hitbox.transform.localPosition -= new Vector3(0, 0.1f, 0); - - var leftButtonElement = Object.Instantiate(PlayerCustomizationMenu.Instance.BackButton.gameObject, tab.transform); - var leftSpriteRenderer = leftButtonElement.GetComponent(); - var leftButton = leftButtonElement.GetComponent(); - - leftButtonElement.transform.localPosition = new Vector3(-1.1f, -0.2f, -55); - leftSpriteRenderer.sprite = MiraAssets.NextButton.LoadAsset(); - leftSpriteRenderer.flipX = true; - - leftButton.OnMouseOver = new UnityEvent(); - leftButton.OnMouseOver.AddListener((Action)(() => leftSpriteRenderer.sprite = MiraAssets.NextButtonActive.LoadAsset())); - leftButton.OnMouseOut = new UnityEvent(); - leftButton.OnMouseOut.AddListener((Action)(() => leftSpriteRenderer.sprite = MiraAssets.NextButton.LoadAsset())); - - leftButton.OnClick = new Button.ButtonClickedEvent(); - leftButton.OnClick.AddListener((Action)(() => previousPage(tab))); - - var rightButtonElement = Object.Instantiate(leftButtonElement, tab.transform); - var rightSpriteRenderer = rightButtonElement.GetComponent(); - var rightButton = rightButtonElement.GetComponent(); - - rightButtonElement.transform.localPosition = new Vector3(2.8f, -0.2f, -55); - rightSpriteRenderer.sprite = MiraAssets.NextButton.LoadAsset(); - rightSpriteRenderer.flipX = false; - - rightButton.OnMouseOver = new UnityEvent(); - rightButton.OnMouseOver.AddListener((Action)(() => rightSpriteRenderer.sprite = MiraAssets.NextButtonActive.LoadAsset())); - rightButton.OnMouseOut = new UnityEvent(); - rightButton.OnMouseOut.AddListener((Action)(() => rightSpriteRenderer.sprite = MiraAssets.NextButton.LoadAsset())); - - rightButton.OnClick = new Button.ButtonClickedEvent(); - rightButton.OnClick.AddListener((Action)(() => nextPage(tab))); - } -} diff --git a/MiraAPI/Patches/Menu/MainMenuManagerPatches.cs b/MiraAPI/Patches/Menu/MainMenuManagerPatches.cs index b2377fe..17a50c0 100644 --- a/MiraAPI/Patches/Menu/MainMenuManagerPatches.cs +++ b/MiraAPI/Patches/Menu/MainMenuManagerPatches.cs @@ -20,7 +20,6 @@ public static class MainMenuManagerPatches [HarmonyPostfix] public static void AwakePostfix() { - AddressablesLoader.LoadAll(); Coroutines.Start(SetFps()); } diff --git a/MiraAPI/Patches/Menu/NameplatesTabPatches.cs b/MiraAPI/Patches/Menu/NameplatesTabPatches.cs deleted file mode 100644 index 0b7acfe..0000000 --- a/MiraAPI/Patches/Menu/NameplatesTabPatches.cs +++ /dev/null @@ -1,142 +0,0 @@ -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)); - private static int currentPage; - 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); - } - } - - private static void PreviousPage(NameplatesTab tab) - { - currentPage--; - currentPage = currentPage < 0 ? SortedNameplates.Count - 1 : currentPage; - GenerateHats(tab, currentPage); - } - - private static void NextPage(NameplatesTab tab) - { - currentPage++; - currentPage = currentPage > SortedNameplates.Count - 1 ? 0 : currentPage; - GenerateHats(tab, currentPage); - } - - [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))); - - InventoryUtility.CreateNextBackButtons(__instance, PreviousPage, NextPage); - - GenerateHats(__instance, currentPage); - - return false; - } - - [HarmonyPatch(typeof(NameplatesTab), nameof(NameplatesTab.Update))] - [HarmonyPrefix] - - public static void UpdatePrefix(NameplatesTab __instance) - { - if (Input.GetKeyDown(KeyCode.LeftControl) || Input.GetKeyDown(KeyCode.RightControl) || Input.GetKeyDown(KeyCode.LeftArrow)) - { - PreviousPage(__instance); - } - else if (Input.GetKeyDown(KeyCode.Tab) || Input.GetKeyDown(KeyCode.RightArrow)) - { - NextPage(__instance); - } - } - - private static void GenerateHats(NameplatesTab __instance, int page) - { - 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; - - var (groupName, nameplates) = SortedNameplates.ToArray()[page]; - 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} ({currentPage + 1}/{SortedNameplates.Count})"; - text.alignment = TextAlignmentOptions.Center; - text.fontSize = 5f; - text.fontSizeMax = 5f; - 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 nameplates.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.SetScrollerBounds(); - __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; - - if (ActiveInputManager.currentControlType == ActiveInputManager.InputType.Keyboard) - { - 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)))); - } - else - { - colorChip.Button.OnClick.AddListener((Action)(() => __instance.SelectNameplate(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 deleted file mode 100644 index b5ea7d7..0000000 --- a/MiraAPI/Patches/Menu/SkinsTabPatches.cs +++ /dev/null @@ -1,139 +0,0 @@ -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 = []; - private static int currentPage; - - private static void PreviousPage(SkinsTab tab) - { - currentPage--; - currentPage = currentPage < 0 ? sortedSkins.Count - 1 : currentPage; - GenerateHats(tab, currentPage); - } - - private static void NextPage(SkinsTab tab) - { - currentPage++; - currentPage = currentPage > sortedSkins.Count - 1 ? 0 : currentPage; - GenerateHats(tab, currentPage); - } - - [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); - } - } - - InventoryUtility.CreateNextBackButtons(__instance, PreviousPage, NextPage); - - GenerateHats(__instance, currentPage); - - return false; - } - - [HarmonyPatch(typeof(SkinsTab), nameof(SkinsTab.Update))] - [HarmonyPrefix] - - public static void UpdatePrefix(SkinsTab __instance) - { - if (Input.GetKeyDown(KeyCode.LeftControl) || Input.GetKeyDown(KeyCode.RightControl) || Input.GetKeyDown(KeyCode.LeftArrow)) - { - PreviousPage(__instance); - } - else if (Input.GetKeyDown(KeyCode.Tab) || Input.GetKeyDown(KeyCode.RightArrow)) - { - NextPage(__instance); - } - } - - private static void GenerateHats(SkinsTab __instance, int page) - { - 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; - - var (groupName, skins) = sortedSkins.ToArray()[page]; - 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} ({currentPage + 1}/{sortedSkins.Count})"; - text.alignment = TextAlignmentOptions.Center; - text.fontSize = 5f; - text.fontSizeMax = 5f; - 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.SetScrollerBounds(); - __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; - if (ActiveInputManager.currentControlType == ActiveInputManager.InputType.Keyboard) - { - 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)))); - } - else - { - colorChip.Button.OnClick.AddListener((Action)(() => __instance.SelectSkin(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 deleted file mode 100644 index e801c1a..0000000 --- a/MiraAPI/Patches/Menu/VisorsTabPatches.cs +++ /dev/null @@ -1,139 +0,0 @@ -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)); - private static int currentPage; - 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); - } - } - - private static void PreviousPage(VisorsTab tab) - { - currentPage--; - currentPage = currentPage < 0 ? SortedVisors.Count - 1 : currentPage; - GenerateHats(tab, currentPage); - } - - private static void NextPage(VisorsTab tab) - { - currentPage++; - currentPage = currentPage > SortedVisors.Count - 1 ? 0 : currentPage; - GenerateHats(tab, currentPage); - } - - - [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))); - - InventoryUtility.CreateNextBackButtons(__instance, PreviousPage, NextPage); - - GenerateHats(__instance, currentPage); - - return false; - } - - [HarmonyPatch(typeof(VisorsTab), nameof(VisorsTab.Update))] - [HarmonyPrefix] - - public static void UpdatePrefix(VisorsTab __instance) - { - if (Input.GetKeyDown(KeyCode.LeftControl) || Input.GetKeyDown(KeyCode.RightControl) || Input.GetKeyDown(KeyCode.LeftArrow)) - { - PreviousPage(__instance); - } - else if (Input.GetKeyDown(KeyCode.Tab) || Input.GetKeyDown(KeyCode.RightArrow)) - { - NextPage(__instance); - } - } - - private static void GenerateHats(VisorsTab __instance, int page) - { - 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; - - var (groupName, visors) = SortedVisors.ToArray()[page]; - 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} ({currentPage + 1}/{SortedVisors.Count})"; - text.alignment = TextAlignmentOptions.Center; - text.fontSize = 5f; - text.fontSizeMax = 5f; - 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.SetScrollerBounds(); - __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; - - if (ActiveInputManager.currentControlType == ActiveInputManager.InputType.Keyboard) - { - 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)))); - } - else - { - colorChip.Button.OnClick.AddListener((Action)(() => __instance.SelectVisor(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 6491880..d83e0ec 100644 --- a/MiraAPI/Utilities/Assets/AddressablesLoader.cs +++ b/MiraAPI/Utilities/Assets/AddressablesLoader.cs @@ -10,20 +10,10 @@ using UnityEngine.ResourceManagement.AsyncOperations; namespace MiraAPI.Utilities.Assets; /// -/// The component for loading Addressables, and cosmetics. +/// The component for loading Addressables, and cosmetics. This is deprecated in favor of Corsac Cosmetics. /// public static class AddressablesLoader { - private static bool _isInitialized; - - private static readonly List<(string Location, string ProviderSuffix)> CatalogLocations = []; - private static readonly List LoadedLocations = []; - - private static readonly List RegisteredHatKeys = []; - private static readonly List<(string, string)> RegisteredVisorKeys = []; - private static readonly List<(string, string)> RegisteredNameplateKeys = []; - private static readonly List RegisteredSkinKeys = []; - /// /// Registers a specific addressables package to load asynchronously at the start of the game, when possible. /// @@ -31,13 +21,7 @@ public static class AddressablesLoader /// The suffix of the provider for an addressables package. public static void RegisterCatalog(string location, string providerSuffix = "") { - if (_isInitialized) - { - Error("AddressablesLoader has already been initialized, cannot register more catalogs."); - return; - } - - CatalogLocations.Add((location, providerSuffix)); + Error("Catalogs are no longer possible to load in MiraAPI! Please use Corsac Cosmetics instead."); } /// @@ -46,13 +30,7 @@ public static class AddressablesLoader /// The key/label/group for a List . public static void RegisterHats(string addressablesKey) { - if (_isInitialized) - { - Error("AddressablesLoader has already been initialized, cannot register more keys for hats."); - return; - } - - RegisteredHatKeys.Add(addressablesKey); + Error("Hats are no longer possible to load in MiraAPI! Please use Corsac Cosmetics instead."); } /// @@ -61,13 +39,7 @@ public static class AddressablesLoader /// The key/label/group for a List . public static void RegisterSkins(string addressablesKey) { - if (_isInitialized) - { - Error("AddressablesLoader has already been initialized, cannot register more keys for skins."); - return; - } - - RegisteredSkinKeys.Add(addressablesKey); + Error("Skins are no longer possible to load in MiraAPI! Please use Corsac Cosmetics instead."); } /// @@ -77,13 +49,7 @@ public static class AddressablesLoader /// /// The title of the group for visors. public static void RegisterNameplates(string addressablesKey, string groupTitle) { - if (_isInitialized) - { - Error("AddressablesLoader has already been initialized, cannot register more keys for nameplates."); - return; - } - - RegisteredNameplateKeys.Add((addressablesKey, groupTitle)); + Error("Nameplates are no longer possible to load in MiraAPI! Please use Corsac Cosmetics instead."); } /// @@ -93,130 +59,6 @@ public static class AddressablesLoader /// The title of the group for visors. public static void RegisterVisors(string addressablesKey, string groupTitle) { - if (_isInitialized) - { - Error("AddressablesLoader has already been initialized, cannot register more keys for visors."); - return; - } - - RegisteredVisorKeys.Add((addressablesKey, groupTitle)); - } - - internal static void LoadAll() - { - if (_isInitialized) - { - Error("AddressablesLoader has already been initialized."); - return; - } - - _isInitialized = true; - foreach (var (location, providerSuffix) in CatalogLocations) - { - Coroutines.Start(CoLoadAddressables(location, providerSuffix)); - } - - Coroutines.Start(LoadCosmetics()); - } - - internal static IEnumerator CoLoadAddressables(string location, string suffix = "") - { - while (!AmongUsClient.Instance) yield return null; - // Load the local/remote content catalog - var catalogOperation = Addressables.LoadContentCatalog(location, suffix); - yield return catalogOperation; - - // Check for errors - if (catalogOperation.Status != AsyncOperationStatus.Succeeded) - { - Error($"Failed to load catalog {location}."); - } - - Info($"Loaded addressables {location}."); - LoadedLocations.Add(location); - } - - [HideFromIl2Cpp] - internal static IEnumerator LoadCosmetics() - { - while (!AmongUsClient.Instance || CatalogLocations.Select(x=>x.Location).Any(x=>!LoadedLocations.Contains(x))) yield return null; - - var hatBehaviours = DiscoverData(RegisteredHatKeys); - var skinBehaviours = DiscoverData(RegisteredSkinKeys); - var namePlateBehaviours = DiscoverAndReportData(RegisteredNameplateKeys); - var visorBehaviours = DiscoverAndReportData(RegisteredVisorKeys); - - var hatData = new List(); - hatData.AddRange(DestroyableSingleton.Instance.allHats); - hatData.ForEach(x => x.StoreName = "Vanilla"); - DestroyableSingleton.Instance.allHats = PrepareArray(hatData, hatBehaviours); - - 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); - VisorsTabPatches.AddRange(visorBehaviours); - DestroyableSingleton.Instance.allVisors = PrepareArray(visorData, visorBehaviours.Select(x=>x.Data).ToList()); - - var namePlateData = new List(); - namePlateData.AddRange(DestroyableSingleton.Instance.allNamePlates); - 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 - { - var count = data.Count; - for (int i = 0; i < behaviours.Count; i++) - { - behaviours[i].displayOrder = count + i; - data.Add(behaviours[i]); - } - return data.ToArray(); - } - - private static List DiscoverData(List tags) - { - var behaviours = new List(); - - foreach (var tag in tags) - { - try - { - var allLocations = Addressables.LoadResourceLocationsAsync(tag).WaitForCompletion(); - var assets = Addressables.LoadAssetsAsync(allLocations, null, false).WaitForCompletion(); - var array = new Il2CppSystem.Collections.Generic.List(assets.Pointer); - behaviours.AddRange(array.ToArray()); - } - catch - { - Error($"Failed to find tag {tag}"); - } - } - 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 allLocations = Addressables.LoadResourceLocationsAsync(tag.Tag).WaitForCompletion(); - var assets = Addressables.LoadAssetsAsync(allLocations, null, false).WaitForCompletion(); - var array = new Il2CppSystem.Collections.Generic.List(assets.Pointer); - behaviours.AddRange(array.ToArray().Select(x => (tag.Category, x))); - } - catch - { - Error($"Failed to find tag {tag}"); - } - } - return behaviours; + Error("Visors are no longer possible to load in MiraAPI! Please use Corsac Cosmetics instead."); } }