/
LiquidBounce.kt
278 lines (239 loc) · 9.86 KB
/
LiquidBounce.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
/*
* This file is part of LiquidBounce (https://github.com/CCBlueX/LiquidBounce)
*
* Copyright (c) 2015 - 2024 CCBlueX
*
* LiquidBounce is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LiquidBounce is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LiquidBounce. If not, see <https://www.gnu.org/licenses/>.
*
*/
package net.ccbluex.liquidbounce
import net.ccbluex.liquidbounce.api.ClientUpdate.gitInfo
import net.ccbluex.liquidbounce.api.ClientUpdate.hasUpdate
import net.ccbluex.liquidbounce.api.IpInfoApi
import net.ccbluex.liquidbounce.config.AutoConfig
import net.ccbluex.liquidbounce.config.ConfigSystem
import net.ccbluex.liquidbounce.event.EventManager
import net.ccbluex.liquidbounce.event.Listenable
import net.ccbluex.liquidbounce.event.events.ClientShutdownEvent
import net.ccbluex.liquidbounce.event.events.ClientStartEvent
import net.ccbluex.liquidbounce.event.handler
import net.ccbluex.liquidbounce.features.Reconnect
import net.ccbluex.liquidbounce.features.command.CommandManager
import net.ccbluex.liquidbounce.features.cosmetic.CapeService
import net.ccbluex.liquidbounce.features.itemgroup.ClientItemGroups
import net.ccbluex.liquidbounce.features.itemgroup.groups.headsCollection
import net.ccbluex.liquidbounce.features.misc.AccountManager
import net.ccbluex.liquidbounce.features.misc.FriendManager
import net.ccbluex.liquidbounce.features.misc.ProxyManager
import net.ccbluex.liquidbounce.features.module.ModuleManager
import net.ccbluex.liquidbounce.features.module.modules.client.ipcConfiguration
import net.ccbluex.liquidbounce.lang.LanguageManager
import net.ccbluex.liquidbounce.render.Fonts
import net.ccbluex.liquidbounce.render.ui.ItemImageAtlas
import net.ccbluex.liquidbounce.script.ScriptManager
import net.ccbluex.liquidbounce.utils.aiming.RotationManager
import net.ccbluex.liquidbounce.utils.block.ChunkScanner
import net.ccbluex.liquidbounce.utils.block.WorldChangeNotifier
import net.ccbluex.liquidbounce.utils.client.ErrorHandler
import net.ccbluex.liquidbounce.utils.client.disableConflictingVfpOptions
import net.ccbluex.liquidbounce.utils.client.mc
import net.ccbluex.liquidbounce.utils.combat.CombatManager
import net.ccbluex.liquidbounce.utils.combat.globalEnemyConfigurable
import net.ccbluex.liquidbounce.utils.item.InventoryTracker
import net.ccbluex.liquidbounce.utils.mappings.Remapper
import net.ccbluex.liquidbounce.utils.render.WorldToScreen
import net.ccbluex.liquidbounce.web.browser.BrowserManager
import net.ccbluex.liquidbounce.web.integration.IntegrationHandler
import net.ccbluex.liquidbounce.web.socket.ClientSocket
import net.ccbluex.liquidbounce.web.theme.ThemeManager
import net.ccbluex.liquidbounce.web.theme.component.ComponentOverlay
import net.minecraft.resource.ReloadableResourceManagerImpl
import net.minecraft.resource.ResourceManager
import net.minecraft.resource.ResourceReloader
import net.minecraft.resource.SynchronousResourceReloader
import org.apache.logging.log4j.LogManager
/**
* LiquidBounce
*
* A free mixin-based injection hacked-client for Minecraft using FabricMC.
*
* @author kawaiinekololis (@team CCBlueX)
*/
object LiquidBounce : Listenable {
/**
* CLIENT INFORMATION
*
* WARNING: Please read the GNU General Public License
*/
const val CLIENT_NAME = "LiquidBounce"
const val CLIENT_AUTHOR = "CCBlueX"
const val CLIENT_CLOUD = "https://cloud.liquidbounce.net/LiquidBounce"
val clientVersion = gitInfo["git.build.version"]?.toString() ?: "unknown"
val clientCommit = gitInfo["git.commit.id.abbrev"]?.let { "git-$it" } ?: "unknown"
val clientBranch = gitInfo["git.branch"]?.toString() ?: "nextgen"
/**
* Defines if the client is in development mode. This will enable update checking on commit time instead of semantic versioning.
*
* TODO: Replace this approach with full semantic versioning.
*/
const val IN_DEVELOPMENT = false
val isIntegrationTesting = !System.getenv("TENACC_TEST_PROVIDER").isNullOrBlank()
/**
* Client logger to print out console messages
*/
val logger = LogManager.getLogger(CLIENT_NAME)!!
/**
* Client update information
*/
val updateAvailable by lazy { hasUpdate() }
/**
* Should be executed to start the client.
*/
val startHandler = handler<ClientStartEvent> {
runCatching {
logger.info("Launching $CLIENT_NAME v$clientVersion by $CLIENT_AUTHOR")
logger.debug("Loading from cloud: '$CLIENT_CLOUD'")
// Load mappings
Remapper.load()
// Load translations
LanguageManager.loadLanguages()
// Initialize client features
EventManager
// Config
ConfigSystem
globalEnemyConfigurable
ChunkScanner
WorldChangeNotifier
// Features
ModuleManager
CommandManager
ScriptManager
RotationManager
CombatManager
FriendManager
ProxyManager
AccountManager
InventoryTracker
WorldToScreen
Reconnect
ConfigSystem.root(ClientItemGroups)
ConfigSystem.root(LanguageManager)
BrowserManager
Fonts
// Register commands and modules
CommandManager.registerInbuilt()
ModuleManager.registerInbuilt()
// Load user scripts
ScriptManager.loadScripts()
// Load theme and component overlay
ThemeManager
ComponentOverlay.insertComponents()
// Load config system from disk
ConfigSystem.loadAll()
// Netty WebSocket
ClientSocket.start()
// Initialize browser
logger.info("Refresh Rate: ${mc.window.refreshRate} Hz")
IntegrationHandler
BrowserManager.initBrowser()
// Register resource reloader
val resourceManager = mc.resourceManager
val clientResourceReloader = ClientResourceReloader()
if (resourceManager is ReloadableResourceManagerImpl) {
resourceManager.registerReloader(clientResourceReloader)
} else {
logger.warn("Failed to register resource reloader!")
// Run resource reloader directly as fallback
clientResourceReloader.reload(resourceManager)
}
ItemImageAtlas
}.onSuccess {
logger.info("Successfully loaded client!")
}.onFailure(ErrorHandler::fatal)
}
/**
* Resource reloader which is executed on client start and reload.
* This is used to run async tasks without blocking the main thread.
*
* For now this is only used to check for updates and request additional information from the internet.
*
* @see SynchronousResourceReloader
* @see ResourceReloader
*/
class ClientResourceReloader : SynchronousResourceReloader {
override fun reload(manager: ResourceManager) {
runCatching {
logger.info("Loading fonts...")
Fonts.loadQueuedFonts()
}.onSuccess {
logger.info("Loaded fonts successfully!")
}.onFailure(ErrorHandler::fatal)
// Check for newest version
if (updateAvailable) {
logger.info("Update available! Please download the latest version from https://liquidbounce.net/")
}
runCatching {
ipcConfiguration.let {
logger.info("Loaded Discord IPC configuration.")
}
}.onFailure {
logger.error("Failed to load Discord IPC configuration.", it)
}
// Refresh local IP info
logger.info("Refreshing local IP info...")
IpInfoApi.refreshLocalIpInfo()
// Login into known token if not empty
if (CapeService.knownToken.isNotBlank()) {
runCatching {
CapeService.login(CapeService.knownToken)
}.onFailure {
logger.error("Failed to login into known cape token.", it)
}.onSuccess {
logger.info("Successfully logged in into known cape token.")
}
}
// Refresh cape service
CapeService.refreshCapeCarriers {
logger.info("Successfully loaded ${CapeService.capeCarriers.size} cape carriers.")
}
// Load Head collection
headsCollection
// Load settings list from API
runCatching {
logger.info("Loading settings list from API...")
AutoConfig.configs
}.onSuccess {
logger.info("Loaded ${it.size} settings from API.")
}.onFailure {
logger.error("Failed to load settings list from API", it)
}
// Disable conflicting options
runCatching {
disableConflictingVfpOptions()
}.onSuccess {
logger.info("Disabled conflicting options.")
}
}
}
/**
* Should be executed to stop the client.
*/
val shutdownHandler = handler<ClientShutdownEvent> {
logger.info("Shutting down client...")
ConfigSystem.storeAll()
ChunkScanner.ChunkScannerThread.stopThread()
// Shutdown browser as last step
BrowserManager.shutdownBrowser()
}
}