mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-10-20 01:46:15 +00:00
Compare commits
19
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2a3c8feeab | ||
|
|
833585f15f | ||
|
|
66b4976619 | ||
|
|
9c0b874e34 | ||
|
|
ce0662f772 | ||
|
|
c928eae183 | ||
|
|
68afe58678 | ||
|
|
e3b2477cb8 | ||
|
|
2b568f933b | ||
|
|
a0701d582f | ||
|
|
c42782b157 | ||
|
|
f932c4f3ff | ||
|
|
2666aa171d | ||
|
|
9f99f6abb5 | ||
|
|
aa53af112b | ||
|
|
ff2f44fd64 | ||
|
|
d64972a574 | ||
|
|
bb45bab198 | ||
|
|
1eb13d0513 |
No files matched your search
@@ -1,10 +1,10 @@
|
|||||||
using MiraAPI.Example.Options.Roles;
|
using System.Collections;
|
||||||
|
using MiraAPI.Example.Options.Roles;
|
||||||
using MiraAPI.Example.Roles;
|
using MiraAPI.Example.Roles;
|
||||||
using MiraAPI.GameOptions;
|
using MiraAPI.GameOptions;
|
||||||
using MiraAPI.Hud;
|
using MiraAPI.Hud;
|
||||||
using MiraAPI.Utilities.Assets;
|
using MiraAPI.Utilities.Assets;
|
||||||
using Reactor.Utilities;
|
using Reactor.Utilities;
|
||||||
using System.Collections;
|
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace MiraAPI.Example.Buttons.Teleporter;
|
namespace MiraAPI.Example.Buttons.Teleporter;
|
||||||
@@ -40,7 +40,10 @@ public class TeleportButton : CustomActionButton
|
|||||||
{
|
{
|
||||||
base.FixedUpdate(playerControl);
|
base.FixedUpdate(playerControl);
|
||||||
|
|
||||||
if (!EffectActive) return;
|
if (!EffectActive)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (Input.GetKey(KeyCode.Mouse0))
|
if (Input.GetKey(KeyCode.Mouse0))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using MiraAPI.Cosmetics;
|
||||||
|
|
||||||
|
namespace MiraAPI.Example.Cosmetics;
|
||||||
|
public class ExampleCosmeticGroup : AbstractCosmeticsGroup
|
||||||
|
{
|
||||||
|
public override string GroupName => "Example";
|
||||||
|
|
||||||
|
[RegisterCustomCosmetic()]
|
||||||
|
public List<HatData> hats { get; set; } = new();
|
||||||
|
[RegisterCustomCosmetic()]
|
||||||
|
public List<NamePlateData> namePlates { get; set;} = new();
|
||||||
|
[RegisterCustomCosmetic()]
|
||||||
|
public List<SkinData> skins { get; set; } = new();
|
||||||
|
[RegisterCustomCosmetic()]
|
||||||
|
public List<VisorData> visors { get; set; } = new();
|
||||||
|
}
|
||||||
@@ -2,7 +2,11 @@
|
|||||||
using BepInEx.Configuration;
|
using BepInEx.Configuration;
|
||||||
using BepInEx.Unity.IL2CPP;
|
using BepInEx.Unity.IL2CPP;
|
||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
|
using MiraAPI.Cosmetics;
|
||||||
|
using MiraAPI.Example.Cosmetics;
|
||||||
using MiraAPI.PluginLoading;
|
using MiraAPI.PluginLoading;
|
||||||
|
using MiraAPI.Utilities.Assets;
|
||||||
|
using MiraAPI.Utilities.Assets.Addressable;
|
||||||
using Reactor;
|
using Reactor;
|
||||||
using Reactor.Networking;
|
using Reactor.Networking;
|
||||||
using Reactor.Networking.Attributes;
|
using Reactor.Networking.Attributes;
|
||||||
@@ -22,5 +26,12 @@ public partial class ExamplePlugin : BasePlugin, IMiraPlugin
|
|||||||
public override void Load()
|
public override void Load()
|
||||||
{
|
{
|
||||||
Harmony.PatchAll();
|
Harmony.PatchAll();
|
||||||
|
AddComponent<MiraDebugWindow>();
|
||||||
|
|
||||||
|
new Catalog("Output".ToLocalPath()).LoadCatalog();
|
||||||
|
CosmeticGroupSingleton<ExampleCosmeticGroup>.Instance.hats = new LoadableAddressableGroupAsset<HatData>(CatalogTools.GetResourceLocation("hatdata")).LoadAsset();
|
||||||
|
CosmeticGroupSingleton<ExampleCosmeticGroup>.Instance.namePlates = new LoadableAddressableGroupAsset<NamePlateData>(CatalogTools.GetResourceLocation("nameplatedata")).LoadAsset();
|
||||||
|
CosmeticGroupSingleton<ExampleCosmeticGroup>.Instance.skins = new LoadableAddressableGroupAsset<SkinData>(CatalogTools.GetResourceLocation("skindata")).LoadAsset();
|
||||||
|
CosmeticGroupSingleton<ExampleCosmeticGroup>.Instance.visors = new LoadableAddressableGroupAsset<VisorData>(CatalogTools.GetResourceLocation("visordata")).LoadAsset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
using MiraAPI.Example.Roles;
|
using System;
|
||||||
|
using MiraAPI.Example.Roles;
|
||||||
using MiraAPI.GameOptions;
|
using MiraAPI.GameOptions;
|
||||||
using MiraAPI.GameOptions.Attributes;
|
using MiraAPI.GameOptions.Attributes;
|
||||||
using System;
|
|
||||||
using MiraAPI.Utilities;
|
using MiraAPI.Utilities;
|
||||||
|
|
||||||
namespace MiraAPI.Example.Options.Roles;
|
namespace MiraAPI.Example.Options.Roles;
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using MiraAPI.Roles;
|
using MiraAPI.Roles;
|
||||||
using TMPro;
|
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace MiraAPI.Example.Roles;
|
namespace MiraAPI.Example.Roles;
|
||||||
@@ -22,8 +21,8 @@ public class ChameloenRole : CrewmateRole, ICustomRole
|
|||||||
{
|
{
|
||||||
if (playerControl.MyPhysics.Velocity.magnitude > 0)
|
if (playerControl.MyPhysics.Velocity.magnitude > 0)
|
||||||
{
|
{
|
||||||
SpriteRenderer rend = playerControl.cosmetics.currentBodySprite.BodySprite;
|
var rend = playerControl.cosmetics.currentBodySprite.BodySprite;
|
||||||
TextMeshPro tmp = playerControl.cosmetics.nameText;
|
var tmp = playerControl.cosmetics.nameText;
|
||||||
tmp.color = Color.Lerp(tmp.color, new Color(tmp.color.r, tmp.color.g, tmp.color.b, 1), Time.deltaTime * 4f);
|
tmp.color = Color.Lerp(tmp.color, new Color(tmp.color.r, tmp.color.g, tmp.color.b, 1), Time.deltaTime * 4f);
|
||||||
rend.color = Color.Lerp(rend.color, new Color(1, 1, 1, 1), Time.deltaTime * 4f);
|
rend.color = Color.Lerp(rend.color, new Color(1, 1, 1, 1), Time.deltaTime * 4f);
|
||||||
|
|
||||||
@@ -34,8 +33,8 @@ public class ChameloenRole : CrewmateRole, ICustomRole
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SpriteRenderer rend = playerControl.cosmetics.currentBodySprite.BodySprite;
|
var rend = playerControl.cosmetics.currentBodySprite.BodySprite;
|
||||||
TextMeshPro tmp = playerControl.cosmetics.nameText;
|
var tmp = playerControl.cosmetics.nameText;
|
||||||
tmp.color = Color.Lerp(tmp.color, new Color(tmp.color.r, tmp.color.g, tmp.color.b, playerControl.AmOwner ? 0.3f : 0), Time.deltaTime * 4f);
|
tmp.color = Color.Lerp(tmp.color, new Color(tmp.color.r, tmp.color.g, tmp.color.b, playerControl.AmOwner ? 0.3f : 0), Time.deltaTime * 4f);
|
||||||
rend.color = Color.Lerp(rend.color, new Color(1, 1, 1, playerControl.AmOwner ? 0.3f : 0), Time.deltaTime * 4f);
|
rend.color = Color.Lerp(rend.color, new Color(1, 1, 1, playerControl.AmOwner ? 0.3f : 0), Time.deltaTime * 4f);
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace MiraAPI.Cosmetics;
|
||||||
|
public abstract class AbstractCosmeticsGroup
|
||||||
|
{
|
||||||
|
public List<HatData> Hats { get; } = [];
|
||||||
|
public List<SkinData> Skins { get; } = [];
|
||||||
|
public List<VisorData> Visors { get; } = [];
|
||||||
|
public List<NamePlateData> Nameplates { get; } = [];
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the name of the group. Visible in options menu.
|
||||||
|
/// </summary>
|
||||||
|
public abstract string GroupName { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a function that determines whether the group should be visible or not.
|
||||||
|
/// </summary>
|
||||||
|
public virtual Func<bool> GroupVisible => () => true;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the sorting mode of individual hats within this group.
|
||||||
|
/// </summary>
|
||||||
|
public virtual SortingMode SortingMode => SortingMode.AlphabeticName;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the priority of a group for sorting groups.
|
||||||
|
/// </summary>
|
||||||
|
public virtual int SortingPriority { get; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum SortingMode
|
||||||
|
{
|
||||||
|
Priority,
|
||||||
|
AlphabeticProductId,
|
||||||
|
AlphabeticStoreName,
|
||||||
|
AlphabeticName,
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace MiraAPI.Cosmetics;
|
||||||
|
internal sealed class AbstractCosmeticsGroupComparer : Comparer<AbstractCosmeticsGroup>
|
||||||
|
{
|
||||||
|
public override int Compare(AbstractCosmeticsGroup? x, AbstractCosmeticsGroup? y)
|
||||||
|
{
|
||||||
|
switch (x)
|
||||||
|
{
|
||||||
|
case not null when y is null:
|
||||||
|
return 1;
|
||||||
|
case null when y is null:
|
||||||
|
return 0;
|
||||||
|
case null:
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
var p = x.SortingPriority - y.SortingPriority;
|
||||||
|
return p == 0 ? StringComparer.InvariantCultureIgnoreCase.Compare(x.GroupName, y.GroupName) : p;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace MiraAPI.Cosmetics;
|
||||||
|
internal sealed class CosmeticComparer(AbstractCosmeticsGroup group) : Comparer<CosmeticData>
|
||||||
|
{
|
||||||
|
internal static readonly string[] NoCosmetics = ["hat_NoHat", "skin_None", "nameplate_NoPlate", "visor_EmptyVisor"];
|
||||||
|
public override int Compare(CosmeticData? x, CosmeticData? y)
|
||||||
|
{
|
||||||
|
if (NoCosmetics.Contains(x?.ProdId))
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (NoCosmetics.Contains(y?.ProdId))
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return group.SortingMode switch
|
||||||
|
{
|
||||||
|
SortingMode.AlphabeticProductId => StringComparer.InvariantCultureIgnoreCase.Compare(x?.ProductId, y?.ProductId),
|
||||||
|
SortingMode.Priority => CustomCosmeticManager.CosmeticToPriority[x!] - CustomCosmeticManager.CosmeticToPriority[y!],
|
||||||
|
SortingMode.AlphabeticStoreName => x switch
|
||||||
|
{
|
||||||
|
HatData h1 when y is HatData h2 => StringComparer.InvariantCultureIgnoreCase.Compare(
|
||||||
|
h1.StoreName,
|
||||||
|
h2.StoreName),
|
||||||
|
SkinData s1 when y is SkinData s2 => StringComparer.InvariantCultureIgnoreCase.Compare(
|
||||||
|
s1.StoreName,
|
||||||
|
s2.StoreName),
|
||||||
|
_ => StringComparer.InvariantCultureIgnoreCase.Compare(x?.GetItemName(), y?.GetItemName()),
|
||||||
|
},
|
||||||
|
_ => StringComparer.InvariantCultureIgnoreCase.Compare(x?.GetItemName(), y?.GetItemName()),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace MiraAPI.Cosmetics;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Used to get access to a CosmeticGroup.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">The type.</typeparam>
|
||||||
|
public static class CosmeticGroupSingleton<T> where T : AbstractCosmeticsGroup
|
||||||
|
{
|
||||||
|
private static T? _instance;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets instance of the cosmetic group.
|
||||||
|
/// </summary>
|
||||||
|
#pragma warning disable CA1000
|
||||||
|
public static T Instance => _instance ??= CustomCosmeticManager.Groups.OfType<T>().Single();
|
||||||
|
#pragma warning restore CA1000
|
||||||
|
}
|
||||||
@@ -0,0 +1,127 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
using HarmonyLib;
|
||||||
|
using MiraAPI.PluginLoading;
|
||||||
|
using MonoMod.Utils;
|
||||||
|
using Reactor.Utilities;
|
||||||
|
|
||||||
|
namespace MiraAPI.Cosmetics;
|
||||||
|
public static class CustomCosmeticManager
|
||||||
|
{
|
||||||
|
private static readonly Dictionary<PropertyInfo, RegisterCustomCosmeticAttribute> OptionAttributes = [];
|
||||||
|
private static readonly Dictionary<Type, AbstractCosmeticsGroup> TypeToGroup = [];
|
||||||
|
internal static readonly Dictionary<CosmeticData, int> CosmeticToPriority = [];
|
||||||
|
internal static readonly Dictionary<CosmeticData, AbstractCosmeticsGroup> CosmeticToGroup = [];
|
||||||
|
|
||||||
|
internal static readonly List<AbstractCosmeticsGroup> Groups = [];
|
||||||
|
|
||||||
|
internal static void RegisterVanilla()
|
||||||
|
{
|
||||||
|
if (Activator.CreateInstance(typeof(VanillaCosmeticsGroup)) is not AbstractCosmeticsGroup group)
|
||||||
|
{
|
||||||
|
Logger<MiraApiPlugin>.Error($"Failed to create group from Vanilla");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (TypeToGroup.ContainsKey(typeof(VanillaCosmeticsGroup)))
|
||||||
|
{
|
||||||
|
Logger<MiraApiPlugin>.Error($"Vanilla group already exists.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Groups.Add(group);
|
||||||
|
TypeToGroup.Add(typeof(VanillaCosmeticsGroup), group);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static bool RegisterGroup(Type type, MiraPluginInfo pluginInfo)
|
||||||
|
{
|
||||||
|
if (Activator.CreateInstance(type) is not AbstractCosmeticsGroup group)
|
||||||
|
{
|
||||||
|
Logger<MiraApiPlugin>.Error($"Failed to create group from {type.Name}");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (TypeToGroup.ContainsKey(type))
|
||||||
|
{
|
||||||
|
Logger<MiraApiPlugin>.Error($"Group {type.Name} already exists.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Groups.Add(group);
|
||||||
|
TypeToGroup.Add(type, group);
|
||||||
|
pluginInfo.CosmeticGroups.Add(group);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static void RegisterAttributeOption(Type type, RegisterCustomCosmeticAttribute attribute, PropertyInfo property, MiraPluginInfo pluginInfo)
|
||||||
|
{
|
||||||
|
if (OptionAttributes.ContainsKey(property))
|
||||||
|
{
|
||||||
|
Logger<MiraApiPlugin>.Error($"Property {property.Name} already has an attribute registered.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!TypeToGroup.TryGetValue(type, out var group))
|
||||||
|
{
|
||||||
|
Logger<MiraApiPlugin>.Error($"Failed to get group for {type.Name}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
OptionAttributes.Add(property, attribute);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static void LoadCosmetic(PropertyInfo property, RegisterCustomCosmeticAttribute attribute)
|
||||||
|
{
|
||||||
|
if (!TypeToGroup.TryGetValue(property.DeclaringType, out var group))
|
||||||
|
{
|
||||||
|
Logger<MiraApiPlugin>.Error($"Failed to get group for {property.DeclaringType.Name}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property.PropertyType.IsAssignableTo(typeof(IEnumerable<HatData>)))
|
||||||
|
{
|
||||||
|
group.Hats.AddRange((IEnumerable<HatData>)property.GetValue(group));
|
||||||
|
}
|
||||||
|
else if (property.PropertyType.IsAssignableTo(typeof(IEnumerable<SkinData>)))
|
||||||
|
{
|
||||||
|
group.Skins.AddRange((IEnumerable<SkinData>)property.GetValue(group));
|
||||||
|
}
|
||||||
|
else if (property.PropertyType.IsAssignableTo(typeof(IEnumerable<VisorData>)))
|
||||||
|
{
|
||||||
|
group.Visors.AddRange((IEnumerable<VisorData>)property.GetValue(group));
|
||||||
|
}
|
||||||
|
else if (property.PropertyType.IsAssignableTo(typeof(IEnumerable<NamePlateData>)))
|
||||||
|
{
|
||||||
|
group.Nameplates.AddRange((IEnumerable<NamePlateData>)property.GetValue(group));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Logger<MiraApiPlugin>.Error($"Failed to get enumerable for {property.Name}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
CosmeticToPriority.AddRange(((IEnumerable<CosmeticData>)property.GetValue(group)).ToDictionary(y => y, x => attribute.Priority));
|
||||||
|
CosmeticToGroup.AddRange(((IEnumerable<CosmeticData>)property.GetValue(group)).ToDictionary(y => y, x => group));
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static bool Registered { get; set; }
|
||||||
|
internal static void LoadAll()
|
||||||
|
{
|
||||||
|
CosmeticGroupSingleton<VanillaCosmeticsGroup>.Instance.runtimeRegister();
|
||||||
|
if (Registered || !CosmeticGroupSingleton<VanillaCosmeticsGroup>.Instance.registered)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Registered = true;
|
||||||
|
CosmeticToPriority.AddRange(CosmeticGroupSingleton<VanillaCosmeticsGroup>.Instance.Cosmetics.ToDictionary(y => y, x => 0));
|
||||||
|
CosmeticToGroup.AddRange(CosmeticGroupSingleton<VanillaCosmeticsGroup>.Instance.Cosmetics.ToDictionary(y => y, x => CosmeticGroupSingleton<VanillaCosmeticsGroup>.Instance));
|
||||||
|
OptionAttributes.Do(x => LoadCosmetic(x.Key, x.Value));
|
||||||
|
DestroyableSingleton<HatManager>.Instance.allHats = CosmeticToGroup.Keys.OfType<HatData>().ToArray();
|
||||||
|
DestroyableSingleton<HatManager>.Instance.allVisors = CosmeticToGroup.Keys.OfType<VisorData>().ToArray();
|
||||||
|
DestroyableSingleton<HatManager>.Instance.allSkins = CosmeticToGroup.Keys.OfType<SkinData>().ToArray();
|
||||||
|
DestroyableSingleton<HatManager>.Instance.allNamePlates = CosmeticToGroup.Keys.OfType<NamePlateData>().ToArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace MiraAPI.Cosmetics;
|
||||||
|
|
||||||
|
[AttributeUsage(AttributeTargets.Property)]
|
||||||
|
public class RegisterCustomCosmeticAttribute(int priority = 0) : Attribute
|
||||||
|
{
|
||||||
|
public int Priority { get; } = priority;
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace MiraAPI.Cosmetics;
|
||||||
|
public class VanillaCosmeticsGroup : AbstractCosmeticsGroup
|
||||||
|
{
|
||||||
|
public override string GroupName => "Vanilla";
|
||||||
|
internal static HatData[] VanillaHats => DestroyableSingleton<HatManager>.Instance.allHats;
|
||||||
|
internal static VisorData[] VanillaVisors => DestroyableSingleton<HatManager>.Instance.allVisors;
|
||||||
|
internal static SkinData[] VanillaSkins => DestroyableSingleton<HatManager>.Instance.allSkins;
|
||||||
|
internal static NamePlateData[] VanillaNameplates => DestroyableSingleton<HatManager>.Instance.allNamePlates;
|
||||||
|
|
||||||
|
internal List<CosmeticData> Cosmetics { get; } = [];
|
||||||
|
|
||||||
|
internal bool registered { get; set; }
|
||||||
|
internal bool runtimeRegister()
|
||||||
|
{
|
||||||
|
if (registered)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!DestroyableSingleton<HatManager>.InstanceExists || VanillaHats.Length == 0
|
||||||
|
|| VanillaVisors.Length == 0 || VanillaSkins.Length == 0
|
||||||
|
|| VanillaNameplates.Length == 0)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
registered = true;
|
||||||
|
Hats.AddRange(VanillaHats);
|
||||||
|
Visors.AddRange(VanillaVisors);
|
||||||
|
Skins.AddRange(VanillaSkins);
|
||||||
|
Nameplates.AddRange(VanillaNameplates);
|
||||||
|
Cosmetics.AddRange(Hats);
|
||||||
|
Cosmetics.AddRange(Visors);
|
||||||
|
Cosmetics.AddRange(Skins);
|
||||||
|
Cosmetics.AddRange(Nameplates);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
using Reactor.Utilities;
|
using System;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using Reactor.Utilities;
|
||||||
|
|
||||||
namespace MiraAPI.GameModes;
|
namespace MiraAPI.GameModes;
|
||||||
|
|
||||||
@@ -21,7 +21,7 @@ public static class CustomGameModeManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Current gamemode.
|
/// Gets current gamemode.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static CustomGameMode? ActiveMode { get; internal set; } = new DefaultMode();
|
public static CustomGameMode? ActiveMode { get; internal set; } = new DefaultMode();
|
||||||
|
|
||||||
@@ -29,7 +29,7 @@ public static class CustomGameModeManager
|
|||||||
/// Set current gamemode.
|
/// Set current gamemode.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="id">gamemode ID.</param>
|
/// <param name="id">gamemode ID.</param>
|
||||||
public static void SetGameMode(int id)
|
internal static void SetGameMode(int id)
|
||||||
{
|
{
|
||||||
if (GameModes.TryGetValue(id, out var gameMode))
|
if (GameModes.TryGetValue(id, out var gameMode))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
using MiraAPI.GameOptions.OptionTypes;
|
using System;
|
||||||
using System;
|
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using MiraAPI.GameOptions.OptionTypes;
|
||||||
|
|
||||||
namespace MiraAPI.GameOptions.Attributes;
|
namespace MiraAPI.GameOptions.Attributes;
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using MiraAPI.GameOptions.OptionTypes;
|
using System;
|
||||||
using MiraAPI.Utilities;
|
|
||||||
using System;
|
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using MiraAPI.GameOptions.OptionTypes;
|
||||||
|
using MiraAPI.Utilities;
|
||||||
|
|
||||||
namespace MiraAPI.GameOptions.Attributes;
|
namespace MiraAPI.GameOptions.Attributes;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
using MiraAPI.GameOptions.OptionTypes;
|
using System;
|
||||||
using System;
|
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using MiraAPI.GameOptions.OptionTypes;
|
||||||
|
|
||||||
namespace MiraAPI.GameOptions.Attributes;
|
namespace MiraAPI.GameOptions.Attributes;
|
||||||
|
|
||||||
|
|||||||
@@ -21,4 +21,5 @@ public interface IModdedOption
|
|||||||
float GetFloatData();
|
float GetFloatData();
|
||||||
NetData GetNetData();
|
NetData GetNetData();
|
||||||
void HandleNetData(byte[] data);
|
void HandleNetData(byte[] data);
|
||||||
|
void ResetToConfig();
|
||||||
}
|
}
|
||||||
@@ -142,7 +142,6 @@ public static class ModdedOptionsManager
|
|||||||
{
|
{
|
||||||
// necessary to disable then re-enable this setting
|
// necessary to disable then re-enable this setting
|
||||||
// we dont know how other plugins handle their configs
|
// we dont know how other plugins handle their configs
|
||||||
// this way, all the options are saved at once, instead of one by one
|
|
||||||
var oldConfigSetting = new Dictionary<MiraPluginInfo, bool>();
|
var oldConfigSetting = new Dictionary<MiraPluginInfo, bool>();
|
||||||
foreach (var plugin in MiraPluginManager.Instance.RegisteredPlugins())
|
foreach (var plugin in MiraPluginManager.Instance.RegisteredPlugins())
|
||||||
{
|
{
|
||||||
@@ -162,7 +161,6 @@ public static class ModdedOptionsManager
|
|||||||
|
|
||||||
foreach (var plugin in MiraPluginManager.Instance.RegisteredPlugins())
|
foreach (var plugin in MiraPluginManager.Instance.RegisteredPlugins())
|
||||||
{
|
{
|
||||||
plugin.PluginConfig.Save();
|
|
||||||
plugin.PluginConfig.SaveOnConfigSet = oldConfigSetting[plugin];
|
plugin.PluginConfig.SaveOnConfigSet = oldConfigSetting[plugin];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -86,7 +86,10 @@ public class ModdedEnumOption : ModdedOption<int>
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override void OnValueChanged(int newValue)
|
protected override void OnValueChanged(int newValue)
|
||||||
{
|
{
|
||||||
HudManager.Instance.Notifier.AddSettingsChangeMessage(StringName, Data?.GetValueString(newValue), false);
|
if (HudManager.InstanceExists)
|
||||||
|
{
|
||||||
|
HudManager.Instance.Notifier.AddSettingsChangeMessage(StringName, Data.GetValueString(newValue), false);
|
||||||
|
}
|
||||||
if (!OptionBehaviour)
|
if (!OptionBehaviour)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using AmongUs.GameOptions;
|
using System;
|
||||||
|
using AmongUs.GameOptions;
|
||||||
using MiraAPI.Networking;
|
using MiraAPI.Networking;
|
||||||
using MiraAPI.Utilities;
|
using MiraAPI.Utilities;
|
||||||
using System;
|
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using Object = UnityEngine.Object;
|
using Object = UnityEngine.Object;
|
||||||
|
|
||||||
@@ -134,10 +134,13 @@ public class ModdedNumberOption : ModdedOption<float>
|
|||||||
protected override void OnValueChanged(float newValue)
|
protected override void OnValueChanged(float newValue)
|
||||||
{
|
{
|
||||||
Value = Mathf.Clamp(newValue, Min, Max);
|
Value = Mathf.Clamp(newValue, Min, Max);
|
||||||
HudManager.Instance.Notifier.AddSettingsChangeMessage(
|
if (HudManager.InstanceExists)
|
||||||
StringName,
|
{
|
||||||
Data?.GetValueString(Value),
|
HudManager.Instance.Notifier.AddSettingsChangeMessage(
|
||||||
false);
|
StringName,
|
||||||
|
Data.GetValueString(Value),
|
||||||
|
false);
|
||||||
|
}
|
||||||
|
|
||||||
if (OptionBehaviour is NumberOption opt)
|
if (OptionBehaviour is NumberOption opt)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
using BepInEx.Configuration;
|
using System;
|
||||||
|
using BepInEx.Configuration;
|
||||||
using MiraAPI.Networking;
|
using MiraAPI.Networking;
|
||||||
using MiraAPI.PluginLoading;
|
using MiraAPI.PluginLoading;
|
||||||
using MiraAPI.Roles;
|
using MiraAPI.Roles;
|
||||||
using Reactor.Localization.Utilities;
|
using Reactor.Localization.Utilities;
|
||||||
using Reactor.Networking.Rpc;
|
using Reactor.Networking.Rpc;
|
||||||
using System;
|
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace MiraAPI.GameOptions.OptionTypes;
|
namespace MiraAPI.GameOptions.OptionTypes;
|
||||||
@@ -45,7 +45,11 @@ public abstract class ModdedOption<T> : IModdedOption
|
|||||||
get => _parentMod;
|
get => _parentMod;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (_parentMod != null || value == null) return;
|
if (_parentMod != null || value == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
_parentMod = value;
|
_parentMod = value;
|
||||||
var entry = _parentMod.GetConfigFile().Bind(ConfigDefinition, DefaultValue);
|
var entry = _parentMod.GetConfigFile().Bind(ConfigDefinition, DefaultValue);
|
||||||
Value = entry.Value;
|
Value = entry.Value;
|
||||||
@@ -85,17 +89,7 @@ public abstract class ModdedOption<T> : IModdedOption
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the config definition of the option.
|
/// Gets or sets the config definition of the option.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ConfigDefinition? ConfigDefinition
|
public ConfigDefinition? ConfigDefinition { get; set; }
|
||||||
{
|
|
||||||
get => _configDefinition;
|
|
||||||
set
|
|
||||||
{
|
|
||||||
if (_configDefinition is not null) return;
|
|
||||||
_configDefinition = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private ConfigDefinition? _configDefinition;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="ModdedOption{T}"/> class.
|
/// Initializes a new instance of the <see cref="ModdedOption{T}"/> class.
|
||||||
@@ -168,6 +162,14 @@ public abstract class ModdedOption<T> : IModdedOption
|
|||||||
/// <param name="data">The NetData's byte array.</param>
|
/// <param name="data">The NetData's byte array.</param>
|
||||||
public abstract void HandleNetData(byte[] data);
|
public abstract void HandleNetData(byte[] data);
|
||||||
|
|
||||||
|
public void ResetToConfig()
|
||||||
|
{
|
||||||
|
if (ParentMod?.GetConfigFile().TryGetEntry<T>(ConfigDefinition, out var entry) == true)
|
||||||
|
{
|
||||||
|
SetValue(entry.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Handles the value changed event.
|
/// Handles the value changed event.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
using MiraAPI.Networking;
|
using System;
|
||||||
using System;
|
using MiraAPI.Networking;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using Object = UnityEngine.Object;
|
using Object = UnityEngine.Object;
|
||||||
|
|
||||||
@@ -69,7 +69,10 @@ public class ModdedToggleOption : ModdedOption<bool>
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override void OnValueChanged(bool newValue)
|
protected override void OnValueChanged(bool newValue)
|
||||||
{
|
{
|
||||||
HudManager.Instance.Notifier.AddSettingsChangeMessage(StringName, newValue ? "On" : "Off", false);
|
if (HudManager.InstanceExists)
|
||||||
|
{
|
||||||
|
HudManager.Instance.Notifier.AddSettingsChangeMessage(StringName, newValue ? "On" : "Off", false);
|
||||||
|
}
|
||||||
if (!OptionBehaviour)
|
if (!OptionBehaviour)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -10,11 +10,10 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="..\README.md" Pack="true" PackagePath="\" />
|
<None Include="..\README.md" Pack="true" PackagePath="\" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<EmbeddedResource Include="Resources\**\*.*" />
|
<EmbeddedResource Include="Resources\**\*.*" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<Import Project="../AmongUs.props" />
|
|
||||||
|
|
||||||
|
<Import Project="../AmongUs.props" />
|
||||||
</Project>
|
</Project>
|
||||||
@@ -1,14 +1,14 @@
|
|||||||
using System;
|
using Il2CppInterop.Runtime.Attributes;
|
||||||
|
using MiraAPI.Modifiers.Types;
|
||||||
|
using MiraAPI.Utilities;
|
||||||
|
using Reactor.Utilities;
|
||||||
|
using Reactor.Utilities.Attributes;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Immutable;
|
using System.Collections.Immutable;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Il2CppInterop.Runtime.Attributes;
|
|
||||||
using MiraAPI.Modifiers.Types;
|
|
||||||
using MiraAPI.Utilities;
|
|
||||||
using Reactor.Utilities;
|
|
||||||
using Reactor.Utilities.Attributes;
|
|
||||||
using TMPro;
|
using TMPro;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
@@ -107,6 +107,10 @@ public class ModifierComponent(IntPtr cppPtr) : MonoBehaviour(cppPtr)
|
|||||||
|
|
||||||
var baseModifiers = filteredModifiers as BaseModifier[] ?? filteredModifiers.ToArray();
|
var baseModifiers = filteredModifiers as BaseModifier[] ?? filteredModifiers.ToArray();
|
||||||
|
|
||||||
|
var inMeeting = MeetingHud.Instance != null;
|
||||||
|
|
||||||
|
_modifierText!.gameObject.SetActive(!inMeeting);
|
||||||
|
|
||||||
if (baseModifiers.Length != 0)
|
if (baseModifiers.Length != 0)
|
||||||
{
|
{
|
||||||
var stringBuild = new StringBuilder();
|
var stringBuild = new StringBuilder();
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using MiraAPI.Modifiers.Types;
|
using MiraAPI.Modifiers.Types;
|
||||||
using MiraAPI.Networking;
|
using MiraAPI.Networking;
|
||||||
using MiraAPI.PluginLoading;
|
|
||||||
using MiraAPI.Roles;
|
using MiraAPI.Roles;
|
||||||
using MiraAPI.Utilities;
|
using MiraAPI.Utilities;
|
||||||
using Reactor.Networking.Rpc;
|
using Reactor.Networking.Rpc;
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ public static class ScrollingColorsPatch
|
|||||||
private static BoxCollider2D? _collider;
|
private static BoxCollider2D? _collider;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Add scrolling to the colors tab
|
/// Add scrolling to the colors tab.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[HarmonyPostfix, HarmonyPatch("OnEnable")]
|
[HarmonyPostfix, HarmonyPatch("OnEnable")]
|
||||||
public static void AddScrollingToColorsTabPatch(PlayerTab __instance)
|
public static void AddScrollingToColorsTabPatch(PlayerTab __instance)
|
||||||
|
|||||||
@@ -0,0 +1,76 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using AmongUs.Data;
|
||||||
|
using HarmonyLib;
|
||||||
|
using MiraAPI.Cosmetics;
|
||||||
|
using MonoMod.Utils;
|
||||||
|
using Reactor.Utilities.Extensions;
|
||||||
|
using TMPro;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace MiraAPI.Patches.Cosmetics;
|
||||||
|
|
||||||
|
[HarmonyPatch(typeof(HatsTab), nameof(HatsTab.OnEnable))]
|
||||||
|
public static class HatsTabPatch
|
||||||
|
{
|
||||||
|
public static bool Prefix(HatsTab __instance)
|
||||||
|
{
|
||||||
|
var hatGroups = new SortedList<AbstractCosmeticsGroup, List<HatData>>(
|
||||||
|
new AbstractCosmeticsGroupComparer()
|
||||||
|
);
|
||||||
|
CustomCosmeticManager.Groups.Do(x => x.Hats.Sort(new CosmeticComparer(x)));
|
||||||
|
var c = CustomCosmeticManager.Groups.Select(x => new KeyValuePair<AbstractCosmeticsGroup, List<HatData>>(x, x.Hats)).
|
||||||
|
ToDictionary(x => x.Key, x => x.Value.Where(x=>x.Free || DataManager.Player.Purchases.GetPurchase(x.ProductId, x.BundleId)).ToList());
|
||||||
|
hatGroups.AddRange<AbstractCosmeticsGroup, List<HatData>>(c);
|
||||||
|
|
||||||
|
foreach (var colorchip in __instance.ColorChips) colorchip.gameObject.Destroy();
|
||||||
|
__instance.ColorChips.Clear();
|
||||||
|
var groupNameText = __instance.GetComponentInChildren<TextMeshPro>(false);
|
||||||
|
var hatIdx = 0;
|
||||||
|
|
||||||
|
__instance.currentHat = DestroyableSingleton<HatManager>.Instance.GetHatById(DataManager.Player.Customization.Hat);
|
||||||
|
|
||||||
|
foreach (var (group, hats) in hatGroups.Where(x=>x.Key.GroupVisible() && x.Key.Hats.Count > 0))
|
||||||
|
{
|
||||||
|
var text = UnityEngine.Object.Instantiate(groupNameText, __instance.scroller.Inner);
|
||||||
|
text.gameObject.transform.localScale = Vector3.one;
|
||||||
|
text.GetComponent<TextTranslatorTMP>().Destroy();
|
||||||
|
text.text = group.GroupName;
|
||||||
|
text.alignment = TextAlignmentOptions.Center;
|
||||||
|
text.fontSize = 3f;
|
||||||
|
text.fontSizeMax = 3f;
|
||||||
|
text.fontSizeMin = 0f;
|
||||||
|
|
||||||
|
hatIdx = (hatIdx + 4) / 5 * 5;
|
||||||
|
|
||||||
|
var xLerp = __instance.XRange.Lerp(0.5f);
|
||||||
|
var yLerp = __instance.YStart - (hatIdx / __instance.NumPerRow) * __instance.YOffset;
|
||||||
|
text.transform.localPosition = new Vector3(xLerp, yLerp, -1f);
|
||||||
|
hatIdx += 5;
|
||||||
|
|
||||||
|
foreach (var hat in hats)
|
||||||
|
{
|
||||||
|
var num = __instance.XRange.Lerp(hatIdx % __instance.NumPerRow / (__instance.NumPerRow - 1f));
|
||||||
|
var num2 = __instance.YStart - hatIdx / __instance.NumPerRow * __instance.YOffset;
|
||||||
|
var colorChip = UnityEngine.Object.Instantiate(__instance.ColorTabPrefab, __instance.scroller.Inner);
|
||||||
|
colorChip.transform.localPosition = new Vector3(num, num2, -1f);
|
||||||
|
colorChip.Button.OnClick.AddListener((Action)(() => __instance.SelectHat(hat)));
|
||||||
|
colorChip.Button.ClickMask = __instance.scroller.Hitbox;
|
||||||
|
colorChip.Inner.SetMaskType(PlayerMaterial.MaskType.SimpleUI);
|
||||||
|
__instance.UpdateMaterials(colorChip.Inner.FrontLayer, hat);
|
||||||
|
colorChip.Inner.SetHat(hat, __instance.HasLocalPlayer() ? PlayerControl.LocalPlayer.Data.DefaultOutfit.ColorId : DataManager.Player.Customization.Color);
|
||||||
|
colorChip.Inner.transform.localPosition = hat.ChipOffset + new Vector2(0f, -0.3f);
|
||||||
|
colorChip.Tag = hat;
|
||||||
|
colorChip.SelectionHighlight.gameObject.SetActive(false);
|
||||||
|
__instance.ColorChips.Add(colorChip);
|
||||||
|
hatIdx += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
__instance.scroller.ContentYBounds.max = -(__instance.YStart - (hatIdx + 1) / __instance.NumPerRow * __instance.YOffset) - 3f;
|
||||||
|
__instance.currentHatIsEquipped = true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
using HarmonyLib;
|
||||||
|
using MiraAPI.Cosmetics;
|
||||||
|
|
||||||
|
namespace MiraAPI.Patches.Cosmetics;
|
||||||
|
|
||||||
|
[HarmonyPatch(typeof(InventoryManager), nameof(InventoryManager.CheckUnlockedItems))]
|
||||||
|
public static class InventoryManagerPatch
|
||||||
|
{
|
||||||
|
public static void Prefix()
|
||||||
|
{
|
||||||
|
CustomCosmeticManager.LoadAll();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using AmongUs.Data;
|
||||||
|
using HarmonyLib;
|
||||||
|
using MiraAPI.Cosmetics;
|
||||||
|
using MiraAPI.Utilities.Assets.Addressable;
|
||||||
|
using MonoMod.Utils;
|
||||||
|
using Reactor.Utilities;
|
||||||
|
using Reactor.Utilities.Extensions;
|
||||||
|
using TMPro;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.AddressableAssets;
|
||||||
|
using UnityEngine.ResourceManagement.AsyncOperations;
|
||||||
|
|
||||||
|
namespace MiraAPI.Patches.Cosmetics;
|
||||||
|
[HarmonyPatch(typeof(NameplatesTab), nameof(NameplatesTab.OnEnable))]
|
||||||
|
public static class NameplatesTabPatch
|
||||||
|
{
|
||||||
|
public static bool Prefix(NameplatesTab __instance)
|
||||||
|
{
|
||||||
|
var groups = new SortedList<AbstractCosmeticsGroup, List<NamePlateData>>(
|
||||||
|
new AbstractCosmeticsGroupComparer()
|
||||||
|
);
|
||||||
|
CustomCosmeticManager.Groups.Do(x => x.Nameplates.Sort(new CosmeticComparer(x)));
|
||||||
|
var c = CustomCosmeticManager.Groups.Select(x => new KeyValuePair<AbstractCosmeticsGroup, List<NamePlateData>>(x, x.Nameplates)).
|
||||||
|
ToDictionary(x => x.Key, x => x.Value.Where(x => x.Free || DataManager.Player.Purchases.GetPurchase(x.ProductId, x.BundleId)).ToList());
|
||||||
|
groups.AddRange<AbstractCosmeticsGroup, List<NamePlateData>>(c);
|
||||||
|
Logger<MiraApiPlugin>.Info($"{c.Count}");
|
||||||
|
|
||||||
|
foreach (var colorchip in __instance.ColorChips) colorchip.gameObject.Destroy();
|
||||||
|
__instance.ColorChips.Clear();
|
||||||
|
var groupNameText = __instance.GetComponentInChildren<TextMeshPro>(false);
|
||||||
|
var hatIdx = 0;
|
||||||
|
|
||||||
|
__instance.PlayerPreview.gameObject.SetActive(false);
|
||||||
|
__instance.StartCoroutine(__instance.CoLoadNameplatePreview());
|
||||||
|
|
||||||
|
foreach (var (group, hats) in groups.Where(x => x.Key.GroupVisible() && x.Key.Nameplates.Count > 0))
|
||||||
|
{
|
||||||
|
var text = UnityEngine.Object.Instantiate(groupNameText, __instance.scroller.Inner);
|
||||||
|
text.gameObject.transform.localScale = Vector3.one;
|
||||||
|
text.GetComponent<TextTranslatorTMP>().Destroy();
|
||||||
|
text.text = group.GroupName;
|
||||||
|
text.alignment = TextAlignmentOptions.Center;
|
||||||
|
text.fontSize = 3f;
|
||||||
|
text.fontSizeMax = 3f;
|
||||||
|
text.fontSizeMin = 0f;
|
||||||
|
|
||||||
|
hatIdx = (hatIdx + 1) / 2 * 2;
|
||||||
|
|
||||||
|
var xLerp = __instance.XRange.Lerp(0.5f);
|
||||||
|
var yLerp = __instance.YStart - (hatIdx / __instance.NumPerRow) * __instance.YOffset;
|
||||||
|
text.transform.localPosition = new Vector3(xLerp, yLerp, -1f);
|
||||||
|
hatIdx += 2;
|
||||||
|
|
||||||
|
foreach (var hat in hats)
|
||||||
|
{
|
||||||
|
var num = __instance.XRange.Lerp(hatIdx % __instance.NumPerRow / (__instance.NumPerRow - 1f));
|
||||||
|
var num2 = __instance.YStart - hatIdx / __instance.NumPerRow * __instance.YOffset;
|
||||||
|
|
||||||
|
var colorChip = UnityEngine.Object.Instantiate(__instance.ColorTabPrefab, __instance.scroller.Inner);
|
||||||
|
colorChip.transform.localPosition = new Vector3(num, num2, -1f);
|
||||||
|
|
||||||
|
colorChip.Button.OnClick.AddListener((Action)(() => __instance.SelectNameplate(hat)));
|
||||||
|
colorChip.Button.ClickMask = __instance.scroller.Hitbox;
|
||||||
|
|
||||||
|
colorChip.ProductId = hat.ProductId;
|
||||||
|
|
||||||
|
var handle = Addressables.LoadAssetAsync<NamePlateViewData>(hat.ViewDataRef);
|
||||||
|
Coroutines.Start(SetupColorChip(colorChip.TryCast<NameplateChip>(), handle));
|
||||||
|
__instance.ColorChips.Add(colorChip);
|
||||||
|
hatIdx += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
__instance.GetDefaultSelectable().PlayerEquippedForeground.SetActive(true);
|
||||||
|
__instance.plateId = DataManager.Player.Customization.NamePlate;
|
||||||
|
__instance.scroller.ContentYBounds.max = -(__instance.YStart - (hatIdx + 1) / __instance.NumPerRow * __instance.YOffset) - 3f;
|
||||||
|
__instance.currentNameplateIsEquipped = true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static IEnumerator SetupColorChip(NameplateChip colorChip, AsyncOperationHandle<NamePlateViewData> handle)
|
||||||
|
{
|
||||||
|
yield return new WaitForAsyncOperationHandleFinish(handle);
|
||||||
|
colorChip.image.sprite = handle.Result?.Image;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,86 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using AmongUs.Data;
|
||||||
|
using HarmonyLib;
|
||||||
|
using MiraAPI.Cosmetics;
|
||||||
|
using MiraAPI.Utilities.Assets.Addressable;
|
||||||
|
using MonoMod.Utils;
|
||||||
|
using Reactor.Utilities;
|
||||||
|
using Reactor.Utilities.Extensions;
|
||||||
|
using TMPro;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.AddressableAssets;
|
||||||
|
using UnityEngine.ResourceManagement.AsyncOperations;
|
||||||
|
|
||||||
|
namespace MiraAPI.Patches.Cosmetics;
|
||||||
|
[HarmonyPatch(typeof(SkinsTab), nameof(SkinsTab.OnEnable))]
|
||||||
|
public static class SkinsTabPatch
|
||||||
|
{
|
||||||
|
public static bool Prefix(SkinsTab __instance)
|
||||||
|
{
|
||||||
|
var groups = new SortedList<AbstractCosmeticsGroup, List<SkinData>>(
|
||||||
|
new AbstractCosmeticsGroupComparer()
|
||||||
|
);
|
||||||
|
CustomCosmeticManager.Groups.Do(x => x.Skins.Sort(new CosmeticComparer(x)));
|
||||||
|
var c = CustomCosmeticManager.Groups.Select(x => new KeyValuePair<AbstractCosmeticsGroup, List<SkinData>>(x, x.Skins)).
|
||||||
|
ToDictionary(x => x.Key, x => x.Value.Where(x => x.Free || DataManager.Player.Purchases.GetPurchase(x.ProductId, x.BundleId)).ToList());
|
||||||
|
groups.AddRange<AbstractCosmeticsGroup, List<SkinData>>(c);
|
||||||
|
|
||||||
|
foreach (var colorchip in __instance.ColorChips) colorchip.gameObject.Destroy();
|
||||||
|
__instance.ColorChips.Clear();
|
||||||
|
var groupNameText = __instance.GetComponentInChildren<TextMeshPro>(false);
|
||||||
|
var hatIdx = 0;
|
||||||
|
|
||||||
|
foreach (var (group, skins) in groups.Where(x => x.Key.GroupVisible() && x.Key.Skins.Count > 0))
|
||||||
|
{
|
||||||
|
var text = UnityEngine.Object.Instantiate(groupNameText, __instance.scroller.Inner);
|
||||||
|
text.gameObject.transform.localScale = Vector3.one;
|
||||||
|
text.GetComponent<TextTranslatorTMP>().Destroy();
|
||||||
|
text.text = group.GroupName;
|
||||||
|
text.alignment = TextAlignmentOptions.Center;
|
||||||
|
text.fontSize = 3f;
|
||||||
|
text.fontSizeMax = 3f;
|
||||||
|
text.fontSizeMin = 0f;
|
||||||
|
|
||||||
|
hatIdx = (hatIdx + 4) / 5 * 5;
|
||||||
|
|
||||||
|
var xLerp = __instance.XRange.Lerp(0.5f);
|
||||||
|
var yLerp = __instance.YStart - (hatIdx / __instance.NumPerRow) * __instance.YOffset;
|
||||||
|
text.transform.localPosition = new Vector3(xLerp, yLerp, -1f);
|
||||||
|
hatIdx += 5;
|
||||||
|
|
||||||
|
foreach (var skin in skins)
|
||||||
|
{
|
||||||
|
var num = __instance.XRange.Lerp(hatIdx % __instance.NumPerRow / (__instance.NumPerRow - 1f));
|
||||||
|
var num2 = __instance.YStart - hatIdx / __instance.NumPerRow * __instance.YOffset;
|
||||||
|
var colorChip = UnityEngine.Object.Instantiate(__instance.ColorTabPrefab, __instance.scroller.Inner);
|
||||||
|
colorChip.transform.localPosition = new Vector3(num, num2, -1f);
|
||||||
|
colorChip.Button.OnClick.AddListener((Action)(() => __instance.SelectSkin(skin)));
|
||||||
|
colorChip.Button.ClickMask = __instance.scroller.Hitbox;
|
||||||
|
colorChip.ProductId = skin.ProductId;
|
||||||
|
__instance.UpdateMaterials(colorChip.Inner.FrontLayer, skin);
|
||||||
|
|
||||||
|
var handle = Addressables.LoadAssetAsync<SkinViewData>(skin.ViewDataRef);
|
||||||
|
Coroutines.Start(SetupColorChip(handle, __instance.HasLocalPlayer() ? PlayerControl.LocalPlayer.Data.DefaultOutfit.ColorId : DataManager.Player.Customization.Color, colorChip));
|
||||||
|
colorChip.SelectionHighlight.gameObject.SetActive(false);
|
||||||
|
__instance.ColorChips.Add(colorChip);
|
||||||
|
hatIdx += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
__instance.skinId = DataManager.Player.Customization.Skin;
|
||||||
|
__instance.currentSkinIsEquipped = true;
|
||||||
|
__instance.scroller.ContentYBounds.max = -(__instance.YStart - (hatIdx + 1) / __instance.NumPerRow * __instance.YOffset) - 3f;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static IEnumerator SetupColorChip(AsyncOperationHandle<SkinViewData> handle, int colorId, ColorChip colorChip)
|
||||||
|
{
|
||||||
|
yield return new WaitForAsyncOperationHandleFinish(handle);
|
||||||
|
colorChip.Inner.FrontLayer.sprite = handle.Result?.IdleFrame;
|
||||||
|
PlayerMaterial.SetColors(colorId, colorChip.Inner.FrontLayer);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,86 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using AmongUs.Data;
|
||||||
|
using HarmonyLib;
|
||||||
|
using MiraAPI.Cosmetics;
|
||||||
|
using MiraAPI.Utilities.Assets.Addressable;
|
||||||
|
using MonoMod.Utils;
|
||||||
|
using Reactor.Utilities;
|
||||||
|
using Reactor.Utilities.Extensions;
|
||||||
|
using TMPro;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.AddressableAssets;
|
||||||
|
using UnityEngine.ResourceManagement.AsyncOperations;
|
||||||
|
|
||||||
|
namespace MiraAPI.Patches.Cosmetics;
|
||||||
|
[HarmonyPatch(typeof(VisorsTab), nameof(VisorsTab.OnEnable))]
|
||||||
|
public static class VisorsTabPatch
|
||||||
|
{
|
||||||
|
public static bool Prefix(VisorsTab __instance)
|
||||||
|
{
|
||||||
|
var groups = new SortedList<AbstractCosmeticsGroup, List<VisorData>>(
|
||||||
|
new AbstractCosmeticsGroupComparer()
|
||||||
|
);
|
||||||
|
CustomCosmeticManager.Groups.Do(x => x.Visors.Sort(new CosmeticComparer(x)));
|
||||||
|
var c = CustomCosmeticManager.Groups.Select(x => new KeyValuePair<AbstractCosmeticsGroup, List<VisorData>>(x, x.Visors)).
|
||||||
|
ToDictionary(x => x.Key, x => x.Value.Where(x => x.Free || DataManager.Player.Purchases.GetPurchase(x.ProductId, x.BundleId)).ToList());
|
||||||
|
groups.AddRange<AbstractCosmeticsGroup, List<VisorData>>(c);
|
||||||
|
|
||||||
|
foreach (var colorchip in __instance.ColorChips) colorchip.gameObject.Destroy();
|
||||||
|
__instance.ColorChips.Clear();
|
||||||
|
var groupNameText = __instance.GetComponentInChildren<TextMeshPro>(false);
|
||||||
|
var hatIdx = 0;
|
||||||
|
|
||||||
|
foreach (var (group, visors) in groups.Where(x => x.Key.GroupVisible() && x.Key.Visors.Count > 0))
|
||||||
|
{
|
||||||
|
var text = UnityEngine.Object.Instantiate(groupNameText, __instance.scroller.Inner);
|
||||||
|
text.gameObject.transform.localScale = Vector3.one;
|
||||||
|
text.GetComponent<TextTranslatorTMP>().Destroy();
|
||||||
|
text.text = group.GroupName;
|
||||||
|
text.alignment = TextAlignmentOptions.Center;
|
||||||
|
text.fontSize = 3f;
|
||||||
|
text.fontSizeMax = 3f;
|
||||||
|
text.fontSizeMin = 0f;
|
||||||
|
|
||||||
|
hatIdx = (hatIdx + 4) / 5 * 5;
|
||||||
|
|
||||||
|
var xLerp = __instance.XRange.Lerp(0.5f);
|
||||||
|
var yLerp = __instance.YStart - (hatIdx / __instance.NumPerRow) * __instance.YOffset;
|
||||||
|
text.transform.localPosition = new Vector3(xLerp, yLerp, -1f);
|
||||||
|
hatIdx += 5;
|
||||||
|
|
||||||
|
foreach (var visor in visors)
|
||||||
|
{
|
||||||
|
var num = __instance.XRange.Lerp(hatIdx % __instance.NumPerRow / (__instance.NumPerRow - 1f));
|
||||||
|
var num2 = __instance.YStart - hatIdx / __instance.NumPerRow * __instance.YOffset;
|
||||||
|
var colorChip = UnityEngine.Object.Instantiate(__instance.ColorTabPrefab, __instance.scroller.Inner);
|
||||||
|
colorChip.transform.localPosition = new Vector3(num, num2, -1f);
|
||||||
|
colorChip.Button.OnClick.AddListener((Action)(() => __instance.SelectVisor(visor)));
|
||||||
|
colorChip.Button.ClickMask = __instance.scroller.Hitbox;
|
||||||
|
colorChip.ProductId = visor.ProductId;
|
||||||
|
__instance.UpdateMaterials(colorChip.Inner.FrontLayer, visor);
|
||||||
|
|
||||||
|
var handle = Addressables.LoadAssetAsync<VisorViewData>(visor.ViewDataRef);
|
||||||
|
Coroutines.Start(SetupColorChip(handle, __instance.HasLocalPlayer() ? PlayerControl.LocalPlayer.Data.DefaultOutfit.ColorId : DataManager.Player.Customization.Color, colorChip));
|
||||||
|
colorChip.SelectionHighlight.gameObject.SetActive(false);
|
||||||
|
__instance.ColorChips.Add(colorChip);
|
||||||
|
hatIdx += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
__instance.visorId = DataManager.Player.Customization.Visor;
|
||||||
|
__instance.currentVisorIsEquipped = true;
|
||||||
|
__instance.scroller.ContentYBounds.max = -(__instance.YStart - (hatIdx + 1) / __instance.NumPerRow * __instance.YOffset) - 3f;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static IEnumerator SetupColorChip(AsyncOperationHandle<VisorViewData> handle, int colorId, ColorChip colorChip)
|
||||||
|
{
|
||||||
|
yield return new WaitForAsyncOperationHandleFinish(handle);
|
||||||
|
colorChip.Inner.FrontLayer.sprite = handle.Result?.IdleFrame;
|
||||||
|
PlayerMaterial.SetColors(colorId, colorChip.Inner.FrontLayer);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,7 +4,7 @@ using MiraAPI.Hud;
|
|||||||
namespace MiraAPI.Patches.Hud;
|
namespace MiraAPI.Patches.Hud;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Reset button patches
|
/// Reset button patches.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[HarmonyPatch]
|
[HarmonyPatch]
|
||||||
public static class ButtonResetPatches
|
public static class ButtonResetPatches
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
using MiraAPI.Hud;
|
using MiraAPI.Hud;
|
||||||
using MiraAPI.Roles;
|
|
||||||
using Reactor.Utilities.Extensions;
|
using Reactor.Utilities.Extensions;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using Object = UnityEngine.Object;
|
using Object = UnityEngine.Object;
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
using HarmonyLib;
|
||||||
|
using MiraAPI.GameOptions;
|
||||||
|
|
||||||
|
namespace MiraAPI.Patches.Options;
|
||||||
|
|
||||||
|
[HarmonyPatch(typeof(CreateOptionsPicker), nameof(CreateOptionsPicker.Start))]
|
||||||
|
public static class CreateOptionsPatch
|
||||||
|
{
|
||||||
|
public static void Postfix()
|
||||||
|
{
|
||||||
|
foreach (var (_, value) in ModdedOptionsManager.ModdedOptions)
|
||||||
|
{
|
||||||
|
value.ResetToConfig();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
using HarmonyLib;
|
using System.Linq;
|
||||||
|
using HarmonyLib;
|
||||||
using MiraAPI.Utilities;
|
using MiraAPI.Utilities;
|
||||||
using MiraAPI.Utilities.Assets;
|
using MiraAPI.Utilities.Assets;
|
||||||
using Reactor.Localization.Utilities;
|
using Reactor.Localization.Utilities;
|
||||||
using Reactor.Utilities.Extensions;
|
using Reactor.Utilities.Extensions;
|
||||||
using System.Linq;
|
|
||||||
using TMPro;
|
using TMPro;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.Events;
|
using UnityEngine.Events;
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
using HarmonyLib;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using HarmonyLib;
|
||||||
using MiraAPI.PluginLoading;
|
using MiraAPI.PluginLoading;
|
||||||
using MiraAPI.Utilities.Assets;
|
using MiraAPI.Utilities.Assets;
|
||||||
using Reactor.Utilities.Extensions;
|
using Reactor.Utilities.Extensions;
|
||||||
using System;
|
|
||||||
using System.Linq;
|
|
||||||
using TMPro;
|
using TMPro;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.Events;
|
using UnityEngine.Events;
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
using HarmonyLib;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using HarmonyLib;
|
||||||
using MiraAPI.PluginLoading;
|
using MiraAPI.PluginLoading;
|
||||||
using MiraAPI.Roles;
|
using MiraAPI.Roles;
|
||||||
using MiraAPI.Utilities;
|
using MiraAPI.Utilities;
|
||||||
using MiraAPI.Utilities.Assets;
|
using MiraAPI.Utilities.Assets;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.Events;
|
using UnityEngine.Events;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
using HarmonyLib;
|
using System.Linq;
|
||||||
|
using HarmonyLib;
|
||||||
using Il2CppSystem;
|
using Il2CppSystem;
|
||||||
using MiraAPI.Roles;
|
using MiraAPI.Roles;
|
||||||
using System.Linq;
|
using UnityEngine;
|
||||||
|
using Object = Il2CppSystem.Object;
|
||||||
|
|
||||||
namespace MiraAPI.Patches.Options;
|
namespace MiraAPI.Patches.Options;
|
||||||
|
|
||||||
@@ -23,9 +25,13 @@ public static class NotificationPopperPatch
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
var text = teamType == RoleTeamTypes.Crewmate
|
var text = customRole.Team switch
|
||||||
? Palette.CrewmateSettingChangeText.ToTextColor()
|
{
|
||||||
: Palette.ImpostorRed.ToTextColor();
|
ModdedRoleTeams.Crewmate => Palette.CrewmateSettingChangeText.ToTextColor(),
|
||||||
|
ModdedRoleTeams.Impostor => Palette.ImpostorRed.ToTextColor(),
|
||||||
|
ModdedRoleTeams.Neutral => Palette.DisabledGrey.ToTextColor(),
|
||||||
|
_ => Color.white.ToTextColor(),
|
||||||
|
};
|
||||||
|
|
||||||
var item = TranslationController.Instance.GetString(
|
var item = TranslationController.Instance.GetString(
|
||||||
StringNames.LobbyChangeSettingNotificationRole,
|
StringNames.LobbyChangeSettingNotificationRole,
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
using HarmonyLib;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using HarmonyLib;
|
||||||
using Il2CppInterop.Runtime.InteropTypes.Arrays;
|
using Il2CppInterop.Runtime.InteropTypes.Arrays;
|
||||||
using MiraAPI.Networking;
|
using MiraAPI.Networking;
|
||||||
using MiraAPI.Roles;
|
using MiraAPI.Roles;
|
||||||
@@ -7,8 +9,6 @@ using MiraAPI.Utilities.Assets;
|
|||||||
using Reactor.Networking.Rpc;
|
using Reactor.Networking.Rpc;
|
||||||
using Reactor.Utilities;
|
using Reactor.Utilities;
|
||||||
using Reactor.Utilities.Extensions;
|
using Reactor.Utilities.Extensions;
|
||||||
using System;
|
|
||||||
using System.Linq;
|
|
||||||
using TMPro;
|
using TMPro;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.Events;
|
using UnityEngine.Events;
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ public static class PlayerControlPatches
|
|||||||
/// Calls the OnDeath method for all active modifiers.
|
/// Calls the OnDeath method for all active modifiers.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="__instance">PlayerControl instance.</param>
|
/// <param name="__instance">PlayerControl instance.</param>
|
||||||
|
/// <param name="reason">The death reason.</param>
|
||||||
[HarmonyPostfix]
|
[HarmonyPostfix]
|
||||||
[HarmonyPatch(nameof(PlayerControl.Die))]
|
[HarmonyPatch(nameof(PlayerControl.Die))]
|
||||||
public static void PlayerControlDiePostfix(PlayerControl __instance, DeathReason reason)
|
public static void PlayerControlDiePostfix(PlayerControl __instance, DeathReason reason)
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ public static class GameStartupPatch
|
|||||||
private static bool _runOnce;
|
private static bool _runOnce;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This is used for registering roles when the game opens, might be a janky solution, but it works
|
/// This is used for registering roles when the game opens, might be a janky solution, but it works.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[HarmonyPostfix]
|
[HarmonyPostfix]
|
||||||
[HarmonyPatch(nameof(MainMenuManager.Start))]
|
[HarmonyPatch(nameof(MainMenuManager.Start))]
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ using UnityEngine;
|
|||||||
namespace MiraAPI.Patches.Roles;
|
namespace MiraAPI.Patches.Roles;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Set nametag color depending on option
|
/// Set nametag color depending on option.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[HarmonyPatch(typeof(PlayerNameColor))]
|
[HarmonyPatch(typeof(PlayerNameColor))]
|
||||||
public static class NameTagPatch
|
public static class NameTagPatch
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ namespace MiraAPI.Patches.Roles;
|
|||||||
public static class RoleBehaviourPatches
|
public static class RoleBehaviourPatches
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Update TeamColor text for Launchpad roles
|
/// Update TeamColor text for custom roles.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[HarmonyPrefix]
|
[HarmonyPrefix]
|
||||||
[HarmonyPatch(nameof(RoleBehaviour.TeamColor), MethodType.Getter)]
|
[HarmonyPatch(nameof(RoleBehaviour.TeamColor), MethodType.Getter)]
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
using AmongUs.GameOptions;
|
using System.Linq;
|
||||||
|
using AmongUs.GameOptions;
|
||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
using MiraAPI.Modifiers;
|
using MiraAPI.Modifiers;
|
||||||
using MiraAPI.Roles;
|
using MiraAPI.Roles;
|
||||||
using System.Linq;
|
|
||||||
|
|
||||||
namespace MiraAPI.Patches.Roles;
|
namespace MiraAPI.Patches.Roles;
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ namespace MiraAPI.Patches.Roles;
|
|||||||
public static class RoleOptionsCollectionPatch
|
public static class RoleOptionsCollectionPatch
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Set the role chance for custom Launchpad roles based on config
|
/// Set the role chance for custom Launchpad roles based on config.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>Return false to skip original method, true to not.</returns>
|
/// <returns>Return false to skip original method, true to not.</returns>
|
||||||
[HarmonyPrefix]
|
[HarmonyPrefix]
|
||||||
@@ -42,7 +42,7 @@ public static class RoleOptionsCollectionPatch
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Set the amount for custom Launchpad roles based on config
|
/// Set the amount for custom Launchpad roles based on config.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>Return false to skip original method, true to not.</returns>
|
/// <returns>Return false to skip original method, true to not.</returns>
|
||||||
[HarmonyPrefix]
|
[HarmonyPrefix]
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ using MiraAPI.Roles;
|
|||||||
namespace MiraAPI.Patches.Roles;
|
namespace MiraAPI.Patches.Roles;
|
||||||
|
|
||||||
[HarmonyPatch(typeof(SabotageButton))]
|
[HarmonyPatch(typeof(SabotageButton))]
|
||||||
public class SabotageButtonPatch
|
public static class SabotageButtonPatch
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Patches the Sabotage button to check if the player's custom role can use sabotage.
|
/// Patches the Sabotage button to check if the player's custom role can use sabotage.
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
using AmongUs.GameOptions;
|
using System;
|
||||||
using HarmonyLib;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using AmongUs.GameOptions;
|
||||||
|
using HarmonyLib;
|
||||||
using MiraAPI.PluginLoading;
|
using MiraAPI.PluginLoading;
|
||||||
using MiraAPI.Roles;
|
using MiraAPI.Roles;
|
||||||
using MiraAPI.Utilities.Assets;
|
using MiraAPI.Utilities.Assets;
|
||||||
using System.Linq;
|
|
||||||
using TMPro;
|
using TMPro;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using Object = UnityEngine.Object;
|
using Object = UnityEngine.Object;
|
||||||
|
|||||||
@@ -1,14 +1,10 @@
|
|||||||
using BepInEx;
|
using System.Collections.Generic;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
|
using BepInEx;
|
||||||
using BepInEx.Configuration;
|
using BepInEx.Configuration;
|
||||||
using MiraAPI.GameModes;
|
using MiraAPI.GameModes;
|
||||||
using MiraAPI.GameOptions;
|
using MiraAPI.GameOptions;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Collections.Immutable;
|
|
||||||
using System.Collections.ObjectModel;
|
|
||||||
using System.Linq;
|
|
||||||
using MiraAPI.GameOptions.OptionTypes;
|
|
||||||
using MiraAPI.Hud;
|
using MiraAPI.Hud;
|
||||||
using MiraAPI.Roles;
|
|
||||||
|
|
||||||
namespace MiraAPI.PluginLoading;
|
namespace MiraAPI.PluginLoading;
|
||||||
|
|
||||||
@@ -61,10 +57,21 @@ public class MiraPluginInfo
|
|||||||
return Buttons.AsReadOnly();
|
return Buttons.AsReadOnly();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a read only collection of this plugin's custom buttons.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Read only collection of buttons.</returns>
|
||||||
|
public IReadOnlyCollection<Cosmetics.AbstractCosmeticsGroup> GetCosmetics()
|
||||||
|
{
|
||||||
|
return CosmeticGroups.AsReadOnly();
|
||||||
|
}
|
||||||
|
|
||||||
internal List<AbstractOptionGroup> OptionGroups { get; } = [];
|
internal List<AbstractOptionGroup> OptionGroups { get; } = [];
|
||||||
|
|
||||||
internal List<IModdedOption> Options { get; } = [];
|
internal List<IModdedOption> Options { get; } = [];
|
||||||
|
|
||||||
|
internal List<Cosmetics.AbstractCosmeticsGroup> CosmeticGroups { get; } = [];
|
||||||
|
|
||||||
internal Dictionary<ushort, RoleBehaviour> CustomRoles { get; } = [];
|
internal Dictionary<ushort, RoleBehaviour> CustomRoles { get; } = [];
|
||||||
|
|
||||||
internal Dictionary<int, CustomGameMode> GameModes { get; } = [];
|
internal Dictionary<int, CustomGameMode> GameModes { get; } = [];
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ using System.Linq;
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using BepInEx.Unity.IL2CPP;
|
using BepInEx.Unity.IL2CPP;
|
||||||
using MiraAPI.Colors;
|
using MiraAPI.Colors;
|
||||||
|
using MiraAPI.Cosmetics;
|
||||||
using MiraAPI.GameOptions;
|
using MiraAPI.GameOptions;
|
||||||
using MiraAPI.GameOptions.Attributes;
|
using MiraAPI.GameOptions.Attributes;
|
||||||
using MiraAPI.Hud;
|
using MiraAPI.Hud;
|
||||||
@@ -29,6 +30,7 @@ public sealed class MiraPluginManager
|
|||||||
internal void Initialize()
|
internal void Initialize()
|
||||||
{
|
{
|
||||||
Instance = this;
|
Instance = this;
|
||||||
|
CustomCosmeticManager.RegisterVanilla();
|
||||||
IL2CPPChainloader.Instance.PluginLoad += (pluginInfo, assembly, plugin) =>
|
IL2CPPChainloader.Instance.PluginLoad += (pluginInfo, assembly, plugin) =>
|
||||||
{
|
{
|
||||||
if (plugin is not IMiraPlugin miraPlugin)
|
if (plugin is not IMiraPlugin miraPlugin)
|
||||||
@@ -40,6 +42,7 @@ public sealed class MiraPluginManager
|
|||||||
|
|
||||||
RegisterModifierAttribute(assembly);
|
RegisterModifierAttribute(assembly);
|
||||||
RegisterAllOptions(assembly, info);
|
RegisterAllOptions(assembly, info);
|
||||||
|
RegisterAllCosmetics(assembly, info);
|
||||||
|
|
||||||
RegisterRoleAttribute(assembly, info);
|
RegisterRoleAttribute(assembly, info);
|
||||||
RegisterButtonAttribute(assembly, info);
|
RegisterButtonAttribute(assembly, info);
|
||||||
@@ -56,11 +59,11 @@ public sealed class MiraPluginManager
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get a mira plugin by its GUID.
|
/// Get a mira plugin by its GUID.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="guid">The plugin GUID.</param>
|
/// <param name="uniqueId">The plugin GUID.</param>
|
||||||
/// <returns>A MiraPluginInfo.</returns>
|
/// <returns>A MiraPluginInfo.</returns>
|
||||||
public static MiraPluginInfo GetPluginByGuid(string guid)
|
public static MiraPluginInfo GetPluginByGuid(string uniqueId)
|
||||||
{
|
{
|
||||||
return Instance._registeredPlugins.Values.First(plugin => plugin.PluginId == guid);
|
return Instance._registeredPlugins.Values.First(plugin => plugin.PluginId == uniqueId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void RegisterAllOptions(Assembly assembly, MiraPluginInfo pluginInfo)
|
private static void RegisterAllOptions(Assembly assembly, MiraPluginInfo pluginInfo)
|
||||||
@@ -95,6 +98,30 @@ public sealed class MiraPluginManager
|
|||||||
pluginInfo.OptionGroups.Sort((x, y) => x.GroupPriority.CompareTo(y.GroupPriority));
|
pluginInfo.OptionGroups.Sort((x, y) => x.GroupPriority.CompareTo(y.GroupPriority));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void RegisterAllCosmetics(Assembly assembly, MiraPluginInfo pluginInfo)
|
||||||
|
{
|
||||||
|
var filteredTypes = assembly.GetTypes().Where(type => type.IsAssignableTo(typeof(AbstractCosmeticsGroup)));
|
||||||
|
|
||||||
|
foreach (var type in filteredTypes)
|
||||||
|
{
|
||||||
|
if (!CustomCosmeticManager.RegisterGroup(type, pluginInfo))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var property in type.GetProperties())
|
||||||
|
{
|
||||||
|
var attribute = property.GetCustomAttribute<RegisterCustomCosmeticAttribute>();
|
||||||
|
if (attribute == null)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
CustomCosmeticManager.RegisterAttributeOption(type, attribute, property, pluginInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static void RegisterRoleAttribute(Assembly assembly, MiraPluginInfo pluginInfo)
|
private static void RegisterRoleAttribute(Assembly assembly, MiraPluginInfo pluginInfo)
|
||||||
{
|
{
|
||||||
List<Type> roles = [];
|
List<Type> roles = [];
|
||||||
|
|||||||
@@ -39,6 +39,8 @@ public struct CustomRoleConfiguration
|
|||||||
CanModifyChance = true;
|
CanModifyChance = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#pragma warning disable S1104
|
||||||
|
#pragma warning disable CA1051
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the hard limit of players that can have this role. This property is used to set a limit in the Role Options menu. If set to 0, the role will not be assigned at start.
|
/// Gets the hard limit of players that can have this role. This property is used to set a limit in the Role Options menu. If set to 0, the role will not be assigned at start.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -123,4 +125,6 @@ public struct CustomRoleConfiguration
|
|||||||
/// Gets the Ghost role that is applied when the player is killed.
|
/// Gets the Ghost role that is applied when the player is killed.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public RoleTypes GhostRole;
|
public RoleTypes GhostRole;
|
||||||
}
|
#pragma warning restore S1104
|
||||||
|
#pragma warning restore CA1051
|
||||||
|
}
|
||||||
@@ -1,4 +1,7 @@
|
|||||||
using AmongUs.GameOptions;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using AmongUs.GameOptions;
|
||||||
using Il2CppInterop.Runtime;
|
using Il2CppInterop.Runtime;
|
||||||
using Il2CppInterop.Runtime.Injection;
|
using Il2CppInterop.Runtime.Injection;
|
||||||
using MiraAPI.Networking;
|
using MiraAPI.Networking;
|
||||||
@@ -8,9 +11,6 @@ using Reactor.Localization.Utilities;
|
|||||||
using Reactor.Networking.Rpc;
|
using Reactor.Networking.Rpc;
|
||||||
using Reactor.Utilities;
|
using Reactor.Utilities;
|
||||||
using Reactor.Utilities.Extensions;
|
using Reactor.Utilities.Extensions;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using TMPro;
|
using TMPro;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using Object = UnityEngine.Object;
|
using Object = UnityEngine.Object;
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ namespace MiraAPI.Roles;
|
|||||||
/// <typeparam name="T">The role you are trying to access.</typeparam>
|
/// <typeparam name="T">The role you are trying to access.</typeparam>
|
||||||
public static class CustomRoleSingleton<T> where T : ICustomRole
|
public static class CustomRoleSingleton<T> where T : ICustomRole
|
||||||
{
|
{
|
||||||
private static ICustomRole? _instance;
|
private static T? _instance;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the instance of the role.
|
/// Gets the instance of the role.
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
using BepInEx.Configuration;
|
using System.Text;
|
||||||
|
using BepInEx.Configuration;
|
||||||
using MiraAPI.Modifiers;
|
using MiraAPI.Modifiers;
|
||||||
using MiraAPI.PluginLoading;
|
using MiraAPI.PluginLoading;
|
||||||
using MiraAPI.Utilities;
|
using MiraAPI.Utilities;
|
||||||
using System.Text;
|
|
||||||
using Reactor.Utilities;
|
using Reactor.Utilities;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
@@ -39,7 +39,7 @@ public interface ICustomRole
|
|||||||
ModdedRoleTeams Team { get; }
|
ModdedRoleTeams Team { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets advanced settings of the role.
|
/// Gets the advanced settings of the role.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
CustomRoleConfiguration Configuration { get; }
|
CustomRoleConfiguration Configuration { get; }
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,52 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using BepInEx.Unity.IL2CPP.Utils.Collections;
|
||||||
|
using Reactor.Utilities;
|
||||||
|
using UnityEngine.AddressableAssets;
|
||||||
|
using UnityEngine.AddressableAssets.ResourceLocators;
|
||||||
|
using UnityEngine.ResourceManagement.AsyncOperations;
|
||||||
|
|
||||||
|
namespace MiraAPI.Utilities.Assets.Addressable;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Catalogs are a representation of resource locators for the Unity Addressables api.
|
||||||
|
/// </summary>
|
||||||
|
public class Catalog(string CatalogPath)
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Loads the catalog asynchronously.
|
||||||
|
/// </summary>
|
||||||
|
public void LoadCatalogAsync()
|
||||||
|
{
|
||||||
|
Coroutines.Start(LoadCatalogAsynchronously());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Loads the catalog. This must be done before you can call any addressables.
|
||||||
|
/// </summary>
|
||||||
|
public void LoadCatalog()
|
||||||
|
{
|
||||||
|
Addressables.LoadContentCatalog(CatalogPath).WaitForCompletion();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Updates the network catalogs.
|
||||||
|
/// </summary>
|
||||||
|
public void UpdateNetworkCatalog()
|
||||||
|
{
|
||||||
|
Coroutines.Start(UpdateCatalog());
|
||||||
|
}
|
||||||
|
protected IEnumerator LoadCatalogAsynchronously()
|
||||||
|
{
|
||||||
|
AsyncOperationHandle<IResourceLocator> handle = Addressables.LoadContentCatalogAsync(CatalogPath, true);
|
||||||
|
yield return handle;
|
||||||
|
}
|
||||||
|
protected IEnumerator UpdateCatalog()
|
||||||
|
{
|
||||||
|
string[] toUpdate = { CatalogPath };
|
||||||
|
var catalogs = toUpdate.WrapToIl2Cpp().Cast<Il2CppSystem.Collections.Generic.IEnumerable<string>>();
|
||||||
|
var updateHandle = Addressables.UpdateCatalogs(catalogs);
|
||||||
|
|
||||||
|
yield return updateHandle;
|
||||||
|
updateHandle.Release();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
using System.IO;
|
||||||
|
using BepInEx.Unity.IL2CPP.Utils.Collections;
|
||||||
|
using UnityEngine.AddressableAssets;
|
||||||
|
|
||||||
|
namespace MiraAPI.Utilities.Assets.Addressable;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A utility class for various catalog-related operations.
|
||||||
|
/// </summary>
|
||||||
|
public static class CatalogTools
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Converts string filenames to catalog paths within the plugins folder.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="fileName">A string of the catalog file without the extension.</param>
|
||||||
|
/// <returns>The path to the catalog file.</returns>
|
||||||
|
public static string ToLocalPath(this string fileName)
|
||||||
|
{
|
||||||
|
return Path.GetDirectoryName(typeof(MiraApiPlugin).Assembly.Location) + $"\\{fileName}.catalog";
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Finds the resource locations of a specific label.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="label">The label of the addressables assets.</param>
|
||||||
|
/// <returns>An IList of IResourceLocation.</returns>
|
||||||
|
public static Il2CppSystem.Collections.Generic.IList<UnityEngine.ResourceManagement.ResourceLocations.IResourceLocation> GetResourceLocation(string label)
|
||||||
|
{
|
||||||
|
return Addressables.LoadResourceLocationsAsync(label).WaitForCompletion();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Finds the resource locations of multiple specific labels.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="labels">The label of the addressables assets.</param>
|
||||||
|
/// <returns>An IList of IResourceLocation.</returns>
|
||||||
|
public static Il2CppSystem.Collections.Generic.IList<UnityEngine.ResourceManagement.ResourceLocations.IResourceLocation> GetResourceLocations(string[] labels)
|
||||||
|
{
|
||||||
|
var il2CPPLabels = new Il2CppSystem.Collections.Generic.IList<Il2CppSystem.Object>(labels.WrapToIl2Cpp().Pointer);
|
||||||
|
return Addressables.LoadResourceLocationsAsync(il2CPPLabels, Addressables.MergeMode.Union).WaitForCompletion();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.ResourceManagement.AsyncOperations;
|
||||||
|
|
||||||
|
namespace MiraAPI.Utilities.Assets.Addressable;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// An IEnumerator for awaiting an AsyncOperationHandle.
|
||||||
|
/// </summary>.
|
||||||
|
/// <param name="handle">The AsyncOperationHandle being awaited.</param>
|
||||||
|
public class WaitForAsyncOperationHandleFinish(AsyncOperationHandle handle) : IEnumerator
|
||||||
|
{
|
||||||
|
public object Current => null;
|
||||||
|
public bool MoveNext()
|
||||||
|
{
|
||||||
|
return !Mathf.Approximately(handle.PercentComplete, 1.0f) && !handle.IsDone;
|
||||||
|
}
|
||||||
|
public void Reset()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
using System;
|
||||||
|
using UnityEngine.AddressableAssets;
|
||||||
|
|
||||||
|
namespace MiraAPI.Utilities.Assets;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A utility class for loading assets from the addressables api.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">The name/identifier of the asset.</param>
|
||||||
|
/// <typeparam name="T">The type of the asset to be loaded.</typeparam>
|
||||||
|
public class LoadableAddressableAsset<T>(string name) : LoadableAsset<T> where T : UnityEngine.Object
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Loads the asset from the addressables api.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The asset.</returns>
|
||||||
|
/// <exception cref="Exception">The asset did not load properly.</exception>
|
||||||
|
public override T LoadAsset()
|
||||||
|
{
|
||||||
|
if (LoadedAsset != null)
|
||||||
|
{
|
||||||
|
return LoadedAsset;
|
||||||
|
}
|
||||||
|
|
||||||
|
LoadedAsset = Addressables.LoadAssetAsync<T>(name).WaitForCompletion();
|
||||||
|
|
||||||
|
if (LoadedAsset == null)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException($"INVALID ASSET: {name}");
|
||||||
|
}
|
||||||
|
|
||||||
|
return LoadedAsset;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine.AddressableAssets;
|
||||||
|
|
||||||
|
namespace MiraAPI.Utilities.Assets;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A utility class for loading multiple assets from the addressables api.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="locations">A list of IResourceLocations that locate the assets.</param>
|
||||||
|
/// <typeparam name="T">The type of the assets to be loaded.</typeparam>
|
||||||
|
public class LoadableAddressableGroupAsset<T>(Il2CppSystem.Collections.Generic.IList<UnityEngine.ResourceManagement.ResourceLocations.IResourceLocation> locations) where T : UnityEngine.Object
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets a reference to the loaded assets. Intended to be used for caching purposes.
|
||||||
|
/// </summary>
|
||||||
|
protected List<T> LoadedAsset { get; set; } = [];
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Loads the assets from the addressables api.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The assets.</returns>
|
||||||
|
/// <exception cref="Exception">The asset did not load properly.</exception>
|
||||||
|
public List<T> LoadAsset()
|
||||||
|
{
|
||||||
|
if (LoadedAsset.Count != 0)
|
||||||
|
{
|
||||||
|
return LoadedAsset;
|
||||||
|
}
|
||||||
|
|
||||||
|
var assets = Addressables.LoadAssetsAsync<T>(locations, null, false).WaitForCompletion();
|
||||||
|
var array = new Il2CppSystem.Collections.Generic.List<T>(assets.Pointer);
|
||||||
|
LoadedAsset = [..array.ToArray()];
|
||||||
|
|
||||||
|
if (LoadedAsset is null || LoadedAsset.Count == 0)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("INVALID ASSET LOCATION/s");
|
||||||
|
}
|
||||||
|
|
||||||
|
return LoadedAsset;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
using MiraAPI.Roles;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using MiraAPI.Roles;
|
||||||
using TMPro;
|
using TMPro;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using Object = UnityEngine.Object;
|
using Object = UnityEngine.Object;
|
||||||
|
|||||||
Reference in new issue
Block a user