From 5c596f5e2fd6ea161b27351e43fdd90d36ac0b4f Mon Sep 17 00:00:00 2001 From: Rammelkast Date: Sun, 24 Oct 2021 10:46:51 +0200 Subject: [PATCH] Completed work on #132, changes to Aimbot check --- .../anticheatreloaded/check/Backend.java | 21 ------------- .../check/movement/AimbotCheck.java | 20 ++++++------ .../check/movement/FlightCheck.java | 31 ++++++++++--------- .../check/movement/SpeedCheck.java | 16 +++++++--- .../config/providers/Magic.java | 12 ------- .../event/EntityListener.java | 19 ------------ src/main/resources/checks.yml | 6 ++-- src/main/resources/magic.yml | 12 ------- 8 files changed, 41 insertions(+), 96 deletions(-) diff --git a/src/main/java/com/rammelkast/anticheatreloaded/check/Backend.java b/src/main/java/com/rammelkast/anticheatreloaded/check/Backend.java index c3475cf..8dbda09 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/check/Backend.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/check/Backend.java @@ -525,27 +525,6 @@ public class Backend { return isDoing(player, placedBlock, 0.1); } - public void logDamage(final Player player, final int type) { - long time; - switch (type) { - case 1: - time = magic.DAMAGE_TIME(); - break; - case 2: - time = magic.KNOCKBACK_DAMAGE_TIME(); - break; - case 3: - time = magic.EXPLOSION_DAMAGE_TIME(); - break; - default: - time = magic.DAMAGE_TIME(); - break; - - } - FlightCheck.MOVING_EXEMPT.put(player.getUniqueId(), System.currentTimeMillis() + time); - // Only map in which termination time is calculated beforehand. - } - public void logEnterExit(final Player player) { FlightCheck.MOVING_EXEMPT.put(player.getUniqueId(), System.currentTimeMillis() + magic.ENTERED_EXITED_TIME()); } diff --git a/src/main/java/com/rammelkast/anticheatreloaded/check/movement/AimbotCheck.java b/src/main/java/com/rammelkast/anticheatreloaded/check/movement/AimbotCheck.java index f41c1b9..73bd283 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/check/movement/AimbotCheck.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/check/movement/AimbotCheck.java @@ -50,17 +50,17 @@ public final class AimbotCheck { final float deltaPitch = movementManager.deltaPitch; final float deltaYaw = movementManager.deltaYaw; final float pitchAcceleration = Math.abs(deltaPitch - movementManager.lastDeltaPitch); - final float yawAcceleration = Math.abs(deltaYaw - movementManager.lastDeltaYaw); - if (deltaYaw > 3.0F && deltaPitch <= 10.0F && pitchAcceleration > 2.0F && yawAcceleration > 2.0F - && deltaPitch < deltaYaw) { - final double gcd = Utilities.computeGcd(deltaPitch, movementManager.lastDeltaPitch); - final double mod = player.getLocation().getPitch() % gcd; - final double maxGcd = checksConfig.getDouble(CheckType.AIMBOT, "maxGcd"); - final double maxMod = checksConfig.getDouble(CheckType.AIMBOT, "maxMod"); - if (gcd < maxGcd || mod < maxMod) { - return new CheckResult(CheckResult.Result.FAILED, "failed computational check (gcd=" + gcd + ", mod=" + mod + ")"); - } + final double gcd = Utilities.computeGcd(deltaPitch, movementManager.lastDeltaPitch); + final double mod = Math.abs(player.getLocation().getPitch() % gcd); + final double minAcceleration = checksConfig.getDouble(CheckType.AIMBOT, "minAcceleration"); + final double maxMod = checksConfig.getDouble(CheckType.AIMBOT, "maxMod"); + if (mod < maxMod && pitchAcceleration > minAcceleration + && (deltaPitch == 0.0f || (deltaPitch > 45.0f && deltaYaw > 45.0f))) { + return new CheckResult(CheckResult.Result.FAILED, + "failed computational check (gcd=" + Utilities.roundDouble(gcd, 4) + ", mod=" + + Utilities.roundDouble(mod, 4) + ", accel=" + Utilities.roundDouble(pitchAcceleration, 4) + + ")"); } return PASS; } diff --git a/src/main/java/com/rammelkast/anticheatreloaded/check/movement/FlightCheck.java b/src/main/java/com/rammelkast/anticheatreloaded/check/movement/FlightCheck.java index 4f99781..d09994e 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/check/movement/FlightCheck.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/check/movement/FlightCheck.java @@ -45,7 +45,7 @@ public final class FlightCheck { public static final Map MOVING_EXEMPT = new HashMap(); public static final Map GRAVITY_VIOLATIONS = new HashMap(); - + private static final CheckResult PASS = new CheckResult(CheckResult.Result.PASSED); private static final double GRAVITY_FRICTION = 0.9800000190734863D; @@ -79,7 +79,7 @@ public final class FlightCheck { // Start AirFlight if (checksConfig.isSubcheckEnabled(CheckType.FLIGHT, "airFlight") && movementManager.airTicks > minAirTicks - && !velocityTracker.isVelocitized() && movementManager.elytraEffectTicks <= 25) { + && movementManager.elytraEffectTicks <= 25) { // Config default base is 1200ms // Ping clamped to max. 1000 to prevent spoofing for an advantage int blockPlaceAccountingTime = (int) (checksConfig.getInteger(CheckType.FLIGHT, "airFlight", @@ -89,7 +89,7 @@ public final class FlightCheck { blockPlaceAccountingTime += checksConfig.getInteger(CheckType.FLIGHT, "airFlight", "accountForTpsDrops"); } - + final long lastPlacedBlock = AntiCheatReloaded.getManager().getBackend().placedBlock .containsKey(player.getUniqueId()) ? AntiCheatReloaded.getManager().getBackend().placedBlock.get(player.getUniqueId()) @@ -100,12 +100,16 @@ public final class FlightCheck { .isNearHalfblock(distance.getFrom().getBlock().getRelative(BlockFace.DOWN).getLocation())) { maxMotionY += 0.004D; } - + // Fixes water false positive - if (Utilities.isNearWater(player) || Utilities.isNearWater(distance.getFrom().clone().subtract(0, 0.51, 0))) { + if (Utilities.isNearWater(player) + || Utilities.isNearWater(distance.getFrom().clone().subtract(0, 0.51, 0))) { maxMotionY += 0.05; } - + + // Velocity adjustment + maxMotionY += velocityTracker.getVertical(); + if (movementManager.motionY > maxMotionY && movementManager.slimeInfluenceTicks <= 0 && !Utilities.isNearClimbable(distance.getTo().clone().subtract(0, 1.25, 0)) && !Utilities.isNearClimbable(distance.getTo().clone().subtract(0, 0.75, 0)) @@ -136,8 +140,7 @@ public final class FlightCheck { && Math.round(movementManager.motionY * 1000) != 248 && !(Math.round(movementManager.motionY * 1000) == 333 && Math.round(movementManager.lastMotionY * 1000) != 333) - && !velocityTracker.isVelocitized() - && !player.hasPotionEffect(PotionEffectType.JUMP) + && !velocityTracker.isVelocitized() && !player.hasPotionEffect(PotionEffectType.JUMP) && (System.currentTimeMillis() - movementManager.lastTeleport >= checksConfig .getInteger(CheckType.FLIGHT, "airClimb", "accountForTeleports")) && (!Utilities.isNearBed(distance.getTo()) || ((Utilities.isNearBed(distance.getTo()) @@ -161,18 +164,16 @@ public final class FlightCheck { if (checksConfig.isSubcheckEnabled(CheckType.FLIGHT, "airClimb") && movementManager.airTicks >= minAirTicks && movementManager.lastMotionY < 0 && movementManager.motionY > 0 - && !velocityTracker.isVelocitized() - && movementManager.elytraEffectTicks <= 25 + && movementManager.motionY > velocityTracker.getVertical() && movementManager.elytraEffectTicks <= 25 && (System.currentTimeMillis() - movementManager.lastTeleport >= checksConfig .getInteger(CheckType.FLIGHT, "airClimb", "accountForTeleports")) && !(Math.round(movementManager.motionY * 1000) == 396) && movementManager.airTicks == 15) { return new CheckResult(CheckResult.Result.FAILED, "AirClimb", "tried to climb air (mY=" + movementManager.motionY + ", at=" + movementManager.airTicks + ")"); } - - if (movementManager.airTicks >= minAirTicks && movementManager.motionY > 0 - && velocityTracker.getVertical() <= 0.0D && movementManager.slimeInfluenceTicks <= 0 - && movementManager.elytraEffectTicks <= 25 + + if (movementManager.airTicks >= minAirTicks && movementManager.motionY > 0 && !velocityTracker.isVelocitized() + && movementManager.slimeInfluenceTicks <= 0 && movementManager.elytraEffectTicks <= 25 && (System.currentTimeMillis() - movementManager.lastTeleport >= checksConfig .getInteger(CheckType.FLIGHT, "airClimb", "accountForTeleports"))) { return new CheckResult(CheckResult.Result.FAILED, "AirClimb", @@ -192,7 +193,7 @@ public final class FlightCheck { // Start Gravity if (checksConfig.isSubcheckEnabled(CheckType.FLIGHT, "gravity") && !movementManager.onGround - && movementManager.motionY < 0 && !velocityTracker.isVelocitized() + && movementManager.motionY < 0 && Math.abs(movementManager.motionY) > velocityTracker.getVertical() && (System.currentTimeMillis() - movementManager.lastTeleport >= checksConfig .getInteger(CheckType.FLIGHT, "gravity", "accountForTeleports")) && !Utilities.isNearWeb(player) && movementManager.elytraEffectTicks <= 25 diff --git a/src/main/java/com/rammelkast/anticheatreloaded/check/movement/SpeedCheck.java b/src/main/java/com/rammelkast/anticheatreloaded/check/movement/SpeedCheck.java index 991c81e..1dde289 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/check/movement/SpeedCheck.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/check/movement/SpeedCheck.java @@ -184,7 +184,7 @@ public final class SpeedCheck { } // Adjust for velocity - predict += velocityTracker.getHorizontal() * 0.8D; + limit += velocityTracker.getHorizontal(); if (distanceXZ - predict > limit) { return new CheckResult(CheckResult.Result.FAILED, "AirSpeed", @@ -233,7 +233,7 @@ public final class SpeedCheck { } // Add velocity - limit += velocityTracker.getHorizontal() * 0.8D; + limit += velocityTracker.getHorizontal(); if (initialAcceleration > limit) { return new CheckResult(CheckResult.Result.FAILED, "AirAcceleration", @@ -339,6 +339,9 @@ public final class SpeedCheck { if (movementManager.sneakingTicks > 1) { limit *= 0.68D; } + + // Velocity adjustment + limit += velocityTracker.getHorizontal(); if (distanceXZ - limit > 0) { return new CheckResult(CheckResult.Result.FAILED, "GroundSpeed", @@ -357,8 +360,10 @@ public final class SpeedCheck { return PASS; } - final MovementManager movementManager = AntiCheatReloaded.getManager().getUserManager() - .getUser(player.getUniqueId()).getMovementManager(); + final User user = AntiCheatReloaded.getManager().getUserManager() + .getUser(player.getUniqueId()); + final MovementManager movementManager = user.getMovementManager(); + final VelocityTracker velocityTracker = user.getVelocityTracker(); // Riptiding exemption if (movementManager.riptideTicks > 0) { return PASS; @@ -378,6 +383,9 @@ public final class SpeedCheck { if (movementManager.nearLiquidTicks > 6) { maxMotionY *= 1.0525D; } + + // Adjust for velocity + maxMotionY += velocityTracker.getVertical(); if (movementManager.motionY > maxMotionY && movementManager.slimeInfluenceTicks <= 0) { return new CheckResult(CheckResult.Result.FAILED, "VerticalSpeed", diff --git a/src/main/java/com/rammelkast/anticheatreloaded/config/providers/Magic.java b/src/main/java/com/rammelkast/anticheatreloaded/config/providers/Magic.java index 1c3a53f..ab49f61 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/config/providers/Magic.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/config/providers/Magic.java @@ -50,18 +50,6 @@ public interface Magic { * Time to exempt a player from moving because of joining the server; Type=SYSTEM, Leniency=INCREASE. */ public int JOIN_TIME(); - /** - * Time to exempt a player from moving because of taking damage; Type=SYSTEM, Leniency=INCREASE. - */ - public int DAMAGE_TIME(); - /** - * Time to exempt a player from moving because of taking damage with knockback effects; Type=SYSTEM, Leniency=INCREASE. - */ - public int KNOCKBACK_DAMAGE_TIME(); - /** - * Time to exempt a player from moving because of taking damage from an explosion; Type=SYSTEM, Leniency=INCREASE. - */ - public int EXPLOSION_DAMAGE_TIME(); /** * Time a player is considered to have a change in velocity; Type=SYSTEM, Leniency=INCREASE. */ diff --git a/src/main/java/com/rammelkast/anticheatreloaded/event/EntityListener.java b/src/main/java/com/rammelkast/anticheatreloaded/event/EntityListener.java index 3332afe..634f411 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/event/EntityListener.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/event/EntityListener.java @@ -19,10 +19,7 @@ package com.rammelkast.anticheatreloaded.event; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.entity.Creeper; import org.bukkit.entity.Player; -import org.bukkit.entity.TNTPrimed; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.entity.EntityDamageByEntityEvent; @@ -39,7 +36,6 @@ import com.rammelkast.anticheatreloaded.check.CheckType; import com.rammelkast.anticheatreloaded.check.combat.CriticalsCheck; import com.rammelkast.anticheatreloaded.check.combat.KillAuraCheck; import com.rammelkast.anticheatreloaded.check.movement.AimbotCheck; -import com.rammelkast.anticheatreloaded.util.VersionUtil; public class EntityListener extends EventListener { @@ -114,21 +110,6 @@ public class EntityListener extends EventListener { log(result.getMessage(), (Player)e.getDamager(), CheckType.AIMBOT, result.getSubCheck()); } } - } - if (event.getEntity() instanceof Player) { - Player player = (Player) event.getEntity(); - if (e.getDamager() instanceof Player) { - Player p = (Player) e.getDamager(); - getBackend().logDamage(p, 1); - int value = VersionUtil.getItemInHand(player).containsEnchantment(Enchantment.KNOCKBACK) ? 2 : 1; - getBackend().logDamage(player, value); - } else { - if (e.getDamager() instanceof TNTPrimed || e.getDamager() instanceof Creeper) { - getBackend().logDamage(player, 3); - } else { - getBackend().logDamage(player, 1); - } - } } if (e.getDamager() instanceof Player && event.getCause() == DamageCause.ENTITY_ATTACK) { Player player = (Player) e.getDamager(); diff --git a/src/main/resources/checks.yml b/src/main/resources/checks.yml index b3e7038..372d08c 100644 --- a/src/main/resources/checks.yml +++ b/src/main/resources/checks.yml @@ -193,10 +193,10 @@ killaura: aimbot: # Should this check be enabled? enabled: true - # Maximum gcd value for check to consider aim illegal - maxGcd: 0.002 + # Maximum pitch acceleration for check to consider aim illegal + minAcceleration: 0.5 # Maximum mod value for check to consider aim illegal - maxMod: 0.003 + maxMod: 0.0001 # Criticals check settings # Checks if the player tries to do a crit without needed conditions criticals: diff --git a/src/main/resources/magic.yml b/src/main/resources/magic.yml index 29a1e9e..f9df524 100644 --- a/src/main/resources/magic.yml +++ b/src/main/resources/magic.yml @@ -8,18 +8,6 @@ TELEPORT_TIME: 1500 # If your server is slow when a player joins, increasing this value is important # Shouldn't be lower than 1500 or higher than 5000 JOIN_TIME: 2000 -# Time to exempt a player from moving because of taking damage -# Can be decreased very slightly to increase detection -# Increase in case of false positives after taking damage -DAMAGE_TIME: 500 -# Time to exempt a player from moving because of taking damage with knockback effects -# Can be decreased very slightly to increase detection -# Increase in case of false positives after knockback -KNOCKBACK_DAMAGE_TIME: 2000 -# Time to exempt a player from moving because of taking damage from an explosion -# Can be decreased very slightly to increase detection -# Increasing in case of false positives after explosions -EXPLOSION_DAMAGE_TIME: 2500 # Time a player is considered to have a change in velocity VELOCITY_TIME: 1500 # Minimum travel distance for move to be considered a teleport and subsequently be ignored