mirror of
https://github.com/ViaVersion/ViaForge.git
synced 2024-11-08 10:09:36 +01:00
Added groups in config.yml
Allow to set button positions Added system to set versions for singleton servers in the server list Added BetaCraft MpPass for classic servers Added per-server-version system
This commit is contained in:
parent
5a4b714bc5
commit
76e8ec8baa
@ -23,7 +23,7 @@ import com.viaversion.viaversion.protocol.ProtocolPipelineImpl;
|
||||
import de.florianmichael.viaforge.common.platform.VFPlatform;
|
||||
import de.florianmichael.viaforge.common.platform.ViaForgeConfig;
|
||||
import de.florianmichael.viaforge.common.protocolhack.ViaForgeVLInjector;
|
||||
import de.florianmichael.viaforge.common.protocolhack.netty.IEncryptionSetup;
|
||||
import de.florianmichael.viaforge.common.protocolhack.netty.VFNetworkManager;
|
||||
import de.florianmichael.viaforge.common.protocolhack.netty.ViaForgeVLLegacyPipeline;
|
||||
import de.florianmichael.viaforge.common.protocolhack.ViaForgeVLLoader;
|
||||
import io.netty.channel.Channel;
|
||||
@ -42,7 +42,7 @@ import java.io.File;
|
||||
*/
|
||||
public class ViaForgeCommon {
|
||||
public final static AttributeKey<UserConnection> LOCAL_VIA_USER = AttributeKey.valueOf("local_via_user");
|
||||
public final static AttributeKey<IEncryptionSetup> ENCRYPTION_SETUP = AttributeKey.valueOf("encryption_setup");
|
||||
public final static AttributeKey<VFNetworkManager> VF_NETWORK_MANAGER = AttributeKey.valueOf("encryption_setup");
|
||||
|
||||
private static ViaForgeCommon manager;
|
||||
|
||||
@ -90,12 +90,11 @@ public class ViaForgeCommon {
|
||||
* @param channel the channel to inject the pipeline into
|
||||
*/
|
||||
public void inject(final Channel channel) {
|
||||
if (channel instanceof SocketChannel && targetVersion != getNativeVersion()) {
|
||||
if (channel instanceof SocketChannel) {
|
||||
final UserConnection user = new UserConnectionImpl(channel, true);
|
||||
new ProtocolPipelineImpl(user);
|
||||
|
||||
channel.attr(LOCAL_VIA_USER).set(user);
|
||||
|
||||
channel.pipeline().addLast(new ViaForgeVLLegacyPipeline(user, targetVersion));
|
||||
}
|
||||
}
|
||||
@ -106,6 +105,8 @@ public class ViaForgeCommon {
|
||||
* @param channel the channel to reorder the compression for
|
||||
*/
|
||||
public void reorderCompression(final Channel channel) {
|
||||
// When Minecraft enables compression, we need to reorder the pipeline
|
||||
// to match the counterparts of via-decoder <-> encoder and via-encoder <-> encoder
|
||||
channel.pipeline().fireUserEventTriggered(CompressionReorderEvent.INSTANCE);
|
||||
}
|
||||
|
||||
@ -117,7 +118,15 @@ public class ViaForgeCommon {
|
||||
return targetVersion;
|
||||
}
|
||||
|
||||
public void setTargetVersion(VersionEnum targetVersion) {
|
||||
public void restoreVersion() {
|
||||
this.targetVersion = VersionEnum.fromProtocolId(config.getClientSideVersion());
|
||||
}
|
||||
|
||||
public void setTargetVersionSilent(final VersionEnum targetVersion) {
|
||||
this.targetVersion = targetVersion;
|
||||
}
|
||||
|
||||
public void setTargetVersion(final VersionEnum targetVersion) {
|
||||
this.targetVersion = targetVersion;
|
||||
config.setClientSideVersion(targetVersion.getVersion());
|
||||
}
|
||||
|
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
|
||||
* Copyright (C) 2021-2023 FlorianMichael/EnZaXD and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.florianmichael.viaforge.common.gui;
|
||||
|
||||
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 {
|
||||
|
||||
VersionEnum viaforge_getVersion();
|
||||
|
||||
void viaforge_setVersion(final VersionEnum version);
|
||||
}
|
@ -18,6 +18,7 @@
|
||||
package de.florianmichael.viaforge.common.platform;
|
||||
|
||||
import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.providers.GameProfileFetcher;
|
||||
import net.raphimc.vialoader.util.VersionEnum;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.function.Supplier;
|
||||
|
@ -1,6 +1,7 @@
|
||||
package de.florianmichael.viaforge.common.platform;
|
||||
|
||||
import com.viaversion.viaversion.util.Config;
|
||||
import com.viaversion.viaversion.util.Pair;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
@ -14,8 +15,13 @@ public class ViaForgeConfig extends Config {
|
||||
public final static String SHOW_MAIN_MENU_BUTTON = "show-main-menu-button";
|
||||
public final static String SHOW_MULTIPLAYER_BUTTON = "show-multiplayer-button";
|
||||
public final static String SHOW_DIRECT_CONNECT_BUTTON = "show-direct-connect-button";
|
||||
public final static String SHOW_ADD_SERVER_BUTTON = "show-add-server-button";
|
||||
|
||||
public final static String VERIFY_SESSION_IN_OLD_VERSIONS = "verify-session-in-old-versions";
|
||||
public final static String ALLOW_BETACRAFT_AUTHENTICATION = "allow-betacraft-authentication";
|
||||
|
||||
public final static String VIA_FORGE_BUTTON_POSITION = "via-forge-button-position";
|
||||
public final static String ADD_SERVER_SCREEN_BUTTON_POSITION = "add-server-screen-button-position";
|
||||
|
||||
/**
|
||||
* @param configFile The location of where the config is loaded/saved.
|
||||
@ -65,7 +71,48 @@ public class ViaForgeConfig extends Config {
|
||||
return getBoolean(SHOW_DIRECT_CONNECT_BUTTON, true);
|
||||
}
|
||||
|
||||
public boolean isShowAddServerButton() {
|
||||
return getBoolean(SHOW_ADD_SERVER_BUTTON, true);
|
||||
}
|
||||
|
||||
public boolean isVerifySessionInOldVersions() {
|
||||
return getBoolean(VERIFY_SESSION_IN_OLD_VERSIONS, true);
|
||||
}
|
||||
|
||||
public boolean isAllowBetacraftAuthentication() {
|
||||
return getBoolean(ALLOW_BETACRAFT_AUTHENTICATION, true);
|
||||
}
|
||||
|
||||
public ButtonPosition getViaForgeButtonPosition() {
|
||||
return ButtonPosition.valueOf(getString(VIA_FORGE_BUTTON_POSITION, ButtonPosition.TOP_LEFT.name()));
|
||||
}
|
||||
|
||||
public ButtonPosition getAddServerScreenButtonPosition() {
|
||||
return ButtonPosition.valueOf(getString(ADD_SERVER_SCREEN_BUTTON_POSITION, ButtonPosition.TOP_LEFT.name()));
|
||||
}
|
||||
|
||||
public enum ButtonPosition {
|
||||
// Button width: 100
|
||||
// Button height: 20
|
||||
// Button margin for both coordinates: 5
|
||||
TOP_LEFT((width, height) -> new Pair<>(5, 5)),
|
||||
TOP_RIGHT((width, height) -> new Pair<>(width - 100 - 5, 5)),
|
||||
BOTTOM_LEFT((width, height) -> new Pair<>(5, height - 20 - 5)),
|
||||
BOTTOM_RIGHT((width, height) -> new Pair<>(width - 100 - 5, height - 20 - 5));
|
||||
|
||||
private final PositionInvoker invoker;
|
||||
|
||||
ButtonPosition(final PositionInvoker invoker) {
|
||||
this.invoker = invoker;
|
||||
}
|
||||
|
||||
public Pair<Integer, Integer> getPosition(int width, int height) {
|
||||
return invoker.invoke(width, height);
|
||||
}
|
||||
|
||||
public interface PositionInvoker {
|
||||
|
||||
Pair<Integer, Integer> invoke(int width, int height);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,10 +22,8 @@ import com.viaversion.viaversion.api.platform.providers.ViaProviders;
|
||||
import com.viaversion.viaversion.api.protocol.version.VersionProvider;
|
||||
import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.MovementTransmitterProvider;
|
||||
import de.florianmichael.viaforge.common.platform.VFPlatform;
|
||||
import de.florianmichael.viaforge.common.protocolhack.provider.DummyMovementTransmitter;
|
||||
import de.florianmichael.viaforge.common.protocolhack.provider.ViaForgeEncryptionProvider;
|
||||
import de.florianmichael.viaforge.common.protocolhack.provider.ViaForgeOldAuthProvider;
|
||||
import de.florianmichael.viaforge.common.protocolhack.provider.ViaForgeVersionProvider;
|
||||
import de.florianmichael.viaforge.common.protocolhack.provider.*;
|
||||
import net.raphimc.vialegacy.protocols.classic.protocola1_0_15toc0_28_30.providers.ClassicMPPassProvider;
|
||||
import net.raphimc.vialegacy.protocols.release.protocol1_3_1_2to1_2_4_5.providers.OldAuthProvider;
|
||||
import net.raphimc.vialegacy.protocols.release.protocol1_7_2_5to1_6_4.providers.EncryptionProvider;
|
||||
import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.providers.GameProfileFetcher;
|
||||
@ -50,5 +48,6 @@ public class ViaForgeVLLoader extends VLLoader {
|
||||
providers.use(OldAuthProvider.class, new ViaForgeOldAuthProvider());
|
||||
providers.use(GameProfileFetcher.class, platform.getGameProfileFetcher());
|
||||
providers.use(EncryptionProvider.class, new ViaForgeEncryptionProvider());
|
||||
providers.use(ClassicMPPassProvider.class, new ViaForgeClassicMPPassProvider());
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,16 @@
|
||||
package de.florianmichael.viaforge.common.protocolhack.netty;
|
||||
|
||||
public interface IEncryptionSetup {
|
||||
import net.raphimc.vialoader.util.VersionEnum;
|
||||
|
||||
public interface VFNetworkManager {
|
||||
|
||||
/**
|
||||
* API method to setup the decryption side of the pipeline.
|
||||
* This method is called by the {@link de.florianmichael.viaforge.common.protocolhack.provider.ViaForgeEncryptionProvider} class.
|
||||
*/
|
||||
void viaforge_setupPreNettyDecryption();
|
||||
|
||||
VersionEnum viaforge_getTrackedVersion();
|
||||
|
||||
void viaforge_setTrackedVersion(final VersionEnum version);
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
package de.florianmichael.viaforge.common.protocolhack.provider;
|
||||
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import de.florianmichael.viaforge.common.ViaForgeCommon;
|
||||
import net.raphimc.vialegacy.protocols.classic.protocola1_0_15toc0_28_30.providers.ClassicMPPassProvider;
|
||||
import net.raphimc.vialegacy.protocols.release.protocol1_3_1_2to1_2_4_5.providers.OldAuthProvider;
|
||||
import net.raphimc.vialegacy.protocols.release.protocol1_7_2_5to1_6_4.storage.HandshakeStorage;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.net.InetAddress;
|
||||
import java.net.URL;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.Formatter;
|
||||
import java.util.Scanner;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class ViaForgeClassicMPPassProvider extends ClassicMPPassProvider {
|
||||
|
||||
@Override
|
||||
public String getMpPass(UserConnection user) {
|
||||
if (ViaForgeCommon.getManager().getConfig().isAllowBetacraftAuthentication()) {
|
||||
final HandshakeStorage handshakeStorage = user.get(HandshakeStorage.class);
|
||||
|
||||
return getBetacraftMpPass(user, user.getProtocolInfo().getUsername(), handshakeStorage.getHostname(), handshakeStorage.getPort());
|
||||
}
|
||||
return super.getMpPass(user);
|
||||
}
|
||||
|
||||
/*
|
||||
Stolen from https://github.com/FlorianMichael/Classic4J/blob/main/src/main/java/de/florianmichael/classic4j/BetaCraftHandler.java :tm:
|
||||
*/
|
||||
|
||||
private static String getBetacraftMpPass(final UserConnection user, final String username, final String ip, final int port) {
|
||||
try {
|
||||
final String server = InetAddress.getByName(ip).getHostAddress() + ":" + port;
|
||||
|
||||
Via.getManager().getProviders().get(OldAuthProvider.class).sendAuthRequest(user, sha1(server.getBytes()));
|
||||
|
||||
final InputStream connection = new URL("https://api.betacraft.uk/getmppass.jsp?user=" + username + "&server=" + server).openStream();
|
||||
Scanner scanner = new Scanner(connection);
|
||||
StringBuilder response = new StringBuilder();
|
||||
while (scanner.hasNext()) {
|
||||
response.append(scanner.next());
|
||||
}
|
||||
connection.close();
|
||||
|
||||
if (response.toString().contains("FAILED") || response.toString().contains("SERVER NOT FOUND")) return "0";
|
||||
|
||||
return response.toString();
|
||||
} catch (Throwable t) {
|
||||
Via.getPlatform().getLogger().log(Level.WARNING, "An unknown error occurred while authenticating with BetaCraft", t);
|
||||
return "0";
|
||||
}
|
||||
}
|
||||
|
||||
private static String sha1(final byte[] input) {
|
||||
try {
|
||||
Formatter formatter = new Formatter();
|
||||
final byte[] hash = MessageDigest.getInstance("SHA-1").digest(input);
|
||||
for (byte b : hash) {
|
||||
formatter.format("%02x", b);
|
||||
}
|
||||
return formatter.toString();
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -8,6 +8,6 @@ public class ViaForgeEncryptionProvider extends EncryptionProvider {
|
||||
|
||||
@Override
|
||||
public void enableDecryption(UserConnection user) {
|
||||
user.getChannel().attr(ViaForgeCommon.ENCRYPTION_SETUP).getAndRemove().viaforge_setupPreNettyDecryption();
|
||||
user.getChannel().attr(ViaForgeCommon.VF_NETWORK_MANAGER).getAndRemove().viaforge_setupPreNettyDecryption();
|
||||
}
|
||||
}
|
||||
|
@ -20,13 +20,19 @@ package de.florianmichael.viaforge.common.protocolhack.provider;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
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 {
|
||||
if (connection.isClientSide() && !ViaForgeCommon.getManager().getPlatform().isSingleplayer().get()) {
|
||||
return ViaForgeCommon.getManager().getTargetVersion().getVersion();
|
||||
try {
|
||||
System.out.println(connection.getChannel().attr(ViaForgeCommon.VF_NETWORK_MANAGER).get());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return connection.getChannel().attr(ViaForgeCommon.VF_NETWORK_MANAGER).get().viaforge_getTrackedVersion().getVersion();
|
||||
}
|
||||
|
||||
return super.getClosestServerProtocol(connection);
|
||||
|
@ -1,9 +1,27 @@
|
||||
# Thanks for downloading ViaForge!
|
||||
# If you need help, you can join our Discord - https://viaversion.com/discord
|
||||
#
|
||||
# Disclaimer:
|
||||
# It cannot be guaranteed that this mod is allowed on specific servers as it can possibly cause problems with anti-cheat plugins, (USE ONLY WITH CAUTION!)
|
||||
# It cannot be guaranteed that this mod is allowed on specific servers as it can possibly cause problems with anti-cheat plugins
|
||||
# (USE ONLY WITH CAUTION!)
|
||||
#
|
||||
#----------------------------------------------------------#
|
||||
# GLOBAL OPTIONS #
|
||||
#----------------------------------------------------------#
|
||||
#
|
||||
# This option sets the protocol version to be used when connecting to servers. (can also be changed in-game)
|
||||
client-side-version: -1
|
||||
#
|
||||
# Manually sends the joinServer request when connecting to <= 1.2.5 servers.
|
||||
verify-session-in-old-versions: true
|
||||
#
|
||||
# Allow ViaForge to authenticate with BetaCraft's MP-Pass system for <= c0.30 servers.
|
||||
allow-betacraft-authentication: true
|
||||
#
|
||||
#----------------------------------------------------------#
|
||||
# GUI OPTIONS #
|
||||
#----------------------------------------------------------#
|
||||
#
|
||||
# This option indicates if the ViaForge button should be shown in the main menu.
|
||||
show-main-menu-button: true
|
||||
#
|
||||
@ -13,5 +31,13 @@ show-multiplayer-button: true
|
||||
# This option indicates if the ViaForge button should be shown in the direct connect screen.
|
||||
show-direct-connect-button: true
|
||||
#
|
||||
# Manually sends the joinServer request when connecting to <= 1.2.5 servers.
|
||||
verify-session-in-old-versions: true
|
||||
# This option indicates if the ViaForge set version button should be shown in the server list.
|
||||
show-add-server-button: true
|
||||
#
|
||||
# This option indicates where the ViaForge button should be located in all screens.
|
||||
# Possible options: TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT
|
||||
via-forge-button-position: "TOP_LEFT"
|
||||
#
|
||||
# This option indicates where the ViaForge set version button should be located in the add server screen.
|
||||
# Possible options: TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT
|
||||
add-server-screen-button-position: "TOP_LEFT"
|
||||
|
@ -29,8 +29,6 @@ import net.raphimc.vialoader.util.VersionEnum;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.datatransfer.StringSelection;
|
||||
import java.io.IOException;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
@ -38,13 +36,23 @@ import java.util.concurrent.ExecutionException;
|
||||
public class GuiProtocolSelector extends GuiScreen {
|
||||
|
||||
private final GuiScreen parent;
|
||||
private final FinishedCallback finishedCallback;
|
||||
|
||||
private SlotList list;
|
||||
|
||||
private String status;
|
||||
private long time;
|
||||
|
||||
public GuiProtocolSelector(GuiScreen parent) {
|
||||
public GuiProtocolSelector(final GuiScreen parent) {
|
||||
this(parent, (version, unused) -> {
|
||||
// Default action is to set the target version and go back to the parent screen.
|
||||
ViaForgeCommon.getManager().setTargetVersion(version);
|
||||
});
|
||||
}
|
||||
|
||||
public GuiProtocolSelector(final GuiScreen parent, final FinishedCallback finishedCallback) {
|
||||
this.parent = parent;
|
||||
this.finishedCallback = finishedCallback;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -125,7 +133,7 @@ public class GuiProtocolSelector extends GuiScreen {
|
||||
|
||||
@Override
|
||||
protected void elementClicked(int index, boolean b, int i1, int i2) {
|
||||
ViaForgeCommon.getManager().setTargetVersion(VersionEnum.SORTED_VERSIONS.get(index));
|
||||
finishedCallback.finished(VersionEnum.SORTED_VERSIONS.get(index), parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -146,4 +154,9 @@ public class GuiProtocolSelector extends GuiScreen {
|
||||
drawCenteredString(mc.fontRenderer,(targetVersion == version ? ChatFormatting.GREEN.toString() : ChatFormatting.DARK_RED.toString()) + version.getName(), width / 2, y, -1);
|
||||
}
|
||||
}
|
||||
|
||||
public interface FinishedCallback {
|
||||
|
||||
void finished(final VersionEnum version, final GuiScreen parent);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,35 @@
|
||||
package de.florianmichael.viaforge.mixin.impl;
|
||||
|
||||
import de.florianmichael.viaforge.common.ViaForgeCommon;
|
||||
import de.florianmichael.viaforge.common.gui.ExtendedServerData;
|
||||
import net.minecraft.client.Minecraft;
|
||||
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;
|
||||
|
||||
import java.net.InetAddress;
|
||||
|
||||
@Mixin(targets = "net.minecraft.client.multiplayer.GuiConnecting$1")
|
||||
public class MixinGuiConnecting_1 {
|
||||
|
||||
@Redirect(method = "run", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/NetworkManager;createNetworkManagerAndConnect(Ljava/net/InetAddress;IZ)Lnet/minecraft/network/NetworkManager;"))
|
||||
public NetworkManager trackVersion(InetAddress address, int i, boolean b) {
|
||||
// We need to track the version of the server we are connecting to, so we can later
|
||||
// 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();
|
||||
if (version != null) {
|
||||
ViaForgeCommon.getManager().setTargetVersionSilent(version);
|
||||
} else {
|
||||
// If the server data does not contain a version, we need to restore the version
|
||||
// we had before, so we don't use the wrong version.
|
||||
ViaForgeCommon.getManager().restoreVersion();
|
||||
}
|
||||
}
|
||||
|
||||
return NetworkManager.createNetworkManagerAndConnect(address, i, b);
|
||||
}
|
||||
}
|
@ -17,8 +17,10 @@
|
||||
*/
|
||||
package de.florianmichael.viaforge.mixin.impl;
|
||||
|
||||
import com.viaversion.viaversion.util.Pair;
|
||||
import de.florianmichael.viaforge.ViaForge112;
|
||||
import de.florianmichael.viaforge.common.ViaForgeCommon;
|
||||
import de.florianmichael.viaforge.common.platform.ViaForgeConfig;
|
||||
import de.florianmichael.viaforge.gui.GuiProtocolSelector;
|
||||
import net.minecraft.client.gui.*;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
@ -33,8 +35,11 @@ public class MixinGuiMainMenu extends GuiScreen {
|
||||
public void hookViaForgeButton(CallbackInfo ci) {
|
||||
ViaForgeCommon.init(ViaForge112.PLATFORM);
|
||||
|
||||
if (ViaForgeCommon.getManager().getConfig().isShowMainMenuButton()) {
|
||||
buttonList.add(new GuiButton(1_000_000_000, 5, 6, 98, 20, "ViaForge"));
|
||||
final ViaForgeConfig config = ViaForgeCommon.getManager().getConfig();
|
||||
if (config.isShowMainMenuButton()) {
|
||||
final Pair<Integer, Integer> pos = config.getViaForgeButtonPosition().getPosition(this.width, this.height);
|
||||
|
||||
buttonList.add(new GuiButton(1_000_000_000, pos.key(), pos.value(), 100, 20, "ViaForge"));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,9 @@
|
||||
*/
|
||||
package de.florianmichael.viaforge.mixin.impl;
|
||||
|
||||
import com.viaversion.viaversion.util.Pair;
|
||||
import de.florianmichael.viaforge.common.ViaForgeCommon;
|
||||
import de.florianmichael.viaforge.common.platform.ViaForgeConfig;
|
||||
import de.florianmichael.viaforge.gui.GuiProtocolSelector;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiMultiplayer;
|
||||
@ -32,8 +34,14 @@ public class MixinGuiMultiplayer extends GuiScreen {
|
||||
|
||||
@Inject(method = "initGui", at = @At("RETURN"))
|
||||
public void hookViaForgeButton(CallbackInfo ci) {
|
||||
if (ViaForgeCommon.getManager().getConfig().isShowMultiplayerButton()) {
|
||||
buttonList.add(new GuiButton(1_000_000_000, 5, 6, 98, 20, "ViaForge"));
|
||||
// If the previous server forced a version, we need to restore the version to the default one.
|
||||
ViaForgeCommon.getManager().restoreVersion();
|
||||
|
||||
final ViaForgeConfig config = ViaForgeCommon.getManager().getConfig();
|
||||
if (config.isShowMultiplayerButton()) {
|
||||
final Pair<Integer, Integer> pos = config.getViaForgeButtonPosition().getPosition(this.width, this.height);
|
||||
|
||||
buttonList.add(new GuiButton(1_000_000_000, pos.key(), pos.value(), 100, 20, "ViaForge"));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,66 @@
|
||||
/*
|
||||
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
|
||||
* Copyright (C) 2021-2023 FlorianMichael/EnZaXD and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.florianmichael.viaforge.mixin.impl;
|
||||
|
||||
import com.viaversion.viaversion.util.Pair;
|
||||
import de.florianmichael.viaforge.common.ViaForgeCommon;
|
||||
import de.florianmichael.viaforge.common.gui.ExtendedServerData;
|
||||
import de.florianmichael.viaforge.common.platform.ViaForgeConfig;
|
||||
import de.florianmichael.viaforge.gui.GuiProtocolSelector;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.gui.GuiScreenAddServer;
|
||||
import net.minecraft.client.multiplayer.ServerData;
|
||||
import net.raphimc.vialoader.util.VersionEnum;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(GuiScreenAddServer.class)
|
||||
public class MixinGuiScreenAddServer extends GuiScreen {
|
||||
|
||||
@Shadow @Final private ServerData serverData;
|
||||
|
||||
@Inject(method = "initGui", at = @At("RETURN"))
|
||||
public void initGui(CallbackInfo ci) {
|
||||
final ViaForgeConfig config = ViaForgeCommon.getManager().getConfig();
|
||||
|
||||
if (config.isShowAddServerButton()) {
|
||||
final Pair<Integer, Integer> pos = config.getAddServerScreenButtonPosition().getPosition(this.width, this.height);
|
||||
|
||||
final VersionEnum 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"));
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "actionPerformed", at = @At("HEAD"))
|
||||
public void actionPerformed(GuiButton button, CallbackInfo ci) {
|
||||
if (ViaForgeCommon.getManager().getConfig().isShowAddServerButton()) {
|
||||
if (button.id == 1_000_000_000) {
|
||||
mc.displayGuiScreen(new GuiProtocolSelector(this, (version, parent) -> {
|
||||
// Set version and go back to the parent screen.
|
||||
((ExtendedServerData) serverData).viaforge_setVersion(version);
|
||||
mc.displayGuiScreen(parent);
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -17,7 +17,9 @@
|
||||
*/
|
||||
package de.florianmichael.viaforge.mixin.impl;
|
||||
|
||||
import com.viaversion.viaversion.util.Pair;
|
||||
import de.florianmichael.viaforge.common.ViaForgeCommon;
|
||||
import de.florianmichael.viaforge.common.platform.ViaForgeConfig;
|
||||
import de.florianmichael.viaforge.gui.GuiProtocolSelector;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
@ -32,8 +34,11 @@ public class MixinGuiScreenServerList extends GuiScreen {
|
||||
|
||||
@Inject(method = "initGui", at = @At("RETURN"))
|
||||
public void hookViaForgeButton(CallbackInfo ci) {
|
||||
if (ViaForgeCommon.getManager().getConfig().isShowDirectConnectButton()) {
|
||||
buttonList.add(new GuiButton(1_000_000_000, 5, 6, 98, 20, "ViaForge"));
|
||||
final ViaForgeConfig config = ViaForgeCommon.getManager().getConfig();
|
||||
if (config.isShowDirectConnectButton()) {
|
||||
final Pair<Integer, Integer> pos = config.getViaForgeButtonPosition().getPosition(this.width, this.height);
|
||||
|
||||
buttonList.add(new GuiButton(1_000_000_000, pos.key(), pos.value(), 100, 20, "ViaForge"));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -18,13 +18,14 @@
|
||||
package de.florianmichael.viaforge.mixin.impl;
|
||||
|
||||
import de.florianmichael.viaforge.common.ViaForgeCommon;
|
||||
import de.florianmichael.viaforge.common.protocolhack.netty.IEncryptionSetup;
|
||||
import de.florianmichael.viaforge.common.protocolhack.netty.VFNetworkManager;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import net.minecraft.network.NettyEncryptingDecoder;
|
||||
import net.minecraft.network.NettyEncryptingEncoder;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.util.CryptManager;
|
||||
import net.minecraft.util.LazyLoadBase;
|
||||
import net.raphimc.vialoader.netty.VLLegacyPipeline;
|
||||
import net.raphimc.vialoader.util.VersionEnum;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
@ -33,25 +34,28 @@ import org.spongepowered.asm.mixin.Unique;
|
||||
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 org.spongepowered.asm.mixin.injection.callback.LocalCapture;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.SecretKey;
|
||||
import java.net.InetAddress;
|
||||
|
||||
@Mixin(NetworkManager.class)
|
||||
public class MixinNetworkManager implements IEncryptionSetup {
|
||||
public class MixinNetworkManager implements VFNetworkManager {
|
||||
|
||||
@Shadow private Channel channel;
|
||||
|
||||
@Unique
|
||||
private Cipher viaforge_decryptionCipher;
|
||||
|
||||
@Inject(method = "channelActive", at = @At("RETURN"))
|
||||
public void trackThisClass(ChannelHandlerContext p_channelActive_1_, CallbackInfo ci) {
|
||||
// We need to access this class later to call the viaforge_setupPreNettyDecryption method.
|
||||
// In one of the ViaLegacy's required providers, so we track this class instance as an own
|
||||
// attribute in the connection and later access it from there and remove it.
|
||||
// Counterpart in {@link java/de/florianmichael/viaforge/common/protocolhack/provider/ViaForgeEncryptionProvider.java}
|
||||
channel.attr(ViaForgeCommon.ENCRYPTION_SETUP).set(this);
|
||||
@Inject(method = "createNetworkManagerAndConnect", 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) {
|
||||
// The connecting screen and server pinger are setting the main target version when a specific version for a server is set,
|
||||
// This works for joining perfect since we can simply restore the version when the server doesn't have a specific one set,
|
||||
// but for the server pinger we need to store the target version and force the pinging to use the target version.
|
||||
// Due to the fact that the server pinger is being called multiple times.
|
||||
((VFNetworkManager) networkmanager).viaforge_setTrackedVersion(ViaForgeCommon.getManager().getTargetVersion());
|
||||
}
|
||||
|
||||
@Inject(method = "enableEncryption", at = @At("HEAD"), cancellable = true)
|
||||
@ -72,8 +76,6 @@ public class MixinNetworkManager implements IEncryptionSetup {
|
||||
|
||||
@Inject(method = "setCompressionThreshold", at = @At("RETURN"))
|
||||
public void reorderPipeline(int p_setCompressionTreshold_1_, CallbackInfo ci) {
|
||||
// When Minecraft enables compression, we need to reorder the pipeline
|
||||
// to match the counterparts of via-decoder <-> encoder and via-encoder <-> encoder
|
||||
ViaForgeCommon.getManager().reorderCompression(channel);
|
||||
}
|
||||
|
||||
@ -82,4 +84,17 @@ public class MixinNetworkManager implements IEncryptionSetup {
|
||||
// Enabling the decryption side for 1.6.4 if the 1.7 -> 1.6 protocol tells us to do
|
||||
this.channel.pipeline().addBefore(VLLegacyPipeline.VIALEGACY_PRE_NETTY_LENGTH_REMOVER_NAME, "decrypt", new NettyEncryptingDecoder(this.viaforge_decryptionCipher));
|
||||
}
|
||||
|
||||
@Unique
|
||||
private VersionEnum viaforge_targetVersion;
|
||||
|
||||
@Override
|
||||
public VersionEnum viaforge_getTrackedVersion() {
|
||||
return viaforge_targetVersion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void viaforge_setTrackedVersion(VersionEnum version) {
|
||||
viaforge_targetVersion = version;
|
||||
}
|
||||
}
|
||||
|
@ -18,8 +18,10 @@
|
||||
package de.florianmichael.viaforge.mixin.impl;
|
||||
|
||||
import de.florianmichael.viaforge.common.ViaForgeCommon;
|
||||
import de.florianmichael.viaforge.common.protocolhack.netty.VFNetworkManager;
|
||||
import io.netty.channel.Channel;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import org.spongepowered.asm.mixin.*;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
@ -27,8 +29,18 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
@Mixin(targets = "net.minecraft.network.NetworkManager$5")
|
||||
public class MixinNetworkManager_5 {
|
||||
|
||||
@Final
|
||||
@Mutable
|
||||
NetworkManager val$networkmanager;
|
||||
|
||||
@Inject(method = "initChannel", at = @At(value = "TAIL"), remap = false)
|
||||
private void onInitChannel(Channel channel, CallbackInfo ci) {
|
||||
// We need to access this class later to call the viaforge_setupPreNettyDecryption method.
|
||||
// In one of the ViaLegacy's required providers, so we track this class instance as an own
|
||||
// attribute in the connection and later access it from there and remove it.
|
||||
// Counterpart in {@link java/de/florianmichael/viaforge/common/protocolhack/provider/ViaForgeEncryptionProvider.java}
|
||||
channel.attr(ViaForgeCommon.VF_NETWORK_MANAGER).set((VFNetworkManager) val$networkmanager);
|
||||
|
||||
ViaForgeCommon.getManager().inject(channel);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,51 @@
|
||||
package de.florianmichael.viaforge.mixin.impl;
|
||||
|
||||
import de.florianmichael.viaforge.common.gui.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;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
|
||||
|
||||
@Mixin(ServerData.class)
|
||||
public class MixinServerData implements ExtendedServerData {
|
||||
|
||||
@Unique
|
||||
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.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(VersionEnum.fromProtocolId(nbtCompound.getInteger("viaforge_version")));
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "copyFrom", at = @At("HEAD"))
|
||||
public void track(ServerData serverDataIn, CallbackInfo ci) {
|
||||
if (serverDataIn instanceof ExtendedServerData) {
|
||||
viaforge_version = ((ExtendedServerData) serverDataIn).viaforge_getVersion();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public VersionEnum viaforge_getVersion() {
|
||||
return viaforge_version;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void viaforge_setVersion(VersionEnum version) {
|
||||
viaforge_version = version;
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package de.florianmichael.viaforge.mixin.impl;
|
||||
|
||||
import de.florianmichael.viaforge.common.ViaForgeCommon;
|
||||
import de.florianmichael.viaforge.common.gui.ExtendedServerData;
|
||||
import net.minecraft.client.multiplayer.ServerData;
|
||||
import net.minecraft.client.network.ServerPinger;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
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;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import java.net.InetAddress;
|
||||
|
||||
@Mixin(ServerPinger.class)
|
||||
public class MixinServerPinger {
|
||||
|
||||
@Unique
|
||||
private ServerData viaforge_serverData;
|
||||
|
||||
@Inject(method = "ping", at = @At("HEAD"))
|
||||
public void trackServerData(ServerData server, CallbackInfo ci) {
|
||||
viaforge_serverData = server;
|
||||
}
|
||||
|
||||
@Redirect(method = "ping", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/NetworkManager;createNetworkManagerAndConnect(Ljava/net/InetAddress;IZ)Lnet/minecraft/network/NetworkManager;"))
|
||||
public NetworkManager trackVersion(InetAddress address, int i, boolean b) {
|
||||
// We need to track the version of the server we are connecting to, so we can later
|
||||
// use it to determine the protocol version to use.
|
||||
// We hope that the current server data is not null
|
||||
|
||||
if (viaforge_serverData instanceof ExtendedServerData) {
|
||||
final VersionEnum version = ((ExtendedServerData) viaforge_serverData).viaforge_getVersion();
|
||||
if (version != null) {
|
||||
ViaForgeCommon.getManager().setTargetVersionSilent(version);
|
||||
} else {
|
||||
// If the server data does not contain a version, we need to restore the version
|
||||
// we had before, so we don't use the wrong version.
|
||||
ViaForgeCommon.getManager().restoreVersion();
|
||||
}
|
||||
|
||||
viaforge_serverData = null;
|
||||
}
|
||||
|
||||
return NetworkManager.createNetworkManagerAndConnect(address, i, b);
|
||||
}
|
||||
}
|
@ -5,12 +5,16 @@
|
||||
"package": "de.florianmichael.viaforge.mixin.impl",
|
||||
"refmap": "mixins.viaforge-mc112.refmap.json",
|
||||
"client": [
|
||||
"MixinGuiConnecting_1",
|
||||
"MixinGuiMainMenu",
|
||||
"MixinGuiMultiplayer",
|
||||
"MixinGuiScreenAddServer",
|
||||
"MixinGuiScreenServerList",
|
||||
"MixinNetHandlerLoginClient",
|
||||
"MixinNetworkManager",
|
||||
"MixinNetworkManager_5",
|
||||
"MixinServerData",
|
||||
"MixinServerPinger",
|
||||
"fixes.MixinEntityPlayerSP"
|
||||
],
|
||||
"verbose": true
|
||||
|
@ -17,7 +17,6 @@
|
||||
*/
|
||||
package de.florianmichael.viaforge.gui;
|
||||
|
||||
import de.florianmichael.viaforge.ViaForge115;
|
||||
import de.florianmichael.viaforge.common.ViaForgeCommon;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
|
@ -18,7 +18,6 @@
|
||||
package de.florianmichael.viaforge.gui;
|
||||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import de.florianmichael.viaforge.ViaForge116;
|
||||
import de.florianmichael.viaforge.common.ViaForgeCommon;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
|
@ -18,7 +18,6 @@
|
||||
package de.florianmichael.viaforge.gui;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import de.florianmichael.viaforge.ViaForge117;
|
||||
import de.florianmichael.viaforge.common.ViaForgeCommon;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
@ -18,7 +18,6 @@
|
||||
package de.florianmichael.viaforge.gui;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import de.florianmichael.viaforge.ViaForge118;
|
||||
import de.florianmichael.viaforge.common.ViaForgeCommon;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
@ -18,7 +18,6 @@
|
||||
package de.florianmichael.viaforge.gui;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import de.florianmichael.viaforge.ViaForge119;
|
||||
import de.florianmichael.viaforge.common.ViaForgeCommon;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
Loading…
Reference in New Issue
Block a user