From 3498d093b0dabf51223d050e9acd12b8be2db494 Mon Sep 17 00:00:00 2001 From: Myles Date: Wed, 20 Apr 2016 01:22:58 +0100 Subject: [PATCH] Thanks @jollyolbrits for debugging, fix the issue with ground not being sent properly for movement. Fixes anti-cheat issues. Placement issues. Probably 100 billion other issues. Fix me being an idiot and changing numbers. --- .../protocol1_9to1_8/PlayerMovementMapper.java | 8 +++++++- .../protocol1_9to1_8/ViaIdleThread.java | 18 ++++++++++++++---- .../protocol1_9to1_8/packets/WorldPackets.java | 8 ++------ .../storage/MovementTracker.java | 4 ++++ 4 files changed, 27 insertions(+), 11 deletions(-) diff --git a/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/PlayerMovementMapper.java b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/PlayerMovementMapper.java index 2f5b4f1ad..dfc8c0d56 100644 --- a/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/PlayerMovementMapper.java +++ b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/PlayerMovementMapper.java @@ -3,6 +3,7 @@ package us.myles.ViaVersion.protocols.protocol1_9to1_8; import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.remapper.PacketHandler; import us.myles.ViaVersion.api.remapper.PacketRemapper; +import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.MovementTracker; public class PlayerMovementMapper extends PacketRemapper { @@ -11,7 +12,12 @@ public class PlayerMovementMapper extends PacketRemapper { handler(new PacketHandler() { @Override public void handle(PacketWrapper wrapper) throws Exception { - wrapper.user().get(MovementTracker.class).incrementIdlePacket(); + MovementTracker tracker = wrapper.user().get(MovementTracker.class); + tracker.incrementIdlePacket(); + // If packet has the ground data + if (wrapper.is(Type.BOOLEAN, 0)) { + tracker.setGround(wrapper.get(Type.BOOLEAN, 0)); + } } }); } diff --git a/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/ViaIdleThread.java b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/ViaIdleThread.java index 393b3d1d2..25b1dd7f6 100644 --- a/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/ViaIdleThread.java +++ b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/ViaIdleThread.java @@ -4,24 +4,31 @@ import io.netty.channel.ChannelHandlerContext; import org.bukkit.scheduler.BukkitRunnable; import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.protocols.base.ProtocolInfo; -import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8; import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.MovementTracker; import us.myles.ViaVersion.util.PipelineUtil; import us.myles.ViaVersion.util.ReflectionUtil; +import java.lang.reflect.Field; import java.util.Map; import java.util.UUID; public class ViaIdleThread extends BukkitRunnable { private final Map portedPlayers; private final Object idlePacket; + private final Object idlePacket2; public ViaIdleThread(Map portedPlayers) { this.portedPlayers = portedPlayers; try { Class idlePacketClass = ReflectionUtil.nms("PacketPlayInFlying"); idlePacket = idlePacketClass.newInstance(); - } catch (InstantiationException | IllegalArgumentException | IllegalAccessException | ClassNotFoundException e) { + idlePacket2 = idlePacketClass.newInstance(); + + Field flying = idlePacketClass.getDeclaredField("f"); + flying.setAccessible(true); + + flying.set(idlePacket2, true); + } catch (NoSuchFieldException | InstantiationException | IllegalArgumentException | IllegalAccessException | ClassNotFoundException e) { throw new RuntimeException("Couldn't find/make player idle packet, help!", e); } } @@ -35,8 +42,11 @@ public class ViaIdleThread extends BukkitRunnable { ChannelHandlerContext context = PipelineUtil.getContextBefore("decoder", info.getChannel().pipeline()); if (info.getChannel().isOpen()) { if (context != null) { - context.fireChannelRead(idlePacket); - + if (info.get(MovementTracker.class).isGround()) { + context.fireChannelRead(idlePacket2); + } else { + context.fireChannelRead(idlePacket); + } info.get(MovementTracker.class).incrementIdlePacket(); } } diff --git a/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/WorldPackets.java b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/WorldPackets.java index f2fcccc13..0b93dc7c0 100644 --- a/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/WorldPackets.java +++ b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/WorldPackets.java @@ -232,12 +232,8 @@ public class WorldPackets { @Override public void handle(PacketWrapper wrapper) throws Exception { int status = wrapper.get(Type.UNSIGNED_BYTE, 0); - if (status == 5) + if (status == 4) wrapper.cancel(); - if(status > 5){ - wrapper.set(Type.UNSIGNED_BYTE, 0, (short) (status - 1)); - } - System.out.println("SENDING ID: " + wrapper.get(Type.UNSIGNED_BYTE, 0)); } }); // Blocking @@ -245,7 +241,7 @@ public class WorldPackets { @Override public void handle(PacketWrapper wrapper) throws Exception { int status = wrapper.get(Type.UNSIGNED_BYTE, 0); - if (status == 5) { + if (status == 4) { EntityTracker entityTracker = wrapper.user().get(EntityTracker.class); if (entityTracker.isBlocking()) { entityTracker.setBlocking(false); diff --git a/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/storage/MovementTracker.java b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/storage/MovementTracker.java index 1bc0c548f..06217b7b4 100644 --- a/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/storage/MovementTracker.java +++ b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/storage/MovementTracker.java @@ -1,6 +1,7 @@ package us.myles.ViaVersion.protocols.protocol1_9to1_8.storage; import lombok.Getter; +import lombok.Setter; import us.myles.ViaVersion.api.data.StoredObject; import us.myles.ViaVersion.api.data.UserConnection; @@ -9,6 +10,9 @@ public class MovementTracker extends StoredObject { private static final long IDLE_PACKET_LIMIT = 20; // Max 20 ticks behind @Getter private long nextIdlePacket = 0L; + @Getter + @Setter + private boolean ground = true; public MovementTracker(UserConnection user) { super(user);