From 86eb3d54f185f5c347b7fd558dbf78c7198a717d Mon Sep 17 00:00:00 2001 From: creeper123123321 <7974274+creeper123123321@users.noreply.github.com> Date: Wed, 16 Sep 2020 10:19:51 -0300 Subject: [PATCH] workaround FabricMC/fabric-loom#279, implement #52, update gradle and fabric, update README.md --- README.md | 4 +- build.gradle.kts | 12 +- gradle/wrapper/gradle-wrapper.jar | Bin 58694 -> 58910 bytes gradle/wrapper/gradle-wrapper.properties | 2 +- gradlew | 2 + gradlew.bat | 1 + .../viafabric/config/VRConfig.java | 9 + .../viafabric/gui/ModMenuConfig.java | 36 ++++ .../viafabric/gui/ViaConfigScreen.java | 194 ++++++++++++++++++ .../client/MixinConnectScreenThread.java | 2 +- .../mixin/client/MixinMultiplayerScreen.java | 122 +---------- .../mixin/client/MixinServerAddress.java | 15 +- .../providers/VRVersionProvider.java | 55 ++--- ...onFormatFilter.java => ProtocolUtils.java} | 39 +++- .../resources/assets/viafabric/config.yml | 4 +- .../assets/viafabric/lang/en_us.json | 9 +- src/main/resources/fabric.mod.json | 6 +- src/main/resources/viafabric.accesswidener | 4 + 18 files changed, 349 insertions(+), 167 deletions(-) create mode 100644 src/main/java/com/github/creeper123123321/viafabric/gui/ModMenuConfig.java create mode 100644 src/main/java/com/github/creeper123123321/viafabric/gui/ViaConfigScreen.java rename src/main/java/com/github/creeper123123321/viafabric/util/{VersionFormatFilter.java => ProtocolUtils.java} (61%) create mode 100644 src/main/resources/viafabric.accesswidener diff --git a/README.md b/README.md index 372a766..42aaeda 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ Note: ViaVersion is designed for Vanilla Minecraft servers. It probably will not | Dependency | Download | | ----------------------------------------- | ------------------------------------------------------------------------------------------ | -| (Bundled 3.1.0 release) ViaVersion 3.0.2+ | https://ci.viaversion.com/job/ViaVersion/ or https://ci.viaversion.com/job/ViaVersion-DEV/ | +| (Bundled 3.1.1 release) ViaVersion 3.0.2+ | https://ci.viaversion.com/job/ViaVersion/ or https://ci.viaversion.com/job/ViaVersion-DEV/ | | (Bundled) Cotton Client Commands | https://www.curseforge.com/minecraft/mc-mods/cotton-client-commands | | (Optional) Fabric Command API v1/v0 | https://www.curseforge.com/minecraft/mc-mods/fabric-api | | Fabric Resource Loader v0 | https://www.curseforge.com/minecraft/mc-mods/fabric-api | @@ -28,7 +28,7 @@ Note: ViaVersion is designed for Vanilla Minecraft servers. It probably will not | Dependency | Download | | ----------------------------------------- | ------------------------------------------------------------------------------------------ | -| (Bundled 3.1.0 release) ViaVersion 3.0.2+ | https://ci.viaversion.com/job/ViaVersion/ or https://ci.viaversion.com/job/ViaVersion-DEV/ | +| (Bundled 3.1.1 release) ViaVersion 3.0.2+ | https://ci.viaversion.com/job/ViaVersion/ or https://ci.viaversion.com/job/ViaVersion-DEV/ | | (Optional) Fabric Commands v0 | https://www.curseforge.com/minecraft/mc-mods/legacy-fabric-api | | Fabric Resource Loader v0 | https://www.curseforge.com/minecraft/mc-mods/legacy-fabric-api | diff --git a/build.gradle.kts b/build.gradle.kts index 8b9f230..5a0fb08 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -20,7 +20,7 @@ val branch = if (!travisBranch.isNullOrBlank()) travisBranch else try { "unknown" } -version = "0.2.12-SNAPSHOT+" + try { +version = "0.2.13-SNAPSHOT+" + try { gitVersion() + "-" + branch } catch (e: Exception) { "unknown" @@ -65,11 +65,12 @@ dependencies { // Use 1.16 snapshot, probably intermediary will make it work on further versions // https://modmuss50.me/fabric.html?&version=1.16 - minecraft("com.mojang:minecraft:1.16") - mappings("net.fabricmc:yarn:1.16+build.1:v2") - modImplementation("net.fabricmc:fabric-loader:0.8.8+build.202") + minecraft("com.mojang:minecraft:1.16.3") + mappings("net.fabricmc:yarn:1.16.3+build.5:v2") + modImplementation("net.fabricmc:fabric-loader:0.9.3+build.207") - modImplementation("net.fabricmc.fabric-api:fabric-api:0.13.1+build.370-1.16") + modImplementation("net.fabricmc.fabric-api:fabric-api:0.20.2+build.402-1.16") + modImplementation("io.github.prospector:modmenu:1.14.5+build.30") modImplementation("io.github.cottonmc:cotton-client-commands:1.0.1+1.16-rc1") include("io.github.cottonmc:cotton-client-commands:1.0.1+1.16-rc1") @@ -137,6 +138,7 @@ curseforge { } minecraft { + accessWidener("src/main/resources/viafabric.accesswidener") } license { diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 490fda8577df6c95960ba7077c43220e5bb2c0d9..62d4c053550b91381bbd28b1afc82d634bf73a8a 100644 GIT binary patch delta 6447 zcmY*dbyQSczlH%shY+L(kQ}C6ise@?c@F%#`dE9xT=qM=Dm?$VxD1hrECD1a#01Q8o zMyT3}z+1K>hPE%4doH=x5X;^NP(OFD5GByp;5FQ^bpzkBa(;eudMu7Iyv$DE+N=>p z{3Y5_BP>F3)tXW*Styc(Ji3jnK-giGA_&42fsbZ@#+e+ly3w0VmLC;LA)h1UY(ChA zfwqQ?-@}@S93F|exOv;Se;P|SrYvEG(8q&|ltqvQHO9KgCSwM!Y+#d5eIRq$Mi`pU__N$FTxW@KAWIw= zayY6@9EyxG<_tr&{Wi87m5*mf=u&=;eL1gf{Mt)q8Drick8CcxzLW>cG~TbW)|$*D zYMc|5eZNNzt7O_C1LqgaI`Z0B+2#;3yO;E7N4oMY@~7$4;MRonU+Ca z#*cD!7$u9pZ|3f!-_6rpN}XhAWd`1qiR{e*1CJK1dvBsjUyY@BuT|;EAz}*0uSwT_ zq(g0jXTAK4wsQ>kIKEfRQZw^GIKNRZmV)b;c*Kpc?IvNuq{+eCM4%IBoRUk!JeJ4IVH!pLl+5gQn^$0Fw(WROw~SclOYWbMmvR+x&lYa zrU`5lck*s2zl;n6HEa_E|Btu!_BeeF8T=~0Z-pdJsKtN8nr88*8loznbI`@@8U-bc zCE&MaHH#?LN;6&wU%>->{X&6n*c6ECkP#Bn{lafo9KW+AKK>>f)YfzG#t`XCsl$WX zeS|50l&G{J6yrdD0#njv3|C}K(~azN%1+c#*-JXtZd=Rs-zr)f{M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ZZQ79>m7YGM zSPJ1GRDQtW?r9jb{g**e3Mr>PHrRWagZ|ku4kjL;JOdL~Id05kc*CA+ui@= zieS-e>hskR-1I9Sx7b4i6p>2LP#vgtG6;8vGL>E3$NPQ$J2r~XGQDNg;Sw=& zC}lz+3@Sq%I2q-97R&9|8Ij2^?^DGQK_oiqZS2$!-rzVqn=~d~TS{n&I+svxt4dWO zT?K0)JEx>9E7saW8h!5+MmAkC`g~v*@ z6VKn0>eZdon>BH(O$mACnxk3D?vSlCFFnvZ#+&hUs)Wr!aP{<@|oc^G>bJk59^xhmz!RA%|K_$o)V`D@gVs>@bSmXVID_PQXp znfja8U01+t3V!o{8ZKi~G@#q$KrAH-Ks3$G{Qo}H|N1ijJMsgZDgOmM1O$Fi0>0CX zpbAzXhYbP@PV;~=*nn7eQGjoT2b9nGFNg-PpHT$a@?7JL7I&pmkmclS7#Y#zRYg_`D0h47O z&|%88tXNh8{Yk$@@*HA-B9r#tDkY$>!U#Ie`j1TupjRn@;(ykyyld-zJ{@qm!UG~I zxR#ZxV8CEi5JXV?ANc~bS9*;MYtkTvifc5iynmg!XpIr%SN*R#E?|3&2QVs~N02d=N!1;GdfNGr)gc$|K#-y*M=Ra9B4#cmk-naoQuS*cWnE3C4 F{|nTN-B$nr diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 622ab64..12d38de 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 2fe81a7..fbd7c51 100755 --- a/gradlew +++ b/gradlew @@ -82,6 +82,7 @@ esac CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + # Determine the Java command to use to start the JVM. if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then @@ -129,6 +130,7 @@ fi if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then APP_HOME=`cygpath --path --mixed "$APP_HOME"` CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` # We build the pattern for arguments to be converted via cygpath diff --git a/gradlew.bat b/gradlew.bat index 62bd9b9..5093609 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -84,6 +84,7 @@ set CMD_LINE_ARGS=%* set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + @rem Execute Gradle "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% diff --git a/src/main/java/com/github/creeper123123321/viafabric/config/VRConfig.java b/src/main/java/com/github/creeper123123321/viafabric/config/VRConfig.java index 77f96a5..ba88bc6 100644 --- a/src/main/java/com/github/creeper123123321/viafabric/config/VRConfig.java +++ b/src/main/java/com/github/creeper123123321/viafabric/config/VRConfig.java @@ -38,6 +38,7 @@ public class VRConfig extends Config { public static final String ENABLE_CLIENT_SIDE = "enable-client-side"; public static final String CLIENT_SIDE_VERSION = "client-side-version"; public static final String CLIENT_SIDE_FORCE_DISABLE = "client-side-force-disable"; + public static final String HIDE_BUTTON = "hide-button"; public VRConfig(File configFile) { super(configFile); @@ -79,6 +80,14 @@ public class VRConfig extends Config { return (List) get(CLIENT_SIDE_FORCE_DISABLE, List.class, Collections.emptyList()); } + public void setHideButton(boolean val) { + set(HIDE_BUTTON, val); + } + + public boolean isHideButton() { + return getBoolean(HIDE_BUTTON, false); + } + public boolean isForcedDisable(String line) { return getClientSideForceDisable().contains(line); } diff --git a/src/main/java/com/github/creeper123123321/viafabric/gui/ModMenuConfig.java b/src/main/java/com/github/creeper123123321/viafabric/gui/ModMenuConfig.java new file mode 100644 index 0000000..bcc572a --- /dev/null +++ b/src/main/java/com/github/creeper123123321/viafabric/gui/ModMenuConfig.java @@ -0,0 +1,36 @@ +/* + * MIT License + * + * Copyright (c) 2018- creeper123123321 + * Copyright (c) 2019- contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.github.creeper123123321.viafabric.gui; + +import io.github.prospector.modmenu.api.ConfigScreenFactory; +import io.github.prospector.modmenu.api.ModMenuApi; + +public class ModMenuConfig implements ModMenuApi { + @Override + public ConfigScreenFactory getModConfigScreenFactory() { + return ViaConfigScreen::new; + } +} diff --git a/src/main/java/com/github/creeper123123321/viafabric/gui/ViaConfigScreen.java b/src/main/java/com/github/creeper123123321/viafabric/gui/ViaConfigScreen.java new file mode 100644 index 0000000..5999e2b --- /dev/null +++ b/src/main/java/com/github/creeper123123321/viafabric/gui/ViaConfigScreen.java @@ -0,0 +1,194 @@ +/* + * MIT License + * + * Copyright (c) 2018- creeper123123321 + * Copyright (c) 2019- contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.github.creeper123123321.viafabric.gui; + + +import com.github.creeper123123321.viafabric.ViaFabric; +import com.github.creeper123123321.viafabric.util.ProtocolUtils; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.screen.ConfirmScreen; +import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.gui.screen.ScreenTexts; +import net.minecraft.client.gui.widget.ButtonWidget; +import net.minecraft.client.gui.widget.TextFieldWidget; +import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.text.TranslatableText; +import us.myles.ViaVersion.api.protocol.ProtocolRegistry; + +import java.util.concurrent.CompletableFuture; + +@Environment(EnvType.CLIENT) +public class ViaConfigScreen extends Screen { + private static CompletableFuture latestProtocolSave; + private final Screen parent; + private TextFieldWidget protocolVersion; + + public ViaConfigScreen(Screen parent) { + super(new TranslatableText("gui.viafabric_config.title")); + this.parent = parent; + } + + private static int getProtocolTextColor(boolean valid, boolean supported) { + + if (!valid) { + return 0xff0000; // Red + } else if (!supported) { + return 0xFFA500; // Orange + } + return 0xE0E0E0; // Default + } + + protected void init() { + int entries = 0; + + this.addButton(new ButtonWidget(this.width / 2 - 155 + entries % 2 * 160, + this.height / 6 + 24 * (entries >> 1), + 150, + 20, getClientSideText(), this::onClickClientSide)); + entries++; + + this.addButton(new ButtonWidget(this.width / 2 - 155 + entries % 2 * 160, + this.height / 6 + 24 * (entries >> 1), + 150, + 20, getHideViaButtonText(), this::onHideViaButton)); + entries++; + + protocolVersion = new TextFieldWidget(this.textRenderer, + this.width / 2 - 155 + entries % 2 * 160, + this.height / 6 + 24 * (entries >> 1), + 150, + 20, new TranslatableText("gui.protocol_version_field.name")); + entries++; + + protocolVersion.setTextPredicate(ProtocolUtils::isStartOfProtocolText); + protocolVersion.setChangedListener(this::onChangeVersionField); + int clientSideVersion = ViaFabric.config.getClientSideVersion(); + protocolVersion.setText(ProtocolUtils.getProtocolName(clientSideVersion)); + + this.children.add(protocolVersion); + + //noinspection ConstantConditions + if (entries % 2 == 1) { + entries++; + } + + this.addButton(new ButtonWidget(this.width / 2 - 100, this.height / 6 + 24 * (entries >> 1), 200, 20, ScreenTexts.DONE, (buttonWidget) -> this.client.openScreen(this.parent))); + } + + private void onChangeVersionField(String text) { + protocolVersion.setSuggestion(null); + int newVersion = ViaFabric.config.getClientSideVersion(); + + Integer parsed = ProtocolUtils.parseProtocolId(text); + boolean validProtocol; + + if (parsed != null) { + newVersion = parsed; + validProtocol = true; + } else { + validProtocol = false; + String[] suggestions = ProtocolUtils.getProtocolSuggestions(text); + if (suggestions.length == 1) { + protocolVersion.setSuggestion(suggestions[0].substring(text.length())); + } + } + + protocolVersion.setEditableColor( + getProtocolTextColor(ProtocolUtils.isSupported(newVersion, ProtocolRegistry.SERVER_PROTOCOL), + validProtocol)); + + int finalNewVersion = newVersion; + if (latestProtocolSave == null) latestProtocolSave = CompletableFuture.completedFuture(null); + ViaFabric.config.setClientSideVersion(finalNewVersion); + latestProtocolSave = latestProtocolSave.thenRunAsync(ViaFabric.config::saveConfig, ViaFabric.ASYNC_EXECUTOR); + } + + private void onClickClientSide(ButtonWidget widget) { + if (!ViaFabric.config.isClientSideEnabled()) { + MinecraftClient.getInstance().openScreen(new ConfirmScreen( + answer -> { + MinecraftClient.getInstance().openScreen(this); + if (answer) { + ViaFabric.config.setClientSideEnabled(true); + ViaFabric.config.saveConfig(); + widget.setMessage(getClientSideText()); + } + }, + new TranslatableText("gui.enable_client_side.question"), + new TranslatableText("gui.enable_client_side.warning"), + new TranslatableText("gui.enable_client_side.enable"), + new TranslatableText("gui.cancel") + )); + } else { + ViaFabric.config.setClientSideEnabled(false); + ViaFabric.config.saveConfig(); + } + widget.setMessage(getClientSideText()); + } + + @Override + public void removed() { + ViaFabric.config.saveConfig(); + } + + @Override + public void onClose() { + this.client.openScreen(this.parent); + } + + private TranslatableText getClientSideText() { + return ViaFabric.config.isClientSideEnabled() ? + new TranslatableText("gui.client_side.disable") + : new TranslatableText("gui.client_side.enable"); + } + + private TranslatableText getHideViaButtonText() { + return ViaFabric.config.isHideButton() ? + new TranslatableText("gui.hide_via_button.disable") : new TranslatableText("gui.hide_via_button.enable"); + } + + private void onHideViaButton(ButtonWidget widget) { + ViaFabric.config.setHideButton(!ViaFabric.config.isHideButton()); + ViaFabric.config.saveConfig(); + widget.setMessage(getHideViaButtonText()); + } + + public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) { + this.renderBackground(matrices); + drawCenteredText(matrices, this.textRenderer, this.title, this.width / 2, 20, 16777215); + super.render(matrices, mouseX, mouseY, delta); + protocolVersion.render(matrices, mouseX, mouseY, delta); + } + + @Override + public void tick() { + super.tick(); + protocolVersion.tick(); + } +} + diff --git a/src/main/java/com/github/creeper123123321/viafabric/mixin/client/MixinConnectScreenThread.java b/src/main/java/com/github/creeper123123321/viafabric/mixin/client/MixinConnectScreenThread.java index 896dcd3..dac1ead 100644 --- a/src/main/java/com/github/creeper123123321/viafabric/mixin/client/MixinConnectScreenThread.java +++ b/src/main/java/com/github/creeper123123321/viafabric/mixin/client/MixinConnectScreenThread.java @@ -35,7 +35,7 @@ import java.net.UnknownHostException; @Mixin(targets = "net/minecraft/client/gui/screen/ConnectScreen$1", priority = 2000) // don't know if it will work with MinerParty mod public class MixinConnectScreenThread { - @Redirect(method = "run", at = @At(value = "INVOKE", + @Redirect(method = "run()V", at = @At(value = "INVOKE", target = "Ljava/net/InetAddress;getByName(Ljava/lang/String;)Ljava/net/InetAddress;")) private InetAddress resolveViaFabricAddr(String address) throws UnknownHostException { ViaFabricAddress viaAddr = new ViaFabricAddress().parse(address); diff --git a/src/main/java/com/github/creeper123123321/viafabric/mixin/client/MixinMultiplayerScreen.java b/src/main/java/com/github/creeper123123321/viafabric/mixin/client/MixinMultiplayerScreen.java index 2558799..7b702c0 100644 --- a/src/main/java/com/github/creeper123123321/viafabric/mixin/client/MixinMultiplayerScreen.java +++ b/src/main/java/com/github/creeper123123321/viafabric/mixin/client/MixinMultiplayerScreen.java @@ -26,45 +26,22 @@ package com.github.creeper123123321.viafabric.mixin.client; import com.github.creeper123123321.viafabric.ViaFabric; -import com.github.creeper123123321.viafabric.util.VersionFormatFilter; +import com.github.creeper123123321.viafabric.gui.ViaConfigScreen; import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.screen.ConfirmScreen; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screen.multiplayer.MultiplayerScreen; import net.minecraft.client.gui.widget.ButtonWidget; -import net.minecraft.client.gui.widget.TextFieldWidget; import net.minecraft.client.gui.widget.TexturedButtonWidget; -import net.minecraft.client.util.math.MatrixStack; import net.minecraft.text.Text; import net.minecraft.text.TranslatableText; import net.minecraft.util.Identifier; import org.spongepowered.asm.mixin.Mixin; -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.callback.CallbackInfo; -import us.myles.ViaVersion.api.protocol.ProtocolRegistry; -import us.myles.ViaVersion.api.protocol.ProtocolVersion; - -import java.util.Arrays; -import java.util.List; -import java.util.concurrent.CompletableFuture; -import java.util.stream.Collectors; -import java.util.stream.Stream; @Mixin(MultiplayerScreen.class) public abstract class MixinMultiplayerScreen extends Screen { - @Unique - private TextFieldWidget protocolVersion; - @Unique - private ButtonWidget enableClientSideViaVersion; - @Unique - private boolean validProtocol; - @Unique - private boolean supportedProtocol; - @Unique - private CompletableFuture latestProtocolSave; - protected MixinMultiplayerScreen(Text title, UnsupportedOperationException e) { super(title); throw e; @@ -72,104 +49,15 @@ public abstract class MixinMultiplayerScreen extends Screen { @Inject(method = "init", at = @At("TAIL")) private void onInit(CallbackInfo ci) { - protocolVersion = new TextFieldWidget(this.textRenderer, this.width / 2 + 88, 13, 65, 15, new TranslatableText("gui.protocol_version_field.name")); - protocolVersion.setTextPredicate(new VersionFormatFilter()); - protocolVersion.setChangedListener((text) -> { - protocolVersion.setSuggestion(null); - int newVersion = ViaFabric.config.getClientSideVersion(); - validProtocol = true; - try { - newVersion = Integer.parseInt(text); - } catch (NumberFormatException e) { - ProtocolVersion closest = ProtocolVersion.getClosest(text); - if (closest != null) { - newVersion = closest.getId(); - } else { - validProtocol = false; - List completions = ProtocolVersion.getProtocols().stream() - .map(ProtocolVersion::getName) - .flatMap(str -> Stream.concat( - Arrays.stream(str.split("-")), - Arrays.stream(new String[]{str}) - )) - .distinct() - .filter(ver -> ver.startsWith(text)) - .collect(Collectors.toList()); - if (completions.size() == 1) { - protocolVersion.setSuggestion(completions.get(0).substring(text.length())); - } - } - } - supportedProtocol = isSupported(newVersion); - protocolVersion.setEditableColor(getTextColor()); - int finalNewVersion = newVersion; - if (latestProtocolSave == null) latestProtocolSave = CompletableFuture.completedFuture(null); - latestProtocolSave = latestProtocolSave.thenRunAsync(() -> { - ViaFabric.config.setClientSideVersion(finalNewVersion); - ViaFabric.config.saveConfig(); - }, ViaFabric.ASYNC_EXECUTOR); - }); - int clientSideVersion = ViaFabric.config.getClientSideVersion(); - - protocolVersion.setVisible(ViaFabric.config.isClientSideEnabled()); - - protocolVersion.setText(ProtocolVersion.isRegistered(clientSideVersion) - ? ProtocolVersion.getProtocol(clientSideVersion).getName() - : Integer.toString(clientSideVersion)); - this.children.add(protocolVersion); - - enableClientSideViaVersion = new TexturedButtonWidget(this.width / 2 + 113, 10, + ButtonWidget enableClientSideViaVersion = new TexturedButtonWidget(this.width / 2 + 113, 10, 40, 20, // Size 0, 0, // Start pos of texture 20, // v Hover offset new Identifier("viafabric:textures/gui/widgets.png"), 256, 256, // Texture size - button -> MinecraftClient.getInstance().openScreen(new ConfirmScreen( - answer -> { - MinecraftClient.getInstance().openScreen(this); - if (answer) { - ViaFabric.config.setClientSideEnabled(true); - ViaFabric.config.saveConfig(); - protocolVersion.setVisible(true); - enableClientSideViaVersion.visible = false; - } - }, - new TranslatableText("gui.enable_client_side.question"), - new TranslatableText("gui.enable_client_side.warning"), - new TranslatableText("gui.enable_client_side.enable"), - new TranslatableText("gui.cancel") - )), - new TranslatableText("gui.enable_client_side_button")); - enableClientSideViaVersion.visible = !protocolVersion.isVisible(); + it -> MinecraftClient.getInstance().openScreen(new ViaConfigScreen(this)), + new TranslatableText("gui.via_button")); + if (ViaFabric.config.isHideButton()) enableClientSideViaVersion.visible = false; addButton(enableClientSideViaVersion); } - - @Inject(method = "render", at = { - @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/Screen;render" + - "(Lnet/minecraft/client/util/math/MatrixStack;IIF)V"), - }) - private void onRender(MatrixStack matrices, int int_1, int int_2, float float_1, CallbackInfo ci) { - protocolVersion.render(matrices, int_1, int_2, float_1); - } - - @Inject(method = "tick", at = @At("TAIL")) - private void onTick(CallbackInfo ci) { - protocolVersion.tick(); - } - - @Unique - private int getTextColor() { - if (!validProtocol) { - return 0xff0000; // Red - } else if (!supportedProtocol) { - return 0xFFA500; // Orange - } - return 0xE0E0E0; // Default - } - - @Unique - private boolean isSupported(int protocol) { - return ProtocolRegistry.getProtocolPath(ProtocolRegistry.SERVER_PROTOCOL, protocol) != null - || ProtocolRegistry.SERVER_PROTOCOL == protocol; - } } diff --git a/src/main/java/com/github/creeper123123321/viafabric/mixin/client/MixinServerAddress.java b/src/main/java/com/github/creeper123123321/viafabric/mixin/client/MixinServerAddress.java index 3f83ee9..59ec507 100644 --- a/src/main/java/com/github/creeper123123321/viafabric/mixin/client/MixinServerAddress.java +++ b/src/main/java/com/github/creeper123123321/viafabric/mixin/client/MixinServerAddress.java @@ -34,21 +34,14 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; @Mixin(ServerAddress.class) -public class MixinServerAddress { - @Redirect(method = "parse", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/ServerAddress;resolveSrv(Ljava/lang/String;)Lcom/mojang/datafixers/util/Pair;")) +public abstract class MixinServerAddress { + @Redirect(method = "parse", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/ServerAddress;resolveServer(Ljava/lang/String;)Lcom/mojang/datafixers/util/Pair;")) private static Pair modifySrvAddr(String address) { ViaFabricAddress viaAddr = new ViaFabricAddress().parse(address); if (viaAddr.viaSuffix == null) { - return resolveSrv(address); + return ServerAddress.resolveServer(address); } - Pair resolvedSrv = resolveSrv(viaAddr.realAddress).mapFirst(it -> it.replaceAll("\\.$", "") + "." + viaAddr.viaSuffix); - - return resolvedSrv; - } - - @Shadow - private static Pair resolveSrv(String address) { - throw new IllegalStateException(); + return ServerAddress.resolveServer(viaAddr.realAddress).mapFirst(it -> it.replaceAll("\\.$", "") + "." + viaAddr.viaSuffix); } } diff --git a/src/main/java/com/github/creeper123123321/viafabric/providers/VRVersionProvider.java b/src/main/java/com/github/creeper123123321/viafabric/providers/VRVersionProvider.java index e1311cf..cf0be41 100644 --- a/src/main/java/com/github/creeper123123321/viafabric/providers/VRVersionProvider.java +++ b/src/main/java/com/github/creeper123123321/viafabric/providers/VRVersionProvider.java @@ -28,6 +28,7 @@ package com.github.creeper123123321.viafabric.providers; import com.github.creeper123123321.viafabric.ViaFabric; import com.github.creeper123123321.viafabric.ViaFabricAddress; import com.github.creeper123123321.viafabric.platform.VRClientSideUserConnection; +import com.github.creeper123123321.viafabric.util.ProtocolUtils; import com.google.common.primitives.Ints; import net.fabricmc.loader.api.FabricLoader; import net.minecraft.network.ClientConnection; @@ -83,44 +84,52 @@ public class VRVersionProvider extends VersionProvider { @Override public int getServerProtocol(UserConnection connection) throws Exception { if (connection instanceof VRClientSideUserConnection) { - int clientSideVersion = ViaFabric.config.getClientSideVersion(); + int serverVer = ViaFabric.config.getClientSideVersion(); SocketAddress addr = connection.getChannel().remoteAddress(); if (addr instanceof InetSocketAddress && ViaFabric.config.isClientSideEnabled()) { int addrVersion = new ViaFabricAddress().parse(((InetSocketAddress) addr).getHostName()).protocol; - if (addrVersion != 0) clientSideVersion = addrVersion; + if (addrVersion != 0) serverVer = addrVersion; } - boolean blocked = false; if (connection.getChannel() != null) { ProtocolInfo info = Objects.requireNonNull(connection.getProtocolInfo()); - if (addr instanceof InetSocketAddress && (isDisabled(((InetSocketAddress) addr).getHostString()) - || ((((InetSocketAddress) addr).getAddress() != null) && - (isDisabled(((InetSocketAddress) addr).getAddress().getHostAddress()) - || isDisabled(((InetSocketAddress) addr).getAddress().getHostName()))))) { - blocked = true; - } + boolean blocked = checkAddressBlocked(addr); + boolean supported = ProtocolUtils.isSupported(serverVer, info.getProtocolVersion()); - if (info.getState() == State.STATUS && info.getProtocolVersion() == -1 - && (clientSideVersion != -1 || blocked) - && connection.getChannel().pipeline().get(ClientConnection.class).getPacketListener() - .getClass().getName().startsWith("net.earthcomputer.multiconnect")) { // multiconnect version detector - int multiconnectSuggestion = getVersionForMulticonnect(clientSideVersion); - if (blocked) multiconnectSuggestion = -1; - ViaFabric.JLOGGER.info("Sending " + ProtocolVersion.getProtocol(multiconnectSuggestion) + " for multiconnect version detector"); - PacketWrapper newAnswer = new PacketWrapper(0x00, null, connection); - newAnswer.write(Type.STRING, "{\"version\":{\"name\":\"viafabric integration\",\"protocol\":" + multiconnectSuggestion + "}}"); - newAnswer.send(info.getPipeline().contains(BaseProtocol1_16.class) ? BaseProtocol1_16.class : BaseProtocol1_7.class); - throw CancelException.generate(); - } - if (clientSideVersion == -1 || blocked) return info.getProtocolVersion(); + handleMulticonnectPing(connection, info, blocked, supported, serverVer); + + if (serverVer == -1 || blocked) return info.getProtocolVersion(); } - return clientSideVersion; + return serverVer; } return super.getServerProtocol(connection); } + private boolean checkAddressBlocked(SocketAddress addr) { + return addr instanceof InetSocketAddress && (isDisabled(((InetSocketAddress) addr).getHostString()) + || ((((InetSocketAddress) addr).getAddress() != null) && + (isDisabled(((InetSocketAddress) addr).getAddress().getHostAddress()) + || isDisabled(((InetSocketAddress) addr).getAddress().getHostName())))); + } + + private void handleMulticonnectPing(UserConnection connection, ProtocolInfo info, boolean blocked, boolean supported, int serverVer) throws Exception { + if (info.getState() == State.STATUS + && info.getProtocolVersion() == -1 + && connection.getChannel().pipeline().get(ClientConnection.class).getPacketListener() + .getClass().getName().startsWith("net.earthcomputer.multiconnect") // multiconnect version detector + && (supported || blocked)) { // Intercept the connection + int multiconnectSuggestion = getVersionForMulticonnect(serverVer); + if (blocked) multiconnectSuggestion = -1; + ViaFabric.JLOGGER.info("Sending " + ProtocolVersion.getProtocol(multiconnectSuggestion) + " for multiconnect version detector"); + PacketWrapper newAnswer = new PacketWrapper(0x00, null, connection); + newAnswer.write(Type.STRING, "{\"version\":{\"name\":\"viafabric integration\",\"protocol\":" + multiconnectSuggestion + "}}"); + newAnswer.send(info.getPipeline().contains(BaseProtocol1_16.class) ? BaseProtocol1_16.class : BaseProtocol1_7.class); + throw CancelException.generate(); + } + } + private int getVersionForMulticonnect(int clientSideVersion) { // https://github.com/ViaVersion/ViaVersion/blob/master/velocity/src/main/java/us/myles/ViaVersion/velocity/providers/VelocityVersionProvider.java // multiconnect supports it diff --git a/src/main/java/com/github/creeper123123321/viafabric/util/VersionFormatFilter.java b/src/main/java/com/github/creeper123123321/viafabric/util/ProtocolUtils.java similarity index 61% rename from src/main/java/com/github/creeper123123321/viafabric/util/VersionFormatFilter.java rename to src/main/java/com/github/creeper123123321/viafabric/util/ProtocolUtils.java index a076a66..2ab326a 100644 --- a/src/main/java/com/github/creeper123123321/viafabric/util/VersionFormatFilter.java +++ b/src/main/java/com/github/creeper123123321/viafabric/util/ProtocolUtils.java @@ -25,15 +25,24 @@ package com.github.creeper123123321.viafabric.util; +import us.myles.ViaVersion.api.protocol.ProtocolRegistry; import us.myles.ViaVersion.api.protocol.ProtocolVersion; import java.util.Arrays; -import java.util.function.Predicate; import java.util.stream.Stream; -public class VersionFormatFilter implements Predicate { - @Override - public boolean test(String s) { +public class ProtocolUtils { + public static boolean isSupported(int server, int client) { + return server == client || ProtocolRegistry.getProtocolPath(client, server) != null; + } + + public static String getProtocolName(int id) { + ProtocolVersion ver = ProtocolVersion.getProtocol(id); + if (ver == null) return Integer.toString(id); + return ver.getName(); + } + + public static boolean isStartOfProtocolText(String s) { try { Integer.parseInt(s); return true; @@ -52,4 +61,26 @@ public class VersionFormatFilter implements Predicate { } } } + + public static Integer parseProtocolId(String s) { + try { + return Integer.parseInt(s); + } catch (NumberFormatException ignored) { + ProtocolVersion closest = ProtocolVersion.getClosest(s); + if (closest == null) return null; + return closest.getId(); + } + } + + public static String[] getProtocolSuggestions(String text) { + return ProtocolVersion.getProtocols().stream() + .map(ProtocolVersion::getName) + .flatMap(str -> Stream.concat( + Arrays.stream(str.split("-")), + Arrays.stream(new String[]{str}) + )) + .distinct() + .filter(ver -> ver.startsWith(text)) + .toArray(String[]::new); + } } diff --git a/src/main/resources/assets/viafabric/config.yml b/src/main/resources/assets/viafabric/config.yml index 186e22f..84481c4 100644 --- a/src/main/resources/assets/viafabric/config.yml +++ b/src/main/resources/assets/viafabric/config.yml @@ -4,7 +4,9 @@ enable-client-side: false # This option sets the protocol version to be used when connection to the server (can also be changed in-game) client-side-version: -1 -# List of servers which ViaFabric will force disabling transforming on client-side. +# Hides VIA button from multiplayer menu. +hide-button: false +# List of servers which ViaFabric will force disabling transforming on client-side. It can be overwritten by setting per-server version. # This isn't always the address in multiplayer GUI. It will use the SRV record pointer when present. Check the game log for the address. # Uses https://wiki.vg/Mojang_API#Blocked_Servers format (mc.example.com, *.example.com, 192.168.0.1, 192.168.*) client-side-force-disable: ["hypixel.net", "*.hypixel.net", "hivemc.com", "*.hivemc.com", "hivemc.eu", "*.hivemc.eu"] \ No newline at end of file diff --git a/src/main/resources/assets/viafabric/lang/en_us.json b/src/main/resources/assets/viafabric/lang/en_us.json index 819cdb6..8edaadf 100644 --- a/src/main/resources/assets/viafabric/lang/en_us.json +++ b/src/main/resources/assets/viafabric/lang/en_us.json @@ -3,5 +3,12 @@ "gui.enable_client_side_button": "Enable ViaVersion", "gui.enable_client_side.question": "Are you sure you want to enable client-side mode?", "gui.enable_client_side.warning": "I cannot guarantee that this mod is allowed on every (or even any) server. This mod may cause problems with anti-cheat plugins. USE AT OWN RISK.", - "gui.enable_client_side.enable": "Enable" + "gui.enable_client_side.enable": "Enable", + "gui.viafabric_config.title": "ViaFabric Configurations", + "gui.client_side.enable": "Enable client-side", + "gui.client_side.disable": "Disable client-side", + "gui.ping_version.translated": "VIA: %s", + "gui.hide_via_button.enable": "Hide VIA button", + "gui.hide_via_button.disable": "Show VIA button", + "gui.via_button": "VIA" } \ No newline at end of file diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index db80008..db12c48 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -63,6 +63,9 @@ ], "cotton-client-commands": [ "com.github.creeper123123321.viafabric.commands.VRClientCommands" + ], + "modmenu": [ + "com.github.creeper123123321.viafabric.gui.ModMenuConfig" ] }, "depends": { @@ -81,5 +84,6 @@ "icon": "assets/viafabric/textures/logo.png", "mixins": [ "mixins.viafabric.json" - ] + ], + "accessWidener": "viafabric.accesswidener" } diff --git a/src/main/resources/viafabric.accesswidener b/src/main/resources/viafabric.accesswidener new file mode 100644 index 0000000..f8fde9e --- /dev/null +++ b/src/main/resources/viafabric.accesswidener @@ -0,0 +1,4 @@ +accessWidener v1 named + +# @Shadow bug workaround https://github.com/FabricMC/fabric-loom/issues/279 +accessible method net/minecraft/network/ServerAddress resolveServer (Ljava/lang/String;)Lcom/mojang/datafixers/util/Pair; \ No newline at end of file