From 752535990afcbf0dab24b8fed220ab504d897393 Mon Sep 17 00:00:00 2001 From: Fallen_Breath Date: Thu, 7 Mar 2024 03:03:45 +0800 Subject: [PATCH] fixed nested usage of markReaderIndex+readerIndex --- src/main/java/carpet/network/ProtocolFixer.java | 4 ++-- src/main/java/carpet/utils/NetworkUtil.java | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/carpet/network/ProtocolFixer.java b/src/main/java/carpet/network/ProtocolFixer.java index 71252297..a84681c3 100644 --- a/src/main/java/carpet/network/ProtocolFixer.java +++ b/src/main/java/carpet/network/ProtocolFixer.java @@ -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 @@ -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 diff --git a/src/main/java/carpet/utils/NetworkUtil.java b/src/main/java/carpet/utils/NetworkUtil.java index f9f39895..3d926a50 100644 --- a/src/main/java/carpet/utils/NetworkUtil.java +++ b/src/main/java/carpet/utils/NetworkUtil.java @@ -48,7 +48,7 @@ public static NbtStyle guessNbtStyle(PacketBuffer buf) { int n = buf.readableBytes(); - buf.markReaderIndex(); + int prevReaderIndex = buf.readerIndex(); try { if (n < 2) @@ -90,7 +90,7 @@ else if (0 <= bytes[0] && bytes[0] < 13) } finally { - buf.resetReaderIndex(); + buf.readerIndex(prevReaderIndex); } return NbtStyle.UNKNOWN; @@ -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();