mirror of
https://github.com/ViaVersion/ViaFabric.git
synced 2024-11-23 11:55:52 +01:00
Use WrapOperation for auto detector mixins instead
This commit is contained in:
parent
0e3ebb1727
commit
8dd5214b03
@ -17,27 +17,29 @@
|
|||||||
*/
|
*/
|
||||||
package com.viaversion.fabric.mc1204.mixin.pipeline.client;
|
package com.viaversion.fabric.mc1204.mixin.pipeline.client;
|
||||||
|
|
||||||
import com.llamalad7.mixinextras.sugar.Local;
|
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
|
||||||
|
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
|
||||||
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 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.callback.CallbackInfo;
|
|
||||||
|
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
@Mixin(targets = "net/minecraft/client/gui/screen/multiplayer/ConnectScreen$1")
|
@Mixin(targets = "net/minecraft/client/gui/screen/multiplayer/ConnectScreen$1")
|
||||||
public class MixinClientConnectionThread {
|
public class MixinClientConnectionThread {
|
||||||
@Inject(method = "run", at = @At(value = "INVOKE_ASSIGN", args = "fuzz=2", target = "Ljava/util/Optional;get()Ljava/lang/Object;"))
|
@WrapOperation(method = "run", at = @At(value = "INVOKE", target = "Ljava/util/Optional;get()Ljava/lang/Object;"))
|
||||||
private void onConnect(CallbackInfo ci, @Local InetSocketAddress address) {
|
private Object onConnect(Optional instance, Operation<InetSocketAddress> original) {
|
||||||
|
InetSocketAddress address = original.call(instance);
|
||||||
try {
|
try {
|
||||||
if (!ViaFabric.config.isClientSideEnabled()) return;
|
if (!ViaFabric.config.isClientSideEnabled()) return address;
|
||||||
ProtocolAutoDetector.detectVersion(address).get(10, TimeUnit.SECONDS);
|
ProtocolAutoDetector.detectVersion(address).get(10, TimeUnit.SECONDS);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
ViaFabric.JLOGGER.log(Level.WARNING, "Could not auto-detect protocol for " + address + " " + e);
|
ViaFabric.JLOGGER.log(Level.WARNING, "Could not auto-detect protocol for " + address + " " + e);
|
||||||
}
|
}
|
||||||
|
return address;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,27 +17,29 @@
|
|||||||
*/
|
*/
|
||||||
package com.viaversion.fabric.mc1206.mixin.pipeline.client;
|
package com.viaversion.fabric.mc1206.mixin.pipeline.client;
|
||||||
|
|
||||||
import com.llamalad7.mixinextras.sugar.Local;
|
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
|
||||||
|
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
|
||||||
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 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.callback.CallbackInfo;
|
|
||||||
|
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
@Mixin(targets = "net/minecraft/client/gui/screen/multiplayer/ConnectScreen$1")
|
@Mixin(targets = "net/minecraft/client/gui/screen/multiplayer/ConnectScreen$1")
|
||||||
public class MixinClientConnectionThread {
|
public class MixinClientConnectionThread {
|
||||||
@Inject(method = "run", at = @At(value = "INVOKE_ASSIGN", args = "fuzz=2", target = "Ljava/util/Optional;get()Ljava/lang/Object;"))
|
@WrapOperation(method = "run", at = @At(value = "INVOKE", target = "Ljava/util/Optional;get()Ljava/lang/Object;"))
|
||||||
private void onConnect(CallbackInfo ci, @Local InetSocketAddress address) {
|
private Object onConnect(Optional instance, Operation<InetSocketAddress> original) {
|
||||||
|
InetSocketAddress address = original.call(instance);
|
||||||
try {
|
try {
|
||||||
if (!ViaFabric.config.isClientSideEnabled()) return;
|
if (!ViaFabric.config.isClientSideEnabled()) return address;
|
||||||
ProtocolAutoDetector.detectVersion(address).get(10, TimeUnit.SECONDS);
|
ProtocolAutoDetector.detectVersion(address).get(10, TimeUnit.SECONDS);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
ViaFabric.JLOGGER.log(Level.WARNING, "Could not auto-detect protocol for " + address + " " + e);
|
ViaFabric.JLOGGER.log(Level.WARNING, "Could not auto-detect protocol for " + address + " " + e);
|
||||||
}
|
}
|
||||||
|
return address;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,27 +17,29 @@
|
|||||||
*/
|
*/
|
||||||
package com.viaversion.fabric.mc1211.mixin.pipeline.client;
|
package com.viaversion.fabric.mc1211.mixin.pipeline.client;
|
||||||
|
|
||||||
import com.llamalad7.mixinextras.sugar.Local;
|
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
|
||||||
|
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
|
||||||
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 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.callback.CallbackInfo;
|
|
||||||
|
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
@Mixin(targets = "net/minecraft/client/gui/screen/multiplayer/ConnectScreen$1")
|
@Mixin(targets = "net/minecraft/client/gui/screen/multiplayer/ConnectScreen$1")
|
||||||
public class MixinClientConnectionThread {
|
public class MixinClientConnectionThread {
|
||||||
@Inject(method = "run", at = @At(value = "INVOKE_ASSIGN", args = "fuzz=2", target = "Ljava/util/Optional;get()Ljava/lang/Object;"))
|
@WrapOperation(method = "run", at = @At(value = "INVOKE", target = "Ljava/util/Optional;get()Ljava/lang/Object;"))
|
||||||
private void onConnect(CallbackInfo ci, @Local InetSocketAddress address) {
|
private Object onConnect(Optional instance, Operation<InetSocketAddress> original) {
|
||||||
|
InetSocketAddress address = original.call(instance);
|
||||||
try {
|
try {
|
||||||
if (!ViaFabric.config.isClientSideEnabled()) return;
|
if (!ViaFabric.config.isClientSideEnabled()) return address;
|
||||||
ProtocolAutoDetector.detectVersion(address).get(10, TimeUnit.SECONDS);
|
ProtocolAutoDetector.detectVersion(address).get(10, TimeUnit.SECONDS);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
ViaFabric.JLOGGER.log(Level.WARNING, "Could not auto-detect protocol for " + address + " " + e);
|
ViaFabric.JLOGGER.log(Level.WARNING, "Could not auto-detect protocol for " + address + " " + e);
|
||||||
}
|
}
|
||||||
|
return address;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user