some, probably incomplete, packetfly fixes
All checks were successful
/ Build BaseBand (push) Successful in 2m36s

This commit is contained in:
Daniella / Tove 2024-10-05 08:34:54 +02:00
parent 0921db6c28
commit 0e0d3a6283
Signed by: TudbuT
GPG key ID: B3CF345217F202D3
5 changed files with 90 additions and 37 deletions

View file

@ -63,17 +63,15 @@ public class Ping extends Feature {
if(holder == null || !holder.passed()) if(holder == null || !holder.passed())
break; break;
this.holderSend.remove(); this.holderSend.remove();
allowSend = holder.packet; mc.player.connection.sendPacket(allowSend = holder.packet);
mc.player.connection.sendPacket(allowSend);
} }
while (true) { while (true) {
PacketHolder holder = this.holderRecv.peek(); PacketHolder holder = this.holderRecv.peek();
if(holder == null || !holder.passed()) if(holder == null || !holder.passed())
break; break;
this.holderRecv.remove(); this.holderRecv.remove();
allowRecv = holder.packet;
try { try {
mc.player.connection.getNetworkManager().channelRead(null, allowRecv); mc.player.connection.getNetworkManager().channelRead(null, allowRecv = holder.packet);
} catch (Exception e) { } catch (Exception e) {
BaseBand.notifyAll("!! BaseBand encountered a BUG. Please report as soon as possible and include the game log."); 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(); new RuntimeException("[BaseBand BUG] Cannot emulate packet read", e).printStackTrace();
@ -106,7 +104,7 @@ public class Ping extends Feature {
@Listen @Listen
public void onPacket(PrePacketEvent.Send e) { public void onPacket(PrePacketEvent.Send e) {
if(allowSend == e.getPacket() || notIngame()) if(allowSend == e.getPacket() || notIngame() || mc.player.ticksExisted < 20)
return; return;
if (e.getPacket() instanceof CPacketKeepAlive || holdAll) { if (e.getPacket() instanceof CPacketKeepAlive || holdAll) {
totalSent++; totalSent++;
@ -117,7 +115,7 @@ public class Ping extends Feature {
@Listen @Listen
public void onPacket(PrePacketEvent.Receive e) { public void onPacket(PrePacketEvent.Receive e) {
if(allowRecv == e.getPacket() || notIngame()) if(allowRecv == e.getPacket() || notIngame() || mc.player.ticksExisted < 20)
return; return;
if (e.getPacket() instanceof SPacketKeepAlive || holdAll) { if (e.getPacket() instanceof SPacketKeepAlive || holdAll) {
totalRecieved++; totalRecieved++;

View file

@ -1,5 +1,6 @@
package de.com.baseband.client.feature.modules.movement; 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.Listen;
import de.com.baseband.client.event.events.MoveEvent; import de.com.baseband.client.event.events.MoveEvent;
import de.com.baseband.client.event.events.PacketEvent; 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.CPacketConfirmTeleport;
import net.minecraft.network.play.client.CPacketPlayer; import net.minecraft.network.play.client.CPacketPlayer;
import net.minecraft.network.play.server.SPacketPlayerPosLook; import net.minecraft.network.play.server.SPacketPlayerPosLook;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec2f; import net.minecraft.util.math.Vec2f;
import net.minecraft.util.math.Vec3d;
import java.util.LinkedList;
import java.util.Queue;
@Experimental @Experimental
public class PacketFly extends Feature { 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.") @Description("Tries to avoid the automatic flight kick mechanism in vanilla.")
public boolean noFlyKick = true; public boolean noFlyKick = true;
@Config("Use conservative constant")
public boolean conservative = false;
private int ticksElapsed = 0; private int ticksElapsed = 0;
private int trackingTPPacket = 0; private int trackingTPPacket = 0;
private boolean moving = false; private boolean moving = false;
private SPacketPlayerPosLook lastPacket = null; private int ticksSinceMovement = 0;
private long time = 0; private long time = 0;
private long verticalTimeout = 0;
private final Queue<Vec3d> positions = new LinkedList<>();
public void onDisable() { public void onDisable() {
moving = false; moving = false;
trackingTPPacket = 0; trackingTPPacket = 0;
positions.clear();
} }
@Override @Override
@ -60,8 +72,13 @@ public class PacketFly extends Feature {
if(meta.isEmpty()) if(meta.isEmpty())
meta = null; meta = null;
time++; ticksSinceMovement++;
if(moving)
ticksSinceMovement = 0;
ticksElapsed++; ticksElapsed++;
mc.world.spawnParticle(EnumParticleTypes.FLAME, mc.player.posX, mc.player.posY + 1, mc.player.posZ, 0.1, 0.1, 0.1);
} }
@Listen @Listen
@ -75,6 +92,8 @@ public class PacketFly extends Feature {
return; return;
} }
time++;
if(mc.getRenderViewEntity() == mc.player) { if(mc.getRenderViewEntity() == mc.player) {
Vec2f movementVec = mc.player.movementInput.getMoveVector(); Vec2f movementVec = mc.player.movementInput.getMoveVector();
float f1 = MathHelper.sin(mc.player.rotationYaw * 0.017453292F); 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 x = movementVec.x * f2 - movementVec.y * f1;
double y = (mc.player.movementInput.jump ? 1 : 0) + (mc.player.movementInput.sneak ? -1 : 0); double y = (mc.player.movementInput.jump ? 1 : 0) + (mc.player.movementInput.sneak ? -1 : 0);
double z = movementVec.y * f2 + movementVec.x * f1; 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(d == 0) {
if(moving) { if(moving) {
sendPosition(0); moving = false;
}
if(ticksSinceMovement > 10) {
sendPosition();
sendForce(); sendForce();
trackingTPPacket = 0; trackingTPPacket = 0;
lastPacket = null; positions.clear();
moving = false;
} }
return; return;
} }
@ -103,50 +134,56 @@ public class PacketFly extends Feature {
mc.player.posY += y; mc.player.posY += y;
mc.player.posZ += z; mc.player.posZ += z;
double yOffset = (time % 30 == 0 ? -0.05 : 0); sendPositionFull();
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;
}
moving = true; moving = true;
ticksElapsed = 0; ticksElapsed = 0;
} }
} }
private void sendPosition(double yOffset) { private void sendPositionFull() {
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)); 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() { 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 @Listen
public void onPacket(PacketEvent.Receive event) { 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) { if(!predict) {
trackingTPPacket = -1; trackingTPPacket = -1;
return; return;
} }
SPacketPlayerPosLook pppl = ((SPacketPlayerPosLook) event.getPacket()); if(positions.isEmpty() ||
if(lastPacket != null && !(pppl.getX() != lastPacket.getX() || pppl.getY() != lastPacket.getY() || pppl.getZ() != lastPacket.getZ())) { (new Vec3d(pppl.getX(), pppl.getY(), pppl.getZ()))
.squareDistanceTo(positions.poll()) > 0.2) {
ticksElapsed = -ServerDataManager.timeToSurelyTicked(); ticksElapsed = -ServerDataManager.timeToSurelyTicked();
moving = false; moving = false;
trackingTPPacket = 0; trackingTPPacket = 0;
positions.clear();
BaseBand.LOGGER.info("Invalid SPPPL. Resetting PacketFly.");
return; return;
} }
lastPacket = pppl;
if(trackingTPPacket == 0 || trackingTPPacket < pppl.getTeleportId()) { if(trackingTPPacket == 0 || trackingTPPacket < pppl.getTeleportId()) {
trackingTPPacket = pppl.getTeleportId(); trackingTPPacket = pppl.getTeleportId();
} }

View file

@ -63,13 +63,25 @@ public class MixinProxy {
} }
public static void onPacketReceive(Packet<?> p_channelRead0_2_, CallbackInfo ci) { 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(); ci.cancel();
return;
}
if (BaseBand.publish(new PacketEvent.Receive(p_channelRead0_2_)).isCancelled()) {
ci.cancel();
return;
}
} }
public static void onPacketSend(Packet<?> packetIn, CallbackInfo ci) { 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(); 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) { public static void chatDrawRect(int left, int top, int right, int bottom, int color) {

View file

@ -55,6 +55,7 @@ public class Configuration {
Feature feature = Features.features[i]; Feature feature = Features.features[i];
wasEnabled[i] = feature.enabled; wasEnabled[i] = feature.enabled;
for (ConfigHandle handle : feature.ownedHandles.values()) { for (ConfigHandle handle : feature.ownedHandles.values()) {
if(fullDB.getSub(handle.getName()) != null)
handle.cloneFrom(fullDB.getSub(handle.getName())); handle.cloneFrom(fullDB.getSub(handle.getName()));
} }
} }
@ -67,6 +68,7 @@ public class Configuration {
Features.features[i].toggle(); Features.features[i].toggle();
} }
} }
if(fullDB.getSub("PlayerData") != null)
PlayerDB.Data.cloneFrom(fullDB.getSub("PlayerData")); PlayerDB.Data.cloneFrom(fullDB.getSub("PlayerData"));
} }

View file

@ -103,4 +103,8 @@ public class ServerDataManager {
public static int timeToSurelyTicked() { public static int timeToSurelyTicked() {
return (int) Math.ceil(((20f / tps) + (getRealPing() / 100f)) * (Features.getFeature(Client.class).tickTimeConservative ? 4f : 3f)); 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));
}
} }