mirror of
https://github.com/darksaid98/AntiCheatReloaded.git
synced 2026-12-02 22:16:03 +00:00
Started on ACR 1.11.0: Added 3 new KillAura checks (ThroughWalls, RepeatedAim and Variance), added new Speed check (Predict), started added buffer systems to speed checks, improved BoatFly (still needs testing), performance improvements, config changes, fixed Flight false positive, fixed BadPackets false positive, some code reformatting
This commit is contained in:
1 parent
5c85b8717b
commit
031e7b145b
29 files changed
+839
-408
No files matched your search
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* AntiCheatReloaded for Bukkit and Spigot.
|
||||
* Copyright (c) 2012-2015 AntiCheat Team
|
||||
* Copyright (c) 2016-2022 Rammelkast
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.rammelkast.anticheatreloaded.util;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
/**
|
||||
* Friction data library to prevent using Reflection or NMS
|
||||
*/
|
||||
public enum Friction {
|
||||
|
||||
DEFAULT(0.6f),
|
||||
ICE(0.98f),
|
||||
BLUE_ICE(0.989f),
|
||||
PACKED_ICE(0.98f),
|
||||
SLIME_BLOCK(0.8f),
|
||||
;
|
||||
|
||||
private final float factor;
|
||||
|
||||
Friction(final float factor) {
|
||||
this.factor = factor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the friction factor
|
||||
*
|
||||
* @return the factor
|
||||
*/
|
||||
public float getFactor() {
|
||||
return this.factor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the friction factor for the given block
|
||||
*
|
||||
* @param block The block
|
||||
* @return the friction factor
|
||||
*/
|
||||
public static float getFactor(final Block block) {
|
||||
final Material type = block.getType();
|
||||
try {
|
||||
return valueOf(type.name()).getFactor();
|
||||
} catch (final Exception exception) {
|
||||
return DEFAULT.getFactor();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -73,6 +73,8 @@ public final class MovementManager {
|
||||
public Distance lastDistance = new Distance();
|
||||
// Movement acceleration
|
||||
public double acceleration;
|
||||
// Last movement acceleration
|
||||
public double lastAcceleration;
|
||||
// Is the block above solid
|
||||
public boolean topSolid;
|
||||
// Is the block below solid
|
||||
@@ -81,6 +83,8 @@ public final class MovementManager {
|
||||
public boolean halfMovement;
|
||||
// If the player is on the ground (determined clientside!)
|
||||
public boolean onGround;
|
||||
// If the player was on the ground (determined clientside!)
|
||||
public boolean wasOnGround;
|
||||
// Ticks counter for last halfMovement
|
||||
public int halfMovementHistoryCounter = 0;
|
||||
// Time of last teleport
|
||||
@@ -107,12 +111,16 @@ public final class MovementManager {
|
||||
public long lastUpdate;
|
||||
// Last location
|
||||
public Location lastLocation;
|
||||
|
||||
/**
|
||||
* Used by prediction speed check
|
||||
*/
|
||||
public float friction;
|
||||
public double adjusted;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public void handle(final Player player, final Location from, final Location to, final Distance distance) {
|
||||
// TODO as of now, we "trust" the client to send the right thing
|
||||
// This is checked for spoofing by "GroundFlight"
|
||||
// Also seems to make NoFall cheats flag for speed lmao
|
||||
this.wasOnGround = this.onGround;
|
||||
this.onGround = player.isOnGround();
|
||||
|
||||
this.lastLocation = from;
|
||||
@@ -139,7 +147,7 @@ public final class MovementManager {
|
||||
// Handle 1.9+ potion effects
|
||||
if (MinecraftVersion.atOrAbove(MinecraftVersion.COMBAT_UPDATE)) {
|
||||
for (PotionEffect effect : player.getActivePotionEffects()) {
|
||||
if (!VersionUtil.isLevitationEffect(effect)) {
|
||||
if (!VersionLib.isLevitationEffect(effect)) {
|
||||
continue;
|
||||
}
|
||||
AntiCheatReloaded.getManager().getBackend().logLevitating(player, 1);
|
||||
@@ -188,7 +196,7 @@ public final class MovementManager {
|
||||
}
|
||||
}
|
||||
|
||||
if (VersionUtil.isGliding(player)) {
|
||||
if (VersionLib.isGliding(player)) {
|
||||
this.elytraEffectTicks = 30;
|
||||
} else {
|
||||
if (this.elytraEffectTicks > 0) {
|
||||
@@ -218,7 +226,7 @@ public final class MovementManager {
|
||||
}
|
||||
}
|
||||
|
||||
if (VersionUtil.isRiptiding(player)) {
|
||||
if (VersionLib.isRiptiding(player)) {
|
||||
this.riptideTicks = 30;
|
||||
} else {
|
||||
if (this.riptideTicks > 0) {
|
||||
@@ -235,6 +243,7 @@ public final class MovementManager {
|
||||
+ this.lastDistance.getZDifference() * this.lastDistance.getZDifference());
|
||||
final double currentDistanceSq = Math.sqrt(distance.getXDifference() * distance.getXDifference()
|
||||
+ distance.getZDifference() * distance.getZDifference());
|
||||
this.lastAcceleration = this.acceleration;
|
||||
this.acceleration = currentDistanceSq - lastDistanceSq;
|
||||
|
||||
this.lastMotionY = this.motionY;
|
||||
@@ -245,7 +254,7 @@ public final class MovementManager {
|
||||
final Location bottom = to.clone().add(0, -1, 0);
|
||||
this.bottomSolid = bottom.getBlock().getType().isSolid();
|
||||
|
||||
if ((this.motionY > 0.42f && this.motionY <= 0.5625f)
|
||||
if ((this.motionY >= 0.42f && this.motionY <= 0.5625f)
|
||||
&& (Utilities.couldBeOnHalfblock(to) || Utilities.isNearBed(to))) {
|
||||
this.halfMovement = true;
|
||||
this.halfMovementHistoryCounter = 30;
|
||||
@@ -263,4 +272,5 @@ public final class MovementManager {
|
||||
// Update "good location"
|
||||
user.setGoodLocation(from);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,100 +0,0 @@
|
||||
/*
|
||||
* AntiCheatReloaded for Bukkit and Spigot.
|
||||
* Copyright (c) 2012-2015 AntiCheat Team
|
||||
* Copyright (c) 2016-2022 Rammelkast
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.rammelkast.anticheatreloaded.util;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.ProtocolManager;
|
||||
import com.comphenix.protocol.events.ListenerPriority;
|
||||
import com.comphenix.protocol.events.PacketAdapter;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import com.comphenix.protocol.injector.server.TemporaryPlayer;
|
||||
import com.comphenix.protocol.wrappers.EnumWrappers.PlayerDigType;
|
||||
import com.rammelkast.anticheatreloaded.AntiCheatReloaded;
|
||||
import com.rammelkast.anticheatreloaded.check.movement.NoSlowCheck;
|
||||
import com.rammelkast.anticheatreloaded.check.packet.BadPacketsCheck;
|
||||
import com.rammelkast.anticheatreloaded.check.packet.MorePacketsCheck;
|
||||
|
||||
public final class PacketListener {
|
||||
|
||||
public static void load(final ProtocolManager manager) {
|
||||
// Used for MorePackets and BadPackets
|
||||
manager.addPacketListener(new PacketAdapter(AntiCheatReloaded.getPlugin(), ListenerPriority.LOWEST,
|
||||
new PacketType[] { PacketType.Play.Client.POSITION, PacketType.Play.Client.POSITION_LOOK,
|
||||
PacketType.Play.Server.POSITION }) {
|
||||
@Override
|
||||
public void onPacketReceiving(final PacketEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
if (player == null || !player.isOnline()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Run MorePackets check
|
||||
MorePacketsCheck.runCheck(player, event);
|
||||
|
||||
if (!event.isCancelled()) {
|
||||
// Run BadPackets check
|
||||
BadPacketsCheck.runCheck(player, event);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPacketSending(final PacketEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
// Check if we have an actual player object
|
||||
if (player instanceof TemporaryPlayer) {
|
||||
return;
|
||||
}
|
||||
// Compensate for teleport
|
||||
MorePacketsCheck.compensate(player);
|
||||
}
|
||||
});
|
||||
|
||||
// Used for accurate ping
|
||||
manager.addPacketListener(new PacketAdapter(AntiCheatReloaded.getPlugin(), ListenerPriority.LOWEST,
|
||||
new PacketType[] { PacketType.Play.Client.KEEP_ALIVE, PacketType.Play.Server.KEEP_ALIVE }) {
|
||||
@Override
|
||||
public void onPacketSending(final PacketEvent event) {
|
||||
final User user = AntiCheatReloaded.getManager().getUserManager()
|
||||
.getUser(event.getPlayer().getUniqueId());
|
||||
user.onServerPing();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPacketReceiving(final PacketEvent event) {
|
||||
final User user = AntiCheatReloaded.getManager().getUserManager()
|
||||
.getUser(event.getPlayer().getUniqueId());
|
||||
user.onClientPong();
|
||||
}
|
||||
});
|
||||
|
||||
// Used for NoSlow
|
||||
manager.addPacketListener(new PacketAdapter(AntiCheatReloaded.getPlugin(),
|
||||
ListenerPriority.LOWEST, new PacketType[] { PacketType.Play.Client.BLOCK_DIG }) {
|
||||
@Override
|
||||
public void onPacketReceiving(final PacketEvent event) {
|
||||
if (event.getPacket().getPlayerDigTypes().read(0) == PlayerDigType.RELEASE_USE_ITEM) {
|
||||
NoSlowCheck.runCheck(event.getPlayer(), event);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -50,7 +50,6 @@ public final class User {
|
||||
private boolean isWaitingOnLevelSync;
|
||||
private Timestamp levelSyncTimestamp;
|
||||
|
||||
private long lastServerPing, lastClientPong;
|
||||
private int ping = -1;
|
||||
private int lastPing = -1;
|
||||
|
||||
@@ -68,7 +67,7 @@ public final class User {
|
||||
this.uuid = uuid;
|
||||
this.name = getPlayer() != null && getPlayer().isOnline() ? getPlayer().getName() : "";
|
||||
this.id = getPlayer() != null && getPlayer().isOnline() ? getPlayer().getEntityId() : -1;
|
||||
this.ping = getPlayer() != null && getPlayer().isOnline() ? VersionUtil.getPlayerPing(getPlayer()) : -1;
|
||||
this.ping = getPlayer() != null && getPlayer().isOnline() ? VersionLib.getPlayerPing(getPlayer()) : -1;
|
||||
|
||||
this.movementManager = new MovementManager();
|
||||
this.velocityTracker = new VelocityTracker(this.config.getMagic().VELOCITY_TIME());
|
||||
@@ -402,20 +401,10 @@ public final class User {
|
||||
return levelSyncTimestamp;
|
||||
}
|
||||
|
||||
public void onServerPing() {
|
||||
this.lastServerPing = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public void onClientPong() {
|
||||
this.lastClientPong = System.currentTimeMillis();
|
||||
this.lastPing = this.ping;
|
||||
this.ping = (int) (this.lastClientPong - this.lastServerPing);
|
||||
}
|
||||
|
||||
public int getPing() {
|
||||
final int ping = this.ping;
|
||||
if (ping < 0) {
|
||||
return VersionUtil.getPlayerPing(getPlayer());
|
||||
return VersionLib.getPlayerPing(getPlayer());
|
||||
}
|
||||
return ping;
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ package com.rammelkast.anticheatreloaded.util;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -31,6 +32,8 @@ import java.util.regex.Pattern;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.attribute.AttributeInstance;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
@@ -80,8 +83,8 @@ public final class Utilities {
|
||||
* @return true if the player should be unable to stand here
|
||||
*/
|
||||
public static boolean cantStandAtExp(final Location location) {
|
||||
return cantStandAt(new Location(location.getWorld(), location.getX(), location.getY() - 0.01D,
|
||||
location.getZ()).getBlock());
|
||||
return cantStandAt(new Location(location.getWorld(), location.getX(), location.getY() - 0.01D, location.getZ())
|
||||
.getBlock());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -134,7 +137,7 @@ public final class Utilities {
|
||||
final Material type = block.getType();
|
||||
return type.equals(XMaterial.SLIME_BLOCK.parseMaterial());
|
||||
}
|
||||
|
||||
|
||||
public static boolean couldBeOnBoat(final Player player) {
|
||||
return couldBeOnBoat(player, 0.35, false);
|
||||
}
|
||||
@@ -159,12 +162,11 @@ public final class Utilities {
|
||||
* @return true if the player could be standing on ice
|
||||
*/
|
||||
public static boolean couldBeOnIce(final Location location) {
|
||||
return isNearIce(new Location(location.getWorld(), location.getX(), location.getY() - 0.01D,
|
||||
location.getZ()))
|
||||
|| isNearIce(new Location(location.getWorld(), location.getX(), location.getY() - 0.26D,
|
||||
location.getZ()))
|
||||
|| isNearIce(new Location(location.getWorld(), location.getX(), location.getY() - 0.51D,
|
||||
location.getZ()));
|
||||
return isNearIce(new Location(location.getWorld(), location.getX(), location.getY() - 0.01D, location.getZ()))
|
||||
|| isNearIce(
|
||||
new Location(location.getWorld(), location.getX(), location.getY() - 0.26D, location.getZ()))
|
||||
|| isNearIce(
|
||||
new Location(location.getWorld(), location.getX(), location.getY() - 0.51D, location.getZ()));
|
||||
}
|
||||
|
||||
public static boolean isNearIce(final Location location) {
|
||||
@@ -188,8 +190,8 @@ public final class Utilities {
|
||||
public static boolean couldBeOnHalfblock(final Location location) {
|
||||
return isNearHalfblock(
|
||||
new Location(location.getWorld(), location.getX(), location.getY() - 0.01D, location.getZ()))
|
||||
|| isNearHalfblock(new Location(location.getWorld(), location.getX(), location.getY() - 0.51D,
|
||||
location.getZ()));
|
||||
|| isNearHalfblock(
|
||||
new Location(location.getWorld(), location.getX(), location.getY() - 0.51D, location.getZ()));
|
||||
}
|
||||
|
||||
public static boolean isNearHalfblock(final Location location) {
|
||||
@@ -223,16 +225,15 @@ public final class Utilities {
|
||||
* @return true if the player could be standing on slime
|
||||
*/
|
||||
public static boolean couldBeOnSlime(final Location location) {
|
||||
return isNearSlime(new Location(location.getWorld(), location.getX(), location.getY() - 0.01D,
|
||||
location.getZ()))
|
||||
|| isNearSlime(new Location(location.getWorld(), location.getX(), location.getY() - 0.51D,
|
||||
location.getZ()));
|
||||
return isNearSlime(new Location(location.getWorld(), location.getX(), location.getY() - 0.01D, location.getZ()))
|
||||
|| isNearSlime(
|
||||
new Location(location.getWorld(), location.getX(), location.getY() - 0.51D, location.getZ()));
|
||||
}
|
||||
|
||||
public static boolean isNearSlime(final Location location) {
|
||||
return isCollisionPoint(location, material -> material == XMaterial.SLIME_BLOCK.parseMaterial());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determine whether a player could be standing on soil
|
||||
*
|
||||
@@ -240,14 +241,14 @@ public final class Utilities {
|
||||
* @return true if the player could be standing on soil
|
||||
*/
|
||||
public static boolean couldBeOnSoil(final Location location) {
|
||||
return isNearSoil(new Location(location.getWorld(), location.getX(), location.getY() - 0.01D,
|
||||
location.getZ()))
|
||||
|| isNearSoil(new Location(location.getWorld(), location.getX(), location.getY() - 0.51D,
|
||||
location.getZ()));
|
||||
return isNearSoil(new Location(location.getWorld(), location.getX(), location.getY() - 0.01D, location.getZ()))
|
||||
|| isNearSoil(
|
||||
new Location(location.getWorld(), location.getX(), location.getY() - 0.51D, location.getZ()));
|
||||
}
|
||||
|
||||
public static boolean isNearSoil(final Location location) {
|
||||
return isCollisionPoint(location, material -> material == XMaterial.SOUL_SOIL.parseMaterial() || material == XMaterial.SOUL_SAND.parseMaterial());
|
||||
return isCollisionPoint(location, material -> material == XMaterial.SOUL_SOIL.parseMaterial()
|
||||
|| material == XMaterial.SOUL_SAND.parseMaterial());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -374,7 +375,7 @@ public final class Utilities {
|
||||
Material type = block.getType();
|
||||
return type.name().endsWith("WALL") || type.name().endsWith("FENCE") || type.name().endsWith("FENCE_GATE");
|
||||
}
|
||||
|
||||
|
||||
public static boolean isNearWall(final Location location) {
|
||||
return isWall(location.getBlock()) || isWall(location.getBlock().getRelative(BlockFace.NORTH))
|
||||
|| isWall(location.getBlock().getRelative(BlockFace.SOUTH))
|
||||
@@ -400,7 +401,7 @@ public final class Utilities {
|
||||
|| block.getRelative(BlockFace.EAST).getType() == XMaterial.LILY_PAD.parseMaterial()
|
||||
|| block.getRelative(BlockFace.WEST).getType() == XMaterial.LILY_PAD.parseMaterial();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determine whether a player is standing on a carpet
|
||||
*
|
||||
@@ -748,9 +749,10 @@ public final class Utilities {
|
||||
int rounded = (int) value;
|
||||
return value < rounded ? rounded - 1 : rounded;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Computes the difference between two angles
|
||||
*
|
||||
* @param a Angle A
|
||||
* @param b Angle B
|
||||
* @return the difference between two angles
|
||||
@@ -759,10 +761,12 @@ public final class Utilities {
|
||||
float diff = Math.abs(a - b);
|
||||
final float altDiff = b + 360 - a;
|
||||
final float altAltDiff = a + 360 - b;
|
||||
if (altDiff < diff) diff = altDiff;
|
||||
if (altAltDiff < diff) diff = altAltDiff;
|
||||
return diff;
|
||||
}
|
||||
if (altDiff < diff)
|
||||
diff = altDiff;
|
||||
if (altAltDiff < diff)
|
||||
diff = altAltDiff;
|
||||
return diff;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the greatest common divider
|
||||
@@ -789,6 +793,49 @@ public final class Utilities {
|
||||
}
|
||||
return materials.stream().anyMatch(predicate);
|
||||
}
|
||||
|
||||
/**
|
||||
* @author Elevated
|
||||
* @param data - The set of data you want to find the variance from
|
||||
* @return - The variance of the numbers.
|
||||
*
|
||||
* @See - https://en.wikipedia.org/wiki/Variance
|
||||
*/
|
||||
public static double getVariance(final Collection<? extends Number> data) {
|
||||
int count = 0;
|
||||
|
||||
double sum = 0.0;
|
||||
double variance = 0.0;
|
||||
|
||||
double average;
|
||||
|
||||
// Increase the sum and the count to find the average and the standard deviation
|
||||
for (final Number number : data) {
|
||||
sum += number.doubleValue();
|
||||
++count;
|
||||
}
|
||||
|
||||
average = sum / count;
|
||||
|
||||
// Run the standard deviation formula
|
||||
for (final Number number : data) {
|
||||
variance += Math.pow(number.doubleValue() - average, 2.0);
|
||||
}
|
||||
|
||||
return variance;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the allowed player movement speed through the "GENERIC_MOVEMENT_SPEED"
|
||||
* attribute
|
||||
*
|
||||
* @return the allowed player movement speed
|
||||
*/
|
||||
public static double getMovementSpeed(final Player player) {
|
||||
final AttributeInstance attribute = player.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED);
|
||||
return attribute.getValue();
|
||||
}
|
||||
|
||||
static {
|
||||
MinecraftVersion currentVersion = MinecraftVersion.getCurrentVersion();
|
||||
@@ -941,7 +988,7 @@ public final class Utilities {
|
||||
CLIMBABLE.add(XMaterial.HONEY_BLOCK.parseMaterial());
|
||||
}
|
||||
// End 1.15 objects
|
||||
|
||||
|
||||
// Start 1.16 objects
|
||||
if (currentVersion.isAtLeast(MinecraftVersion.NETHER_UPDATE)) {
|
||||
CLIMBABLE.add(XMaterial.TWISTING_VINES.parseMaterial());
|
||||
|
||||
+1
-1
@@ -34,7 +34,7 @@ import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
import com.rammelkast.anticheatreloaded.AntiCheatReloaded;
|
||||
|
||||
public class VersionUtil {
|
||||
public class VersionLib {
|
||||
|
||||
public static final MinecraftVersion CURRENT_VERSION;
|
||||
private static final List<String> SUPPORTED_VERSIONS;
|
||||
Reference in new issue
Block a user