mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-10-28 19:43:55 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
34b89c5c46 |
No files matched your search
+1
-1
@@ -2,7 +2,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Reactor" Version="2.3.1" />
|
<PackageReference Include="Reactor" Version="2.3.1" />
|
||||||
<PackageReference Include="BepInEx.Unity.IL2CPP" Version="6.0.0-be.697" Private="false" ExcludeAssets="runtime;native" />
|
<PackageReference Include="BepInEx.Unity.IL2CPP" Version="6.0.0-be.697" Private="false" ExcludeAssets="runtime;native" />
|
||||||
<PackageReference Include="AmongUs.GameLibs.Steam" Version="2024.9.4" PrivateAssets="all" />
|
<PackageReference Include="AmongUs.GameLibs.Steam" Version="2024.8.13" PrivateAssets="all" />
|
||||||
|
|
||||||
<PackageReference Include="BepInEx.AutoPlugin" Version="1.1.0" PrivateAssets="all" />
|
<PackageReference Include="BepInEx.AutoPlugin" Version="1.1.0" PrivateAssets="all" />
|
||||||
<PackageReference Include="BepInEx.IL2CPP.MSBuild" Version="2.0.1" PrivateAssets="all" ExcludeAssets="runtime" />
|
<PackageReference Include="BepInEx.IL2CPP.MSBuild" Version="2.0.1" PrivateAssets="all" ExcludeAssets="runtime" />
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
|
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
|
||||||
|
|
||||||
<VersionPrefix>0.1.6</VersionPrefix>
|
<VersionPrefix>0.1.4</VersionPrefix>
|
||||||
<VersionSuffix>dev</VersionSuffix>
|
<VersionSuffix>dev</VersionSuffix>
|
||||||
|
|
||||||
<Authors>All Of Us, XtraCube, Angxl</Authors>
|
<Authors>All Of Us, XtraCube, Angxl</Authors>
|
||||||
|
|||||||
@@ -43,4 +43,4 @@ public class ChameloenRole : CrewmateRole, ICustomRole
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
using MiraAPI.Animations;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace MiraAPI.Modifiers;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The manager for handling modifiers.
|
||||||
|
/// </summary>
|
||||||
|
public static class AnimationPresetManager
|
||||||
|
{
|
||||||
|
private static uint _nextId;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets registered Animation Presets.
|
||||||
|
/// </summary>
|
||||||
|
public static List<CustomAnimationPreset> Presets { get; internal set; } = new List<CustomAnimationPreset>();
|
||||||
|
|
||||||
|
private static uint GetNextId()
|
||||||
|
{
|
||||||
|
_nextId++;
|
||||||
|
return _nextId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get Animation Preset by ID.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">The id of the preset you want to find.</param>
|
||||||
|
/// <returns>The animation preset.</returns>
|
||||||
|
public static CustomAnimationPreset? GetPresetById(uint id)
|
||||||
|
{
|
||||||
|
return Presets.Find(p => p.Id == id);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static void RegisterPreset(Type modifierType)
|
||||||
|
{
|
||||||
|
if (!typeof(CustomAnimationPreset).IsAssignableFrom(modifierType))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
CustomAnimationPreset preset = (CustomAnimationPreset)Activator.CreateInstance(modifierType);
|
||||||
|
preset.Id = GetNextId();
|
||||||
|
Presets.Add(preset);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace MiraAPI.Animations;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Configure an animation's settings using presets.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="clip">The animation clip the preset will use.</param>
|
||||||
|
public abstract class CustomAnimationPreset(AnimationClip clip)
|
||||||
|
{
|
||||||
|
internal uint Id;
|
||||||
|
|
||||||
|
internal void PlayAnimation(PlayerControl source)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Check whether the local player should be able to see this animation.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="source">The player who the animation is being triggered upon.</param>
|
||||||
|
/// <returns>Whether the local player can see the animation or not.</returns>
|
||||||
|
public abstract bool AnimationVisible(PlayerControl source);
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
using MiraAPI.Animations.Presets;
|
||||||
|
using MiraAPI.Modifiers;
|
||||||
|
using MiraAPI.Networking;
|
||||||
|
using MiraAPI.Utilities;
|
||||||
|
using Reactor.Networking.Attributes;
|
||||||
|
using Reactor.Utilities.Attributes;
|
||||||
|
using System;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace MiraAPI.Animations;
|
||||||
|
|
||||||
|
[RegisterInIl2Cpp]
|
||||||
|
public class CustomAnimator(IntPtr cppPtr) : MonoBehaviour(cppPtr)
|
||||||
|
{
|
||||||
|
private PlayerControl _player;
|
||||||
|
|
||||||
|
private void Start()
|
||||||
|
{
|
||||||
|
_player = gameObject.GetComponent<PlayerControl>();
|
||||||
|
|
||||||
|
_player.GetCustomAnimator()?.TriggerCustomAnimation(new LocalAnimationPreset(new AnimationClip()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void TriggerCustomAnimation(CustomAnimationPreset preset) => RpcTriggerCustomAnimation(_player, preset.Id);
|
||||||
|
|
||||||
|
|
||||||
|
[MethodRpc((uint)MiraRpc.TriggerAnimation)]
|
||||||
|
internal static void RpcTriggerCustomAnimation(PlayerControl source, uint presetId)
|
||||||
|
{
|
||||||
|
CustomAnimationPreset preset = AnimationPresetManager.GetPresetById(presetId);
|
||||||
|
if (preset is null) return;
|
||||||
|
|
||||||
|
if (preset.AnimationVisible(source))
|
||||||
|
{
|
||||||
|
preset.PlayAnimation(source);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace MiraAPI.Animations.Presets;
|
||||||
|
public class LocalAnimationPreset(AnimationClip clip) : CustomAnimationPreset(clip)
|
||||||
|
{
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public override bool AnimationVisible(PlayerControl source)
|
||||||
|
{
|
||||||
|
return source.AmOwner;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace MiraAPI.Animations;
|
||||||
|
|
||||||
|
[AttributeUsage(AttributeTargets.Class)]
|
||||||
|
public class RegisterAnimationPresetAttribute : Attribute;
|
||||||
@@ -12,7 +12,7 @@ internal interface IModdedOption
|
|||||||
string Title { get; }
|
string Title { get; }
|
||||||
StringNames StringName { get; }
|
StringNames StringName { get; }
|
||||||
IMiraPlugin? ParentMod { get; set; }
|
IMiraPlugin? ParentMod { get; set; }
|
||||||
BaseGameSetting Data { get; }
|
BaseGameSetting? Data { get; }
|
||||||
Type? AdvancedRole { get; set; }
|
Type? AdvancedRole { get; set; }
|
||||||
OptionBehaviour? OptionBehaviour { get; }
|
OptionBehaviour? OptionBehaviour { get; }
|
||||||
Func<bool> Visible { get; set; }
|
Func<bool> Visible { get; set; }
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ public abstract class ModdedOption<T> : IModdedOption
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the BaseGameSetting data of the option.
|
/// Gets the BaseGameSetting data of the option.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public BaseGameSetting Data { get; protected init; }
|
public BaseGameSetting? Data { get; protected init; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the parent mod of the option.
|
/// Gets or sets the parent mod of the option.
|
||||||
|
|||||||
@@ -34,4 +34,9 @@ public enum MiraRpc : uint
|
|||||||
/// Custom Murder RPC.
|
/// Custom Murder RPC.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
CustomMurder,
|
CustomMurder,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Trigger Animation using CustomAnimator.
|
||||||
|
/// </summary>
|
||||||
|
TriggerAnimation,
|
||||||
}
|
}
|
||||||
@@ -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;
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ using MiraAPI.PluginLoading;
|
|||||||
using MiraAPI.Roles;
|
using MiraAPI.Roles;
|
||||||
using MiraAPI.Utilities;
|
using MiraAPI.Utilities;
|
||||||
using MiraAPI.Utilities.Assets;
|
using MiraAPI.Utilities.Assets;
|
||||||
using Reactor.Utilities;
|
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.Events;
|
using UnityEngine.Events;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
@@ -129,6 +128,11 @@ public static class LobbyViewPanePatches
|
|||||||
|
|
||||||
foreach (var group in filteredGroups)
|
foreach (var group in filteredGroups)
|
||||||
{
|
{
|
||||||
|
if (group.Options.Count == 0)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
var categoryHeaderMasked = Object.Instantiate(
|
var categoryHeaderMasked = Object.Instantiate(
|
||||||
instance.categoryHeaderOrigin,
|
instance.categoryHeaderOrigin,
|
||||||
instance.settingsContainer,
|
instance.settingsContainer,
|
||||||
@@ -172,6 +176,11 @@ public static class LobbyViewPanePatches
|
|||||||
|
|
||||||
var data = option.Data;
|
var data = option.Data;
|
||||||
|
|
||||||
|
if (data == null)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (data.Type == OptionTypes.Checkbox)
|
if (data.Type == OptionTypes.Checkbox)
|
||||||
{
|
{
|
||||||
viewSettingsInfoPanel.SetInfoCheckbox(
|
viewSettingsInfoPanel.SetInfoCheckbox(
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ public static class NotificationPopperPatch
|
|||||||
[HarmonyArgument(3)] RoleTeamTypes teamType,
|
[HarmonyArgument(3)] RoleTeamTypes teamType,
|
||||||
[HarmonyArgument(4)] bool playSound)
|
[HarmonyArgument(4)] bool playSound)
|
||||||
{
|
{
|
||||||
if (CustomRoleManager.CustomRoles.Values.FirstOrDefault(x=>x.StringName==key) is not ICustomRole customRole)
|
if (CustomRoleManager.CustomRoles.Values.All(role => role.StringName != key))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -29,12 +29,10 @@ public static class NotificationPopperPatch
|
|||||||
|
|
||||||
var item = DestroyableSingleton<TranslationController>.Instance.GetString(
|
var item = DestroyableSingleton<TranslationController>.Instance.GetString(
|
||||||
StringNames.LobbyChangeSettingNotificationRole,
|
StringNames.LobbyChangeSettingNotificationRole,
|
||||||
string.Concat(
|
"<font=\"Barlow-Black SDF\" material=\"Barlow-Black Outline\">",
|
||||||
"<font=\"Barlow-Black SDF\" material=\"Barlow-Black Outline\">",
|
text,
|
||||||
text,
|
DestroyableSingleton<TranslationController>.Instance.GetString(key, Array.Empty<Object>()),
|
||||||
DestroyableSingleton<TranslationController>.Instance.GetString(key, Array.Empty<Object>()),
|
"</color></font>",
|
||||||
"</color></font>"
|
|
||||||
),
|
|
||||||
"<font=\"Barlow-Black SDF\" material=\"Barlow-Black Outline\">" + roleCount + "</font>",
|
"<font=\"Barlow-Black SDF\" material=\"Barlow-Black Outline\">" + roleCount + "</font>",
|
||||||
"<font=\"Barlow-Black SDF\" material=\"Barlow-Black Outline\">" + roleChance + "%"
|
"<font=\"Barlow-Black SDF\" material=\"Barlow-Black Outline\">" + roleChance + "%"
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ public static class SettingPatches
|
|||||||
MiraNumberSuffixes.Percent => value.ToString(__instance.FormatString, NumberFormatInfo.InvariantInfo) + "%",
|
MiraNumberSuffixes.Percent => value.ToString(__instance.FormatString, NumberFormatInfo.InvariantInfo) + "%",
|
||||||
_ => DestroyableSingleton<TranslationController>.Instance.GetString(
|
_ => DestroyableSingleton<TranslationController>.Instance.GetString(
|
||||||
StringNames.GameSecondsAbbrev,
|
StringNames.GameSecondsAbbrev,
|
||||||
(Il2CppSystem.Object[])[value.ToString(__instance.FormatString, CultureInfo.InvariantCulture)]),
|
(Il2CppSystem.Object[]) [value.ToString(__instance.FormatString, CultureInfo.InvariantCulture)]),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
|
using MiraAPI.Animations;
|
||||||
using MiraAPI.Hud;
|
using MiraAPI.Hud;
|
||||||
using MiraAPI.Modifiers;
|
using MiraAPI.Modifiers;
|
||||||
using MiraAPI.Roles;
|
using MiraAPI.Roles;
|
||||||
@@ -13,8 +14,9 @@ namespace MiraAPI.Patches;
|
|||||||
public static class PlayerControlPatches
|
public static class PlayerControlPatches
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds the modifier component to the player on start.
|
/// Adds the modifier and animator component to the player on start.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <param name="__instance">The player which will be given the components.</param>
|
||||||
[HarmonyPrefix]
|
[HarmonyPrefix]
|
||||||
[HarmonyPatch(nameof(PlayerControl.Start))]
|
[HarmonyPatch(nameof(PlayerControl.Start))]
|
||||||
public static void PlayerControlStartPostfix(PlayerControl __instance)
|
public static void PlayerControlStartPostfix(PlayerControl __instance)
|
||||||
@@ -24,12 +26,20 @@ public static class PlayerControlPatches
|
|||||||
comp.DestroyImmediate();
|
comp.DestroyImmediate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (__instance.gameObject.TryGetComponent<CustomAnimator>(out var anim))
|
||||||
|
{
|
||||||
|
anim.DestroyImmediate();
|
||||||
|
}
|
||||||
|
|
||||||
|
__instance.gameObject.AddComponent<CustomAnimator>();
|
||||||
__instance.gameObject.AddComponent<ModifierComponent>();
|
__instance.gameObject.AddComponent<ModifierComponent>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Calls the OnDeath method for all active modifiers.
|
/// Calls the OnDeath method for all active modifiers.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <param name="__instance">The player who died.</param>
|
||||||
|
/// <param name="reason">The reason of the death.</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)
|
||||||
@@ -38,13 +48,14 @@ public static class PlayerControlPatches
|
|||||||
|
|
||||||
if (modifiersComponent)
|
if (modifiersComponent)
|
||||||
{
|
{
|
||||||
modifiersComponent.ActiveModifiers.ForEach(x=>x.OnDeath(reason));
|
modifiersComponent.ActiveModifiers.ForEach(x => x.OnDeath(reason));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// FixedUpdate handler for custom roles and custom buttons.
|
/// FixedUpdate handler for custom roles and custom buttons.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <param name="__instance">The player who's fixed update is being called.</param>
|
||||||
[HarmonyPostfix]
|
[HarmonyPostfix]
|
||||||
[HarmonyPatch(nameof(PlayerControl.FixedUpdate))]
|
[HarmonyPatch(nameof(PlayerControl.FixedUpdate))]
|
||||||
public static void PlayerControlFixedUpdatePostfix(PlayerControl __instance)
|
public static void PlayerControlFixedUpdatePostfix(PlayerControl __instance)
|
||||||
|
|||||||
@@ -27,11 +27,10 @@ public static class HudManagerPatches
|
|||||||
{
|
{
|
||||||
var flag = localPlayer.Data != null && localPlayer.Data.IsDead;
|
var flag = localPlayer.Data != null && localPlayer.Data.IsDead;
|
||||||
|
|
||||||
if (role is ICustomRole customRole)
|
if (role is ICustomRole)
|
||||||
{
|
{
|
||||||
__instance.KillButton.ToggleVisible(isActive && role.CanUseKillButton && !flag);
|
__instance.KillButton.ToggleVisible(isActive && role.CanUseKillButton && !flag);
|
||||||
__instance.ImpostorVentButton.ToggleVisible(isActive && role.CanVent && !flag);
|
__instance.ImpostorVentButton.ToggleVisible(isActive && role.CanVent && !flag);
|
||||||
__instance.SabotageButton.gameObject.SetActive(isActive && customRole.CanUseSabotage);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_roleTab)
|
if (_roleTab)
|
||||||
|
|||||||
@@ -1,62 +0,0 @@
|
|||||||
using HarmonyLib;
|
|
||||||
using MiraAPI.Roles;
|
|
||||||
|
|
||||||
namespace MiraAPI.Patches.Roles;
|
|
||||||
|
|
||||||
[HarmonyPatch(typeof(SabotageButton))]
|
|
||||||
public class SabotageButtonPatch
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Patches the Sabotage button to check if the player's custom role can use sabotage.
|
|
||||||
/// </summary>
|
|
||||||
[HarmonyPatch(nameof(SabotageButton.DoClick))]
|
|
||||||
[HarmonyPrefix]
|
|
||||||
public static bool DoClickPrefix(SabotageButton __instance)
|
|
||||||
{
|
|
||||||
var player = PlayerControl.LocalPlayer;
|
|
||||||
|
|
||||||
if (player.Data.Role is not ICustomRole customRole)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!customRole.CanUseSabotage || PlayerControl.LocalPlayer.inVent || !GameManager.Instance.SabotagesEnabled())
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
DestroyableSingleton<HudManager>.Instance.ToggleMapVisible(
|
|
||||||
new MapOptions
|
|
||||||
{
|
|
||||||
Mode = MapOptions.Modes.Sabotage,
|
|
||||||
});
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
[HarmonyPrefix]
|
|
||||||
[HarmonyPatch(nameof(SabotageButton.Refresh))]
|
|
||||||
public static bool RefreshPrefix(SabotageButton __instance)
|
|
||||||
{
|
|
||||||
var player = PlayerControl.LocalPlayer;
|
|
||||||
if (GameManager.Instance == null || player == null)
|
|
||||||
{
|
|
||||||
__instance.ToggleVisible(false);
|
|
||||||
__instance.SetDisabled();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (player.Data.Role is not ICustomRole customRole)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (player.inVent || !GameManager.Instance.SabotagesEnabled() || player.petting)
|
|
||||||
{
|
|
||||||
__instance.ToggleVisible(customRole.CanUseSabotage && GameManager.Instance.SabotagesEnabled());
|
|
||||||
__instance.SetDisabled();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
__instance.SetEnabled();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,8 +1,5 @@
|
|||||||
using System;
|
using BepInEx.Unity.IL2CPP;
|
||||||
using System.Collections.Generic;
|
using MiraAPI.Animations;
|
||||||
using System.Linq;
|
|
||||||
using System.Reflection;
|
|
||||||
using BepInEx.Unity.IL2CPP;
|
|
||||||
using MiraAPI.Colors;
|
using MiraAPI.Colors;
|
||||||
using MiraAPI.GameOptions;
|
using MiraAPI.GameOptions;
|
||||||
using MiraAPI.GameOptions.Attributes;
|
using MiraAPI.GameOptions.Attributes;
|
||||||
@@ -10,17 +7,29 @@ using MiraAPI.Hud;
|
|||||||
using MiraAPI.Modifiers;
|
using MiraAPI.Modifiers;
|
||||||
using MiraAPI.Roles;
|
using MiraAPI.Roles;
|
||||||
using MiraAPI.Utilities;
|
using MiraAPI.Utilities;
|
||||||
|
using MiraAPI.Utilities.Assets;
|
||||||
using Reactor.Networking;
|
using Reactor.Networking;
|
||||||
using Reactor.Utilities;
|
using Reactor.Utilities;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
namespace MiraAPI.PluginLoading;
|
namespace MiraAPI.PluginLoading;
|
||||||
|
|
||||||
internal sealed class MiraPluginManager
|
internal sealed class MiraPluginManager
|
||||||
{
|
{
|
||||||
private readonly Dictionary<Assembly, MiraPluginInfo> _registeredPlugins = [];
|
private readonly Dictionary<Assembly, MiraPluginInfo> _registeredPlugins = [];
|
||||||
|
|
||||||
internal MiraPluginInfo[] RegisteredPlugins() => [.. _registeredPlugins.Values];
|
internal MiraPluginInfo[] RegisteredPlugins() => [.. _registeredPlugins.Values];
|
||||||
|
|
||||||
|
public List<LoadableBundleAsset<UnityEngine.Object>> BundleAssets = new();
|
||||||
|
internal uint NextAssetId { get; private set; }
|
||||||
|
internal uint GetNextAssetId()
|
||||||
|
{
|
||||||
|
NextAssetId++;
|
||||||
|
return NextAssetId;
|
||||||
|
}
|
||||||
|
|
||||||
public static MiraPluginManager Instance { get; private set; } = new();
|
public static MiraPluginManager Instance { get; private set; } = new();
|
||||||
|
|
||||||
internal void Initialize()
|
internal void Initialize()
|
||||||
@@ -36,6 +45,7 @@ internal sealed class MiraPluginManager
|
|||||||
var info = new MiraPluginInfo(miraPlugin, pluginInfo);
|
var info = new MiraPluginInfo(miraPlugin, pluginInfo);
|
||||||
|
|
||||||
RegisterModifierAttribute(assembly);
|
RegisterModifierAttribute(assembly);
|
||||||
|
RegisterAnimPresetAttribute(assembly);
|
||||||
RegisterAllOptions(assembly, info);
|
RegisterAllOptions(assembly, info);
|
||||||
|
|
||||||
RegisterRoleAttribute(assembly, info);
|
RegisterRoleAttribute(assembly, info);
|
||||||
@@ -161,6 +171,18 @@ internal sealed class MiraPluginManager
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void RegisterAnimPresetAttribute(Assembly assembly)
|
||||||
|
{
|
||||||
|
foreach (var type in assembly.GetTypes())
|
||||||
|
{
|
||||||
|
var attribute = type.GetCustomAttribute<RegisterAnimationPresetAttribute>();
|
||||||
|
if (attribute != null)
|
||||||
|
{
|
||||||
|
AnimationPresetManager.RegisterPreset(type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static void RegisterButtonAttribute(Assembly assembly)
|
private static void RegisterButtonAttribute(Assembly assembly)
|
||||||
{
|
{
|
||||||
foreach (var type in assembly.GetTypes())
|
foreach (var type in assembly.GetTypes())
|
||||||
|
|||||||
@@ -77,11 +77,6 @@ public interface ICustomRole
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
bool CanUseVent => Team == ModdedRoleTeams.Impostor;
|
bool CanUseVent => Team == ModdedRoleTeams.Impostor;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets a value indicating whether the role can use the sabotage button.
|
|
||||||
/// </summary>
|
|
||||||
bool CanUseSabotage => Team == ModdedRoleTeams.Impostor;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a value indicating whether the role's tasks count towards task progress.
|
/// Gets a value indicating whether the role's tasks count towards task progress.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using MiraAPI.PluginLoading;
|
||||||
using Reactor.Utilities.Extensions;
|
using Reactor.Utilities.Extensions;
|
||||||
|
using System;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace MiraAPI.Utilities.Assets;
|
namespace MiraAPI.Utilities.Assets;
|
||||||
@@ -10,8 +11,30 @@ namespace MiraAPI.Utilities.Assets;
|
|||||||
/// <param name="name">The name of the asset.</param>
|
/// <param name="name">The name of the asset.</param>
|
||||||
/// <param name="bundle">The AssetBundle that contains the asset.</param>
|
/// <param name="bundle">The AssetBundle that contains the asset.</param>
|
||||||
/// <typeparam name="T">The type of the asset to be loaded.</typeparam>
|
/// <typeparam name="T">The type of the asset to be loaded.</typeparam>
|
||||||
public class LoadableBundleAsset<T>(string name, AssetBundle bundle) : LoadableAsset<T> where T : UnityEngine.Object
|
public class LoadableBundleAsset<T> : LoadableAsset<T> where T : UnityEngine.Object
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the ID of this asset. Used for networking.
|
||||||
|
/// </summary>
|
||||||
|
public uint AssetId { get; internal set; }
|
||||||
|
private string _name { get; }
|
||||||
|
private AssetBundle _bundle { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="LoadableBundleAsset{T}"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">Name of the bundle.</param>
|
||||||
|
/// <param name="bundle">Asset bundle.</param>
|
||||||
|
public LoadableBundleAsset(string name, AssetBundle bundle)
|
||||||
|
{
|
||||||
|
AssetId = MiraPluginManager.Instance.GetNextAssetId();
|
||||||
|
//MiraPluginManager.Instance.BundleAssets.Add((LoadableBundleAsset<Object>)this);
|
||||||
|
|
||||||
|
_name = name;
|
||||||
|
_bundle = bundle;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Loads the asset from the asset bundle.
|
/// Loads the asset from the asset bundle.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -24,11 +47,11 @@ public class LoadableBundleAsset<T>(string name, AssetBundle bundle) : LoadableA
|
|||||||
return LoadedAsset;
|
return LoadedAsset;
|
||||||
}
|
}
|
||||||
|
|
||||||
LoadedAsset = bundle.LoadAsset<T>(name);
|
LoadedAsset = _bundle.LoadAsset<T>(_name);
|
||||||
|
|
||||||
if (LoadedAsset == null)
|
if (LoadedAsset == null)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException($"INVALID ASSET: {name}");
|
throw new InvalidOperationException($"INVALID ASSET: {_name}");
|
||||||
}
|
}
|
||||||
|
|
||||||
return LoadedAsset;
|
return LoadedAsset;
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
|
using MiraAPI.Animations;
|
||||||
using MiraAPI.GameOptions;
|
using MiraAPI.GameOptions;
|
||||||
using MiraAPI.Modifiers;
|
using MiraAPI.Modifiers;
|
||||||
using MiraAPI.Networking;
|
using MiraAPI.Networking;
|
||||||
using MiraAPI.Roles;
|
using MiraAPI.Roles;
|
||||||
using Reactor.Networking.Attributes;
|
using Reactor.Networking.Attributes;
|
||||||
using Reactor.Utilities;
|
using Reactor.Utilities;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace MiraAPI.Utilities;
|
namespace MiraAPI.Utilities;
|
||||||
@@ -116,6 +117,7 @@ public static class Extensions
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static readonly Dictionary<PlayerControl, ModifierComponent> ModifierComponents = [];
|
private static readonly Dictionary<PlayerControl, ModifierComponent> ModifierComponents = [];
|
||||||
|
private static readonly Dictionary<PlayerControl, CustomAnimator> AnimatorComponents = [];
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the ModifierComponent for a player.
|
/// Gets the ModifierComponent for a player.
|
||||||
@@ -138,6 +140,27 @@ public static class Extensions
|
|||||||
return component;
|
return component;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the CustomAnimator for a player.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="player">The PlayerControl object.</param>
|
||||||
|
/// <returns>A CustomAnimator if there is one, null otherwise.</returns>
|
||||||
|
public static CustomAnimator? GetCustomAnimator(this PlayerControl player)
|
||||||
|
{
|
||||||
|
if (AnimatorComponents.TryGetValue(player, out var component))
|
||||||
|
{
|
||||||
|
return component;
|
||||||
|
}
|
||||||
|
|
||||||
|
component = player.GetComponent<CustomAnimator>();
|
||||||
|
if (component)
|
||||||
|
{
|
||||||
|
AnimatorComponents[player] = component;
|
||||||
|
}
|
||||||
|
|
||||||
|
return component;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Randomizes a list.
|
/// Randomizes a list.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -23,8 +23,6 @@ To start using Mira API, you need to:
|
|||||||
2. Add a BepInDependency on your plugin class like this: `[BepInDependency(MiraApiPlugin.Id)]`
|
2. Add a BepInDependency on your plugin class like this: `[BepInDependency(MiraApiPlugin.Id)]`
|
||||||
3. Implement the IMiraPlugin interface on your plugin class.
|
3. Implement the IMiraPlugin interface on your plugin class.
|
||||||
|
|
||||||
Mira API also depends on [Reactor](https://github.com/NuclearPowered/Reactor) in order to function properly! Do not forget to include it as a reference and `BepInDependency`!
|
|
||||||
|
|
||||||
For a full example, see [this file](https://github.com/All-Of-Us-Mods/MiraAPI/blob/master/MiraAPI.Example/ExamplePlugin.cs).
|
For a full example, see [this file](https://github.com/All-Of-Us-Mods/MiraAPI/blob/master/MiraAPI.Example/ExamplePlugin.cs).
|
||||||
|
|
||||||
## Recommended Project Structure
|
## Recommended Project Structure
|
||||||
|
|||||||
Reference in new issue
Block a user