Skip to content

Commit

Permalink
refactor(legacy): render and other code cleanup (#5015)
Browse files Browse the repository at this point in the history
* AutoRod entity list

* Language decode

* Client Features

* Nuker & Fucker breaking render

* RenderUtils WorldRenderer from Tessellator

* ESP & PointerESP entity display name color

* Background Tessellator
  • Loading branch information
MukjepScarlet authored Dec 22, 2024
1 parent 97bedfa commit 03a1c0a
Show file tree
Hide file tree
Showing 14 changed files with 271 additions and 273 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ object AutoRod : Module("AutoRod", Category.COMBAT, hideModule = false) {

if (isSelected(facingEntity, true)) {
// Checks how many enemy is nearby, if <= then should rod.
if (nearbyEnemies?.size!! <= enemiesNearby) {
if (nearbyEnemies.size <= enemiesNearby) {

// Check if the enemy's health is below the threshold.
if (ignoreOnEnemyLowHealth) {
Expand Down Expand Up @@ -177,8 +177,8 @@ object AutoRod : Module("AutoRod", Category.COMBAT, hideModule = false) {
return -1
}

private fun getAllNearbyEnemies(): List<Entity>? {
val player = mc.thePlayer ?: return null
private fun getAllNearbyEnemies(): List<Entity> {
val player = mc.thePlayer ?: return emptyList()

return mc.theWorld.loadedEntityList.filter {
isSelected(it, true) && player.getDistanceToEntityBox(it) < activationDistance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@ import net.ccbluex.liquidbounce.event.handler
import net.ccbluex.liquidbounce.features.module.Category
import net.ccbluex.liquidbounce.features.module.Module
import net.ccbluex.liquidbounce.features.module.modules.misc.AntiBot.isBot
import net.ccbluex.liquidbounce.ui.font.GameFontRenderer.Companion.getColorIndex
import net.ccbluex.liquidbounce.utils.attack.EntityUtils.colorFromDisplayName
import net.ccbluex.liquidbounce.utils.attack.EntityUtils.isLookingOnEntities
import net.ccbluex.liquidbounce.utils.attack.EntityUtils.isSelected
import net.ccbluex.liquidbounce.utils.client.ClientUtils.LOGGER
import net.ccbluex.liquidbounce.utils.extensions.*
import net.ccbluex.liquidbounce.utils.render.ColorSettingsInteger
import net.ccbluex.liquidbounce.utils.render.ColorUtils
import net.ccbluex.liquidbounce.utils.render.ColorUtils.rainbow
import net.ccbluex.liquidbounce.utils.render.RenderUtils.draw2D
import net.ccbluex.liquidbounce.utils.render.RenderUtils.drawEntityBox
Expand Down Expand Up @@ -119,6 +118,7 @@ object ESP : Module("ESP", Category.RENDER, hideModule = false) {

when (mode) {
"Box", "OtherBox" -> drawEntityBox(entity, color, mode != "OtherBox")

"2D" -> {
draw2D(entity, pos.xCoord, pos.yCoord, pos.zCoord, color.rgb, Color.BLACK.rgb)
}
Expand Down Expand Up @@ -232,20 +232,9 @@ object ESP : Module("ESP", Category.RENDER, hideModule = false) {
return Color.BLUE

if (colorTeam) {
val chars = (entity.displayName ?: return@run).formattedText.toCharArray()
var color = Int.MAX_VALUE

for (i in chars.indices) {
if (chars[i] != '§' || i + 1 >= chars.size) continue

val index = getColorIndex(chars[i + 1])
if (index < 0 || index > 15) continue

color = ColorUtils.hexColors[index]
break
entity.colorFromDisplayName()?.let {
return it
}

return Color(color)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import net.ccbluex.liquidbounce.features.module.Category
import net.ccbluex.liquidbounce.features.module.Module
import net.ccbluex.liquidbounce.features.module.modules.misc.AntiBot.isBot
import net.ccbluex.liquidbounce.features.module.modules.misc.Teams
import net.ccbluex.liquidbounce.ui.font.GameFontRenderer.Companion.getColorIndex
import net.ccbluex.liquidbounce.utils.attack.EntityUtils
import net.ccbluex.liquidbounce.utils.attack.EntityUtils.colorFromDisplayName
import net.ccbluex.liquidbounce.utils.attack.EntityUtils.getHealth
import net.ccbluex.liquidbounce.utils.render.ColorSettingsInteger
import net.ccbluex.liquidbounce.utils.render.ColorUtils
Expand Down Expand Up @@ -116,7 +116,7 @@ object PointerESP : Module("PointerESP", Category.RENDER, hideModule = false) {
glEnable(GL_LINE_SMOOTH)
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST)

for (entity in world.loadedEntityList.filterNotNull()) {
for (entity in world.loadedEntityList) {
if (entity !is EntityLivingBase || !bot && isBot(entity)) continue
if (!team && Teams.isInYourTeam(entity)) continue

Expand All @@ -142,22 +142,8 @@ object PointerESP : Module("PointerESP", Category.RENDER, hideModule = false) {
val targetHealth = getHealth(entity, healthFromScoreboard, absorption)
val arrowsColor = when {
targetHealth <= 0 -> Color(255, 0, 0, alpha)
colorTeam -> {
val chars = (entity.displayName ?: return).formattedText.toCharArray()
var color = Int.MAX_VALUE

for (i in chars.indices) {
if (chars[i] != '§' || i + 1 >= chars.size) continue

val index = getColorIndex(chars[i + 1])
if (index < 0 || index > 15) continue

color = ColorUtils.hexColors[index]
break
}

Color(color)
}
colorTeam -> entity.colorFromDisplayName() ?: continue

healthMode == "Custom" -> {
ColorUtils.interpolateHealthColor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ import net.ccbluex.liquidbounce.utils.block.BlockUtils.getBlockName
import net.ccbluex.liquidbounce.utils.block.BlockUtils.getCenterDistance
import net.ccbluex.liquidbounce.utils.block.BlockUtils.isBlockBBValid
import net.ccbluex.liquidbounce.utils.block.block
import net.ccbluex.liquidbounce.utils.block.blockById
import net.ccbluex.liquidbounce.utils.block.center
import net.ccbluex.liquidbounce.utils.client.PacketUtils.sendPacket
import net.ccbluex.liquidbounce.utils.extensions.*
import net.ccbluex.liquidbounce.utils.render.ColorUtils
import net.ccbluex.liquidbounce.utils.render.RenderUtils.disableGlCap
import net.ccbluex.liquidbounce.utils.render.RenderUtils.drawBlockBox
import net.ccbluex.liquidbounce.utils.render.RenderUtils.drawBlockDamageText
import net.ccbluex.liquidbounce.utils.render.RenderUtils.enableGlCap
import net.ccbluex.liquidbounce.utils.render.RenderUtils.resetCaps
import net.ccbluex.liquidbounce.utils.rotation.RotationSettings
Expand Down Expand Up @@ -300,51 +303,22 @@ object Fucker : Module("Fucker", Category.WORLD, hideModule = false) {

val onRender3D = handler<Render3DEvent> {
val pos = pos ?: return@handler
val player = mc.thePlayer ?: return@handler
val renderManager = mc.renderManager

// Check if it is the player's own bed
if (ignoreOwnBed && isBedNearSpawn(pos)) {
if (mc.thePlayer == null || ignoreOwnBed && isBedNearSpawn(pos)) {
return@handler
}

if (blockProgress) {
if (Block.getBlockById(block) == Blocks.air) return@handler

val progress = ((currentDamage * 100).coerceIn(0f, 100f)).toInt()
val progressText = "%d%%".format(progress)

glPushAttrib(GL_ENABLE_BIT)
glPushMatrix()

val (x, y, z) = pos.center - renderManager.renderPos

// Translate to block position
glTranslated(x, y, z)
if (block.blockById == Blocks.air) return@handler

glRotatef(-renderManager.playerViewY, 0F, 1F, 0F)
glRotatef(renderManager.playerViewX, 1F, 0F, 0F)

disableGlCap(GL_LIGHTING, GL_DEPTH_TEST)
enableGlCap(GL_BLEND)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

val fontRenderer = font
val color = ((colorRed and 0xFF) shl 16) or ((colorGreen and 0xFF) shl 8) or (colorBlue and 0xFF)

// Scale
val scale = ((player.getDistanceSq(pos) / 8F).coerceAtLeast(1.5) / 150F) * scale
glScaled(-scale, -scale, scale)

// Draw text
val width = fontRenderer.getStringWidth(progressText) * 0.5f
fontRenderer.drawString(
progressText, -width, if (fontRenderer == Fonts.minecraftFont) 1F else 1.5F, color, fontShadow
if (blockProgress) {
pos.drawBlockDamageText(
currentDamage,
font,
fontShadow,
ColorUtils.packARGBValue(colorRed, colorGreen, colorBlue),
scale,
)

resetCaps()
glPopMatrix()
glPopAttrib()
}

// Render block box
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ import net.ccbluex.liquidbounce.ui.font.Fonts
import net.ccbluex.liquidbounce.utils.block.BlockUtils.getCenterDistance
import net.ccbluex.liquidbounce.utils.block.BlockUtils.searchBlocks
import net.ccbluex.liquidbounce.utils.block.block
import net.ccbluex.liquidbounce.utils.block.blockById
import net.ccbluex.liquidbounce.utils.block.center
import net.ccbluex.liquidbounce.utils.client.PacketUtils.sendPacket
import net.ccbluex.liquidbounce.utils.extensions.*
import net.ccbluex.liquidbounce.utils.render.ColorUtils
import net.ccbluex.liquidbounce.utils.render.RenderUtils.disableGlCap
import net.ccbluex.liquidbounce.utils.render.RenderUtils.drawBlockBox
import net.ccbluex.liquidbounce.utils.render.RenderUtils.drawBlockDamageText
import net.ccbluex.liquidbounce.utils.render.RenderUtils.enableGlCap
import net.ccbluex.liquidbounce.utils.render.RenderUtils.resetCaps
import net.ccbluex.liquidbounce.utils.rotation.RotationSettings
Expand Down Expand Up @@ -235,46 +238,18 @@ object Nuker : Module("Nuker", Category.WORLD, gameDetecting = false, hideModule

val onRender3D = handler<Render3DEvent> {
val player = mc.thePlayer ?: return@handler
val renderManager = mc.renderManager ?: return@handler

if (blocks.blockById == air) return@handler

for (pos in attackedBlocks) {
if (blockProgress) {
if (Block.getBlockById(blocks) == air) return@handler

val progress = (currentDamage * 100).coerceIn(0f, 100f).toInt()
val progressText = "%d%%".format(progress)

glPushAttrib(GL_ENABLE_BIT)
glPushMatrix()

val (x, y, z) = pos.center - renderManager.renderPos

// Translate to block position
glTranslated(x, y, z)

glRotatef(-renderManager.playerViewY, 0F, 1F, 0F)
glRotatef(renderManager.playerViewX, 1F, 0F, 0F)

disableGlCap(GL_LIGHTING, GL_DEPTH_TEST)
enableGlCap(GL_BLEND)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

val fontRenderer = font
val color = ((colorRed and 0xFF) shl 16) or ((colorGreen and 0xFF) shl 8) or (colorBlue and 0xFF)

// Scale
val scale = ((player.getDistanceSq(pos) / 8F).coerceAtLeast(1.5) / 150F) * scale
glScaled(-scale, -scale, scale)

// Draw text
val width = fontRenderer.getStringWidth(progressText) * 0.5f
fontRenderer.drawString(
progressText, -width, if (fontRenderer == Fonts.minecraftFont) 1F else 1.5F, color, fontShadow
pos.drawBlockDamageText(
currentDamage,
font,
fontShadow,
ColorUtils.packARGBValue(colorRed, colorGreen, colorBlue),
scale,
)

resetCaps()
glPopMatrix()
glPopAttrib()
}

// Just draw all blocks
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,11 @@ object ClientFixes : MinecraftInstance, Listenable {
return@runCatching
}

packet is C17PacketCustomPayload -> {
if (blockPayloadPackets && !packet.channelName.startsWith("MC|")) {
packet is C17PacketCustomPayload -> when {
blockPayloadPackets && !packet.channelName.startsWith("MC|") -> {
event.cancelEvent()
} else if (packet.channelName == "MC|Brand") {
}
packet.channelName == "MC|Brand" -> {
packet.data = PacketBuffer(Unpooled.buffer()).writeString(
when (clientBrand) {
"Vanilla" -> "vanilla"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
package net.ccbluex.liquidbounce.features.special

import com.google.gson.JsonObject
import com.google.gson.JsonParser
import com.jagrosh.discordipc.IPCClient
import com.jagrosh.discordipc.IPCListener
import com.jagrosh.discordipc.entities.RichPresence
Expand All @@ -24,6 +23,7 @@ import net.ccbluex.liquidbounce.utils.client.MinecraftInstance
import net.ccbluex.liquidbounce.utils.client.ServerUtils
import net.ccbluex.liquidbounce.utils.kotlin.SharedScopes
import net.ccbluex.liquidbounce.utils.io.HttpUtils.get
import net.ccbluex.liquidbounce.utils.io.parseJson
import org.json.JSONObject
import java.io.IOException
import java.time.OffsetDateTime
Expand Down Expand Up @@ -155,7 +155,7 @@ object ClientRichPresence : MinecraftInstance {
val (response, _) = get("$CLIENT_CLOUD/discord.json")

// Read from web and convert to json object
val json = JsonParser().parse(response)
val json = response.parseJson()

if (json !is JsonObject)
return
Expand Down
9 changes: 4 additions & 5 deletions src/main/java/net/ccbluex/liquidbounce/lang/Language.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
*/
package net.ccbluex.liquidbounce.lang

import net.ccbluex.liquidbounce.file.FileManager.PRETTY_GSON
import net.ccbluex.liquidbounce.utils.client.ClientUtils.LOGGER
import net.ccbluex.liquidbounce.utils.client.MinecraftInstance
import net.ccbluex.liquidbounce.utils.io.decodeJson

fun translationMenu(key: String, vararg args: Any) = LanguageManager.getTranslation("menu.$key", *args)
fun translation(key: String, vararg args: Any) = LanguageManager.getTranslation(key, *args)
Expand All @@ -34,7 +34,7 @@ object LanguageManager : MinecraftInstance {
"bg_BG",
"ru_RU"
)
private val languageMap = mutableMapOf<String, Language>()
private val languageMap = hashMapOf<String, Language>()

/**
* Load all languages which are pre-defined in [knownLanguages] and stored in assets.
Expand All @@ -45,9 +45,8 @@ object LanguageManager : MinecraftInstance {
fun loadLanguages() {
for (language in knownLanguages) {
runCatching {
val languageFile = javaClass.getResourceAsStream("/assets/minecraft/liquidbounce/lang/$language.json")
val languageJson = PRETTY_GSON.fromJson(languageFile.bufferedReader(), Language::class.java)
languageMap[language] = languageJson
languageMap[language] = javaClass.getResourceAsStream("/assets/minecraft/liquidbounce/lang/$language.json")!!
.bufferedReader().use { it.decodeJson() }
}.onSuccess {
LOGGER.info("Loaded language $language")
}.onFailure {
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/net/ccbluex/liquidbounce/utils/attack/EntityUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,20 @@ package net.ccbluex.liquidbounce.utils.attack
import net.ccbluex.liquidbounce.features.module.modules.combat.NoFriends
import net.ccbluex.liquidbounce.features.module.modules.misc.AntiBot.isBot
import net.ccbluex.liquidbounce.features.module.modules.misc.Teams
import net.ccbluex.liquidbounce.ui.font.GameFontRenderer.Companion.getColorIndex
import net.ccbluex.liquidbounce.utils.client.MinecraftInstance
import net.ccbluex.liquidbounce.utils.extensions.isAnimal
import net.ccbluex.liquidbounce.utils.extensions.isClientFriend
import net.ccbluex.liquidbounce.utils.extensions.isMob
import net.ccbluex.liquidbounce.utils.extensions.toRadiansD
import net.ccbluex.liquidbounce.utils.kotlin.StringUtils.contains
import net.ccbluex.liquidbounce.utils.render.ColorUtils
import net.minecraft.entity.Entity
import net.minecraft.entity.EntityLivingBase
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.tileentity.TileEntity
import net.minecraft.util.Vec3
import java.awt.Color
import kotlin.math.cos
import kotlin.math.sin

Expand Down Expand Up @@ -113,4 +116,21 @@ object EntityUtils : MinecraftInstance {
return if (health > 0) health else 20f
}

fun Entity.colorFromDisplayName(): Color? {
val chars = (this.displayName ?: return null).formattedText.toCharArray()
var color = Int.MAX_VALUE

for (i in 0 until chars.lastIndex) {
if (chars[i] != '§') continue

val index = getColorIndex(chars[i + 1])
if (index < 0 || index > 15) continue

color = ColorUtils.hexColors[index]
break
}

return Color(color)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.google.gson.JsonParser
import net.ccbluex.liquidbounce.file.FileManager.PRETTY_GSON
import org.apache.commons.codec.digest.DigestUtils
import java.io.File
import java.io.Reader

private val parser = JsonParser()

Expand All @@ -15,6 +16,10 @@ fun File.writeJson(content: Any?, gson: Gson = PRETTY_GSON) = bufferedWriter().u

fun File.readJson(): JsonElement = bufferedReader().use { parser.parse(it) }

fun String.parseJson(): JsonElement = parser.parse(this)

fun Reader.readJson(): JsonElement = parser.parse(this)

fun File.sha256(): String = inputStream().use { DigestUtils.sha256Hex(it) }

val File.isEmpty: Boolean get() = length() == 0L
Loading

0 comments on commit 03a1c0a

Please sign in to comment.