AntiExploit module

AntiExploit: Minecraft 26.3 cheat module, full source for every implementation (1 client: LiquidBounce (Kotlin)).

1 implementationPLAYER

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.

LiquidBounce (Kotlin)PLAYERsrc/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/player/ModuleAntiExploit.ktKotlin · 135 lines · 4.9 KB

Prevents the server from exploiting client-side bugs.

SettingsCancelDemoIgnoreProtocolKickObfuscatedMaxLengthVFPScoreboardFix
ModuleAntiExploit.ktKotlin · Minecraft 26.2 · 135 lines · 4.9 KB · complete file, verbatimOriginal ↗
1
/*
2
 * This file is part of LiquidBounce (https://github.com/CCBlueX/LiquidBounce)
3
 *
4
 * Copyright (c) 2015 - 2026 CCBlueX
5
 *
6
 * LiquidBounce is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * LiquidBounce is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with LiquidBounce. If not, see <https://www.gnu.org/licenses/>.
18
 */
19
package net.ccbluex.liquidbounce.features.module.modules.player
20
21
import net.ccbluex.fastutil.enumMapOf
22
import net.ccbluex.fastutil.enumSetAllOf
23
import net.ccbluex.liquidbounce.config.types.group.ToggleableValueGroup
24
import net.ccbluex.liquidbounce.config.types.list.Tagged
25
import net.ccbluex.liquidbounce.event.events.ChatReceiveEvent
26
import net.ccbluex.liquidbounce.event.events.NotificationEvent
27
import net.ccbluex.liquidbounce.event.handler
28
import net.ccbluex.liquidbounce.features.module.ClientModule
29
import net.ccbluex.liquidbounce.features.module.ModuleCategories
30
import net.ccbluex.liquidbounce.injection.mixins.minecraft.gui.MixinScoreboard
31
import net.ccbluex.liquidbounce.utils.client.notification
32
import net.ccbluex.liquidbounce.utils.text.mapComponent
33
import net.minecraft.network.chat.Component
34
import net.minecraft.network.chat.FormattedText
35
import net.minecraft.network.chat.Style
36
import java.util.Optional
37
38
/**
39
 * AntiExploit module
40
 *
41
 * Prevents exploits (and bugs).
42
 */
43
object ModuleAntiExploit : ClientModule("AntiExploit", ModuleCategories.PLAYER) {
44
    private val limits = multiEnumChoice("Limit", enumSetAllOf<Limit>())
45
    val cancelDemo by boolean("CancelDemo", true)
46
    val ignoreProtocol by boolean("IgnoreProtocolKick", true)
47
    private val maxObfuscatedLength by int("ObfuscatedMaxLength", 128, 32..1024, "chars")
48
49
    private object Notify : ToggleableValueGroup(this, "Notify", true) {
50
        private val notifiedTime = enumMapOf<Limit, Long>()
51
52
        fun canNotify(type: Limit?): Boolean {
53
            if (!enabled) return false
54
            if (type == null) return true
55
56
            val now = System.currentTimeMillis()
57
            val prev = notifiedTime[type]
58
            if (prev != null && now - prev < type.notifyCooldown) return false
59
            notifiedTime[type] = now
60
            return true
61
        }
62
    }
63
64
    /**
65
     * Implemented in [MixinScoreboard].
66
     */
67
    val vfpScoreboardFix by boolean("VFPScoreboardFix", false)
68
69
    private val chatHandler = handler<ChatReceiveEvent> { event ->
70
        if (hasBlockedObfuscatedText(event.textData)) {
71
            notifyAboutObfuscatedText()
72
            event.cancelEvent()
73
        }
74
    }
75
76
    /**
77
     * If [component] contains a too long run of obfuscated (`§k`) text, returns a sanitized copy with the obfuscation
78
     * stripped so it can still be displayed. Returns null if nothing needs to be limited.
79
     */
80
    fun unobfuscateIfNeeded(component: Component): Component? {
81
        if (!hasBlockedObfuscatedText(component)) {
82
            return null
83
        }
84
85
        notifyAboutObfuscatedText()
86
        return component.mapComponent(styleMapper = { if (it.isObfuscated) it.withObfuscated(false) else it })
87
    }
88
89
    private fun hasBlockedObfuscatedText(component: Component): Boolean =
90
        canLimit(Limit.OBFUSCATED_MESSAGE) && component.hasLongObfuscatedRun(maxObfuscatedLength)
91
92
    private fun notifyAboutObfuscatedText() {
93
        notify(Limit.OBFUSCATED_MESSAGE, "Blocked text with too long obfuscated text", false)
94
    }
95
96
    fun notify(type: Limit?, message: String, crashAttempt: Boolean) {
97
        if (Notify.canNotify(type)) {
98
            notification(
99
                this.name,
100
                message,
101
                if (crashAttempt) NotificationEvent.Severity.ERROR else NotificationEvent.Severity.INFO
102
            )
103
        }
104
    }
105
106
    @JvmStatic
107
    fun canLimit(limit: Limit): Boolean = running && limit in limits
108
}
109
110
enum class Limit(override val tag: String, val notifyCooldown: Long = 1_000L) : Tagged {
111
    EXPLOSION_STRENGTH("ExplosionStrength"),
112
    PARTICLES_AMOUNT("ParticlesAmount"),
113
    PARTICLES_SPEED("ParticlesSpeed"),
114
    OBFUSCATED_MESSAGE("ObfuscatedMessage", 10_000L),
115
}
116
117
/**
118
 * Returns whether at least [maxLength] consecutive obfuscated (`§k`) characters appear in this component.
119
 */
120
private fun Component.hasLongObfuscatedRun(maxLength: Int): Boolean {
121
    var run = 0
122
    return visit({ style, text ->
123
        if (style.isObfuscated) {
124
            run += text.length
125
            if (run >= maxLength) {
126
                return@visit FormattedText.STOP_ITERATION
127
            }
128
        } else {
129
            run = 0
130
        }
131
132
        Optional.empty()
133
    }, Style.EMPTY).isPresent
134
}
135