Skip to content

Commit

Permalink
Add PacketOrderK
Browse files Browse the repository at this point in the history
  • Loading branch information
ManInMyVan committed Sep 1, 2024
1 parent 2c31868 commit fc1d341
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package ac.grim.grimac.checks.impl.packetorder;

import ac.grim.grimac.checks.Check;
import ac.grim.grimac.checks.CheckData;
import ac.grim.grimac.checks.type.PostPredictionCheck;
import ac.grim.grimac.player.GrimPlayer;
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.WrapperPlayClientInteractEntity;
import com.github.retrooper.packetevents.wrapper.play.client.WrapperPlayClientPlayerFlying;

import java.util.ArrayDeque;
import java.util.ArrayList;

@CheckData(name = "PacketOrderK", experimental = true)
public class PacketOrderK extends Check implements PostPredictionCheck {
public PacketOrderK(final GrimPlayer player) {
super(player);
}

private final ArrayDeque<String> flags = new ArrayDeque<>();
private int lastEntity;
private boolean hasInteracted = false;

@Override
public void onPacketReceive(PacketReceiveEvent event) {
if (event.getPacketType() == PacketType.Play.Client.INTERACT_ENTITY) {
int entity = new WrapperPlayClientInteractEntity(event).getEntityId();
if (hasInteracted && entity != lastEntity) {
String verbose = "lastEntity=" + lastEntity + ", entity=" + entity;
if (player.getClientVersion().isOlderThanOrEquals(ClientVersion.V_1_8)) {
if (flagAndAlert(verbose) && shouldModifyPackets()) {
event.setCancelled(true);
player.onPacketCancel();
}
} else {
flags.add(verbose);
}
}
lastEntity = entity;
hasInteracted = true;
}

if (WrapperPlayClientPlayerFlying.isFlying(event.getPacketType()) && player.getClientVersion().isOlderThanOrEquals(ClientVersion.V_1_8) && !player.packetStateData.lastPacketWasTeleport) {
hasInteracted = false;
}
}

@Override
public void onPredictionComplete(PredictionComplete predictionComplete) {
// we don't need to check pre-1.9 players here (no tick skipping)
if (player.getClientVersion().isOlderThanOrEquals(ClientVersion.V_1_8)) return;

if (!player.skippedTickInActualMovement) {
for (String verbose : flags) {
flagAndAlert(verbose);
}
}

flags.clear();
hasInteracted = false;
}
}
1 change: 1 addition & 0 deletions src/main/java/ac/grim/grimac/manager/CheckManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ public CheckManager(GrimPlayer player) {
.put(PacketOrderH.class, new PacketOrderH(player))
.put(PacketOrderI.class, new PacketOrderI(player))
.put(PacketOrderJ.class, new PacketOrderJ(player))
.put(PacketOrderK.class, new PacketOrderK(player))
.put(NoFallB.class, new NoFallB(player))
.put(OffsetHandler.class, new OffsetHandler(player))
.put(SuperDebug.class, new SuperDebug(player))
Expand Down

0 comments on commit fc1d341

Please sign in to comment.