Skip to content

Commit

Permalink
Update 2.0
Browse files Browse the repository at this point in the history
2022.7.25 update 2.0!
  • Loading branch information
RMCQAZ committed Jul 25, 2022
1 parent 3887b4d commit defe71e
Show file tree
Hide file tree
Showing 37 changed files with 1,170 additions and 140 deletions.
7 changes: 6 additions & 1 deletion src/minecraft/kevin/command/commands/SayCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ class SayCommand : ICommand {
ChatUtils.messageWithStart("§cUsage: .say <Message>")
return
}
Minecraft.getMinecraft().thePlayer.sendQueue.addToSendQueue(C01PacketChatMessage(args[0]))
var tmp = ""
for (t in args) {
tmp += " $t"
}
tmp = tmp.removePrefix(" ")
Minecraft.getMinecraft().thePlayer.sendQueue.addToSendQueue(C01PacketChatMessage(tmp))
}
}
33 changes: 31 additions & 2 deletions src/minecraft/kevin/file/ConfigManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import com.google.gson.JsonNull
import com.google.gson.JsonObject
import com.google.gson.JsonParser
import kevin.main.KevinClient
import kevin.module.Module
import kevin.module.Value
import kevin.utils.ChatUtils
import org.apache.commons.io.FileUtils
import java.io.*
import java.util.function.Consumer
Expand Down Expand Up @@ -33,6 +35,8 @@ object ConfigManager {
val jsonMod = JsonObject()
jsonMod.addProperty("State", it.state)
jsonMod.addProperty("KeyBind", it.keyBind)
jsonMod.addProperty("Hide", !it.array)
jsonMod.addProperty("AutoDisable", if (it.autoDisable.first) it.autoDisable.second else "Disable")
it.values.forEach(Consumer { value: Value<*> -> jsonMod.add(value.name, value.toJson())})
modulesConfig.add(it.name, jsonMod)
}
Expand All @@ -52,6 +56,8 @@ object ConfigManager {
val modulesConfig = config[0]
val hudConfig = File(configDir,"$name-HUD.json")
var returnValue = 0
val warns = mutableMapOf<String,String>()
val setModules = arrayListOf<Module>()
//LoadModules
if (modulesConfig.exists()&&modulesConfig.isFile){
val jsonElement = JsonParser().parse(BufferedReader(FileReader(modulesConfig)))
Expand All @@ -62,17 +68,40 @@ object ConfigManager {
val (key, value) = entryIterator.next()
val module = KevinClient.moduleManager.getModule(key)
if (module != null) {
setModules.add(module)
val jsonModule = value as JsonObject
module.state = jsonModule["State"].asBoolean
module.keyBind = jsonModule["KeyBind"].asInt
if (jsonModule["Hide"] != null)
module.array = !jsonModule["Hide"].asBoolean
else
warns["$key-HideValue"] = "The hide attribute of the module is not saved in the config file(OldConfig?)."
if (jsonModule["AutoDisable"] != null)
module.autoDisable = Pair(
jsonModule["AutoDisable"].asString != "Disable",
if (jsonModule["AutoDisable"].asString == "Disable") "" else jsonModule["AutoDisable"].asString
)
else
warns["$key-AutoDisableValue"] = "The AutoDisable attribute of the module is not saved in the config file(OldConfig?)."
for (moduleValue in module.values) {
val element = jsonModule[moduleValue.name]
if (element != null) moduleValue.fromJson(element)
if (element != null) moduleValue.fromJson(element) else warns["$key-$moduleValue"] = "The config file does not have a value for this option."
}
}
} else warns[key] = "Module does not exist."
}
}
} else returnValue = 1
KevinClient.moduleManager.getModules().forEach {
if (it !in setModules) {
warns[it.name] = "The parameters for this module are not saved in the config file(OldConfig?)."
}
}
if (warns.isNotEmpty()) {
ChatUtils.messageWithStart("There were some warnings when loading the configuration:")
warns.forEach { (t, u) ->
ChatUtils.message("§7[§9$t§7]: §e$u")
}
}
//LoadHUD
if (hudConfig.exists()&&modulesConfig.isFile){
KevinClient.hud.clearElements()
Expand Down
39 changes: 36 additions & 3 deletions src/minecraft/kevin/hud/HUD.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package kevin.hud
import kevin.hud.designer.GuiHudDesigner
import kevin.hud.element.Element
import kevin.hud.element.elements.*
import kevin.main.KevinClient
import kevin.module.modules.misc.NoScoreboard
import kevin.utils.*
import net.minecraft.client.gui.ScaledResolution
import org.lwjgl.opengl.GL11
Expand All @@ -25,7 +27,7 @@ open class HUD : MinecraftInstance() {
Information::class.java,
//TabGUI::class.java,
Text::class.java,
//ScoreboardElement::class.java,
ScoreboardElement::class.java,
TargetHUD::class.java,
Radar::class.java,
InvItem::class.java
Expand All @@ -38,8 +40,8 @@ open class HUD : MinecraftInstance() {
fun createDefault() = HUD()
.addElement(Text.defaultClient())
.addElement(Text.defaultClientVersion())
/**.addElement(TabGUI())
.addElement(ScoreboardElement())**/
/**.addElement(TabGUI())**/
.addElement(ScoreboardElement())
.addElement(Notifications())
.addElement(Armor())
.addElement(Arraylist())
Expand All @@ -48,6 +50,37 @@ open class HUD : MinecraftInstance() {

}

fun disableMinecraftScoreboard() =
(elements.filterIsInstance<ScoreboardElement>().isNotEmpty() && (KevinClient.moduleManager.getModule("HUD")!!.state || (KevinClient.moduleManager.getModule("HUD")!! as kevin.module.modules.render.HUD).keepScoreboard.get())) || NoScoreboard.state

fun renderScoreboardOnly() {
elements.filterIsInstance<ScoreboardElement>()
.forEach {
GL11.glPushMatrix()

if (!it.info.disableScale)
GL11.glScalef(it.scale, it.scale, it.scale)

GL11.glTranslated(it.renderX, it.renderY, 0.0)

try {
it.border = it.drawElement()
} catch (ex: Exception) {
println("Something went wrong while drawing ${it.name} element in HUD. $ex")
}

GL11.glEnable(GL11.GL_BLEND)
GL11.glColor4f(1F,1F,1F,1F)
GL11.glPopMatrix()
}
}

fun updateScoreboardOnly() {
elements.filterIsInstance<ScoreboardElement>()
.forEach {
it.updateElement()
}
}
/**
* Render all elements
*/
Expand Down
176 changes: 176 additions & 0 deletions src/minecraft/kevin/hud/element/elements/ScoreboardElement.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
package kevin.hud.element.elements

import com.google.common.collect.Iterables
import com.google.common.collect.Lists
import kevin.hud.element.Border
import kevin.hud.element.Element
import kevin.hud.element.ElementInfo
import kevin.hud.element.Side
import kevin.main.KevinClient
import kevin.module.BooleanValue
import kevin.module.IntegerValue
import kevin.module.ListValue
import kevin.module.modules.misc.NoScoreboard
import kevin.utils.ColorUtils
import kevin.utils.FontManager
import kevin.utils.RenderUtils
import net.minecraft.scoreboard.*
import net.minecraft.util.EnumChatFormatting
import org.lwjgl.opengl.GL11
import java.awt.Color

/**
* CustomHUD scoreboard
*
* Allows to move and customize minecraft scoreboard
*/
@ElementInfo(name = "Scoreboard")
class ScoreboardElement(x: Double = 5.0, y: Double = 0.0, scale: Float = 1F,
side: Side = Side(Side.Horizontal.RIGHT, Side.Vertical.MIDDLE)) : Element(x, y, scale, side) {

private val textRedValue = IntegerValue("Text-R", 255, 0, 255)
private val textGreenValue = IntegerValue("Text-G", 255, 0, 255)
private val textBlueValue = IntegerValue("Text-B", 255, 0, 255)

private val backgroundColorRedValue = IntegerValue("Background-R", 0, 0, 255)
private val backgroundColorGreenValue = IntegerValue("Background-G", 0, 0, 255)
private val backgroundColorBlueValue = IntegerValue("Background-B", 0, 0, 255)
private val backgroundColorAlphaValue = IntegerValue("Background-Alpha", 95, 0, 255)

private val rectValue = BooleanValue("Rect", false)
private val rectColorModeValue = ListValue("Rect-Color", arrayOf("Custom", "Rainbow"), "Custom")
private val rectColorRedValue = IntegerValue("Rect-R", 0, 0, 255)
private val rectColorGreenValue = IntegerValue("Rect-G", 111, 0, 255)
private val rectColorBlueValue = IntegerValue("Rect-B", 255, 0, 255)
private val rectColorBlueAlpha = IntegerValue("Rect-Alpha", 255, 0, 255)

private val clientFont = BooleanValue("ClientFont", false)

private val shadowValue = BooleanValue("Shadow", false)

private val clientName = BooleanValue("ClientName", false)

/**
* Draw element
*/
override fun drawElement(): Border? {
if (NoScoreboard.state)
return null

val textColor = textColor().rgb
val backColor = backgroundColor().rgb

val rectColorMode = rectColorModeValue.get()
val rectCustomColor = Color(rectColorRedValue.get(), rectColorGreenValue.get(), rectColorBlueValue.get(),
rectColorBlueAlpha.get()).rgb

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

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 = Lists.newArrayList(Iterables.filter(scoreCollection) { input ->
input?.playerName != null && !input.playerName.startsWith("#")
})

fun clientname(): Score {
val s = Score(Scoreboard(), ScoreObjective(Scoreboard(),"", IScoreObjectiveCriteria.health),"§3§l§nKevin§6§l§nClient")
s.scorePoints = -114514
return s
}

if(clientName.get()) scores.add(0,clientname())

scoreCollection = if (scores.size > 15)
Lists.newArrayList(Iterables.skip(scores, scoreCollection.size - 15))
else
scores

var maxWidth = getStringWidth(objective.displayName)

for (score in scoreCollection) {
val scorePlayerTeam = scoreboard.getPlayersTeam(score.playerName)
val width = "${scoreboardFormatPlayerName(scorePlayerTeam, score.playerName)}: ${EnumChatFormatting.RED}${score.scorePoints}"
maxWidth = maxWidth.coerceAtLeast(getStringWidth(width))
}

val maxHeight = scoreCollection.size * FONT_HEIGHT
val l1 = -maxWidth - 3 - if (rectValue.get()) 3 else 0



RenderUtils.drawRect(l1 - 2, -2, 5, (maxHeight + FONT_HEIGHT), backColor)

scoreCollection.forEachIndexed { index, score ->
val team = scoreboard.getPlayersTeam(score.playerName)

val name = scoreboardFormatPlayerName(team, score.playerName)
val scorePoints = "${EnumChatFormatting.RED}${score.scorePoints}"

val width = 5 - if (rectValue.get()) 4 else 0
val height = maxHeight - index * FONT_HEIGHT.toFloat()

GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f)

//if(clientName.get()&&name.toLowerCase().contains(".net")) name = name + " §3§l§nKevin§6§l§nClient"

if(name != "§3§l§nKevin§6§l§nClient"){
drawString(name, l1.toFloat(), height, textColor, shadowValue.get())
}else{
FontManager.RainbowFontShader.begin(true,1.0F / 1000,1.0F / 1000,System.currentTimeMillis() % 10000 / 10000F).use {
drawString("§lKevin§lClient", l1.toFloat(), height, 0, shadowValue.get())
}
}

drawString(scorePoints, (width - getStringWidth(scorePoints)).toFloat(), height, textColor, shadowValue.get())

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

GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f)

drawString(displayName, (l1 + maxWidth / 2 - getStringWidth(displayName) / 2).toFloat(), (height -
FONT_HEIGHT), textColor, shadowValue.get())
}

if (rectValue.get()) {
val rectColor = when {
rectColorMode.equals("Rainbow", ignoreCase = true) -> ColorUtils.rainbow(400000000L * index).rgb
else -> rectCustomColor
}

RenderUtils.drawRect(2F, if (index == scoreCollection.size - 1) -2F else height, 5F, if (index == 0) FONT_HEIGHT.toFloat() else height + FONT_HEIGHT * 2F, rectColor)
}
}

return Border(-maxWidth.toFloat() - 5 - if (rectValue.get()) 3 else 0, -2F, 5F, maxHeight + FONT_HEIGHT.toFloat())
}

private fun backgroundColor() = Color(backgroundColorRedValue.get(), backgroundColorGreenValue.get(),
backgroundColorBlueValue.get(), backgroundColorAlphaValue.get())

private fun textColor() = Color(textRedValue.get(), textGreenValue.get(),
textBlueValue.get())

private fun scoreboardFormatPlayerName(scorePlayerTeam: Team?, playerName: String) =
ScorePlayerTeam.formatPlayerName(scorePlayerTeam, playerName)

private fun drawString(string: String?, x: Float, y: Float, color: Int, shadow: Boolean) =
if (clientFont.get()) KevinClient.fontManager.font35!!.drawString(string, x, y, color, shadow) else KevinClient.fontManager.minecraftFont.drawString(string, x, y, color, shadow)

private val FONT_HEIGHT
get() = if (clientFont.get()) KevinClient.fontManager.font35!!.fontHeight else KevinClient.fontManager.minecraftFont.FONT_HEIGHT

private fun getStringWidth(string: String) =
if (clientFont.get()) KevinClient.fontManager.font35!!.getStringWidth(string) else KevinClient.fontManager.minecraftFont.getStringWidth(string)
}
Loading

0 comments on commit defe71e

Please sign in to comment.