From c3312772108cf6cd4eb3063a10c60b630b8d15f7 Mon Sep 17 00:00:00 2001 From: Alexander01998 Date: Tue, 28 May 2024 14:15:29 +0200 Subject: [PATCH] Fix TriggerBot detection Fixes #997 --- .../events/HandleInputListener.java | 49 +++++++++++++++++++ .../net/wurstclient/hacks/TriggerBotHack.java | 24 ++++++--- .../mixin/MinecraftClientMixin.java | 7 +++ .../settings/AttackSpeedSliderSetting.java | 36 ++++++++++++-- 4 files changed, 104 insertions(+), 12 deletions(-) create mode 100644 src/main/java/net/wurstclient/events/HandleInputListener.java diff --git a/src/main/java/net/wurstclient/events/HandleInputListener.java b/src/main/java/net/wurstclient/events/HandleInputListener.java new file mode 100644 index 00000000..bc0955ac --- /dev/null +++ b/src/main/java/net/wurstclient/events/HandleInputListener.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2014-2024 Wurst-Imperium and contributors. + * + * This source code is subject to the terms of the GNU General Public + * License, version 3. If a copy of the GPL was not distributed with this + * file, You can obtain one at: https://www.gnu.org/licenses/gpl-3.0.txt + */ +package net.wurstclient.events; + +import java.util.ArrayList; + +import net.minecraft.client.MinecraftClient; +import net.wurstclient.event.Event; +import net.wurstclient.event.Listener; + +/** + * Fired at the beginning of {@link MinecraftClient#handleInputEvents()}. + * This is the ideal time to simulate mouse and keyboard input. + */ +public interface HandleInputListener extends Listener +{ + /** + * Fired at the beginning of {@link MinecraftClient#handleInputEvents()}. + * This is the ideal time to simulate mouse and keyboard input. + */ + public void onHandleInput(); + + /** + * Fired at the beginning of {@link MinecraftClient#handleInputEvents()}. + * This is the ideal time to simulate mouse and keyboard input. + */ + public static class HandleInputEvent extends Event + { + public static final HandleInputEvent INSTANCE = new HandleInputEvent(); + + @Override + public void fire(ArrayList listeners) + { + for(HandleInputListener listener : listeners) + listener.onHandleInput(); + } + + @Override + public Class getListenerType() + { + return HandleInputListener.class; + } + } +} diff --git a/src/main/java/net/wurstclient/hacks/TriggerBotHack.java b/src/main/java/net/wurstclient/hacks/TriggerBotHack.java index 7cb096a5..2c3b66e9 100644 --- a/src/main/java/net/wurstclient/hacks/TriggerBotHack.java +++ b/src/main/java/net/wurstclient/hacks/TriggerBotHack.java @@ -14,7 +14,7 @@ import net.minecraft.util.Hand; import net.minecraft.util.hit.EntityHitResult; import net.wurstclient.Category; import net.wurstclient.SearchTags; -import net.wurstclient.events.PostMotionListener; +import net.wurstclient.events.HandleInputListener; import net.wurstclient.events.PreMotionListener; import net.wurstclient.hack.Hack; import net.wurstclient.mixinterface.IKeyBinding; @@ -30,7 +30,7 @@ import net.wurstclient.util.EntityUtils; @SearchTags({"trigger bot", "AutoAttack", "auto attack", "AutoClicker", "auto clicker"}) public final class TriggerBotHack extends Hack - implements PreMotionListener, PostMotionListener + implements PreMotionListener, HandleInputListener { private final SliderSetting range = new SliderSetting("Range", 4.25, 1, 6, 0.05, ValueDisplay.DECIMAL); @@ -38,6 +38,15 @@ public final class TriggerBotHack extends Hack private final AttackSpeedSliderSetting speed = new AttackSpeedSliderSetting(); + private final SliderSetting speedRandMS = + new SliderSetting("Speed randomization", + "Helps you bypass anti-cheat plugins by varying the delay between" + + " attacks.\n\n" + "\u00b1100ms is recommended for Vulcan.\n\n" + + "0 (off) is fine for NoCheat+, AAC, Grim, Verus, Spartan, and" + + " vanilla servers.", + 100, 0, 1000, 50, ValueDisplay.INTEGER.withPrefix("\u00b1") + .withSuffix("ms").withLabel(0, "off")); + private final SwingHandSetting swingHand = new SwingHandSetting( "How TriggerBot should swing your hand when attacking.\n\n" + "This setting will be ignored if \"Simulate mouse click\" is" @@ -75,6 +84,7 @@ public final class TriggerBotHack extends Hack addSetting(range); addSetting(speed); + addSetting(speedRandMS); addSetting(swingHand); addSetting(attackWhileBlocking); addSetting(simulateMouseClick); @@ -95,9 +105,9 @@ public final class TriggerBotHack extends Hack WURST.getHax().protectHack.setEnabled(false); WURST.getHax().tpAuraHack.setEnabled(false); - speed.resetTimer(); + speed.resetTimer(speedRandMS.getValue()); EVENTS.add(PreMotionListener.class, this); - EVENTS.add(PostMotionListener.class, this); + EVENTS.add(HandleInputListener.class, this); } @Override @@ -110,7 +120,7 @@ public final class TriggerBotHack extends Hack } EVENTS.remove(PreMotionListener.class, this); - EVENTS.remove(PostMotionListener.class, this); + EVENTS.remove(HandleInputListener.class, this); } @Override @@ -124,7 +134,7 @@ public final class TriggerBotHack extends Hack } @Override - public void onPostMotion() + public void onHandleInput() { speed.updateTimer(); if(!speed.isTimeToAttack()) @@ -160,7 +170,7 @@ public final class TriggerBotHack extends Hack swingHand.swing(Hand.MAIN_HAND); } - speed.resetTimer(); + speed.resetTimer(speedRandMS.getValue()); } private boolean isCorrectEntity(Entity entity) diff --git a/src/main/java/net/wurstclient/mixin/MinecraftClientMixin.java b/src/main/java/net/wurstclient/mixin/MinecraftClientMixin.java index 20f8eb02..f062a860 100644 --- a/src/main/java/net/wurstclient/mixin/MinecraftClientMixin.java +++ b/src/main/java/net/wurstclient/mixin/MinecraftClientMixin.java @@ -34,6 +34,7 @@ import net.minecraft.util.hit.HitResult; import net.minecraft.util.thread.ReentrantThreadExecutor; import net.wurstclient.WurstClient; import net.wurstclient.event.EventManager; +import net.wurstclient.events.HandleInputListener.HandleInputEvent; import net.wurstclient.events.LeftClickListener.LeftClickEvent; import net.wurstclient.events.RightClickListener.RightClickEvent; import net.wurstclient.mixinterface.IClientPlayerEntity; @@ -64,6 +65,12 @@ public abstract class MinecraftClientMixin super(name); } + @Inject(at = @At("HEAD"), method = "handleInputEvents()V") + private void onHandleInputEvents(CallbackInfo ci) + { + EventManager.fire(HandleInputEvent.INSTANCE); + } + @Inject(at = @At(value = "FIELD", target = "Lnet/minecraft/client/MinecraftClient;crosshairTarget:Lnet/minecraft/util/hit/HitResult;", ordinal = 0), method = "doAttack()Z", cancellable = true) diff --git a/src/main/java/net/wurstclient/settings/AttackSpeedSliderSetting.java b/src/main/java/net/wurstclient/settings/AttackSpeedSliderSetting.java index c1653bf7..5faae8cf 100644 --- a/src/main/java/net/wurstclient/settings/AttackSpeedSliderSetting.java +++ b/src/main/java/net/wurstclient/settings/AttackSpeedSliderSetting.java @@ -7,10 +7,12 @@ */ package net.wurstclient.settings; +import net.minecraft.util.math.random.Random; import net.wurstclient.WurstClient; public final class AttackSpeedSliderSetting extends SliderSetting { + private final Random random = Random.createLocal(); private int tickTimer; public AttackSpeedSliderSetting() @@ -35,19 +37,43 @@ public final class AttackSpeedSliderSetting extends SliderSetting public void resetTimer() { - tickTimer = 0; + double value = getValue(); + if(value <= 0) + tickTimer = -1; + else + tickTimer = (int)(1000 / value); + } + + public void resetTimer(double maxRandMS) + { + if(maxRandMS <= 0) + { + resetTimer(); + return; + } + + double value = getValue(); + double rand = random.nextGaussian(); + int randOffset = (int)(rand * maxRandMS); + + if(value <= 0) + tickTimer = randOffset; + else + tickTimer = (int)(1000 / value) + randOffset; } public void updateTimer() { - tickTimer += 50; + if(tickTimer >= 0) + tickTimer -= 50; } public boolean isTimeToAttack() { - if(getValue() > 0) - return tickTimer >= 1000 / getValue(); + double value = getValue(); + if(value <= 0 && WurstClient.MC.player.getAttackCooldownProgress(0) < 1) + return false; - return WurstClient.MC.player.getAttackCooldownProgress(0) >= 1; + return tickTimer <= 0; } }