Skip to content

Commit

Permalink
feat: RenderModel visual option to FakeLag.
Browse files Browse the repository at this point in the history
  • Loading branch information
opZywl committed Dec 30, 2024
1 parent 4511fa4 commit 8f8421a
Show file tree
Hide file tree
Showing 7 changed files with 332 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@ import net.ccbluex.liquidbounce.features.module.Module
import net.ccbluex.liquidbounce.features.module.modules.player.Blink
import net.ccbluex.liquidbounce.injection.implementations.IMixinEntity
import net.ccbluex.liquidbounce.utils.attack.EntityUtils.isSelected
import net.ccbluex.liquidbounce.utils.client.*
import net.ccbluex.liquidbounce.utils.client.PacketUtils
import net.ccbluex.liquidbounce.utils.client.realX
import net.ccbluex.liquidbounce.utils.client.realY
import net.ccbluex.liquidbounce.utils.client.realZ
import net.ccbluex.liquidbounce.utils.extensions.*
import net.ccbluex.liquidbounce.utils.kotlin.StringUtils.contains
import net.ccbluex.liquidbounce.utils.render.ColorSettingsInteger
import net.ccbluex.liquidbounce.utils.render.ColorUtils.rainbow
import net.ccbluex.liquidbounce.utils.render.RenderUtils.drawBacktrackBox
import net.ccbluex.liquidbounce.utils.render.RenderUtils.glColor
import net.ccbluex.liquidbounce.utils.rotation.Rotation
import net.ccbluex.liquidbounce.utils.timing.MSTimer
import net.ccbluex.liquidbounce.utils.timing.TimeUtils.randomDelay
import net.minecraft.client.renderer.GlStateManager.color
Expand Down Expand Up @@ -638,6 +642,40 @@ object Backtrack : Module("Backtrack", Category.COMBAT, hideModule = false) {
return result
}

fun <T> runWithModifiedRotation(
entity: EntityPlayer, rotation: Rotation, body: Pair<Float, Float>? = null,
f: (Rotation) -> T?
): T? {
val currRotation = entity.rotation
val prevRotation = entity.prevRotation
val bodyYaw = entity.prevRenderYawOffset to entity.renderYawOffset
val headRotation = entity.prevRotationYawHead to entity.rotationYawHead

entity.prevRotation = rotation
entity.rotation = rotation
entity.prevRotationYawHead = rotation.yaw
entity.rotationYawHead = rotation.yaw

body?.let {
entity.prevRenderYawOffset = it.first
entity.renderYawOffset = it.second
}

val result = f(rotation)

entity.rotation = currRotation
entity.prevRotation = prevRotation
entity.rotationYawHead = headRotation.second
entity.prevRotationYawHead = headRotation.first

body?.let {
entity.prevRenderYawOffset = bodyYaw.first
entity.renderYawOffset = bodyYaw.second
}

return result
}

val color
get() = if (espColorMode == "Rainbow") rainbow() else Color(espColor.color().rgb)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import net.ccbluex.liquidbounce.config.int
import net.ccbluex.liquidbounce.event.*
import net.ccbluex.liquidbounce.features.module.Category
import net.ccbluex.liquidbounce.features.module.Module
import net.ccbluex.liquidbounce.features.module.modules.combat.Backtrack.runWithModifiedRotation
import net.ccbluex.liquidbounce.features.module.modules.player.Blink
import net.ccbluex.liquidbounce.features.module.modules.player.scaffolds.Scaffold
import net.ccbluex.liquidbounce.injection.implementations.IMixinEntity
Expand All @@ -20,8 +21,12 @@ import net.ccbluex.liquidbounce.utils.client.pos
import net.ccbluex.liquidbounce.utils.extensions.*
import net.ccbluex.liquidbounce.utils.kotlin.removeEach
import net.ccbluex.liquidbounce.utils.render.ColorUtils.rainbow
import net.ccbluex.liquidbounce.utils.render.RenderUtils
import net.ccbluex.liquidbounce.utils.render.RenderUtils.glColor
import net.ccbluex.liquidbounce.utils.rotation.Rotation
import net.ccbluex.liquidbounce.utils.rotation.RotationUtils
import net.ccbluex.liquidbounce.utils.timing.MSTimer
import net.minecraft.client.entity.EntityPlayerSP
import net.minecraft.client.gui.inventory.GuiContainer
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.network.handshake.client.C00Handshake
Expand All @@ -35,6 +40,8 @@ import net.minecraft.network.status.server.S01PacketPong
import net.minecraft.util.Vec3
import org.lwjgl.opengl.GL11.*
import java.awt.Color
import java.util.*
import kotlin.math.min

object FakeLag : Module("FakeLag", Category.COMBAT, gameDetecting = false, hideModule = false) {

Expand All @@ -59,13 +66,16 @@ object FakeLag : Module("FakeLag", Category.COMBAT, gameDetecting = false, hideM
private val red by int("R", 0, 0..255, subjective = true) { !rainbow && line }
private val green by int("G", 255, 0..255, subjective = true) { !rainbow && line }
private val blue by int("B", 0, 0..255, subjective = true) { !rainbow && line }
private val renderModel by boolean("RenderModel", false, subjective = true)

private val packetQueue = Queues.newArrayDeque<QueueData>()
private val positions = Queues.newArrayDeque<PositionData>()
private val resetTimer = MSTimer()
private var wasNearEnemy = false
private var ignoreWholeTick = false

private var renderData = ModelRenderData(Vec3_ZERO, Rotation.ZERO)

override fun onDisable() {
if (mc.thePlayer == null) return

Expand Down Expand Up @@ -153,7 +163,7 @@ object FakeLag : Module("FakeLag", Category.COMBAT, gameDetecting = false, hideM

if (packet is C03PacketPlayer && packet.isMoving) {
synchronized(positions) {
positions += PositionData(packet.pos, System.currentTimeMillis())
positions += PositionData(packet.pos, System.currentTimeMillis(), player.renderYawOffset, RotationUtils.serverRotation)
}
}

Expand All @@ -163,7 +173,7 @@ object FakeLag : Module("FakeLag", Category.COMBAT, gameDetecting = false, hideM
}
}

val onWorld = handler<WorldEvent> { event ->
val onWorld = handler<WorldEvent> { event ->
// Clear packets on disconnect only
if (event.worldClient == null) blink(false)
}
Expand Down Expand Up @@ -218,33 +228,67 @@ object FakeLag : Module("FakeLag", Category.COMBAT, gameDetecting = false, hideM
ignoreWholeTick = false
}

val onRender3D = handler<Render3DEvent> {
val onRender3D = handler<Render3DEvent> { event ->
val player = mc.thePlayer ?: return@handler
val color = if (rainbow) rainbow() else Color(red, green, blue)

if (!line || Blink.blinkingSend() || positions.isEmpty()) return@handler
if (Blink.blinkingSend() || positions.isEmpty()) {
renderData.reset(player)
return@handler
}

renderData.update(positions)

if (line) {
glPushMatrix()
glDisable(GL_TEXTURE_2D)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
glEnable(GL_LINE_SMOOTH)
glEnable(GL_BLEND)
glDisable(GL_DEPTH_TEST)
mc.entityRenderer.disableLightmap()
glBegin(GL_LINE_STRIP)
glColor(color)

val renderPosX = mc.renderManager.viewerPosX
val renderPosY = mc.renderManager.viewerPosY
val renderPosZ = mc.renderManager.viewerPosZ

for ((pos) in positions) glVertex3d(
pos.xCoord - renderPosX, pos.yCoord - renderPosY, pos.zCoord - renderPosZ
)

glColor4d(1.0, 1.0, 1.0, 1.0)
glEnd()
glEnable(GL_DEPTH_TEST)
glDisable(GL_LINE_SMOOTH)
glDisable(GL_BLEND)
glEnable(GL_TEXTURE_2D)
glPopMatrix()
}

// A pretty basic model render process. Position and rotation interpolation is applied to look visually appealing to the user.
// This can be smarter by adding sneak checks, more timed hand swing/body movement, etc.
if (mc.gameSettings.thirdPersonView == 0 || renderModel) return@handler

val manager = mc.renderManager

glPushMatrix()
glDisable(GL_TEXTURE_2D)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
glEnable(GL_LINE_SMOOTH)
glEnable(GL_BLEND)
glDisable(GL_DEPTH_TEST)
mc.entityRenderer.disableLightmap()
glBegin(GL_LINE_STRIP)
glColor(color)

val renderPosX = mc.renderManager.viewerPosX
val renderPosY = mc.renderManager.viewerPosY
val renderPosZ = mc.renderManager.viewerPosZ

for ((pos) in positions) glVertex3d(pos.xCoord - renderPosX, pos.yCoord - renderPosY, pos.zCoord - renderPosZ)

glColor4d(1.0, 1.0, 1.0, 1.0)
glEnd()
glEnable(GL_DEPTH_TEST)
glDisable(GL_LINE_SMOOTH)
glDisable(GL_BLEND)
glEnable(GL_TEXTURE_2D)
glPushAttrib(GL_ALL_ATTRIB_BITS)

RenderUtils.glColor(Color.BLACK)

val (old, new) = positions.first() to positions.elementAt(min(1, positions.size - 1))

val pos = renderData.pos - manager.renderPos

runWithModifiedRotation(player, renderData.rotation, old.body to new.body) {
manager.doRenderEntity(
player, pos.xCoord, pos.yCoord, pos.zCoord, it.yaw, event.partialTicks, true
)
}

glPopAttrib()
glPopMatrix()
}

Expand Down Expand Up @@ -279,4 +323,18 @@ object FakeLag : Module("FakeLag", Category.COMBAT, gameDetecting = false, hideM

}

data class PositionData(val pos: Vec3, val time: Long)
data class ModelRenderData(var pos: Vec3, var rotation: Rotation) {
fun reset(player: EntityPlayerSP) {
pos = player.currPos
rotation = RotationUtils.serverRotation
}

fun update(positions: ArrayDeque<PositionData>) {
val data = positions.first()

pos = pos.lerpWith(data.pos, RenderUtils.deltaTimeNormalized(3))
rotation = rotation.lerpWith(data.rotation, RenderUtils.deltaTimeNormalized(1))
}
}

data class PositionData(val pos: Vec3, val time: Long, val body: Float, val rotation: Rotation)
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ object Scaffold : Module("Scaffold", Category.PLAYER, Keyboard.KEY_V, hideModule

if (blockSneakingAgainUntilOnGround && !player.onGround) {
WaitTickUtils.conditionalSchedule("block") {
player.onGround.also { if (it) requestedStopSneak = true }
mc.thePlayer?.onGround.also { if (it != false) requestedStopSneak = true } ?: true
}
}
}
Expand Down
Loading

0 comments on commit 8f8421a

Please sign in to comment.