From 854df3b89b43d7316f283b11aefa4d3d5872487e Mon Sep 17 00:00:00 2001 From: D1GQ Date: Wed, 31 Jul 2024 00:46:45 -0500 Subject: [PATCH] Modded Protocol toggleable --- Modules/ExtendedPlayerControl.cs | 1 + Modules/GameState.cs | 4 +++- Modules/RPC.cs | 2 ++ Patches/ClientOptionsPatch.cs | 20 +++++++++++++++++--- Patches/PingTrackerPatch.cs | 5 +++++ Patches/ServerVersionPatch.cs | 14 ++++++++++++-- 6 files changed, 40 insertions(+), 6 deletions(-) diff --git a/Modules/ExtendedPlayerControl.cs b/Modules/ExtendedPlayerControl.cs index 76d820a..9fe3d4b 100644 --- a/Modules/ExtendedPlayerControl.cs +++ b/Modules/ExtendedPlayerControl.cs @@ -100,6 +100,7 @@ static class ExtendedPlayerControl public static void RpcTeleport(this PlayerControl player, Vector2 position) { if (!GameStates.IsHost) return; + if (!GameStates.IsModdedProtocol) return; var cancelTeleport = false; diff --git a/Modules/GameState.cs b/Modules/GameState.cs index 140e0eb..66deb8a 100644 --- a/Modules/GameState.cs +++ b/Modules/GameState.cs @@ -1,4 +1,5 @@ using AmongUs.GameOptions; +using BetterAmongUs.Patches; namespace BetterAmongUs; @@ -23,7 +24,8 @@ public static class GameStates public static bool IsInGamePlay => (InGame && !IsLobby && !IsInIntro && IsShip) || IsFreePlay; public static bool IsEnded => AmongUsClient.Instance?.GameState == InnerNet.InnerNetClient.GameStates.Ended; public static bool IsNotJoined => AmongUsClient.Instance?.GameState == InnerNet.InnerNetClient.GameStates.NotJoined; - public static bool IsOnlineGame => AmongUsClient.Instance?.NetworkMode == NetworkModes.OnlineGame; + public static bool IsOnlineGame => AmongUsClient.Instance?.NetworkMode == NetworkModes.OnlineGame; + public static bool IsModdedProtocol => ServerUpdatePatch.IsModdedProtocol; public static bool IsVanillaServer { get diff --git a/Modules/RPC.cs b/Modules/RPC.cs index 2890bd1..60b8a29 100644 --- a/Modules/RPC.cs +++ b/Modules/RPC.cs @@ -94,6 +94,8 @@ internal static class RPC return; } + if (!GameStates.IsModdedProtocol) return; + PlayerControl asPlayer = Main.AllPlayerControls.Where(pc => pc.IsAlive()).OrderBy(pc => pc == PlayerControl.LocalPlayer ? 0 : 1).First(); var oldName = asPlayer.CurrentOutfit.PlayerName; diff --git a/Patches/ClientOptionsPatch.cs b/Patches/ClientOptionsPatch.cs index ba7777e..05c78aa 100644 --- a/Patches/ClientOptionsPatch.cs +++ b/Patches/ClientOptionsPatch.cs @@ -11,6 +11,7 @@ public static class OptionsMenuBehaviourPatch { private static ClientOptionItem AntiCheat; private static ClientOptionItem BetterHost; + private static ClientOptionItem ModdedProtocol; private static ClientOptionItem BetterRoleAlgorithma; private static ClientOptionItem LobbyPlayerInfo; private static ClientOptionItem DisableLobbyTheme; @@ -22,9 +23,17 @@ public static class OptionsMenuBehaviourPatch [HarmonyPrefix] public static void Start_Postfix(OptionsMenuBehaviour __instance) { - static bool toggleCheckInGame(string buttonName) + static bool toggleCheckInGamePlay(string buttonName) { bool flag = GameStates.IsInGame && !GameStates.IsLobby || GameStates.IsFreePlay; + if (flag) + BetterNotificationManager.Notify($"Unable to toggle {buttonName} while in gameplay!", 2.5f); + + return flag; + } + static bool toggleCheckInGame(string buttonName) + { + bool flag = GameStates.IsInGame; if (flag) BetterNotificationManager.Notify($"Unable to toggle {buttonName} while in game!", 2.5f); @@ -40,7 +49,7 @@ public static class OptionsMenuBehaviourPatch if (BetterHost == null || BetterHost.ToggleButton == null) { - BetterHost = ClientOptionItem.Create("Better Host", Main.BetterHost, __instance, BetterHostButtonToggle, () => !toggleCheckInGame("Better Host")); + BetterHost = ClientOptionItem.Create("Better Host", Main.BetterHost, __instance, BetterHostButtonToggle, () => !toggleCheckInGamePlay("Better Host")); static void BetterHostButtonToggle() { var flag = GameStates.IsHost && Main.BetterHost.Value; @@ -51,11 +60,16 @@ public static class OptionsMenuBehaviourPatch RPC.SyncAllNames(force: true); } + } + + if (ModdedProtocol == null || ModdedProtocol.ToggleButton == null) + { + ModdedProtocol = ClientOptionItem.Create("Modded Protocol", Main.ModdedProtocol, __instance, toggleCheck: () => !toggleCheckInGame("Modded Protocol")); } if (BetterRoleAlgorithma == null || BetterRoleAlgorithma.ToggleButton == null) { - BetterRoleAlgorithma = ClientOptionItem.Create("Better Role Algorithma", Main.BetterRoleAlgorithma, __instance, toggleCheck: () => !toggleCheckInGame("Better Role Algorithma")); + BetterRoleAlgorithma = ClientOptionItem.Create("Better Role Algorithma", Main.BetterRoleAlgorithma, __instance, toggleCheck: () => !toggleCheckInGamePlay("Better Role Algorithma")); } if (LobbyPlayerInfo == null || LobbyPlayerInfo.ToggleButton == null) diff --git a/Patches/PingTrackerPatch.cs b/Patches/PingTrackerPatch.cs index f6430a2..40e6735 100644 --- a/Patches/PingTrackerPatch.cs +++ b/Patches/PingTrackerPatch.cs @@ -31,6 +31,11 @@ public class PingTrackerPatch sb.Append("Better Host: Enabled\n"); } + if (GameStates.IsModdedProtocol) + { + sb.Append("Modded Protocol: Enabled\n"); + } + if (Main.ShowFPS.Value) { float FPSNum = 1.0f / Time.deltaTime; diff --git a/Patches/ServerVersionPatch.cs b/Patches/ServerVersionPatch.cs index d35ee94..028b263 100644 --- a/Patches/ServerVersionPatch.cs +++ b/Patches/ServerVersionPatch.cs @@ -7,6 +7,11 @@ namespace BetterAmongUs.Patches; [HarmonyPatch(typeof(Constants), nameof(Constants.GetBroadcastVersion))] class ServerUpdatePatch { + + private static int VanillaVersionServer = 0; + private static int ModdedVersionServer = 0; + public static bool IsModdedProtocol => ModdedVersionServer == VanillaVersionServer + 25; + static void Postfix(ref int __result) { if (GameStates.IsLocalGame) @@ -15,7 +20,12 @@ class ServerUpdatePatch } if (GameStates.IsOnlineGame) { - // __result += 25; + VanillaVersionServer = __result; + if (Main.ModdedProtocol.Value) + { + __result += 25; + } + ModdedVersionServer = __result; Logger.Log($"IsOnlineGame: {__result}", "VersionServer"); } } @@ -25,7 +35,7 @@ public static class IsVersionModdedPatch { public static bool Prefix(ref bool __result) { - __result = true; + __result = ServerUpdatePatch.IsModdedProtocol; return false; } } \ No newline at end of file