DebugRecorder module

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

1 implementationMISC

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)MISCsrc/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/misc/debugrecorder/ModuleDebugRecorder.ktKotlin · 131 lines · 4.9 KB

Only of interest to developers.

ModuleDebugRecorder.ktKotlin · Minecraft 26.2 · 131 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.misc.debugrecorder
20
21
import net.ccbluex.liquidbounce.config.ConfigSystem
22
import net.ccbluex.liquidbounce.config.gson.adapter.toUnderlinedString
23
import net.ccbluex.liquidbounce.config.gson.fileGson
24
import net.ccbluex.liquidbounce.config.types.group.Mode
25
import net.ccbluex.liquidbounce.config.types.group.ModeValueGroup
26
import net.ccbluex.liquidbounce.features.module.ClientModule
27
import net.ccbluex.liquidbounce.features.module.ModuleCategories
28
import net.ccbluex.liquidbounce.features.module.modules.misc.debugrecorder.modes.AimDebugRecorder
29
import net.ccbluex.liquidbounce.features.module.modules.misc.debugrecorder.modes.BoxDebugRecorder
30
import net.ccbluex.liquidbounce.features.module.modules.misc.debugrecorder.modes.DebugCPSRecorder
31
import net.ccbluex.liquidbounce.features.module.modules.misc.debugrecorder.modes.DebugCombatRecorder
32
import net.ccbluex.liquidbounce.features.module.modules.misc.debugrecorder.modes.DebugCombatTrainerRecorder
33
import net.ccbluex.liquidbounce.features.module.modules.misc.debugrecorder.modes.GenericDebugRecorder
34
import net.ccbluex.liquidbounce.utils.text.asText
35
import net.ccbluex.liquidbounce.utils.client.chat
36
import net.ccbluex.liquidbounce.utils.client.markAsError
37
import net.ccbluex.liquidbounce.utils.client.onClick
38
import net.ccbluex.liquidbounce.utils.client.onHover
39
import net.ccbluex.liquidbounce.utils.client.regular
40
import net.ccbluex.liquidbounce.utils.client.underline
41
import net.ccbluex.liquidbounce.utils.client.variable
42
import net.minecraft.network.chat.ClickEvent
43
import net.minecraft.network.chat.HoverEvent
44
import java.io.File
45
import java.time.LocalDateTime
46
47
object ModuleDebugRecorder : ClientModule("DebugRecorder", ModuleCategories.MISC, disableOnQuit = true) {
48
49
    init {
50
        // [Debug Recorder] is usually used by developers and testers and is not needed in the auto config.
51
        doNotIncludeAlways()
52
    }
53
54
    val modes = choices("Mode", GenericDebugRecorder, arrayOf(
55
        DebugCombatRecorder,
56
        DebugCombatTrainerRecorder,
57
58
        GenericDebugRecorder,
59
        DebugCPSRecorder,
60
        AimDebugRecorder,
61
        BoxDebugRecorder
62
    ))
63
64
    abstract class DebugRecorderMode<T>(name: String) : Mode(name) {
65
        override val parent: ModeValueGroup<*>
66
            get() = modes
67
68
        val folder = ConfigSystem.rootFolder.resolve("debug-recorder/$name").apply {
69
            mkdirs()
70
        }
71
72
        protected val packets = mutableListOf<T>()
73
74
        protected fun recordPacket(packet: T) {
75
            if (!this.isSelected) {
76
                return
77
            }
78
79
            packets.add(packet)
80
        }
81
82
        protected open val fileExtension: String get() = "json"
83
84
        protected open fun writePackets(file: File) {
85
            file.bufferedWriter().use { writer ->
86
                // No indent as default
87
                fileGson.toJson(this.packets, writer)
88
            }
89
        }
90
91
        override fun enable() {
92
            this.packets.clear()
93
            chat(regular("Recording "), variable(name), regular("..."))
94
        }
95
96
        override fun disable() {
97
            if (this.packets.isEmpty()) {
98
                chat(regular("No packets recorded."))
99
                return
100
            }
101
102
            runCatching {
103
                // Create parent folder
104
                folder.mkdirs()
105
106
                val baseName = LocalDateTime.now().toUnderlinedString()
107
                var file = folder.resolve("$baseName.$fileExtension")
108
109
                var idx = 0
110
                while (file.exists()) {
111
                    file = folder.resolve("${baseName}_${idx++}.$fileExtension")
112
                }
113
114
                writePackets(file)
115
                file.absolutePath
116
            }.onFailure {
117
                chat(markAsError("Failed to write log to file $it"))
118
            }.onSuccess { path ->
119
                val text = path.asText()
120
                    .underline(true)
121
                    .onHover(HoverEvent.ShowText(regular("Browse...")))
122
                    .onClick(ClickEvent.OpenFile(path))
123
124
                chat(regular("Log was written to "), text, regular("."))
125
            }
126
127
            this.packets.clear()
128
        }
129
    }
130
}
131