24w07a, port to upstream changes (maybe)

This commit is contained in:
FlorianMichael 2024-02-14 23:04:43 +01:00
parent 39424cef6e
commit 1e1536120e
No known key found for this signature in database
GPG Key ID: C2FB87E71C425126
16 changed files with 71 additions and 50 deletions

View File

@ -8,8 +8,8 @@ maven_version=3.5.0
maven_group=de.florianmichael
# ViaVersion
viaversion_version=4.10.0-24w06a-SNAPSHOT
viabackwards_version=4.10.0-24w06a-SNAPSHOT
viaversion_version=4.10.0-24w07a-SNAPSHOT
viabackwards_version=4.10.0-24w07a-SNAPSHOT
viarewind_version=3.0.6-SNAPSHOT
vialegacy_version=2.2.22-SNAPSHOT
viaaprilfools_version=2.0.11-SNAPSHOT

View File

@ -19,6 +19,7 @@
package de.florianmichael.viaforge.common;
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 de.florianmichael.viaforge.common.platform.VFPlatform;
@ -33,7 +34,6 @@ import io.netty.util.AttributeKey;
import net.raphimc.vialoader.ViaLoader;
import net.raphimc.vialoader.impl.platform.*;
import net.raphimc.vialoader.netty.CompressionReorderEvent;
import net.raphimc.vialoader.util.VersionEnum;
import java.io.File;
@ -42,14 +42,14 @@ import java.io.File;
* It is used to inject the ViaVersion pipeline into the netty pipeline. It also manages the target version.
*/
public class ViaForgeCommon {
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 ViaForgeCommon manager;
private final VFPlatform platform;
private VersionEnum targetVersion;
private ProtocolVersion targetVersion;
private ViaForgeConfig config;
@ -66,8 +66,8 @@ public class ViaForgeCommon {
if (manager != null) {
return; // Already initialized, ignore it then :tm:
}
final VersionEnum version = VersionEnum.fromProtocolId(platform.getGameVersion());
if (version == VersionEnum.UNKNOWN) {
final ProtocolVersion version = ProtocolVersion.getProtocol(platform.getGameVersion()); // ViaForge will only load on post-netty versions
if (version == ProtocolVersion.unknown) {
throw new IllegalArgumentException("Unknown version " + platform.getGameVersion());
}
@ -78,8 +78,8 @@ public class ViaForgeCommon {
ViaLoader.init(new ViaVersionPlatformImpl(mainFolder), new ViaForgeVLLoader(platform), new ViaForgeVLInjector(), null, ViaBackwardsPlatformImpl::new, ViaRewindPlatformImpl::new, ViaLegacyPlatformImpl::new, ViaAprilFoolsPlatformImpl::new);
manager.config = new ViaForgeConfig(new File(mainFolder, "viaforge.yml"));
final VersionEnum configVersion = VersionEnum.fromProtocolId(manager.config.getClientSideVersion());
if (configVersion != VersionEnum.UNKNOWN) {
final ProtocolVersion configVersion = ProtocolVersion.getClosest(manager.config.getClientSideVersion());
if (configVersion != null) {
manager.setTargetVersion(configVersion);
} else {
manager.setTargetVersion(version);
@ -114,25 +114,25 @@ public class ViaForgeCommon {
channel.pipeline().fireUserEventTriggered(CompressionReorderEvent.INSTANCE);
}
public VersionEnum getNativeVersion() {
return VersionEnum.fromProtocolId(platform.getGameVersion());
public ProtocolVersion getNativeVersion() {
return ProtocolVersion.getProtocol(platform.getGameVersion());
}
public VersionEnum getTargetVersion() {
public ProtocolVersion getTargetVersion() {
return targetVersion;
}
public void restoreVersion() {
this.targetVersion = VersionEnum.fromProtocolId(config.getClientSideVersion());
this.targetVersion = ProtocolVersion.getClosest(config.getClientSideVersion());
}
public void setTargetVersionSilent(final VersionEnum targetVersion) {
public void setTargetVersionSilent(final ProtocolVersion targetVersion) {
this.targetVersion = targetVersion;
}
public void setTargetVersion(final VersionEnum targetVersion) {
public void setTargetVersion(final ProtocolVersion targetVersion) {
this.targetVersion = targetVersion;
config.setClientSideVersion(targetVersion.getVersion());
config.setClientSideVersion(targetVersion.getName());
}
public VFPlatform getPlatform() {
@ -146,5 +146,5 @@ public class ViaForgeCommon {
public static ViaForgeCommon getManager() {
return manager;
}
}
}

View File

@ -18,15 +18,15 @@
package de.florianmichael.viaforge.common.gui;
import net.raphimc.vialoader.util.VersionEnum;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
/**
* This interface is used to store the target version for a specific server in the server list.
*/
public interface ExtendedServerData {
VersionEnum viaForge$getVersion();
ProtocolVersion viaForge$getVersion();
void viaForge$setVersion(final VersionEnum version);
void viaForge$setVersion(final ProtocolVersion version);
}

View File

@ -18,6 +18,7 @@
package de.florianmichael.viaforge.common.platform;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viaversion.util.Config;
import com.viaversion.viaversion.util.Pair;
@ -70,11 +71,14 @@ public class ViaForgeConfig extends Config {
save(); // Automatically save the config when something changes
}
public int getClientSideVersion() {
return getInt(CLIENT_SIDE_VERSION, 0);
public String getClientSideVersion() {
if (getInt(CLIENT_SIDE_VERSION, -1) != -1) { // Temporary fix for old configs
return ProtocolVersion.getProtocol(getInt(CLIENT_SIDE_VERSION, -1)).getName();
}
return getString(CLIENT_SIDE_VERSION, "");
}
public void setClientSideVersion(final int version) {
public void setClientSideVersion(final String version) {
set(CLIENT_SIDE_VERSION, version);
}

View File

@ -18,7 +18,7 @@
package de.florianmichael.viaforge.common.protocolhack.netty;
import net.raphimc.vialoader.util.VersionEnum;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
public interface VFNetworkManager {
@ -31,13 +31,13 @@ public interface VFNetworkManager {
/**
* @return the target version of the connection
*/
VersionEnum viaForge$getTrackedVersion();
ProtocolVersion viaForge$getTrackedVersion();
/**
* Sets the target version of the connection.
*
* @param version the target version
*/
void viaForge$setTrackedVersion(final VersionEnum version);
void viaForge$setTrackedVersion(final ProtocolVersion version);
}

View File

@ -19,12 +19,12 @@
package de.florianmichael.viaforge.common.protocolhack.netty;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import net.raphimc.vialoader.netty.VLLegacyPipeline;
import net.raphimc.vialoader.util.VersionEnum;
public class ViaForgeVLLegacyPipeline extends VLLegacyPipeline {
public ViaForgeVLLegacyPipeline(UserConnection user, VersionEnum version) {
public ViaForgeVLLegacyPipeline(UserConnection user, ProtocolVersion version) {
super(user, version);
}

View File

@ -19,16 +19,16 @@
package de.florianmichael.viaforge.common.protocolhack.provider;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viaversion.protocols.base.BaseVersionProvider;
import de.florianmichael.viaforge.common.ViaForgeCommon;
import net.raphimc.vialoader.util.VersionEnum;
public class ViaForgeVersionProvider extends BaseVersionProvider {
@Override
public int getClosestServerProtocol(UserConnection connection) throws Exception {
public ProtocolVersion getClosestServerProtocol(UserConnection connection) throws Exception {
if (connection.isClientSide() && !ViaForgeCommon.getManager().getPlatform().isSingleplayer().get()) {
return connection.getChannel().attr(ViaForgeCommon.VF_NETWORK_MANAGER).get().viaForge$getTrackedVersion().getVersion();
return connection.getChannel().attr(ViaForgeCommon.VF_NETWORK_MANAGER).get().viaForge$getTrackedVersion();
}
return super.getClosestServerProtocol(connection);
}

View File

@ -20,12 +20,14 @@ package de.florianmichael.viaforge.gui;
import com.mojang.realmsclient.gui.ChatFormatting;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viaversion.util.DumpUtil;
import de.florianmichael.viaforge.common.ViaForgeCommon;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.GuiSlot;
import net.raphimc.vialoader.util.ProtocolVersionList;
import net.raphimc.vialoader.util.VersionEnum;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.GL11;
@ -133,12 +135,12 @@ public class GuiProtocolSelector extends GuiScreen {
@Override
protected int getSize() {
return VersionEnum.SORTED_VERSIONS.size();
return ProtocolVersionList.getProtocolsNewToOld().size();
}
@Override
protected void elementClicked(int index, boolean b, int i1, int i2) {
finishedCallback.finished(VersionEnum.SORTED_VERSIONS.get(index), parent);
finishedCallback.finished(ProtocolVersionList.getProtocolsNewToOld().get(index), parent);
}
@Override
@ -153,8 +155,8 @@ public class GuiProtocolSelector extends GuiScreen {
@Override
protected void drawSlot(int index, int x, int y, int slotHeight, int mouseX, int mouseY) {
final VersionEnum targetVersion = ViaForgeCommon.getManager().getTargetVersion();
final VersionEnum version = VersionEnum.SORTED_VERSIONS.get(index);
final ProtocolVersion targetVersion = ViaForgeCommon.getManager().getTargetVersion();
final ProtocolVersion version = ProtocolVersionList.getProtocolsNewToOld().get(index);
String color;
if (targetVersion == version) {
@ -169,7 +171,7 @@ public class GuiProtocolSelector extends GuiScreen {
public interface FinishedCallback {
void finished(final VersionEnum version, final GuiScreen parent);
void finished(final ProtocolVersion version, final GuiScreen parent);
}

View File

@ -18,6 +18,7 @@
package de.florianmichael.viaforge.mixin.impl;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import de.florianmichael.viaforge.common.ViaForgeCommon;
import de.florianmichael.viaforge.common.gui.ExtendedServerData;
import net.minecraft.client.Minecraft;
@ -38,7 +39,7 @@ public class MixinGuiConnecting_1 {
// use it to determine the protocol version to use.
// We hope that the current server data is not null
if (Minecraft.getMinecraft().getCurrentServerData() instanceof ExtendedServerData) {
final VersionEnum version = ((ExtendedServerData) Minecraft.getMinecraft().getCurrentServerData()).viaForge$getVersion();
final ProtocolVersion version = ((ExtendedServerData) Minecraft.getMinecraft().getCurrentServerData()).viaForge$getVersion();
if (version != null) {
ViaForgeCommon.getManager().setTargetVersionSilent(version);
} else {

View File

@ -18,6 +18,7 @@
package de.florianmichael.viaforge.mixin.impl;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import de.florianmichael.viaforge.common.ViaForgeCommon;
import net.minecraft.client.gui.GuiOverlayDebug;
import net.raphimc.vialegacy.api.LegacyProtocolVersion;
@ -35,13 +36,13 @@ public class MixinGuiOverlayDebug {
@Inject(method = "getDebugInfoRight", at = @At(value = "TAIL"))
public void addViaForgeVersion(CallbackInfoReturnable<List<String>> cir) {
final ViaForgeCommon common = ViaForgeCommon.getManager();
final VersionEnum version = ViaForgeCommon.getManager().getTargetVersion();
final ProtocolVersion version = ViaForgeCommon.getManager().getTargetVersion();
if (common.getConfig().isShowProtocolVersionInF3() && version != common.getNativeVersion() && !common.getPlatform().isSingleplayer().get()) {
cir.getReturnValue().add("");
int protocolVersion = version.getVersion();
if (version.isOlderThanOrEqualTo(VersionEnum.r1_6_4)) {
if (version.olderThanOrEqualTo(LegacyProtocolVersion.r1_6_4)) {
// Older versions (<= 1.6.4) are using fake ids in ViaLegacy to prevent version duplications / mismatches
// So we need to unmap the version to get the real protocol version id
protocolVersion = LegacyProtocolVersion.getRealProtocolVersion(protocolVersion);

View File

@ -18,6 +18,7 @@
package de.florianmichael.viaforge.mixin.impl;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viaversion.util.Pair;
import de.florianmichael.viaforge.common.ViaForgeCommon;
import de.florianmichael.viaforge.common.gui.ExtendedServerData;
@ -47,7 +48,7 @@ public class MixinGuiScreenAddServer extends GuiScreen {
if (config.isShowAddServerButton()) {
final Pair<Integer, Integer> pos = config.getAddServerScreenButtonPosition().getPosition(this.width, this.height);
final VersionEnum target = ((ExtendedServerData) serverData).viaForge$getVersion();
final ProtocolVersion target = ((ExtendedServerData) serverData).viaForge$getVersion();
buttonList.add(new GuiButton(1_000_000_000, pos.key(), pos.value(), 100, 20, target != null ? target.getName() : "Set Version"));
}
}

View File

@ -25,6 +25,7 @@ import com.viaversion.viaversion.api.connection.UserConnection;
import de.florianmichael.viaforge.common.ViaForgeCommon;
import net.minecraft.client.network.NetHandlerLoginClient;
import net.minecraft.network.NetworkManager;
import net.raphimc.vialegacy.api.LegacyProtocolVersion;
import net.raphimc.vialegacy.protocols.release.protocol1_7_2_5to1_6_4.storage.ProtocolMetadataStorage;
import net.raphimc.vialoader.util.VersionEnum;
import org.spongepowered.asm.mixin.Final;
@ -41,7 +42,7 @@ public class MixinNetHandlerLoginClient {
@Redirect(method = "handleEncryptionRequest", at = @At(value = "INVOKE", target = "Lcom/mojang/authlib/minecraft/MinecraftSessionService;joinServer(Lcom/mojang/authlib/GameProfile;Ljava/lang/String;Ljava/lang/String;)V"))
public void onlyJoinServerIfPremium(MinecraftSessionService instance, GameProfile profile, String authenticationToken, String serverId) throws AuthenticationException {
if (ViaForgeCommon.getManager().getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_6_4)) {
if (ViaForgeCommon.getManager().getTargetVersion().olderThanOrEqualTo(LegacyProtocolVersion.r1_6_4)) {
final UserConnection user = networkManager.channel().attr(ViaForgeCommon.LOCAL_VIA_USER).get();
if (user != null && user.has(ProtocolMetadataStorage.class) && !user.get(ProtocolMetadataStorage.class).authenticate) {
// We are in the 1.7 -> 1.6 protocol, so we need to skip the joinServer call

View File

@ -18,6 +18,7 @@
package de.florianmichael.viaforge.mixin.impl;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import de.florianmichael.viaforge.common.ViaForgeCommon;
import de.florianmichael.viaforge.common.protocolhack.netty.VFNetworkManager;
import io.netty.channel.Channel;
@ -27,6 +28,7 @@ import net.minecraft.network.NetworkManager;
import net.minecraft.util.CryptManager;
import net.minecraft.util.IChatComponent;
import net.minecraft.util.LazyLoadBase;
import net.raphimc.vialegacy.api.LegacyProtocolVersion;
import net.raphimc.vialoader.netty.VLLegacyPipeline;
import net.raphimc.vialoader.util.VersionEnum;
import org.spongepowered.asm.mixin.Mixin;
@ -51,7 +53,7 @@ public class MixinNetworkManager implements VFNetworkManager {
private Cipher viaForge$decryptionCipher;
@Unique
private VersionEnum viaForge$targetVersion;
private ProtocolVersion 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)
private static void trackSelfTarget(InetAddress address, int serverPort, boolean useNativeTransport, CallbackInfoReturnable<NetworkManager> cir, NetworkManager networkmanager, Class oclass, LazyLoadBase lazyloadbase) {
@ -64,7 +66,7 @@ public class MixinNetworkManager implements VFNetworkManager {
@Inject(method = "enableEncryption", at = @At("HEAD"), cancellable = true)
private void storeEncryptionCiphers(SecretKey key, CallbackInfo ci) {
if (ViaForgeCommon.getManager().getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_6_4)) {
if (ViaForgeCommon.getManager().getTargetVersion().olderThanOrEqualTo(LegacyProtocolVersion.r1_6_4)) {
// Minecraft's encryption code is bad for us, we need to reorder the pipeline
ci.cancel();
@ -96,12 +98,12 @@ public class MixinNetworkManager implements VFNetworkManager {
}
@Override
public VersionEnum viaForge$getTrackedVersion() {
public ProtocolVersion viaForge$getTrackedVersion() {
return viaForge$targetVersion;
}
@Override
public void viaForge$setTrackedVersion(VersionEnum version) {
public void viaForge$setTrackedVersion(ProtocolVersion version) {
viaForge$targetVersion = version;
}

View File

@ -18,6 +18,7 @@
package de.florianmichael.viaforge.mixin.impl;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import de.florianmichael.viaforge.common.gui.ExtendedServerData;
import net.minecraft.client.multiplayer.ServerData;
import net.minecraft.nbt.NBTTagCompound;
@ -39,14 +40,20 @@ public class MixinServerData implements ExtendedServerData {
@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.setInteger("viaForge$version", viaForge$version.getVersion());
nbttagcompound.setString("viaForge$version", viaForge$version.getName());
}
}
@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(VersionEnum.fromProtocolId(nbtCompound.getInteger("viaForge$version")));
ProtocolVersion version;
if (nbtCompound.getInteger("viaForge$version") != 0) { // Temporary fix for old versions
version = ProtocolVersion.getProtocol(nbtCompound.getInteger("viaForge$version"));
} else {
version = ProtocolVersion.getClosest(nbtCompound.getString("viaForge$version"));
}
((ExtendedServerData) cir.getReturnValue()).viaForge$setVersion(version);
}
}

View File

@ -18,6 +18,7 @@
package de.florianmichael.viaforge.mixin.impl;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import de.florianmichael.viaforge.common.ViaForgeCommon;
import de.florianmichael.viaforge.common.gui.ExtendedServerData;
import net.minecraft.client.multiplayer.ServerData;
@ -51,7 +52,7 @@ public class MixinServerPinger {
// We hope that the current server data is not null
if (viaForge$serverData instanceof ExtendedServerData) {
final VersionEnum version = ((ExtendedServerData) viaForge$serverData).viaForge$getVersion();
final ProtocolVersion version = ((ExtendedServerData) viaForge$serverData).viaForge$getVersion();
if (version != null) {
ViaForgeCommon.getManager().setTargetVersionSilent(version);
} else {

View File

@ -19,6 +19,7 @@
package de.florianmichael.viaforge.mixin.impl.fixes;
import com.mojang.authlib.GameProfile;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import de.florianmichael.viaforge.common.ViaForgeCommon;
import net.minecraft.client.entity.AbstractClientPlayer;
import net.minecraft.client.entity.EntityPlayerSP;
@ -46,7 +47,7 @@ public class MixinEntityPlayerSP extends AbstractClientPlayer {
@Redirect(method = "onUpdateWalkingPlayer", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/NetHandlerPlayClient;addToSendQueue(Lnet/minecraft/network/Packet;)V", ordinal = 7))
public void emulateIdlePacket(NetHandlerPlayClient instance, Packet p_addToSendQueue_1_) {
if (ViaForgeCommon.getManager().getTargetVersion().isNewerThan(VersionEnum.r1_8)) {
if (ViaForgeCommon.getManager().getTargetVersion().newerThan(ProtocolVersion.v1_8)) {
// <= 1.8 spams the idle packet instead of only sending it when the ground state changes
if (this.viaForge$prevOnGround == this.onGround) {
return;