Skip to content

Commit

Permalink
2D正方形目标ESP
Browse files Browse the repository at this point in the history
  • Loading branch information
XeContrast committed Nov 2, 2024
1 parent 5848f24 commit ce11769
Show file tree
Hide file tree
Showing 5 changed files with 182 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@ import net.ccbluex.liquidbounce.features.value.BoolValue
import net.ccbluex.liquidbounce.features.value.FloatValue
import net.ccbluex.liquidbounce.features.value.IntegerValue
import net.ccbluex.liquidbounce.features.value.ListValue
import net.ccbluex.liquidbounce.ui.client.gui.clickgui.style.styles.Slight.RenderUtil
import net.ccbluex.liquidbounce.ui.font.GameFontRenderer.Companion.getColorIndex
import net.ccbluex.liquidbounce.utils.EntityUtils.getSmoothDistanceToEntity
import net.ccbluex.liquidbounce.utils.animations.Direction
import net.ccbluex.liquidbounce.utils.animations.impl.DecelerateAnimation
import net.ccbluex.liquidbounce.utils.animations.impl.SmoothStepAnimation
import net.ccbluex.liquidbounce.utils.render.BlendUtils
import net.ccbluex.liquidbounce.utils.render.ColorUtils
import net.ccbluex.liquidbounce.utils.render.ColorUtils.LiquidSlowly
Expand All @@ -39,21 +43,23 @@ import net.minecraft.init.Blocks
import net.minecraft.network.play.server.S2CPacketSpawnGlobalEntity
import net.minecraft.potion.Potion
import net.minecraft.util.EnumParticleTypes
import net.minecraft.util.MathHelper
import net.minecraft.util.ResourceLocation
import java.awt.Color
import java.io.File
import java.io.IOException
import java.util.*
import javax.sound.sampled.AudioInputStream
import javax.sound.sampled.AudioSystem
import kotlin.math.abs


@ModuleInfo("CombatVisuals", category = ModuleCategory.VISUAL)
object CombatVisuals : Module() {

// Mark
private val colorModeValue = ListValue("Color", arrayOf("Custom", "Rainbow", "Sky", "LiquidSlowly", "Fade", "Mixer", "Health"), "Custom")
private val markValue = ListValue("MarkMode", arrayOf("None", "Box", "RoundBox", "Head", "Mark", "Sims","jello", "Zavz"), "Zavz")
val markValue = ListValue("MarkMode", arrayOf("None", "Box", "RoundBox", "Head", "Mark", "Sims","Jello", "Zavz","Rectangle","Round"), "Zavz")
private val saturationValue = FloatValue("Saturation", 1f, 0f, 1f)
private val brightnessValue = FloatValue("Brightness", 1f, 0f, 1f)
private val mixerSecondsValue = IntegerValue("Seconds", 2, 1, 10)
Expand Down Expand Up @@ -98,6 +104,7 @@ object CombatVisuals : Module() {
const val DOUBLE_PI = Math.PI * 2
var start = 0.0
private var killedAmount = 0
private val auraESPAnim = SmoothStepAnimation(650, 1.0)

@EventTarget
fun onWorld(event: WorldEvent?) {
Expand Down Expand Up @@ -163,6 +170,29 @@ object CombatVisuals : Module() {
event
)

"rectangle","round" -> {
// No null pointer anymore
auraESPAnim.setDirection(
if (!(combat.target!!.isDead || mc.thePlayer.getDistanceToEntity(
combat.target
) > 10)
) Direction.FORWARDS else Direction.BACKWARDS
)
if (!auraESPAnim.finished(Direction.BACKWARDS)) {
val dst = mc.thePlayer.getSmoothDistanceToEntity(combat.target)
val vector2f = RenderUtil.targetESPSPos(combat.target, event.partialTicks) ?: return
RenderUtil.drawTargetESP2D(
vector2f.x,
vector2f.y,
getColor(combat.target),
getColor(combat.target),
1.0f - MathHelper.clamp_float(abs((dst - 6.0f)) / 60.0f, 0.0f, 0.75f),
1,
auraESPAnim.output.toFloat()
)
}
}

"jello" -> {
val auraESPAnim = DecelerateAnimation(300, 1.0)
drawCircle(combat.target!!,event.partialTicks, 0.75,getColor(combat.target).rgb, auraESPAnim.output?.toFloat()!!)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,33 @@
package net.ccbluex.liquidbounce.ui.client.gui.clickgui.style.styles.Slight;

import net.ccbluex.liquidbounce.FDPClient;
import net.ccbluex.liquidbounce.features.module.modules.visual.CombatVisuals;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.*;
import net.minecraft.client.renderer.culling.Frustum;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.client.shader.Framebuffer;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.MathHelper;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.EXTFramebufferObject;
import org.jetbrains.annotations.NotNull;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.GL11;
import org.lwjgl.util.glu.GLU;

import javax.vecmath.Vector2f;
import javax.vecmath.Vector3d;
import javax.vecmath.Vector4d;
import java.awt.*;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import java.util.Objects;

public enum RenderUtil {

;

static Minecraft mc = Minecraft.getMinecraft();
public static int reAlpha(int color, float alpha) {
Color c = new Color(color);
float r = 0.003921569F * (float) c.getRed();
Expand Down Expand Up @@ -186,7 +197,7 @@ public static void arc(float x, float y, float start, float end, float radius, C
public static void arcEllipse(float x, float y, float start, float end, float w, float h, int color) {
GlStateManager.color(0.0F, 0.0F, 0.0F);
GL11.glColor4f(0.0F, 0.0F, 0.0F, 0.0F);
float temp = 0.0F;
float temp;

if (start > end) {
temp = end;
Expand Down Expand Up @@ -238,7 +249,7 @@ public static void arcEllipse(float x, float y, float start, float end, float w,
public static void arcEllipse(float x, float y, float start, float end, float w, float h, Color color) {
GlStateManager.color(0.0F, 0.0F, 0.0F);
GL11.glColor4f(0.0F, 0.0F, 0.0F, 0.0F);
float temp = 0.0F;
float temp;

if (start > end) {
temp = end;
Expand Down Expand Up @@ -318,4 +329,116 @@ public static void drawRect(double d, double e, double g, double h, int color) {
GlStateManager.disableBlend();
}

public static double interpolate(double current, double old, double scale) {
return old + (current - old) * scale;
}

private static Vector3d project2D(int scaleFactor, double x, double y, double z) {
IntBuffer viewport = GLAllocation.createDirectIntBuffer(16);
FloatBuffer modelView = GLAllocation.createDirectFloatBuffer(16);
FloatBuffer projection = GLAllocation.createDirectFloatBuffer(16);
FloatBuffer vector = GLAllocation.createDirectFloatBuffer(4);
GL11.glGetFloat(2982, modelView);
GL11.glGetFloat(2983, projection);
GL11.glGetInteger(2978, viewport);
return GLU.gluProject((float)x, (float)y, (float)z, modelView, projection, viewport, vector) ? new Vector3d(vector.get(0) / (float)scaleFactor, ((float) Display.getHeight() - vector.get(1)) / (float)scaleFactor, vector.get(2)) : null;
}

public static Vector2f targetESPSPos(EntityLivingBase entity, float partialTicks) {
EntityRenderer entityRenderer = mc.entityRenderer;
int scaleFactor = new ScaledResolution(mc).getScaleFactor();
Vector3d[] vectors = getVectors(entity, partialTicks);
entityRenderer.setupCameraTransform(partialTicks, 0);
Vector4d position = null;
for (Vector3d vector3d : vectors) {
Vector3d vector = vector3d;
vector = project2D(scaleFactor, vector.x - mc.getRenderManager().viewerPosX, vector.y - mc.getRenderManager().viewerPosY, vector.z - mc.getRenderManager().viewerPosZ);
if (vector == null || !(vector.z >= 0.0) || !(vector.z < 1.0)) continue;
if (position == null) {
position = new Vector4d(vector.x, vector.y, vector.z, 0.0);
}
position.x = Math.min(vector.x, position.x);
position.y = Math.min(vector.y, position.y);
position.z = Math.max(vector.x, position.z);
position.w = Math.max(vector.y, position.w);
}
entityRenderer.setupOverlayRendering();
if (position != null) {
return new Vector2f((float)position.x, (float)position.y);
}
return null;
}

@NotNull
private static Vector3d [] getVectors(EntityLivingBase entity, float partialTicks) {
double x = interpolate(entity.prevPosX, entity.posX, partialTicks);
double y = interpolate(entity.prevPosY, entity.posY, partialTicks);
double z = interpolate(entity.prevPosZ, entity.posZ, partialTicks);
double height = entity.height / (entity.isChild() ? 1.75f : 1.0f) / 2.0f;
AxisAlignedBB aabb = new AxisAlignedBB(x - 0.0, y, z - 0.0, x + 0.0, y + height, z + 0.0);
return new Vector3d[]{new Vector3d(aabb.minX, aabb.minY, aabb.minZ), new Vector3d(aabb.minX, aabb.maxY, aabb.minZ), new Vector3d(aabb.maxX, aabb.minY, aabb.minZ), new Vector3d(aabb.maxX, aabb.maxY, aabb.minZ), new Vector3d(aabb.minX, aabb.minY, aabb.maxZ), new Vector3d(aabb.minX, aabb.maxY, aabb.maxZ), new Vector3d(aabb.maxX, aabb.minY, aabb.maxZ), new Vector3d(aabb.maxX, aabb.maxY, aabb.maxZ)};
}

private static ResourceLocation getESPImage() {
switch (Objects.requireNonNull(FDPClient.moduleManager.getModule(CombatVisuals.class)).getMarkValue().get()) {
case "Round":
return new ResourceLocation("fdpclient/round.png");
case "Rectangle":
return new ResourceLocation("fdpclient/rectangle.png");
}
return null;
}

public static void customRotatedObject2D(float oXpos, float oYpos, float oWidth, float oHeight, float rotate) {
GL11.glTranslated(oXpos + oWidth / 2.0f, oYpos + oHeight / 2.0f, 0.0);
GL11.glRotated(rotate, 0.0, 0.0, 1.0);
GL11.glTranslated(-oXpos - oWidth / 2.0f, -oYpos - oHeight / 2.0f, 0.0);
}

public static void drawTargetESP2D(float x, float y, Color color, Color color2, float scale, int index, float alpha) {
ResourceLocation resource = getESPImage();
if (resource == null) {
return;
}

long millis = System.currentTimeMillis() + (long) index * 400L;
double angle = MathHelper.clamp_double((Math.sin((double) millis / 150.0) + 1.0) / 2.0 * 30.0, 0.0, 30.0);
double scaled = MathHelper.clamp_double((Math.sin((double) millis / 500.0) + 1.0) / 2.0, 0.8, 1.0);
double rotate = MathHelper.clamp_double((Math.sin((double) millis / 1000.0) + 1.0) / 2.0 * 360.0, 0.0, 360.0);
rotate = (double) 45 - (angle - 15.0) + rotate;
float size = 128.0f * scale * (float) scaled;
float x2 = (x -= size / 2.0f) + size;
float y2 = (y -= size / 2.0f) + size;
GlStateManager.pushMatrix();
RenderUtil.customRotatedObject2D(x, y, size, size, (float) rotate);
GL11.glDisable(3008);
GlStateManager.depthMask(false);
GlStateManager.enableBlend();
GlStateManager.shadeModel(7425);
GlStateManager.tryBlendFuncSeparate(770, 1, 1, 0);
drawESPImage(resource, x, y, x2, y2, color, color2, alpha);
GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
GlStateManager.resetColor();
GlStateManager.shadeModel(7424);
GlStateManager.depthMask(true);
GL11.glEnable(3008);
GlStateManager.popMatrix();
}

private static void drawESPImage(ResourceLocation resource, double x, double y, double x2, double y2, Color c, Color c2, float alpha) {
mc.getTextureManager().bindTexture(resource);
Tessellator tessellator = Tessellator.getInstance();
WorldRenderer bufferbuilder = tessellator.getWorldRenderer();
bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
bufferbuilder.pos(x, y2, 0.0).tex(0.0, 1.0).color(c.getRed(), c.getGreen(), c.getBlue(), (int) (alpha * 255)).endVertex();
bufferbuilder.pos(x2, y2, 0.0).tex(1.0, 1.0).color(c2.getRed(), c2.getGreen(), c2.getBlue(), (int) (alpha * 255)).endVertex();
bufferbuilder.pos(x2, y, 0.0).tex(1.0, 0.0).color(c.getRed(), c.getGreen(), c.getBlue(), (int) (alpha * 255)).endVertex();
bufferbuilder.pos(x, y, 0.0).tex(0.0, 0.0).color(c2.getRed(), c2.getGreen(), c2.getBlue(), (int) (alpha * 255)).endVertex();
GlStateManager.shadeModel(7425);
GlStateManager.depthMask(false);
tessellator.draw();
GlStateManager.depthMask(true);
GlStateManager.shadeModel(7424);
}

}
22 changes: 22 additions & 0 deletions src/main/java/net/ccbluex/liquidbounce/utils/EntityUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import net.ccbluex.liquidbounce.features.module.modules.other.AntiBot.isBot
import net.ccbluex.liquidbounce.features.module.modules.other.Teams
import net.ccbluex.liquidbounce.utils.extensions.eyes
import net.ccbluex.liquidbounce.utils.render.ColorUtils.stripColor
import net.minecraft.client.Minecraft
import net.minecraft.entity.Entity
import net.minecraft.entity.EntityLivingBase
import net.minecraft.entity.boss.EntityDragon
Expand All @@ -28,6 +29,7 @@ import net.minecraft.entity.passive.EntityBat
import net.minecraft.entity.passive.EntitySquid
import net.minecraft.entity.passive.EntityVillager
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.util.MathHelper
import net.minecraft.util.Vec3
import kotlin.math.cos
import kotlin.math.hypot
Expand Down Expand Up @@ -158,4 +160,24 @@ object EntityUtils : MinecraftInstance() {
fun Entity.speed() : Double {
return hypot(this.posX - this.prevPosX, this.posZ - this.prevPosZ) * 20
}

@JvmStatic
fun Entity.getSmoothDistanceToEntity(entityIn: Entity?): Float {
val pTicks = Minecraft.getMinecraft().timer.renderPartialTicks
val xposme: Double = this.lastTickPosX + (this.posX - this.lastTickPosX) * pTicks.toDouble()
val yposme: Double = this.lastTickPosY + (this.posY - this.lastTickPosY) * pTicks.toDouble()
val zposme: Double = this.lastTickPosZ + (this.posZ - this.lastTickPosZ) * pTicks.toDouble()
var xposent = 0.0
var yposent = 0.0
var zposent = 0.0
if (entityIn != null) {
xposent = entityIn.lastTickPosX + (entityIn.posX - entityIn.lastTickPosX) * pTicks.toDouble()
yposent = entityIn.lastTickPosY + (entityIn.posY - entityIn.lastTickPosY) * pTicks.toDouble()
zposent = entityIn.lastTickPosZ + (entityIn.posZ - entityIn.lastTickPosZ) * pTicks.toDouble()
}
val f = (xposme - xposent).toFloat()
val f1 = (yposme - yposent).toFloat()
val f2 = (zposme - zposent).toFloat()
return if (entityIn != null) MathHelper.sqrt_double((f * f + f1 * f1 + f2 * f2).toDouble()) else 0.0f
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ce11769

Please sign in to comment.