LiquidSense Dev NoSlow module 2 files, 851 lines

LiquidSense Dev NoSlow: Full Source Analysis

NoSlowDown attacks the item-use slowdown on two layers.

net/ccbluex/liquidbounce/features/module/modules/movement/NoSlow.kt · GitHub source ↗

Published 2026-08-12 · Updated 2026-08-12

Analysis

Overview

NoSlowDown attacks the item-use slowdown on two layers. Client-side, the fork's MixinEntityPlayerSP fires a SlowDownEvent carrying the vanilla 0.2F/0.2F multipliers whenever the player uses an item or sword-blocks, and the module's onSlowDown handler replaces those values with per-item multipliers (default 1.0, full speed). Server-side, the Packet family of modes keeps the item-use state re-armed: a C07 RELEASE_USE_ITEM in the motion PRE phase and a C08 use-item placement in POST, per tick or on a half-rate cadence depending on the mode, with a Hypixel variant that re-arms at a constant fake block coordinate.

Client-side slowdown removal

The fork hook lives in MixinEntityPlayerSP.onLivingUpdate: when a held item is present and the player is using it or sword-blocking through the Aura blocking status, and not riding, it constructs SlowDownEvent(0.2F, 0.2F), multiplies movementInput.moveStrafe and moveForward by the event's values, and resets sprintToggleTimer to 0. The module's onSlowDown handler rewrites those values through getMultiplier: ItemFood, ItemPotion and ItemBucketMilk pick the consume multipliers, ItemSword the block multipliers, ItemBow the bow multipliers, and any other item falls back to the vanilla 0.2F. All six multipliers default to 1.0, so a stock install completely cancels the input slowdown with no packet cost at all.

Packet re-arm loop

Packet mode runs from MotionEvent and needs a sword in hand, movement (unless AAC4 mode is on, which drops the movement gate) and a blocking state from either the player or the Aura blockingStatus. The PRE phase queues C07PacketPlayerDigging(RELEASE_USE_ITEM, BlockPos(-.8,-.8,-.8), DOWN) and POST queues C08PacketPlayerBlockPlacement with the same fake block position, face 255 and the held stack: the release ends the server-side use, the re-arm restores it, so the server never sees the sustained item-use that would re-apply slowdown. AAC4 mode halves the rate by gating on ticksExisted and 1 (odd ticks only) plus an aura-target or blocking requirement, using BlockPos(-1,-1,-1) for the release. Hyt32 fires whenever the Aura has no target, releasing at BlockPos.ORIGIN and re-arming at getHypixelBlockpos, which despite the Random calls always evaluates to the constant BlockPos(2820, 0, 2820).

SlowDownEvent as the mechanism

The event itself is defined in Events.kt with mutable strafe and forward floats, and the mixin reads the mutated values back through getStrafe and getForward before applying them. Because the module writes 1.0F defaults, the multiplication becomes identity and the sprintToggleTimer reset in the mixin stays vanilla. The packet ceremony therefore manages server-side item state only; the movement gain is purely the fork hook, which is why the module has no effect when the mixin is not active, and why the onSlowDown handler alone would be a no-op without the mixin firing the event.

source NoSlow.kt

NoSlow.kt146 lines · JavaOriginal ↗
1
/*
2
 * LiquidBounce Hacked Client
3
 * A free open source mixin-based injection hacked client for Minecraft using Minecraft Forge.
4
 * https://github.com/CCBlueX/LiquidBounce/
5
 */
6
package net.ccbluex.liquidbounce.features.module.modules.movement
7
8
import net.ccbluex.liquidbounce.LiquidBounce
9
import net.ccbluex.liquidbounce.event.EventState
10
import net.ccbluex.liquidbounce.event.EventTarget
11
import net.ccbluex.liquidbounce.event.MotionEvent
12
import net.ccbluex.liquidbounce.event.SlowDownEvent
13
import net.ccbluex.liquidbounce.features.module.Module
14
import net.ccbluex.liquidbounce.features.module.ModuleCategory
15
import net.ccbluex.liquidbounce.features.module.ModuleInfo
16
import net.ccbluex.liquidbounce.features.module.modules.combat.Aura
17
import net.ccbluex.liquidbounce.utils.MovementUtils
18
import net.ccbluex.liquidbounce.value.BoolValue
19
import net.ccbluex.liquidbounce.value.FloatValue
20
import net.minecraft.item.*
21
import net.minecraft.network.play.client.C07PacketPlayerDigging
22
import net.minecraft.network.play.client.C08PacketPlayerBlockPlacement
23
import net.minecraft.util.BlockPos
24
import net.minecraft.util.EnumFacing
25
import net.minecraft.util.MathHelper
26
27
@ModuleInfo(name = "NoSlowDown", description = "Cancels slowness effects caused by soulsand and using items.",
28
        category = ModuleCategory.MOVEMENT)
29
class NoSlow : Module() {
30
31
    private val blockForwardMultiplier = FloatValue("BlockForwardMultiplier", 1.0F, 0.2F, 1.0F)
32
    private val blockStrafeMultiplier = FloatValue("BlockStrafeMultiplier", 1.0F, 0.2F, 1.0F)
33
34
    private val consumeForwardMultiplier = FloatValue("ConsumeForwardMultiplier", 1.0F, 0.2F, 1.0F)
35
    private val consumeStrafeMultiplier = FloatValue("ConsumeStrafeMultiplier", 1.0F, 0.2F, 1.0F)
36
37
    private val bowForwardMultiplier = FloatValue("BowForwardMultiplier", 1.0F, 0.2F, 1.0F)
38
    private val bowStrafeMultiplier = FloatValue("BowStrafeMultiplier", 1.0F, 0.2F, 1.0F)
39
40
    private val packet = BoolValue("Packet", true)
41
    private val Hyt32 = BoolValue("Hyt32", true)
42
    private val A4 = BoolValue("AAC4", true)
43
    // Soulsand
44
    val soulsandValue = BoolValue("Soulsand", true)
45
    val aura = LiquidBounce.moduleManager[Aura::class.java] as Aura
46
47
    @EventTarget
48
    fun onMotion(event: MotionEvent) {
49
        val blockState = isBlocking()
50
        val heldItem = mc.thePlayer.heldItem
51
        if(!A4.get()){
52
            if (heldItem == null || heldItem.item !is ItemSword || !MovementUtils.isMoving()){
53
                return
54
            }
55
            if (!mc.thePlayer.isBlocking && !aura.blockingStatus) {
56
                return
57
            }
58
        } else {
59
            if (heldItem == null || heldItem.item !is ItemSword){
60
                return
61
            }
62
        }
63
64
        if (this.packet.get()) {
65
            when (event.eventState) {
66
                EventState.PRE -> {
67
                    val digging = C07PacketPlayerDigging(C07PacketPlayerDigging.Action.RELEASE_USE_ITEM, BlockPos(-.8,-.8,-.8), EnumFacing.DOWN)
68
                    mc.netHandler.addToSendQueue(digging)
69
                }
70
                EventState.POST -> {
71
                    val blockPlace = C08PacketPlayerBlockPlacement(BlockPos(-.8,-.8,-.8), 255, mc.thePlayer.inventory.getCurrentItem(), 0.0f, 0.0f, 0.0f)
72
                    mc.netHandler.addToSendQueue(blockPlace)
73
                }
74
            }
75
        }
76
        var test = fuckKotline(mc.thePlayer.ticksExisted and 1);
77
        if (this.A4.get() && (test || !(blockState)) && (aura.target != null || mc.thePlayer.isBlocking)) {
78
            when (event.eventState) {
79
                EventState.PRE -> {
80
                    val digging = C07PacketPlayerDigging(C07PacketPlayerDigging.Action.RELEASE_USE_ITEM, BlockPos(-1, -1, -1), EnumFacing.DOWN)
81
                    mc.netHandler.addToSendQueue(digging)
82
                }
83
                EventState.POST -> {
84
                    val blockPlace = C08PacketPlayerBlockPlacement(mc.thePlayer.inventory.getCurrentItem())
85
                    mc.netHandler.addToSendQueue(blockPlace)
86
                }
87
            }
88
        }
89
        if (this.Hyt32.get() && aura.target == null) {
90
            when (event.eventState) {
91
                EventState.PRE -> {
92
                    val digging = C07PacketPlayerDigging(C07PacketPlayerDigging.Action.RELEASE_USE_ITEM, BlockPos.ORIGIN, EnumFacing.DOWN)
93
                    mc.netHandler.addToSendQueue(digging)
94
                }
95
                EventState.POST -> {
96
                    mc.thePlayer.sendQueue.addToSendQueue(C08PacketPlayerBlockPlacement(getHypixelBlockpos(), 255, mc.thePlayer.inventory.getCurrentItem(), 0f, 0f, 0f))
97
                }
98
            }
99
        }
100
    }
101
102
    fun fuckKotline(value: Int): Boolean{
103
        return value == 1
104
    }
105
106
    fun getHypixelBlockpos(): BlockPos? {
107
        val random = java.util.Random()
108
        val dx = MathHelper.floor_double(random.nextDouble() / 1000 + 2820)
109
        val jy = MathHelper.floor_double(random.nextDouble() / 100 * 0.20000000298023224)
110
        val kz = MathHelper.floor_double(random.nextDouble() / 1000 + 2820)
111
        return BlockPos(dx, -jy % 255, kz)
112
    }
113
114
    @EventTarget
115
    fun onSlowDown(event: SlowDownEvent) {
116
        val heldItem = mc.thePlayer.heldItem?.item
117
118
        event.forward = getMultiplier(heldItem, true)
119
        event.strafe = getMultiplier(heldItem, false)
120
    }
121
122
    private fun getMultiplier(item: Item?, isForward: Boolean) = when (item) {
123
        is ItemFood, is ItemPotion, is ItemBucketMilk -> {
124
            if (isForward) this.consumeForwardMultiplier.get() else this.consumeStrafeMultiplier.get()
125
        }
126
        is ItemSword -> {
127
            if (isForward) this.blockForwardMultiplier.get() else this.blockStrafeMultiplier.get()
128
        }
129
        is ItemBow -> {
130
            if (isForward) this.bowForwardMultiplier.get() else this.bowStrafeMultiplier.get()
131
        }
132
        else -> 0.2F
133
    }
134
135
    fun isBlocking(): Boolean {
136
        return mc.thePlayer.isBlocking || aura.blockingStatus
137
    }
138
139
    override val tag: String?
140
        get() = when {
141
            packet.get() -> "Packet"
142
            Hyt32.get() -> "HytPacket"
143
            A4.get() -> "AAC4"
144
            else -> "Vanilla"
145
        }
146
}

What this file does

The module file holds every mode: the onMotion PRE/POST ceremony for Packet, AAC4 and Hyt32, the onSlowDown multiplier rewrite, the odd-tick gate in fuckKotline, and getHypixelBlockpos whose random-looking math always yields the constant block position (2820, 0, 2820). The Aura reference (blockingStatus, target) is what ties the packet cadence to combat state.

source MixinEntityPlayerSP.java (SlowDownEvent hook)

MixinEntityPlayerSP.java705 lines · JavaOriginal ↗
1
/*
2
 * LiquidBounce Hacked Client
3
 * A free open source mixin-based injection hacked client for Minecraft using Minecraft Forge.
4
 * https://github.com/CCBlueX/LiquidBounce/
5
 */
6
package net.ccbluex.liquidbounce.injection.forge.mixins.entity;
7
8
import net.ccbluex.liquidbounce.LiquidBounce;
9
import net.ccbluex.liquidbounce.event.*;
10
import net.ccbluex.liquidbounce.features.module.modules.combat.Aura;
11
import net.ccbluex.liquidbounce.features.module.modules.fun.Derp;
12
import net.ccbluex.liquidbounce.features.module.modules.movement.InventoryMove;
13
import net.ccbluex.liquidbounce.features.module.modules.movement.NoSlow;
14
import net.ccbluex.liquidbounce.features.module.modules.movement.Sprint;
15
import net.ccbluex.liquidbounce.features.module.modules.render.NoSwing;
16
import net.ccbluex.liquidbounce.features.module.modules.render.Rotations;
17
import net.ccbluex.liquidbounce.features.module.modules.world.Scaffold;
18
import net.ccbluex.liquidbounce.utils.MovementUtils;
19
import net.ccbluex.liquidbounce.utils.Rotation;
20
import net.ccbluex.liquidbounce.utils.RotationUtils;
21
import net.minecraft.block.Block;
22
import net.minecraft.block.BlockFence;
23
import net.minecraft.block.BlockFenceGate;
24
import net.minecraft.block.BlockWall;
25
import net.minecraft.block.material.Material;
26
import net.minecraft.client.Minecraft;
27
import net.minecraft.client.audio.PositionedSoundRecord;
28
import net.minecraft.client.entity.EntityPlayerSP;
29
import net.minecraft.client.network.NetHandlerPlayClient;
30
import net.minecraft.crash.CrashReport;
31
import net.minecraft.crash.CrashReportCategory;
32
import net.minecraft.entity.Entity;
33
import net.minecraft.init.Blocks;
34
import net.minecraft.item.ItemSword;
35
import net.minecraft.network.play.client.C03PacketPlayer;
36
import net.minecraft.network.play.client.C0APacketAnimation;
37
import net.minecraft.network.play.client.C0BPacketEntityAction;
38
import net.minecraft.potion.Potion;
39
import net.minecraft.util.*;
40
import net.minecraftforge.fml.relauncher.Side;
41
import net.minecraftforge.fml.relauncher.SideOnly;
42
import org.spongepowered.asm.mixin.Final;
43
import org.spongepowered.asm.mixin.Mixin;
44
import org.spongepowered.asm.mixin.Overwrite;
45
import org.spongepowered.asm.mixin.Shadow;
46
import org.spongepowered.asm.mixin.injection.At;
47
import org.spongepowered.asm.mixin.injection.Inject;
48
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
49
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
50
51
import java.util.List;
52
53
@Mixin(EntityPlayerSP.class)
54
@SideOnly(Side.CLIENT)
55
public abstract class MixinEntityPlayerSP extends MixinAbstractClientPlayer {
56
57
    @Shadow
58
    public boolean serverSprintState;
59
60
    @Shadow
61
    public abstract void playSound(String name, float volume, float pitch);
62
63
    @Shadow
64
    public int sprintingTicksLeft;
65
66
    @Shadow
67
    protected int sprintToggleTimer;
68
69
    @Shadow
70
    public float timeInPortal;
71
72
    @Shadow
73
    public float prevTimeInPortal;
74
75
    @Shadow
76
    protected Minecraft mc;
77
78
    @Shadow
79
    public MovementInput movementInput;
80
81
    @Shadow
82
    public abstract void setSprinting(boolean sprinting);
83
84
    @Shadow
85
    protected abstract boolean pushOutOfBlocks(double x, double y, double z);
86
87
    @Shadow
88
    public abstract void sendPlayerAbilities();
89
90
    @Shadow
91
    public float horseJumpPower;
92
93
    @Shadow
94
    public int horseJumpPowerCounter;
95
96
    @Shadow
97
    protected abstract void sendHorseJump();
98
99
    @Shadow
100
    public abstract boolean isRidingHorse();
101
102
    @Shadow
103
    @Final
104
    public NetHandlerPlayClient sendQueue;
105
106
    @Shadow
107
    private boolean serverSneakState;
108
109
    @Shadow
110
    public abstract boolean isSneaking();
111
112
    @Shadow
113
    protected abstract boolean isCurrentViewEntity();
114
115
    @Shadow
116
    private double lastReportedPosX;
117
118
    @Shadow
119
    private int positionUpdateTicks;
120
121
    @Shadow
122
    private double lastReportedPosY;
123
124
    @Shadow
125
    private double lastReportedPosZ;
126
127
    @Shadow
128
    private float lastReportedYaw;
129
130
    @Shadow
131
    private float lastReportedPitch;
132
133
    /**
134
     * @author CCBlueX
135
     */
136
    @Overwrite
137
    public void onUpdateWalkingPlayer() {
138
        final Rotations rotations = (Rotations) LiquidBounce.moduleManager.getModule(Rotations.class);
139
        try {
140
            LiquidBounce.eventManager.callEvent(new MotionEvent(EventState.PRE));
141
142
            final InventoryMove inventoryMove = (InventoryMove) LiquidBounce.moduleManager.getModule(InventoryMove.class);
143
            final boolean fakeSprint = (inventoryMove.getState() && inventoryMove.getAacAdditionProValue().get());
144
145
            boolean sprinting = this.isSprinting() && !fakeSprint;
146
147
            if (sprinting != this.serverSprintState) {
148
                if (sprinting)
149
                    this.sendQueue.addToSendQueue(new C0BPacketEntityAction((EntityPlayerSP) (Object) this, C0BPacketEntityAction.Action.START_SPRINTING));
150
                else
151
                    this.sendQueue.addToSendQueue(new C0BPacketEntityAction((EntityPlayerSP) (Object) this, C0BPacketEntityAction.Action.STOP_SPRINTING));
152
153
                this.serverSprintState = sprinting;
154
            }
155
156
            if (this.isCurrentViewEntity()) {
157
                float yaw = rotationYaw;
158
                float pitch = rotationPitch;
159
                float lastReportedYaw = RotationUtils.serverRotation.getYaw();
160
                float lastReportedPitch = RotationUtils.serverRotation.getPitch();
161
162
                final Derp derp = (Derp) LiquidBounce.moduleManager.getModule(Derp.class);
163
                if (derp.getState()) {
164
                    float[] rot = derp.getRotation();
165
                    yaw = rot[0];
166
                    pitch = rot[1];
167
                }
168
169
                if (RotationUtils.targetRotation != null) {
170
                    yaw = RotationUtils.targetRotation.getYaw();
171
                    pitch = RotationUtils.targetRotation.getPitch();
172
                }
173
174
                double xDiff = this.posX - this.lastReportedPosX;
175
                double yDiff = this.getEntityBoundingBox().minY - this.lastReportedPosY;
176
                double zDiff = this.posZ - this.lastReportedPosZ;
177
                double yawDiff = (double) (yaw - lastReportedYaw);
178
                double pitchDiff = (double) (pitch - lastReportedPitch);
179
                boolean moved = xDiff * xDiff + yDiff * yDiff + zDiff * zDiff > 9.0E-4D || this.positionUpdateTicks >= 20;
180
                boolean rotated = yawDiff != 0.0D || pitchDiff != 0.0D;
181
182
                if (this.ridingEntity == null) {
183
                    if (moved && rotated) {
184
                        this.sendQueue.addToSendQueue(new C03PacketPlayer.C06PacketPlayerPosLook(this.posX, this.getEntityBoundingBox().minY, this.posZ, yaw, pitch, this.onGround));
185
                    } else if (moved) {
186
                        this.sendQueue.addToSendQueue(new C03PacketPlayer.C04PacketPlayerPosition(this.posX, this.getEntityBoundingBox().minY, this.posZ, this.onGround));
187
                    } else if (rotated) {
188
                        this.sendQueue.addToSendQueue(new C03PacketPlayer.C05PacketPlayerLook(yaw, pitch, this.onGround));
189
                    } else {
190
                        this.sendQueue.addToSendQueue(new C03PacketPlayer(this.onGround));
191
                    }
192
                } else {
193
                    this.sendQueue.addToSendQueue(new C03PacketPlayer.C06PacketPlayerPosLook(this.motionX, -999.0D, this.motionZ, yaw, pitch, this.onGround));
194
                    moved = false;
195
                }
196
197
                ++this.positionUpdateTicks;
198
199
                if (moved) {
200
                    this.lastReportedPosX = this.posX;
201
                    this.lastReportedPosY = this.getEntityBoundingBox().minY;
202
                    this.lastReportedPosZ = this.posZ;
203
                    this.positionUpdateTicks = 0;
204
                }
205
206
                if (rotated) {
207
                    this.lastReportedYaw = this.rotationYaw;
208
                    this.lastReportedPitch = this.rotationPitch;
209
                }
210
                SommtheEvent sommther = new SommtheEvent(this.posX, this.posY, this.posZ, yaw, pitch, mc.thePlayer.isSneaking(), this.onGround);
211
                LiquidBounce.eventManager.callEvent(sommther);
212
                sommther.fire();
213
            }
214
215
            LiquidBounce.eventManager.callEvent(new MotionEvent(EventState.POST));
216
        } catch (final Exception e) {
217
            e.printStackTrace();
218
        }
219
    }
220
221
    @Inject(method = "swingItem", at = @At("HEAD"), cancellable = true)
222
    private void swingItem(CallbackInfo callbackInfo) {
223
        final NoSwing noSwing = (NoSwing) LiquidBounce.moduleManager.getModule(NoSwing.class);
224
225
        if (noSwing.getState()) {
226
            callbackInfo.cancel();
227
228
            if (!noSwing.getServerSideValue().get())
229
                this.sendQueue.addToSendQueue(new C0APacketAnimation());
230
        }
231
    }
232
233
    @Inject(method = "pushOutOfBlocks", at = @At("HEAD"), cancellable = true)
234
    private void onPushOutOfBlocks(CallbackInfoReturnable<Boolean> callbackInfoReturnable) {
235
        PushOutEvent event = new PushOutEvent();
236
        if (this.noClip) event.cancelEvent();
237
        LiquidBounce.eventManager.callEvent(event);
238
239
        if (event.isCancelled())
240
            callbackInfoReturnable.setReturnValue(false);
241
    }
242
243
    /**
244
     * @author CCBlueX
245
     */
246
    @Overwrite
247
    public void onLivingUpdate() {
248
        LiquidBounce.eventManager.callEvent(new UpdateEvent());
249
250
        if (this.sprintingTicksLeft > 0) {
251
            --this.sprintingTicksLeft;
252
253
            if (this.sprintingTicksLeft == 0) {
254
                this.setSprinting(false);
255
            }
256
        }
257
258
        if (this.sprintToggleTimer > 0) {
259
            --this.sprintToggleTimer;
260
        }
261
262
        this.prevTimeInPortal = this.timeInPortal;
263
264
        if (this.inPortal) {
265
            if (this.mc.currentScreen != null && !this.mc.currentScreen.doesGuiPauseGame()
266
                    ) {
267
                this.mc.displayGuiScreen(null);
268
            }
269
270
            if (this.timeInPortal == 0.0F) {
271
                this.mc.getSoundHandler().playSound(PositionedSoundRecord.create(new ResourceLocation("portal.trigger"), this.rand.nextFloat() * 0.4F + 0.8F));
272
            }
273
274
            this.timeInPortal += 0.0125F;
275
276
            if (this.timeInPortal >= 1.0F) {
277
                this.timeInPortal = 1.0F;
278
            }
279
280
            this.inPortal = false;
281
        } else if (this.isPotionActive(Potion.confusion) && this.getActivePotionEffect(Potion.confusion).getDuration() > 60) {
282
            this.timeInPortal += 0.006666667F;
283
284
            if (this.timeInPortal > 1.0F) {
285
                this.timeInPortal = 1.0F;
286
            }
287
        } else {
288
            if (this.timeInPortal > 0.0F) {
289
                this.timeInPortal -= 0.05F;
290
            }
291
292
            if (this.timeInPortal < 0.0F) {
293
                this.timeInPortal = 0.0F;
294
            }
295
        }
296
297
        if (this.timeUntilPortal > 0) {
298
            --this.timeUntilPortal;
299
        }
300
301
        boolean flag = this.movementInput.jump;
302
        boolean flag1 = this.movementInput.sneak;
303
        float f = 0.8F;
304
        boolean flag2 = this.movementInput.moveForward >= f;
305
        this.movementInput.updatePlayerMoveState();
306
307
        final NoSlow noSlow = (NoSlow) LiquidBounce.moduleManager.getModule(NoSlow.class);
308
        final Aura killAura = (Aura) LiquidBounce.moduleManager.getModule(Aura.class);
309
310
        if (getHeldItem() != null && (this.isUsingItem() || (getHeldItem().getItem() instanceof ItemSword && killAura.getBlockingStatus())) && !this.isRiding()) {
311
            final SlowDownEvent slowDownEvent = new SlowDownEvent(0.2F, 0.2F);
312
            LiquidBounce.eventManager.callEvent(slowDownEvent);
313
            this.movementInput.moveStrafe *= slowDownEvent.getStrafe();
314
            this.movementInput.moveForward *= slowDownEvent.getForward();
315
            this.sprintToggleTimer = 0;
316
        }
317
318
        this.pushOutOfBlocks(this.posX - (double) this.width * 0.35D, this.getEntityBoundingBox().minY + 0.5D, this.posZ + (double) this.width * 0.35D);
319
        this.pushOutOfBlocks(this.posX - (double) this.width * 0.35D, this.getEntityBoundingBox().minY + 0.5D, this.posZ - (double) this.width * 0.35D);
320
        this.pushOutOfBlocks(this.posX + (double) this.width * 0.35D, this.getEntityBoundingBox().minY + 0.5D, this.posZ - (double) this.width * 0.35D);
321
        this.pushOutOfBlocks(this.posX + (double) this.width * 0.35D, this.getEntityBoundingBox().minY + 0.5D, this.posZ + (double) this.width * 0.35D);
322
323
        final Sprint sprint = (Sprint) LiquidBounce.moduleManager.getModule(Sprint.class);
324
325
        boolean flag3 = !sprint.foodValue.get() || (float) this.getFoodStats().getFoodLevel() > 6.0F || this.capabilities.allowFlying;
326
327
        if (this.onGround && !flag1 && !flag2 && this.movementInput.moveForward >= f && !this.isSprinting() && flag3 && !this.isUsingItem() && !this.isPotionActive(Potion.blindness)) {
328
            if (this.sprintToggleTimer <= 0 && !this.mc.gameSettings.keyBindSprint.isKeyDown()) {
329
                this.sprintToggleTimer = 7;
330
            } else {
331
                this.setSprinting(true);
332
            }
333
        }
334
335
        if (!this.isSprinting() && this.movementInput.moveForward >= f && flag3 && (noSlow.getState() || !this.isUsingItem()) && !this.isPotionActive(Potion.blindness) && this.mc.gameSettings.keyBindSprint.isKeyDown()) {
336
            this.setSprinting(true);
337
        }
338
339
        final Scaffold scaffold = (Scaffold) LiquidBounce.moduleManager.getModule(Scaffold.class);
340
        if ((scaffold.getState() && !scaffold.sprintValue.get()) || (sprint.getState() && sprint.checkServerSide.get() && (onGround || !sprint.checkServerSideGround.get()) && !sprint.allDirectionsValue.get() && RotationUtils.targetRotation != null && RotationUtils.getRotationDifference(new Rotation(mc.thePlayer.rotationYaw, mc.thePlayer.rotationPitch)) > 30))
341
            this.setSprinting(false);
342
343
        if (this.isSprinting() && ((!(sprint.getState() && sprint.allDirectionsValue.get()) && this.movementInput.moveForward < f) || this.isCollidedHorizontally || !flag3)) {
344
            this.setSprinting(false);
345
        }
346
347
        if (this.capabilities.allowFlying) {
348
            if (this.mc.playerController.isSpectatorMode()) {
349
                if (!this.capabilities.isFlying) {
350
                    this.capabilities.isFlying = true;
351
                    this.sendPlayerAbilities();
352
                }
353
            } else if (!flag && this.movementInput.jump) {
354
                if (this.flyToggleTimer == 0) {
355
                    this.flyToggleTimer = 7;
356
                } else {
357
                    this.capabilities.isFlying = !this.capabilities.isFlying;
358
                    this.sendPlayerAbilities();
359
                    this.flyToggleTimer = 0;
360
                }
361
            }
362
        }
363
364
        if (this.capabilities.isFlying && this.isCurrentViewEntity()) {
365
            if (this.movementInput.sneak) {
366
                this.motionY -= (double) (this.capabilities.getFlySpeed() * 3.0F);
367
            }
368
369
            if (this.movementInput.jump) {
370
                this.motionY += (double) (this.capabilities.getFlySpeed() * 3.0F);
371
            }
372
        }
373
374
        if (this.isRidingHorse()) {
375
            if (this.horseJumpPowerCounter < 0) {
376
                ++this.horseJumpPowerCounter;
377
378
                if (this.horseJumpPowerCounter == 0) {
379
                    this.horseJumpPower = 0.0F;
380
                }
381
            }
382
383
            if (flag && !this.movementInput.jump) {
384
                this.horseJumpPowerCounter = -10;
385
                this.sendHorseJump();
386
            } else if (!flag && this.movementInput.jump) {
387
                this.horseJumpPowerCounter = 0;
388
                this.horseJumpPower = 0.0F;
389
            } else if (flag) {
390
                ++this.horseJumpPowerCounter;
391
392
                if (this.horseJumpPowerCounter < 10) {
393
                    this.horseJumpPower = (float) this.horseJumpPowerCounter * 0.1F;
394
                } else {
395
                    this.horseJumpPower = 0.8F + 2.0F / (float) (this.horseJumpPowerCounter - 9) * 0.1F;
396
                }
397
            }
398
        } else {
399
            this.horseJumpPower = 0.0F;
400
        }
401
402
        super.onLivingUpdate();
403
404
        if (this.onGround && this.capabilities.isFlying && !this.mc.playerController.isSpectatorMode()) {
405
            this.capabilities.isFlying = false;
406
            this.sendPlayerAbilities();
407
        }
408
    }
409
410
    @Override
411
    public void moveEntity(double x, double y, double z) {
412
        MoveEvent moveEvent = new MoveEvent(x, y, z);
413
        LiquidBounce.eventManager.callEvent(moveEvent);
414
415
        if (moveEvent.isCancelled())
416
            return;
417
418
        x = moveEvent.getX();
419
        y = moveEvent.getY();
420
        z = moveEvent.getZ();
421
422
        if (this.noClip) {
423
            this.setEntityBoundingBox(this.getEntityBoundingBox().offset(x, y, z));
424
            this.posX = (this.getEntityBoundingBox().minX + this.getEntityBoundingBox().maxX) / 2.0D;
425
            this.posY = this.getEntityBoundingBox().minY;
426
            this.posZ = (this.getEntityBoundingBox().minZ + this.getEntityBoundingBox().maxZ) / 2.0D;
427
        } else {
428
            this.worldObj.theProfiler.startSection("move");
429
            double d0 = this.posX;
430
            double d1 = this.posY;
431
            double d2 = this.posZ;
432
433
            if (this.isInWeb) {
434
                this.isInWeb = false;
435
                x *= 0.25D;
436
                y *= 0.05000000074505806D;
437
                z *= 0.25D;
438
                this.motionX = 0.0D;
439
                this.motionY = 0.0D;
440
                this.motionZ = 0.0D;
441
            }
442
443
            double d3 = x;
444
            double d4 = y;
445
            double d5 = z;
446
            boolean flag = this.onGround && this.isSneaking();
447
448
            if (flag || moveEvent.isSafeWalk()) {
449
                double d6;
450
451
                for (d6 = 0.05D; x != 0.0D && this.worldObj.getCollidingBoundingBoxes((Entity) (Object) this, this.getEntityBoundingBox().offset(x, -1.0D, 0.0D)).isEmpty(); d3 = x) {
452
                    if (x < d6 && x >= -d6) {
453
                        x = 0.0D;
454
                    } else if (x > 0.0D) {
455
                        x -= d6;
456
                    } else {
457
                        x += d6;
458
                    }
459
                }
460
461
                for (; z != 0.0D && this.worldObj.getCollidingBoundingBoxes((Entity) (Object) this, this.getEntityBoundingBox().offset(0.0D, -1.0D, z)).isEmpty(); d5 = z) {
462
                    if (z < d6 && z >= -d6) {
463
                        z = 0.0D;
464
                    } else if (z > 0.0D) {
465
                        z -= d6;
466
                    } else {
467
                        z += d6;
468
                    }
469
                }
470
471
                for (; x != 0.0D && z != 0.0D && this.worldObj.getCollidingBoundingBoxes((Entity) (Object) this, this.getEntityBoundingBox().offset(x, -1.0D, z)).isEmpty(); d5 = z) {
472
                    if (x < d6 && x >= -d6) {
473
                        x = 0.0D;
474
                    } else if (x > 0.0D) {
475
                        x -= d6;
476
                    } else {
477
                        x += d6;
478
                    }
479
480
                    d3 = x;
481
482
                    if (z < d6 && z >= -d6) {
483
                        z = 0.0D;
484
                    } else if (z > 0.0D) {
485
                        z -= d6;
486
                    } else {
487
                        z += d6;
488
                    }
489
                }
490
            }
491
492
            List<AxisAlignedBB> list1 = this.worldObj.getCollidingBoundingBoxes((Entity) (Object) this, this.getEntityBoundingBox().addCoord(x, y, z));
493
            AxisAlignedBB axisalignedbb = this.getEntityBoundingBox();
494
495
            for (AxisAlignedBB axisalignedbb1 : list1) {
496
                y = axisalignedbb1.calculateYOffset(this.getEntityBoundingBox(), y);
497
            }
498
499
            this.setEntityBoundingBox(this.getEntityBoundingBox().offset(0.0D, y, 0.0D));
500
            boolean flag1 = this.onGround || d4 != y && d4 < 0.0D;
501
502
            for (AxisAlignedBB axisalignedbb2 : list1) {
503
                x = axisalignedbb2.calculateXOffset(this.getEntityBoundingBox(), x);
504
            }
505
506
            this.setEntityBoundingBox(this.getEntityBoundingBox().offset(x, 0.0D, 0.0D));
507
508
            for (AxisAlignedBB axisalignedbb13 : list1) {
509
                z = axisalignedbb13.calculateZOffset(this.getEntityBoundingBox(), z);
510
            }
511
512
            this.setEntityBoundingBox(this.getEntityBoundingBox().offset(0.0D, 0.0D, z));
513
514
            if (this.stepHeight > 0.0F && flag1 && (d3 != x || d5 != z)) {
515
                StepEvent stepEvent = new StepEvent(this.stepHeight);
516
                LiquidBounce.eventManager.callEvent(stepEvent);
517
                double d11 = x;
518
                double d7 = y;
519
                double d8 = z;
520
                AxisAlignedBB axisalignedbb3 = this.getEntityBoundingBox();
521
                this.setEntityBoundingBox(axisalignedbb);
522
                y = stepEvent.getStepHeight();
523
                List<AxisAlignedBB> list = this.worldObj.getCollidingBoundingBoxes((Entity) (Object) this, this.getEntityBoundingBox().addCoord(d3, y, d5));
524
                AxisAlignedBB axisalignedbb4 = this.getEntityBoundingBox();
525
                AxisAlignedBB axisalignedbb5 = axisalignedbb4.addCoord(d3, 0.0D, d5);
526
                double d9 = y;
527
528
                for (AxisAlignedBB axisalignedbb6 : list) {
529
                    d9 = axisalignedbb6.calculateYOffset(axisalignedbb5, d9);
530
                }
531
532
                axisalignedbb4 = axisalignedbb4.offset(0.0D, d9, 0.0D);
533
                double d15 = d3;
534
535
                for (AxisAlignedBB axisalignedbb7 : list) {
536
                    d15 = axisalignedbb7.calculateXOffset(axisalignedbb4, d15);
537
                }
538
539
                axisalignedbb4 = axisalignedbb4.offset(d15, 0.0D, 0.0D);
540
                double d16 = d5;
541
542
                for (AxisAlignedBB axisalignedbb8 : list) {
543
                    d16 = axisalignedbb8.calculateZOffset(axisalignedbb4, d16);
544
                }
545
546
                axisalignedbb4 = axisalignedbb4.offset(0.0D, 0.0D, d16);
547
                AxisAlignedBB axisalignedbb14 = this.getEntityBoundingBox();
548
                double d17 = y;
549
550
                for (AxisAlignedBB axisalignedbb9 : list) {
551
                    d17 = axisalignedbb9.calculateYOffset(axisalignedbb14, d17);
552
                }
553
554
                axisalignedbb14 = axisalignedbb14.offset(0.0D, d17, 0.0D);
555
                double d18 = d3;
556
557
                for (AxisAlignedBB axisalignedbb10 : list) {
558
                    d18 = axisalignedbb10.calculateXOffset(axisalignedbb14, d18);
559
                }
560
561
                axisalignedbb14 = axisalignedbb14.offset(d18, 0.0D, 0.0D);
562
                double d19 = d5;
563
564
                for (AxisAlignedBB axisalignedbb11 : list) {
565
                    d19 = axisalignedbb11.calculateZOffset(axisalignedbb14, d19);
566
                }
567
568
                axisalignedbb14 = axisalignedbb14.offset(0.0D, 0.0D, d19);
569
                double d20 = d15 * d15 + d16 * d16;
570
                double d10 = d18 * d18 + d19 * d19;
571
572
                if (d20 > d10) {
573
                    x = d15;
574
                    z = d16;
575
                    y = -d9;
576
                    this.setEntityBoundingBox(axisalignedbb4);
577
                } else {
578
                    x = d18;
579
                    z = d19;
580
                    y = -d17;
581
                    this.setEntityBoundingBox(axisalignedbb14);
582
                }
583
584
                for (AxisAlignedBB axisalignedbb12 : list) {
585
                    y = axisalignedbb12.calculateYOffset(this.getEntityBoundingBox(), y);
586
                }
587
588
                this.setEntityBoundingBox(this.getEntityBoundingBox().offset(0.0D, y, 0.0D));
589
590
                if (d11 * d11 + d8 * d8 >= x * x + z * z) {
591
                    x = d11;
592
                    y = d7;
593
                    z = d8;
594
                    this.setEntityBoundingBox(axisalignedbb3);
595
                } else {
596
                    LiquidBounce.eventManager.callEvent(new StepConfirmEvent(this.stepHeight));
597
                }
598
            }
599
600
            this.worldObj.theProfiler.endSection();
601
            this.worldObj.theProfiler.startSection("rest");
602
            this.posX = (this.getEntityBoundingBox().minX + this.getEntityBoundingBox().maxX) / 2.0D;
603
            this.posY = this.getEntityBoundingBox().minY;
604
            this.posZ = (this.getEntityBoundingBox().minZ + this.getEntityBoundingBox().maxZ) / 2.0D;
605
            this.isCollidedHorizontally = d3 != x || d5 != z;
606
            this.isCollidedVertically = d4 != y;
607
            this.onGround = this.isCollidedVertically && d4 < 0.0D;
608
            this.isCollided = this.isCollidedHorizontally || this.isCollidedVertically;
609
            int i = MathHelper.floor_double(this.posX);
610
            int j = MathHelper.floor_double(this.posY - 0.20000000298023224D);
611
            int k = MathHelper.floor_double(this.posZ);
612
            BlockPos blockpos = new BlockPos(i, j, k);
613
            Block block1 = this.worldObj.getBlockState(blockpos).getBlock();
614
615
            if (block1.getMaterial() == Material.air) {
616
                Block block = this.worldObj.getBlockState(blockpos.down()).getBlock();
617
618
                if (block instanceof BlockFence || block instanceof BlockWall || block instanceof BlockFenceGate) {
619
                    block1 = block;
620
                    blockpos = blockpos.down();
621
                }
622
            }
623
624
            this.updateFallState(y, this.onGround, block1, blockpos);
625
626
            if (d3 != x) {
627
                this.motionX = 0.0D;
628
            }
629
630
            if (d5 != z) {
631
                this.motionZ = 0.0D;
632
            }
633
634
            if (d4 != y) {
635
                block1.onLanded(this.worldObj, (Entity) (Object) this);
636
            }
637
638
            if (this.canTriggerWalking() && !flag && this.ridingEntity == null) {
639
                double d12 = this.posX - d0;
640
                double d13 = this.posY - d1;
641
                double d14 = this.posZ - d2;
642
643
                if (block1 != Blocks.ladder) {
644
                    d13 = 0.0D;
645
                }
646
647
                if (block1 != null && this.onGround) {
648
                    block1.onEntityCollidedWithBlock(this.worldObj, blockpos, (Entity) (Object) this);
649
                }
650
651
                this.distanceWalkedModified = (float) ((double) this.distanceWalkedModified + (double) MathHelper.sqrt_double(d12 * d12 + d14 * d14) * 0.6D);
652
                this.distanceWalkedOnStepModified = (float) ((double) this.distanceWalkedOnStepModified + (double) MathHelper.sqrt_double(d12 * d12 + d13 * d13 + d14 * d14) * 0.6D);
653
654
                if (this.distanceWalkedOnStepModified > (float) getNextStepDistance() && block1.getMaterial() != Material.air) {
655
                    setNextStepDistance((int) this.distanceWalkedOnStepModified + 1);
656
657
                    if (this.isInWater()) {
658
                        float f = MathHelper.sqrt_double(this.motionX * this.motionX * 0.20000000298023224D + this.motionY * this.motionY + this.motionZ * this.motionZ * 0.20000000298023224D) * 0.35F;
659
660
                        if (f > 1.0F) {
661
                            f = 1.0F;
662
                        }
663
664
                        this.playSound(this.getSwimSound(), f, 1.0F + (this.rand.nextFloat() - this.rand.nextFloat()) * 0.4F);
665
                    }
666
667
                    this.playStepSound(blockpos, block1);
668
                }
669
            }
670
671
            try {
672
                this.doBlockCollisions();
673
            } catch (Throwable throwable) {
674
                CrashReport crashreport = CrashReport.makeCrashReport(throwable, "Checking entity block collision");
675
                CrashReportCategory crashreportcategory = crashreport.makeCategory("Entity being checked for collision");
676
                this.addEntityCrashInfo(crashreportcategory);
677
                throw new ReportedException(crashreport);
678
            }
679
680
            boolean flag2 = this.isWet();
681
682
            if (this.worldObj.isFlammableWithin(this.getEntityBoundingBox().contract(0.001D, 0.001D, 0.001D))) {
683
                this.dealFireDamage(1);
684
685
                if (!flag2) {
686
                    setFire(getFire() + 1);
687
688
                    if (getFire() == 0) {
689
                        this.setFire(8);
690
                    }
691
                }
692
            } else if (getFire() <= 0) {
693
                setFire(-this.fireResistance);
694
            }
695
696
            if (flag2 && getFire() > 0) {
697
                this.playSound("random.fizz", 0.7F, 1.6F + (this.rand.nextFloat() - this.rand.nextFloat()) * 0.4F);
698
                setFire(-this.fireResistance);
699
            }
700
701
            this.worldObj.theProfiler.endSection();
702
        }
703
    }
704
}

What this file does

This mixin is the actual speed mechanism: it fires SlowDownEvent(0.2F, 0.2F) in onLivingUpdate while the player uses an item or sword-blocks and is not riding, then multiplies the strafe and forward inputs by the event's mutated values and resets the sprint toggle timer. Without this hook the module's C07/C08 dance would only resync server-side item state and grant nothing client-side.

anticheat Countering Checks

The anticheat code that detects or counters the techniques this module uses. Full source, with the detection mechanism explained below each box.

anticheat UseItemAdapter (release-gap ledger)

UseItemAdapter.java438 lines · Java
1
/*
2
 * This program is free software: you can redistribute it and/or modify
3
 *   it under the terms of the GNU General Public License as published by
4
 *   the Free Software Foundation, either version 3 of the License, or
5
 *   (at your option) any later version.
6
 *
7
 *   This program is distributed in the hope that it will be useful,
8
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 *   GNU General Public License for more details.
11
 *
12
 *   You should have received a copy of the GNU General Public License
13
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
14
 */
15
package fr.neatmonster.nocheatplus.checks.net.protocollib;
16
17
import java.util.Arrays;
18
import java.util.LinkedList;
19
import java.util.List;
20
21
import org.bukkit.GameMode;
22
import org.bukkit.Material;
23
import org.bukkit.entity.HumanEntity;
24
import org.bukkit.entity.Player;
25
import org.bukkit.event.Event;
26
import org.bukkit.event.EventHandler;
27
import org.bukkit.event.EventPriority;
28
import org.bukkit.event.block.Action;
29
import org.bukkit.event.entity.PlayerDeathEvent;
30
import org.bukkit.event.inventory.InventoryOpenEvent;
31
import org.bukkit.event.player.PlayerInteractEvent;
32
import org.bukkit.event.player.PlayerItemConsumeEvent;
33
import org.bukkit.event.player.PlayerItemHeldEvent;
34
import org.bukkit.event.player.PlayerRespawnEvent;
35
import org.bukkit.event.player.PlayerRiptideEvent;
36
import org.bukkit.inventory.EquipmentSlot;
37
import org.bukkit.inventory.ItemStack;
38
import org.bukkit.inventory.meta.CrossbowMeta;
39
import org.bukkit.plugin.Plugin;
40
41
import com.comphenix.protocol.PacketType;
42
import com.comphenix.protocol.events.ListenerPriority;
43
import com.comphenix.protocol.events.PacketContainer;
44
import com.comphenix.protocol.events.PacketEvent;
45
import com.comphenix.protocol.reflect.StructureModifier;
46
import com.comphenix.protocol.wrappers.EnumWrappers.PlayerDigType;
47
48
import fr.neatmonster.nocheatplus.NCPAPIProvider;
49
import fr.neatmonster.nocheatplus.checks.combined.CombinedData;
50
import fr.neatmonster.nocheatplus.checks.moving.MovingConfig;
51
import fr.neatmonster.nocheatplus.checks.moving.MovingData;
52
import fr.neatmonster.nocheatplus.compat.Bridge1_13;
53
import fr.neatmonster.nocheatplus.compat.Bridge1_9;
54
import fr.neatmonster.nocheatplus.compat.bukkit.BridgeEnchant;
55
import fr.neatmonster.nocheatplus.compat.bukkit.BridgeMaterial;
56
import fr.neatmonster.nocheatplus.compat.BridgeMisc;
57
import fr.neatmonster.nocheatplus.compat.versions.ClientVersion;
58
import fr.neatmonster.nocheatplus.compat.versions.ServerVersion;
59
import fr.neatmonster.nocheatplus.components.NoCheatPlusAPI;
60
import fr.neatmonster.nocheatplus.components.registry.order.RegistrationOrder.RegisterMethodWithOrder;
61
import fr.neatmonster.nocheatplus.event.mini.MiniListener;
62
import fr.neatmonster.nocheatplus.logging.StaticLog;
63
import fr.neatmonster.nocheatplus.players.DataManager;
64
import fr.neatmonster.nocheatplus.players.IPlayerData;
65
import fr.neatmonster.nocheatplus.utilities.entity.InventoryUtil;
66
import fr.neatmonster.nocheatplus.utilities.map.BlockProperties;
67
import fr.neatmonster.nocheatplus.utilities.map.MaterialUtil;
68
69
/**
70
 * <p>Adapter for listening to packets and Bukkit events relevant to item use.</p>
71
 *
72
 * On versions 1.17 and above, the adapter will only register events related to a specific item-use exploit, 
73
 * as Bukkit provides the {@link HumanEntity#getItemInUse()} method.<br>
74
 *
75
 * <p>On versions 1.12 and above, up to 1.17, all listeners will be registered because Bukkit does not offer a way to 
76
 * determine <em>which</em> item is in use; we can only detect if a player is using an item through {@link HumanEntity#isHandRaised()}.</p>
77
 *
78
 * The {@link PlayerRespawnEvent} is always listened to in order to fix a specific item desynchronization issue.
79
 */
80
public class UseItemAdapter extends BaseAdapter {
81
    
82
    private final static String dftag = "system.nocheatplus.useitemadapter";
83
        
84
    // All relevant Bukkit events for item-use.
85
    private final static MiniListener<?>[] miniListeners = new MiniListener<?>[] {
86
        new MiniListener<PlayerItemConsumeEvent>() {
87
            @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
88
            @RegisterMethodWithOrder(tag = dftag)
89
            @Override
90
            public void onEvent(final PlayerItemConsumeEvent event) {
91
                onItemConsume(event);
92
            }
93
        },
94
        new MiniListener<PlayerInteractEvent>() {
95
            @EventHandler(priority = EventPriority.MONITOR)
96
            @RegisterMethodWithOrder(tag = dftag)
97
            @Override
98
            public void onEvent(final PlayerInteractEvent event) {
99
                onItemInteract(event);
100
            }
101
        },
102
        new MiniListener<InventoryOpenEvent>() {
103
            @EventHandler(priority = EventPriority.LOWEST)
104
            @RegisterMethodWithOrder(tag = dftag)
105
            @Override
106
            public void onEvent(final InventoryOpenEvent event) {
107
                onInventoryOpen(event);
108
            }
109
        },
110
        new MiniListener<PlayerDeathEvent>() {
111
            @EventHandler(priority = EventPriority.MONITOR)
112
            @RegisterMethodWithOrder(tag = dftag)
113
            @Override
114
            public void onEvent(final PlayerDeathEvent event) {
115
                onDeath(event);
116
            }
117
        },
118
        new MiniListener<PlayerItemHeldEvent>() {
119
            @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
120
            @RegisterMethodWithOrder(tag = dftag)
121
            @Override
122
            public void onEvent(final PlayerItemHeldEvent event) {
123
                onChangeSlot(event);
124
            }
125
        },
126
    };
127
128
    private static int timeBetweenRL = 70;
129
130
    private static PacketType[] initPacketTypes() {
131
        // Only interested in these two packets.
132
        final List<PacketType> types = new LinkedList<PacketType>(Arrays.asList(PacketType.Play.Client.BLOCK_DIG, PacketType.Play.Client.BLOCK_PLACE));
133
        return types.toArray(new PacketType[types.size()]);
134
    }
135
136
    public UseItemAdapter(Plugin plugin) {
137
        super(plugin, ListenerPriority.MONITOR, initPacketTypes());
138
        final NoCheatPlusAPI api = NCPAPIProvider.getNoCheatPlusAPI();
139
        if (!BridgeMisc.hasGetItemInUseMethod()) {
140
            // getItemInUse() isn't there, register all events
141
            if (Bridge1_13.hasPlayerRiptideEvent()) {
142
                // Only register this one if available.
143
                final MiniListener<?> riptideListener = new MiniListener<PlayerRiptideEvent>() {
144
                    @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
145
                    @RegisterMethodWithOrder(tag = dftag)
146
                    @Override
147
                    public void onEvent(final PlayerRiptideEvent event) {
148
                        onTridentRelease(event);
149
                   }
150
                };
151
                api.addComponent(riptideListener, false);
152
            }
153
            // ...All the other listeners
154
            for (final MiniListener<?> listener : miniListeners) {
155
                api.addComponent(listener, false);
156
            }
157
        }
158
        // Always register this event, because it is used to fix an MC/Bukkit glitch, not for item-use setting.
159
        final MiniListener<?> respawningListener = new MiniListener<PlayerRespawnEvent>() {
160
            @EventHandler(priority = EventPriority.MONITOR)
161
            @RegisterMethodWithOrder(tag = dftag)
162
            @Override
163
            public void onEvent(final PlayerRespawnEvent event) {
164
                onRespawning(event);
165
            }
166
        };
167
        api.addComponent(respawningListener, false);
168
    }
169
170
    @Override
171
    public void onPacketReceiving(final PacketEvent event) {
172
        // Fast return tests first.
173
        try {
174
            if (event.isPlayerTemporary()) return;
175
        } 
176
        catch (NoSuchMethodError e) {
177
            if (event.getPlayer() == null) {
178
                counters.add(ProtocolLibComponent.idNullPlayer, 1);
179
                return;
180
            }
181
            if (DataManager.getPlayerDataSafe(event.getPlayer()) == null) {
182
                StaticLog.logWarning("Failed to fetch player data with " + event.getPacketType() + " for: " + event.getPlayer().toString());
183
                return;
184
            }
185
        }
186
        if (BridgeMisc.hasGetItemInUseMethod()) {
187
            // getItemInUse() is already there. Only check the digging packet for exploitation prevention purposes.
188
            if (event.getPacketType().equals(PacketType.Play.Client.BLOCK_DIG)) {
189
                handleDiggingPacket(event);
190
            }
191
            // Don't need to do anything else.
192
            return;
193
        }
194
        
195
        // getItemInUse() ins't there: do the ordinary stuff.
196
        if (event.getPacketType().equals(PacketType.Play.Client.BLOCK_DIG)) {
197
            handleDiggingPacket(event);
198
        }
199
        else handleBlockPlacePacket(event);
200
    }
201
    
202
    /** Attempt to fix server-side-only blocking after respawn. */
203
    private static void onRespawning(final PlayerRespawnEvent e) {
204
        final IPlayerData pData = DataManager.getPlayerData(e.getPlayer());
205
        // Patch up issues on Bukkit's (Minecraft's ?) side (item has been reset already on death).
206
        if (Bridge1_9.hasGetItemInOffHand() && e.getPlayer().isBlocking()) {
207
            pData.requestItemUseResync();
208
        }
209
    }
210
211
    private static void onTridentRelease(final PlayerRiptideEvent e) {
212
        final IPlayerData pData = DataManager.getPlayerData(e.getPlayer());
213
        // This event is called on releasing the trident (See ItemTrident.java), so the item is not in use anymore.
214
        pData.setItemInUse(null);
215
    }
216
217
    private static void onItemConsume(final PlayerItemConsumeEvent e) {
218
        final Player p = e.getPlayer();
219
        final IPlayerData pData = DataManager.getPlayerData(p);
220
        // Consume(d) (!!), so the player isn't using the item anymore
221
        pData.setItemInUse(null);   
222
    }
223
224
    private static void onInventoryOpen(final InventoryOpenEvent e) {
225
        if (e.isCancelled()) return;
226
        final Player p = (Player) e.getPlayer();
227
        final IPlayerData pData = DataManager.getPlayerData(p);
228
        // Can't use item with an inventory open.
229
        pData.setItemInUse(null);
230
    }
231
232
    private static void onDeath(final PlayerDeathEvent e) {
233
        final IPlayerData pData = DataManager.getPlayerData((Player) e.getEntity());
234
        // Can't use item if dead
235
        pData.setItemInUse(null);  
236
    }
237
238
    @SuppressWarnings("deprecation")
239
	private static void onItemInteract(final PlayerInteractEvent e) {
240
        if (e.getAction() != Action.RIGHT_CLICK_AIR && e.getAction() != Action.RIGHT_CLICK_BLOCK) {
241
            return;
242
        }
243
        final Player p = e.getPlayer();
244
        final IPlayerData pData = DataManager.getPlayerData(p);
245
        final MovingConfig mCC = pData.getGenericInstance(MovingConfig.class);
246
        final CombinedData data = pData.getGenericInstance(CombinedData.class);
247
        data.offHandUse = false;
248
        if (!data.mightUseItem) {
249
            // Player did not send the block-placement packet, so they are for sure not using anything, return.
250
            return;
251
        }
252
        // Do reset the flag at the start (!)
253
        data.mightUseItem = false;
254
255
        if (e.useItemInHand().equals(Event.Result.DENY)) {
256
            // A plugin denied the item-use.
257
            return;
258
        }
259
260
        if (p.getGameMode() == GameMode.CREATIVE) {
261
            // TODO: If merging SurvivalFly and CreativeFly, creative mode needs to be taken into consideration as well.
262
            pData.setItemInUse(null);
263
            return;
264
        }
265
        
266
        // Proceed to check...
267
        if (e.hasItem()) {
268
            final ItemStack item = e.getItem();
269
            final Material m = item.getType();
270
            if (Bridge1_9.hasElytra() && p.hasCooldown(m)) {
271
                // Item is in cooldown so it cannot be used.
272
                return;
273
            }
274
            
275
            // Edible / consumable items...
276
            if (InventoryUtil.isConsumable(item)) {
277
                if (!Bridge1_9.hasElytra() && item.getDurability() > 16384) {
278
                    // pre1.9 splash potion edge case.
279
                    return;
280
                }
281
                if (m == Material.POTION || m == Material.MILK_BUCKET || m.toString().endsWith("_APPLE") || m.name().startsWith("HONEY_BOTTLE")) {
282
                    // Can be consumed regardless of hunger level
283
                    pData.setItemInUse(m);
284
                    data.offHandUse = Bridge1_9.hasGetItemInOffHand() && e.getHand() == EquipmentSlot.OFF_HAND;
285
                    return;
286
                }
287
                if (item.getType().isEdible() && p.getFoodLevel() < 20) {
288
                    // Hunger level dependant consumables.
289
                    pData.setItemInUse(m); 
290
                    data.offHandUse = Bridge1_9.hasGetItemInOffHand() && e.getHand() == EquipmentSlot.OFF_HAND;
291
                    return;
292
                }
293
            }
294
            // Bows...
295
            if (m == Material.BOW && InventoryUtil.hasArrow(p.getInventory(), false)) {
296
                pData.setItemInUse(m);
297
                data.offHandUse = Bridge1_9.hasGetItemInOffHand() && e.getHand() == EquipmentSlot.OFF_HAND;
298
                return;
299
            }
300
            // Shields and swords (legacy)... Bukkit takes care here, but set anyway.
301
            if (ServerVersion.isAtLeast("1.9") && pData.getClientVersion().isAtLeast(ClientVersion.V_1_9)) {
302
                // Both server and client are on a version that support shield (thus, sword-blocking is not possible)
303
            	if (m == Material.SHIELD) {
304
            	    pData.setItemInUse(m);
305
                    data.offHandUse = e.getHand() == EquipmentSlot.OFF_HAND;
306
                    return;
307
            	}
308
            }
309
            else if (MaterialUtil.isSword(m) && (ServerVersion.isLowerThan("1.9") || pData.getClientVersion().isAtMost(ClientVersion.V_1_8))) {
310
            	// Legacy server. Or legacy client on a modern server. Blocking is done with swords in both cases.
311
            	pData.setItemInUse(m);
312
            	// (Off hand doesn't exist)
313
            	return;
314
            }
315
            
316
            // Crosswbows...
317
            if (m.toString().equals("CROSSBOW")) {
318
                if (!((CrossbowMeta) item.getItemMeta()).hasChargedProjectiles() && InventoryUtil.hasArrow(p.getInventory(), true)) {
319
                    pData.setItemInUse(m);
320
                    data.offHandUse = e.getHand() == EquipmentSlot.OFF_HAND;
321
                }
322
            }
323
            // Tridents (1.13)... 
324
            if (m == BridgeMaterial.TRIDENT && item.getDurability() < m.getMaxDurability() - 1 && pData.getClientVersion().isAtLeast(ClientVersion.V_1_13)
325
            	&& (
326
                    // 1: If the trident has riptide enchant, it can only be used in rain or water 
327
            		BridgeEnchant.getRiptideLevel(p) > 0.0
328
                    && (
329
                        // 2: In water
330
                        BlockProperties.isInWater(p, p.getLocation(), mCC.yOnGround)
331
                        // 2: Always check raining first, since canSeeSky is a much more expensive call. Needs optimization.
332
                        || p.getLocation().getWorld().hasStorm() && BlockProperties.canSeeSky(p, p.getLocation(), mCC.yOnGround) 
333
                    ) 
334
                    // 1: Otherwise, the trident can be used and thrown anywhere
335
                    || BridgeEnchant.getRiptideLevel(p) <= 0.0
336
                )) {
337
                pData.setItemInUse(m);
338
                data.offHandUse = e.getHand() == EquipmentSlot.OFF_HAND;
339
                return;
340
            }
341
            // Spyglass (1.17)...
342
            if (BridgeMisc.hasIsFrozen() && m == Material.SPYGLASS) {
343
                pData.setItemInUse(m);
344
                data.offHandUse = e.getHand() == EquipmentSlot.OFF_HAND;
345
                return;
346
            }
347
            // Lastly, goat horns (1.19)...
348
            if (m.toString().equals("GOAT_HORN")) {
349
                pData.setItemInUse(m);
350
                data.offHandUse = e.getHand() == EquipmentSlot.OFF_HAND;
351
                return;
352
            }
353
            // 1.21.11: Spears...
354
            if (MaterialUtil.isSpear(m)) {
355
                pData.setItemInUse(m);
356
                data.offHandUse = e.getHand() == EquipmentSlot.OFF_HAND;
357
            }
358
        } 
359
        else {
360
            // No item in hands, no deal.
361
            pData.setItemInUse(null);  
362
        }
363
    }
364
    
365
    // NOTE: Bukkit takes care of invalid slot values (< 0 or > 8. PlayerConnection.java), so we don't need to check for this as well.
366
    private static void onChangeSlot(final PlayerItemHeldEvent e) {
367
        final Player p = e.getPlayer();
368
        final IPlayerData pData = DataManager.getPlayerData(p);
369
        // Switching a slot, so the item use status is reset.
370
        final MovingData mData = pData.getGenericInstance(MovingData.class);
371
        final CombinedData cData = pData.getGenericInstance(CombinedData.class);
372
        if (e.getPreviousSlot() != e.getNewSlot()) {
373
            /*if ((pData.getItemInUse() != null || p.isBlocking()) && mData.playerMoves.getCurrentMove() != null) {
374
                p.getInventory().setHeldItemSlot(e.getPreviousSlot());
375
                cData.invalidItemUse = true;
376
            }*/
377
            // To avoid any more potential bypasses, let Minecraft forcibly release the item.
378
            pData.requestItemUseResync();
379
        }
380
    }
381
382
    private void handleBlockPlacePacket(PacketEvent event) {
383
        final Player p = event.getPlayer();
384
        final IPlayerData pData = DataManager.getPlayerData(p);
385
        final CombinedData data = pData.getGenericInstance(CombinedData.class);
386
        final PacketContainer packet = event.getPacket();
387
        final StructureModifier<Integer> ints = packet.getIntegers();
388
        // Legacy: pre 1.9
389
        if (ints.size() > 0 && !ServerVersion.isAtLeast("1.9")) {
390
            final int faceIndex = ints.read(0); // arg 3 if 1.7.10 below
391
            if (faceIndex <= 5) {
392
                data.mightUseItem = false;
393
                return;
394
            }
395
        }
396
        // Player sends a block-placement item when right-clicking, so they might be actually using an item. Set the flag.
397
        if (!event.isCancelled()) data.mightUseItem = true;
398
    }
399
400
    private void handleDiggingPacket(PacketEvent event) {
401
        Player p = event.getPlayer();       
402
        final IPlayerData pData = DataManager.getPlayerDataSafe(p);
403
        final CombinedData data = pData.getGenericInstance(CombinedData.class);
404
        PlayerDigType digtype = event.getPacket().getPlayerDigTypes().read(0);
405
        if (!BridgeMisc.hasGetItemInUseMethod()) {
406
            // DROP_ALL_ITEMS when dead?
407
            if (digtype == PlayerDigType.DROP_ALL_ITEMS || digtype == PlayerDigType.DROP_ITEM) {
408
                pData.setItemInUse(null);
409
            }
410
        }
411
        
412
        if (digtype == PlayerDigType.RELEASE_USE_ITEM) {
413
            pData.setItemInUse(null);
414
            long now = System.currentTimeMillis();
415
            if (data.releaseItemTime != 0) {
416
                if (now < data.releaseItemTime) {
417
                    data.releaseItemTime = now;
418
                    return;
419
                }
420
                if (data.releaseItemTime + timeBetweenRL > now) {
421
                    data.isHackingRI = true;
422
                }
423
            }
424
            data.releaseItemTime = now;
425
        }
426
    }
427
428
    /**
429
     * Set Minimum time between RELEASE_USE_ITEM packet is sent.
430
     * If time lower this value, A check will flag
431
     * Should be set from 51-100. Larger number, more protection more false-positive
432
     * 
433
     * @param time milliseconds
434
     */ 
435
    public static void setuseRLThreshold(int time) {
436
        timeBetweenRL = time;
437
    }   
438
}

How it counteracts this module

UseItemAdapter timestamps every C07 RELEASE_USE_ITEM and sets CombinedData.isHackingRI when a release arrives within timeBetweenRL (default 70ms) of the previous one; SurvivalFly then tags the move noslowpacket and runs Improbable on the horizontal distance. Packet mode's per-tick release and re-arm land about 50ms apart, well inside the window, so the release stream trips the flag; AAC4's odd-tick cadence spaces releases at roughly 100ms, just past the 70ms ledger, which is the honest evasion surface.

anticheat Speed (releaseItem teardown)

Speed.java280 lines · Java
1
/*
2
 * This file is part of Hawk Anticheat.
3
 * Copyright (C) 2018 Hawk Development Team
4
 *
5
 * This program is free software: you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation, either version 3 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
17
 */
18
19
package me.islandscout.hawk.check.movement.position;
20
21
import me.islandscout.hawk.Hawk;
22
import me.islandscout.hawk.HawkPlayer;
23
import me.islandscout.hawk.check.MovementCheck;
24
import me.islandscout.hawk.event.Event;
25
import me.islandscout.hawk.event.HawkEventListener;
26
import me.islandscout.hawk.event.ItemSwitchEvent;
27
import me.islandscout.hawk.event.MoveEvent;
28
import me.islandscout.hawk.util.*;
29
import me.islandscout.hawk.wrap.entity.WrappedEntity;
30
import org.bukkit.ChatColor;
31
import org.bukkit.Material;
32
import org.bukkit.enchantments.Enchantment;
33
import org.bukkit.entity.Player;
34
import org.bukkit.event.Listener;
35
import org.bukkit.util.Vector;
36
37
import java.util.*;
38
39
public class Speed extends MovementCheck implements Listener {
40
41
    //I legit hate this game's movement.
42
    //Do you realize how much easier it would be if
43
    //the server handled movement?
44
45
    //TODO False flag with pistons
46
47
    //Basically, this check is doing, "if your previous speed was X then your current speed must not exceed f(X)"
48
49
    private static final double EPSILON = 0.000001;
50
    //Now what we can do is predict how far a player could have travelled
51
    //if the move doesn't have a deltaPos due to insignificance.
52
    private static final double MAX_NO_MOVE_DISTANCE = 0.03;
53
    private final double DISCREPANCY_THRESHOLD;
54
    private final double VL_FAIL_DISCREPANCY_FACTOR;
55
    private final boolean RESET_DISCREPANCY_ON_FAIL;
56
    private final int RELEASE_ITEM_OVER_VL;
57
    private final boolean CHECK_FLYING;
58
    private final boolean DEBUG;
59
60
    private final Map<UUID, Double> prevSpeed;
61
    private final Map<UUID, Double> discrepancies;
62
    private final Map<UUID, Integer> noMovesMap;
63
    private final Map<UUID, Double> lastNegativeDiscrepancies;
64
    private final Map<UUID, Double> negativeDiscrepanciesCumulative;
65
    private final Map<UUID, Integer> slotSwitchQuirkTicksMap; //I hate this game.
66
    private final Map<UUID, Long> lastSlotSwitchTickMap;
67
68
    public Speed() {
69
        super("speed", true, 0, 5, 0.99, 5000, "%player% failed movement speed, VL: %vl%", null);
70
        prevSpeed = new HashMap<>();
71
        discrepancies = new HashMap<>();
72
        noMovesMap = new HashMap<>();
73
        lastNegativeDiscrepancies = new HashMap<>();
74
        negativeDiscrepanciesCumulative = new HashMap<>();
75
        slotSwitchQuirkTicksMap = new HashMap<>();
76
        lastSlotSwitchTickMap = new HashMap<>();
77
        DISCREPANCY_THRESHOLD = (double) customSetting("discrepancyThreshold", "", 0.1D);
78
        VL_FAIL_DISCREPANCY_FACTOR = (double) customSetting("vlFailDiscrepancyFactor", "", 10D);
79
        RESET_DISCREPANCY_ON_FAIL = (boolean) customSetting("resetDiscrepancyOnFail", "", true);
80
        RELEASE_ITEM_OVER_VL = (int) customSetting("releaseItemOverVl", "", 4);
81
        CHECK_FLYING = (boolean) customSetting("checkFlying", "", true);
82
        DEBUG = (boolean) customSetting("debug", "", false);
83
    }
84
85
    @Override
86
    protected void check(MoveEvent event) {
87
        Player p = event.getPlayer();
88
        HawkPlayer pp = event.getHawkPlayer();
89
90
        int noMoves = noMovesMap.getOrDefault(p.getUniqueId(), 0);
91
        double lastSpeed;
92
        double speed;
93
        if(event.isUpdatePos()) {
94
            lastSpeed = prevSpeed.getOrDefault(p.getUniqueId(), 0D);
95
            if(noMoves > 0) {
96
                //Players don't update position unless they've moved at least 0.03 blocks (or if 20 ticks passed)
97
                lastSpeed = Math.min(lastSpeed, MAX_NO_MOVE_DISTANCE);
98
            }
99
            speed = MathPlus.distance2d(event.getTo().getX() - event.getFrom().getX(), event.getTo().getZ() - event.getFrom().getZ());
100
        }
101
        else {
102
            speed = prevSpeed.getOrDefault(p.getUniqueId(), 0D) - (lastNegativeDiscrepancies.getOrDefault(p.getUniqueId(), 0D) + EPSILON);
103
            lastSpeed = speed;
104
        }
105
106
        if(event.isUpdatePos())
107
            noMoves = 0;
108
        else
109
            noMoves++;
110
111
        boolean flying = pp.isFlying();
112
        boolean swimming = pp.isInWater(); //this needs improvement
113
        //it is possible that the player has pressed the jump key even if this move is "stepped" (only while sprinting)
114
        boolean jump = event.isJump() || (event.isStep() && pp.isOnGround() && pp.isSprinting());
115
116
        float friction = event.getFriction();
117
        float maxForce = event.getMaxExpectedInputForce();
118
        float maxForceNoItemUse = event.getMaxExpectedInputForceNoItemUse();
119
120
        //It represents the previous location. Block collision is done after moving the entity.
121
        Set<Material> touchedBlocks = WrappedEntity.getWrappedEntity(p).getCollisionBox(event.getFrom().toVector()).getMaterials(pp.getWorld());
122
123
        //handle any pending knockbacks
124
        if(event.hasAcceptedKnockback() || (flying && !CHECK_FLYING)) {
125
            prepareNextMove(pp, noMoves, speed, touchedBlocks);
126
            return;
127
        }
128
129
        double lastSpeedCompare = lastSpeed;
130
        //Handle other things in the game that multiply velocity.
131
        //These affect velocity first (coincidentally, these are all multiplication operations)
132
        double handleMultipliers = 1;
133
        if(event.hasHitSlowdown())
134
            handleMultipliers *= 0.6;
135
        if(touchedBlocks.contains(Material.SOUL_SAND) && !flying)
136
            handleMultipliers *= 0.4;
137
        if(touchedBlocks.contains(Material.WEB) && !flying)
138
            handleMultipliers *= 0.25;
139
        if(Hawk.getServerVersion() > 7 && touchedBlocks.contains(Material.SLIME_BLOCK)) {
140
            //TODO I believe webs affect this mot Y too.
141
            if (Math.abs(pp.getVelocity().getY()) < 0.1 && !pp.isSneaking()) {
142
                handleMultipliers *= 0.4 + Math.abs(pp.getVelocity().getY()) * 0.2;
143
            }
144
        }
145
        //Handle other things in the game that add to velocity.
146
        //These affect velocity later (coincidentally, these are all addition operations)
147
        double handleAdders = 0;
148
        if(pp.isSprinting() && jump) {
149
            handleAdders += 0.2;
150
        }
151
        if(swimming && !flying) { //This is actually a terrible way of handling horizontal water flow.
152
            Vector move = new Vector(event.getTo().getX() - event.getFrom().getX(), 0, event.getTo().getZ() - event.getFrom().getZ());
153
            Vector waterForce = event.getWaterFlowForce().clone().setY(0);
154
            double waterForceLength = waterForce.length() + 0.003; //add epsilon to allow room for error
155
            double moveLength = move.length();
156
            double computedForce = moveLength == 0 ? waterForceLength : (move.dot(waterForce) / moveLength);
157
158
            handleAdders += computedForce;
159
        }
160
161
        //Finally, the expected speed calculation. There's another "expected" because of a dumb quirk when switching slots while using an item.
162
        //Optimize later.
163
        double expected = friction * lastSpeedCompare * handleMultipliers + (maxForce + handleAdders + EPSILON);
164
        double expectedNoItemUse = friction * lastSpeedCompare * handleMultipliers + (maxForceNoItemUse + handleAdders + EPSILON);
165
166
        //I hate this game. Handle slot switching quirk. The slot switch packet is delayed by a tick.
167
        //This sort of "event listening" must be done because Hawk's MoveEvents can be skipped under certain conditions.
168
        long slotSwitchTick = pp.getLastSlotSwitchTick();
169
        boolean switchedSlot = slotSwitchTick != lastSlotSwitchTickMap.getOrDefault(p.getUniqueId(), slotSwitchTick);
170
        int slotSwitchQuirkTicks = slotSwitchQuirkTicksMap.getOrDefault(p.getUniqueId(), 0);
171
        if(switchedSlot) {
172
            slotSwitchQuirkTicks = 0;
173
        }
174
        lastSlotSwitchTickMap.put(p.getUniqueId(), slotSwitchTick);
175
176
        //Calculate discrepancy.
177
        Discrepancy discrepancy; //This is the one that will be used for final comparison. It is the value of either discrepancyBase or discrepancyNoItemUse.
178
        Discrepancy discrepancyBase; //Used for pretty much 99.99% of moves.
179
        Discrepancy discrepancyNoItemUse; //Similar to discrepancyBase, but doesn't consider item-use slowdown.
180
181
        discrepancyBase = new Discrepancy(expected, speed);
182
        discrepancyNoItemUse = new Discrepancy(expectedNoItemUse, speed);
183
        if((pp.isBlocking() || pp.isConsumingItem() || pp.isPullingBow()) && Math.abs(discrepancyNoItemUse.value) < Math.abs(discrepancyBase.value)) {
184
            //This means that they're using an item, but they're moving at normal speed. This COULD be due to that
185
            //dumb item switch quirk, so we'll grant them only one extra tick. It resets when they switch their slot.
186
            if(slotSwitchQuirkTicks < 1) {
187
                //Allow them to move at normal speed for 1 tick.
188
                discrepancy = discrepancyNoItemUse;
189
                slotSwitchQuirkTicks++;
190
            } else {
191
                discrepancy = discrepancyBase;
192
            }
193
        } else {
194
            discrepancy = discrepancyBase;
195
        }
196
197
        //Client told server that it updated its position. Checking time.
198
        if (event.isUpdatePos()) {
199
            double haltDistanceExpected = negativeDiscrepanciesCumulative.getOrDefault(p.getUniqueId(), 0D);
200
            lastNegativeDiscrepancies.put(p.getUniqueId(), 0D);
201
            if(discrepancy.value < 0 || speed > haltDistanceExpected)
202
                discrepancies.put(p.getUniqueId(), Math.max(discrepancies.getOrDefault(p.getUniqueId(), 0D) + discrepancy.value, 0));
203
            double totalDiscrepancy = discrepancies.getOrDefault(p.getUniqueId(), 0D);
204
205
            if(DEBUG) {
206
                p.sendMessage((totalDiscrepancy > DISCREPANCY_THRESHOLD ? ChatColor.RED : ChatColor.GREEN) + "" + totalDiscrepancy);
207
            }
208
209
            if(discrepancy.value > 0 && totalDiscrepancy > DISCREPANCY_THRESHOLD && !event.isPossiblePistonPush()) {
210
                punishAndTryRubberband(pp, discrepancy.value * VL_FAIL_DISCREPANCY_FACTOR, event);
211
                if(RESET_DISCREPANCY_ON_FAIL)
212
                    discrepancies.put(p.getUniqueId(), 0D);
213
                if(RELEASE_ITEM_OVER_VL > -1 && (pp.isPullingBow() || pp.isConsumingItem() || pp.isBlocking()) && pp.getVL(this) > RELEASE_ITEM_OVER_VL)
214
                    pp.releaseItem();
215
            }
216
            else {
217
                reward(pp);
218
            }
219
220
            lastNegativeDiscrepancies.put(p.getUniqueId(), 0D);
221
            negativeDiscrepanciesCumulative.put(p.getUniqueId(), 0D);
222
        }
223
        //Client sent a flying packet, but didn't update position.
224
        //The move might have not been significant enough, so we need
225
        //to prepare for when the client decides it's time to update
226
        //position.
227
        else {
228
            lastNegativeDiscrepancies.put(p.getUniqueId(), discrepancy.value);
229
230
            //TODO improve these two lines...
231
            double val = negativeDiscrepanciesCumulative.getOrDefault(p.getUniqueId(), 0D);
232
            negativeDiscrepanciesCumulative.put(p.getUniqueId(), Math.min(val + speed, MAX_NO_MOVE_DISTANCE + speed));
233
            //negativeDiscrepanciesCumulative.put(p.getUniqueId(), negativeDiscrepanciesCumulative.getOrDefault(p.getUniqueId(), 0D) + speed);
234
        }
235
236
        slotSwitchQuirkTicksMap.put(p.getUniqueId(), slotSwitchQuirkTicks);
237
        prepareNextMove(pp, noMoves, speed, touchedBlocks);
238
    }
239
240
    private void prepareNextMove(HawkPlayer pp, int noMoves, double currentSpeed, Set<Material> touchedBlocks) {
241
        if(touchedBlocks.contains(Material.WEB) && !pp.isFlying()) {
242
            currentSpeed = 0;
243
        }
244
        UUID uuid = pp.getUuid();
245
        prevSpeed.put(uuid, currentSpeed);
246
        noMovesMap.put(uuid, noMoves);
247
    }
248
249
    public void removeData(Player p) {
250
        UUID uuid = p.getUniqueId();
251
        prevSpeed.remove(uuid);
252
        discrepancies.remove(uuid);
253
        noMovesMap.remove(uuid);
254
        lastNegativeDiscrepancies.remove(uuid);
255
        negativeDiscrepanciesCumulative.remove(uuid);
256
        slotSwitchQuirkTicksMap.remove(uuid);
257
        lastSlotSwitchTickMap.remove(uuid);
258
    }
259
260
    //speed potions do not affect swimming
261
    private Discrepancy waterMapping(double lastSpeed, double currentSpeed, double waterFlowForce) {
262
        double expected = 0.800001 * lastSpeed + 0.020001 + waterFlowForce;
263
        return new Discrepancy(expected, currentSpeed);
264
    }
265
266
    private Discrepancy lavaMapping(double lastSpeed, double currentSpeed) {
267
        double expected = 0.500001 * lastSpeed + 0.020001;
268
        return new Discrepancy(expected, currentSpeed);
269
    }
270
271
    private class Discrepancy {
272
273
        double value;
274
275
        Discrepancy(double expectedSpeed, double currentSpeed) {
276
            value = currentSpeed - expectedSpeed;
277
        }
278
279
    }
280
}

How it counteracts this module

Hawk's Speed check tracks players who are pulling a bow, consuming or blocking, and once releaseItemOverVl (default 4) is exceeded it forces releaseItem() on the player, tearing down the re-arm loop server-side so the next C08 use-item cannot re-enter the blocking state. The forced release resets the item-use the module is trying to preserve, so sustained noslow packet streams accumulate the VL that triggers it.

anticheat NoSlowCheck (release while blocking)

NoSlowCheck.java51 lines · Java
1
package better.anticheat.core.check.broken;
2
3
import better.anticheat.core.BetterAnticheat;
4
import better.anticheat.core.check.Check;
5
import better.anticheat.core.check.CheckInfo;
6
import better.anticheat.core.player.Player;
7
import com.github.retrooper.packetevents.event.simple.PacketPlayReceiveEvent;
8
import com.github.retrooper.packetevents.protocol.player.DiggingAction;
9
import com.github.retrooper.packetevents.wrapper.play.client.WrapperPlayClientEntityAction;
10
import com.github.retrooper.packetevents.wrapper.play.client.WrapperPlayClientPlayerDigging;
11
12
@CheckInfo(name = "NoSlow", category = "combat")
13
public class NoSlowCheck extends Check {
14
    private boolean blocking = false, sprinting = false;
15
16
    public NoSlowCheck(BetterAnticheat plugin, Player player) {
17
        super(plugin, player);
18
    }
19
20
    @Override
21
    public void handleReceivePlayPacket(PacketPlayReceiveEvent event) {
22
23
        /*
24
         * This check is intended to detect starting sprinting while using an item (like blocking a shield, shooting a
25
         * bow, or eating food). However, this check has unexplainable falses.
26
         */
27
28
        switch (event.getPacketType()) {
29
            case USE_ITEM:
30
                blocking = true;
31
                sprinting = false;
32
                break;
33
            case ENTITY_ACTION:
34
                WrapperPlayClientEntityAction actionWrapper = new WrapperPlayClientEntityAction(event);
35
                if (actionWrapper.getAction().equals(WrapperPlayClientEntityAction.Action.START_SPRINTING)) {
36
                    sprinting = true;
37
                }
38
                break;
39
            case PLAYER_DIGGING:
40
                WrapperPlayClientPlayerDigging diggingWrapper = new WrapperPlayClientPlayerDigging(event);
41
                if (diggingWrapper.getAction() != DiggingAction.RELEASE_USE_ITEM) return;
42
43
                // Only flag on use item release as previously we don't know if the player is actually blocking.
44
45
                if (blocking && sprinting) fail();
46
                blocking = false;
47
48
                break;
49
        }
50
    }
51
}

How it counteracts this module

NoSlowCheck flags a RELEASE_USE_ITEM seen while the player is blocking (a prior USE_ITEM) and sprinting, then resets the blocking marker, which matches the module's release-while-blocked pattern exactly. The check ships under check/broken and is disabled in the tree because of unexplainable false positives, so it is a latent counter, not a live one.

anticheat RepeatedReleaseCheck (release without use)

RepeatedReleaseCheck.java57 lines · Java
1
package better.anticheat.core.check.broken;
2
3
import better.anticheat.core.BetterAnticheat;
4
import better.anticheat.core.check.Check;
5
import better.anticheat.core.check.CheckInfo;
6
import better.anticheat.core.player.Player;
7
import com.github.retrooper.packetevents.event.simple.PacketPlayReceiveEvent;
8
import com.github.retrooper.packetevents.protocol.player.DiggingAction;
9
import com.github.retrooper.packetevents.wrapper.play.client.WrapperPlayClientPlayerDigging;
10
11
/*
12
 * NOTE: This check is currenlty not enabled due to false flag issues.
13
 * Use Item mechanics may have changed since this was originally designed?
14
 */
15
@CheckInfo(name = "RepeatedRelease", category = "dig")
16
public class RepeatedReleaseCheck extends Check {
17
    private boolean useItem = true;
18
19
    public RepeatedReleaseCheck(BetterAnticheat plugin, Player player) {
20
        super(plugin, player);
21
    }
22
23
    @Override
24
    public void handleReceivePlayPacket(PacketPlayReceiveEvent event) {
25
26
        /*
27
         * For some reason you can send multiple releases? Needs debugging.
28
         */
29
30
        switch (event.getPacketType()) {
31
            //Keep track of whether the player sent an initial use item packet.
32
            case USE_ITEM:
33
                useItem = true;
34
35
                break;
36
            case PLAYER_DIGGING:
37
                WrapperPlayClientPlayerDigging wrapper = new WrapperPlayClientPlayerDigging(event);
38
39
                /*
40
                 * In 1.9 and above using an item works as the following:
41
                 * First, the client initiates it by sending a use item packet.
42
                 * Second, the client releases it by sending a block dig packet.
43
                 *
44
                 * This means that between all release use item digs there must be a use item.
45
                 * From my testing, it does not appear like there must be a release between uses as there are edge
46
                 * cases that make UseItem seem to de-sync.
47
                 */
48
                if (wrapper.getAction() == DiggingAction.RELEASE_USE_ITEM) {
49
                    if (!useItem) fail();
50
51
                    useItem = false;
52
                }
53
54
                break;
55
        }
56
    }
57
}

How it counteracts this module

The check flags a release that arrives without a preceding USE_ITEM, but the module always sends its C08 re-arm before the next release, so a release is never orphaned and the check never fires against this pattern. It is also disabled in the tree; the entry documents why a naive release-ordering rule fails against re-arm noslow loops.

← Back to Analysis Hub