Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove nbt reading limit in registry-data packet for pre 1.20.5 #994

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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