From 476f4400ad7604709f7571228db84c0cfeb02b5b Mon Sep 17 00:00:00 2001 From: XtraCube <72575280+XtraCube@users.noreply.github.com> Date: Thu, 29 May 2025 22:04:05 -0400 Subject: [PATCH] Fix ReportBodyEventPatch.cs --- .../Patches/Events/ReportBodyEventPatch.cs | 41 ++++++++++++++++--- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/MiraAPI/Patches/Events/ReportBodyEventPatch.cs b/MiraAPI/Patches/Events/ReportBodyEventPatch.cs index feba1c9..7b4c60a 100644 --- a/MiraAPI/Patches/Events/ReportBodyEventPatch.cs +++ b/MiraAPI/Patches/Events/ReportBodyEventPatch.cs @@ -1,21 +1,52 @@ -using HarmonyLib; +using AmongUs.InnerNet.GameDataMessages; +using HarmonyLib; +using InnerNet; using MiraAPI.Events; using MiraAPI.Events.Vanilla.Meeting; using MiraAPI.Utilities; +using Reactor.Utilities; namespace MiraAPI.Patches.Events; [HarmonyPatch] public static class ReportBodyEventPatch { - [HarmonyPrefix] - [HarmonyPatch(typeof(PlayerControl), nameof(PlayerControl.CmdReportDeadBody))] - public static bool PlayerControlCmdReportDeadBodyPrefix(PlayerControl __instance, NetworkedPlayerInfo? target) + private static bool ReportBodyEventHook(PlayerControl source, NetworkedPlayerInfo? target) { 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); 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(); + + if (reportBodyMessage == null) + { + return true; + } + + var source = AmongUsClient.Instance.FindObjectByNetId(reportBodyMessage.rpcObjectNetId); + if (source == null) + { + Logger.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); + } }