NameProtect module

NameProtect: Minecraft 26.3 cheat module, full source for every implementation (3 clients: MelaHack (ThunderHack fork), OfflineClient, LiquidBounce

3 implementationsMISC

Full module source: 3 implementations

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

MelaHack (ThunderHack fork)MISCsrc/main/java/thunder/hack/features/modules/misc/NameProtect.javaJava · 18 lines · 653 B

Hides your nickname.

SettingsnameHide friends
NameProtect.javaJava · Minecraft 26.2 · 18 lines · 653 B · complete file, verbatimOriginal ↗
1
package thunder.hack.features.modules.misc;
2
3
import thunder.hack.core.manager.client.ModuleManager;
4
import thunder.hack.features.modules.Module;
5
import thunder.hack.setting.Setting;
6
7
public class NameProtect extends Module {
8
    public NameProtect() {
9
        super("NameProtect", Category.MISC);
10
    }
11
12
    public static Setting<String> newName = new Setting<>("name", "Hell_Raider");
13
    public static Setting<Boolean> hideFriends = new Setting<>("Hide friends", true);
14
15
    public static String getCustomName() {
16
        return ModuleManager.nameProtect.isEnabled() ? newName.getValue().replaceAll("&", "\u00a7") : mc.getGameProfile().name();
17
    }
18
}
OfflineClientMISCsrc/main/java/com/jellypudding/offlineclient/modules/misc/NameProtect.javaJava · 217 lines · 8.5 KB

Hides your own name and renames other players on your screen.

SettingsPlayerShown asPaintColourRename yourselfAliasColour itHide skinsRenamesRename everyone
NameProtect.javaJava · Minecraft 26.2 · 217 lines · 8.5 KB · complete file, verbatimOriginal ↗
1
package com.jellypudding.offlineclient.modules.misc;
2
3
import com.jellypudding.offlineclient.module.Category;
4
import com.jellypudding.offlineclient.module.Module;
5
import com.jellypudding.offlineclient.setting.BoolSetting;
6
import com.jellypudding.offlineclient.setting.ColorSetting;
7
import com.jellypudding.offlineclient.setting.NumberSetting;
8
import com.jellypudding.offlineclient.setting.TextSetting;
9
import com.jellypudding.offlineclient.util.ChatUtil;
10
import net.minecraft.client.multiplayer.PlayerInfo;
11
import net.minecraft.network.chat.Component;
12
import net.minecraft.network.chat.MutableComponent;
13
import net.minecraft.network.chat.Style;
14
import net.minecraft.network.chat.TextColor;
15
16
import java.util.ArrayList;
17
import java.util.Comparator;
18
import java.util.HashMap;
19
import java.util.List;
20
import java.util.Map;
21
import java.util.Optional;
22
23
// Renames are client side only. Nobody else on the server sees them.
24
// Chat and the tab list and the name tags and tracers all ask this for the display name.
25
public final class NameProtect extends Module {
26
27
    private static final String DEFAULT_ALIAS = "Player";
28
29
    // How many other players can be renamed one by one.
30
    private static final int SLOTS = 16;
31
32
    // One name swapped for another. A null colour keeps whatever style the text had.
33
    private record Rename(String from, String to, Integer colour) {
34
    }
35
36
    // The settings for one renamed player. The name row folds the rest away.
37
    private static final class Slot {
38
39
        final TextSetting player;
40
        final TextSetting shownAs;
41
        final BoolSetting paint;
42
        final ColorSetting colour;
43
44
        Slot(int number, NumberSetting count) {
45
            int slot = number - 1;
46
            player = new TextSetting("Player " + number, "Their real name. Click to type it.", "")
47
                .visibleWhen(() -> slot < count.getInt());
48
            shownAs = new TextSetting("Shown as " + number, "What their name becomes. Click to type it.",
49
                "")
50
                .under(player, () -> slot < count.getInt());
51
            paint = new BoolSetting("Paint " + number, "Gives the new name a colour of its own.",
52
                false)
53
                .under(player, () -> slot < count.getInt());
54
            colour = new ColorSetting("Colour " + number, "The colour that name is painted.",
55
                140, false)
56
                .under(paint, () -> slot < count.getInt() && paint.isOn());
57
        }
58
59
        // Null whilst either box is blank.
60
        Rename rename() {
61
            if (player.isBlank() || shownAs.isBlank()) {
62
                return null;
63
            }
64
            return new Rename(player.getValue().trim(), shownAs.getValue().trim(),
65
                paint.isOn() ? colour.getColor() : null);
66
        }
67
    }
68
69
    private final BoolSetting renameSelf = new BoolSetting("Rename yourself",
70
        "Swaps your own name for the alias.", true);
71
    private final TextSetting alias = new TextSetting("Alias",
72
        "The name shown instead of yours.", DEFAULT_ALIAS).under(renameSelf);
73
    private final BoolSetting colored = new BoolSetting("Colour it",
74
        "Paints your name to make it easy to pick out.", false).under(renameSelf);
75
    private final ColorSetting color = new ColorSetting("Colour",
76
        "The colour your name is painted.", 140, false)
77
        .under(colored);
78
    private final BoolSetting hideSkins = new BoolSetting("Hide skins",
79
        "Draws everyone with the default skin. Nobody is recognised on a stream.", false);
80
    private final NumberSetting renameCount = new NumberSetting("Renames",
81
        "How many other players get a name of your choosing. A row opens for each.",
82
        0, 0, SLOTS, 1).min(0).max(SLOTS);
83
    private final Slot[] slots = new Slot[SLOTS];
84
    private final BoolSetting renameAll = new BoolSetting("Rename everyone",
85
        "Renames every other player on your screen to Player1 and Player2 and so on.", false);
86
87
    // The number handed to each player the blanket rename has met.
88
    private final Map<String, String> numbered = new HashMap<>();
89
90
    public NameProtect() {
91
        super("NameProtect", "Hides your own name and renames other players on your screen.",
92
            Category.MISC);
93
        addSettings(renameSelf, alias, colored, color, hideSkins, renameCount);
94
        for (int i = 0; i < SLOTS; i++) {
95
            slots[i] = new Slot(i + 1, renameCount);
96
            addSettings(slots[i].player, slots[i].shownAs, slots[i].paint, slots[i].colour);
97
        }
98
        addSettings(renameAll);
99
        searchTags("hide name", "stream", "colour name", "rename", "alias");
100
    }
101
102
    @Override
103
    protected void onDisable() {
104
        numbered.clear();
105
    }
106
107
    // Read by AbstractClientPlayerMixin for every skin lookup.
108
    public boolean hidesSkins() {
109
        return hideSkins.isOn();
110
    }
111
112
    // What the name reads as on this screen. Unchanged whilst the module is off.
113
    public String display(String name) {
114
        if (!isEnabled()) {
115
            return name;
116
        }
117
        for (Rename rename : renames()) {
118
            if (rename.from().equals(name)) {
119
                return rename.to();
120
            }
121
        }
122
        return name;
123
    }
124
125
    // The same player keeps the same number for as long as the module is on.
126
    private String numberFor(String name) {
127
        String found = numbered.get(name);
128
        if (found == null) {
129
            found = DEFAULT_ALIAS + (numbered.size() + 1);
130
            numbered.put(name, found);
131
        }
132
        return found;
133
    }
134
135
    private boolean isOwn(String name) {
136
        return mc.getUser() != null && mc.getUser().getName().equals(name);
137
    }
138
139
    private String ownAlias() {
140
        return alias.isBlank() ? DEFAULT_ALIAS : alias.getValue().trim();
141
    }
142
143
    // Every rename to apply. Longer names go first. A name that starts with
144
    // another one is then never half swapped.
145
    private List<Rename> renames() {
146
        List<Rename> all = new ArrayList<>();
147
        if (renameSelf.isOn() && mc.getUser() != null) {
148
            all.add(new Rename(mc.getUser().getName(), ownAlias(),
149
                colored.isOn() ? color.getColor() : null));
150
        }
151
        for (Slot slot : slots) {
152
            Rename rename = slot.rename();
153
            if (rename != null && !isOwn(rename.from())) {
154
                all.add(rename);
155
            }
156
        }
157
        if (renameAll.isOn() && mc.getConnection() != null) {
158
            for (PlayerInfo info : mc.getConnection().getOnlinePlayers()) {
159
                String name = info.getProfile().name();
160
                if (!isOwn(name) && all.stream().noneMatch(rename -> rename.from().equals(name))) {
161
                    all.add(new Rename(name, numberFor(name), null));
162
                }
163
            }
164
        }
165
        all.sort(Comparator.comparingInt((Rename rename) -> rename.from().length()).reversed());
166
        return all;
167
    }
168
169
    // Styles and click actions survive. A painted rename takes its colour and nothing else.
170
    public Component filter(Component message) {
171
        if (!isEnabled()) {
172
            return message;
173
        }
174
        List<Rename> renames = renames();
175
        String text = message.getString();
176
        if (renames.stream().noneMatch(rename -> text.contains(rename.from()))) {
177
            return message;
178
        }
179
        MutableComponent result = Component.empty();
180
        message.visit((style, part) -> {
181
            append(result, part, style, renames);
182
            return Optional.empty();
183
        }, Style.EMPTY);
184
        return result;
185
    }
186
187
    // Copies the text across with every whole word rename swapped in.
188
    private static void append(MutableComponent result, String text, Style style,
189
                               List<Rename> renames) {
190
        int from = 0;
191
        while (true) {
192
            Rename hit = null;
193
            int at = -1;
194
            for (Rename rename : renames) {
195
                int found = ChatUtil.wholeWordIndex(text, rename.from(), from);
196
                if (found != -1 && (at == -1 || found < at)) {
197
                    at = found;
198
                    hit = rename;
199
                }
200
            }
201
            if (hit == null) {
202
                break;
203
            }
204
            if (at > from) {
205
                result.append(Component.literal(text.substring(from, at)).setStyle(style));
206
            }
207
            Style painted = hit.colour() == null ? style
208
                : style.withColor(TextColor.fromRgb(hit.colour() & 0xFFFFFF));
209
            result.append(Component.literal(hit.to()).setStyle(painted));
210
            from = at + hit.from().length();
211
        }
212
        if (from < text.length()) {
213
            result.append(Component.literal(text.substring(from)).setStyle(style));
214
        }
215
    }
216
}
217
LiquidBounce (Kotlin)MISCsrc/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/misc/nameprotect/ModuleNameProtect.ktKotlin · 289 lines · 9.8 KB

Hides the player's real username client-side (useful for videos).

SettingsReplacement
ModuleNameProtect.ktKotlin · Minecraft 26.2 · 289 lines · 9.8 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.nameprotect
20
21
import it.unimi.dsi.fastutil.objects.ObjectArrayList
22
import net.ccbluex.fastutil.LfuCache
23
import net.ccbluex.fastutil.Pool
24
import net.ccbluex.fastutil.Pool.Companion.use
25
import net.ccbluex.liquidbounce.config.types.group.ToggleableValueGroup
26
import net.ccbluex.liquidbounce.event.events.GameTickEvent
27
import net.ccbluex.liquidbounce.event.handler
28
import net.ccbluex.liquidbounce.features.misc.FriendManager
29
import net.ccbluex.liquidbounce.features.module.ClientModule
30
import net.ccbluex.liquidbounce.features.module.ModuleCategories
31
import net.ccbluex.liquidbounce.render.GenericColorMode
32
import net.ccbluex.liquidbounce.render.GenericRainbowColorMode
33
import net.ccbluex.liquidbounce.render.GenericStaticColorMode
34
import net.ccbluex.liquidbounce.render.engine.type.Color4b
35
import net.ccbluex.liquidbounce.utils.client.bypassesNameProtection
36
import net.ccbluex.liquidbounce.utils.text.toText
37
import net.ccbluex.liquidbounce.utils.collection.Pools
38
import net.minecraft.network.chat.Component
39
import net.minecraft.network.chat.Style
40
import net.minecraft.util.FormattedCharSequence
41
import net.minecraft.util.FormattedCharSink
42
import net.minecraft.util.StringDecomposer
43
44
private const val DEFAULT_CACHE_SIZE = 512
45
46
/**
47
 * NameProtect module
48
 *
49
 * Changes players names clientside.
50
 */
51
52
object ModuleNameProtect : ClientModule("NameProtect", ModuleCategories.MISC) {
53
54
    private val replacement by text("Replacement", "You")
55
56
    private val colorMode = choices<GenericColorMode<Unit>>(
57
        "ColorMode",
58
        0
59
    ) {
60
        arrayOf(GenericStaticColorMode(it, Color4b(255, 179, 72, 50)), GenericRainbowColorMode(it))
61
    }
62
63
    private object ReplaceFriendNames : ToggleableValueGroup(this, "ObfuscateFriends", true) {
64
        val colorMode = modes<GenericColorMode<Unit>>(
65
            ReplaceFriendNames,
66
            "ColorMode",
67
            0
68
        ) {
69
            arrayOf(GenericStaticColorMode(it, Color4b(0, 241, 255)), GenericRainbowColorMode(it))
70
        }
71
    }
72
73
    private object ReplaceOthers : ToggleableValueGroup(this, "ObfuscateOthers", false) {
74
        val colorMode = modes<GenericColorMode<Unit>>(
75
            ReplaceOthers,
76
            "ColorMode",
77
            0
78
        ) {
79
            arrayOf(GenericStaticColorMode(it, Color4b(71, 71, 71)), GenericRainbowColorMode(it))
80
        }
81
    }
82
83
    init {
84
        tree(ReplaceFriendNames)
85
        tree(ReplaceOthers)
86
87
        // Entirely keep out from public config
88
        doNotIncludeAlways()
89
    }
90
91
    private val replacementMappings = NameProtectMappings()
92
93
    private val coloringInfo = NameProtectMappings.ColoringInfo(
94
        username = { this.colorMode.activeMode.getColor(Unit) },
95
        friends = { ReplaceFriendNames.colorMode.activeMode.getColor(Unit) },
96
        otherPlayers = { ReplaceOthers.colorMode.activeMode.getColor(Unit) },
97
    )
98
99
    @Suppress("unused")
100
    private val renderHandler = handler<GameTickEvent> {
101
        val friendMappings = if (ReplaceFriendNames.enabled) {
102
            FriendManager.friends.filter { it.name.isNotBlank() }.mapIndexed { id, friend ->
103
                friend.name to (friend.alias ?: friend.getDefaultName(id))
104
            }
105
        } else {
106
            emptyList()
107
        }
108
109
        val playerName = player.gameProfile.name ?: mc.user.name
110
111
        val otherPlayers = if (ReplaceOthers.enabled) {
112
            network.onlinePlayers.mapNotNull { playerListEntry ->
113
                val otherName = playerListEntry.profile.name
114
115
                if (otherName != playerName) otherName else null
116
            }
117
        } else { null } ?: emptyList()
118
119
        this.replacementMappings.update(
120
            playerName to this.replacement,
121
            friendMappings,
122
            otherPlayers,
123
            coloringInfo
124
        )
125
    }
126
127
    private val stringMappingCache =
128
        LfuCache<String, String>(DEFAULT_CACHE_SIZE)
129
    private val orderedTextMappingCache =
130
        LfuCache<FormattedCharSequence, WrappedOrderedText>(DEFAULT_CACHE_SIZE) { _, v ->
131
            mappedCharListPool.recycle(v.mappedCharacters)
132
        }
133
    private val mappedCharListPool = Pool(
134
        initializer = { ObjectArrayList(128) },
135
        finalizer = ObjectArrayList<MappedCharacter>::clear,
136
    ).synchronized()
137
138
    fun replace(original: String): String =
139
        when {
140
            !running -> original
141
            mc.isSameThread -> stringMappingCache.getOrPut(original) { uncachedReplace(original) }
142
            else -> uncachedReplace(original)
143
        }
144
145
    private fun uncachedReplace(original: String): String {
146
        val replacements = replacementMappings.findReplacements(original)
147
148
        if (replacements.isEmpty()) {
149
            return original
150
        }
151
152
        return Pools.buildStringPooled {
153
            var currReplacementIndex = 0
154
            var currentIndex = 0
155
156
            while (currentIndex < original.length) {
157
                val replacement = replacements.getOrNull(currReplacementIndex)
158
159
                val replacementStartIdx = replacement?.first?.start
160
161
                if (replacementStartIdx == currentIndex) {
162
                    append(replacement.second.newName)
163
164
                    currentIndex = replacement.first.end + 1
165
                    currReplacementIndex += 1
166
                } else {
167
                    val maxCopyIdx = replacementStartIdx ?: original.length
168
169
                    append(original, currentIndex, maxCopyIdx)
170
171
                    currentIndex = maxCopyIdx
172
                }
173
            }
174
        }
175
    }
176
177
    fun wrap(original: FormattedCharSequence): FormattedCharSequence =
178
        when {
179
            !running -> original
180
            mc.isSameThread -> orderedTextMappingCache.getOrPut(original) { uncachedWrap(original) }
181
            else -> uncachedWrap(original)
182
        }
183
184
    /**
185
     * Wraps an [FormattedCharSequence] to apply name protection.
186
     */
187
    private fun uncachedWrap(original: FormattedCharSequence): WrappedOrderedText {
188
        val mappedCharacters = mappedCharListPool.borrow()
189
190
        val originalCharacters = mappedCharListPool.borrow()
191
192
        original.accept { _, style, codePoint ->
193
            originalCharacters += MappedCharacter(
194
                style,
195
                style.color?.bypassesNameProtection ?: false,
196
                codePoint
197
            )
198
199
            true
200
        }
201
202
        val replacements = Pools.StringBuilder.use {
203
            it.ensureCapacity(originalCharacters.size)
204
            for (c in originalCharacters) {
205
                it.appendCodePoint(c.codePoint)
206
            }
207
            replacementMappings.findReplacements(it)
208
        }
209
210
        var currReplacementIndex = 0
211
        var currentIndex = 0
212
213
        while (currentIndex < originalCharacters.size) {
214
            val replacement = replacements.getOrNull(currReplacementIndex)
215
216
            val replacementStartIdx = replacement?.first?.start
217
218
            if (replacementStartIdx == currentIndex) {
219
                if (originalCharacters[replacementStartIdx].bypassesNameProtection) {
220
                    currReplacementIndex++
221
222
                    continue
223
                }
224
225
                val color = replacement.second.colorGetter()
226
227
                mappedCharacters.ensureCapacity(mappedCharacters.size + replacement.second.newName.length)
228
                replacement.second.newName.mapTo(mappedCharacters) { ch ->
229
                    MappedCharacter(
230
                        originalCharacters[currentIndex].style.withColor(color.argb),
231
                        false,
232
                        ch.code
233
                    )
234
                }
235
236
                currentIndex = replacement.first.end + 1
237
                currReplacementIndex += 1
238
            } else {
239
                val maxCopyIdx = replacementStartIdx ?: originalCharacters.size
240
241
                mappedCharacters.addAll(originalCharacters.subList(currentIndex, maxCopyIdx))
242
243
                currentIndex = maxCopyIdx
244
            }
245
        }
246
247
        mappedCharListPool.recycle(originalCharacters)
248
249
        return WrappedOrderedText(mappedCharacters)
250
    }
251
252
    private class MappedCharacter(
253
        @JvmField val style: Style,
254
        @JvmField val bypassesNameProtection: Boolean,
255
        @JvmField val codePoint: Int,
256
    )
257
258
    private class WrappedOrderedText(@JvmField val mappedCharacters: ObjectArrayList<MappedCharacter>) :
259
        FormattedCharSequence {
260
        override fun accept(visitor: FormattedCharSink): Boolean {
261
            for (index in 0 until mappedCharacters.size) {
262
                val char = mappedCharacters[index] as MappedCharacter
263
                if (!visitor.accept(index, char.style, char.codePoint)) {
264
                    return false
265
                }
266
            }
267
268
            return true
269
        }
270
    }
271
}
272
273
/**
274
 * Sanitizes texts which are sent to the client.
275
 * 1. Degenerates legacy formatting into new formatting [StringDecomposer]
276
 * 2. Applies [ModuleNameProtect] - if needed
277
 */
278
fun Component.sanitizeForeignInput(): Component {
279
    val degeneratedText = FormattedCharSequence { output ->
280
        StringDecomposer.iterateFormatted(this, Style.EMPTY, output)
281
    }
282
283
    if (!ModuleNameProtect.running) {
284
        return degeneratedText.toText()
285
    }
286
287
    return ModuleNameProtect.wrap(degeneratedText).toText()
288
}
289