Skip to content

Commit

Permalink
Merge branch 'merge-dev' into merge
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/main/java/ac/grim/grimac/checks/Check.java
#	src/main/java/ac/grim/grimac/checks/impl/elytra/ElytraA.java
#	src/main/java/ac/grim/grimac/checks/impl/elytra/ElytraC.java
#	src/main/java/ac/grim/grimac/checks/impl/elytra/ElytraD.java
#	src/main/java/ac/grim/grimac/checks/impl/elytra/ElytraE.java
#	src/main/java/ac/grim/grimac/checks/impl/elytra/ElytraF.java
#	src/main/java/ac/grim/grimac/checks/impl/elytra/ElytraH.java
#	src/main/java/ac/grim/grimac/checks/impl/prediction/GroundSpoof.java
#	src/main/java/ac/grim/grimac/checks/impl/sprint/SprintB.java
#	src/main/java/ac/grim/grimac/checks/impl/sprint/SprintF.java
#	src/main/java/ac/grim/grimac/checks/impl/timer/TickTimer.java
#	src/main/java/ac/grim/grimac/manager/player/features/FeatureManagerImpl.java
#	src/main/java/ac/grim/grimac/manager/player/features/types/ExemptElytraFeature.java
#	src/main/java/ac/grim/grimac/manager/player/features/types/ExperimentalChecksFeature.java
#	src/main/java/ac/grim/grimac/manager/player/features/types/GrimFeature.java
#	src/main/java/ac/grim/grimac/player/GrimPlayer.java
  • Loading branch information
Axionize committed Jan 22, 2025
2 parents 1bbaad3 + 9e296cb commit ff28ad2
Show file tree
Hide file tree
Showing 83 changed files with 391 additions and 257 deletions.
51 changes: 36 additions & 15 deletions src/main/java/ac/grim/grimac/checks/Check.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,16 @@ public class Check extends GrimProcessor implements AbstractCheck {
private boolean experimental;
@Setter
private boolean isEnabled;
private boolean exempted;

private boolean exemptPermission;
private boolean noSetbackPermission;
private boolean noModifyPacketPermission;

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

final Class<?> checkClass = this.getClass();

if (checkClass.isAnnotationPresent(CheckData.class)) {
final CheckData checkData = checkClass.getAnnotation(CheckData.class);
final CheckData checkData = this.getClass().getAnnotation(CheckData.class);
if (checkData != null) {
this.checkName = checkData.name();
this.configName = checkData.configName();
// Fall back to check name
Expand All @@ -57,14 +58,22 @@ public Check(final GrimPlayer player) {
}

public boolean shouldModifyPackets() {
return isEnabled && !player.disableGrim && !player.noModifyPacketPermission && !exempted;
return isEnabled && !player.disableGrim && !player.noModifyPacketPermission && !exemptPermission;
}

public void updateExempted() {
public void updatePermissions() {
if (player.bukkitPlayer == null || checkName == null) return;
FoliaScheduler.getEntityScheduler().run(player.bukkitPlayer, GrimAPI.INSTANCE.getPlugin(),
t -> exempted = player.bukkitPlayer.hasPermission("grim.exempt." + checkName.toLowerCase()),
() -> {});
FoliaScheduler.getEntityScheduler().run(
player.bukkitPlayer,
GrimAPI.INSTANCE.getPlugin(),
t -> {
final String id = checkName.toLowerCase();
exemptPermission = player.bukkitPlayer.hasPermission("grim.exempt." + id);
noSetbackPermission = player.bukkitPlayer.hasPermission("grim.nosetback." + id);
noModifyPacketPermission = player.bukkitPlayer.hasPermission("grim.nomodifypacket." + id);
},
() -> {}
);
}

public final boolean flagAndAlert(String verbose) {
Expand All @@ -86,7 +95,7 @@ public final boolean flag() {
private long lastViolationTime;

public final boolean flag(String verbose) {
if (player.disableGrim || (experimental && !player.isExperimentalChecks()) || exempted)
if (player.disableGrim || (experimental && !player.isExperimentalChecks()) || exemptPermission)
return false; // Avoid calling event if disabled

FlagEvent event = new FlagEvent(player, this, verbose);
Expand All @@ -107,6 +116,18 @@ public final boolean flagWithSetback() {
return false;
}

public final boolean flagAndAlertWithSetback() {
return flagAndAlertWithSetback("");
}

public final boolean flagAndAlertWithSetback(String verbose) {
if (flagAndAlert(verbose)) {
setbackIfAboveSetbackVL();
return true;
}
return false;
}

public final void reward() {
violations = Math.max(0, violations - decay);
}
Expand All @@ -119,7 +140,7 @@ public void reload(ConfigManager configuration) {
description = configuration.getStringElse(configName + ".description", description);

if (setbackVL == -1) setbackVL = Double.MAX_VALUE;
updateExempted();
updatePermissions();
onReload(configuration);
}

Expand All @@ -133,14 +154,14 @@ public boolean alert(String verbose) {
}

public boolean setbackIfAboveSetbackVL() {
if (getViolations() > setbackVL) {
if (shouldSetback()) {
return player.getSetbackTeleportUtil().executeViolationSetback();
}
return false;
}

public boolean isAboveSetbackVl() {
return getViolations() > setbackVL;
public boolean shouldSetback() {
return !noSetbackPermission && violations > setbackVL;
}

public String formatOffset(double offset) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import ac.grim.grimac.checks.type.PacketCheck;
import ac.grim.grimac.player.GrimPlayer;

@CheckData(name = "BadPacketsN")
@CheckData(name = "BadPacketsN", setback = 0)
public class BadPacketsN extends Check implements PacketCheck {
public BadPacketsN(final GrimPlayer player) {
super(player);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import ac.grim.grimac.checks.type.PacketCheck;
import ac.grim.grimac.player.GrimPlayer;
import com.github.retrooper.packetevents.event.PacketReceiveEvent;
import com.github.retrooper.packetevents.protocol.entity.type.EntityTypes;
import com.github.retrooper.packetevents.protocol.packettype.PacketType.Play.Client;
import com.github.retrooper.packetevents.wrapper.play.client.WrapperPlayClientEntityAction;
import com.github.retrooper.packetevents.wrapper.play.client.WrapperPlayClientEntityAction.Action;
Expand All @@ -20,10 +19,10 @@ public BadPacketsQ(final GrimPlayer player) {
public void onPacketReceive(PacketReceiveEvent event) {
if (event.getPacketType() == Client.ENTITY_ACTION) {
WrapperPlayClientEntityAction wrapper = new WrapperPlayClientEntityAction(event);
// Camels are able to send negative jump boost, how and why!?
if (wrapper.getJumpBoost() < 0 && player.compensatedEntities.getSelf().getRiding().getType() == EntityTypes.CAMEL) return;

if (wrapper.getJumpBoost() < 0 || wrapper.getJumpBoost() > 100 || wrapper.getEntityId() != player.entityID || (wrapper.getAction() != Action.START_JUMPING_WITH_HORSE && wrapper.getJumpBoost() != 0)) {
// you are able to send negative jump boost, how and why!?
if (Math.abs(wrapper.getJumpBoost()) > 100
|| wrapper.getEntityId() != player.entityID
|| wrapper.getAction() != Action.START_JUMPING_WITH_HORSE && wrapper.getJumpBoost() != 0) {
if (flagAndAlert("boost=" + wrapper.getJumpBoost() + ", action=" + wrapper.getAction() + ", entity=" + wrapper.getEntityId()) && shouldModifyPackets()) {
event.setCancelled(true);
player.onPacketCancel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ public void onPredictionComplete(final PredictionComplete predictionComplete) {

if (player.isTickingReliablyFor(3)) {
for (; flags > 0; flags--) {
if (flagAndAlert()) {
setbackIfAboveSetbackVL();
}
flagAndAlertWithSetback();
}
}

Expand Down Expand Up @@ -64,6 +62,10 @@ public void onPacketReceive(PacketReceiveEvent event) {

case START_SPRINTING:
case STOP_SPRINTING:
if (player.inVehicle()) {
return;
}

if (sprint) {
if (player.canSkipTicks() || flagAndAlert()) {
flags++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ public void onBlockBreak(BlockBreak blockBreak) {
}

if (blockDelayBalance > 1000) { // If more than a second of advantage
flagAndAlert("Delay=" + breakDelay);
if (shouldModifyPackets()) {
if (flagAndAlert("Delay=" + breakDelay) && shouldModifyPackets()) {
blockBreak.cancel();
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/ac/grim/grimac/checks/impl/elytra/ElytraA.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ public ElytraA(GrimPlayer player) {
}

public void onStartGliding(PacketReceiveEvent event) {
if (player.getClientVersion().isOlderThanOrEquals(ClientVersion.V_1_8)) {
return;
}

if (player.isGliding && flagAndAlert()) {
setback = true;
if (shouldModifyPackets()) {
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/ac/grim/grimac/checks/impl/elytra/ElytraC.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import ac.grim.grimac.utils.anticheat.update.PredictionComplete;
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.protocol.player.GameMode;
import com.github.retrooper.packetevents.wrapper.play.client.WrapperPlayClientEntityAction;

Expand All @@ -21,6 +22,10 @@ public ElytraC(GrimPlayer player) {

@Override
public void onPacketReceive(PacketReceiveEvent event) {
if (player.getClientVersion().isOlderThanOrEquals(ClientVersion.V_1_8)) {
return;
}

if (player.gamemode == GameMode.SPECTATOR) {
glideThisTick = glideLastTick = false;
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/ac/grim/grimac/checks/impl/elytra/ElytraD.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import ac.grim.grimac.utils.anticheat.update.PredictionComplete;
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.WrapperPlayClientEntityAction;

@CheckData(name = "ElytraD", description = "Started gliding without an elytra", experimental = true)
Expand All @@ -19,6 +20,10 @@ public ElytraD(GrimPlayer player) {

@Override
public void onPacketReceive(PacketReceiveEvent event) {
if (player.getClientVersion().isOlderThanOrEquals(ClientVersion.V_1_8)) {
return;
}

if (event.getPacketType() == PacketType.Play.Client.ENTITY_ACTION
&& new WrapperPlayClientEntityAction(event).getAction() == WrapperPlayClientEntityAction.Action.START_FLYING_WITH_ELYTRA
&& !player.canGlide()
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/ac/grim/grimac/checks/impl/elytra/ElytraE.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import ac.grim.grimac.utils.anticheat.update.PredictionComplete;
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.WrapperPlayClientEntityAction;

@CheckData(name = "ElytraE", description = "Started gliding while flying", experimental = true)
Expand All @@ -19,6 +20,10 @@ public ElytraE(GrimPlayer player) {

@Override
public void onPacketReceive(PacketReceiveEvent event) {
if (player.getClientVersion().isOlderThanOrEquals(ClientVersion.V_1_8)) {
return;
}

if (event.getPacketType() == PacketType.Play.Client.ENTITY_ACTION
&& new WrapperPlayClientEntityAction(event).getAction() == WrapperPlayClientEntityAction.Action.START_FLYING_WITH_ELYTRA
&& player.isFlying
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/ac/grim/grimac/checks/impl/elytra/ElytraF.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import ac.grim.grimac.utils.anticheat.update.PredictionComplete;
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.WrapperPlayClientEntityAction;

@CheckData(name = "ElytraF", description = "Started gliding while on ground", experimental = true)
Expand All @@ -19,6 +20,10 @@ public ElytraF(GrimPlayer player) {

@Override
public void onPacketReceive(PacketReceiveEvent event) {
if (player.getClientVersion().isOlderThanOrEquals(ClientVersion.V_1_8)) {
return;
}

if (event.getPacketType() == PacketType.Play.Client.ENTITY_ACTION
&& new WrapperPlayClientEntityAction(event).getAction() == WrapperPlayClientEntityAction.Action.START_FLYING_WITH_ELYTRA
&& player.clientClaimsLastOnGround
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/ac/grim/grimac/checks/impl/elytra/ElytraH.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
import ac.grim.grimac.utils.anticheat.update.PredictionComplete;
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.WrapperPlayClientEntityAction;

@CheckData(name = "ElytraF", description = "Started gliding in vehicle", experimental = true)
@CheckData(name = "ElytraH", description = "Started gliding in vehicle", experimental = true)
public class ElytraH extends Check implements PostPredictionCheck {
private boolean setback;

Expand All @@ -19,6 +20,10 @@ public ElytraH(GrimPlayer player) {

@Override
public void onPacketReceive(PacketReceiveEvent event) {
if (player.getClientVersion().isOlderThanOrEquals(ClientVersion.V_1_8)) {
return;
}

if (event.getPacketType() == PacketType.Play.Client.ENTITY_ACTION
&& new WrapperPlayClientEntityAction(event).getAction() == WrapperPlayClientEntityAction.Action.START_FLYING_WITH_ELYTRA
&& player.inVehicle()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void onPacketReceive(PacketReceiveEvent event) {
if (wrapper.isOnGround() && !hasPosition) {
if (!isNearGround(wrapper.isOnGround())) { // If player isn't near ground
// 1.8 boats have a mind on their own... only flag if they're not near a boat or are on 1.9+
if (!GhostBlockDetector.isGhostBlock(player) && flagWithSetback()) alert("");
if (!GhostBlockDetector.isGhostBlock(player)) flagAndAlertWithSetback();
if (shouldModifyPackets()) {
wrapper.setOnGround(false);
event.markForReEncode(true);
Expand Down

This file was deleted.

8 changes: 4 additions & 4 deletions src/main/java/ac/grim/grimac/checks/impl/movement/NoSlow.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import ac.grim.grimac.utils.anticheat.update.PredictionComplete;
import com.github.retrooper.packetevents.protocol.player.ClientVersion;

@CheckData(name = "NoSlow (Prediction)", configName = "NoSlow", description = "Was not slowed while using an item", setback = 5)
@CheckData(name = "NoSlow", description = "Was not slowed while using an item", setback = 5)
public class NoSlow extends Check implements PostPredictionCheck {
double offsetToFlag;
double bestOffset = 1;
Expand All @@ -34,8 +34,8 @@ public void onPredictionComplete(final PredictionComplete predictionComplete) {
}

if (bestOffset > offsetToFlag) {
if (flaggedLastTick && flagWithSetback()) {
alert("");
if (flaggedLastTick) {
flagAndAlertWithSetback();
}
flaggedLastTick = true;
} else {
Expand All @@ -52,6 +52,6 @@ public void handlePredictionAnalysis(double offset) {

@Override
public void onReload(ConfigManager config) {
offsetToFlag = config.getDoubleElse("NoSlow.threshold", 0.001);
offsetToFlag = config.getDoubleElse(getConfigName() + ".threshold", 0.001);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import com.github.retrooper.packetevents.event.PacketSendEvent;
import com.github.retrooper.packetevents.protocol.packettype.PacketType;

@CheckData(name = "MultiActionsC", description = "Clicked in inventory while performing other actions", experimental = true)
@CheckData(name = "MultiActionsC", description = "Clicked in inventory while sprinting", experimental = true)
public class MultiActionsC extends Check implements PacketCheck {
public MultiActionsC(GrimPlayer player) {
super(player);
Expand All @@ -19,13 +19,8 @@ public MultiActionsC(GrimPlayer player) {
@Override
public void onPacketReceive(PacketReceiveEvent event) {
if (event.getPacketType() == PacketType.Play.Client.CLICK_WINDOW) {
String verbose = player.isSprinting && !player.isSwimming && !serverOpenedInventoryThisTick ? "sprinting" : "";

if (player.packetStateData.isSlowedByUsingItem()) {
verbose += (verbose.isEmpty() ? "" : ", ") + "using";
}

if (!verbose.isEmpty() && flagAndAlert(verbose) && shouldModifyPackets()) {
if (player.isSprinting && !player.isSwimming && !serverOpenedInventoryThisTick && flagAndAlert() && shouldModifyPackets()) {
event.setCancelled(true);
player.onPacketCancel();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import com.github.retrooper.packetevents.event.PacketReceiveEvent;
import com.github.retrooper.packetevents.protocol.packettype.PacketType;

@CheckData(name = "MultiActionsD", description = "Closed inventory while performing other actions", experimental = true)
@CheckData(name = "MultiActionsD", description = "Closed inventory while sprinting", experimental = true)
public class MultiActionsD extends Check implements PacketCheck {
public MultiActionsD(GrimPlayer player) {
super(player);
Expand All @@ -16,13 +16,7 @@ public MultiActionsD(GrimPlayer player) {
@Override
public void onPacketReceive(PacketReceiveEvent event) {
if (event.getPacketType() == PacketType.Play.Client.CLOSE_WINDOW) {
String verbose = player.isSprinting && !player.isSwimming ? "sprinting" : "";

if (player.packetStateData.isSlowedByUsingItem()) {
verbose += (verbose.isEmpty() ? "" : ", ") + "using";
}

if (!verbose.isEmpty() && flagAndAlert(verbose) && shouldModifyPackets()) {
if (player.isSprinting && !player.isSwimming && flagAndAlert() && shouldModifyPackets()) {
event.setCancelled(true);
player.onPacketCancel();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;

@CheckData(name = "Prediction (Debug)")
public class DebugHandler extends Check implements PostPredictionCheck {

Set<Player> listeners = new CopyOnWriteArraySet<>(new HashSet<>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ public void onPredictionComplete(final PredictionComplete predictionComplete) {
if (player.packetStateData.lastPacketWasTeleport) return;

if (player.clientClaimsLastOnGround != player.onGround) {
if (flagAndAlert("claimed " + player.clientClaimsLastOnGround)) {
setbackIfAboveSetbackVL();
}
flagAndAlertWithSetback("claimed " + player.clientClaimsLastOnGround);
player.checkManager.getNoFall().flipPlayerGroundStatus = true;
}
}
Expand Down
Loading

0 comments on commit ff28ad2

Please sign in to comment.