more events

This commit is contained in:
XtraCube committed 2024-12-08 14:44:01 -05:00
1 parent 707b5629b4
commit 3ea46d5574
8 files changed
+204

No files matched your search

@@ -0,0 +1,21 @@
namespace MiraAPI.Events.Vanilla;
/// <summary>
/// Button click event for <see cref="AdminButton"/> from Vanilla Among Us.
/// </summary>
public class AdminButtonClickEvent : MiraCancelableEvent
{
/// <summary>
/// Gets the instance of <see cref="AdminButton"/> that was clicked.
/// </summary>
public AdminButton Button { get; }
/// <summary>
/// Initializes a new instance of the <see cref="AdminButtonClickEvent"/> class.
/// </summary>
/// <param name="button">The AdminButton.</param>
public AdminButtonClickEvent(AdminButton button)
{
Button = button;
}
}
@@ -0,0 +1,28 @@
namespace MiraAPI.Events.Vanilla;
/// <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,21 @@
namespace MiraAPI.Events.Vanilla;
/// <summary>
/// Button click event for <see cref="ReportButton"/> from Vanilla Among Us.
/// </summary>
public class ReportButtonClickEvent : MiraCancelableEvent
{
/// <summary>
/// Gets the instance of <see cref="ReportButton"/> that was clicked.
/// </summary>
public ReportButton Button { get; }
/// <summary>
/// Initializes a new instance of the <see cref="ReportButtonClickEvent"/> class.
/// </summary>
/// <param name="button">The ReportButton.</param>
public ReportButtonClickEvent(ReportButton button)
{
Button = button;
}
}
@@ -0,0 +1,21 @@
namespace MiraAPI.Events.Vanilla;
/// <summary>
/// Button click event for <see cref="SabotageButton"/> from Vanilla Among Us.
/// </summary>
public class SabotageButtonClickEvent : MiraCancelableEvent
{
/// <summary>
/// Gets the instance of <see cref="SabotageButton"/> that was clicked.
/// </summary>
public SabotageButton Button { get; }
/// <summary>
/// Initializes a new instance of the <see cref="SabotageButtonClickEvent"/> class.
/// </summary>
/// <param name="button">The SabotageButton.</param>
public SabotageButtonClickEvent(SabotageButton button)
{
Button = button;
}
}
@@ -0,0 +1,21 @@
namespace MiraAPI.Events.Vanilla;
/// <summary>
/// Button click event for <see cref="UseButton"/> from Vanilla Among Us.
/// </summary>
public class UseButtonClickEvent : MiraCancelableEvent
{
/// <summary>
/// Gets the instance of <see cref="UseButton"/> that was clicked.
/// </summary>
public UseButton Button { get; }
/// <summary>
/// Initializes a new instance of the <see cref="UseButtonClickEvent"/> class.
/// </summary>
/// <param name="button">The UseButton.</param>
public UseButtonClickEvent(UseButton button)
{
Button = button;
}
}
@@ -0,0 +1,21 @@
namespace MiraAPI.Events.Vanilla;
/// <summary>
/// Button click event for <see cref="VentButton"/> from Vanilla Among Us.
/// </summary>
public class VentButtonClickEvent : MiraCancelableEvent
{
/// <summary>
/// Gets the instance of <see cref="VentButton"/> that was clicked.
/// </summary>
public VentButton Button { get; }
/// <summary>
/// Initializes a new instance of the <see cref="VentButtonClickEvent"/> class.
/// </summary>
/// <param name="button">The VentButton.</param>
public VentButtonClickEvent(VentButton button)
{
Button = button;
}
}
+15
View File
@@ -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);
}
}
@@ -0,0 +1,56 @@
using HarmonyLib;
using MiraAPI.Events;
using MiraAPI.Events.Vanilla;
namespace MiraAPI.Patches.Events;
/// <summary>
/// Patch for button related MiraEvents.
/// </summary>
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;
}
}