diff --git a/MiraAPI/Events/Vanilla/AdminButtonClickEvent.cs b/MiraAPI/Events/Vanilla/AdminButtonClickEvent.cs new file mode 100644 index 0000000..c37b933 --- /dev/null +++ b/MiraAPI/Events/Vanilla/AdminButtonClickEvent.cs @@ -0,0 +1,21 @@ +namespace MiraAPI.Events.Vanilla; + +/// +/// Button click event for from Vanilla Among Us. +/// +public class AdminButtonClickEvent : MiraCancelableEvent +{ + /// + /// Gets the instance of that was clicked. + /// + public AdminButton Button { get; } + + /// + /// Initializes a new instance of the class. + /// + /// The AdminButton. + public AdminButtonClickEvent(AdminButton button) + { + Button = button; + } +} diff --git a/MiraAPI/Events/Vanilla/AfterMurderEvent.cs b/MiraAPI/Events/Vanilla/AfterMurderEvent.cs new file mode 100644 index 0000000..a425cd2 --- /dev/null +++ b/MiraAPI/Events/Vanilla/AfterMurderEvent.cs @@ -0,0 +1,28 @@ +namespace MiraAPI.Events.Vanilla; + +/// +/// Event that is invoked after a player is murdered. Only called after a successful murder. This event is not cancelable. +/// +public class AfterMurderEvent : MiraEvent +{ + /// + /// Gets the player that killed the target. + /// + public PlayerControl Source { get; } + + /// + /// Gets the player that was killed. + /// + public PlayerControl Target { get; } + + /// + /// Initializes a new instance of the class. + /// + /// The killer. + /// The killed player. + public AfterMurderEvent(PlayerControl source, PlayerControl target) + { + Source = source; + Target = target; + } +} diff --git a/MiraAPI/Events/Vanilla/ReportButtonClickEvent.cs b/MiraAPI/Events/Vanilla/ReportButtonClickEvent.cs new file mode 100644 index 0000000..e6892b9 --- /dev/null +++ b/MiraAPI/Events/Vanilla/ReportButtonClickEvent.cs @@ -0,0 +1,21 @@ +namespace MiraAPI.Events.Vanilla; + +/// +/// Button click event for from Vanilla Among Us. +/// +public class ReportButtonClickEvent : MiraCancelableEvent +{ + /// + /// Gets the instance of that was clicked. + /// + public ReportButton Button { get; } + + /// + /// Initializes a new instance of the class. + /// + /// The ReportButton. + public ReportButtonClickEvent(ReportButton button) + { + Button = button; + } +} diff --git a/MiraAPI/Events/Vanilla/SabotageButtonClickEvent.cs b/MiraAPI/Events/Vanilla/SabotageButtonClickEvent.cs new file mode 100644 index 0000000..b657486 --- /dev/null +++ b/MiraAPI/Events/Vanilla/SabotageButtonClickEvent.cs @@ -0,0 +1,21 @@ +namespace MiraAPI.Events.Vanilla; + +/// +/// Button click event for from Vanilla Among Us. +/// +public class SabotageButtonClickEvent : MiraCancelableEvent +{ + /// + /// Gets the instance of that was clicked. + /// + public SabotageButton Button { get; } + + /// + /// Initializes a new instance of the class. + /// + /// The SabotageButton. + public SabotageButtonClickEvent(SabotageButton button) + { + Button = button; + } +} diff --git a/MiraAPI/Events/Vanilla/UseButtonClickEvent.cs b/MiraAPI/Events/Vanilla/UseButtonClickEvent.cs new file mode 100644 index 0000000..043b166 --- /dev/null +++ b/MiraAPI/Events/Vanilla/UseButtonClickEvent.cs @@ -0,0 +1,21 @@ +namespace MiraAPI.Events.Vanilla; + +/// +/// Button click event for from Vanilla Among Us. +/// +public class UseButtonClickEvent : MiraCancelableEvent +{ + /// + /// Gets the instance of that was clicked. + /// + public UseButton Button { get; } + + /// + /// Initializes a new instance of the class. + /// + /// The UseButton. + public UseButtonClickEvent(UseButton button) + { + Button = button; + } +} diff --git a/MiraAPI/Events/Vanilla/VentButtonClickEvent.cs b/MiraAPI/Events/Vanilla/VentButtonClickEvent.cs new file mode 100644 index 0000000..a46601f --- /dev/null +++ b/MiraAPI/Events/Vanilla/VentButtonClickEvent.cs @@ -0,0 +1,21 @@ +namespace MiraAPI.Events.Vanilla; + +/// +/// Button click event for from Vanilla Among Us. +/// +public class VentButtonClickEvent : MiraCancelableEvent +{ + /// + /// Gets the instance of that was clicked. + /// + public VentButton Button { get; } + + /// + /// Initializes a new instance of the class. + /// + /// The VentButton. + public VentButtonClickEvent(VentButton button) + { + Button = button; + } +} diff --git a/MiraAPI/Networking/CustomMurderRpc.cs b/MiraAPI/Networking/CustomMurderRpc.cs index 51c0c52..df565c2 100644 --- a/MiraAPI/Networking/CustomMurderRpc.cs +++ b/MiraAPI/Networking/CustomMurderRpc.cs @@ -3,6 +3,9 @@ using System.Linq; using AmongUs.GameOptions; using Assets.CoreScripts; using BepInEx.Unity.IL2CPP.Utils; +using Discord; +using MiraAPI.Events; +using MiraAPI.Events.Vanilla; using Reactor.Networking.Attributes; using Reactor.Networking.Rpc; using Reactor.Utilities; @@ -39,6 +42,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( @@ -268,5 +280,8 @@ public static class CustomMurderRpc PlayerControl.LocalPlayer.isKilling = false; source.isKilling = false; + + var afterMurderEvent = new AfterMurderEvent(source, target); + MiraEventManager.InvokeEvent(afterMurderEvent); } } diff --git a/MiraAPI/Patches/Events/HudButtonEventPatches.cs b/MiraAPI/Patches/Events/HudButtonEventPatches.cs new file mode 100644 index 0000000..212bb75 --- /dev/null +++ b/MiraAPI/Patches/Events/HudButtonEventPatches.cs @@ -0,0 +1,56 @@ +using HarmonyLib; +using MiraAPI.Events; +using MiraAPI.Events.Vanilla; + +namespace MiraAPI.Patches.Events; + +/// +/// Patch for button related MiraEvents. +/// +public static class HudButtonEventPatches +{ + [HarmonyPrefix] + [HarmonyPatch(typeof(AdminButton), nameof(AdminButton.DoClick))] + public static bool AdminButtonDoClickPrefix(AdminButton __instance) + { + var @event = new AdminButtonClickEvent(__instance); + MiraEventManager.InvokeEvent(@event); + return !@event.IsCancelled; + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(ReportButton), nameof(ReportButton.DoClick))] + public static bool ReportButtonDoClickPrefix(ReportButton __instance) + { + var @event = new ReportButtonClickEvent(__instance); + MiraEventManager.InvokeEvent(@event); + return !@event.IsCancelled; + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(SabotageButton), nameof(SabotageButton.DoClick))] + public static bool SabotageButtonDoClickPrefix(SabotageButton __instance) + { + var @event = new SabotageButtonClickEvent(__instance); + MiraEventManager.InvokeEvent(@event); + return !@event.IsCancelled; + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(UseButton), nameof(UseButton.DoClick))] + public static bool UseButtonDoClickPrefix(UseButton __instance) + { + var @event = new UseButtonClickEvent(__instance); + MiraEventManager.InvokeEvent(@event); + return !@event.IsCancelled; + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(VentButton), nameof(VentButton.DoClick))] + public static bool VentButtonDoClickPrefix(VentButton __instance) + { + var @event = new VentButtonClickEvent(__instance); + MiraEventManager.InvokeEvent(@event); + return !@event.IsCancelled; + } +}