KTLeave module

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

1 implementationCOMBAT

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.

CombatantCOMBATsrc/main/java/combatant/client/features/module/modules/combat/KTLeave.javaJava · 300 lines · 8.9 KB
SettingsktLeaveHpThresholdktLeaveIncludeAbsorptionktLeaveModektLeaveTotemModektLeaveDelayMsktLeavePacketFallbackMsktLeaveJoinCooldownMs
KTLeave.javaJava · Minecraft 26.2 · 300 lines · 8.9 KB · complete file, verbatimOriginal ↗
1
/*
2
 * This file is part of the Combatant Client distribution.
3
 * Copyright (c) 2026 pivosos2007.
4
 *
5
 * Licensed under the GNU General Public License v3.0.
6
 */
7
8
package combatant.client.features.module.modules.combat;
9
10
import net.minecraft.client.Minecraft;
11
import net.minecraft.client.multiplayer.ClientLevel;
12
import net.minecraft.client.player.LocalPlayer;
13
import net.minecraft.network.Connection;
14
import net.minecraft.network.chat.Component;
15
import net.minecraft.network.protocol.common.ServerboundPongPacket;
16
import net.minecraft.util.Util;
17
import net.minecraft.world.item.Items;
18
import combatant.client.config.common.CommonSettingSchemas;
19
import combatant.client.config.values.BindMode;
20
import combatant.client.config.values.BooleanValue;
21
import combatant.client.config.values.EnumValue;
22
import combatant.client.config.values.NumberValue;
23
import combatant.client.features.module.Module;
24
import combatant.client.features.module.ModuleCategory;
25
import combatant.client.features.module.ModuleInfo;
26
import combatant.client.features.module.Notifier;
27
import combatant.client.features.module.Modules;
28
import combatant.client.features.module.modules.player.AutoTotem;
29
import combatant.client.util.network.BlinkManager;
30
import combatant.client.util.pvp.client.CooldownsState;
31
32
//todo Description
33
@ModuleInfo(
34
        id = "ktleave",
35
        displayName = "KTLeave",
36
        category = ModuleCategory.COMBAT
37
)
38
public final class KTLeave extends Module {
39
    private static final String ACTION_LEAVE = "leave";
40
41
    private final NumberValue<Integer> hpThreshold = numCommon(
42
            "ktLeaveHpThreshold",
43
            "hp_threshold",
44
            CommonSettingSchemas.PLAYER_HEALTH_THRESHOLD,
45
            6,
46
            1,
47
            20
48
    );
49
    private final BooleanValue includeAbsorption = bool("ktLeaveIncludeAbsorption", "include_absorption", true);
50
    private final EnumValue<Mode> mode = enumSetting("ktLeaveMode", "mode", Mode.LEGIT);
51
    private final EnumValue<TotemMode> totemMode = enumSetting("ktLeaveTotemMode", "totem_mode", TotemMode.AUTO_TOTEM);
52
    private final NumberValue<Integer> leaveDelayMs = num("ktLeaveDelayMs", "leave_delay_ms", 250, 0, 5000);
53
    private final NumberValue<Integer> packetFallbackMs = visibleWhen(
54
            num("ktLeavePacketFallbackMs", "packet_fallback_ms", 1500, 0, 5000),
55
            () -> mode.get() == Mode.PACKET_KICK
56
    );
57
    private final NumberValue<Integer> joinCooldownMs =
58
            num("ktLeaveJoinCooldownMs", "join_cooldown_ms", 1500, 0, 60000);
59
60
    private final Minecraft mc = Minecraft.getInstance();
61
    private ClientLevel lastWorld;
62
    private boolean pendingLowHealth;
63
    private boolean leaveScheduled;
64
    private boolean packetKickSent;
65
    private boolean manualLeaveScheduled;
66
    private long joinCooldownUntilMs;
67
    private long leaveAtMs;
68
    private long manualLeaveAtMs;
69
    private long packetFallbackAtMs;
70
    private boolean armedInPvp;
71
72
    public KTLeave() {
73
        action(ACTION_LEAVE, "NONE", BindMode.PRESS);
74
    }
75
76
    @Override
77
    public void onDisable() {
78
        resetState();
79
    }
80
81
    @Override
82
    public void onTick() {
83
        if (!isEnabled()) {
84
            return;
85
        }
86
        if (mc == null || mc.player == null || mc.level == null || mc.getConnection() == null) {
87
            resetState();
88
            return;
89
        }
90
91
        long now = Util.getMillis();
92
        if (mc.level != lastWorld) {
93
            resetState();
94
            lastWorld = mc.level;
95
            joinCooldownUntilMs = now + joinCooldownMs.get();
96
            return;
97
        }
98
99
        if (isActionPressedOnce(ACTION_LEAVE)) {
100
            manualLeaveScheduled = true;
101
            manualLeaveAtMs = now + leaveDelayMs.get();
102
        }
103
104
        if (packetKickSent) {
105
            if (packetFallbackMs.get() > 0 && now >= packetFallbackAtMs) {
106
                disconnectNormally();
107
            }
108
            return;
109
        }
110
111
        if (manualLeaveScheduled) {
112
            if (now >= manualLeaveAtMs) {
113
                executeConfiguredLeave(now);
114
            }
115
            return;
116
        }
117
118
        if (now < joinCooldownUntilMs) {
119
            return;
120
        }
121
122
        if (currentHealth(mc.player) > hpThreshold.get()) {
123
            clearLowHealthState();
124
            return;
125
        }
126
127
        if (shouldHoldForTotem(mc.player)) {
128
            clearLowHealthState();
129
            return;
130
        }
131
132
        if (CooldownsState.MANAGER.isInPvp()) {
133
            pendingLowHealth = true;
134
            armedInPvp = true;
135
            leaveScheduled = false;
136
            return;
137
        }
138
        if (!armedInPvp) {
139
            return;
140
        }
141
142
        pendingLowHealth = true;
143
        executeLeave(now);
144
    }
145
146
    private void executeLeave(long now) {
147
        if (!pendingLowHealth || mc.getConnection() == null) {
148
            return;
149
        }
150
151
        if (!leaveScheduled) {
152
            leaveScheduled = true;
153
            leaveAtMs = now + leaveDelayMs.get();
154
            return;
155
        }
156
        if (now < leaveAtMs) {
157
            return;
158
        }
159
160
        executeConfiguredLeave(now);
161
    }
162
163
    private void executeConfiguredLeave(long now) {
164
        if (mode.get() == Mode.PACKET_KICK && !mc.hasSingleplayerServer()) {
165
            sendKickPackets(now);
166
            return;
167
        }
168
        disconnectNormally();
169
    }
170
171
    private boolean shouldHoldForTotem(LocalPlayer player) {
172
        TotemMode guardMode = totemMode.get();
173
        if (guardMode == TotemMode.OFF) {
174
            return false;
175
        }
176
        if (player == null) {
177
            return false;
178
        }
179
180
        if (isTotemHeld(player)) {
181
            return guardMode == TotemMode.AUTO_TOTEM
182
                    || guardMode == TotemMode.HELD
183
                    || guardMode == TotemMode.INVENTORY;
184
        }
185
186
        return switch (guardMode) {
187
            case AUTO_TOTEM -> canAutoTotemHandleNow(player);
188
            case INVENTORY -> hasTotemInInventory(player);
189
            case HELD, OFF -> false;
190
        };
191
    }
192
193
    private boolean canAutoTotemHandleNow(LocalPlayer player) {
194
        AutoTotem autoTotem = Modules.get(AutoTotem.class);
195
        if (autoTotem == null || !autoTotem.isEnabled()) {
196
            return false;
197
        }
198
        if (autoTotem.isTotemSwapPending()) {
199
            return true;
200
        }
201
        return autoTotem.shouldHoldTotemNow(player) && autoTotem.canProvideTotemNow(player);
202
    }
203
204
    private boolean isTotemHeld(LocalPlayer player) {
205
        return player.getOffhandItem().is(Items.TOTEM_OF_UNDYING)
206
                || player.getMainHandItem().is(Items.TOTEM_OF_UNDYING);
207
    }
208
209
    private boolean hasTotemInInventory(LocalPlayer player) {
210
        for (int i = 0; i < 36; i++) {
211
            if (player.getInventory().getItem(i).is(Items.TOTEM_OF_UNDYING)) {
212
                return true;
213
            }
214
        }
215
        return false;
216
    }
217
218
    private void clearLowHealthState() {
219
        pendingLowHealth = false;
220
        armedInPvp = false;
221
        leaveScheduled = false;
222
    }
223
224
    private int currentHealth(LocalPlayer player) {
225
        float hp = player.getHealth();
226
        if (includeAbsorption.get()) {
227
            hp += player.getAbsorptionAmount();
228
        }
229
        return Math.round(hp);
230
    }
231
232
    private void sendKickPackets(long now) {
233
        Connection connection = mc.getConnection().getConnection();
234
        if (connection == null || !connection.isConnected()) {
235
            return;
236
        }
237
238
        int seed = (int) System.nanoTime();
239
        BlinkManager.INSTANCE.sendSilently(new ServerboundPongPacket(seed ^ 0x5A5A5A5A));
240
        BlinkManager.INSTANCE.sendSilently(new ServerboundPongPacket(Integer.MIN_VALUE + (seed & 0xFFFF)));
241
        BlinkManager.INSTANCE.sendSilently(new ServerboundPongPacket(Integer.MAX_VALUE - (seed & 0xFFFF)));
242
243
        packetKickSent = true;
244
        packetFallbackAtMs = now + packetFallbackMs.get();
245
        Notifier.info("KTLeave packet kick sent");
246
    }
247
248
    private void disconnectNormally() {
249
        if (mc.getConnection() == null) {
250
            return;
251
        }
252
        mc.getConnection().getConnection().disconnect(Component.empty());
253
    }
254
255
    private void resetState() {
256
        pendingLowHealth = false;
257
        armedInPvp = false;
258
        leaveScheduled = false;
259
        packetKickSent = false;
260
        manualLeaveScheduled = false;
261
        leaveAtMs = 0L;
262
        manualLeaveAtMs = 0L;
263
        packetFallbackAtMs = 0L;
264
    }
265
266
    public enum Mode implements EnumValue.IdProvider {
267
        LEGIT("legit"),
268
        PACKET_KICK("packet_kick");
269
270
        private final String id;
271
272
        Mode(String id) {
273
            this.id = id;
274
        }
275
276
        @Override
277
        public String id() {
278
            return id;
279
        }
280
    }
281
282
    public enum TotemMode implements EnumValue.IdProvider {
283
        OFF("off"),
284
        AUTO_TOTEM("auto_totem"),
285
        HELD("held"),
286
        INVENTORY("inventory");
287
288
        private final String id;
289
290
        TotemMode(String id) {
291
            this.id = id;
292
        }
293
294
        @Override
295
        public String id() {
296
            return id;
297
        }
298
    }
299
}
300