From cba6030dc1bda46c1282175efaaff87086e14bf8 Mon Sep 17 00:00:00 2001 From: FlorianMichael <60033407+FlorianMichael@users.noreply.github.com> Date: Thu, 20 Apr 2023 22:16:45 +0200 Subject: [PATCH] updated Via* (23w16a) --- .github/workflows/main.yml | 2 +- build.gradle | 12 +-- gradle.properties | 13 +-- settings.gradle | 1 - .../de/florianmichael/viaforge/ViaForge.java | 79 ++++++------------- .../viaforge/ViaForgeVLBPipeline.java | 47 +++++++++++ .../{ => gui}/GuiProtocolSelector.java | 33 ++++++-- .../viaforge/mixin/MixinLoader.java | 17 ++++ ...uiMainMenuGuiMultiplayerGuiServerList.java | 19 ++++- .../viaforge/mixin/impl/MixinMinecraft.java | 17 ++++ .../mixin/impl/MixinNetworkManager.java | 21 ++++- .../mixin/impl/MixinNetworkManagerSub5.java | 33 -------- .../mixin/impl/MixinNetworkManager_5.java | 45 +++++++++++ src/main/resources/mixins.viaforge.json | 28 +++---- 14 files changed, 241 insertions(+), 126 deletions(-) create mode 100644 src/main/java/de/florianmichael/viaforge/ViaForgeVLBPipeline.java rename src/main/java/de/florianmichael/viaforge/{ => gui}/GuiProtocolSelector.java (64%) delete mode 100644 src/main/java/de/florianmichael/viaforge/mixin/impl/MixinNetworkManagerSub5.java create mode 100644 src/main/java/de/florianmichael/viaforge/mixin/impl/MixinNetworkManager_5.java diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 32830dc..6e77860 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -28,5 +28,5 @@ jobs: if: ${{ runner.os == 'Linux' && matrix.java == '8' }} uses: actions/upload-artifact@v2 with: - name: ViaForge-1.12.2 + name: ViaForge-1.8.9 path: build/libs/ diff --git a/build.gradle b/build.gradle index 22d7429..be200e3 100644 --- a/build.gradle +++ b/build.gradle @@ -1,8 +1,9 @@ buildscript { repositories { mavenCentral() - maven { url = "https://repo.viaversion.com" } + maven { url = "https://maven.minecraftforge.net/" } maven { url = "https://repo.spongepowered.org/repository/maven-public/" } + maven { url = "https://repo.viaversion.com" } maven { url = "https://jitpack.io/" } } @@ -28,9 +29,9 @@ compileJava.options.encoding = 'UTF-8' repositories { mavenCentral() - maven { url = "https://repo.viaversion.com" } maven { url = "https://maven.minecraftforge.net/" } maven { url = "https://repo.spongepowered.org/repository/maven-public/" } + maven { url = "https://repo.viaversion.com" } maven { url = "https://jitpack.io/" } } @@ -53,14 +54,13 @@ configurations { implementation.extendsFrom(include) } -// ViaProtocolHack READ-ME def viaLibs = [ "com.viaversion:viaversion:${project.viaversion_version}", "com.viaversion:viabackwards:${project.viabackwards_version}", "com.viaversion:viarewind-core:${project.viarewind_version}", - "org.yaml:snakeyaml:1.29", + "org.yaml:snakeyaml:${project.snake_yml_version}", - "com.github.RejectedVia:ViaProtocolHack:${project.viaprotocolhack_version}" + "com.github.FlorianMichael:ViaLoadingBase:${project.vialoadingbase_version}" ] dependencies { @@ -133,4 +133,4 @@ reobf { shadowJar {} } -jar.dependsOn("shadowJar") \ No newline at end of file +jar.dependsOn("shadowJar") diff --git a/gradle.properties b/gradle.properties index 6866490..f23571a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,14 +5,15 @@ org.gradle.daemon=false # forge mod_id=viaforge mod_name=ViaForge -mod_version=2.0.0 -mod_base_package=de.enzaxd +mod_version=3.1.0 +mod_base_package=de.florianmichael # mixin mixin_version=0.8.3 # via-version -viaprotocolhack_version=ba5dcf9ce6 -viaversion_version=4.5.2-SNAPSHOT -viabackwards_version=4.5.2-SNAPSHOT -viarewind_version=2.0.2-SNAPSHOT +vialoadingbase_version=ff86e681d7 +viaversion_version=4.7.0-23w16a-SNAPSHOT +viabackwards_version=4.7.0-23w16a-SNAPSHOT +viarewind_version=2.0.4-SNAPSHOT +snake_yml_version=2.0 diff --git a/settings.gradle b/settings.gradle index e032b8d..5f0a7df 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,3 +1,2 @@ rootProject.name = "ViaForge" -include 'mc1122' diff --git a/src/main/java/de/florianmichael/viaforge/ViaForge.java b/src/main/java/de/florianmichael/viaforge/ViaForge.java index 835d5f0..7ee83de 100644 --- a/src/main/java/de/florianmichael/viaforge/ViaForge.java +++ b/src/main/java/de/florianmichael/viaforge/ViaForge.java @@ -1,63 +1,34 @@ +/* + * This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge + * Copyright (C) 2021-2023 FlorianMichael/EnZaXD and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package de.florianmichael.viaforge; -import com.viaversion.viaversion.libs.gson.JsonObject; -import de.florianmichael.viaprotocolhack.INativeProvider; -import de.florianmichael.viaprotocolhack.ViaProtocolHack; -import io.netty.channel.EventLoop; -import io.netty.channel.local.LocalEventLoopGroup; +import de.florianmichael.vialoadingbase.ViaLoadingBase; import net.minecraft.client.Minecraft; import net.minecraft.realms.RealmsSharedConstants; -import java.io.File; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.ThreadFactory; - -public class ViaForge implements INativeProvider { - - public static int targetVersion = RealmsSharedConstants.NETWORK_PROTOCOL_VERSION; +public class ViaForge { public static void start() { - try { - ViaProtocolHack.instance().init(new ViaForge(), () -> System.out.println("ViaProtocolHack loaded successfully")); - } catch (Exception ignored) { - } - } - - @Override - public boolean isSinglePlayer() { - return Minecraft.getMinecraft().isSingleplayer(); - } - - @Override - public int nativeVersion() { - return RealmsSharedConstants.NETWORK_PROTOCOL_VERSION; - } - - @Override - public int targetVersion() { - return targetVersion; - } - - @Override - public String[] nettyOrder() { - return new String[] { - "decompress", - "compress" - }; - } - - @Override - public File run() { - return Minecraft.getMinecraft().mcDataDir; - } - - @Override - public JsonObject createDump() { - return new JsonObject(); - } - - @Override - public EventLoop eventLoop(ThreadFactory threadFactory, ExecutorService executorService) { - return new LocalEventLoopGroup(1, threadFactory).next(); + ViaLoadingBase.ViaLoadingBaseBuilder. + create(). + runDirectory(Minecraft.getMinecraft().mcDataDir). + nativeVersion(RealmsSharedConstants.NETWORK_PROTOCOL_VERSION). + forceNativeVersionCondition(() -> Minecraft.getMinecraft().isSingleplayer()). + build(); } } diff --git a/src/main/java/de/florianmichael/viaforge/ViaForgeVLBPipeline.java b/src/main/java/de/florianmichael/viaforge/ViaForgeVLBPipeline.java new file mode 100644 index 0000000..d0bdec2 --- /dev/null +++ b/src/main/java/de/florianmichael/viaforge/ViaForgeVLBPipeline.java @@ -0,0 +1,47 @@ +/* + * This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge + * Copyright (C) 2021-2023 FlorianMichael/EnZaXD and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package de.florianmichael.viaforge; + +import com.viaversion.viaversion.api.connection.UserConnection; +import de.florianmichael.vialoadingbase.netty.VLBPipeline; + +public class ViaForgeVLBPipeline extends VLBPipeline { + public ViaForgeVLBPipeline(UserConnection info) { + super(info); + } + + @Override + public String getDecoderHandlerName() { + return "decoder"; + } + + @Override + public String getEncoderHandlerName() { + return "encoder"; + } + + @Override + public String getDecompressionHandlerName() { + return "decompress"; + } + + @Override + public String getCompressionHandlerName() { + return "compress"; + } +} diff --git a/src/main/java/de/florianmichael/viaforge/GuiProtocolSelector.java b/src/main/java/de/florianmichael/viaforge/gui/GuiProtocolSelector.java similarity index 64% rename from src/main/java/de/florianmichael/viaforge/GuiProtocolSelector.java rename to src/main/java/de/florianmichael/viaforge/gui/GuiProtocolSelector.java index c947369..3866138 100644 --- a/src/main/java/de/florianmichael/viaforge/GuiProtocolSelector.java +++ b/src/main/java/de/florianmichael/viaforge/gui/GuiProtocolSelector.java @@ -1,8 +1,25 @@ -package de.florianmichael.viaforge; +/* + * This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge + * Copyright (C) 2021-2023 FlorianMichael/EnZaXD and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package de.florianmichael.viaforge.gui; import com.mojang.realmsclient.gui.ChatFormatting; import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; -import de.florianmichael.viaprotocolhack.util.VersionList; +import de.florianmichael.vialoadingbase.ViaLoadingBase; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; @@ -13,9 +30,9 @@ import java.io.IOException; public class GuiProtocolSelector extends GuiScreen { - public SlotList list; + private final GuiScreen parent; - private GuiScreen parent; + public SlotList list; public GuiProtocolSelector(GuiScreen parent) { this.parent = parent; @@ -68,12 +85,12 @@ public class GuiProtocolSelector extends GuiScreen { @Override protected int getSize() { - return VersionList.getProtocols().size(); + return ViaLoadingBase.getProtocols().size(); } @Override protected void elementClicked(int i, boolean b, int i1, int i2) { - ViaForge.targetVersion = VersionList.getProtocols().get(i).getVersion(); + ViaLoadingBase.getInstance().reload(ViaLoadingBase.getProtocols().get(i)); } @Override @@ -88,9 +105,9 @@ public class GuiProtocolSelector extends GuiScreen { @Override protected void drawSlot(int i, int i1, int i2, int i3, int i4, int i5) { - final ProtocolVersion version = VersionList.getProtocols().get(i); + final ProtocolVersion version = ViaLoadingBase.getProtocols().get(i); - drawCenteredString(mc.fontRendererObj,(ViaForge.targetVersion == version.getVersion() ? ChatFormatting.GREEN.toString() : ChatFormatting.DARK_RED.toString()) + version.getName(), width / 2, i2, -1); + drawCenteredString(mc.fontRendererObj, (ViaLoadingBase.getInstance().getTargetVersion().getVersion() == version.getVersion() ? ChatFormatting.GREEN.toString() : ChatFormatting.DARK_RED.toString()) + version.getName(), width / 2, i2, -1); } } } diff --git a/src/main/java/de/florianmichael/viaforge/mixin/MixinLoader.java b/src/main/java/de/florianmichael/viaforge/mixin/MixinLoader.java index e4b66a7..215a971 100644 --- a/src/main/java/de/florianmichael/viaforge/mixin/MixinLoader.java +++ b/src/main/java/de/florianmichael/viaforge/mixin/MixinLoader.java @@ -1,3 +1,20 @@ +/* + * This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge + * Copyright (C) 2021-2023 FlorianMichael/EnZaXD and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package de.florianmichael.viaforge.mixin; import net.minecraftforge.fml.relauncher.IFMLLoadingPlugin; diff --git a/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinGuiMainMenuGuiMultiplayerGuiServerList.java b/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinGuiMainMenuGuiMultiplayerGuiServerList.java index 22bdf39..7cd1a25 100644 --- a/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinGuiMainMenuGuiMultiplayerGuiServerList.java +++ b/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinGuiMainMenuGuiMultiplayerGuiServerList.java @@ -1,6 +1,23 @@ +/* + * This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge + * Copyright (C) 2021-2023 FlorianMichael/EnZaXD and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package de.florianmichael.viaforge.mixin.impl; -import de.florianmichael.viaforge.GuiProtocolSelector; +import de.florianmichael.viaforge.gui.GuiProtocolSelector; import net.minecraft.client.gui.*; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; diff --git a/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinMinecraft.java b/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinMinecraft.java index ef170fe..0587739 100644 --- a/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinMinecraft.java +++ b/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinMinecraft.java @@ -1,3 +1,20 @@ +/* + * This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge + * Copyright (C) 2021-2023 FlorianMichael/EnZaXD and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package de.florianmichael.viaforge.mixin.impl; import de.florianmichael.viaforge.ViaForge; diff --git a/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinNetworkManager.java b/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinNetworkManager.java index df31e99..7b23ae2 100644 --- a/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinNetworkManager.java +++ b/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinNetworkManager.java @@ -1,6 +1,23 @@ +/* + * This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge + * Copyright (C) 2021-2023 FlorianMichael/EnZaXD and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package de.florianmichael.viaforge.mixin.impl; -import de.florianmichael.viaprotocolhack.event.PipelineReorderEvent; +import de.florianmichael.vialoadingbase.netty.event.CompressionReorderEvent; import io.netty.channel.Channel; import net.minecraft.network.NetworkManager; import org.spongepowered.asm.mixin.Mixin; @@ -16,6 +33,6 @@ public class MixinNetworkManager { @Inject(method = "setCompressionTreshold", at = @At("RETURN")) public void reOrderPipeline(int p_setCompressionTreshold_1_, CallbackInfo ci) { - channel.pipeline().fireUserEventTriggered(new PipelineReorderEvent()); + channel.pipeline().fireUserEventTriggered(new CompressionReorderEvent()); } } diff --git a/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinNetworkManagerSub5.java b/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinNetworkManagerSub5.java deleted file mode 100644 index 80c0dcc..0000000 --- a/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinNetworkManagerSub5.java +++ /dev/null @@ -1,33 +0,0 @@ -package de.florianmichael.viaforge.mixin.impl; - -import com.viaversion.viaversion.api.connection.UserConnection; -import com.viaversion.viaversion.connection.UserConnectionImpl; -import com.viaversion.viaversion.protocol.ProtocolPipelineImpl; -import de.florianmichael.viaforge.ViaForge; -import de.florianmichael.viaprotocolhack.netty.CustomViaDecodeHandler; -import de.florianmichael.viaprotocolhack.netty.CustomViaEncodeHandler; -import de.florianmichael.viaprotocolhack.netty.NettyConstants; -import io.netty.channel.Channel; -import io.netty.channel.socket.SocketChannel; -import net.minecraft.realms.RealmsSharedConstants; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(targets = "net.minecraft.network.NetworkManager$5") -public class MixinNetworkManagerSub5 { - - @Inject(method = "initChannel", at = @At(value = "TAIL"), remap = false) - private void onInitChannel(Channel channel, CallbackInfo ci) { - if (channel instanceof SocketChannel && ViaForge.targetVersion != RealmsSharedConstants.NETWORK_PROTOCOL_VERSION) { - - UserConnection user = new UserConnectionImpl(channel, true); - new ProtocolPipelineImpl(user); - - channel.pipeline() - .addBefore("encoder", NettyConstants.HANDLER_ENCODER_NAME, new CustomViaEncodeHandler(user)) - .addBefore("decoder", NettyConstants.HANDLER_DECODER_NAME, new CustomViaDecodeHandler(user)); - } - } -} diff --git a/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinNetworkManager_5.java b/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinNetworkManager_5.java new file mode 100644 index 0000000..9e27abe --- /dev/null +++ b/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinNetworkManager_5.java @@ -0,0 +1,45 @@ +/* + * This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge + * Copyright (C) 2021-2023 FlorianMichael/EnZaXD and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package de.florianmichael.viaforge.mixin.impl; + +import com.viaversion.viaversion.api.connection.UserConnection; +import com.viaversion.viaversion.connection.UserConnectionImpl; +import com.viaversion.viaversion.protocol.ProtocolPipelineImpl; +import de.florianmichael.viaforge.ViaForgeVLBPipeline; +import de.florianmichael.vialoadingbase.ViaLoadingBase; +import io.netty.channel.Channel; +import io.netty.channel.socket.SocketChannel; +import net.minecraft.realms.RealmsSharedConstants; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(targets = "net.minecraft.network.NetworkManager$5") +public class MixinNetworkManager_5 { + + @Inject(method = "initChannel", at = @At(value = "TAIL"), remap = false) + private void onInitChannel(Channel channel, CallbackInfo ci) { + if (channel instanceof SocketChannel && ViaLoadingBase.getInstance().getTargetVersion().getVersion() != RealmsSharedConstants.NETWORK_PROTOCOL_VERSION) { + final UserConnection user = new UserConnectionImpl(channel, true); + new ProtocolPipelineImpl(user); + + channel.pipeline().addLast(new ViaForgeVLBPipeline(user)); + } + } +} diff --git a/src/main/resources/mixins.viaforge.json b/src/main/resources/mixins.viaforge.json index c57cc0d..c87fcbc 100644 --- a/src/main/resources/mixins.viaforge.json +++ b/src/main/resources/mixins.viaforge.json @@ -1,16 +1,16 @@ { - "required": true, - "minVersion": "0.7.5", - "compatibilityLevel": "JAVA_8", - "package": "de.florianmichael.viaforge.mixin.impl", - "refmap": "mixins.viaforge.refmap.json", - "mixins": [ - "MixinNetworkManager", - "MixinNetworkManagerSub5" - ], - "verbose": true, - "client": [ - "MixinGuiMainMenuGuiMultiplayerGuiServerList", - "MixinMinecraft" - ] + "required": true, + "minVersion": "0.7.5", + "compatibilityLevel": "JAVA_8", + "package": "de.florianmichael.viaforge.mixin.impl", + "refmap": "mixins.viaforge.refmap.json", + "mixins": [ + "MixinNetworkManager", + "MixinNetworkManager_5" + ], + "verbose": true, + "client": [ + "MixinGuiMainMenuGuiMultiplayerGuiServerList", + "MixinMinecraft" + ] }