From 4180d3b20be56c256ce98aedfee0ff63deb34517 Mon Sep 17 00:00:00 2001 From: asofold Date: Thu, 26 Mar 2015 23:29:42 +0100 Subject: [PATCH] Let fight.direction use the location trace (simplified version @Iceee). Allow 15 ticks total latency (2 x attacker + 1 x damaged) for the looping, decrease tolerance for direction by a lot. --- .../fr/neatmonster/nocheatplus/checks/fight/Direction.java | 4 ++-- .../fr/neatmonster/nocheatplus/checks/fight/FightConfig.java | 3 +++ .../neatmonster/nocheatplus/checks/fight/FightListener.java | 2 +- .../neatmonster/nocheatplus/checks/moving/MovingListener.java | 4 ++-- .../java/fr/neatmonster/nocheatplus/utilities/TrigUtil.java | 4 +++- 5 files changed, 11 insertions(+), 6 deletions(-) diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/fight/Direction.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/fight/Direction.java index d28a4b18..20376903 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/fight/Direction.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/fight/Direction.java @@ -134,11 +134,11 @@ public class Direction extends Check { final double off; if (cc.directionStrict){ - off = TrigUtil.combinedDirectionCheck(loc, player.getEyeHeight(), context.direction, dLoc.x, dLoc.y + context.damagedHeight / 2D, dLoc.z, context.damagedWidth, context.damagedHeight, TrigUtil.DIRECTION_PRECISION, 80.0); + off = TrigUtil.combinedDirectionCheck(loc, player.getEyeHeight(), context.direction, dLoc.x, dLoc.y + context.damagedHeight / 2D, dLoc.z, context.damagedWidth, context.damagedHeight, TrigUtil.DIRECTION_LOOP_PRECISION, 80.0); } else{ // Also take into account the angle. - off = TrigUtil.directionCheck(loc, player.getEyeHeight(), context.direction, dLoc.x, dLoc.y + context.damagedHeight / 2D, dLoc.z, context.damagedWidth, context.damagedHeight, TrigUtil.DIRECTION_PRECISION); + off = TrigUtil.directionCheck(loc, player.getEyeHeight(), context.direction, dLoc.x, dLoc.y + context.damagedHeight / 2D, dLoc.z, context.damagedWidth, context.damagedHeight, TrigUtil.DIRECTION_LOOP_PRECISION); } if (off > 0.1) { diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/fight/FightConfig.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/fight/FightConfig.java index 3ff7cc6c..7161f319 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/fight/FightConfig.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/fight/FightConfig.java @@ -115,6 +115,9 @@ public class FightConfig extends ACheckConfig { public final boolean yawRateCheck; public final boolean cancelDead; public final boolean knockBackVelocityPvP; + + /** Maximum latency counted in ticks for the loop checks (reach, direction). */ + public final long loopMaxLatencyTicks = 15; // TODO: Configurable, sections for players and entities. /** * Instantiates a new fight configuration. diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/fight/FightListener.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/fight/FightListener.java index 67864190..0a6b70ba 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/fight/FightListener.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/fight/FightListener.java @@ -339,7 +339,7 @@ public class FightListener extends CheckListener implements JoinLeaveListener{ final ReachContext reachContext = reachEnabled ? reach.getContext(player, loc, damaged, damagedLoc, data, cc, sharedContext) : null; final DirectionContext directionContext = directionEnabled ? direction.getContext(player, loc, damaged, damagedLoc, data, cc, sharedContext) : null; - final long traceOldest = tick; // - damagedTrace.getMaxSize(); // TODO: Set by window. + final long traceOldest = tick - cc.loopMaxLatencyTicks; // TODO: Set by latency-window. // TODO: Iterating direction, which, static/dynamic choice. final Iterator traceIt = damagedTrace.maxAgeIterator(traceOldest); diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java index dae4e410..ce3c4542 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java @@ -798,9 +798,9 @@ public class MovingListener extends CheckListener implements TickListener, IRemo if (player.isInsideVehicle()) { // TODO: refine (!). final Location ref = player.getVehicle().getLocation(useLoc); - mData.resetPositions(ref); + mData.resetPositions(ref); // TODO: Consider using to and intercept cheat attempts in another way. useLoc.setWorld(null); - mData.updateTrace(player, ref, time); + mData.updateTrace(player, to, time); // TODO: Can you become invincible by sending special moves? } else if (!fromWorldName.equals(toWorldName)) { mData.resetPositions(to); diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/utilities/TrigUtil.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/utilities/TrigUtil.java index 7ada13d0..7f90fbc5 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/utilities/TrigUtil.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/utilities/TrigUtil.java @@ -18,8 +18,10 @@ public class TrigUtil { private static final Vector vec2 = new Vector(); /** Multiply to get grad from rad. */ public static final double fRadToGrad = 360.0 / (2.0 * Math.PI); - /** Some default precision value for the directionCheck method. */ + /** Some default precision value for the classic fight.direction check. */ public static final double DIRECTION_PRECISION = 2.6; + /** Precision for the fight.direction check within the LocationTrace loop. */ + public static final double DIRECTION_LOOP_PRECISION = 0.5; private static final Location useLoc = new Location(null, 0, 0, 0);