Skip to content

Commit

Permalink
Merge pull request #994 from booky10/fix/pre-1.20.5-registry-data-limit
Browse files Browse the repository at this point in the history
Remove nbt reading limit in registry-data packet for pre 1.20.5
  • Loading branch information
retrooper authored Sep 17, 2024
2 parents 99acbe4 + 402ebd7 commit a1663f5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
}
Expand Down

0 comments on commit a1663f5

Please sign in to comment.