mirror of
https://github.com/darksaid98/AntiCheatReloaded.git
synced 2026-12-03 06:28:52 +00:00
Also added extra KillAura check and fixed compatibility issues
This commit is contained in:
1 parent
7c9a05ff92
commit
661718d001
11 files changed
+159
-54
No files matched your search
@@ -16,7 +16,6 @@
|
||||
* 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.check.combat;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -29,33 +28,31 @@ import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
|
||||
import com.rammelkast.anticheatreloaded.AntiCheatReloaded;
|
||||
import com.rammelkast.anticheatreloaded.check.CheckResult;
|
||||
import com.rammelkast.anticheatreloaded.config.providers.Magic;
|
||||
import com.rammelkast.anticheatreloaded.util.Utilities;
|
||||
import com.rammelkast.anticheatreloaded.util.checkassist.KillauraAssist;
|
||||
|
||||
public class KillAuraCheck {
|
||||
|
||||
// Angle check
|
||||
public static final Map<String, Integer> ANGLE_FLAGS = new HashMap<String, Integer>();
|
||||
// Heuristic fight speed check
|
||||
public static final Map<String, Integer> DEVIATION_SCORES = new HashMap<String, Integer>();
|
||||
public static final Map<String, Integer> DIFF_MAP = new HashMap<String, Integer>();
|
||||
public static final Map<String, ClickSpeed> CLICKSPEED_MAP = new HashMap<String, ClickSpeed>();
|
||||
// Heuristic aimbot check
|
||||
public static final Map<String, List<Float>> PITCH_MOVEMENTS_CACHE = new HashMap<String, List<Float>>();
|
||||
public static final Map<String, Float> GCD_CACHE = new HashMap<String, Float>();
|
||||
// Not used as of now, code not committed yet
|
||||
private static final KillauraAssist KILLAURA_ASSIST;
|
||||
private static final CheckResult PASS = new CheckResult(CheckResult.Result.PASSED);
|
||||
|
||||
public static void listenPackets() {
|
||||
/*AntiCheatReloaded.getProtocolManager().addPacketListener(new PacketAdapter(AntiCheatReloaded.getPlugin(),
|
||||
ListenerPriority.LOWEST, new PacketType[] { PacketType.Play.Client.POSITION_LOOK }) {
|
||||
@Override
|
||||
public void onPacketReceiving(PacketEvent e) {
|
||||
Player player = e.getPlayer();
|
||||
PacketContainer packet = e.getPacket();
|
||||
}
|
||||
});*/
|
||||
}
|
||||
|
||||
public static CheckResult checkAngle(Player player, EntityDamageEvent event) {
|
||||
String uuid = player.getUniqueId().toString();
|
||||
Entity entity = event.getEntity();
|
||||
if (entity instanceof LivingEntity) {
|
||||
LivingEntity living = (LivingEntity) entity;
|
||||
@@ -66,29 +63,30 @@ public class KillAuraCheck {
|
||||
|
||||
double angleDifference = Math.abs(180 - Math.abs(Math.abs(yawDifference - playerYaw) - 180));
|
||||
if (Math.round(angleDifference) > AntiCheatReloaded.getManager().getConfiguration().getMagic().KILLAURA_MAX_ANGLE_DIFFERENCE()) {
|
||||
if (!ANGLE_FLAGS.containsKey(player.getUniqueId().toString())) {
|
||||
ANGLE_FLAGS.put(player.getUniqueId().toString(), 1);
|
||||
if (!ANGLE_FLAGS.containsKey(uuid)) {
|
||||
ANGLE_FLAGS.put(uuid, 1);
|
||||
return PASS;
|
||||
}
|
||||
|
||||
int flags = ANGLE_FLAGS.get(player.getUniqueId().toString());
|
||||
int flags = ANGLE_FLAGS.get(uuid);
|
||||
if (flags >= AntiCheatReloaded.getManager().getConfiguration().getMagic().KILLAURA_MAX_ANGLE_VIOLATIONS()) {
|
||||
ANGLE_FLAGS.remove(player.getUniqueId().toString());
|
||||
ANGLE_FLAGS.remove(uuid);
|
||||
return new CheckResult(CheckResult.Result.FAILED, "tried to attack from an illegal angle (angle=" + Math.round(angleDifference) + ")");
|
||||
}
|
||||
|
||||
ANGLE_FLAGS.put(player.getUniqueId().toString(), flags + 1);
|
||||
ANGLE_FLAGS.put(uuid, flags + 1);
|
||||
}
|
||||
}
|
||||
return PASS;
|
||||
}
|
||||
|
||||
public static CheckResult checkFightSpeed(Player player, EntityDamageEvent event) {
|
||||
if (!CLICKSPEED_MAP.containsKey(player.getUniqueId().toString())) {
|
||||
CLICKSPEED_MAP.put(player.getUniqueId().toString(), new ClickSpeed());
|
||||
String uuid = player.getUniqueId().toString();
|
||||
if (!CLICKSPEED_MAP.containsKey(uuid)) {
|
||||
CLICKSPEED_MAP.put(uuid, new ClickSpeed());
|
||||
return PASS;
|
||||
}
|
||||
ClickSpeed clickSpeed = CLICKSPEED_MAP.get(player.getUniqueId().toString());
|
||||
ClickSpeed clickSpeed = CLICKSPEED_MAP.get(uuid);
|
||||
clickSpeed.registerClick();
|
||||
int deviationScore = clickSpeed.getDeviationScore();
|
||||
// Prevents false positives since scores under 2000 aren't reliable
|
||||
@@ -96,27 +94,63 @@ public class KillAuraCheck {
|
||||
return PASS;
|
||||
}
|
||||
|
||||
if (!DEVIATION_SCORES.containsKey(player.getUniqueId().toString())) {
|
||||
DEVIATION_SCORES.put(player.getUniqueId().toString(), deviationScore);
|
||||
if (!DEVIATION_SCORES.containsKey(uuid)) {
|
||||
DEVIATION_SCORES.put(uuid, deviationScore);
|
||||
return PASS;
|
||||
}
|
||||
|
||||
Magic magic = AntiCheatReloaded.getManager().getConfiguration().getMagic();
|
||||
int lastScore = DEVIATION_SCORES.get(player.getUniqueId().toString());
|
||||
DEVIATION_SCORES.put(player.getUniqueId().toString(), deviationScore);
|
||||
int lastScore = DEVIATION_SCORES.get(uuid);
|
||||
DEVIATION_SCORES.put(uuid, deviationScore);
|
||||
int diff = Math.abs(deviationScore - lastScore);
|
||||
if (!DIFF_MAP.containsKey(player.getUniqueId().toString())) {
|
||||
DIFF_MAP.put(player.getUniqueId().toString(), diff);
|
||||
if (!DIFF_MAP.containsKey(uuid)) {
|
||||
DIFF_MAP.put(uuid, diff);
|
||||
return PASS;
|
||||
}
|
||||
int lastDiff = DIFF_MAP.get(player.getUniqueId().toString());
|
||||
DIFF_MAP.put(player.getUniqueId().toString(), diff);
|
||||
int lastDiff = DIFF_MAP.get(uuid);
|
||||
DIFF_MAP.put(uuid, diff);
|
||||
if (Math.abs(diff - lastDiff) < magic.KILLAURA_FIGHTSPEED_MINDIFF()) {
|
||||
event.setCancelled(true);
|
||||
return new CheckResult(CheckResult.Result.FAILED, "had a suspiciously consistant fighting speed (absdiff=" + Math.abs(diff - lastDiff) + ")");
|
||||
}
|
||||
return PASS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check idea by Hawk AntiCheat (https://github.com/HawkAnticheat/Hawk)
|
||||
*/
|
||||
public static CheckResult checkAimbot(Player player, PlayerMoveEvent event) {
|
||||
String uuid = player.getUniqueId().toString();
|
||||
float pitchMovement = event.getTo().getPitch() - event.getFrom().getPitch();
|
||||
if (!PITCH_MOVEMENTS_CACHE.containsKey(uuid)) {
|
||||
PITCH_MOVEMENTS_CACHE.put(uuid, new ArrayList<Float>());
|
||||
return PASS;
|
||||
}
|
||||
List<Float> pitchMovements = PITCH_MOVEMENTS_CACHE.get(uuid);
|
||||
if (pitchMovement != 0 && Math.abs(pitchMovement) <= 10 && Math.abs(event.getTo().getPitch()) != 90) {
|
||||
pitchMovements.add(Math.abs(pitchMovement));
|
||||
}
|
||||
|
||||
if (pitchMovements.size() >= 20) {
|
||||
float greatestCommonDivisor = Utilities.gcdRational(pitchMovements);
|
||||
if (!GCD_CACHE.containsKey(uuid)) {
|
||||
GCD_CACHE.put(uuid, greatestCommonDivisor);
|
||||
}
|
||||
|
||||
float divisorDifference = Math.abs(greatestCommonDivisor - GCD_CACHE.get(uuid));
|
||||
if (divisorDifference > 0.00425 || greatestCommonDivisor < 0.00001) {
|
||||
pitchMovements.clear();
|
||||
GCD_CACHE.put(uuid, greatestCommonDivisor);
|
||||
PITCH_MOVEMENTS_CACHE.put(uuid, pitchMovements);
|
||||
return new CheckResult(CheckResult.Result.FAILED, "performed aimbot-like movements (divisor-diff=" + divisorDifference + ")");
|
||||
}
|
||||
pitchMovements.clear();
|
||||
GCD_CACHE.put(uuid, greatestCommonDivisor);
|
||||
PITCH_MOVEMENTS_CACHE.put(uuid, pitchMovements);
|
||||
}
|
||||
PITCH_MOVEMENTS_CACHE.put(uuid, pitchMovements);
|
||||
return PASS;
|
||||
}
|
||||
|
||||
private static class ClickSpeed {
|
||||
private final List<Long> clicks;
|
||||
|
||||
Reference in new issue
Block a user