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

feat: improve flag-check #4212

Draft
wants to merge 2 commits into
base: nextgen
Choose a base branch
from
Draft
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 @@ -21,91 +21,142 @@ package net.ccbluex.liquidbounce.features.module.modules.misc
import net.ccbluex.liquidbounce.config.ToggleableConfigurable
import net.ccbluex.liquidbounce.event.events.NotificationEvent
import net.ccbluex.liquidbounce.event.events.PacketEvent
import net.ccbluex.liquidbounce.event.events.WorldRenderEvent
import net.ccbluex.liquidbounce.event.handler
import net.ccbluex.liquidbounce.event.repeatable
import net.ccbluex.liquidbounce.features.module.Category
import net.ccbluex.liquidbounce.features.module.Module
import net.ccbluex.liquidbounce.render.engine.Color4b
import net.ccbluex.liquidbounce.utils.client.MessageMetadata
import net.ccbluex.liquidbounce.utils.client.chat
import net.ccbluex.liquidbounce.utils.client.notification
import net.ccbluex.liquidbounce.utils.render.WireframePlayer
import net.minecraft.network.packet.s2c.common.DisconnectS2CPacket
import net.minecraft.network.packet.s2c.play.PlayerPositionLookS2CPacket
import net.minecraft.util.math.Vec3d
import org.apache.commons.lang3.StringUtils

/**
* alerts you about flags
* Module Flag Check.
*
* Alerts you about set backs.
*/
object ModuleFlagCheck : Module("FlagCheck", Category.MISC, aliases = arrayOf("FlagDetect")) {

object ModuleFlagCheck: Module("FlagCheck", Category.MISC, aliases = arrayOf("FlagDetect")) {

private var alertThroughChat by boolean("AlertThroughChat", true)
private var chatMessage by boolean("ChatMessage", true)
private var notification by boolean("Notification", false)
private var invalidAttributes by boolean("InvalidAttributes", false)

private object ResetFlags : ToggleableConfigurable(this, "ResetFlags", true) {

private var afterSeconds by int("After", 30, 1..300, "s")

@Suppress("unused")
private val repeatable = repeatable {
clearFlags()
flagCount = 0
waitSeconds(afterSeconds)
}

}

private object Render : ToggleableConfigurable(this, "Render", true) {

private val notInFirstPerson by boolean("NotInFirstPerson", true)
//private var renderTime by int("Alive", 1000, 1..2000, "ms")
private var color by color("Color", Color4b.RED.alpha(100).darker())
private var outlineColor by color("OutlineColor", Color4b.RED.darker())

val wireframePlayer = WireframePlayer(Vec3d.ZERO, 0f, 0f)
var creationTime = 0L

@Suppress("unused")
val renderHandler = handler<WorldRenderEvent> { // TODO fade out
if (notInFirstPerson && mc.options.perspective.isFirstPerson) {
return@handler
}

//if (System.currentTimeMillis() - creationTime <= renderTime) {
wireframePlayer.render(it, color, outlineColor)
//}
}

}

init {
tree(ResetFlags)
tree(Render)
}

private var flagCount = 0
private fun clearFlags() {
flagCount = 0
}

@Suppress("unused")
private val packetHandler = handler<PacketEvent> { event ->
when (event.packet) {
when (val packet = event.packet) {
is PlayerPositionLookS2CPacket -> {
if (player.age > 25) {
flagCount++
alert(AlertReason.LAGBACK, flagCount)
if (player.age <= 25) {
return@handler
}

flagCount++
alert(AlertReason.LAGBACK)
Render.creationTime = System.currentTimeMillis()
Render.wireframePlayer.setPosRot(packet.x, packet.y, packet.z, packet.yaw, packet.pitch)
}

is DisconnectS2CPacket -> {
clearFlags()
flagCount = 0
}
}
}

@Suppress("unused")
private val repeatable = repeatable {
if (!invalidAttributes) {
return@repeatable
}

val invalidHeath = player.health <= 0f && player.isAlive
val invalidHunger = player.hungerManager.foodLevel <= 0

if (!invalidHeath && !invalidHunger) {
return@repeatable
}

val invalidReasons = mutableListOf<String>()

val invalidReason = mutableListOf<String>()
if (player.health <= 0.0f && player.isAlive) {
invalidReason.add("Health")
if (invalidHeath) {
invalidReasons.add("Health")
}
if (player.hungerManager.foodLevel <= 0) {
invalidReason.add("Hunger")

if (invalidHunger) {
invalidReasons.add("Hunger")
}

if (invalidReason.isNotEmpty()) {
if (invalidReasons.isNotEmpty()) {
flagCount++

val reasonString = invalidReason.joinToString()
invalidReason.clear()
alert(AlertReason.INVALID, flagCount, reasonString)
val reasonString = invalidReasons.joinToString()
alert(AlertReason.INVALID, reasonString)
}
}

private fun alert(reason: AlertReason, count: Int, extra: String = "") {
flagCount++

val message = if (extra.isBlank()) {
message("alert", message(reason.key), count)
private fun alert(reason: AlertReason, extra: String? = null) {
val message = if (StringUtils.isEmpty(extra)) {
message("alert", message(reason.key), flagCount)
} else {
message("alertWithExtra", message(reason.key), extra, count)
message("alertWithExtra", message(reason.key), extra!!, flagCount)
}

if (!alertThroughChat) {
if (notification) {
notification(name, message, NotificationEvent.Severity.INFO)
} else {
chat(message)
}

if (chatMessage) {
chat(message, metadata = MessageMetadata(id = "$name#${reason.key}"))
}
}

@Suppress("SpellCheckingInspection")
private enum class AlertReason(val key: String) {
INVALID("invalid"),
LAGBACK("lagback")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,9 @@ data class Color4b(val r: Int, val g: Int, val b: Int, val a: Int) {
} else {
alpha((a * fade).toInt())
}

fun darker() = Color4b(darkerChannel(r), darkerChannel(g), darkerChannel(b), a)

private fun darkerChannel(value: Int) = (value * 0.7).toInt().coerceAtLeast(0)

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package net.ccbluex.liquidbounce.utils.render

import net.ccbluex.liquidbounce.event.events.WorldRenderEvent
import net.ccbluex.liquidbounce.render.BoxRenderer
import net.ccbluex.liquidbounce.render.engine.Color4b
import net.ccbluex.liquidbounce.render.renderEnvironmentForWorld
import net.ccbluex.liquidbounce.render.withPositionRelativeToCamera
import net.minecraft.util.math.Box
import net.minecraft.util.math.MathHelper
import net.minecraft.util.math.Vec3d
import org.joml.Quaternionf

// pixels / (16 + 16)
val LIMB = Box(0.0, 0.0, 0.0, 0.125, 0.375, 0.125)
val BODY = Box(0.0, 0.0, 0.0, 0.25, 0.375, 0.125)
val HEAD = Box(0.0, 0.0, 0.0, 0.25, 0.25, 0.25)

val RENDER_LEFT_LEG: Box = LIMB.offset(-LIMB.maxX, 0.0, 0.0)
val RENDER_RIGHT_LEG: Box = LIMB
val RENDER_BODY: Box = BODY.offset(-LIMB.maxX, LIMB.maxY, 0.0)
val RENDER_LEFT_ARM: Box = LIMB.offset(-2 * LIMB.maxX, LIMB.maxY, 0.0)
val RENDER_RIGHT_ARM: Box = LIMB.offset(BODY.maxX - LIMB.maxX, LIMB.maxY, 0.0)
val RENDER_HEAD: Box = HEAD.offset(-LIMB.maxX, LIMB.maxY * 2, -HEAD.maxZ * 0.25)

data class WireframePlayer(var pos: Vec3d, var yaw: Float, var pitch: Float) {

fun render(event: WorldRenderEvent, color: Color4b, outlineColor: Color4b) {
renderEnvironmentForWorld(event.matrixStack) {
withPositionRelativeToCamera(pos) {
val matrix = matrixStack.peek().positionMatrix
val yRot = -MathHelper.wrapDegrees(yaw.toDouble())
matrix.rotate(Quaternionf().rotationY(Math.toRadians(yRot).toFloat()))
matrix.scale(1.9f)

BoxRenderer.drawWith(this) {
drawBox(RENDER_LEFT_LEG, color, outlineColor)
drawBox(RENDER_RIGHT_LEG, color, outlineColor)
drawBox(RENDER_BODY, color, outlineColor)
drawBox(RENDER_LEFT_ARM, color, outlineColor)
drawBox(RENDER_RIGHT_ARM, color, outlineColor)

matrix.translate(0f, RENDER_HEAD.minY.toFloat(), 0f)
matrix.rotate(Quaternionf().rotationX(Math.toRadians(pitch.toDouble()).toFloat()))
matrix.translate(0f, -RENDER_HEAD.minY.toFloat(), 0f)

drawBox(RENDER_HEAD, color, outlineColor)
}
}
}
}

fun setPosRot(x: Double, y: Double, z: Double, yaw: Float, pitch: Float) {
this.pos = Vec3d(x, y, z)
this.yaw = yaw
this.pitch = pitch
}

}
Loading