From df005b41816f5ddacd9966655f56bf258b570751 Mon Sep 17 00:00:00 2001 From: asofold Date: Wed, 6 Feb 2013 18:43:34 +0100 Subject: [PATCH] More grace to velocity handling, configurable. Before full revert or recode: a moderate (smaller than before) minimal grace amount for the counters is used now. --- .../checks/moving/MovingConfig.java | 3 ++ .../nocheatplus/checks/moving/MovingData.java | 6 ++-- .../checks/moving/MovingListener.java | 29 ++++++++++++++----- .../checks/moving/SurvivalFly.java | 8 +++-- .../nocheatplus/config/ConfPaths.java | 5 +++- .../nocheatplus/config/DefaultConfig.java | 3 ++ 6 files changed, 41 insertions(+), 13 deletions(-) diff --git a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingConfig.java b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingConfig.java index 5b560210..7fbd1d59 100644 --- a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingConfig.java +++ b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingConfig.java @@ -110,6 +110,8 @@ public class MovingConfig extends ACheckConfig { public final double sfHoverViolation; // Special tolerance values: + /** This is not strictly ticks, but packets, for now.*/ + public final int velocityGraceTicks; public final double noFallyOnGround; public final double yOnGround; public final double yStep; @@ -168,6 +170,7 @@ public class MovingConfig extends ACheckConfig { sfHoverFallDamage = data.getBoolean(ConfPaths.MOVING_SURVIVALFLY_HOVER_FALLDAMAGE); sfHoverViolation = data.getDouble(ConfPaths.MOVING_SURVIVALFLY_HOVER_SFVIOLATION); + velocityGraceTicks = data.getInt(ConfPaths.MOVING_VELOCITY_GRACETICKS); yOnGround = data.getDouble(ConfPaths.MOVING_YONGROUND, 0.001, 2.0, 0.0626); // sqrt(1/256), see: NetServerHandler. noFallyOnGround = data.getDouble(ConfPaths.MOVING_NOFALL_YONGROUND, 0.001, 2.0, 0.3); // ystep is set to 0.45 by default, for stairs / steps. diff --git a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingData.java b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingData.java index 1234fe52..91e5c41b 100644 --- a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingData.java +++ b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingData.java @@ -87,11 +87,13 @@ public class MovingData extends ACheckData { // Velocity handling. // TODO: consider resetting these with clearFlyData and onSetBack. + public int verticalVelocityCounter; public double verticalFreedom; public double verticalVelocity; - public int verticalVelocityCounter; - public double horizontalVelocityCounter; + public int verticalVelocityUsed = 0; + public int horizontalVelocityCounter; public double horizontalFreedom; + public int horizontalVelocityUsed = 0; // Coordinates. /** Last from coordinates. */ diff --git a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java index e4e27e30..908158af 100644 --- a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java +++ b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java @@ -525,20 +525,28 @@ public class MovingListener extends CheckListener implements TickListener, IRemo // Just try to estimate velocities over time. Not very precise, but works good enough most of the time. Do // general data modifications one for each event. if (data.horizontalVelocityCounter > 0D){ + data.horizontalVelocityUsed ++; data.horizontalVelocityCounter--; data.horizontalFreedom = Math.max(0.0, data.horizontalFreedom - 0.09); } - else if (data.horizontalFreedom > 0.001D) - data.horizontalFreedom *= 0.90D; + else if (data.horizontalFreedom > 0.001D){ + data.horizontalVelocityUsed ++; + data.horizontalFreedom *= 0.90D; + } - if (data.verticalVelocity <= 0.09D) - data.verticalVelocityCounter--; + if (data.verticalVelocity <= 0.09D){ + data.verticalVelocityUsed ++; + data.verticalVelocityCounter--; + } else if (data.verticalVelocityCounter > 0D) { + data.verticalVelocityUsed ++; data.verticalFreedom += data.verticalVelocity; data.verticalVelocity = Math.max(0.0, data.verticalVelocity -0.09); - } else if (data.verticalFreedom > 0.001D) + } else if (data.verticalFreedom > 0.001D){ // Counter has run out, now reduce the vertical freedom over time. + data.verticalVelocityUsed ++; data.verticalFreedom *= 0.93D; + } Location newTo = null; @@ -884,15 +892,20 @@ public class MovingListener extends CheckListener implements TickListener, IRemo double newVal = velocity.getY(); if (newVal >= 0D) { + if (data.verticalFreedom <= 0.001 && data.verticalVelocityCounter >= 0){ + data.verticalVelocity = 0; + } data.verticalVelocity += newVal; data.verticalFreedom += data.verticalVelocity; - data.verticalVelocityCounter = Math.min(100, Math.max(data.verticalVelocityCounter, 0) + 1 + (int) Math.round(newVal * 10.0)); // 50; + data.verticalVelocityCounter = Math.min(100, Math.max(data.verticalVelocityCounter, cc.velocityGraceTicks ) + 1 + (int) Math.round(newVal * 10.0)); // 50; + data.verticalVelocityUsed = 0; } newVal = Math.sqrt(velocity.getX() * velocity.getX() + velocity.getZ() * velocity.getZ()); if (newVal > 0D) { data.horizontalFreedom += newVal; - data.horizontalVelocityCounter = Math.min(100, Math.max(data.horizontalVelocityCounter, 0) + 1 + (int) Math.round(newVal * 10.0)); // 30; + data.horizontalVelocityCounter = Math.min(100, Math.max(data.horizontalVelocityCounter, cc.velocityGraceTicks ) + 1 + (int) Math.round(newVal * 10.0)); // 30; + data.horizontalVelocityUsed = 0; } // Set dirty flag here. @@ -1106,9 +1119,11 @@ public class MovingListener extends CheckListener implements TickListener, IRemo // Experiment: add some velocity (fake). data.horizontalVelocityCounter = 1; data.horizontalFreedom = 0.75; + data.horizontalVelocityUsed = 0; data.verticalVelocityCounter = 1; data.verticalFreedom = 1.2; data.verticalVelocity = 0.1; + data.verticalVelocityUsed = 0; } @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) diff --git a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/moving/SurvivalFly.java b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/moving/SurvivalFly.java index 3d95c4d1..88fad212 100644 --- a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/moving/SurvivalFly.java +++ b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/moving/SurvivalFly.java @@ -400,7 +400,7 @@ public class SurvivalFly extends Check { // Apply reset conditions. data.toWasReset = resetTo || data.noFallAssumeGround; data.fromWasReset = resetFrom || data.noFallAssumeGround; - if (yDistance <= 0 && data.sfLastYDist > 0){ + if (data.verticalVelocityUsed > cc.velocityGraceTicks && yDistance <= 0 && data.sfLastYDist > 0){ // data.verticalFreedom = 0; data.verticalVelocityCounter = 0; data.verticalVelocity = 0; @@ -411,14 +411,16 @@ public class SurvivalFly extends Check { data.sfJumpPhase = 0; data.clearAccounting(); // TODO: Experimental: reset velocity. - if (toOnGround && yDistance < 0 || Math.abs(yDistance) < 0.09){ + if (data.verticalVelocityUsed > cc.velocityGraceTicks && toOnGround && yDistance < 0){ data.verticalVelocityCounter = 0; data.verticalFreedom = 0; data.verticalVelocity = 0; + data.verticalVelocityUsed = 0; } - if (hDistance < sprintingSpeed){ + if (data.horizontalVelocityUsed > cc.velocityGraceTicks && hDistance < sprintingSpeed){ data.horizontalFreedom = 0; data.horizontalVelocityCounter = 0; + data.horizontalVelocityUsed = 0; } } else if (resetFrom){ diff --git a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/config/ConfPaths.java b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/config/ConfPaths.java index e8912c4f..26faf5df 100644 --- a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/config/ConfPaths.java +++ b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/config/ConfPaths.java @@ -508,6 +508,9 @@ public abstract class ConfPaths { public static final String MOVING_SURVIVALFLY_HOVER_SFVIOLATION = MOVING_SURVIVALFLY_HOVER + "sfviolation"; // Special (to be sorted in or factored out). + private static final String MOVING_VELOCITY = MOVING + "velocity."; + public static final String MOVING_VELOCITY_GRACETICKS = MOVING_VELOCITY + "graceticks"; + public static final String MOVING_NOFALL_YONGROUND = MOVING_NOFALL + "yonground"; public static final String MOVING_YONGROUND = MOVING + "yonground"; public static final String MOVING_SURVIVALFLY_YSTEP = MOVING_SURVIVALFLY + "ystep"; @@ -534,5 +537,5 @@ public abstract class ConfPaths { public static final String SUB_IGNOREPASSABLE = RootConfPaths.SUB_IGNOREPASSABLE; public static final String SUB_ALLOWINSTANTBREAK = RootConfPaths.SUB_ALLOWINSTANTBREAK; public static final String SUB_LAG = "lag"; - + } diff --git a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/config/DefaultConfig.java b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/config/DefaultConfig.java index 6d0a6c36..be510ee7 100644 --- a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/config/DefaultConfig.java +++ b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/config/DefaultConfig.java @@ -400,6 +400,9 @@ public class DefaultConfig extends ConfigFile { set(ConfPaths.MOVING_SURVIVALFLY_HOVER_FALLDAMAGE, true); set(ConfPaths.MOVING_SURVIVALFLY_HOVER_SFVIOLATION, 500); + // Special. + set(ConfPaths.MOVING_VELOCITY_GRACETICKS, 20); + /* * dP"8 d8 ,e, * C8b Y d88 888,8, " 888 8e e88 888 dP"Y