From f4b47025e62ee8dd0fde0d99dc21a72659dec327 Mon Sep 17 00:00:00 2001 From: Marc Hermans Date: Mon, 13 Nov 2023 20:49:26 +0100 Subject: [PATCH] Add the unversioned patches. --- .../CommonListenerCookie.java.patch | 10 ++ .../network/ConnectionProtocol.java.patch | 135 ++++++++++++++++++ .../network/PacketDecoder.java.patch | 11 ++ .../ClientCommonPacketListener.java.patch | 11 ++ .../ServerCommonPacketListener.java.patch | 11 ++ ...rverConfigurationPacketListener.java.patch | 11 ++ .../network/CommonListenerCookie.java.patch | 13 ++ .../network/ConfigurationTask.java.patch | 21 +++ ...ConfigurationPacketListenerImpl.java.patch | 133 +++++++++++++++++ 9 files changed, 356 insertions(+) create mode 100644 patches/net/minecraft/client/multiplayer/CommonListenerCookie.java.patch create mode 100644 patches/net/minecraft/network/ConnectionProtocol.java.patch create mode 100644 patches/net/minecraft/network/PacketDecoder.java.patch create mode 100644 patches/net/minecraft/network/protocol/common/ClientCommonPacketListener.java.patch create mode 100644 patches/net/minecraft/network/protocol/common/ServerCommonPacketListener.java.patch create mode 100644 patches/net/minecraft/network/protocol/configuration/ServerConfigurationPacketListener.java.patch create mode 100644 patches/net/minecraft/server/network/CommonListenerCookie.java.patch create mode 100644 patches/net/minecraft/server/network/ConfigurationTask.java.patch create mode 100644 patches/net/minecraft/server/network/ServerConfigurationPacketListenerImpl.java.patch diff --git a/patches/net/minecraft/client/multiplayer/CommonListenerCookie.java.patch b/patches/net/minecraft/client/multiplayer/CommonListenerCookie.java.patch new file mode 100644 index 00000000000..4544bef0f23 --- /dev/null +++ b/patches/net/minecraft/client/multiplayer/CommonListenerCookie.java.patch @@ -0,0 +1,10 @@ +--- a/net/minecraft/client/multiplayer/CommonListenerCookie.java ++++ b/net/minecraft/client/multiplayer/CommonListenerCookie.java +@@ -15,6 +15,7 @@ + WorldSessionTelemetryManager telemetryManager, + RegistryAccess.Frozen receivedRegistries, + FeatureFlagSet enabledFeatures, ++ boolean isModdedConnection, + @Nullable String serverBrand, + @Nullable ServerData serverData, + @Nullable Screen postDisconnectScreen diff --git a/patches/net/minecraft/network/ConnectionProtocol.java.patch b/patches/net/minecraft/network/ConnectionProtocol.java.patch new file mode 100644 index 00000000000..c043b83e172 --- /dev/null +++ b/patches/net/minecraft/network/ConnectionProtocol.java.patch @@ -0,0 +1,135 @@ +--- a/net/minecraft/network/ConnectionProtocol.java ++++ b/net/minecraft/network/ConnectionProtocol.java +@@ -3,6 +3,7 @@ + import com.google.common.collect.Lists; + import com.google.common.collect.Maps; + import com.mojang.logging.LogUtils; ++import io.netty.channel.ChannelHandlerContext; + import it.unimi.dsi.fastutil.ints.Int2ObjectMap; + import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; + import it.unimi.dsi.fastutil.objects.Object2IntMap; +@@ -12,6 +13,7 @@ + import java.util.List; + import java.util.Map; + import java.util.Set; ++import java.util.function.BiFunction; + import java.util.function.Function; + import javax.annotation.Nullable; + import net.minecraft.Util; +@@ -238,7 +240,7 @@ + .addPacket(ClientboundContainerSetSlotPacket.class, ClientboundContainerSetSlotPacket::new) + .addPacket(ClientboundCooldownPacket.class, ClientboundCooldownPacket::new) + .addPacket(ClientboundCustomChatCompletionsPacket.class, ClientboundCustomChatCompletionsPacket::new) +- .addPacket(ClientboundCustomPayloadPacket.class, ClientboundCustomPayloadPacket::new) ++ .addContextualPacket(ClientboundCustomPayloadPacket.class, (buf, context) -> new ClientboundCustomPayloadPacket(buf, context, ConnectionProtocol.play())) + .addPacket(ClientboundDamageEventPacket.class, ClientboundDamageEventPacket::new) + .addPacket(ClientboundDeleteChatPacket.class, ClientboundDeleteChatPacket::new) + .addPacket(ClientboundDisconnectPacket.class, ClientboundDisconnectPacket::new) +@@ -346,7 +348,7 @@ + .addPacket(ServerboundContainerButtonClickPacket.class, ServerboundContainerButtonClickPacket::new) + .addPacket(ServerboundContainerClickPacket.class, ServerboundContainerClickPacket::new) + .addPacket(ServerboundContainerClosePacket.class, ServerboundContainerClosePacket::new) +- .addPacket(ServerboundCustomPayloadPacket.class, ServerboundCustomPayloadPacket::new) ++ .addContextualPacket(ServerboundCustomPayloadPacket.class, (buf, context) -> new ServerboundCustomPayloadPacket(buf, context, ConnectionProtocol.play())) + .addPacket(ServerboundEditBookPacket.class, ServerboundEditBookPacket::new) + .addPacket(ServerboundEntityTagQuery.class, ServerboundEntityTagQuery::new) + .addPacket(ServerboundInteractPacket.class, ServerboundInteractPacket::new) +@@ -430,7 +432,7 @@ + .addFlow( + PacketFlow.CLIENTBOUND, + new ConnectionProtocol.PacketSet() +- .addPacket(ClientboundCustomPayloadPacket.class, ClientboundCustomPayloadPacket::new) ++ .addContextualPacket(ClientboundCustomPayloadPacket.class, (buf, context) -> new ClientboundCustomPayloadPacket(buf, context, ConnectionProtocol.configuration())) + .addPacket(ClientboundDisconnectPacket.class, ClientboundDisconnectPacket::new) + .addPacket(ClientboundFinishConfigurationPacket.class, ClientboundFinishConfigurationPacket::new) + .addPacket(ClientboundKeepAlivePacket.class, ClientboundKeepAlivePacket::new) +@@ -444,7 +446,7 @@ + PacketFlow.SERVERBOUND, + new ConnectionProtocol.PacketSet() + .addPacket(ServerboundClientInformationPacket.class, ServerboundClientInformationPacket::new) +- .addPacket(ServerboundCustomPayloadPacket.class, ServerboundCustomPayloadPacket::new) ++ .addContextualPacket(ServerboundCustomPayloadPacket.class, (buf, context) -> new ServerboundCustomPayloadPacket(buf, context, ConnectionProtocol.play())) + .addPacket(ServerboundFinishConfigurationPacket.class, ServerboundFinishConfigurationPacket::new) + .addPacket(ServerboundKeepAlivePacket.class, ServerboundKeepAlivePacket::new) + .addPacket(ServerboundPongPacket.class, ServerboundPongPacket::new) +@@ -456,6 +458,22 @@ + private final String id; + private final Map> flows; + ++ private static ConnectionProtocol play() { ++ return PLAY; ++ } ++ ++ private static ConnectionProtocol configuration() { ++ return CONFIGURATION; ++ } ++ ++ public boolean isPlay() { ++ return this == PLAY; ++ } ++ ++ public boolean isConfiguration() { ++ return this == CONFIGURATION; ++ } ++ + private static ConnectionProtocol.ProtocolBuilder protocol() { + return new ConnectionProtocol.ProtocolBuilder(); + } +@@ -514,8 +532,8 @@ + } + + @Nullable +- public Packet createPacket(int p_294972_, FriendlyByteBuf p_296217_) { +- return this.packetSet.createPacket(p_294972_, p_296217_); ++ public Packet createPacket(int p_294972_, FriendlyByteBuf p_296217_, ChannelHandlerContext p_130535_) { ++ return this.packetSet.createPacket(p_294972_, p_296217_, p_130535_); + } + + public boolean isValidPacketType(Packet p_294142_) { +@@ -528,19 +546,28 @@ + final Object2IntMap>> classToId = Util.make( + new Object2IntOpenHashMap<>(), p_129613_ -> p_129613_.defaultReturnValue(-1) + ); ++ /** ++ * @deprecated Use {@link #contextualIdToDeserializer} instead it allows for context to be passed to the deserializer ++ */ ++ @Deprecated + private final List>> idToDeserializer = Lists.newArrayList(); ++ private final List>> contextualIdToDeserializer = Lists.newArrayList(); + private BundlerInfo bundlerInfo = BundlerInfo.EMPTY; + private final Set>> extraClasses = new HashSet<>(); +- ++ + public

> ConnectionProtocol.PacketSet addPacket(Class

p_178331_, Function p_178332_) { +- int i = this.idToDeserializer.size(); +- int j = this.classToId.put(p_178331_, i); ++ return addContextualPacket(p_178331_, (buf, channelHandlerContext) -> p_178332_.apply(buf)); ++ } ++ ++ public

> ConnectionProtocol.PacketSet addContextualPacket(Class

packetClass, BiFunction readerBuilder) { ++ int i = this.contextualIdToDeserializer.size(); ++ int j = this.classToId.put(packetClass, i); + if (j != -1) { +- String s = "Packet " + p_178331_ + " is already registered to ID " + j; ++ String s = "Packet " + packetClass + " is already registered to ID " + j; + LOGGER.error(LogUtils.FATAL_MARKER, s); + throw new IllegalArgumentException(s); + } else { +- this.idToDeserializer.add(p_178332_); ++ this.contextualIdToDeserializer.add(readerBuilder); + return this; + } + } +@@ -566,9 +593,9 @@ + } + + @Nullable +- public Packet createPacket(int p_178328_, FriendlyByteBuf p_178329_) { +- Function> function = this.idToDeserializer.get(p_178328_); +- return function != null ? function.apply(p_178329_) : null; ++ public Packet createPacket(int p_178328_, FriendlyByteBuf p_178329_, ChannelHandlerContext p_130535_) { ++ BiFunction> function = this.contextualIdToDeserializer.get(p_178328_); ++ return function != null ? function.apply(p_178329_, p_130535_) : null; + } + + public BundlerInfo bundlerInfo() { diff --git a/patches/net/minecraft/network/PacketDecoder.java.patch b/patches/net/minecraft/network/PacketDecoder.java.patch new file mode 100644 index 00000000000..f7f3560f552 --- /dev/null +++ b/patches/net/minecraft/network/PacketDecoder.java.patch @@ -0,0 +1,11 @@ +--- a/net/minecraft/network/PacketDecoder.java ++++ b/net/minecraft/network/PacketDecoder.java +@@ -28,7 +28,7 @@ + ConnectionProtocol.CodecData codecdata = attribute.get(); + FriendlyByteBuf friendlybytebuf = new FriendlyByteBuf(p_130536_); + int j = friendlybytebuf.readVarInt(); +- Packet packet = codecdata.createPacket(j, friendlybytebuf); ++ Packet packet = codecdata.createPacket(j, friendlybytebuf, p_130535_); + if (packet == null) { + throw new IOException("Bad packet id " + j); + } else { diff --git a/patches/net/minecraft/network/protocol/common/ClientCommonPacketListener.java.patch b/patches/net/minecraft/network/protocol/common/ClientCommonPacketListener.java.patch new file mode 100644 index 00000000000..5de794cfb63 --- /dev/null +++ b/patches/net/minecraft/network/protocol/common/ClientCommonPacketListener.java.patch @@ -0,0 +1,11 @@ +--- a/net/minecraft/network/protocol/common/ClientCommonPacketListener.java ++++ b/net/minecraft/network/protocol/common/ClientCommonPacketListener.java +@@ -2,7 +2,7 @@ + + import net.minecraft.network.ClientboundPacketListener; + +-public interface ClientCommonPacketListener extends ClientboundPacketListener { ++public interface ClientCommonPacketListener extends ClientboundPacketListener, net.neoforged.neoforge.common.extensions.IClientCommonPacketListenerExtension { + void handleKeepAlive(ClientboundKeepAlivePacket p_295236_); + + void handlePing(ClientboundPingPacket p_296451_); diff --git a/patches/net/minecraft/network/protocol/common/ServerCommonPacketListener.java.patch b/patches/net/minecraft/network/protocol/common/ServerCommonPacketListener.java.patch new file mode 100644 index 00000000000..00d2c8e633e --- /dev/null +++ b/patches/net/minecraft/network/protocol/common/ServerCommonPacketListener.java.patch @@ -0,0 +1,11 @@ +--- a/net/minecraft/network/protocol/common/ServerCommonPacketListener.java ++++ b/net/minecraft/network/protocol/common/ServerCommonPacketListener.java +@@ -2,7 +2,7 @@ + + import net.minecraft.network.protocol.game.ServerPacketListener; + +-public interface ServerCommonPacketListener extends ServerPacketListener { ++public interface ServerCommonPacketListener extends ServerPacketListener, net.neoforged.neoforge.common.extensions.IClientboundPacketSenderExtension { + void handleKeepAlive(ServerboundKeepAlivePacket p_296457_); + + void handlePong(ServerboundPongPacket p_294309_); diff --git a/patches/net/minecraft/network/protocol/configuration/ServerConfigurationPacketListener.java.patch b/patches/net/minecraft/network/protocol/configuration/ServerConfigurationPacketListener.java.patch new file mode 100644 index 00000000000..f7ba82063a9 --- /dev/null +++ b/patches/net/minecraft/network/protocol/configuration/ServerConfigurationPacketListener.java.patch @@ -0,0 +1,11 @@ +--- a/net/minecraft/network/protocol/configuration/ServerConfigurationPacketListener.java ++++ b/net/minecraft/network/protocol/configuration/ServerConfigurationPacketListener.java +@@ -3,7 +3,7 @@ + import net.minecraft.network.ConnectionProtocol; + import net.minecraft.network.protocol.common.ServerCommonPacketListener; + +-public interface ServerConfigurationPacketListener extends ServerCommonPacketListener { ++public interface ServerConfigurationPacketListener extends ServerCommonPacketListener, net.neoforged.neoforge.common.extensions.IServerConfigurationPacketListenerExtension { + @Override + default ConnectionProtocol protocol() { + return ConnectionProtocol.CONFIGURATION; diff --git a/patches/net/minecraft/server/network/CommonListenerCookie.java.patch b/patches/net/minecraft/server/network/CommonListenerCookie.java.patch new file mode 100644 index 00000000000..b17726ed2b3 --- /dev/null +++ b/patches/net/minecraft/server/network/CommonListenerCookie.java.patch @@ -0,0 +1,13 @@ +--- a/net/minecraft/server/network/CommonListenerCookie.java ++++ b/net/minecraft/server/network/CommonListenerCookie.java +@@ -3,8 +3,8 @@ + import com.mojang.authlib.GameProfile; + import net.minecraft.server.level.ClientInformation; + +-public record CommonListenerCookie(GameProfile gameProfile, int latency, ClientInformation clientInformation) { ++public record CommonListenerCookie(GameProfile gameProfile, int latency, ClientInformation clientInformation, boolean isModdedConnection) { + public static CommonListenerCookie createInitial(GameProfile p_302024_) { +- return new CommonListenerCookie(p_302024_, 0, ClientInformation.createDefault()); ++ return new CommonListenerCookie(p_302024_, 0, ClientInformation.createDefault(), false); + } + } diff --git a/patches/net/minecraft/server/network/ConfigurationTask.java.patch b/patches/net/minecraft/server/network/ConfigurationTask.java.patch new file mode 100644 index 00000000000..c1370f21d9b --- /dev/null +++ b/patches/net/minecraft/server/network/ConfigurationTask.java.patch @@ -0,0 +1,21 @@ +--- a/net/minecraft/server/network/ConfigurationTask.java ++++ b/net/minecraft/server/network/ConfigurationTask.java +@@ -2,6 +2,7 @@ + + import java.util.function.Consumer; + import net.minecraft.network.protocol.Packet; ++import net.minecraft.resources.ResourceLocation; + + public interface ConfigurationTask { + void start(Consumer> p_294184_); +@@ -9,6 +10,10 @@ + ConfigurationTask.Type type(); + + public static record Type(String id) { ++ public Type(ResourceLocation location) { ++ this(location.toString()); ++ } ++ + @Override + public String toString() { + return this.id; diff --git a/patches/net/minecraft/server/network/ServerConfigurationPacketListenerImpl.java.patch b/patches/net/minecraft/server/network/ServerConfigurationPacketListenerImpl.java.patch new file mode 100644 index 00000000000..2fcf4f2768b --- /dev/null +++ b/patches/net/minecraft/server/network/ServerConfigurationPacketListenerImpl.java.patch @@ -0,0 +1,133 @@ +--- a/net/minecraft/server/network/ServerConfigurationPacketListenerImpl.java ++++ b/net/minecraft/server/network/ServerConfigurationPacketListenerImpl.java +@@ -12,11 +12,7 @@ + import net.minecraft.network.TickablePacketListener; + import net.minecraft.network.chat.Component; + import net.minecraft.network.protocol.PacketUtils; +-import net.minecraft.network.protocol.common.ClientboundCustomPayloadPacket; +-import net.minecraft.network.protocol.common.ClientboundDisconnectPacket; +-import net.minecraft.network.protocol.common.ClientboundUpdateTagsPacket; +-import net.minecraft.network.protocol.common.ServerboundClientInformationPacket; +-import net.minecraft.network.protocol.common.ServerboundResourcePackPacket; ++import net.minecraft.network.protocol.common.*; + import net.minecraft.network.protocol.common.custom.BrandPayload; + import net.minecraft.network.protocol.configuration.ClientboundRegistryDataPacket; + import net.minecraft.network.protocol.configuration.ClientboundUpdateEnabledFeaturesPacket; +@@ -31,6 +27,8 @@ + import net.minecraft.server.players.PlayerList; + import net.minecraft.tags.TagNetworkSerialization; + import net.minecraft.world.flag.FeatureFlags; ++import net.neoforged.neoforge.network.payload.ModdedNetworkQueryPayload; ++import net.neoforged.neoforge.network.registration.NetworkRegistry; + import org.slf4j.Logger; + + public class ServerConfigurationPacketListenerImpl extends ServerCommonPacketListenerImpl implements TickablePacketListener, ServerConfigurationPacketListener { +@@ -41,6 +39,8 @@ + @Nullable + private ConfigurationTask currentTask; + private ClientInformation clientInformation; ++ private boolean isModdedConnection = false; ++ private boolean isHandlingModdedConfigurationPhase = false; + + public ServerConfigurationPacketListenerImpl(MinecraftServer p_294645_, Connection p_295787_, CommonListenerCookie p_302003_) { + super(p_294645_, p_295787_, p_302003_); +@@ -65,6 +65,11 @@ + } + + public void startConfiguration() { ++ this.send(new ModdedNetworkQueryPayload()); ++ this.send(new ClientboundPingPacket(0)); ++ } ++ ++ private void runConfiguration() { + this.send(new ClientboundCustomPayloadPacket(new BrandPayload(this.server.getServerModName()))); + LayeredRegistryAccess layeredregistryaccess = this.server.registries(); + this.send(new ClientboundUpdateEnabledFeaturesPacket(FeatureFlags.REGISTRY.toNames(this.server.getWorldData().enabledFeatures()))); +@@ -86,6 +91,10 @@ + + private void addOptionalTasks() { + this.server.getServerResourcePack().ifPresent(p_296496_ -> this.configurationTasks.add(new ServerResourcePackConfigurationTask(p_296496_))); ++ ++ this.configurationTasks.add(new net.neoforged.neoforge.network.configuration.ModdedConfigurationPhaseStarted(this)); ++ this.configurationTasks.addAll(net.neoforged.neoforge.common.NeoForge.EVENT_BUS.post(new net.neoforged.neoforge.network.event.OnGameConfiguration()).getConfigurationTasks()); ++ this.configurationTasks.add(new net.neoforged.neoforge.network.configuration.ModdedConfigurationPhaseCompleted(this)); + } + + @Override +@@ -100,7 +109,40 @@ + this.finishCurrentTask(ServerResourcePackConfigurationTask.TYPE); + } + } +- ++ ++ @Override ++ public void handleCustomPayload(ServerboundCustomPayloadPacket p_294276_) { ++ if (p_294276_.payload() instanceof ModdedNetworkQueryPayload moddedEnvironmentPayload) { ++ this.isModdedConnection = true; ++ NetworkRegistry.getInstance() ++ .onModdedConnectionDetectedAtServer( ++ this, ++ moddedEnvironmentPayload.configuration(), ++ moddedEnvironmentPayload.play() ++ ); ++ return; ++ } ++ ++ if (!isHandlingModdedConfigurationPhase) { ++ super.handleCustomPayload(p_294276_); ++ return; ++ } ++ ++ NetworkRegistry.getInstance().onModdedPacketAtServer(this, p_294276_); ++ } ++ ++ @Override ++ public void handlePong(ServerboundPongPacket p_295142_) { ++ super.handlePong(p_295142_); ++ if (p_295142_.getId() == 0) { ++ if (!this.isModdedConnection && !net.neoforged.neoforge.network.registration.NetworkRegistry.getInstance().onVanillaConnectionDetectedAtServer(this)) { ++ return; ++ } ++ ++ this.runConfiguration(); ++ } ++ } ++ + @Override + public void handleConfigurationFinished(ServerboundFinishConfigurationPacket p_294283_) { + this.connection.suspendInboundAfterProtocolChange(); +@@ -121,7 +163,7 @@ + } + + ServerPlayer serverplayer = playerlist.getPlayerForLogin(this.gameProfile, this.clientInformation); +- playerlist.placeNewPlayer(this.connection, serverplayer, this.createCookie(this.clientInformation)); ++ playerlist.placeNewPlayer(this.connection, serverplayer, this.createCookie(this.clientInformation, this.isModdedConnection)); + this.connection.resumeInboundAfterProtocolChange(); + } catch (Exception exception) { + LOGGER.error("Couldn't place player in world", (Throwable)exception); +@@ -147,7 +189,8 @@ + } + } + +- private void finishCurrentTask(ConfigurationTask.Type p_294853_) { ++ @Override ++ public void finishCurrentTask(ConfigurationTask.Type p_294853_) { + ConfigurationTask.Type configurationtask$type = this.currentTask != null ? this.currentTask.type() : null; + if (!p_294853_.equals(configurationtask$type)) { + throw new IllegalStateException("Unexpected request for task finish, current task: " + configurationtask$type + ", requested: " + p_294853_); +@@ -155,5 +198,15 @@ + this.currentTask = null; + this.startNextTask(); + } ++ } ++ ++ public void onModdedConfigurationPhaseStarted() { ++ isHandlingModdedConfigurationPhase = true; ++ finishCurrentTask(net.neoforged.neoforge.network.configuration.ModdedConfigurationPhaseStarted.TYPE); ++ } ++ ++ public void onModdedConfigurationPhaseEnded() { ++ isHandlingModdedConfigurationPhase = false; ++ finishCurrentTask(net.neoforged.neoforge.network.configuration.ModdedConfigurationPhaseCompleted.TYPE); + } + }