@@ -3,9 +3,8 @@ package com.lambda.client.module.modules.movement
3
3
import com.lambda.client.event.Phase
4
4
import com.lambda.client.event.events.OnUpdateWalkingPlayerEvent
5
5
import com.lambda.client.event.events.PacketEvent
6
- import com.lambda.client.event.events.PlayerTravelEvent
6
+ import com.lambda.client.event.events.PlayerMoveEvent
7
7
import com.lambda.client.event.listener.listener
8
- import com.lambda.client.manager.managers.PacketManager
9
8
import com.lambda.client.manager.managers.PlayerPacketManager.sendPlayerPacket
10
9
import com.lambda.client.mixin.extension.playerPosLookPitch
11
10
import com.lambda.client.mixin.extension.playerPosLookYaw
@@ -14,96 +13,228 @@ import com.lambda.client.module.Module
14
13
import com.lambda.client.util.MovementUtils
15
14
import com.lambda.client.util.MovementUtils.calcMoveYaw
16
15
import com.lambda.client.util.threads.runSafe
16
+ import com.lambda.client.util.threads.runSafeR
17
17
import com.lambda.client.util.threads.safeListener
18
18
import net.minecraft.network.play.client.CPacketConfirmTeleport
19
19
import net.minecraft.network.play.client.CPacketPlayer
20
20
import net.minecraft.network.play.server.SPacketCloseWindow
21
21
import net.minecraft.network.play.server.SPacketPlayerPosLook
22
+ import net.minecraft.util.math.Vec3d
22
23
import kotlin.math.cos
24
+ import kotlin.math.floor
25
+ import kotlin.math.hypot
23
26
import kotlin.math.sin
24
27
28
+
25
29
object Flight : Module(
26
30
name = " Flight" ,
27
31
description = " Makes the player fly" ,
28
32
category = Category .MOVEMENT ,
29
33
modulePriority = 500
30
34
) {
35
+ // non packet
31
36
private val mode by setting(" Mode" , FlightMode .PACKET )
32
- private val speed by setting(" Speed" , 1.0f , 0.0f .. 10.0f , 0.1f )
33
- private val glideSpeed by setting(" Glide Speed" , 0.05 , 0.0 .. 0.3 , 0.001 )
34
- private val packetMode by setting(" Packet Mode" , PacketMode .NEGATIVE , { mode == FlightMode .PACKET })
35
- private val upSpeed by setting(" Up Speed" , 0.0622 , 0.0 .. 0.3 , 0.001 , { mode == FlightMode .PACKET })
37
+ private val speed by setting(" Speed" , 1.0f , 0f .. 10f , 0.1f , { mode != FlightMode .PACKET })
38
+ private val glideSpeed by setting(" Glide Speed" , 0.05 , 0.0 .. 0.3 , 0.001 , { mode != FlightMode .PACKET })
39
+
40
+ // packet
41
+ private val packetMode by setting(" Packet Mode" , PacketMode .FAST , { mode == FlightMode .PACKET })
42
+ private val bounds by setting(" Packet Type" , PacketType .NEGATIVE , { mode == FlightMode .PACKET })
43
+ private val factor by setting(" Bypass Factor" , 1f , 0f .. 10f , .1f , { mode == FlightMode .PACKET })
44
+ private val concealFactor by setting(" Conceal Factor" , 2f , 0f .. 10f , .1f , { mode == FlightMode .PACKET })
45
+ private val conceal by setting(" Conceal" , false , { mode == FlightMode .PACKET })
36
46
private val antiKick by setting(" Anti Kick" , true , { mode == FlightMode .PACKET })
37
- private val antiKickSpeed by setting(" Anti Kick Speed" , 0.0622 , 0.0 .. 0.3 , 0.001 , { mode == FlightMode .PACKET && antiKick })
38
- private val antiKickDelay by setting(" Anti Kick Delay" , 14 , 0 .. 100 , 1 , { mode == FlightMode .PACKET && antiKick }, unit = " ticks" )
39
- private val hShrinkAmount by setting(" Horizontal Shrink Amount" , 4.0 , 1.0 .. 10.0 , 0.1 , { mode == FlightMode .PACKET })
40
- private val vShrinkAmount by setting(" Vertical Shrink Amount" , 2.70 , 1.0 .. 10.0 , 0.1 , { mode == FlightMode .PACKET })
41
47
42
48
private enum class FlightMode {
43
49
PACKET , VANILLA , STATIC
44
50
}
45
51
52
+ private enum class PacketType {
53
+ POSITIVE , NEGATIVE , STRICT
54
+ }
55
+
46
56
private enum class PacketMode {
47
- POSITIVE , NEGATIVE
57
+ FAST , SETBACK
48
58
}
49
59
60
+ private const val BASE_SPEED = .2873
61
+ private const val CONCEAL_SPEED = .0624
62
+ private const val SQRT_TWO_OVER_TWO = .707106781
63
+ private const val ANTIKICK_AMOUNT = .03125
64
+
65
+ private val history = HashMap <Int , Vec3d >()
66
+ private val filter = ArrayList <CPacketPlayer .Position >()
67
+ private var tpID = - 1
68
+ private var ticksEnabled = 0
69
+
50
70
init {
51
71
onDisable {
52
72
runSafe {
73
+ tpID = - 1
74
+ ticksEnabled = 0
75
+ player.noClip = false
76
+
53
77
player.capabilities?.apply {
54
78
isFlying = false
55
79
flySpeed = 0.05f
56
80
}
57
81
}
58
82
}
59
83
60
- safeListener<PlayerTravelEvent > {
84
+ onEnable {
85
+ runSafeR {
86
+ val position = CPacketPlayer .Position (.0 , .0 , .0 , true )
87
+ filter.add(position)
88
+ connection.sendPacket(position)
89
+ } ? : disable()
90
+ }
91
+
92
+ safeListener<PlayerMoveEvent > {
61
93
when (mode) {
94
+ // uses the same concepts as https://gist.github.com/Doogie13/aa04c6a8eb496c1afdb9c675e2ebd91c
95
+ // completely written from scratch, however
62
96
FlightMode .PACKET -> {
63
- it.cancel()
97
+ player.noClip = true
64
98
65
- player.motionY = if (mc.gameSettings.keyBindJump.isKeyDown xor mc.gameSettings.keyBindSneak.isKeyDown) {
66
- if (mc.gameSettings.keyBindJump.isKeyDown) {
67
- if (player.ticksExisted % antiKickDelay == 0 && antiKick) {
68
- - antiKickSpeed / vShrinkAmount
69
- } else {
70
- upSpeed / vShrinkAmount
71
- }
72
- } else (- upSpeed / vShrinkAmount)
73
- } else {
74
- if (MovementUtils .isInputting) {
75
- val yaw = calcMoveYaw()
76
- player.motionX = (- sin(yaw) * 0.2f * speed) / hShrinkAmount
77
- player.motionZ = (cos(yaw) * 0.2f * speed) / hShrinkAmount
78
- }
79
- - glideSpeed / vShrinkAmount
99
+ // region Motion
100
+ val concealing = world.collidesWithAnyBlock(player.entityBoundingBox) || conceal
101
+ var motionY: Double
102
+ var up = 0
103
+
104
+ // we must use else if to allow phasing
105
+ if (mc.gameSettings.keyBindJump.isKeyDown)
106
+ up++
107
+ else if (mc.gameSettings.keyBindSneak.isKeyDown)
108
+ up--
109
+
110
+ motionY = if (up == 0 )
111
+ .0
112
+ else
113
+ CONCEAL_SPEED * up.toDouble()
114
+
115
+ var motionXZ: Double = if (! MovementUtils .isInputting)
116
+ .0
117
+ else if (concealing)
118
+ CONCEAL_SPEED
119
+ else
120
+ BASE_SPEED
121
+
122
+ if (motionY != .0 && motionXZ == BASE_SPEED )
123
+ motionY = .0
124
+
125
+ if (motionXZ == CONCEAL_SPEED && motionY == CONCEAL_SPEED ) {
126
+ motionXZ * = SQRT_TWO_OVER_TWO
127
+ motionY * = SQRT_TWO_OVER_TWO
80
128
}
81
129
82
- val posX = player.posX + (player.motionX * hShrinkAmount)
83
- val posY = player.posY + (player.motionY * vShrinkAmount)
84
- val posZ = player.posZ + (player.motionZ * hShrinkAmount)
130
+ // endregion
131
+
132
+ // region packets
133
+
134
+ val calcFactor =
135
+ if (hypot(motionXZ, motionY) < .0625 )
136
+ concealFactor
137
+ else
138
+ factor
139
+
140
+ var factorInt = floor(calcFactor).toInt()
141
+ val diff = calcFactor - factorInt
85
142
86
- val invalidPacketOffset = when (packetMode) {
87
- PacketMode .POSITIVE -> 1000
88
- PacketMode .NEGATIVE -> - 1000
143
+ if (++ ticksEnabled % 10 < diff * 10 )
144
+ factorInt++
145
+
146
+ if (factorInt == 0 ) {
147
+ player.setVelocity(.0 , .0 , .0 )
148
+ return @safeListener
89
149
}
90
150
91
- connection.sendPacket(CPacketPlayer .Position (posX, posY, posZ, false ))
92
- connection.sendPacket(CPacketPlayer .Position (posX, player.posY + invalidPacketOffset, posZ, false ))
93
- if (PacketManager .lastTeleportId != - 1 ) {
94
- connection.sendPacket(CPacketConfirmTeleport (PacketManager .lastTeleportId++ ))
151
+ if (motionXZ == .0 && motionY == .0 )
152
+ factorInt = 1
153
+
154
+ val yaw = calcMoveYaw()
155
+
156
+ val baseX = - sin(yaw) * motionXZ
157
+ val baseY = motionY
158
+ val baseZ = cos(yaw) * motionXZ
159
+
160
+ var currentX = baseX
161
+ var currentY = if (antiKick && ticksEnabled % 10 == 0 ) - ANTIKICK_AMOUNT else baseY
162
+ var currentZ = baseZ
163
+
164
+ for (i in 1 .. factorInt) {
165
+ // should never happen
166
+ if (i > 10 )
167
+ break
168
+
169
+ val moveVec = Vec3d (currentX, currentY, currentZ)
170
+
171
+ var yOffset: Double
172
+
173
+ // region bounds
174
+ when (bounds) {
175
+ PacketType .STRICT -> {
176
+ var random = (Math .random() * 256 ) + 256
177
+
178
+ (random + player.posY > (if (player.dimension == - 1 ) 127 else 255 ))
179
+ random * = - 1
180
+
181
+ yOffset = random
182
+ }
183
+ PacketType .POSITIVE -> {
184
+ yOffset = 1337.0
185
+ }
186
+ PacketType .NEGATIVE -> {
187
+ yOffset = - 1337.0
188
+ }
189
+ }
190
+ // endregion
191
+
192
+ // region sending
193
+
194
+ val boundsPacket = CPacketPlayer .Position (player.posX + moveVec.x, player.posY + moveVec.y + yOffset, player.posZ + moveVec.z, true )
195
+ val movePacket = CPacketPlayer .Position (player.posX + moveVec.x, player.posY + moveVec.y, player.posZ + moveVec.z, true )
196
+
197
+ filter.add(movePacket)
198
+ filter.add(boundsPacket)
199
+
200
+ connection.sendPacket(movePacket)
201
+ connection.sendPacket(boundsPacket)
202
+
203
+ history[++ tpID] = moveVec.add(player.positionVector)
204
+ connection.sendPacket(CPacketConfirmTeleport (tpID))
205
+
206
+ currentX + = baseX
207
+ currentY + = baseY
208
+ currentZ + = baseZ
209
+
210
+ // endregion
211
+
95
212
}
213
+
214
+ // endregion
215
+
216
+ if (packetMode == PacketMode .FAST )
217
+ player.setVelocity(currentX - baseX, currentY - baseY, currentZ - baseZ)
218
+ else
219
+ player.setVelocity(.0 , .0 , .0 )
220
+
96
221
}
97
222
FlightMode .STATIC -> {
98
- player.capabilities.isFlying = true
99
- player.capabilities.flySpeed = speed
223
+ var up = 0
224
+
225
+ if (mc.gameSettings.keyBindJump.isKeyDown) up++
226
+
227
+ if (mc.gameSettings.keyBindSneak.isKeyDown) up--
100
228
101
- player.motionX = 0.0
102
- player.motionY = - glideSpeed
103
- player.motionZ = 0.0
229
+ player.motionY = if (up == 0 ) - glideSpeed else speed * up.toDouble()
230
+
231
+ if (! MovementUtils .isInputting)
232
+ return @safeListener
233
+
234
+ val yaw = calcMoveYaw()
235
+ player.motionX - = sin(yaw) * speed
236
+ player.motionZ + = cos(yaw) * speed
104
237
105
- if (mc.gameSettings.keyBindJump.isKeyDown) player.motionY + = speed / 2.0f
106
- if (mc.gameSettings.keyBindSneak.isKeyDown) player.motionY - = speed / 2.0f
107
238
}
108
239
FlightMode .VANILLA -> {
109
240
player.capabilities.isFlying = true
@@ -125,15 +256,45 @@ object Flight : Module(
125
256
126
257
safeListener<PacketEvent .Receive > {
127
258
if (mode != FlightMode .PACKET ) return @safeListener
128
- when (it.packet) {
259
+
260
+ when (val packet = it.packet) {
129
261
is SPacketPlayerPosLook -> {
130
- it.packet.playerPosLookYaw = player.rotationYaw
131
- it.packet.playerPosLookPitch = player.rotationPitch
262
+ val id = packet.teleportId
263
+
264
+ if (history.containsKey(packet.teleportId) && tpID != - 1 ) {
265
+ history[id]?.let { vec ->
266
+ if (vec.x == packet.x && vec.y == packet.y && vec.z == packet.z) {
267
+ if (packetMode != PacketMode .SETBACK )
268
+ it.cancel()
269
+
270
+ history.remove(id)
271
+ player.connection.sendPacket(CPacketConfirmTeleport (id))
272
+ return @safeListener
273
+ }
274
+ }
275
+ }
276
+
277
+ packet.playerPosLookYaw = player.rotationYaw
278
+ packet.playerPosLookPitch = player.rotationPitch
279
+
280
+ player.connection.sendPacket(CPacketConfirmTeleport (id))
281
+
282
+ tpID = id
132
283
}
133
284
is SPacketCloseWindow -> {
134
285
it.cancel()
135
286
}
136
287
}
137
288
}
289
+
290
+ safeListener<PacketEvent .Send > {
291
+ if (mode != FlightMode .PACKET || it.packet !is CPacketPlayer ) return @safeListener
292
+
293
+ if (! filter.contains(it.packet))
294
+ it.cancel()
295
+ else
296
+ filter.remove(it.packet)
297
+
298
+ }
138
299
}
139
300
}
0 commit comments