Skip to content

Commit

Permalink
fixed nested usage of markReaderIndex+readerIndex
Browse files Browse the repository at this point in the history
  • Loading branch information
Fallen-Breath committed Mar 6, 2024
1 parent f3b15a6 commit 7525359
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/main/java/carpet/network/ProtocolFixer.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class ProtocolFixer
{
public static PacketBuffer fixCarpetPacket(PacketBuffer buf)
{
buf.markReaderIndex();
int prevReaderIndex = buf.readerIndex();
try
{
// try the old v1 protocol
Expand All @@ -35,7 +35,7 @@ public static PacketBuffer fixCarpetPacket(PacketBuffer buf)
}
finally
{
buf.resetReaderIndex();
buf.readerIndex(prevReaderIndex);
}

// try protocol v2 from fabric-carpet >= 1.4.114
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/carpet/utils/NetworkUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static NbtStyle guessNbtStyle(PacketBuffer buf)
{
int n = buf.readableBytes();

buf.markReaderIndex();
int prevReaderIndex = buf.readerIndex();
try
{
if (n < 2)
Expand Down Expand Up @@ -90,7 +90,7 @@ else if (0 <= bytes[0] && bytes[0] < 13)
}
finally
{
buf.resetReaderIndex();
buf.readerIndex(prevReaderIndex);
}

return NbtStyle.UNKNOWN;
Expand All @@ -111,12 +111,12 @@ public static NBTTagCompound readNbt(PacketBuffer buf)
{
// I'm < mc1.20.2 (OLD), trying to read a nbt in NEW style

buf.markReaderIndex();
int prevReaderIndex = buf.readerIndex();
PacketBuffer tweakedBuf = new PacketBuffer(Unpooled.buffer());
tweakedBuf.writeByte(buf.readByte()); // 0x0A, tag type
tweakedBuf.writeByte(0).writeByte(0); // 2* 0x00
tweakedBuf.writeBytes(buf);
buf.resetReaderIndex();
buf.readerIndex(prevReaderIndex);

NBTTagCompound nbt = tweakedBuf.readCompoundTag();

Expand Down

0 comments on commit 7525359

Please sign in to comment.