AutoLog module

AutoLog: Minecraft 26.3 cheat module, full source for every implementation (1 client: OfflineClient).

1 implementationMISC

Clients with this module

Full module source: 1 implementation

Every implementation below is the complete module file, verbatim. Expand a client to read its code.

OfflineClientMISCsrc/main/java/com/jellypudding/offlineclient/modules/misc/AutoLog.javaJava · 260 lines · 11.6 KB

Logs you out when your health gets low.

SettingsModePause in creativeHealthPredict damageInstant killTotemsTotem popsOnly trustedEntitiesCountCombined limitEach limitEntity rangeToggle offRearm when healedStop AutoReconnect
AutoLog.javaJava · Minecraft 26.2 · 260 lines · 11.6 KB · complete file, verbatimOriginal ↗
1
package com.jellypudding.offlineclient.modules.misc;
2
3
import com.jellypudding.offlineclient.OfflineClient;
4
import com.jellypudding.offlineclient.event.Subscribe;
5
import com.jellypudding.offlineclient.event.events.PacketReceiveEvent;
6
import com.jellypudding.offlineclient.event.events.TickEvent;
7
import com.jellypudding.offlineclient.module.Category;
8
import com.jellypudding.offlineclient.module.Module;
9
import com.jellypudding.offlineclient.setting.BoolSetting;
10
import com.jellypudding.offlineclient.setting.EnumSetting;
11
import com.jellypudding.offlineclient.setting.NumberSetting;
12
import com.jellypudding.offlineclient.setting.RegistryListSetting;
13
import com.jellypudding.offlineclient.util.ChatUtil;
14
import com.jellypudding.offlineclient.util.DamageUtil;
15
import com.jellypudding.offlineclient.util.EntityUtil;
16
import com.jellypudding.offlineclient.util.InventoryUtil;
17
import com.jellypudding.offlineclient.util.Modules;
18
import net.minecraft.core.registries.BuiltInRegistries;
19
import net.minecraft.network.chat.Component;
20
import net.minecraft.network.protocol.game.ClientboundEntityEventPacket;
21
import net.minecraft.network.protocol.game.ServerboundAttackPacket;
22
import net.minecraft.world.entity.Entity;
23
import net.minecraft.world.entity.EntityEvent;
24
import net.minecraft.world.entity.EntityType;
25
import net.minecraft.world.entity.EntityTypes;
26
import net.minecraft.world.entity.player.Player;
27
import net.minecraft.world.item.Items;
28
29
import java.util.HashMap;
30
import java.util.List;
31
import java.util.Map;
32
import java.util.concurrent.atomic.AtomicInteger;
33
34
public final class AutoLog extends Module {
35
36
    public enum Count { TOGETHER, EACH }
37
38
    // Health points in one heart.
39
    private static final float HEART = 2;
40
41
    // How close a player has to be for a one hit kill to count.
42
    private static final double INSTANT_KILL_RANGE = 8;
43
44
    public enum Mode { QUIT, CHARS, SELF_HURT }
45
46
    private final EnumSetting<Mode> mode = new EnumSetting<>("Mode",
47
        "How you leave the server.", Mode.QUIT)
48
        .describe(Mode.QUIT, "A plain disconnect.")
49
        .describe(Mode.CHARS, "Sends a chat line the server refuses and gets you kicked. Slips past combat log plugins.")
50
        .describe(Mode.SELF_HURT, "Attacks yourself which every server kicks you for. Slips past anti cheats too.");
51
    private final BoolSetting pauseInCreative = new BoolSetting("Pause in creative",
52
        "Does nothing whilst you are in creative mode.", true);
53
    private final NumberSetting health = new NumberSetting("Health",
54
        "Disconnect at or below this many hearts.", 3, 0.5, 9.5, 0.5, " hearts");
55
    private final BoolSetting predict = new BoolSetting("Predict damage",
56
        "Also disconnect when a crystal or bed or weapon or fall nearby would take you under the line.",
57
        true);
58
    private final BoolSetting instantKill = new BoolSetting("Instant kill",
59
        "Disconnect when a player within eight blocks holds a weapon that could kill you in one hit.",
60
        false);
61
    private final NumberSetting totems = new NumberSetting("Totems",
62
        "Also disconnect with fewer totems than this. Zero ignores totems.", 0, 0, 10, 1);
63
    private final NumberSetting totemPops = new NumberSetting("Totem pops",
64
        "Disconnect once this many of your totems have popped. Zero ignores pops.", 0, 0, 10, 1);
65
    private final BoolSetting onlyTrusted = new BoolSetting("Only trusted",
66
        "Disconnect when any player who is not a friend comes into view.", false);
67
    private final RegistryListSetting<EntityType<?>> entities = new RegistryListSetting<>("Entities",
68
        "Disconnect when too many of these gather near you.", BuiltInRegistries.ENTITY_TYPE,
69
        List.of(EntityTypes.END_CRYSTAL));
70
    private final EnumSetting<Count> count = new EnumSetting<>("Count",
71
        "How the listed entities are counted.", Count.TOGETHER)
72
        .describe(Count.TOGETHER, "Every listed kind counts towards one total.")
73
        .describe(Count.EACH, "Each kind is counted on its own.")
74
        .visibleWhen(() -> entities.size() > 0);
75
    private final NumberSetting combinedLimit = new NumberSetting("Combined limit",
76
        "How many listed entities in total trigger the disconnect.", 10, 1, 32, 1)
77
        .under(count, Count.TOGETHER);
78
    private final NumberSetting eachLimit = new NumberSetting("Each limit",
79
        "How many of one kind trigger the disconnect.", 2, 1, 16, 1)
80
        .under(count, Count.EACH);
81
    private final NumberSetting entityRange = new NumberSetting("Entity range",
82
        "How close a listed entity has to be to count.", 5, 1, 16, 1, " blocks")
83
        .visibleWhen(() -> entities.size() > 0);
84
    private final BoolSetting toggleOff = new BoolSetting("Toggle off",
85
        "Turn the module off after it disconnects you.", true);
86
    private final BoolSetting rearm = new BoolSetting("Rearm when healed",
87
        "After a low health disconnect turn back on once you are above the health line again.", false)
88
        .under(toggleOff);
89
    private final BoolSetting stopReconnect = new BoolSetting("Stop AutoReconnect",
90
        "Turn AutoReconnect off as you leave so you do not rejoin into the danger.", true);
91
92
    // Counted on the network thread and read on the game thread.
93
    private final AtomicInteger pops = new AtomicInteger();
94
    private final Map<EntityType<?>, Integer> tally = new HashMap<>();
95
96
    // Listens whilst the module is off to come back once healed.
97
    private final Object healWatcher = new Object() {
98
        @Subscribe
99
        private void onTick(TickEvent event) {
100
            if (isEnabled()) {
101
                stopWatching();
102
                return;
103
            }
104
            if (inGame() && !mc.player.isDeadOrDying()
105
                && !EntityUtil.healthAtOrBelow(health.getValue())) {
106
                stopWatching();
107
                setEnabled(true);
108
                ChatUtil.message("AutoLog is back on now that you have healed.");
109
            }
110
        }
111
    };
112
113
    public AutoLog() {
114
        super("AutoLog", "Logs you out when your health gets low.", Category.MISC);
115
        addSettings(mode, pauseInCreative, health, predict, instantKill, totems, totemPops, onlyTrusted, entities, count,
116
            combinedLimit, eachLimit, entityRange, toggleOff, rearm, stopReconnect);
117
        searchTags("auto disconnect", "log out");
118
    }
119
120
    @Override
121
    public String getSuffix() {
122
        return health.getValueString();
123
    }
124
125
    @Override
126
    protected void onEnable() {
127
        pops.set(0);
128
    }
129
130
    // Fired on the netty thread. Only the counter is touched here.
131
    @Subscribe
132
    private void onPacketReceive(PacketReceiveEvent event) {
133
        if (event.getPacket() instanceof ClientboundEntityEventPacket packet
134
            && packet.getEventId() == EntityEvent.PROTECTED_FROM_DEATH
135
            && mc.player != null && packet.entityId == mc.player.getId()) {
136
            pops.incrementAndGet();
137
        }
138
    }
139
140
    @Subscribe
141
    private void onTick(TickEvent event) {
142
        if (!inGame() || mc.player.isDeadOrDying()
143
            || (pauseInCreative.isOn() && mc.player.isCreative())) {
144
            return;
145
        }
146
        // Absorption hearts from golden apples and totems count as health.
147
        if (EntityUtil.healthAtOrBelow(health.getValue())) {
148
            logOut("Health was at or below " + health.getValueString() + ".", true);
149
            return;
150
        }
151
        float line = health.getFloat() * HEART;
152
        if (predict.isOn()
153
            && EntityUtil.totalHealth(mc.player) - DamageUtil.possibleIncoming() <= line) {
154
            logOut("Something nearby was about to take you below " + health.getValueString() + ".", false);
155
            return;
156
        }
157
        if (totems.getInt() > 0 && countTotems() < totems.getInt()) {
158
            logOut("Fewer than " + totems.getInt() + " totems were left.", false);
159
            return;
160
        }
161
        if (totemPops.getInt() > 0 && pops.get() >= totemPops.getInt()) {
162
            logOut(pops.get() + " totems had popped.", false);
163
            return;
164
        }
165
        if (!checkPlayers()) {
166
            checkEntities();
167
        }
168
    }
169
170
    // True when a player caused a logout.
171
    private boolean checkPlayers() {
172
        if (!onlyTrusted.isOn() && !instantKill.isOn()) {
173
            return false;
174
        }
175
        for (Entity entity : mc.level.entitiesForRendering()) {
176
            if (!(entity instanceof Player player) || player == mc.player) {
177
                continue;
178
            }
179
            if (onlyTrusted.isOn() && !EntityUtil.isFriend(player)) {
180
                logOut(EntityUtil.nameOf(player) + " came into view and is not a friend.", false);
181
                return true;
182
            }
183
            if (instantKill.isOn() && EntityUtil.isEnemy(player)
184
                && player.distanceTo(mc.player) <= INSTANT_KILL_RANGE
185
                && DamageUtil.attackDamage(player, mc.player) > EntityUtil.totalHealth(mc.player)) {
186
                logOut(EntityUtil.nameOf(player) + " held a weapon that could kill you in one hit.", false);
187
                return true;
188
            }
189
        }
190
        return false;
191
    }
192
193
    // True when the listed entities caused a logout.
194
    private boolean checkEntities() {
195
        if (entities.size() == 0) {
196
            return false;
197
        }
198
        tally.clear();
199
        int total = 0;
200
        for (Entity entity : mc.level.entitiesForRendering()) {
201
            if (!entities.contains(entity.getType())
202
                || entity.distanceTo(mc.player) > entityRange.getValue()) {
203
                continue;
204
            }
205
            total++;
206
            tally.merge(entity.getType(), 1, Integer::sum);
207
        }
208
        if (count.is(Count.TOGETHER)) {
209
            if (total >= combinedLimit.getInt()) {
210
                logOut(total + " of the listed entities were within " + entityRange.getInt() + " blocks.",
211
                    false);
212
                return true;
213
            }
214
            return false;
215
        }
216
        for (Map.Entry<EntityType<?>, Integer> entry : tally.entrySet()) {
217
            if (entry.getValue() >= eachLimit.getInt()) {
218
                logOut(entry.getValue() + " " + entry.getKey().getDescription().getString()
219
                    + " were within " + entityRange.getInt() + " blocks.", false);
220
                return true;
221
            }
222
        }
223
        return false;
224
    }
225
226
    private int countTotems() {
227
        int offhand = mc.player.getOffhandItem().is(Items.TOTEM_OF_UNDYING)
228
            ? mc.player.getOffhandItem().getCount() : 0;
229
        return offhand + InventoryUtil.count(Items.TOTEM_OF_UNDYING, InventoryUtil.WHOLE_INVENTORY);
230
    }
231
232
    // Turning off first stops an instant logout after reconnecting.
233
    // A low health logout can leave a watcher behind that turns the module back on.
234
    private void logOut(String reason, boolean lowHealth) {
235
        String note = "";
236
        AutoReconnect autoReconnect = Modules.active(AutoReconnect.class);
237
        if (stopReconnect.isOn() && autoReconnect != null) {
238
            autoReconnect.setEnabled(false);
239
            note = "\n§7AutoReconnect was turned off.";
240
        }
241
        if (toggleOff.isOn()) {
242
            setEnabled(false);
243
            if (lowHealth && rearm.isOn()) {
244
                OfflineClient.INSTANCE.getEventBus().register(healWatcher);
245
            }
246
        }
247
        switch (mode.getValue()) {
248
            case QUIT -> mc.player.connection.getConnection().disconnect(
249
                Component.literal("§b[§3Offline§b] §fAutoLog saved you.\n§7" + reason + note));
250
            // The section sign is refused by every server.
251
            case CHARS -> mc.player.connection.sendChat("§");
252
            case SELF_HURT -> mc.player.connection.send(new ServerboundAttackPacket(mc.player.getId()));
253
        }
254
    }
255
256
    private void stopWatching() {
257
        OfflineClient.INSTANCE.getEventBus().unregister(healWatcher);
258
    }
259
}
260