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/fix(legacy): add assumeNonVolatile to scoreboard & fix image causing 1281 gl error #4978

Merged
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 @@ -102,6 +102,7 @@ object PointerESP : Module("PointerESP", Category.RENDER, hideModule = false) {

private fun draw(ticks: Float) {
val player = mc.thePlayer ?: return
val world = mc.theWorld ?: return

val arrowRadius = -arrowRadius
val halfAngle = arrowAngle / 2
Expand All @@ -115,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 mc.theWorld.loadedEntityList) {
for (entity in world.loadedEntityList.filterNotNull()) {
if (entity !is EntityLivingBase || !bot && isBot(entity)) continue
if (!team && Teams.isInYourTeam(entity)) continue

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,15 @@ class Armor(
for (index in 3 downTo 0) {
val stack = mc.thePlayer.inventory.armorInventory[index] ?: continue

glPushMatrix()
glEnable(GL_BLEND)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
enableGUIStandardItemLighting()
renderItem.renderItemIntoGUI(stack, x, y)
renderItem.renderItemOverlays(mc.fontRendererObj, stack, x, y)
disableStandardItemLighting()
glDisable(GL_BLEND)
glPopMatrix()

when (modeValue) {
"Horizontal" -> x += 18
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import net.ccbluex.liquidbounce.utils.render.ColorUtils
import net.ccbluex.liquidbounce.utils.render.RenderUtils.drawRoundedRect
import net.ccbluex.liquidbounce.utils.render.RenderUtils.drawRoundedRectInt
import net.ccbluex.liquidbounce.config.*
import net.ccbluex.liquidbounce.ui.font.AWTFontRenderer.Companion.assumeNonVolatile
import net.minecraft.scoreboard.ScoreObjective
import net.minecraft.scoreboard.ScorePlayerTeam
import net.minecraft.util.EnumChatFormatting
Expand Down Expand Up @@ -62,135 +63,139 @@ class ScoreboardElement(
* Draw element
*/
override fun drawElement(): Border? {
if (AntiBlind.handleEvents() && AntiBlind.scoreboard)
return null
assumeNonVolatile {
if (AntiBlind.handleEvents() && AntiBlind.scoreboard)
return null

val (fontRenderer, fontHeight) = font to ((font as? GameFontRenderer)?.height ?: font.FONT_HEIGHT)
val textColor = textColor().rgb
val backColor = backgroundColor().rgb
val (fontRenderer, fontHeight) = font to ((font as? GameFontRenderer)?.height ?: font.FONT_HEIGHT)
val textColor = textColor().rgb
val backColor = backgroundColor().rgb

val rectColorMode = rectColorMode
val rectCustomColor = Color(rectColorRed, rectColorGreen, rectColorBlue, rectColorAlpha).rgb
val rectColorMode = rectColorMode
val rectCustomColor = Color(rectColorRed, rectColorGreen, rectColorBlue, rectColorAlpha).rgb

val worldScoreboard = mc.theWorld.scoreboard
var currObjective: ScoreObjective? = null
val playerTeam = worldScoreboard.getPlayersTeam(mc.thePlayer.name)
val worldScoreboard = mc.theWorld.scoreboard ?: return null
var currObjective: ScoreObjective? = null
val playerTeam = worldScoreboard.getPlayersTeam(mc.thePlayer.name)

if (playerTeam != null) {
val colorIndex = playerTeam.chatFormat.colorIndex
if (playerTeam != null) {
val colorIndex = playerTeam.chatFormat.colorIndex

if (colorIndex >= 0)
currObjective = worldScoreboard.getObjectiveInDisplaySlot(3 + colorIndex)
}

val objective = currObjective ?: worldScoreboard.getObjectiveInDisplaySlot(1) ?: return null

val scoreboard = objective.scoreboard
var scoreCollection = scoreboard.getSortedScores(objective)
val scores = scoreCollection.filter { it.playerName?.startsWith("#") == false }
if (colorIndex >= 0)
currObjective = worldScoreboard.getObjectiveInDisplaySlot(3 + colorIndex)
}

scoreCollection = if (scores.size > 15) {
scores.drop(scoreCollection.size - 15)
} else scores
val objective = currObjective ?: worldScoreboard.getObjectiveInDisplaySlot(1) ?: return null

var maxWidth = fontRenderer.getStringWidth(objective.displayName)
val scoreboard = objective.scoreboard ?: return null
var scoreCollection = scoreboard.getSortedScores(objective) ?: return null
val scores = scoreCollection.filter { it.playerName?.startsWith("#") == false }

for (score in scoreCollection) {
val scorePlayerTeam = scoreboard.getPlayersTeam(score.playerName)
val width = "${
ScorePlayerTeam.formatPlayerName(
scorePlayerTeam,
score.playerName
)
}: ${EnumChatFormatting.RED}${score.scorePoints}"
maxWidth = maxWidth.coerceAtLeast(fontRenderer.getStringWidth(width))
}
scoreCollection = if (scores.size > 15) {
scores.drop(scoreCollection.size - 15)
} else scores

val maxHeight = scoreCollection.size * fontHeight
val l1 = -maxWidth - 3 - if (rect) 3 else 0
var maxWidth = fontRenderer.getStringWidth(objective.displayName)

drawRoundedRectInt(l1 - 4, -4, 7, maxHeight + fontHeight, backColor, roundedRectRadius)
for (score in scoreCollection) {
val scorePlayerTeam = scoreboard.getPlayersTeam(score.playerName)
val width = "${
ScorePlayerTeam.formatPlayerName(
scorePlayerTeam,
score.playerName
)
}: ${EnumChatFormatting.RED}${score.scorePoints}"
maxWidth = maxWidth.coerceAtLeast(fontRenderer.getStringWidth(width))
}

scoreCollection.forEachIndexed { index, score ->
val team = scoreboard.getPlayersTeam(score.playerName)
val maxHeight = scoreCollection.size * fontHeight
val l1 = -maxWidth - 3 - if (rect) 3 else 0

var name = ScorePlayerTeam.formatPlayerName(team, score.playerName)
val scorePoints = "${EnumChatFormatting.RED}${score.scorePoints}"
drawRoundedRectInt(l1 - 4, -4, 7, maxHeight + fontHeight, backColor, roundedRectRadius)

val width = 5 - if (rect) 4 else 0
val height = maxHeight - index * fontHeight.toFloat()
scoreCollection.filterNotNull().forEachIndexed { index, score ->
val team = scoreboard.getPlayersTeam(score.playerName)

glColor4f(1f, 1f, 1f, 1f)
var name = ScorePlayerTeam.formatPlayerName(team, score.playerName)
val scorePoints = "${EnumChatFormatting.RED}${score.scorePoints}"

if (serverIp != "Normal") {
runCatching {
val nameWithoutFormatting = name?.replace(EnumChatFormatting.RESET.toString(), "")
?.replace(Regex("[\u00a7&][0-9a-fk-or]"), "")?.trim()
val trimmedServerIP = mc.currentServerData?.serverIP?.trim()?.lowercase()
val width = 5 - if (rect) 4 else 0
val height = maxHeight - index * fontHeight.toFloat()

val domainRegex =
Regex("\\b(?:[a-zA-Z0-9](?:[a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9])?\\.)+[a-zA-Z]{2,63}\\b")
val containsDomain = nameWithoutFormatting?.let { domainRegex.containsMatchIn(it) } == true
glColor4f(1f, 1f, 1f, 1f)

runCatching {
if (nameWithoutFormatting?.lowercase() == trimmedServerIP || containsDomain) {
val colorCode = name?.substring(0, 2) ?: "§9"
name = when (serverIp.lowercase()) {
"none" -> ""
"client" -> "$colorCode$CLIENT_NAME"
"website" -> "$colorCode$CLIENT_WEBSITE"
else -> return null
if (serverIp != "Normal") {
try {
val nameWithoutFormatting = name?.replace(EnumChatFormatting.RESET.toString(), "")
?.replace(Regex("[\u00a7&][0-9a-fk-or]"), "")?.trim()
val trimmedServerIP = mc.currentServerData?.serverIP?.trim()?.lowercase() ?: ""

val domainRegex =
Regex("\\b(?:[a-zA-Z0-9](?:[a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9])?\\.)+[a-zA-Z]{2,63}\\b")
val containsDomain = nameWithoutFormatting?.let { domainRegex.containsMatchIn(it) } == true

runCatching {
if (nameWithoutFormatting?.lowercase() == trimmedServerIP || containsDomain) {
val colorCode = name?.substring(0, 2) ?: "§9"
name = when (serverIp.lowercase()) {
"none" -> ""
"client" -> "$colorCode$CLIENT_NAME"
"website" -> "$colorCode$CLIENT_WEBSITE"
else -> return null
}
}
}.onFailure {
LOGGER.error("Error while changing Scoreboard Server IP: ${it.message}")
}
}.onFailure {
LOGGER.error("Error while changing Scoreboard Server IP: ${it.message}")
} catch (e: Exception) {
LOGGER.error("Error while drawing ScoreboardElement", e)
}
}.onFailure {
LOGGER.error("Failed to run: ${it.message}")
}
}

fontRenderer.drawString(name, l1.toFloat(), height, textColor, shadow)
fontRenderer.drawString(
scorePoints,
(width - fontRenderer.getStringWidth(scorePoints)).toFloat(),
height,
textColor,
shadow
)

if (index == scoreCollection.size - 1) {
val displayName = objective.displayName

glColor4f(1f, 1f, 1f, 1f)

fontRenderer.drawString(name, l1.toFloat(), height, textColor, shadow)
fontRenderer.drawString(
displayName,
(l1 + maxWidth / 2 - fontRenderer.getStringWidth(displayName) / 2).toFloat(),
height - fontHeight,
scorePoints,
(width - fontRenderer.getStringWidth(scorePoints)).toFloat(),
height,
textColor,
shadow
)
}

if (rect) {
val rectColor = when (rectColorMode) {
"Rainbow" -> ColorUtils.rainbow(400000000L * index).rgb
else -> rectCustomColor
if (index == scoreCollection.size - 1) {
val displayName = objective.displayName

glColor4f(1f, 1f, 1f, 1f)

fontRenderer.drawString(
displayName,
(l1 + maxWidth / 2 - fontRenderer.getStringWidth(displayName) / 2).toFloat(),
height - fontHeight,
textColor,
shadow
)
}

drawRoundedRect(
2F,
if (index == scoreCollection.size - 1) -2F else height,
5F,
if (index == 0) fontHeight.toFloat() else height + fontHeight * 2F,
rectColor,
roundedRectRadius
)
if (rect) {
val rectColor = when (rectColorMode) {
"Rainbow" -> ColorUtils.rainbow(400000000L * index).rgb
else -> rectCustomColor
}

drawRoundedRect(
2F,
if (index == scoreCollection.size - 1) -2F else height,
5F,
if (index == 0) fontHeight.toFloat() else height + fontHeight * 2F,
rectColor,
roundedRectRadius
)
}
}

return Border(l1 - 4F, -4F, 7F, maxHeight + fontHeight.toFloat())
}

return Border(l1 - 4F, -4F, 7F, maxHeight + fontHeight.toFloat())
return null
}

private fun backgroundColor() = Color(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,6 @@ object RenderUtils : MinecraftInstance() {

fun drawImage(image: ResourceLocation?, x: Int, y: Int, width: Int, height: Int) {
glPushMatrix()
glPushAttrib(GL_ALL_ATTRIB_BITS)
glDisable(GL_DEPTH_TEST)
glEnable(GL_BLEND)
glDepthMask(false)
Expand All @@ -856,7 +855,6 @@ object RenderUtils : MinecraftInstance() {
glDepthMask(true)
glDisable(GL_BLEND)
glEnable(GL_DEPTH_TEST)
glPopAttrib()
glPopMatrix()
}

Expand Down
Loading