mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-10-20 11:39:45 +00:00
Compare commits
131
Commits
0.1.5
...
0.1.9-ci.246
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9504862bea | ||
|
|
4b6ffc65df | ||
|
|
ccde63068b | ||
|
|
5e16429acf | ||
|
|
1e47500686 | ||
|
|
0b1cf998f8 | ||
|
|
14a3669031 | ||
|
|
ae79cd87d9 | ||
|
|
fb99f02549 | ||
|
|
8382b9adf1 | ||
|
|
cb1a818377 | ||
|
|
e950278bf9 | ||
|
|
3de9482233 | ||
|
|
4508aaeb55 | ||
|
|
ee15a1acbe | ||
|
|
113c716fd3 | ||
|
|
f7c34fb5cd | ||
|
|
37446964c5 | ||
|
|
0af392d60e | ||
|
|
e910805e50 | ||
|
|
2b1db0ee24 | ||
|
|
2bb1d41e65 | ||
|
|
7bf35fc8ae | ||
|
|
719ee0400d | ||
|
|
4db7605d27 | ||
|
|
c7d16f7fc9 | ||
|
|
8ed38c02ce | ||
|
|
328ee52549 | ||
|
|
e412e5ead5 | ||
|
|
59ab2736ab | ||
|
|
bb27f83e8b | ||
|
|
7fe2341be0 | ||
|
|
5bf39593c5 | ||
|
|
1e56c8860a | ||
|
|
7042c6e646 | ||
|
|
4fe301511d | ||
|
|
22718a708c | ||
|
|
e569c27010 | ||
|
|
145ae304eb | ||
|
|
dcf557ca46 | ||
|
|
a65de5a938 | ||
|
|
35689487ae | ||
|
|
51fcc2c88f | ||
|
|
d5ac231811 | ||
|
|
3538bea933 | ||
|
|
1d34e82503 | ||
|
|
c32eabcdff | ||
|
|
96f108ab92 | ||
|
|
204d1fe123 | ||
|
|
7b51d9b6e6 | ||
|
|
786450c7c1 | ||
|
|
82050b9d2b | ||
|
|
e2b8c0c0a9 | ||
|
|
69635e02f1 | ||
|
|
f39442785f | ||
|
|
ed7e9949f5 | ||
|
|
0fe6d98c67 | ||
|
|
9fb8a6bda4 | ||
|
|
3d2f53ce25 | ||
|
|
ed0c75acf8 | ||
|
|
246e40539c | ||
|
|
160d424707 | ||
|
|
14276b6c2b | ||
|
|
b909fb7447 | ||
|
|
8b9621dafa | ||
|
|
9de2ba8e41 | ||
|
|
23e11fef93 | ||
|
|
570bb388b6 | ||
|
|
5d05a07364 | ||
|
|
d3a815faa9 | ||
|
|
a23de7b51c | ||
|
|
13268ac70a | ||
|
|
870c913b5d | ||
|
|
c1d2455e4d | ||
|
|
29c2939871 | ||
|
|
2567722b52 | ||
|
|
04ee35d708 | ||
|
|
3ea46d5574 | ||
|
|
707b5629b4 | ||
|
|
8884996c06 | ||
|
|
eac41a7c9e | ||
|
|
4c113e5fb8 | ||
|
|
bc756d5c1b | ||
|
|
bbe7cd5a91 | ||
|
|
538ad48d18 | ||
|
|
53baac167c | ||
|
|
167566dc9b | ||
|
|
2df1eaa7c0 | ||
|
|
dd7f643153 | ||
|
|
13dd0f4874 | ||
|
|
715d235bdc | ||
|
|
25590242bc | ||
|
|
49489ff0d1 | ||
|
|
aa2350bedf | ||
|
|
52daf69dfe | ||
|
|
95f78addee | ||
|
|
12d947748c | ||
|
|
be28948e7e | ||
|
|
d0161ba85c | ||
|
|
2411ac28a4 | ||
|
|
1bc0950acc | ||
|
|
3aecd5a91c | ||
|
|
836823c477 | ||
|
|
c24404620b | ||
|
|
7471a43d39 | ||
|
|
dd6d57343e | ||
|
|
fd75c99850 | ||
|
|
6e3de08043 | ||
|
|
1fa30485b0 | ||
|
|
faed84d0f6 | ||
|
|
2f7b0692f3 | ||
|
|
8123381e1e | ||
|
|
4d36c13c5b | ||
|
|
91b7901528 | ||
|
|
9a27a0c3d8 | ||
|
|
cda441ee56 | ||
|
|
6ee83f8c7d | ||
|
|
8712a2b4e7 | ||
|
|
30d2edfd9c | ||
|
|
76cb2a6a59 | ||
|
|
f20e7459a4 | ||
|
|
f462a116d7 | ||
|
|
6f771821c8 | ||
|
|
754b8ef684 | ||
|
|
d8eb671b49 | ||
|
|
24ebee2743 | ||
|
|
878cf15a20 | ||
|
|
2f7cf4d664 | ||
|
|
4fcfb2a9ee | ||
|
|
41bedd3e16 | ||
|
|
d27bf67f65 |
No files matched your search
@@ -6,11 +6,11 @@ jobs:
|
||||
build:
|
||||
runs-on: ubuntu-22.04
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
|
||||
- uses: actions/cache@v3
|
||||
- uses: actions/cache@v4
|
||||
with:
|
||||
path: |
|
||||
~/.nuget/packages
|
||||
@@ -20,7 +20,7 @@ jobs:
|
||||
${{ runner.os }}-nuget-
|
||||
|
||||
- name: Setup .NET
|
||||
uses: actions/setup-dotnet@v3
|
||||
uses: actions/setup-dotnet@v4
|
||||
with:
|
||||
dotnet-version: 8.0.x
|
||||
|
||||
@@ -29,17 +29,17 @@ jobs:
|
||||
with:
|
||||
verbosity: Diagnostic
|
||||
|
||||
- uses: actions/upload-artifact@v3
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: MiraAPI.dll
|
||||
path: MiraAPI/bin/Release/net6.0/MiraAPI.dll
|
||||
|
||||
- uses: actions/upload-artifact@v3
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: AllOfUs.MiraAPI.nupkg
|
||||
path: MiraAPI/bin/Release/AllOfUs.MiraAPI.*.nupkg
|
||||
|
||||
- uses: softprops/action-gh-release@v1
|
||||
- uses: softprops/action-gh-release@v2
|
||||
if: github.ref_type == 'tag'
|
||||
with:
|
||||
draft: true
|
||||
|
||||
+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.8.13" PrivateAssets="all" />
|
||||
<PackageReference Include="AmongUs.GameLibs.Steam" Version="2024.10.29" 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.5</VersionPrefix>
|
||||
<VersionPrefix>0.1.9</VersionPrefix>
|
||||
<VersionSuffix>dev</VersionSuffix>
|
||||
|
||||
<Authors>All Of Us, XtraCube, Angxl</Authors>
|
||||
|
||||
@@ -9,13 +9,14 @@ using UnityEngine;
|
||||
|
||||
namespace MiraAPI.Example.Buttons.Freezer;
|
||||
|
||||
[RegisterButton]
|
||||
public class FreezeButton : CustomActionButton<PlayerControl>
|
||||
{
|
||||
public override string Name => "Freeze";
|
||||
|
||||
public override float Cooldown => OptionGroupSingleton<FreezerRoleSettings>.Instance.FreezeDuration;
|
||||
public override float EffectDuration => 0f;
|
||||
|
||||
public override int MaxUses => (int)OptionGroupSingleton<FreezerRoleSettings>.Instance.FreezeUses;
|
||||
|
||||
public override LoadableAsset<Sprite> Sprite => ExampleAssets.ExampleButton;
|
||||
|
||||
protected override void OnClick()
|
||||
|
||||
@@ -6,22 +6,19 @@ using UnityEngine;
|
||||
|
||||
namespace MiraAPI.Example.Buttons;
|
||||
|
||||
[RegisterButton]
|
||||
public class MeetingButton : CustomActionButton
|
||||
{
|
||||
public override string Name => "Call Meeting";
|
||||
|
||||
public override float Cooldown => 15;
|
||||
|
||||
public override float EffectDuration => 0;
|
||||
|
||||
public override int MaxUses => 3;
|
||||
|
||||
public override LoadableAsset<Sprite> Sprite => ExampleAssets.ExampleButton;
|
||||
|
||||
public override bool Enabled(RoleBehaviour? role)
|
||||
{
|
||||
return PlayerControl.LocalPlayer.HasModifier<CaptainModifier>();
|
||||
return PlayerControl.LocalPlayer != null && PlayerControl.LocalPlayer.HasModifier<CaptainModifier>();
|
||||
}
|
||||
|
||||
protected override void OnClick()
|
||||
|
||||
@@ -8,7 +8,7 @@ using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.Example.Buttons.Teleporter;
|
||||
[RegisterButton]
|
||||
|
||||
public class TeleportButton : CustomActionButton
|
||||
{
|
||||
public override string Name => "Teleport";
|
||||
@@ -16,16 +16,17 @@ public class TeleportButton : CustomActionButton
|
||||
public override float Cooldown => OptionGroupSingleton<TeleporterOptions>.Instance.TeleportCooldown.Value;
|
||||
|
||||
public override float EffectDuration => OptionGroupSingleton<TeleporterOptions>.Instance.TeleportDuration;
|
||||
|
||||
public override int MaxUses => 0;
|
||||
public override int MaxUses => 2;
|
||||
|
||||
public override LoadableAsset<Sprite> Sprite => ExampleAssets.TeleportButton;
|
||||
|
||||
public static bool IsZoom { get; private set; }
|
||||
|
||||
public override bool Enabled(RoleBehaviour? role)
|
||||
{
|
||||
return role is TeleporterRole;
|
||||
}
|
||||
|
||||
protected override void OnClick()
|
||||
{
|
||||
Coroutines.Start(ZoomOutCoroutine());
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
using MiraAPI.Events;
|
||||
using MiraAPI.Events.Mira;
|
||||
using MiraAPI.Events.Vanilla.Gameplay;
|
||||
using MiraAPI.Events.Vanilla.Map;
|
||||
using MiraAPI.Events.Vanilla.Player;
|
||||
using MiraAPI.Example.Buttons.Freezer;
|
||||
using Reactor.Utilities;
|
||||
|
||||
namespace MiraAPI.Example;
|
||||
|
||||
public static class ExampleEventHandlers
|
||||
{
|
||||
public static void Initialize()
|
||||
{
|
||||
// Register event handlers here
|
||||
MiraEventManager.RegisterEventHandler<MiraButtonClickEvent<FreezeButton>>(FreezeButtonClickHandler, 1);
|
||||
MiraEventManager.RegisterEventHandler<MiraButtonCancelledEvent<FreezeButton>>(FreezeButtonCancelledHandler);
|
||||
MiraEventManager.RegisterEventHandler<UpdateSystemEvent>(UpdateSystemEventHandler);
|
||||
|
||||
MiraEventManager.RegisterEventHandler<BeforeMurderEvent>(@event =>
|
||||
{
|
||||
Logger<ExamplePlugin>.Info($"{@event.Source.Data.PlayerName} is about to kill {@event.Target.Data.PlayerName}");
|
||||
});
|
||||
|
||||
MiraEventManager.RegisterEventHandler<AfterMurderEvent>(@event =>
|
||||
{
|
||||
Logger<ExamplePlugin>.Info($"{@event.Source.Data.PlayerName} has killed {@event.Target.Data.PlayerName}");
|
||||
});
|
||||
|
||||
MiraEventManager.RegisterEventHandler<CompleteTaskEvent>(@event =>
|
||||
{
|
||||
Logger<ExamplePlugin>.Info($"{@event.Player.Data.PlayerName} completed {@event.Task.TaskType.ToString()}");
|
||||
});
|
||||
}
|
||||
|
||||
public static void UpdateSystemEventHandler(UpdateSystemEvent @event)
|
||||
{
|
||||
Logger<ExamplePlugin>.Error(@event.SystemType.ToString());
|
||||
}
|
||||
|
||||
// Example event handler
|
||||
public static void FreezeButtonClickHandler(MiraButtonClickEvent<FreezeButton> @event)
|
||||
{
|
||||
Logger<ExamplePlugin>.Warning("Freeze button clicked!");
|
||||
|
||||
if (PlayerControl.LocalPlayer.Data.PlayerName == "stupid")
|
||||
{
|
||||
@event.Cancel();
|
||||
@event.Button.SetTimer(15f);
|
||||
}
|
||||
}
|
||||
|
||||
// Example event handler
|
||||
public static void FreezeButtonCancelledHandler(MiraButtonCancelledEvent<FreezeButton> @event)
|
||||
{
|
||||
Logger<ExamplePlugin>.Warning("Freeze button cancelled!");
|
||||
@event.Button.OverrideName("Freeze Canceled");
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,7 @@ public partial class ExamplePlugin : BasePlugin, IMiraPlugin
|
||||
public ConfigFile GetConfigFile() => Config;
|
||||
public override void Load()
|
||||
{
|
||||
ExampleEventHandlers.Initialize();
|
||||
Harmony.PatchAll();
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,6 @@ using MiraAPI.Modifiers.Types;
|
||||
|
||||
namespace MiraAPI.Example.Modifiers;
|
||||
|
||||
[RegisterModifier]
|
||||
public class CaptainModifier : GameModifier
|
||||
{
|
||||
public override string ModifierName => "Captain";
|
||||
|
||||
@@ -6,7 +6,6 @@ using UnityEngine;
|
||||
|
||||
namespace MiraAPI.Example.Modifiers.Freezer;
|
||||
|
||||
[RegisterModifier]
|
||||
public class FreezeModifier : TimedModifier
|
||||
{
|
||||
public override string ModifierName => "Freezed";
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
using MiraAPI.Modifiers;
|
||||
using MiraAPI.Modifiers.Types;
|
||||
|
||||
namespace MiraAPI.Example.Modifiers;
|
||||
|
||||
public class HighPriorityModifier : GameModifier
|
||||
{
|
||||
public override string ModifierName => "High Priority";
|
||||
public override int GetAssignmentChance()
|
||||
{
|
||||
return 100;
|
||||
}
|
||||
|
||||
public override int GetAmountPerGame()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
public override int Priority()
|
||||
{
|
||||
return 100;
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,7 @@ public class ExampleOptions : AbstractOptionGroup
|
||||
[ModdedToggleOption("Toggle Opt 2")]
|
||||
public bool ToggleOpt2 { get; set; } = true;
|
||||
|
||||
[ModdedNumberOption("Number Opt", min: 0, max: 10, suffixType: MiraNumberSuffixes.Percent)]
|
||||
[ModdedNumberOption("Number Opt", min: 0, max: 10, increment: .25f, formatString: "0.00", suffixType: MiraNumberSuffixes.Percent)]
|
||||
public float NumberOpt { get; set; } = 4f;
|
||||
|
||||
[ModdedEnumOption("Best API", typeof(BestApi), ["Mira API", "Mitochondria", "Reactor"])]
|
||||
|
||||
@@ -14,16 +14,16 @@ public class ExampleOptions2 : AbstractOptionGroup
|
||||
|
||||
public ModdedToggleOption ToggleOpt2 { get; } = new("Toggle Option 2", false)
|
||||
{
|
||||
Visible = () => OptionGroupSingleton<ExampleOptions2>.Instance.ToggleOpt1.Value,
|
||||
Visible = () => OptionGroupSingleton<ExampleOptions2>.Instance.ToggleOpt1, // implicit cast from ModdedToggleOption to bool
|
||||
};
|
||||
|
||||
public ModdedEnumOption EnumOpt { get; } = new("Enum Opt", 0, typeof(TestingData))
|
||||
public ModdedEnumOption<TestingData> EnumOpt { get; } = new("Enum Opt", 0)
|
||||
{
|
||||
ChangedEvent = x => Logger<ExamplePlugin>.Info($"changed Enum Opt to {x}"),
|
||||
};
|
||||
}
|
||||
|
||||
public enum TestingData
|
||||
public enum TestingData : ulong
|
||||
{
|
||||
Happy,
|
||||
Sad,
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
using MiraAPI.Roles;
|
||||
using MiraAPI.Utilities.Assets;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.Example.Roles;
|
||||
|
||||
[RegisterCustomRole]
|
||||
public class ChameloenRole : CrewmateRole, ICustomRole
|
||||
{
|
||||
public string RoleName => "Chamelon";
|
||||
@@ -13,8 +11,11 @@ public class ChameloenRole : CrewmateRole, ICustomRole
|
||||
public string RoleDescription => RoleLongDescription;
|
||||
public Color RoleColor => Palette.AcceptedGreen;
|
||||
public ModdedRoleTeams Team => ModdedRoleTeams.Crewmate;
|
||||
public LoadableAsset<Sprite> OptionsScreenshot => ExampleAssets.Banner;
|
||||
public int MaxPlayers => 2;
|
||||
|
||||
public CustomRoleConfiguration Configuration => new CustomRoleConfiguration(this)
|
||||
{
|
||||
OptionsScreenshot = ExampleAssets.Banner,
|
||||
};
|
||||
|
||||
public void PlayerControlFixedUpdate(PlayerControl playerControl)
|
||||
{
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
using Il2CppInterop.Runtime.Attributes;
|
||||
using MiraAPI.Roles;
|
||||
using MiraAPI.Utilities.Assets;
|
||||
using MiraAPI.Roles;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.Example.Roles;
|
||||
|
||||
[RegisterCustomRole]
|
||||
public class FreezerRole : ImpostorRole, ICustomRole
|
||||
{
|
||||
public string RoleName => "Freezer";
|
||||
@@ -13,7 +10,10 @@ public class FreezerRole : ImpostorRole, ICustomRole
|
||||
public string RoleDescription => RoleLongDescription;
|
||||
public Color RoleColor => Palette.Blue;
|
||||
public ModdedRoleTeams Team => ModdedRoleTeams.Impostor;
|
||||
[HideFromIl2Cpp]
|
||||
public LoadableAsset<Sprite> OptionsScreenshot => ExampleAssets.Banner;
|
||||
public int MaxPlayers => 2;
|
||||
|
||||
public CustomRoleConfiguration Configuration => new CustomRoleConfiguration(this)
|
||||
{
|
||||
OptionsScreenshot = ExampleAssets.Banner,
|
||||
MaxRoleCount = 2,
|
||||
};
|
||||
}
|
||||
@@ -3,17 +3,27 @@ using UnityEngine;
|
||||
|
||||
namespace MiraAPI.Example.Roles;
|
||||
|
||||
[RegisterCustomRole]
|
||||
public class NeutralKillerRole : ImpostorRole, ICustomRole
|
||||
{
|
||||
public string RoleName => "Neutral Killer";
|
||||
public string RoleDescription => "Neutral who can kill.";
|
||||
public string RoleName => "Outcast Killer";
|
||||
public string RoleDescription => "Outcast who can kill.";
|
||||
public string RoleLongDescription => RoleDescription;
|
||||
public Color RoleColor => Color.magenta;
|
||||
public ModdedRoleTeams Team => ModdedRoleTeams.Neutral;
|
||||
public bool UseVanillaKillButton => true;
|
||||
public bool CanGetKilled => true;
|
||||
public bool CanUseVent => true;
|
||||
public ModdedRoleTeams Team => ModdedRoleTeams.Custom;
|
||||
|
||||
public CustomRoleConfiguration Configuration => new(this)
|
||||
{
|
||||
UseVanillaKillButton = true,
|
||||
CanGetKilled = true,
|
||||
CanUseVent = true,
|
||||
};
|
||||
|
||||
public RoleOptionsGroup RoleOptionsGroup { get; } = new("Outcast", Color.gray);
|
||||
|
||||
public TeamIntroConfiguration? IntroConfiguration { get; } = new(
|
||||
Color.gray,
|
||||
"NEUTRAL",
|
||||
"You are an Outcast. You do not have a team.");
|
||||
|
||||
public override void SpawnTaskHeader(PlayerControl playerControl)
|
||||
{
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
using Il2CppInterop.Runtime.Attributes;
|
||||
using MiraAPI.Roles;
|
||||
using MiraAPI.Utilities.Assets;
|
||||
using MiraAPI.Roles;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.Example.Roles;
|
||||
|
||||
[RegisterCustomRole]
|
||||
public class TeleporterRole : CrewmateRole, ICustomRole
|
||||
{
|
||||
public string RoleName => "Teleporter";
|
||||
@@ -13,6 +10,17 @@ public class TeleporterRole : CrewmateRole, ICustomRole
|
||||
public string RoleDescription => RoleLongDescription;
|
||||
public Color RoleColor => new Color32(221, 176, 152, 255);
|
||||
public ModdedRoleTeams Team => ModdedRoleTeams.Crewmate;
|
||||
[HideFromIl2Cpp]
|
||||
public LoadableAsset<Sprite> OptionsScreenshot => ExampleAssets.Banner;
|
||||
|
||||
public CustomRoleConfiguration Configuration => new CustomRoleConfiguration(this)
|
||||
{
|
||||
OptionsScreenshot = ExampleAssets.Banner,
|
||||
CanModifyChance = false,
|
||||
DefaultChance = 73,
|
||||
DefaultRoleCount = 4,
|
||||
};
|
||||
|
||||
public bool CanLocalPlayerSeeRole(PlayerControl player)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
using MiraAPI.Hud;
|
||||
|
||||
namespace MiraAPI.Events.Mira;
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when a Mira Button click is cancelled. Do not use for vanilla buttons.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The Mira Button type.</typeparam>
|
||||
public sealed class MiraButtonCancelledEvent<T> : MiraEvent where T : CustomActionButton
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets Mira Button whose click was cancelled.
|
||||
/// </summary>
|
||||
public T Button { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="MiraButtonCancelledEvent{T}"/> class.
|
||||
/// </summary>
|
||||
/// <param name="button">The Mira Button whose click was cancelled.</param>
|
||||
public MiraButtonCancelledEvent(T button)
|
||||
{
|
||||
Button = button;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when a Mira Button click is cancelled. Do not use for vanilla buttons.
|
||||
/// </summary>
|
||||
public sealed class MiraButtonCancelledEvent : MiraEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets Mira Button whose click was cancelled.
|
||||
/// </summary>
|
||||
public CustomActionButton Button { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="MiraButtonCancelledEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="button">The Mira Button whose click was cancelled.</param>
|
||||
public MiraButtonCancelledEvent(CustomActionButton button)
|
||||
{
|
||||
Button = button;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
using MiraAPI.Hud;
|
||||
|
||||
namespace MiraAPI.Events.Mira;
|
||||
|
||||
/// <summary>
|
||||
/// Button click event for Mira Buttons only. Do not use for vanilla buttons.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The Mira Button type.</typeparam>
|
||||
public sealed class MiraButtonClickEvent<T> : MiraCancelableEvent where T : CustomActionButton
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets Mira Button that was clicked.
|
||||
/// </summary>
|
||||
public T Button { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the generic click event that is invoked before this button-specific event.
|
||||
/// </summary>
|
||||
public MiraButtonClickEvent GenericClickEvent { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="MiraButtonClickEvent{T}"/> class.
|
||||
/// </summary>
|
||||
/// <param name="button">The Mira Button that was clicked.</param>
|
||||
/// <param name="genericClickEvent">The generic click event invoked before button-specific events.</param>
|
||||
public MiraButtonClickEvent(T button, MiraButtonClickEvent genericClickEvent)
|
||||
{
|
||||
GenericClickEvent = genericClickEvent;
|
||||
Button = button;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Button click event for Mira Buttons only. Do not use for vanilla buttons.
|
||||
/// </summary>
|
||||
public sealed class MiraButtonClickEvent : MiraCancelableEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets Mira Button that was clicked.
|
||||
/// </summary>
|
||||
public CustomActionButton Button { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="MiraButtonClickEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="button">The Mira Button that was clicked.</param>
|
||||
public MiraButtonClickEvent(CustomActionButton button)
|
||||
{
|
||||
Button = button;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
namespace MiraAPI.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Abstract class for Mira Events that can be cancelled.
|
||||
/// </summary>
|
||||
public abstract class MiraCancelableEvent : MiraEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the event is cancelled.
|
||||
/// </summary>
|
||||
public bool IsCancelled { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Cancels the event.
|
||||
/// </summary>
|
||||
public void Cancel()
|
||||
{
|
||||
IsCancelled = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Uncancels the event.
|
||||
/// </summary>
|
||||
public void UnCancel()
|
||||
{
|
||||
IsCancelled = false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace MiraAPI.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Abstract class for Mira Events.
|
||||
/// </summary>
|
||||
public abstract class MiraEvent;
|
||||
@@ -0,0 +1,81 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace MiraAPI.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Mira Event manager.
|
||||
/// </summary>
|
||||
public static class MiraEventManager
|
||||
{
|
||||
private static readonly Dictionary<Type, List<MiraEventWrapper>> EventWrappers = [];
|
||||
|
||||
/// <summary>
|
||||
/// Invoke an event.
|
||||
/// </summary>
|
||||
/// <param name="eventInstance">The event instance.</param>
|
||||
/// <typeparam name="T">Type of Event.</typeparam>
|
||||
/// <returns>If there was an event handler invoked for this event, return true. Otherwise, return false.</returns>
|
||||
public static bool InvokeEvent<T>(T eventInstance) where T : MiraEvent
|
||||
{
|
||||
EventWrappers.TryGetValue(typeof(T), out var handlers);
|
||||
if (handlers == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (var handler in handlers)
|
||||
{
|
||||
((Action<T>)handler.EventHandler).Invoke(eventInstance);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invoke an event and use a specific type to find the handlers.
|
||||
/// </summary>
|
||||
/// <param name="eventInstance">The event instance.</param>
|
||||
/// <param name="type">The type to use for handler lookup.</param>
|
||||
/// <returns>If there was an event handler invoked for this event, return true. Otherwise, return false.</returns>
|
||||
public static bool InvokeEvent(MiraEvent eventInstance, Type type)
|
||||
{
|
||||
EventWrappers.TryGetValue(type, out var handlers);
|
||||
if (handlers == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (var handler in handlers)
|
||||
{
|
||||
handler.EventHandler.DynamicInvoke(eventInstance);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Register an event.
|
||||
/// </summary>
|
||||
/// <param name="handler">The callback method/handler for the event.</param>
|
||||
/// <param name="priority">The priority of the event handler. Higher values are called first.</param>
|
||||
/// <typeparam name="T">Type of event.</typeparam>
|
||||
public static void RegisterEventHandler<T>(Action<T> handler, int priority = 0) where T : MiraEvent
|
||||
{
|
||||
if (!EventWrappers.ContainsKey(typeof(T)))
|
||||
{
|
||||
EventWrappers.Add(typeof(T), []);
|
||||
}
|
||||
|
||||
var handlers = EventWrappers[typeof(T)];
|
||||
handlers.Add(new MiraEventWrapper(handler, priority));
|
||||
}
|
||||
|
||||
internal static void SortAllHandlers()
|
||||
{
|
||||
foreach (var handlers in EventWrappers.Values)
|
||||
{
|
||||
handlers.Sort((a, b) => a.Priority.CompareTo(b.Priority));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
|
||||
namespace MiraAPI.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Wrapper for event handlers.
|
||||
/// </summary>
|
||||
public class MiraEventWrapper
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the event handler delegate.
|
||||
/// </summary>
|
||||
public Delegate EventHandler { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the priority of the handler. Higher values are called first.
|
||||
/// </summary>
|
||||
public int Priority { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="MiraEventWrapper"/> class.
|
||||
/// </summary>
|
||||
/// <param name="eventHandler">The action for the event handler.</param>
|
||||
/// <param name="priority">The priority of the handler.</param>
|
||||
public MiraEventWrapper(Delegate eventHandler, int priority)
|
||||
{
|
||||
EventHandler = eventHandler;
|
||||
Priority = priority;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
namespace MiraAPI.Events.Vanilla.Gameplay;
|
||||
|
||||
/// <summary>
|
||||
/// Event that is invoked after a player is murdered. Only called after a successful murder. This event is not cancelable.
|
||||
/// </summary>
|
||||
public class AfterMurderEvent : MiraEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the player that killed the target.
|
||||
/// </summary>
|
||||
public PlayerControl Source { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the player that was killed.
|
||||
/// </summary>
|
||||
public PlayerControl Target { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="AfterMurderEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="source">The killer.</param>
|
||||
/// <param name="target">The killed player.</param>
|
||||
public AfterMurderEvent(PlayerControl source, PlayerControl target)
|
||||
{
|
||||
Source = source;
|
||||
Target = target;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
namespace MiraAPI.Events.Vanilla.Gameplay;
|
||||
|
||||
/// <summary>
|
||||
/// Event that is invoked before a player is murdered. This event is cancelable.
|
||||
/// </summary>
|
||||
public sealed class BeforeMurderEvent : MiraCancelableEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the player that is killing the target.
|
||||
/// </summary>
|
||||
public PlayerControl Source { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the player that is being killed.
|
||||
/// </summary>
|
||||
public PlayerControl Target { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="BeforeMurderEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="source">The player that is killing the target.</param>
|
||||
/// <param name="target">The player that is being killed.</param>
|
||||
public BeforeMurderEvent(PlayerControl source, PlayerControl target)
|
||||
{
|
||||
Source = source;
|
||||
Target = target;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
namespace MiraAPI.Events.Vanilla.Gameplay;
|
||||
|
||||
/// <summary>
|
||||
/// The event that is invoked when the end game screen is shown. Non cancelable.
|
||||
/// </summary>
|
||||
public class GameEndEvent : MiraEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the instance of the EndGameManager.
|
||||
/// </summary>
|
||||
public EndGameManager EndGameManager { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GameEndEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="manager">The instance of the EndGameManager.</param>
|
||||
public GameEndEvent(EndGameManager manager)
|
||||
{
|
||||
EndGameManager = manager;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
namespace MiraAPI.Events.Vanilla.Gameplay;
|
||||
|
||||
/// <summary>
|
||||
/// The event that is invoked when the intro cutscene is shown. Non cancelable.
|
||||
/// </summary>
|
||||
public class IntroBeginEvent : MiraEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the instance of the IntroCutscene.
|
||||
/// </summary>
|
||||
public IntroCutscene IntroCutscene { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="IntroBeginEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="introCutscene">The intro cutscene.</param>
|
||||
public IntroBeginEvent(IntroCutscene introCutscene)
|
||||
{
|
||||
IntroCutscene = introCutscene;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using AmongUs.GameOptions;
|
||||
|
||||
namespace MiraAPI.Events.Vanilla.Gameplay;
|
||||
|
||||
/// <summary>
|
||||
/// Event that is invoked after a player's role is set. This event is not cancelable.
|
||||
/// </summary>
|
||||
public class SetRoleEvent : MiraEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the player whos role was changed.
|
||||
/// </summary>
|
||||
public PlayerControl Player { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the role that the player was set to.
|
||||
/// </summary>
|
||||
public RoleTypes Role { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SetRoleEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="player">The player.</param>
|
||||
/// <param name="role">The new role.</param>
|
||||
public SetRoleEvent(PlayerControl player, RoleTypes role)
|
||||
{
|
||||
Player = player;
|
||||
Role = role;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
namespace MiraAPI.Events.Vanilla.Map;
|
||||
|
||||
/// <summary>
|
||||
/// Event fired when a player closes the doors in a room.
|
||||
/// </summary>
|
||||
public class CloseDoorsEvent : MiraCancelableEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the room that the doors were closed in.
|
||||
/// </summary>
|
||||
public SystemTypes Room { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="CloseDoorsEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="room">The room that was closed.</param>
|
||||
public CloseDoorsEvent(SystemTypes room)
|
||||
{
|
||||
Room = room;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
namespace MiraAPI.Events.Vanilla.Map;
|
||||
|
||||
/// <summary>
|
||||
/// Sabotage from Vanilla Among Us.
|
||||
/// </summary>
|
||||
public class PlayerOpenSabotageEvent : MiraCancelableEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the MapBehaviour.
|
||||
/// </summary>
|
||||
public MapBehaviour MapBehaviour { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PlayerOpenSabotageEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="mapBehaviour">The MapBehaviour.</param>
|
||||
public PlayerOpenSabotageEvent(MapBehaviour mapBehaviour)
|
||||
{
|
||||
MapBehaviour = mapBehaviour;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
namespace MiraAPI.Events.Vanilla.Map;
|
||||
|
||||
/// <summary>
|
||||
/// Cancelable event that is invoked before a system is updated. Usually used for sabotage events.
|
||||
/// </summary>
|
||||
public class UpdateSystemEvent : MiraCancelableEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the type of system that will be updated.
|
||||
/// </summary>
|
||||
public SystemTypes SystemType { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the player that is updating the system.
|
||||
/// </summary>
|
||||
public PlayerControl Player { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the byte amount the system is being updated by.
|
||||
/// </summary>
|
||||
public byte Amount { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UpdateSystemEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="systemType">The SystemType being updated.</param>
|
||||
/// <param name="amount">Amount to update System to.</param>
|
||||
public UpdateSystemEvent(SystemTypes systemType, PlayerControl player, byte amount)
|
||||
{
|
||||
SystemType = systemType;
|
||||
Player = player;
|
||||
Amount = amount;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
namespace MiraAPI.Events.Vanilla.Meeting;
|
||||
|
||||
/// <summary>
|
||||
/// The event that is invoked when a player is ejected. Non-cancelable.
|
||||
/// </summary>
|
||||
public class EjectionEvent : MiraEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the instance of the ExileController.
|
||||
/// </summary>
|
||||
public ExileController ExileController { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="EjectionEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="controller">The exile controller.</param>
|
||||
public EjectionEvent(ExileController controller)
|
||||
{
|
||||
ExileController = controller;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
namespace MiraAPI.Events.Vanilla.Meeting;
|
||||
|
||||
/// <summary>
|
||||
/// The event that is invoked when a meeting is called.
|
||||
/// </summary>
|
||||
public class StartMeetingEvent : MiraCancelableEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the player that is calling the meeting.
|
||||
/// </summary>
|
||||
public PlayerControl Reporter { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the player that is being reported. Will be null for emergency meeting.
|
||||
/// </summary>
|
||||
public NetworkedPlayerInfo? Target { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the body that is being reported. Will be null for emergency meeting.
|
||||
/// </summary>
|
||||
public DeadBody? Body { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="StartMeetingEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="reporter">The player who reported the body.</param>
|
||||
/// <param name="target">The player being reported.</param>
|
||||
/// <param name="body">The body being reported.</param>
|
||||
public StartMeetingEvent(PlayerControl reporter, NetworkedPlayerInfo? target, DeadBody? body)
|
||||
{
|
||||
Reporter = reporter;
|
||||
Target = target;
|
||||
Body = body;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
namespace MiraAPI.Events.Vanilla.Player;
|
||||
|
||||
/// <summary>
|
||||
/// The event that is invoked when a player completes a task. Non cancelable.
|
||||
/// </summary>
|
||||
public class CompleteTaskEvent : MiraEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the instance of the <see cref="PlayerControl"/>.
|
||||
/// </summary>
|
||||
public PlayerControl Player { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the instance of the <see cref="PlayerTask"/> that the player completed.
|
||||
/// </summary>
|
||||
public PlayerTask Task { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="CompleteTaskEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="player">The player who completed the task.</param>
|
||||
/// <param name="task">The task that the player completed.</param>
|
||||
public CompleteTaskEvent(PlayerControl player, PlayerTask task)
|
||||
{
|
||||
Player = player;
|
||||
Task = task;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
namespace MiraAPI.Events.Vanilla.Player;
|
||||
|
||||
/// <summary>
|
||||
/// Event that is invoked when a player dies. Non cancelable.
|
||||
/// </summary>
|
||||
public class PlayerDeathEvent : MiraEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the player who died.
|
||||
/// </summary>
|
||||
public PlayerControl Player { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the reason the player died.
|
||||
/// </summary>
|
||||
public DeathReason DeathReason { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PlayerDeathEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="player">The player who died.</param>
|
||||
/// <param name="reason">The reason the player died.</param>
|
||||
public PlayerDeathEvent(PlayerControl player, DeathReason reason)
|
||||
{
|
||||
Player = player;
|
||||
DeathReason = reason;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using InnerNet;
|
||||
|
||||
namespace MiraAPI.Events.Vanilla.Player;
|
||||
|
||||
/// <summary>
|
||||
/// Event that is invoked when a player joins the lobby. Non cancelable.
|
||||
/// </summary>
|
||||
public class PlayerJoinEvent : MiraEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the player who joined.
|
||||
/// </summary>
|
||||
public ClientData ClientData { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PlayerJoinEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="data">The data of the player who joined.</param>
|
||||
public PlayerJoinEvent(ClientData data)
|
||||
{
|
||||
ClientData = data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using InnerNet;
|
||||
|
||||
namespace MiraAPI.Events.Vanilla.Player;
|
||||
|
||||
/// <summary>
|
||||
/// Event that is invoked when a player leaves the game. Non cancelable.
|
||||
/// </summary>
|
||||
public class PlayerLeaveEvent : MiraEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the player who left.
|
||||
/// </summary>
|
||||
public ClientData ClientData { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the reason why the player left.
|
||||
/// </summary>
|
||||
public DisconnectReasons Reason { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PlayerLeaveEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="data">The data of the player who left.</param>
|
||||
/// <param name="reason">The reason why the player left.</param>
|
||||
public PlayerLeaveEvent(ClientData data, DisconnectReasons reason)
|
||||
{
|
||||
ClientData = data;
|
||||
Reason = reason;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
namespace MiraAPI.Events.Vanilla.Usables;
|
||||
|
||||
/// <summary>
|
||||
/// Event that is invoked when a player enters a vent. This event is cancelable.
|
||||
/// </summary>
|
||||
public class EnterVentEvent : MiraCancelableEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the player that is entering the vent.
|
||||
/// </summary>
|
||||
public PlayerControl Player { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the vent that the player is entering.
|
||||
/// </summary>
|
||||
public Vent? Vent { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="EnterVentEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="player">The player that is entering the vent.</param>
|
||||
/// <param name="vent">The vent being entered.</param>
|
||||
public EnterVentEvent(PlayerControl player, Vent? vent)
|
||||
{
|
||||
Player = player;
|
||||
Vent = vent;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
namespace MiraAPI.Events.Vanilla.Usables;
|
||||
|
||||
/// <summary>
|
||||
/// Event that is invoked when a player exits a vent. This event is cancelable.
|
||||
/// </summary>
|
||||
public class ExitVentEvent : MiraCancelableEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the player that is exiting the vent.
|
||||
/// </summary>
|
||||
public PlayerControl Player { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the vent that the player is exiting.
|
||||
/// </summary>
|
||||
public Vent? Vent { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ExitVentEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="player">The player who is exiting the vent.</param>
|
||||
/// <param name="vent">The vent being exited from.</param>
|
||||
public ExitVentEvent(PlayerControl player, Vent? vent)
|
||||
{
|
||||
Player = player;
|
||||
Vent = vent;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
namespace MiraAPI.Events.Vanilla.Usables;
|
||||
|
||||
/// <summary>
|
||||
/// Event for if a <see cref="PlayerControl"/> can use an <see cref="IUsable"/> from Vanilla Among Us. Will always be ran locally.
|
||||
/// </summary>
|
||||
public class PlayerCanUseEvent : PlayerUseEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PlayerCanUseEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="usable">The IUsable.</param>
|
||||
public PlayerCanUseEvent(IUsable usable) : base(usable)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
namespace MiraAPI.Events.Vanilla;
|
||||
|
||||
/// <summary>
|
||||
/// Event for <see cref="PlayerControl"/> using a <see cref="IUsable"/> from Vanilla Among Us. Will always be ran locally.
|
||||
/// </summary>
|
||||
public class PlayerUseEvent : MiraCancelableEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the instance of <see cref="IUsable"/> that was used.
|
||||
/// </summary>
|
||||
public IUsable Usable { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the IUsable is a <see cref="Console"/>, <see cref="MapConsole"/>, or <see cref="SystemConsole"/>.
|
||||
/// </summary>
|
||||
public bool IsPrimaryConsole { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the IUsable is a <see cref="Vent"/>.
|
||||
/// </summary>
|
||||
public bool IsVent { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PlayerUseEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="usable">The IUsable.</param>
|
||||
public PlayerUseEvent(IUsable usable)
|
||||
{
|
||||
Usable = usable;
|
||||
|
||||
IsPrimaryConsole = usable.TryCast<Console>() || usable.TryCast<SystemConsole>() || usable.TryCast<MapConsole>();
|
||||
IsVent = usable.TryCast<Vent>();
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
namespace MiraAPI.GameModes;
|
||||
|
||||
[RegisterGameMode]
|
||||
public class DefaultMode : CustomGameMode
|
||||
{
|
||||
public override string Name => "Default";
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
|
||||
namespace MiraAPI.GameModes;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Class)]
|
||||
public class RegisterGameModeAttribute : Attribute
|
||||
{
|
||||
private static readonly HashSet<Assembly> RegisteredAssemblies = [];
|
||||
|
||||
internal static void Register(Assembly assembly)
|
||||
{
|
||||
if (!RegisteredAssemblies.Add(assembly))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var type in assembly.GetTypes())
|
||||
{
|
||||
var attribute = type.GetCustomAttribute<RegisterGameModeAttribute>();
|
||||
if (attribute != null)
|
||||
{
|
||||
CustomGameModeManager.RegisterGameMode(type);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,10 +27,8 @@ public class ModdedEnumOptionAttribute(string title, Type enumType, string[]? va
|
||||
/// <inheritdoc />
|
||||
public override object GetValue()
|
||||
{
|
||||
if (HolderOption is ModdedEnumOption opt)
|
||||
{
|
||||
return Enum.ToObject(enumType, opt.Value);
|
||||
}
|
||||
throw new InvalidOperationException($"HolderOption for option \"{Title}\" with EnumType ${enumType.FullName} is not a ModdedEnumOption");
|
||||
return HolderOption is ModdedEnumOption opt
|
||||
? Enum.ToObject(enumType, opt.Value)
|
||||
: throw new InvalidOperationException($"HolderOption for option \"{Title}\" with EnumType ${enumType.FullName} is not a ModdedEnumOption");
|
||||
}
|
||||
}
|
||||
@@ -15,13 +15,14 @@ public class ModdedNumberOptionAttribute(
|
||||
float max,
|
||||
float increment = 1,
|
||||
MiraNumberSuffixes suffixType = MiraNumberSuffixes.None,
|
||||
string? formatString = null,
|
||||
bool zeroInfinity = false,
|
||||
Type? roleType = null)
|
||||
: ModdedOptionAttribute(title, roleType)
|
||||
{
|
||||
internal override IModdedOption CreateOption(object? value, PropertyInfo property)
|
||||
{
|
||||
return new ModdedNumberOption(Title, (float)(value ?? min+increment), min, max, increment, suffixType, zeroInfinity, RoleType);
|
||||
return new ModdedNumberOption(Title, (float)(value ?? min+increment), min, max, increment, suffixType, formatString, zeroInfinity, RoleType);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@@ -6,13 +6,13 @@ using UnityEngine;
|
||||
|
||||
namespace MiraAPI.GameOptions;
|
||||
|
||||
internal interface IModdedOption
|
||||
public interface IModdedOption
|
||||
{
|
||||
uint Id { get; }
|
||||
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; }
|
||||
|
||||
@@ -31,7 +31,6 @@ public static class ModdedOptionsManager
|
||||
{
|
||||
if (Activator.CreateInstance(type) is not AbstractOptionGroup group)
|
||||
{
|
||||
Logger<MiraApiPlugin>.Error($"Failed to create group from {type.Name}");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -45,6 +44,10 @@ 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;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Il2CppInterop.Runtime.InteropTypes.Arrays;
|
||||
using MiraAPI.Networking;
|
||||
using Reactor.Localization.Utilities;
|
||||
@@ -86,7 +88,7 @@ public class ModdedEnumOption : ModdedOption<int>
|
||||
/// <inheritdoc />
|
||||
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)
|
||||
{
|
||||
return;
|
||||
@@ -98,3 +100,96 @@ public class ModdedEnumOption : ModdedOption<int>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// An option for selecting an enum value.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The enum type.</typeparam>
|
||||
public class ModdedEnumOption<T> : ModdedOption<T> where T : Enum
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the string values of the enum.
|
||||
/// </summary>
|
||||
public string[]? Values { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ModdedEnumOption{T}"/> class.
|
||||
/// </summary>
|
||||
/// <param name="title">The title of the option.</param>
|
||||
/// <param name="defaultValue">The default value as an int.</param>
|
||||
/// <param name="enumType">The Enum type.</param>
|
||||
/// <param name="values">An option list of string values to use in place of the enum name.</param>
|
||||
/// <param name="roleType">An optional role type to specify for a specific role.</param>
|
||||
public ModdedEnumOption(string title, T defaultValue, string[]? values = null, Type? roleType = null) : base(title, defaultValue, roleType)
|
||||
{
|
||||
Values = values ?? Enum.GetNames(typeof(T));
|
||||
Data = ScriptableObject.CreateInstance<StringGameSetting>();
|
||||
var data = (StringGameSetting)Data;
|
||||
|
||||
data.Title = StringName;
|
||||
data.Type = global::OptionTypes.String;
|
||||
data.Values = values is null ?
|
||||
Enum.GetNames(typeof(T)).Select(CustomStringName.CreateAndRegister).ToArray()
|
||||
: values.Select(CustomStringName.CreateAndRegister).ToArray();
|
||||
|
||||
data.Index = Convert.ToInt32(Value);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override OptionBehaviour CreateOption(ToggleOption toggleOpt, NumberOption numberOpt, StringOption stringOpt, Transform container)
|
||||
{
|
||||
var stringOption = Object.Instantiate(stringOpt, container);
|
||||
|
||||
stringOption.SetUpFromData(Data, 20);
|
||||
stringOption.OnValueChanged = (Il2CppSystem.Action<OptionBehaviour>)ValueChanged;
|
||||
|
||||
// SetUpFromData method doesnt work correctly so we must set the values manually
|
||||
stringOption.Title = StringName;
|
||||
stringOption.Values = (Data as StringGameSetting)?.Values ?? new Il2CppStructArray<StringNames>(0);
|
||||
stringOption.Value = Convert.ToInt32(Value);
|
||||
|
||||
OptionBehaviour = stringOption;
|
||||
|
||||
return stringOption;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override float GetFloatData()
|
||||
{
|
||||
return Convert.ToSingle(Value);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override NetData GetNetData()
|
||||
{
|
||||
return new NetData(Id, Encoding.Unicode.GetBytes(Convert.ToString(Value)));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void HandleNetData(byte[] data)
|
||||
{
|
||||
SetValue((T)Enum.Parse(typeof(T), Encoding.Unicode.GetString(data)));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override T GetValueFromOptionBehaviour(OptionBehaviour optionBehaviour)
|
||||
{
|
||||
return (T)Enum.Parse(typeof(T), optionBehaviour.GetInt().ToString());
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnValueChanged(T newValue)
|
||||
{
|
||||
HudManager.Instance.Notifier.AddSettingsChangeMessage(StringName, Data?.GetValueString(Convert.ToInt32(newValue)), false);
|
||||
if (!OptionBehaviour)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (OptionBehaviour is StringOption opt)
|
||||
{
|
||||
opt.Value = Convert.ToInt32(newValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -46,6 +46,7 @@ public class ModdedNumberOption : ModdedOption<float>
|
||||
/// <param name="max">The maximum value.</param>
|
||||
/// <param name="increment">The increment.</param>
|
||||
/// <param name="suffixType">The suffix type.</param>
|
||||
/// <param name="formatString">Optional format string for the option screen.</param>
|
||||
/// <param name="zeroInfinity">Whether zero is infinity or not.</param>
|
||||
/// <param name="roleType">An optional role type.</param>
|
||||
public ModdedNumberOption(
|
||||
@@ -55,6 +56,7 @@ public class ModdedNumberOption : ModdedOption<float>
|
||||
float max,
|
||||
float increment,
|
||||
MiraNumberSuffixes suffixType,
|
||||
string? formatString = null,
|
||||
bool zeroInfinity = false,
|
||||
Type? roleType = null) : base(title, defaultValue, roleType)
|
||||
{
|
||||
@@ -74,7 +76,13 @@ public class ModdedNumberOption : ModdedOption<float>
|
||||
data.Value = Value;
|
||||
data.Increment = Increment;
|
||||
data.ValidRange = new FloatRange(Min, Max);
|
||||
data.FormatString = Increment % 1 == 0 && Value % 1 == 0 && Min % 1 == 0 && Max % 1 == 0 ? "0" : "0.0"; // not sure if the == checks will work since this is floats but we'll find out
|
||||
data.FormatString = formatString ??
|
||||
(!Mathf.Approximately(defaultValue, 0) ||
|
||||
!Mathf.Approximately(Increment % 1, 0) ||
|
||||
!Mathf.Approximately(Value % 1, 0) ||
|
||||
!Mathf.Approximately(Min % 1, 0) ||
|
||||
!Mathf.Approximately(Max % 1, 0) ? "0.0" : "0");
|
||||
|
||||
data.ZeroIsInfinity = ZeroInfinity;
|
||||
data.SuffixType = (NumberSuffixes)SuffixType;
|
||||
data.OptionName = FloatOptionNames.Invalid;
|
||||
@@ -134,7 +142,7 @@ public class ModdedNumberOption : ModdedOption<float>
|
||||
protected override void OnValueChanged(float newValue)
|
||||
{
|
||||
Value = Mathf.Clamp(newValue, Min, Max);
|
||||
DestroyableSingleton<HudManager>.Instance.Notifier.AddSettingsChangeMessage(
|
||||
HudManager.Instance.Notifier.AddSettingsChangeMessage(
|
||||
StringName,
|
||||
Data?.GetValueString(Value),
|
||||
false);
|
||||
@@ -144,4 +152,14 @@ public class ModdedNumberOption : ModdedOption<float>
|
||||
opt.Value = Value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Implicitly converts the option to an int.
|
||||
/// </summary>
|
||||
/// <param name="option">The option.</param>
|
||||
/// <returns>Integer value.</returns>
|
||||
public static implicit operator int(ModdedNumberOption option)
|
||||
{
|
||||
return (int)option.Value;
|
||||
}
|
||||
}
|
||||
@@ -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.
|
||||
@@ -194,4 +194,14 @@ public abstract class ModdedOption<T> : IModdedOption
|
||||
NumberOption numberOpt,
|
||||
StringOption stringOpt,
|
||||
Transform container);
|
||||
|
||||
/// <summary>
|
||||
/// Implicitly converts the option to type of <typeparamref name="T"/>.
|
||||
/// </summary>
|
||||
/// <param name="option">The option.</param>
|
||||
/// <returns>Value of type <typeparamref name="T"/>.</returns>
|
||||
public static implicit operator T(ModdedOption<T> option)
|
||||
{
|
||||
return option.Value;
|
||||
}
|
||||
}
|
||||
@@ -69,7 +69,7 @@ public class ModdedToggleOption : ModdedOption<bool>
|
||||
/// <inheritdoc />
|
||||
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)
|
||||
{
|
||||
return;
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
using MiraAPI.Utilities.Assets;
|
||||
using MiraAPI.Events;
|
||||
using MiraAPI.Events.Mira;
|
||||
using MiraAPI.Patches;
|
||||
using MiraAPI.Utilities.Assets;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.UI;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace MiraAPI.Hud;
|
||||
|
||||
@@ -15,30 +20,35 @@ public abstract class CustomActionButton
|
||||
/// </summary>
|
||||
public abstract string Name { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the initial cooldown duration in seconds.
|
||||
/// </summary>
|
||||
public virtual float InitialCooldown => Cooldown;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the button's cooldown duration in seconds.
|
||||
/// </summary>
|
||||
public abstract float Cooldown { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the button's effect duration in seconds. If the button has no effect, set to 0.
|
||||
/// </summary>
|
||||
public abstract float EffectDuration { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the maximum amount of uses the button has. If the button has infinite uses, set to 0.
|
||||
/// </summary>
|
||||
public abstract int MaxUses { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the sprite of the button. Use <see cref="LoadableResourceAsset"/> to load a sprite from a resource path. Use <see cref="LoadableBundleAsset{T}"/> to load a sprite from an asset bundle.
|
||||
/// </summary>
|
||||
public abstract LoadableAsset<Sprite> Sprite { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the button's effect duration in seconds. If the button has no effect, set to 0.
|
||||
/// </summary>
|
||||
public virtual float EffectDuration => 0;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the maximum amount of uses the button has. If the button has infinite uses, set to 0.
|
||||
/// </summary>
|
||||
public virtual int MaxUses => 0;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the location of the button on the screen.
|
||||
/// </summary>
|
||||
public virtual ButtonLocation Location => ButtonLocation.BottomLeft;
|
||||
public virtual ButtonLocation Location { get; private set; } = ButtonLocation.BottomLeft;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the button has an effect ability.
|
||||
@@ -55,6 +65,11 @@ public abstract class CustomActionButton
|
||||
/// </summary>
|
||||
public bool EffectActive { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the timer is currently active.
|
||||
/// </summary>
|
||||
public bool TimerPaused { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the amount of uses left.
|
||||
/// </summary>
|
||||
@@ -70,7 +85,11 @@ public abstract class CustomActionButton
|
||||
/// </summary>
|
||||
protected ActionButton? Button { get; private set; }
|
||||
|
||||
internal void CreateButton(Transform parent)
|
||||
/// <summary>
|
||||
/// The method used to create the button.
|
||||
/// </summary>
|
||||
/// <param name="parent">The parent of the button.</param>
|
||||
public virtual void CreateButton(Transform parent)
|
||||
{
|
||||
if (Button)
|
||||
{
|
||||
@@ -78,8 +97,9 @@ public abstract class CustomActionButton
|
||||
}
|
||||
|
||||
UsesLeft = MaxUses;
|
||||
Timer = Cooldown;
|
||||
Timer = AmongUsClient.Instance?.NetworkMode == NetworkModes.FreePlay ? 0 : InitialCooldown;
|
||||
EffectActive = false;
|
||||
TimerPaused = false;
|
||||
|
||||
Button = Object.Instantiate(HudManager.Instance.AbilityButton, parent);
|
||||
Button.name = Name + "Button";
|
||||
@@ -95,13 +115,87 @@ public abstract class CustomActionButton
|
||||
|
||||
var pb = Button.GetComponent<PassiveButton>();
|
||||
pb.OnClick = new Button.ButtonClickedEvent();
|
||||
pb.OnClick.AddListener((UnityAction)ClickHandler);
|
||||
pb.OnClick.AddListener((UnityAction)(() =>
|
||||
{
|
||||
// Invoke the generic button click event.
|
||||
var genericEvent = new MiraButtonClickEvent(this);
|
||||
MiraEventManager.InvokeEvent(genericEvent);
|
||||
if (genericEvent.IsCancelled)
|
||||
{
|
||||
MiraEventManager.InvokeEvent(new MiraButtonCancelledEvent(this));
|
||||
}
|
||||
|
||||
// Invoke the button click event for specific button.
|
||||
var eventType = CustomButtonManager.ButtonEventTypes[GetType()];
|
||||
var @event = (MiraCancelableEvent)Activator.CreateInstance(eventType, this, genericEvent)!;
|
||||
var specificInvoked = MiraEventManager.InvokeEvent(@event, eventType);
|
||||
if (@event.IsCancelled)
|
||||
{
|
||||
var cancelEventType = CustomButtonManager.ButtonCancelledEventTypes[GetType()];
|
||||
var cancelEvent = (MiraEvent)Activator.CreateInstance(cancelEventType, this)!;
|
||||
MiraEventManager.InvokeEvent(cancelEvent, cancelEventType);
|
||||
}
|
||||
|
||||
if (specificInvoked)
|
||||
{
|
||||
if (!@event.IsCancelled)
|
||||
{
|
||||
ClickHandler();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!genericEvent.IsCancelled)
|
||||
{
|
||||
ClickHandler();
|
||||
}
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Allows you to change the button's location.
|
||||
/// </summary>
|
||||
/// <param name="location">The new location.</param>
|
||||
/// <param name="moveButton">Whether the button's position should change ingame.</param>
|
||||
public virtual void SetButtonLocation(ButtonLocation location, bool moveButton = true)
|
||||
{
|
||||
if (!HudManager.InstanceExists || Button == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this.Location = location;
|
||||
|
||||
if (!moveButton) return;
|
||||
|
||||
if (HudManagerPatches._bottomLeft == null || HudManagerPatches._bottomRight == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
switch (location)
|
||||
{
|
||||
case ButtonLocation.BottomLeft:
|
||||
var gridArrange = HudManagerPatches._bottomLeft.GetComponent<GridArrange>();
|
||||
var aspectPosition = HudManagerPatches._bottomLeft.GetComponent<AspectPosition>();
|
||||
|
||||
Button.transform.SetParent(HudManagerPatches._bottomLeft.transform);
|
||||
|
||||
gridArrange.Start();
|
||||
gridArrange.ArrangeChilds();
|
||||
aspectPosition.AdjustPosition();
|
||||
break;
|
||||
case ButtonLocation.BottomRight:
|
||||
Button.transform.SetParent(HudManagerPatches._bottomRight);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A utility function to reset the cooldown and/or effect of the button.
|
||||
/// </summary>
|
||||
public void ResetCooldownAndOrEffect()
|
||||
public virtual void ResetCooldownAndOrEffect()
|
||||
{
|
||||
Timer = Cooldown;
|
||||
if (EffectActive)
|
||||
@@ -116,7 +210,7 @@ public abstract class CustomActionButton
|
||||
/// A utility function to override the sprite of the button.
|
||||
/// </summary>
|
||||
/// <param name="sprite">The new sprite to override with.</param>
|
||||
public void OverrideSprite(Sprite sprite)
|
||||
public virtual void OverrideSprite(Sprite sprite)
|
||||
{
|
||||
if (Button != null)
|
||||
{
|
||||
@@ -128,7 +222,7 @@ public abstract class CustomActionButton
|
||||
/// A utility function to override the name of the button.
|
||||
/// </summary>
|
||||
/// <param name="name">The new name to override with.</param>
|
||||
public void OverrideName(string name)
|
||||
public virtual void OverrideName(string name)
|
||||
{
|
||||
Button?.OverrideText(name);
|
||||
}
|
||||
@@ -137,7 +231,7 @@ public abstract class CustomActionButton
|
||||
/// Set the button's timer.
|
||||
/// </summary>
|
||||
/// <param name="time">The time you want to set to.</param>
|
||||
public void SetTimer(float time)
|
||||
public virtual void SetTimer(float time)
|
||||
{
|
||||
Timer = Mathf.Clamp(time, -1, float.MaxValue);
|
||||
}
|
||||
@@ -146,7 +240,7 @@ public abstract class CustomActionButton
|
||||
/// Increase the button's timer.
|
||||
/// </summary>
|
||||
/// <param name="amount">The amount you want to increase by.</param>
|
||||
public void IncreaseTimer(float amount)
|
||||
public virtual void IncreaseTimer(float amount)
|
||||
{
|
||||
SetTimer(Timer + amount);
|
||||
}
|
||||
@@ -155,25 +249,40 @@ public abstract class CustomActionButton
|
||||
/// Decrease the button's timer.
|
||||
/// </summary>
|
||||
/// <param name="amount">The amount you want to decrease by.</param>
|
||||
public void DecreaseTimer(float amount)
|
||||
public virtual void DecreaseTimer(float amount)
|
||||
{
|
||||
SetTimer(Timer - amount);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets whether the timer is paused or not.
|
||||
/// </summary>
|
||||
/// <param name="val">Whether you want to pause/resume the timer.</param>
|
||||
public virtual void SetTimerPaused(bool val)
|
||||
{
|
||||
TimerPaused = val;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the amount of uses this button has left.
|
||||
/// </summary>
|
||||
/// <param name="amount">The amount you want to set to.</param>
|
||||
public void SetUses(int amount)
|
||||
public virtual void SetUses(int amount)
|
||||
{
|
||||
UsesLeft = Mathf.Clamp(amount, 0, int.MaxValue);
|
||||
Button?.SetUsesRemaining(UsesLeft);
|
||||
|
||||
if (Button != null)
|
||||
{
|
||||
Button.usesRemainingSprite.color = UsesLeft == 0 ? Color.red : Color.white;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Increase the amount of uses this button has left.
|
||||
/// </summary>
|
||||
/// <param name="amount">The amount you want to increase by. Default: 1.</param>
|
||||
public void IncreaseUses(int amount = 1)
|
||||
public virtual void IncreaseUses(int amount = 1)
|
||||
{
|
||||
SetUses(UsesLeft + amount);
|
||||
}
|
||||
@@ -182,7 +291,7 @@ public abstract class CustomActionButton
|
||||
/// Decrease the amount of uses this button has left.
|
||||
/// </summary>
|
||||
/// <param name="amount">The amount you want to decrease by. Default: 1.</param>
|
||||
public void DecreaseUses(int amount = 1)
|
||||
public virtual void DecreaseUses(int amount = 1)
|
||||
{
|
||||
SetUses(UsesLeft - amount);
|
||||
}
|
||||
@@ -217,14 +326,24 @@ public abstract class CustomActionButton
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// When the button is enabled, this method is called to determine if the button can be used.
|
||||
/// When the button is usable, this method is called to determine if the button can be clicked.
|
||||
/// By default, it takes into account the timer, effect, and uses.
|
||||
/// You can override it to change the behavior.
|
||||
/// </summary>
|
||||
/// <returns>A value that represents whether the button can be used or not.</returns>
|
||||
/// <returns>A value that represents whether the button can be clicked or not.</returns>
|
||||
public virtual bool CanClick()
|
||||
{
|
||||
return Timer <= 0 && !EffectActive && CanUse();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether the button should light up or not. This is also the base for CanClick.
|
||||
/// You can override it to change the behaviour. Do not include timer in here, that is for CanClick.
|
||||
/// </summary>
|
||||
/// <returns>A value that represents whether the button should light up or not.</returns>
|
||||
public virtual bool CanUse()
|
||||
{
|
||||
return Timer <= 0 && !EffectActive && (!LimitedUses || UsesLeft > 0);
|
||||
return !LimitedUses || UsesLeft > 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -244,9 +363,9 @@ public abstract class CustomActionButton
|
||||
/// This method takes into account cooldowns, effects, and uses, before calling the <see cref="OnClick"/> method.
|
||||
/// It can be overridden for custom behavior.
|
||||
/// </summary>
|
||||
protected virtual void ClickHandler()
|
||||
public virtual void ClickHandler()
|
||||
{
|
||||
if (!CanUse())
|
||||
if (!CanClick())
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -258,7 +377,7 @@ public abstract class CustomActionButton
|
||||
}
|
||||
|
||||
OnClick();
|
||||
Button?.SetDisabled();
|
||||
|
||||
if (HasEffect)
|
||||
{
|
||||
EffectActive = true;
|
||||
@@ -278,7 +397,7 @@ public abstract class CustomActionButton
|
||||
/// <param name="playerControl">The local PlayerControl.</param>
|
||||
public virtual void FixedUpdateHandler(PlayerControl playerControl)
|
||||
{
|
||||
if (Timer >= 0)
|
||||
if (Timer >= 0 && !TimerPaused)
|
||||
{
|
||||
Timer -= Time.deltaTime;
|
||||
}
|
||||
@@ -298,7 +417,17 @@ public abstract class CustomActionButton
|
||||
Button?.SetDisabled();
|
||||
}
|
||||
|
||||
Button?.SetCoolDown(Timer, EffectActive ? EffectDuration : Cooldown);
|
||||
if (EffectActive)
|
||||
{
|
||||
Button?.SetFillUp(Timer, EffectDuration);
|
||||
|
||||
Button!.cooldownTimerText.text = Mathf.CeilToInt(Timer).ToString();
|
||||
Button!.cooldownTimerText.gameObject.SetActive(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
Button?.SetCoolDown(Timer, Cooldown);
|
||||
}
|
||||
|
||||
FixedUpdate(playerControl);
|
||||
}
|
||||
@@ -327,7 +456,7 @@ public abstract class CustomActionButton<T> : CustomActionButton where T : MonoB
|
||||
/// <returns>True if the target object is valid, false otherwise.</returns>
|
||||
public virtual bool IsTargetValid(T? target)
|
||||
{
|
||||
return target;
|
||||
return target != null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -354,6 +483,21 @@ public abstract class CustomActionButton<T> : CustomActionButton where T : MonoB
|
||||
Target = IsTargetValid(newTarget) ? newTarget : null;
|
||||
SetOutline(true);
|
||||
|
||||
return base.CanUse() && Target;
|
||||
return base.CanUse() && Target != null;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool CanClick()
|
||||
{
|
||||
return base.CanClick() && Target != null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Use this to reset the button's target after used.
|
||||
/// </summary>
|
||||
public virtual void ResetTarget()
|
||||
{
|
||||
Target = null;
|
||||
SetOutline(false);
|
||||
}
|
||||
}
|
||||
@@ -1,31 +1,42 @@
|
||||
using System;
|
||||
using MiraAPI.Events.Mira;
|
||||
using MiraAPI.PluginLoading;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Reflection;
|
||||
using Reactor.Utilities;
|
||||
|
||||
namespace MiraAPI.Hud;
|
||||
|
||||
internal static class CustomButtonManager
|
||||
/// <summary>
|
||||
/// Custom button manager for handling custom buttons.
|
||||
/// </summary>
|
||||
public static class CustomButtonManager
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets a list of all registered custom buttons.
|
||||
/// </summary>
|
||||
public static ReadOnlyCollection<CustomActionButton> Buttons { get; internal set; } = new([]);
|
||||
|
||||
internal static readonly List<CustomActionButton> CustomButtons = [];
|
||||
internal static readonly Dictionary<Type, Type> ButtonEventTypes = [];
|
||||
internal static readonly Dictionary<Type, Type> ButtonCancelledEventTypes = [];
|
||||
|
||||
internal static void RegisterButton(Type buttonType)
|
||||
internal static bool RegisterButton(Type buttonType, MiraPluginInfo pluginInfo)
|
||||
{
|
||||
if (!typeof(CustomActionButton).IsAssignableFrom(buttonType))
|
||||
if (!buttonType.IsAssignableTo(typeof(CustomActionButton)) || Activator.CreateInstance(buttonType) is not CustomActionButton button)
|
||||
{
|
||||
Logger<MiraApiPlugin>.Error($"{buttonType?.Name} does not inherit from CustomActionButton.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (Activator.CreateInstance(buttonType) is not CustomActionButton button)
|
||||
{
|
||||
Logger<MiraApiPlugin>.Error($"Failed to create button from {buttonType.Name}");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
CustomButtons.Add(button);
|
||||
pluginInfo.Buttons.Add(button);
|
||||
typeof(CustomButtonSingleton<>).MakeGenericType(buttonType)
|
||||
.GetField("_instance", BindingFlags.Static | BindingFlags.NonPublic)!
|
||||
.SetValue(null, button);
|
||||
|
||||
ButtonEventTypes.Add(buttonType, typeof(MiraButtonClickEvent<>).MakeGenericType(buttonType));
|
||||
ButtonCancelledEventTypes.Add(buttonType, typeof(MiraButtonCancelledEvent<>).MakeGenericType(buttonType));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
using AmongUs.GameOptions;
|
||||
using Il2CppInterop.Runtime.Attributes;
|
||||
using MiraAPI.Patches.Stubs;
|
||||
using Reactor.Utilities.Attributes;
|
||||
using Reactor.Utilities.Extensions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
namespace MiraAPI.Hud;
|
||||
|
||||
/// <summary>
|
||||
/// Custom Player Menu using the ShapeshifterPanel as a base.
|
||||
/// </summary>
|
||||
/// <param name="il2CppPtr">Used by Il2Cpp. Do not use constructor, this is a MonoBehaviour.</param>
|
||||
[RegisterInIl2Cpp]
|
||||
public class CustomPlayerMenu(IntPtr il2CppPtr) : Minigame(il2CppPtr)
|
||||
{
|
||||
public ShapeshifterPanel PanelPrefab;
|
||||
|
||||
public float XStart = -0.8f;
|
||||
|
||||
public float YStart = 2.15f;
|
||||
|
||||
public float XOffset = 1.95f;
|
||||
|
||||
public float YOffset = -0.65f;
|
||||
|
||||
public UiElement BackButton;
|
||||
|
||||
public UiElement DefaultButtonSelected;
|
||||
|
||||
public List<ShapeshifterPanel> potentialVictims;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a CustomPlayerMenu.
|
||||
/// </summary>
|
||||
/// <returns>New CustomPlayerMenu object.</returns>
|
||||
public static CustomPlayerMenu Create()
|
||||
{
|
||||
var shapeShifterRole = RoleManager.Instance.GetRole(RoleTypes.Shapeshifter);
|
||||
|
||||
var ogMenu = shapeShifterRole.TryCast<ShapeshifterRole>().ShapeshifterMenu;
|
||||
var newMenu = Instantiate(ogMenu);
|
||||
var customMenu = newMenu.gameObject.AddComponent<CustomPlayerMenu>();
|
||||
|
||||
customMenu.PanelPrefab = newMenu.PanelPrefab;
|
||||
customMenu.XStart = newMenu.XStart;
|
||||
customMenu.YStart = newMenu.YStart;
|
||||
customMenu.XOffset = newMenu.XOffset;
|
||||
customMenu.YOffset = newMenu.YOffset;
|
||||
customMenu.BackButton = newMenu.BackButton;
|
||||
var back = customMenu.BackButton.GetComponent<PassiveButton>();
|
||||
back.OnClick.RemoveAllListeners();
|
||||
back.OnClick.AddListener((UnityAction)(() =>
|
||||
{
|
||||
Instance.Close();
|
||||
}));
|
||||
|
||||
customMenu.CloseSound = newMenu.CloseSound;
|
||||
customMenu.logger = newMenu.logger;
|
||||
customMenu.OpenSound = newMenu.OpenSound;
|
||||
|
||||
newMenu.DestroyImmediate();
|
||||
|
||||
customMenu.transform.SetParent(Camera.main.transform, false);
|
||||
customMenu.transform.localPosition = new Vector3(0f, 0f, -50f);
|
||||
return customMenu;
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
ControllerManager.Instance.CloseOverlayMenu(name);
|
||||
}
|
||||
|
||||
public override void Begin(PlayerTask task)
|
||||
{
|
||||
throw new NotImplementedException("Use the other Begin method.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Begins/opens the custom player menu.
|
||||
/// </summary>
|
||||
/// <param name="playerMatch">Function to determine if player should show in the custom menu.</param>
|
||||
/// <param name="onClick">Onclick action for player.</param>
|
||||
[HideFromIl2Cpp]
|
||||
public void Begin(Func<PlayerControl, bool> playerMatch, Action<PlayerControl?> onClick)
|
||||
{
|
||||
MinigameStubs.Begin(this, null);
|
||||
|
||||
var back = BackButton.GetComponent<PassiveButton>();
|
||||
back.OnClick.AddListener((UnityAction)(() =>
|
||||
{
|
||||
onClick(null);
|
||||
}));
|
||||
|
||||
DestroyableSingleton<DebugAnalytics>.Instance.Analytics.MinigameOpened(PlayerControl.LocalPlayer.Data, TaskType);
|
||||
var list = PlayerControl.AllPlayerControls.ToArray().Where(playerMatch).ToList();
|
||||
potentialVictims = [];
|
||||
var list2 = new Il2CppSystem.Collections.Generic.List<UiElement>();
|
||||
|
||||
for (var i = 0; i < list.Count; i++)
|
||||
{
|
||||
var player = list[i];
|
||||
var num = i % 3;
|
||||
var num2 = i / 3;
|
||||
var flag = PlayerControl.LocalPlayer.Data.Role.NameColor == player.Data.Role.NameColor;
|
||||
var shapeshifterPanel = Instantiate(PanelPrefab, transform);
|
||||
shapeshifterPanel.transform.localPosition = new Vector3(XStart + num * XOffset, YStart + num2 * YOffset, -1f);
|
||||
shapeshifterPanel.SetPlayer(i, player.Data, (Il2CppSystem.Action)(() => { onClick(player); }));
|
||||
shapeshifterPanel.NameText.color = flag ? player.Data.Role.NameColor : Color.white;
|
||||
potentialVictims.Add(shapeshifterPanel);
|
||||
list2.Add(shapeshifterPanel.Button);
|
||||
}
|
||||
ControllerManager.Instance.OpenOverlayMenu(name, BackButton, DefaultButtonSelected, list2);
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace MiraAPI.Hud;
|
||||
|
||||
/// <summary>
|
||||
/// Attribute to register a button in the HUD. Necessary for the button to be recognized by Mira.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Class)]
|
||||
public class RegisterButtonAttribute : Attribute;
|
||||
@@ -75,6 +75,6 @@ public abstract class BaseModifier
|
||||
/// <summary>
|
||||
/// Determines whether the player can vent.
|
||||
/// </summary>
|
||||
/// <returns>True if the player can vent, false otherwise.</returns>
|
||||
public virtual bool CanVent() => Player?.Data.Role.CanVent == true;
|
||||
/// <returns>True if the player can vent, false otherwise. Null for no effect.</returns>
|
||||
public virtual bool? CanVent() => null;
|
||||
}
|
||||
@@ -1,14 +1,14 @@
|
||||
using System;
|
||||
using Il2CppInterop.Runtime.Attributes;
|
||||
using MiraAPI.Modifiers.Types;
|
||||
using MiraAPI.Utilities;
|
||||
using Reactor.Utilities;
|
||||
using Reactor.Utilities.Attributes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Il2CppInterop.Runtime.Attributes;
|
||||
using MiraAPI.Modifiers.Types;
|
||||
using MiraAPI.Utilities;
|
||||
using Reactor.Utilities;
|
||||
using Reactor.Utilities.Attributes;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -39,11 +39,6 @@ public class ModifierComponent(IntPtr cppPtr) : MonoBehaviour(cppPtr)
|
||||
|
||||
internal void ClearModifiers()
|
||||
{
|
||||
foreach (var modifier in Modifiers)
|
||||
{
|
||||
modifier.OnDeactivate();
|
||||
}
|
||||
|
||||
_toRemove.AddRange(Modifiers);
|
||||
}
|
||||
|
||||
@@ -74,7 +69,7 @@ public class ModifierComponent(IntPtr cppPtr) : MonoBehaviour(cppPtr)
|
||||
Modifiers.Add(modifier);
|
||||
modifier.OnActivate();
|
||||
|
||||
if (_player?.AmOwner == true && modifier is TimedModifier { AutoStart: true } timer)
|
||||
if (modifier is TimedModifier { AutoStart: true } timer)
|
||||
{
|
||||
timer.StartTimer();
|
||||
}
|
||||
@@ -84,7 +79,7 @@ public class ModifierComponent(IntPtr cppPtr) : MonoBehaviour(cppPtr)
|
||||
{
|
||||
if (_player?.AmOwner == true)
|
||||
{
|
||||
HudManager.Instance?.SetHudActive(true);
|
||||
HudManager.Instance?.SetHudActive(_player, _player.Data.Role, HudManager.Instance.TaskPanel.isActiveAndEnabled);
|
||||
}
|
||||
_toAdd.Clear();
|
||||
_toRemove.Clear();
|
||||
@@ -112,7 +107,7 @@ public class ModifierComponent(IntPtr cppPtr) : MonoBehaviour(cppPtr)
|
||||
|
||||
var baseModifiers = filteredModifiers as BaseModifier[] ?? filteredModifiers.ToArray();
|
||||
|
||||
if (baseModifiers.Length != 0)
|
||||
if (baseModifiers.Length != 0 && !MeetingHud.Instance)
|
||||
{
|
||||
var stringBuild = new StringBuilder();
|
||||
foreach (var mod in baseModifiers)
|
||||
@@ -260,4 +255,24 @@ public class ModifierComponent(IntPtr cppPtr) : MonoBehaviour(cppPtr)
|
||||
{
|
||||
return AddModifier(typeof(T)) as T;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if a player has an active or queued modifier by its ID.
|
||||
/// </summary>
|
||||
/// <param name="id">The Modifier ID.</param>
|
||||
/// <returns>True if the Modifier is present, false otherwise.</returns>
|
||||
public bool HasModifier(uint id)
|
||||
{
|
||||
return ActiveModifiers.Exists(x => x.ModifierId == id) || _toAdd.Exists(x => x.ModifierId == id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if a player has an active or queued modifier by its type.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The Type of the Modifier.</typeparam>
|
||||
/// <returns>True if the Modifier is present, false otherwise.</returns>
|
||||
public bool HasModifier<T>()
|
||||
{
|
||||
return ActiveModifiers.Exists(x => x is T) || _toAdd.Exists(x => x is T);
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@ public static class ModifierManager
|
||||
{
|
||||
private static readonly Dictionary<uint, Type> IdToTypeModifierMap = [];
|
||||
private static readonly Dictionary<Type, uint> TypeToIdModifierMap = [];
|
||||
private static readonly Dictionary<int, List<uint>> PrioritiesToIdsMap = [];
|
||||
|
||||
private static uint _nextId;
|
||||
|
||||
@@ -48,84 +49,100 @@ public static class ModifierManager
|
||||
return TypeToIdModifierMap.GetValueOrDefault(type);
|
||||
}
|
||||
|
||||
internal static void RegisterModifier(Type modifierType)
|
||||
internal static bool RegisterModifier(Type modifierType)
|
||||
{
|
||||
if (!typeof(BaseModifier).IsAssignableFrom(modifierType))
|
||||
{
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
IdToTypeModifierMap.Add(GetNextId(), modifierType);
|
||||
TypeToIdModifierMap.Add(modifierType, _nextId);
|
||||
|
||||
if (!typeof(GameModifier).IsAssignableFrom(modifierType))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
var mod = Activator.CreateInstance(modifierType) as GameModifier;
|
||||
var priority = mod!.Priority();
|
||||
|
||||
if (!PrioritiesToIdsMap.TryGetValue(priority, out var list))
|
||||
{
|
||||
PrioritiesToIdsMap[priority] = list = [];
|
||||
}
|
||||
|
||||
list.Add(_nextId);
|
||||
return true;
|
||||
}
|
||||
|
||||
internal static void AssignModifiers(List<PlayerControl> plrs)
|
||||
{
|
||||
var rand = new Random();
|
||||
|
||||
List<uint> filteredModifiers = [];
|
||||
|
||||
foreach (var modifier in IdToTypeModifierMap.Where(pair => pair.Value.IsAssignableTo(typeof(GameModifier))))
|
||||
foreach (var priority in PrioritiesToIdsMap.Keys.OrderByDescending(x => x))
|
||||
{
|
||||
if (Activator.CreateInstance(modifier.Value) is not GameModifier mod)
|
||||
var filteredModifiers = new List<uint>();
|
||||
|
||||
foreach (var id in PrioritiesToIdsMap[priority])
|
||||
{
|
||||
Logger<MiraApiPlugin>.Error($"Failed to create instance of {modifier.Value.Name}");
|
||||
continue;
|
||||
}
|
||||
var mod = Activator.CreateInstance(IdToTypeModifierMap[id]) as GameModifier;
|
||||
var chance = Math.Clamp(mod!.GetAssignmentChance(), 0, 100);
|
||||
var count = mod.GetAmountPerGame();
|
||||
|
||||
if (!plrs.Exists(x => IsGameModifierValid(x, mod, modifier.Key)))
|
||||
{
|
||||
Logger<MiraApiPlugin>.Warning("No players are valid for modifier: " + mod.ModifierName);
|
||||
continue;
|
||||
}
|
||||
|
||||
var maxCount = plrs.Count(x => IsGameModifierValid(x, mod, modifier.Key));
|
||||
|
||||
var num = Math.Clamp(mod.GetAmountPerGame(), 0, maxCount);
|
||||
var chance = mod.GetAssignmentChance();
|
||||
|
||||
for (var i = 0; i < num; i++)
|
||||
{
|
||||
var randomNum = rand.Next(100);
|
||||
|
||||
if (randomNum < Math.Clamp(chance, 0, 100))
|
||||
if (chance == 0 || count == 0)
|
||||
{
|
||||
filteredModifiers.Add(TypeToIdModifierMap[modifier.Value]);
|
||||
continue;
|
||||
}
|
||||
|
||||
var maxCount = plrs.Count(x => IsGameModifierValid(x, mod, id));
|
||||
|
||||
if (maxCount == 0)
|
||||
{
|
||||
Logger<MiraApiPlugin>.Warning($"No players are valid for {mod.ModifierName}");
|
||||
continue;
|
||||
}
|
||||
|
||||
var num = Math.Clamp(count, 0, maxCount);
|
||||
|
||||
for (var i = 0; i < num; i++)
|
||||
{
|
||||
var randomNum = rand.Next(100);
|
||||
|
||||
if (randomNum < chance)
|
||||
{
|
||||
filteredModifiers.Add(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var shuffledModifiers = filteredModifiers.Randomize();
|
||||
if (shuffledModifiers.Count > plrs.Count)
|
||||
{
|
||||
shuffledModifiers = shuffledModifiers.GetRange(0, plrs.Count);
|
||||
}
|
||||
|
||||
while (shuffledModifiers.Count > 0)
|
||||
{
|
||||
var id = shuffledModifiers[0];
|
||||
|
||||
if (Activator.CreateInstance(IdToTypeModifierMap[id]) is not GameModifier mod)
|
||||
if (filteredModifiers.Count == 0)
|
||||
{
|
||||
Logger<MiraApiPlugin>.Error($"Failed to create instance of {IdToTypeModifierMap[id].Name}");
|
||||
Logger<MiraApiPlugin>.Warning($"No filtered modifiers for priority {priority}");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!plrs.Exists(x => IsGameModifierValid(x, mod, id)))
|
||||
var shuffledList = filteredModifiers.Randomize();
|
||||
|
||||
if (shuffledList.Count > plrs.Count)
|
||||
{
|
||||
shuffledModifiers.RemoveAt(0);
|
||||
continue;
|
||||
shuffledList = shuffledList.GetRange(0, plrs.Count);
|
||||
}
|
||||
|
||||
var plr = plrs.Random();
|
||||
|
||||
if (plr == null || !IsGameModifierValid(plr, mod, id))
|
||||
foreach (var id in shuffledList)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
var mod = Activator.CreateInstance(IdToTypeModifierMap[id]) as GameModifier;
|
||||
var plr = plrs.Where(x => IsGameModifierValid(x, mod!, id)).Random();
|
||||
|
||||
shuffledModifiers.RemoveAt(0);
|
||||
plr.RpcAddModifier(id);
|
||||
if (plr == null)
|
||||
{
|
||||
Logger<MiraApiPlugin>.Warning($"Somehow valid players for modifier {mod!.ModifierName} disappeared");
|
||||
}
|
||||
else
|
||||
{
|
||||
plr.RpcAddModifier(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace MiraAPI.Modifiers;
|
||||
|
||||
/// <summary>
|
||||
/// Marks a class as a modifier that can be registered with the <see cref="ModifierManager"/>.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Class)]
|
||||
public class RegisterModifierAttribute : Attribute;
|
||||
@@ -17,10 +17,23 @@ public abstract class GameModifier : BaseModifier
|
||||
/// <returns>An int value greater than or equal to zero.</returns>
|
||||
public abstract int GetAmountPerGame();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the priority at which the modifier will spawn. The higher the value, the higher up on the assignment list.
|
||||
/// </summary>
|
||||
/// <returns>An int value greater than or equal to -1.</returns>
|
||||
public virtual int Priority() => -1;
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the modifier is valid on a role.
|
||||
/// </summary>
|
||||
/// <param name="role">The role to be checked.</param>
|
||||
/// <returns>True if the modifier is valid on the role, otherwise false.</returns>
|
||||
public virtual bool IsModifierValidOn(RoleBehaviour role) => true;
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the player won the game with this modifier.
|
||||
/// </summary>
|
||||
/// <param name="reason">The reason why the game ended.</param>
|
||||
/// <returns>True if the player won, false if they lost. Return null to use the player's default win condition.</returns>
|
||||
public virtual bool? DidWin(GameOverReason reason) => null;
|
||||
}
|
||||
@@ -39,6 +39,9 @@ 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>
|
||||
@@ -53,25 +56,18 @@ public abstract class TimedModifier : BaseModifier
|
||||
/// </summary>
|
||||
public override void FixedUpdate()
|
||||
{
|
||||
if (Player?.AmOwner == false)
|
||||
if (!TimerActive)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (TimeRemaining > 0 && TimerActive)
|
||||
if (TimeRemaining > 0)
|
||||
{
|
||||
TimeRemaining -= Time.fixedDeltaTime;
|
||||
}
|
||||
else
|
||||
{
|
||||
TimerActive = false;
|
||||
TimeRemaining = Duration;
|
||||
OnTimerComplete();
|
||||
|
||||
if (RemoveOnComplete)
|
||||
{
|
||||
ModifierComponent?.RemoveModifier(ModifierId);
|
||||
}
|
||||
StopTimer();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,7 +82,52 @@ 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;
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,13 @@
|
||||
using System.Collections;
|
||||
using System.Linq;
|
||||
using AmongUs.GameOptions;
|
||||
using AmongUs.GameOptions;
|
||||
using Assets.CoreScripts;
|
||||
using BepInEx.Unity.IL2CPP.Utils;
|
||||
using MiraAPI.Events;
|
||||
using MiraAPI.Events.Vanilla.Gameplay;
|
||||
using Reactor.Networking.Attributes;
|
||||
using Reactor.Utilities;
|
||||
using Reactor.Networking.Rpc;
|
||||
using Reactor.Utilities.Extensions;
|
||||
using System.Collections;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.Networking;
|
||||
@@ -26,7 +28,7 @@ public static class CustomMurderRpc
|
||||
/// <param name="teleportMurderer">Should the killer be snapped to the dead player.</param>
|
||||
/// <param name="showKillAnim">Should the kill animation be shown.</param>
|
||||
/// <param name="playKillSound">Should the kill sound be played.</param>
|
||||
[MethodRpc((uint)MiraRpc.CustomMurder)]
|
||||
[MethodRpc((uint)MiraRpc.CustomMurder, LocalHandling = RpcLocalHandling.Before, SendImmediately = true)]
|
||||
public static void RpcCustomMurder(
|
||||
this PlayerControl source,
|
||||
PlayerControl target,
|
||||
@@ -38,6 +40,15 @@ public static class CustomMurderRpc
|
||||
bool playKillSound = true)
|
||||
{
|
||||
var murderResultFlags = didSucceed ? MurderResultFlags.Succeeded : MurderResultFlags.FailedError;
|
||||
|
||||
var beforeMurderEvent = new BeforeMurderEvent(source, target);
|
||||
MiraEventManager.InvokeEvent(beforeMurderEvent);
|
||||
|
||||
if (beforeMurderEvent.IsCancelled)
|
||||
{
|
||||
murderResultFlags = MurderResultFlags.FailedError;
|
||||
}
|
||||
|
||||
var murderResultFlags2 = MurderResultFlags.DecisionByHost | murderResultFlags;
|
||||
|
||||
source.CustomMurder(
|
||||
@@ -72,7 +83,6 @@ public static class CustomMurderRpc
|
||||
bool playKillSound = true)
|
||||
{
|
||||
source.isKilling = false;
|
||||
Logger<MiraApiPlugin>.Error($"{source.PlayerId} trying to murder {target.PlayerId}");
|
||||
var data = target.Data;
|
||||
if (resultFlags.HasFlag(MurderResultFlags.FailedError))
|
||||
{
|
||||
@@ -87,7 +97,7 @@ public static class CustomMurderRpc
|
||||
if (flag && PlayerControl.LocalPlayer.Data.PlayerId == target.protectedByGuardianId)
|
||||
{
|
||||
StatsManager.Instance.IncrementStat(StringNames.StatsGuardianAngelCrewmatesProtected);
|
||||
DestroyableSingleton<AchievementManager>.Instance.OnProtectACrewmate();
|
||||
AchievementManager.Instance.OnProtectACrewmate();
|
||||
}
|
||||
|
||||
if (source.AmOwner || flag)
|
||||
@@ -105,7 +115,6 @@ public static class CustomMurderRpc
|
||||
target.RemoveProtection();
|
||||
}
|
||||
|
||||
Logger<MiraApiPlugin>.Error($"{source.PlayerId} failed to murder {target.PlayerId} due to guardian angel protection");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -115,7 +124,7 @@ public static class CustomMurderRpc
|
||||
return;
|
||||
}
|
||||
|
||||
DestroyableSingleton<DebugAnalytics>.Instance.Analytics.Kill(target.Data, source.Data);
|
||||
DebugAnalytics.Instance.Analytics.Kill(target.Data, source.Data);
|
||||
if (source.AmOwner)
|
||||
{
|
||||
StatsManager.Instance.IncrementStat(
|
||||
@@ -139,7 +148,7 @@ public static class CustomMurderRpc
|
||||
}
|
||||
}
|
||||
|
||||
DestroyableSingleton<UnityTelemetry>.Instance.WriteMurder();
|
||||
UnityTelemetry.Instance.WriteMurder();
|
||||
target.gameObject.layer = LayerMask.NameToLayer("Ghost");
|
||||
if (target.AmOwner)
|
||||
{
|
||||
@@ -159,21 +168,20 @@ public static class CustomMurderRpc
|
||||
|
||||
if (showKillAnim)
|
||||
{
|
||||
DestroyableSingleton<HudManager>.Instance.KillOverlay.ShowKillAnimation(source.Data, data);
|
||||
HudManager.Instance.KillOverlay.ShowKillAnimation(source.Data, data);
|
||||
}
|
||||
|
||||
target.cosmetics.SetNameMask(false);
|
||||
target.RpcSetScanner(false);
|
||||
}
|
||||
|
||||
DestroyableSingleton<AchievementManager>.Instance.OnMurder(
|
||||
AchievementManager.Instance.OnMurder(
|
||||
source.AmOwner,
|
||||
target.AmOwner,
|
||||
source.CurrentOutfitType == PlayerOutfitType.Shapeshifted,
|
||||
source.shapeshiftTargetPlayerId,
|
||||
target.PlayerId);
|
||||
source.MyPhysics.StartCoroutine(source.KillAnimations.Random()?.CoPerformCustomKill(source, target, createDeadBody, teleportMurderer));
|
||||
Logger<MiraApiPlugin>.Error($"{source.PlayerId} succeeded in murdering {target.PlayerId}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -239,11 +247,11 @@ public static class CustomMurderRpc
|
||||
}
|
||||
|
||||
target.Die(DeathReason.Kill, true);
|
||||
yield return source.MyPhysics.Animations.CoPlayCustomAnimation(anim.BlurAnim);
|
||||
sourcePhys.Animations.PlayIdleAnimation();
|
||||
|
||||
if (teleportMurderer)
|
||||
{
|
||||
yield return source.MyPhysics.Animations.CoPlayCustomAnimation(anim.BlurAnim);
|
||||
sourcePhys.Animations.PlayIdleAnimation();
|
||||
source.NetTransform.SnapTo(target.transform.position);
|
||||
KillAnimation.SetMovement(source, true);
|
||||
}
|
||||
@@ -255,6 +263,9 @@ public static class CustomMurderRpc
|
||||
deadBody.enabled = true;
|
||||
}
|
||||
|
||||
var afterMurderEvent = new AfterMurderEvent(source, target);
|
||||
MiraEventManager.InvokeEvent(afterMurderEvent);
|
||||
|
||||
if (!isParticipant)
|
||||
{
|
||||
yield break;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using HarmonyLib;
|
||||
using InnerNet;
|
||||
using MiraAPI.Events;
|
||||
using MiraAPI.Events.Vanilla.Player;
|
||||
using MiraAPI.GameOptions;
|
||||
using MiraAPI.Modifiers;
|
||||
using MiraAPI.Roles;
|
||||
@@ -9,11 +11,16 @@ namespace MiraAPI.Patches;
|
||||
/// <summary>
|
||||
/// Sync all options, role settings, and modifiers to the player when they join the game.
|
||||
/// </summary>
|
||||
[HarmonyPatch(typeof(AmongUsClient), nameof(AmongUsClient.CreatePlayer))]
|
||||
[HarmonyPatch(typeof(AmongUsClient))]
|
||||
public static class AmongUsClientSyncPatch
|
||||
{
|
||||
public static void Postfix(ClientData clientData)
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(AmongUsClient), nameof(AmongUsClient.CreatePlayer))]
|
||||
public static void CreatePlayerPatch(ClientData clientData)
|
||||
{
|
||||
var joinEvent = new PlayerJoinEvent(clientData);
|
||||
MiraEventManager.InvokeEvent(joinEvent);
|
||||
|
||||
if (!AmongUsClient.Instance.AmHost)
|
||||
{
|
||||
return;
|
||||
@@ -28,4 +35,12 @@ public static class AmongUsClientSyncPatch
|
||||
CustomRoleManager.SyncAllRoleSettings(clientData.Id);
|
||||
ModifierManager.SyncAllModifiers(clientData.Id);
|
||||
}
|
||||
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(AmongUsClient), nameof(AmongUsClient.OnPlayerLeft))]
|
||||
public static void PlayerLeftPatch(ClientData data, DisconnectReasons reason)
|
||||
{
|
||||
var leftEvent = new PlayerLeaveEvent(data, reason);
|
||||
MiraEventManager.InvokeEvent(leftEvent);
|
||||
}
|
||||
}
|
||||
@@ -4,17 +4,19 @@ using UnityEngine;
|
||||
|
||||
namespace MiraAPI.Patches.Colors;
|
||||
|
||||
[HarmonyPatch(typeof(PlayerTab))]
|
||||
/// <summary>
|
||||
/// This patch adds scrolling to the colors tab in the player customization menu.
|
||||
/// </summary>
|
||||
[HarmonyPatch(typeof(PlayerTab), nameof(PlayerTab.OnEnable))]
|
||||
public static class ScrollingColorsPatch
|
||||
{
|
||||
// Collider
|
||||
private static BoxCollider2D? _collider;
|
||||
|
||||
/// <summary>
|
||||
/// Add scrolling to the colors tab
|
||||
/// Add scrolling to the colors tab.
|
||||
/// </summary>
|
||||
[HarmonyPostfix, HarmonyPatch("OnEnable")]
|
||||
public static void AddScrollingToColorsTabPatch(PlayerTab __instance)
|
||||
public static void Postfix(PlayerTab __instance)
|
||||
{
|
||||
if (!PlayerCustomizationMenu.Instance)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
using HarmonyLib;
|
||||
using MiraAPI.Events;
|
||||
using MiraAPI.Events.Vanilla.Usables;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
|
||||
namespace MiraAPI.Patches.Events;
|
||||
|
||||
[HarmonyPatch]
|
||||
public static class CanUsePatches
|
||||
{
|
||||
public static IEnumerable<MethodBase> TargetMethods()
|
||||
{
|
||||
yield return AccessTools.Method(typeof(Console), nameof(Console.CanUse));
|
||||
yield return AccessTools.Method(typeof(MapConsole), nameof(MapConsole.CanUse));
|
||||
yield return AccessTools.Method(typeof(SystemConsole), nameof(SystemConsole.CanUse));
|
||||
yield return AccessTools.Method(typeof(Ladder), nameof(Ladder.CanUse));
|
||||
yield return AccessTools.Method(typeof(PlatformConsole), nameof(PlatformConsole.CanUse));
|
||||
yield return AccessTools.Method(typeof(OpenDoorConsole), nameof(OpenDoorConsole.CanUse));
|
||||
yield return AccessTools.Method(typeof(DoorConsole), nameof(DoorConsole.CanUse));
|
||||
yield return AccessTools.Method(typeof(OptionsConsole), nameof(OptionsConsole.CanUse));
|
||||
yield return AccessTools.Method(typeof(ZiplineConsole), nameof(ZiplineConsole.CanUse));
|
||||
}
|
||||
|
||||
[HarmonyPriority(Priority.Last)]
|
||||
[HarmonyPrefix]
|
||||
public static bool CanUsePatch(Il2CppSystem.Object __instance, [HarmonyArgument(0)] NetworkedPlayerInfo pc, [HarmonyArgument(1)] out bool canUse, [HarmonyArgument(2)] out bool couldUse)
|
||||
{
|
||||
canUse = couldUse = false;
|
||||
|
||||
IUsable usable = __instance.Cast<IUsable>();
|
||||
if (usable != null)
|
||||
{
|
||||
var @event = new PlayerCanUseEvent(__instance.Cast<IUsable>());
|
||||
MiraEventManager.InvokeEvent(@event);
|
||||
|
||||
return !@event.IsCancelled;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using HarmonyLib;
|
||||
using MiraAPI.Events;
|
||||
using MiraAPI.Events.Vanilla.Gameplay;
|
||||
|
||||
namespace MiraAPI.Patches.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Patch for trigging the GameEndEvent.
|
||||
/// </summary>
|
||||
[HarmonyPatch]
|
||||
public static class EndGamePatches
|
||||
{
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(EndGameManager), nameof(EndGameManager.SetEverythingUp))]
|
||||
public static void SetEverythingUpPatch(EndGameManager __instance)
|
||||
{
|
||||
var @event = new GameEndEvent(__instance);
|
||||
MiraEventManager.InvokeEvent(@event);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using HarmonyLib;
|
||||
using MiraAPI.Events;
|
||||
using MiraAPI.Events.Vanilla.Gameplay;
|
||||
|
||||
namespace MiraAPI.Patches;
|
||||
|
||||
/// <summary>
|
||||
/// General patches for the KillAnimation class.
|
||||
/// </summary>
|
||||
[HarmonyPatch]
|
||||
public static class KillAnimationPatches
|
||||
{
|
||||
/// <summary>
|
||||
/// Used to trigger the <see cref="AfterMurderEvent"/>.
|
||||
/// </summary>
|
||||
/// <param name="source">The killer.</param>
|
||||
/// <param name="target">The target.</param>
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(KillAnimation), nameof(KillAnimation.CoPerformKill))]
|
||||
public static void KillAnimPostfix(PlayerControl source, PlayerControl target)
|
||||
{
|
||||
var afterMurderEvent = new AfterMurderEvent(source, target);
|
||||
MiraEventManager.InvokeEvent(afterMurderEvent);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using HarmonyLib;
|
||||
using MiraAPI.Events;
|
||||
using MiraAPI.Events.Vanilla.Map;
|
||||
|
||||
namespace MiraAPI.Patches.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Patch for map related MiraEvents.
|
||||
/// </summary>
|
||||
[HarmonyPatch]
|
||||
public static class MapBehaviourPatches
|
||||
{
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(MapBehaviour), nameof(MapBehaviour.ShowSabotageMap))]
|
||||
public static bool MapShowSabotagePatch(MapBehaviour __instance)
|
||||
{
|
||||
var @event = new PlayerOpenSabotageEvent(__instance);
|
||||
MiraEventManager.InvokeEvent(@event);
|
||||
return !@event.IsCancelled;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using HarmonyLib;
|
||||
using MiraAPI.Events;
|
||||
using MiraAPI.Events.Vanilla.Map;
|
||||
|
||||
namespace MiraAPI.Patches.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Used for patching sabotage/system related MiraEvents.
|
||||
/// </summary>
|
||||
[HarmonyPatch]
|
||||
public static class SabotageEventPatches
|
||||
{
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(ShipStatus), nameof(ShipStatus.RpcUpdateSystem), typeof(SystemTypes), typeof(byte))]
|
||||
public static bool ShipStatusUpdateSystemPrefix(ShipStatus __instance, SystemTypes systemType, byte amount)
|
||||
{
|
||||
var @event = new UpdateSystemEvent(systemType, PlayerControl.LocalPlayer, amount);
|
||||
MiraEventManager.InvokeEvent(@event);
|
||||
return !@event.IsCancelled;
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(ShipStatus), nameof(ShipStatus.RpcCloseDoorsOfType))]
|
||||
public static bool ShipStatusCloseDoorsOfTypePrefix(ShipStatus __instance, SystemTypes type)
|
||||
{
|
||||
var @event = new CloseDoorsEvent(type);
|
||||
MiraEventManager.InvokeEvent(@event);
|
||||
return !@event.IsCancelled;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using HarmonyLib;
|
||||
using MiraAPI.Events;
|
||||
using MiraAPI.Events.Vanilla.Meeting;
|
||||
using MiraAPI.Utilities;
|
||||
|
||||
namespace MiraAPI.Patches.Events;
|
||||
|
||||
[HarmonyPatch]
|
||||
public static class StartMeetingEventPatch
|
||||
{
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(PlayerControl), nameof(PlayerControl.CmdReportDeadBody))]
|
||||
public static bool PlayerControlCmdReportDeadBodyPrefix(PlayerControl __instance, NetworkedPlayerInfo? target)
|
||||
{
|
||||
var body = target != null ? Helpers.GetBodyById(target.PlayerId) : null;
|
||||
|
||||
var @event = new StartMeetingEvent(__instance, target, body);
|
||||
MiraEventManager.InvokeEvent(@event);
|
||||
return !@event.IsCancelled;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
using HarmonyLib;
|
||||
using MiraAPI.Events;
|
||||
using MiraAPI.Events.Vanilla;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
|
||||
namespace MiraAPI.Patches.Events;
|
||||
|
||||
[HarmonyPatch]
|
||||
public static class UsePatches
|
||||
{
|
||||
public static IEnumerable<MethodBase> TargetMethods()
|
||||
{
|
||||
yield return AccessTools.Method(typeof(Console), nameof(Console.Use));
|
||||
yield return AccessTools.Method(typeof(MapConsole), nameof(MapConsole.Use));
|
||||
yield return AccessTools.Method(typeof(SystemConsole), nameof(SystemConsole.Use));
|
||||
yield return AccessTools.Method(typeof(Vent), nameof(Vent.Use));
|
||||
yield return AccessTools.Method(typeof(Ladder), nameof(Ladder.Use));
|
||||
yield return AccessTools.Method(typeof(PlatformConsole), nameof(PlatformConsole.Use));
|
||||
yield return AccessTools.Method(typeof(OpenDoorConsole), nameof(OpenDoorConsole.Use));
|
||||
yield return AccessTools.Method(typeof(DoorConsole), nameof(DoorConsole.Use));
|
||||
yield return AccessTools.Method(typeof(OptionsConsole), nameof(OptionsConsole.Use));
|
||||
yield return AccessTools.Method(typeof(ZiplineConsole), nameof(ZiplineConsole.Use));
|
||||
}
|
||||
|
||||
[HarmonyPriority(Priority.Last)]
|
||||
[HarmonyPrefix]
|
||||
public static bool UsePatch(Il2CppSystem.Object __instance)
|
||||
{
|
||||
var @event = new PlayerUseEvent(__instance.Cast<IUsable>());
|
||||
MiraEventManager.InvokeEvent(@event);
|
||||
|
||||
return !@event.IsCancelled;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
using HarmonyLib;
|
||||
using MiraAPI.Events;
|
||||
using MiraAPI.Events.Vanilla.Usables;
|
||||
using System.Linq;
|
||||
|
||||
namespace MiraAPI.Patches.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Patches to invoke vent related MiraEvents.
|
||||
/// </summary>
|
||||
[HarmonyPatch]
|
||||
public static class VentEventPatches
|
||||
{
|
||||
// necessary because Vent.Use is inlined in il2cpp.
|
||||
private static bool _showButtons;
|
||||
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(VentButton), nameof(VentButton.DoClick))]
|
||||
public static void VentUsePostfix(VentButton __instance)
|
||||
{
|
||||
__instance.currentTarget?.SetButtons(_showButtons);
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(PlayerPhysics), nameof(PlayerPhysics.RpcEnterVent))]
|
||||
public static bool PlayerPhysicsRpcEnterVentPrefix(PlayerPhysics __instance, int id)
|
||||
{
|
||||
var pc = __instance.myPlayer;
|
||||
var vent = ShipStatus.Instance.AllVents.FirstOrDefault(v => v.Id == id);
|
||||
|
||||
var @event = new EnterVentEvent(pc, vent);
|
||||
MiraEventManager.InvokeEvent(@event);
|
||||
|
||||
if (pc.AmOwner)
|
||||
{
|
||||
_showButtons = !@event.IsCancelled;
|
||||
}
|
||||
return !@event.IsCancelled;
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(PlayerPhysics), nameof(PlayerPhysics.RpcExitVent))]
|
||||
public static bool PlayerPhysicsRpcExitVentPrefix(PlayerPhysics __instance, int id)
|
||||
{
|
||||
var pc = __instance.myPlayer;
|
||||
var vent = ShipStatus.Instance.AllVents.First(v => v.Id == id);
|
||||
|
||||
var @event = new ExitVentEvent(pc, vent);
|
||||
MiraEventManager.InvokeEvent(@event);
|
||||
|
||||
if (pc.AmOwner)
|
||||
{
|
||||
_showButtons = @event.IsCancelled;
|
||||
}
|
||||
return !@event.IsCancelled;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
using HarmonyLib;
|
||||
using MiraAPI.Hud;
|
||||
using MiraAPI.Roles;
|
||||
using Reactor.Utilities.Extensions;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
@@ -14,7 +13,9 @@ namespace MiraAPI.Patches;
|
||||
public static class HudManagerPatches
|
||||
{
|
||||
// Custom buttons parent.
|
||||
private static GameObject? _bottomLeft;
|
||||
internal static GameObject? _bottomLeft;
|
||||
internal static Transform? _bottomRight;
|
||||
internal static Transform? _buttons;
|
||||
|
||||
/*
|
||||
/// <summary>
|
||||
@@ -35,12 +36,19 @@ public static class HudManagerPatches
|
||||
[HarmonyPatch(nameof(HudManager.Start))]
|
||||
public static void StartPostfix(HudManager __instance)
|
||||
{
|
||||
var buttons = __instance.transform.Find("Buttons");
|
||||
var bottomRight = buttons.Find("BottomRight");
|
||||
if (_buttons == null)
|
||||
{
|
||||
_buttons = __instance.transform.Find("Buttons");
|
||||
}
|
||||
|
||||
if (_bottomRight == null)
|
||||
{
|
||||
_bottomRight = _buttons.Find("BottomRight");
|
||||
}
|
||||
|
||||
if (_bottomLeft == null)
|
||||
{
|
||||
_bottomLeft = Object.Instantiate(bottomRight.gameObject, buttons);
|
||||
_bottomLeft = Object.Instantiate(_bottomRight.gameObject, _buttons);
|
||||
}
|
||||
|
||||
foreach (var t in _bottomLeft.GetComponentsInChildren<ActionButton>(true))
|
||||
@@ -60,7 +68,7 @@ public static class HudManagerPatches
|
||||
var location = button.Location switch
|
||||
{
|
||||
ButtonLocation.BottomLeft => _bottomLeft.transform,
|
||||
ButtonLocation.BottomRight => bottomRight,
|
||||
ButtonLocation.BottomRight => _bottomRight,
|
||||
_ => null,
|
||||
};
|
||||
|
||||
@@ -89,7 +97,8 @@ 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)
|
||||
{
|
||||
if (!localPlayer.Data)
|
||||
__instance.AdminButton.ToggleVisible(isActive && role.IsImpostor && GameOptionsManager.Instance.CurrentGameOptions.GameMode == AmongUs.GameOptions.GameModes.HideNSeek);
|
||||
if (localPlayer.Data == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using HarmonyLib;
|
||||
using MiraAPI.Events;
|
||||
using MiraAPI.Events.Vanilla.Gameplay;
|
||||
using MiraAPI.Roles;
|
||||
using MiraAPI.Utilities;
|
||||
using UnityEngine;
|
||||
@@ -20,6 +22,32 @@ public static class IntroCutscenePatches
|
||||
}
|
||||
}*/
|
||||
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(nameof(IntroCutscene.CoBegin))]
|
||||
public static void IntroBeginPatch(IntroCutscene __instance)
|
||||
{
|
||||
var @event = new IntroBeginEvent(__instance);
|
||||
MiraEventManager.InvokeEvent(@event);
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(nameof(IntroCutscene.BeginImpostor))]
|
||||
public static void BeginImpostorPatch(IntroCutscene __instance)
|
||||
{
|
||||
if (PlayerControl.LocalPlayer.Data.Role is not ICustomRole customRole)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (customRole.IntroConfiguration is { } introConfig)
|
||||
{
|
||||
__instance.BackgroundBar.material.SetColor(ShaderID.Color, introConfig.IntroTeamColor);
|
||||
__instance.TeamTitle.color = introConfig.IntroTeamColor;
|
||||
__instance.TeamTitle.text = introConfig.IntroTeamTitle;
|
||||
__instance.ImpostorText.text = introConfig.IntroTeamDescription;
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(nameof(IntroCutscene.BeginCrewmate))]
|
||||
public static bool BeginCrewmatePatch(IntroCutscene __instance)
|
||||
@@ -29,7 +57,15 @@ public static class IntroCutscenePatches
|
||||
return true;
|
||||
}
|
||||
|
||||
if (customRole.Team is not ModdedRoleTeams.Neutral)
|
||||
if (customRole.IntroConfiguration is { } introConfig)
|
||||
{
|
||||
__instance.BackgroundBar.material.SetColor(ShaderID.Color, introConfig.IntroTeamColor);
|
||||
__instance.TeamTitle.color = introConfig.IntroTeamColor;
|
||||
__instance.TeamTitle.text = introConfig.IntroTeamTitle;
|
||||
__instance.ImpostorText.text = introConfig.IntroTeamDescription;
|
||||
}
|
||||
|
||||
if (customRole.Team is not ModdedRoleTeams.Custom)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -39,11 +75,7 @@ public static class IntroCutscenePatches
|
||||
position.y -= 0.25f;
|
||||
barTransform.position = position;
|
||||
|
||||
__instance.BackgroundBar.material.SetColor(ShaderID.Color, Color.gray);
|
||||
__instance.TeamTitle.text = "NEUTRAL";
|
||||
__instance.impostorScale = 1f;
|
||||
__instance.ImpostorText.text = "You are Neutral. You do not have a team.";
|
||||
__instance.TeamTitle.color = Color.gray;
|
||||
|
||||
__instance.ourCrewmate = __instance.CreatePlayer(
|
||||
0,
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
using System.Linq;
|
||||
using HarmonyLib;
|
||||
using MiraAPI.Modifiers.Types;
|
||||
using MiraAPI.Utilities;
|
||||
|
||||
namespace MiraAPI.Patches.Modifiers;
|
||||
|
||||
[HarmonyPatch(typeof(AmongUsClient), nameof(AmongUsClient.CoEndGame))]
|
||||
public static class EndGameDidWinPatch
|
||||
{
|
||||
public static void Prefix()
|
||||
{
|
||||
var gameOverReason = EndGameResult.CachedGameOverReason;
|
||||
EndGameResult.CachedWinners.Clear();
|
||||
|
||||
var players = GameData.Instance.AllPlayers.ToArray();
|
||||
for (var i = 0; i < GameData.Instance.PlayerCount; i++)
|
||||
{
|
||||
var networkedPlayerInfo = players[i];
|
||||
if (networkedPlayerInfo == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var didWin = networkedPlayerInfo.Role.DidWin(gameOverReason);
|
||||
|
||||
var modifierWin = networkedPlayerInfo.Object?.GetModifierComponent()?.ActiveModifiers.OfType<GameModifier>()
|
||||
.FirstOrDefault(x => x.DidWin(gameOverReason) != null)?.DidWin(gameOverReason);
|
||||
if (modifierWin != null)
|
||||
{
|
||||
didWin = modifierWin.Value;
|
||||
}
|
||||
|
||||
if (didWin)
|
||||
{
|
||||
EndGameResult.CachedWinners.Add(new CachedPlayerData(networkedPlayerInfo));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
using HarmonyLib;
|
||||
using MiraAPI.Utilities;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.Patches.Modifiers;
|
||||
|
||||
[HarmonyPatch(typeof(Vent))]
|
||||
public static class VentPatches
|
||||
{
|
||||
[HarmonyPostfix]
|
||||
[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)
|
||||
{
|
||||
var @object = pc.Object;
|
||||
var role = @object.Data.Role;
|
||||
|
||||
var modifiers = @object.GetModifierComponent()?.ActiveModifiers;
|
||||
if (modifiers is null || modifiers.Count <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
switch (role.CanVent)
|
||||
{
|
||||
case true when modifiers.Exists(x => !x.CanVent()):
|
||||
couldUse = canUse = false;
|
||||
return;
|
||||
case false when modifiers.Exists(x => x.CanVent()):
|
||||
couldUse = true;
|
||||
break;
|
||||
}
|
||||
|
||||
var num = float.MaxValue;
|
||||
|
||||
canUse = couldUse;
|
||||
if (canUse)
|
||||
{
|
||||
var center = @object.Collider.bounds.center;
|
||||
var position = __instance.transform.position;
|
||||
num = Vector2.Distance(center, position);
|
||||
canUse &= num <= __instance.UsableDistance && !PhysicsHelpers.AnythingBetween(@object.Collider, center, position, Constants.ShipOnlyMask, false);
|
||||
}
|
||||
__result = num;
|
||||
}
|
||||
}
|
||||
@@ -32,16 +32,25 @@ public static class GameOptionsMenuPatch
|
||||
var num = 2.1f;
|
||||
var filteredGroups =
|
||||
GameSettingMenuPatches.SelectedMod?.OptionGroups.Where(
|
||||
x => x.GroupVisible.Invoke() && x.AdvancedRole is null) ?? [];
|
||||
x => x.AdvancedRole is null) ?? [];
|
||||
|
||||
foreach (var group in filteredGroups)
|
||||
{
|
||||
var filteredOpts = group.Options.Where(x => x.Visible.Invoke()).ToList();
|
||||
if (filteredOpts.Count == 0 || group.Header is null)
|
||||
if (group.Options.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);
|
||||
|
||||
@@ -157,8 +157,6 @@ public static class GameSettingMenuPatches
|
||||
roles.AdvancedRolesSettings.gameObject.SetActive(false);
|
||||
roles.RoleChancesSettings.gameObject.SetActive(true);
|
||||
roles.SetQuotaTab();
|
||||
|
||||
roles.scrollBar.CalculateAndSetYBounds(roles.roleChances.Count + 5, 1f, 6f, 0.43f);
|
||||
roles.scrollBar.ScrollToTop();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using HarmonyLib;
|
||||
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 Reactor.Localization.Utilities;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.UI;
|
||||
@@ -128,11 +129,6 @@ public static class LobbyViewPanePatches
|
||||
|
||||
foreach (var group in filteredGroups)
|
||||
{
|
||||
if (group.Options.Count == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var categoryHeaderMasked = Object.Instantiate(
|
||||
instance.categoryHeaderOrigin,
|
||||
instance.settingsContainer,
|
||||
@@ -176,11 +172,6 @@ public static class LobbyViewPanePatches
|
||||
|
||||
var data = option.Data;
|
||||
|
||||
if (data == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (data.Type == OptionTypes.Checkbox)
|
||||
{
|
||||
viewSettingsInfoPanel.SetInfoCheckbox(
|
||||
@@ -221,34 +212,43 @@ public static class LobbyViewPanePatches
|
||||
|
||||
var list = new List<Type>();
|
||||
|
||||
foreach (var team in Enum.GetValues<ModdedRoleTeams>())
|
||||
{
|
||||
var filteredRoles = SelectedMod.CustomRoles.Values
|
||||
.OfType<ICustomRole>()
|
||||
.Where(x => !x.HideSettings && x.Team == team).ToList();
|
||||
var roleGroups = GameSettingMenuPatches.SelectedMod?.CustomRoles.Values.OfType<ICustomRole>()
|
||||
.ToLookup(x => x.RoleOptionsGroup);
|
||||
|
||||
if (filteredRoles.Count == 0)
|
||||
if (roleGroups is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// sort the groups by priority
|
||||
var sortedRoleGroups = roleGroups
|
||||
.OrderBy(x => x.Key.Priority)
|
||||
.ThenBy(x => x.Key.Name);
|
||||
|
||||
foreach (var grouping in sortedRoleGroups)
|
||||
{
|
||||
if (!grouping.Any())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var categoryHeaderRoleVariant =
|
||||
Object.Instantiate(instance.categoryHeaderRoleOrigin, instance.settingsContainer, true);
|
||||
var group = grouping.Key;
|
||||
|
||||
switch (team)
|
||||
var name = group.Name switch
|
||||
{
|
||||
case ModdedRoleTeams.Crewmate:
|
||||
categoryHeaderRoleVariant.SetHeader(StringNames.CrewmateRolesHeader, 61);
|
||||
break;
|
||||
case ModdedRoleTeams.Impostor:
|
||||
categoryHeaderRoleVariant.SetHeader(StringNames.ImpostorRolesHeader, 61);
|
||||
break;
|
||||
default:
|
||||
categoryHeaderRoleVariant.SetHeader(StringNames.CrewmateRolesHeader, 61);
|
||||
categoryHeaderRoleVariant.Title.text = team + " Roles";
|
||||
categoryHeaderRoleVariant.Background.color = Color.gray;
|
||||
categoryHeaderRoleVariant.Title.color = Color.white;
|
||||
break;
|
||||
"Crewmate" => StringNames.CrewmateRolesHeader,
|
||||
"Impostor" => StringNames.ImpostorRolesHeader,
|
||||
_ => CustomStringName.CreateAndRegister(group.Name),
|
||||
};
|
||||
|
||||
var categoryHeaderRoleVariant = Object.Instantiate(instance.categoryHeaderRoleOrigin, instance.settingsContainer, true);
|
||||
categoryHeaderRoleVariant.SetHeader(name, 61);
|
||||
|
||||
if (name is not (StringNames.CrewmateRolesHeader or StringNames.ImpostorRolesHeader))
|
||||
{
|
||||
var veryDarkColor = group.Color.DarkenColor(.35f);
|
||||
categoryHeaderRoleVariant.Title.color = veryDarkColor;
|
||||
categoryHeaderRoleVariant.Background.color = group.Color;
|
||||
}
|
||||
|
||||
categoryHeaderRoleVariant.transform.localScale = Vector3.one;
|
||||
@@ -256,7 +256,7 @@ public static class LobbyViewPanePatches
|
||||
instance.settingsInfo.Add(categoryHeaderRoleVariant.gameObject);
|
||||
num -= 0.696f;
|
||||
|
||||
foreach (var customRole in filteredRoles)
|
||||
foreach (var customRole in grouping)
|
||||
{
|
||||
var roleBehaviour = customRole as RoleBehaviour;
|
||||
if (roleBehaviour == null)
|
||||
@@ -269,8 +269,6 @@ public static class LobbyViewPanePatches
|
||||
var numPerGame =
|
||||
GameOptionsManager.Instance.CurrentGameOptions.RoleOptions.GetNumPerGame(roleBehaviour.Role);
|
||||
|
||||
var flag = numPerGame == 0;
|
||||
|
||||
var viewSettingsInfoPanelRoleVariant =
|
||||
Object.Instantiate(
|
||||
instance.infoPanelRoleOrigin,
|
||||
@@ -283,7 +281,7 @@ public static class LobbyViewPanePatches
|
||||
.Where(x => x.AdvancedRole == customRole.GetType())
|
||||
.ToList();
|
||||
|
||||
if (!flag && advancedRoleOptions.Count > 0)
|
||||
if (numPerGame > 0 && advancedRoleOptions.Count > 0)
|
||||
{
|
||||
list.Add(customRole.GetType());
|
||||
}
|
||||
@@ -294,8 +292,10 @@ public static class LobbyViewPanePatches
|
||||
chancePerGame,
|
||||
61,
|
||||
customRole.RoleColor,
|
||||
customRole.Icon.LoadAsset(),
|
||||
customRole.Configuration.Icon.LoadAsset(),
|
||||
true);
|
||||
viewSettingsInfoPanelRoleVariant.iconSprite.transform.localScale = new Vector3(0.365f, 0.365f, 1f);
|
||||
viewSettingsInfoPanelRoleVariant.iconSprite.transform.localPosition = new Vector3(0.7144f, -0.028f, -2);
|
||||
|
||||
viewSettingsInfoPanelRoleVariant.titleText.color =
|
||||
viewSettingsInfoPanelRoleVariant.chanceTitle.color =
|
||||
@@ -379,7 +379,8 @@ public static class LobbyViewPanePatches
|
||||
role.StringName,
|
||||
maskLayer,
|
||||
role.TeamType == RoleTeamTypes.Crewmate,
|
||||
customRole.Icon.LoadAsset());
|
||||
customRole.Configuration.Icon.LoadAsset());
|
||||
viewPanel.header.icon.transform.localScale = new Vector3(0.465f, 0.465f, 1f);
|
||||
viewPanel.divider.material.SetInt(PlayerMaterial.MaskLayer, maskLayer);
|
||||
|
||||
var num = viewPanel.yPosStart;
|
||||
@@ -399,11 +400,6 @@ public static class LobbyViewPanePatches
|
||||
|
||||
var value = option.GetFloatData();
|
||||
|
||||
if (baseGameSetting == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (baseGameSetting.Type == OptionTypes.Checkbox)
|
||||
{
|
||||
viewSettingsInfoPanel.SetInfoCheckbox(baseGameSetting.Title, maskLayer, value > 0f);
|
||||
|
||||
@@ -27,12 +27,12 @@ public static class NotificationPopperPatch
|
||||
? Palette.CrewmateSettingChangeText.ToTextColor()
|
||||
: Palette.ImpostorRed.ToTextColor();
|
||||
|
||||
var item = DestroyableSingleton<TranslationController>.Instance.GetString(
|
||||
var item = TranslationController.Instance.GetString(
|
||||
StringNames.LobbyChangeSettingNotificationRole,
|
||||
string.Concat(
|
||||
"<font=\"Barlow-Black SDF\" material=\"Barlow-Black Outline\">",
|
||||
text,
|
||||
DestroyableSingleton<TranslationController>.Instance.GetString(key, Array.Empty<Object>()),
|
||||
TranslationController.Instance.GetString(key, Array.Empty<Object>()),
|
||||
"</color></font>"
|
||||
),
|
||||
"<font=\"Barlow-Black SDF\" material=\"Barlow-Black Outline\">" + roleCount + "</font>",
|
||||
|
||||
@@ -17,7 +17,7 @@ public static class OptionsPatches
|
||||
}
|
||||
|
||||
__instance.TitleText.text =
|
||||
DestroyableSingleton<TranslationController>.Instance.GetString(__instance.Title, Array.Empty<Object>());
|
||||
TranslationController.Instance.GetString(__instance.Title, Array.Empty<Object>());
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -39,7 +39,7 @@ public static class OptionsPatches
|
||||
}
|
||||
|
||||
__instance.TitleText.text =
|
||||
DestroyableSingleton<TranslationController>.Instance.GetString(__instance.Title, Array.Empty<Object>());
|
||||
TranslationController.Instance.GetString(__instance.Title, Array.Empty<Object>());
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -61,8 +61,8 @@ public static class OptionsPatches
|
||||
}
|
||||
|
||||
__instance.TitleText.text =
|
||||
DestroyableSingleton<TranslationController>.Instance.GetString(__instance.Title, Array.Empty<Object>());
|
||||
__instance.ValueText.text = DestroyableSingleton<TranslationController>.Instance.GetString(
|
||||
TranslationController.Instance.GetString(__instance.Title, Array.Empty<Object>());
|
||||
__instance.ValueText.text = TranslationController.Instance.GetString(
|
||||
__instance.Values[__instance.Value],
|
||||
Array.Empty<Object>());
|
||||
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
using HarmonyLib;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using HarmonyLib;
|
||||
using Il2CppInterop.Runtime.InteropTypes.Arrays;
|
||||
using MiraAPI.Networking;
|
||||
using MiraAPI.Roles;
|
||||
using MiraAPI.Utilities;
|
||||
using MiraAPI.Utilities.Assets;
|
||||
using Reactor.Localization.Utilities;
|
||||
using Reactor.Networking.Rpc;
|
||||
using Reactor.Utilities;
|
||||
using Reactor.Utilities.Extensions;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
@@ -20,10 +22,20 @@ namespace MiraAPI.Patches.Options;
|
||||
[HarmonyPatch(typeof(RolesSettingsMenu))]
|
||||
public static class RoleSettingMenuPatches
|
||||
{
|
||||
private static Dictionary<RoleOptionsGroup, bool> RoleGroupHidden { get; } = [];
|
||||
private static List<CategoryHeaderEditRole> CategoryHeaderEditRoles { get; } = [];
|
||||
private static List<RoleOptionSetting> RoleOptionSettings { get; } = [];
|
||||
|
||||
private static float ScrollerNum { get; set; } = 0.522f;
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(nameof(RolesSettingsMenu.SetQuotaTab))]
|
||||
public static bool PatchStart(RolesSettingsMenu __instance)
|
||||
{
|
||||
CategoryHeaderEditRoles.ForEach(Object.Destroy);
|
||||
CategoryHeaderEditRoles.Clear();
|
||||
RoleOptionSettings.ForEach(Object.Destroy);
|
||||
RoleOptionSettings.Clear();
|
||||
__instance.roleChances = new Il2CppSystem.Collections.Generic.List<RoleOptionSetting>();
|
||||
__instance.advancedSettingChildren = new Il2CppSystem.Collections.Generic.List<OptionBehaviour>();
|
||||
|
||||
@@ -42,7 +54,7 @@ public static class RoleSettingMenuPatches
|
||||
return true;
|
||||
}
|
||||
|
||||
var num = 0.522f;
|
||||
ScrollerNum = 0.522f;
|
||||
|
||||
__instance.AllButton.transform.parent.gameObject.SetActive(false);
|
||||
__instance.AllButton.gameObject.SetActive(false);
|
||||
@@ -54,92 +66,131 @@ public static class RoleSettingMenuPatches
|
||||
|
||||
var num3 = 0;
|
||||
|
||||
var crewRoles = GameSettingMenuPatches.SelectedMod?.CustomRoles.Values
|
||||
.OfType<ICustomRole>()
|
||||
.Where(role => role is { Team: ModdedRoleTeams.Crewmate, HideSettings: false })
|
||||
.ToList() ?? [];
|
||||
var roleGroups = GameSettingMenuPatches.SelectedMod?.CustomRoles.Values.OfType<ICustomRole>()
|
||||
.ToLookup(x => x.RoleOptionsGroup);
|
||||
|
||||
if (crewRoles is { Count: > 0 })
|
||||
if (roleGroups is null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// sort the groups by priority
|
||||
var sortedRoleGroups = roleGroups
|
||||
.OrderBy(x => x.Key.Priority)
|
||||
.ThenBy(x => x.Key.Name);
|
||||
|
||||
foreach (var grouping in sortedRoleGroups)
|
||||
{
|
||||
if (!grouping.Any())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var group = grouping.Key;
|
||||
|
||||
RoleGroupHidden.TryAdd(group, false);
|
||||
|
||||
var name = group.Name switch
|
||||
{
|
||||
"Crewmate" => StringNames.CrewmateRolesHeader,
|
||||
"Impostor" => StringNames.ImpostorRolesHeader,
|
||||
_ => CustomStringName.CreateAndRegister(group.Name),
|
||||
};
|
||||
|
||||
var categoryHeaderEditRole = Object.Instantiate(
|
||||
__instance.categoryHeaderEditRoleOrigin,
|
||||
Vector3.zero,
|
||||
Quaternion.identity,
|
||||
__instance.RoleChancesSettings.transform);
|
||||
categoryHeaderEditRole.SetHeader(StringNames.CrewmateRolesHeader, 20);
|
||||
categoryHeaderEditRole.transform.localPosition = new Vector3(4.986f, num, -2f);
|
||||
num -= 0.522f;
|
||||
|
||||
foreach (var role in crewRoles)
|
||||
categoryHeaderEditRole.SetHeader(name, 20);
|
||||
if (name is not (StringNames.CrewmateRolesHeader or StringNames.ImpostorRolesHeader))
|
||||
{
|
||||
if (role is RoleBehaviour roleBehaviour)
|
||||
var darkColor = group.Color.DarkenColor(.25f);
|
||||
var veryDarkColor = group.Color.DarkenColor(.35f);
|
||||
categoryHeaderEditRole.Title.color = veryDarkColor;
|
||||
categoryHeaderEditRole.blankLabel.color = veryDarkColor;
|
||||
categoryHeaderEditRole.Background.color = group.Color;
|
||||
categoryHeaderEditRole.chanceLabel.color = darkColor;
|
||||
categoryHeaderEditRole.countLabel.color = darkColor;
|
||||
}
|
||||
|
||||
categoryHeaderEditRole.transform.localPosition = new Vector3(4.986f, ScrollerNum, -2f);
|
||||
categoryHeaderEditRole.transform.Find("LabelSprite").transform.localScale = new Vector3(1.3f, 1, 0.5529f);
|
||||
categoryHeaderEditRole.transform.Find("QuotaHeader").gameObject.SetActive(!RoleGroupHidden[group]);
|
||||
|
||||
CategoryHeaderEditRoles.Add(categoryHeaderEditRole);
|
||||
|
||||
ScrollerNum -= 0.522f;
|
||||
|
||||
var label = RoleGroupHidden[group]
|
||||
? "(Click to open)"
|
||||
: "(Click to close)";
|
||||
var newText = Object.Instantiate(categoryHeaderEditRole.Title, categoryHeaderEditRole.transform);
|
||||
newText.text = $"<size=50%>{label}</size>";
|
||||
newText.transform.localPosition = new Vector3(-3.3425f, -0.1706f, -1);
|
||||
newText.gameObject.GetComponent<TextTranslatorTMP>().Destroy();
|
||||
|
||||
if (!RoleGroupHidden[group])
|
||||
{
|
||||
foreach (var role in grouping)
|
||||
{
|
||||
CreateQuotaOption(__instance, roleBehaviour, ref num, num3);
|
||||
if (role is not RoleBehaviour roleBehaviour)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var option = CreateQuotaOption(__instance, roleBehaviour, num3);
|
||||
if (option is not null)
|
||||
{
|
||||
RoleOptionSettings.Add(option);
|
||||
num3++;
|
||||
}
|
||||
}
|
||||
num3++;
|
||||
}
|
||||
|
||||
var boxCol = categoryHeaderEditRole.gameObject.AddComponent<BoxCollider2D>();
|
||||
boxCol.size = new Vector2(3, 0.25f);
|
||||
boxCol.offset = new Vector2(-2.05f, -.175f);
|
||||
|
||||
var headerBtn = categoryHeaderEditRole.gameObject.AddComponent<PassiveButton>();
|
||||
headerBtn.ClickSound = __instance.BackButton.GetComponent<PassiveButton>().ClickSound;
|
||||
headerBtn.OnMouseOver = new UnityEvent();
|
||||
headerBtn.OnMouseOut = new UnityEvent();
|
||||
headerBtn.OnClick.AddListener(
|
||||
(UnityAction)(() =>
|
||||
{
|
||||
if (RoleGroupHidden.TryGetValue(group, out var value))
|
||||
{
|
||||
RoleGroupHidden[group] = !value;
|
||||
}
|
||||
foreach (var header in CategoryHeaderEditRoles)
|
||||
{
|
||||
header.gameObject.Destroy();
|
||||
}
|
||||
CategoryHeaderEditRoles.Clear();
|
||||
foreach (var option in RoleOptionSettings)
|
||||
{
|
||||
option.gameObject.Destroy();
|
||||
}
|
||||
RoleOptionSettings.Clear();
|
||||
__instance.SetQuotaTab();
|
||||
}));
|
||||
headerBtn.SetButtonEnableState(true);
|
||||
|
||||
if (!RoleGroupHidden[group])
|
||||
{
|
||||
ScrollerNum -= 0.4f;
|
||||
}
|
||||
}
|
||||
|
||||
var impRoles = GameSettingMenuPatches.SelectedMod?.CustomRoles.Values
|
||||
.OfType<ICustomRole>()
|
||||
.Where(role => role is { Team: ModdedRoleTeams.Impostor, HideSettings: false })
|
||||
.ToList() ?? [];
|
||||
|
||||
if (impRoles is { Count: > 0 })
|
||||
{
|
||||
num -= 0.4f;
|
||||
var categoryHeaderEditRole2 = Object.Instantiate(
|
||||
__instance.categoryHeaderEditRoleOrigin,
|
||||
Vector3.zero,
|
||||
Quaternion.identity,
|
||||
__instance.RoleChancesSettings.transform);
|
||||
categoryHeaderEditRole2.SetHeader(StringNames.ImpostorRolesHeader, 20);
|
||||
categoryHeaderEditRole2.transform.localPosition = new Vector3(4.986f, num, -2f);
|
||||
num -= 0.522f;
|
||||
|
||||
foreach (var role in impRoles)
|
||||
{
|
||||
if (role is RoleBehaviour roleBehaviour)
|
||||
{
|
||||
CreateQuotaOption(__instance, roleBehaviour, ref num, num3);
|
||||
}
|
||||
num3++;
|
||||
}
|
||||
}
|
||||
|
||||
var neutRoles = GameSettingMenuPatches.SelectedMod?.CustomRoles.Values
|
||||
.OfType<ICustomRole>()
|
||||
.Where(role => role is { Team: ModdedRoleTeams.Neutral, HideSettings: false })
|
||||
.ToList() ?? [];
|
||||
|
||||
if (neutRoles is { Count: > 0 })
|
||||
{
|
||||
num -= 0.4f;
|
||||
var categoryHeaderEditRole3 = Object.Instantiate(
|
||||
__instance.categoryHeaderEditRoleOrigin,
|
||||
Vector3.zero,
|
||||
Quaternion.identity,
|
||||
__instance.RoleChancesSettings.transform);
|
||||
categoryHeaderEditRole3.SetHeader(StringNames.None, 20);
|
||||
categoryHeaderEditRole3.Title.text = "Neutral Roles";
|
||||
categoryHeaderEditRole3.Background.color = Color.gray;
|
||||
categoryHeaderEditRole3.Title.color = Color.white;
|
||||
categoryHeaderEditRole3.transform.localPosition = new Vector3(4.986f, num, -2f);
|
||||
num -= 0.522f;
|
||||
|
||||
foreach (var role in neutRoles)
|
||||
{
|
||||
if (role is RoleBehaviour roleBehaviour)
|
||||
{
|
||||
CreateQuotaOption(__instance, roleBehaviour, ref num, num3);
|
||||
}
|
||||
num3++;
|
||||
}
|
||||
}
|
||||
|
||||
__instance.scrollBar.SetScrollBounds();
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void SetScrollBounds(this Scroller scroller)
|
||||
{
|
||||
scroller.CalculateAndSetYBounds(1 + 1.5f * CategoryHeaderEditRoles.Count + RoleOptionSettings.Count, 1f, 6f, 0.43f);
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(nameof(RolesSettingsMenu.Update))]
|
||||
public static bool UpdatePatch()
|
||||
@@ -151,7 +202,12 @@ public static class RoleSettingMenuPatches
|
||||
[HarmonyPatch(nameof(RolesSettingsMenu.OpenChancesTab))]
|
||||
public static void OpenChancesTabPostfix(RolesSettingsMenu __instance)
|
||||
{
|
||||
__instance.scrollBar.CalculateAndSetYBounds(__instance.roleChances.Count + 5, 1f, 6f, 0.43f);
|
||||
if (GameSettingMenuPatches.SelectedModIdx == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
__instance.scrollBar.SetScrollBounds();
|
||||
__instance.scrollBar.ScrollToTop();
|
||||
}
|
||||
|
||||
@@ -159,18 +215,22 @@ public static class RoleSettingMenuPatches
|
||||
{
|
||||
var roleSetting = obj.Cast<RoleOptionSetting>();
|
||||
var role = roleSetting.Role as ICustomRole;
|
||||
if (role is null or { HideSettings: true })
|
||||
if (role is null or { Configuration.HideSettings: true })
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
role.ParentMod.PluginConfig.TryGetEntry<int>(role.NumConfigDefinition, out var numEntry);
|
||||
numEntry.Value = roleSetting.RoleMaxCount;
|
||||
if (role.Configuration.MaxRoleCount != 0)
|
||||
{
|
||||
role.SetCount(roleSetting.RoleMaxCount);
|
||||
}
|
||||
|
||||
role.ParentMod.PluginConfig.TryGetEntry<int>(role.ChanceConfigDefinition, out var chanceEntry);
|
||||
chanceEntry.Value = roleSetting.RoleChance;
|
||||
if (role.Configuration.CanModifyChance)
|
||||
{
|
||||
role.SetChance(roleSetting.RoleChance);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -178,7 +238,7 @@ public static class RoleSettingMenuPatches
|
||||
}
|
||||
|
||||
roleSetting.UpdateValuesAndText(GameOptionsManager.Instance.CurrentGameOptions.RoleOptions);
|
||||
DestroyableSingleton<HudManager>.Instance.Notifier.AddRoleSettingsChangeMessage(
|
||||
HudManager.Instance.Notifier.AddRoleSettingsChangeMessage(
|
||||
roleSetting.Role.StringName,
|
||||
roleSetting.RoleMaxCount,
|
||||
roleSetting.RoleChance,
|
||||
@@ -228,7 +288,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);
|
||||
@@ -254,11 +314,11 @@ public static class RoleSettingMenuPatches
|
||||
}
|
||||
|
||||
__instance.roleDescriptionText.text = customRole.RoleLongDescription;
|
||||
__instance.roleTitleText.text = DestroyableSingleton<TranslationController>.Instance.GetString(
|
||||
__instance.roleTitleText.text = TranslationController.Instance.GetString(
|
||||
role.StringName,
|
||||
new Il2CppReferenceArray<Il2CppSystem.Object>(0));
|
||||
__instance.roleScreenshot.sprite = Sprite.Create(
|
||||
customRole.OptionsScreenshot.LoadAsset().texture,
|
||||
customRole.Configuration.OptionsScreenshot.LoadAsset().texture,
|
||||
new Rect(0, 0, 370, 230),
|
||||
Vector2.one / 2,
|
||||
100);
|
||||
@@ -291,12 +351,17 @@ public static class RoleSettingMenuPatches
|
||||
__instance.RefreshChildren();
|
||||
}
|
||||
|
||||
private static void CreateQuotaOption(RolesSettingsMenu __instance, RoleBehaviour role, ref float yPos, int index)
|
||||
private static RoleOptionSetting? CreateQuotaOption(RolesSettingsMenu __instance, RoleBehaviour role, int index)
|
||||
{
|
||||
if (role is not ICustomRole customRole)
|
||||
{
|
||||
Logger<MiraApiPlugin>.Error($"Role {role.NiceName} is not a custom role.");
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
if (customRole.Configuration.HideSettings)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var roleOptionSetting = Object.Instantiate(
|
||||
@@ -304,7 +369,8 @@ public static class RoleSettingMenuPatches
|
||||
Vector3.zero,
|
||||
Quaternion.identity,
|
||||
__instance.RoleChancesSettings.transform);
|
||||
roleOptionSetting.transform.localPosition = new Vector3(-0.15f, yPos, -2f);
|
||||
roleOptionSetting.transform.localPosition = new Vector3(-0.15f, ScrollerNum, -2f);
|
||||
|
||||
roleOptionSetting.SetRole(GameOptionsManager.Instance.CurrentGameOptions.RoleOptions, role, 20);
|
||||
roleOptionSetting.labelSprite.color = customRole.RoleColor;
|
||||
roleOptionSetting.OnValueChanged = new Action<OptionBehaviour>(ValueChanged);
|
||||
@@ -336,9 +402,23 @@ public static class RoleSettingMenuPatches
|
||||
passiveButton.OnClick.AddListener((UnityAction)(() => { ChangeTab(role, __instance); }));
|
||||
}
|
||||
|
||||
if (customRole.Configuration is { MaxRoleCount: 0 })
|
||||
{
|
||||
roleOptionSetting.CountMinusBtn.gameObject.SetActive(false);
|
||||
roleOptionSetting.CountPlusBtn.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
if (!customRole.Configuration.CanModifyChance)
|
||||
{
|
||||
roleOptionSetting.ChanceMinusBtn.gameObject.SetActive(false);
|
||||
roleOptionSetting.ChancePlusBtn.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
if (index < GameSettingMenuPatches.SelectedMod?.CustomRoles.Count - 1)
|
||||
{
|
||||
yPos += -0.43f;
|
||||
ScrollerNum += -0.43f;
|
||||
}
|
||||
|
||||
return roleOptionSetting;
|
||||
}
|
||||
}
|
||||
@@ -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) + "%",
|
||||
_ => DestroyableSingleton<TranslationController>.Instance.GetString(
|
||||
_ => TranslationController.Instance.GetString(
|
||||
StringNames.GameSecondsAbbrev,
|
||||
(Il2CppSystem.Object[]) [value.ToString(__instance.FormatString, CultureInfo.InvariantCulture)]),
|
||||
(Il2CppSystem.Object[])[value.ToString(__instance.FormatString, CultureInfo.InvariantCulture)]),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
using HarmonyLib;
|
||||
using MiraAPI.Events;
|
||||
using MiraAPI.Events.Vanilla.Gameplay;
|
||||
using MiraAPI.Events.Vanilla.Player;
|
||||
using MiraAPI.Hud;
|
||||
using MiraAPI.Modifiers;
|
||||
using MiraAPI.Roles;
|
||||
using Reactor.Utilities.Extensions;
|
||||
using System.Linq;
|
||||
|
||||
namespace MiraAPI.Patches;
|
||||
|
||||
@@ -15,7 +19,8 @@ public static class PlayerControlPatches
|
||||
/// <summary>
|
||||
/// Adds the modifier component to the player on start.
|
||||
/// </summary>
|
||||
[HarmonyPrefix]
|
||||
/// <param name="__instance">PlayerControl instance.</param>
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(nameof(PlayerControl.Start))]
|
||||
public static void PlayerControlStartPostfix(PlayerControl __instance)
|
||||
{
|
||||
@@ -30,21 +35,59 @@ public static class PlayerControlPatches
|
||||
/// <summary>
|
||||
/// Calls the OnDeath method for all active modifiers.
|
||||
/// </summary>
|
||||
/// <param name="__instance">PlayerControl instance.</param>
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(nameof(PlayerControl.Die))]
|
||||
public static void PlayerControlDiePostfix(PlayerControl __instance, DeathReason reason)
|
||||
{
|
||||
var deathEvent = new PlayerDeathEvent(__instance, reason);
|
||||
MiraEventManager.InvokeEvent(deathEvent);
|
||||
|
||||
var modifiersComponent = __instance.GetComponent<ModifierComponent>();
|
||||
|
||||
if (modifiersComponent)
|
||||
{
|
||||
modifiersComponent.ActiveModifiers.ForEach(x=>x.OnDeath(reason));
|
||||
modifiersComponent.ActiveModifiers.ForEach(x => x.OnDeath(reason));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Used to trigger the <see cref="CompleteTaskEvent"/>.
|
||||
/// </summary>
|
||||
/// <param name="__instance">PlayerControl instance.</param>
|
||||
/// <param name="idx">The task id.</param>
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(nameof(PlayerControl.CompleteTask))]
|
||||
public static void PlayerCompleteTaskPostfix(PlayerControl __instance, uint idx)
|
||||
{
|
||||
var playerTask = __instance.myTasks.ToArray().First(playerTask => playerTask.Id == idx);
|
||||
if (playerTask != null)
|
||||
{
|
||||
var completeTaskEvent = new CompleteTaskEvent(__instance, playerTask);
|
||||
MiraEventManager.InvokeEvent(completeTaskEvent);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Used to trigger the <see cref="BeforeMurderEvent"/>.
|
||||
/// </summary>
|
||||
/// <param name="__instance">The source player.</param>
|
||||
/// <param name="target">The target.</param>
|
||||
/// <param name="didSucceed">Whether the kill succeeded.</param>
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(nameof(PlayerControl.RpcMurderPlayer))]
|
||||
public static void PlayerControlMurderPrefix(PlayerControl __instance, PlayerControl target, ref bool didSucceed)
|
||||
{
|
||||
var beforeMurderEvent = new BeforeMurderEvent(__instance, target);
|
||||
MiraEventManager.InvokeEvent(beforeMurderEvent);
|
||||
|
||||
didSucceed = beforeMurderEvent.IsCancelled;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// FixedUpdate handler for custom roles and custom buttons.
|
||||
/// </summary>
|
||||
/// <param name="__instance">PlayerControl instance.</param>
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(nameof(PlayerControl.FixedUpdate))]
|
||||
public static void PlayerControlFixedUpdatePostfix(PlayerControl __instance)
|
||||
@@ -74,4 +117,15 @@ 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);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
using HarmonyLib;
|
||||
using MiraAPI.Events;
|
||||
using MiraAPI.Events.Vanilla.Meeting;
|
||||
using MiraAPI.Roles;
|
||||
|
||||
namespace MiraAPI.Patches.Roles;
|
||||
@@ -13,6 +15,9 @@ public static class EjectionPatches
|
||||
[HarmonyPatch(nameof(ExileController.Begin))]
|
||||
public static void BeginPostfix(ExileController __instance)
|
||||
{
|
||||
var @event = new EjectionEvent(__instance);
|
||||
MiraEventManager.InvokeEvent(@event);
|
||||
|
||||
if (!__instance.initData.networkedPlayer || !__instance.initData.networkedPlayer.Role ||
|
||||
__instance.initData.networkedPlayer.Role is not ICustomRole role)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
using HarmonyLib;
|
||||
using MiraAPI.Roles;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.Patches.Roles;
|
||||
|
||||
/// <summary>
|
||||
/// Patches the haunt menu to show the actual role name rather then team.
|
||||
/// </summary>
|
||||
[HarmonyPatch(typeof(HauntMenuMinigame), nameof(HauntMenuMinigame.SetFilterText))]
|
||||
public static class HauntMenuMinigamePatch
|
||||
{
|
||||
public static void Postfix(HauntMenuMinigame __instance)
|
||||
{
|
||||
if (__instance.HauntTarget.Data.IsDead)
|
||||
{
|
||||
__instance.FilterText.color = Color.white;
|
||||
return;
|
||||
}
|
||||
|
||||
var role = __instance.HauntTarget.Data.Role;
|
||||
var color = role is ICustomRole custom ? custom.RoleColor : role.TeamColor;
|
||||
|
||||
__instance.FilterText.text = role.NiceName;
|
||||
__instance.FilterText.color = color;
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,10 @@ 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(
|
||||
@@ -29,9 +33,9 @@ public static class HudManagerPatches
|
||||
|
||||
if (role is ICustomRole customRole)
|
||||
{
|
||||
__instance.KillButton.ToggleVisible(isActive && role.CanUseKillButton && !flag);
|
||||
__instance.ImpostorVentButton.ToggleVisible(isActive && role.CanVent && !flag);
|
||||
__instance.SabotageButton.gameObject.SetActive(isActive && customRole.CanUseSabotage);
|
||||
__instance.KillButton.ToggleVisible(isActive && customRole.Configuration.UseVanillaKillButton && !flag);
|
||||
__instance.ImpostorVentButton.ToggleVisible(isActive && customRole.Configuration.CanUseVent && !flag);
|
||||
__instance.SabotageButton.gameObject.SetActive(isActive && customRole.Configuration.CanUseSabotage);
|
||||
}
|
||||
|
||||
if (_roleTab)
|
||||
@@ -56,7 +60,7 @@ public static class HudManagerPatches
|
||||
|
||||
var role = local?.Data?.Role;
|
||||
|
||||
if (role is ICustomRole { RoleHintType: RoleHintType.RoleTab } customRole)
|
||||
if (role is ICustomRole { Configuration.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.KillButtonOutlineColor));
|
||||
__instance.currentTarget.cosmetics.SetOutline(true, new Nullable<Color>(customRole.Configuration.KillButtonOutlineColor));
|
||||
__instance.SetEnabled();
|
||||
return false;
|
||||
}
|
||||
@@ -52,11 +52,6 @@ public static class KillButtonPatches
|
||||
[HarmonyPatch(nameof(KillButton.DoClick))]
|
||||
public static bool DoClickPrefix(KillButton __instance)
|
||||
{
|
||||
if (PlayerControl.LocalPlayer.Data.Role is not ICustomRole)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!__instance.isActiveAndEnabled || !__instance.currentTarget || __instance.isCoolingDown ||
|
||||
PlayerControl.LocalPlayer.Data.IsDead || !PlayerControl.LocalPlayer.CanMove)
|
||||
{
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
using HarmonyLib;
|
||||
using MiraAPI.Roles;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.Patches.Roles;
|
||||
|
||||
/// <summary>
|
||||
/// Set nametag color depending on option
|
||||
/// Set nametag color depending on visibility.
|
||||
/// </summary>
|
||||
[HarmonyPatch(typeof(PlayerNameColor))]
|
||||
public static class NameTagPatch
|
||||
@@ -13,6 +14,12 @@ public static class NameTagPatch
|
||||
[HarmonyPatch(nameof(PlayerNameColor.Get), typeof(RoleBehaviour))]
|
||||
public static bool GetPatch([HarmonyArgument(0)] RoleBehaviour otherPlayerRole, ref Color __result)
|
||||
{
|
||||
if (otherPlayerRole is ICustomRole customRole && customRole.CanLocalPlayerSeeRole(otherPlayerRole.Player))
|
||||
{
|
||||
__result = customRole.RoleColor;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (PlayerControl.LocalPlayer.Data.Role.IsImpostor && otherPlayerRole.IsImpostor)
|
||||
{
|
||||
return true;
|
||||
|
||||
+3
-3
@@ -5,10 +5,10 @@ using UnityEngine;
|
||||
namespace MiraAPI.Patches.Roles;
|
||||
|
||||
[HarmonyPatch(typeof(RoleBehaviour))]
|
||||
public static class RoleBehaviourPatches
|
||||
public static class RoleBehaviourPatch
|
||||
{
|
||||
/// <summary>
|
||||
/// Update TeamColor text for Launchpad roles
|
||||
/// Update TeamColor text for Mira roles.
|
||||
/// </summary>
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(nameof(RoleBehaviour.TeamColor), MethodType.Getter)]
|
||||
@@ -22,4 +22,4 @@ public static class RoleBehaviourPatches
|
||||
__result = behaviour.RoleColor;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
using AmongUs.GameOptions;
|
||||
using HarmonyLib;
|
||||
using MiraAPI.Events;
|
||||
using MiraAPI.Events.Vanilla.Gameplay;
|
||||
using MiraAPI.Modifiers;
|
||||
using MiraAPI.Roles;
|
||||
using System.Linq;
|
||||
@@ -9,6 +11,14 @@ namespace MiraAPI.Patches.Roles;
|
||||
[HarmonyPatch(typeof(RoleManager))]
|
||||
public static class RoleManagerPatches
|
||||
{
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(nameof(RoleManager.SetRole))]
|
||||
public static void SetRolePatch(RoleManager __instance, PlayerControl targetPlayer, RoleTypes roleType)
|
||||
{
|
||||
var @event = new SetRoleEvent(targetPlayer, roleType);
|
||||
MiraEventManager.InvokeEvent(@event);
|
||||
}
|
||||
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(nameof(RoleManager.SelectRoles))]
|
||||
public static void ModifierSelectionPatches(RoleManager __instance)
|
||||
@@ -37,12 +47,12 @@ public static class RoleManagerPatches
|
||||
return true;
|
||||
}
|
||||
|
||||
if (role.GhostRole is RoleTypes.CrewmateGhost or RoleTypes.ImpostorGhost)
|
||||
if (role.Configuration.GhostRole is RoleTypes.CrewmateGhost or RoleTypes.ImpostorGhost)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
plr.RpcSetRole(role.GhostRole);
|
||||
plr.RpcSetRole(role.Configuration.GhostRole);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,55 +1,73 @@
|
||||
using AmongUs.GameOptions;
|
||||
using HarmonyLib;
|
||||
using MiraAPI.Roles;
|
||||
using Reactor.Utilities;
|
||||
|
||||
namespace MiraAPI.Patches.Roles;
|
||||
|
||||
/// <summary>
|
||||
/// Patches to return the correct role counts.
|
||||
/// </summary>
|
||||
[HarmonyPatch(typeof(RoleOptionsCollectionV08))]
|
||||
public static class RoleOptionsCollectionPatch
|
||||
{
|
||||
/// <summary>
|
||||
/// Set the role chance for custom Launchpad roles based on config
|
||||
/// </summary>
|
||||
/// <returns>Return false to skip original method, true to not.</returns>
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(nameof(RoleOptionsCollectionV08.GetChancePerGame))]
|
||||
public static bool GetChancePrefix([HarmonyArgument(0)] RoleTypes roleType, ref int __result)
|
||||
public static bool GetChancePrefix(RoleTypes role, ref int __result)
|
||||
{
|
||||
if (!CustomRoleManager.GetCustomRoleBehaviour(roleType, out var customRole) || customRole == null)
|
||||
if (!CustomRoleManager.GetCustomRoleBehaviour(role, out var customRole) || customRole == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (customRole.HideSettings)
|
||||
if (customRole.Configuration.HideSettings)
|
||||
{
|
||||
__result = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
customRole.ParentMod.PluginConfig.TryGetEntry<int>(customRole.ChanceConfigDefinition, out var entry);
|
||||
__result = entry.Value;
|
||||
var chance = customRole.GetChance();
|
||||
if (chance == null)
|
||||
{
|
||||
Logger<MiraApiPlugin>.Error($"Chance is null, defaulting to zero.");
|
||||
chance = 0;
|
||||
}
|
||||
|
||||
__result = chance.Value;
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the amount for custom Launchpad roles based on config
|
||||
/// </summary>
|
||||
/// <returns>Return false to skip original method, true to not.</returns>
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(nameof(RoleOptionsCollectionV08.GetNumPerGame))]
|
||||
public static bool GetNumPrefix([HarmonyArgument(0)] RoleTypes roleType, ref int __result)
|
||||
public static bool GetNumPrefix(RoleTypes role, ref int __result)
|
||||
{
|
||||
if (!CustomRoleManager.GetCustomRoleBehaviour(roleType, out var customRole) || customRole == null)
|
||||
if (!CustomRoleManager.GetCustomRoleBehaviour(role, out var customRole) || customRole == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (customRole.HideSettings)
|
||||
if (customRole.Configuration.HideSettings)
|
||||
{
|
||||
__result = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
customRole.ParentMod.PluginConfig.TryGetEntry<int>(customRole.NumConfigDefinition, out var entry);
|
||||
__result = entry.Value;
|
||||
var count = customRole.GetCount();
|
||||
if (count == null)
|
||||
{
|
||||
Logger<MiraApiPlugin>.Error($"Count is null, defaulting to zero.");
|
||||
count = 0;
|
||||
}
|
||||
|
||||
__result = count.Value;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -20,12 +20,12 @@ public class SabotageButtonPatch
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!customRole.CanUseSabotage || PlayerControl.LocalPlayer.inVent || !GameManager.Instance.SabotagesEnabled())
|
||||
if (!customRole.Configuration.CanUseSabotage || PlayerControl.LocalPlayer.inVent || !GameManager.Instance.SabotagesEnabled())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
DestroyableSingleton<HudManager>.Instance.ToggleMapVisible(
|
||||
HudManager.Instance.ToggleMapVisible(
|
||||
new MapOptions
|
||||
{
|
||||
Mode = MapOptions.Modes.Sabotage,
|
||||
@@ -52,7 +52,7 @@ public class SabotageButtonPatch
|
||||
|
||||
if (player.inVent || !GameManager.Instance.SabotagesEnabled() || player.petting)
|
||||
{
|
||||
__instance.ToggleVisible(customRole.CanUseSabotage && GameManager.Instance.SabotagesEnabled());
|
||||
__instance.ToggleVisible(customRole.Configuration.CanUseSabotage && GameManager.Instance.SabotagesEnabled());
|
||||
__instance.SetDisabled();
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
using AmongUs.GameOptions;
|
||||
using HarmonyLib;
|
||||
using Il2CppSystem;
|
||||
using Il2CppSystem.Collections.Generic;
|
||||
using MiraAPI.PluginLoading;
|
||||
using MiraAPI.Roles;
|
||||
using MiraAPI.Utilities.Assets;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
@@ -12,12 +12,19 @@ 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 System.Collections.Generic.Dictionary<string, string> ModsFolders = [];
|
||||
private static readonly Dictionary<string, string> ModsFolders = [];
|
||||
private static Scroller? _scroller;
|
||||
|
||||
/// <summary>
|
||||
/// Adds custom roles to the TaskAdder.
|
||||
/// </summary>
|
||||
/// <param name="__instance">TaskAdder instance.</param>
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(TaskAdderGame), nameof(TaskAdderGame.Begin))]
|
||||
public static void AddRolesFolder(TaskAdderGame __instance)
|
||||
@@ -83,13 +90,17 @@ public static class TaskAdderPatch
|
||||
__instance.GoToRoot();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the color of the role button based on the role.
|
||||
/// </summary>
|
||||
/// <param name="__instance">TaskAddButton instance.</param>
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(TaskAddButton), "Role", MethodType.Setter)]
|
||||
[HarmonyPatch(typeof(TaskAddButton), nameof(TaskAddButton.Role), MethodType.Setter)]
|
||||
public static void RoleGetterPatch(TaskAddButton __instance)
|
||||
{
|
||||
if (__instance.role is ICustomRole { Team: ModdedRoleTeams.Neutral })
|
||||
if (__instance.role is ICustomRole { Team: ModdedRoleTeams.Custom } customRole)
|
||||
{
|
||||
__instance.FileImage.color = Color.gray;
|
||||
__instance.FileImage.color = customRole.IntroConfiguration?.IntroTeamColor ?? Color.gray;
|
||||
}
|
||||
|
||||
__instance.RolloverHandler.OutColor = __instance.FileImage.color;
|
||||
@@ -167,19 +178,14 @@ public static class TaskAdderPatch
|
||||
|
||||
ControllerManager.Instance.AddSelectableUiElement(taskFolder2.Button);
|
||||
if (!string.IsNullOrEmpty(__instance.restorePreviousSelectionByFolderName) &&
|
||||
taskFolder2.FolderName.Equals(__instance.restorePreviousSelectionByFolderName, System.StringComparison.Ordinal))
|
||||
taskFolder2.FolderName.Equals(__instance.restorePreviousSelectionByFolderName, StringComparison.Ordinal))
|
||||
{
|
||||
__instance.restorePreviousSelectionFound = taskFolder2.Button;
|
||||
}
|
||||
}
|
||||
|
||||
var flag = false;
|
||||
var list = new List<PlayerTask>();
|
||||
|
||||
foreach (var item in taskFolder.Children)
|
||||
{
|
||||
list.Add(item);
|
||||
}
|
||||
var list = taskFolder.Children.ToArray().OrderBy(t => t.TaskType).ToList();
|
||||
|
||||
for (var l = 0; l < list.Count; l++)
|
||||
{
|
||||
@@ -188,28 +194,26 @@ public static class TaskAdderPatch
|
||||
switch (taskAddButton.MyTask.TaskType)
|
||||
{
|
||||
case TaskTypes.DivertPower:
|
||||
{
|
||||
var targetSystem = taskAddButton.MyTask.Cast<DivertPowerTask>().TargetSystem;
|
||||
taskAddButton.Text.text = DestroyableSingleton<TranslationController>.Instance.GetString(
|
||||
StringNames.DivertPowerTo,
|
||||
DestroyableSingleton<TranslationController>.Instance.GetString(targetSystem));
|
||||
break;
|
||||
}
|
||||
{
|
||||
var targetSystem = taskAddButton.MyTask.Cast<DivertPowerTask>().TargetSystem;
|
||||
taskAddButton.Text.text = TranslationController.Instance.GetString(
|
||||
StringNames.DivertPowerTo,
|
||||
TranslationController.Instance.GetString(targetSystem));
|
||||
break;
|
||||
}
|
||||
case TaskTypes.FixWeatherNode:
|
||||
{
|
||||
var nodeId = ((WeatherNodeTask)taskAddButton.MyTask).NodeId;
|
||||
taskAddButton.Text.text =
|
||||
DestroyableSingleton<TranslationController>.Instance.GetString(
|
||||
StringNames.FixWeatherNode,
|
||||
Array.Empty<Il2CppSystem.Object>()) + " " +
|
||||
DestroyableSingleton<TranslationController>.Instance.GetString(
|
||||
WeatherSwitchGame.ControlNames[nodeId],
|
||||
Array.Empty<Il2CppSystem.Object>());
|
||||
break;
|
||||
}
|
||||
{
|
||||
var nodeId = taskAddButton.MyTask.Cast<WeatherNodeTask>().NodeId;
|
||||
taskAddButton.Text.text =
|
||||
TranslationController.Instance.GetString(
|
||||
StringNames.FixWeatherNode) + " " +
|
||||
TranslationController.Instance.GetString(
|
||||
WeatherSwitchGame.ControlNames[nodeId]);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
taskAddButton.Text.text =
|
||||
DestroyableSingleton<TranslationController>.Instance.GetString(taskAddButton.MyTask.TaskType);
|
||||
TranslationController.Instance.GetString(taskAddButton.MyTask.TaskType);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -238,9 +242,9 @@ public static class TaskAdderPatch
|
||||
|
||||
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 ||
|
||||
CustomRoleManager.CustomRoles.ContainsKey((ushort)roleBehaviour.Role))
|
||||
{
|
||||
@@ -275,12 +279,12 @@ public static class TaskAdderPatch
|
||||
|
||||
if (ModsFolders.TryGetValue(taskFolder.FolderName, out var guid))
|
||||
{
|
||||
var plugin = MiraPluginManager.Instance.GetPluginByGuid(guid);
|
||||
var plugin = MiraPluginManager.GetPluginByGuid(guid);
|
||||
for (var m = 0; m < plugin.CustomRoles.Count; m++)
|
||||
{
|
||||
var roleBehaviour = plugin.CustomRoles.ElementAt(m).Value;
|
||||
if (roleBehaviour.Role == RoleTypes.ImpostorGhost || roleBehaviour.Role == RoleTypes.CrewmateGhost ||
|
||||
roleBehaviour.IsDead)
|
||||
(roleBehaviour is ICustomRole customRole && !customRole.Configuration.ShowInFreeplay))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -6,12 +6,17 @@ using UnityEngine;
|
||||
namespace MiraAPI.Patches.Roles;
|
||||
|
||||
/// <summary>
|
||||
/// Set vent outline color based on the player's role.
|
||||
/// Vent patches for Roles.
|
||||
/// </summary>
|
||||
[HarmonyPatch(typeof(Vent), nameof(Vent.SetOutline))]
|
||||
public static class VentOutlinePatch
|
||||
[HarmonyPatch(typeof(Vent))]
|
||||
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)
|
||||
{
|
||||
@@ -0,0 +1,36 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
using HarmonyLib;
|
||||
|
||||
namespace MiraAPI.Patches.Stubs;
|
||||
|
||||
/// <summary>
|
||||
/// Reverse patches for Minigames.
|
||||
/// </summary>
|
||||
[HarmonyPatch]
|
||||
public static class MinigameStubs
|
||||
{
|
||||
/// <summary>
|
||||
/// Reverse patch for Minigame.Begin.
|
||||
/// </summary>
|
||||
/// <param name="instance">The Minigame instance.</param>
|
||||
/// <param name="task">Associated PlayerTask.</param>
|
||||
[HarmonyReversePatch]
|
||||
[HarmonyPatch(typeof(Minigame), nameof(Minigame.Begin))]
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static void Begin(Minigame instance, PlayerTask? task)
|
||||
{
|
||||
// nothing needed
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reverse patch for Minigame.Close.
|
||||
/// </summary>
|
||||
/// <param name="instance">The Minigame instance.</param>
|
||||
[HarmonyReversePatch]
|
||||
[HarmonyPatch(typeof(Minigame), nameof(Minigame.Close), [])]
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static void Close(Minigame instance)
|
||||
{
|
||||
// nothing needed
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,229 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
using HarmonyLib;
|
||||
using Il2CppSystem.Text;
|
||||
|
||||
namespace MiraAPI.Patches.Stubs;
|
||||
|
||||
[HarmonyPatch]
|
||||
public static class RoleBehaviourStubs
|
||||
{
|
||||
/// <summary>
|
||||
/// Stub method for RoleBehaviour.Initialize.
|
||||
/// </summary>
|
||||
/// <param name="instance">The RoleBehaviour object.</param>
|
||||
/// <param name="player">The PlayerControl to initialize.</param>
|
||||
[HarmonyReversePatch]
|
||||
[HarmonyPatch(typeof(RoleBehaviour), nameof(RoleBehaviour.Initialize))]
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static void Initialize(RoleBehaviour instance, PlayerControl player)
|
||||
{
|
||||
// nothing needed
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stub method for RoleBehaviour.AdjustTasks.
|
||||
/// </summary>
|
||||
/// <param name="instance">The RoleBehaviour object.</param>
|
||||
/// <param name="player">The PlayerControl to adjust tasks for.</param>
|
||||
[HarmonyReversePatch]
|
||||
[HarmonyPatch(typeof(RoleBehaviour), nameof(RoleBehaviour.AdjustTasks))]
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static void AdjustTasks(RoleBehaviour instance, PlayerControl player)
|
||||
{
|
||||
// nothing needed
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stub method for RoleBehaviour.AppendTaskHint.
|
||||
/// </summary>
|
||||
/// <param name="instance">The RoleBehaviour object.</param>
|
||||
/// <param name="taskStringBuilder">The StringBuilder to append the task hint to.</param>
|
||||
[HarmonyReversePatch]
|
||||
[HarmonyPatch(typeof(RoleBehaviour), nameof(RoleBehaviour.AppendTaskHint), typeof(StringBuilder))]
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static void AppendTaskHint(RoleBehaviour instance, StringBuilder taskStringBuilder)
|
||||
{
|
||||
// nothing needed
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stub method for RoleBehaviour.CanUse.
|
||||
/// </summary>
|
||||
/// <param name="instance">The RoleBehaviour object.</param>
|
||||
/// <param name="console">The IUsable console to check.</param>
|
||||
/// <returns>Whether the console can be used.</returns>
|
||||
[HarmonyReversePatch]
|
||||
[HarmonyPatch(typeof(RoleBehaviour), nameof(RoleBehaviour.CanUse))]
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static bool CanUse(RoleBehaviour instance, IUsable console)
|
||||
{
|
||||
return default;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stub method for RoleBehaviour.Deinitialize.
|
||||
/// </summary>
|
||||
/// <param name="instance">The RoleBehaviour object.</param>
|
||||
/// <param name="targetPlayer">The PlayerControl to deinitialize for.</param>
|
||||
[HarmonyReversePatch]
|
||||
[HarmonyPatch(typeof(RoleBehaviour), nameof(RoleBehaviour.Deinitialize))]
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static void Deinitialize(RoleBehaviour instance, PlayerControl targetPlayer)
|
||||
{
|
||||
// nothing needed
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stub method for RoleBehaviour.DidWin.
|
||||
/// </summary>
|
||||
/// <param name="instance">The RoleBehaviour object.</param>
|
||||
/// <param name="gameOverReason">The reason for game over.</param>
|
||||
/// <returns>Whether the role won.</returns>
|
||||
[HarmonyReversePatch]
|
||||
[HarmonyPatch(typeof(RoleBehaviour), nameof(RoleBehaviour.DidWin))]
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static bool DidWin(RoleBehaviour instance, GameOverReason gameOverReason)
|
||||
{
|
||||
return default;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stub method for RoleBehaviour.FindClosestTarget.
|
||||
/// </summary>
|
||||
/// <param name="instance">The RoleBehaviour object.</param>
|
||||
/// <returns>The closest target PlayerControl.</returns>
|
||||
[HarmonyReversePatch]
|
||||
[HarmonyPatch(typeof(RoleBehaviour), nameof(RoleBehaviour.FindClosestTarget))]
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static PlayerControl FindClosestTarget(RoleBehaviour instance)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stub method for RoleBehaviour.GetAbilityDistance.
|
||||
/// </summary>
|
||||
/// <param name="instance">The RoleBehaviour object.</param>
|
||||
/// <returns>The ability distance.</returns>
|
||||
[HarmonyReversePatch]
|
||||
[HarmonyPatch(typeof(RoleBehaviour), nameof(RoleBehaviour.GetAbilityDistance))]
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static float GetAbilityDistance(RoleBehaviour instance)
|
||||
{
|
||||
return default;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stub method for RoleBehaviour.IsValidTarget.
|
||||
/// </summary>
|
||||
/// <param name="instance">The RoleBehaviour object.</param>
|
||||
/// <param name="target">The NetworkedPlayerInfo to validate.</param>
|
||||
/// <returns>Whether the target is valid.</returns>
|
||||
[HarmonyReversePatch]
|
||||
[HarmonyPatch(typeof(RoleBehaviour), nameof(RoleBehaviour.IsValidTarget))]
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static bool IsValidTarget(RoleBehaviour instance, NetworkedPlayerInfo target)
|
||||
{
|
||||
return default;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stub method for RoleBehaviour.OnDeath.
|
||||
/// </summary>
|
||||
/// <param name="instance">The RoleBehaviour object.</param>
|
||||
/// <param name="reason">The reason for death.</param>
|
||||
[HarmonyReversePatch]
|
||||
[HarmonyPatch(typeof(RoleBehaviour), nameof(RoleBehaviour.OnDeath))]
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static void OnDeath(RoleBehaviour instance, DeathReason reason)
|
||||
{
|
||||
// nothing needed
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stub method for RoleBehaviour.OnMeetingStart.
|
||||
/// </summary>
|
||||
/// <param name="instance">The RoleBehaviour object.</param>
|
||||
[HarmonyReversePatch]
|
||||
[HarmonyPatch(typeof(RoleBehaviour), nameof(RoleBehaviour.OnMeetingStart))]
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static void OnMeetingStart(RoleBehaviour instance)
|
||||
{
|
||||
// nothing needed
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stub method for RoleBehaviour.OnVotingComplete.
|
||||
/// </summary>
|
||||
/// <param name="instance">The RoleBehaviour object.</param>
|
||||
[HarmonyReversePatch]
|
||||
[HarmonyPatch(typeof(RoleBehaviour), nameof(RoleBehaviour.OnVotingComplete))]
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static void OnVotingComplete(RoleBehaviour instance)
|
||||
{
|
||||
// nothing needed
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stub method for RoleBehaviour.SetCooldown.
|
||||
/// </summary>
|
||||
/// <param name="instance">The RoleBehaviour object.</param>
|
||||
[HarmonyReversePatch]
|
||||
[HarmonyPatch(typeof(RoleBehaviour), nameof(RoleBehaviour.SetCooldown))]
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static void SetCooldown(RoleBehaviour instance)
|
||||
{
|
||||
// nothing needed
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stub method for RoleBehaviour.SetPlayerTarget.
|
||||
/// </summary>
|
||||
/// <param name="instance">The RoleBehaviour object.</param>
|
||||
/// <param name="target">The PlayerControl target to set.</param>
|
||||
[HarmonyReversePatch]
|
||||
[HarmonyPatch(typeof(RoleBehaviour), nameof(RoleBehaviour.SetPlayerTarget))]
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static void SetPlayerTarget(RoleBehaviour instance, PlayerControl target)
|
||||
{
|
||||
// nothing needed
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stub method for RoleBehaviour.SetUsableTarget.
|
||||
/// </summary>
|
||||
/// <param name="instance">The RoleBehaviour object.</param>
|
||||
/// <param name="target">The IUsable target to set.</param>
|
||||
[HarmonyReversePatch]
|
||||
[HarmonyPatch(typeof(RoleBehaviour), nameof(RoleBehaviour.SetUsableTarget))]
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static void SetUsableTarget(RoleBehaviour instance, IUsable target)
|
||||
{
|
||||
// nothing needed
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stub method for RoleBehaviour.SpawnTaskHeader.
|
||||
/// </summary>
|
||||
/// <param name="instance">The RoleBehaviour object.</param>
|
||||
/// <param name="playerControl">The PlayerControl to spawn the task header for.</param>
|
||||
[HarmonyReversePatch]
|
||||
[HarmonyPatch(typeof(RoleBehaviour), nameof(RoleBehaviour.SpawnTaskHeader))]
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static void SpawnTaskHeader(RoleBehaviour instance, PlayerControl playerControl)
|
||||
{
|
||||
// nothing needed
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stub method for RoleBehaviour.UseAbility.
|
||||
/// </summary>
|
||||
/// <param name="instance">The RoleBehaviour object.</param>
|
||||
[HarmonyReversePatch]
|
||||
[HarmonyPatch(typeof(RoleBehaviour), nameof(RoleBehaviour.UseAbility))]
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static void UseAbility(RoleBehaviour instance)
|
||||
{
|
||||
// nothing needed
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
using HarmonyLib;
|
||||
using MiraAPI.Events;
|
||||
using MiraAPI.Events.Vanilla.Usables;
|
||||
using MiraAPI.Roles;
|
||||
using MiraAPI.Utilities;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.Patches;
|
||||
|
||||
/// <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)
|
||||
{
|
||||
var @event = new PlayerCanUseEvent(__instance.Cast<IUsable>());
|
||||
MiraEventManager.InvokeEvent(@event);
|
||||
|
||||
if (@event.IsCancelled)
|
||||
{
|
||||
canUse = couldUse = false;
|
||||
return;
|
||||
}
|
||||
|
||||
var @object = pc.Object;
|
||||
var role = @object.Data.Role;
|
||||
|
||||
var canVent = role is ICustomRole customRole ? customRole.Configuration.CanUseVent : role.CanVent;
|
||||
couldUse = canVent;
|
||||
|
||||
var modifiers = @object.GetModifierComponent()?.ActiveModifiers;
|
||||
if (modifiers is { Count: > 0 })
|
||||
{
|
||||
switch (canVent)
|
||||
{
|
||||
case true when modifiers.Exists(x => x.CanVent().HasValue && x.CanVent() == false):
|
||||
couldUse = canUse = false;
|
||||
return;
|
||||
case false when modifiers.Exists(x => x.CanVent().HasValue && x.CanVent() == true):
|
||||
couldUse = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
var num = float.MaxValue;
|
||||
|
||||
canUse = couldUse;
|
||||
if (canUse)
|
||||
{
|
||||
var center = @object.Collider.bounds.center;
|
||||
var position = __instance.transform.position;
|
||||
num = Vector2.Distance(center, position);
|
||||
canUse &= num <= __instance.UsableDistance && !PhysicsHelpers.AnythingBetween(@object.Collider, center, position, Constants.ShipOnlyMask, false);
|
||||
}
|
||||
|
||||
__result = num;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using System;
|
||||
|
||||
namespace MiraAPI.PluginLoading;
|
||||
|
||||
/// <summary>
|
||||
/// Skip an element during plugin loading.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property, Inherited = false)]
|
||||
public class MiraIgnoreAttribute : Attribute;
|
||||
@@ -3,6 +3,8 @@ using BepInEx.Configuration;
|
||||
using MiraAPI.GameModes;
|
||||
using MiraAPI.GameOptions;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using MiraAPI.Hud;
|
||||
|
||||
namespace MiraAPI.PluginLoading;
|
||||
|
||||
@@ -19,6 +21,42 @@ public class MiraPluginInfo
|
||||
PluginId = info.Metadata.GUID;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a read only collection of this plugin's Option Groups.
|
||||
/// </summary>
|
||||
/// <returns>Readonly collection of option groups.</returns>
|
||||
public IReadOnlyCollection<AbstractOptionGroup> GetOptionGroups()
|
||||
{
|
||||
return OptionGroups.AsReadOnly();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a read only collection of this plugin's options.
|
||||
/// </summary>
|
||||
/// <returns>Read only collection of options.</returns>
|
||||
public IReadOnlyCollection<IModdedOption> GetOptions()
|
||||
{
|
||||
return Options.AsReadOnly();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a read only dictionary of Role IDs and the RoleBehaviour object they are associated with.
|
||||
/// </summary>
|
||||
/// <returns>Read only dictionary of IDs and Roles.</returns>
|
||||
public ReadOnlyDictionary<ushort, RoleBehaviour> GetRoles()
|
||||
{
|
||||
return new ReadOnlyDictionary<ushort, RoleBehaviour>(CustomRoles);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a read only collection of this plugin's custom buttons.
|
||||
/// </summary>
|
||||
/// <returns>Read only collection of buttons.</returns>
|
||||
public IReadOnlyCollection<CustomActionButton> GetButtons()
|
||||
{
|
||||
return Buttons.AsReadOnly();
|
||||
}
|
||||
|
||||
internal List<AbstractOptionGroup> OptionGroups { get; } = [];
|
||||
|
||||
internal List<IModdedOption> Options { get; } = [];
|
||||
@@ -27,6 +65,8 @@ public class MiraPluginInfo
|
||||
|
||||
internal Dictionary<int, CustomGameMode> GameModes { get; } = [];
|
||||
|
||||
internal List<CustomActionButton> Buttons { get; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Gets the plugin's ID, as defined in the plugin's BepInEx metadata.
|
||||
/// </summary>
|
||||
|
||||
Loaded 100 of 114 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user