BetterChat module

BetterChat: Minecraft 26.3 cheat module, full source for every implementation (2 clients: OfflineClient, LiquidBounce (Kotlin)).

2 implementationsMISCRENDER

Full module source: 2 implementations

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

OfflineClientMISCsrc/main/java/com/jellypudding/offlineclient/modules/misc/BetterChat.javaJava · 376 lines · 15.3 KB

Small improvements to the chat box.

SettingsTimestampsShow secondsPlayer headsScrollbarLonger historyHistory sizeKeep historyInfinite chat boxGuard coordinatesAnti clearFilter regexAnnoyFancy chatPrefixRandom prefixPrefix textSmall caps prefixSuffixRandom suffixSuffix textSmall caps suffix
BetterChat.javaJava · Minecraft 26.2 · 376 lines · 15.3 KB · complete file, verbatimOriginal ↗
1
package com.jellypudding.offlineclient.modules.misc;
2
3
import com.jellypudding.offlineclient.event.Subscribe;
4
import com.jellypudding.offlineclient.event.events.ChatSendEvent;
5
import com.jellypudding.offlineclient.module.Category;
6
import com.jellypudding.offlineclient.module.Module;
7
import com.jellypudding.offlineclient.setting.BoolSetting;
8
import com.jellypudding.offlineclient.setting.NumberSetting;
9
import com.jellypudding.offlineclient.setting.TextSetting;
10
import com.jellypudding.offlineclient.util.ChatUtil;
11
import com.jellypudding.offlineclient.util.TextLines;
12
import net.minecraft.ChatFormatting;
13
import net.minecraft.client.gui.GuiGraphicsExtractor;
14
import net.minecraft.client.gui.components.ChatComponent;
15
import net.minecraft.client.gui.components.PlayerFaceExtractor;
16
import net.minecraft.client.multiplayer.PlayerInfo;
17
import net.minecraft.client.multiplayer.chat.GuiMessage;
18
import net.minecraft.network.chat.Component;
19
import net.minecraft.network.chat.MutableComponent;
20
import net.minecraft.network.chat.Style;
21
import net.minecraft.world.entity.player.PlayerSkin;
22
23
import java.time.LocalTime;
24
import java.time.format.DateTimeFormatter;
25
import java.util.ArrayList;
26
import java.util.IdentityHashMap;
27
import java.util.List;
28
import java.util.Map;
29
import java.util.Optional;
30
import java.util.concurrent.ThreadLocalRandom;
31
import java.util.regex.Matcher;
32
import java.util.regex.Pattern;
33
import java.util.regex.PatternSyntaxException;
34
35
// ChatComponentMixin asks this about every line that comes in and about the history size.
36
public final class BetterChat extends Module {
37
38
    private static final int VANILLA_HISTORY = 100;
39
    private static final DateTimeFormatter CLOCK = DateTimeFormatter.ofPattern("HH:mm");
40
    private static final DateTimeFormatter CLOCK_SECONDS = DateTimeFormatter.ofPattern("HH:mm:ss");
41
42
    private static final String PLAIN = "abcdefghijklmnopqrstuvwxyz";
43
    private static final String SMALL = "ᴀʙᴄᴅᴇꜰɢʜɪᴊᴋʟᴍɴᴏᴩqʀꜱᴛᴜᴠᴡxyᴢ";
44
45
    // How much wider the chat gets to fit a head on the left.
46
    private static final int HEAD_ROOM = 10;
47
    private static final int HEAD_SIZE = 8;
48
49
    // Sender lookups remembered per message. Cleared once it outgrows any history.
50
    private static final int HEAD_CACHE = 8192;
51
52
    // A number of three digits or more then one of two or more read as coordinates.
53
    private static final Pattern COORDINATES = Pattern.compile("-?\\d{3,}[\\s,;/]+-?\\d{2,}");
54
55
    // A run of blank lines is what a server sends to push chat off the screen.
56
    private static final Pattern BLANK_RUN = Pattern.compile("\\n(\\n|\\s)+\\n");
57
58
    // Our own clock stamp on the front of a stored line.
59
    private static final Pattern STAMP = Pattern.compile("^\\[\\d{2}:\\d{2}(?::\\d{2})?] ");
60
61
    // The usual server layout for a chat line.
62
    private static final Pattern SENDER = Pattern.compile("^<([^<>]{1,32})>");
63
64
    private final BoolSetting timestamps = new BoolSetting("Timestamps",
65
        "Puts the time in front of every line.", true);
66
    private final BoolSetting showSeconds = new BoolSetting("Show seconds",
67
        "Timestamps carry seconds as well as hours and minutes.", false)
68
        .under(timestamps);
69
    private final BoolSetting playerHeads = new BoolSetting("Player heads",
70
        "Draws the face of the sender in front of their message.", true);
71
    private final BoolSetting scrollbar = new BoolSetting("Scrollbar",
72
        "A bar beside the open chat you can drag or click to scroll.", true);
73
    private final BoolSetting longerHistory = new BoolSetting("Longer history",
74
        "Keeps more lines than the hundred vanilla scrolls back through.", true);
75
    private final NumberSetting historySize = new NumberSetting("History size",
76
        "Lines kept for scrolling back.", 1000, 100, 5000, 100, " lines")
77
        .under(longerHistory);
78
    private final BoolSetting keepHistory = new BoolSetting("Keep history",
79
        "Chat survives a disconnect and the debug clear key.", true);
80
    private final BoolSetting infiniteBox = new BoolSetting("Infinite chat box",
81
        "Lifts the limit on how much you can type into the chat box.", true);
82
    private final BoolSetting guardCoordinates = new BoolSetting("Guard coordinates",
83
        "Holds back a message that looks like coordinates until you send it a second time.",
84
        true);
85
    private final BoolSetting antiClear = new BoolSetting("Anti clear",
86
        "Some servers send a wall of blank lines to push your chat off the screen. This cuts it out.",
87
        true);
88
    private final BoolSetting filterRegex = new BoolSetting("Filter regex",
89
        "Drops any line that matches one of your patterns.", false);
90
    private final TextLines patterns = new TextLines("Patterns",
91
        "How many patterns to match against.").plain().under(filterRegex);
92
93
    private final BoolSetting annoy = new BoolSetting("Annoy",
94
        "Sends your messages in aLtErNaTiNg case.", false);
95
    private final BoolSetting fancy = new BoolSetting("Fancy chat",
96
        "Sends your messages in small caps.", false);
97
98
    private final BoolSetting prefix = new BoolSetting("Prefix",
99
        "Puts something in front of every message you send.", false);
100
    private final BoolSetting prefixRandom = new BoolSetting("Random prefix",
101
        "Uses a random three digit number instead of the text.", false)
102
        .under(prefix);
103
    private final TextSetting prefixText = new TextSetting("Prefix text",
104
        "The text put in front. Click to type it.", "> ")
105
        .under(prefix, () -> prefix.isOn() && !prefixRandom.isOn());
106
    private final BoolSetting prefixSmall = new BoolSetting("Small caps prefix",
107
        "Writes the prefix in small caps.", false)
108
        .under(prefix, () -> prefix.isOn() && !prefixRandom.isOn());
109
110
    private final BoolSetting suffix = new BoolSetting("Suffix",
111
        "Puts something on the end of every message you send.", false);
112
    private final BoolSetting suffixRandom = new BoolSetting("Random suffix",
113
        "Uses a random three digit number instead of the text.", false)
114
        .under(suffix);
115
    private final TextSetting suffixText = new TextSetting("Suffix text",
116
        "The text put on the end. Click to type it.", " | offline")
117
        .under(suffix, () -> suffix.isOn() && !suffixRandom.isOn());
118
    private final BoolSetting suffixSmall = new BoolSetting("Small caps suffix",
119
        "Writes the suffix in small caps.", true)
120
        .under(suffix, () -> suffix.isOn() && !suffixRandom.isOn());
121
122
    private final List<Pattern> compiled = new ArrayList<>();
123
    private String compiledFrom = "";
124
    private String heldBack;
125
126
    // The skin found for each message. A miss is remembered as well and never searched twice.
127
    private final Map<GuiMessage, Optional<PlayerSkin>> heads = new IdentityHashMap<>();
128
129
    // The chat line being drawn. Set by the line consumer just before the text goes out.
130
    private GuiMessage.Line drawing;
131
    private boolean topOfEntry;
132
133
    public BetterChat() {
134
        super("BetterChat", "Small improvements to the chat box.", Category.MISC);
135
        addSettings(timestamps, showSeconds, playerHeads, scrollbar, longerHistory, historySize,
136
            keepHistory, infiniteBox, guardCoordinates, antiClear, filterRegex);
137
        addSettings(patterns.settings());
138
        addSettings(annoy, fancy, prefix, prefixRandom, prefixText, prefixSmall,
139
            suffix, suffixRandom, suffixText, suffixSmall);
140
        searchTags("timestamp", "chat history", "coords", "player heads", "small caps",
141
            "scrollbar");
142
    }
143
144
    // True when a line matches one of the patterns and must never reach the chat.
145
    public boolean filters(Component message) {
146
        if (!isEnabled() || !filterRegex.isOn()) {
147
            return false;
148
        }
149
        String text = message.getString();
150
        for (Pattern pattern : compiledPatterns()) {
151
            if (pattern.matcher(text).find()) {
152
                return true;
153
            }
154
        }
155
        return false;
156
    }
157
158
    // Patterns are rebuilt only after the rows change. A bad one is dropped with a warning.
159
    private List<Pattern> compiledPatterns() {
160
        List<String> rows = patterns.all();
161
        String key = String.join("\n", rows);
162
        if (key.equals(compiledFrom)) {
163
            return compiled;
164
        }
165
        compiledFrom = key;
166
        compiled.clear();
167
        for (String row : rows) {
168
            try {
169
                compiled.add(Pattern.compile(row));
170
            } catch (PatternSyntaxException error) {
171
                ChatUtil.error("That is not a pattern: " + row);
172
            }
173
        }
174
        return compiled;
175
    }
176
177
    public Component decorate(Component message) {
178
        if (!isEnabled()) {
179
            return message;
180
        }
181
        if (antiClear.isOn() && BLANK_RUN.matcher(message.getString()).find()) {
182
            message = collapse(message);
183
        }
184
        if (!timestamps.isOn()) {
185
            return message;
186
        }
187
        String now = LocalTime.now().format(showSeconds.isOn() ? CLOCK_SECONDS : CLOCK);
188
        MutableComponent stamp = Component.literal("[" + now + "] ")
189
            .withStyle(ChatFormatting.DARK_GRAY);
190
        // Both hang off a blank root or the message would inherit the grey of the stamp.
191
        return Component.empty().append(stamp).append(message);
192
    }
193
194
    // Rebuilds the line with every run of blank lines cut down to one break.
195
    private static Component collapse(Component message) {
196
        MutableComponent rebuilt = Component.empty();
197
        message.visit((style, text) -> {
198
            Matcher matcher = BLANK_RUN.matcher(text);
199
            rebuilt.append(Component.literal(matcher.find() ? matcher.replaceAll("\n\n") : text)
200
                .setStyle(style));
201
            return Optional.empty();
202
        }, Style.EMPTY);
203
        return rebuilt;
204
    }
205
206
    public int historyLimit(int vanilla) {
207
        if (!isEnabled() || !longerHistory.isOn()) {
208
            return vanilla;
209
        }
210
        return Math.max(VANILLA_HISTORY, historySize.getInt());
211
    }
212
213
    public boolean keepsHistory() {
214
        return isEnabled() && keepHistory.isOn();
215
    }
216
217
    public boolean liftsBoxLimit() {
218
        return isEnabled() && infiniteBox.isOn();
219
    }
220
221
    public boolean showsScrollbar() {
222
        return isEnabled() && scrollbar.isOn();
223
    }
224
225
    // Player heads.
226
227
    private boolean drawsHeads() {
228
        return isEnabled() && playerHeads.isOn();
229
    }
230
231
    // The chat background grows to fit a head beside a full width line.
232
    public int headRoom(int width) {
233
        return drawsHeads() ? width + HEAD_ROOM : width;
234
    }
235
236
    // Only a line with a head beside it moves across. The rest stay flush with the edge.
237
    public int textStart(int x) {
238
        return drawing != null && headOf(drawing.parent()) != null ? x + HEAD_ROOM : x;
239
    }
240
241
    // The consumer walks the lines from the bottom up. The top line of a message is
242
    // the one below a line that ends the message above it.
243
    public void beginLine(GuiMessage.Line line, int index) {
244
        if (!drawsHeads()) {
245
            return;
246
        }
247
        drawing = line;
248
        ChatComponent chat = mc.gui.hud.getChat();
249
        List<GuiMessage.Line> lines = chat.trimmedMessages;
250
        int above = index + chat.chatScrollbarPos + 1;
251
        topOfEntry = above >= lines.size() || lines.get(above).endOfEntry();
252
    }
253
254
    public void endLine() {
255
        drawing = null;
256
    }
257
258
    public void drawHead(GuiGraphicsExtractor graphics, int y, int colour) {
259
        if (drawing == null || !topOfEntry) {
260
            return;
261
        }
262
        PlayerSkin skin = headOf(drawing.parent());
263
        if (skin != null) {
264
            PlayerFaceExtractor.extractRenderState(graphics, skin, 0, y, HEAD_SIZE, colour);
265
        }
266
    }
267
268
    private PlayerSkin headOf(GuiMessage message) {
269
        if (!drawsHeads()) {
270
            return null;
271
        }
272
        if (heads.size() > HEAD_CACHE) {
273
            heads.clear();
274
        }
275
        return heads.computeIfAbsent(message, m -> Optional.ofNullable(senderSkin(m))).orElse(null);
276
    }
277
278
    // The sender is the name in the usual <name> opening or failing that the first
279
    // online player named in the line. That covers servers that dress names up.
280
    private static PlayerSkin senderSkin(GuiMessage message) {
281
        if (mc.getConnection() == null) {
282
            return null;
283
        }
284
        String text = STAMP.matcher(message.content().getString()).replaceFirst("").trim();
285
        Matcher matcher = SENDER.matcher(text);
286
        if (matcher.find()) {
287
            PlayerInfo info = mc.getConnection().getPlayerInfoIgnoreCase(matcher.group(1));
288
            return info == null ? null : info.getSkin();
289
        }
290
        PlayerInfo first = null;
291
        int earliest = Integer.MAX_VALUE;
292
        for (PlayerInfo info : mc.getConnection().getOnlinePlayers()) {
293
            int at = ChatUtil.wholeWordIndex(text, info.getProfile().name(), 0);
294
            if (at != -1 && at < earliest) {
295
                earliest = at;
296
                first = info;
297
            }
298
        }
299
        return first == null ? null : first.getSkin();
300
    }
301
302
    // Sending.
303
304
    // The text to send in place of what was typed. Commands are left alone.
305
    public String rewrite(String message) {
306
        if (!isEnabled() || message.startsWith("/")) {
307
            return message;
308
        }
309
        String body = message;
310
        if (annoy.isOn()) {
311
            body = alternate(body);
312
        }
313
        if (fancy.isOn()) {
314
            body = smallCaps(body);
315
        }
316
        return affix(prefix, prefixRandom, prefixText, prefixSmall) + body
317
            + affix(suffix, suffixRandom, suffixText, suffixSmall);
318
    }
319
320
    private static String affix(BoolSetting on, BoolSetting random, TextSetting text,
321
                                BoolSetting small) {
322
        if (!on.isOn()) {
323
            return "";
324
        }
325
        if (random.isOn()) {
326
            return String.format("(%03d) ", ThreadLocalRandom.current().nextInt(1000));
327
        }
328
        return small.isOn() ? smallCaps(text.getValue()) : text.getValue();
329
    }
330
331
    private static String alternate(String message) {
332
        StringBuilder out = new StringBuilder(message.length());
333
        boolean upper = true;
334
        for (int point : message.codePoints().toArray()) {
335
            out.appendCodePoint(upper ? Character.toUpperCase(point) : Character.toLowerCase(point));
336
            upper = !upper;
337
        }
338
        return out.toString();
339
    }
340
341
    private static String smallCaps(String message) {
342
        StringBuilder out = new StringBuilder(message.length());
343
        for (char letter : message.toCharArray()) {
344
            int at = PLAIN.indexOf(Character.toLowerCase(letter));
345
            out.append(at == -1 ? letter : SMALL.charAt(at));
346
        }
347
        return out.toString();
348
    }
349
350
    @Subscribe
351
    private void onChatSend(ChatSendEvent event) {
352
        if (!guardCoordinates.isOn()) {
353
            return;
354
        }
355
        String message = event.getMessage();
356
        if (message.startsWith("/") || !COORDINATES.matcher(message).find()) {
357
            return;
358
        }
359
        // The same text sent twice goes through. That is the second look asked for.
360
        if (message.equals(heldBack)) {
361
            heldBack = null;
362
            return;
363
        }
364
        heldBack = message;
365
        event.cancel();
366
        ChatUtil.message("That looks like coordinates. Send it again if you mean it.");
367
    }
368
369
    @Override
370
    protected void onDisable() {
371
        heldBack = null;
372
        drawing = null;
373
        heads.clear();
374
    }
375
}
376
LiquidBounce (Kotlin)RENDERsrc/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/misc/betterchat/ModuleBetterChat.ktKotlin · 258 lines · 8.6 KB

Improvements to the in-game chat.

SettingsFeaturesPrefixSuffixNotifyHighlight
ModuleBetterChat.ktKotlin · Minecraft 26.2 · 258 lines · 8.6 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.misc.betterchat
20
21
import com.mojang.blaze3d.platform.InputConstants
22
import net.ccbluex.liquidbounce.config.types.group.ToggleableValueGroup
23
import net.ccbluex.liquidbounce.config.types.list.Tagged
24
import net.ccbluex.liquidbounce.event.events.ChatReceiveEvent
25
import net.ccbluex.liquidbounce.event.events.KeyboardKeyEvent
26
import net.ccbluex.liquidbounce.event.events.NotificationEvent
27
import net.ccbluex.liquidbounce.event.handler
28
import net.ccbluex.liquidbounce.event.suspendHandler
29
import net.ccbluex.liquidbounce.features.command.CommandManager
30
import net.ccbluex.liquidbounce.features.global.GlobalSettingsAutoTranslate
31
import net.ccbluex.liquidbounce.features.module.ClientModule
32
import net.ccbluex.liquidbounce.features.module.ModuleCategories
33
import net.ccbluex.liquidbounce.interfaces.GuiMessageLineAddition
34
import net.ccbluex.liquidbounce.utils.client.MessageMetadata
35
import net.ccbluex.liquidbounce.utils.client.chat
36
import net.ccbluex.liquidbounce.utils.client.notification
37
import net.ccbluex.liquidbounce.utils.client.openChat
38
import net.ccbluex.liquidbounce.utils.text.stripMinecraftColorCodes
39
import net.ccbluex.liquidbounce.utils.collection.Pools
40
import net.minecraft.client.gui.screens.DeathScreen
41
import net.minecraft.client.multiplayer.chat.GuiMessage
42
import net.minecraft.util.FormattedCharSink
43
44
/**
45
 * BetterChat Module
46
 *
47
 * Quality of life improvements to the in-game chat.
48
 */
49
object ModuleBetterChat : ClientModule("BetterChat", ModuleCategories.RENDER, aliases = listOf("AntiSpam")) {
50
    private val features by multiEnumChoice("Features",
51
        Features.INFINITE,
52
        Features.ANTI_CLEAR,
53
        Features.KEEP_AFTER_DEATH
54
    )
55
56
    val infiniteLength get() = Features.INFINITE in features
57
    val antiClear get() = Features.ANTI_CLEAR in features
58
59
    /**
60
     * Allows you to transform your message text to Unicode.
61
     */
62
    private val forceUnicodeChat get() = Features.FORCE_UNICODE_CHAT in features
63
64
    /**
65
     * Allows you to use the chat on the death screen.
66
     */
67
    private val keepAfterDeath get() = Features.KEEP_AFTER_DEATH in features
68
69
    private object AppendPrefix : MessageModifier("AppendPrefix", false) {
70
        val prefix by text("Prefix", "> ")
71
72
        override fun getMessage(content: String) = prefix + content
73
    }
74
75
    private object AppendSuffix : MessageModifier("AppendSuffix", false) {
76
        val suffix by text("Suffix", " | \uD835\uDE7B\uD835\uDE92\uD835\uDE9A\uD835\uDE9E" +
77
            "\uD835\uDE92\uD835\uDE8D\uD835\uDE71\uD835\uDE98\uD835\uDE9E\uD835\uDE97\uD835\uDE8C\uD835\uDE8E")
78
79
        override fun getMessage(content: String) = content + suffix
80
    }
81
82
    private val autoTranslate by multiEnumChoice<ChatReceiveEvent.ChatType>("AutoTranslate")
83
84
    object Copy : ToggleableValueGroup(this, "Copy", true) {
85
        private val notify by boolean("Notify", true)
86
        val highlight by boolean("Highlight", true)
87
88
        @JvmStatic
89
        fun copyMessage(parts: List<GuiMessage.Line>, button: Int) {
90
            val content = Pools.buildStringPooled {
91
                val visitor = FormattedCharSink { _, _, codePoint ->
92
                    appendCodePoint(codePoint)
93
                    true
94
                }
95
96
                for (line in parts) {
97
                    line.content().accept(visitor)
98
                }
99
            }
100
101
            if ((InputConstants.isKeyDown(mc.window, InputConstants.KEY_LSHIFT)
102
                    || InputConstants.isKeyDown(mc.window, InputConstants.KEY_RSHIFT))
103
                && button == InputConstants.MOUSE_BUTTON_LEFT
104
            ) {
105
                mc.keyboardHandler.clipboard = content
106
107
                if (notify) {
108
                    notification(
109
                        "ChatCopy",
110
                        "The line is copied",
111
                        NotificationEvent.Severity.SUCCESS
112
                    )
113
                }
114
            } else if (button == InputConstants.MOUSE_BUTTON_RIGHT) {
115
                mc.openChat(content)
116
            }
117
        }
118
119
    }
120
121
    init {
122
        tree(AppendPrefix)
123
        tree(AppendSuffix)
124
        tree(AntiSpam)
125
        tree(Copy)
126
    }
127
128
    var antiChatClearPaused = false
129
130
    @Suppress("unused")
131
    private val keyboardKeyHandler = handler<KeyboardKeyEvent> {
132
        if (keepAfterDeath && mc.gui.screen() !is DeathScreen) {
133
            return@handler
134
        }
135
136
        val options = mc.options
137
        val prefix = CommandManager.GlobalSettings.prefix[0]
138
        when (it.keyCode) {
139
            options.keyChat.key.value -> mc.openChat("")
140
            options.keyCommand.key.value -> mc.openChat("/")
141
            prefix.code -> mc.openChat(prefix.toString())
142
        }
143
    }
144
145
    @Suppress("unused")
146
    private val chatReceiveHandler = suspendHandler<ChatReceiveEvent> { event ->
147
        if (event.type !in autoTranslate) {
148
            return@suspendHandler
149
        }
150
151
        val plainMessage = event.message.stripMinecraftColorCodes()
152
        if (plainMessage.isBlank()) {
153
            return@suspendHandler
154
        }
155
156
        val result = GlobalSettingsAutoTranslate.translate(text = plainMessage)
157
        if (result.isValid) {
158
            chat(
159
                result.toResultText(),
160
                metadata = MessageMetadata(prefix = false)
161
            )
162
        }
163
    }
164
165
    fun modifyMessage(content: String): String {
166
        if (!running) {
167
            return content
168
        }
169
170
        val result = if (forceUnicodeChat) {
171
            applyUnicodeTransformation(content)
172
        } else {
173
            content
174
        }
175
176
        return AppendSuffix.modifyMessage(AppendPrefix.modifyMessage(result))
177
    }
178
179
    private fun applyUnicodeTransformation(content: String): String {
180
        return buildString {
181
            for (c in content) {
182
                if (c.code in 33..128) {
183
                    append(Character.toChars(c.code + 65248))
184
                } else {
185
                    append(c)
186
                }
187
            }
188
        }
189
    }
190
191
    private sealed class MessageModifier(
192
        name: String,
193
        enabled: Boolean
194
    ) : ToggleableValueGroup(this, name, enabled) {
195
        fun modifyMessage(content: String) =
196
            if (!this.enabled) {
197
                content
198
            } else {
199
                getMessage(content)
200
            }
201
202
        abstract fun getMessage(content: String): String
203
    }
204
205
    @Suppress("unused")
206
    private enum class Features(override val tag: String) : Tagged {
207
        INFINITE("Infinite"),
208
        ANTI_CLEAR("AntiClear"),
209
        KEEP_AFTER_DEATH("KeepAfterDeath"),
210
        FORCE_UNICODE_CHAT("ForceUnicodeChat")
211
    }
212
213
    /**
214
     * Resolves the contiguous wrapped-line range for the message at [index].
215
     */
216
    @Suppress("CAST_NEVER_SUCCEEDS")
217
    @JvmStatic
218
    fun resolveMessageBounds(visibleMessages: List<GuiMessage.Line>, index: Int): IntRange {
219
        val id = (visibleMessages[index] as GuiMessageLineAddition).`liquid_bounce$getId`()
220
221
        if (id != null) {
222
            var start = index
223
            while (start > 0) {
224
                val previousId = (visibleMessages[start - 1] as GuiMessageLineAddition).`liquid_bounce$getId`()
225
                if (id != previousId) {
226
                    break
227
                }
228
                start--
229
            }
230
231
            var end = index
232
            val lastIndex = visibleMessages.size - 1
233
            while (end < lastIndex) {
234
                val nextId = (visibleMessages[end + 1] as GuiMessageLineAddition).`liquid_bounce$getId`()
235
                if (id != nextId) {
236
                    break
237
                }
238
                end++
239
            }
240
241
            return start..end
242
        }
243
244
        var start = index
245
        while (start > 0 && !visibleMessages[start].endOfEntry()) {
246
            start--
247
        }
248
249
        var end = index
250
        val lastIndex = visibleMessages.size - 1
251
        while (end < lastIndex && !visibleMessages[end + 1].endOfEntry()) {
252
            end++
253
        }
254
255
        return start..end
256
    }
257
}
258