Skip to content

Commit

Permalink
24w07a, port to upstream changes (maybe)
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianMichael committed Feb 14, 2024
1 parent 39424ce commit 1e15361
Show file tree
Hide file tree
Showing 16 changed files with 71 additions and 50 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 16 additions & 16 deletions src/main/java/de/florianmichael/viaforge/common/ViaForgeCommon.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -33,7 +34,6 @@
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;

Expand All @@ -42,14 +42,14 @@
* 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;

Expand All @@ -66,8 +66,8 @@ public static void init(final VFPlatform platform) {
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());
}

Expand All @@ -78,8 +78,8 @@ public static void init(final VFPlatform platform) {
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);
Expand Down Expand Up @@ -114,25 +114,25 @@ public void reorderCompression(final Channel channel) {
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() {
Expand All @@ -146,5 +146,5 @@ public ViaForgeConfig getConfig() {
public static ViaForgeCommon getManager() {
return manager;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -70,11 +71,14 @@ public void set(String path, Object value) {
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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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);

}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@

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;
Expand Down Expand Up @@ -133,12 +135,12 @@ public SlotList(Minecraft client, int width, int height, int top, int bottom, in

@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
Expand All @@ -153,8 +155,8 @@ protected void drawBackground() {

@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) {
Expand All @@ -169,7 +171,7 @@ protected void drawSlot(int index, int x, int y, int slotHeight, int mouseX, int

public interface FinishedCallback {

void finished(final VersionEnum version, final GuiScreen parent);
void finished(final ProtocolVersion version, final GuiScreen parent);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -38,7 +39,7 @@ public NetworkManager trackVersion(InetAddress address, int i, boolean b) {
// 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -47,7 +48,7 @@ public void initGui(CallbackInfo ci) {
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"));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
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;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,6 +28,7 @@
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;
Expand All @@ -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) {
Expand All @@ -64,7 +66,7 @@ private static void trackSelfTarget(InetAddress address, int serverPort, boolean

@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();

Expand Down Expand Up @@ -96,12 +98,12 @@ public void reorderPipeline(int p_setCompressionTreshold_1_, CallbackInfo ci) {
}

@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;
}

Expand Down
Loading

0 comments on commit 1e15361

Please sign in to comment.