From 18a6c449d1da94e937664ea848c62ba2ba71a73c Mon Sep 17 00:00:00 2001 From: FlorianMichael <60033407+FlorianMichael@users.noreply.github.com> Date: Sat, 12 Aug 2023 03:09:19 +0200 Subject: [PATCH] Fixed incompatible version string being visible on <= 1.6.4 servers Updated ViaVersion and ViaBackwards --- README.md | 2 +- gradle.properties | 10 +++++----- .../definition/LegacyServerAddress.java | 3 --- .../mixin/base/MixinMultiplayerScreen.java | 4 ++-- ...inMultiplayerServerListWidget_ServerEntry.java | 12 ++++++++++++ .../MixinMultiplayerServerListPinger.java | 3 ++- .../mixin/fixes/viaversion/MixinNBTType.java | 8 ++++---- .../fixes/viaversion/MixinProtocolVersion.java | 2 +- .../viafabricplus/protocolhack/ProtocolHack.java | 15 +++++++++++++++ .../screen/impl/thirdparty/BetaCraftScreen.java | 3 ++- 10 files changed, 44 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 42a5060a..d700414f 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ # Why another protocol translator? ViaFabricPlus is intended to replace [multiconnect](https://github.com/Earthcomputer/multiconnect), and it also promises more compactness and stability. ViaFabricPlus can do everything multiconnect could do, but supports more Minecraft versions (listed below) and has more protocol changes implemented. ### Supported Server versions -- Release (1.0.0 - 1.20.1) +- Release (1.0.0 - 1.20.2 [23w32a]) - Beta (b1.0 - b1.8.1) - Alpha (a1.0.15 - a1.2.6) - Classic (c0.0.15 - c0.30 including [CPE](https://wiki.vg/Classic_Protocol_Extension)) diff --git a/gradle.properties b/gradle.properties index 50579313..98c96522 100644 --- a/gradle.properties +++ b/gradle.properties @@ -18,15 +18,15 @@ raknet_transport_version=1.0.0.CR1-SNAPSHOT classic4j_version=1.2.0 # viaversion (and required) libs -viaversion_version=4.7.1-SNAPSHOT -viabackwards_version=4.7.1-SNAPSHOT +viaversion_version=4.8.0-23w32a-SNAPSHOT +viabackwards_version=4.8.0-23w32a-SNAPSHOT # raphimc libs -vialegacy_version=2.2.18-SNAPSHOT -viaaprilfools_version=2.0.8-SNAPSHOT +vialegacy_version=2.2.19-SNAPSHOT +viaaprilfools_version=2.0.9-SNAPSHOT viabedrock_version=0.0.2-SNAPSHOT minecraftauth_version=2.1.4-SNAPSHOT -vialoader_version=2.2.8-SNAPSHOT +vialoader_version=2.2.9-SNAPSHOT # lenni0451 libs reflect_version=1.2.2 diff --git a/src/main/java/de/florianmichael/viafabricplus/definition/LegacyServerAddress.java b/src/main/java/de/florianmichael/viafabricplus/definition/LegacyServerAddress.java index b1f31168..eb2c7eac 100644 --- a/src/main/java/de/florianmichael/viafabricplus/definition/LegacyServerAddress.java +++ b/src/main/java/de/florianmichael/viafabricplus/definition/LegacyServerAddress.java @@ -17,8 +17,6 @@ */ package de.florianmichael.viafabricplus.definition; -import de.florianmichael.viafabricplus.protocolhack.ProtocolHack; -import net.minecraft.client.network.AllowedAddressResolver; import net.minecraft.client.network.ServerAddress; import net.raphimc.vialoader.util.VersionEnum; import net.raphimc.vialoader.util.VersionRange; @@ -27,7 +25,6 @@ public class LegacyServerAddress { public final static VersionRange SRV_RANGE = VersionRange.andOlder(VersionEnum.r1_2_4tor1_2_5).add(VersionRange.single(VersionEnum.bedrockLatest)); public static ServerAddress parse(VersionEnum version, String address) { - if (version == null) version = ProtocolHack.getTargetVersion(); final ServerAddress modern = ServerAddress.parse(address); if (SRV_RANGE.contains(version) && !modern.equals(ServerAddress.INVALID)) { final var addressParts = address.split(":"); diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/base/MixinMultiplayerScreen.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/base/MixinMultiplayerScreen.java index cc2a2f86..d8457dde 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/base/MixinMultiplayerScreen.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/base/MixinMultiplayerScreen.java @@ -18,7 +18,7 @@ package de.florianmichael.viafabricplus.injection.mixin.base; import de.florianmichael.viafabricplus.definition.LegacyServerAddress; -import de.florianmichael.viafabricplus.injection.access.IServerInfo; +import de.florianmichael.viafabricplus.protocolhack.ProtocolHack; import de.florianmichael.viafabricplus.screen.impl.base.ProtocolSelectionScreen; import de.florianmichael.viafabricplus.base.settings.groups.GeneralSettings; import net.minecraft.client.gui.screen.Screen; @@ -66,6 +66,6 @@ public class MixinMultiplayerScreen extends Screen { @Redirect(method = "connect(Lnet/minecraft/client/network/ServerInfo;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ServerAddress;parse(Ljava/lang/String;)Lnet/minecraft/client/network/ServerAddress;")) public ServerAddress doOwnParse(String address) { - return LegacyServerAddress.parse(((IServerInfo) viafabricplus_lastConnect).viafabricplus_forcedVersion(), address); + return LegacyServerAddress.parse(ProtocolHack.getTargetVersion(viafabricplus_lastConnect), address); } } diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/base/MixinMultiplayerServerListWidget_ServerEntry.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/base/MixinMultiplayerServerListWidget_ServerEntry.java index 8a0c55be..0d416ede 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/base/MixinMultiplayerServerListWidget_ServerEntry.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/base/MixinMultiplayerServerListWidget_ServerEntry.java @@ -19,16 +19,20 @@ package de.florianmichael.viafabricplus.injection.mixin.base; import de.florianmichael.viafabricplus.base.settings.groups.GeneralSettings; import de.florianmichael.viafabricplus.injection.access.IServerInfo; +import de.florianmichael.viafabricplus.protocolhack.ProtocolHack; import net.minecraft.client.gui.screen.multiplayer.MultiplayerScreen; import net.minecraft.client.gui.screen.multiplayer.MultiplayerServerListWidget; import net.minecraft.client.network.ServerInfo; import net.minecraft.text.Text; +import net.raphimc.vialegacy.api.LegacyProtocolVersion; import net.raphimc.vialoader.util.VersionEnum; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; 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.CallbackInfoReturnable; import java.util.ArrayList; import java.util.List; @@ -52,4 +56,12 @@ public class MixinMultiplayerServerListWidget_ServerEntry { } instance.setMultiplayerScreenTooltip(tooltipOverwrite); } + + @Inject(method = "protocolVersionMatches", at = @At("HEAD"), cancellable = true) + public void supportViaLegacyVersionRanges(CallbackInfoReturnable cir) { + final var version = ProtocolHack.getTargetVersion(server); + if (version.isOlderThanOrEqualTo(VersionEnum.r1_6_4)) { + cir.setReturnValue(LegacyProtocolVersion.getRealProtocolVersion(version.getVersion()) == server.protocolVersion); + } + } } diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/MixinMultiplayerServerListPinger.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/MixinMultiplayerServerListPinger.java index 0eb1a4b6..dcaa5b08 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/MixinMultiplayerServerListPinger.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/MixinMultiplayerServerListPinger.java @@ -20,6 +20,7 @@ package de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft; import com.google.common.net.HostAndPort; import de.florianmichael.viafabricplus.definition.LegacyServerAddress; import de.florianmichael.viafabricplus.injection.access.IServerInfo; +import de.florianmichael.viafabricplus.protocolhack.ProtocolHack; import net.lenni0451.reflect.stream.RStream; import net.minecraft.client.network.MultiplayerServerListPinger; import net.minecraft.client.network.ServerAddress; @@ -35,7 +36,7 @@ public class MixinMultiplayerServerListPinger { @Inject(method = "add", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/AllowedAddressResolver;resolve(Lnet/minecraft/client/network/ServerAddress;)Ljava/util/Optional;"), locals = LocalCapture.CAPTURE_FAILHARD) public void mapParsing(ServerInfo entry, Runnable saver, CallbackInfo ci, ServerAddress serverAddress) { - final ServerAddress remapped = LegacyServerAddress.parse(((IServerInfo) entry).viafabricplus_forcedVersion(), serverAddress.hostAndPort.toString()); + final ServerAddress remapped = LegacyServerAddress.parse(ProtocolHack.getTargetVersion(entry), serverAddress.hostAndPort.toString()); RStream.of(serverAddress).fields().filter(HostAndPort.class).by(0).set(RStream.of(remapped).fields().filter(HostAndPort.class).by(0).get()); } } diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/viaversion/MixinNBTType.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/viaversion/MixinNBTType.java index e10d6fb7..900ffc7b 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/viaversion/MixinNBTType.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/viaversion/MixinNBTType.java @@ -28,7 +28,7 @@ import org.spongepowered.asm.mixin.injection.Redirect; public class MixinNBTType { @Unique - private final TagLimiter viafabricplus_tag_limiter = new TagLimiter() { + private static final TagLimiter viafabricplus_tag_limiter = new TagLimiter() { private final int maxBytes = 2097152; private int bytes; @@ -59,8 +59,8 @@ public class MixinNBTType { } }; - @Redirect(method = "read(Lio/netty/buffer/ByteBuf;)Lcom/viaversion/viaversion/libs/opennbt/tag/builtin/CompoundTag;", at = @At(value = "INVOKE", target = "Lcom/viaversion/viaversion/libs/opennbt/tag/limiter/TagLimiter;create(II)Lcom/viaversion/viaversion/libs/opennbt/tag/limiter/TagLimiter;")) - public TagLimiter replaceTagLimiter(int maxBytes, int maxLevels) { - return this.viafabricplus_tag_limiter; + @Redirect(method = "read(Lio/netty/buffer/ByteBuf;Z)Lcom/viaversion/viaversion/libs/opennbt/tag/builtin/CompoundTag;", at = @At(value = "INVOKE", target = "Lcom/viaversion/viaversion/libs/opennbt/tag/limiter/TagLimiter;create(II)Lcom/viaversion/viaversion/libs/opennbt/tag/limiter/TagLimiter;")) + private static TagLimiter replaceTagLimiter(int maxBytes, int maxLevels) { + return viafabricplus_tag_limiter; } } diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/viaversion/MixinProtocolVersion.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/viaversion/MixinProtocolVersion.java index f4b86239..d359f575 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/viaversion/MixinProtocolVersion.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/viaversion/MixinProtocolVersion.java @@ -17,7 +17,6 @@ */ package de.florianmichael.viafabricplus.injection.mixin.fixes.viaversion; -import net.raphimc.vialoader.util.VersionEnum; import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import com.viaversion.viaversion.api.protocol.version.VersionRange; import com.viaversion.viaversion.util.Pair; @@ -47,6 +46,7 @@ public abstract class MixinProtocolVersion { viafabricplus_remaps.put("1.18/1.18.1", new Pair<>("1.18-1.18.1", null)); viafabricplus_remaps.put("1.19.1/2", new Pair<>("1.19.1-1.19.2", null)); viafabricplus_remaps.put("1.20/1.20.1", new Pair<>("1.20-1.20.1", null)); + viafabricplus_remaps.put("1.20.2", new Pair<>("23w32a", null)); } @Redirect(method = "", at = @At(value = "INVOKE", target = "Lcom/viaversion/viaversion/api/protocol/version/ProtocolVersion;register(ILjava/lang/String;)Lcom/viaversion/viaversion/api/protocol/version/ProtocolVersion;")) diff --git a/src/main/java/de/florianmichael/viafabricplus/protocolhack/ProtocolHack.java b/src/main/java/de/florianmichael/viafabricplus/protocolhack/ProtocolHack.java index af647f32..fe54e61d 100644 --- a/src/main/java/de/florianmichael/viafabricplus/protocolhack/ProtocolHack.java +++ b/src/main/java/de/florianmichael/viafabricplus/protocolhack/ProtocolHack.java @@ -28,6 +28,7 @@ import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.storage.Inventor import de.florianmichael.viafabricplus.ViaFabricPlus; import de.florianmichael.viafabricplus.base.event.ChangeProtocolVersionCallback; import de.florianmichael.viafabricplus.base.event.FinishViaVersionStartupCallback; +import de.florianmichael.viafabricplus.injection.access.IServerInfo; import de.florianmichael.viafabricplus.protocolhack.command.ViaFabricPlusVLCommandHandler; import de.florianmichael.viafabricplus.protocolhack.impl.ViaFabricPlusVLInjector; import de.florianmichael.viafabricplus.protocolhack.impl.ViaFabricPlusVLLoader; @@ -39,6 +40,7 @@ import io.netty.util.AttributeKey; import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback; import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; import net.minecraft.client.MinecraftClient; +import net.minecraft.client.network.ServerInfo; import net.minecraft.network.ClientConnection; import net.raphimc.vialoader.ViaLoader; import net.raphimc.vialoader.impl.platform.ViaAprilFoolsPlatformImpl; @@ -117,6 +119,19 @@ public class ProtocolHack { return targetVersion; } + /** + * This method is used when you need the target version while connecting to the server after Netty is started and after ViaVersion is finished loading. + * + * @param serverInfo the current server info + * @return the target version + */ + public static VersionEnum getTargetVersion(final ServerInfo serverInfo) { + final var forcedVersion = ((IServerInfo) serverInfo).viafabricplus_forcedVersion(); + if (forcedVersion == null) return getTargetVersion(); + + return forcedVersion; + } + public static Map getForcedVersions() { return forcedVersions; } diff --git a/src/main/java/de/florianmichael/viafabricplus/screen/impl/thirdparty/BetaCraftScreen.java b/src/main/java/de/florianmichael/viafabricplus/screen/impl/thirdparty/BetaCraftScreen.java index b1e4ca82..18f03601 100644 --- a/src/main/java/de/florianmichael/viafabricplus/screen/impl/thirdparty/BetaCraftScreen.java +++ b/src/main/java/de/florianmichael/viafabricplus/screen/impl/thirdparty/BetaCraftScreen.java @@ -21,6 +21,7 @@ import de.florianmichael.classic4j.model.betacraft.BCServerInfo; import de.florianmichael.classic4j.model.betacraft.BCServerList; import de.florianmichael.classic4j.model.betacraft.BCVersion; import de.florianmichael.viafabricplus.definition.LegacyServerAddress; +import de.florianmichael.viafabricplus.protocolhack.ProtocolHack; import de.florianmichael.viafabricplus.screen.MappedSlotEntry; import de.florianmichael.viafabricplus.screen.VFPScreen; import de.florianmichael.viafabricplus.screen.impl.settings.settingrenderer.meta.TitleRenderer; @@ -106,7 +107,7 @@ public class BetaCraftScreen extends VFPScreen { @Override public void mappedMouseClicked(double mouseX, double mouseY, int button) { - final ServerAddress serverAddress = LegacyServerAddress.parse(null, server.host() + ":" + server.port()); + final ServerAddress serverAddress = LegacyServerAddress.parse(ProtocolHack.getTargetVersion(), server.host() + ":" + server.port()); final ServerInfo entry = new ServerInfo(server.name(), serverAddress.getAddress(), false); ConnectScreen.connect(MinecraftClient.getInstance().currentScreen, MinecraftClient.getInstance(), serverAddress, entry, false);