diff --git a/build.gradle b/build.gradle index 863ba5d..4f0e286 100644 --- a/build.gradle +++ b/build.gradle @@ -84,8 +84,23 @@ allprojects { } subprojects { + loom { + runs { + named("client") { + client() + ideConfigGenerated(true) + runDir("run") + } + named("server") { + server() + ideConfigGenerated(true) + runDir("run") + } + } + } + dependencies { - implementation(rootProject) { + implementation(project(path: ":", configuration: "namedElements")) { exclude group: "net.fabricmc", module: "fabric-loader" // prevent duplicate fabric-loader on run } } @@ -126,7 +141,7 @@ static void setupRepositories(RepositoryHandler repositories) { } subprojects.each { - remapJar.dependsOn("${it.path}:remapJar") + rootProject.remapJar.dependsOn("${it.path}:remapJar") } configurations { diff --git a/src/main/java/com/viaversion/fabric/common/protocol/HostnameParserProtocol.java b/src/main/java/com/viaversion/fabric/common/protocol/HostnameParserProtocol.java index d818cf4..d94d6d1 100644 --- a/src/main/java/com/viaversion/fabric/common/protocol/HostnameParserProtocol.java +++ b/src/main/java/com/viaversion/fabric/common/protocol/HostnameParserProtocol.java @@ -31,7 +31,7 @@ public class HostnameParserProtocol extends AbstractSimpleProtocol { @Override protected void registerPackets() { - registerServerbound(State.HANDSHAKE, ServerboundHandshakePackets.CLIENT_INTENTION.getId(), ServerboundHandshakePackets.CLIENT_INTENTION.getId(), new PacketHandlers() { + registerServerbound(State.HANDSHAKE, ServerboundHandshakePackets.CLIENT_INTENTION, new PacketHandlers() { @Override protected void register() { map(Types.VAR_INT); // Protocol version diff --git a/src/main/java/com/viaversion/fabric/common/provider/AbstractFabricVersionProvider.java b/src/main/java/com/viaversion/fabric/common/provider/AbstractFabricVersionProvider.java index 661bb4e..658f15a 100644 --- a/src/main/java/com/viaversion/fabric/common/provider/AbstractFabricVersionProvider.java +++ b/src/main/java/com/viaversion/fabric/common/provider/AbstractFabricVersionProvider.java @@ -31,9 +31,8 @@ import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import com.viaversion.viaversion.api.type.Types; import com.viaversion.viaversion.exception.CancelException; import com.viaversion.viaversion.protocol.version.BaseVersionProvider; -import com.viaversion.viaversion.protocols.base.BaseProtocol1_16; -import com.viaversion.viaversion.protocols.base.BaseProtocol1_7; import com.viaversion.viaversion.protocols.base.ClientboundStatusPackets; +import com.viaversion.viaversion.protocols.base.v1_7.ClientboundBaseProtocol1_7; import io.netty.channel.ChannelPipeline; import net.fabricmc.loader.api.FabricLoader; @@ -150,7 +149,7 @@ public abstract class AbstractFabricVersionProvider extends BaseVersionProvider getLogger().info("Sending " + multiconnectSuggestion + " for multiconnect version detector"); PacketWrapper newAnswer = PacketWrapper.create(ClientboundStatusPackets.STATUS_RESPONSE, null, connection); newAnswer.write(Types.STRING, "{\"version\":{\"name\":\"viafabric integration\",\"protocol\":" + multiconnectSuggestion.getVersion() + "}}"); - newAnswer.send(info.getPipeline().contains(BaseProtocol1_16.class) ? BaseProtocol1_16.class : BaseProtocol1_7.class); + newAnswer.send(ClientboundBaseProtocol1_7.class); throw CancelException.generate(); } } 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