mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-10-21 13:37:54 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
34b89c5c46 |
No files matched your search
+1
-1
@@ -2,7 +2,7 @@
|
||||
<ItemGroup>
|
||||
<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="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.IL2CPP.MSBuild" Version="2.0.1" PrivateAssets="all" ExcludeAssets="runtime" />
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
|
||||
|
||||
<VersionPrefix>0.1.9</VersionPrefix>
|
||||
<VersionPrefix>0.1.4</VersionPrefix>
|
||||
<VersionSuffix>dev</VersionSuffix>
|
||||
|
||||
<Authors>All Of Us, XtraCube, Angxl</Authors>
|
||||
|
||||
@@ -21,7 +21,7 @@ public class MeetingButton : CustomActionButton
|
||||
|
||||
public override bool Enabled(RoleBehaviour? role)
|
||||
{
|
||||
return PlayerControl.LocalPlayer != null && PlayerControl.LocalPlayer.HasModifier<CaptainModifier>();
|
||||
return PlayerControl.LocalPlayer.HasModifier<CaptainModifier>();
|
||||
}
|
||||
|
||||
protected override void OnClick()
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using MiraAPI.Roles;
|
||||
using MiraAPI.Utilities.Assets;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -12,11 +13,8 @@ public class ChameloenRole : CrewmateRole, ICustomRole
|
||||
public string RoleDescription => RoleLongDescription;
|
||||
public Color RoleColor => Palette.AcceptedGreen;
|
||||
public ModdedRoleTeams Team => ModdedRoleTeams.Crewmate;
|
||||
|
||||
public CustomRoleConfiguration Configuration => new CustomRoleConfiguration(this)
|
||||
{
|
||||
OptionsScreenshot = ExampleAssets.Banner,
|
||||
};
|
||||
public LoadableAsset<Sprite> OptionsScreenshot => ExampleAssets.Banner;
|
||||
public int MaxPlayers => 2;
|
||||
|
||||
public void PlayerControlFixedUpdate(PlayerControl playerControl)
|
||||
{
|
||||
@@ -45,4 +43,4 @@ public class ChameloenRole : CrewmateRole, ICustomRole
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
using MiraAPI.Roles;
|
||||
using Il2CppInterop.Runtime.Attributes;
|
||||
using MiraAPI.Roles;
|
||||
using MiraAPI.Utilities.Assets;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.Example.Roles;
|
||||
@@ -11,10 +13,7 @@ public class FreezerRole : ImpostorRole, ICustomRole
|
||||
public string RoleDescription => RoleLongDescription;
|
||||
public Color RoleColor => Palette.Blue;
|
||||
public ModdedRoleTeams Team => ModdedRoleTeams.Impostor;
|
||||
|
||||
public CustomRoleConfiguration Configuration => new CustomRoleConfiguration(this)
|
||||
{
|
||||
OptionsScreenshot = ExampleAssets.Banner,
|
||||
MaxRoleCount = 2,
|
||||
};
|
||||
[HideFromIl2Cpp]
|
||||
public LoadableAsset<Sprite> OptionsScreenshot => ExampleAssets.Banner;
|
||||
public int MaxPlayers => 2;
|
||||
}
|
||||
@@ -11,13 +11,9 @@ public class NeutralKillerRole : ImpostorRole, ICustomRole
|
||||
public string RoleLongDescription => RoleDescription;
|
||||
public Color RoleColor => Color.magenta;
|
||||
public ModdedRoleTeams Team => ModdedRoleTeams.Neutral;
|
||||
|
||||
public CustomRoleConfiguration Configuration => new CustomRoleConfiguration(this)
|
||||
{
|
||||
UseVanillaKillButton = true,
|
||||
CanGetKilled = true,
|
||||
CanUseVent = true,
|
||||
};
|
||||
public bool UseVanillaKillButton => true;
|
||||
public bool CanGetKilled => true;
|
||||
public bool CanUseVent => true;
|
||||
|
||||
public override void SpawnTaskHeader(PlayerControl playerControl)
|
||||
{
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using MiraAPI.Roles;
|
||||
using Il2CppInterop.Runtime.Attributes;
|
||||
using MiraAPI.Roles;
|
||||
using MiraAPI.Utilities.Assets;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.Example.Roles;
|
||||
@@ -11,12 +13,6 @@ public class TeleporterRole : CrewmateRole, ICustomRole
|
||||
public string RoleDescription => RoleLongDescription;
|
||||
public Color RoleColor => new Color32(221, 176, 152, 255);
|
||||
public ModdedRoleTeams Team => ModdedRoleTeams.Crewmate;
|
||||
|
||||
public CustomRoleConfiguration Configuration => new CustomRoleConfiguration(this)
|
||||
{
|
||||
OptionsScreenshot = ExampleAssets.Banner,
|
||||
CanModifyChance = false,
|
||||
DefaultChance = 73,
|
||||
DefaultRoleCount = 4,
|
||||
};
|
||||
[HideFromIl2Cpp]
|
||||
public LoadableAsset<Sprite> OptionsScreenshot => ExampleAssets.Banner;
|
||||
}
|
||||
@@ -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; }
|
||||
StringNames StringName { get; }
|
||||
IMiraPlugin? ParentMod { get; set; }
|
||||
BaseGameSetting Data { get; }
|
||||
BaseGameSetting? Data { get; }
|
||||
Type? AdvancedRole { get; set; }
|
||||
OptionBehaviour? OptionBehaviour { get; }
|
||||
Func<bool> Visible { get; set; }
|
||||
|
||||
@@ -45,10 +45,6 @@ public static class ModdedOptionsManager
|
||||
TypeToGroup.Add(type, group);
|
||||
pluginInfo.OptionGroups.Add(group);
|
||||
|
||||
typeof(OptionGroupSingleton<>).MakeGenericType(type)
|
||||
.GetField("_instance", BindingFlags.Static | BindingFlags.NonPublic)!
|
||||
.SetValue(null, group);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -86,7 +86,7 @@ public class ModdedEnumOption : ModdedOption<int>
|
||||
/// <inheritdoc />
|
||||
protected override void OnValueChanged(int newValue)
|
||||
{
|
||||
HudManager.Instance.Notifier.AddSettingsChangeMessage(StringName, Data?.GetValueString(newValue), false);
|
||||
DestroyableSingleton<HudManager>.Instance.Notifier.AddSettingsChangeMessage(StringName, Data?.GetValueString(newValue), false);
|
||||
if (!OptionBehaviour)
|
||||
{
|
||||
return;
|
||||
|
||||
@@ -134,7 +134,7 @@ public class ModdedNumberOption : ModdedOption<float>
|
||||
protected override void OnValueChanged(float newValue)
|
||||
{
|
||||
Value = Mathf.Clamp(newValue, Min, Max);
|
||||
HudManager.Instance.Notifier.AddSettingsChangeMessage(
|
||||
DestroyableSingleton<HudManager>.Instance.Notifier.AddSettingsChangeMessage(
|
||||
StringName,
|
||||
Data?.GetValueString(Value),
|
||||
false);
|
||||
|
||||
@@ -35,7 +35,7 @@ public abstract class ModdedOption<T> : IModdedOption
|
||||
/// <summary>
|
||||
/// Gets the BaseGameSetting data of the option.
|
||||
/// </summary>
|
||||
public BaseGameSetting Data { get; protected init; }
|
||||
public BaseGameSetting? Data { get; protected init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the parent mod of the option.
|
||||
|
||||
@@ -69,7 +69,7 @@ public class ModdedToggleOption : ModdedOption<bool>
|
||||
/// <inheritdoc />
|
||||
protected override void OnValueChanged(bool newValue)
|
||||
{
|
||||
HudManager.Instance.Notifier.AddSettingsChangeMessage(StringName, newValue ? "On" : "Off", false);
|
||||
DestroyableSingleton<HudManager>.Instance.Notifier.AddSettingsChangeMessage(StringName, newValue ? "On" : "Off", false);
|
||||
if (!OptionBehaviour)
|
||||
{
|
||||
return;
|
||||
|
||||
@@ -167,7 +167,6 @@ public abstract class CustomActionButton
|
||||
public void SetUses(int amount)
|
||||
{
|
||||
UsesLeft = Mathf.Clamp(amount, 0, int.MaxValue);
|
||||
Button?.SetUsesRemaining(MaxUses);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -39,6 +39,11 @@ public class ModifierComponent(IntPtr cppPtr) : MonoBehaviour(cppPtr)
|
||||
|
||||
internal void ClearModifiers()
|
||||
{
|
||||
foreach (var modifier in Modifiers)
|
||||
{
|
||||
modifier.OnDeactivate();
|
||||
}
|
||||
|
||||
_toRemove.AddRange(Modifiers);
|
||||
}
|
||||
|
||||
@@ -69,7 +74,7 @@ public class ModifierComponent(IntPtr cppPtr) : MonoBehaviour(cppPtr)
|
||||
Modifiers.Add(modifier);
|
||||
modifier.OnActivate();
|
||||
|
||||
if (modifier is TimedModifier { AutoStart: true } timer)
|
||||
if (_player?.AmOwner == true && modifier is TimedModifier { AutoStart: true } timer)
|
||||
{
|
||||
timer.StartTimer();
|
||||
}
|
||||
@@ -79,7 +84,7 @@ public class ModifierComponent(IntPtr cppPtr) : MonoBehaviour(cppPtr)
|
||||
{
|
||||
if (_player?.AmOwner == true)
|
||||
{
|
||||
HudManager.Instance?.SetHudActive(HudManager.Instance.TaskPanel.isActiveAndEnabled);
|
||||
HudManager.Instance?.SetHudActive(true);
|
||||
}
|
||||
_toAdd.Clear();
|
||||
_toRemove.Clear();
|
||||
|
||||
@@ -39,9 +39,6 @@ public abstract class TimedModifier : BaseModifier
|
||||
/// </summary>
|
||||
public float TimeRemaining { get; protected set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool HideOnUi => !TimerActive;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the HUD information for Timed Modifier, including the time remaining.
|
||||
/// </summary>
|
||||
@@ -56,18 +53,25 @@ public abstract class TimedModifier : BaseModifier
|
||||
/// </summary>
|
||||
public override void FixedUpdate()
|
||||
{
|
||||
if (!TimerActive)
|
||||
if (Player?.AmOwner == false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (TimeRemaining > 0)
|
||||
if (TimeRemaining > 0 && TimerActive)
|
||||
{
|
||||
TimeRemaining -= Time.fixedDeltaTime;
|
||||
}
|
||||
else
|
||||
{
|
||||
StopTimer();
|
||||
TimerActive = false;
|
||||
TimeRemaining = Duration;
|
||||
OnTimerComplete();
|
||||
|
||||
if (RemoveOnComplete)
|
||||
{
|
||||
ModifierComponent?.RemoveModifier(ModifierId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,52 +86,7 @@ public abstract class TimedModifier : BaseModifier
|
||||
return;
|
||||
}
|
||||
|
||||
TimeRemaining = Duration;
|
||||
TimerActive = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stops the timer and calls OnTimerComplete().
|
||||
/// </summary>
|
||||
public void StopTimer()
|
||||
{
|
||||
if (!TimerActive)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
TimerActive = false;
|
||||
TimeRemaining = Duration;
|
||||
OnTimerComplete();
|
||||
|
||||
if (RemoveOnComplete)
|
||||
{
|
||||
ModifierComponent?.RemoveModifier(ModifierId);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resets the timer. Does not call OnTimerComplete().
|
||||
/// </summary>
|
||||
public void ResetTimer()
|
||||
{
|
||||
TimerActive = false;
|
||||
TimeRemaining = Duration;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Pauses the timer.
|
||||
/// </summary>
|
||||
public void PauseTimer()
|
||||
{
|
||||
TimerActive = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Pauses the timer.
|
||||
/// </summary>
|
||||
public void ResumeTimer()
|
||||
{
|
||||
TimerActive = true;
|
||||
}
|
||||
}
|
||||
@@ -87,7 +87,7 @@ public static class CustomMurderRpc
|
||||
if (flag && PlayerControl.LocalPlayer.Data.PlayerId == target.protectedByGuardianId)
|
||||
{
|
||||
StatsManager.Instance.IncrementStat(StringNames.StatsGuardianAngelCrewmatesProtected);
|
||||
AchievementManager.Instance.OnProtectACrewmate();
|
||||
DestroyableSingleton<AchievementManager>.Instance.OnProtectACrewmate();
|
||||
}
|
||||
|
||||
if (source.AmOwner || flag)
|
||||
@@ -115,7 +115,7 @@ public static class CustomMurderRpc
|
||||
return;
|
||||
}
|
||||
|
||||
DebugAnalytics.Instance.Analytics.Kill(target.Data, source.Data);
|
||||
DestroyableSingleton<DebugAnalytics>.Instance.Analytics.Kill(target.Data, source.Data);
|
||||
if (source.AmOwner)
|
||||
{
|
||||
StatsManager.Instance.IncrementStat(
|
||||
@@ -139,7 +139,7 @@ public static class CustomMurderRpc
|
||||
}
|
||||
}
|
||||
|
||||
UnityTelemetry.Instance.WriteMurder();
|
||||
DestroyableSingleton<UnityTelemetry>.Instance.WriteMurder();
|
||||
target.gameObject.layer = LayerMask.NameToLayer("Ghost");
|
||||
if (target.AmOwner)
|
||||
{
|
||||
@@ -159,14 +159,14 @@ public static class CustomMurderRpc
|
||||
|
||||
if (showKillAnim)
|
||||
{
|
||||
HudManager.Instance.KillOverlay.ShowKillAnimation(source.Data, data);
|
||||
DestroyableSingleton<HudManager>.Instance.KillOverlay.ShowKillAnimation(source.Data, data);
|
||||
}
|
||||
|
||||
target.cosmetics.SetNameMask(false);
|
||||
target.RpcSetScanner(false);
|
||||
}
|
||||
|
||||
AchievementManager.Instance.OnMurder(
|
||||
DestroyableSingleton<AchievementManager>.Instance.OnMurder(
|
||||
source.AmOwner,
|
||||
target.AmOwner,
|
||||
source.CurrentOutfitType == PlayerOutfitType.Shapeshifted,
|
||||
|
||||
@@ -34,4 +34,9 @@ public enum MiraRpc : uint
|
||||
/// Custom Murder RPC.
|
||||
/// </summary>
|
||||
CustomMurder,
|
||||
|
||||
/// <summary>
|
||||
/// Trigger Animation using CustomAnimator.
|
||||
/// </summary>
|
||||
TriggerAnimation,
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
using HarmonyLib;
|
||||
using MiraAPI.Hud;
|
||||
using MiraAPI.Roles;
|
||||
using Reactor.Utilities.Extensions;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
@@ -89,8 +88,7 @@ public static class HudManagerPatches
|
||||
[HarmonyPatch(nameof(HudManager.SetHudActive), typeof(PlayerControl), typeof(RoleBehaviour), typeof(bool))]
|
||||
public static void SetHudActivePostfix(HudManager __instance, PlayerControl localPlayer, RoleBehaviour role, bool isActive)
|
||||
{
|
||||
__instance.AdminButton.ToggleVisible(isActive && role.IsImpostor && GameOptionsManager.Instance.CurrentGameOptions.GameMode == AmongUs.GameOptions.GameModes.HideNSeek);
|
||||
if (localPlayer.Data == null)
|
||||
if (!localPlayer.Data)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,35 +1,26 @@
|
||||
using HarmonyLib;
|
||||
using MiraAPI.Roles;
|
||||
using MiraAPI.Utilities;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.Patches;
|
||||
namespace MiraAPI.Patches.Modifiers;
|
||||
|
||||
/// <summary>
|
||||
/// Vent patches to make sure the player is able to use the vent.
|
||||
/// </summary>
|
||||
[HarmonyPatch(typeof(Vent))]
|
||||
public static class VentPatches
|
||||
{
|
||||
/// <summary>
|
||||
/// CanUse patch.
|
||||
/// </summary>
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(nameof(Vent.CanUse))]
|
||||
public static void VentCanUsePostfix(Vent __instance, ref float __result, [HarmonyArgument(0)] NetworkedPlayerInfo pc, [HarmonyArgument(1)] ref bool canUse, [HarmonyArgument(2)] ref bool couldUse)
|
||||
public static void CanUseVentPatch(Vent __instance, ref float __result, [HarmonyArgument(0)] NetworkedPlayerInfo pc, [HarmonyArgument(1)] ref bool canUse, [HarmonyArgument(2)] ref bool couldUse)
|
||||
{
|
||||
var @object = pc.Object;
|
||||
var role = @object.Data.Role;
|
||||
|
||||
var canVent = role is ICustomRole customRole ? customRole.Configuration.CanUseVent : role.CanVent;
|
||||
|
||||
var modifiers = @object.GetModifierComponent()?.ActiveModifiers;
|
||||
if (modifiers is null || modifiers.Count <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
switch (canVent)
|
||||
switch (role.CanVent)
|
||||
{
|
||||
case true when modifiers.Exists(x => !x.CanVent()):
|
||||
couldUse = canUse = false;
|
||||
@@ -32,25 +32,16 @@ public static class GameOptionsMenuPatch
|
||||
var num = 2.1f;
|
||||
var filteredGroups =
|
||||
GameSettingMenuPatches.SelectedMod?.OptionGroups.Where(
|
||||
x => x.AdvancedRole is null) ?? [];
|
||||
x => x.GroupVisible.Invoke() && x.AdvancedRole is null) ?? [];
|
||||
|
||||
foreach (var group in filteredGroups)
|
||||
{
|
||||
if (group.Options.Count == 0 || group.Header is null)
|
||||
var filteredOpts = group.Options.Where(x => x.Visible.Invoke()).ToList();
|
||||
if (filteredOpts.Count == 0 || group.Header is null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!group.GroupVisible.Invoke())
|
||||
{
|
||||
group.Header.gameObject.SetActive(false);
|
||||
foreach (var option in group.Options)
|
||||
{
|
||||
option.OptionBehaviour?.gameObject.SetActive(false);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
group.Header.gameObject.SetActive(true);
|
||||
group.Header.transform.localScale = Vector3.one * 0.63f;
|
||||
group.Header.transform.localPosition = new Vector3(-0.903f, num, -2f);
|
||||
|
||||
@@ -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;
|
||||
@@ -128,6 +128,11 @@ public static class LobbyViewPanePatches
|
||||
|
||||
foreach (var group in filteredGroups)
|
||||
{
|
||||
if (group.Options.Count == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var categoryHeaderMasked = Object.Instantiate(
|
||||
instance.categoryHeaderOrigin,
|
||||
instance.settingsContainer,
|
||||
@@ -171,6 +176,11 @@ public static class LobbyViewPanePatches
|
||||
|
||||
var data = option.Data;
|
||||
|
||||
if (data == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (data.Type == OptionTypes.Checkbox)
|
||||
{
|
||||
viewSettingsInfoPanel.SetInfoCheckbox(
|
||||
@@ -215,7 +225,7 @@ public static class LobbyViewPanePatches
|
||||
{
|
||||
var filteredRoles = SelectedMod.CustomRoles.Values
|
||||
.OfType<ICustomRole>()
|
||||
.Where(x => !x.Configuration.HideSettings && x.Team == team).ToList();
|
||||
.Where(x => !x.HideSettings && x.Team == team).ToList();
|
||||
|
||||
if (filteredRoles.Count == 0)
|
||||
{
|
||||
@@ -284,7 +294,7 @@ public static class LobbyViewPanePatches
|
||||
chancePerGame,
|
||||
61,
|
||||
customRole.RoleColor,
|
||||
customRole.Configuration.Icon.LoadAsset(),
|
||||
customRole.Icon.LoadAsset(),
|
||||
true);
|
||||
|
||||
viewSettingsInfoPanelRoleVariant.titleText.color =
|
||||
@@ -369,7 +379,7 @@ public static class LobbyViewPanePatches
|
||||
role.StringName,
|
||||
maskLayer,
|
||||
role.TeamType == RoleTeamTypes.Crewmate,
|
||||
customRole.Configuration.Icon.LoadAsset());
|
||||
customRole.Icon.LoadAsset());
|
||||
viewPanel.divider.material.SetInt(PlayerMaterial.MaskLayer, maskLayer);
|
||||
|
||||
var num = viewPanel.yPosStart;
|
||||
@@ -389,6 +399,11 @@ public static class LobbyViewPanePatches
|
||||
|
||||
var value = option.GetFloatData();
|
||||
|
||||
if (baseGameSetting == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (baseGameSetting.Type == OptionTypes.Checkbox)
|
||||
{
|
||||
viewSettingsInfoPanel.SetInfoCheckbox(baseGameSetting.Title, maskLayer, value > 0f);
|
||||
|
||||
@@ -18,7 +18,7 @@ public static class NotificationPopperPatch
|
||||
[HarmonyArgument(3)] RoleTeamTypes teamType,
|
||||
[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;
|
||||
}
|
||||
@@ -27,14 +27,12 @@ public static class NotificationPopperPatch
|
||||
? Palette.CrewmateSettingChangeText.ToTextColor()
|
||||
: Palette.ImpostorRed.ToTextColor();
|
||||
|
||||
var item = TranslationController.Instance.GetString(
|
||||
var item = DestroyableSingleton<TranslationController>.Instance.GetString(
|
||||
StringNames.LobbyChangeSettingNotificationRole,
|
||||
string.Concat(
|
||||
"<font=\"Barlow-Black SDF\" material=\"Barlow-Black Outline\">",
|
||||
text,
|
||||
TranslationController.Instance.GetString(key, Array.Empty<Object>()),
|
||||
"</color></font>"
|
||||
),
|
||||
"<font=\"Barlow-Black SDF\" material=\"Barlow-Black Outline\">",
|
||||
text,
|
||||
DestroyableSingleton<TranslationController>.Instance.GetString(key, Array.Empty<Object>()),
|
||||
"</color></font>",
|
||||
"<font=\"Barlow-Black SDF\" material=\"Barlow-Black Outline\">" + roleCount + "</font>",
|
||||
"<font=\"Barlow-Black SDF\" material=\"Barlow-Black Outline\">" + roleChance + "%"
|
||||
);
|
||||
|
||||
@@ -17,7 +17,7 @@ public static class OptionsPatches
|
||||
}
|
||||
|
||||
__instance.TitleText.text =
|
||||
TranslationController.Instance.GetString(__instance.Title, Array.Empty<Object>());
|
||||
DestroyableSingleton<TranslationController>.Instance.GetString(__instance.Title, Array.Empty<Object>());
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -39,7 +39,7 @@ public static class OptionsPatches
|
||||
}
|
||||
|
||||
__instance.TitleText.text =
|
||||
TranslationController.Instance.GetString(__instance.Title, Array.Empty<Object>());
|
||||
DestroyableSingleton<TranslationController>.Instance.GetString(__instance.Title, Array.Empty<Object>());
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -61,8 +61,8 @@ public static class OptionsPatches
|
||||
}
|
||||
|
||||
__instance.TitleText.text =
|
||||
TranslationController.Instance.GetString(__instance.Title, Array.Empty<Object>());
|
||||
__instance.ValueText.text = TranslationController.Instance.GetString(
|
||||
DestroyableSingleton<TranslationController>.Instance.GetString(__instance.Title, Array.Empty<Object>());
|
||||
__instance.ValueText.text = DestroyableSingleton<TranslationController>.Instance.GetString(
|
||||
__instance.Values[__instance.Value],
|
||||
Array.Empty<Object>());
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ public static class RoleSettingMenuPatches
|
||||
|
||||
var crewRoles = GameSettingMenuPatches.SelectedMod?.CustomRoles.Values
|
||||
.OfType<ICustomRole>()
|
||||
.Where(role => role is { Team: ModdedRoleTeams.Crewmate, Configuration.HideSettings: false })
|
||||
.Where(role => role is { Team: ModdedRoleTeams.Crewmate, HideSettings: false })
|
||||
.ToList() ?? [];
|
||||
|
||||
if (crewRoles is { Count: > 0 })
|
||||
@@ -82,7 +82,7 @@ public static class RoleSettingMenuPatches
|
||||
|
||||
var impRoles = GameSettingMenuPatches.SelectedMod?.CustomRoles.Values
|
||||
.OfType<ICustomRole>()
|
||||
.Where(role => role is { Team: ModdedRoleTeams.Impostor, Configuration.HideSettings: false })
|
||||
.Where(role => role is { Team: ModdedRoleTeams.Impostor, HideSettings: false })
|
||||
.ToList() ?? [];
|
||||
|
||||
if (impRoles is { Count: > 0 })
|
||||
@@ -109,7 +109,7 @@ public static class RoleSettingMenuPatches
|
||||
|
||||
var neutRoles = GameSettingMenuPatches.SelectedMod?.CustomRoles.Values
|
||||
.OfType<ICustomRole>()
|
||||
.Where(role => role is { Team: ModdedRoleTeams.Neutral, Configuration.HideSettings: false })
|
||||
.Where(role => role is { Team: ModdedRoleTeams.Neutral, HideSettings: false })
|
||||
.ToList() ?? [];
|
||||
|
||||
if (neutRoles is { Count: > 0 })
|
||||
@@ -159,24 +159,18 @@ public static class RoleSettingMenuPatches
|
||||
{
|
||||
var roleSetting = obj.Cast<RoleOptionSetting>();
|
||||
var role = roleSetting.Role as ICustomRole;
|
||||
if (role is null or { Configuration.HideSettings: true })
|
||||
if (role is null or { HideSettings: true })
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (role.Configuration.MaxRoleCount != 0)
|
||||
{
|
||||
role.ParentMod.PluginConfig.TryGetEntry<int>(role.NumConfigDefinition, out var numEntry);
|
||||
numEntry.Value = Mathf.Clamp(roleSetting.RoleMaxCount, 0, role.Configuration.MaxRoleCount);
|
||||
}
|
||||
role.ParentMod.PluginConfig.TryGetEntry<int>(role.NumConfigDefinition, out var numEntry);
|
||||
numEntry.Value = roleSetting.RoleMaxCount;
|
||||
|
||||
if (role.Configuration.CanModifyChance)
|
||||
{
|
||||
role.ParentMod.PluginConfig.TryGetEntry<int>(role.ChanceConfigDefinition, out var chanceEntry);
|
||||
chanceEntry.Value = roleSetting.RoleChance;
|
||||
}
|
||||
role.ParentMod.PluginConfig.TryGetEntry<int>(role.ChanceConfigDefinition, out var chanceEntry);
|
||||
chanceEntry.Value = roleSetting.RoleChance;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -184,7 +178,7 @@ public static class RoleSettingMenuPatches
|
||||
}
|
||||
|
||||
roleSetting.UpdateValuesAndText(GameOptionsManager.Instance.CurrentGameOptions.RoleOptions);
|
||||
HudManager.Instance.Notifier.AddRoleSettingsChangeMessage(
|
||||
DestroyableSingleton<HudManager>.Instance.Notifier.AddRoleSettingsChangeMessage(
|
||||
roleSetting.Role.StringName,
|
||||
roleSetting.RoleMaxCount,
|
||||
roleSetting.RoleChance,
|
||||
@@ -234,7 +228,7 @@ public static class RoleSettingMenuPatches
|
||||
renderer.material.SetInt(PlayerMaterial.MaskLayer, 20);
|
||||
}
|
||||
|
||||
foreach (var fontMat in newOpt.GetComponentsInChildren<TextMeshPro>(true).Select(x => x.fontMaterial))
|
||||
foreach (var fontMat in newOpt.GetComponentsInChildren<TextMeshPro>(true).Select(x=>x.fontMaterial))
|
||||
{
|
||||
fontMat.SetFloat(ShaderID.StencilComp, 3f);
|
||||
fontMat.SetFloat(ShaderID.Stencil, 20);
|
||||
@@ -260,11 +254,11 @@ public static class RoleSettingMenuPatches
|
||||
}
|
||||
|
||||
__instance.roleDescriptionText.text = customRole.RoleLongDescription;
|
||||
__instance.roleTitleText.text = TranslationController.Instance.GetString(
|
||||
__instance.roleTitleText.text = DestroyableSingleton<TranslationController>.Instance.GetString(
|
||||
role.StringName,
|
||||
new Il2CppReferenceArray<Il2CppSystem.Object>(0));
|
||||
__instance.roleScreenshot.sprite = Sprite.Create(
|
||||
customRole.Configuration.OptionsScreenshot.LoadAsset().texture,
|
||||
customRole.OptionsScreenshot.LoadAsset().texture,
|
||||
new Rect(0, 0, 370, 230),
|
||||
Vector2.one / 2,
|
||||
100);
|
||||
@@ -311,24 +305,12 @@ public static class RoleSettingMenuPatches
|
||||
Quaternion.identity,
|
||||
__instance.RoleChancesSettings.transform);
|
||||
roleOptionSetting.transform.localPosition = new Vector3(-0.15f, yPos, -2f);
|
||||
|
||||
roleOptionSetting.SetRole(GameOptionsManager.Instance.CurrentGameOptions.RoleOptions, role, 20);
|
||||
roleOptionSetting.labelSprite.color = customRole.RoleColor;
|
||||
roleOptionSetting.OnValueChanged = new Action<OptionBehaviour>(ValueChanged);
|
||||
roleOptionSetting.SetClickMask(__instance.ButtonClickMask);
|
||||
__instance.roleChances.Add(roleOptionSetting);
|
||||
|
||||
if (customRole.Configuration.MaxRoleCount == 0 && customRole.Configuration.CanModifyChance)
|
||||
{
|
||||
roleOptionSetting.CountMinusBtn.gameObject.SetActive(false);
|
||||
roleOptionSetting.CountPlusBtn.gameObject.SetActive(false);
|
||||
}
|
||||
else if (!customRole.Configuration.CanModifyChance)
|
||||
{
|
||||
roleOptionSetting.ChanceMinusBtn.gameObject.SetActive(false);
|
||||
roleOptionSetting.ChancePlusBtn.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
roleOptionSetting.titleText.transform.localPosition = new Vector3(-0.5376f, -0.2923f, 0f);
|
||||
roleOptionSetting.titleText.color = customRole.RoleColor.GetAlternateColor();
|
||||
roleOptionSetting.titleText.horizontalAlignment = HorizontalAlignmentOptions.Left;
|
||||
|
||||
@@ -39,9 +39,9 @@ public static class SettingPatches
|
||||
MiraNumberSuffixes.None => value.ToString(__instance.FormatString, NumberFormatInfo.InvariantInfo),
|
||||
MiraNumberSuffixes.Multiplier => value.ToString(__instance.FormatString, NumberFormatInfo.InvariantInfo) + "x",
|
||||
MiraNumberSuffixes.Percent => value.ToString(__instance.FormatString, NumberFormatInfo.InvariantInfo) + "%",
|
||||
_ => TranslationController.Instance.GetString(
|
||||
_ => DestroyableSingleton<TranslationController>.Instance.GetString(
|
||||
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 MiraAPI.Animations;
|
||||
using MiraAPI.Hud;
|
||||
using MiraAPI.Modifiers;
|
||||
using MiraAPI.Roles;
|
||||
@@ -13,9 +14,9 @@ namespace MiraAPI.Patches;
|
||||
public static class PlayerControlPatches
|
||||
{
|
||||
/// <summary>
|
||||
/// Adds the modifier component to the player on start.
|
||||
/// Adds the modifier and animator component to the player on start.
|
||||
/// </summary>
|
||||
/// <param name="__instance">PlayerControl instance.</param>
|
||||
/// <param name="__instance">The player which will be given the components.</param>
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(nameof(PlayerControl.Start))]
|
||||
public static void PlayerControlStartPostfix(PlayerControl __instance)
|
||||
@@ -25,13 +26,20 @@ public static class PlayerControlPatches
|
||||
comp.DestroyImmediate();
|
||||
}
|
||||
|
||||
if (__instance.gameObject.TryGetComponent<CustomAnimator>(out var anim))
|
||||
{
|
||||
anim.DestroyImmediate();
|
||||
}
|
||||
|
||||
__instance.gameObject.AddComponent<CustomAnimator>();
|
||||
__instance.gameObject.AddComponent<ModifierComponent>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calls the OnDeath method for all active modifiers.
|
||||
/// </summary>
|
||||
/// <param name="__instance">PlayerControl instance.</param>
|
||||
/// <param name="__instance">The player who died.</param>
|
||||
/// <param name="reason">The reason of the death.</param>
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(nameof(PlayerControl.Die))]
|
||||
public static void PlayerControlDiePostfix(PlayerControl __instance, DeathReason reason)
|
||||
@@ -40,14 +48,14 @@ public static class PlayerControlPatches
|
||||
|
||||
if (modifiersComponent)
|
||||
{
|
||||
modifiersComponent.ActiveModifiers.ForEach(x=>x.OnDeath(reason));
|
||||
modifiersComponent.ActiveModifiers.ForEach(x => x.OnDeath(reason));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// FixedUpdate handler for custom roles and custom buttons.
|
||||
/// </summary>
|
||||
/// <param name="__instance">PlayerControl instance.</param>
|
||||
/// <param name="__instance">The player who's fixed update is being called.</param>
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(nameof(PlayerControl.FixedUpdate))]
|
||||
public static void PlayerControlFixedUpdatePostfix(PlayerControl __instance)
|
||||
@@ -77,15 +85,4 @@ public static class PlayerControlPatches
|
||||
button.FixedUpdateHandler(__instance);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clear from modifier component cache.
|
||||
/// </summary>
|
||||
/// <param name="__instance">PlayerControl instance.</param>
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(nameof(PlayerControl.OnDestroy))]
|
||||
public static void PlayerControlOnDestroyPrefix(PlayerControl __instance)
|
||||
{
|
||||
Utilities.Extensions.ModifierComponents.Remove(__instance);
|
||||
}
|
||||
}
|
||||
@@ -17,10 +17,6 @@ public static class HudManagerPatches
|
||||
/// <summary>
|
||||
/// Fixes Kill Button not showing for Neutral killing role.
|
||||
/// </summary>
|
||||
/// <param name="__instance">HudManager instance.</param>
|
||||
/// <param name="localPlayer">The local PlayerControl.</param>
|
||||
/// <param name="role">The player's RoleBehaviour.</param>
|
||||
/// <param name="isActive">Whether the Hud should be set active or not.</param>
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(nameof(HudManager.SetHudActive), typeof(PlayerControl), typeof(RoleBehaviour), typeof(bool))]
|
||||
public static void SetHudActivePostfix(
|
||||
@@ -31,11 +27,10 @@ public static class HudManagerPatches
|
||||
{
|
||||
var flag = localPlayer.Data != null && localPlayer.Data.IsDead;
|
||||
|
||||
if (role is ICustomRole customRole)
|
||||
if (role is ICustomRole)
|
||||
{
|
||||
__instance.KillButton.ToggleVisible(isActive && customRole.Configuration.UseVanillaKillButton && !flag);
|
||||
__instance.ImpostorVentButton.ToggleVisible(isActive && customRole.Configuration.CanUseVent && !flag);
|
||||
__instance.SabotageButton.gameObject.SetActive(isActive && customRole.Configuration.CanUseSabotage);
|
||||
__instance.KillButton.ToggleVisible(isActive && role.CanUseKillButton && !flag);
|
||||
__instance.ImpostorVentButton.ToggleVisible(isActive && role.CanVent && !flag);
|
||||
}
|
||||
|
||||
if (_roleTab)
|
||||
@@ -60,7 +55,7 @@ public static class HudManagerPatches
|
||||
|
||||
var role = local?.Data?.Role;
|
||||
|
||||
if (role is ICustomRole { Configuration.RoleHintType: RoleHintType.RoleTab } customRole)
|
||||
if (role is ICustomRole { RoleHintType: RoleHintType.RoleTab } customRole)
|
||||
{
|
||||
customRole.HudUpdate(__instance);
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ public static class KillButtonPatches
|
||||
__instance.currentTarget = target;
|
||||
if (__instance.currentTarget)
|
||||
{
|
||||
__instance.currentTarget.cosmetics.SetOutline(true, new Nullable<Color>(customRole.Configuration.KillButtonOutlineColor));
|
||||
__instance.currentTarget.cosmetics.SetOutline(true, new Nullable<Color>(customRole.KillButtonOutlineColor));
|
||||
__instance.SetEnabled();
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -37,12 +37,12 @@ public static class RoleManagerPatches
|
||||
return true;
|
||||
}
|
||||
|
||||
if (role.Configuration.GhostRole is RoleTypes.CrewmateGhost or RoleTypes.ImpostorGhost)
|
||||
if (role.GhostRole is RoleTypes.CrewmateGhost or RoleTypes.ImpostorGhost)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
plr.RpcSetRole(role.Configuration.GhostRole);
|
||||
plr.RpcSetRole(role.GhostRole);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,7 @@ public static class RoleOptionsCollectionPatch
|
||||
return true;
|
||||
}
|
||||
|
||||
if (customRole.Configuration.HideSettings)
|
||||
if (customRole.HideSettings)
|
||||
{
|
||||
__result = 0;
|
||||
return false;
|
||||
@@ -42,7 +42,7 @@ public static class RoleOptionsCollectionPatch
|
||||
return true;
|
||||
}
|
||||
|
||||
if (customRole.Configuration.HideSettings)
|
||||
if (customRole.HideSettings)
|
||||
{
|
||||
__result = 0;
|
||||
return false;
|
||||
|
||||
@@ -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.Configuration.CanUseSabotage || PlayerControl.LocalPlayer.inVent || !GameManager.Instance.SabotagesEnabled())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
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.Configuration.CanUseSabotage && GameManager.Instance.SabotagesEnabled());
|
||||
__instance.SetDisabled();
|
||||
return false;
|
||||
}
|
||||
__instance.SetEnabled();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
using AmongUs.GameOptions;
|
||||
using HarmonyLib;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Il2CppSystem;
|
||||
using Il2CppSystem.Collections.Generic;
|
||||
using MiraAPI.PluginLoading;
|
||||
using MiraAPI.Roles;
|
||||
using MiraAPI.Utilities.Assets;
|
||||
@@ -12,13 +12,10 @@ using Object = UnityEngine.Object;
|
||||
|
||||
namespace MiraAPI.Patches.Roles;
|
||||
|
||||
/// <summary>
|
||||
/// Patch TaskAdder for organizing Roles and adding scroller.
|
||||
/// </summary>
|
||||
[HarmonyPatch]
|
||||
public static class TaskAdderPatch
|
||||
{
|
||||
private static readonly Dictionary<string, string> ModsFolders = [];
|
||||
private static readonly System.Collections.Generic.Dictionary<string, string> ModsFolders = [];
|
||||
private static Scroller? _scroller;
|
||||
|
||||
[HarmonyPostfix]
|
||||
@@ -170,14 +167,19 @@ public static class TaskAdderPatch
|
||||
|
||||
ControllerManager.Instance.AddSelectableUiElement(taskFolder2.Button);
|
||||
if (!string.IsNullOrEmpty(__instance.restorePreviousSelectionByFolderName) &&
|
||||
taskFolder2.FolderName.Equals(__instance.restorePreviousSelectionByFolderName, StringComparison.Ordinal))
|
||||
taskFolder2.FolderName.Equals(__instance.restorePreviousSelectionByFolderName, System.StringComparison.Ordinal))
|
||||
{
|
||||
__instance.restorePreviousSelectionFound = taskFolder2.Button;
|
||||
}
|
||||
}
|
||||
|
||||
var flag = false;
|
||||
var list = taskFolder.Children.ToArray().OrderBy(t => t.TaskType).ToList();
|
||||
var list = new List<PlayerTask>();
|
||||
|
||||
foreach (var item in taskFolder.Children)
|
||||
{
|
||||
list.Add(item);
|
||||
}
|
||||
|
||||
for (var l = 0; l < list.Count; l++)
|
||||
{
|
||||
@@ -188,24 +190,26 @@ public static class TaskAdderPatch
|
||||
case TaskTypes.DivertPower:
|
||||
{
|
||||
var targetSystem = taskAddButton.MyTask.Cast<DivertPowerTask>().TargetSystem;
|
||||
taskAddButton.Text.text = TranslationController.Instance.GetString(
|
||||
taskAddButton.Text.text = DestroyableSingleton<TranslationController>.Instance.GetString(
|
||||
StringNames.DivertPowerTo,
|
||||
TranslationController.Instance.GetString(targetSystem));
|
||||
DestroyableSingleton<TranslationController>.Instance.GetString(targetSystem));
|
||||
break;
|
||||
}
|
||||
case TaskTypes.FixWeatherNode:
|
||||
{
|
||||
var nodeId = taskAddButton.MyTask.Cast<WeatherNodeTask>().NodeId;
|
||||
var nodeId = ((WeatherNodeTask)taskAddButton.MyTask).NodeId;
|
||||
taskAddButton.Text.text =
|
||||
TranslationController.Instance.GetString(
|
||||
StringNames.FixWeatherNode) + " " +
|
||||
TranslationController.Instance.GetString(
|
||||
WeatherSwitchGame.ControlNames[nodeId]);
|
||||
DestroyableSingleton<TranslationController>.Instance.GetString(
|
||||
StringNames.FixWeatherNode,
|
||||
Array.Empty<Il2CppSystem.Object>()) + " " +
|
||||
DestroyableSingleton<TranslationController>.Instance.GetString(
|
||||
WeatherSwitchGame.ControlNames[nodeId],
|
||||
Array.Empty<Il2CppSystem.Object>());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
taskAddButton.Text.text =
|
||||
TranslationController.Instance.GetString(taskAddButton.MyTask.TaskType);
|
||||
DestroyableSingleton<TranslationController>.Instance.GetString(taskAddButton.MyTask.TaskType);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -234,9 +238,9 @@ public static class TaskAdderPatch
|
||||
|
||||
if (taskFolder.FolderName == "Roles")
|
||||
{
|
||||
for (var m = 0; m < RoleManager.Instance.AllRoles.Length; m++)
|
||||
for (var m = 0; m < DestroyableSingleton<RoleManager>.Instance.AllRoles.Length; m++)
|
||||
{
|
||||
var roleBehaviour = RoleManager.Instance.AllRoles[m];
|
||||
var roleBehaviour = DestroyableSingleton<RoleManager>.Instance.AllRoles[m];
|
||||
if (roleBehaviour.Role == RoleTypes.ImpostorGhost || roleBehaviour.Role == RoleTypes.CrewmateGhost ||
|
||||
CustomRoleManager.CustomRoles.ContainsKey((ushort)roleBehaviour.Role))
|
||||
{
|
||||
|
||||
@@ -6,17 +6,12 @@ using UnityEngine;
|
||||
namespace MiraAPI.Patches.Roles;
|
||||
|
||||
/// <summary>
|
||||
/// Vent patches for Roles.
|
||||
/// Set vent outline color based on the player's role.
|
||||
/// </summary>
|
||||
[HarmonyPatch(typeof(Vent))]
|
||||
public static class VentPatches
|
||||
[HarmonyPatch(typeof(Vent), nameof(Vent.SetOutline))]
|
||||
public static class VentOutlinePatch
|
||||
{
|
||||
/// <summary>
|
||||
/// Set outline to player's custom role color.
|
||||
/// </summary>
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(nameof(Vent.SetOutline))]
|
||||
public static void SetOutlinePostfix(Vent __instance, bool on, bool mainTarget)
|
||||
public static void Postfix(Vent __instance, bool on, bool mainTarget)
|
||||
{
|
||||
if (PlayerControl.LocalPlayer.Data.Role is not ICustomRole customRole)
|
||||
{
|
||||
@@ -1,8 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using BepInEx.Unity.IL2CPP;
|
||||
using BepInEx.Unity.IL2CPP;
|
||||
using MiraAPI.Animations;
|
||||
using MiraAPI.Colors;
|
||||
using MiraAPI.GameOptions;
|
||||
using MiraAPI.GameOptions.Attributes;
|
||||
@@ -10,17 +7,29 @@ using MiraAPI.Hud;
|
||||
using MiraAPI.Modifiers;
|
||||
using MiraAPI.Roles;
|
||||
using MiraAPI.Utilities;
|
||||
using MiraAPI.Utilities.Assets;
|
||||
using Reactor.Networking;
|
||||
using Reactor.Utilities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
namespace MiraAPI.PluginLoading;
|
||||
|
||||
internal sealed class MiraPluginManager
|
||||
{
|
||||
private readonly Dictionary<Assembly, MiraPluginInfo> _registeredPlugins = [];
|
||||
|
||||
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();
|
||||
|
||||
internal void Initialize()
|
||||
@@ -36,6 +45,7 @@ internal sealed class MiraPluginManager
|
||||
var info = new MiraPluginInfo(miraPlugin, pluginInfo);
|
||||
|
||||
RegisterModifierAttribute(assembly);
|
||||
RegisterAnimPresetAttribute(assembly);
|
||||
RegisterAllOptions(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)
|
||||
{
|
||||
foreach (var type in assembly.GetTypes())
|
||||
|
||||
@@ -1,126 +0,0 @@
|
||||
using AmongUs.GameOptions;
|
||||
using MiraAPI.Utilities.Assets;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.Roles;
|
||||
|
||||
/// <summary>
|
||||
/// Used to configure the specific settings of a role.
|
||||
/// </summary>
|
||||
public struct CustomRoleConfiguration
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="CustomRoleConfiguration"/> struct.
|
||||
/// </summary>
|
||||
/// <param name="role">The role in which you are configuring.</param>
|
||||
public CustomRoleConfiguration(ICustomRole role)
|
||||
{
|
||||
MaxRoleCount = 15;
|
||||
DefaultRoleCount = 0;
|
||||
DefaultChance = 0;
|
||||
|
||||
OptionsScreenshot = Icon = MiraAssets.Empty;
|
||||
AffectedByLightOnAirship = role.Team == ModdedRoleTeams.Crewmate;
|
||||
KillButtonOutlineColor = role.Team switch
|
||||
{
|
||||
ModdedRoleTeams.Impostor => Palette.ImpostorRed,
|
||||
ModdedRoleTeams.Crewmate => Palette.CrewmateBlue,
|
||||
_ => role.RoleColor,
|
||||
};
|
||||
RoleHintType = RoleHintType.RoleTab;
|
||||
GhostRole = role.Team == ModdedRoleTeams.Impostor ? RoleTypes.ImpostorGhost : RoleTypes.CrewmateGhost;
|
||||
CanGetKilled = role.Team == ModdedRoleTeams.Crewmate;
|
||||
UseVanillaKillButton = role.Team == ModdedRoleTeams.Impostor;
|
||||
CanUseVent = role.Team == ModdedRoleTeams.Impostor;
|
||||
CanUseSabotage = role.Team == ModdedRoleTeams.Impostor;
|
||||
TasksCountForProgress = role.Team == ModdedRoleTeams.Crewmate;
|
||||
IsGhostRole = false;
|
||||
HideSettings = IsGhostRole;
|
||||
CanModifyChance = true;
|
||||
}
|
||||
|
||||
/// <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>
|
||||
public int MaxRoleCount;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the default role count.
|
||||
/// </summary>
|
||||
public int DefaultRoleCount;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the default role chance.
|
||||
/// </summary>
|
||||
public int DefaultChance;
|
||||
|
||||
/// <summary>
|
||||
/// Whether the chance option can be changed or not.
|
||||
/// </summary>
|
||||
public bool CanModifyChance;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Sprite used for the Role Options menu screenshot.
|
||||
/// </summary>
|
||||
public LoadableAsset<Sprite> OptionsScreenshot;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Sprite used for the Role Icon.
|
||||
/// </summary>
|
||||
public LoadableAsset<Sprite> Icon;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the role is affected by light affectors on Airship.
|
||||
/// </summary>
|
||||
public bool AffectedByLightOnAirship;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the role can be killed by vanilla murder system.
|
||||
/// </summary>
|
||||
public bool CanGetKilled;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the role should use the vanilla kill button.
|
||||
/// </summary>
|
||||
public bool UseVanillaKillButton;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the role can use vents.
|
||||
/// </summary>
|
||||
public bool CanUseVent;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the role can use the sabotage button.
|
||||
/// </summary>
|
||||
public bool CanUseSabotage;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the role's tasks count towards task progress.
|
||||
/// </summary>
|
||||
public bool TasksCountForProgress;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the role is a Ghost.
|
||||
/// </summary>
|
||||
public bool IsGhostRole;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the role should show up in the Role Options menu.
|
||||
/// </summary>
|
||||
public bool HideSettings;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the outline color for the KillButton if <see cref="UseVanillaKillButton"/> is true.
|
||||
/// </summary>
|
||||
public Color KillButtonOutlineColor;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the role hint style. See <see cref="RoleHintType"/> enum for all options.
|
||||
/// </summary>
|
||||
public RoleHintType RoleHintType;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Ghost role that is applied when the player is killed.
|
||||
/// </summary>
|
||||
public RoleTypes GhostRole;
|
||||
}
|
||||
@@ -36,7 +36,7 @@ public static class CustomRoleManager
|
||||
{
|
||||
RoleManager.Instance.AllRoles = RoleManager.Instance.AllRoles.Concat(CustomRoles.Values).ToArray();
|
||||
|
||||
foreach (var role in CustomRoles.Values.Where(x => x.IsDead))
|
||||
foreach (var role in CustomRoles.Values.Where(x=>x.IsDead))
|
||||
{
|
||||
RoleManager.GhostRoles.Add(role.Role);
|
||||
}
|
||||
@@ -84,21 +84,21 @@ public static class CustomRoleManager
|
||||
roleBehaviour.StringName = CustomStringName.CreateAndRegister(customRole.RoleName);
|
||||
roleBehaviour.BlurbName = CustomStringName.CreateAndRegister(customRole.RoleDescription);
|
||||
roleBehaviour.BlurbNameLong = CustomStringName.CreateAndRegister(customRole.RoleLongDescription);
|
||||
roleBehaviour.AffectedByLightAffectors = customRole.Configuration.AffectedByLightOnAirship;
|
||||
roleBehaviour.CanBeKilled = customRole.Configuration.CanGetKilled;
|
||||
roleBehaviour.CanUseKillButton = customRole.Configuration.UseVanillaKillButton;
|
||||
roleBehaviour.TasksCountTowardProgress = customRole.Configuration.TasksCountForProgress;
|
||||
roleBehaviour.CanVent = customRole.Configuration.CanUseVent;
|
||||
roleBehaviour.DefaultGhostRole = customRole.Configuration.GhostRole;
|
||||
roleBehaviour.MaxCount = customRole.Configuration.MaxRoleCount;
|
||||
roleBehaviour.RoleScreenshot = customRole.Configuration.OptionsScreenshot.LoadAsset();
|
||||
roleBehaviour.AffectedByLightAffectors = customRole.AffectedByLightOnAirship;
|
||||
roleBehaviour.CanBeKilled = customRole.CanGetKilled;
|
||||
roleBehaviour.CanUseKillButton = customRole.UseVanillaKillButton;
|
||||
roleBehaviour.TasksCountTowardProgress = customRole.TasksCountForProgress;
|
||||
roleBehaviour.CanVent = customRole.CanUseVent;
|
||||
roleBehaviour.DefaultGhostRole = customRole.GhostRole;
|
||||
roleBehaviour.MaxCount = customRole.MaxPlayers;
|
||||
roleBehaviour.RoleScreenshot = customRole.OptionsScreenshot.LoadAsset();
|
||||
|
||||
if (customRole.Configuration.IsGhostRole)
|
||||
if (customRole.IsGhostRole)
|
||||
{
|
||||
RoleManager.GhostRoles.Add(roleBehaviour.Role);
|
||||
}
|
||||
|
||||
var useTaskHint = customRole.Configuration.RoleHintType is RoleHintType.TaskHint;
|
||||
var useTaskHint = customRole.RoleHintType is RoleHintType.TaskHint;
|
||||
var overridesTaskText = customRole.GetType().GetMethod("SpawnTaskHeader")?.DeclaringType == customRole.GetType();
|
||||
|
||||
if (useTaskHint && !overridesTaskText)
|
||||
@@ -108,14 +108,14 @@ public static class CustomRoleManager
|
||||
|
||||
CustomRoles.Add(roleId, roleBehaviour);
|
||||
|
||||
if (customRole.Configuration.HideSettings)
|
||||
if (customRole.HideSettings)
|
||||
{
|
||||
return roleBehaviour;
|
||||
}
|
||||
|
||||
var config = parentMod.PluginConfig;
|
||||
config.Bind(customRole.NumConfigDefinition, Mathf.Clamp(customRole.Configuration.DefaultRoleCount, 0, customRole.Configuration.MaxRoleCount));
|
||||
config.Bind(customRole.ChanceConfigDefinition, Mathf.Clamp(customRole.Configuration.DefaultChance, 0, 100));
|
||||
config.Bind(customRole.NumConfigDefinition, 1);
|
||||
config.Bind(customRole.ChanceConfigDefinition, 100);
|
||||
|
||||
return roleBehaviour;
|
||||
}
|
||||
@@ -186,7 +186,7 @@ public static class CustomRoleManager
|
||||
internal static void SyncAllRoleSettings(int targetId = -1)
|
||||
{
|
||||
var data = CustomRoles.Values
|
||||
.Where(x => x is ICustomRole { Configuration.HideSettings: false })
|
||||
.Where(x => x is ICustomRole { HideSettings: false })
|
||||
.Select(x => ((ICustomRole)x).GetNetData())
|
||||
.ChunkNetData(1000);
|
||||
|
||||
@@ -216,7 +216,7 @@ public static class CustomRoleManager
|
||||
}
|
||||
|
||||
var customRole = role as ICustomRole;
|
||||
if (customRole is null or { Configuration.HideSettings: true })
|
||||
if (customRole is null or { HideSettings: true })
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -224,7 +224,7 @@ public static class CustomRoleManager
|
||||
var num = BitConverter.ToInt32(netData.Data, 0);
|
||||
var chance = BitConverter.ToInt32(netData.Data, 4);
|
||||
|
||||
HudManager.Instance.Notifier.AddRoleSettingsChangeMessage(role.StringName, num, chance, role.TeamType, false);
|
||||
DestroyableSingleton<HudManager>.Instance.Notifier.AddRoleSettingsChangeMessage(role.StringName, num, chance, role.TeamType, false);
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
using System.Linq;
|
||||
|
||||
namespace MiraAPI.Roles;
|
||||
|
||||
/// <summary>
|
||||
/// A utility class to get the instance of a custom role.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The role you are trying to access.</typeparam>
|
||||
public static class CustomRoleSingleton<T> where T : ICustomRole
|
||||
{
|
||||
private static ICustomRole? _instance;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the instance of the role.
|
||||
/// </summary>
|
||||
#pragma warning disable CA1000
|
||||
public static ICustomRole Instance => _instance ??= CustomRoleManager.CustomRoles.Values.OfType<T>().Single();
|
||||
#pragma warning restore CA1000
|
||||
}
|
||||
@@ -1,8 +1,11 @@
|
||||
using BepInEx.Configuration;
|
||||
using System.Text;
|
||||
using AmongUs.GameOptions;
|
||||
using BepInEx.Configuration;
|
||||
using Il2CppInterop.Runtime.Attributes;
|
||||
using MiraAPI.Modifiers;
|
||||
using MiraAPI.PluginLoading;
|
||||
using MiraAPI.Utilities;
|
||||
using System.Text;
|
||||
using MiraAPI.Utilities.Assets;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.Roles;
|
||||
@@ -38,9 +41,86 @@ public interface ICustomRole
|
||||
ModdedRoleTeams Team { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Configure advanced settings of the role.
|
||||
/// Gets the hard limit of players that can have this role. This property is used to set a limit in the Role Options menu.
|
||||
/// </summary>
|
||||
CustomRoleConfiguration Configuration { get; }
|
||||
int MaxPlayers => 15;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Sprite used for the Role Options menu screenshot.
|
||||
/// </summary>
|
||||
[HideFromIl2Cpp]
|
||||
LoadableAsset<Sprite> OptionsScreenshot => MiraAssets.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Sprite used for the Role Icon.
|
||||
/// </summary>
|
||||
[HideFromIl2Cpp]
|
||||
LoadableAsset<Sprite> Icon => MiraAssets.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the role is affected by light affectors on Airship.
|
||||
/// </summary>
|
||||
bool AffectedByLightOnAirship => Team == ModdedRoleTeams.Crewmate;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the role can be killed by vanilla murder system.
|
||||
/// </summary>
|
||||
bool CanGetKilled => Team == ModdedRoleTeams.Crewmate;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the role should use the vanilla kill button.
|
||||
/// </summary>
|
||||
bool UseVanillaKillButton => Team == ModdedRoleTeams.Impostor;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the role can use vents.
|
||||
/// </summary>
|
||||
bool CanUseVent => Team == ModdedRoleTeams.Impostor;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the role's tasks count towards task progress.
|
||||
/// </summary>
|
||||
bool TasksCountForProgress => Team == ModdedRoleTeams.Crewmate;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the role is a Ghost.
|
||||
/// </summary>
|
||||
bool IsGhostRole => false;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the role should show up in the Role Options menu.
|
||||
/// </summary>
|
||||
bool HideSettings => IsGhostRole;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the outline color for the KillButton if <see cref="UseVanillaKillButton"/> is true.
|
||||
/// </summary>
|
||||
Color KillButtonOutlineColor => Team switch
|
||||
{
|
||||
ModdedRoleTeams.Impostor => Palette.ImpostorRed,
|
||||
ModdedRoleTeams.Crewmate => Palette.CrewmateBlue,
|
||||
_ => RoleColor,
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Gets the role hint style. See <see cref="RoleHintType"/> enum for all options.
|
||||
/// </summary>
|
||||
RoleHintType RoleHintType => RoleHintType.RoleTab;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Ghost role that is applied when the player is killed.
|
||||
/// </summary>
|
||||
RoleTypes GhostRole => Team == ModdedRoleTeams.Impostor ? RoleTypes.ImpostorGhost : RoleTypes.CrewmateGhost;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the BepInEx ConfigDefinition for the amount of players that can have this role.
|
||||
/// </summary>
|
||||
ConfigDefinition NumConfigDefinition => new("Roles", $"Num {GetType().FullName}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets the BepInEx ConfigDefinition for the chance of this role being selected.
|
||||
/// </summary>
|
||||
ConfigDefinition ChanceConfigDefinition => new("Roles", $"Chance {GetType().FullName}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets the parent mod of this role.
|
||||
@@ -55,36 +135,6 @@ public interface ICustomRole
|
||||
{
|
||||
}
|
||||
|
||||
internal ConfigDefinition NumConfigDefinition => new("Roles", $"Num {GetType().FullName}");
|
||||
internal ConfigDefinition ChanceConfigDefinition => new("Roles", $"Chance {GetType().FullName}");
|
||||
|
||||
/// <summary>
|
||||
/// Get the role chance option.
|
||||
/// </summary>
|
||||
/// <returns>The role chance option.</returns>
|
||||
public int? GetChance()
|
||||
{
|
||||
if (ParentMod.PluginConfig.TryGetEntry(ChanceConfigDefinition, out ConfigEntry<int> entry))
|
||||
{
|
||||
return Mathf.Clamp(entry.Value, 0, 100);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the role count option.
|
||||
/// </summary>
|
||||
/// <returns>The role count option.</returns>
|
||||
public int? GetCount()
|
||||
{
|
||||
if (ParentMod.PluginConfig.TryGetEntry(NumConfigDefinition, out ConfigEntry<int> entry))
|
||||
{
|
||||
return Mathf.Clamp(entry.Value, 0, Configuration.MaxRoleCount);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
/// <summary>
|
||||
/// This method runs on the HudManager.Update method ONLY when the LOCAL player has this role.
|
||||
/// </summary>
|
||||
|
||||
@@ -16,7 +16,7 @@ public enum RoleHintType
|
||||
TaskHint,
|
||||
|
||||
/// <summary>
|
||||
/// Use Mira's custom role tab.
|
||||
/// Use custom role tab.
|
||||
/// </summary>
|
||||
RoleTab,
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using MiraAPI.PluginLoading;
|
||||
using Reactor.Utilities.Extensions;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.Utilities.Assets;
|
||||
@@ -10,8 +11,30 @@ namespace MiraAPI.Utilities.Assets;
|
||||
/// <param name="name">The name of 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>
|
||||
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>
|
||||
/// Loads the asset from the asset bundle.
|
||||
/// </summary>
|
||||
@@ -24,11 +47,11 @@ public class LoadableBundleAsset<T>(string name, AssetBundle bundle) : LoadableA
|
||||
return LoadedAsset;
|
||||
}
|
||||
|
||||
LoadedAsset = bundle.LoadAsset<T>(name);
|
||||
LoadedAsset = _bundle.LoadAsset<T>(_name);
|
||||
|
||||
if (LoadedAsset == null)
|
||||
{
|
||||
throw new InvalidOperationException($"INVALID ASSET: {name}");
|
||||
throw new InvalidOperationException($"INVALID ASSET: {_name}");
|
||||
}
|
||||
|
||||
return LoadedAsset;
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace MiraAPI.Utilities.Assets;
|
||||
/// A utility class for loading assets from embedded resources.
|
||||
/// </summary>
|
||||
/// <param name="path">The path to the embedded resource.</param>
|
||||
public class LoadableResourceAsset(string path, float pixelsPerUnit=100f) : LoadableAsset<Sprite>
|
||||
public class LoadableResourceAsset(string path) : LoadableAsset<Sprite>
|
||||
{
|
||||
private readonly Assembly _assembly = Assembly.GetCallingAssembly();
|
||||
|
||||
@@ -19,6 +19,6 @@ public class LoadableResourceAsset(string path, float pixelsPerUnit=100f) : Load
|
||||
return LoadedAsset;
|
||||
}
|
||||
|
||||
return LoadedAsset = SpriteTools.LoadSpriteFromPath(path, _assembly, pixelsPerUnit);
|
||||
return LoadedAsset = SpriteTools.LoadSpriteFromPath(path, _assembly);
|
||||
}
|
||||
}
|
||||
@@ -39,7 +39,7 @@ public static class SpriteTools
|
||||
/// <param name="resourcePath">The path to the resource.</param>
|
||||
/// <returns>A sprite made from the resource.</returns>
|
||||
/// <exception cref="Exception">The resource cannot be found.</exception>
|
||||
public static Sprite LoadSpriteFromPath(string resourcePath, Assembly assembly, float pixelsPerUnit)
|
||||
public static Sprite LoadSpriteFromPath(string resourcePath, Assembly assembly)
|
||||
{
|
||||
var tex = new Texture2D(1, 1, TextureFormat.ARGB32, false);
|
||||
var myStream = assembly.GetManifestResourceStream(resourcePath);
|
||||
@@ -53,6 +53,6 @@ public static class SpriteTools
|
||||
Logger<MiraApiPlugin>.Error($"Resource not found: {resourcePath}\nReturning empty sprite!");
|
||||
}
|
||||
|
||||
return Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), new Vector2(0.5f, 0.5f), pixelsPerUnit);
|
||||
return Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), new Vector2(0.5f, 0.5f));
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using HarmonyLib;
|
||||
using MiraAPI.Animations;
|
||||
using MiraAPI.GameOptions;
|
||||
using MiraAPI.Modifiers;
|
||||
using MiraAPI.Networking;
|
||||
using MiraAPI.Roles;
|
||||
using Reactor.Networking.Attributes;
|
||||
using Reactor.Utilities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.Utilities;
|
||||
@@ -22,9 +23,7 @@ public static class Extensions
|
||||
role.ParentMod.PluginConfig.TryGetEntry<int>(role.NumConfigDefinition, out var numEntry);
|
||||
role.ParentMod.PluginConfig.TryGetEntry<int>(role.ChanceConfigDefinition, out var chanceEntry);
|
||||
|
||||
return new NetData(
|
||||
RoleId.Get(role.GetType()),
|
||||
BitConverter.GetBytes(numEntry.Value).AddRangeToArray(BitConverter.GetBytes(chanceEntry.Value)));
|
||||
return new NetData(RoleId.Get(role.GetType()), BitConverter.GetBytes(numEntry.Value).AddRangeToArray(BitConverter.GetBytes(chanceEntry.Value)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -114,11 +113,11 @@ public static class Extensions
|
||||
/// <returns>True if the OptionBehaviour is for a custom options, false otherwise.</returns>
|
||||
public static bool IsCustom(this OptionBehaviour optionBehaviour)
|
||||
{
|
||||
return ModdedOptionsManager.ModdedOptions.Values.Any(
|
||||
opt => opt.OptionBehaviour && opt.OptionBehaviour == optionBehaviour);
|
||||
return ModdedOptionsManager.ModdedOptions.Values.Any(opt => opt.OptionBehaviour && opt.OptionBehaviour == optionBehaviour);
|
||||
}
|
||||
|
||||
internal static Dictionary<PlayerControl, ModifierComponent> ModifierComponents { get; } = [];
|
||||
private static readonly Dictionary<PlayerControl, ModifierComponent> ModifierComponents = [];
|
||||
private static readonly Dictionary<PlayerControl, CustomAnimator> AnimatorComponents = [];
|
||||
|
||||
/// <summary>
|
||||
/// Gets the ModifierComponent for a player.
|
||||
@@ -133,12 +132,32 @@ public static class Extensions
|
||||
}
|
||||
|
||||
component = player.GetComponent<ModifierComponent>();
|
||||
if (component == null)
|
||||
if (component)
|
||||
{
|
||||
return null;
|
||||
ModifierComponents[player] = 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;
|
||||
}
|
||||
|
||||
ModifierComponents[player] = component;
|
||||
return component;
|
||||
}
|
||||
|
||||
@@ -158,7 +177,6 @@ public static class Extensions
|
||||
randomizedList.Add(list[index]);
|
||||
list.RemoveAt(index);
|
||||
}
|
||||
|
||||
return randomizedList;
|
||||
}
|
||||
|
||||
@@ -181,8 +199,7 @@ public static class Extensions
|
||||
/// <returns>True if the Modifier is present, false otherwise.</returns>
|
||||
public static bool HasModifier<T>(this PlayerControl? player) where T : BaseModifier
|
||||
{
|
||||
return player?.GetModifierComponent() != null &&
|
||||
player.GetModifierComponent()!.ActiveModifiers.Exists(x => x is T);
|
||||
return player?.GetModifierComponent() != null && player.GetModifierComponent()!.ActiveModifiers.Exists(x => x is T);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -193,8 +210,7 @@ public static class Extensions
|
||||
/// <returns>True if the Modifier is present, false otherwise.</returns>
|
||||
public static bool HasModifier(this PlayerControl? player, uint id)
|
||||
{
|
||||
return player?.GetModifierComponent() != null &&
|
||||
player.GetModifierComponent()!.ActiveModifiers.Exists(x => x.ModifierId == id);
|
||||
return player?.GetModifierComponent() != null && player.GetModifierComponent()!.ActiveModifiers.Exists(x => x.ModifierId == id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -240,7 +256,6 @@ public static class Extensions
|
||||
Logger<MiraApiPlugin>.Error($"Cannot add modifier with id {modifierId} because it is not registered.");
|
||||
return;
|
||||
}
|
||||
|
||||
target.GetModifierComponent()?.AddModifier(type);
|
||||
}
|
||||
|
||||
@@ -312,9 +327,7 @@ public static class Extensions
|
||||
/// <returns>The dead body if it is found, or null there is none within the radius.</returns>
|
||||
public static DeadBody? GetNearestDeadBody(this PlayerControl playerControl, float radius)
|
||||
{
|
||||
return Helpers
|
||||
.GetNearestDeadBodies(playerControl.GetTruePosition(), radius, Helpers.CreateFilter(Constants.NotShipMask))
|
||||
.Find(component => component && !component.Reported);
|
||||
return Helpers.GetNearestDeadBodies(playerControl.GetTruePosition(), radius).Find(component => component && !component.Reported);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -322,46 +335,29 @@ public static class Extensions
|
||||
/// </summary>
|
||||
/// <param name="playerControl">The player object.</param>
|
||||
/// <param name="radius">The radius to search within.</param>
|
||||
/// <param name="filter">The contact filter.</param>
|
||||
/// <param name="colliderTag">An optional collider tag.</param>
|
||||
/// <param name="predicate">Optional predicate to test if the object is valid.</param>
|
||||
/// <typeparam name="T">The type of the object.</typeparam>
|
||||
/// <returns>The object if it was found, or null if there is none within the radius.</returns>
|
||||
public static T? GetNearestObjectOfType<T>(
|
||||
this PlayerControl playerControl,
|
||||
float radius,
|
||||
ContactFilter2D filter,
|
||||
string? colliderTag = null,
|
||||
Predicate<T>? predicate = null) where T : Component
|
||||
public static T? GetNearestObjectOfType<T>(this PlayerControl playerControl, float radius, string? colliderTag = null, Predicate<T>? predicate = null) where T : Component
|
||||
{
|
||||
return Helpers.GetNearestObjectsOfType<T>(playerControl.GetTruePosition(), radius, filter, colliderTag)
|
||||
.Find(predicate ?? (component => component));
|
||||
return Helpers.GetNearestObjectsOfType<T>(playerControl.GetTruePosition(), radius, colliderTag).Find(predicate ?? (component => component));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the closest player that matches the given criteria.
|
||||
/// Gets the nearest player to a player.
|
||||
/// </summary>
|
||||
/// <param name="playerControl">The player object.</param>
|
||||
/// <param name="includeImpostors">Whether impostors should be included in the search.</param>
|
||||
/// <param name="distance">The radius to search within.</param>
|
||||
/// <param name="ignoreColliders">Whether colliders should be ignored when searching.</param>
|
||||
/// <param name="predicate">Optional predicate to test if the object is valid.</param>
|
||||
/// <returns>The closest player if there is one, false otherwise.</returns>
|
||||
public static PlayerControl? GetClosestPlayer(
|
||||
this PlayerControl playerControl,
|
||||
bool includeImpostors,
|
||||
float distance,
|
||||
bool ignoreColliders = false,
|
||||
Predicate<PlayerControl>? predicate = null)
|
||||
public static PlayerControl? GetClosestPlayer(this PlayerControl playerControl, bool includeImpostors, float distance, bool ignoreColliders = false)
|
||||
{
|
||||
var filteredPlayers = Helpers.GetClosestPlayers(playerControl, distance, ignoreColliders)
|
||||
.Where(
|
||||
playerInfo => !playerInfo.Data.Disconnected &&
|
||||
playerInfo.PlayerId != playerControl.PlayerId &&
|
||||
!playerInfo.Data.IsDead &&
|
||||
(includeImpostors || !playerInfo.Data.Role.IsImpostor))
|
||||
.ToList();
|
||||
.Where(playerInfo => !playerInfo.Data.Disconnected && playerInfo.PlayerId != playerControl.PlayerId && !playerInfo.Data.IsDead &&
|
||||
(includeImpostors || !playerInfo.Data.Role.IsImpostor));
|
||||
|
||||
return predicate != null ? filteredPlayers.Find(predicate) : filteredPlayers.FirstOrDefault();
|
||||
return filteredPlayers.FirstOrDefault();
|
||||
}
|
||||
}
|
||||
@@ -15,14 +15,12 @@ namespace MiraAPI.Utilities;
|
||||
public static class Helpers
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a ContactFilter2D from a layer mask.
|
||||
/// NotShipMask filter for collisions.
|
||||
/// </summary>
|
||||
/// <param name="layerMask">The layer mask.</param>
|
||||
/// <returns>A new ContactFilter2D that represents the layer mask.</returns>
|
||||
public static ContactFilter2D CreateFilter(int layerMask)
|
||||
{
|
||||
return ContactFilter2D.CreateLegacyFilter(layerMask, float.MinValue, float.MaxValue);
|
||||
}
|
||||
public static readonly ContactFilter2D Filter = ContactFilter2D.CreateLegacyFilter(
|
||||
Constants.NotShipMask,
|
||||
float.MinValue,
|
||||
float.MaxValue);
|
||||
|
||||
/// <summary>
|
||||
/// Get the room at a specific position.
|
||||
@@ -39,12 +37,11 @@ public static class Helpers
|
||||
/// </summary>
|
||||
/// <param name="source">The source location.</param>
|
||||
/// <param name="radius">The radius to search in.</param>
|
||||
/// <param name="filter">The contact filter.</param>
|
||||
/// <returns>A list of dead bodies.</returns>
|
||||
public static List<DeadBody> GetNearestDeadBodies(Vector2 source, float radius, ContactFilter2D filter)
|
||||
public static List<DeadBody> GetNearestDeadBodies(Vector2 source, float radius)
|
||||
{
|
||||
var results = new Il2CppSystem.Collections.Generic.List<Collider2D>();
|
||||
Physics2D.OverlapCircle(source, radius, filter, results);
|
||||
Physics2D.OverlapCircle(source, radius, Filter, results);
|
||||
return results.ToArray()
|
||||
.Where(collider2D => collider2D.CompareTag("DeadBody"))
|
||||
.Select(collider2D => collider2D.GetComponent<DeadBody>()).ToList();
|
||||
@@ -55,15 +52,14 @@ public static class Helpers
|
||||
/// </summary>
|
||||
/// <param name="source">The source point.</param>
|
||||
/// <param name="radius">The radius to search in.</param>
|
||||
/// <param name="filter">The contact filter.</param>
|
||||
/// <param name="colliderTag">An optional collider tag.</param>
|
||||
/// <typeparam name="T">The type of the object.</typeparam>
|
||||
/// <returns>A list of objects of type T.</returns>
|
||||
public static List<T> GetNearestObjectsOfType<T>(Vector2 source, float radius, ContactFilter2D filter, string? colliderTag = null)
|
||||
public static List<T> GetNearestObjectsOfType<T>(Vector2 source, float radius, string? colliderTag = null)
|
||||
where T : Component
|
||||
{
|
||||
var results = new Il2CppSystem.Collections.Generic.List<Collider2D>();
|
||||
Physics2D.OverlapCircle(source, radius, filter, results);
|
||||
Physics2D.OverlapCircle(source, radius, Filter, results);
|
||||
return results.ToArray()
|
||||
.Where(collider2D => colliderTag == null || collider2D.CompareTag(colliderTag))
|
||||
.Select(collider2D => collider2D.GetComponent<T>()).ToList();
|
||||
@@ -81,7 +77,7 @@ public static class Helpers
|
||||
float radius,
|
||||
bool ignoreColliders = true)
|
||||
{
|
||||
var newList = GetNearestObjectsOfType<PlayerControl>(source, radius, CreateFilter(Constants.NotShipMask));
|
||||
var newList = GetNearestObjectsOfType<PlayerControl>(source, radius);
|
||||
|
||||
if (!ignoreColliders)
|
||||
{
|
||||
|
||||
@@ -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)]`
|
||||
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).
|
||||
|
||||
## Recommended Project Structure
|
||||
|
||||
Reference in new issue
Block a user