BookBot module

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

2 implementationsMISCEXPLOIT

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/BookBot.javaJava · 262 lines · 10.2 KB

Writes book after book for you.

SettingsModeFileCharactersPagesCharacters per pageWord wrapDelaySignTitleNumber books
BookBot.javaJava · Minecraft 26.2 · 262 lines · 10.2 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.TickEvent;
6
import com.jellypudding.offlineclient.module.Category;
7
import com.jellypudding.offlineclient.module.Module;
8
import com.jellypudding.offlineclient.setting.BoolSetting;
9
import com.jellypudding.offlineclient.setting.EnumSetting;
10
import com.jellypudding.offlineclient.setting.NumberSetting;
11
import com.jellypudding.offlineclient.setting.TextSetting;
12
import com.jellypudding.offlineclient.util.ChatUtil;
13
import com.jellypudding.offlineclient.util.InventoryUtil;
14
import net.minecraft.core.component.DataComponents;
15
import net.minecraft.network.chat.Component;
16
import net.minecraft.network.chat.FormattedText;
17
import net.minecraft.network.protocol.game.ServerboundEditBookPacket;
18
import net.minecraft.world.item.ItemStack;
19
import net.minecraft.world.item.Items;
20
import net.minecraft.world.item.component.WritableBookContent;
21
22
import java.io.IOException;
23
import java.nio.file.Files;
24
import java.nio.file.Path;
25
import java.util.ArrayList;
26
import java.util.List;
27
import java.util.Optional;
28
import java.util.Random;
29
30
// Fills book and quill after book and quill with text.
31
// Random text makes heavy books and a file writes whatever you like.
32
public final class BookBot extends Module {
33
34
    public enum Mode { RANDOM, FILE }
35
36
    public enum Characters { ASCII, UNICODE, PAPER }
37
38
    // Book limits the server enforces.
39
    private static final int MAX_PAGES = 100;
40
    private static final int MAX_PAGE_LENGTH = 1024;
41
42
    // The Paper layout. Pages before this hold one wide character and the rest ASCII.
43
    private static final int PAPER_LIGHT_PAGES = 50;
44
    private static final int PAPER_MIXED_WIDE = 110;
45
46
    // Three bytes and two bytes of UTF-8 each.
47
    private static final char WIDE_CHARACTER = 0x4E00;
48
    private static final char MIDDLE_CHARACTER = 0x00A9;
49
50
    // Width in pixels and lines of one book page.
51
    private static final int PAGE_WIDTH = 114;
52
    private static final int PAGE_LINES = 14;
53
54
    private final EnumSetting<Mode> mode = new EnumSetting<>("Mode",
55
        "Where the text comes from.", Mode.RANDOM)
56
        .describe(Mode.RANDOM, "Random characters.")
57
        .describe(Mode.FILE, "The text of a file in the offlineclient folder.");
58
    private final TextSetting file = new TextSetting("File",
59
        "Name of the text file inside the offlineclient folder.", "bookbot.txt")
60
        .under(mode, Mode.FILE);
61
    private final EnumSetting<Characters> characters = new EnumSetting<>("Characters",
62
        "Which characters random text draws from.", Characters.UNICODE)
63
        .describe(Characters.ASCII, "Plain printable letters and symbols.")
64
        .describe(Characters.UNICODE, "Any printable character. Far heavier per page.")
65
        .describe(Characters.PAPER, "A fixed hundred page layout sized to the Paper packet limit. Pages and characters are ignored.")
66
        .under(mode, Mode.RANDOM);
67
    private final NumberSetting pages = new NumberSetting("Pages",
68
        "Pages per book.", 50, 1, MAX_PAGES, 1).max(MAX_PAGES)
69
        .under(mode, () -> mode.is(Mode.RANDOM) && !characters.is(Characters.PAPER));
70
    private final NumberSetting perPage = new NumberSetting("Characters per page",
71
        "How many characters each page holds.", 128, 1, MAX_PAGE_LENGTH, 1)
72
        .max(MAX_PAGE_LENGTH)
73
        .under(mode, () -> mode.is(Mode.RANDOM) && !characters.is(Characters.PAPER));
74
    private final BoolSetting wordWrap = new BoolSetting("Word wrap",
75
        "Breaks lines between words the way the book screen would.", true)
76
        .under(mode, Mode.FILE);
77
    private final NumberSetting delay = new NumberSetting("Delay",
78
        "Ticks between books.", 20, 1, 200, 1, " ticks").min(1);
79
    private final BoolSetting sign = new BoolSetting("Sign",
80
        "Signs the book and locks it against editing.", true);
81
    private final TextSetting title = new TextSetting("Title",
82
        "Title given to a signed book.", "Offline").under(sign);
83
    private final BoolSetting number = new BoolSetting("Number books",
84
        "Adds the book count to each title.", true).under(sign);
85
86
    private final InventoryUtil.HotbarLoan loan = new InventoryUtil.HotbarLoan();
87
    private final Random random = new Random();
88
    private int timer;
89
    private int written;
90
91
    public BookBot() {
92
        super("BookBot", "Writes book after book for you.", Category.MISC);
93
        addSettings(mode, file, characters, pages, perPage, wordWrap, delay, sign, title, number);
94
        searchTags("book and quill", "write books");
95
    }
96
97
    @Override
98
    public String getSuffix() {
99
        return written == 0 ? null : written + " written";
100
    }
101
102
    @Override
103
    protected void onEnable() {
104
        timer = delay.getInt();
105
        written = 0;
106
    }
107
108
    @Override
109
    protected void onDisable() {
110
        loan.giveBack();
111
    }
112
113
    @Subscribe
114
    private void onTick(TickEvent event) {
115
        if (!inGame() || mc.gui.screen() != null) {
116
            return;
117
        }
118
        if (!isBlankBook(mc.player.getMainHandItem())) {
119
            int slot = InventoryUtil.findSlot(BookBot::isBlankBook, InventoryUtil.WHOLE_INVENTORY);
120
            if (slot == -1) {
121
                ChatUtil.message("§bBookBot §7has no blank books left.");
122
                setEnabled(false);
123
                return;
124
            }
125
            loan.select(slot);
126
            return;
127
        }
128
        if (timer > 0) {
129
            timer--;
130
            return;
131
        }
132
        timer = delay.getInt();
133
        List<String> text = mode.is(Mode.FILE) ? fromFile() : randomPages();
134
        if (text == null) {
135
            setEnabled(false);
136
            return;
137
        }
138
        send(text);
139
    }
140
141
    private static boolean isBlankBook(ItemStack stack) {
142
        if (!stack.is(Items.WRITABLE_BOOK)) {
143
            return false;
144
        }
145
        WritableBookContent content = stack.get(DataComponents.WRITABLE_BOOK_CONTENT);
146
        return content == null || content.pages().isEmpty();
147
    }
148
149
    private List<String> randomPages() {
150
        if (characters.is(Characters.PAPER)) {
151
            return paperPages();
152
        }
153
        int high = characters.is(Characters.ASCII) ? 0x7F : 0xD800;
154
        List<String> result = new ArrayList<>();
155
        for (int page = 0; page < pages.getInt(); page++) {
156
            StringBuilder text = new StringBuilder();
157
            while (text.length() < perPage.getInt()) {
158
                int codePoint = random.nextInt(0x21, high);
159
                if (!Character.isWhitespace(codePoint) && Character.isDefined(codePoint)) {
160
                    text.appendCodePoint(codePoint);
161
                }
162
            }
163
            result.add(text.toString());
164
        }
165
        return result;
166
    }
167
168
    // A hundred pages built to sit right on the Paper packet size limit. The
169
    // first fifty are mostly one byte characters and the last fifty are three.
170
    private List<String> paperPages() {
171
        List<String> result = new ArrayList<>(MAX_PAGES);
172
        for (int page = 0; page < MAX_PAGES; page++) {
173
            StringBuilder text = new StringBuilder(MAX_PAGE_LENGTH);
174
            if (page < PAPER_LIGHT_PAGES) {
175
                text.append(wide(1)).append(narrow(MAX_PAGE_LENGTH - 1));
176
            } else if (page == PAPER_LIGHT_PAGES) {
177
                text.append(wide(PAPER_MIXED_WIDE)).append(MIDDLE_CHARACTER)
178
                    .append(narrow(MAX_PAGE_LENGTH - PAPER_MIXED_WIDE - 1));
179
            } else {
180
                text.append(wide(MAX_PAGE_LENGTH));
181
            }
182
            result.add(text.toString());
183
        }
184
        return result;
185
    }
186
187
    private String wide(int count) {
188
        return String.valueOf(WIDE_CHARACTER).repeat(count);
189
    }
190
191
    private String narrow(int count) {
192
        StringBuilder text = new StringBuilder(count);
193
        while (text.length() < count) {
194
            int codePoint = random.nextInt(0x21, 0x7F);
195
            text.appendCodePoint(codePoint);
196
        }
197
        return text.toString();
198
    }
199
200
    // Null when the file cannot be read. A message says why.
201
    private List<String> fromFile() {
202
        Path path = OfflineClient.MC.gameDirectory.toPath().resolve("offlineclient").resolve(file.getValue());
203
        String text;
204
        try {
205
            text = Files.readString(path);
206
        } catch (IOException e) {
207
            ChatUtil.error("Could not read " + path.getFileName() + " from the offlineclient folder.");
208
            return null;
209
        }
210
        if (text.isBlank()) {
211
            ChatUtil.error(path.getFileName() + " is empty.");
212
            return null;
213
        }
214
        return wordWrap.isOn() ? wrapPages(text) : cutPages(text);
215
    }
216
217
    // The game's own line breaking decides where each page ends.
218
    private List<String> wrapPages(String text) {
219
        List<FormattedText> lines = mc.font.splitIgnoringLanguage(Component.literal(text), PAGE_WIDTH);
220
        List<String> result = new ArrayList<>();
221
        StringBuilder page = new StringBuilder();
222
        int lineCount = 0;
223
        for (FormattedText line : lines) {
224
            if (!page.isEmpty()) {
225
                page.append('\n');
226
            }
227
            page.append(line.getString());
228
            if (++lineCount == PAGE_LINES) {
229
                result.add(page.toString());
230
                page.setLength(0);
231
                lineCount = 0;
232
                if (result.size() == MAX_PAGES) {
233
                    return result;
234
                }
235
            }
236
        }
237
        if (!page.isEmpty()) {
238
            result.add(page.toString());
239
        }
240
        return result;
241
    }
242
243
    private static List<String> cutPages(String text) {
244
        List<String> result = new ArrayList<>();
245
        for (int start = 0; start < text.length() && result.size() < MAX_PAGES; start += MAX_PAGE_LENGTH) {
246
            result.add(text.substring(start, Math.min(text.length(), start + MAX_PAGE_LENGTH)));
247
        }
248
        return result;
249
    }
250
251
    private void send(List<String> text) {
252
        String name = title.getValue();
253
        if (number.isOn()) {
254
            name += " " + (written + 1);
255
        }
256
        Optional<String> signed = sign.isOn() ? Optional.of(name) : Optional.empty();
257
        mc.player.connection.send(new ServerboundEditBookPacket(
258
            InventoryUtil.selectedSlot(), text, signed));
259
        written++;
260
    }
261
}
262
LiquidBounce (Kotlin)EXPLOITsrc/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/misc/ModuleBookBot.ktKotlin · 343 lines · 12.6 KB

Automatically writes in books.

SettingsNameDelayPagesAsciiOnlyAllowSpaceCyclic
ModuleBookBot.ktKotlin · Minecraft 26.2 · 343 lines · 12.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
20
package net.ccbluex.liquidbounce.features.module.modules.misc
21
22
import it.unimi.dsi.fastutil.ints.IntArrayList
23
import net.ccbluex.liquidbounce.config.types.group.Mode
24
import net.ccbluex.liquidbounce.config.types.group.ModeValueGroup
25
import net.ccbluex.liquidbounce.config.types.group.ToggleableValueGroup
26
import net.ccbluex.liquidbounce.event.events.ScheduleInventoryActionEvent
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.utils.client.Chronometer
31
import net.ccbluex.liquidbounce.utils.inventory.HotbarItemSlot
32
import net.ccbluex.liquidbounce.utils.inventory.InventoryAction
33
import net.ccbluex.liquidbounce.utils.inventory.PlayerInventoryConstraints
34
import net.ccbluex.liquidbounce.utils.inventory.Slots
35
import net.ccbluex.liquidbounce.utils.text.asPlainText
36
import net.minecraft.core.component.DataComponents
37
import net.minecraft.network.chat.Component
38
import net.minecraft.network.chat.Style
39
import net.minecraft.network.protocol.game.ServerboundEditBookPacket
40
import net.minecraft.server.network.Filterable
41
import net.minecraft.world.item.ItemStack
42
import net.minecraft.world.item.Items
43
import net.minecraft.world.item.component.WrittenBookContent
44
import okio.buffer
45
import okio.source
46
import java.util.Optional
47
import java.util.PrimitiveIterator
48
import java.util.Random
49
import java.util.stream.IntStream
50
51
/**
52
 * Maximum number of lines that can fit on a single page in the Minecraft book.
53
 *
54
 * This constant is used to eliminate "magic numbers" in the code and improve readability and maintainability.
55
 * It defines the limit for the number of lines displayed on a single page, ensuring consistent formatting.
56
 *
57
 * **Note:** This value is fixed and should not be changed to maintain the intended functionality.
58
 */
59
private const val MAX_LINES_PER_PAGE: Int = 14
60
61
/**
62
 * Maximum width of a single line of text in the Minecraft book, measured in float units.
63
 *
64
 * This constant is used to eliminate "magic numbers" in the code and improve readability and maintainability.
65
 * It defines the maximum length of a single line, ensuring that the text does not overflow or break formatting.
66
 *
67
 * **Note:** This value is fixed and should not be changed to maintain the intended functionality.
68
 */
69
private const val MAX_LINE_WIDTH: Float = 114f
70
71
/**
72
 * ModuleBookBot
73
 *
74
 * This module simplifies the process of filling and creating books using various principles,
75
 * enabling efficient generation and potential automation for mass book creation or "spam."
76
 *
77
 * @author sqlerrorthing
78
 * @since 12/28/2024
79
 **/
80
object ModuleBookBot : ClientModule("BookBot", ModuleCategories.EXPLOIT, disableOnQuit = true) {
81
    private val inventoryConstraints = tree(PlayerInventoryConstraints())
82
83
    internal val generationMode = choices(
84
        "Mode",
85
        GenerationMode.Random,
86
        arrayOf(GenerationMode.Random, GenerationMode.File)
87
    ).apply {
88
        tagBy(this)
89
    }
90
91
    private object Sign : ToggleableValueGroup(ModuleBookBot, "Sign", true) {
92
        val bookName by text("Name", "Generated book #%count%")
93
    }
94
95
    init {
96
        treeAll(Sign)
97
    }
98
99
    private val delay by float("Delay", .5f, 0f..20f, suffix = "s")
100
101
    private val chronometer = Chronometer()
102
103
    private var bookCount = 0
104
105
    override fun onEnabled() {
106
        bookCount = 0
107
        chronometer.reset()
108
    }
109
110
    private fun isCandidate(itemStack: ItemStack): Boolean {
111
        return itemStack.item == Items.WRITABLE_BOOK &&
112
            itemStack.get(DataComponents.WRITABLE_BOOK_CONTENT)?.pages()?.isEmpty() == true
113
    }
114
115
    private val randomBook get() = Slots.All.findSlot(::isCandidate)
116
117
    @Suppress("unused")
118
    private val scheduleInventoryAction = handler<ScheduleInventoryActionEvent> { event ->
119
        val book = randomBook ?: run {
120
            enabled = false
121
            return@handler
122
        }
123
124
        if (!isCandidate(player.mainHandItem)) {
125
            event.schedule(
126
                inventoryConstraints, InventoryAction.Click.performSwap(
127
                from = book,
128
                to = HotbarItemSlot(player.inventory.selectedSlot),
129
            ))
130
        }
131
132
        if (chronometer.hasElapsed((delay * 1000L).toLong())) {
133
            chronometer.reset()
134
            writeBook()
135
        }
136
    }
137
138
    /**
139
     * Generates a book with content based on the active choice of the generation mode.
140
     * The book content is generated character by character, and the text is split into pages,
141
     * ensuring that each page contains lines that fit within the given width constraints.
142
     *
143
     * This method processes each character from the generator, managing line breaks and page formatting,
144
     * and stores the generated text in the `pages` and `filteredPages` lists. Once a page is full, it is
145
     * added to the collection, and the process continues until the specified number of pages is reached.
146
     *
147
     * The method performs the following steps:
148
     * - Generates characters using the active choice from the generation mode.
149
     * - Breaks lines based on a width limit and ensures that a line fits within this constraint.
150
     * - Adds new lines when a line exceeds the width limit or encounters a line break character (`\r` or `\n`).
151
     * - If a page is full, it is added to the `pages` and `filteredPages` lists, and the process continues.
152
     * - Stops once the desired number of pages is generated.
153
     *
154
     * The generated pages are used to create a book with the specified name, which is then saved.
155
     *
156
     *
157
     * @see PrimitiveIterator.OfInt
158
     * @see GenerationMode.generate
159
     */
160
    private fun writeBook() {
161
        if (!isCandidate(player.mainHandItem)) {
162
            return
163
        }
164
165
        val bookBuilder = BookBuilder()
166
        val generator = generationMode.activeMode.generate()
167
            .filter { it.toChar() != '\r' }
168
            .iterator()
169
170
        bookBuilder.buildBookContent(generator) {
171
            mc.font.splitter.widthProvider.getWidth(it, Style.EMPTY)
172
        }
173
        bookBuilder.writeBook()
174
175
        bookCount++
176
    }
177
178
    private fun StringBuilder.appendLineBreak(lineIndex: Int) {
179
        append('\n')
180
        if (lineIndex == MAX_LINES_PER_PAGE) {
181
            append(' ')
182
        }
183
    }
184
185
    private class BookBuilder {
186
        private val title: String = Sign.bookName.replace("%count%", bookCount.toString())
187
        private val pageAmount: Int = generationMode.activeMode.pages
188
189
        private val pages = ArrayList<String>(pageAmount)
190
        private val filteredPages = ArrayList<Filterable<Component>>(pageAmount)
191
192
        /**
193
         * @source <a href="https://github.com/MeteorDevelopment/meteor-client/blob/2025789457e5b4c0671f04f0d3c7e0d91a31765c/src/main/java/meteordevelopment/meteorclient/systems/modules/misc/BookBot.java#L252-L326">code section</a>
194
         * @contributor sqlerrorthing (<a href="https://github.com/CCBlueX/LiquidBounce/pull/5076">pull request</a>)
195
         * @author arlomcwalter (on Meteor Client)
196
         */
197
        @Suppress("detekt:CognitiveComplexMethod")
198
        inline fun buildBookContent(
199
            charGenerator: PrimitiveIterator.OfInt,
200
            charWidthProvider: (charCode: Int) -> Float
201
        ) {
202
            var pageIndex = 0
203
            var lineIndex = 0
204
            var lineWidth = 0.0f
205
            val page = StringBuilder()
206
207
            while (charGenerator.hasNext()) {
208
                val char = charGenerator.nextInt().toChar()
209
210
                if (lineWidth == 0f && char == ' ') {
211
                    continue
212
                } else if (char == '\r' || char == '\n') {
213
                    page.append('\n')
214
                    lineWidth = 0.0f
215
                    lineIndex++
216
                } else {
217
                    val charWidth = charWidthProvider(char.code)
218
219
                    if (lineWidth + charWidth > MAX_LINE_WIDTH) {
220
                        lineIndex++
221
                        lineWidth = charWidth
222
                        page.appendLineBreak(lineIndex)
223
                    } else {
224
                        lineWidth += charWidth
225
                        page.appendCodePoint(char.code)
226
                    }
227
                }
228
229
                if (lineIndex == MAX_LINES_PER_PAGE) {
230
                    this.addPage(page.toString())
231
                    page.setLength(0)
232
                    pageIndex++
233
                    lineIndex = 0
234
235
                    if (pageIndex >= pageAmount) {
236
                        break
237
                    }
238
239
                    if (char != '\r' && char != '\n') {
240
                        page.append(char)
241
                    }
242
                }
243
            }
244
245
            if (page.isNotEmpty() && pageIndex < pageAmount) {
246
                this.addPage(page.toString())
247
            }
248
        }
249
250
        fun addPage(page: String) {
251
            filteredPages.add(Filterable.passThrough(page.asPlainText()))
252
            pages.add(page)
253
        }
254
255
        fun writeBook() {
256
            player.mainHandItem.set(
257
                DataComponents.WRITTEN_BOOK_CONTENT,
258
                WrittenBookContent(
259
                    Filterable.passThrough(title),
260
                    player.gameProfile.name,
261
                    0,
262
                    filteredPages,
263
                    true
264
                )
265
            )
266
267
            player.connection.send(
268
                ServerboundEditBookPacket(
269
                    player.inventory.selectedSlot,
270
                    pages,
271
                    if (Sign.enabled) Optional.of(title) else Optional.empty()
272
                )
273
            )
274
        }
275
    }
276
}
277
278
internal sealed class GenerationMode(
279
    name: String,
280
) : Mode(name) {
281
    override val parent: ModeValueGroup<*> get() = ModuleBookBot.generationMode
282
283
    internal val random = Random()
284
285
    val pages by int("Pages", 50, 0..100)
286
287
    abstract fun generate(): IntStream
288
289
    object Random : GenerationMode("Random") {
290
        private val asciiOnly by boolean("AsciiOnly", false)
291
        private val allowSpace by boolean("AllowSpace", true)
292
293
        @Suppress("MaxLineLength")
294
        /**
295
         * @source <a href="https://github.com/MeteorDevelopment/meteor-client/blob/2025789457e5b4c0671f04f0d3c7e0d91a31765c/src/main/java/meteordevelopment/meteorclient/systems/modules/misc/BookBot.java#L201-L209">code section</a>
296
         * @contributor sqlerrorthing (<a href="https://github.com/CCBlueX/LiquidBounce/pull/5076">pull request</a>)
297
         * @author arlomcwalter (on Meteor Client)
298
         */
299
        override fun generate(): IntStream {
300
            val origin = if (asciiOnly) 0x21 else 0x0800
301
            val bound = if (asciiOnly) 0x7E else 0x10FFFF
302
303
            return random
304
                .ints(origin, bound)
305
                .filter { allowSpace || !Character.isWhitespace(it) }
306
        }
307
    }
308
309
    object File : GenerationMode("File") {
310
        private const val MAX_CODE_POINTS: Long = 64 * 1024 * 1024
311
        private val cyclic by boolean("Cyclic", true)
312
        private val source = file("Source", supportedExtensions = setOf("txt"))
313
314
        /**
315
         * @author sqlerrorthing, MukjepScarlet
316
         */
317
        override fun generate(): IntStream {
318
            val file = source.absoluteFile.takeIf {
319
                it.exists() && it.isFile && it.canRead() && it.length() != 0L
320
            } ?: return IntStream.empty()
321
322
            // UTF-8 averaged 3 bytes -> 1 code point
323
            val codePoints = IntArrayList(minOf(MAX_CODE_POINTS, file.length()).toInt() / 3)
324
            file.source().buffer().use {
325
                while (!it.exhausted() && codePoints.size < MAX_CODE_POINTS) {
326
                    codePoints.add(it.readUtf8CodePoint())
327
                }
328
            }
329
330
            return if (cyclic && codePoints.isNotEmpty()) {
331
                var index = 0
332
                IntStream.generate {
333
                    val value = codePoints.getInt(index)
334
                    index = (index + 1) % codePoints.size
335
                    value
336
                }
337
            } else {
338
                codePoints.intStream()
339
            }
340
        }
341
    }
342
}
343