From 790d868759a15da66c38d45dce142ea69aadff5f Mon Sep 17 00:00:00 2001 From: XtraCube <72575280+XtraCube@users.noreply.github.com> Date: Sun, 14 Sep 2025 15:26:58 -0400 Subject: [PATCH] fix viper --- MiraAPI/Patches/PlayerControlPatches.cs | 45 +++++++++++++++++++++- MiraAPI/Patches/Roles/KillButtonPatches.cs | 5 +++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/MiraAPI/Patches/PlayerControlPatches.cs b/MiraAPI/Patches/PlayerControlPatches.cs index a0b88cd..ac88d94 100644 --- a/MiraAPI/Patches/PlayerControlPatches.cs +++ b/MiraAPI/Patches/PlayerControlPatches.cs @@ -1,4 +1,5 @@ -using System.Linq; +using System.Globalization; +using System.Linq; using HarmonyLib; using MiraAPI.Events; using MiraAPI.Events.Vanilla.Gameplay; @@ -66,6 +67,48 @@ internal static class PlayerControlPatches } } + [HarmonyPrefix] + [HarmonyPatch(nameof(PlayerControl.CheckMurder))] + public static void PlayerControlCheckMurderPrefix(PlayerControl __instance, PlayerControl target, ref bool __runOriginal) + { + __runOriginal = false; + + __instance.logger.Debug($"Checking if {__instance.PlayerId} murdered {(target == null ? "null player" : target.PlayerId.ToString(NumberFormatInfo.InvariantInfo))}"); + + __instance.isKilling = false; + if (AmongUsClient.Instance.IsGameOver || !AmongUsClient.Instance.AmHost) + { + return; + } + + if (!target || __instance.Data.IsDead || !__instance.Data.Role.IsImpostor || __instance.Data.Disconnected) + { + int num = target ? target!.PlayerId : -1; + __instance.logger.Warning($"Bad kill from {__instance.PlayerId} to {num}"); + __instance.RpcMurderPlayer(target, false); + return; + } + + NetworkedPlayerInfo data = target!.Data; + if (data == null || data.IsDead || target.inVent || target.MyPhysics.Animations.IsPlayingEnterVentAnimation() || + target.MyPhysics.Animations.IsPlayingAnyLadderAnimation() || target.inMovingPlat) + { + __instance.logger.Warning("Invalid target data for kill"); + __instance.RpcMurderPlayer(target, false); + return; + } + + if (MeetingHud.Instance) + { + __instance.logger.Warning("Tried to kill while a meeting was starting"); + __instance.RpcMurderPlayer(target, false); + return; + } + + __instance.isKilling = true; + __instance.RpcMurderPlayer(target, true); + } + [HarmonyPrefix] [HarmonyPatch(nameof(PlayerControl.RpcMurderPlayer))] // ReSharper disable once InconsistentNaming diff --git a/MiraAPI/Patches/Roles/KillButtonPatches.cs b/MiraAPI/Patches/Roles/KillButtonPatches.cs index 2a04e9d..902a9e6 100644 --- a/MiraAPI/Patches/Roles/KillButtonPatches.cs +++ b/MiraAPI/Patches/Roles/KillButtonPatches.cs @@ -58,6 +58,11 @@ public static class KillButtonPatches return false; } + if (PlayerControl.LocalPlayer.Data.Role is not ICustomRole) + { + return true; + } + PlayerControl.LocalPlayer.RpcCustomMurder(__instance.currentTarget); __instance.SetTarget(null);