Skip to content

Commit

Permalink
Merge pull request #1478 from ManInMyVan/SprintChecks
Browse files Browse the repository at this point in the history
Add NoSlowC, NoSlowD, and NoSlowE
  • Loading branch information
AoElite authored Jul 17, 2024
2 parents bc0b0d5 + f8c97d2 commit 5410e1d
Show file tree
Hide file tree
Showing 9 changed files with 169 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/main/java/ac/grim/grimac/checks/impl/movement/NoSlowC.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
53 changes: 53 additions & 0 deletions src/main/java/ac/grim/grimac/checks/impl/movement/NoSlowD.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
}
42 changes: 42 additions & 0 deletions src/main/java/ac/grim/grimac/checks/impl/movement/NoSlowE.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -217,7 +218,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;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
3 changes: 3 additions & 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,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))
Expand Down
Original file line number Diff line number Diff line change
@@ -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.data.packetentity.PacketEntity;
Expand Down Expand Up @@ -63,6 +64,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;
Expand All @@ -83,6 +86,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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -65,6 +67,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);
}
Expand Down

0 comments on commit 5410e1d

Please sign in to comment.