From 0bac9201ac9139228e13f6147a1259d7d9383b45 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Sun, 8 Sep 2024 10:48:10 +0200 Subject: [PATCH] Don't remove configuration packet storage on login Needed with proxies if a server is doing nonstandard optimizations Fixes #881 --- .../rewriter/EntityPacketRewriter1_20_2.java | 2 +- .../storage/ConfigurationPacketStorage.java | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_2to1_20/rewriter/EntityPacketRewriter1_20_2.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_2to1_20/rewriter/EntityPacketRewriter1_20_2.java index d4445f65..15efccdd 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_2to1_20/rewriter/EntityPacketRewriter1_20_2.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_2to1_20/rewriter/EntityPacketRewriter1_20_2.java @@ -108,7 +108,7 @@ public final class EntityPacketRewriter1_20_2 extends EntityRewriter { - final ConfigurationPacketStorage configurationPacketStorage = wrapper.user().remove(ConfigurationPacketStorage.class); + final ConfigurationPacketStorage configurationPacketStorage = wrapper.user().get(ConfigurationPacketStorage.class); wrapper.passthrough(Types.INT); // Entity id wrapper.passthrough(Types.BOOLEAN); // Hardcore diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_2to1_20/storage/ConfigurationPacketStorage.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_2to1_20/storage/ConfigurationPacketStorage.java index a3952ac4..41cde0cf 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_2to1_20/storage/ConfigurationPacketStorage.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_2to1_20/storage/ConfigurationPacketStorage.java @@ -18,13 +18,13 @@ package com.viaversion.viabackwards.protocol.v1_20_2to1_20.storage; import com.google.common.base.Preconditions; +import com.viaversion.nbt.tag.CompoundTag; import com.viaversion.viabackwards.protocol.v1_20_2to1_20.Protocol1_20_2To1_20; import com.viaversion.viaversion.api.connection.StorableObject; import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.protocol.packet.PacketType; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.protocols.v1_19_3to1_19_4.packet.ClientboundPackets1_19_4; -import com.viaversion.nbt.tag.CompoundTag; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import java.util.ArrayList; @@ -77,17 +77,21 @@ public final class ConfigurationPacketStorage implements StorableObject { public void sendQueuedPackets(final UserConnection connection) { // Send resource pack at the end + List packets = rawPackets; if (resourcePack != null) { - rawPackets.add(resourcePack); + packets = new ArrayList<>(rawPackets); + packets.add(resourcePack); resourcePack = null; } - for (final QueuedPacket queuedPacket : rawPackets) { + for (final QueuedPacket queuedPacket : packets) { + // Don't clear the list or use the original buffer, we might need them later if a server skips subsequent config phases + final ByteBuf buf = queuedPacket.buf().copy(); try { - final PacketWrapper packet = PacketWrapper.create(queuedPacket.packetType(), queuedPacket.buf(), connection); + final PacketWrapper packet = PacketWrapper.create(queuedPacket.packetType(), buf, connection); packet.send(Protocol1_20_2To1_20.class); } finally { - queuedPacket.buf().release(); + buf.release(); } } }