Skip to content

Commit

Permalink
improve anti afk (MeteorDevelopment#4033)
Browse files Browse the repository at this point in the history
  • Loading branch information
RacoonDog authored Sep 2, 2023
1 parent 7d4645a commit 3af641e
Showing 1 changed file with 123 additions and 183 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,96 +6,57 @@
package meteordevelopment.meteorclient.systems.modules.movement;

import meteordevelopment.meteorclient.events.world.TickEvent;
import meteordevelopment.meteorclient.gui.GuiTheme;
import meteordevelopment.meteorclient.gui.widgets.WWidget;
import meteordevelopment.meteorclient.gui.widgets.containers.WTable;
import meteordevelopment.meteorclient.gui.widgets.input.WTextBox;
import meteordevelopment.meteorclient.gui.widgets.pressable.WMinus;
import meteordevelopment.meteorclient.gui.widgets.pressable.WPlus;
import meteordevelopment.meteorclient.settings.*;
import meteordevelopment.meteorclient.systems.modules.Categories;
import meteordevelopment.meteorclient.systems.modules.Module;
import meteordevelopment.meteorclient.utils.Utils;
import meteordevelopment.meteorclient.utils.player.ChatUtils;
import meteordevelopment.meteorclient.utils.player.Rotations;
import meteordevelopment.orbit.EventHandler;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtElement;
import net.minecraft.nbt.NbtList;
import net.minecraft.nbt.NbtString;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class AntiAFK extends Module {
public enum SpinMode {
Server,
Client
}

private final SettingGroup sgActions = settings.createGroup("Actions");
private final SettingGroup sgMessages = settings.createGroup("Messages");

// Actions

private final Setting<Boolean> spin = sgActions.add(new BoolSetting.Builder()
.name("spin")
.description("Spins.")
.defaultValue(true)
.build()
);

private final Setting<SpinMode> spinMode = sgActions.add(new EnumSetting.Builder<SpinMode>()
.name("spin-mode")
.description("The method of rotating.")
.defaultValue(SpinMode.Server)
.visible(spin::get)
.build()
);

private final Setting<Integer> spinSpeed = sgActions.add(new IntSetting.Builder()
.name("spin-speed")
.description("The speed to spin you.")
.defaultValue(7)
.visible(spin::get)
.build()
);

private final Setting<Double> pitch = sgActions.add(new DoubleSetting.Builder()
.name("pitch")
.description("The pitch to set in server mode.")
.defaultValue(-90)
.range(-90, 90)
.sliderRange(-90, 90)
.visible(() -> spin.get() && spinMode.get() == SpinMode.Server)
.build()
);

private final Setting<Boolean> jump = sgActions.add(new BoolSetting.Builder()
.name("jump")
.description("Jumps.")
.description("Jump randomly.")
.defaultValue(true)
.build()
);

private final Setting<Boolean> click = sgActions.add(new BoolSetting.Builder()
.name("click")
.description("Clicks.")
private final Setting<Boolean> swing = sgActions.add(new BoolSetting.Builder()
.name("swing")
.description("Swings your hand.")
.defaultValue(false)
.build()
);

private final Setting<Boolean> disco = sgActions.add(new BoolSetting.Builder()
.name("disco")
private final Setting<Boolean> sneak = sgActions.add(new BoolSetting.Builder()
.name("sneak")
.description("Sneaks and unsneaks quickly.")
.defaultValue(false)
.build()
);

private final Setting<Integer> sneakTime = sgActions.add(new IntSetting.Builder()
.name("sneak-time")
.description("How many ticks to stay sneaked.")
.defaultValue(5)
.min(1)
.sliderMin(1)
.visible(sneak::get)
.build()
);

private final Setting<Boolean> strafe = sgActions.add(new BoolSetting.Builder()
.name("strafe")
.description("Strafe right and left")
.description("Strafe right and left.")
.defaultValue(false)
.onChanged(aBoolean -> {
strafeTimer = 0;
Expand All @@ -109,6 +70,40 @@ public enum SpinMode {
.build()
);

private final Setting<Boolean> spin = sgActions.add(new BoolSetting.Builder()
.name("spin")
.description("Spins the player in place.")
.defaultValue(true)
.build()
);

private final Setting<SpinMode> spinMode = sgActions.add(new EnumSetting.Builder<SpinMode>()
.name("spin-mode")
.description("The method of rotating.")
.defaultValue(SpinMode.Server)
.visible(spin::get)
.build()
);

private final Setting<Integer> spinSpeed = sgActions.add(new IntSetting.Builder()
.name("speed")
.description("The speed to spin you.")
.defaultValue(7)
.visible(spin::get)
.build()
);

private final Setting<Integer> pitch = sgActions.add(new IntSetting.Builder()
.name("pitch")
.description("The pitch to send to the server.")
.defaultValue(0)
.range(-90, 90)
.sliderRange(-90, 90)
.visible(() -> spin.get() && spinMode.get() == SpinMode.Server)
.build()
);


// Messages

private final Setting<Boolean> sendMessages = sgMessages.add(new BoolSetting.Builder()
Expand All @@ -118,40 +113,56 @@ public enum SpinMode {
.build()
);

private final Setting<Boolean> randomMessage = sgMessages.add(new BoolSetting.Builder()
.name("random")
.description("Selects a random message from your message list.")
.defaultValue(false)
.visible(sendMessages::get)
.build()
);

private final Setting<Integer> delay = sgMessages.add(new IntSetting.Builder()
.name("delay")
.description("The delay between specified messages in seconds.")
.defaultValue(2)
.defaultValue(15)
.min(0)
.sliderMax(20)
.sliderMax(30)
.visible(sendMessages::get)
.build()
);

private final Setting<Boolean> randomMessage = sgMessages.add(new BoolSetting.Builder()
.name("random")
.description("Selects a random message from your message list.")
.defaultValue(false)
private final Setting<List<String>> messages = sgMessages.add(new StringListSetting.Builder()
.name("messages")
.description("The messages to choose from.")
.defaultValue(
"Meteor on top!",
"Meteor on crack!"
)
.visible(sendMessages::get)
.build()
);

private final List<String> messages = new ArrayList<>();
private int timer;
private int messageI;
private int strafeTimer = 0;
private boolean direction = false;
public AntiAFK() {
super(Categories.Player, "anti-afk", "Performs different actions to prevent getting kicked while AFK.");
}

private final Random random = new Random();

private int messageTimer = 0;
private int messageI = 0;
private int sneakTimer = 0;
private int strafeTimer = 0;
private boolean direction = false;
private float prevYaw;

public AntiAFK() {
super(Categories.Player, "anti-afk", "Performs different actions to prevent getting kicked for AFK reasons.");
}

@Override
public void onActivate() {
if (sendMessages.get() && messages.get().isEmpty()) {
warning("Message list is empty, disabling messages...");
sendMessages.set(false);
}

prevYaw = mc.player.getYaw();
timer = delay.get() * 20;
messageTimer = delay.get() * 20;
}

@Override
Expand All @@ -164,127 +175,56 @@ public void onDeactivate() {

@EventHandler
private void onTick(TickEvent.Pre event) {
if (Utils.canUpdate()) {
//Spin
if (spin.get()) {
prevYaw += spinSpeed.get();
switch (spinMode.get()) {
case Client -> mc.player.setYaw(prevYaw);
case Server -> Rotations.rotate(prevYaw, pitch.get(), -15, null);
}
}

//Jump
if (jump.get() && mc.options.jumpKey.isPressed()) mc.options.jumpKey.setPressed(false);
if (jump.get() && mc.options.sneakKey.isPressed()) mc.options.sneakKey.setPressed(false);
else if (jump.get() && random.nextInt(99) + 1 == 50) mc.options.jumpKey.setPressed(true);

//Click
if (click.get() && random.nextInt(99) + 1 == 45) {
mc.options.attackKey.setPressed(true);
Utils.leftClick();
mc.options.attackKey.setPressed(false);
}
if (!Utils.canUpdate()) return;

//Disco
if (disco.get() && random.nextInt(24) + 1 == 15) mc.options.sneakKey.setPressed(true);

//Spam
if (sendMessages.get() && !messages.isEmpty())
if (timer <= 0) {
int i;
if (randomMessage.get()) {
i = Utils.random(0, messages.size());
} else {
if (messageI >= messages.size()) messageI = 0;
i = messageI++;
}

ChatUtils.sendPlayerMsg(messages.get(i));

timer = delay.get() * 20;
} else {
timer--;
}

//Strafe
if (strafe.get() && strafeTimer == 20) {
mc.options.leftKey.setPressed(!direction);
mc.options.rightKey.setPressed(direction);
direction = !direction;
strafeTimer = 0;
} else
strafeTimer++;
// Jump
if (jump.get()) {
if (mc.options.jumpKey.isPressed()) mc.options.jumpKey.setPressed(false);
else if (random.nextInt(99) == 0) mc.options.jumpKey.setPressed(true);
}
}

@Override
public WWidget getWidget(GuiTheme theme) {
messages.removeIf(String::isEmpty);
// Swing
if (swing.get() && random.nextInt(99) == 0) {
mc.player.swingHand(mc.player.getActiveHand());
}

WTable table = theme.table();
fillTable(theme, table);
// Sneak
if (sneak.get()) {
if (sneakTimer++ >= sneakTime.get()) {
mc.options.sneakKey.setPressed(false);
if (random.nextInt(99) == 0) sneakTimer = 0; // Sneak after ~5 seconds
} else mc.options.sneakKey.setPressed(true);
}

return table;
}
// Strafe
if (strafe.get() && strafeTimer-- <= 0) {
mc.options.leftKey.setPressed(!direction);
mc.options.rightKey.setPressed(direction);
direction = !direction;
strafeTimer = 20;
}

private void fillTable(GuiTheme theme, WTable table) {
table.add(theme.horizontalSeparator("Message List")).expandX();
table.row();
// Spin
if (spin.get()) {
prevYaw += spinSpeed.get();
switch (spinMode.get()) {
case Client -> mc.player.setYaw(prevYaw);
case Server -> Rotations.rotate(prevYaw, pitch.get(), -15);
}
}

// Messages
for (int i = 0; i < messages.size(); i++) {
int msgI = i;
String message = messages.get(i);

WTextBox textBox = table.add(theme.textBox(message)).minWidth(100).expandX().widget();
textBox.action = () -> messages.set(msgI, textBox.get());

WMinus delete = table.add(theme.minus()).widget();
delete.action = () -> {
messages.remove(msgI);

table.clear();
fillTable(theme, table);
};
if (sendMessages.get() && !messages.get().isEmpty() && messageTimer-- <= 0) {
if (randomMessage.get()) messageI = random.nextInt(messages.get().size());
else if (++messageI >= messages.get().size()) messageI = 0;

table.row();
ChatUtils.sendPlayerMsg(messages.get().get(messageI));
messageTimer = delay.get() * 20;
}

// New Message
WPlus add = table.add(theme.plus()).expandCellX().right().widget();
add.action = () -> {
messages.add("");

table.clear();
fillTable(theme, table);
};
}

@Override
public NbtCompound toTag() {
NbtCompound tag = super.toTag();

messages.removeIf(String::isEmpty);
NbtList messagesTag = new NbtList();

for (String message : messages) messagesTag.add(NbtString.of(message));
tag.put("messages", messagesTag);

return tag;
}

@Override
public Module fromTag(NbtCompound tag) {
messages.clear();

if (tag.contains("messages")) {
NbtList messagesTag = tag.getList("messages", 8);
for (NbtElement messageTag : messagesTag) messages.add(messageTag.asString());
} else {
messages.add("This is an AntiAFK message. Meteor on Crack!");
}

return super.fromTag(tag);
public enum SpinMode {
Server,
Client
}
}

0 comments on commit 3af641e

Please sign in to comment.