mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-10-21 21:43:26 +00:00
code style stuff and merge
This commit is contained in:
1 parent
d64972a574
commit
ff2f44fd64
52 files changed
+312
-290
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.GameOptions;
|
||||
using MiraAPI.Hud;
|
||||
using MiraAPI.Utilities.Assets;
|
||||
using Reactor.Utilities;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.Example.Buttons.Teleporter;
|
||||
@@ -40,7 +40,10 @@ public class TeleportButton : CustomActionButton
|
||||
{
|
||||
base.FixedUpdate(playerControl);
|
||||
|
||||
if (!EffectActive) return;
|
||||
if (!EffectActive)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (Input.GetKey(KeyCode.Mouse0))
|
||||
{
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
using MiraAPI.Cosmetics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Generic;
|
||||
using MiraAPI.Cosmetics;
|
||||
|
||||
namespace MiraAPI.Example.Cosmetics;
|
||||
public class ExampleCosmeticGroup : AbstractCosmeticsGroup
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using MiraAPI.Example.Roles;
|
||||
using System;
|
||||
using MiraAPI.Example.Roles;
|
||||
using MiraAPI.GameOptions;
|
||||
using MiraAPI.GameOptions.Attributes;
|
||||
using System;
|
||||
using MiraAPI.Utilities;
|
||||
|
||||
namespace MiraAPI.Example.Options.Roles;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using MiraAPI.Roles;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.Example.Roles;
|
||||
@@ -22,8 +21,8 @@ public class ChameloenRole : CrewmateRole, ICustomRole
|
||||
{
|
||||
if (playerControl.MyPhysics.Velocity.magnitude > 0)
|
||||
{
|
||||
SpriteRenderer rend = playerControl.cosmetics.currentBodySprite.BodySprite;
|
||||
TextMeshPro tmp = playerControl.cosmetics.nameText;
|
||||
var rend = playerControl.cosmetics.currentBodySprite.BodySprite;
|
||||
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);
|
||||
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
|
||||
{
|
||||
SpriteRenderer rend = playerControl.cosmetics.currentBodySprite.BodySprite;
|
||||
TextMeshPro tmp = playerControl.cosmetics.nameText;
|
||||
var rend = playerControl.cosmetics.currentBodySprite.BodySprite;
|
||||
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);
|
||||
rend.color = Color.Lerp(rend.color, new Color(1, 1, 1, playerControl.AmOwner ? 0.3f : 0), Time.deltaTime * 4f);
|
||||
|
||||
|
||||
@@ -10,24 +10,24 @@ public abstract class AbstractCosmeticsGroup
|
||||
public List<NamePlateData> Nameplates { get; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// The name of the group. Visible in options menu.
|
||||
/// Gets the name of the group. Visible in options menu.
|
||||
/// </summary>
|
||||
public abstract string GroupName { get; }
|
||||
|
||||
/// <summary>
|
||||
/// A function that returns whether the group should be visible or not.
|
||||
/// Gets a function that determines whether the group should be visible or not.
|
||||
/// </summary>
|
||||
public virtual Func<bool> GroupVisible => () => true;
|
||||
|
||||
/// <summary>
|
||||
/// The sorting mode of individual hats within this group.
|
||||
/// Gets the sorting mode of individual hats within this group.
|
||||
/// </summary>
|
||||
public virtual SortingMode SortingMode { get; } = SortingMode.AlphabeticName;
|
||||
|
||||
public virtual SortingMode SortingMode => SortingMode.AlphabeticName;
|
||||
|
||||
/// <summary>
|
||||
/// The priority of a group for sorting groups.
|
||||
/// Gets the priority of a group for sorting groups.
|
||||
/// </summary>
|
||||
public virtual int SortingPriority { get; } = 0;
|
||||
public virtual int SortingPriority { get; }
|
||||
}
|
||||
|
||||
public enum SortingMode
|
||||
@@ -36,4 +36,4 @@ public enum SortingMode
|
||||
AlphabeticProductId,
|
||||
AlphabeticStoreName,
|
||||
AlphabeticName,
|
||||
}
|
||||
}
|
||||
@@ -2,12 +2,21 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace MiraAPI.Cosmetics;
|
||||
internal class AbstractCosmeticsGroupComparer : Comparer<AbstractCosmeticsGroup>
|
||||
internal sealed class AbstractCosmeticsGroupComparer : Comparer<AbstractCosmeticsGroup>
|
||||
{
|
||||
public override int Compare(AbstractCosmeticsGroup x, AbstractCosmeticsGroup y)
|
||||
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;
|
||||
if (p == 0) return StringComparer.InvariantCultureIgnoreCase.Compare(x.GroupName, y.GroupName);
|
||||
return p;
|
||||
return p == 0 ? StringComparer.InvariantCultureIgnoreCase.Compare(x.GroupName, y.GroupName) : p;
|
||||
}
|
||||
}
|
||||
@@ -3,26 +3,36 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace MiraAPI.Cosmetics;
|
||||
internal class CosmeticComparer(AbstractCosmeticsGroup group) : Comparer<CosmeticData>
|
||||
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)
|
||||
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;
|
||||
switch (group.SortingMode)
|
||||
if (NoCosmetics.Contains(x?.ProdId))
|
||||
{
|
||||
default:
|
||||
case SortingMode.AlphabeticName:
|
||||
return StringComparer.InvariantCultureIgnoreCase.Compare(x.GetItemName(), y.GetItemName());
|
||||
case SortingMode.AlphabeticProductId:
|
||||
return StringComparer.InvariantCultureIgnoreCase.Compare(x.ProductId, y.ProductId);
|
||||
case SortingMode.Priority:
|
||||
return CustomCosmeticManager._cosmeticToPriority[x] - CustomCosmeticManager._cosmeticToPriority[y];
|
||||
case SortingMode.AlphabeticStoreName:
|
||||
if (x is HatData h1 && y is HatData h2) return StringComparer.InvariantCultureIgnoreCase.Compare(h1.StoreName, h2.StoreName);
|
||||
if (x is SkinData s1 && y is SkinData s2) return StringComparer.InvariantCultureIgnoreCase.Compare(s1.StoreName, s2.StoreName);
|
||||
goto case SortingMode.AlphabeticName;
|
||||
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()),
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,23 +1,19 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Linq;
|
||||
|
||||
namespace MiraAPI.Cosmetics;
|
||||
|
||||
public class CosmeticGroupSingleton<T> where T : AbstractCosmeticsGroup
|
||||
/// <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;
|
||||
private static T? _instance;
|
||||
|
||||
public static T Instance
|
||||
{
|
||||
get => _instance ??= CustomCosmeticManager.Groups.OfType<T>().Single();
|
||||
set
|
||||
{
|
||||
if (_instance != null)
|
||||
{
|
||||
throw new InvalidOperationException($"Instance for {typeof(T)} is already set");
|
||||
}
|
||||
|
||||
_instance = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <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
|
||||
}
|
||||
@@ -1,19 +1,19 @@
|
||||
using HarmonyLib;
|
||||
using MiraAPI.PluginLoading;
|
||||
using MonoMod.Utils;
|
||||
using Reactor.Utilities;
|
||||
using System;
|
||||
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 = new();
|
||||
private static readonly Dictionary<Type, AbstractCosmeticsGroup> TypeToGroup = new();
|
||||
internal static readonly Dictionary<CosmeticData, int> _cosmeticToPriority = new();
|
||||
internal static readonly Dictionary<CosmeticData, AbstractCosmeticsGroup> _cosmeticToGroup = new();
|
||||
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 = [];
|
||||
|
||||
@@ -67,14 +67,13 @@ public static class CustomCosmeticManager
|
||||
{
|
||||
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}");
|
||||
@@ -103,22 +102,26 @@ public static class CustomCosmeticManager
|
||||
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));
|
||||
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;
|
||||
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.Where(x=>x is HatData).Select(x=>(HatData)x).ToArray();
|
||||
DestroyableSingleton<HatManager>.Instance.allVisors = _cosmeticToGroup.Keys.Where(x=>x is VisorData).Select(x => (VisorData)x).ToArray();
|
||||
DestroyableSingleton<HatManager>.Instance.allSkins = _cosmeticToGroup.Keys.Where(x=>x is SkinData).Select(x => (SkinData)x).ToArray();
|
||||
DestroyableSingleton<HatManager>.Instance.allNamePlates = _cosmeticToGroup.Keys.Where(x=>x is NamePlateData).Select(x => (NamePlateData)x).ToArray();
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -3,11 +3,7 @@
|
||||
namespace MiraAPI.Cosmetics;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
public class RegisterCustomCosmeticAttribute : Attribute
|
||||
public class RegisterCustomCosmeticAttribute(int priority = 0) : Attribute
|
||||
{
|
||||
public int Priority { get; } = 0;
|
||||
public RegisterCustomCosmeticAttribute(int priority=0)
|
||||
{
|
||||
Priority = priority;
|
||||
}
|
||||
}
|
||||
public int Priority { get; } = priority;
|
||||
}
|
||||
@@ -3,21 +3,29 @@
|
||||
namespace MiraAPI.Cosmetics;
|
||||
public class VanillaCosmeticsGroup : AbstractCosmeticsGroup
|
||||
{
|
||||
public override string GroupName { get; } = "Vanilla";
|
||||
internal HatData[] VanillaHats { get { return DestroyableSingleton<HatManager>.Instance.allHats; } }
|
||||
internal VisorData[] VanillaVisors { get { return DestroyableSingleton<HatManager>.Instance.allVisors; } }
|
||||
internal SkinData[] VanillaSkins { get { return DestroyableSingleton<HatManager>.Instance.allSkins; } }
|
||||
internal NamePlateData[] VanillaNameplates { get { return DestroyableSingleton<HatManager>.Instance.allNamePlates; } }
|
||||
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 readonly List<CosmeticData> Cosmetics = new();
|
||||
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;
|
||||
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);
|
||||
@@ -29,4 +37,4 @@ public class VanillaCosmeticsGroup : AbstractCosmeticsGroup
|
||||
Cosmetics.AddRange(Nameplates);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
using Reactor.Utilities;
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Reactor.Utilities;
|
||||
|
||||
namespace MiraAPI.GameModes;
|
||||
|
||||
@@ -21,7 +21,7 @@ public static class CustomGameModeManager
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Current gamemode.
|
||||
/// Gets current gamemode.
|
||||
/// </summary>
|
||||
public static CustomGameMode? ActiveMode { get; internal set; } = new DefaultMode();
|
||||
|
||||
@@ -29,7 +29,7 @@ public static class CustomGameModeManager
|
||||
/// Set current gamemode.
|
||||
/// </summary>
|
||||
/// <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))
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using MiraAPI.GameOptions.OptionTypes;
|
||||
using System;
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using MiraAPI.GameOptions.OptionTypes;
|
||||
|
||||
namespace MiraAPI.GameOptions.Attributes;
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using MiraAPI.GameOptions.OptionTypes;
|
||||
using MiraAPI.Utilities;
|
||||
using System;
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using MiraAPI.GameOptions.OptionTypes;
|
||||
using MiraAPI.Utilities;
|
||||
|
||||
namespace MiraAPI.GameOptions.Attributes;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using MiraAPI.GameOptions.OptionTypes;
|
||||
using System;
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using MiraAPI.GameOptions.OptionTypes;
|
||||
|
||||
namespace MiraAPI.GameOptions.Attributes;
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using AmongUs.GameOptions;
|
||||
using System;
|
||||
using AmongUs.GameOptions;
|
||||
using MiraAPI.Networking;
|
||||
using MiraAPI.Utilities;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
using BepInEx.Configuration;
|
||||
using System;
|
||||
using BepInEx.Configuration;
|
||||
using MiraAPI.Networking;
|
||||
using MiraAPI.PluginLoading;
|
||||
using MiraAPI.Roles;
|
||||
using Reactor.Localization.Utilities;
|
||||
using Reactor.Networking.Rpc;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.GameOptions.OptionTypes;
|
||||
@@ -45,7 +45,11 @@ public abstract class ModdedOption<T> : IModdedOption
|
||||
get => _parentMod;
|
||||
set
|
||||
{
|
||||
if (_parentMod != null || value == null) return;
|
||||
if (_parentMod != null || value == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_parentMod = value;
|
||||
var entry = _parentMod.GetConfigFile().Bind(ConfigDefinition, DefaultValue);
|
||||
Value = entry.Value;
|
||||
@@ -90,7 +94,11 @@ public abstract class ModdedOption<T> : IModdedOption
|
||||
get => _configDefinition;
|
||||
set
|
||||
{
|
||||
if (_configDefinition is not null) return;
|
||||
if (_configDefinition is not null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_configDefinition = value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using MiraAPI.Networking;
|
||||
using System;
|
||||
using System;
|
||||
using MiraAPI.Networking;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using MiraAPI.Modifiers.Types;
|
||||
using MiraAPI.Networking;
|
||||
using MiraAPI.PluginLoading;
|
||||
using MiraAPI.Roles;
|
||||
using MiraAPI.Utilities;
|
||||
using Reactor.Networking.Rpc;
|
||||
|
||||
@@ -11,7 +11,7 @@ public static class ScrollingColorsPatch
|
||||
private static BoxCollider2D? _collider;
|
||||
|
||||
/// <summary>
|
||||
/// Add scrolling to the colors tab
|
||||
/// Add scrolling to the colors tab.
|
||||
/// </summary>
|
||||
[HarmonyPostfix, HarmonyPatch("OnEnable")]
|
||||
public static void AddScrollingToColorsTabPatch(PlayerTab __instance)
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
using AmongUs.Data;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using AmongUs.Data;
|
||||
using HarmonyLib;
|
||||
using MiraAPI.Cosmetics;
|
||||
using MonoMod.Utils;
|
||||
using Reactor.Utilities;
|
||||
using Reactor.Utilities.Extensions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -28,11 +27,11 @@ public static class HatsTabPatch
|
||||
foreach (var colorchip in __instance.ColorChips) colorchip.gameObject.Destroy();
|
||||
__instance.ColorChips.Clear();
|
||||
var groupNameText = __instance.GetComponentInChildren<TextMeshPro>(false);
|
||||
int hatIdx = 0;
|
||||
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))
|
||||
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;
|
||||
@@ -45,16 +44,16 @@ public static class HatsTabPatch
|
||||
|
||||
hatIdx = (hatIdx + 4) / 5 * 5;
|
||||
|
||||
float xLerp = __instance.XRange.Lerp(0.5f);
|
||||
float yLerp = __instance.YStart - (hatIdx / __instance.NumPerRow) * __instance.YOffset;
|
||||
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)
|
||||
{
|
||||
float num = __instance.XRange.Lerp(hatIdx % __instance.NumPerRow / (__instance.NumPerRow - 1f));
|
||||
float num2 = __instance.YStart - hatIdx / __instance.NumPerRow * __instance.YOffset;
|
||||
ColorChip colorChip = UnityEngine.Object.Instantiate(__instance.ColorTabPrefab, __instance.scroller.Inner);
|
||||
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;
|
||||
|
||||
@@ -1,10 +1,5 @@
|
||||
using HarmonyLib;
|
||||
using MiraAPI.Cosmetics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MiraAPI.Patches.Cosmetics;
|
||||
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
using AmongUs.Data;
|
||||
using HarmonyLib;
|
||||
using MiraAPI.Cosmetics;
|
||||
using MonoMod.Utils;
|
||||
using Reactor.Utilities.Extensions;
|
||||
using System;
|
||||
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 MiraAPI.Utilities.Assets.Addressable;
|
||||
using Reactor.Utilities;
|
||||
using UnityEngine.ResourceManagement.AsyncOperations;
|
||||
using System.Collections;
|
||||
|
||||
namespace MiraAPI.Patches.Cosmetics;
|
||||
[HarmonyPatch(typeof(NameplatesTab), nameof(NameplatesTab.OnEnable))]
|
||||
@@ -20,24 +20,24 @@ public static class NameplatesTabPatch
|
||||
{
|
||||
public static bool Prefix(NameplatesTab __instance)
|
||||
{
|
||||
var Groups = new SortedList<AbstractCosmeticsGroup, List<NamePlateData>>(
|
||||
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);
|
||||
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);
|
||||
int hatIdx = 0;
|
||||
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))
|
||||
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;
|
||||
@@ -50,17 +50,17 @@ public static class NameplatesTabPatch
|
||||
|
||||
hatIdx = (hatIdx + 1) / 2 * 2;
|
||||
|
||||
float xLerp = __instance.XRange.Lerp(0.5f);
|
||||
float yLerp = __instance.YStart - (hatIdx / __instance.NumPerRow) * __instance.YOffset;
|
||||
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)
|
||||
{
|
||||
float num = __instance.XRange.Lerp(hatIdx % __instance.NumPerRow / (__instance.NumPerRow - 1f));
|
||||
float num2 = __instance.YStart - hatIdx / __instance.NumPerRow * __instance.YOffset;
|
||||
var num = __instance.XRange.Lerp(hatIdx % __instance.NumPerRow / (__instance.NumPerRow - 1f));
|
||||
var num2 = __instance.YStart - hatIdx / __instance.NumPerRow * __instance.YOffset;
|
||||
|
||||
ColorChip colorChip = UnityEngine.Object.Instantiate(__instance.ColorTabPrefab, __instance.scroller.Inner);
|
||||
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)));
|
||||
@@ -83,7 +83,7 @@ public static class NameplatesTabPatch
|
||||
return false;
|
||||
}
|
||||
|
||||
static IEnumerator SetupColorChip(NameplateChip colorChip, AsyncOperationHandle<NamePlateViewData> handle)
|
||||
private static IEnumerator SetupColorChip(NameplateChip colorChip, AsyncOperationHandle<NamePlateViewData> handle)
|
||||
{
|
||||
yield return new WaitForAsyncOperationHandleFinish(handle);
|
||||
colorChip.image.sprite = handle.Result?.Image;
|
||||
|
||||
@@ -1,23 +1,18 @@
|
||||
using AmongUs.Data;
|
||||
using HarmonyLib;
|
||||
using MiraAPI.Cosmetics;
|
||||
using MonoMod.Utils;
|
||||
using Reactor.Utilities.Extensions;
|
||||
using Sentry;
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
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 static Rewired.Controller;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using System.Drawing;
|
||||
using System.Collections;
|
||||
using UnityEngine.ResourceManagement.AsyncOperations;
|
||||
using Reactor.Utilities;
|
||||
using MiraAPI.Utilities.Assets.Addressable;
|
||||
|
||||
namespace MiraAPI.Patches.Cosmetics;
|
||||
[HarmonyPatch(typeof(SkinsTab), nameof(SkinsTab.OnEnable))]
|
||||
@@ -25,20 +20,20 @@ public static class SkinsTabPatch
|
||||
{
|
||||
public static bool Prefix(SkinsTab __instance)
|
||||
{
|
||||
var Groups = new SortedList<AbstractCosmeticsGroup, List<SkinData>>(
|
||||
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);
|
||||
groups.AddRange<AbstractCosmeticsGroup, List<SkinData>>(c);
|
||||
|
||||
foreach (var colorchip in __instance.ColorChips) colorchip.gameObject.Destroy();
|
||||
__instance.ColorChips.Clear();
|
||||
var groupNameText = __instance.GetComponentInChildren<TextMeshPro>(false);
|
||||
int hatIdx = 0;
|
||||
var hatIdx = 0;
|
||||
|
||||
foreach (var (group, skins) in Groups.Where(x => x.Key.GroupVisible() && x.Key.Skins.Count > 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;
|
||||
@@ -51,16 +46,16 @@ public static class SkinsTabPatch
|
||||
|
||||
hatIdx = (hatIdx + 4) / 5 * 5;
|
||||
|
||||
float xLerp = __instance.XRange.Lerp(0.5f);
|
||||
float yLerp = __instance.YStart - (hatIdx / __instance.NumPerRow) * __instance.YOffset;
|
||||
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)
|
||||
{
|
||||
float num = __instance.XRange.Lerp(hatIdx % __instance.NumPerRow / (__instance.NumPerRow - 1f));
|
||||
float num2 = __instance.YStart - hatIdx / __instance.NumPerRow * __instance.YOffset;
|
||||
ColorChip colorChip = UnityEngine.Object.Instantiate(__instance.ColorTabPrefab, __instance.scroller.Inner);
|
||||
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;
|
||||
|
||||
@@ -1,20 +1,18 @@
|
||||
using AmongUs.Data;
|
||||
using HarmonyLib;
|
||||
using MiraAPI.Cosmetics;
|
||||
using MonoMod.Utils;
|
||||
using Reactor.Utilities.Extensions;
|
||||
using Reactor.Utilities;
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TMPro;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using UnityEngine;
|
||||
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;
|
||||
using System.Collections;
|
||||
|
||||
namespace MiraAPI.Patches.Cosmetics;
|
||||
[HarmonyPatch(typeof(VisorsTab), nameof(VisorsTab.OnEnable))]
|
||||
@@ -22,20 +20,20 @@ public static class VisorsTabPatch
|
||||
{
|
||||
public static bool Prefix(VisorsTab __instance)
|
||||
{
|
||||
var Groups = new SortedList<AbstractCosmeticsGroup, List<VisorData>>(
|
||||
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);
|
||||
groups.AddRange<AbstractCosmeticsGroup, List<VisorData>>(c);
|
||||
|
||||
foreach (var colorchip in __instance.ColorChips) colorchip.gameObject.Destroy();
|
||||
__instance.ColorChips.Clear();
|
||||
var groupNameText = __instance.GetComponentInChildren<TextMeshPro>(false);
|
||||
int hatIdx = 0;
|
||||
var hatIdx = 0;
|
||||
|
||||
foreach (var (group, visors) in Groups.Where(x => x.Key.GroupVisible() && x.Key.Visors.Count > 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;
|
||||
@@ -48,16 +46,16 @@ public static class VisorsTabPatch
|
||||
|
||||
hatIdx = (hatIdx + 4) / 5 * 5;
|
||||
|
||||
float xLerp = __instance.XRange.Lerp(0.5f);
|
||||
float yLerp = __instance.YStart - (hatIdx / __instance.NumPerRow) * __instance.YOffset;
|
||||
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)
|
||||
{
|
||||
float num = __instance.XRange.Lerp(hatIdx % __instance.NumPerRow / (__instance.NumPerRow - 1f));
|
||||
float num2 = __instance.YStart - hatIdx / __instance.NumPerRow * __instance.YOffset;
|
||||
ColorChip colorChip = UnityEngine.Object.Instantiate(__instance.ColorTabPrefab, __instance.scroller.Inner);
|
||||
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;
|
||||
|
||||
@@ -4,7 +4,7 @@ using MiraAPI.Hud;
|
||||
namespace MiraAPI.Patches.Hud;
|
||||
|
||||
/// <summary>
|
||||
/// Reset button patches
|
||||
/// Reset button patches.
|
||||
/// </summary>
|
||||
[HarmonyPatch]
|
||||
public static class ButtonResetPatches
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using HarmonyLib;
|
||||
using MiraAPI.Hud;
|
||||
using MiraAPI.Roles;
|
||||
using Reactor.Utilities.Extensions;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
using HarmonyLib;
|
||||
using System.Linq;
|
||||
using HarmonyLib;
|
||||
using MiraAPI.Utilities;
|
||||
using MiraAPI.Utilities.Assets;
|
||||
using Reactor.Localization.Utilities;
|
||||
using Reactor.Utilities.Extensions;
|
||||
using System.Linq;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
using HarmonyLib;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using HarmonyLib;
|
||||
using MiraAPI.PluginLoading;
|
||||
using MiraAPI.Utilities.Assets;
|
||||
using Reactor.Utilities.Extensions;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
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.Roles;
|
||||
using MiraAPI.Utilities;
|
||||
using MiraAPI.Utilities.Assets;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.UI;
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
using HarmonyLib;
|
||||
using System.Linq;
|
||||
using HarmonyLib;
|
||||
using Il2CppSystem;
|
||||
using MiraAPI.Roles;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using Object = Il2CppSystem.Object;
|
||||
|
||||
namespace MiraAPI.Patches.Options;
|
||||
|
||||
@@ -23,9 +25,13 @@ public static class NotificationPopperPatch
|
||||
return true;
|
||||
}
|
||||
|
||||
var text = teamType == RoleTeamTypes.Crewmate
|
||||
? Palette.CrewmateSettingChangeText.ToTextColor()
|
||||
: Palette.ImpostorRed.ToTextColor();
|
||||
var text = customRole.Team switch
|
||||
{
|
||||
ModdedRoleTeams.Crewmate => Palette.CrewmateSettingChangeText.ToTextColor(),
|
||||
ModdedRoleTeams.Impostor => Palette.ImpostorRed.ToTextColor(),
|
||||
ModdedRoleTeams.Neutral => Palette.DisabledGrey.ToTextColor(),
|
||||
_ => Color.white.ToTextColor(),
|
||||
};
|
||||
|
||||
var item = TranslationController.Instance.GetString(
|
||||
StringNames.LobbyChangeSettingNotificationRole,
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using HarmonyLib;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using HarmonyLib;
|
||||
using Il2CppInterop.Runtime.InteropTypes.Arrays;
|
||||
using MiraAPI.Networking;
|
||||
using MiraAPI.Roles;
|
||||
@@ -7,8 +9,6 @@ using MiraAPI.Utilities.Assets;
|
||||
using Reactor.Networking.Rpc;
|
||||
using Reactor.Utilities;
|
||||
using Reactor.Utilities.Extensions;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
@@ -32,6 +32,7 @@ public static class PlayerControlPatches
|
||||
/// Calls the OnDeath method for all active modifiers.
|
||||
/// </summary>
|
||||
/// <param name="__instance">PlayerControl instance.</param>
|
||||
/// <param name="reason">The death reason.</param>
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(nameof(PlayerControl.Die))]
|
||||
public static void PlayerControlDiePostfix(PlayerControl __instance, DeathReason reason)
|
||||
|
||||
@@ -9,7 +9,7 @@ public static class GameStartupPatch
|
||||
private static bool _runOnce;
|
||||
|
||||
/// <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>
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(nameof(MainMenuManager.Start))]
|
||||
|
||||
@@ -4,7 +4,7 @@ using UnityEngine;
|
||||
namespace MiraAPI.Patches.Roles;
|
||||
|
||||
/// <summary>
|
||||
/// Set nametag color depending on option
|
||||
/// Set nametag color depending on option.
|
||||
/// </summary>
|
||||
[HarmonyPatch(typeof(PlayerNameColor))]
|
||||
public static class NameTagPatch
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace MiraAPI.Patches.Roles;
|
||||
public static class RoleBehaviourPatches
|
||||
{
|
||||
/// <summary>
|
||||
/// Update TeamColor text for Launchpad roles
|
||||
/// Update TeamColor text for custom roles.
|
||||
/// </summary>
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(nameof(RoleBehaviour.TeamColor), MethodType.Getter)]
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
using AmongUs.GameOptions;
|
||||
using System.Linq;
|
||||
using AmongUs.GameOptions;
|
||||
using HarmonyLib;
|
||||
using MiraAPI.Modifiers;
|
||||
using MiraAPI.Roles;
|
||||
using System.Linq;
|
||||
|
||||
namespace MiraAPI.Patches.Roles;
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace MiraAPI.Patches.Roles;
|
||||
public static class RoleOptionsCollectionPatch
|
||||
{
|
||||
/// <summary>
|
||||
/// Set the role chance for custom Launchpad roles based on config
|
||||
/// Set the role chance for custom Launchpad roles based on config.
|
||||
/// </summary>
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(nameof(RoleOptionsCollectionV08.GetChancePerGame))]
|
||||
@@ -31,7 +31,7 @@ public static class RoleOptionsCollectionPatch
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the amount for custom Launchpad roles based on config
|
||||
/// Set the amount for custom Launchpad roles based on config.
|
||||
/// </summary>
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(nameof(RoleOptionsCollectionV08.GetNumPerGame))]
|
||||
|
||||
@@ -4,7 +4,7 @@ using MiraAPI.Roles;
|
||||
namespace MiraAPI.Patches.Roles;
|
||||
|
||||
[HarmonyPatch(typeof(SabotageButton))]
|
||||
public class SabotageButtonPatch
|
||||
public static class SabotageButtonPatch
|
||||
{
|
||||
/// <summary>
|
||||
/// Patches the Sabotage button to check if the player's custom role can use sabotage.
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
using AmongUs.GameOptions;
|
||||
using HarmonyLib;
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using AmongUs.GameOptions;
|
||||
using HarmonyLib;
|
||||
using MiraAPI.PluginLoading;
|
||||
using MiraAPI.Roles;
|
||||
using MiraAPI.Utilities.Assets;
|
||||
using System.Linq;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
@@ -1,14 +1,10 @@
|
||||
using BepInEx;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using BepInEx;
|
||||
using BepInEx.Configuration;
|
||||
using MiraAPI.GameModes;
|
||||
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.Roles;
|
||||
|
||||
namespace MiraAPI.PluginLoading;
|
||||
|
||||
|
||||
@@ -59,11 +59,11 @@ public sealed class MiraPluginManager
|
||||
/// <summary>
|
||||
/// Get a mira plugin by its GUID.
|
||||
/// </summary>
|
||||
/// <param name="guid">The plugin GUID.</param>
|
||||
/// <param name="uniqueId">The plugin GUID.</param>
|
||||
/// <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)
|
||||
|
||||
@@ -39,6 +39,8 @@ public struct CustomRoleConfiguration
|
||||
CanModifyChance = true;
|
||||
}
|
||||
|
||||
#pragma warning disable S1104
|
||||
#pragma warning disable CA1051
|
||||
/// <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.
|
||||
/// </summary>
|
||||
@@ -123,4 +125,6 @@ public struct CustomRoleConfiguration
|
||||
/// Gets the Ghost role that is applied when the player is killed.
|
||||
/// </summary>
|
||||
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.Injection;
|
||||
using MiraAPI.Networking;
|
||||
@@ -8,9 +11,6 @@ using Reactor.Localization.Utilities;
|
||||
using Reactor.Networking.Rpc;
|
||||
using Reactor.Utilities;
|
||||
using Reactor.Utilities.Extensions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace MiraAPI.Roles;
|
||||
/// <typeparam name="T">The role you are trying to access.</typeparam>
|
||||
public static class CustomRoleSingleton<T> where T : ICustomRole
|
||||
{
|
||||
private static ICustomRole? _instance;
|
||||
private static T? _instance;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the instance of the role.
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
using BepInEx.Configuration;
|
||||
using System.Text;
|
||||
using BepInEx.Configuration;
|
||||
using MiraAPI.Modifiers;
|
||||
using MiraAPI.PluginLoading;
|
||||
using MiraAPI.Utilities;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.Roles;
|
||||
@@ -38,7 +38,7 @@ public interface ICustomRole
|
||||
ModdedRoleTeams Team { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Configure advanced settings of the role.
|
||||
/// Gets the advanced settings of the role.
|
||||
/// </summary>
|
||||
CustomRoleConfiguration Configuration { get; }
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using BepInEx.Unity.IL2CPP.Utils.Collections;
|
||||
using System.Collections;
|
||||
using BepInEx.Unity.IL2CPP.Utils.Collections;
|
||||
using Reactor.Utilities;
|
||||
using System.Collections;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using UnityEngine.AddressableAssets.ResourceLocators;
|
||||
using UnityEngine.ResourceManagement.AsyncOperations;
|
||||
@@ -15,7 +15,8 @@ public class Catalog(string CatalogPath)
|
||||
/// <summary>
|
||||
/// Loads the catalog asynchronously.
|
||||
/// </summary>
|
||||
public void LoadCatalogAsync() {
|
||||
public void LoadCatalogAsync()
|
||||
{
|
||||
Coroutines.Start(LoadCatalogAsynchronously());
|
||||
}
|
||||
|
||||
@@ -48,4 +49,4 @@ public class Catalog(string CatalogPath)
|
||||
yield return updateHandle;
|
||||
updateHandle.Release();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
using BepInEx.Unity.IL2CPP.Utils.Collections;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.IO;
|
||||
using BepInEx.Unity.IL2CPP.Utils.Collections;
|
||||
using UnityEngine.AddressableAssets;
|
||||
|
||||
namespace MiraAPI.Utilities.Assets.Addressable;
|
||||
@@ -13,18 +12,18 @@ 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>
|
||||
/// <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(Assembly.GetAssembly(typeof(MiraApiPlugin)).Location) + $"\\{fileName}.catalog";
|
||||
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>
|
||||
/// <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();
|
||||
@@ -33,11 +32,11 @@ public static class CatalogTools
|
||||
/// <summary>
|
||||
/// Finds the resource locations of multiple specific labels.
|
||||
/// </summary>
|
||||
/// <param name="label">The label of the addressables assets</param>
|
||||
/// <returns>An IList of IResourceLocation</returns>
|
||||
/// <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();
|
||||
var il2CPPLabels = new Il2CppSystem.Collections.Generic.IList<Il2CppSystem.Object>(labels.WrapToIl2Cpp().Pointer);
|
||||
return Addressables.LoadResourceLocationsAsync(il2CPPLabels, Addressables.MergeMode.Union).WaitForCompletion();
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,19 @@
|
||||
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>
|
||||
/// 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 handle.PercentComplete != 1.0f && !handle.IsDone;
|
||||
return !Mathf.Approximately(handle.PercentComplete, 1.0f) && !handle.IsDone;
|
||||
}
|
||||
public void Reset()
|
||||
{
|
||||
|
||||
@@ -6,29 +6,29 @@ 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
|
||||
/// <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>
|
||||
/// <returns>The asset.</returns>
|
||||
/// <exception cref="Exception">The asset did not load properly.</exception>
|
||||
public override T LoadAsset()
|
||||
{
|
||||
if (LoadedAsset)
|
||||
if (LoadedAsset != null)
|
||||
{
|
||||
return LoadedAsset;
|
||||
}
|
||||
|
||||
LoadedAsset = Addressables.LoadAssetAsync<T>(name).WaitForCompletion();
|
||||
|
||||
if (!LoadedAsset)
|
||||
if (LoadedAsset == null)
|
||||
{
|
||||
throw new Exception($"INVALID ASSET: {name}");
|
||||
throw new InvalidOperationException($"INVALID ASSET: {name}");
|
||||
}
|
||||
|
||||
return LoadedAsset;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,17 +8,18 @@ namespace MiraAPI.Utilities.Assets;
|
||||
/// 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>
|
||||
/// <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>
|
||||
/// A reference to the loaded assets. Intended to be used for caching purposes.
|
||||
/// Gets or sets a reference to the loaded assets. Intended to be used for caching purposes.
|
||||
/// </summary>
|
||||
protected List<T> LoadedAsset = new();
|
||||
protected List<T> LoadedAsset { get; set; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Loads the assets from the addressables api.
|
||||
/// </summary>
|
||||
/// <returns>The assets</returns>
|
||||
/// <returns>The assets.</returns>
|
||||
/// <exception cref="Exception">The asset did not load properly.</exception>
|
||||
public List<T> LoadAsset()
|
||||
{
|
||||
@@ -29,13 +30,13 @@ public class LoadableAddressableGroupAsset<T>(Il2CppSystem.Collections.Generic.I
|
||||
|
||||
var assets = Addressables.LoadAssetsAsync<T>(locations, null, false).WaitForCompletion();
|
||||
var array = new Il2CppSystem.Collections.Generic.List<T>(assets.Pointer);
|
||||
LoadedAsset = new List<T>(array.ToArray());
|
||||
LoadedAsset = [..array.ToArray()];
|
||||
|
||||
if (LoadedAsset is null || LoadedAsset.Count == 0)
|
||||
{
|
||||
throw new Exception($"INVALID ASSET LOCATION/s");
|
||||
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.Linq;
|
||||
using System.Text;
|
||||
using MiraAPI.Roles;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
Reference in new issue
Block a user