mirror of
https://github.com/xiaozhou233/OrangeX-Client.git
synced 2026-12-05 13:05:52 +08:00
Merge pull request #6 from xiaozhou233/feat/autoclicker
Feat/autoclicker
This commit is contained in:
commit
e40d4831d0
6 files changed
+207
No files matched your search
@@ -4,6 +4,7 @@ import cn.xiaozhou233.orangex.alts.AltManager;
|
||||
import cn.xiaozhou233.orangex.config.ConfigManager;
|
||||
import cn.xiaozhou233.orangex.font.FontManager;
|
||||
import cn.xiaozhou233.orangex.manager.ResourceManager;
|
||||
import cn.xiaozhou233.orangex.manager.ThreadManager;
|
||||
import cn.xiaozhou233.orangex.mixin.MixinManager;
|
||||
import cn.xiaozhou233.orangex.module.ModuleManager;
|
||||
import lombok.Getter;
|
||||
@@ -28,6 +29,7 @@ public class OrangeX {
|
||||
private final ModuleManager moduleManager = new ModuleManager();
|
||||
private FontManager fontManager;
|
||||
private final AltManager altManager = new AltManager();
|
||||
private final ThreadManager threadManager = new ThreadManager();
|
||||
|
||||
public OrangeX() {
|
||||
}
|
||||
@@ -39,6 +41,7 @@ public class OrangeX {
|
||||
moduleManager.init();
|
||||
configManager.loadConfig();
|
||||
altManager.init();
|
||||
threadManager.init();
|
||||
mixinManager.start();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
package cn.xiaozhou233.orangex.event.impl;
|
||||
|
||||
public class EventTimerThread {
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package cn.xiaozhou233.orangex.manager;
|
||||
|
||||
import cn.xiaozhou233.orangex.OrangeX;
|
||||
import cn.xiaozhou233.orangex.event.impl.EventTimerThread;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public class ThreadManager {
|
||||
|
||||
private Thread timerThread;
|
||||
private volatile boolean running = false;
|
||||
|
||||
private static final long TIMER_INTERVAL_MS = 10L;
|
||||
|
||||
public void init() {
|
||||
if (running) {
|
||||
return;
|
||||
}
|
||||
|
||||
running = true;
|
||||
|
||||
timerThread = new Thread(() -> {
|
||||
while (running && !Thread.currentThread().isInterrupted()) {
|
||||
OrangeX.getInstance()
|
||||
.getEventBus()
|
||||
.post(new EventTimerThread());
|
||||
|
||||
try {
|
||||
Thread.sleep(TIMER_INTERVAL_MS);
|
||||
} catch (InterruptedException e) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}, "OrangeX-Timer");
|
||||
|
||||
timerThread.start();
|
||||
|
||||
Runtime.getRuntime().addShutdownHook(
|
||||
new Thread(this::shutdown, "OrangeX-Timer-Shutdown")
|
||||
);
|
||||
}
|
||||
|
||||
public void shutdown() {
|
||||
running = false;
|
||||
if (timerThread != null) {
|
||||
timerThread.interrupt();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package cn.xiaozhou233.orangex.module;
|
||||
|
||||
import cn.xiaozhou233.orangex.OrangeX;
|
||||
import cn.xiaozhou233.orangex.event.impl.EventKey;
|
||||
import cn.xiaozhou233.orangex.module.impl.combat.AutoClicker;
|
||||
import cn.xiaozhou233.orangex.module.impl.fun.Derp;
|
||||
import cn.xiaozhou233.orangex.module.impl.misc.Test;
|
||||
import cn.xiaozhou233.orangex.module.impl.movement.NoJumpDelay;
|
||||
@@ -34,6 +35,8 @@ public class ModuleManager {
|
||||
register(new Derp());
|
||||
|
||||
register(new NoJumpDelay());
|
||||
|
||||
register(new AutoClicker());
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
package cn.xiaozhou233.orangex.module.impl.combat;
|
||||
|
||||
import cn.xiaozhou233.orangex.event.impl.EventTimerThread;
|
||||
import cn.xiaozhou233.orangex.module.Module;
|
||||
import cn.xiaozhou233.orangex.module.ModuleCategory;
|
||||
import cn.xiaozhou233.orangex.module.value.NumberValue;
|
||||
import net.minecraft.client.settings.KeyBinding;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.lwjgl.input.Mouse;
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Deque;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class AutoClicker extends Module {
|
||||
|
||||
private final ScheduledExecutorService CLICK_EXECUTOR =
|
||||
Executors.newSingleThreadScheduledExecutor(r -> new Thread(r, "OrangeX-ClickThread"));
|
||||
|
||||
private final Random random = new Random();
|
||||
|
||||
private long lastClickTime = System.currentTimeMillis();
|
||||
private long delayMs = 100;
|
||||
|
||||
private final Deque<Double> intervalTicks = new ArrayDeque<>();
|
||||
private static final int HISTORY = 100;
|
||||
|
||||
private final NumberValue cps =
|
||||
new NumberValue("CPS", "Clicks per second", 8d, 1, 20, 0.1);
|
||||
|
||||
public AutoClicker() {
|
||||
super("AutoClicker", ModuleCategory.COMBAT);
|
||||
addValue(cps);
|
||||
}
|
||||
|
||||
private double getStdDev() {
|
||||
if (intervalTicks.size() < 5) return 1.0;
|
||||
|
||||
double sum = 0;
|
||||
for (double v : intervalTicks) sum += v;
|
||||
double mean = sum / intervalTicks.size();
|
||||
|
||||
double var = 0;
|
||||
for (double v : intervalTicks) var += (v - mean) * (v - mean);
|
||||
var /= intervalTicks.size();
|
||||
|
||||
return Math.sqrt(var);
|
||||
}
|
||||
|
||||
private long generateDelayMs() {
|
||||
double target = cps.getValue();
|
||||
double meanMs = 1000.0 / target;
|
||||
|
||||
// 双峰:更快 / 更慢
|
||||
double shortDelay = meanMs * (0.65 + random.nextDouble() * 0.15); // 0.65~0.8 倍
|
||||
double longDelay = meanMs * (1.25 + random.nextDouble() * 0.35); // 1.25~1.6 倍
|
||||
|
||||
// 计算 stdDev
|
||||
double stdDev = getStdDev();
|
||||
|
||||
// 10% 极端值
|
||||
if (random.nextDouble() < 0.1) {
|
||||
if (random.nextBoolean()) {
|
||||
return Math.max(1, (long) (meanMs * (0.35 + random.nextDouble() * 0.25)));
|
||||
} else {
|
||||
return Math.max(1, (long) (meanMs * (1.7 + random.nextDouble() * 0.8)));
|
||||
}
|
||||
}
|
||||
|
||||
// 如果 stdDev < 1,则强制“极端化”
|
||||
if (stdDev < 1.0) {
|
||||
if (random.nextBoolean()) {
|
||||
return Math.max(1, (long) (meanMs * (0.35 + random.nextDouble() * 0.25)));
|
||||
} else {
|
||||
return Math.max(1, (long) (meanMs * (1.7 + random.nextDouble() * 0.8)));
|
||||
}
|
||||
}
|
||||
|
||||
// 这里是关键:让“短间隔出现概率更高”,保证平均 CPS 不下降
|
||||
// 例如:短间隔 70% / 长间隔 30%
|
||||
boolean pickShort = random.nextDouble() < 0.7;
|
||||
return Math.max(1, (long) (pickShort ? shortDelay : longDelay));
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onTimer(EventTimerThread event) {
|
||||
if (mc.theWorld == null) return;
|
||||
if (!Mouse.isButtonDown(0)) return;
|
||||
|
||||
long now = System.currentTimeMillis();
|
||||
if (now - lastClickTime < delayMs) return;
|
||||
|
||||
int keyCode = mc.gameSettings.keyBindAttack.getKeyCode();
|
||||
KeyBinding.setKeyBindState(keyCode, true);
|
||||
KeyBinding.onTick(keyCode);
|
||||
|
||||
CLICK_EXECUTOR.schedule(() -> {
|
||||
KeyBinding.setKeyBindState(keyCode, false);
|
||||
}, 1 + random.nextInt(10), TimeUnit.MILLISECONDS);
|
||||
|
||||
double intervalMs = now - lastClickTime;
|
||||
double intervalTick = intervalMs / 50.0;
|
||||
|
||||
intervalTicks.addLast(intervalTick);
|
||||
if (intervalTicks.size() > HISTORY) intervalTicks.removeFirst();
|
||||
|
||||
lastClickTime = now;
|
||||
delayMs = generateDelayMs();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDisable() {
|
||||
CLICK_EXECUTOR.shutdownNow();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package cn.xiaozhou233.orangex.utils;
|
||||
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public class MathUtil {
|
||||
|
||||
private static final int MAX_ATTEMPTS = 8;
|
||||
|
||||
public static double generateNoise(double min, double max) {
|
||||
double mean = (min + max) / 2.0;
|
||||
double range = max - min;
|
||||
double stdDev = Math.max(1.0, range / 3.0);
|
||||
|
||||
ThreadLocalRandom random = ThreadLocalRandom.current();
|
||||
|
||||
for (int i = 0; i < MAX_ATTEMPTS; i++) {
|
||||
double value = random.nextGaussian() * stdDev + mean;
|
||||
if (value >= min && value <= max) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
// fallback: clamp gaussian
|
||||
return clamp(random.nextGaussian() * stdDev + mean, min, max);
|
||||
}
|
||||
|
||||
public static double clamp(double value, double min, double max) {
|
||||
return Math.max(min, Math.min(max, value));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user