diff --git a/Client/src/main/java/de/com/baseband/client/feature/modules/client/Ping.java b/Client/src/main/java/de/com/baseband/client/feature/modules/client/Ping.java index 61b527c..d18a78f 100644 --- a/Client/src/main/java/de/com/baseband/client/feature/modules/client/Ping.java +++ b/Client/src/main/java/de/com/baseband/client/feature/modules/client/Ping.java @@ -63,17 +63,15 @@ public class Ping extends Feature { if(holder == null || !holder.passed()) break; this.holderSend.remove(); - allowSend = holder.packet; - mc.player.connection.sendPacket(allowSend); + mc.player.connection.sendPacket(allowSend = holder.packet); } while (true) { PacketHolder holder = this.holderRecv.peek(); if(holder == null || !holder.passed()) break; this.holderRecv.remove(); - allowRecv = holder.packet; try { - mc.player.connection.getNetworkManager().channelRead(null, allowRecv); + mc.player.connection.getNetworkManager().channelRead(null, allowRecv = holder.packet); } catch (Exception e) { BaseBand.notifyAll("!! BaseBand encountered a BUG. Please report as soon as possible and include the game log."); new RuntimeException("[BaseBand BUG] Cannot emulate packet read", e).printStackTrace(); @@ -106,7 +104,7 @@ public class Ping extends Feature { @Listen public void onPacket(PrePacketEvent.Send e) { - if(allowSend == e.getPacket() || notIngame()) + if(allowSend == e.getPacket() || notIngame() || mc.player.ticksExisted < 20) return; if (e.getPacket() instanceof CPacketKeepAlive || holdAll) { totalSent++; @@ -117,7 +115,7 @@ public class Ping extends Feature { @Listen public void onPacket(PrePacketEvent.Receive e) { - if(allowRecv == e.getPacket() || notIngame()) + if(allowRecv == e.getPacket() || notIngame() || mc.player.ticksExisted < 20) return; if (e.getPacket() instanceof SPacketKeepAlive || holdAll) { totalRecieved++; diff --git a/Client/src/main/java/de/com/baseband/client/feature/modules/movement/PacketFly.java b/Client/src/main/java/de/com/baseband/client/feature/modules/movement/PacketFly.java index f94397b..f723cfa 100644 --- a/Client/src/main/java/de/com/baseband/client/feature/modules/movement/PacketFly.java +++ b/Client/src/main/java/de/com/baseband/client/feature/modules/movement/PacketFly.java @@ -1,5 +1,6 @@ package de.com.baseband.client.feature.modules.movement; +import de.com.baseband.client.BaseBand; import de.com.baseband.client.event.Listen; import de.com.baseband.client.event.events.MoveEvent; import de.com.baseband.client.event.events.PacketEvent; @@ -14,8 +15,13 @@ import de.com.baseband.client.util.interact.ServerDataManager; import net.minecraft.network.play.client.CPacketConfirmTeleport; import net.minecraft.network.play.client.CPacketPlayer; import net.minecraft.network.play.server.SPacketPlayerPosLook; +import net.minecraft.util.EnumParticleTypes; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec2f; +import net.minecraft.util.math.Vec3d; + +import java.util.LinkedList; +import java.util.Queue; @Experimental public class PacketFly extends Feature { @@ -38,15 +44,21 @@ public class PacketFly extends Feature { @Description("Tries to avoid the automatic flight kick mechanism in vanilla.") public boolean noFlyKick = true; + @Config("Use conservative constant") + public boolean conservative = false; + private int ticksElapsed = 0; private int trackingTPPacket = 0; private boolean moving = false; - private SPacketPlayerPosLook lastPacket = null; + private int ticksSinceMovement = 0; private long time = 0; + private long verticalTimeout = 0; + private final Queue positions = new LinkedList<>(); public void onDisable() { moving = false; trackingTPPacket = 0; + positions.clear(); } @Override @@ -60,8 +72,13 @@ public class PacketFly extends Feature { if(meta.isEmpty()) meta = null; - time++; + ticksSinceMovement++; + if(moving) + ticksSinceMovement = 0; + ticksElapsed++; + + mc.world.spawnParticle(EnumParticleTypes.FLAME, mc.player.posX, mc.player.posY + 1, mc.player.posZ, 0.1, 0.1, 0.1); } @Listen @@ -75,6 +92,8 @@ public class PacketFly extends Feature { return; } + time++; + if(mc.getRenderViewEntity() == mc.player) { Vec2f movementVec = mc.player.movementInput.getMoveVector(); float f1 = MathHelper.sin(mc.player.rotationYaw * 0.017453292F); @@ -82,15 +101,27 @@ public class PacketFly extends Feature { double x = movementVec.x * f2 - movementVec.y * f1; double y = (mc.player.movementInput.jump ? 1 : 0) + (mc.player.movementInput.sneak ? -1 : 0); double z = movementVec.y * f2 + movementVec.x * f1; - float d = (float) Math.sqrt(x * x + y * y + z * z) / (0.249f * speed); + if(noFlyKick && time % 20 == 0) + y = -1; + if(noFlyKick && time % 20 == 1) + y = 1; + if(y != 0) { + verticalTimeout = ServerDataManager.asyncTimeToSurelyTicked(); + } + if(verticalTimeout-- > 0) { + x = z = 0; + } + float d = (float) Math.sqrt(x * x + y * y + z * z) / ((conservative ? 0.06249f : 0.249f) * speed); if(d == 0) { if(moving) { - sendPosition(0); + moving = false; + } + if(ticksSinceMovement > 10) { + sendPosition(); sendForce(); trackingTPPacket = 0; - lastPacket = null; - moving = false; + positions.clear(); } return; } @@ -103,50 +134,56 @@ public class PacketFly extends Feature { mc.player.posY += y; mc.player.posZ += z; - double yOffset = (time % 30 == 0 ? -0.05 : 0); - - sendPosition(yOffset); - sendForce(); - if(predict) { - if (trackingTPPacket == 0) { - HUD.notify("Synchronizing PacketFly.", 1000); - } else { - mc.player.connection.sendPacket(new CPacketConfirmTeleport(++trackingTPPacket)); - sendPosition(yOffset); - } - } - else { - trackingTPPacket = 0; - } + sendPositionFull(); moving = true; ticksElapsed = 0; } } - private void sendPosition(double yOffset) { - mc.player.connection.sendPacket(new CPacketPlayer.PositionRotation(mc.player.posX, mc.player.posY + yOffset, mc.player.posZ, mc.player.rotationYaw, mc.player.rotationPitch, mc.player.onGround)); + private void sendPositionFull() { + sendPosition(); + sendForce(); + if (predict) { + if (trackingTPPacket == 0) { + HUD.notify("Synchronizing PacketFly.", 1000); + } else { + mc.player.connection.sendPacket(new CPacketConfirmTeleport(++trackingTPPacket)); + sendPosition(); + } + } else { + trackingTPPacket = 0; + } + } + + private void sendPosition() { + mc.player.connection.sendPacket(new CPacketPlayer.PositionRotation(mc.player.posX, mc.player.posY, mc.player.posZ, mc.player.rotationYaw, mc.player.rotationPitch, false)); } private void sendForce() { - mc.player.connection.sendPacket(new CPacketPlayer.Position(mc.player.posX, mc.player.posY - 1000, mc.player.posZ, mc.player.onGround)); + positions.add(mc.player.getPositionVector()); + mc.player.connection.sendPacket(new CPacketPlayer.Position(mc.player.posX + 1000, mc.player.posY + 1000, mc.player.posZ + 1000, false)); } @Listen public void onPacket(PacketEvent.Receive event) { - if(event.getPacket() instanceof SPacketPlayerPosLook) { + if(event.getPacket() instanceof SPacketPlayerPosLook && !notIngame()) { + SPacketPlayerPosLook pppl = ((SPacketPlayerPosLook) event.getPacket()); + BaseBand.LOGGER.info("Diff: " + (pppl.getY() - mc.player.posY)); if(!predict) { trackingTPPacket = -1; return; } - SPacketPlayerPosLook pppl = ((SPacketPlayerPosLook) event.getPacket()); - if(lastPacket != null && !(pppl.getX() != lastPacket.getX() || pppl.getY() != lastPacket.getY() || pppl.getZ() != lastPacket.getZ())) { + if(positions.isEmpty() || + (new Vec3d(pppl.getX(), pppl.getY(), pppl.getZ())) + .squareDistanceTo(positions.poll()) > 0.2) { ticksElapsed = -ServerDataManager.timeToSurelyTicked(); moving = false; trackingTPPacket = 0; + positions.clear(); + BaseBand.LOGGER.info("Invalid SPPPL. Resetting PacketFly."); return; } - lastPacket = pppl; if(trackingTPPacket == 0 || trackingTPPacket < pppl.getTeleportId()) { trackingTPPacket = pppl.getTeleportId(); } diff --git a/Client/src/main/java/de/com/baseband/client/mixin/MixinProxy.java b/Client/src/main/java/de/com/baseband/client/mixin/MixinProxy.java index af178f6..014c8a8 100644 --- a/Client/src/main/java/de/com/baseband/client/mixin/MixinProxy.java +++ b/Client/src/main/java/de/com/baseband/client/mixin/MixinProxy.java @@ -63,13 +63,25 @@ public class MixinProxy { } public static void onPacketReceive(Packet p_channelRead0_2_, CallbackInfo ci) { - if (BaseBand.publish(new PrePacketEvent.Receive(p_channelRead0_2_)).isCancelled() || BaseBand.publish(new PacketEvent.Receive(p_channelRead0_2_)).isCancelled()) + if (BaseBand.publish(new PrePacketEvent.Receive(p_channelRead0_2_)).isCancelled()) { ci.cancel(); + return; + } + if (BaseBand.publish(new PacketEvent.Receive(p_channelRead0_2_)).isCancelled()) { + ci.cancel(); + return; + } } public static void onPacketSend(Packet packetIn, CallbackInfo ci) { - if (BaseBand.publish(new PrePacketEvent.Send(packetIn)).isCancelled() || BaseBand.publish(new PacketEvent.Send(packetIn)).isCancelled()) + if (BaseBand.publish(new PrePacketEvent.Send(packetIn)).isCancelled()) { ci.cancel(); + return; + } + if (BaseBand.publish(new PacketEvent.Send(packetIn)).isCancelled()) { + ci.cancel(); + return; + } } public static void chatDrawRect(int left, int top, int right, int bottom, int color) { diff --git a/Client/src/main/java/de/com/baseband/client/registry/Configuration.java b/Client/src/main/java/de/com/baseband/client/registry/Configuration.java index 1c19ceb..39ed508 100644 --- a/Client/src/main/java/de/com/baseband/client/registry/Configuration.java +++ b/Client/src/main/java/de/com/baseband/client/registry/Configuration.java @@ -55,7 +55,8 @@ public class Configuration { Feature feature = Features.features[i]; wasEnabled[i] = feature.enabled; for (ConfigHandle handle : feature.ownedHandles.values()) { - handle.cloneFrom(fullDB.getSub(handle.getName())); + if(fullDB.getSub(handle.getName()) != null) + handle.cloneFrom(fullDB.getSub(handle.getName())); } } for (Updater updater : updaters) { @@ -67,6 +68,7 @@ public class Configuration { Features.features[i].toggle(); } } + if(fullDB.getSub("PlayerData") != null) PlayerDB.Data.cloneFrom(fullDB.getSub("PlayerData")); } diff --git a/Client/src/main/java/de/com/baseband/client/util/interact/ServerDataManager.java b/Client/src/main/java/de/com/baseband/client/util/interact/ServerDataManager.java index 3d7432b..654cd43 100644 --- a/Client/src/main/java/de/com/baseband/client/util/interact/ServerDataManager.java +++ b/Client/src/main/java/de/com/baseband/client/util/interact/ServerDataManager.java @@ -103,4 +103,8 @@ public class ServerDataManager { public static int timeToSurelyTicked() { return (int) Math.ceil(((20f / tps) + (getRealPing() / 100f)) * (Features.getFeature(Client.class).tickTimeConservative ? 4f : 3f)); } + + public static int asyncTimeToSurelyTicked() { + return (int) Math.ceil((20f / tps) * (Features.getFeature(Client.class).tickTimeConservative ? 2f : 1.1f)); + } }