From fb905a15144dbef4e38af33a0ef128f8e5d13afd Mon Sep 17 00:00:00 2001 From: RaphiMC <50594595+RaphiMC@users.noreply.github.com> Date: Mon, 2 Sep 2024 23:08:39 +0200 Subject: [PATCH] Ensure input buffer isn't modified by VV --- .../java/net/raphimc/vialegacy/api/util/PacketUtil.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/net/raphimc/vialegacy/api/util/PacketUtil.java b/src/main/java/net/raphimc/vialegacy/api/util/PacketUtil.java index 90923a9..c856b3e 100644 --- a/src/main/java/net/raphimc/vialegacy/api/util/PacketUtil.java +++ b/src/main/java/net/raphimc/vialegacy/api/util/PacketUtil.java @@ -19,6 +19,7 @@ import com.viaversion.viaversion.api.protocol.packet.PacketType; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; +import com.viaversion.viaversion.protocol.packet.PacketWrapperImpl; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; @@ -29,7 +30,13 @@ public static int calculateLength(final PacketWrapper wrapper) { wrapper.setPacketType(null); final ByteBuf lengthBuffer = Unpooled.buffer(); + if (wrapper instanceof PacketWrapperImpl impl && impl.getInputBuffer() != null) { + impl.getInputBuffer().markReaderIndex(); + } wrapper.writeToBuffer(lengthBuffer); + if (wrapper instanceof PacketWrapperImpl impl && impl.getInputBuffer() != null) { + impl.getInputBuffer().resetReaderIndex(); + } final int length = lengthBuffer.readableBytes(); lengthBuffer.release();