From d73c21936c7402c14222ba5a3cfe87c038174ba8 Mon Sep 17 00:00:00 2001
From: Atony <75191600+AtonyGit@users.noreply.github.com>
Date: Sat, 6 Sep 2025 14:19:17 -0500
Subject: [PATCH] Add Before and After vote events
Useful for local checks before a vote is placed (like with TOU Mira Prosecutor)
---
.../Vanilla/Meeting/Voting/AfterVoteEvent.cs | 30 +++++++++++++++++++
.../Vanilla/Meeting/Voting/BeforeVoteEvent.cs | 30 +++++++++++++++++++
MiraAPI/Patches/Voting/MeetingHudPatches.cs | 18 +++++++++++
3 files changed, 78 insertions(+)
create mode 100644 MiraAPI/Events/Vanilla/Meeting/Voting/AfterVoteEvent.cs
create mode 100644 MiraAPI/Events/Vanilla/Meeting/Voting/BeforeVoteEvent.cs
diff --git a/MiraAPI/Events/Vanilla/Meeting/Voting/AfterVoteEvent.cs b/MiraAPI/Events/Vanilla/Meeting/Voting/AfterVoteEvent.cs
new file mode 100644
index 0000000..714d3b8
--- /dev/null
+++ b/MiraAPI/Events/Vanilla/Meeting/Voting/AfterVoteEvent.cs
@@ -0,0 +1,30 @@
+using MiraAPI.Voting;
+
+namespace MiraAPI.Events.Vanilla.Meeting.Voting;
+
+///
+/// Event that is invoked after the local player successfully votes a player or skips. This event is not cancelable.
+///
+public class AfterVoteEvent : MiraEvent
+{
+ ///
+ /// Gets the instance of the voter's vote data.
+ ///
+ public PlayerVoteArea VoteArea { get; }
+
+ ///
+ /// Gets the player who voted.
+ ///
+ public PlayerControl Player { get; }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The player vote area that was voted on.
+ /// The player who voted.
+ public AfterVoteEvent(PlayerVoteArea playerVoteArea, PlayerControl voter)
+ {
+ VoteArea = playerVoteArea;
+ Player = voter;
+ }
+}
diff --git a/MiraAPI/Events/Vanilla/Meeting/Voting/BeforeVoteEvent.cs b/MiraAPI/Events/Vanilla/Meeting/Voting/BeforeVoteEvent.cs
new file mode 100644
index 0000000..1d8d907
--- /dev/null
+++ b/MiraAPI/Events/Vanilla/Meeting/Voting/BeforeVoteEvent.cs
@@ -0,0 +1,30 @@
+using MiraAPI.Voting;
+
+namespace MiraAPI.Events.Vanilla.Meeting.Voting;
+
+///
+/// Event that is invoked before the local player confirms a vote on a player or when skipping. This event is cancelable.
+///
+public class BeforeVoteEvent : MiraCancelableEvent
+{
+ ///
+ /// Gets the instance of the voter's vote data.
+ ///
+ public PlayerVoteArea VoteArea { get; }
+
+ ///
+ /// Gets the player who voted.
+ ///
+ public PlayerControl Player { get; }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The player vote area that was voted on.
+ /// The player who voted.
+ public BeforeVoteEvent(PlayerVoteArea playerVoteArea, PlayerControl voter)
+ {
+ VoteArea = playerVoteArea;
+ Player = voter;
+ }
+}
diff --git a/MiraAPI/Patches/Voting/MeetingHudPatches.cs b/MiraAPI/Patches/Voting/MeetingHudPatches.cs
index 919170d..2aa9a82 100644
--- a/MiraAPI/Patches/Voting/MeetingHudPatches.cs
+++ b/MiraAPI/Patches/Voting/MeetingHudPatches.cs
@@ -15,6 +15,24 @@ namespace MiraAPI.Patches.Voting;
[SuppressMessage("ReSharper", "InconsistentNaming", Justification = "Harmony Convention")]
internal static class MeetingHudPatches
{
+ [HarmonyPrefix]
+ [HarmonyPatch(typeof(PlayerVoteArea), nameof(PlayerVoteArea.VoteForMe))]
+ public static bool VotePatch(PlayerVoteArea __instance)
+ {
+ var beforeVoteEvent = new BeforeVoteEvent(__instance, PlayerControl.LocalPlayer);
+ MiraEventManager.InvokeEvent(beforeVoteEvent);
+
+ if (beforeVoteEvent.IsCancelled)
+ {
+ return false;
+ }
+
+ var afterVoteEvent = new AfterVoteEvent(__instance, PlayerControl.LocalPlayer);
+ MiraEventManager.InvokeEvent(afterVoteEvent);
+
+ return true;
+ }
+
[HarmonyPostfix]
[HarmonyPatch(nameof(MeetingHud.Start))]
public static void MeetingHudStartPatch(MeetingHud __instance)