mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-10-20 11:39:45 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1fa30485b0 | ||
|
|
faed84d0f6 | ||
|
|
2f7b0692f3 | ||
|
|
8123381e1e | ||
|
|
4d36c13c5b | ||
|
|
91b7901528 | ||
|
|
9a27a0c3d8 | ||
|
|
cda441ee56 | ||
|
|
6ee83f8c7d | ||
|
|
8712a2b4e7 | ||
|
|
30d2edfd9c | ||
|
|
76cb2a6a59 | ||
|
|
f20e7459a4 | ||
|
|
f462a116d7 | ||
|
|
6f771821c8 | ||
|
|
754b8ef684 | ||
|
|
d8eb671b49 | ||
|
|
24ebee2743 | ||
|
|
878cf15a20 | ||
|
|
2f7cf4d664 | ||
|
|
4fcfb2a9ee | ||
|
|
41bedd3e16 | ||
|
|
d27bf67f65 | ||
|
|
76ddfa4126 | ||
|
|
400ad535a4 | ||
|
|
eaf5890f67 | ||
|
|
b2651adcab | ||
|
|
c8c6ab1f61 | ||
|
|
7f65f2d5bb | ||
|
|
17da594207 | ||
|
|
75dd5e8a35 |
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.8.13" PrivateAssets="all" />
|
<PackageReference Include="AmongUs.GameLibs.Steam" Version="2024.9.4" 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.4</VersionPrefix>
|
<VersionPrefix>0.1.8</VersionPrefix>
|
||||||
<VersionSuffix>dev</VersionSuffix>
|
<VersionSuffix>dev</VersionSuffix>
|
||||||
|
|
||||||
<Authors>All Of Us, XtraCube, Angxl</Authors>
|
<Authors>All Of Us, XtraCube, Angxl</Authors>
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ public class MeetingButton : CustomActionButton
|
|||||||
|
|
||||||
public override bool Enabled(RoleBehaviour? role)
|
public override bool Enabled(RoleBehaviour? role)
|
||||||
{
|
{
|
||||||
return PlayerControl.LocalPlayer.HasModifier<CaptainModifier>();
|
return PlayerControl.LocalPlayer != null && PlayerControl.LocalPlayer.HasModifier<CaptainModifier>();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnClick()
|
protected override void OnClick()
|
||||||
|
|||||||
@@ -43,4 +43,4 @@ public class ChameloenRole : CrewmateRole, ICustomRole
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
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);
|
|
||||||
}
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
using UnityEngine;
|
|
||||||
|
|
||||||
namespace MiraAPI.Animations.Presets;
|
|
||||||
public class LocalAnimationPreset(AnimationClip clip) : CustomAnimationPreset(clip)
|
|
||||||
{
|
|
||||||
/// <inheritdoc/>
|
|
||||||
public override bool AnimationVisible(PlayerControl source)
|
|
||||||
{
|
|
||||||
return source.AmOwner;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
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; }
|
||||||
|
|||||||
@@ -45,6 +45,10 @@ public static class ModdedOptionsManager
|
|||||||
TypeToGroup.Add(type, group);
|
TypeToGroup.Add(type, group);
|
||||||
pluginInfo.OptionGroups.Add(group);
|
pluginInfo.OptionGroups.Add(group);
|
||||||
|
|
||||||
|
typeof(OptionGroupSingleton<>).MakeGenericType(type)
|
||||||
|
.GetField("_instance", BindingFlags.Static | BindingFlags.NonPublic)!
|
||||||
|
.SetValue(null, group);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ public class ModdedEnumOption : ModdedOption<int>
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override void OnValueChanged(int newValue)
|
protected override void OnValueChanged(int newValue)
|
||||||
{
|
{
|
||||||
DestroyableSingleton<HudManager>.Instance.Notifier.AddSettingsChangeMessage(StringName, Data?.GetValueString(newValue), false);
|
HudManager.Instance.Notifier.AddSettingsChangeMessage(StringName, Data?.GetValueString(newValue), false);
|
||||||
if (!OptionBehaviour)
|
if (!OptionBehaviour)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ public class ModdedNumberOption : ModdedOption<float>
|
|||||||
protected override void OnValueChanged(float newValue)
|
protected override void OnValueChanged(float newValue)
|
||||||
{
|
{
|
||||||
Value = Mathf.Clamp(newValue, Min, Max);
|
Value = Mathf.Clamp(newValue, Min, Max);
|
||||||
DestroyableSingleton<HudManager>.Instance.Notifier.AddSettingsChangeMessage(
|
HudManager.Instance.Notifier.AddSettingsChangeMessage(
|
||||||
StringName,
|
StringName,
|
||||||
Data?.GetValueString(Value),
|
Data?.GetValueString(Value),
|
||||||
false);
|
false);
|
||||||
|
|||||||
@@ -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.
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ public class ModdedToggleOption : ModdedOption<bool>
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override void OnValueChanged(bool newValue)
|
protected override void OnValueChanged(bool newValue)
|
||||||
{
|
{
|
||||||
DestroyableSingleton<HudManager>.Instance.Notifier.AddSettingsChangeMessage(StringName, newValue ? "On" : "Off", false);
|
HudManager.Instance.Notifier.AddSettingsChangeMessage(StringName, newValue ? "On" : "Off", false);
|
||||||
if (!OptionBehaviour)
|
if (!OptionBehaviour)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -39,11 +39,6 @@ public class ModifierComponent(IntPtr cppPtr) : MonoBehaviour(cppPtr)
|
|||||||
|
|
||||||
internal void ClearModifiers()
|
internal void ClearModifiers()
|
||||||
{
|
{
|
||||||
foreach (var modifier in Modifiers)
|
|
||||||
{
|
|
||||||
modifier.OnDeactivate();
|
|
||||||
}
|
|
||||||
|
|
||||||
_toRemove.AddRange(Modifiers);
|
_toRemove.AddRange(Modifiers);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,7 +69,7 @@ public class ModifierComponent(IntPtr cppPtr) : MonoBehaviour(cppPtr)
|
|||||||
Modifiers.Add(modifier);
|
Modifiers.Add(modifier);
|
||||||
modifier.OnActivate();
|
modifier.OnActivate();
|
||||||
|
|
||||||
if (_player?.AmOwner == true && modifier is TimedModifier { AutoStart: true } timer)
|
if (modifier is TimedModifier { AutoStart: true } timer)
|
||||||
{
|
{
|
||||||
timer.StartTimer();
|
timer.StartTimer();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,6 +39,9 @@ public abstract class TimedModifier : BaseModifier
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public float TimeRemaining { get; protected set; }
|
public float TimeRemaining { get; protected set; }
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override bool HideOnUi => !TimerActive;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the HUD information for Timed Modifier, including the time remaining.
|
/// Gets the HUD information for Timed Modifier, including the time remaining.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -53,25 +56,18 @@ public abstract class TimedModifier : BaseModifier
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public override void FixedUpdate()
|
public override void FixedUpdate()
|
||||||
{
|
{
|
||||||
if (Player?.AmOwner == false)
|
if (!TimerActive)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TimeRemaining > 0 && TimerActive)
|
if (TimeRemaining > 0)
|
||||||
{
|
{
|
||||||
TimeRemaining -= Time.fixedDeltaTime;
|
TimeRemaining -= Time.fixedDeltaTime;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
TimerActive = false;
|
StopTimer();
|
||||||
TimeRemaining = Duration;
|
|
||||||
OnTimerComplete();
|
|
||||||
|
|
||||||
if (RemoveOnComplete)
|
|
||||||
{
|
|
||||||
ModifierComponent?.RemoveModifier(ModifierId);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,7 +82,52 @@ public abstract class TimedModifier : BaseModifier
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TimeRemaining = Duration;
|
||||||
TimerActive = true;
|
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;
|
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)
|
if (flag && PlayerControl.LocalPlayer.Data.PlayerId == target.protectedByGuardianId)
|
||||||
{
|
{
|
||||||
StatsManager.Instance.IncrementStat(StringNames.StatsGuardianAngelCrewmatesProtected);
|
StatsManager.Instance.IncrementStat(StringNames.StatsGuardianAngelCrewmatesProtected);
|
||||||
DestroyableSingleton<AchievementManager>.Instance.OnProtectACrewmate();
|
AchievementManager.Instance.OnProtectACrewmate();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (source.AmOwner || flag)
|
if (source.AmOwner || flag)
|
||||||
@@ -115,7 +115,7 @@ public static class CustomMurderRpc
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
DestroyableSingleton<DebugAnalytics>.Instance.Analytics.Kill(target.Data, source.Data);
|
DebugAnalytics.Instance.Analytics.Kill(target.Data, source.Data);
|
||||||
if (source.AmOwner)
|
if (source.AmOwner)
|
||||||
{
|
{
|
||||||
StatsManager.Instance.IncrementStat(
|
StatsManager.Instance.IncrementStat(
|
||||||
@@ -139,7 +139,7 @@ public static class CustomMurderRpc
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DestroyableSingleton<UnityTelemetry>.Instance.WriteMurder();
|
UnityTelemetry.Instance.WriteMurder();
|
||||||
target.gameObject.layer = LayerMask.NameToLayer("Ghost");
|
target.gameObject.layer = LayerMask.NameToLayer("Ghost");
|
||||||
if (target.AmOwner)
|
if (target.AmOwner)
|
||||||
{
|
{
|
||||||
@@ -159,14 +159,14 @@ public static class CustomMurderRpc
|
|||||||
|
|
||||||
if (showKillAnim)
|
if (showKillAnim)
|
||||||
{
|
{
|
||||||
DestroyableSingleton<HudManager>.Instance.KillOverlay.ShowKillAnimation(source.Data, data);
|
HudManager.Instance.KillOverlay.ShowKillAnimation(source.Data, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
target.cosmetics.SetNameMask(false);
|
target.cosmetics.SetNameMask(false);
|
||||||
target.RpcSetScanner(false);
|
target.RpcSetScanner(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
DestroyableSingleton<AchievementManager>.Instance.OnMurder(
|
AchievementManager.Instance.OnMurder(
|
||||||
source.AmOwner,
|
source.AmOwner,
|
||||||
target.AmOwner,
|
target.AmOwner,
|
||||||
source.CurrentOutfitType == PlayerOutfitType.Shapeshifted,
|
source.CurrentOutfitType == PlayerOutfitType.Shapeshifted,
|
||||||
|
|||||||
@@ -34,9 +34,4 @@ public enum MiraRpc : uint
|
|||||||
/// Custom Murder RPC.
|
/// Custom Murder RPC.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
CustomMurder,
|
CustomMurder,
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Trigger Animation using CustomAnimator.
|
|
||||||
/// </summary>
|
|
||||||
TriggerAnimation,
|
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
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;
|
||||||
|
|||||||
@@ -32,16 +32,25 @@ public static class GameOptionsMenuPatch
|
|||||||
var num = 2.1f;
|
var num = 2.1f;
|
||||||
var filteredGroups =
|
var filteredGroups =
|
||||||
GameSettingMenuPatches.SelectedMod?.OptionGroups.Where(
|
GameSettingMenuPatches.SelectedMod?.OptionGroups.Where(
|
||||||
x => x.GroupVisible.Invoke() && x.AdvancedRole is null) ?? [];
|
x => x.AdvancedRole is null) ?? [];
|
||||||
|
|
||||||
foreach (var group in filteredGroups)
|
foreach (var group in filteredGroups)
|
||||||
{
|
{
|
||||||
var filteredOpts = group.Options.Where(x => x.Visible.Invoke()).ToList();
|
if (group.Options.Count == 0 || group.Header is null)
|
||||||
if (filteredOpts.Count == 0 || group.Header is null)
|
|
||||||
{
|
{
|
||||||
continue;
|
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.gameObject.SetActive(true);
|
||||||
group.Header.transform.localScale = Vector3.one * 0.63f;
|
group.Header.transform.localScale = Vector3.one * 0.63f;
|
||||||
group.Header.transform.localPosition = new Vector3(-0.903f, num, -2f);
|
group.Header.transform.localPosition = new Vector3(-0.903f, num, -2f);
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ 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;
|
||||||
@@ -128,11 +129,6 @@ 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,
|
||||||
@@ -176,11 +172,6 @@ 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(
|
||||||
@@ -399,11 +390,6 @@ public static class LobbyViewPanePatches
|
|||||||
|
|
||||||
var value = option.GetFloatData();
|
var value = option.GetFloatData();
|
||||||
|
|
||||||
if (baseGameSetting == null)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (baseGameSetting.Type == OptionTypes.Checkbox)
|
if (baseGameSetting.Type == OptionTypes.Checkbox)
|
||||||
{
|
{
|
||||||
viewSettingsInfoPanel.SetInfoCheckbox(baseGameSetting.Title, maskLayer, value > 0f);
|
viewSettingsInfoPanel.SetInfoCheckbox(baseGameSetting.Title, maskLayer, value > 0f);
|
||||||
|
|||||||
@@ -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.All(role => role.StringName != key))
|
if (CustomRoleManager.CustomRoles.Values.FirstOrDefault(x=>x.StringName==key) is not ICustomRole customRole)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -27,12 +27,14 @@ public static class NotificationPopperPatch
|
|||||||
? Palette.CrewmateSettingChangeText.ToTextColor()
|
? Palette.CrewmateSettingChangeText.ToTextColor()
|
||||||
: Palette.ImpostorRed.ToTextColor();
|
: Palette.ImpostorRed.ToTextColor();
|
||||||
|
|
||||||
var item = DestroyableSingleton<TranslationController>.Instance.GetString(
|
var item = TranslationController.Instance.GetString(
|
||||||
StringNames.LobbyChangeSettingNotificationRole,
|
StringNames.LobbyChangeSettingNotificationRole,
|
||||||
"<font=\"Barlow-Black SDF\" material=\"Barlow-Black Outline\">",
|
string.Concat(
|
||||||
text,
|
"<font=\"Barlow-Black SDF\" material=\"Barlow-Black Outline\">",
|
||||||
DestroyableSingleton<TranslationController>.Instance.GetString(key, Array.Empty<Object>()),
|
text,
|
||||||
"</color></font>",
|
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\">" + roleCount + "</font>",
|
||||||
"<font=\"Barlow-Black SDF\" material=\"Barlow-Black Outline\">" + roleChance + "%"
|
"<font=\"Barlow-Black SDF\" material=\"Barlow-Black Outline\">" + roleChance + "%"
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ public static class OptionsPatches
|
|||||||
}
|
}
|
||||||
|
|
||||||
__instance.TitleText.text =
|
__instance.TitleText.text =
|
||||||
DestroyableSingleton<TranslationController>.Instance.GetString(__instance.Title, Array.Empty<Object>());
|
TranslationController.Instance.GetString(__instance.Title, Array.Empty<Object>());
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -39,7 +39,7 @@ public static class OptionsPatches
|
|||||||
}
|
}
|
||||||
|
|
||||||
__instance.TitleText.text =
|
__instance.TitleText.text =
|
||||||
DestroyableSingleton<TranslationController>.Instance.GetString(__instance.Title, Array.Empty<Object>());
|
TranslationController.Instance.GetString(__instance.Title, Array.Empty<Object>());
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -61,8 +61,8 @@ public static class OptionsPatches
|
|||||||
}
|
}
|
||||||
|
|
||||||
__instance.TitleText.text =
|
__instance.TitleText.text =
|
||||||
DestroyableSingleton<TranslationController>.Instance.GetString(__instance.Title, Array.Empty<Object>());
|
TranslationController.Instance.GetString(__instance.Title, Array.Empty<Object>());
|
||||||
__instance.ValueText.text = DestroyableSingleton<TranslationController>.Instance.GetString(
|
__instance.ValueText.text = TranslationController.Instance.GetString(
|
||||||
__instance.Values[__instance.Value],
|
__instance.Values[__instance.Value],
|
||||||
Array.Empty<Object>());
|
Array.Empty<Object>());
|
||||||
|
|
||||||
|
|||||||
@@ -178,7 +178,7 @@ public static class RoleSettingMenuPatches
|
|||||||
}
|
}
|
||||||
|
|
||||||
roleSetting.UpdateValuesAndText(GameOptionsManager.Instance.CurrentGameOptions.RoleOptions);
|
roleSetting.UpdateValuesAndText(GameOptionsManager.Instance.CurrentGameOptions.RoleOptions);
|
||||||
DestroyableSingleton<HudManager>.Instance.Notifier.AddRoleSettingsChangeMessage(
|
HudManager.Instance.Notifier.AddRoleSettingsChangeMessage(
|
||||||
roleSetting.Role.StringName,
|
roleSetting.Role.StringName,
|
||||||
roleSetting.RoleMaxCount,
|
roleSetting.RoleMaxCount,
|
||||||
roleSetting.RoleChance,
|
roleSetting.RoleChance,
|
||||||
@@ -254,7 +254,7 @@ public static class RoleSettingMenuPatches
|
|||||||
}
|
}
|
||||||
|
|
||||||
__instance.roleDescriptionText.text = customRole.RoleLongDescription;
|
__instance.roleDescriptionText.text = customRole.RoleLongDescription;
|
||||||
__instance.roleTitleText.text = DestroyableSingleton<TranslationController>.Instance.GetString(
|
__instance.roleTitleText.text = TranslationController.Instance.GetString(
|
||||||
role.StringName,
|
role.StringName,
|
||||||
new Il2CppReferenceArray<Il2CppSystem.Object>(0));
|
new Il2CppReferenceArray<Il2CppSystem.Object>(0));
|
||||||
__instance.roleScreenshot.sprite = Sprite.Create(
|
__instance.roleScreenshot.sprite = Sprite.Create(
|
||||||
|
|||||||
@@ -39,9 +39,9 @@ public static class SettingPatches
|
|||||||
MiraNumberSuffixes.None => value.ToString(__instance.FormatString, NumberFormatInfo.InvariantInfo),
|
MiraNumberSuffixes.None => value.ToString(__instance.FormatString, NumberFormatInfo.InvariantInfo),
|
||||||
MiraNumberSuffixes.Multiplier => value.ToString(__instance.FormatString, NumberFormatInfo.InvariantInfo) + "x",
|
MiraNumberSuffixes.Multiplier => value.ToString(__instance.FormatString, NumberFormatInfo.InvariantInfo) + "x",
|
||||||
MiraNumberSuffixes.Percent => value.ToString(__instance.FormatString, NumberFormatInfo.InvariantInfo) + "%",
|
MiraNumberSuffixes.Percent => value.ToString(__instance.FormatString, NumberFormatInfo.InvariantInfo) + "%",
|
||||||
_ => DestroyableSingleton<TranslationController>.Instance.GetString(
|
_ => TranslationController.Instance.GetString(
|
||||||
StringNames.GameSecondsAbbrev,
|
StringNames.GameSecondsAbbrev,
|
||||||
(Il2CppSystem.Object[]) [value.ToString(__instance.FormatString, CultureInfo.InvariantCulture)]),
|
(Il2CppSystem.Object[])[value.ToString(__instance.FormatString, CultureInfo.InvariantCulture)]),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
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;
|
||||||
@@ -14,9 +13,9 @@ namespace MiraAPI.Patches;
|
|||||||
public static class PlayerControlPatches
|
public static class PlayerControlPatches
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds the modifier and animator component to the player on start.
|
/// Adds the modifier component to the player on start.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="__instance">The player which will be given the components.</param>
|
/// <param name="__instance">PlayerControl instance.</param>
|
||||||
[HarmonyPrefix]
|
[HarmonyPrefix]
|
||||||
[HarmonyPatch(nameof(PlayerControl.Start))]
|
[HarmonyPatch(nameof(PlayerControl.Start))]
|
||||||
public static void PlayerControlStartPostfix(PlayerControl __instance)
|
public static void PlayerControlStartPostfix(PlayerControl __instance)
|
||||||
@@ -26,20 +25,13 @@ 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="__instance">PlayerControl instance.</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)
|
||||||
@@ -48,14 +40,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>
|
/// <param name="__instance">PlayerControl instance.</param>
|
||||||
[HarmonyPostfix]
|
[HarmonyPostfix]
|
||||||
[HarmonyPatch(nameof(PlayerControl.FixedUpdate))]
|
[HarmonyPatch(nameof(PlayerControl.FixedUpdate))]
|
||||||
public static void PlayerControlFixedUpdatePostfix(PlayerControl __instance)
|
public static void PlayerControlFixedUpdatePostfix(PlayerControl __instance)
|
||||||
@@ -85,4 +77,15 @@ public static class PlayerControlPatches
|
|||||||
button.FixedUpdateHandler(__instance);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -27,10 +27,11 @@ public static class HudManagerPatches
|
|||||||
{
|
{
|
||||||
var flag = localPlayer.Data != null && localPlayer.Data.IsDead;
|
var flag = localPlayer.Data != null && localPlayer.Data.IsDead;
|
||||||
|
|
||||||
if (role is ICustomRole)
|
if (role is ICustomRole customRole)
|
||||||
{
|
{
|
||||||
__instance.KillButton.ToggleVisible(isActive && role.CanUseKillButton && !flag);
|
__instance.KillButton.ToggleVisible(isActive && customRole.UseVanillaKillButton && !flag);
|
||||||
__instance.ImpostorVentButton.ToggleVisible(isActive && role.CanVent && !flag);
|
__instance.ImpostorVentButton.ToggleVisible(isActive && customRole.CanUseVent && !flag);
|
||||||
|
__instance.SabotageButton.gameObject.SetActive(isActive && customRole.CanUseSabotage);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_roleTab)
|
if (_roleTab)
|
||||||
|
|||||||
@@ -0,0 +1,62 @@
|
|||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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,7 +1,7 @@
|
|||||||
using AmongUs.GameOptions;
|
using AmongUs.GameOptions;
|
||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
using Il2CppSystem;
|
using System;
|
||||||
using Il2CppSystem.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using MiraAPI.PluginLoading;
|
using MiraAPI.PluginLoading;
|
||||||
using MiraAPI.Roles;
|
using MiraAPI.Roles;
|
||||||
using MiraAPI.Utilities.Assets;
|
using MiraAPI.Utilities.Assets;
|
||||||
@@ -12,10 +12,13 @@ using Object = UnityEngine.Object;
|
|||||||
|
|
||||||
namespace MiraAPI.Patches.Roles;
|
namespace MiraAPI.Patches.Roles;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Patch TaskAdder for organizing Roles and adding scroller.
|
||||||
|
/// </summary>
|
||||||
[HarmonyPatch]
|
[HarmonyPatch]
|
||||||
public static class TaskAdderPatch
|
public static class TaskAdderPatch
|
||||||
{
|
{
|
||||||
private static readonly System.Collections.Generic.Dictionary<string, string> ModsFolders = [];
|
private static readonly Dictionary<string, string> ModsFolders = [];
|
||||||
private static Scroller? _scroller;
|
private static Scroller? _scroller;
|
||||||
|
|
||||||
[HarmonyPostfix]
|
[HarmonyPostfix]
|
||||||
@@ -167,19 +170,14 @@ public static class TaskAdderPatch
|
|||||||
|
|
||||||
ControllerManager.Instance.AddSelectableUiElement(taskFolder2.Button);
|
ControllerManager.Instance.AddSelectableUiElement(taskFolder2.Button);
|
||||||
if (!string.IsNullOrEmpty(__instance.restorePreviousSelectionByFolderName) &&
|
if (!string.IsNullOrEmpty(__instance.restorePreviousSelectionByFolderName) &&
|
||||||
taskFolder2.FolderName.Equals(__instance.restorePreviousSelectionByFolderName, System.StringComparison.Ordinal))
|
taskFolder2.FolderName.Equals(__instance.restorePreviousSelectionByFolderName, StringComparison.Ordinal))
|
||||||
{
|
{
|
||||||
__instance.restorePreviousSelectionFound = taskFolder2.Button;
|
__instance.restorePreviousSelectionFound = taskFolder2.Button;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var flag = false;
|
var flag = false;
|
||||||
var list = new List<PlayerTask>();
|
var list = taskFolder.Children.ToArray().OrderBy(t => t.TaskType).ToList();
|
||||||
|
|
||||||
foreach (var item in taskFolder.Children)
|
|
||||||
{
|
|
||||||
list.Add(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var l = 0; l < list.Count; l++)
|
for (var l = 0; l < list.Count; l++)
|
||||||
{
|
{
|
||||||
@@ -190,26 +188,24 @@ public static class TaskAdderPatch
|
|||||||
case TaskTypes.DivertPower:
|
case TaskTypes.DivertPower:
|
||||||
{
|
{
|
||||||
var targetSystem = taskAddButton.MyTask.Cast<DivertPowerTask>().TargetSystem;
|
var targetSystem = taskAddButton.MyTask.Cast<DivertPowerTask>().TargetSystem;
|
||||||
taskAddButton.Text.text = DestroyableSingleton<TranslationController>.Instance.GetString(
|
taskAddButton.Text.text = TranslationController.Instance.GetString(
|
||||||
StringNames.DivertPowerTo,
|
StringNames.DivertPowerTo,
|
||||||
DestroyableSingleton<TranslationController>.Instance.GetString(targetSystem));
|
TranslationController.Instance.GetString(targetSystem));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TaskTypes.FixWeatherNode:
|
case TaskTypes.FixWeatherNode:
|
||||||
{
|
{
|
||||||
var nodeId = ((WeatherNodeTask)taskAddButton.MyTask).NodeId;
|
var nodeId = taskAddButton.MyTask.Cast<WeatherNodeTask>().NodeId;
|
||||||
taskAddButton.Text.text =
|
taskAddButton.Text.text =
|
||||||
DestroyableSingleton<TranslationController>.Instance.GetString(
|
TranslationController.Instance.GetString(
|
||||||
StringNames.FixWeatherNode,
|
StringNames.FixWeatherNode) + " " +
|
||||||
Array.Empty<Il2CppSystem.Object>()) + " " +
|
TranslationController.Instance.GetString(
|
||||||
DestroyableSingleton<TranslationController>.Instance.GetString(
|
WeatherSwitchGame.ControlNames[nodeId]);
|
||||||
WeatherSwitchGame.ControlNames[nodeId],
|
|
||||||
Array.Empty<Il2CppSystem.Object>());
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
taskAddButton.Text.text =
|
taskAddButton.Text.text =
|
||||||
DestroyableSingleton<TranslationController>.Instance.GetString(taskAddButton.MyTask.TaskType);
|
TranslationController.Instance.GetString(taskAddButton.MyTask.TaskType);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -238,9 +234,9 @@ public static class TaskAdderPatch
|
|||||||
|
|
||||||
if (taskFolder.FolderName == "Roles")
|
if (taskFolder.FolderName == "Roles")
|
||||||
{
|
{
|
||||||
for (var m = 0; m < DestroyableSingleton<RoleManager>.Instance.AllRoles.Length; m++)
|
for (var m = 0; m < RoleManager.Instance.AllRoles.Length; m++)
|
||||||
{
|
{
|
||||||
var roleBehaviour = DestroyableSingleton<RoleManager>.Instance.AllRoles[m];
|
var roleBehaviour = RoleManager.Instance.AllRoles[m];
|
||||||
if (roleBehaviour.Role == RoleTypes.ImpostorGhost || roleBehaviour.Role == RoleTypes.CrewmateGhost ||
|
if (roleBehaviour.Role == RoleTypes.ImpostorGhost || roleBehaviour.Role == RoleTypes.CrewmateGhost ||
|
||||||
CustomRoleManager.CustomRoles.ContainsKey((ushort)roleBehaviour.Role))
|
CustomRoleManager.CustomRoles.ContainsKey((ushort)roleBehaviour.Role))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -6,12 +6,17 @@ using UnityEngine;
|
|||||||
namespace MiraAPI.Patches.Roles;
|
namespace MiraAPI.Patches.Roles;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Set vent outline color based on the player's role.
|
/// Vent patches for Roles.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[HarmonyPatch(typeof(Vent), nameof(Vent.SetOutline))]
|
[HarmonyPatch(typeof(Vent))]
|
||||||
public static class VentOutlinePatch
|
public static class VentPatches
|
||||||
{
|
{
|
||||||
public static void Postfix(Vent __instance, bool on, bool mainTarget)
|
/// <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)
|
||||||
{
|
{
|
||||||
if (PlayerControl.LocalPlayer.Data.Role is not ICustomRole customRole)
|
if (PlayerControl.LocalPlayer.Data.Role is not ICustomRole customRole)
|
||||||
{
|
{
|
||||||
@@ -1,26 +1,35 @@
|
|||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
|
using MiraAPI.Roles;
|
||||||
using MiraAPI.Utilities;
|
using MiraAPI.Utilities;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace MiraAPI.Patches.Modifiers;
|
namespace MiraAPI.Patches;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Vent patches to make sure the player is able to use the vent.
|
||||||
|
/// </summary>
|
||||||
[HarmonyPatch(typeof(Vent))]
|
[HarmonyPatch(typeof(Vent))]
|
||||||
public static class VentPatches
|
public static class VentPatches
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// CanUse patch.
|
||||||
|
/// </summary>
|
||||||
[HarmonyPostfix]
|
[HarmonyPostfix]
|
||||||
[HarmonyPatch(nameof(Vent.CanUse))]
|
[HarmonyPatch(nameof(Vent.CanUse))]
|
||||||
public static void CanUseVentPatch(Vent __instance, ref float __result, [HarmonyArgument(0)] NetworkedPlayerInfo pc, [HarmonyArgument(1)] ref bool canUse, [HarmonyArgument(2)] ref bool couldUse)
|
public static void VentCanUsePostfix(Vent __instance, ref float __result, [HarmonyArgument(0)] NetworkedPlayerInfo pc, [HarmonyArgument(1)] ref bool canUse, [HarmonyArgument(2)] ref bool couldUse)
|
||||||
{
|
{
|
||||||
var @object = pc.Object;
|
var @object = pc.Object;
|
||||||
var role = @object.Data.Role;
|
var role = @object.Data.Role;
|
||||||
|
|
||||||
|
var canVent = role is ICustomRole customRole ? customRole.CanUseVent : role.CanVent;
|
||||||
|
|
||||||
var modifiers = @object.GetModifierComponent()?.ActiveModifiers;
|
var modifiers = @object.GetModifierComponent()?.ActiveModifiers;
|
||||||
if (modifiers is null || modifiers.Count <= 0)
|
if (modifiers is null || modifiers.Count <= 0)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (role.CanVent)
|
switch (canVent)
|
||||||
{
|
{
|
||||||
case true when modifiers.Exists(x => !x.CanVent()):
|
case true when modifiers.Exists(x => !x.CanVent()):
|
||||||
couldUse = canUse = false;
|
couldUse = canUse = false;
|
||||||
@@ -1,5 +1,8 @@
|
|||||||
using BepInEx.Unity.IL2CPP;
|
using System;
|
||||||
using MiraAPI.Animations;
|
using System.Collections.Generic;
|
||||||
|
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;
|
||||||
@@ -7,28 +10,16 @@ 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];
|
|
||||||
|
|
||||||
public List<LoadableBundleAsset<UnityEngine.Object>> BundleAssets = new();
|
internal MiraPluginInfo[] RegisteredPlugins() => [.. _registeredPlugins.Values];
|
||||||
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();
|
||||||
|
|
||||||
@@ -45,7 +36,6 @@ 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);
|
||||||
@@ -171,18 +161,6 @@ 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())
|
||||||
|
|||||||
@@ -224,7 +224,7 @@ public static class CustomRoleManager
|
|||||||
var num = BitConverter.ToInt32(netData.Data, 0);
|
var num = BitConverter.ToInt32(netData.Data, 0);
|
||||||
var chance = BitConverter.ToInt32(netData.Data, 4);
|
var chance = BitConverter.ToInt32(netData.Data, 4);
|
||||||
|
|
||||||
DestroyableSingleton<HudManager>.Instance.Notifier.AddRoleSettingsChangeMessage(role.StringName, num, chance, role.TeamType, false);
|
HudManager.Instance.Notifier.AddRoleSettingsChangeMessage(role.StringName, num, chance, role.TeamType, false);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -77,6 +77,11 @@ 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,6 +1,5 @@
|
|||||||
using MiraAPI.PluginLoading;
|
using System;
|
||||||
using Reactor.Utilities.Extensions;
|
using Reactor.Utilities.Extensions;
|
||||||
using System;
|
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace MiraAPI.Utilities.Assets;
|
namespace MiraAPI.Utilities.Assets;
|
||||||
@@ -11,30 +10,8 @@ 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> : LoadableAsset<T> where T : UnityEngine.Object
|
public class LoadableBundleAsset<T>(string name, AssetBundle bundle) : 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>
|
||||||
@@ -47,11 +24,11 @@ public class LoadableBundleAsset<T> : LoadableAsset<T> where T : UnityEngine.Obj
|
|||||||
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;
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ namespace MiraAPI.Utilities.Assets;
|
|||||||
/// A utility class for loading assets from embedded resources.
|
/// A utility class for loading assets from embedded resources.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="path">The path to the embedded resource.</param>
|
/// <param name="path">The path to the embedded resource.</param>
|
||||||
public class LoadableResourceAsset(string path) : LoadableAsset<Sprite>
|
public class LoadableResourceAsset(string path, float pixelsPerUnit=100f) : LoadableAsset<Sprite>
|
||||||
{
|
{
|
||||||
private readonly Assembly _assembly = Assembly.GetCallingAssembly();
|
private readonly Assembly _assembly = Assembly.GetCallingAssembly();
|
||||||
|
|
||||||
@@ -19,6 +19,6 @@ public class LoadableResourceAsset(string path) : LoadableAsset<Sprite>
|
|||||||
return LoadedAsset;
|
return LoadedAsset;
|
||||||
}
|
}
|
||||||
|
|
||||||
return LoadedAsset = SpriteTools.LoadSpriteFromPath(path, _assembly);
|
return LoadedAsset = SpriteTools.LoadSpriteFromPath(path, _assembly, pixelsPerUnit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -39,7 +39,7 @@ public static class SpriteTools
|
|||||||
/// <param name="resourcePath">The path to the resource.</param>
|
/// <param name="resourcePath">The path to the resource.</param>
|
||||||
/// <returns>A sprite made from the resource.</returns>
|
/// <returns>A sprite made from the resource.</returns>
|
||||||
/// <exception cref="Exception">The resource cannot be found.</exception>
|
/// <exception cref="Exception">The resource cannot be found.</exception>
|
||||||
public static Sprite LoadSpriteFromPath(string resourcePath, Assembly assembly)
|
public static Sprite LoadSpriteFromPath(string resourcePath, Assembly assembly, float pixelsPerUnit)
|
||||||
{
|
{
|
||||||
var tex = new Texture2D(1, 1, TextureFormat.ARGB32, false);
|
var tex = new Texture2D(1, 1, TextureFormat.ARGB32, false);
|
||||||
var myStream = assembly.GetManifestResourceStream(resourcePath);
|
var myStream = assembly.GetManifestResourceStream(resourcePath);
|
||||||
@@ -53,6 +53,6 @@ public static class SpriteTools
|
|||||||
Logger<MiraApiPlugin>.Error($"Resource not found: {resourcePath}\nReturning empty sprite!");
|
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));
|
return Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), new Vector2(0.5f, 0.5f), pixelsPerUnit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,14 +1,13 @@
|
|||||||
|
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;
|
||||||
@@ -23,7 +22,9 @@ public static class Extensions
|
|||||||
role.ParentMod.PluginConfig.TryGetEntry<int>(role.NumConfigDefinition, out var numEntry);
|
role.ParentMod.PluginConfig.TryGetEntry<int>(role.NumConfigDefinition, out var numEntry);
|
||||||
role.ParentMod.PluginConfig.TryGetEntry<int>(role.ChanceConfigDefinition, out var chanceEntry);
|
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>
|
/// <summary>
|
||||||
@@ -113,11 +114,11 @@ public static class Extensions
|
|||||||
/// <returns>True if the OptionBehaviour is for a custom options, false otherwise.</returns>
|
/// <returns>True if the OptionBehaviour is for a custom options, false otherwise.</returns>
|
||||||
public static bool IsCustom(this OptionBehaviour optionBehaviour)
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static readonly Dictionary<PlayerControl, ModifierComponent> ModifierComponents = [];
|
internal static Dictionary<PlayerControl, ModifierComponent> ModifierComponents { get; } = [];
|
||||||
private static readonly Dictionary<PlayerControl, CustomAnimator> AnimatorComponents = [];
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the ModifierComponent for a player.
|
/// Gets the ModifierComponent for a player.
|
||||||
@@ -132,32 +133,12 @@ public static class Extensions
|
|||||||
}
|
}
|
||||||
|
|
||||||
component = player.GetComponent<ModifierComponent>();
|
component = player.GetComponent<ModifierComponent>();
|
||||||
if (component)
|
if (component == null)
|
||||||
{
|
{
|
||||||
ModifierComponents[player] = component;
|
return null;
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
return component;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -177,6 +158,7 @@ public static class Extensions
|
|||||||
randomizedList.Add(list[index]);
|
randomizedList.Add(list[index]);
|
||||||
list.RemoveAt(index);
|
list.RemoveAt(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
return randomizedList;
|
return randomizedList;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -199,7 +181,8 @@ public static class Extensions
|
|||||||
/// <returns>True if the Modifier is present, false otherwise.</returns>
|
/// <returns>True if the Modifier is present, false otherwise.</returns>
|
||||||
public static bool HasModifier<T>(this PlayerControl? player) where T : BaseModifier
|
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>
|
/// <summary>
|
||||||
@@ -210,7 +193,8 @@ public static class Extensions
|
|||||||
/// <returns>True if the Modifier is present, false otherwise.</returns>
|
/// <returns>True if the Modifier is present, false otherwise.</returns>
|
||||||
public static bool HasModifier(this PlayerControl? player, uint id)
|
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>
|
/// <summary>
|
||||||
@@ -256,6 +240,7 @@ public static class Extensions
|
|||||||
Logger<MiraApiPlugin>.Error($"Cannot add modifier with id {modifierId} because it is not registered.");
|
Logger<MiraApiPlugin>.Error($"Cannot add modifier with id {modifierId} because it is not registered.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
target.GetModifierComponent()?.AddModifier(type);
|
target.GetModifierComponent()?.AddModifier(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -327,7 +312,9 @@ public static class Extensions
|
|||||||
/// <returns>The dead body if it is found, or null there is none within the radius.</returns>
|
/// <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)
|
public static DeadBody? GetNearestDeadBody(this PlayerControl playerControl, float radius)
|
||||||
{
|
{
|
||||||
return Helpers.GetNearestDeadBodies(playerControl.GetTruePosition(), radius).Find(component => component && !component.Reported);
|
return Helpers
|
||||||
|
.GetNearestDeadBodies(playerControl.GetTruePosition(), radius, Helpers.CreateFilter(Constants.NotShipMask))
|
||||||
|
.Find(component => component && !component.Reported);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -335,29 +322,46 @@ public static class Extensions
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="playerControl">The player object.</param>
|
/// <param name="playerControl">The player object.</param>
|
||||||
/// <param name="radius">The radius to search within.</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="colliderTag">An optional collider tag.</param>
|
||||||
/// <param name="predicate">Optional predicate to test if the object is valid.</param>
|
/// <param name="predicate">Optional predicate to test if the object is valid.</param>
|
||||||
/// <typeparam name="T">The type of the object.</typeparam>
|
/// <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>
|
/// <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, string? colliderTag = null, Predicate<T>? predicate = null) where T : Component
|
public static T? GetNearestObjectOfType<T>(
|
||||||
|
this PlayerControl playerControl,
|
||||||
|
float radius,
|
||||||
|
ContactFilter2D filter,
|
||||||
|
string? colliderTag = null,
|
||||||
|
Predicate<T>? predicate = null) where T : Component
|
||||||
{
|
{
|
||||||
return Helpers.GetNearestObjectsOfType<T>(playerControl.GetTruePosition(), radius, colliderTag).Find(predicate ?? (component => component));
|
return Helpers.GetNearestObjectsOfType<T>(playerControl.GetTruePosition(), radius, filter, colliderTag)
|
||||||
|
.Find(predicate ?? (component => component));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the nearest player to a player.
|
/// Gets the closest player that matches the given criteria.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="playerControl">The player object.</param>
|
/// <param name="playerControl">The player object.</param>
|
||||||
/// <param name="includeImpostors">Whether impostors should be included in the search.</param>
|
/// <param name="includeImpostors">Whether impostors should be included in the search.</param>
|
||||||
/// <param name="distance">The radius to search within.</param>
|
/// <param name="distance">The radius to search within.</param>
|
||||||
/// <param name="ignoreColliders">Whether colliders should be ignored when searching.</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>
|
/// <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)
|
public static PlayerControl? GetClosestPlayer(
|
||||||
|
this PlayerControl playerControl,
|
||||||
|
bool includeImpostors,
|
||||||
|
float distance,
|
||||||
|
bool ignoreColliders = false,
|
||||||
|
Predicate<PlayerControl>? predicate = null)
|
||||||
{
|
{
|
||||||
var filteredPlayers = Helpers.GetClosestPlayers(playerControl, distance, ignoreColliders)
|
var filteredPlayers = Helpers.GetClosestPlayers(playerControl, distance, ignoreColliders)
|
||||||
.Where(playerInfo => !playerInfo.Data.Disconnected && playerInfo.PlayerId != playerControl.PlayerId && !playerInfo.Data.IsDead &&
|
.Where(
|
||||||
(includeImpostors || !playerInfo.Data.Role.IsImpostor));
|
playerInfo => !playerInfo.Data.Disconnected &&
|
||||||
|
playerInfo.PlayerId != playerControl.PlayerId &&
|
||||||
|
!playerInfo.Data.IsDead &&
|
||||||
|
(includeImpostors || !playerInfo.Data.Role.IsImpostor))
|
||||||
|
.ToList();
|
||||||
|
|
||||||
return filteredPlayers.FirstOrDefault();
|
return predicate != null ? filteredPlayers.Find(predicate) : filteredPlayers.FirstOrDefault();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -15,12 +15,14 @@ namespace MiraAPI.Utilities;
|
|||||||
public static class Helpers
|
public static class Helpers
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// NotShipMask filter for collisions.
|
/// Creates a ContactFilter2D from a layer mask.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static readonly ContactFilter2D Filter = ContactFilter2D.CreateLegacyFilter(
|
/// <param name="layerMask">The layer mask.</param>
|
||||||
Constants.NotShipMask,
|
/// <returns>A new ContactFilter2D that represents the layer mask.</returns>
|
||||||
float.MinValue,
|
public static ContactFilter2D CreateFilter(int layerMask)
|
||||||
float.MaxValue);
|
{
|
||||||
|
return ContactFilter2D.CreateLegacyFilter(layerMask, float.MinValue, float.MaxValue);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get the room at a specific position.
|
/// Get the room at a specific position.
|
||||||
@@ -37,11 +39,12 @@ public static class Helpers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="source">The source location.</param>
|
/// <param name="source">The source location.</param>
|
||||||
/// <param name="radius">The radius to search in.</param>
|
/// <param name="radius">The radius to search in.</param>
|
||||||
|
/// <param name="filter">The contact filter.</param>
|
||||||
/// <returns>A list of dead bodies.</returns>
|
/// <returns>A list of dead bodies.</returns>
|
||||||
public static List<DeadBody> GetNearestDeadBodies(Vector2 source, float radius)
|
public static List<DeadBody> GetNearestDeadBodies(Vector2 source, float radius, ContactFilter2D filter)
|
||||||
{
|
{
|
||||||
var results = new Il2CppSystem.Collections.Generic.List<Collider2D>();
|
var results = new Il2CppSystem.Collections.Generic.List<Collider2D>();
|
||||||
Physics2D.OverlapCircle(source, radius, Filter, results);
|
Physics2D.OverlapCircle(source, radius, filter, results);
|
||||||
return results.ToArray()
|
return results.ToArray()
|
||||||
.Where(collider2D => collider2D.CompareTag("DeadBody"))
|
.Where(collider2D => collider2D.CompareTag("DeadBody"))
|
||||||
.Select(collider2D => collider2D.GetComponent<DeadBody>()).ToList();
|
.Select(collider2D => collider2D.GetComponent<DeadBody>()).ToList();
|
||||||
@@ -52,14 +55,15 @@ public static class Helpers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="source">The source point.</param>
|
/// <param name="source">The source point.</param>
|
||||||
/// <param name="radius">The radius to search in.</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>
|
/// <param name="colliderTag">An optional collider tag.</param>
|
||||||
/// <typeparam name="T">The type of the object.</typeparam>
|
/// <typeparam name="T">The type of the object.</typeparam>
|
||||||
/// <returns>A list of objects of type T.</returns>
|
/// <returns>A list of objects of type T.</returns>
|
||||||
public static List<T> GetNearestObjectsOfType<T>(Vector2 source, float radius, string? colliderTag = null)
|
public static List<T> GetNearestObjectsOfType<T>(Vector2 source, float radius, ContactFilter2D filter, string? colliderTag = null)
|
||||||
where T : Component
|
where T : Component
|
||||||
{
|
{
|
||||||
var results = new Il2CppSystem.Collections.Generic.List<Collider2D>();
|
var results = new Il2CppSystem.Collections.Generic.List<Collider2D>();
|
||||||
Physics2D.OverlapCircle(source, radius, Filter, results);
|
Physics2D.OverlapCircle(source, radius, filter, results);
|
||||||
return results.ToArray()
|
return results.ToArray()
|
||||||
.Where(collider2D => colliderTag == null || collider2D.CompareTag(colliderTag))
|
.Where(collider2D => colliderTag == null || collider2D.CompareTag(colliderTag))
|
||||||
.Select(collider2D => collider2D.GetComponent<T>()).ToList();
|
.Select(collider2D => collider2D.GetComponent<T>()).ToList();
|
||||||
@@ -77,7 +81,7 @@ public static class Helpers
|
|||||||
float radius,
|
float radius,
|
||||||
bool ignoreColliders = true)
|
bool ignoreColliders = true)
|
||||||
{
|
{
|
||||||
var newList = GetNearestObjectsOfType<PlayerControl>(source, radius);
|
var newList = GetNearestObjectsOfType<PlayerControl>(source, radius, CreateFilter(Constants.NotShipMask));
|
||||||
|
|
||||||
if (!ignoreColliders)
|
if (!ignoreColliders)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ 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