diff --git a/EHR.csproj b/EHR.csproj index 70d6618b6..b2a60e93b 100644 --- a/EHR.csproj +++ b/EHR.csproj @@ -33,7 +33,7 @@ - + diff --git a/Modules/AntiBlackout.cs b/Modules/AntiBlackout.cs index f9cc50476..aec72dd57 100644 --- a/Modules/AntiBlackout.cs +++ b/Modules/AntiBlackout.cs @@ -126,10 +126,10 @@ public static class AntiBlackout else { if (pc.AmOwner && Utils.TempReviveHostRunning) continue; - + // Ensure that the players who are considered dead by the mod are actually dead in the game. - pc.RpcSetRoleGlobal(pc.GetGhostRoleBasis()); - + pc.RpcExiled(); + if (GhostRolesManager.AssignedGhostRoles.TryGetValue(pc.PlayerId, out var ghostRole) && ghostRole.Instance.RoleTypes == RoleTypes.GuardianAngel) pc.RpcResetAbilityCooldown(); } diff --git a/Modules/CustomRpcSender.cs b/Modules/CustomRpcSender.cs index 674bafb58..83b63e11f 100644 --- a/Modules/CustomRpcSender.cs +++ b/Modules/CustomRpcSender.cs @@ -708,13 +708,17 @@ public static class CustomRpcSenderExtensions newSender = sender; return hasValue; } - - public static bool RpcExileV2(this CustomRpcSender sender, PlayerControl player) + public static bool RpcExiled(this CustomRpcSender sender, PlayerControl target, bool autoStartRpc = true, int targetClientId = -1, bool exileForHost = true) { - player.Exiled(); - sender.AutoStartRpc(player.NetId, RpcCalls.Exiled); - sender.EndRpc(); - FixedUpdatePatch.LoversSuicide(player.PlayerId); + if (exileForHost) target.Exiled(); + if (autoStartRpc) sender.AutoStartRpc(target.NetId, RpcCalls.Exiled, targetClientId).EndRpc(); + else sender.StartRpc(target.NetId, RpcCalls.Exiled).EndRpc(); + return true; + } + public static bool RpcExileV2(this CustomRpcSender sender, PlayerControl target, bool autoStartRpc = true, int targetClientId = -1, bool exileForHost = true) + { + sender.RpcExiled(target, autoStartRpc, targetClientId, exileForHost); + FixedUpdatePatch.LoversSuicide(target.PlayerId); return true; } diff --git a/Modules/ExtendedPlayerControl.cs b/Modules/ExtendedPlayerControl.cs index 08718c0ff..13f9f59cd 100644 --- a/Modules/ExtendedPlayerControl.cs +++ b/Modules/ExtendedPlayerControl.cs @@ -1723,10 +1723,7 @@ internal static class ExtendedPlayerControl var sender = CustomRpcSender.Create("RpcResetInvisibility", SendOption.Reliable); sender.StartMessage(pc.OwnerId); - sender.StartRpc(player.NetId, RpcCalls.SetRole) - .Write((ushort)player.GetGhostRoleBasis()) - .Write(true) - .EndRpc(); + sender.RpcExiled(player, autoStartRpc: false, exileForHost: false); RoleTypes role = Utils.GetRoleMap(pc.PlayerId, player.PlayerId).RoleType; sender.StartRpc(player.NetId, RpcCalls.SetRole) .Write((ushort)role) @@ -1969,11 +1966,15 @@ internal static class ExtendedPlayerControl return count.Item1 >= count.Item2; } - public static void RpcExileV2(this PlayerControl player) + public static void RpcExiled(this PlayerControl player) { player.Exiled(); MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(player.NetId, (byte)RpcCalls.Exiled, SendOption.Reliable); AmongUsClient.Instance.FinishRpcImmediately(writer); + } + public static void RpcExileV2(this PlayerControl player) + { + player.RpcExiled(); FixedUpdatePatch.LoversSuicide(player.PlayerId); } diff --git a/Patches/ClientPatch.cs b/Patches/ClientPatch.cs index 557e493a2..0e1664b58 100644 --- a/Patches/ClientPatch.cs +++ b/Patches/ClientPatch.cs @@ -1,11 +1,11 @@ -using System; -using System.Linq; -using System.Reflection; using AmongUs.Data; using EHR.Modules; using HarmonyLib; using Il2CppInterop.Runtime.InteropTypes; using InnerNet; +using System; +using System.Linq; +using System.Reflection; using TMPro; using UnityEngine; using static EHR.Translator; @@ -169,17 +169,19 @@ static class CheckOnlinePermissionsPatch [HarmonyPatch] internal static class AuthTimeoutPatch { - [HarmonyPatch(typeof(AuthManager._CoConnect_d__4), nameof(AuthManager._CoConnect_d__4.MoveNext))] - [HarmonyPatch(typeof(AuthManager._CoWaitForNonce_d__6), nameof(AuthManager._CoWaitForNonce_d__6.MoveNext))] - [HarmonyPrefix] // From Reactor.gg // https://github.com/NuclearPowered/Reactor/blob/master/Reactor/Patches/Miscellaneous/CustomServersPatch.cs - public static bool CoWaitforNoncePrefix(ref bool __result) + [HarmonyPatch(typeof(AuthManager), nameof(AuthManager.CoConnect))] + [HarmonyPrefix] + public static bool CoConnect_Prefix() { - if (GameStates.CurrentServerType is GameStates.ServerType.Vanilla or GameStates.ServerType.Local) return true; - - __result = false; - return false; + return GameStates.CurrentServerType is GameStates.ServerType.Vanilla or GameStates.ServerType.Local; + } + [HarmonyPatch(typeof(AuthManager), nameof(AuthManager.CoWaitForNonce))] + [HarmonyPrefix] + public static bool CoWaitforNonce_Prefix() + { + return GameStates.CurrentServerType is GameStates.ServerType.Vanilla or GameStates.ServerType.Local; } // If you don't patch this, you still need to wait for 5 s. diff --git a/Patches/DleksPatch.cs b/Patches/DleksPatch.cs index 4c3fc47aa..2afd7daeb 100644 --- a/Patches/DleksPatch.cs +++ b/Patches/DleksPatch.cs @@ -45,40 +45,6 @@ internal static class AllMapIconsPatch catch (Exception e) { Utils.ThrowException(e); } } } - -[HarmonyPatch(typeof(AmongUsClient._CoStartGameHost_d__28), nameof(AmongUsClient._CoStartGameHost_d__28.MoveNext))] -public static class DleksPatch -{ - public static bool Prepare() - { - return !OperatingSystem.IsAndroid(); - } - - public static bool Prefix(AmongUsClient._CoStartGameHost_d__28 __instance, ref bool __result) - { - if (__instance.__1__state != 0) return true; - - __instance.__1__state = -1; - if (LobbyBehaviour.Instance) LobbyBehaviour.Instance.Despawn(); - - if (ShipStatus.Instance) - { - __instance.__2__current = null; - __instance.__1__state = 2; - __result = true; - return false; - } - - // removed dleks check as it's always false - int num2 = GameOptionsManager.Instance.CurrentGameOptions.MapId == 6 && SubmergedCompatibility.Loaded ? 6 : Mathf.Clamp(GameOptionsManager.Instance.CurrentGameOptions.MapId, 0, Constants.MapNames.Length - 1); - __instance.__2__current = __instance.__4__this.ShipLoadingAsyncHandle = __instance.__4__this.ShipPrefabs[num2].InstantiateAsync(); - __instance.__1__state = 1; - - __result = true; - return false; - } -} - [HarmonyPatch(typeof(StringOption), nameof(StringOption.Start))] public static class AutoselectDleksPatch { diff --git a/Patches/ExilePatch.cs b/Patches/ExilePatch.cs index d57b2b7ad..5c6283e7b 100644 --- a/Patches/ExilePatch.cs +++ b/Patches/ExilePatch.cs @@ -220,33 +220,11 @@ internal static class ExileControllerWrapUpPatch [HarmonyPatch(typeof(AirshipExileController), nameof(AirshipExileController.WrapUpAndSpawn))] private static class AirshipExileControllerPatchAndroid { - public static bool Prepare() - { - return OperatingSystem.IsAndroid(); - } - public static void Postfix(AirshipExileController __instance) - { - try { WrapUpPostfix(__instance.initData.networkedPlayer); } - finally { WrapUpFinalizer(); } - } - } - - [HarmonyPatch(typeof(AirshipExileController._WrapUpAndSpawn_d__11), nameof(AirshipExileController._WrapUpAndSpawn_d__11.MoveNext))] - private static class AirshipExileControllerPatch - { - public static bool Prepare() - { - return !OperatingSystem.IsAndroid(); - } - - public static void Postfix(AirshipExileController._WrapUpAndSpawn_d__11 __instance, ref bool __result) { if (Main.LIMap) return; - if (__result) return; - - try { WrapUpPostfix(__instance.__4__this.initData.networkedPlayer); } + try { WrapUpPostfix(__instance.initData.networkedPlayer); } finally { WrapUpFinalizer(); } } } diff --git a/Roles/Standard/Neutral/Killing/SoulCollector.cs b/Roles/Standard/Neutral/Killing/SoulCollector.cs index 4c4bb71dc..2f2bad492 100644 --- a/Roles/Standard/Neutral/Killing/SoulCollector.cs +++ b/Roles/Standard/Neutral/Killing/SoulCollector.cs @@ -94,7 +94,7 @@ public class SoulCollector : RoleBase { var sender = CustomRpcSender.Create("SoulCollector Kill: Target", SendOption.Reliable); - sender.RpcSetRole(target, target.GetGhostRoleBasis(), target.OwnerId); + sender.RpcExiled(target, targetClientId: target.OwnerId, exileForHost: false); sender.SendMessage(); } @@ -113,10 +113,7 @@ public class SoulCollector : RoleBase toExile.ForEach(x => { Main.AllPlayerSpeed[x.PlayerId] = Main.RealOptionsData.GetFloat(FloatOptionNames.PlayerSpeedMod); - sender.StartRpc(x.NetId, RpcCalls.SetRole) - .Write((ushort)x.GetGhostRoleBasis()) - .Write(true) - .EndRpc(); + sender.RpcExiled(x, autoStartRpc: false); }); sender.SendMessage(); }