diff --git a/src/main/java/ac/grim/grimac/checks/impl/badpackets/BadPacketsX.java b/src/main/java/ac/grim/grimac/checks/impl/badpackets/BadPacketsX.java new file mode 100644 index 0000000000..41a66b2fc3 --- /dev/null +++ b/src/main/java/ac/grim/grimac/checks/impl/badpackets/BadPacketsX.java @@ -0,0 +1,45 @@ +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.player.GrimPlayer; +import ac.grim.grimac.utils.nmsutil.BlockBreakSpeed; +import com.github.retrooper.packetevents.event.PacketReceiveEvent; +import com.github.retrooper.packetevents.protocol.item.type.ItemTypes; +import com.github.retrooper.packetevents.protocol.player.ClientVersion; +import com.github.retrooper.packetevents.protocol.player.DiggingAction; +import com.github.retrooper.packetevents.protocol.world.states.type.StateType; +import com.github.retrooper.packetevents.protocol.world.states.type.StateTypes; +import com.github.retrooper.packetevents.wrapper.play.client.WrapperPlayClientPlayerDigging; + +@CheckData(name = "BadPacketsX", experimental = true) +public class BadPacketsX extends Check implements PacketCheck { + public BadPacketsX(GrimPlayer player) { + super(player); + } + + public final boolean noFireHitbox = player.getClientVersion().isOlderThanOrEquals(ClientVersion.V_1_15_2); + + public final void handle(PacketReceiveEvent event, WrapperPlayClientPlayerDigging dig, StateType block) { + if (dig.getAction() != DiggingAction.START_DIGGING && dig.getAction() != DiggingAction.FINISHED_DIGGING) + return; + + final boolean invalid; + + if (dig.getAction() == DiggingAction.FINISHED_DIGGING) { + invalid = BlockBreakSpeed.getBlockDamage(player, dig.getBlockPosition()) >= 1 || block.getHardness() == -1.0f; + } else invalid = (block == StateTypes.LIGHT && !(player.getInventory().getHeldItem().is(ItemTypes.LIGHT) || player.getInventory().getOffHand().is(ItemTypes.LIGHT))) + || block.isAir() + || block == StateTypes.WATER + || block == StateTypes.LAVA + || block == StateTypes.BUBBLE_COLUMN + || block == StateTypes.MOVING_PISTON + || (block == StateTypes.FIRE && noFireHitbox); + + if (invalid && flagAndAlert("block=" + block.getName() + ", type=" + dig.getAction()) && shouldModifyPackets()) { + event.setCancelled(true); + player.onPacketCancel(); + } + } +} diff --git a/src/main/java/ac/grim/grimac/events/packets/CheckManagerListener.java b/src/main/java/ac/grim/grimac/events/packets/CheckManagerListener.java index 2638793eb2..87c440adac 100644 --- a/src/main/java/ac/grim/grimac/events/packets/CheckManagerListener.java +++ b/src/main/java/ac/grim/grimac/events/packets/CheckManagerListener.java @@ -1,6 +1,7 @@ package ac.grim.grimac.events.packets; import ac.grim.grimac.GrimAPI; +import ac.grim.grimac.checks.impl.badpackets.BadPacketsX; import ac.grim.grimac.events.packets.patch.ResyncWorldUtil; import ac.grim.grimac.player.GrimPlayer; import ac.grim.grimac.utils.anticheat.update.*; @@ -434,16 +435,18 @@ public void onPacketReceive(PacketReceiveEvent event) { WrapperPlayClientPlayerDigging dig = new WrapperPlayClientPlayerDigging(event); WrappedBlockState block = player.compensatedWorld.getWrappedBlockStateAt(dig.getBlockPosition()); + player.checkManager.getPacketCheck(BadPacketsX.class).handle(event, dig, block.getType()); + if (dig.getAction() == DiggingAction.FINISHED_DIGGING) { // Not unbreakable - if (block.getType().getHardness() != -1.0f) { + if (block.getType().getHardness() != -1.0f && !event.isCancelled()) { player.compensatedWorld.startPredicting(); player.compensatedWorld.updateBlock(dig.getBlockPosition().getX(), dig.getBlockPosition().getY(), dig.getBlockPosition().getZ(), 0); player.compensatedWorld.stopPredicting(dig); } } - if (dig.getAction() == DiggingAction.START_DIGGING) { + if (dig.getAction() == DiggingAction.START_DIGGING && !event.isCancelled()) { double damage = BlockBreakSpeed.getBlockDamage(player, dig.getBlockPosition()); //Instant breaking, no damage means it is unbreakable by creative players (with swords) @@ -460,8 +463,10 @@ public void onPacketReceive(PacketReceiveEvent event) { } } - if (dig.getAction() == DiggingAction.START_DIGGING || dig.getAction() == DiggingAction.FINISHED_DIGGING || dig.getAction() == DiggingAction.CANCELLED_DIGGING) { - player.compensatedWorld.handleBlockBreakPrediction(dig); + if (!event.isCancelled()) { + if (dig.getAction() == DiggingAction.START_DIGGING || dig.getAction() == DiggingAction.FINISHED_DIGGING || dig.getAction() == DiggingAction.CANCELLED_DIGGING) { + player.compensatedWorld.handleBlockBreakPrediction(dig); + } } } diff --git a/src/main/java/ac/grim/grimac/manager/CheckManager.java b/src/main/java/ac/grim/grimac/manager/CheckManager.java index c5ece5a3ac..c247d23a55 100644 --- a/src/main/java/ac/grim/grimac/manager/CheckManager.java +++ b/src/main/java/ac/grim/grimac/manager/CheckManager.java @@ -90,6 +90,7 @@ public CheckManager(GrimPlayer player) { .put(BadPacketsU.class, new BadPacketsU(player)) .put(BadPacketsV.class, new BadPacketsV(player)) .put(BadPacketsW.class, new BadPacketsW(player)) + .put(BadPacketsX.class, new BadPacketsX(player)) .put(FastBreak.class, new FastBreak(player)) .put(TransactionOrder.class, new TransactionOrder(player)) .put(NoSlowB.class, new NoSlowB(player))