From 66ebce7d47bdc84a07cb1db009215eab0a6d51c3 Mon Sep 17 00:00:00 2001 From: creeper123123321 Date: Sun, 7 Oct 2018 10:02:28 -0300 Subject: [PATCH] Remove ViaRift.fakeServerVersion, use git version, add version detector --- build.gradle | 3 +- .../creeper123123321/viarift/ViaRift.java | 10 +++-- .../gui/multiplayer/SaveProtocolButton.java | 6 +-- .../IPatchedCPacketHandshake.java} | 13 ++---- .../mixin/client/MixinCPacketHandshake.java | 40 +++++++++++++++++++ .../mixin/client/MixinGuiMultiplayer.java | 4 +- .../viarift/platform/VRInjector.java | 16 +++++--- .../viarift/platform/VRLoader.java | 3 -- .../resources/assets/viarift/.modassetsroot | 0 src/main/resources/mixins.viarift.main.json | 3 +- 10 files changed, 70 insertions(+), 28 deletions(-) rename src/main/java/com/github/creeper123123321/viarift/{provider/VRVersionProvider.java => interfaces/IPatchedCPacketHandshake.java} (73%) create mode 100644 src/main/java/com/github/creeper123123321/viarift/mixin/client/MixinCPacketHandshake.java delete mode 100644 src/main/resources/assets/viarift/.modassetsroot diff --git a/build.gradle b/build.gradle index 8613a8e..31ad90d 100644 --- a/build.gradle +++ b/build.gradle @@ -12,6 +12,7 @@ buildscript { plugins { id 'net.minecrell.licenser' version '0.4.1' + id 'com.palantir.git-version' version '0.12.0-rc2' } apply plugin: 'net.minecraftforge.gradle.tweaker-client' @@ -19,7 +20,7 @@ apply plugin: 'org.spongepowered.mixin' apply plugin: 'java' group 'com.github.creeper123123321.viarift' -version '1.0.1' +version gitVersion() archivesBaseName = 'ViaRift' sourceCompatibility = 1.8 diff --git a/src/main/java/com/github/creeper123123321/viarift/ViaRift.java b/src/main/java/com/github/creeper123123321/viarift/ViaRift.java index 07c342c..9bef991 100644 --- a/src/main/java/com/github/creeper123123321/viarift/ViaRift.java +++ b/src/main/java/com/github/creeper123123321/viarift/ViaRift.java @@ -34,21 +34,25 @@ import io.netty.channel.EventLoop; import net.minecraft.util.NamedThreadFactory; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.dimdev.rift.listener.MinecraftStartListener; import org.dimdev.riftloader.listener.InitializationListener; import org.spongepowered.asm.launch.MixinBootstrap; import org.spongepowered.asm.mixin.Mixins; import us.myles.ViaVersion.ViaManager; import us.myles.ViaVersion.api.Via; -public class ViaRift implements InitializationListener { - public static int fakeServerVersion = -1; - public static final Logger LOGGER = LogManager.getLogger(); +public class ViaRift implements InitializationListener, MinecraftStartListener { + public static final Logger LOGGER = LogManager.getLogger("ViaRift"); public static final java.util.logging.Logger JLOGGER = new JLoggerToLog4j(LOGGER); public static final EventLoop EVENT_LOOP = new DefaultEventLoop(new NamedThreadFactory("ViaRift")); @Override public void onInitialization() { MixinBootstrap.init(); Mixins.addConfiguration("mixins.viarift.main.json"); + } + + @Override + public void onMinecraftStart() { Via.init(ViaManager.builder() .injector(new VRInjector()) .loader(new VRLoader()) diff --git a/src/main/java/com/github/creeper123123321/viarift/gui/multiplayer/SaveProtocolButton.java b/src/main/java/com/github/creeper123123321/viarift/gui/multiplayer/SaveProtocolButton.java index 9d1614e..df58c8b 100644 --- a/src/main/java/com/github/creeper123123321/viarift/gui/multiplayer/SaveProtocolButton.java +++ b/src/main/java/com/github/creeper123123321/viarift/gui/multiplayer/SaveProtocolButton.java @@ -24,9 +24,9 @@ package com.github.creeper123123321.viarift.gui.multiplayer; -import com.github.creeper123123321.viarift.ViaRift; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiTextField; +import us.myles.ViaVersion.api.protocol.ProtocolRegistry; public class SaveProtocolButton extends GuiButton { private GuiTextField textField; @@ -40,9 +40,9 @@ public class SaveProtocolButton extends GuiButton { public void mousePressed(double p_mouseClicked_1_, double p_mouseClicked_3_) { super.mousePressed(p_mouseClicked_1_, p_mouseClicked_3_); try { - ViaRift.fakeServerVersion = Integer.parseInt(textField.getText()); + ProtocolRegistry.SERVER_PROTOCOL = Integer.parseInt(textField.getText()); } catch (NumberFormatException e) { - textField.setText(Integer.toString(ViaRift.fakeServerVersion)); + textField.setText(Integer.toString(ProtocolRegistry.SERVER_PROTOCOL)); } } } diff --git a/src/main/java/com/github/creeper123123321/viarift/provider/VRVersionProvider.java b/src/main/java/com/github/creeper123123321/viarift/interfaces/IPatchedCPacketHandshake.java similarity index 73% rename from src/main/java/com/github/creeper123123321/viarift/provider/VRVersionProvider.java rename to src/main/java/com/github/creeper123123321/viarift/interfaces/IPatchedCPacketHandshake.java index 3e25189..5942dc2 100644 --- a/src/main/java/com/github/creeper123123321/viarift/provider/VRVersionProvider.java +++ b/src/main/java/com/github/creeper123123321/viarift/interfaces/IPatchedCPacketHandshake.java @@ -22,15 +22,8 @@ * SOFTWARE. */ -package com.github.creeper123123321.viarift.provider; +package com.github.creeper123123321.viarift.interfaces; -import com.github.creeper123123321.viarift.ViaRift; -import us.myles.ViaVersion.api.data.UserConnection; -import us.myles.ViaVersion.protocols.base.VersionProvider; - -public class VRVersionProvider extends VersionProvider { - @Override - public int getServerProtocol(UserConnection connection) throws Exception { - return ViaRift.fakeServerVersion; - } +public interface IPatchedCPacketHandshake { + int getProtocolVersion(); } diff --git a/src/main/java/com/github/creeper123123321/viarift/mixin/client/MixinCPacketHandshake.java b/src/main/java/com/github/creeper123123321/viarift/mixin/client/MixinCPacketHandshake.java new file mode 100644 index 0000000..93673b2 --- /dev/null +++ b/src/main/java/com/github/creeper123123321/viarift/mixin/client/MixinCPacketHandshake.java @@ -0,0 +1,40 @@ +/* + * MIT License + * + * Copyright (c) 2018 creeper123123321 and 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.viarift.mixin.client; + +import com.github.creeper123123321.viarift.interfaces.IPatchedCPacketHandshake; +import net.minecraft.network.handshake.client.CPacketHandshake; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; + +@Mixin(CPacketHandshake.class) +public class MixinCPacketHandshake implements IPatchedCPacketHandshake { + @Shadow private int protocolVersion; + + @Override + public int getProtocolVersion() { + return protocolVersion; + } +} diff --git a/src/main/java/com/github/creeper123123321/viarift/mixin/client/MixinGuiMultiplayer.java b/src/main/java/com/github/creeper123123321/viarift/mixin/client/MixinGuiMultiplayer.java index 79ef056..f85d4ab 100644 --- a/src/main/java/com/github/creeper123123321/viarift/mixin/client/MixinGuiMultiplayer.java +++ b/src/main/java/com/github/creeper123123321/viarift/mixin/client/MixinGuiMultiplayer.java @@ -24,7 +24,6 @@ package com.github.creeper123123321.viarift.mixin.client; -import com.github.creeper123123321.viarift.ViaRift; import com.github.creeper123123321.viarift.gui.multiplayer.SaveProtocolButton; import com.github.creeper123123321.viarift.util.IntegerFormatFilter; import net.minecraft.client.gui.*; @@ -34,6 +33,7 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import us.myles.ViaVersion.api.protocol.ProtocolRegistry; @Mixin(GuiMultiplayer.class) public abstract class MixinGuiMultiplayer extends GuiScreen { @@ -43,7 +43,7 @@ public abstract class MixinGuiMultiplayer extends GuiScreen { @Inject(method = "initGui", at = @At("TAIL")) private void onInitGui(CallbackInfo ci) { protocolVersion = new GuiTextField(1235, fontRenderer, this.width / 2 + 70, 8, 30, 20); - protocolVersion.setText(Integer.toString(ViaRift.fakeServerVersion)); + protocolVersion.setText(Integer.toString(ProtocolRegistry.SERVER_PROTOCOL)); protocolVersion.func_200675_a(new IntegerFormatFilter()); this.eventListeners.add(protocolVersion); saveProtocol = new SaveProtocolButton(6356, width / 2 + 100, 8, 50, 20, diff --git a/src/main/java/com/github/creeper123123321/viarift/platform/VRInjector.java b/src/main/java/com/github/creeper123123321/viarift/platform/VRInjector.java index 398401c..fba0c5f 100644 --- a/src/main/java/com/github/creeper123123321/viarift/platform/VRInjector.java +++ b/src/main/java/com/github/creeper123123321/viarift/platform/VRInjector.java @@ -24,23 +24,29 @@ package com.github.creeper123123321.viarift.platform; -import com.github.creeper123123321.viarift.ViaRift; +import com.github.creeper123123321.viarift.interfaces.IPatchedCPacketHandshake; +import net.minecraft.network.EnumConnectionState; +import net.minecraft.network.handshake.client.CPacketHandshake; import us.myles.ViaVersion.api.platform.ViaInjector; public class VRInjector implements ViaInjector { @Override - public void inject() throws Exception { + public void inject() { // *looks at Mixins* } @Override - public void uninject() throws Exception { + public void uninject() { // not possible *plays sad violin* } @Override - public int getServerProtocolVersion() throws Exception { - return ViaRift.fakeServerVersion; + public int getServerProtocolVersion() { + return ((IPatchedCPacketHandshake) new CPacketHandshake( + "XGH to get protocol", + 0, + EnumConnectionState.HANDSHAKING) + ).getProtocolVersion(); } @Override diff --git a/src/main/java/com/github/creeper123123321/viarift/platform/VRLoader.java b/src/main/java/com/github/creeper123123321/viarift/platform/VRLoader.java index b3f2877..f44e391 100644 --- a/src/main/java/com/github/creeper123123321/viarift/platform/VRLoader.java +++ b/src/main/java/com/github/creeper123123321/viarift/platform/VRLoader.java @@ -24,17 +24,14 @@ package com.github.creeper123123321.viarift.platform; -import com.github.creeper123123321.viarift.provider.VRVersionProvider; import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.platform.ViaPlatformLoader; import us.myles.ViaVersion.bungee.providers.BungeeMovementTransmitter; -import us.myles.ViaVersion.protocols.base.VersionProvider; import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.MovementTransmitterProvider; public class VRLoader implements ViaPlatformLoader { @Override public void load() { - Via.getManager().getProviders().use(VersionProvider.class, new VRVersionProvider()); Via.getManager().getProviders().use(MovementTransmitterProvider.class, new BungeeMovementTransmitter()); } diff --git a/src/main/resources/assets/viarift/.modassetsroot b/src/main/resources/assets/viarift/.modassetsroot deleted file mode 100644 index e69de29..0000000 diff --git a/src/main/resources/mixins.viarift.main.json b/src/main/resources/mixins.viarift.main.json index 1e50895..0c15217 100644 --- a/src/main/resources/mixins.viarift.main.json +++ b/src/main/resources/mixins.viarift.main.json @@ -9,6 +9,7 @@ "MixinNetworkManagerClientChInit" ], "client": [ - "client.MixinGuiMultiplayer" + "client.MixinGuiMultiplayer", + "client.MixinCPacketHandshake" ] }