From 0f1962394a68be22e197d9562498de04d45dfc86 Mon Sep 17 00:00:00 2001 From: XtraCube <72575280+XtraCube@users.noreply.github.com> Date: Fri, 19 Sep 2025 21:07:22 -0400 Subject: [PATCH] un-inline rpcendgame --- MiraAPI/Patches/Events/EndGamePatches.cs | 93 +++++++++++++++++++++++- 1 file changed, 92 insertions(+), 1 deletion(-) diff --git a/MiraAPI/Patches/Events/EndGamePatches.cs b/MiraAPI/Patches/Events/EndGamePatches.cs index 558c468..13291c6 100644 --- a/MiraAPI/Patches/Events/EndGamePatches.cs +++ b/MiraAPI/Patches/Events/EndGamePatches.cs @@ -1,4 +1,6 @@ -using HarmonyLib; +using System.Linq; +using AmongUs.Data; +using HarmonyLib; using MiraAPI.Events; using MiraAPI.Events.Vanilla.Gameplay; using MiraAPI.GameEnd; @@ -7,6 +9,95 @@ namespace MiraAPI.Patches.Events; internal static class EndGamePatches { + // To un-inline RpcEndGame + [HarmonyPatch(typeof(LogicGameFlowNormal), nameof(LogicGameFlowNormal.CheckEndCriteria))] + public static class LogicGameFlowNormalPatches + { + public static void Prefix(LogicGameFlowNormal __instance, ref bool __runOriginal) + { + __runOriginal = false; + if (!GameData.Instance) + { + return; + } + + if (ShipStatus.Instance.Systems.TryGetValue(SystemTypes.LifeSupp, out var systemType)) + { + var lifeSuppSystemType = systemType.Cast(); + if (lifeSuppSystemType.Countdown < 0f) + { + __instance.EndGameForSabotage(); + lifeSuppSystemType.Countdown = 10000f; + } + } + + foreach (var systemType2 in ShipStatus.Instance.Systems.Values) + { + var criticalSabotage = systemType2.TryCast(); + if (criticalSabotage is { Countdown: < 0f }) + { + __instance.EndGameForSabotage(); + criticalSabotage.ClearSabotage(); + } + } + + var playerCounts = __instance.GetPlayerCounts(); + var item = playerCounts.Item1; + var item2 = playerCounts.Item2; + var item3 = playerCounts.Item3; + if (item2 <= 0 && (!TutorialManager.InstanceExists || item3 > 0)) + { + if (!TutorialManager.InstanceExists) + { + var gameOverReason = GameOverReason.CrewmatesByVote; + __instance.Manager.RpcEndGame(gameOverReason, !DataManager.Player.Ads.HasPurchasedAdRemoval); + return; + } + + if (!Minigame.Instance) + { + HudManager.Instance.ShowPopUp( + TranslationController.Instance.GetString(StringNames.GameOverImpostorDead)); + __instance.Manager.ReviveEveryoneFreeplay(); + } + } + else if (item <= item2) + { + if (!TutorialManager.InstanceExists) + { + var gameOverReason2 = GameData.LastDeathReason switch + { + DeathReason.Exile => GameOverReason.ImpostorsByVote, + DeathReason.Kill => GameOverReason.ImpostorsByKill, + _ => GameOverReason.CrewmateDisconnect, + }; + + __instance.Manager.RpcEndGame(gameOverReason2, !DataManager.Player.Ads.HasPurchasedAdRemoval); + return; + } + + HudManager.Instance.ShowPopUp(TranslationController.Instance.GetString(StringNames.GameOverImpostorKills)); + __instance.Manager.ReviveEveryoneFreeplay(); + } + else + { + if (!TutorialManager.InstanceExists) + { + __instance.Manager.CheckEndGameViaTasks(); + return; + } + + if (PlayerControl.LocalPlayer.myTasks.ToArray().All(t => t.IsComplete)) + { + HudManager.Instance.ShowPopUp( + TranslationController.Instance.GetString( + StringNames.GameOverTaskWin)); + ShipStatus.Instance.Begin(); + } + } + } + } + [HarmonyPatch(typeof(GameManager), nameof(GameManager.RpcEndGame))] public static class GameManagerPatches {