From 81feb5be3f084029fd00cac15253534e324db360 Mon Sep 17 00:00:00 2001 From: ManInMyVan Date: Sun, 17 Nov 2024 17:25:57 -0700 Subject: [PATCH] fix falses --- .../checks/impl/packetorder/PacketOrderK.java | 42 ++++++++++++++++--- .../checks/impl/packetorder/PacketOrderL.java | 24 +++++++---- .../ac/grim/grimac/manager/CheckManager.java | 2 +- 3 files changed, 53 insertions(+), 15 deletions(-) diff --git a/src/main/java/ac/grim/grimac/checks/impl/packetorder/PacketOrderK.java b/src/main/java/ac/grim/grimac/checks/impl/packetorder/PacketOrderK.java index eda4559330..8a6e6f2c15 100644 --- a/src/main/java/ac/grim/grimac/checks/impl/packetorder/PacketOrderK.java +++ b/src/main/java/ac/grim/grimac/checks/impl/packetorder/PacketOrderK.java @@ -2,33 +2,63 @@ 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.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.WrapperPlayClientClientStatus; +import java.util.ArrayDeque; + @CheckData(name = "PacketOrderK", experimental = true) -public class PacketOrderK extends Check implements PacketCheck { +public class PacketOrderK extends Check implements PostPredictionCheck { public PacketOrderK(final GrimPlayer player) { super(player); } + private final ArrayDeque flags = new ArrayDeque<>(); + @Override public void onPacketReceive(PacketReceiveEvent event) { if (event.getPacketType() == PacketType.Play.Client.CLIENT_STATUS) { if (new WrapperPlayClientClientStatus(event).getAction() == WrapperPlayClientClientStatus.Action.OPEN_INVENTORY_ACHIEVEMENT) { if (player.packetOrderProcessor.isClickingInInventory() || player.packetOrderProcessor.isClosingInventory()) { - flagAndAlert(); + if (player.getClientVersion().isOlderThanOrEquals(ClientVersion.V_1_8)) { + flagAndAlert("open"); + } else { + flags.add("open"); + } } } } if (event.getPacketType() == PacketType.Play.Client.CLICK_WINDOW || event.getPacketType() == PacketType.Play.Client.CLOSE_WINDOW) { - if (player.packetOrderProcessor.isOpeningInventory() && flagAndAlert() && shouldModifyPackets()) { - event.setCancelled(true); - player.onPacketCancel(); + if (player.packetOrderProcessor.isOpeningInventory()) { + if (player.getClientVersion().isOlderThanOrEquals(ClientVersion.V_1_8)) { + if (flagAndAlert(event.getPacketType() == PacketType.Play.Client.CLICK_WINDOW ? "click" : "close") && shouldModifyPackets()) { + event.setCancelled(true); + player.onPacketCancel(); + } + } else { + flags.add(event.getPacketType() == PacketType.Play.Client.CLICK_WINDOW ? "click" : "close"); + } + } + } + } + + @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 && predictionComplete.isChecked()) { + for (String verbose : flags) { + flagAndAlert(verbose); } } + + flags.clear(); } } diff --git a/src/main/java/ac/grim/grimac/checks/impl/packetorder/PacketOrderL.java b/src/main/java/ac/grim/grimac/checks/impl/packetorder/PacketOrderL.java index 0d936abd03..a0a3430017 100644 --- a/src/main/java/ac/grim/grimac/checks/impl/packetorder/PacketOrderL.java +++ b/src/main/java/ac/grim/grimac/checks/impl/packetorder/PacketOrderL.java @@ -12,21 +12,29 @@ import com.github.retrooper.packetevents.wrapper.play.client.WrapperPlayClientClientStatus; import com.github.retrooper.packetevents.wrapper.play.client.WrapperPlayClientPlayerDigging; +import java.util.ArrayDeque; + @CheckData(name = "PacketOrderL", experimental = true) public class PacketOrderL extends Check implements PostPredictionCheck { public PacketOrderL(final GrimPlayer player) { super(player); } - private int invalid; + private final ArrayDeque flags = new ArrayDeque<>(); @Override public void onPacketReceive(PacketReceiveEvent event) { if (event.getPacketType() == PacketType.Play.Client.CLIENT_STATUS) { if (new WrapperPlayClientClientStatus(event).getAction() == WrapperPlayClientClientStatus.Action.OPEN_INVENTORY_ACHIEVEMENT) { - if (player.packetOrderProcessor.isDropping() && flagAndAlert("inventory") && shouldModifyPackets()) { - event.setCancelled(true); - player.onPacketCancel(); + if (player.packetOrderProcessor.isDropping()) { + if (player.getClientVersion().isOlderThanOrEquals(ClientVersion.V_1_8)) { + if (flagAndAlert("inventory") && shouldModifyPackets()) { + event.setCancelled(true); + player.onPacketCancel(); + } + } else { + flags.add("inventory"); + } } } } @@ -34,7 +42,7 @@ public void onPacketReceive(PacketReceiveEvent event) { if (event.getPacketType() == PacketType.Play.Client.PLAYER_DIGGING) { if (new WrapperPlayClientPlayerDigging(event).getAction() == DiggingAction.SWAP_ITEM_WITH_OFFHAND) { if (player.packetOrderProcessor.isDropping()) { - invalid++; + flags.add("swap"); } } } @@ -46,11 +54,11 @@ public void onPredictionComplete(PredictionComplete predictionComplete) { if (player.getClientVersion().isOlderThanOrEquals(ClientVersion.V_1_8)) return; if (!player.skippedTickInActualMovement && predictionComplete.isChecked()) { - for (; invalid >= 1; invalid--) { - flagAndAlert("swap"); + for (String verbose : flags) { + flagAndAlert(verbose); } } - invalid = 0; + flags.clear(); } } diff --git a/src/main/java/ac/grim/grimac/manager/CheckManager.java b/src/main/java/ac/grim/grimac/manager/CheckManager.java index e6b9a84ab9..3b00c9d6a8 100644 --- a/src/main/java/ac/grim/grimac/manager/CheckManager.java +++ b/src/main/java/ac/grim/grimac/manager/CheckManager.java @@ -102,7 +102,6 @@ public CheckManager(GrimPlayer player) { .put(PacketOrderB.class, new PacketOrderB(player)) .put(PacketOrderC.class, new PacketOrderC(player)) .put(PacketOrderD.class, new PacketOrderD(player)) - .put(PacketOrderK.class, new PacketOrderK(player)) .put(PacketOrderP.class, new PacketOrderP(player)) .put(NoSlowB.class, new NoSlowB(player)) .put(SetbackBlocker.class, new SetbackBlocker(player)) // Must be last class otherwise we can't check while blocking packets @@ -136,6 +135,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(PacketOrderL.class, new PacketOrderL(player)) .put(PacketOrderM.class, new PacketOrderM(player)) .put(NoFallB.class, new NoFallB(player))