diff --git a/build.gradle b/build.gradle index f6c179fb..72bd727e 100644 --- a/build.gradle +++ b/build.gradle @@ -52,7 +52,8 @@ def viaLibs = [ "com.viaversion:viaversion:${project.viaversion_version}", "com.viaversion:viabackwards:${project.viabackwards_version}", "com.viaversion:viarewind-universal:${project.viarewind_version}", - "net.raphimc:ViaLoader:${project.vialoader_version}" + "net.raphimc:ViaLoader:${project.vialoader_version}", + "net.raphimc:ViaAprilFools:${project.viaaprilfools_version}" ] dependencies { @@ -71,6 +72,10 @@ dependencies { include(via) } + include ("net.raphimc:ViaLegacy:${project.vialegacy_version}") { + exclude group: "com.google.code.gson", module: "gson" + } + include('com.github.half-cambodian-hacker-man:Koffee:d8cee73') { exclude module: 'asm-commons' exclude module: 'asm-tree' diff --git a/gradle.properties b/gradle.properties index 4b0f4d5a..7c0a7250 100644 --- a/gradle.properties +++ b/gradle.properties @@ -18,4 +18,6 @@ mixingradle_version = ae2a80e viaversion_version=4.10.0-24w09a-SNAPSHOT viabackwards_version=4.10.0-24w09a-SNAPSHOT viarewind_version=3.0.7-24w09a-SNAPSHOT -vialoader_version=2.2.13-SNAPSHOT \ No newline at end of file +vialoader_version=2.2.13-SNAPSHOT +vialegacy_version=2.2.22-SNAPSHOT +viaaprilfools_version=2.0.11-SNAPSHOT \ No newline at end of file diff --git a/src/main/java/net/aspw/client/Launch.kt b/src/main/java/net/aspw/client/Launch.kt index 711a5aa7..66fb5945 100644 --- a/src/main/java/net/aspw/client/Launch.kt +++ b/src/main/java/net/aspw/client/Launch.kt @@ -1,6 +1,5 @@ package net.aspw.client -import com.viaversion.viaversion.api.protocol.version.ProtocolVersion import net.aspw.client.config.FileManager import net.aspw.client.event.ClientShutdownEvent import net.aspw.client.event.EventManager @@ -25,16 +24,15 @@ import net.aspw.client.utils.ClassUtils.hasForge import net.aspw.client.utils.misc.sound.TipSoundManager import net.aspw.client.visual.client.clickgui.dropdown.ClickGui import net.aspw.client.visual.font.semi.Fonts -import net.raphimc.vialoader.util.ProtocolVersionList object Launch { // Client information const val CLIENT_BEST = "NightX" const val CLIENT_FOLDER = "NightX-Client" - const val CLIENT_VERSION = "B105" + const val CLIENT_VERSION = "B106" const val CLIENT_CHAT = "§c$CLIENT_BEST: §r" - const val CLIENT_PROTOCOL_RANGE = "1.8 to 1.20.4" + const val CLIENT_PROTOCOL_RANGE = "1.7.2 to 1.20.4" var isStarting = false @@ -57,9 +55,6 @@ object Launch { // Discord RPC lateinit var discordRPC: DiscordRPC - // ViaVersion - var versions = mutableListOf() - /** * Execute if client will be started */ @@ -72,18 +67,6 @@ object Launch { ProtocolBase.init(ProtocolMod.PLATFORM) - versions.addAll(ProtocolVersionList.getProtocolsNewToOld()) - - try { - for (i in versions) { - if (i == ProtocolVersion.unknown || i == ProtocolVersion.v1_20_5) { - versions.remove(i) - ClientUtils.getLogger().info("Removed Unknown Protocols ($i)") - } - } - } catch (_: Exception) { - } - // Check update APIConnecter.checkStaffList() APIConnecter.checkStatus() diff --git a/src/main/java/net/aspw/client/injection/forge/mixins/client/MixinMinecraft.java b/src/main/java/net/aspw/client/injection/forge/mixins/client/MixinMinecraft.java index f057fcd7..edd9fb28 100644 --- a/src/main/java/net/aspw/client/injection/forge/mixins/client/MixinMinecraft.java +++ b/src/main/java/net/aspw/client/injection/forge/mixins/client/MixinMinecraft.java @@ -1,9 +1,11 @@ package net.aspw.client.injection.forge.mixins.client; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import net.aspw.client.Launch; import net.aspw.client.event.*; import net.aspw.client.features.module.impl.other.FastPlace; import net.aspw.client.injection.forge.mixins.accessors.MinecraftForgeClientAccessor; +import net.aspw.client.protocol.ProtocolBase; import net.aspw.client.protocol.api.ProtocolFixes; import net.aspw.client.utils.CPSCounter; import net.aspw.client.utils.MinecraftInstance; @@ -268,7 +270,7 @@ private void sendClickBlockToController(boolean leftClick) { if (leftClick && this.objectMouseOver != null && this.objectMouseOver.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) { BlockPos blockPos = this.objectMouseOver.getBlockPos(); - if (this.thePlayer.isUsingItem()) + if (this.thePlayer.isUsingItem() && ProtocolBase.getManager().getTargetVersion().newerThanOrEqualTo(ProtocolVersion.v1_8)) return; if (this.leftClickCounter == 0) diff --git a/src/main/java/net/aspw/client/protocol/ProtocolBase.java b/src/main/java/net/aspw/client/protocol/ProtocolBase.java index 99befd79..23ca80a7 100644 --- a/src/main/java/net/aspw/client/protocol/ProtocolBase.java +++ b/src/main/java/net/aspw/client/protocol/ProtocolBase.java @@ -10,10 +10,13 @@ import net.aspw.client.protocol.api.*; import net.aspw.client.utils.ClientUtils; import net.raphimc.vialoader.ViaLoader; -import net.raphimc.vialoader.impl.platform.ViaBackwardsPlatformImpl; -import net.raphimc.vialoader.impl.platform.ViaRewindPlatformImpl; -import net.raphimc.vialoader.impl.platform.ViaVersionPlatformImpl; +import net.raphimc.vialoader.impl.platform.*; import net.raphimc.vialoader.netty.CompressionReorderEvent; +import net.raphimc.vialoader.util.ProtocolVersionList; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; public class ProtocolBase { @@ -21,6 +24,7 @@ public class ProtocolBase { public static final AttributeKey LOCAL_VIA_USER = AttributeKey.valueOf("local_via_user"); public static final AttributeKey VF_NETWORK_MANAGER = AttributeKey.valueOf("encryption_setup"); private static ProtocolBase manager; + public static List versions = new ArrayList<>(); public ProtocolBase() { } @@ -30,9 +34,28 @@ public static void init(final VFPlatform platform) { return; } + final ProtocolVersion version = ProtocolVersion.getProtocol(platform.getGameVersion()); + + if (version == ProtocolVersion.unknown) + throw new IllegalArgumentException("Unknown Protocol Found (" + platform.getGameVersion() + ")"); + manager = new ProtocolBase(); - ViaLoader.init(new ViaVersionPlatformImpl(null), new ProtocolVLLoader(platform), new ProtocolVLInjector(), null, ViaBackwardsPlatformImpl::new, ViaRewindPlatformImpl::new, null, null); + ViaLoader.init(new ViaVersionPlatformImpl(null), new ProtocolVLLoader(platform), new ProtocolVLInjector(), null, ViaBackwardsPlatformImpl::new, ViaRewindPlatformImpl::new, ViaLegacyPlatformImpl::new, ViaAprilFoolsPlatformImpl::new); + + versions.addAll(ProtocolVersionList.getProtocolsNewToOld()); + + try { + Iterator iterator = versions.iterator(); + while (iterator.hasNext()) { + ProtocolVersion i = iterator.next(); + if (i == ProtocolVersion.unknown || i.olderThan(ProtocolVersion.v1_7_2) || i == ProtocolVersion.v1_20_5) { + iterator.remove(); + ClientUtils.getLogger().info("Removed Protocol (" + i + ")"); + } + } + } catch (Exception ignored) { + } ClientUtils.getLogger().info("ViaVersion Injected"); } diff --git a/src/main/java/net/aspw/client/protocol/ProtocolMod.java b/src/main/java/net/aspw/client/protocol/ProtocolMod.java index 3ff3f01e..cb29356b 100644 --- a/src/main/java/net/aspw/client/protocol/ProtocolMod.java +++ b/src/main/java/net/aspw/client/protocol/ProtocolMod.java @@ -1,9 +1,16 @@ package net.aspw.client.protocol; import net.aspw.client.protocol.api.VFPlatform; +import net.minecraft.realms.RealmsSharedConstants; import net.minecraftforge.fml.common.Mod; @Mod(modid = "NightX", version = "Release") public class ProtocolMod implements VFPlatform { + public static final ProtocolMod PLATFORM = new ProtocolMod(); + + @Override + public int getGameVersion() { + return RealmsSharedConstants.NETWORK_PROTOCOL_VERSION; + } } \ No newline at end of file diff --git a/src/main/java/net/aspw/client/protocol/api/ProtocolSelector.java b/src/main/java/net/aspw/client/protocol/api/ProtocolSelector.java index 046f46a7..a14d2596 100644 --- a/src/main/java/net/aspw/client/protocol/api/ProtocolSelector.java +++ b/src/main/java/net/aspw/client/protocol/api/ProtocolSelector.java @@ -2,7 +2,6 @@ import com.mojang.realmsclient.gui.ChatFormatting; import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; -import net.aspw.client.Launch; import net.aspw.client.protocol.ProtocolBase; import net.aspw.client.visual.font.smooth.FontLoaders; import net.minecraft.client.Minecraft; @@ -75,12 +74,12 @@ public SlotList(Minecraft client, int width, int height, int top, int bottom, in @Override protected int getSize() { - return Launch.INSTANCE.getVersions().size() - 2; + return ProtocolBase.versions.size(); } @Override protected void elementClicked(int index, boolean b, int i1, int i2) { - finishedCallback.finished(Launch.INSTANCE.getVersions().get(index), parent); + finishedCallback.finished(ProtocolBase.versions.get(index), parent); } @Override @@ -96,7 +95,7 @@ protected void drawBackground() { @Override protected void drawSlot(int index, int x, int y, int slotHeight, int mouseX, int mouseY) { final ProtocolVersion targetVersion = ProtocolBase.getManager().getTargetVersion(); - final ProtocolVersion version = Launch.INSTANCE.getVersions().get(index); + final ProtocolVersion version = ProtocolBase.versions.get(index); String color; if (targetVersion == version) { diff --git a/src/main/java/net/aspw/client/protocol/api/VFPlatform.java b/src/main/java/net/aspw/client/protocol/api/VFPlatform.java index 0215ada7..307dec6b 100644 --- a/src/main/java/net/aspw/client/protocol/api/VFPlatform.java +++ b/src/main/java/net/aspw/client/protocol/api/VFPlatform.java @@ -1,4 +1,6 @@ package net.aspw.client.protocol.api; public interface VFPlatform { + + int getGameVersion(); } \ No newline at end of file