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
This commit is contained in:
Ampflower 2024-08-23 02:38:06 -07:00 committed by GitHub
parent c5dcc31c37
commit 5e59b9d947
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 21 additions and 24 deletions

View File

@ -17,23 +17,22 @@
*/ */
package com.viaversion.fabric.mc1204.mixin.pipeline.client; 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.ViaFabric;
import com.viaversion.fabric.mc1204.service.ProtocolAutoDetector; 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.Mixin;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; 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.net.InetSocketAddress;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.logging.Level; import java.util.logging.Level;
@Mixin(ClientConnection.class) @Mixin(targets = "net/minecraft/client/gui/screen/multiplayer/ConnectScreen$1")
public class MixinClientConnection { public class MixinClientConnectionThread {
@Inject(method = "connect(Ljava/net/InetSocketAddress;ZLnet/minecraft/network/ClientConnection;)Lio/netty/channel/ChannelFuture;", at = @At("HEAD")) @Inject(method = "run", at = @At(value = "INVOKE_ASSIGN", args = "fuzz=2", target = "Ljava/util/Optional;get()Ljava/lang/Object;"))
private static void onConnect(InetSocketAddress address, boolean useEpoll, ClientConnection connection, CallbackInfoReturnable<ChannelFuture> cir) { private void onConnect(CallbackInfo ci, @Local InetSocketAddress address) {
try { try {
if (!ViaFabric.config.isClientSideEnabled()) return; if (!ViaFabric.config.isClientSideEnabled()) return;
ProtocolAutoDetector.detectVersion(address).get(10, TimeUnit.SECONDS); ProtocolAutoDetector.detectVersion(address).get(10, TimeUnit.SECONDS);

View File

@ -6,7 +6,7 @@
"MixinClientConnection" "MixinClientConnection"
], ],
"client": [ "client": [
"client.MixinClientConnection" "client.MixinClientConnectionThread"
], ],
"injectors": { "injectors": {
"defaultRequire": 1 "defaultRequire": 1

View File

@ -17,23 +17,22 @@
*/ */
package com.viaversion.fabric.mc1206.mixin.pipeline.client; 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.ViaFabric;
import com.viaversion.fabric.mc1206.service.ProtocolAutoDetector; 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.Mixin;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; 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.net.InetSocketAddress;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.logging.Level; import java.util.logging.Level;
@Mixin(ClientConnection.class) @Mixin(targets = "net/minecraft/client/gui/screen/multiplayer/ConnectScreen$1")
public class MixinClientConnection { public class MixinClientConnectionThread {
@Inject(method = "connect(Ljava/net/InetSocketAddress;ZLnet/minecraft/network/ClientConnection;)Lio/netty/channel/ChannelFuture;", at = @At("HEAD")) @Inject(method = "run", at = @At(value = "INVOKE_ASSIGN", args = "fuzz=2", target = "Ljava/util/Optional;get()Ljava/lang/Object;"))
private static void onConnect(InetSocketAddress address, boolean useEpoll, ClientConnection connection, CallbackInfoReturnable<ChannelFuture> cir) { private void onConnect(CallbackInfo ci, @Local InetSocketAddress address) {
try { try {
if (!ViaFabric.config.isClientSideEnabled()) return; if (!ViaFabric.config.isClientSideEnabled()) return;
ProtocolAutoDetector.detectVersion(address).get(10, TimeUnit.SECONDS); ProtocolAutoDetector.detectVersion(address).get(10, TimeUnit.SECONDS);

View File

@ -6,7 +6,7 @@
"MixinClientConnection" "MixinClientConnection"
], ],
"client": [ "client": [
"client.MixinClientConnection" "client.MixinClientConnectionThread"
], ],
"injectors": { "injectors": {
"defaultRequire": 1 "defaultRequire": 1

View File

@ -17,23 +17,22 @@
*/ */
package com.viaversion.fabric.mc1211.mixin.pipeline.client; 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.ViaFabric;
import com.viaversion.fabric.mc1211.service.ProtocolAutoDetector; 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.Mixin;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; 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.net.InetSocketAddress;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.logging.Level; import java.util.logging.Level;
@Mixin(ClientConnection.class) @Mixin(targets = "net/minecraft/client/gui/screen/multiplayer/ConnectScreen$1")
public class MixinClientConnection { public class MixinClientConnectionThread {
@Inject(method = "connect(Ljava/net/InetSocketAddress;ZLnet/minecraft/network/ClientConnection;)Lio/netty/channel/ChannelFuture;", at = @At("HEAD")) @Inject(method = "run", at = @At(value = "INVOKE_ASSIGN", args = "fuzz=2", target = "Ljava/util/Optional;get()Ljava/lang/Object;"))
private static void onConnect(InetSocketAddress address, boolean useEpoll, ClientConnection connection, CallbackInfoReturnable<ChannelFuture> cir) { private void onConnect(CallbackInfo ci, @Local InetSocketAddress address) {
try { try {
if (!ViaFabric.config.isClientSideEnabled()) return; if (!ViaFabric.config.isClientSideEnabled()) return;
ProtocolAutoDetector.detectVersion(address).get(10, TimeUnit.SECONDS); ProtocolAutoDetector.detectVersion(address).get(10, TimeUnit.SECONDS);

View File

@ -6,7 +6,7 @@
"MixinClientConnection" "MixinClientConnection"
], ],
"client": [ "client": [
"client.MixinClientConnection" "client.MixinClientConnectionThread"
], ],
"injectors": { "injectors": {
"defaultRequire": 1 "defaultRequire": 1