From 293e1b0ac0f31f52dd5397f1c0485b2ff31f8cb7 Mon Sep 17 00:00:00 2001 From: D1GQ Date: Sun, 18 Aug 2024 03:21:44 -0500 Subject: [PATCH] sabo fixes --- Modules/AntiCheat.cs | 132 ++++++++++++++++++++++++++++--- Modules/ExtendedPlayerControl.cs | 3 + Modules/ExtendedPlayerInfo.cs | 2 + Modules/Utils.cs | 6 +- main.cs | 2 +- 5 files changed, 132 insertions(+), 13 deletions(-) diff --git a/Modules/AntiCheat.cs b/Modules/AntiCheat.cs index 35d1126..a93df9b 100644 --- a/Modules/AntiCheat.cs +++ b/Modules/AntiCheat.cs @@ -4,6 +4,7 @@ using Hazel; using InnerNet; using UnityEngine; using UnityEngine.Purchasing; +using UnityEngine.Rendering; namespace BetterAmongUs; @@ -294,6 +295,15 @@ class AntiCheat player.BetterData().LastTaskId = taskId; } + if (callId is (byte)RpcCalls.CloseDoorsOfType) + { + if (!player.IsImpostorTeam()) + { + BetterNotificationManager.NotifyCheat(player, $"Invalid Action RPC: {Enum.GetName((RpcCalls)callId)}"); + Logger.LogCheat($"{player.Data.PlayerName} {Enum.GetName((RpcCalls)callId)}: {!player.IsImpostorTeam()}"); + } + } + if (callId is (byte)RpcCalls.Pet or (byte)RpcCalls.CancelPet) { if (player?.CurrentOutfit?.PetId == "pet_EmptyPet") @@ -314,27 +324,129 @@ class AntiCheat // Check game states when sabotaging public static bool RpcUpdateSystemCheck(PlayerControl player, SystemTypes systemType, byte amount) { - if (PlayerControl.LocalPlayer == null || player == null || player == PlayerControl.LocalPlayer || player.BetterData().IsBetterHost || !IsEnabled || !Main.AntiCheat.Value - || GameStates.IsBetterHostLobby && !GameStates.IsHost) return true; + byte hostNum = 128; // Only host should ever send this number + byte singleFixNum = 0; + byte minLightNum = 0; + byte MaxLightNum = 4; + byte fixNum = 16; // 16 and 17 + byte openPanelNum = 64; // 64 and 65 + byte closePanelNum = 32; // 32 and 33 + // Set fixing status if (Utils.SystemTypeIsSabotage(systemType)) { - if (!player.IsImpostorTeam() || !GameStates.IsSystemActive(systemType) && GameStates.IsAnySabotageActive() - || ShipStatus.Instance.AllDoors.ToArray().Any(door => !door.IsOpen)) + if (amount == openPanelNum && !player.BetterData().IsFixingPanelSabotage) + { + player.BetterData().OpenSabotageNum = 1; + } + else if (amount == openPanelNum + 1 && !player.BetterData().IsFixingPanelSabotage) + { + player.BetterData().OpenSabotageNum = 2; + } + + if (amount == closePanelNum && player.BetterData().OpenSabotageNum == 1) + { + player.BetterData().OpenSabotageNum = 0; + } + else if (amount == closePanelNum + 1 && player.BetterData().OpenSabotageNum == 2) + { + player.BetterData().OpenSabotageNum = 0; + } + } + + if (!GameStates.IsHost || PlayerControl.LocalPlayer == null || player == null || player == PlayerControl.LocalPlayer + || player.BetterData().IsBetterHost || !IsEnabled || !Main.AntiCheat.Value + || GameStates.IsBetterHostLobby && !GameStates.IsHost) return true; + + // Single Fix: 0 + // Lights: 0-1-2-3-4 + // Fix 1: 16 + // Fix 2: 17 + // Panel 1: Open/Hold 64 - Close/Release 32 + // Panel 2: Open/Hold 65 - Close/Release 33 + // Cheat Sabo: 128 + + // Activate sabotage + if (systemType == SystemTypes.Sabotage) + { + SystemTypes SaboType = (SystemTypes)amount; + + if (!player.IsImpostorTeam() || GameStates.IsAnySabotageActive() || !Utils.SystemTypeIsSabotage(SaboType)) + { + BetterNotificationManager.NotifyCheat(player, $"Invalid Action RPC: {Enum.GetName(SaboType)}"); + Logger.LogCheat($"{player.Data.PlayerName} {Enum.GetName(SaboType)}: {!player.IsImpostorTeam()} || {GameStates.IsAnySabotageActive()} " + + $"|| {!Utils.SystemTypeIsSabotage(SaboType)}"); + return false; + } + } + + // Fix sabotage + else if (Utils.SystemTypeIsSabotage(systemType)) + { + if (amount == hostNum && !player.IsHost()) { BetterNotificationManager.NotifyCheat(player, $"Invalid Action RPC: {Enum.GetName(systemType)}"); - Logger.LogCheat($"{player.Data.PlayerName} {Enum.GetName(systemType)} Start Sabotage: {!player.IsImpostorTeam()} || {!GameStates.IsSystemActive(systemType)} " + - $"&& {GameStates.IsAnySabotageActive()} || {ShipStatus.Instance.AllDoors.ToArray().Any(door => !door.IsOpen)}"); + Logger.LogCheat($"{player.Data.PlayerName} {Enum.GetName(systemType)}: {amount == hostNum} && {!player.IsHost()}"); return false; } - // Fix Sabo - if (amount == 16) + if (!GameStates.IsSystemActive(systemType)) { - if (!GameStates.IsSystemActive(systemType)) + if (systemType is SystemTypes.Electrical) { BetterNotificationManager.NotifyCheat(player, $"Invalid Action RPC: {Enum.GetName(systemType)}"); - Logger.LogCheat($"{player.Data.PlayerName} {Enum.GetName(systemType)} Fix Sabotage: {!GameStates.IsSystemActive(systemType)}"); + Logger.LogCheat($"{player.Data.PlayerName} {Enum.GetName(systemType)}: {systemType is SystemTypes.Electrical}"); + } + + return false; + } + + if (player.BetterData().IsFixingPanelSabotage) + { + if (player.BetterData().OpenSabotageNum == 0) + { + BetterNotificationManager.NotifyCheat(player, $"Invalid Action RPC: {Enum.GetName(systemType)}"); + Logger.LogCheat($"{player.Data.PlayerName} {Enum.GetName(systemType)}: {player.BetterData().OpenSabotageNum == 0}"); + return false; + } + + if (amount == openPanelNum && amount == openPanelNum + 1) + { + BetterNotificationManager.NotifyCheat(player, $"Invalid Action RPC: {Enum.GetName(systemType)}"); + Logger.LogCheat($"{player.Data.PlayerName} {Enum.GetName(systemType)}: {amount == openPanelNum} && {amount == openPanelNum + 1}"); + return false; + } + + if (player.BetterData().OpenSabotageNum == 1 && amount == openPanelNum + 1 + || player.BetterData().OpenSabotageNum == 2 && amount == openPanelNum) + { + BetterNotificationManager.NotifyCheat(player, $"Invalid Action RPC: {Enum.GetName(systemType)}"); + Logger.LogCheat($"{player.Data.PlayerName} {Enum.GetName(systemType)}: {player.BetterData().OpenSabotageNum == 1} && {amount == openPanelNum + 1} " + + $"|| {player.BetterData().OpenSabotageNum == 2} && {amount == openPanelNum}"); + return false; + } + } + else + { + if (amount != fixNum && amount != fixNum + 1 + && amount != closePanelNum && amount != closePanelNum + 1 + && amount > MaxLightNum) + { + BetterNotificationManager.NotifyCheat(player, $"Invalid Action RPC: {Enum.GetName(systemType)}"); + Logger.LogCheat($"{player.Data.PlayerName} {Enum.GetName(systemType)}: {amount != fixNum} && {amount != fixNum + 1}" + + $" && {amount != closePanelNum} && {amount != closePanelNum + 1}" + + $" && {amount > MaxLightNum}"); + return false; + } + + if (systemType == SystemTypes.Electrical) + { + if (amount > MaxLightNum) + { + BetterNotificationManager.NotifyCheat(player, $"Invalid Action RPC: {Enum.GetName(systemType)}"); + Logger.LogCheat($"{player.Data.PlayerName} {Enum.GetName(systemType)}: {amount > MaxLightNum}"); + return false; + } } } } diff --git a/Modules/ExtendedPlayerControl.cs b/Modules/ExtendedPlayerControl.cs index 168b03d..8fa2b42 100644 --- a/Modules/ExtendedPlayerControl.cs +++ b/Modules/ExtendedPlayerControl.cs @@ -114,7 +114,10 @@ static class ExtendedPlayerControl player.RpcSetName(setReasonInfo + ""); } + byte savePlayerId = player.PlayerId; + string saveName = player.Data.PlayerName; AmongUsClient.Instance.KickPlayer(player.GetClientId(), ban); + GameData.Instance.GetPlayerById(savePlayerId).PlayerName = saveName; } // RPCs diff --git a/Modules/ExtendedPlayerInfo.cs b/Modules/ExtendedPlayerInfo.cs index edf7f3d..259795a 100644 --- a/Modules/ExtendedPlayerInfo.cs +++ b/Modules/ExtendedPlayerInfo.cs @@ -12,6 +12,8 @@ public class ExtendedPlayerInfo public bool BannedByAntiCheat { get; set; } = false; // Track Game Info + public int OpenSabotageNum { get; set; } = 0; + public bool IsFixingPanelSabotage => OpenSabotageNum != 0; public float TimeSinceLastTask { get; set; } = 5f; public uint LastTaskId { get; set; } = 0; public int TimesCalledMeeting { get; set; } = 0; diff --git a/Modules/Utils.cs b/Modules/Utils.cs index ea46f90..024836a 100644 --- a/Modules/Utils.cs +++ b/Modules/Utils.cs @@ -68,13 +68,15 @@ public static class Utils or SystemTypes.Comms or SystemTypes.LifeSupp or SystemTypes.MushroomMixupSabotage - or SystemTypes.HeliSabotage; + or SystemTypes.HeliSabotage + or SystemTypes.Electrical; public static bool SystemTypeIsSabotage(int typeNum) => (SystemTypes)typeNum is SystemTypes.Reactor or SystemTypes.Laboratory or SystemTypes.Comms or SystemTypes.LifeSupp or SystemTypes.MushroomMixupSabotage - or SystemTypes.HeliSabotage; + or SystemTypes.HeliSabotage + or SystemTypes.Electrical; // Get players HashPuid public static string GetHashPuid(PlayerControl player) { diff --git a/main.cs b/main.cs index 0ee4b3e..486000c 100644 --- a/main.cs +++ b/main.cs @@ -24,7 +24,7 @@ public class Main : BasePlugin { public const ReleaseTypes ReleaseBuildType = ReleaseTypes.Release; public const string CanaryNum = "0"; - public const string HotfixNum = "1"; + public const string HotfixNum = "2"; public const bool IsHotFix = true; public const string PluginGuid = "com.d1gq.betteramongus"; public const string PluginVersion = "1.0.3";