Skip to content

Commit

Permalink
Add BadPackets3
Browse files Browse the repository at this point in the history
  • Loading branch information
ManInMyVan committed Jun 13, 2024
1 parent 21c119d commit b80b239
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package ac.grim.grimac.checks.impl.badpackets;

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;
import com.github.retrooper.packetevents.wrapper.play.client.WrapperPlayClientPlayerFlying;

@CheckData(name = "BadPackets3")
public class BadPackets3 extends Check implements PacketCheck, PostPredictionCheck {
public BadPackets3(GrimPlayer player) {
super(player);
}

private float sprints = 0;
private float sneaks = 0;

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

if (player.skippedTickInActualMovement) {
sprints *= 0.05f;
sneaks *= 0.05f;
}

for (; sneaks > 1; sneaks--) flagAndAlert("sneak");
for (; sprints > 1; sprints--) flagAndAlert("sprint");
sneaks = 0;
sprints = 0;
}

@Override
public void onPacketReceive(PacketReceiveEvent event) {
if (WrapperPlayClientPlayerFlying.isFlying(event.getPacketType()) && player.getClientVersion().isOlderThan(ClientVersion.V_1_9) && !player.packetStateData.lastPacketWasTeleport) {
sprints = 0;
sneaks = 0;
return;
}

if (event.getPacketType() == PacketType.Play.Client.ENTITY_ACTION) {
switch (new WrapperPlayClientEntityAction(event).getAction()) {
case START_SNEAKING:
case STOP_SNEAKING:
sneaks++;
if (player.getClientVersion().isOlderThan(ClientVersion.V_1_9) && sneaks > 1) {
if (flagAndAlert("sneak") && shouldModifyPackets()) {
event.setCancelled(true);
player.onPacketCancel();
}
}
break;
case START_SPRINTING:
case STOP_SPRINTING:
sprints++;
if (player.getClientVersion().isOlderThan(ClientVersion.V_1_9) && sprints > 1) {
if (flagAndAlert("sprint") && shouldModifyPackets()) {
event.setCancelled(true);
player.onPacketCancel();
}
}
break;
}
}
}
}
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 @@ -124,6 +124,7 @@ public CheckManager(GrimPlayer player) {
.put(SuperDebug.class, new SuperDebug(player))
.put(DebugHandler.class, new DebugHandler(player))
.put(EntityControl.class, new EntityControl(player))
.put(BadPackets3.class, new BadPackets3(player))
.put(NoSlowA.class, new NoSlowA(player))
.put(SetbackTeleportUtil.class, new SetbackTeleportUtil(player)) // Avoid teleporting to new position, update safe pos last
.put(CompensatedFireworks.class, player.compensatedFireworks)
Expand Down

0 comments on commit b80b239

Please sign in to comment.