Skip to content

Commit

Permalink
fix(legacy): ForwardTrack not displaying positions correctly in Singl…
Browse files Browse the repository at this point in the history
…eplayer. (CCBlueX#4050)
  • Loading branch information
mems01 authored Oct 3, 2024
1 parent 4388a43 commit 9f84c5f
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ object Backtrack : Module("Backtrack", Category.COMBAT, hideModule = false) {

// ESP
val espMode by ListValue("ESP-Mode",
arrayOf("None", "Box", "Player"),
arrayOf("None", "Box", "Model"),
"Box",
subjective = true
) { mode == "Modern" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import net.minecraft.util.Vec3
import java.awt.Color

object ForwardTrack : Module("ForwardTrack", Category.COMBAT) {
val espMode by ListValue("ESP-Mode", arrayOf("Box", "Player"), "Player", subjective = true)
val espMode by ListValue("ESP-Mode", arrayOf("Box", "Model"), "Model", subjective = true)

private val rainbow by BoolValue("Rainbow", true, subjective = true) { espMode == "Box" }
private val red by IntegerValue("R", 0, 0..255, subjective = true) { !rainbow && espMode == "Box" }
Expand All @@ -37,24 +37,31 @@ object ForwardTrack : Module("ForwardTrack", Category.COMBAT) {
* Any good anti-cheat will easily detect this module.
*/
fun includeEntityTruePos(entity: Entity, action: () -> Unit) {
if (!state || entity !is EntityLivingBase || entity is EntityPlayerSP)
return

val iEntity = (entity as IMixinEntity)

if (!iEntity.truePos)
if (!handleEvents() || entity !is EntityLivingBase || entity is EntityPlayerSP)
return

// Would be more fun if we simulated instead.
val pos = iEntity.run { Vec3(trueX, trueY, trueZ) }

Backtrack.runWithSimulatedPosition(entity, pos) {
Backtrack.runWithSimulatedPosition(entity, usePosition(entity)) {
action()

null
}
}

fun usePosition(entity: Entity): Vec3 {
entity.run {
return if (!mc.isSingleplayer) {
val iEntity = entity as IMixinEntity

if (iEntity.truePos) {
Vec3(iEntity.trueX, iEntity.trueY, iEntity.trueZ)
} else positionVector
} else if (this is EntityLivingBase) {
Vec3(newPosX, newPosY, newPosZ)
} else positionVector
}
}

@EventTarget
fun onRender3D(event: Render3DEvent) {
if (espMode != "Box")
Expand All @@ -66,30 +73,25 @@ object ForwardTrack : Module("ForwardTrack", Category.COMBAT) {
if (target is EntityPlayerSP)
continue

target?.run {
val targetEntity = target as IMixinEntity

if (targetEntity.truePos) {
val x =
targetEntity.trueX - renderManager.renderPosX
val y =
targetEntity.trueY - renderManager.renderPosY
val z =
targetEntity.trueZ - renderManager.renderPosZ

val axisAlignedBB = entityBoundingBox.offset(-posX, -posY, -posZ).offset(x, y, z)

drawBacktrackBox(
AxisAlignedBB.fromBounds(
axisAlignedBB.minX,
axisAlignedBB.minY,
axisAlignedBB.minZ,
axisAlignedBB.maxX,
axisAlignedBB.maxY,
axisAlignedBB.maxZ
), color
)
}
target.run {
val vec = usePosition(this)

val x = vec.xCoord - renderManager.renderPosX
val y = vec.yCoord - renderManager.renderPosY
val z = vec.zCoord - renderManager.renderPosZ

val axisAlignedBB = entityBoundingBox.offset(-posX, -posY, -posZ).offset(x, y, z)

drawBacktrackBox(
AxisAlignedBB.fromBounds(
axisAlignedBB.minX,
axisAlignedBB.minY,
axisAlignedBB.minZ,
axisAlignedBB.maxX,
axisAlignedBB.maxY,
axisAlignedBB.maxZ
), color
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import net.minecraft.potion.Potion
import net.minecraft.util.BlockPos
import net.minecraft.util.EnumFacing
import net.minecraft.util.MovingObjectPosition
import net.minecraft.util.Vec3
import net.minecraft.world.WorldSettings
import org.lwjgl.input.Keyboard
import java.awt.Color
Expand Down Expand Up @@ -753,9 +754,10 @@ object KillAura : Module("KillAura", Category.COMBAT, Keyboard.KEY_R, hideModule
Potion.regeneration
).amplifier else -1
}

"inweb" -> targets.sortBy { if (it.isInWeb) -1 else 1 } // Sort by whether the target is inside a web block
"onladder" -> targets.sortBy { if (it.isOnLadder) -1 else 1 } // Sort by on a ladder
"inliquid" -> targets.sortBy { if (it.isInWater || it.isInLava) -1 else 1 } // Sort by whether the target is in water or lava
"inliquid" -> targets.sortBy { if (it.isInWater || it.isInLava) -1 else 1 } // Sort by whether the target is in water or lava
}

// Find best target
Expand Down Expand Up @@ -1007,7 +1009,21 @@ object KillAura : Module("KillAura", Category.COMBAT, Keyboard.KEY_R, hideModule
hittable = isRotationFaced(target, range.toDouble(), currentRotation)
}

if (!hittable) {
var shouldExcept = false

chosenEntity ?: this.target?.run {
if (ForwardTrack.handleEvents()) {
ForwardTrack.includeEntityTruePos(this) {
checkIfAimingAtBox(this, currentRotation, eyes, onSuccess = {
hittable = true

shouldExcept = true
})
}
}
}

if (!hittable || shouldExcept) {
return
}

Expand All @@ -1023,27 +1039,21 @@ object KillAura : Module("KillAura", Category.COMBAT, Keyboard.KEY_R, hideModule

if (Backtrack.handleEvents()) {
Backtrack.loopThroughBacktrackData(targetToCheck) {
if (targetToCheck.hitBox.isVecInside(eyes)) {
checkNormally = false
return@loopThroughBacktrackData true
}

// Recreate raycast logic
val intercept = targetToCheck.hitBox.calculateIntercept(eyes,
eyes + getVectorForRotation(currentRotation) * range.toDouble()
)
var result = false

if (intercept != null) {
// Is the entity box raycast vector visible? If not, check through-wall range
hittable = isVisible(intercept.hitVec) || mc.thePlayer.getDistanceToEntityBox(targetToCheck) <= throughWallsRange
checkIfAimingAtBox(targetToCheck, currentRotation, eyes, onSuccess = {
checkNormally = false

if (hittable) {
checkNormally = false
return@loopThroughBacktrackData true
}
}
result = true
}, onFail = {
result = false
})

return@loopThroughBacktrackData false
return@loopThroughBacktrackData result
}
} else if (ForwardTrack.handleEvents()) {
ForwardTrack.includeEntityTruePos(targetToCheck) {
checkIfAimingAtBox(targetToCheck, currentRotation, eyes, onSuccess = { checkNormally = false })
}
}

Expand Down Expand Up @@ -1192,6 +1202,33 @@ object KillAura : Module("KillAura", Category.COMBAT, Keyboard.KEY_R, hideModule
return lastAttack != null && lastAttack.first.typeOfHit != currentType && runTimeTicks - lastAttack.second <= hitDelayTicks
}

private fun checkIfAimingAtBox(
targetToCheck: Entity, currentRotation: Rotation, eyes: Vec3, onSuccess: () -> Unit,
onFail: () -> Unit = { },
) {
if (targetToCheck.hitBox.isVecInside(eyes)) {
onSuccess()
return
}

// Recreate raycast logic
val intercept = targetToCheck.hitBox.calculateIntercept(eyes,
eyes + getVectorForRotation(currentRotation) * range.toDouble()
)

if (intercept != null) {
// Is the entity box raycast vector visible? If not, check through-wall range
hittable = isVisible(intercept.hitVec) || mc.thePlayer.getDistanceToEntityBox(targetToCheck) <= throughWallsRange

if (hittable) {
onSuccess()
return
}
}

onFail()
}

/**
* Check if run should be cancelled
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
import net.ccbluex.liquidbounce.features.module.modules.combat.HitBox;
import net.ccbluex.liquidbounce.features.module.modules.render.FreeCam;
import net.ccbluex.liquidbounce.injection.implementations.IMixinEntity;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.entity.Entity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.Vec3;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.spongepowered.asm.mixin.Mixin;
Expand Down Expand Up @@ -56,13 +58,16 @@ private AxisAlignedBB getEntityBoundingBox(Entity entity) {
private void renderEntityStatic(Entity entity, float tickDelta, boolean bool, CallbackInfoReturnable<Boolean> cir) {
FreeCam.INSTANCE.restoreOriginalPosition();

if (entity instanceof EntityPlayerSP)
return;

Backtrack backtrack = Backtrack.INSTANCE;
IMixinEntity targetEntity = (IMixinEntity) backtrack.getTarget();

boolean shouldBacktrackRenderEntity = backtrack.handleEvents() && backtrack.getShouldRender()
&& backtrack.shouldBacktrack() && backtrack.getTarget() == entity;

if (backtrack.getEspMode().equals("Player")) {
if (backtrack.getEspMode().equals("Model")) {
if (shouldBacktrackRenderEntity && targetEntity != null && targetEntity.getTruePos()) {
if (entity.ticksExisted == 0) {
entity.lastTickPosX = entity.posX;
Expand Down Expand Up @@ -90,32 +95,27 @@ private void renderEntityStatic(Entity entity, float tickDelta, boolean bool, Ca

ForwardTrack forwardTrack = ForwardTrack.INSTANCE;

if (forwardTrack.handleEvents() && forwardTrack.getEspMode().equals("Player") && !shouldBacktrackRenderEntity) {
targetEntity = (IMixinEntity) entity;
if (forwardTrack.handleEvents() && forwardTrack.getEspMode().equals("Model") && !shouldBacktrackRenderEntity) {
if (entity.ticksExisted == 0) {
entity.lastTickPosX = entity.posX;
entity.lastTickPosY = entity.posY;
entity.lastTickPosZ = entity.posZ;
}

if (targetEntity != null && targetEntity.getTruePos()) {
if (entity.ticksExisted == 0) {
entity.lastTickPosX = entity.posX;
entity.lastTickPosY = entity.posY;
entity.lastTickPosZ = entity.posZ;
}
Vec3 pos = forwardTrack.usePosition(entity);

double d0 = targetEntity.getTrueX();
double d1 = targetEntity.getTrueY();
double d2 = targetEntity.getTrueZ();
float f = entity.prevRotationYaw + (entity.rotationYaw - entity.prevRotationYaw) * tickDelta;
int i = entity.getBrightnessForRender(tickDelta);
if (entity.isBurning()) {
i = 15728880;
}

int j = i % 65536;
int k = i / 65536;
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, (float) j, (float) k);
// Darker color to differentiate fake player & real player.
GlStateManager.color(0.5F, 0.5F, 0.5F, 1.0F);
this.doRenderEntity(entity, d0 - this.renderPosX, d1 - this.renderPosY, d2 - this.renderPosZ, f, tickDelta, bool);
float f = entity.prevRotationYaw + (entity.rotationYaw - entity.prevRotationYaw) * tickDelta;
int i = entity.getBrightnessForRender(tickDelta);
if (entity.isBurning()) {
i = 15728880;
}

int j = i % 65536;
int k = i / 65536;
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, (float) j, (float) k);
// Darker color to differentiate fake player & real player.
GlStateManager.color(0.5F, 0.5F, 0.5F, 1.0F);
this.doRenderEntity(entity, pos.xCoord - this.renderPosX, pos.yCoord - this.renderPosY, pos.zCoord - this.renderPosZ, f, tickDelta, bool);
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/liquidbounce_at.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,7 @@ public net.minecraft.entity.EntityLivingBase field_70773_bE # jumpTicks
public-f net.minecraft.util.Vec3 field_72450_a # xCoord
public-f net.minecraft.util.Vec3 field_72448_b # yCoord
public-f net.minecraft.util.Vec3 field_72449_c # zCoord

public net.minecraft.entity.EntityLivingBase field_70709_bj # newPosX
public net.minecraft.entity.EntityLivingBase field_70710_bk # newPosY
public net.minecraft.entity.EntityLivingBase field_110152_bk # newPosZ

0 comments on commit 9f84c5f

Please sign in to comment.