From 5e59b9d947fb6a5f284216a1e0cf9840aa894f4b Mon Sep 17 00:00:00 2001 From: Ampflower Date: Fri, 23 Aug 2024 02:38:06 -0700 Subject: [PATCH] Move protocol detector outside of sync block (#370) * Move protocol detector injection outside of sync block Fixes ViaVersion/ViaFabric#302 * Fix bad package reference for 1.20.1 * Revert 1.20.1's move * Omit static on mixins --- ...ection.java => MixinClientConnectionThread.java} | 13 ++++++------- .../resources/mixins.viafabric1204.pipeline.json | 2 +- ...ection.java => MixinClientConnectionThread.java} | 13 ++++++------- .../resources/mixins.viafabric1206.pipeline.json | 2 +- ...ection.java => MixinClientConnectionThread.java} | 13 ++++++------- .../resources/mixins.viafabric1211.pipeline.json | 2 +- 6 files changed, 21 insertions(+), 24 deletions(-) rename viafabric-mc1204/src/main/java/com/viaversion/fabric/mc1204/mixin/pipeline/client/{MixinClientConnection.java => MixinClientConnectionThread.java} (77%) rename viafabric-mc1206/src/main/java/com/viaversion/fabric/mc1206/mixin/pipeline/client/{MixinClientConnection.java => MixinClientConnectionThread.java} (77%) rename viafabric-mc1211/src/main/java/com/viaversion/fabric/mc1211/mixin/pipeline/client/{MixinClientConnection.java => MixinClientConnectionThread.java} (77%) diff --git a/viafabric-mc1204/src/main/java/com/viaversion/fabric/mc1204/mixin/pipeline/client/MixinClientConnection.java b/viafabric-mc1204/src/main/java/com/viaversion/fabric/mc1204/mixin/pipeline/client/MixinClientConnectionThread.java similarity index 77% rename from viafabric-mc1204/src/main/java/com/viaversion/fabric/mc1204/mixin/pipeline/client/MixinClientConnection.java rename to viafabric-mc1204/src/main/java/com/viaversion/fabric/mc1204/mixin/pipeline/client/MixinClientConnectionThread.java index c63da17..53cd6ba 100644 --- a/viafabric-mc1204/src/main/java/com/viaversion/fabric/mc1204/mixin/pipeline/client/MixinClientConnection.java +++ b/viafabric-mc1204/src/main/java/com/viaversion/fabric/mc1204/mixin/pipeline/client/MixinClientConnectionThread.java @@ -17,23 +17,22 @@ */ package com.viaversion.fabric.mc1204.mixin.pipeline.client; +import com.llamalad7.mixinextras.sugar.Local; import com.viaversion.fabric.mc1204.ViaFabric; import com.viaversion.fabric.mc1204.service.ProtocolAutoDetector; -import io.netty.channel.ChannelFuture; -import net.minecraft.network.ClientConnection; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import java.net.InetSocketAddress; import java.util.concurrent.TimeUnit; import java.util.logging.Level; -@Mixin(ClientConnection.class) -public class MixinClientConnection { - @Inject(method = "connect(Ljava/net/InetSocketAddress;ZLnet/minecraft/network/ClientConnection;)Lio/netty/channel/ChannelFuture;", at = @At("HEAD")) - private static void onConnect(InetSocketAddress address, boolean useEpoll, ClientConnection connection, CallbackInfoReturnable cir) { +@Mixin(targets = "net/minecraft/client/gui/screen/multiplayer/ConnectScreen$1") +public class MixinClientConnectionThread { + @Inject(method = "run", at = @At(value = "INVOKE_ASSIGN", args = "fuzz=2", target = "Ljava/util/Optional;get()Ljava/lang/Object;")) + private void onConnect(CallbackInfo ci, @Local InetSocketAddress address) { try { if (!ViaFabric.config.isClientSideEnabled()) return; ProtocolAutoDetector.detectVersion(address).get(10, TimeUnit.SECONDS); diff --git a/viafabric-mc1204/src/main/resources/mixins.viafabric1204.pipeline.json b/viafabric-mc1204/src/main/resources/mixins.viafabric1204.pipeline.json index b8723fb..68b0b7e 100644 --- a/viafabric-mc1204/src/main/resources/mixins.viafabric1204.pipeline.json +++ b/viafabric-mc1204/src/main/resources/mixins.viafabric1204.pipeline.json @@ -6,7 +6,7 @@ "MixinClientConnection" ], "client": [ - "client.MixinClientConnection" + "client.MixinClientConnectionThread" ], "injectors": { "defaultRequire": 1 diff --git a/viafabric-mc1206/src/main/java/com/viaversion/fabric/mc1206/mixin/pipeline/client/MixinClientConnection.java b/viafabric-mc1206/src/main/java/com/viaversion/fabric/mc1206/mixin/pipeline/client/MixinClientConnectionThread.java similarity index 77% rename from viafabric-mc1206/src/main/java/com/viaversion/fabric/mc1206/mixin/pipeline/client/MixinClientConnection.java rename to viafabric-mc1206/src/main/java/com/viaversion/fabric/mc1206/mixin/pipeline/client/MixinClientConnectionThread.java index f174235..645347b 100644 --- a/viafabric-mc1206/src/main/java/com/viaversion/fabric/mc1206/mixin/pipeline/client/MixinClientConnection.java +++ b/viafabric-mc1206/src/main/java/com/viaversion/fabric/mc1206/mixin/pipeline/client/MixinClientConnectionThread.java @@ -17,23 +17,22 @@ */ package com.viaversion.fabric.mc1206.mixin.pipeline.client; +import com.llamalad7.mixinextras.sugar.Local; import com.viaversion.fabric.mc1206.ViaFabric; import com.viaversion.fabric.mc1206.service.ProtocolAutoDetector; -import io.netty.channel.ChannelFuture; -import net.minecraft.network.ClientConnection; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import java.net.InetSocketAddress; import java.util.concurrent.TimeUnit; import java.util.logging.Level; -@Mixin(ClientConnection.class) -public class MixinClientConnection { - @Inject(method = "connect(Ljava/net/InetSocketAddress;ZLnet/minecraft/network/ClientConnection;)Lio/netty/channel/ChannelFuture;", at = @At("HEAD")) - private static void onConnect(InetSocketAddress address, boolean useEpoll, ClientConnection connection, CallbackInfoReturnable cir) { +@Mixin(targets = "net/minecraft/client/gui/screen/multiplayer/ConnectScreen$1") +public class MixinClientConnectionThread { + @Inject(method = "run", at = @At(value = "INVOKE_ASSIGN", args = "fuzz=2", target = "Ljava/util/Optional;get()Ljava/lang/Object;")) + private void onConnect(CallbackInfo ci, @Local InetSocketAddress address) { try { if (!ViaFabric.config.isClientSideEnabled()) return; ProtocolAutoDetector.detectVersion(address).get(10, TimeUnit.SECONDS); diff --git a/viafabric-mc1206/src/main/resources/mixins.viafabric1206.pipeline.json b/viafabric-mc1206/src/main/resources/mixins.viafabric1206.pipeline.json index ac881a5..beea212 100644 --- a/viafabric-mc1206/src/main/resources/mixins.viafabric1206.pipeline.json +++ b/viafabric-mc1206/src/main/resources/mixins.viafabric1206.pipeline.json @@ -6,7 +6,7 @@ "MixinClientConnection" ], "client": [ - "client.MixinClientConnection" + "client.MixinClientConnectionThread" ], "injectors": { "defaultRequire": 1 diff --git a/viafabric-mc1211/src/main/java/com/viaversion/fabric/mc1211/mixin/pipeline/client/MixinClientConnection.java b/viafabric-mc1211/src/main/java/com/viaversion/fabric/mc1211/mixin/pipeline/client/MixinClientConnectionThread.java similarity index 77% rename from viafabric-mc1211/src/main/java/com/viaversion/fabric/mc1211/mixin/pipeline/client/MixinClientConnection.java rename to viafabric-mc1211/src/main/java/com/viaversion/fabric/mc1211/mixin/pipeline/client/MixinClientConnectionThread.java index 4ebc528..e199906 100644 --- a/viafabric-mc1211/src/main/java/com/viaversion/fabric/mc1211/mixin/pipeline/client/MixinClientConnection.java +++ b/viafabric-mc1211/src/main/java/com/viaversion/fabric/mc1211/mixin/pipeline/client/MixinClientConnectionThread.java @@ -17,23 +17,22 @@ */ package com.viaversion.fabric.mc1211.mixin.pipeline.client; +import com.llamalad7.mixinextras.sugar.Local; import com.viaversion.fabric.mc1211.ViaFabric; import com.viaversion.fabric.mc1211.service.ProtocolAutoDetector; -import io.netty.channel.ChannelFuture; -import net.minecraft.network.ClientConnection; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import java.net.InetSocketAddress; import java.util.concurrent.TimeUnit; import java.util.logging.Level; -@Mixin(ClientConnection.class) -public class MixinClientConnection { - @Inject(method = "connect(Ljava/net/InetSocketAddress;ZLnet/minecraft/network/ClientConnection;)Lio/netty/channel/ChannelFuture;", at = @At("HEAD")) - private static void onConnect(InetSocketAddress address, boolean useEpoll, ClientConnection connection, CallbackInfoReturnable cir) { +@Mixin(targets = "net/minecraft/client/gui/screen/multiplayer/ConnectScreen$1") +public class MixinClientConnectionThread { + @Inject(method = "run", at = @At(value = "INVOKE_ASSIGN", args = "fuzz=2", target = "Ljava/util/Optional;get()Ljava/lang/Object;")) + private void onConnect(CallbackInfo ci, @Local InetSocketAddress address) { try { if (!ViaFabric.config.isClientSideEnabled()) return; ProtocolAutoDetector.detectVersion(address).get(10, TimeUnit.SECONDS); diff --git a/viafabric-mc1211/src/main/resources/mixins.viafabric1211.pipeline.json b/viafabric-mc1211/src/main/resources/mixins.viafabric1211.pipeline.json index be6a2f6..b2bfd85 100644 --- a/viafabric-mc1211/src/main/resources/mixins.viafabric1211.pipeline.json +++ b/viafabric-mc1211/src/main/resources/mixins.viafabric1211.pipeline.json @@ -6,7 +6,7 @@ "MixinClientConnection" ], "client": [ - "client.MixinClientConnection" + "client.MixinClientConnectionThread" ], "injectors": { "defaultRequire": 1