Skip to content

Commit

Permalink
refactor: value system, Kotlin 2.0.21
Browse files Browse the repository at this point in the history
  • Loading branch information
opZywl committed Jan 20, 2025
1 parent c9aaf9f commit 44e0d3d
Show file tree
Hide file tree
Showing 248 changed files with 2,444 additions and 3,272 deletions.
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@ dependencies {
include("org.knowm.xchart:xchart:3.8.8")

// HTTP Client
include("com.squareup.okhttp3:okhttp:4.10.0") { // for Kotlin 1.6.20
include("com.squareup.okhttp3:okhttp:5.0.0-alpha.14") {
exclude module: "kotlin-stdlib"
}
// Kotlin
include "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
include "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.3"
include "org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.3"
include "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlin_coroutines_version"
include "org.jetbrains.kotlinx:kotlinx-coroutines-test:$kotlin_coroutines_version"

include "com.formdev:flatlaf:3.5.4"

Expand Down
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ archives_base_name=FDPClient

# Kotlin
kotlin_version=2.0.21
kotlin_coroutines_version=1.10.1

detekt_version = 1.23.7
forgegradle_version = a3d86a59c0
mixingradle_version = ae2a80e
7 changes: 6 additions & 1 deletion src/main/java/net/ccbluex/liquidbounce/FDPClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import net.ccbluex.liquidbounce.features.module.ModuleManager.registerModules
import net.ccbluex.liquidbounce.file.FileManager
import net.ccbluex.liquidbounce.file.FileManager.loadAllConfigs
import net.ccbluex.liquidbounce.file.FileManager.saveAllConfigs
import net.ccbluex.liquidbounce.file.configs.models.ClientConfiguration.updateClientWindow
import net.ccbluex.liquidbounce.handler.api.ClientUpdate
import net.ccbluex.liquidbounce.handler.api.ClientUpdate.gitInfo
import net.ccbluex.liquidbounce.handler.api.loadSettings
Expand All @@ -40,7 +41,6 @@ import net.ccbluex.liquidbounce.ui.client.altmanager.GuiAltManager.Companion.loa
import net.ccbluex.liquidbounce.ui.client.clickgui.ClickGui
import net.ccbluex.liquidbounce.ui.client.clickgui.style.styles.yzygui.font.manager.FontManager
import net.ccbluex.liquidbounce.ui.client.clickgui.style.styles.yzygui.manager.GUIManager
import net.ccbluex.liquidbounce.ui.client.gui.GuiClientConfiguration.Companion.updateClientWindow
import net.ccbluex.liquidbounce.ui.client.hud.HUD
import net.ccbluex.liquidbounce.ui.client.keybind.KeyBindManager
import net.ccbluex.liquidbounce.ui.font.Fonts
Expand All @@ -50,6 +50,7 @@ import net.ccbluex.liquidbounce.utils.client.ClientUtils.disableFastRender
import net.ccbluex.liquidbounce.utils.client.BlinkUtils
import net.ccbluex.liquidbounce.utils.client.PacketUtils
import net.ccbluex.liquidbounce.utils.inventory.InventoryManager
import net.ccbluex.liquidbounce.utils.io.MiscUtils
import net.ccbluex.liquidbounce.utils.kotlin.SharedScopes
import net.ccbluex.liquidbounce.utils.inventory.InventoryUtils
import net.ccbluex.liquidbounce.utils.inventory.SilentHotbar
Expand Down Expand Up @@ -275,6 +276,10 @@ object FDPClient {
// Set is starting status
isStarting = false

if (!FileManager.firstStart && FileManager.backedup) {
MiscUtils.showMessageDialog("Warning: backup triggered", "Client update detected! Please check the config folder.")
}

EventManager.call(StartupEvent)
LOGGER.info("Successfully started client")
}
Expand Down
131 changes: 131 additions & 0 deletions src/main/java/net/ccbluex/liquidbounce/config/Configurable.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/*
* FDPClient Hacked Client
* A free open source mixin-based injection hacked client for Minecraft using Minecraft Forge by LiquidBounce.
* https://github.com/SkidderMC/FDPClient/
*/
package net.ccbluex.liquidbounce.config

import com.google.gson.JsonElement
import com.google.gson.JsonObject
import net.ccbluex.liquidbounce.utils.io.json
import net.minecraft.client.gui.FontRenderer
import java.awt.Color

/**
* A container of the values
*/
open class Configurable(
name: String
) : Value<MutableList<Value<*>>>(
name, mutableListOf()
) {

val values: List<Value<*>>
get() = this.get()

fun addValue(value: Value<*>) = apply {
get().add(value)
}

fun addValues(values: Collection<Value<*>>) = apply {
get().addAll(values)
}

operator fun <T, V : Value<T>> V.unaryPlus() = apply(::addValue)

override fun toJson(): JsonElement = json {
for (value in values) {
if (value.excluded) {
continue
}

value.name to value.toJson()
}
}

override fun fromJsonF(element: JsonElement): MutableList<Value<*>>? {
element as JsonObject

val values = get()
// Set all sub values from the JSON object
for ((valueName, value) in element.entrySet()) {
values.find { it.name.equals(valueName, true) }?.fromJson(value)
}

return values
}

override fun toText(): String {
TODO("Not yet implemented")
}

override fun fromTextF(text: String): MutableList<Value<*>>? {
TODO("Not yet implemented")
}

fun int(
name: String, value: Int, range: IntRange, suffix: String? = null, isSupported: (() -> Boolean)? = null
) = +IntValue(name, value, range, suffix).apply {
if (isSupported != null) setSupport { isSupported.invoke() }
}

fun float(
name: String, value: Float, range: ClosedFloatingPointRange<Float> = 0f..Float.MAX_VALUE, suffix: String? = null, isSupported: (() -> Boolean)? = null
) = +FloatValue(name, value, range, suffix).apply {
if (isSupported != null) setSupport { isSupported.invoke() }
}

fun choices(
name: String, values: Array<String>, value: String, isSupported: (() -> Boolean)? = null
) = +ListValue(name, values, value).apply {
if (isSupported != null) setSupport { isSupported.invoke() }
}

fun block(
name: String, value: Int, isSupported: (() -> Boolean)? = null
) = +BlockValue(name, value).apply {
if (isSupported != null) setSupport { isSupported.invoke() }
}

fun font(
name: String, value: FontRenderer, isSupported: (() -> Boolean)? = null
) = +FontValue(name, value).apply {
if (isSupported != null) setSupport { isSupported.invoke() }
}

fun text(
name: String, value: String, isSupported: (() -> Boolean)? = null
) = +TextValue(name, value).apply {
if (isSupported != null) setSupport { isSupported.invoke() }
}

fun boolean(
name: String, value: Boolean, isSupported: (() -> Boolean)? = null
) = +BoolValue(name, value).apply {
if (isSupported != null) setSupport { isSupported.invoke() }
}

fun intRange(
name: String, value: IntRange, range: IntRange, suffix: String? = null, isSupported: (() -> Boolean)? = null
) = +IntRangeValue(name, value, range, suffix).apply {
if (isSupported != null) setSupport { isSupported.invoke() }
}

fun floatRange(
name: String, value: ClosedFloatingPointRange<Float>, range: ClosedFloatingPointRange<Float> = 0f..Float.MAX_VALUE,
suffix: String? = null, isSupported: (() -> Boolean)? = null
) = +FloatRangeValue(name, value, range, suffix).apply {
if (isSupported != null) setSupport { isSupported.invoke() }
}

fun color(
name: String, value: Color, rainbow: Boolean = false, showPicker: Boolean = false, isSupported: (() -> Boolean)? = null
) = +ColorValue(name, value, rainbow, showPicker).apply {
if (isSupported != null) setSupport { isSupported.invoke() }
}

fun color(
name: String, value: Int, rainbow: Boolean = false, showPicker: Boolean = false, isSupported: (() -> Boolean)? = null
) = color(name, Color(value, true), rainbow, showPicker, isSupported)

}
63 changes: 8 additions & 55 deletions src/main/java/net/ccbluex/liquidbounce/config/SettingsUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,15 @@ package net.ccbluex.liquidbounce.config

import kotlinx.coroutines.runBlocking
import net.ccbluex.liquidbounce.FDPClient.moduleManager
import net.ccbluex.liquidbounce.features.module.Module
import net.ccbluex.liquidbounce.handler.api.ClientApi
import net.ccbluex.liquidbounce.features.module.Module
import net.ccbluex.liquidbounce.features.module.modules.client.TargetModule
import net.ccbluex.liquidbounce.file.FileManager
import net.ccbluex.liquidbounce.utils.client.chat
import net.ccbluex.liquidbounce.utils.io.HttpUtils
import net.ccbluex.liquidbounce.utils.kotlin.StringUtils
import net.ccbluex.liquidbounce.utils.render.ColorUtils.translateAlternateColorCodes
import org.lwjgl.input.Keyboard
import java.awt.Color
import javax.vecmath.Vector2f
import kotlin.math.roundToInt
import kotlin.reflect.KMutableProperty0

/**
Expand All @@ -36,7 +33,7 @@ object SettingsUtils {
return@forEachIndexed
}

val args = s.split(" ").toTypedArray()
val args = s.split(' ').toTypedArray()

if (args.size <= 1) {
chat("§7[§3§lAutoSettings§7] §cSyntax error at line '$index' in setting script.\n§8§lLine: §7$s")
Expand Down Expand Up @@ -125,14 +122,14 @@ object SettingsUtils {

// Utility functions for setting target settings
private fun setTargetSetting(setting: KMutableProperty0<Boolean>, args: Array<String>) {
setting.set(args[1].equals("true", ignoreCase = true))
setting.set(args[1].toBoolean())
chat("§7[§3§lAutoSettings§7] §a§l${args[0]}§7 set to §c§l${args[1]}§7.")
}

// Utility functions for setting toggles
private fun setToggle(module: Module, value: String) {
module.state = value.equals("true", ignoreCase = true)
//chat("§7[§3§lAutoSettings§7] §a§l${module.getName()} §7was toggled §c§l${if (module.state) "on" else "off"}§7.")
module.state = value.toBoolean()
chat("§7[§3§lAutoSettings§7] §a§l${module.getName()} §7was toggled §c§l${if (module.state) "on" else "off"}§7.")
}

// Utility functions for setting binds
Expand All @@ -157,52 +154,8 @@ object SettingsUtils {
}

try {
when (moduleValue) {
is BoolValue -> moduleValue.changeValue(value.toBoolean())
is FloatValue -> moduleValue.changeValue(value.toFloat())
is IntegerValue -> moduleValue.changeValue(value.toInt())
is TextValue -> moduleValue.changeValue(StringUtils.toCompleteString(args, 2))
is ListValue -> moduleValue.changeValue(value)
is IntegerRangeValue, is FloatRangeValue -> {
value.split("..").takeIf { it.size == 2 }?.let {
val (min, max) = (it[0].toFloatOrNull() ?: return@let) to (it[1].toFloatOrNull() ?: return@let)

if (moduleValue is IntegerRangeValue) {
moduleValue.changeValue(min.toInt()..max.toInt())
} else (moduleValue as FloatRangeValue).changeValue(min..max)
}
}
is ColorValue -> {
moduleValue.readColorFromConfig(value)?.let { list ->
val pos = list[0].toFloatOrNull() to list[1].toFloatOrNull()
val hue = list[2].toFloatOrNull()
val alpha = list[3].toFloatOrNull()
val rainbow = list[4].toBooleanStrictOrNull()

rainbow?.let { moduleValue.rainbow = it }

if (pos.first != null && pos.second != null && hue != null && alpha != null) {
moduleValue.colorPickerPos = Vector2f(pos.first!!, pos.second!!)
moduleValue.hueSliderY = hue
moduleValue.opacitySliderY = alpha

val rgb = Color.HSBtoRGB(hue, pos.first!!, 1 - pos.second!!)

val a = (alpha * 255).roundToInt()

val r = (rgb shr 16) and 0xFF
val g = (rgb shr 8) and 0xFF
val b = rgb and 0xFF

moduleValue.set(Color(a shl 24 or (r shl 16) or (g shl 8) or b, true))
}
}
}

else -> {}
}

// chat("§7[§3§lAutoSettings§7] §a§l${module.getName()}§7 value §8§l${moduleValue.name}§7 set to §c§l$value§7.")
moduleValue.fromText(value)
chat("§7[§3§lAutoSettings§7] §a§l${module.getName()}§7 value §8§l${moduleValue.name}§7 set to §c§l$value§7.")
} catch (e: Exception) {
chat("§7[§3§lAutoSettings§7] §a§l${e.javaClass.name}§7(${e.message}) §cAn Exception occurred while setting §a§l$value§c to §a§l${moduleValue.name}§c in §a§l${module.getName()}§c.")
}
Expand All @@ -224,7 +177,7 @@ object SettingsUtils {
if (values) {
for (value in module.values) {
if (all || !value.subjective && value.shouldRender()) {
val valueString = "${module.name} ${value.name} ${value.getString()}"
val valueString = "${module.name} ${value.name} ${value.toText()}"

if (valueString.isNotBlank()) {
appendLine(valueString)
Expand Down
Loading

0 comments on commit 44e0d3d

Please sign in to comment.