Memeware 7.3 NoSlow module 2 files, 785 lines

Memeware 7.3 NoSlow: Full Source Analysis

Memeware 7.3's NoSlow works on two layers.

me/memewaredevs/client/module/movement/NoSlow.java · GitHub source ↗

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

Analysis

Overview

Memeware 7.3's NoSlow works on two layers. The client itself is modified: EntityPlayerSP.onLivingUpdate gates the vanilla 0.2F movement-input slowdown on Module.getInstance(NoSlow.class).isToggled(), so while the module is on, blocking no longer scales strafe and forward input by 0.2F and sprint is never cancelled. The module's own handler adds the packet layer: in the 'NCP' mode, the pre phase of each UpdateEvent sends C07PacketPlayerDigging RELEASE_USE_ITEM while blocking, and the post phase re-arms with setItemInUse(currentItem, 71999999) plus sendUseItem, which emits a fresh C08PacketPlayerBlockPlacement, keeping the server-side item-in-use state consistent with full-speed movement. The constructor registers modes 'AAC', 'NCP' and 'Velt', but the handler only tests isMode('NCP'), so the other two names select no branch and the packet layer is effectively single-mode.

Architecture

Two independent mechanisms share the module name. The client-side half lives in the fork's EntityPlayerSP.onLivingUpdate: line 634 reads boolean cancel = Module.getInstance(NoSlow.class).isToggled() and lines 635-639 only apply the 0.2F strafe/forward multiplier, the sprintToggleTimer reset and the sprint-suppression when !cancel, so a toggled module removes the entire vanilla slowdown and the isUsingItem-based sprint lock. The module file itself only carries the packet half: a single @Handler-flagged Consumer on UpdateEvent whose isPre() flag splits the work, plus the static unusableItemSlot() helper (lines 36-44) that scans the hotbar for an EnumAction.NONE stack and is never called from the handler in this tree, a leftover from a slot-swap variant.

The packet re-arm cycle

In the NCP mode, while mc.thePlayer.isBlocking() is true the pre phase queues C07PacketPlayerDigging(RELEASE_USE_ITEM, BlockPos.ORIGIN, EnumFacing.UP), and the post phase calls setItemInUse(getCurrentEquippedItem(), 71999999) followed by mc.playerController.sendUseItem. This fork's sendUseItem (PlayerControllerMP line 457) syncs the held slot, addToSendQueue's a C08PacketPlayerBlockPlacement carrying only the item stack (line 463), then runs useItemRightClick locally. The 71999999 duration is effectively infinite, so the client believes the block is still held for the whole fight while the server saw a release. Per blocking tick the server therefore receives RELEASE_USE_ITEM followed by a use-item C08: the release clears the server's item-in-use state (which is what allows sprint and full-speed movement to be consistent), and the C08 re-arms the use for combat purposes.

Mode and timing profile

The packet pair fires every tick while blocking, so the C07 release cadence is 20/s, 50ms between releases; vanilla sends a single RELEASE_USE_ITEM when the use key is released, so the per-tick release stream is the module's packet fingerprint. The dead registrations matter for behavior: addModes registers 'AAC', 'NCP' and 'Velt' (line 18), but the handler tests only isMode('NCP') (line 23), so switching to 'AAC' or 'Velt' leaves the packet layer inert while the client-side EntityPlayerSP hook (which does not consult the mode string) keeps removing the slowdown. A user in those modes gets the speed gain with no packet re-arm, which produces the one-fingerprint state: full-speed blocking movement with no releases at all.

source NoSlow.java (module logic)

NoSlow.java45 lines · JavaOriginal ↗
1
2
package me.memewaredevs.client.module.movement;
3
4
import me.hippo.api.lwjeb.annotation.Handler;
5
import me.memewaredevs.client.event.events.UpdateEvent;
6
import me.memewaredevs.client.module.Module;
7
import net.minecraft.item.EnumAction;
8
import net.minecraft.item.ItemStack;
9
import net.minecraft.network.play.client.C07PacketPlayerDigging;
10
import net.minecraft.util.BlockPos;
11
import net.minecraft.util.EnumFacing;
12
13
import java.util.function.Consumer;
14
15
public class NoSlow extends Module {
16
    public NoSlow() {
17
        super("No Slowdown", 0, Module.Category.MOVEMENT);
18
        this.addModes("AAC", "NCP", "Velt");
19
    }
20
21
    @Handler
22
    public Consumer<UpdateEvent> eventConsumer0 = e -> {
23
        if (isMode("NCP")) {
24
            if (mc.thePlayer.isBlocking()) {
25
                if (e.isPre()) {
26
                    this.mc.thePlayer.sendQueue.addToSendQueue(new C07PacketPlayerDigging(
27
                            C07PacketPlayerDigging.Action.RELEASE_USE_ITEM, BlockPos.ORIGIN, EnumFacing.UP));
28
                } else {
29
                    mc.thePlayer.setItemInUse(mc.thePlayer.getCurrentEquippedItem(), 71999999);
30
                    mc.playerController.sendUseItem(mc.thePlayer, mc.theWorld, mc.thePlayer.getCurrentEquippedItem());
31
                }
32
            }
33
        }
34
    };
35
36
    public static int unusableItemSlot() {
37
        for (int j = 0; j < 8; ++j) {
38
            ItemStack stack = mc.thePlayer.inventory.mainInventory[j];
39
            if (stack != null && stack.getItemUseAction() == EnumAction.NONE) {
40
                return j;
41
            }
42
        }
43
        return -10;
44
    }
45
}

What this file does

The handler is the packet layer: e.isPre() gates the C07 RELEASE_USE_ITEM send (lines 25-27) and the else branch re-arms with setItemInUse(..., 71999999) plus sendUseItem (lines 28-31), which routes through PlayerControllerMP.sendUseItem to emit the C08. The mode wiring is the module's defining quirk: addModes('AAC', 'NCP', 'Velt') at line 18 versus the single isMode('NCP') test at line 23, so two of three registered modes select nothing. unusableItemSlot() (lines 36-44) is dead code in this tree.

source EntityPlayerSP.java (the client-side slowdown hook)

EntityPlayerSP.java740 lines · JavaOriginal ↗
1
package net.minecraft.client.entity;
2
3
import me.memewaredevs.client.event.EventAPI;
4
import me.memewaredevs.client.event.events.MovementEvent;
5
import me.memewaredevs.client.event.events.UpdateEvent;
6
import me.memewaredevs.client.module.Module;
7
import me.memewaredevs.client.module.combat.TargetStrafe;
8
import me.memewaredevs.client.module.movement.NoSlow;
9
import net.minecraft.client.Minecraft;
10
import net.minecraft.client.audio.MovingSoundMinecartRiding;
11
import net.minecraft.client.audio.PositionedSoundRecord;
12
import net.minecraft.client.gui.*;
13
import net.minecraft.client.gui.inventory.*;
14
import net.minecraft.client.network.NetHandlerPlayClient;
15
import net.minecraft.command.server.CommandBlockLogic;
16
import net.minecraft.entity.Entity;
17
import net.minecraft.entity.IMerchant;
18
import net.minecraft.entity.item.EntityItem;
19
import net.minecraft.entity.item.EntityMinecart;
20
import net.minecraft.entity.passive.EntityHorse;
21
import net.minecraft.init.Items;
22
import net.minecraft.inventory.IInventory;
23
import net.minecraft.item.Item;
24
import net.minecraft.item.ItemStack;
25
import net.minecraft.network.play.client.*;
26
import net.minecraft.potion.Potion;
27
import net.minecraft.stats.StatBase;
28
import net.minecraft.stats.StatFileWriter;
29
import net.minecraft.tileentity.TileEntitySign;
30
import net.minecraft.util.*;
31
import net.minecraft.world.IInteractionObject;
32
import net.minecraft.world.World;
33
34
public class EntityPlayerSP extends AbstractClientPlayer {
35
	public final NetHandlerPlayClient sendQueue;
36
	private final StatFileWriter field_146108_bO;
37
	private double field_175172_bI;
38
	private double field_175166_bJ;
39
	private double field_175167_bK;
40
	private float field_175164_bL;
41
	private float field_175165_bM;
42
	private boolean field_175170_bN;
43
	private boolean field_175171_bO;
44
	private int field_175168_bP;
45
	private boolean field_175169_bQ;
46
	private String clientBrand;
47
	public MovementInput movementInput;
48
	protected Minecraft mc;
49
50
	/**
51
	 * Used to tell if the player pressed forward twice. If this is at 0 and it's
52
	 * pressed (And they are allowed to sprint, aka enough food on the ground etc)
53
	 * it sets this to 7. If it's pressed and it's greater than 0 enable sprinting.
54
	 */
55
	protected int sprintToggleTimer;
56
57
	/**
58
	 * Ticks left before sprinting is disabled.
59
	 */
60
	public int sprintingTicksLeft;
61
	public float renderArmYaw;
62
	public float renderArmPitch;
63
	public float prevRenderArmYaw;
64
	public float prevRenderArmPitch;
65
	private int horseJumpPowerCounter;
66
	private float horseJumpPower;
67
68
	/**
69
	 * The amount of time an entity has been in a Portal
70
	 */
71
	public float timeInPortal;
72
73
	/**
74
	 * The amount of time an entity has been in a Portal the previous tick
75
	 */
76
	public float prevTimeInPortal;
77
	private static final String __OBFID = "CL_00000938";
78
79
	public EntityPlayerSP(Minecraft mcIn, World worldIn, NetHandlerPlayClient p_i46278_3_, StatFileWriter p_i46278_4_) {
80
		super(worldIn, p_i46278_3_.func_175105_e());
81
		this.sendQueue = p_i46278_3_;
82
		this.field_146108_bO = p_i46278_4_;
83
		this.mc = mcIn;
84
		this.dimension = 0;
85
	}
86
87
	/**
88
	 * Called when the entity is attacked.
89
	 */
90
	public boolean attackEntityFrom(DamageSource source, float amount) {
91
		return false;
92
	}
93
94
	/**
95
	 * Heal living entity (param: amount of half-hearts)
96
	 */
97
	public void heal(float p_70691_1_) {
98
	}
99
100
	/**
101
	 * Called when a player mounts an entity. e.g. mounts a pig, mounts a boat.
102
	 */
103
	public void mountEntity(Entity entityIn) {
104
		super.mountEntity(entityIn);
105
106
		if (entityIn instanceof EntityMinecart) {
107
			this.mc.getSoundHandler().playSound(new MovingSoundMinecartRiding(this, (EntityMinecart) entityIn));
108
		}
109
	}
110
111
	/**
112
	 * Called to update the entity's position/logic.
113
	 */
114
	public void onUpdate() {
115
		if (this.worldObj.isBlockLoaded(new BlockPos(this.posX, 0.0D, this.posZ))) {
116
			super.onUpdate();
117
118
			if (this.isRiding()) {
119
				this.sendQueue.addToSendQueue(
120
						new C03PacketPlayer.C05PacketPlayerLook(this.rotationYaw, this.rotationPitch, this.onGround));
121
				this.sendQueue.addToSendQueue(new C0CPacketInput(this.moveStrafing, this.moveForward,
122
						this.movementInput.isJumping(), this.movementInput.isSneaking()));
123
			} else {
124
				this.func_175161_p();
125
			}
126
		}
127
	}
128
129
	@Override
130
	public void moveEntity(double x, double y, double z) {
131
		MovementEvent e = new MovementEvent(x, y, z);
132
		EventAPI.fire(e);
133
		if (e.isCancelled())
134
			return;
135
		super.moveEntity(e.getX(), e.getY(), e.getZ());
136
	}
137
138
	public void func_175161_p() {
139
		UpdateEvent event = new UpdateEvent(posX, boundingBox.minY, posZ, rotationYaw, rotationPitch, onGround);
140
		EventAPI.fire(event);
141
		if (event.isCancelled())
142
			return;
143
		boolean var1 = this.isSprinting();
144
		if (var1 != this.field_175171_bO) {
145
			if (var1) {
146
				this.sendQueue
147
						.addToSendQueue(new C0BPacketEntityAction(this, C0BPacketEntityAction.Action.START_SPRINTING));
148
			} else {
149
				this.sendQueue
150
						.addToSendQueue(new C0BPacketEntityAction(this, C0BPacketEntityAction.Action.STOP_SPRINTING));
151
			}
152
153
			this.field_175171_bO = var1;
154
		}
155
156
		boolean var2 = this.isSneaking();
157
158
		if (var2 != this.field_175170_bN) {
159
			if (var2) {
160
				this.sendQueue
161
						.addToSendQueue(new C0BPacketEntityAction(this, C0BPacketEntityAction.Action.START_SNEAKING));
162
			} else {
163
				this.sendQueue
164
						.addToSendQueue(new C0BPacketEntityAction(this, C0BPacketEntityAction.Action.STOP_SNEAKING));
165
			}
166
167
			this.field_175170_bN = var2;
168
		}
169
170
		if (this.func_175160_A()) {
171
			double var3 = event.getX() - this.field_175172_bI;
172
			double var5 = event.getY() - this.field_175166_bJ;
173
			double var7 = event.getZ() - this.field_175167_bK;
174
			double var9 = event.getYaw() - this.field_175164_bL;
175
			double var11 = event.getPitch() - this.field_175165_bM;
176
			boolean var13 = var3 * var3 + var5 * var5 + var7 * var7 > 9.0E-4D || this.field_175168_bP >= 20;
177
			boolean var14 = var9 != 0.0D || var11 != 0.0D;
178
179
			if (this.ridingEntity == null) {
180
				if (var13 && var14) {
181
					this.sendQueue.addToSendQueue(new C03PacketPlayer.C06PacketPlayerPosLook(event.getX(), event.getY(),
182
							event.getZ(), event.getYaw(), event.getPitch(), event.getGroundState()));
183
				} else if (var13) {
184
					this.sendQueue.addToSendQueue(new C03PacketPlayer.C04PacketPlayerPosition(event.getX(),
185
							event.getY(), event.getZ(), event.getGroundState()));
186
				} else if (var14) {
187
					this.sendQueue.addToSendQueue(new C03PacketPlayer.C05PacketPlayerLook(event.getYaw(),
188
							event.getPitch(), event.getGroundState()));
189
				} else {
190
					this.sendQueue.addToSendQueue(new C03PacketPlayer(event.getGroundState()));
191
				}
192
			} else {
193
				this.sendQueue.addToSendQueue(new C03PacketPlayer.C06PacketPlayerPosLook(this.motionX, -999.0D,
194
						this.motionZ, this.rotationYaw, this.rotationPitch, this.onGround));
195
				var13 = false;
196
			}
197
198
			++this.field_175168_bP;
199
200
			if (var13) {
201
				this.field_175172_bI = event.getX();
202
				this.field_175166_bJ = event.getY();
203
				this.field_175167_bK = event.getZ();
204
				this.field_175168_bP = 0;
205
			}
206
207
			if (var14) {
208
				this.field_175164_bL = event.getYaw();
209
				this.field_175165_bM = event.getPitch();
210
			}
211
		}
212
		EventAPI.fire(new UpdateEvent());
213
	}
214
215
	/**
216
	 * Called when player presses the drop item key
217
	 */
218
	public EntityItem dropOneItem(boolean p_71040_1_) {
219
		C07PacketPlayerDigging.Action var2 = p_71040_1_ ? C07PacketPlayerDigging.Action.DROP_ALL_ITEMS
220
				: C07PacketPlayerDigging.Action.DROP_ITEM;
221
		this.sendQueue.addToSendQueue(new C07PacketPlayerDigging(var2, BlockPos.ORIGIN, EnumFacing.DOWN));
222
		return null;
223
	}
224
225
	/**
226
	 * Joins the passed in entity item with the world. Args: entityItem
227
	 */
228
	protected void joinEntityItemWithWorld(EntityItem p_71012_1_) {
229
	}
230
231
	/**
232
	 * Sends a chat message from the player. Args: chatMessage
233
	 */
234
	public void sendChatMessage(String p_71165_1_) {
235
		this.sendQueue.addToSendQueue(new C01PacketChatMessage(p_71165_1_));
236
	}
237
238
	/**
239
	 * Swings the item the player is holding.
240
	 */
241
	public void swingItem() {
242
		super.swingItem();
243
		this.sendQueue.addToSendQueue(new C0APacketAnimation());
244
	}
245
246
	public void respawnPlayer() {
247
		this.sendQueue.addToSendQueue(new C16PacketClientStatus(C16PacketClientStatus.EnumState.PERFORM_RESPAWN));
248
	}
249
250
	/**
251
	 * Deals damage to the entity. If its a EntityPlayer then will take damage from
252
	 * the armor first and then health second with the reduced value. Args:
253
	 * damageAmount
254
	 */
255
	protected void damageEntity(DamageSource p_70665_1_, float p_70665_2_) {
256
		if (!this.func_180431_b(p_70665_1_)) {
257
			this.setHealth(this.getHealth() - p_70665_2_);
258
		}
259
	}
260
261
	/**
262
	 * set current crafting inventory back to the 2x2 square
263
	 */
264
	public void closeScreen() {
265
		this.sendQueue.addToSendQueue(new C0DPacketCloseWindow(this.openContainer.windowId));
266
		this.func_175159_q();
267
	}
268
269
	public void func_175159_q() {
270
		this.inventory.setItemStack(null);
271
		super.closeScreen();
272
		this.mc.displayGuiScreen(null);
273
	}
274
275
	/**
276
	 * Updates health locally.
277
	 */
278
	public void setPlayerSPHealth(float p_71150_1_) {
279
		if (this.field_175169_bQ) {
280
			float var2 = this.getHealth() - p_71150_1_;
281
282
			if (var2 <= 0.0F) {
283
				this.setHealth(p_71150_1_);
284
285
				if (var2 < 0.0F) {
286
					this.hurtResistantTime = this.maxHurtResistantTime / 2;
287
				}
288
			} else {
289
				this.lastDamage = var2;
290
				this.setHealth(this.getHealth());
291
				this.hurtResistantTime = this.maxHurtResistantTime;
292
				this.damageEntity(DamageSource.generic, var2);
293
				this.hurtTime = this.maxHurtTime = 10;
294
			}
295
		} else {
296
			this.setHealth(p_71150_1_);
297
			this.field_175169_bQ = true;
298
		}
299
	}
300
301
	/**
302
	 * Adds a value to a statistic field.
303
	 */
304
	public void addStat(StatBase p_71064_1_, int p_71064_2_) {
305
		if (p_71064_1_ != null) {
306
			if (p_71064_1_.isIndependent) {
307
				super.addStat(p_71064_1_, p_71064_2_);
308
			}
309
		}
310
	}
311
312
	/**
313
	 * Sends the player's abilities to the server (if there is one).
314
	 */
315
	public void sendPlayerAbilities() {
316
		this.sendQueue.addToSendQueue(new C13PacketPlayerAbilities(this.capabilities));
317
	}
318
319
	public boolean func_175144_cb() {
320
		return true;
321
	}
322
323
	protected void sendHorseJump() {
324
		this.sendQueue.addToSendQueue(new C0BPacketEntityAction(this, C0BPacketEntityAction.Action.RIDING_JUMP,
325
				(int) (this.getHorseJumpPower() * 100.0F)));
326
	}
327
328
	public void func_175163_u() {
329
		this.sendQueue.addToSendQueue(new C0BPacketEntityAction(this, C0BPacketEntityAction.Action.OPEN_INVENTORY));
330
	}
331
332
	public void func_175158_f(String p_175158_1_) {
333
		this.clientBrand = p_175158_1_;
334
	}
335
336
	public String getClientBrand() {
337
		return this.clientBrand;
338
	}
339
340
	public StatFileWriter getStatFileWriter() {
341
		return this.field_146108_bO;
342
	}
343
344
	public void addChatComponentMessage(IChatComponent p_146105_1_) {
345
		this.mc.ingameGUI.getChatGUI().printChatMessage(p_146105_1_);
346
	}
347
348
	protected boolean pushOutOfBlocks(double x, double y, double z) {
349
		if (this.noClip) {
350
			return false;
351
		} else {
352
			BlockPos var7 = new BlockPos(x, y, z);
353
			double var8 = x - (double) var7.getX();
354
			double var10 = z - (double) var7.getZ();
355
356
			if (!this.func_175162_d(var7)) {
357
				byte var12 = -1;
358
				double var13 = 9999.0D;
359
360
				if (this.func_175162_d(var7.offsetWest()) && var8 < var13) {
361
					var13 = var8;
362
					var12 = 0;
363
				}
364
365
				if (this.func_175162_d(var7.offsetEast()) && 1.0D - var8 < var13) {
366
					var13 = 1.0D - var8;
367
					var12 = 1;
368
				}
369
370
				if (this.func_175162_d(var7.offsetNorth()) && var10 < var13) {
371
					var13 = var10;
372
					var12 = 4;
373
				}
374
375
				if (this.func_175162_d(var7.offsetSouth()) && 1.0D - var10 < var13) {
376
					var13 = 1.0D - var10;
377
					var12 = 5;
378
				}
379
380
				float var15 = 0.1F;
381
382
				if (var12 == 0) {
383
					this.motionX = -var15;
384
				}
385
386
				if (var12 == 1) {
387
					this.motionX = var15;
388
				}
389
390
				if (var12 == 4) {
391
					this.motionZ = -var15;
392
				}
393
394
				if (var12 == 5) {
395
					this.motionZ = var15;
396
				}
397
			}
398
399
			return false;
400
		}
401
	}
402
403
	private boolean func_175162_d(BlockPos p_175162_1_) {
404
		return !this.worldObj.getBlockState(p_175162_1_).getBlock().isNormalCube()
405
				&& !this.worldObj.getBlockState(p_175162_1_.offsetUp()).getBlock().isNormalCube();
406
	}
407
408
	/**
409
	 * Set sprinting switch for Entity.
410
	 */
411
	public void setSprinting(boolean sprinting) {
412
		super.setSprinting(sprinting);
413
		this.sprintingTicksLeft = sprinting ? 600 : 0;
414
	}
415
416
	/**
417
	 * Sets the current XP, total XP, and level number.
418
	 */
419
	public void setXPStats(float p_71152_1_, int p_71152_2_, int p_71152_3_) {
420
		this.experience = p_71152_1_;
421
		this.experienceTotal = p_71152_2_;
422
		this.experienceLevel = p_71152_3_;
423
	}
424
425
	/**
426
	 * Notifies this sender of some sort of information. This is for messages
427
	 * intended to display to the user. Used for typical output (like "you asked for
428
	 * whether or not this game rule is set, so here's your answer"), warnings (like
429
	 * "I fetched this block for you by ID, but I'd like you to know that every time
430
	 * you do this, I die a little inside"), and errors (like "it's not called
431
	 * iron_pixacke, silly").
432
	 */
433
	public void addChatMessage(IChatComponent message) {
434
		this.mc.ingameGUI.getChatGUI().printChatMessage(message);
435
	}
436
437
	/**
438
	 * Returns true if the command sender is allowed to use the given command.
439
	 */
440
	public boolean canCommandSenderUseCommand(int permissionLevel, String command) {
441
		return permissionLevel <= 0;
442
	}
443
444
	public BlockPos getPosition() {
445
		return new BlockPos(this.posX + 0.5D, this.posY + 0.5D, this.posZ + 0.5D);
446
	}
447
448
	public void playSound(String name, float volume, float pitch) {
449
		this.worldObj.playSound(this.posX, this.posY, this.posZ, name, volume, pitch, false);
450
	}
451
452
	/**
453
	 * Returns whether the entity is in a server world
454
	 */
455
	public boolean isServerWorld() {
456
		return true;
457
	}
458
459
	public boolean isRidingHorse() {
460
		return this.ridingEntity != null && this.ridingEntity instanceof EntityHorse
461
				&& ((EntityHorse) this.ridingEntity).isHorseSaddled();
462
	}
463
464
	public float getHorseJumpPower() {
465
		return this.horseJumpPower;
466
	}
467
468
	public void func_175141_a(TileEntitySign p_175141_1_) {
469
		this.mc.displayGuiScreen(new GuiEditSign(p_175141_1_));
470
	}
471
472
	public void func_146095_a(CommandBlockLogic p_146095_1_) {
473
		this.mc.displayGuiScreen(new GuiCommandBlock(p_146095_1_));
474
	}
475
476
	/**
477
	 * Displays the GUI for interacting with a book.
478
	 */
479
	public void displayGUIBook(ItemStack bookStack) {
480
		Item var2 = bookStack.getItem();
481
482
		if (var2 == Items.writable_book) {
483
			this.mc.displayGuiScreen(new GuiScreenBook(this, bookStack, true));
484
		}
485
	}
486
487
	/**
488
	 * Displays the GUI for interacting with a chest inventory. Args: chestInventory
489
	 */
490
	public void displayGUIChest(IInventory chestInventory) {
491
		String var2 = chestInventory instanceof IInteractionObject ? ((IInteractionObject) chestInventory).getGuiID()
492
				: "minecraft:container";
493
494
		if ("minecraft:chest".equals(var2)) {
495
			this.mc.displayGuiScreen(new GuiChest(this.inventory, chestInventory));
496
		} else if ("minecraft:hopper".equals(var2)) {
497
			this.mc.displayGuiScreen(new GuiHopper(this.inventory, chestInventory));
498
		} else if ("minecraft:furnace".equals(var2)) {
499
			this.mc.displayGuiScreen(new GuiFurnace(this.inventory, chestInventory));
500
		} else if ("minecraft:brewing_stand".equals(var2)) {
501
			this.mc.displayGuiScreen(new GuiBrewingStand(this.inventory, chestInventory));
502
		} else if ("minecraft:beacon".equals(var2)) {
503
			this.mc.displayGuiScreen(new GuiBeacon(this.inventory, chestInventory));
504
		} else if (!"minecraft:dispenser".equals(var2) && !"minecraft:dropper".equals(var2)) {
505
			this.mc.displayGuiScreen(new GuiChest(this.inventory, chestInventory));
506
		} else {
507
			this.mc.displayGuiScreen(new GuiDispenser(this.inventory, chestInventory));
508
		}
509
	}
510
511
	public void displayGUIHorse(EntityHorse p_110298_1_, IInventory p_110298_2_) {
512
		this.mc.displayGuiScreen(new GuiScreenHorseInventory(this.inventory, p_110298_2_, p_110298_1_));
513
	}
514
515
	public void displayGui(IInteractionObject guiOwner) {
516
		String var2 = guiOwner.getGuiID();
517
518
		if ("minecraft:crafting_table".equals(var2)) {
519
			this.mc.displayGuiScreen(new GuiCrafting(this.inventory, this.worldObj));
520
		} else if ("minecraft:enchanting_table".equals(var2)) {
521
			this.mc.displayGuiScreen(new GuiEnchantment(this.inventory, this.worldObj, guiOwner));
522
		} else if ("minecraft:anvil".equals(var2)) {
523
			this.mc.displayGuiScreen(new GuiRepair(this.inventory, this.worldObj));
524
		}
525
	}
526
527
	public void displayVillagerTradeGui(IMerchant villager) {
528
		this.mc.displayGuiScreen(new GuiMerchant(this.inventory, villager, this.worldObj));
529
	}
530
531
	/**
532
	 * Called when the player performs a critical hit on the Entity. Args: entity
533
	 * that was hit critically
534
	 */
535
	public void onCriticalHit(Entity p_71009_1_) {
536
		this.mc.effectRenderer.func_178926_a(p_71009_1_, EnumParticleTypes.CRIT);
537
	}
538
539
	public void onEnchantmentCritical(Entity p_71047_1_) {
540
		this.mc.effectRenderer.func_178926_a(p_71047_1_, EnumParticleTypes.CRIT_MAGIC);
541
	}
542
543
	/**
544
	 * Returns if this entity is sneaking.
545
	 */
546
	public boolean isSneaking() {
547
		boolean var1 = this.movementInput != null && this.movementInput.isSneaking();
548
		return var1 && !this.sleeping;
549
	}
550
551
	public void updateEntityActionState() {
552
		super.updateEntityActionState();
553
554
		if (this.func_175160_A()) {
555
			this.moveStrafing = this.movementInput.getStrafe();
556
			this.moveForward = this.movementInput.getForward();
557
			this.isJumping = this.movementInput.isJumping();
558
			this.prevRenderArmYaw = this.renderArmYaw;
559
			this.prevRenderArmPitch = this.renderArmPitch;
560
			this.renderArmPitch = (float) ((double) this.renderArmPitch
561
					+ (double) (this.rotationPitch - this.renderArmPitch) * 0.5D);
562
			this.renderArmYaw = (float) ((double) this.renderArmYaw
563
					+ (double) (this.rotationYaw - this.renderArmYaw) * 0.5D);
564
		}
565
	}
566
567
	protected boolean func_175160_A() {
568
		return this.mc.func_175606_aa() == this;
569
	}
570
571
	/**
572
	 * Called frequently so the entity can update its state every tick as required.
573
	 * For example, zombies and skeletons use this to react to sunlight and start to
574
	 * burn.
575
	 */
576
	public void onLivingUpdate() {
577
		if (this.sprintingTicksLeft > 0) {
578
			--this.sprintingTicksLeft;
579
580
			if (this.sprintingTicksLeft == 0) {
581
				this.setSprinting(false);
582
			}
583
		}
584
585
		if (this.sprintToggleTimer > 0) {
586
			--this.sprintToggleTimer;
587
		}
588
589
		this.prevTimeInPortal = this.timeInPortal;
590
591
		if (this.inPortal) {
592
			if (this.mc.currentScreen != null && !this.mc.currentScreen.doesGuiPauseGame()) {
593
				this.mc.displayGuiScreen(null);
594
			}
595
596
			if (this.timeInPortal == 0.0F) {
597
				this.mc.getSoundHandler().playSound(PositionedSoundRecord.createPositionedSoundRecord(
598
						new ResourceLocation("portal.trigger"), this.rand.nextFloat() * 0.4F + 0.8F));
599
			}
600
601
			this.timeInPortal += 0.0125F;
602
603
			if (this.timeInPortal >= 1.0F) {
604
				this.timeInPortal = 1.0F;
605
			}
606
607
			this.inPortal = false;
608
		} else if (this.isPotionActive(Potion.confusion)
609
				&& this.getActivePotionEffect(Potion.confusion).getDuration() > 60) {
610
			this.timeInPortal += 0.006666667F;
611
612
			if (this.timeInPortal > 1.0F) {
613
				this.timeInPortal = 1.0F;
614
			}
615
		} else {
616
			if (this.timeInPortal > 0.0F) {
617
				this.timeInPortal -= 0.05F;
618
			}
619
620
			if (this.timeInPortal < 0.0F) {
621
				this.timeInPortal = 0.0F;
622
			}
623
		}
624
625
		if (this.timeUntilPortal > 0) {
626
			--this.timeUntilPortal;
627
		}
628
629
		boolean var1 = this.movementInput.isJumping();
630
		boolean var2 = this.movementInput.isSneaking();
631
		float var3 = 0.8F;
632
		boolean var4 = this.movementInput.getForward() >= var3;
633
		this.movementInput.updatePlayerMoveState();
634
		boolean cancel = Module.getInstance(NoSlow.class).isToggled();
635
		if (this.isUsingItem() && !cancel && !this.isRiding()) {
636
			this.movementInput.setStrafe(this.movementInput.getStrafe() * 0.2F);
637
			this.movementInput.setForward(this.movementInput.getForward() * 0.2F);
638
			this.sprintToggleTimer = 0;
639
		}
640
641
		this.pushOutOfBlocks(this.posX - (double) this.width * 0.35D, this.getEntityBoundingBox().minY + 0.5D,
642
				this.posZ + (double) this.width * 0.35D);
643
		this.pushOutOfBlocks(this.posX - (double) this.width * 0.35D, this.getEntityBoundingBox().minY + 0.5D,
644
				this.posZ - (double) this.width * 0.35D);
645
		this.pushOutOfBlocks(this.posX + (double) this.width * 0.35D, this.getEntityBoundingBox().minY + 0.5D,
646
				this.posZ - (double) this.width * 0.35D);
647
		this.pushOutOfBlocks(this.posX + (double) this.width * 0.35D, this.getEntityBoundingBox().minY + 0.5D,
648
				this.posZ + (double) this.width * 0.35D);
649
		boolean var5 = (float) this.getFoodStats().getFoodLevel() > 6.0F || this.capabilities.allowFlying;
650
651
		if (this.onGround && !var2 && !var4 && this.movementInput.getForward() >= var3 && !this.isSprinting() && var5
652
				&& !this.isUsingItem() && !this.isPotionActive(Potion.blindness)) {
653
			if (this.sprintToggleTimer <= 0 && !this.mc.gameSettings.keyBindSprint.getIsKeyPressed()) {
654
				this.sprintToggleTimer = 7;
655
			} else {
656
				this.setSprinting(true);
657
			}
658
		}
659
660
		if (!this.isSprinting() && this.movementInput.getForward() >= var3 && var5 && !this.isUsingItem()
661
				&& !this.isPotionActive(Potion.blindness) && this.mc.gameSettings.keyBindSprint.getIsKeyPressed()) {
662
			this.setSprinting(true);
663
		}
664
665
		if (this.isSprinting() && (this.movementInput.getForward() < var3 || this.isCollidedHorizontally || !var5)) {
666
			this.setSprinting(false);
667
		}
668
669
		if (this.capabilities.allowFlying) {
670
			if (this.mc.playerController.isSpectatorMode()) {
671
				if (!this.capabilities.isFlying) {
672
					this.capabilities.isFlying = true;
673
					this.sendPlayerAbilities();
674
				}
675
			} else if (!var1 && this.movementInput.isJumping()) {
676
				if (this.flyToggleTimer == 0) {
677
					this.flyToggleTimer = 7;
678
				} else {
679
					this.capabilities.isFlying = !this.capabilities.isFlying;
680
					this.sendPlayerAbilities();
681
					this.flyToggleTimer = 0;
682
				}
683
			}
684
		}
685
686
		if (this.capabilities.isFlying && this.func_175160_A()) {
687
			if (this.movementInput.isSneaking()) {
688
				this.motionY -= this.capabilities.getFlySpeed() * 3.0F;
689
			}
690
691
			if (this.movementInput.isJumping()) {
692
				this.motionY += this.capabilities.getFlySpeed() * 3.0F;
693
			}
694
		}
695
696
		if (this.isRidingHorse()) {
697
			if (this.horseJumpPowerCounter < 0) {
698
				++this.horseJumpPowerCounter;
699
700
				if (this.horseJumpPowerCounter == 0) {
701
					this.horseJumpPower = 0.0F;
702
				}
703
			}
704
705
			if (var1 && !this.movementInput.isJumping()) {
706
				this.horseJumpPowerCounter = -10;
707
				this.sendHorseJump();
708
			} else if (!var1 && this.movementInput.isJumping()) {
709
				this.horseJumpPowerCounter = 0;
710
				this.horseJumpPower = 0.0F;
711
			} else if (var1) {
712
				++this.horseJumpPowerCounter;
713
714
				if (this.horseJumpPowerCounter < 10) {
715
					this.horseJumpPower = (float) this.horseJumpPowerCounter * 0.1F;
716
				} else {
717
					this.horseJumpPower = 0.8F + 2.0F / (float) (this.horseJumpPowerCounter - 9) * 0.1F;
718
				}
719
			}
720
		} else {
721
			this.horseJumpPower = 0.0F;
722
		}
723
724
		super.onLivingUpdate();
725
726
		if (this.onGround && this.capabilities.isFlying && !this.mc.playerController.isSpectatorMode()) {
727
			this.capabilities.isFlying = false;
728
			this.sendPlayerAbilities();
729
		}
730
	}
731
732
	public boolean isMoving() {
733
		return (TargetStrafe.canStrafe() ? TargetStrafe.dir != 0 : false)
734
				|| (this.movementInput.getForward() != 0 || this.movementInput.getStrafe() != 0);
735
	}
736
737
	public boolean isMovingOnGround() {
738
		return this.isMoving() && this.onGround;
739
	}
740
}

What this file does

The fork-modified movement code is where the actual speed gain lives. onLivingUpdate line 634 reads boolean cancel = Module.getInstance(NoSlow.class).isToggled(), and lines 635-639 apply the vanilla 0.2F strafe/forward multiplier and the sprintToggleTimer reset only when !cancel. With the module toggled, blocking no longer scales movement input and sprint is no longer suppressed by isUsingItem, so the client generates full-speed movement packets while holding a block. This file is the reason the packet handler alone is not the whole module.

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 detection

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

NCP's UseItemAdapter intercepts C07 and timestamps every RELEASE_USE_ITEM (lines 412-425): when a new release arrives less than timeBetweenRL (default 70ms, line 128) after the previous one, it sets CombinedData.isHackingRI. The NCP mode's releases land 50ms apart, so every release after the first marks the player; SurvivalFly consumes the flag (line 877) by tagging the move 'noslowpacket' and running Improbable.check on the horizontal distance (line 880), so the full-speed sprint the re-arm cycle enables is scored against NCP's statistical speed model instead of the vanilla slowdown. This is the direct counter to the packet layer: the module removes the slowdown, and the release-gap detector fingerprints exactly that removal.

anticheat NoSlow (blocking while sprinting)

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

BetterAnticheat's NoSlowCheck tracks USE_ITEM (blocking = true), ENTITY_ACTION START_SPRINTING (sprinting = true) and fails when a RELEASE_USE_ITEM arrives with both flags set (lines 39-47), resetting blocking after each release. That is precisely the module's state: the EntityPlayerSP hook keeps sprint active while the block is armed, and the per-tick release lands mid-sprint, so the first release trips the check. The check ships in the 'broken' package with a comment admitting unexplainable false positives, so servers may keep it disabled; when enabled, the module's own wire pattern is the textbook trigger.

anticheat Speed (release-item-over-VL force release)

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 predicts the horizontal position from the previous move and compares it against the actual update; on a discrepancy beyond its threshold it punishes and rubber-bands, and its releaseItemOverVl setting (default 4, line 80) then forces the item to release (lines 213-214) when the flagged player is pulling a bow, consuming or blocking. The module's whole effect is sprint-speed movement while blocking, so a blocked sprint that accumulates speed VL triggers the forced release, which tears the re-arm loop down: the client is made to emit a genuine RELEASE_USE_ITEM that the module did not schedule, and the server-side use state desyncs.

anticheat RepeatedRelease (release without a 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

RepeatedReleaseCheck flags any RELEASE_USE_ITEM that arrives without an intervening USE_ITEM (lines 48-52), on the model that every release must be preceded by a use. Two facts blunt it against this module: it is disabled in the shipped tree due to false flags (lines 12-14), and the module re-arms with a use-item C08 after each release, so every release in the stream is preceded by a use and the predicate never fires even when enabled. It is included as the boundary case: the check family exists precisely because per-tick release streams are the NoSlow signature, but this implementation's own 1.8 item semantics leave the pattern uncaught.

← Back to Analysis Hub