diff --git a/Modules/AntiCheat/RPCHandlers/UpdateSystemHandler.cs b/Modules/AntiCheat/RPCHandlers/UpdateSystemHandler.cs index 26923f3..f761520 100644 --- a/Modules/AntiCheat/RPCHandlers/UpdateSystemHandler.cs +++ b/Modules/AntiCheat/RPCHandlers/UpdateSystemHandler.cs @@ -1,5 +1,6 @@ using BetterAmongUs.Helpers; using Hazel; +using UnityEngine; namespace BetterAmongUs.Modules.AntiCheat; @@ -30,13 +31,31 @@ public class UpdateSystemHandler : RPCHandler }; } + public static bool CheckConsoleDistance(PlayerControl? player, float distance = 2f) where T : PlayerTask, new() + { + bool isClose = false; + Console[]? consoles = new T().FindConsoles().ToArray(); + foreach (var console in consoles) + { + if (console == null) + { + isClose = true; + break; + } + isClose = Vector2.Distance(console.transform.position, player.GetCustomPosition()) < distance; + if (isClose) break; + } + + return isClose; + } + public override bool HandleAntiCheatCancel(PlayerControl? sender, MessageReader reader) { + if (GameState.IsHost && sender.IsHost()) return true; + MessageReader oldReader = MessageReader.Get(reader); byte count = reader.ReadByte(); - Logger.InGame($"{Enum.GetName(CatchedSystemType)}"); - if (ShipStatus.Instance.Systems.TryGetValue(CatchedSystemType, out ISystemType system)) { uint systemKey = (uint)CatchedSystemType; @@ -80,6 +99,16 @@ public class UpdateSystemHandler : RPCHandler return false; } + if (!switchSystem.IsActive) + { + return false; + } + + if (!CheckConsoleDistance(sender)) + { + return false; + } + return true; } @@ -87,13 +116,24 @@ public class UpdateSystemHandler : RPCHandler { if (system == null) return false; - if (system.TryCast(out var hqHudSystem)) + try { + var hqHudSystem = system.Cast(); return HandleHqHudSystem(sender, hqHudSystem, count); } - if (system.TryCast(out var HudOverrideSystem)) + catch { - return HandleHudOverrideSystem(sender, HudOverrideSystem, count); + + } + + try + { + var hudOverrideSystem = system.Cast(); + return HandleHudOverrideSystem(sender, hudOverrideSystem, count); + } + catch + { + } return true; @@ -101,7 +141,18 @@ public class UpdateSystemHandler : RPCHandler private static bool HandleHqHudSystem(PlayerControl? sender, HqHudSystemType hqHudSystem, byte count) { - if (count == 128) // Direct sabotage call from client, which is not possible, only the host should have this count when HandleSabotageSystem it's called + Logger.InGame("TEST"); + if ((count & 128) > 0) // Direct sabotage call from client, which is not possible, only the host should have this count when HandleSabotageSystem it's called + { + return false; + } + + if (!hqHudSystem.IsActive) + { + return false; + } + + if (!CheckConsoleDistance(sender, 2f)) { return false; } @@ -111,11 +162,22 @@ public class UpdateSystemHandler : RPCHandler private static bool HandleHudOverrideSystem(PlayerControl? sender, HudOverrideSystemType hudOverrideSystem, byte count) { + Logger.InGame("TEST"); if (count == 128) // Direct sabotage call from client, which is not possible, only the host should have this count when HandleSabotageSystem it's called { return false; } + if (!hudOverrideSystem.IsActive) + { + return false; + } + + if (!CheckConsoleDistance(sender, 2f)) + { + return false; + } + return true; } @@ -126,6 +188,11 @@ public class UpdateSystemHandler : RPCHandler return false; } + if (mushroomMixupSabotage.IsActive) + { + return false; + } + return true; } @@ -141,11 +208,34 @@ public class UpdateSystemHandler : RPCHandler private static bool HandleReactorSystem(PlayerControl? sender, ReactorSystemType reactorSystem, byte count) { - if (count == 128) // Direct sabotage call from client, which is not possible, only the host should have this count when HandleSabotageSystem it's called + Logger.InGame(count.ToString()); + if (count == 128 || count == 16) // Direct sabotage call from client, which is not possible, only the host should have this count when HandleSabotageSystem it's called { return false; } + if (!reactorSystem.IsActive) + { + return false; + } + + if (!CheckConsoleDistance(sender)) + { + return false; + } + + if (count.HasAnyBit(64)) + { + foreach (var tuple in reactorSystem.UserConsolePairs) + { + if (tuple.Item1 == sender.PlayerId) + { + Logger.InGame("TEST 1"); + return false; + } + } + } + return true; } @@ -156,6 +246,16 @@ public class UpdateSystemHandler : RPCHandler return false; } + if (!heliSabotageSystem.IsActive) + { + return false; + } + + if (!CheckConsoleDistance(sender)) + { + return false; + } + return true; } @@ -166,6 +266,16 @@ public class UpdateSystemHandler : RPCHandler return false; } + if (!lifeSuppSystem.IsActive) + { + return false; + } + + if (!CheckConsoleDistance(sender)) + { + return false; + } + return true; } } \ No newline at end of file