From 6410a0dd426f2df72511f159cbbb1515e042cc18 Mon Sep 17 00:00:00 2001 From: Az <56699741+AlchlcDvl@users.noreply.github.com> Date: Thu, 8 Oct 2026 01:02:09 -0400 Subject: [PATCH] consolidate copy pasted addressables code --- .../Utilities/Assets/AddressablesLoader.cs | 66 ++++++++----------- 1 file changed, 28 insertions(+), 38 deletions(-) diff --git a/MiraAPI/Utilities/Assets/AddressablesLoader.cs b/MiraAPI/Utilities/Assets/AddressablesLoader.cs index 39626e9..ec02972 100644 --- a/MiraAPI/Utilities/Assets/AddressablesLoader.cs +++ b/MiraAPI/Utilities/Assets/AddressablesLoader.cs @@ -1,6 +1,7 @@ using System.Collections; using System.Collections.Generic; using System.Linq; +using System.Runtime.CompilerServices; using Il2CppInterop.Runtime.Attributes; using MiraAPI.Patches.Menu; using Reactor.Utilities; @@ -23,26 +24,36 @@ public static class AddressablesLoader private static readonly List RegisteredSkinKeys = []; private static bool _isInitialized; + private static bool _addressableHatsExist; + private static bool _addressableVisorsExist; + private static bool _addressableNameplatesExist; + private static bool _addressableSkinsExist; + private static bool _catalogsExist; /// /// Gets a value indicating whether hats have been loaded by the addressables system. /// - public static bool AddressableHatsExist { get; private set; } + public static bool AddressableHatsExist => _addressableHatsExist; /// /// Gets a value indicating whether visors have been loaded by the addressables system. /// - public static bool AddressableVisorsExist { get; private set; } + public static bool AddressableVisorsExist => _addressableVisorsExist; /// /// Gets a value indicating whether nameplates have been loaded by the addressables system. /// - public static bool AddressableNameplatesExist { get; private set; } + public static bool AddressableNameplatesExist => _addressableNameplatesExist; /// /// Gets a value indicating whether skins have been loaded by the addressables system. /// - public static bool AddressableSkinsExist { get; private set; } + public static bool AddressableSkinsExist => _addressableSkinsExist; + + /// + /// Gets a value indicating whether catalogs have been loaded by the addressables system. + /// + public static bool CatalogsExist => _catalogsExist; /// /// Registers a specific addressables package to load asynchronously at the start of the game, when possible. @@ -51,13 +62,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)); + RegisterCosmetic((location, providerSuffix), CatalogLocations, "catalog", ref _catalogsExist); } /// @@ -66,14 +71,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; - } - - AddressableHatsExist = true; - RegisteredHatKeys.Add(addressablesKey); + RegisterCosmetic(addressablesKey, RegisteredHatKeys, "hat", ref _addressableHatsExist); } /// @@ -82,14 +80,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; - } - - AddressableSkinsExist = true; - RegisteredSkinKeys.Add(addressablesKey); + RegisterCosmetic(addressablesKey, RegisteredSkinKeys, "skin", ref _addressableSkinsExist); } /// @@ -99,14 +90,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; - } - - AddressableNameplatesExist = true; - RegisteredNameplateKeys.Add((addressablesKey, groupTitle)); + RegisterCosmetic((addressablesKey, groupTitle), RegisteredNameplateKeys, "nameplate", ref _addressableNameplatesExist); } /// @@ -115,15 +99,21 @@ public static class AddressablesLoader /// The key/label/group for a List . /// The title of the group for visors. public static void RegisterVisors(string addressablesKey, string groupTitle) + { + RegisterCosmetic((addressablesKey, groupTitle), RegisteredVisorKeys, "visor", ref _addressableVisorsExist); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static void RegisterCosmetic(T value, List values, string type, ref bool flag) { if (_isInitialized) { - Error("AddressablesLoader has already been initialized, cannot register more keys for visors."); + Error($"AddressablesLoader has already been initialized, cannot register more keys for {type}s."); return; } - AddressableVisorsExist = true; - RegisteredVisorKeys.Add((addressablesKey, groupTitle)); + flag = true; + values.Add(value); } internal static void LoadAll()