Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MVP for new CheckManager; faster iteration; structure to support reloading, adding/unloading checks #26

Open
wants to merge 8 commits into
base: merge
Choose a base branch
from
5 changes: 3 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ dependencies {
implementation("com.zaxxer:HikariCP:4.0.3")

//implementation("com.github.grimanticheat:grimapi:1193c4fa41")
// Used for local testing: implementation("ac.grim.grimac:GRIMAPI:1.0")
implementation("com.github.grimanticheat:grimapi:fc5634e444")
// Used for local testing:
implementation("ac.grim.grimac:GrimAPI:1.0")
// implementation("com.github.grimanticheat:grimapi:fc5634e444")

implementation("org.jetbrains:annotations:24.1.0")
compileOnly("org.geysermc.floodgate:api:2.2.3-SNAPSHOT")
Expand Down
8 changes: 8 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
pluginManagement {
plugins {
kotlin("jvm") version "2.0.21"
}
}
plugins {
id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0"
}
rootProject.name = "grimac"
6 changes: 6 additions & 0 deletions src/main/java/ac/grim/grimac/GrimExternalAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ public ConfigManager getConfigManager() {
return configManager;
}

@Override
public boolean hasStarted() {
// TODO implement this
throw new UnsupportedOperationException("Not implemented yet");
}

private ConfigManager configManager = null;
private final ConfigManagerFileImpl configManagerFile = new ConfigManagerFileImpl();
private boolean started = false;
Expand Down
37 changes: 36 additions & 1 deletion src/main/java/ac/grim/grimac/checks/Check.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import ac.grim.grimac.GrimAPI;
import ac.grim.grimac.api.AbstractCheck;
import ac.grim.grimac.api.config.ConfigManager;
import ac.grim.grimac.api.dynamic.DefaultUnloadedBehavior;
import ac.grim.grimac.api.dynamic.UnloadedBehavior;
import ac.grim.grimac.api.events.FlagEvent;
import ac.grim.grimac.player.GrimPlayer;
import ac.grim.grimac.utils.common.ConfigReloadObserver;
Expand All @@ -15,6 +17,8 @@
import lombok.Setter;
import org.bukkit.Bukkit;

import java.lang.reflect.Method;

// Class from https://github.com/Tecnio/AntiCheatBase/blob/master/src/main/java/me/tecnio/anticheat/check/Check.java
@Getter
public class Check implements AbstractCheck, ConfigReloadObserver {
Expand All @@ -40,6 +44,16 @@ public boolean isExperimental() {
return experimental;
}

@Override
public UnloadedBehavior getUnloadedBehavior() {
return DefaultUnloadedBehavior.INSTANCE;
}

@Override
public int getMask() {
throw new UnsupportedOperationException("Override this method to show which check types your check is!");
}

public Check(final GrimPlayer player) {
this.player = player;

Expand Down Expand Up @@ -112,7 +126,6 @@ public final void reward() {
violations = Math.max(0, violations - decay);
}

@Override
public void reload(ConfigManager configuration) {
decay = configuration.getDoubleElse(configName + ".decay", decay);
setbackVL = configuration.getDoubleElse(configName + ".setbackvl", setbackVL);
Expand Down Expand Up @@ -185,6 +198,28 @@ public boolean isTickPacketIncludingNonMovement(PacketTypeCommon packetType) {
return isFlying(packetType);
}

public interface UnloadedCheckHandler<T extends Check> {
// Return what the check's methods should return when unloaded
Object handleUnloadedCall(Method method, Object[] args);
}

// Default behavior - do nothing and return false/0/null
public static final UnloadedCheckHandler<?> DEFAULT_HANDLER = (method, args) -> {
// Return appropriate "no-op" value based on return type
Class<?> returnType = method.getReturnType();
if (returnType == boolean.class) return false;
if (returnType == int.class) return 0;
if (returnType == void.class) return null;
// etc...
return null;
};

private UnloadedCheckHandler<?> unloadedHandler = DEFAULT_HANDLER;

public void setUnloadedHandler(UnloadedCheckHandler<?> handler) {
this.unloadedHandler = handler;
}

@Override
public void reload() {
reload(GrimAPI.INSTANCE.getConfigManager().getConfig());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package ac.grim.grimac.checks.impl.aim;

import ac.grim.grimac.checks.Check;
import ac.grim.grimac.checks.CheckData;
import ac.grim.grimac.checks.type.RotationCheck;
import ac.grim.grimac.checks.type.abstracts.AbstractRotationCheck;
import ac.grim.grimac.player.GrimPlayer;
import ac.grim.grimac.utils.anticheat.update.RotationUpdate;

@CheckData(name = "AimDuplicateLook")
public class AimDuplicateLook extends Check implements RotationCheck {
public class AimDuplicateLook extends AbstractRotationCheck {
public AimDuplicateLook(GrimPlayer playerData) {
super(playerData);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package ac.grim.grimac.checks.impl.aim;

import ac.grim.grimac.checks.Check;
import ac.grim.grimac.checks.CheckData;
import ac.grim.grimac.checks.type.RotationCheck;
import ac.grim.grimac.checks.type.abstracts.AbstractRotationCheck;
import ac.grim.grimac.player.GrimPlayer;
import ac.grim.grimac.utils.anticheat.update.RotationUpdate;

// Based on Kauri AimA,
// I also discovered this flaw before open source Kauri, but did not want to open source its detection.
// It works on clients who % 360 their rotation.
@CheckData(name = "AimModulo360", decay = 0.005)
public class AimModulo360 extends Check implements RotationCheck {
public class AimModulo360 extends AbstractRotationCheck {

private float lastDeltaYaw;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package ac.grim.grimac.checks.impl.aim.processor;

import ac.grim.grimac.checks.Check;
import ac.grim.grimac.checks.type.RotationCheck;
import ac.grim.grimac.checks.type.abstracts.AbstractRotationCheck;
import ac.grim.grimac.player.GrimPlayer;
import ac.grim.grimac.utils.anticheat.update.RotationUpdate;
import ac.grim.grimac.utils.data.Pair;
import ac.grim.grimac.utils.lists.RunningMode;
import ac.grim.grimac.utils.math.GrimMath;


public class AimProcessor extends Check implements RotationCheck {
public class AimProcessor extends AbstractRotationCheck {

private static final int SIGNIFICANT_SAMPLES_THRESHOLD = 15;
private static final int TOTAL_SAMPLES_THRESHOLD = 80;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package ac.grim.grimac.checks.impl.badpackets;

import ac.grim.grimac.checks.Check;
import ac.grim.grimac.checks.CheckData;
import ac.grim.grimac.checks.type.PacketCheck;
import ac.grim.grimac.checks.type.abstracts.AbstractPacketCheck;
import ac.grim.grimac.player.GrimPlayer;
import com.github.retrooper.packetevents.event.PacketReceiveEvent;
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
import com.github.retrooper.packetevents.wrapper.play.client.WrapperPlayClientHeldItemChange;

@CheckData(name = "BadPacketsA", description = "Sent duplicate slot id")
public class BadPacketsA extends Check implements PacketCheck {
public class BadPacketsA extends AbstractPacketCheck {
int lastSlot = -1;

public BadPacketsA(final GrimPlayer player) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package ac.grim.grimac.checks.impl.badpackets;

import ac.grim.grimac.checks.Check;
import ac.grim.grimac.checks.CheckData;
import ac.grim.grimac.checks.type.PacketCheck;
import ac.grim.grimac.checks.type.abstracts.AbstractPacketCheck;
import ac.grim.grimac.player.GrimPlayer;
import com.github.retrooper.packetevents.event.PacketReceiveEvent;
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
import com.github.retrooper.packetevents.wrapper.play.client.WrapperPlayClientSteerVehicle;

@CheckData(name = "BadPacketsB", description = "Sent impossible steer vehicle packet")
public class BadPacketsB extends Check implements PacketCheck {
public class BadPacketsB extends AbstractPacketCheck {
public BadPacketsB(GrimPlayer player) {
super(player);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package ac.grim.grimac.checks.impl.badpackets;

import ac.grim.grimac.checks.Check;
import ac.grim.grimac.checks.CheckData;
import ac.grim.grimac.checks.type.PacketCheck;
import ac.grim.grimac.checks.type.abstracts.AbstractPacketCheck;
import ac.grim.grimac.player.GrimPlayer;
import com.github.retrooper.packetevents.event.PacketReceiveEvent;
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
import com.github.retrooper.packetevents.wrapper.play.client.WrapperPlayClientInteractEntity;

@CheckData(name = "BadPacketsC", description = "Interacted with self")
public class BadPacketsC extends Check implements PacketCheck {
public class BadPacketsC extends AbstractPacketCheck {
public BadPacketsC(GrimPlayer player) {
super(player);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package ac.grim.grimac.checks.impl.badpackets;

import ac.grim.grimac.checks.Check;
import ac.grim.grimac.checks.CheckData;
import ac.grim.grimac.checks.type.PacketCheck;
import ac.grim.grimac.checks.type.abstracts.AbstractPacketCheck;
import ac.grim.grimac.player.GrimPlayer;
import com.github.retrooper.packetevents.event.PacketReceiveEvent;
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
import com.github.retrooper.packetevents.wrapper.play.client.WrapperPlayClientPlayerFlying;

@CheckData(name = "BadPacketsD")
public class BadPacketsD extends Check implements PacketCheck {
public class BadPacketsD extends AbstractPacketCheck {
public BadPacketsD(GrimPlayer player) {
super(player);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package ac.grim.grimac.checks.impl.badpackets;

import ac.grim.grimac.checks.Check;
import ac.grim.grimac.checks.CheckData;
import ac.grim.grimac.checks.type.PacketCheck;
import ac.grim.grimac.checks.type.abstracts.AbstractPacketCheck;
import ac.grim.grimac.player.GrimPlayer;
import com.github.retrooper.packetevents.event.PacketReceiveEvent;
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
import com.github.retrooper.packetevents.wrapper.play.client.WrapperPlayClientPlayerFlying;

@CheckData(name = "BadPacketsE")
public class BadPacketsE extends Check implements PacketCheck {
public class BadPacketsE extends AbstractPacketCheck {
private int noReminderTicks;

public BadPacketsE(GrimPlayer player) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package ac.grim.grimac.checks.impl.badpackets;

import ac.grim.grimac.checks.Check;
import ac.grim.grimac.checks.CheckData;
import ac.grim.grimac.checks.type.PacketCheck;
import ac.grim.grimac.checks.type.abstracts.AbstractPacketCheck;
import ac.grim.grimac.player.GrimPlayer;
import com.github.retrooper.packetevents.event.PacketReceiveEvent;
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
import com.github.retrooper.packetevents.wrapper.play.client.WrapperPlayClientEntityAction;

@CheckData(name = "BadPacketsF", description = "Sent duplicate sprinting status")
public class BadPacketsF extends Check implements PacketCheck {
public class BadPacketsF extends AbstractPacketCheck {
public boolean lastSprinting;
public boolean exemptNext = true; // Support 1.14+ clients starting on either true or false sprinting, we don't know

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package ac.grim.grimac.checks.impl.badpackets;

import ac.grim.grimac.checks.Check;
import ac.grim.grimac.checks.CheckData;
import ac.grim.grimac.checks.type.PacketCheck;
import ac.grim.grimac.checks.type.abstracts.AbstractPacketCheck;
import ac.grim.grimac.player.GrimPlayer;
import com.github.retrooper.packetevents.event.PacketReceiveEvent;
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
import com.github.retrooper.packetevents.wrapper.play.client.WrapperPlayClientEntityAction;

@CheckData(name = "BadPacketsG", description = "Sent duplicate sneaking status")
public class BadPacketsG extends Check implements PacketCheck {
public class BadPacketsG extends AbstractPacketCheck {
private boolean lastSneaking, respawn;

public BadPacketsG(GrimPlayer player) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package ac.grim.grimac.checks.impl.badpackets;

import ac.grim.grimac.checks.Check;
import ac.grim.grimac.checks.CheckData;
import ac.grim.grimac.checks.type.PacketCheck;
import ac.grim.grimac.checks.type.abstracts.AbstractPacketCheck;
import ac.grim.grimac.player.GrimPlayer;
import com.github.retrooper.packetevents.event.PacketReceiveEvent;
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
import com.github.retrooper.packetevents.wrapper.play.client.WrapperPlayClientPlayerAbilities;

@CheckData(name = "BadPacketsI", description = "Claimed to be flying while unable to fly")
public class BadPacketsI extends Check implements PacketCheck {
public class BadPacketsI extends AbstractPacketCheck {
public BadPacketsI(GrimPlayer player) {
super(player);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package ac.grim.grimac.checks.impl.badpackets;

import ac.grim.grimac.checks.Check;
import ac.grim.grimac.checks.CheckData;
import ac.grim.grimac.checks.type.PacketCheck;
import ac.grim.grimac.checks.type.abstracts.AbstractPacketCheck;
import ac.grim.grimac.player.GrimPlayer;
import com.github.retrooper.packetevents.event.PacketReceiveEvent;
import com.github.retrooper.packetevents.protocol.packettype.PacketType;

@CheckData(name = "BadPacketsJ", description = "Sent steer vehicle packets while not in a vehicle")
public class BadPacketsJ extends Check implements PacketCheck {
public class BadPacketsJ extends AbstractPacketCheck {
public BadPacketsJ(GrimPlayer player) {
super(player);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package ac.grim.grimac.checks.impl.badpackets;

import ac.grim.grimac.checks.Check;
import ac.grim.grimac.checks.CheckData;
import ac.grim.grimac.checks.type.PacketCheck;
import ac.grim.grimac.checks.type.abstracts.AbstractPacketCheck;
import ac.grim.grimac.player.GrimPlayer;
import com.github.retrooper.packetevents.event.PacketReceiveEvent;
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
import com.github.retrooper.packetevents.protocol.player.GameMode;

@CheckData(name = "BadPacketsK", description = "Sent spectate packets while not in spectator mode")
public class BadPacketsK extends Check implements PacketCheck {
public class BadPacketsK extends AbstractPacketCheck {
public BadPacketsK(GrimPlayer player) {
super(player);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package ac.grim.grimac.checks.impl.badpackets;

import ac.grim.grimac.checks.Check;
import ac.grim.grimac.checks.CheckData;
import ac.grim.grimac.checks.type.PacketCheck;
import ac.grim.grimac.checks.type.abstracts.AbstractPacketCheck;
import ac.grim.grimac.player.GrimPlayer;
import com.github.retrooper.packetevents.event.PacketReceiveEvent;
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
Expand All @@ -14,7 +13,7 @@
import java.util.Locale;

@CheckData(name = "BadPacketsL", description = "Sent impossible dig packet")
public class BadPacketsL extends Check implements PacketCheck {
public class BadPacketsL extends AbstractPacketCheck {

public BadPacketsL(GrimPlayer player) {
super(player);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package ac.grim.grimac.checks.impl.badpackets;

import ac.grim.grimac.checks.Check;
import ac.grim.grimac.checks.CheckData;
import ac.grim.grimac.checks.type.PacketCheck;
import ac.grim.grimac.checks.type.abstracts.AbstractPacketCheck;
import ac.grim.grimac.player.GrimPlayer;

@CheckData(name = "BadPacketsN")
public class BadPacketsN extends Check implements PacketCheck {
public class BadPacketsN extends AbstractPacketCheck {
public BadPacketsN(final GrimPlayer player) {
super(player);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package ac.grim.grimac.checks.impl.badpackets;

import ac.grim.grimac.checks.Check;
import ac.grim.grimac.checks.CheckData;
import ac.grim.grimac.checks.type.PacketCheck;
import ac.grim.grimac.checks.type.abstracts.AbstractPacketCheck;
import ac.grim.grimac.player.GrimPlayer;
import ac.grim.grimac.utils.data.Pair;
import com.github.retrooper.packetevents.event.PacketReceiveEvent;
Expand All @@ -15,7 +14,7 @@
import java.util.Queue;

@CheckData(name = "BadPacketsO")
public class BadPacketsO extends Check implements PacketCheck {
public class BadPacketsO extends AbstractPacketCheck {
Queue<Pair<Long, Long>> keepaliveMap = new LinkedList<>();

public BadPacketsO(GrimPlayer player) {
Expand Down
Loading
Loading