From 402ebd729eee71ea0ba98c535617ac4521021ea3 Mon Sep 17 00:00:00 2001 From: booky10 Date: Tue, 17 Sep 2024 16:21:38 +0200 Subject: [PATCH] Remove nbt reading limit in registry-data packet for pre 1.20.5 --- .../packetevents/protocol/nbt/codec/NBTCodec.java | 4 ++++ .../retrooper/packetevents/wrapper/PacketWrapper.java | 9 +++++++++ .../server/WrapperConfigServerRegistryData.java | 6 +++--- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/api/src/main/java/com/github/retrooper/packetevents/protocol/nbt/codec/NBTCodec.java b/api/src/main/java/com/github/retrooper/packetevents/protocol/nbt/codec/NBTCodec.java index 3824ab2736..190f02419c 100644 --- a/api/src/main/java/com/github/retrooper/packetevents/protocol/nbt/codec/NBTCodec.java +++ b/api/src/main/java/com/github/retrooper/packetevents/protocol/nbt/codec/NBTCodec.java @@ -151,6 +151,10 @@ else if (nbt instanceof NBTCompound) { public static NBT readNBTFromBuffer(Object byteBuf, ServerVersion serverVersion) { NBTLimiter limiter = NBTLimiter.forBuffer(byteBuf); + return readNBTFromBuffer(byteBuf, serverVersion, limiter); + } + + public static NBT readNBTFromBuffer(Object byteBuf, ServerVersion serverVersion, NBTLimiter limiter) { if (serverVersion.isNewerThanOrEquals(ServerVersion.V_1_8)) { try { final boolean named = serverVersion.isOlderThan(ServerVersion.V_1_20_2); diff --git a/api/src/main/java/com/github/retrooper/packetevents/wrapper/PacketWrapper.java b/api/src/main/java/com/github/retrooper/packetevents/wrapper/PacketWrapper.java index 2a843f5f14..236e38371d 100644 --- a/api/src/main/java/com/github/retrooper/packetevents/wrapper/PacketWrapper.java +++ b/api/src/main/java/com/github/retrooper/packetevents/wrapper/PacketWrapper.java @@ -76,6 +76,7 @@ import com.github.retrooper.packetevents.protocol.mapper.MappedEntity; import com.github.retrooper.packetevents.protocol.nbt.NBT; import com.github.retrooper.packetevents.protocol.nbt.NBTCompound; +import com.github.retrooper.packetevents.protocol.nbt.NBTLimiter; import com.github.retrooper.packetevents.protocol.nbt.codec.NBTCodec; import com.github.retrooper.packetevents.protocol.packettype.PacketType; import com.github.retrooper.packetevents.protocol.packettype.PacketTypeCommon; @@ -613,6 +614,14 @@ public NBT readNBTRaw() { return NBTCodec.readNBTFromBuffer(buffer, serverVersion); } + public NBTCompound readUnlimitedNBT() { + return (NBTCompound) this.readUnlimitedNBTRaw(); + } + + public NBT readUnlimitedNBTRaw() { + return NBTCodec.readNBTFromBuffer(buffer, serverVersion, NBTLimiter.noop()); + } + public void writeNBT(NBTCompound nbt) { this.writeNBTRaw(nbt); } diff --git a/api/src/main/java/com/github/retrooper/packetevents/wrapper/configuration/server/WrapperConfigServerRegistryData.java b/api/src/main/java/com/github/retrooper/packetevents/wrapper/configuration/server/WrapperConfigServerRegistryData.java index 819e30bfa4..34e4cce96d 100644 --- a/api/src/main/java/com/github/retrooper/packetevents/wrapper/configuration/server/WrapperConfigServerRegistryData.java +++ b/api/src/main/java/com/github/retrooper/packetevents/wrapper/configuration/server/WrapperConfigServerRegistryData.java @@ -75,8 +75,8 @@ public WrapperConfigServerRegistryData( @Override public void read() { - if (!this.serverVersion.isNewerThanOrEquals(ServerVersion.V_1_20_5)) { - this.registryData = this.readNBT(); + if (this.serverVersion.isOlderThan(ServerVersion.V_1_20_5)) { + this.registryData = this.readUnlimitedNBT(); return; } this.registryKey = this.readIdentifier(); @@ -89,7 +89,7 @@ public void read() { @Override public void write() { - if (!this.serverVersion.isNewerThanOrEquals(ServerVersion.V_1_20_5)) { + if (this.serverVersion.isOlderThan(ServerVersion.V_1_20_5)) { this.writeNBT(this.registryData); return; }