Skip to content

Commit

Permalink
Ensure input buffer isn't modified by VV
Browse files Browse the repository at this point in the history
  • Loading branch information
RaphiMC committed Sep 2, 2024
1 parent 4959d65 commit fb905a1
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/main/java/net/raphimc/vialegacy/api/util/PacketUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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();

Expand Down

0 comments on commit fb905a1

Please sign in to comment.