Skip to content

Commit

Permalink
Added StorageESP, added Render2DContext and Render3DContext
Browse files Browse the repository at this point in the history
  • Loading branch information
ya-ilya committed Sep 11, 2023
1 parent 30994e6 commit a972108
Show file tree
Hide file tree
Showing 17 changed files with 486 additions and 127 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.progreso.client.mixins;

import net.minecraft.client.render.Camera;
import net.minecraft.client.render.GameRenderer;
import net.minecraft.client.render.LightmapTextureManager;
import net.minecraft.client.render.WorldRenderer;
import net.minecraft.client.util.math.MatrixStack;
import org.joml.Matrix4f;
import org.progreso.client.Client;
import org.progreso.client.events.render.Render3DEvent;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(WorldRenderer.class)
public abstract class MixinWorldRenderer {
@Inject(
method = "render",
at = @At("RETURN")
)
public void renderHook(
MatrixStack matrices,
float tickDelta,
long limitTime,
boolean renderBlockOutline,
Camera camera,
GameRenderer gameRenderer,
LightmapTextureManager lightmapTextureManager,
Matrix4f projectionMatrix,
CallbackInfo callbackInfo
) {
Client.EVENT_BUS.post(new Render3DEvent(matrices));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import org.progreso.client.gui.createDefaultTextRenderer
import org.progreso.client.gui.customTextRenderer
import org.progreso.client.managers.minecraft.ProgresoResourceManager
import org.progreso.client.managers.minecraft.exceptions.ProgresoResourceManagerException
import org.progreso.client.util.render.TextRendererUtil
import org.progreso.client.util.render.createTextRendererFromProgresoResource

@AbstractCommand.Register("font")
object FontCommand : AbstractCommand() {
Expand Down Expand Up @@ -65,7 +65,7 @@ object FontCommand : AbstractCommand() {

private fun loadFont(fontName: String, size: Float = 11f) {
try {
customTextRenderer = TextRendererUtil.createTextRendererFromProgresoResource(fontName, size)!!
customTextRenderer = createTextRendererFromProgresoResource(fontName, size)!!
config.customFont = Client.ProgresoGlobalConfigAccessor.GlobalConfig.CustomFont(fontName, size)

infoLocalized(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.progreso.client.events.render

import net.minecraft.client.util.math.MatrixStack
import org.progreso.api.event.Event

data class Render3DEvent(val matrices: MatrixStack) : Event()
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,24 @@

package org.progreso.client.gui

import com.mojang.blaze3d.systems.RenderSystem
import net.minecraft.client.font.TextRenderer
import net.minecraft.client.gui.DrawContext
import net.minecraft.client.render.GameRenderer
import net.minecraft.client.render.Tessellator
import net.minecraft.client.render.VertexFormat
import net.minecraft.client.render.VertexFormats
import org.progreso.client.Client.Companion.config
import org.progreso.client.Client.Companion.mc
import org.progreso.client.gui.clickgui.element.Element
import org.progreso.client.modules.client.ClickGUI
import org.progreso.client.util.render.TextRendererUtil
import org.progreso.client.util.render.createTextRenderer
import org.progreso.client.util.render.createTextRendererFromProgresoResource
import java.awt.Color
import kotlin.math.cos
import kotlin.math.sin

fun createDefaultTextRenderer(): TextRenderer {
return TextRendererUtil.createTextRenderer("vitala", 11f)!!
return createTextRenderer("vitala", 11f)!!
}

var customTextRenderer = run {
if (config.customFont != null) {
try {
return@run TextRendererUtil.createTextRendererFromProgresoResource(
return@run createTextRendererFromProgresoResource(
config.customFont!!.name!!,
config.customFont!!.size!!
)!!
Expand All @@ -49,12 +43,12 @@ val Color.glColors: List<Float>
(rgb shr 24 and 0xFF) / 255.0f,
)

operator fun DrawContext.invoke(block: ContextWrapper.() -> Unit) {
ContextWrapper(this).apply(block)
operator fun DrawContext.invoke(block: DrawContextWrapper.() -> Unit) {
DrawContextWrapper(this).apply(block)
}

fun <S> DrawContext.invokeSuper(superRef: S, block: ContextWrapper.(S) -> Unit) {
ContextWrapper(this).also { block(it, superRef) }
fun <S> DrawContext.invokeSuper(superRef: S, block: DrawContextWrapper.(S) -> Unit) {
DrawContextWrapper(this).also { block(it, superRef) }
}

val DrawContext.fontHeight get() = textRenderer.fontHeight
Expand Down Expand Up @@ -108,44 +102,11 @@ fun DrawContext.drawHorizontalLine(startX: Int, endX: Int, y: Int, color: Color)
fill(startX, y, endX, y + 1, color.rgb)
}

fun DrawContext.drawCircle(
centerX: Int,
centerY: Int,
angleFrom: Double,
angleTo: Double,
segments: Int,
radius: Double,
color: Color
) {
val buffer = Tessellator.getInstance().buffer
val matrix = matrices.peek().positionMatrix

val angleStep = Math.toRadians(angleTo - angleFrom) / segments

buffer.begin(VertexFormat.DrawMode.TRIANGLE_FAN, VertexFormats.POSITION_COLOR)
buffer.vertex(matrix, centerX.toFloat(), centerY.toFloat(), 0f).color(color.rgb).next()

for (i in segments downTo 0) {
val theta = Math.toRadians(angleFrom) + i * angleStep
buffer.vertex(
matrix,
(centerX - cos(theta) * radius).toFloat(),
(centerY - sin(theta) * radius).toFloat(), 0f
).color(color.rgb).next()
}

RenderSystem.enableBlend()
RenderSystem.defaultBlendFunc()
RenderSystem.setShader(GameRenderer::getPositionColorProgram)

Tessellator.getInstance().draw()
}

fun DrawContext.getTextWidth(string: String): Int {
return textRenderer.getWidth(string)
}

class ContextWrapper(private val context: DrawContext) {
class DrawContextWrapper(private val context: DrawContext) {
val fontHeight get() = context.fontHeight

fun drawText(textRenderer: TextRenderer, text: String, x: Int, y: Int, color: Color, shadow: Boolean = false) {
Expand Down Expand Up @@ -205,18 +166,6 @@ class ContextWrapper(private val context: DrawContext) {
)
}

fun drawCircle(
centerX: Int,
centerY: Int,
angleFrom: Double,
angleTo: Double,
segments: Int,
radius: Double,
color: Color
) {
context.drawCircle(centerX, centerY, angleFrom, angleTo, segments, radius, color)
}

fun getTextWidth(string: String): Int {
return context.getTextWidth(string)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import net.minecraft.client.gui.DrawContext
import org.progreso.api.setting.settings.BooleanSetting
import org.progreso.client.gui.clickgui.element.ParentElement
import org.progreso.client.gui.invoke
import org.progreso.client.util.render.drawCircle
import org.progreso.client.util.render.render2D
import org.progreso.client.util.render.withColor
import java.awt.Color

class BooleanElement(
Expand Down Expand Up @@ -35,13 +38,17 @@ class BooleanElement(
BUTTON_HEIGHT,
BUTTON_BACK_RECT_COLOR
)
drawCircle(
buttonStartX + if (setting.value) BUTTON_WIDTH else 0,
buttonStartY + 2,
0.0, 360.0,
40, 3.0,
mainColor
)

render2D(context) {
withColor(mainColor) {
drawCircle(
buttonStartX + if (setting.value) BUTTON_WIDTH else 0,
buttonStartY + 2,
0.0, 360.0,
40, 3.0
)
}
}
}

override fun mouseClicked(mouseX: Int, mouseY: Int, button: Int) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.progreso.client.gui.clickgui.element.elements
import com.mojang.blaze3d.platform.GlStateManager
import com.mojang.blaze3d.systems.RenderSystem
import net.minecraft.client.gui.DrawContext
import net.minecraft.client.render.GameRenderer
import net.minecraft.client.render.Tessellator
import net.minecraft.client.render.VertexFormat
import net.minecraft.client.render.VertexFormats
Expand All @@ -13,6 +14,9 @@ import org.progreso.client.gui.clickgui.element.AbstractChildListElement
import org.progreso.client.gui.clickgui.element.ParentElement
import org.progreso.client.gui.glColors
import org.progreso.client.gui.invoke
import org.progreso.client.util.render.drawCircle
import org.progreso.client.util.render.render2D
import org.progreso.client.util.render.withColor
import java.awt.Color
import kotlin.math.max
import kotlin.math.min
Expand Down Expand Up @@ -108,9 +112,13 @@ class ColorElement(
val (red, green, blue, alpha) = color.glColors
val matrix = context.matrices.peek().positionMatrix

context.matrices.push()
RenderSystem.enableBlend()
RenderSystem.blendFunc(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA)
RenderSystem.disableDepthTest()

context.matrices.push()

RenderSystem.setShader(GameRenderer::getPositionColorProgram)

val buffer = Tessellator.getInstance().buffer
buffer.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR)
Expand Down Expand Up @@ -160,6 +168,10 @@ class ColorElement(

Tessellator.getInstance().draw()
context.matrices.pop()

RenderSystem.setShaderColor(1f, 1f, 1f, 1f)
RenderSystem.disableBlend()
RenderSystem.enableDepthTest()
}
})

Expand All @@ -173,13 +185,17 @@ class ColorElement(
offsets.textOffset,
Color.WHITE
)
drawCircle(
x + width - 9,
y + height.div(2),
0.0, 360.0,
40, 2.6,
setting.value
)

render2D(context) {
withColor(setting.value) {
drawCircle(
x + width - 9,
y + height.div(2),
0.0, 360.0,
40, 2.6
)
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import net.minecraft.client.gui.DrawContext
import org.progreso.api.setting.settings.NumberSetting
import org.progreso.client.gui.clickgui.element.ParentElement
import org.progreso.client.gui.invoke
import org.progreso.client.util.render.drawCircle
import org.progreso.client.util.render.render2D
import org.progreso.client.util.render.withColor
import java.awt.Color
import kotlin.math.floor

Expand Down Expand Up @@ -84,13 +87,17 @@ class SliderElement(
SLIDER_HEIGHT,
mainColor
)
drawCircle(
sliderStartX + sliderWidth,
sliderStartY + SLIDER_HEIGHT / 2,
0.0, 360.0,
40, 2.6,
mainColor
)

render2D(context) {
withColor(mainColor) {
drawCircle(
sliderStartX + sliderWidth,
sliderStartY + SLIDER_HEIGHT / 2,
0.0, 360.0,
40, 2.6
)
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import org.progreso.client.gui.drawText
import org.progreso.client.gui.invoke
import org.progreso.client.gui.minecraft.common.SimpleElementListEntry
import org.progreso.client.gui.minecraft.common.TitledScreen
import org.progreso.client.util.session.SessionUtil
import org.progreso.client.util.misc.SessionUtil
import java.awt.Color

class ProgresoAltsScreen(private val alts: Set<AltAccount>) : TitledScreen(i18n = "gui.alts.title") {
Expand Down
Loading

0 comments on commit a972108

Please sign in to comment.