Skip to content

Commit

Permalink
ViaVersion REWORK
Browse files Browse the repository at this point in the history
  • Loading branch information
Aspw-w committed Apr 12, 2024
1 parent 6a9030b commit 99d6b1b
Show file tree
Hide file tree
Showing 18 changed files with 73 additions and 83 deletions.
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ okhttp_version=4.9.1
snake_yml_version=2.2
slf4j_version=2.0.12

viaversion_version=4.10.0-24w09a-SNAPSHOT
viabackwards_version=4.10.0-24w09a-SNAPSHOT
viarewind_version=3.0.7-24w09a-SNAPSHOT
viaversion_version=4.9.3
viabackwards_version=4.9.2
viarewind_version=3.0.6
vialoader_version=2.2.12
vialegacy_version=2.2.22-SNAPSHOT
viaaprilfools_version=2.0.11-SNAPSHOT
vialoader_version=2.2.13-SNAPSHOT
viaaprilfools_version=2.0.11-SNAPSHOT
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,12 @@ class AutoHeal : Module() {
if (mc.thePlayer.inventory.currentItem == potIndex - 36) {
mc.thePlayer.inventory.currentItem = oldSlot
mc.playerController.updateController()
potting = false
throwing = false
tickTimer.reset()
debug("switch back")
}
return
}
if (throwing && mc.currentScreen !is GuiContainer
&& mc.inGameHasFocus && Display.isActive()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,6 @@ class LegitScaffold : Module() {
BlockPos(mc.thePlayer.posX, mc.thePlayer.posY - 1.0, mc.thePlayer.posZ)
).block === Blocks.air

if (sneakValue.get())
mc.gameSettings.keyBindSneak.pressed = shouldEagle

if (shouldEagle && (tickTimer.hasTimePassed(delayValue.get()) || !mc.thePlayer.onGround)) {
if (mc.thePlayer.heldItem != null && mc.thePlayer.heldItem.item is ItemBlock)
KeyBinding.onTick(mc.gameSettings.keyBindUseItem.keyCode)
Expand All @@ -108,6 +105,15 @@ class LegitScaffold : Module() {
return
}

val shouldEagle = mc.theWorld.getBlockState(
BlockPos(mc.thePlayer.posX, mc.thePlayer.posY - 1.0, mc.thePlayer.posZ)
).block === Blocks.air

if (sneakValue.get() && shouldEagle || GameSettings.isKeyDown(mc.gameSettings.keyBindSneak))
mc.gameSettings.keyBindSneak.pressed = true
else if (!GameSettings.isKeyDown(mc.gameSettings.keyBindSneak))
mc.gameSettings.keyBindSneak.pressed = false

if (stopSprintValue.get())
mc.thePlayer.isSprinting = false

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class Interface : Module() {
val connectChecks = if (!APIConnecter.canConnect) " - Disconnected" else ""
val fpsChecks = if (watermarkFpsValue.get()) " [" + Minecraft.getDebugFPS() + " FPS]" else ""
val protocolChecks =
if (watermarkProtocolValue.get()) " [version: " + (if (!mc.isIntegratedServerRunning) ProtocolBase.getManager().targetVersion.name else "1.8.x") + "]" else ""
if (watermarkProtocolValue.get()) " [version: " + (if (!mc.isIntegratedServerRunning) ProtocolBase.getManager().targetVersion.getName() else "1.8.x") + "]" else ""
var firstChar = ""
var restOfString = ""
if (inputString != "") {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package net.aspw.client.injection.forge.mixins.gui;

import com.google.gson.JsonObject;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import net.aspw.client.Launch;
import net.aspw.client.auth.account.CrackedAccount;
import net.aspw.client.auth.account.MinecraftAccount;
Expand All @@ -22,6 +21,7 @@
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.util.IChatComponent;
import net.minecraft.util.Session;
import net.raphimc.vialoader.util.VersionEnum;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
Expand Down Expand Up @@ -104,7 +104,7 @@ private void actionPerformed(GuiButton button, CallbackInfo callbackInfo) {

@Inject(method = "drawScreen", at = @At("RETURN"))
private void drawScreen(CallbackInfo callbackInfo) {
final ProtocolVersion version = ProtocolBase.getManager().getTargetVersion();
final VersionEnum version = ProtocolBase.getManager().getTargetVersion();

Fonts.minecraftFont.drawStringWithShadow(
"§7Username: §d" + mc.getSession().getUsername(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package net.aspw.client.injection.forge.mixins.gui;

import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import net.aspw.client.features.api.PacketManager;
import net.aspw.client.protocol.ProtocolBase;
import net.aspw.client.utils.MinecraftInstance;
import net.aspw.client.utils.ServerUtils;
import net.aspw.client.visual.font.semi.Fonts;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiIngameMenu;
import net.raphimc.vialoader.util.VersionEnum;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
Expand All @@ -31,7 +31,7 @@ private void actionPerformed(GuiButton button, CallbackInfo callbackInfo) {
@Inject(method = "drawScreen", at = @At("RETURN"))
private void drawScreen(CallbackInfo callbackInfo) {
try {
final ProtocolVersion version = ProtocolBase.getManager().getTargetVersion();
final VersionEnum version = ProtocolBase.getManager().getTargetVersion();

Fonts.minecraftFont.drawStringWithShadow("§7Username: §d" + mc.getSession().getUsername(), 6f, 6f, 0xffffff);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package net.aspw.client.injection.forge.mixins.gui;

import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import net.aspw.client.protocol.ProtocolBase;
import net.aspw.client.protocol.api.ProtocolSelector;
import net.aspw.client.visual.client.altmanager.GuiAltManager;
import net.aspw.client.visual.font.semi.Fonts;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiMultiplayer;
import net.minecraft.client.gui.GuiScreen;
import net.raphimc.vialoader.util.VersionEnum;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
Expand All @@ -27,7 +27,7 @@ private void initGui(CallbackInfo callbackInfo) {

@Inject(method = "drawScreen", at = @At("RETURN"))
private void drawScreen(CallbackInfo callbackInfo) {
final ProtocolVersion version = ProtocolBase.getManager().getTargetVersion();
final VersionEnum version = ProtocolBase.getManager().getTargetVersion();

Fonts.minecraftFont.drawStringWithShadow("§7Username: §d" + mc.getSession().getUsername(), 6f, 6f, 0xffffff);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package net.aspw.client.injection.forge.mixins.gui;

import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import net.aspw.client.Launch;
import net.aspw.client.protocol.ProtocolBase;
import net.aspw.client.utils.MinecraftInstance;
import net.minecraft.client.gui.GuiOverlayDebug;
import net.raphimc.vialoader.util.VersionEnum;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
Expand All @@ -17,7 +17,7 @@ public class MixinGuiOverlayDebug {

@Inject(method = "getDebugInfoRight", at = @At(value = "TAIL"))
public void addProtocolVersion(CallbackInfoReturnable<List<String>> cir) {
final ProtocolVersion version = ProtocolBase.getManager().getTargetVersion();
final VersionEnum version = ProtocolBase.getManager().getTargetVersion();

cir.getReturnValue().add("");

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package net.aspw.client.injection.forge.mixins.network;

import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import net.aspw.client.protocol.ProtocolBase;
import net.aspw.client.protocol.api.ExtendedServerData;
import net.aspw.client.utils.MinecraftInstance;
import net.minecraft.network.NetworkManager;
import net.raphimc.vialoader.util.VersionEnum;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
Expand All @@ -17,7 +17,7 @@ public class MixinGuiConnecting_1 {
@Redirect(method = "run", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/NetworkManager;func_181124_a(Ljava/net/InetAddress;IZ)Lnet/minecraft/network/NetworkManager;"), remap = false)
public NetworkManager trackVersion(InetAddress address, int i, boolean b) {
if (MinecraftInstance.mc.getCurrentServerData() instanceof ExtendedServerData) {
final ProtocolVersion version = ((ExtendedServerData) MinecraftInstance.mc.getCurrentServerData()).viaForge$getVersion();
final VersionEnum version = ((ExtendedServerData) MinecraftInstance.mc.getCurrentServerData()).viaForge$getVersion();
if (version != null) {
ProtocolBase.getManager().setTargetVersionSilent(version);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package net.aspw.client.injection.forge.mixins.network;

import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import net.aspw.client.Launch;
Expand All @@ -14,6 +13,7 @@
import net.minecraft.network.Packet;
import net.minecraft.network.ThreadQuickExitException;
import net.minecraft.util.LazyLoadBase;
import net.raphimc.vialoader.util.VersionEnum;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
Expand All @@ -39,7 +39,7 @@ public class MixinNetworkManager implements VFNetworkManager {
private INetHandler packetListener;

@Unique
private ProtocolVersion viaForge$targetVersion;
private VersionEnum viaForge$targetVersion;

@Inject(method = "func_181124_a", at = @At(value = "INVOKE", target = "Lio/netty/bootstrap/Bootstrap;group(Lio/netty/channel/EventLoopGroup;)Lio/netty/bootstrap/AbstractBootstrap;"), locals = LocalCapture.CAPTURE_FAILHARD, remap = false)
private static void trackSelfTarget(final InetAddress address, final int serverPort, final boolean useNativeTransport, final CallbackInfoReturnable<NetworkManager> cir, final NetworkManager networkmanager, final Class oclass, final LazyLoadBase lazyloadbase) {
Expand All @@ -52,12 +52,12 @@ public void reorderPipeline(final int p_setCompressionTreshold_1_, final Callbac
}

@Override
public ProtocolVersion viaForge$getTrackedVersion() {
public VersionEnum viaForge$getTrackedVersion() {
return viaForge$targetVersion;
}

@Override
public void viaForge$setTrackedVersion(final ProtocolVersion version) {
public void viaForge$setTrackedVersion(final VersionEnum version) {
viaForge$targetVersion = version;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package net.aspw.client.injection.forge.mixins.network;

import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import net.aspw.client.protocol.api.ExtendedServerData;
import net.minecraft.client.multiplayer.ServerData;
import net.minecraft.nbt.NBTTagCompound;
import net.raphimc.vialoader.util.VersionEnum;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
Expand All @@ -16,19 +16,19 @@
public class MixinServerData implements ExtendedServerData {

@Unique
private ProtocolVersion viaForge$version;
private VersionEnum viaForge$version;

@Inject(method = "getNBTCompound", at = @At(value = "INVOKE", target = "Lnet/minecraft/nbt/NBTTagCompound;setString(Ljava/lang/String;Ljava/lang/String;)V", ordinal = 0), locals = LocalCapture.CAPTURE_FAILHARD)
public void saveVersion(CallbackInfoReturnable<NBTTagCompound> cir, NBTTagCompound nbttagcompound) {
if (viaForge$version != null) {
nbttagcompound.setString("viaForge$version", viaForge$version.getName());
nbttagcompound.setInteger("viaForge$version", viaForge$version.getVersion());
}
}

@Inject(method = "getServerDataFromNBTCompound", at = @At(value = "TAIL"))
private static void getVersion(NBTTagCompound nbtCompound, CallbackInfoReturnable<ServerData> cir) {
if (nbtCompound.hasKey("viaForge$version")) {
((ExtendedServerData) cir.getReturnValue()).viaForge$setVersion(ProtocolVersion.getClosest(nbtCompound.getString("viaForge$version")));
((ExtendedServerData) cir.getReturnValue()).viaForge$setVersion(VersionEnum.fromProtocolId(nbtCompound.getInteger("viaForge$version")));
}
}

Expand All @@ -40,12 +40,12 @@ public void track(ServerData serverDataIn, CallbackInfo ci) {
}

@Override
public ProtocolVersion viaForge$getVersion() {
public VersionEnum viaForge$getVersion() {
return viaForge$version;
}

@Override
public void viaForge$setVersion(ProtocolVersion version) {
public void viaForge$setVersion(VersionEnum version) {
viaForge$version = version;
}

Expand Down
34 changes: 11 additions & 23 deletions src/main/java/net/aspw/client/protocol/ProtocolBase.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package net.aspw.client.protocol;

import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viaversion.connection.UserConnectionImpl;
import com.viaversion.viaversion.protocol.ProtocolPipelineImpl;
import io.netty.channel.Channel;
Expand All @@ -12,19 +11,18 @@
import net.raphimc.vialoader.ViaLoader;
import net.raphimc.vialoader.impl.platform.*;
import net.raphimc.vialoader.netty.CompressionReorderEvent;
import net.raphimc.vialoader.util.ProtocolVersionList;
import net.raphimc.vialoader.util.VersionEnum;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class ProtocolBase {

private ProtocolVersion targetVersion = ProtocolVersion.v1_8;
private VersionEnum targetVersion = VersionEnum.r1_8;
public static final AttributeKey<UserConnection> LOCAL_VIA_USER = AttributeKey.valueOf("local_via_user");
public static final AttributeKey<VFNetworkManager> VF_NETWORK_MANAGER = AttributeKey.valueOf("encryption_setup");
private static ProtocolBase manager;
public static List<ProtocolVersion> versions = new ArrayList<>();
public static List<VersionEnum> versions = new ArrayList<>();

public ProtocolBase() {
}
Expand All @@ -34,28 +32,18 @@ public static void init(final VFPlatform platform) {
return;
}

final ProtocolVersion version = ProtocolVersion.getProtocol(platform.getGameVersion());
final VersionEnum version = VersionEnum.fromProtocolId(platform.getGameVersion());

if (version == ProtocolVersion.unknown)
if (version == VersionEnum.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, ViaLegacyPlatformImpl::new, ViaAprilFoolsPlatformImpl::new);

versions.addAll(ProtocolVersionList.getProtocolsNewToOld());

try {
Iterator<ProtocolVersion> 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) {
}
versions.addAll(VersionEnum.SORTED_VERSIONS);

versions.removeIf(i -> i == VersionEnum.UNKNOWN || i.isOlderThan(VersionEnum.r1_7_2tor1_7_5));

ClientUtils.getLogger().info("ViaVersion Injected");
}
Expand All @@ -72,15 +60,15 @@ public void inject(final Channel channel, final VFNetworkManager networkManager)
}
}

public ProtocolVersion getTargetVersion() {
public VersionEnum getTargetVersion() {
return targetVersion;
}

public void setTargetVersionSilent(final ProtocolVersion targetVersion) {
public void setTargetVersionSilent(final VersionEnum targetVersion) {
this.targetVersion = targetVersion;
}

public void setTargetVersion(final ProtocolVersion targetVersion) {
public void setTargetVersion(final VersionEnum targetVersion) {
this.targetVersion = targetVersion;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package net.aspw.client.protocol.api;

import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import net.raphimc.vialoader.util.VersionEnum;

/**
* This interface is used to store the target version for a specific server in the server list.
*/
public interface ExtendedServerData {

ProtocolVersion viaForge$getVersion();
VersionEnum viaForge$getVersion();

void viaForge$setVersion(final ProtocolVersion version);
void viaForge$setVersion(final VersionEnum version);

}
Loading

0 comments on commit 99d6b1b

Please sign in to comment.