Fix ReportBodyEventPatch.cs

This commit is contained in:
XtraCube committed 2025-05-29 22:04:34 -04:00
1 parent 2b46d90570
commit 476f4400ad
1 file changed
+36 -5
+36 -5
View File
@@ -1,21 +1,52 @@
using HarmonyLib; using AmongUs.InnerNet.GameDataMessages;
using HarmonyLib;
using InnerNet;
using MiraAPI.Events; using MiraAPI.Events;
using MiraAPI.Events.Vanilla.Meeting; using MiraAPI.Events.Vanilla.Meeting;
using MiraAPI.Utilities; using MiraAPI.Utilities;
using Reactor.Utilities;
namespace MiraAPI.Patches.Events; namespace MiraAPI.Patches.Events;
[HarmonyPatch] [HarmonyPatch]
public static class ReportBodyEventPatch public static class ReportBodyEventPatch
{ {
[HarmonyPrefix] private static bool ReportBodyEventHook(PlayerControl source, NetworkedPlayerInfo? target)
[HarmonyPatch(typeof(PlayerControl), nameof(PlayerControl.CmdReportDeadBody))]
public static bool PlayerControlCmdReportDeadBodyPrefix(PlayerControl __instance, NetworkedPlayerInfo? target)
{ {
var body = target != null ? Helpers.GetBodyById(target.PlayerId) : null; var body = target != null ? Helpers.GetBodyById(target.PlayerId) : null;
var @event = new ReportBodyEvent(__instance, target, body); var @event = new ReportBodyEvent(source, target, body);
MiraEventManager.InvokeEvent(@event); MiraEventManager.InvokeEvent(@event);
return !@event.IsCancelled; return !@event.IsCancelled;
} }
[HarmonyPrefix]
[HarmonyPatch(typeof(PlayerControl), nameof(PlayerControl.ReportDeadBody))]
public static bool PlayerControlCmdReportDeadBodyPrefix(PlayerControl __instance, NetworkedPlayerInfo? target)
{
return ReportBodyEventHook(__instance, target);
}
[HarmonyPrefix]
[HarmonyPatch(typeof(InnerNetClient), nameof(InnerNetClient.LateBroadcastReliableMessage))]
public static bool LateBroadcastReliableMessagePrefix(IGameDataMessage rpcMessage)
{
var reportBodyMessage = rpcMessage.TryCast<RpcReportDeadBodyMessage>();
if (reportBodyMessage == null)
{
return true;
}
var source = AmongUsClient.Instance.FindObjectByNetId<PlayerControl>(reportBodyMessage.rpcObjectNetId);
if (source == null)
{
Logger<MiraApiPlugin>.Error("Failed to find source player for RpcReportDeadBodyMessage with NetId: " + reportBodyMessage.rpcObjectNetId);
return true;
}
var target = GameData.Instance.GetPlayerById(reportBodyMessage.targetPlayerId);
return ReportBodyEventHook(source, target);
}
} }