Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions common/src/main/kotlin/com/lambda/Lambda.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import net.minecraft.util.math.BlockPos
import org.apache.logging.log4j.LogManager
import org.apache.logging.log4j.Logger
import java.awt.Color
import java.util.*


object Lambda {
Expand All @@ -41,6 +42,7 @@ object Lambda {
.registerTypeAdapter(BlockPos::class.java, BlockPosSerializer)
.registerTypeAdapter(Block::class.java, BlockSerializer)
.registerTypeAdapter(GameProfile::class.java, GameProfileSerializer)
.registerTypeAdapter(Optional::class.java, OptionalSerializer)
.create()

fun initialize() {
Expand Down
19 changes: 14 additions & 5 deletions common/src/main/kotlin/com/lambda/config/Configurable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,9 @@ abstract class Configurable(
* The type parameter [T] must either be a primitive type or a type with a registered type adapter in [Lambda.gson].
*
* @param name The unique identifier for the setting.
* @param defaultValue The default [ArrayList] value of type [T] for the setting.
* @param defaultValue The default [List] value of type [T] for the setting.
* @param description A brief explanation of the setting's purpose and behavior.
* @param hackDelegates A flag that determines whether the setting should be serialized with the default value.
* @param visibility A lambda expression that determines the visibility status of the setting.
*
* ```kotlin
Expand All @@ -175,12 +176,14 @@ abstract class Configurable(
defaultValue: List<T>,
description: String = "",
noinline visibility: () -> Boolean = { true },
hackDelegates: Boolean = false,
) = ListSetting(
name,
defaultValue.toMutableList(),
TypeToken.getParameterized(MutableList::class.java, T::class.java).type,
description,
visibility
hackDelegates,
visibility,
).also {
settings.add(it)
}
Expand All @@ -193,6 +196,7 @@ abstract class Configurable(
* @param name The unique identifier for the setting.
* @param defaultValue The default [Map] value of type [K] and [V] for the setting.
* @param description A brief explanation of the setting's purpose and behavior.
* @param hackDelegates A flag that determines whether the setting should be serialized with the default value.
* @param visibility A lambda expression that determines the visibility status of the setting.
*
* ```kotlin
Expand All @@ -206,12 +210,14 @@ abstract class Configurable(
name: String,
defaultValue: Map<K, V>,
description: String = "",
hackDelegates: Boolean,
noinline visibility: () -> Boolean = { true },
) = MapSetting(
name,
defaultValue.toMutableMap(),
TypeToken.getParameterized(Map::class.java, K::class.java, V::class.java).type,
TypeToken.getParameterized(MutableMap::class.java, K::class.java, V::class.java).type,
description,
hackDelegates,
visibility
).also {
settings.add(it)
Expand All @@ -225,6 +231,7 @@ abstract class Configurable(
* @param name The unique identifier for the setting.
* @param defaultValue The default [Set] value of type [T] for the setting.
* @param description A brief explanation of the setting's purpose and behavior.
* @param hackDelegates A flag that determines whether the setting should be serialized with the default value.
* @param visibility A lambda expression that determines the visibility status of the setting.
*
* ```kotlin
Expand All @@ -238,13 +245,15 @@ abstract class Configurable(
name: String,
defaultValue: Set<T>,
description: String = "",
hackDelegates: Boolean = false,
noinline visibility: () -> Boolean = { true },
) = SetSetting(
name,
defaultValue.toMutableSet(),
TypeToken.getParameterized(Set::class.java, T::class.java).type,
TypeToken.getParameterized(MutableSet::class.java, T::class.java).type,
description,
visibility
hackDelegates,
visibility,
).also {
settings.add(it)
}
Expand Down
9 changes: 3 additions & 6 deletions common/src/main/kotlin/com/lambda/config/Configuration.kt
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,15 @@ abstract class Configuration : Jsonable {

private fun save() {
with(primary) {
if (exists()) {
copyTo(backup, true)
}
if (exists()) copyTo(backup, true)

parentFile.mkdirs()
writeText(gson.toJson(toJson()))
}
}

private fun load(file: File) {
check(file.exists()) {
"No configuration file found for ${configName.capitalize()}"
}
check(file.exists()) { "No configuration file found for ${configName.capitalize()}" }

loadFromJson(JsonParser.parseReader(file.reader()).asJsonObject)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.lambda.config.serializer

import com.google.gson.*
import java.lang.reflect.Type
import java.util.*

object OptionalSerializer : JsonSerializer<Optional<Any>>, JsonDeserializer<Optional<Any>> {
override fun serialize(src: Optional<Any>?, typeOfSrc: Type?, context: JsonSerializationContext?): JsonElement =
src?.map { context?.serialize(it) }?.orElse(JsonNull.INSTANCE) ?: JsonNull.INSTANCE

override fun deserialize(
json: JsonElement?,
typeOfT: Type?,
context: JsonDeserializationContext?
): Optional<Any> =
Optional.ofNullable(json?.let { context?.deserialize(it, typeOfT) ?: Optional.empty<Any>() })
}
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
package com.lambda.config.settings.collections

import com.google.gson.JsonElement
import com.lambda.Lambda.gson
import com.lambda.config.AbstractSetting
import java.lang.reflect.Type

class ListSetting<T : Any>(
override val name: String,
defaultValue: MutableList<T>,
private val type: Type,
private val defaultValue: MutableList<T>,
type: Type,
description: String,
private val hackDelegates: Boolean,
visibility: () -> Boolean,
) : AbstractSetting<MutableList<T>>(
defaultValue,
type,
description,
visibility
) {
override fun loadFromJson(serialized: JsonElement) {
value = gson.fromJson(serialized, type)
}

override fun toJson(): JsonElement {
return gson.toJsonTree(value)
if (hackDelegates) value = defaultValue
return super.toJson()
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
package com.lambda.config.settings.collections

import com.google.gson.JsonElement
import com.lambda.config.AbstractSetting
import java.lang.reflect.Type

class MapSetting<K, V>(
override val name: String,
defaultValue: MutableMap<K, V>,
private val defaultValue: Map<K, V>,
type: Type,
description: String,
private val hackDelegates: Boolean,
visibility: () -> Boolean,
) : AbstractSetting<MutableMap<K, V>>(
) : AbstractSetting<Map<K, V>>(
defaultValue,
type,
description,
visibility
)
) {
override fun toJson(): JsonElement {
if (hackDelegates) value = defaultValue
return super.toJson()
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
package com.lambda.config.settings.collections

import com.google.gson.JsonElement
import com.lambda.config.AbstractSetting
import java.lang.reflect.Type

class SetSetting<T : Any>(
override val name: String,
defaultValue: MutableSet<T>,
private val defaultValue: MutableSet<T>,
type: Type,
description: String,
private val hackDelegates: Boolean,
visibility: () -> Boolean,
) : AbstractSetting<MutableSet<T>>(
defaultValue,
type,
description,
visibility
)
) {
override fun toJson(): JsonElement {
if (hackDelegates) value = defaultValue
return super.toJson()
}
}
2 changes: 1 addition & 1 deletion common/src/main/kotlin/com/lambda/friend/FriendRegistry.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import com.mojang.authlib.GameProfile
object FriendRegistry : Configurable(FriendConfig), Loadable {
override val name = "friends"

val friends by setting("friends", listOf<GameProfile>()) // Todo: Fix the fucking delegates
val friends by setting("friends", listOf<GameProfile>(), hackDelegates = true)

override fun load(): String {
return "Loaded ${friends.size} friends"
Expand Down
2 changes: 1 addition & 1 deletion common/src/main/kotlin/com/lambda/module/Module.kt
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ abstract class Module(
private val isEnabledSetting = setting("Enabled", enabledByDefault, visibility = { false })
private val keybindSetting = setting("Keybind", defaultKeybind)
private val isVisible = setting("Visible", true)
val customTags = setting("Tags", emptySet<ModuleTag>(), visibility = { false })
val customTags = setting("Tags", setOf<ModuleTag>(), visibility = { false })

var isEnabled by isEnabledSetting
val isDisabled get() = !isEnabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.lambda.module.modules.network

import com.lambda.Lambda
import com.lambda.Lambda.mc
import com.lambda.event.EventFlow.lambdaScope
import com.lambda.event.events.PacketEvent
import com.lambda.event.events.TickEvent
import com.lambda.event.listener.UnsafeListener.Companion.unsafeConcurrentListener
Expand All @@ -16,10 +15,8 @@ import com.lambda.util.DynamicReflectionSerializer.dynamicString
import com.lambda.util.FolderRegister
import com.lambda.util.Formatting.getTime
import com.lambda.util.text.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.channels.BufferOverflow
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.launch
import net.minecraft.network.packet.Packet
import java.awt.Color
import java.io.File
Expand All @@ -38,8 +35,8 @@ object PacketLogger : Module(
private val networkSide by setting("Network Side", NetworkSide.ANY, "Side of the network to log packets from")
private val logTicks by setting("Log Ticks", true, "Show game ticks in the log")
private val scope by setting("Scope", Scope.ANY, "Scope of packets to log")
private val whitelist by setting("Whitelist Packets", arrayListOf<String>(), "Packets to whitelist") { scope == Scope.WHITELIST }
private val blacklist by setting("Blacklist Packets", arrayListOf<String>(), "Packets to blacklist") { scope == Scope.BLACKLIST }
private val whitelist by setting("Whitelist Packets", emptyList<String>(), "Packets to whitelist", visibility = { scope == Scope.WHITELIST })
private val blacklist by setting("Blacklist Packets", emptyList<String>(), "Packets to blacklist", visibility = { scope == Scope.BLACKLIST })
private val maxRecursionDepth by setting("Max Recursion Depth", 6, 1..10, 1, "Maximum recursion depth for packet serialization")
private val logConcurrent by setting("Build Data Concurrent", false, "Whether to serialize packets concurrently. Will not save packets in chronological order but wont lag the game.")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import com.lambda.Lambda.mc
import com.lambda.graphics.renderer.esp.ChunkedESP.Companion.newChunkedESP
import com.lambda.graphics.renderer.esp.DirectionMask
import com.lambda.graphics.renderer.esp.DirectionMask.buildSideMesh
import com.lambda.graphics.renderer.esp.DirectionMask.exclude
import com.lambda.graphics.renderer.esp.DirectionMask.mask
import com.lambda.graphics.renderer.esp.ESPRenderer
import com.lambda.graphics.renderer.esp.global.buildFilled
import com.lambda.graphics.renderer.esp.global.buildOutline
Expand All @@ -17,7 +15,6 @@ import net.minecraft.block.Blocks
import net.minecraft.client.render.model.BakedModel
import net.minecraft.util.math.BlockPos
import net.minecraft.util.math.Box
import net.minecraft.util.math.Direction
import java.awt.Color

object BlockESP : Module(
Expand Down Expand Up @@ -98,4 +95,4 @@ object BlockESP : Module(
buildOutline(box, outlineColor, sides, outlineMode)
}
}
}
}
1 change: 0 additions & 1 deletion common/src/main/kotlin/com/lambda/util/BlockUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import com.lambda.util.item.ItemUtils.shulkerBoxes
import net.minecraft.block.Block
import net.minecraft.block.BlockState
import net.minecraft.block.Blocks
import net.minecraft.client.world.ClientWorld
import net.minecraft.fluid.FluidState
import net.minecraft.fluid.Fluids
import net.minecraft.item.Item
Expand Down