Tweaked some things

This commit is contained in:
RaphiMC 2023-11-30 20:26:13 +01:00
parent 1706b8c718
commit 859f5b7fcd
No known key found for this signature in database
GPG Key ID: 0F6BB0657A03AC94
3 changed files with 5 additions and 16 deletions

View File

@ -19,8 +19,11 @@ package net.raphimc.viaproxy.injection;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import net.lenni0451.reflect.Enums;
import net.lenni0451.reflect.stream.RStream;
import net.raphimc.vialoader.util.VersionEnum;
import java.util.Map;
public class VersionEnumExtension {
private static final ProtocolVersion autoDetect = ProtocolVersion.register(-2, "Auto Detect (1.7+ servers)");
@ -28,6 +31,7 @@ public class VersionEnumExtension {
static {
Enums.addEnumInstance(VersionEnum.class, AUTO_DETECT);
RStream.of(VersionEnum.class).fields().by("VERSION_REGISTRY").<Map<ProtocolVersion, VersionEnum>>get().put(autoDetect, AUTO_DETECT);
VersionEnum.SORTED_VERSIONS.add(AUTO_DETECT);
}

View File

@ -21,16 +21,12 @@ import com.google.common.collect.ImmutableSet;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viaversion.api.protocol.version.VersionRange;
import com.viaversion.viaversion.util.Pair;
import net.raphimc.viaproxy.injection.VersionEnumExtension;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import java.util.HashMap;
import java.util.Map;
@ -39,10 +35,6 @@ import java.util.Set;
@Mixin(value = ProtocolVersion.class, remap = false)
public abstract class MixinProtocolVersion {
@Shadow
@Final
private int version;
@Unique
private static Set<String> skips;
@ -97,11 +89,4 @@ public abstract class MixinProtocolVersion {
return ProtocolVersion.register(version, name, versionRange);
}
@Inject(method = "isKnown", at = @At("HEAD"), cancellable = true)
private void markAutoDetectAsUnknown(CallbackInfoReturnable<Boolean> cir) {
if (VersionEnumExtension.AUTO_DETECT != null && this.version == VersionEnumExtension.AUTO_DETECT.getVersion()) {
cir.setReturnValue(false);
}
}
}

View File

@ -25,7 +25,7 @@ import net.raphimc.vialoader.util.VersionEnum;
public class ProtocolVersionDetector {
private static final int TIMEOUT = 1000;
private static final int TIMEOUT = 3000;
public static VersionEnum get(final ServerAddress serverAddress, final VersionEnum clientVersion) {
MCPingResponse response = MCPing