Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: debug parameter/geometry with extension functions #5644

Merged
merged 2 commits into from
Feb 19, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ object ModuleDebug : ClientModule("Debug", Category.RENDER) {
private val expireHandler = tickHandler {
val currentTime = System.currentTimeMillis()

debugParameters.entries.removeIf { (parameter, capture) ->
(currentTime - capture.time) / 1000 >= expireTime
debugParameters.entries.removeIf { (_, capture) ->
currentTime - capture.time >= expireTime * 1000
}
}

Expand All @@ -155,8 +155,6 @@ object ModuleDebug : ClientModule("Debug", Category.RENDER) {
return@handler
}

val width = mc.window.scaledWidth

renderEnvironmentForGUI {
fontRenderer.withBuffers { buffers ->
/**
Expand Down Expand Up @@ -220,27 +218,25 @@ object ModuleDebug : ClientModule("Debug", Category.RENDER) {

commit(buffers)
}


}
}
}

inline fun debugGeometry(owner: Any, name: String, lazyGeometry: () -> DebuggedGeometry) {
fun debugGeometry(owner: Any, name: String, geometry: DebuggedGeometry) {
// Do not take any new debugging while the module is off
if (!running) {
return
}

debugGeometry(owner, name, lazyGeometry.invoke())
debuggedGeometry[DebuggedGeometryOwner(owner, name)] = geometry
}

fun debugGeometry(owner: Any, name: String, geometry: DebuggedGeometry) {
// Do not take any new debugging while the module is off
if (!running) {
inline fun Any.debugGeometry(name: String, lazyGeometry: () -> DebuggedGeometry) {
if (!ModuleDebug.running) {
return
}

debuggedGeometry[DebuggedGeometryOwner(owner, name)] = geometry
debugGeometry(owner = this, name, lazyGeometry())
}

private data class DebuggedGeometryOwner(val owner: Any, val name: String)
Expand All @@ -251,20 +247,20 @@ object ModuleDebug : ClientModule("Debug", Category.RENDER) {

private val debugParameters = hashMapOf<DebuggedParameter, ParameterCapture>()

inline fun debugParameter(owner: Any, name: String, lazyValue: () -> Any) {
fun debugParameter(owner: Any, name: String, value: Any?) {
if (!running) {
return
}

debugParameter(owner, name, lazyValue.invoke())
debugParameters[DebuggedParameter(owner, name)] = ParameterCapture(value = value)
}

fun debugParameter(owner: Any, name: String, value: Any?) {
if (!running) {
inline fun Any.debugParameter(name: String, lazyValue: () -> Any) {
if (!ModuleDebug.running) {
return
}

debugParameters[DebuggedParameter(owner, name)] = ParameterCapture(value = value)
debugParameter(owner = this, name, lazyValue())
}

fun getArrayEntryColor(idx: Int, length: Int): Color4b {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import net.ccbluex.liquidbounce.features.module.Category
import net.ccbluex.liquidbounce.features.module.ClientModule
import net.ccbluex.liquidbounce.utils.inventory.HotbarItemSlot
import net.ccbluex.liquidbounce.features.module.modules.render.ModuleDebug
import net.ccbluex.liquidbounce.features.module.modules.render.ModuleDebug.debugGeometry
import net.ccbluex.liquidbounce.features.module.modules.world.fucker.isSelfBedChoices
import net.ccbluex.liquidbounce.render.engine.Color4b
import net.ccbluex.liquidbounce.utils.block.placer.BlockPlacer
Expand Down Expand Up @@ -148,7 +149,7 @@ object ModuleBedDefender : ClientModule("BedDefender", category = Category.WORLD
)
}

ModuleDebug.debugGeometry(this, "PlacementPosition") {
debugGeometry("PlacementPosition") {
ModuleDebug.DebugCollection(
updatePositions.map { (_, pos) ->
ModuleDebug.DebuggedPoint(pos.toCenterPos(), Color4b.RED.with(a = 100))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package net.ccbluex.liquidbounce.utils.aiming.utils

import net.ccbluex.liquidbounce.features.module.modules.combat.aimbot.ModuleProjectileAimbot
import net.ccbluex.liquidbounce.features.module.modules.render.ModuleDebug
import net.ccbluex.liquidbounce.features.module.modules.render.ModuleDebug.debugGeometry
import net.ccbluex.liquidbounce.render.engine.Color4b
import net.ccbluex.liquidbounce.utils.client.world
import net.ccbluex.liquidbounce.utils.kotlin.mapArray
import net.ccbluex.liquidbounce.utils.math.geometry.Line
import net.ccbluex.liquidbounce.utils.math.geometry.NormalizedPlane
import net.ccbluex.liquidbounce.utils.math.geometry.PlaneSection
Expand Down Expand Up @@ -98,14 +100,14 @@ inline fun projectPointsOnBox(
// Find a point between the virtual eye and the target box such that every edge point of the box is behind it
// (from the perspective of the virtual eye). This position is used to craft a the targeting frame
val targetFrameOrigin = targetBox.edgePoints
.map { playerToBoxLine.getNearestPointTo(it) }
.mapArray { playerToBoxLine.getNearestPointTo(it) }
.minBy { it.squaredDistanceTo(virtualEye) }
.moveTowards(virtualEye, 0.1)

val plane = NormalizedPlane(targetFrameOrigin, playerToBoxLine.direction)
val (toMatrix, backMatrix) = getRotationMatricesForVec(plane.normalVec)

val projectedAndRotatedPoints = targetBox.edgePoints.map {
val projectedAndRotatedPoints = targetBox.edgePoints.mapArray {
plane.intersection(Line.fromPoints(virtualEye, it))!!.subtract(targetFrameOrigin).toVector3f().mul(backMatrix)
}

Expand All @@ -121,10 +123,9 @@ inline fun projectPointsOnBox(
maxY = max(maxY, it.y)
}

val posVec =
Vec3d(0.0, minY.toDouble(), minZ.toDouble()).toVector3f().mul(toMatrix).toVec3d().add(targetFrameOrigin)
val dirVecY = Vec3d(0.0, (maxY - minY).toDouble(), 0.0).toVector3f().mul(toMatrix).toVec3d()
val dirVecZ = Vec3d(0.0, 0.0, (maxZ - minZ).toDouble()).toVector3f().mul(toMatrix).toVec3d()
val posVec = Vector3f(0f, minY, minZ).mul(toMatrix).toVec3d().add(targetFrameOrigin)
val dirVecY = Vector3f(0f, maxY - minY, 0f).mul(toMatrix).toVec3d()
val dirVecZ = Vector3f(0f, 0f, maxZ - minZ).mul(toMatrix).toVec3d()

val planeSection = PlaneSection(posVec, dirVecY, dirVecZ)

Expand Down Expand Up @@ -165,16 +166,16 @@ fun findVisiblePointFromVirtualEye(
): Vec3d? {
val points = projectPointsOnBox(virtualEyes, box) ?: return null

val debugCollection = ModuleDebug.DebugCollection(points.map { ModuleDebug.DebuggedPoint(it, Color4b.BLUE, 0.01) })

ModuleDebug.debugGeometry(ModuleProjectileAimbot, "points", debugCollection)
ModuleProjectileAimbot.debugGeometry("points") {
ModuleDebug.DebugCollection(points.map { ModuleDebug.DebuggedPoint(it, Color4b.BLUE, 0.01) })
}

val rays = ArrayList<ModuleDebug.DebuggedGeometry>()

val center = box.center
val sortedPoints = points.sortedBy { it.distanceTo(center) }
points.sortBy { it.squaredDistanceTo(center) }

for (spot in sortedPoints) {
for (spot in points) {
val vecFromEyes = spot - virtualEyes
val raycastTarget = vecFromEyes * 2.0 + virtualEyes
val spotOnBox = box.raycast(virtualEyes, raycastTarget).getOrNull() ?: continue
Expand All @@ -186,12 +187,12 @@ fun findVisiblePointFromVirtualEye(
rays.add(ModuleDebug.DebuggedLineSegment(rayStart, spotOnBox, if (visible) Color4b.GREEN else Color4b.RED))

if (visible) {
ModuleDebug.debugGeometry(ModuleProjectileAimbot, "rays", ModuleDebug.DebugCollection(rays))
ModuleProjectileAimbot.debugGeometry("rays") { ModuleDebug.DebugCollection(rays) }
return spotOnBox
}
}

ModuleDebug.debugGeometry(ModuleProjectileAimbot, "rays", ModuleDebug.DebugCollection(rays))
ModuleProjectileAimbot.debugGeometry("rays") { ModuleDebug.DebugCollection(rays) }

return null
}
Expand Down
Loading