Skip to content

Commit efac398

Browse files
Doogie13Avanatiker
andauthored
Step Rewrite (#477)
* Rewrite Step entirely * Step * Some minor changes * Cleanup --------- Co-authored-by: Constructor <[email protected]>
1 parent 0bc8bdd commit efac398

File tree

3 files changed

+98
-111
lines changed

3 files changed

+98
-111
lines changed

src/main/java/com/lambda/mixin/entity/MixinEntity.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
package com.lambda.mixin.entity;
22

33
import com.lambda.client.module.modules.movement.SafeWalk;
4+
import com.lambda.client.module.modules.movement.Step;
45
import com.lambda.client.module.modules.movement.Velocity;
56
import com.lambda.client.module.modules.player.Freecam;
67
import com.lambda.client.module.modules.player.ViewLock;
8+
import net.minecraft.client.Minecraft;
9+
import net.minecraft.client.entity.EntityPlayerSP;
710
import net.minecraft.entity.Entity;
811
import net.minecraft.entity.MoverType;
12+
import net.minecraft.util.math.AxisAlignedBB;
913
import org.spongepowered.asm.mixin.Mixin;
1014
import org.spongepowered.asm.mixin.Shadow;
1115
import org.spongepowered.asm.mixin.injection.At;
@@ -17,7 +21,9 @@ public abstract class MixinEntity {
1721

1822
@Shadow private int entityId;
1923

24+
@Shadow private AxisAlignedBB boundingBox;
2025
private boolean modifiedSneaking = false;
26+
float storedStepHeight = -1;
2127

2228
@Inject(method = "applyEntityCollision", at = @At("HEAD"), cancellable = true)
2329
public void applyEntityCollisionHead(Entity entityIn, CallbackInfo ci) {
@@ -48,4 +54,33 @@ public void turn(float yaw, float pitch, CallbackInfo ci) {
4854
if (Freecam.handleTurn(casted, yaw, pitch, ci)) return;
4955
ViewLock.handleTurn(casted, yaw, pitch, ci);
5056
}
57+
58+
// these mixins are for step module before and after the step calculations are performed
59+
@Inject(method = "move", at = @At(value = "FIELD", target = "net/minecraft/entity/Entity.stepHeight:F", ordinal = 3, shift = At.Shift.BEFORE))
60+
private void preStep(MoverType type, double x, double y, double z, CallbackInfo ci) {
61+
EntityPlayerSP player = Minecraft.getMinecraft().player;
62+
63+
if (player == null) return;
64+
65+
if (entityId == player.getEntityId()
66+
&& Step.INSTANCE.isEnabled()
67+
&& !Step.INSTANCE.pre(boundingBox, player)
68+
) {
69+
storedStepHeight = player.stepHeight;
70+
player.stepHeight = Step.INSTANCE.getStrict() ? 1.015f : Step.INSTANCE.getUpStep().getValue();
71+
}
72+
}
73+
74+
@Inject(method = "move", at = @At(value = "INVOKE", target = "net/minecraft/entity/Entity.resetPositionToBB ()V", ordinal = 1, shift = At.Shift.BEFORE))
75+
private void postStep(MoverType type, double x, double y, double z, CallbackInfo ci) {
76+
Minecraft mc = Minecraft.getMinecraft();
77+
EntityPlayerSP player = mc.player;
78+
79+
if (player == null || !Step.INSTANCE.isEnabled()) return;
80+
81+
if (entityId == player.getEntityId()) {
82+
Step.INSTANCE.post(boundingBox, mc);
83+
}
84+
}
85+
5186
}

src/main/kotlin/com/lambda/client/manager/managers/TimerManager.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ object TimerManager : Manager {
2121

2222
init {
2323
listener<RunGameLoopEvent.Start> {
24-
if (timer.tick(5L)) {
25-
val removeTime = System.currentTimeMillis() - 250L
24+
if (timer.tick(6L)) {
25+
val removeTime = System.currentTimeMillis() - 600L
2626
modifications.values.removeIf { it.second < removeTime }
2727
}
2828

Lines changed: 61 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -1,150 +1,102 @@
11
package com.lambda.client.module.modules.movement
22

3-
import com.lambda.client.event.SafeClientEvent
4-
import com.lambda.client.event.events.PacketEvent
5-
import com.lambda.client.event.listener.listener
6-
import com.lambda.client.manager.managers.PlayerPacketManager
7-
import com.lambda.client.mixin.extension.playerY
3+
import com.lambda.client.manager.managers.TimerManager.modifyTimer
4+
import com.lambda.client.manager.managers.TimerManager.resetTimer
85
import com.lambda.client.module.Category
96
import com.lambda.client.module.Module
10-
import com.lambda.client.module.modules.combat.Surround.inHoleCheck
11-
import com.lambda.client.setting.settings.impl.primitive.BooleanSetting
127
import com.lambda.client.util.BaritoneUtils
13-
import com.lambda.client.util.Bind
14-
import com.lambda.client.util.EntityUtils.isInOrAboveLiquid
15-
import com.lambda.client.util.text.MessageSendHelper
168
import com.lambda.client.util.threads.runSafe
179
import com.lambda.client.util.threads.safeListener
10+
import net.minecraft.client.Minecraft
11+
import net.minecraft.client.entity.EntityPlayerSP
1812
import net.minecraft.network.play.client.CPacketPlayer
19-
import net.minecraftforge.fml.common.gameevent.InputEvent
20-
import net.minecraftforge.fml.common.gameevent.TickEvent
21-
import org.lwjgl.input.Keyboard
13+
import net.minecraft.util.math.AxisAlignedBB
14+
import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent
15+
2216

2317
/**
24-
* The packet mode code is licensed under MIT and can be found here:
25-
* https://github.com/fr1kin/ForgeHax/blob/2011740/src/main/java/com/matt/forgehax/mods/StepMod.java
18+
* @author Doogie13
19+
* @since 20/09/2022
2620
*/
2721
object Step : Module(
2822
name = "Step",
29-
description = "Changes the vanilla behavior for stepping up blocks",
3023
category = Category.MOVEMENT,
31-
modulePriority = 200
24+
description = "Allows you to step up blocks",
25+
modulePriority = 201
3226
) {
33-
private val mode by setting("Mode", Mode.PACKET)
34-
private val upStep = setting("Up Step", true)
35-
private val downStep = setting("Down Step", false)
36-
private val entityStep by setting("Entities", true)
37-
private val checkHole by setting("Check Hole", false)
38-
private val height by setting("Height", 1.0f, 0.25f..2.0f, 0.25f)
39-
private val downSpeed by setting("Down Speed", 0.2f, 0.0f..1.0f, 0.05f)
40-
private val bindUpStep by setting("Bind Up Step", Bind())
41-
private val bindDownStep by setting("Bind Down Step", Bind())
42-
43-
private const val defaultHeight = 0.6f
44-
45-
private val ignoredPackets = HashSet<CPacketPlayer>()
46-
private var lastCollidedTick = 0
47-
private var onGroundTick = 0
48-
49-
@Suppress("UNUSED")
27+
28+
private val mode by setting("Mode", Mode.NCP, description = "Anticheat step bypass")
29+
val strict by setting("Strict", false, description = "Bypass the new UpdatedNCP step checks")
30+
val upStep = setting("Step Height", 2.5f, 1f..2.5f, .5f, { !strict }, description = "How high to step")
31+
5032
private enum class Mode {
51-
VANILLA, PACKET
33+
NCP, VANILLA
5234
}
5335

36+
private var playerY = 0.0
37+
private var timing = false
38+
5439
init {
40+
upStep.valueListeners.add { _, _ ->
41+
BaritoneUtils.settings?.assumeStep?.value = isEnabled
42+
}
43+
5544
onDisable {
45+
resetTimer()
5646
runSafe {
57-
player.apply {
58-
stepHeight = defaultHeight
59-
ridingEntity?.stepHeight = 1.0f
60-
}
47+
player.stepHeight = .6f
6148
}
62-
ignoredPackets.clear()
6349
}
6450

65-
onToggle {
66-
BaritoneUtils.settings?.assumeStep?.value = it && upStep.value
51+
safeListener<ClientTickEvent> {
52+
if (!timing) resetTimer()
53+
54+
timing = false
6755
}
56+
}
6857

69-
listener<InputEvent.KeyInputEvent> {
70-
val key = Keyboard.getEventKey()
58+
fun pre(bb: AxisAlignedBB, player: EntityPlayerSP): Boolean {
59+
player.ridingEntity?.let {
60+
it.stepHeight = if (strict) 1f else upStep.value
61+
}
7162

72-
if (bindUpStep.isDown(key)) {
73-
upStep.value = !upStep.value
74-
MessageSendHelper.sendChatMessage(upStep.toggleMsg())
75-
}
63+
playerY = bb.minY
7664

77-
if (bindDownStep.isDown(key)) {
78-
downStep.value = !downStep.value
79-
MessageSendHelper.sendChatMessage(downStep.toggleMsg())
80-
}
81-
}
65+
return player.isInWater
66+
|| player.isInLava
67+
|| !player.onGround
68+
|| player.isOnLadder
69+
|| player.movementInput.jump
70+
|| player.fallDistance >= 0.1
8271
}
8372

84-
private fun BooleanSetting.toggleMsg() = "$chatName Turned ${this.name} ${if (this.value) "&aon" else "&coff"}&f!"
73+
fun post(bb: AxisAlignedBB, mc: Minecraft) {
74+
if (mode == Mode.VANILLA) return
8575

86-
init {
87-
safeListener<TickEvent.ClientTickEvent> {
88-
if (it.phase != TickEvent.Phase.START || !shouldRunStep) return@safeListener
89-
setStepHeight()
90-
if (downStep.value && player.motionY <= 0.0 && player.ticksExisted - onGroundTick <= 3) downStep()
91-
if (player.collidedHorizontally) lastCollidedTick = player.ticksExisted
92-
if (player.onGround) onGroundTick = player.ticksExisted
93-
}
94-
}
76+
val height = bb.minY - playerY
9577

96-
private val SafeClientEvent.shouldRunStep: Boolean
97-
get() = !mc.gameSettings.keyBindSneak.isKeyDown
98-
&& !player.isElytraFlying
99-
&& !player.capabilities.isFlying
100-
&& !player.isOnLadder
101-
&& !player.isInOrAboveLiquid
102-
&& (!checkHole || !inHoleCheck())
78+
if (height < .6)
79+
return
10380

104-
private fun SafeClientEvent.setStepHeight() {
105-
player.stepHeight = if (upStep.value && player.onGround && player.collidedHorizontally) height else defaultHeight
106-
player.ridingEntity?.let {
107-
it.stepHeight = if (entityStep && it.collidedHorizontally) height else 1.0f
108-
}
109-
}
81+
val player = mc.player
82+
val connection = mc.connection ?: return
11083

111-
private fun SafeClientEvent.downStep() {
112-
// Down step doesn't work for edge lower than 1 blocks anyways
113-
val belowBB = player.entityBoundingBox.expand(0.0, -1.05, 0.0)
114-
if (world.collidesWithAnyBlock(belowBB)) player.motionY -= downSpeed
115-
}
84+
val values = ArrayList<Double>()
11685

117-
init {
118-
safeListener<PacketEvent.Send> { event ->
119-
if (!upStep.value || mode != Mode.PACKET || !shouldRunStep) return@safeListener
120-
if (event.packet !is CPacketPlayer || event.packet !is CPacketPlayer.Position && event.packet !is CPacketPlayer.PositionRotation) return@safeListener
121-
if (ignoredPackets.remove(event.packet)) return@safeListener
122-
123-
val prevPos = PlayerPacketManager.prevServerSidePosition
124-
if (player.ticksExisted - lastCollidedTick <= 5) getStepArray(event.packet.playerY - prevPos.y)?.let {
125-
for (posY in it) {
126-
val packet = CPacketPlayer.Position(prevPos.x, prevPos.y + posY, prevPos.z, true)
127-
ignoredPackets.add(packet)
128-
connection.sendPacket(packet)
129-
}
130-
}
86+
when {
87+
height > 2.019 -> values.addAll(listOf(.425, .821, .699, .599, 1.022, 1.372, 1.652, 1.869, 2.019, 1.919))
88+
height > 1.5 -> values.addAll(listOf(.42, .78, .63, .51, .9, 1.21, 1.45, 1.43))
89+
height > 1.015 -> values.addAll(listOf(.42, .7532, 1.01, 1.093, 1.015))
90+
height > .6 -> values.addAll(listOf(.42 * height, .7532 * height))
13191
}
132-
}
133-
134-
private fun getStepArray(diff: Double) = when {
135-
height >= diff && diff in 0.6..1.0 -> stepOne
136-
height >= diff && diff in 1.0..1.5 -> stepOneHalf
137-
height >= diff && diff in 1.5..2.0 -> stepTwo
138-
else -> null
139-
}
14092

141-
private val stepOne = doubleArrayOf(0.41999, 0.75320)
142-
private val stepOneHalf = doubleArrayOf(0.41999, 0.75320, 1.00133, 1.16611, 1.24919, 1.17079)
143-
private val stepTwo = doubleArrayOf(0.42, 0.78, 0.63, 0.51, 0.90, 1.21, 1.45, 1.43)
93+
if (strict && height > .6) values.add(height)
14494

145-
init {
146-
upStep.valueListeners.add { _, it ->
147-
BaritoneUtils.settings?.assumeStep?.value = isEnabled && it
95+
values.forEach {
96+
connection.sendPacket(CPacketPlayer.Position(player.posX, player.posY + it, player.posZ, false))
14897
}
98+
99+
modifyTimer(50f * values.size)
100+
timing = true
149101
}
150102
}

0 commit comments

Comments
 (0)