Ensure input buffer isn't modified by VV

This commit is contained in:
RaphiMC 2024-09-02 23:08:39 +02:00
parent 4959d65984
commit fb905a1514
No known key found for this signature in database
GPG Key ID: 0F6BB0657A03AC94

View File

@ -19,6 +19,7 @@ package net.raphimc.vialegacy.api.util;
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 class PacketUtil {
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();