Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Packetfly changes #246

Merged
merged 8 commits into from
Mar 4, 2022
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.lambda.client.manager.managers

import com.lambda.client.event.events.ConnectionEvent
import com.lambda.client.event.events.PacketEvent
import com.lambda.client.event.listener.listener
import com.lambda.client.manager.Manager
import com.lambda.client.util.threads.safeListener
import net.minecraft.network.play.server.SPacketPlayerPosLook

object PacketManager : Manager {
var lastTeleportId = -1

init {
listener<PacketEvent.Receive> {
when (it.packet) {
is SPacketPlayerPosLook -> {
lastTeleportId = it.packet.teleportId
}
}
}

safeListener<ConnectionEvent> {
lastTeleportId = -1
}
}
}
94 changes: 66 additions & 28 deletions src/main/kotlin/com/lambda/client/module/modules/movement/Flight.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,21 @@ import com.lambda.client.event.Phase
import com.lambda.client.event.events.OnUpdateWalkingPlayerEvent
import com.lambda.client.event.events.PacketEvent
import com.lambda.client.event.events.PlayerTravelEvent
import com.lambda.client.event.listener.listener
import com.lambda.client.manager.managers.PacketManager
import com.lambda.client.manager.managers.PlayerPacketManager.sendPlayerPacket
import com.lambda.client.mixin.extension.playerPosLookPitch
import com.lambda.client.mixin.extension.playerPosLookYaw
import com.lambda.client.module.Category
import com.lambda.client.module.Module
import com.lambda.client.util.MovementUtils
import com.lambda.client.util.MovementUtils.calcMoveYaw
import com.lambda.client.util.threads.runSafe
import com.lambda.client.util.threads.safeListener
import com.lambda.client.event.listener.listener
import net.minecraft.network.play.client.CPacketConfirmTeleport
import net.minecraft.network.play.client.CPacketPlayer
import net.minecraft.network.play.server.SPacketCloseWindow
import net.minecraft.network.play.server.SPacketPlayerPosLook
import kotlin.math.cos
import kotlin.math.sin

Expand All @@ -23,12 +28,23 @@ object Flight : Module(
description = "Makes the player fly",
modulePriority = 500
) {
private val mode by setting("Mode", FlightMode.VANILLA)
private val mode by setting("Mode", FlightMode.PACKET)
private val speed by setting("Speed", 1.0f, 0.0f..10.0f, 0.1f)
private val glideSpeed by setting("Glide Speed", 0.05, 0.0..0.3, 0.001)
private val packetMode by setting("Packet Mode", PacketMode.NEGATIVE, { mode == FlightMode.PACKET })
private val upSpeed by setting("Up Speed", 0.0622, 0.0..0.3, 0.001, { mode == FlightMode.PACKET })
private val antiKick by setting("Anti Kick", true, { mode == FlightMode.PACKET })
private val antiKickSpeed by setting("Anti Kick Speed", 0.0622, 0.0..0.3, 0.001, { mode == FlightMode.PACKET && antiKick })
private val antiKickDelay by setting("Anti Kick Delay", 14, 0..100, 1, { mode == FlightMode.PACKET && antiKick})
private val hShrinkAmount by setting("Horizontal Shrink Amount", 4.0, 1.0..10.0, 0.1, { mode == FlightMode.PACKET })
private val vShrinkAmount by setting("Vertical Shrink Amount", 2.70, 1.0..10.0, 0.1, { mode == FlightMode.PACKET })

private enum class FlightMode {
VANILLA, STATIC, PACKET
PACKET, VANILLA, STATIC
}

private enum class PacketMode {
POSITIVE, NEGATIVE
}

init {
Expand All @@ -43,6 +59,41 @@ object Flight : Module(

safeListener<PlayerTravelEvent> {
when (mode) {
FlightMode.PACKET -> {
it.cancel()

player.motionY = if (mc.gameSettings.keyBindJump.isKeyDown xor mc.gameSettings.keyBindSneak.isKeyDown) {
if (mc.gameSettings.keyBindJump.isKeyDown) {
if (player.ticksExisted % antiKickDelay == 0 && antiKick) {
-antiKickSpeed / vShrinkAmount
} else {
upSpeed / vShrinkAmount
}
} else (-upSpeed / vShrinkAmount)
} else {
if (MovementUtils.isInputting) {
val yaw = calcMoveYaw()
player.motionX = (-sin(yaw) * 0.2f * speed) / hShrinkAmount
player.motionZ = (cos(yaw) * 0.2f * speed) / hShrinkAmount
}
-glideSpeed / vShrinkAmount
}

val posX = player.posX + (player.motionX * hShrinkAmount)
val posY = player.posY + (player.motionY * vShrinkAmount)
val posZ = player.posZ + (player.motionZ * hShrinkAmount)

val invalidPacketOffset = when (packetMode) {
PacketMode.POSITIVE -> 1000
PacketMode.NEGATIVE -> -1000
}

connection.sendPacket(CPacketPlayer.Position(posX, posY, posZ, false))
connection.sendPacket(CPacketPlayer.Position(posX, player.posY + invalidPacketOffset, posZ, false))
if (PacketManager.lastTeleportId != -1) {
connection.sendPacket(CPacketConfirmTeleport(PacketManager.lastTeleportId++))
}
}
FlightMode.STATIC -> {
player.capabilities.isFlying = true
player.capabilities.flySpeed = speed
Expand All @@ -62,40 +113,27 @@ object Flight : Module(
&& !mc.gameSettings.keyBindJump.isKeyDown
&& !mc.gameSettings.keyBindSneak.isKeyDown) player.motionY = -glideSpeed
}
FlightMode.PACKET -> {
it.cancel()

player.motionY = if (mc.gameSettings.keyBindJump.isKeyDown xor mc.gameSettings.keyBindSneak.isKeyDown) {
if (mc.gameSettings.keyBindJump.isKeyDown) 0.0622
else -0.0622
} else {
if (MovementUtils.isInputting) {
val yaw = calcMoveYaw()
player.motionX = -sin(yaw) * 0.2f
player.motionZ = cos(yaw) * 0.2f
}
-glideSpeed
}

val posX = player.posX + player.motionX
val posY = player.posY + player.motionY
val posZ = player.posZ + player.motionZ

connection.sendPacket(CPacketPlayer.PositionRotation(posX, posY, posZ, player.rotationYaw, player.rotationPitch, false))
connection.sendPacket(CPacketPlayer.Position(posX, player.posY - 42069, posZ, true))
}
}
}

listener<OnUpdateWalkingPlayerEvent> {
if (mode != FlightMode.PACKET || it.phase != Phase.PRE) return@listener
if (it.phase != Phase.PRE || mode != FlightMode.PACKET) return@listener
sendPlayerPacket {
cancelAll()
}
}

listener<PacketEvent.Receive> {
if (mode == FlightMode.PACKET && it.packet is SPacketCloseWindow) it.cancel()
safeListener<PacketEvent.Receive> {
if (mode != FlightMode.PACKET) return@safeListener
when (it.packet) {
is SPacketPlayerPosLook -> {
it.packet.playerPosLookYaw = player.rotationYaw
it.packet.playerPosLookPitch = player.rotationPitch
}
is SPacketCloseWindow -> {
it.cancel()
}
}
}
}
}