From f8c97d2eaef0b98abe9ec978b296257b39b998a9 Mon Sep 17 00:00:00 2001 From: ManInMyVan Date: Mon, 20 May 2024 16:48:06 -0600 Subject: [PATCH] Add NoSlowC, NoSlowD, and NoSlowE --- .../grimac/checks/impl/movement/NoSlowC.java | 47 ++++++++++++++++ .../grimac/checks/impl/movement/NoSlowD.java | 53 +++++++++++++++++++ .../grimac/checks/impl/movement/NoSlowE.java | 42 +++++++++++++++ .../events/packets/PacketEntityAction.java | 3 ++ .../events/packets/PacketPlayerDigging.java | 7 +++ .../packets/PacketSelfMetadataListener.java | 3 ++ .../ac/grim/grimac/manager/CheckManager.java | 3 ++ .../predictionengine/PlayerBaseTick.java | 5 ++ .../data/packetentity/PacketEntitySelf.java | 6 +++ 9 files changed, 169 insertions(+) create mode 100644 src/main/java/ac/grim/grimac/checks/impl/movement/NoSlowC.java create mode 100644 src/main/java/ac/grim/grimac/checks/impl/movement/NoSlowD.java create mode 100644 src/main/java/ac/grim/grimac/checks/impl/movement/NoSlowE.java diff --git a/src/main/java/ac/grim/grimac/checks/impl/movement/NoSlowC.java b/src/main/java/ac/grim/grimac/checks/impl/movement/NoSlowC.java new file mode 100644 index 0000000000..39f77a941c --- /dev/null +++ b/src/main/java/ac/grim/grimac/checks/impl/movement/NoSlowC.java @@ -0,0 +1,47 @@ +package ac.grim.grimac.checks.impl.movement; + +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.WrapperPlayClientEntityAction; + +@CheckData(name = "NoSlowC", setback = 5, experimental = true) +public class NoSlowC extends Check implements PostPredictionCheck, PacketCheck { + public NoSlowC(GrimPlayer player) { + super(player); + } + + public boolean startedSprintingBeforeSlowMovement = false; + + @Override + public void onPacketReceive(PacketReceiveEvent event) { + if (event.getPacketType() == PacketType.Play.Client.ENTITY_ACTION) { + if (new WrapperPlayClientEntityAction(event).getAction() == WrapperPlayClientEntityAction.Action.START_SPRINTING) { + startedSprintingBeforeSlowMovement = false; + } + } + } + + @Override + public void onPredictionComplete(final PredictionComplete predictionComplete) { + if (!predictionComplete.isChecked()) return; + + if (player.isSlowMovement) { + // https://bugs.mojang.com/browse/MC-152728 + if (startedSprintingBeforeSlowMovement && player.getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_14_2)) { + reward(); + return; + } + + if (player.isSprinting && player.sneakingSpeedMultiplier < 0.8f) { + if (flagWithSetback()) alert(""); + } else reward(); + } + } +} diff --git a/src/main/java/ac/grim/grimac/checks/impl/movement/NoSlowD.java b/src/main/java/ac/grim/grimac/checks/impl/movement/NoSlowD.java new file mode 100644 index 0000000000..a8ca86cc43 --- /dev/null +++ b/src/main/java/ac/grim/grimac/checks/impl/movement/NoSlowD.java @@ -0,0 +1,53 @@ +package ac.grim.grimac.checks.impl.movement; + +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.WrapperPlayClientEntityAction; + +@CheckData(name = "NoSlowD", setback = 5, experimental = true) +public class NoSlowD extends Check implements PostPredictionCheck, PacketCheck { + public NoSlowD(GrimPlayer player) { + super(player); + } + + public boolean startedSprintingBeforeUse = false; + private boolean flaggedLastTick = false; + + @Override + public void onPacketReceive(PacketReceiveEvent event) { + if (event.getPacketType() == PacketType.Play.Client.ENTITY_ACTION) { + if (new WrapperPlayClientEntityAction(event).getAction() == WrapperPlayClientEntityAction.Action.START_SPRINTING) { + startedSprintingBeforeUse = false; + } + } + } + + @Override + public void onPredictionComplete(final PredictionComplete predictionComplete) { + if (!predictionComplete.isChecked()) return; + + if (player.packetStateData.slowedByUsingItem) { + // https://bugs.mojang.com/browse/MC-152728 + if (startedSprintingBeforeUse && player.getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_14_2)) { + reward(); + flaggedLastTick = false; + return; + } + + if (player.isSprinting) { + if (flaggedLastTick && flagWithSetback()) alert(""); + flaggedLastTick = true; + } else { + reward(); + flaggedLastTick = false; + } + } + } +} diff --git a/src/main/java/ac/grim/grimac/checks/impl/movement/NoSlowE.java b/src/main/java/ac/grim/grimac/checks/impl/movement/NoSlowE.java new file mode 100644 index 0000000000..cb441a3b55 --- /dev/null +++ b/src/main/java/ac/grim/grimac/checks/impl/movement/NoSlowE.java @@ -0,0 +1,42 @@ +package ac.grim.grimac.checks.impl.movement; + +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.wrapper.play.client.WrapperPlayClientEntityAction; + +import static com.github.retrooper.packetevents.protocol.potion.PotionTypes.BLINDNESS; + +@CheckData(name = "NoSlowE", setback = 5, experimental = true) +public class NoSlowE extends Check implements PostPredictionCheck, PacketCheck { + public NoSlowE(GrimPlayer player) { + super(player); + } + + public boolean startedSprintingBeforeBlind = false; + + @Override + public void onPacketReceive(PacketReceiveEvent event) { + if (event.getPacketType() == PacketType.Play.Client.ENTITY_ACTION) { + if (new WrapperPlayClientEntityAction(event).getAction() == WrapperPlayClientEntityAction.Action.START_SPRINTING) { + startedSprintingBeforeBlind = false; + } + } + } + + @Override + public void onPredictionComplete(final PredictionComplete predictionComplete) { + if (!predictionComplete.isChecked()) return; + + if (player.compensatedEntities.getSelf().potionsMap != null && player.compensatedEntities.getSelf().potionsMap.containsKey(BLINDNESS)) { + if (player.isSprinting && !startedSprintingBeforeBlind) { + if (flagWithSetback()) alert(""); + } else reward(); + } + } +} diff --git a/src/main/java/ac/grim/grimac/events/packets/PacketEntityAction.java b/src/main/java/ac/grim/grimac/events/packets/PacketEntityAction.java index 86f99275a4..e273c7d921 100644 --- a/src/main/java/ac/grim/grimac/events/packets/PacketEntityAction.java +++ b/src/main/java/ac/grim/grimac/events/packets/PacketEntityAction.java @@ -1,6 +1,9 @@ package ac.grim.grimac.events.packets; import ac.grim.grimac.GrimAPI; +import ac.grim.grimac.checks.impl.movement.NoSlowC; +import ac.grim.grimac.checks.impl.movement.NoSlowD; +import ac.grim.grimac.checks.impl.movement.NoSlowE; import ac.grim.grimac.player.GrimPlayer; import com.github.retrooper.packetevents.event.PacketListenerAbstract; import com.github.retrooper.packetevents.event.PacketListenerPriority; diff --git a/src/main/java/ac/grim/grimac/events/packets/PacketPlayerDigging.java b/src/main/java/ac/grim/grimac/events/packets/PacketPlayerDigging.java index 9c9b259fc4..8d5d5568d5 100644 --- a/src/main/java/ac/grim/grimac/events/packets/PacketPlayerDigging.java +++ b/src/main/java/ac/grim/grimac/events/packets/PacketPlayerDigging.java @@ -2,6 +2,7 @@ import ac.grim.grimac.GrimAPI; import ac.grim.grimac.checks.impl.movement.NoSlowA; +import ac.grim.grimac.checks.impl.movement.NoSlowD; import ac.grim.grimac.player.GrimPlayer; import com.github.retrooper.packetevents.PacketEvents; import com.github.retrooper.packetevents.event.PacketListenerAbstract; @@ -207,7 +208,13 @@ public void onPacketReceive(PacketReceiveEvent event) { final ItemStack item = hand == InteractionHand.MAIN_HAND ? player.getInventory().getHeldItem() : player.getInventory().getOffHand(); + final boolean wasSlow = player.packetStateData.slowedByUsingItem; + handleUseItem(player, item, hand); + + if (!wasSlow) { + player.checkManager.getPostPredictionCheck(NoSlowD.class).startedSprintingBeforeUse = player.packetStateData.slowedByUsingItem && player.isSprinting; + } } } } diff --git a/src/main/java/ac/grim/grimac/events/packets/PacketSelfMetadataListener.java b/src/main/java/ac/grim/grimac/events/packets/PacketSelfMetadataListener.java index f9b6a6a31d..50d2f8a8b8 100644 --- a/src/main/java/ac/grim/grimac/events/packets/PacketSelfMetadataListener.java +++ b/src/main/java/ac/grim/grimac/events/packets/PacketSelfMetadataListener.java @@ -1,6 +1,7 @@ package ac.grim.grimac.events.packets; import ac.grim.grimac.GrimAPI; +import ac.grim.grimac.checks.impl.movement.NoSlowD; import ac.grim.grimac.player.GrimPlayer; import ac.grim.grimac.utils.nmsutil.WatchableIndexUtil; import com.github.retrooper.packetevents.PacketEvents; @@ -206,6 +207,8 @@ public void onPacketSend(PacketSendEvent event) { // The above line is a hack to fake activate use item player.packetStateData.slowedByUsingItem = isActive; + player.checkManager.getPostPredictionCheck(NoSlowD.class).startedSprintingBeforeUse = player.packetStateData.slowedByUsingItem && player.isSprinting; + if (isActive) { player.packetStateData.eatingHand = isOffhand ? InteractionHand.OFF_HAND : InteractionHand.MAIN_HAND; } diff --git a/src/main/java/ac/grim/grimac/manager/CheckManager.java b/src/main/java/ac/grim/grimac/manager/CheckManager.java index f311f1f099..2a82b63fea 100644 --- a/src/main/java/ac/grim/grimac/manager/CheckManager.java +++ b/src/main/java/ac/grim/grimac/manager/CheckManager.java @@ -125,6 +125,9 @@ public CheckManager(GrimPlayer player) { .put(DebugHandler.class, new DebugHandler(player)) .put(EntityControl.class, new EntityControl(player)) .put(NoSlowA.class, new NoSlowA(player)) + .put(NoSlowC.class, new NoSlowC(player)) + .put(NoSlowD.class, new NoSlowD(player)) + .put(NoSlowE.class, new NoSlowE(player)) .put(SetbackTeleportUtil.class, new SetbackTeleportUtil(player)) // Avoid teleporting to new position, update safe pos last .put(CompensatedFireworks.class, player.compensatedFireworks) .put(SneakingEstimator.class, new SneakingEstimator(player)) diff --git a/src/main/java/ac/grim/grimac/predictionengine/PlayerBaseTick.java b/src/main/java/ac/grim/grimac/predictionengine/PlayerBaseTick.java index 3974ed249a..b99fe52f9e 100644 --- a/src/main/java/ac/grim/grimac/predictionengine/PlayerBaseTick.java +++ b/src/main/java/ac/grim/grimac/predictionengine/PlayerBaseTick.java @@ -1,5 +1,6 @@ package ac.grim.grimac.predictionengine; +import ac.grim.grimac.checks.impl.movement.NoSlowC; import ac.grim.grimac.player.GrimPlayer; import ac.grim.grimac.utils.collisions.datatypes.SimpleCollisionBox; import ac.grim.grimac.utils.enums.FluidTag; @@ -61,6 +62,8 @@ public void doBaseTick() { player.trackBaseTickAddition(waterPushVector); } + final boolean wasSlowMovement = player.isSlowMovement; + if (player.getClientVersion().isOlderThanOrEquals(ClientVersion.V_1_13_2)) { // 1.13.2 and below logic: If crouching, then slow movement, simple! player.isSlowMovement = player.isSneaking; @@ -81,6 +84,8 @@ public void doBaseTick() { if (player.compensatedEntities.getSelf().inVehicle()) player.isSlowMovement = false; + if (wasSlowMovement != player.isSlowMovement) player.checkManager.getPostPredictionCheck(NoSlowC.class).startedSprintingBeforeSlowMovement = player.isSlowMovement && player.isSprinting; + // Players in boats don't care about being in blocks if (!player.compensatedEntities.getSelf().inVehicle()) { this.moveTowardsClosestSpace(player.lastX - (player.boundingBox.maxX - player.boundingBox.minX) * 0.35, player.lastZ + (player.boundingBox.maxZ - player.boundingBox.minZ) * 0.35); diff --git a/src/main/java/ac/grim/grimac/utils/data/packetentity/PacketEntitySelf.java b/src/main/java/ac/grim/grimac/utils/data/packetentity/PacketEntitySelf.java index 67096816d8..15b762693b 100644 --- a/src/main/java/ac/grim/grimac/utils/data/packetentity/PacketEntitySelf.java +++ b/src/main/java/ac/grim/grimac/utils/data/packetentity/PacketEntitySelf.java @@ -1,5 +1,6 @@ package ac.grim.grimac.utils.data.packetentity; +import ac.grim.grimac.checks.impl.movement.NoSlowE; import ac.grim.grimac.player.GrimPlayer; import ac.grim.grimac.utils.collisions.datatypes.SimpleCollisionBox; import com.github.retrooper.packetevents.PacketEvents; @@ -8,6 +9,7 @@ import com.github.retrooper.packetevents.protocol.player.ClientVersion; import com.github.retrooper.packetevents.protocol.player.GameMode; import com.github.retrooper.packetevents.protocol.potion.PotionType; +import com.github.retrooper.packetevents.protocol.potion.PotionTypes; import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerUpdateAttributes; import lombok.Getter; import lombok.Setter; @@ -62,6 +64,10 @@ public boolean inVehicle() { @Override public void addPotionEffect(PotionType effect, int amplifier) { + if (effect == PotionTypes.BLINDNESS && (potionsMap == null || !potionsMap.containsKey(PotionTypes.BLINDNESS))) { + player.checkManager.getPostPredictionCheck(NoSlowE.class).startedSprintingBeforeBlind = player.isSprinting; + } + player.pointThreeEstimator.updatePlayerPotions(effect, amplifier); super.addPotionEffect(effect, amplifier); }