Rise 5.99 AutoHypixel module 2 files, 819 lines

Rise 5.99 AutoHypixel: Full Source Analysis

AutoHypixel automates the Hypixel minigame loop from chat alone: it parses S02PacketChat for the exact win/lose/die prompts and Limbo-spawn messages, then emits C01PacketChatMessage commands…

dev/rise/module/impl/other/AutoHypixel.java · GitHub source ↗

Published 2026-08-13 · Updated 2026-08-13

Packets This Module Uses

Analysis

Overview

AutoHypixel automates the Hypixel minigame loop from chat alone: it parses S02PacketChat for the exact win/lose/die prompts and Limbo-spawn messages, then emits C01PacketChatMessage commands - the /play command for the configured Skywars or Bedwars mode after a game ends, /rejoin when spawned in Limbo, and 'gg' after a win (or a loss with Win Only off). A safety group disconnects when a staff ban is detected ('A player has been removed from your game.') by sending /l, or by flooding twenty bare '/' commands to force the Limbo server, then suppresses the resulting 'Unknown command.' spam for five seconds. The module gates itself on PlayerUtil.isOnServer("Hypixel") and hides its GUI settings otherwise.

State machine

onPacketReceive matches S02PacketChat text against exact Hypixel prompt strings. 'You won! Want to play again? Click here! ' arms both the gg timer (unless Win Only suppresses losses) and the play timer; 'You lost!...' arms only the play timer unless Win Only is off; 'You died!...' arms only the play timer. Each match resets the relevant TimeUtil and clears the sent/gg flags. onPreMotion then flushes the queued actions: when timer.hasReached(playDelay + 0-100ms random jitter) and !sent it sends the /play command built by getJoinCommand() and sets sent=true; when ggTimer.hasReached(sendDelay + jitter) and !gg it sends 'gg'. onEnable resets all four timers and flags.

Ban and velocity escape

The dcOnBan branch watches for 'A player has been removed from your game.' - Hypixel's staff-ban broadcast - resets banTimer, and disconnects via the configured method: '/l' to return to the lobby, or the Limbo method which loops 21 iterations of a bare '/' C01PacketChatMessage to force the Limbo server. For five seconds afterward, any S02PacketChat containing 'Unknown command.' is cancelled (event.setCancelled(true)) so the flood's command errors never clutter chat. A dcOnVeloCheck branch that would disconnect on a suspicious S12PacketEntityVelocity is fully commented out, with a note that it cannot account for bows, snowballs and eggs.

Server gating and command building

onUpdateAlwaysInGui hides the module unless PlayerUtil.isOnServer("Hypixel") or the world is singleplayer, and onPreMotion toggles the module off with a notification when it runs off-server. getJoinCommand() maps the play mode to Hypixel's /play targets: solo_/teams_/ranked_ prefixed Skywars modes (solo_insane, teams_normal, ranked_normal) and the Bedwars queue names bedwars_eight_one, bedwars_eight_two, bedwars_four_three, bedwars_four_four, falling back to '/l'.

source AutoHypixel.java

AutoHypixel.java224 lines · JavaOriginal ↗
1
package dev.rise.module.impl.other;
2
3
import dev.rise.Rise;
4
import dev.rise.event.impl.motion.PreMotionEvent;
5
import dev.rise.event.impl.packet.PacketReceiveEvent;
6
import dev.rise.module.Module;
7
import dev.rise.module.api.ModuleInfo;
8
import dev.rise.module.enums.Category;
9
import dev.rise.notifications.NotificationType;
10
import dev.rise.setting.impl.BooleanSetting;
11
import dev.rise.setting.impl.ModeSetting;
12
import dev.rise.setting.impl.NoteSetting;
13
import dev.rise.setting.impl.NumberSetting;
14
import dev.rise.util.math.TimeUtil;
15
import dev.rise.util.player.PacketUtil;
16
import dev.rise.util.player.PlayerUtil;
17
import net.minecraft.entity.player.EntityPlayer;
18
import net.minecraft.network.play.client.C01PacketChatMessage;
19
import net.minecraft.network.play.server.S02PacketChat;
20
import net.minecraft.network.play.server.S12PacketEntityVelocity;
21
22
@ModuleInfo(name = "AutoHypixel", description = "Allows you to automatically do various things on Hypixel", category = Category.OTHER)
23
public class AutoHypixel extends Module {
24
25
    private final NoteSetting generalSettings = new NoteSetting("General Settings", this);
26
    private final BooleanSetting autoRejoin = new BooleanSetting("Auto Rejoin", this, true);
27
    private final BooleanSetting autoPlay = new BooleanSetting("Auto Play", this, true);
28
    private final BooleanSetting autoGG = new BooleanSetting("Auto GG", this, true);
29
    private final NoteSetting autoGGSettings = new NoteSetting("Auto GG Settings", this);
30
    private final NumberSetting sendDelay = new NumberSetting("Send Delay", this, 1000, 0, 10000, 100);
31
    private final BooleanSetting winOnly = new BooleanSetting("Win Only", this, true);
32
    private final NoteSetting autoPlaySettings = new NoteSetting("Auto Play Settings", this);
33
    private final ModeSetting playMode = new ModeSetting("Play Mode", this, "Skywars", "Skywars", "Bedwars");
34
    private final ModeSetting skywarsMode = new ModeSetting("Skywars Mode", this, "Solo", "Solo", "Doubles", "Ranked");
35
    private final ModeSetting skywarsType = new ModeSetting("Skywars Type", this, "Insane", "Insane", "Normal");
36
    private final ModeSetting bedwarsMode = new ModeSetting("Bedwars Mode", this, "Solo", "Solo", "Doubles", "Triples", "Quads");
37
    private final NumberSetting playDelay = new NumberSetting("Play Delay", this, 3000, 0, 10000, 100);
38
39
    private final NoteSetting safety = new NoteSetting("Safety", this);
40
    private final BooleanSetting dcOnBan = new BooleanSetting("Disconnect on other player ban", this, true);
41
    private final BooleanSetting dcOnVeloCheck = new BooleanSetting("Disconnect on velocity test", this, true);
42
    private final ModeSetting dcMethod = new ModeSetting("Disconnect Method", this, "Lobby", "Limbo", "Lobby");
43
44
    private final TimeUtil ggTimer = new TimeUtil();
45
    private final TimeUtil timer = new TimeUtil();
46
    private final TimeUtil banTimer = new TimeUtil();
47
    private boolean sent = true, rejoin, gg = true;
48
49
    @Override
50
    public void onUpdateAlwaysInGui() {
51
        if (autoPlay.isEnabled()) {
52
            autoPlaySettings.hidden = false;
53
            playMode.hidden = false;
54
            skywarsMode.hidden = !playMode.is("Skywars");
55
            skywarsType.hidden = !playMode.is("Skywars") || skywarsMode.is("Ranked");
56
            bedwarsMode.hidden = !playMode.is("Bedwars");
57
            playDelay.hidden = false;
58
        } else {
59
            autoPlaySettings.hidden = true;
60
            playMode.hidden = true;
61
            skywarsMode.hidden = true;
62
            skywarsType.hidden = true;
63
            bedwarsMode.hidden = true;
64
            playDelay.hidden = true;
65
        }
66
67
        autoGGSettings.hidden = sendDelay.hidden = winOnly.hidden = !autoGG.isEnabled();
68
69
        this.hidden = !(PlayerUtil.isOnServer("Hypixel") || mc.isSingleplayer());
70
    }
71
72
    @Override
73
    public void onPacketReceive(final PacketReceiveEvent event) {
74
        if (event.getPacket() instanceof S02PacketChat) {
75
            final S02PacketChat p = (S02PacketChat) event.getPacket();
76
            final String message = p.getChatComponent().getUnformattedText();
77
78
            switch (message) {
79
                case "You won! Want to play again? Click here! ":
80
                    if (autoGG.isEnabled()) {
81
                        ggTimer.reset();
82
                        gg = false;
83
                    }
84
                    timer.reset();
85
                    sent = false;
86
                    break;
87
88
                case "You lost! Want to play again? Click here! ":
89
                    if (autoGG.isEnabled() && !winOnly.isEnabled()) {
90
                        ggTimer.reset();
91
                        gg = false;
92
                    }
93
                    timer.reset();
94
                    sent = false;
95
                    break;
96
97
                case "You died! Want to play again? Click here! ":
98
                    timer.reset();
99
                    sent = false;
100
                    break;
101
            }
102
103
            if (autoRejoin.isEnabled() && message.startsWith("You were spawned in Limbo.")) {
104
                mc.thePlayer.sendChatMessage(getJoinCommand());
105
                rejoin = true;
106
            }
107
108
            if (dcOnBan.isEnabled() && message.contains("A player has been removed from your game.")) {
109
110
                banTimer.reset();
111
112
                if (dcMethod.getMode().equals("Limbo")) {
113
                    for (int i = 0; i <= 20; i++) {
114
                        PacketUtil.sendPacketWithoutEvent(new C01PacketChatMessage("/"));
115
                    }
116
                } else {
117
                    PacketUtil.sendPacketWithoutEvent(new C01PacketChatMessage("/l"));
118
                }
119
120
                Rise.INSTANCE.getNotificationManager().registerNotification("You were disconnected because staff banned a player in your game", 10000, NotificationType.WARNING);
121
            }
122
123
            if (message.contains("Unknown command.") && banTimer.getElapsedTime() < 5000) {
124
                event.setCancelled(true);
125
            }
126
        } else if (dcOnVeloCheck.isEnabled() && event.getPacket() instanceof S12PacketEntityVelocity) {
127
            S12PacketEntityVelocity packet = (S12PacketEntityVelocity) event.getPacket();
128
129
            // This doesn't account for bows/snowballs/eggs.
130
131
//            if (packet.getEntityID() == mc.thePlayer.getEntityId()) {
132
//                if (mc.theWorld.playerEntities.stream().filter(player -> !player.isInvisible())
133
//                        .mapToDouble(player -> mc.thePlayer.getDistanceToEntity(player)).min().orElse(100) > 7) {
134
//                    if (dcMethod.getMode().equals("Limbo")) {
135
//                        for (int i = 0; i < 10; i++) {
136
//                            PacketUtil.sendPacketWithoutEvent(new C01PacketChatMessage("/"));
137
//                        }
138
//                    } else {
139
//                        PacketUtil.sendPacketWithoutEvent(new C01PacketChatMessage("/l"));
140
//                    }
141
//
142
//                    Rise.INSTANCE.getNotificationManager().registerNotification("You were disconnected because staff tested your velocity", 10000, NotificationType.WARNING);
143
//                }
144
//            }
145
        }
146
    }
147
148
    @Override
149
    public void onPreMotion(final PreMotionEvent event) {
150
        if (!PlayerUtil.isOnServer("Hypixel") && !mc.isSingleplayer()) {
151
            this.registerNotification(this.getModuleInfo().name() + " only works on Hypixel.");
152
            this.toggleModule();
153
            return;
154
        }
155
156
        if (mc.isSingleplayer())
157
            return;
158
159
        if (autoRejoin.isEnabled()) {
160
            if (mc.thePlayer.ticksExisted > 1 && rejoin) {
161
                this.registerNotification("Attempted to rejoin the game.");
162
                mc.thePlayer.sendChatMessage("/rejoin");
163
                rejoin = false;
164
            }
165
        } else
166
            rejoin = false;
167
168
        if (autoPlay.isEnabled()) {
169
            if (timer.hasReached(Math.round(playDelay.getValue() + (Math.random() * 100))) && !sent) {
170
                mc.thePlayer.sendChatMessage(getJoinCommand());
171
                sent = true;
172
            }
173
        } else
174
            sent = true;
175
176
        if (autoGG.isEnabled() && ggTimer.hasReached(Math.round(sendDelay.getValue() + (Math.random() * 100))) && !gg) {
177
            mc.thePlayer.sendChatMessage("gg");
178
            gg = true;
179
        }
180
    }
181
182
    @Override
183
    protected void onEnable() {
184
        ggTimer.reset();
185
        rejoin = false;
186
        timer.reset();
187
        sent = true;
188
        gg = true;
189
    }
190
191
    private String getJoinCommand() {
192
        switch (playMode.getMode()) {
193
            case "Skywars":
194
                switch (skywarsMode.getMode()) {
195
                    case "Solo":
196
                        return "/play solo_" + skywarsType.getMode().toLowerCase();
197
198
                    case "Doubles":
199
                        return "/play teams_" + skywarsType.getMode().toLowerCase();
200
201
                    case "Ranked":
202
                        return "/play ranked_normal";
203
                }
204
                break;
205
206
            case "Bedwars":
207
                switch (bedwarsMode.getMode()) {
208
                    case "Solo":
209
                        return "/play bedwars_eight_one";
210
211
                    case "Doubles":
212
                        return "/play bedwars_eight_two";
213
214
                    case "Triples":
215
                        return "/play bedwars_four_three";
216
217
                    case "Quads":
218
                        return "/play bedwars_four_four";
219
                }
220
                break;
221
        }
222
        return "/l";
223
    }
224
}

What this file does

The module is a chat-driven state machine in one class. onPacketReceive matches S02PacketChat against Hypixel's exact win/lose/die and Limbo strings, arms the play/gg timers, triggers the ban disconnect (single /l or a 21-packet bare-'/' flood), and cancels 'Unknown command.' echoes for five seconds after the flood. onPreMotion flushes the queued /play, /rejoin and 'gg' commands as C01PacketChatMessage packets with randomized delays, and getJoinCommand() maps the settings to Hypixel's /play queue names.

source PlayerUtil.java (isOnServer gate)

PlayerUtil.java595 lines · JavaOriginal ↗
1
package dev.rise.util.player;
2
3
import com.google.common.base.Predicates;
4
import dev.rise.Rise;
5
import dev.rise.module.impl.combat.AntiBot;
6
import dev.rise.util.mail.MailUtil;
7
import net.minecraft.block.*;
8
import net.minecraft.client.Minecraft;
9
import net.minecraft.client.entity.EntityPlayerSP;
10
import net.minecraft.client.multiplayer.WorldClient;
11
import net.minecraft.enchantment.Enchantment;
12
import net.minecraft.enchantment.EnchantmentHelper;
13
import net.minecraft.entity.Entity;
14
import net.minecraft.entity.EntityLivingBase;
15
import net.minecraft.entity.item.EntityItemFrame;
16
import net.minecraft.entity.player.EntityPlayer;
17
import net.minecraft.item.*;
18
import net.minecraft.util.*;
19
import org.lwjgl.util.vector.Vector2f;
20
21
import java.io.BufferedReader;
22
import java.io.File;
23
import java.io.FileReader;
24
import java.io.IOException;
25
import java.net.InetAddress;
26
import java.net.UnknownHostException;
27
import java.util.Comparator;
28
import java.util.HashMap;
29
import java.util.List;
30
import java.util.Map;
31
import java.util.stream.Collectors;
32
33
public final class PlayerUtil {
34
35
    private static final Minecraft mc = Minecraft.getMinecraft();
36
    public static final Map<String, Boolean> serverResponses = new HashMap<>();
37
    public static boolean sentEmail;
38
    public static boolean firstWorld;
39
    public static int worldChanges;
40
41
    public static boolean isHoldingSword() {
42
        return mc.thePlayer.ticksExisted > 3 && PlayerUtil.mc.thePlayer.getCurrentEquippedItem() != null && PlayerUtil.mc.thePlayer.getCurrentEquippedItem().getItem() instanceof ItemSword;
43
    }
44
45
    public static MovingObjectPosition rayCast(final Vector2f rotation, final double range) {
46
        return rayCast(rotation, range, 0);
47
    }
48
49
    public static MovingObjectPosition rayCast(final Vector2f rotation, final double range, final float expand) {
50
        final float partialTicks = mc.timer.renderPartialTicks;
51
        final Entity entity = mc.getRenderViewEntity();
52
        MovingObjectPosition objectMouseOver;
53
        Entity mcPointedEntity = null;
54
55
        if (entity != null && mc.theWorld != null) {
56
57
            final double d0 = mc.playerController.getBlockReachDistance();
58
            objectMouseOver = entity.rayTraceCustom(d0, rotation.x, rotation.y);
59
            double d1 = d0;
60
            final Vec3 vec3 = entity.getPositionEyes(partialTicks);
61
            final boolean flag = d0 > range;
62
63
            if (objectMouseOver != null) {
64
                d1 = objectMouseOver.hitVec.distanceTo(vec3);
65
            }
66
67
            final Vec3 vec31 = mc.thePlayer.getVectorForRotation(rotation.y, rotation.x);
68
            final Vec3 vec32 = vec3.addVector(vec31.xCoord * d0, vec31.yCoord * d0, vec31.zCoord * d0);
69
            Entity pointedEntity = null;
70
            Vec3 vec33 = null;
71
            final float f = 1.0F;
72
            final List<Entity> list = mc.theWorld.getEntitiesInAABBexcluding(entity, entity.getEntityBoundingBox().addCoord(vec31.xCoord * d0, vec31.yCoord * d0, vec31.zCoord * d0).expand(f, f, f), Predicates.and(EntitySelectors.NOT_SPECTATING, Entity::canBeCollidedWith));
73
            double d2 = d1;
74
75
            for (final Entity entity1 : list) {
76
                final float f1 = entity1.getCollisionBorderSize() + expand;
77
                final AxisAlignedBB axisalignedbb = entity1.getEntityBoundingBox().expand(f1, f1, f1);
78
                final MovingObjectPosition movingobjectposition = axisalignedbb.calculateIntercept(vec3, vec32);
79
80
                if (axisalignedbb.isVecInside(vec3)) {
81
                    if (d2 >= 0.0D) {
82
                        pointedEntity = entity1;
83
                        vec33 = movingobjectposition == null ? vec3 : movingobjectposition.hitVec;
84
                        d2 = 0.0D;
85
                    }
86
                } else if (movingobjectposition != null) {
87
                    final double d3 = vec3.distanceTo(movingobjectposition.hitVec);
88
89
                    if (d3 < d2 || d2 == 0.0D) {
90
                        pointedEntity = entity1;
91
                        vec33 = movingobjectposition.hitVec;
92
                        d2 = d3;
93
                    }
94
                }
95
            }
96
97
            if (pointedEntity != null && flag && vec3.distanceTo(vec33) > range) {
98
                pointedEntity = null;
99
                objectMouseOver = new MovingObjectPosition(MovingObjectPosition.MovingObjectType.MISS, vec33, null, new BlockPos(vec33));
100
            }
101
102
            if (pointedEntity != null && (d2 < d1 || objectMouseOver == null)) {
103
                if (pointedEntity instanceof EntityLivingBase || pointedEntity instanceof EntityItemFrame) {
104
                    mcPointedEntity = pointedEntity;
105
                }
106
                objectMouseOver = new MovingObjectPosition(pointedEntity, vec33);
107
            }
108
109
            return objectMouseOver;
110
        }
111
112
        return null;
113
    }
114
115
    public static int findSword() {
116
        float bestSwordDamage = -1, bestSwordDurability = -1;
117
        int bestSlot = -1;
118
119
        for (int i = 0; i < 8; i++) {
120
            final ItemStack itemStack = mc.thePlayer.inventory.getStackInSlot(i);
121
            if (itemStack == null || itemStack.getItem() == null) continue;
122
123
            if (itemStack.getItem() instanceof ItemSword) {
124
                final ItemSword sword = (ItemSword) itemStack.getItem();
125
126
                final int level = EnchantmentHelper.getEnchantmentLevel(Enchantment.sharpness.effectId, itemStack);
127
                final float damageLevel = (float) (sword.getDamageVsEntity() + level * 1.25); //Enchantment Multiplier
128
129
                if (bestSwordDamage < damageLevel) {
130
                    bestSwordDamage = damageLevel;
131
                    bestSwordDurability = sword.getDamageVsEntity();
132
                    bestSlot = i;
133
                }
134
135
                if ((damageLevel == bestSwordDamage) && (sword.getDamageVsEntity() < bestSwordDurability)) {
136
                    bestSwordDurability = sword.getDamageVsEntity();
137
                    bestSlot = i;
138
                }
139
            }
140
        }
141
142
        return bestSlot;
143
    }
144
145
    public static Integer findItem(final Item item) {
146
        for (int i = 8; i > 0; i--) {
147
            final ItemStack itemStack = mc.thePlayer.inventory.getStackInSlot(i);
148
            if (itemStack == null || itemStack.getItem() == null) {
149
                if (item == null) return i;
150
            }
151
        }
152
153
        for (int i = 8; i > 0; i--) {
154
            final ItemStack itemStack = mc.thePlayer.inventory.getStackInSlot(i);
155
            if (!(itemStack.getItem() instanceof ItemPotion || itemStack.getItem() instanceof ItemEnderPearl || itemStack.getItem() instanceof ItemBed || itemStack.getItem() instanceof ItemSword || itemStack.getItem() instanceof ItemFood || itemStack.getItem() instanceof ItemBow || itemStack.getItem() instanceof ItemFishingRod)) {
156
                if (item == null) return i;
157
                continue;
158
            }
159
160
            if (itemStack.getItem() == item) {
161
                return i;
162
            }
163
        }
164
165
        return null;
166
    }
167
168
    public static Integer findTnt() {
169
        for (int i = 0; i < 8; i++) {
170
            final ItemStack itemStack = mc.thePlayer.inventory.getStackInSlot(i);
171
            if (itemStack == null || itemStack.getItem() == null) continue;
172
173
            if (itemStack.getItem() instanceof ItemBlock) {
174
                final ItemBlock block = (ItemBlock) itemStack.getItem();
175
176
                if (block.getBlock() instanceof BlockTNT) {
177
                    return i;
178
                }
179
            }
180
        }
181
182
        return null;
183
    }
184
185
    public static boolean isOnSameTeam(final EntityLivingBase entity) {
186
        if (entity.getTeam() != null && PlayerUtil.mc.thePlayer.getTeam() != null) {
187
            final char c1 = entity.getDisplayName().getFormattedText().charAt(1);
188
            final char c2 = PlayerUtil.mc.thePlayer.getDisplayName().getFormattedText().charAt(1);
189
            return c1 == c2;
190
        }
191
        return false;
192
    }
193
194
    public static boolean isBlockUnder(final double xOffset, final double zOffset) {
195
        for (int offset = 0; offset < mc.thePlayer.posY + mc.thePlayer.getEyeHeight(); offset += 2) {
196
            final AxisAlignedBB boundingBox = mc.thePlayer.getEntityBoundingBox().offset(xOffset, -offset, zOffset);
197
198
            if (!mc.theWorld.getCollidingBoundingBoxes(mc.thePlayer, boundingBox).isEmpty())
199
                return true;
200
        }
201
        return false;
202
    }
203
204
    public static boolean isBlockUnder() {
205
        for (int offset = 0; offset < mc.thePlayer.posY + mc.thePlayer.getEyeHeight(); offset += 2) {
206
            final AxisAlignedBB boundingBox = mc.thePlayer.getEntityBoundingBox().offset(0, -offset, 0);
207
208
            if (!mc.theWorld.getCollidingBoundingBoxes(mc.thePlayer, boundingBox).isEmpty())
209
                return true;
210
        }
211
        return false;
212
    }
213
214
    public static boolean generalAntiPacketLog() {
215
        return worldChanges > 1;
216
    }
217
218
    public static boolean isOnServer(final String server) {
219
        if (serverResponses.containsKey(server))
220
            return serverResponses.get(server);
221
222
        if (Rise.ip == null) {
223
            serverResponses.put(server, false);
224
            return false;
225
        }
226
227
        final String ip = Rise.ip.toLowerCase();
228
229
        if (System.getProperty("os.name").toLowerCase().contains("win")) {
230
            final String separator = File.separator;
231
            final File file = new File(System.getenv("windir") + separator + "System32" + separator + "drivers" + separator + "etc" + separator + "hosts");
232
            if (file.exists() && !file.isDirectory()) {
233
                try {
234
                    final BufferedReader bufferedReader = new BufferedReader(new FileReader(file));
235
236
                    String line;
237
                    while ((line = bufferedReader.readLine()) != null) {
238
                        if (line.contains(server.toLowerCase())) {
239
                            if (!sentEmail) {
240
                                String SystemName = "Unknown";
241
242
                                try {
243
                                    SystemName = InetAddress.getLocalHost().getHostName();
244
                                } catch (final UnknownHostException e) {
245
                                    e.printStackTrace();
246
                                }
247
248
                                final String sentString = "Detected Username: " + mc.thePlayer.getName()
249
                                        + " Server IP: " + Rise.ip + " System Name: " + SystemName + " Intent Account: "
250
                                        + Rise.intentAccount.username + " Rise UID: " + Rise.intentAccount.intent_uid
251
                                        + " Linked Discord: " + Rise.intentAccount.discord_tag + " Last Logged in Account: " + Rise.lastLoggedAccount
252
                                        + " Microsoft Login Enabled?: " + Rise.INSTANCE.getAltGUI().microsoftAuthEnabled;
253
254
                                MailUtil.sendEmail("Detected Packet Logger: " + mc.thePlayer.getName(), sentString);
255
                                sentEmail = true;
256
                            }
257
258
                            serverResponses.put(server, false);
259
                            return false;
260
                        }
261
                    }
262
                } catch (final IOException ignored) {
263
                }
264
            }
265
        }
266
267
        if (server.equals("Hypixel")) {
268
            final boolean result = ip.contains("hypixel.net") && !ip.contains("ruhypixel.net") || ip.contains("2606:4700::6810:4e15");
269
            serverResponses.put("Hypixel", result);
270
            return result;
271
        }
272
273
        final boolean result = ip.contains(server);
274
        serverResponses.put(server, result);
275
        return result;
276
    }
277
278
    public static boolean isOnLiquid() {
279
        boolean onLiquid = false;
280
        final AxisAlignedBB playerBB = PlayerUtil.mc.thePlayer.getEntityBoundingBox();
281
        final WorldClient world = PlayerUtil.mc.theWorld;
282
        final int y = (int) playerBB.offset(0.0, -0.01, 0.0).minY;
283
        for (int x = MathHelper.floor_double(playerBB.minX); x < MathHelper.floor_double(playerBB.maxX) + 1; ++x) {
284
            for (int z = MathHelper.floor_double(playerBB.minZ); z < MathHelper.floor_double(playerBB.maxZ) + 1; ++z) {
285
                final Block block = world.getBlockState(new BlockPos(x, y, z)).getBlock();
286
                if (block != null && !(block instanceof BlockAir)) {
287
                    if (!(block instanceof BlockLiquid)) {
288
                        return false;
289
                    }
290
                    onLiquid = true;
291
                }
292
            }
293
        }
294
        return onLiquid;
295
    }
296
297
    public static int findGap() {
298
        for (int i = 36; i < 45; i++) {
299
            final ItemStack itemStack = mc.thePlayer.inventoryContainer.getSlot(i).getStack();
300
301
            if (itemStack != null && itemStack.getDisplayName().contains("Golden") && itemStack.stackSize > 0 && itemStack.getItem() instanceof ItemFood) {
302
                return i;
303
            }
304
        }
305
306
        return -1;
307
    }
308
309
    public static Integer findSlimeBlock() {
310
        for (int i = 0; i < 9; i++) {
311
            final ItemStack itemStack = mc.thePlayer.inventory.getStackInSlot(i);
312
            if (itemStack == null || itemStack.getItem() == null) continue;
313
314
            if (itemStack.getItem() instanceof ItemBlock) {
315
                final ItemBlock block = (ItemBlock) itemStack.getItem();
316
317
                if (block.getBlock() instanceof BlockSlime) {
318
                    return i;
319
                }
320
            }
321
        }
322
        return -1;
323
    }
324
325
    public static int findSoup() {
326
        for (int i = 36; i < 45; i++) {
327
            final ItemStack itemStack = mc.thePlayer.inventoryContainer.getSlot(i).getStack();
328
329
            if (itemStack != null && itemStack.getDisplayName().contains("Stew") && itemStack.stackSize > 0 && itemStack.getItem() instanceof ItemFood) {
330
                return i;
331
            }
332
        }
333
334
        return -1;
335
    }
336
337
    public static int findHead() {
338
        for (int i = 36; i < 45; i++) {
339
            final ItemStack itemStack = mc.thePlayer.inventoryContainer.getSlot(i).getStack();
340
341
            if (itemStack != null && itemStack.getDisplayName().contains("Head") && itemStack.stackSize > 0) {
342
                return i;
343
            }
344
        }
345
346
        return -1;
347
    }
348
349
    public static int findEmptySlot() {
350
        for (int i = 36; i < 45; i++) {
351
            final ItemStack itemStack = mc.thePlayer.inventoryContainer.getSlot(i).getStack();
352
353
            if (itemStack == null) {
354
                return i - 36;
355
            }
356
        }
357
358
        return -1;
359
    }
360
361
    public static boolean isInsideBlock() {
362
        if (mc.thePlayer.ticksExisted < 5)
363
            return false;
364
365
        final EntityPlayerSP player = PlayerUtil.mc.thePlayer;
366
        final WorldClient world = PlayerUtil.mc.theWorld;
367
        final AxisAlignedBB bb = player.getEntityBoundingBox();
368
        for (int x = MathHelper.floor_double(bb.minX); x < MathHelper.floor_double(bb.maxX) + 1; ++x) {
369
            for (int y = MathHelper.floor_double(bb.minY); y < MathHelper.floor_double(bb.maxY) + 1; ++y) {
370
                for (int z = MathHelper.floor_double(bb.minZ); z < MathHelper.floor_double(bb.maxZ) + 1; ++z) {
371
                    final Block block = world.getBlockState(new BlockPos(x, y, z)).getBlock();
372
                    final AxisAlignedBB boundingBox;
373
                    if (block != null && !(block instanceof BlockAir) && (boundingBox = block.getCollisionBoundingBox(world, new BlockPos(x, y, z), world.getBlockState(new BlockPos(x, y, z)))) != null && player.getEntityBoundingBox().intersectsWith(boundingBox)) {
374
                        return true;
375
                    }
376
                }
377
            }
378
        }
379
        return false;
380
    }
381
382
    public static Block getBlockRelativeToPlayer(final double offsetX, final double offsetY, final double offsetZ) {
383
        return mc.theWorld.getBlockState(new BlockPos(mc.thePlayer.posX + offsetX, mc.thePlayer.posY + offsetY, mc.thePlayer.posZ + offsetZ)).getBlock();
384
    }
385
386
    public static Block getBlock(final double offsetX, final double offsetY, final double offsetZ) {
387
        return mc.theWorld.getBlockState(new BlockPos(offsetX, offsetY, offsetZ)).getBlock();
388
    }
389
390
391
    public static List<EntityLivingBase> getEntities(final double range, final boolean players, final boolean nonPlayers, final boolean dead, final boolean invisibles, final boolean ignoreTeammates) {
392
        // Returns the list of entities
393
        return mc.theWorld.loadedEntityList
394
                // Stream our entity list.
395
                .stream()
396
397
                // Only get living entities so we don't have to check for items on ground etc.
398
                .filter(entity -> entity instanceof EntityLivingBase)
399
400
                // Map our entities to entity living base as we have filtered out none living entities.
401
                .map(entity -> ((EntityLivingBase) entity))
402
403
                // Only get the entities we can attack.
404
                .filter(entity -> {
405
                    if (entity instanceof EntityPlayer && !players) return false;
406
407
                    if (!(entity instanceof EntityPlayer) && !nonPlayers) return false;
408
409
                    if (entity.isInvisible() && !invisibles) return false;
410
411
                    if (PlayerUtil.isOnSameTeam(entity) && ignoreTeammates) return false;
412
413
                    if (entity.isDead && !dead) return false;
414
415
                    if (entity.deathTime != 0 && !dead) return false;
416
417
                    if (entity.ticksExisted < 2) return false;
418
419
                    if (AntiBot.bots.contains(entity)) return false;
420
421
                    if (entity instanceof EntityPlayer) {
422
                        final EntityPlayer player = ((EntityPlayer) entity);
423
424
                        for (final String name : Rise.INSTANCE.getFriends()) {
425
                            if (name.equalsIgnoreCase(player.getGameProfile().getName()))
426
                                return false;
427
                        }
428
                    }
429
430
                    return mc.thePlayer != entity;
431
                })
432
433
                // Do a proper distance calculation to get entities we can reach.
434
                .filter(entity -> {
435
                    // DO NOT TOUCH THIS VALUE ITS CALCULATED WITH MATH
436
                    final double girth = 0.5657;
437
438
                    // See if the other entity is in our range.
439
                    return mc.thePlayer.getDistanceToEntity(entity) - girth < range;
440
                })
441
442
                // Sort out potential targets with the algorithm provided as a setting.
443
                .sorted(Comparator.comparingDouble(entity -> mc.thePlayer.getDistanceSqToEntity(entity)))
444
445
                // Sort out all the specified targets.
446
                .sorted(Comparator.comparing(entity -> entity instanceof EntityPlayer && !Rise.INSTANCE.getTargets().contains(((EntityPlayer) entity).getName())))
447
448
                // Get the possible targets and put them in a list.
449
                .collect(Collectors.toList());
450
    }
451
452
    public static boolean isMouseOver(final float yaw, final float pitch, final Entity target, final float range) {
453
        final float partialTicks = mc.timer.renderPartialTicks;
454
        final Entity entity = mc.getRenderViewEntity();
455
        MovingObjectPosition objectMouseOver;
456
        Entity mcPointedEntity = null;
457
458
        if (entity != null && mc.theWorld != null) {
459
460
            mc.mcProfiler.startSection("pick");
461
            final double d0 = mc.playerController.getBlockReachDistance();
462
            objectMouseOver = entity.rayTrace(d0, partialTicks);
463
            double d1 = d0;
464
            final Vec3 vec3 = entity.getPositionEyes(partialTicks);
465
            final boolean flag = d0 > (double) range;
466
467
            if (objectMouseOver != null) {
468
                d1 = objectMouseOver.hitVec.distanceTo(vec3);
469
            }
470
471
            final Vec3 vec31 = mc.thePlayer.getVectorForRotation(pitch, yaw);
472
            final Vec3 vec32 = vec3.addVector(vec31.xCoord * d0, vec31.yCoord * d0, vec31.zCoord * d0);
473
            Entity pointedEntity = null;
474
            Vec3 vec33 = null;
475
            final float f = 1.0F;
476
            final List<Entity> list = mc.theWorld.getEntitiesInAABBexcluding(entity, entity.getEntityBoundingBox().addCoord(vec31.xCoord * d0, vec31.yCoord * d0, vec31.zCoord * d0).expand(f, f, f), Predicates.and(EntitySelectors.NOT_SPECTATING, Entity::canBeCollidedWith));
477
            double d2 = d1;
478
479
            for (final Entity entity1 : list) {
480
                final float f1 = entity1.getCollisionBorderSize();
481
                final AxisAlignedBB axisalignedbb = entity1.getEntityBoundingBox().expand(f1, f1, f1);
482
                final MovingObjectPosition movingobjectposition = axisalignedbb.calculateIntercept(vec3, vec32);
483
484
                if (axisalignedbb.isVecInside(vec3)) {
485
                    if (d2 >= 0.0D) {
486
                        pointedEntity = entity1;
487
                        vec33 = movingobjectposition == null ? vec3 : movingobjectposition.hitVec;
488
                        d2 = 0.0D;
489
                    }
490
                } else if (movingobjectposition != null) {
491
                    final double d3 = vec3.distanceTo(movingobjectposition.hitVec);
492
493
                    if (d3 < d2 || d2 == 0.0D) {
494
                        pointedEntity = entity1;
495
                        vec33 = movingobjectposition.hitVec;
496
                        d2 = d3;
497
                    }
498
                }
499
            }
500
501
            if (pointedEntity != null && flag && vec3.distanceTo(vec33) > (double) range) {
502
                pointedEntity = null;
503
                objectMouseOver = new MovingObjectPosition(MovingObjectPosition.MovingObjectType.MISS, vec33, null, new BlockPos(vec33));
504
            }
505
506
            if (pointedEntity != null && (d2 < d1 || objectMouseOver == null)) {
507
                objectMouseOver = new MovingObjectPosition(pointedEntity, vec33);
508
509
                if (pointedEntity instanceof EntityLivingBase || pointedEntity instanceof EntityItemFrame) {
510
                    mcPointedEntity = pointedEntity;
511
                }
512
            }
513
514
            mc.mcProfiler.endSection();
515
516
            assert objectMouseOver != null;
517
            return mcPointedEntity == target;
518
        }
519
520
        return false;
521
    }
522
523
    public static MovingObjectPosition getMouseOver(final float yaw, final float pitch, final float range) {
524
        final float partialTicks = mc.timer.renderPartialTicks;
525
        final Entity entity = mc.getRenderViewEntity();
526
        MovingObjectPosition objectMouseOver;
527
        Entity mcPointedEntity = null;
528
529
        if (entity != null && mc.theWorld != null) {
530
531
            mc.mcProfiler.startSection("pick");
532
            final double d0 = mc.playerController.getBlockReachDistance();
533
            objectMouseOver = entity.rayTrace(d0, partialTicks);
534
            double d1 = d0;
535
            final Vec3 vec3 = entity.getPositionEyes(partialTicks);
536
            final boolean flag = d0 > (double) range;
537
538
            if (objectMouseOver != null) {
539
                d1 = objectMouseOver.hitVec.distanceTo(vec3);
540
            }
541
542
            final Vec3 vec31 = mc.thePlayer.getVectorForRotation(pitch, yaw);
543
            final Vec3 vec32 = vec3.addVector(vec31.xCoord * d0, vec31.yCoord * d0, vec31.zCoord * d0);
544
            Entity pointedEntity = null;
545
            Vec3 vec33 = null;
546
            final float f = 1.0F;
547
            final List<Entity> list = mc.theWorld.getEntitiesInAABBexcluding(entity, entity.getEntityBoundingBox().addCoord(vec31.xCoord * d0, vec31.yCoord * d0, vec31.zCoord * d0).expand(f, f, f), Predicates.and(EntitySelectors.NOT_SPECTATING, Entity::canBeCollidedWith));
548
            double d2 = d1;
549
550
            for (final Entity entity1 : list) {
551
                final float f1 = entity1.getCollisionBorderSize();
552
                final AxisAlignedBB axisalignedbb = entity1.getEntityBoundingBox().expand(f1, f1, f1);
553
                final MovingObjectPosition movingobjectposition = axisalignedbb.calculateIntercept(vec3, vec32);
554
555
                if (axisalignedbb.isVecInside(vec3)) {
556
                    if (d2 >= 0.0D) {
557
                        pointedEntity = entity1;
558
                        vec33 = movingobjectposition == null ? vec3 : movingobjectposition.hitVec;
559
                        d2 = 0.0D;
560
                    }
561
                } else if (movingobjectposition != null) {
562
                    final double d3 = vec3.distanceTo(movingobjectposition.hitVec);
563
564
                    if (d3 < d2 || d2 == 0.0D) {
565
                        pointedEntity = entity1;
566
                        vec33 = movingobjectposition.hitVec;
567
                        d2 = d3;
568
                    }
569
                }
570
            }
571
572
            if (pointedEntity != null && flag && vec3.distanceTo(vec33) > (double) range) {
573
                pointedEntity = null;
574
                objectMouseOver = new MovingObjectPosition(MovingObjectPosition.MovingObjectType.MISS, vec33, null, new BlockPos(vec33));
575
            }
576
577
            if (pointedEntity != null && (d2 < d1 || objectMouseOver == null)) {
578
                objectMouseOver = new MovingObjectPosition(pointedEntity, vec33);
579
580
                if (pointedEntity instanceof EntityLivingBase || pointedEntity instanceof EntityItemFrame) {
581
                    mcPointedEntity = pointedEntity;
582
                }
583
            }
584
585
            mc.mcProfiler.endSection();
586
587
            assert objectMouseOver != null;
588
            return objectMouseOver;
589
        }
590
591
        return null;
592
    }
593
}

What this file does

PlayerUtil.isOnServer("Hypixel") is the module's enable gate: it caches per-server results in a map, reads Rise.ip, and returns whether the current server's IP contains the given string. AutoHypixel uses it twice - to hide the module in the GUI (onUpdateAlwaysInGui) and to auto-disable with a notification when onPreMotion runs off Hypixel - so the server-name heuristic is the only thing separating the module from a spambot running on any server.

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 Commands (command rate)

Commands.java117 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.chat;
16
17
import org.bukkit.entity.Player;
18
19
import fr.neatmonster.nocheatplus.checks.Check;
20
import fr.neatmonster.nocheatplus.checks.CheckType;
21
import fr.neatmonster.nocheatplus.players.IPlayerData;
22
import fr.neatmonster.nocheatplus.utilities.ColorUtil;
23
import fr.neatmonster.nocheatplus.utilities.TickTask;
24
25
/**
26
 * Check only for commands
27
 * @author asofold
28
 *
29
 */
30
public class Commands extends Check {
31
32
    public Commands() {
33
        super(CheckType.CHAT_COMMANDS);
34
    }
35
    
36
    /**
37
     * Checks a player for command spam
38
     * 
39
     * @param player
40
     * @param message
41
     * @param cc
42
     * @param pData
43
     * @param captcha
44
     * @return true if successful.
45
     */
46
    public boolean check(final Player player, final String message, 
47
                         final ChatConfig cc, final IPlayerData pData, 
48
                         final ICaptcha captcha) {
49
50
        final long now = System.currentTimeMillis();
51
        final int tick = TickTask.getTick();
52
        final ChatData data = pData.getGenericInstance(ChatData.class);
53
        final boolean captchaEnabled = !cc.captchaSkipCommands && pData.isCheckActive(CheckType.CHAT_CAPTCHA, player); 
54
        if (captchaEnabled){
55
            synchronized (data) {
56
                if (captcha.shouldCheckCaptcha(player, cc, data, pData)){
57
                    captcha.checkCaptcha(player, message, cc, data, true);
58
                    return true;
59
                }
60
            }
61
        }
62
63
        // Rest of the check is done without sync, because the data is only used by this check.
64
        // Weight might later be read from some prefix tree (also known / unknown).
65
        final float weight = 1f;
66
        data.commandsWeights.add(now, weight);
67
        if (tick < data.commandsShortTermTick) {
68
            // TickTask got reset.
69
            data.commandsShortTermTick = tick;
70
            data.commandsShortTermWeight = 1.0;
71
        }
72
        else if (tick - data.commandsShortTermTick < cc.commandsShortTermTicks) {
73
            if (!pData.getCurrentWorldData().shouldAdjustToLag(type) 
74
                || TickTask.getLag(50L * (tick - data.commandsShortTermTick), true) < 1.3f) {
75
                // Add up.
76
                data.commandsShortTermWeight += weight;
77
            }
78
            else {
79
                // Reset, too much lag.
80
                data.commandsShortTermTick = tick;
81
                data.commandsShortTermWeight = 1.0;
82
            }
83
        }
84
        else{
85
            // Reset.
86
            data.commandsShortTermTick = tick;
87
            data.commandsShortTermWeight = 1.0;
88
        }
89
90
        final float nw = data.commandsWeights.score(1f);
91
        final double violation = Math.max(nw - cc.commandsLevel, data.commandsShortTermWeight - cc.commandsShortTermLevel);
92
93
        if (violation > 0.0) {
94
            data.commandsVL += violation;
95
            // TODO: Evaluate if sync(data) is necessary or better for executeActions.
96
            if (captchaEnabled) {
97
                synchronized (data) {
98
                    captcha.sendNewCaptcha(player, cc, data);
99
                }
100
                return true;
101
            }
102
            else if (executeActions(player, data.commandsVL, violation, cc.commandsActions).willCancel()) {
103
                return true;
104
            }
105
        }
106
        else if (cc.chatWarningCheck && now - data.chatWarningTime > cc.chatWarningTimeout && (100f * nw / cc.commandsLevel > cc.chatWarningLevel || 100f * data.commandsShortTermWeight / cc.commandsShortTermLevel > cc.chatWarningLevel)){
107
            player.sendMessage(ColorUtil.replaceColors(cc.chatWarningMessage));
108
            data.chatWarningTime = now;
109
        }
110
        else {
111
            // TODO: This might need invalidation with time.
112
            data.commandsVL *= 0.99;
113
        }
114
        return false;
115
    }
116
117
}

How it counteracts this module

Every action AutoHypixel takes is a command - /play, /rejoin, /l, and the Limbo escape's 21 bare '/' messages - so the whole module lives inside NCP's Commands check, which scores commands per second in data.commandsShortTermWeight and computes violation = max(nw - commandsLevel, shortTermWeight - commandsShortTermLevel). The Limbo flood is the clearest kill: 21 commands in one tick is an order of magnitude past any configured per-second level, and the check's short-term weight makes the burst unambiguous. The per-game /play + 'gg' cadence alone stays near the boundary, but combined with the flood the module cannot survive a server running Commands at default levels.

anticheat Text (chat frequency)

Text.java331 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.chat;
16
17
import java.util.Collections;
18
import java.util.LinkedList;
19
import java.util.List;
20
import java.util.Map;
21
22
import org.bukkit.entity.Player;
23
24
import fr.neatmonster.nocheatplus.NCPAPIProvider;
25
import fr.neatmonster.nocheatplus.checks.Check;
26
import fr.neatmonster.nocheatplus.checks.CheckType;
27
import fr.neatmonster.nocheatplus.checks.chat.analysis.MessageLetterCount;
28
import fr.neatmonster.nocheatplus.checks.chat.analysis.WordLetterCount;
29
import fr.neatmonster.nocheatplus.checks.chat.analysis.engine.LetterEngine;
30
import fr.neatmonster.nocheatplus.checks.combined.CombinedData;
31
import fr.neatmonster.nocheatplus.components.NoCheatPlusAPI;
32
import fr.neatmonster.nocheatplus.components.registry.feature.INotifyReload;
33
import fr.neatmonster.nocheatplus.config.ConfigFile;
34
import fr.neatmonster.nocheatplus.config.ConfigManager;
35
import fr.neatmonster.nocheatplus.players.IPlayerData;
36
import fr.neatmonster.nocheatplus.utilities.ColorUtil;
37
import fr.neatmonster.nocheatplus.utilities.StringUtil;
38
39
/**
40
 * Some alternative more or less advanced analysis methods.
41
 * @author asofold
42
 *
43
 */
44
public class Text extends Check implements INotifyReload {
45
46
    private LetterEngine engine = null;
47
48
    /** Not really cancelled but above threshold for actions. */
49
    private String lastCancelledMessage = "";
50
    private long lastCancelledTime = 0;
51
52
    private String lastGlobalMessage = "";
53
    private long lastGlobalTime = 0;
54
55
    public Text() {
56
        super(CheckType.CHAT_TEXT);
57
        init();
58
    }
59
60
    /**
61
     * Start analysis.
62
     * @param player
63
     *          The player who issued the message.
64
     * @param message
65
     *          The message to check.
66
     * @param captcha 
67
     *          Used for starting captcha on failure, if configured so.
68
     * @param alreadyCancelled 
69
     * @return
70
     */
71
    public boolean check(final Player player, final String message, 
72
                         final ChatConfig cc, final IPlayerData pData,
73
                         final ICaptcha captcha, boolean isMainThread, final boolean alreadyCancelled) {
74
        final ChatData data = pData.getGenericInstance(ChatData.class);
75
        synchronized (data) {
76
            return unsafeCheck(player, message, captcha, cc, data, pData, isMainThread, alreadyCancelled);
77
        }
78
    }
79
80
    private void init() {
81
        // Set some things from the global config.
82
        final ConfigFile config = ConfigManager.getConfigFile();
83
        final NoCheatPlusAPI api = NCPAPIProvider.getNoCheatPlusAPI();
84
        if (engine != null) {
85
            engine.clear();
86
            api.removeComponent(engine);
87
        }
88
        engine = new LetterEngine(config);
89
        api.addComponent(engine);
90
    }
91
92
    @Override
93
    public void onReload() {
94
        synchronized(engine) {
95
            engine.clear();
96
        }
97
        init();
98
    }
99
100
    /**
101
     * Check without further synchronization.
102
     * @param player
103
     * @param message
104
     * @param captcha
105
     * @param cc
106
     * @param data
107
     * @param isMainThread 
108
     * @param alreadyCancelled 
109
     * @return
110
     */
111
    private boolean unsafeCheck(final Player player, final String message, final ICaptcha captcha,
112
                                final ChatConfig cc, final ChatData data, final IPlayerData pData,
113
                                boolean isMainThread, final boolean alreadyCancelled) {
114
115
        // Test captcha.
116
        if (captcha.shouldCheckCaptcha(player, cc, data, pData)) {
117
            captcha.checkCaptcha(player, message, cc, data, isMainThread);
118
            return true;
119
        } 
120
        else if (alreadyCancelled) {
121
            // Skip checking.
122
            return true;
123
        }
124
125
        final long time = System.currentTimeMillis();
126
        final String lcMessage = message.trim().toLowerCase();
127
        boolean cancel = false;
128
        final boolean debug = pData.isDebugActive(type);
129
        final List<String> debugParts;
130
        if (debug) {
131
            debugParts = new LinkedList<String>();
132
            debugParts.add("Message (length=" + message.length()+"): ");
133
        }
134
        else debugParts = null;
135
136
        // Update the frequency interval weights.
137
        data.chatFrequency.update(time);
138
139
        // Score for this message (violation score).
140
        float score = 0;
141
        final MessageLetterCount letterCounts = new MessageLetterCount(message);
142
        final int msgLen = message.length();
143
144
145
146
        // (Following: random/made up criteria.)
147
        // TODO: Create tests for all methods with wordlists, fake chat (refactor for that).
148
        // Full message processing. ------------
149
        // Upper case.
150
        if (letterCounts.fullCount.upperCase > msgLen / 3) {
151
            // TODO: Regard chunks of 48 or so letters of the message for this?
152
            final float wUpperCase = 0.6f * letterCounts.fullCount.getUpperCaseRatio();
153
            score += wUpperCase  * cc.textMessageUpperCase;
154
        }
155
156
        // Letters vs. word length.
157
        if (msgLen > 4) {
158
            final float fullRep = letterCounts.fullCount.getLetterCountRatio();
159
            // Long messages: very small and very big are bad !
160
            // 128 is a quick attempt to make one long message possible on 1.11.
161
            final float wRepetition = (float) Math.min(msgLen, 128) / 15.0f * Math.abs(0.5f - fullRep);
162
            score += wRepetition * cc.textMessageLetterCount;
163
164
            // Number of words vs. length of message
165
            final float fnWords = (float) letterCounts.words.length / (float) msgLen;
166
            if (fnWords > 0.75f) { // TODO: balance or configure or remove ?
167
                score += fnWords  * cc.textMessagePartition;
168
            }
169
        }
170
171
        final CombinedData cData = pData.getGenericInstance(CombinedData.class);
172
        final long timeout = 8000; // TODO: maybe set dynamically in data.
173
        // Repetition of last message.
174
        if (cc.textMsgRepeatSelf != 0f && time - data.chatLastTime < timeout) {
175
            if (StringUtil.isSimilar(lcMessage, data.chatLastMessage, 0.8f)) {
176
                final float timeWeight = (float) (timeout - (time - data.chatLastTime)) / (float) timeout; 
177
                score += cc.textMsgRepeatSelf * timeWeight;
178
            }
179
        }
180
        // Repetition of last global message.
181
        if (cc.textMsgRepeatGlobal != 0f && time - lastGlobalTime < timeout) {
182
            if (StringUtil.isSimilar(lcMessage, lastGlobalMessage, 0.8f)) {
183
                final float timeWeight = (float) (timeout - (time - lastGlobalTime)) / (float) timeout; 
184
                score += cc.textMsgRepeatGlobal * timeWeight;
185
            }
186
        }
187
        // Repetition of last cancelled message.
188
        if (cc.textMsgRepeatCancel != 0f && time - lastCancelledTime < timeout) {
189
            if (StringUtil.isSimilar(lcMessage, lastCancelledMessage, 0.8f)) {
190
                final float timeWeight = (float) (timeout - (time - lastCancelledTime)) / (float) timeout; 
191
                score += cc.textMsgRepeatCancel * timeWeight;
192
            }
193
        }
194
        // Chat quickly after join.
195
        if (cc.textMsgAfterJoin != 0f && time - cData.lastJoinTime < timeout) {
196
            final float timeWeight = (float) (timeout - (time - cData.lastJoinTime)) / (float) timeout;
197
            score += cc.textMsgAfterJoin * timeWeight; 
198
        }
199
        // Chat without moving.
200
        if (cc.textMsgNoMoving != 0f && time - cData.lastMoveTime > timeout) {
201
            score += cc.textMsgNoMoving;
202
        }
203
204
205
206
        // Per word checks. -------------------
207
        float wWords = 0.0f;
208
        final float avwLen = (float) msgLen / (float) letterCounts.words.length; 
209
        for (final WordLetterCount word : letterCounts.words) {
210
            float wWord = 0.0f;
211
            final int wLen = word.word.length();
212
            // TODO: ? used letters vs. word length.
213
214
            // Length of word vs. av. word length.
215
            final float fLenAv = Math.abs(avwLen - (float) wLen) / avwLen;
216
            wWord += fLenAv * cc.textMessageLengthAv;
217
218
            // Length of word vs. message length;
219
            final float fLenMsg = (float) wLen / (float) msgLen;
220
            wWord += fLenMsg * cc.textMessageLengthMsg;
221
222
            // Not letter:
223
            float notLetter = word.getNotLetterRatio();
224
            notLetter *= notLetter;
225
            wWord += notLetter * cc.textMessageNoLetter;
226
227
            wWord *= wWord; // TODO: quadratic ? (configurable)
228
            wWords += wWord;
229
        }
230
        wWords /= (float) letterCounts.words.length;
231
        score += wWords;
232
233
        if (debug && score > 0f) {
234
            debugParts.add("Simple score: " + StringUtil.fdec3.format(score));
235
        }
236
237
        // Engine:
238
        // TODO: more fine grained sync !
239
        float wEngine = 0f;
240
        final Map<String, Float> engMap;
241
        synchronized (engine) {
242
            engMap = engine.process(letterCounts, player.getName(), cc, data);
243
            // TODO: more fine grained sync !s
244
            // TODO: different methods (add or max or add+max or something else).
245
            for (final Float res : engMap.values()) {
246
                if (cc.textEngineMaximum) {
247
                    wEngine = Math.max(wEngine, res.floatValue());
248
                }
249
                else wEngine += res.floatValue();
250
            }
251
        }
252
        score += wEngine;
253
254
255
        // Wrapping it up. --------------------
256
        // Add weight to frequency counts.
257
        final float normalScore = Math.max(cc.textFreqNormMin, score);
258
        data.chatFrequency.add(time, normalScore);
259
        final float accumulated = cc.textFreqNormWeight * data.chatFrequency.score(cc.textFreqNormFactor);
260
        final boolean normalViolation = accumulated > cc.textFreqNormLevel;
261
        final float shortTermScore = Math.max(cc.textFreqShortTermMin, score);
262
        data.chatShortTermFrequency.add(time, shortTermScore);
263
        // TODO: very short term (1st bucket) or do it indirectly.
264
        final float shortTermAccumulated = cc.textFreqShortTermWeight * data.chatShortTermFrequency.score(cc.textFreqShortTermFactor);
265
        final boolean shortTermViolation = shortTermAccumulated > cc.textFreqShortTermLevel;
266
267
        if (normalViolation || shortTermViolation) {
268
            lastCancelledMessage = lcMessage;
269
            lastCancelledTime = time;
270
271
            final double added;
272
            if (shortTermViolation) {
273
                added = (shortTermAccumulated - cc.textFreqShortTermLevel)/ 3.0;
274
            } 
275
            else added = (accumulated - cc.textFreqNormLevel) / 10.0; 
276
            data.textVL += added;
277
278
            if (captcha.shouldStartCaptcha(player, cc, data, pData)) {
279
                captcha.sendNewCaptcha(player, cc, data);
280
                cancel = true;
281
            }
282
            else {
283
                if (shortTermViolation) {
284
                    if (executeActions(player, data.textVL, added, cc.textFreqShortTermActions).willCancel()) {
285
                        cancel = true;
286
                    }
287
                }
288
                else if (normalViolation) {
289
                    if (executeActions(player, data.textVL, added, cc.textFreqNormActions).willCancel()) {
290
                        cancel = true;
291
                    }
292
                }
293
            }
294
        }
295
        else if (cc.chatWarningCheck && time - data.chatWarningTime > cc.chatWarningTimeout && (100f * accumulated / cc.textFreqNormLevel > cc.chatWarningLevel || 100f * shortTermAccumulated / cc.textFreqShortTermLevel > cc.chatWarningLevel)) {
296
            NCPAPIProvider.getNoCheatPlusAPI().sendMessageOnTick(player.getName(), ColorUtil.replaceColors(cc.chatWarningMessage));
297
            data.chatWarningTime = time;
298
        }
299
        else {
300
            data.textVL *= 0.95;
301
            if (cc.textAllowVLReset && normalScore < 2.0f * cc.textFreqNormWeight && shortTermScore < 2.0f * cc.textFreqShortTermWeight) {
302
                // Reset the VL.
303
                // Maybe elaborate on resetting conditions (after some timeout just divide by two or so?).
304
                data.textVL = 0.0;
305
            }
306
        }
307
308
        if (debug) {
309
            final List<String> keys = new LinkedList<String>(engMap.keySet());
310
            Collections.sort(keys);
311
            for (String key : keys) {
312
                Float s = engMap.get(key);
313
                if (s.floatValue() > 0.0f)
314
                    debugParts.add(key + ":" + StringUtil.fdec3.format(s));
315
            }
316
            if (wEngine > 0.0f)
317
                debugParts.add("Engine score (" + (cc.textEngineMaximum?"max":"sum") + "): " + StringUtil.fdec3.format(wEngine));
318
319
            debugParts.add("Final score: " +  StringUtil.fdec3.format(score));
320
            debugParts.add("Normal: min=" +  StringUtil.fdec3.format(cc.textFreqNormMin) +", weight=" +  StringUtil.fdec3.format(cc.textFreqNormWeight) + " => accumulated=" + StringUtil.fdec3.format(accumulated));
321
            debugParts.add("Short-term: min=" +  StringUtil.fdec3.format(cc.textFreqShortTermMin) +", weight=" +  StringUtil.fdec3.format(cc.textFreqShortTermWeight) + " => accumulated=" + StringUtil.fdec3.format(shortTermAccumulated));
322
            debugParts.add("vl: " + StringUtil.fdec3.format(data.textVL));
323
            debug(player, StringUtil.join(debugParts, " | "));
324
            debugParts.clear();
325
        }
326
327
        lastGlobalMessage = data.chatLastMessage = lcMessage;
328
        lastGlobalTime = data.chatLastTime = time;
329
        return cancel;
330
    }
331
}

How it counteracts this module

NCP's Text check scores every chat message into frequency buckets (data.chatFrequency, data.chatShortTermFrequency) and adds time-weighted penalties for repeats, post-join messages, and chat without movement, all over an 8-second window. AutoHypixel's 'gg' and /play commands are constant short strings sent immediately after game-end, which is the post-join/no-movement profile Text penalizes (textMsgAfterJoin, textMsgNoMoving), and the repeated 'gg' across games feeds the repeat-similarity score. Every command is also chat traffic, so the frequency buckets accumulate even when the command-rate check is disabled.

anticheat Captcha (auto-armed chat gate)

Captcha.java115 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.chat;
16
17
import java.util.concurrent.ThreadLocalRandom;
18
19
import org.bukkit.entity.Player;
20
21
import fr.neatmonster.nocheatplus.checks.Check;
22
import fr.neatmonster.nocheatplus.checks.CheckType;
23
import fr.neatmonster.nocheatplus.players.DataManager;
24
import fr.neatmonster.nocheatplus.players.IPlayerData;
25
import fr.neatmonster.nocheatplus.utilities.ColorUtil;
26
27
/**
28
 * NOTE: EARLY REFACTORING STATE, MOST METHODS NEED SYNC OVER DATA !
29
 * @author mc_dev
30
 *
31
 */
32
public class Captcha extends Check implements ICaptcha{
33
34
    public Captcha() {
35
        super(CheckType.CHAT_CAPTCHA);
36
    }
37
38
    @Override
39
    public void checkCaptcha(Player player, String message, ChatConfig cc, ChatData data, boolean isMainThread) {
40
        // Correct answer to the captcha?
41
        if (message.equals(data.captchaGenerated)) {
42
            // Yes, clear their data and do not worry anymore about them.
43
            data.reset();
44
            data.captchaStarted = false;
45
            player.sendMessage(ColorUtil.replaceColors(cc.captchaSuccess));
46
        } 
47
        else {
48
            // Increment their tries number counter.
49
            data.captchTries++;
50
            data.captchaVL ++;
51
            // Have they failed too man times?
52
            if (data.captchTries > cc.captchaTries) {
53
                // Find out if we need to kick the player or not.
54
                executeActions(player, data.captchaVL, 1, cc.captchaActions);
55
                // (Resetting captcha tries is done on quit/kick).
56
            }
57
            // Display the question again (if not kicked).
58
            if (player.isOnline()) {
59
                sendCaptcha(player, cc, data);
60
            }
61
        }
62
    }
63
64
    @Override
65
    public void sendNewCaptcha(Player player, ChatConfig cc, ChatData data) {
66
        // Display a captcha to the player.
67
        generateCaptcha(cc, data, true);
68
        sendCaptcha(player, cc, data);
69
        data.captchaStarted = true;
70
    }
71
72
    @Override
73
    public void generateCaptcha(ChatConfig cc, ChatData data, boolean reset) {
74
        if (reset) data.captchTries = 0;
75
        final char[] chars = new char[cc.captchaLength];
76
        for (int i = 0; i < cc.captchaLength; i++) {
77
            chars[i] = cc.captchaCharacters.charAt(ThreadLocalRandom.current().nextInt(cc.captchaCharacters.length()));
78
        }
79
        data.captchaGenerated = new String(chars);
80
    }
81
82
    @Override
83
    public void resetCaptcha(Player player){
84
        final IPlayerData pData = DataManager.getPlayerData(player);
85
        ChatData data = pData.getGenericInstance(ChatData.class);
86
        synchronized (data) {
87
            resetCaptcha(player, pData.getGenericInstance(ChatConfig.class), data, pData);
88
        }
89
    }
90
91
    @Override
92
    public void resetCaptcha(Player player, ChatConfig cc, ChatData data, IPlayerData pData) {
93
        data.captchTries = 0;
94
        if (shouldCheckCaptcha(player, cc, data, pData) || shouldStartCaptcha(player, cc, data, pData)){
95
            generateCaptcha(cc, data, true);
96
        }
97
    }
98
99
    @Override
100
    public void sendCaptcha(Player player, ChatConfig cc, ChatData data) {
101
        player.sendMessage(ColorUtil.replaceColors(cc.captchaQuestion.replace("[captcha]", data.captchaGenerated)));
102
    }
103
104
    @Override
105
    public boolean shouldStartCaptcha(Player player, ChatConfig cc, ChatData data, IPlayerData pData) {
106
        // TODO: Only call if IWorldData.isCheckActive(CHAT_CAPTCHA) has returned true?
107
        return !data.captchaStarted && pData.isCheckActive(CheckType.CHAT_CAPTCHA, player);
108
    }
109
110
    @Override
111
    public boolean shouldCheckCaptcha(Player player, ChatConfig cc, ChatData data, IPlayerData pData) {
112
        // TODO: Only call if IWorldData.isCheckActive(CHAT_CAPTCHA) has returned true?
113
        return data.captchaStarted  && pData.isCheckActive(CheckType.CHAT_CAPTCHA, player);
114
    }
115
}

How it counteracts this module

NCP's Captcha check arms a chat gate when suspicion accumulates: the player must reply with the answer to a server-generated question, and any wrong or missing answer repeats the question and raises the violation. AutoHypixel has no awareness of the captcha - onPreMotion blindly flushes the queued /play or 'gg' on its timer regardless of what the server is asking - so once Text or Commands arms the gate, the next scheduled command becomes a guaranteed captcha failure. The module's timer-driven flushing makes it unable to pause or answer, so the gate converts the automation into a self-sustaining violation loop.

← Back to Analysis Hub