Skip to content

Commit

Permalink
Stop using server-side tracked position when attempting to account fo…
Browse files Browse the repository at this point in the history
…r teleports not always moving entity client side; expand from client area instead (GrimAnticheat#1902)
  • Loading branch information
Axionize authored Jan 22, 2025
1 parent 6cfe71d commit 40bbd2e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,18 @@ public double distance(SimpleCollisionBox box) {
return hxz - (xwidth + zwidth + bxwidth + bzwidth) / 4;
}

public double distanceX(double x) {
return x >= this.minX && x <= this.maxX ? 0.0 : Math.min(Math.abs(x - this.minX), Math.abs(x - this.maxX));
}

public double distanceY(double y) {
return y >= this.minY && y <= this.maxY ? 0.0 : Math.min(Math.abs(y - this.minY), Math.abs(y - this.maxY));
}

public double distanceZ(double z) {
return z >= this.minZ && z <= this.maxZ ? 0.0 : Math.min(Math.abs(z - this.minZ), Math.abs(z - this.maxZ));
}

/**
* Calculates intersection with the given ray between a certain distance
* interval.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class ReachInterpolationData {
private int interpolationStepsLowBound = 0;
private int interpolationStepsHighBound = 0;
private int interpolationSteps = 1;
private boolean expandNonRelative = false;

public ReachInterpolationData(GrimPlayer player, SimpleCollisionBox startingLocation, TrackedPosition position, PacketEntity entity) {
final boolean isPointNine = !player.compensatedEntities.getSelf().inVehicle() && player.getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_9);
Expand Down Expand Up @@ -114,6 +115,9 @@ public SimpleCollisionBox getPossibleLocationCombined() {
startingLocation.maxZ + (step * stepMaxZ)));
}

if (expandNonRelative)
minimumInterpLocation.expand(0.03125D, 0.015625D, 0.03125D);

return minimumInterpLocation;
}

Expand All @@ -139,4 +143,8 @@ public String toString() {
", interpolationStepsHighBound=" + interpolationStepsHighBound +
'}';
}

public void expandNonRelative() {
expandNonRelative = true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,17 @@ public void onFirstTransaction(boolean relative, boolean hasPos, double relX, do
}
trackedServerPosition.setPos(vec3d);
} else {
// I think we can reduce this but I'm too lazy to minimize interpolations needed so...
SimpleCollisionBox clientArea = newPacketLocation.getPossibleLocationCombined();
// In versions < 1.16.2 when the client receives non-relative teleport for an entity
// And they move less by the thresholds given, the entity does not move client side
if (player.getClientVersion().isOlderThanOrEquals(ClientVersion.V_1_16_1)
&& clientArea.distanceX(relX) < 0.03125D
&& clientArea.distanceY(relY) < 0.015625D
&& clientArea.distanceZ(relZ) < 0.03125D
) {
newPacketLocation.expandNonRelative();
}
trackedServerPosition.setPos(new Vector3d(relX, relY, relZ));
// ViaVersion desync's here for teleports
// It simply teleports the entity with its position divided by 32... ignoring the offset this causes.
Expand Down

0 comments on commit 40bbd2e

Please sign in to comment.