@@ -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
@@ -19,92 +18,246 @@ import net.minecraft.network.play.client.CPacketConfirmTeleport
19
18
import net.minecraft.network.play.client.CPacketPlayer
20
19
import net.minecraft.network.play.server.SPacketCloseWindow
21
20
import net.minecraft.network.play.server.SPacketPlayerPosLook
21
+ import net.minecraft.util.math.Vec3d
22
22
import kotlin.math.cos
23
+ import kotlin.math.floor
24
+ import kotlin.math.hypot
23
25
import kotlin.math.sin
24
26
27
+
25
28
object Flight : Module(
26
29
name = " Flight" ,
27
30
description = " Makes the player fly" ,
28
31
category = Category .MOVEMENT ,
29
32
modulePriority = 500
30
33
) {
34
+ // non packet
31
35
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 })
36
+ private val speed by setting(" Speed" , 1.0f , 0f .. 10f , 0.1f , { mode != FlightMode .PACKET })
37
+ private val glideSpeed by setting(" Glide Speed" , 0.05 , 0.0 .. 0.3 , 0.001 , { mode != FlightMode .PACKET })
38
+
39
+ // packet
40
+ private val packetMode by setting(" Packet Mode" , PacketMode .FAST , { mode == FlightMode .PACKET })
41
+ private val bounds by setting(" Packet Type" , PacketType .NEGATIVE , { mode == FlightMode .PACKET })
42
+ private val factor by setting(" Bypass Factor" , 1f , 0f .. 10f , .1f , { mode == FlightMode .PACKET })
43
+ private val concealFactor by setting(" Conceal Factor" , 2f ,0f .. 10f , .1f , { mode == FlightMode .PACKET })
44
+ private val conceal by setting(" Conceal" , false , { mode == FlightMode .PACKET })
36
45
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
46
42
47
private enum class FlightMode {
43
48
PACKET , VANILLA , STATIC
44
49
}
45
50
51
+ private enum class PacketType {
52
+ POSITIVE , NEGATIVE , STRICT
53
+ }
54
+
46
55
private enum class PacketMode {
47
- POSITIVE , NEGATIVE
56
+ FAST , SETBACK
48
57
}
49
58
59
+ private const val BASE_SPEED = .2873
60
+ private const val CONCEAL_SPEED = .0624
61
+ private const val SQRT_TWO_OVER_TWO = .707106781
62
+ private const val ANTIKICK_AMOUNT = .03125
63
+
64
+ private val history = HashMap <Int , Vec3d >()
65
+ private val filter = ArrayList <CPacketPlayer .Position >()
66
+ private var tpID = - 1
67
+ private var ticksEnabled = 0
68
+
50
69
init {
51
70
onDisable {
52
71
runSafe {
72
+
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
}
81
+
82
+ }
83
+ }
84
+
85
+ onEnable {
86
+ runSafe {
87
+ val position = CPacketPlayer .Position (.0 , .0 , .0 , true )
88
+ filter.add(position)
89
+ connection.sendPacket(position)
57
90
}
58
91
}
59
92
60
- safeListener<PlayerTravelEvent > {
93
+ safeListener<PlayerMoveEvent > {
61
94
when (mode) {
95
+
96
+ // uses the same concepts as https://gist.github.com/Doogie13/aa04c6a8eb496c1afdb9c675e2ebd91c
97
+ // completely written from scratch, however
62
98
FlightMode .PACKET -> {
63
- it.cancel()
64
99
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
100
+ player.noClip = true
101
+
102
+ // region Motion
103
+ val concealing = world.collidesWithAnyBlock(player.entityBoundingBox) || conceal
104
+
105
+ var motionY: Double
106
+
107
+ var up = 0
108
+
109
+ // we must use else if to allow phasing
110
+ if (mc.gameSettings.keyBindJump.isKeyDown)
111
+ up++
112
+ else if (mc.gameSettings.keyBindSneak.isKeyDown)
113
+ up--
114
+
115
+ motionY =
116
+ if (up == 0 )
117
+ .0
118
+ else
119
+ CONCEAL_SPEED * up.toDouble()
120
+
121
+ var motionXZ: Double = if (! MovementUtils .isInputting)
122
+ .0
123
+ else if (concealing)
124
+ CONCEAL_SPEED
125
+ else
126
+ BASE_SPEED
127
+
128
+ if (motionY != .0 && motionXZ == BASE_SPEED )
129
+ motionY = .0
130
+
131
+ if (motionXZ == CONCEAL_SPEED && motionY == CONCEAL_SPEED ) {
132
+ motionXZ * = SQRT_TWO_OVER_TWO
133
+ motionY * = SQRT_TWO_OVER_TWO
80
134
}
81
135
82
- val posX = player.posX + (player.motionX * hShrinkAmount)
83
- val posY = player.posY + (player.motionY * vShrinkAmount)
84
- val posZ = player.posZ + (player.motionZ * hShrinkAmount)
136
+ // endregion
137
+
138
+ // region packets
85
139
86
- val invalidPacketOffset = when (packetMode) {
87
- PacketMode .POSITIVE -> 1000
88
- PacketMode .NEGATIVE -> - 1000
140
+ val calcFactor =
141
+ if (hypot(motionXZ, motionY) < .0625 )
142
+ concealFactor
143
+ else
144
+ factor
145
+
146
+ var factorInt = floor(calcFactor).toInt()
147
+ val diff = calcFactor - factorInt
148
+
149
+ if (++ ticksEnabled % 10 < diff * 10 )
150
+ factorInt++
151
+
152
+ if (factorInt == 0 ) {
153
+ player.setVelocity(.0 , .0 , .0 )
154
+ return @safeListener
89
155
}
90
156
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++ ))
157
+ if (motionXZ == .0 && motionY == .0 )
158
+ factorInt = 1
159
+
160
+ val yaw = calcMoveYaw()
161
+
162
+ val baseX = - sin(yaw) * motionXZ
163
+ val baseY = motionY
164
+ val baseZ = cos(yaw) * motionXZ
165
+
166
+ var currentX = baseX
167
+ var currentY = if (antiKick && ticksEnabled % 10 == 0 ) - ANTIKICK_AMOUNT else baseY
168
+ var currentZ = baseZ
169
+
170
+ for (i in 1 .. (factorInt)) {
171
+
172
+ // should never happen
173
+ if (i > 10 )
174
+ break
175
+
176
+ val moveVec = Vec3d (currentX, currentY, currentZ)
177
+
178
+ var yOffset: Double
179
+
180
+ // region bounds
181
+ when (bounds) {
182
+
183
+ PacketType .STRICT -> {
184
+
185
+ var random = (Math .random() * 256 ) + 256
186
+
187
+ (random + player.posY > (if (player.dimension == - 1 ) 127 else 255 ))
188
+ random * = - 1
189
+
190
+ yOffset = random
191
+
192
+ }
193
+
194
+ PacketType .POSITIVE -> {
195
+
196
+ yOffset = 1337.0
197
+
198
+ }
199
+
200
+ PacketType .NEGATIVE -> {
201
+
202
+ yOffset = - 1337.0
203
+
204
+ }
205
+
206
+ }
207
+ // endregion
208
+
209
+ // region sending
210
+
211
+ val boundsPacket = CPacketPlayer .Position (player.posX + moveVec.x, player.posY + moveVec.y + yOffset, player.posZ + moveVec.z, true )
212
+ val movePacket = CPacketPlayer .Position (player.posX + moveVec.x, player.posY + moveVec.y, player.posZ + moveVec.z, true )
213
+
214
+ filter.add(movePacket)
215
+ filter.add(boundsPacket)
216
+
217
+ connection.sendPacket(movePacket)
218
+ connection.sendPacket(boundsPacket)
219
+
220
+ history[++ tpID] = moveVec.add(player.positionVector)
221
+ connection.sendPacket(CPacketConfirmTeleport (tpID))
222
+
223
+ currentX + = baseX
224
+ currentY + = baseY
225
+ currentZ + = baseZ
226
+
227
+ // endregion
228
+
95
229
}
230
+
231
+ // endregion
232
+
233
+ if (packetMode == PacketMode .FAST )
234
+ player.setVelocity(currentX - baseX, currentY - baseY, currentZ - baseZ)
235
+ else
236
+ player.setVelocity(.0 , .0 , .0 )
237
+
96
238
}
239
+
97
240
FlightMode .STATIC -> {
98
- player.capabilities.isFlying = true
99
- player.capabilities.flySpeed = speed
100
241
101
- player.motionX = 0.0
102
- player.motionY = - glideSpeed
103
- player.motionZ = 0.0
242
+ var up = 0
243
+
244
+ if (mc.gameSettings.keyBindJump.isKeyDown)
245
+ up++
246
+
247
+ if (mc.gameSettings.keyBindSneak.isKeyDown)
248
+ up--
249
+
250
+ player.motionY = if (up == 0 ) - glideSpeed else speed * up.toDouble()
251
+
252
+ if (! MovementUtils .isInputting)
253
+ return @safeListener
254
+
255
+ val yaw = calcMoveYaw()
256
+ player.motionX - = sin(yaw) * speed
257
+ player.motionZ + = cos(yaw) * speed
104
258
105
- if (mc.gameSettings.keyBindJump.isKeyDown) player.motionY + = speed / 2.0f
106
- if (mc.gameSettings.keyBindSneak.isKeyDown) player.motionY - = speed / 2.0f
107
259
}
260
+
108
261
FlightMode .VANILLA -> {
109
262
player.capabilities.isFlying = true
110
263
player.capabilities.flySpeed = speed / 11.11f
@@ -113,7 +266,9 @@ object Flight : Module(
113
266
&& ! mc.gameSettings.keyBindJump.isKeyDown
114
267
&& ! mc.gameSettings.keyBindSneak.isKeyDown) player.motionY = - glideSpeed
115
268
}
269
+
116
270
}
271
+
117
272
}
118
273
119
274
listener<OnUpdateWalkingPlayerEvent > {
@@ -124,16 +279,65 @@ object Flight : Module(
124
279
}
125
280
126
281
safeListener<PacketEvent .Receive > {
127
- if (mode != FlightMode .PACKET ) return @safeListener
282
+
283
+ if (mode != FlightMode .PACKET )
284
+ return @safeListener
285
+
128
286
when (it.packet) {
287
+
129
288
is SPacketPlayerPosLook -> {
289
+
290
+ val packet = it.packet
291
+ val id = packet.teleportId
292
+
293
+ if (history.containsKey(id) && tpID != - 1 ) {
294
+
295
+ val vec = history[id]
296
+
297
+ if (vec != null ) {
298
+
299
+ if (vec.x == packet.x && vec.y == packet.y && vec.z == packet.z) {
300
+
301
+ if (packetMode != PacketMode .SETBACK )
302
+ it.cancel()
303
+
304
+ history.remove(id)
305
+
306
+ player.connection.sendPacket(CPacketConfirmTeleport (id))
307
+
308
+ return @safeListener
309
+
310
+ }
311
+
312
+ }
313
+ }
314
+
130
315
it.packet.playerPosLookYaw = player.rotationYaw
131
316
it.packet.playerPosLookPitch = player.rotationPitch
317
+
318
+ player.connection.sendPacket(CPacketConfirmTeleport (id))
319
+
320
+ tpID = id
321
+
132
322
}
323
+
133
324
is SPacketCloseWindow -> {
134
325
it.cancel()
135
326
}
327
+
136
328
}
137
329
}
330
+
331
+ safeListener<PacketEvent .Send > {
332
+
333
+ if (mode != FlightMode .PACKET || it.packet !is CPacketPlayer ) return @safeListener
334
+
335
+ if (! filter.contains(it.packet))
336
+ it.cancel()
337
+ else
338
+ filter.remove(it.packet)
339
+
340
+ }
341
+
138
342
}
139
343
}
0 commit comments