mirror of
https://github.com/ViaVersion/ViaFabricPlus.git
synced 2024-12-26 17:27:58 +01:00
Updated ViaBedrock (Implemented TransferProvider)
This commit is contained in:
parent
aaf1fb6b9e
commit
39efa16f75
@ -42,6 +42,7 @@ public class SettingsSystem extends FileSaver {
|
||||
addGroup(
|
||||
GeneralSettings.INSTANCE,
|
||||
ExperimentalSettings.INSTANCE,
|
||||
BedrockSettings.INSTANCE,
|
||||
AuthenticationSettings.INSTANCE,
|
||||
VisualSettings.INSTANCE,
|
||||
DebugSettings.INSTANCE
|
||||
|
@ -17,28 +17,9 @@
|
||||
*/
|
||||
package de.florianmichael.viafabricplus.base.settings.groups;
|
||||
|
||||
import de.florianmichael.viafabricplus.definition.bedrock.BedrockAccountHandler;
|
||||
import de.florianmichael.viafabricplus.screen.impl.base.ProtocolSelectionScreen;
|
||||
import de.florianmichael.viafabricplus.screen.impl.settings.SettingsScreen;
|
||||
import de.florianmichael.viafabricplus.base.settings.base.SettingGroup;
|
||||
import de.florianmichael.viafabricplus.base.settings.type_impl.BooleanSetting;
|
||||
import de.florianmichael.viafabricplus.base.settings.type_impl.ButtonSetting;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.screen.ConfirmScreen;
|
||||
import net.minecraft.client.gui.screen.NoticeScreen;
|
||||
import net.minecraft.client.gui.screen.TitleScreen;
|
||||
import net.minecraft.client.gui.screen.multiplayer.MultiplayerScreen;
|
||||
import net.minecraft.text.MutableText;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Util;
|
||||
import net.raphimc.mcauth.MinecraftAuth;
|
||||
import net.raphimc.mcauth.step.msa.StepMsaDeviceCode;
|
||||
import net.raphimc.mcauth.util.MicrosoftConstants;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class AuthenticationSettings extends SettingGroup {
|
||||
public final static AuthenticationSettings INSTANCE = new AuthenticationSettings();
|
||||
@ -46,41 +27,6 @@ public class AuthenticationSettings extends SettingGroup {
|
||||
public final BooleanSetting useBetaCraftAuthentication = new BooleanSetting(this, Text.translatable("authentication.viafabricplus.betacraft"), true);
|
||||
public final BooleanSetting allowViaLegacyToCallJoinServerToVerifySession = new BooleanSetting(this, Text.translatable("authentication.viafabricplus.verify"), true);
|
||||
public final BooleanSetting disconnectIfJoinServerCallFails = new BooleanSetting(this, Text.translatable("authentication.viafabricplus.fail"), true);
|
||||
public final ButtonSetting BEDROCK_ACCOUNT = new ButtonSetting(this, Text.translatable("authentication.viafabricplus.bedrock"), () -> CompletableFuture.runAsync(() -> {
|
||||
try {
|
||||
try (final CloseableHttpClient httpClient = MicrosoftConstants.createHttpClient()) {
|
||||
final var mcChain = MinecraftAuth.BEDROCK_DEVICE_CODE_LOGIN.getFromInput(httpClient, new StepMsaDeviceCode.MsaDeviceCodeCallback(msaDeviceCode -> {
|
||||
MinecraftClient.getInstance().execute(() -> MinecraftClient.getInstance().setScreen(new ConfirmScreen(consumer -> {
|
||||
if (consumer) {
|
||||
MinecraftClient.getInstance().keyboard.setClipboard(msaDeviceCode.userCode());
|
||||
} else {
|
||||
SettingsScreen.INSTANCE.open(new MultiplayerScreen(new TitleScreen()));
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}, Text.literal("Microsoft Bedrock login"), Text.translatable("bedrocklogin.viafabricplus.text", msaDeviceCode.userCode()), Text.translatable("words.viafabricplus.copy"), Text.translatable("words.viafabricplus.cancel"))));
|
||||
try {
|
||||
Util.getOperatingSystem().open(new URI(msaDeviceCode.verificationUri()));
|
||||
} catch (URISyntaxException e) {
|
||||
e.printStackTrace();
|
||||
MinecraftClient.getInstance().execute(() -> MinecraftClient.getInstance().setScreen(new NoticeScreen(() -> Thread.currentThread().interrupt(), Text.literal("Microsoft Bedrock login"), Text.translatable("bedrocklogin.viafabricplus.error"), Text.translatable("words.viafabricplus.cancel"), false)));
|
||||
}
|
||||
}));
|
||||
BedrockAccountHandler.INSTANCE.setAccount(mcChain, MinecraftAuth.BEDROCK_PLAY_FAB_TOKEN.getFromInput(httpClient, mcChain.prevResult().fullXblSession()));
|
||||
}
|
||||
ProtocolSelectionScreen.INSTANCE.open(new MultiplayerScreen(new TitleScreen()));
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
MinecraftClient.getInstance().execute(() -> MinecraftClient.getInstance().setScreen(new NoticeScreen(() -> Thread.currentThread().interrupt(), Text.literal("Microsoft Bedrock login"), Text.translatable("bedrocklogin.viafabricplus.error"), Text.translatable("words.viafabricplus.cancel"), false)));
|
||||
}
|
||||
})) {
|
||||
@Override
|
||||
public MutableText displayValue() {
|
||||
if (BedrockAccountHandler.INSTANCE.getMcChain() != null) {
|
||||
return Text.literal("Bedrock account: " + BedrockAccountHandler.INSTANCE.getMcChain().displayName());
|
||||
}
|
||||
return super.displayValue();
|
||||
}
|
||||
};
|
||||
public final BooleanSetting forceCPEIfUsingClassiCube = new BooleanSetting(this, Text.translatable("authentication.viafabricplus.classicube"), true);
|
||||
public final BooleanSetting spoofUserNameIfUsingClassiCube = new BooleanSetting(this, Text.translatable("authentication.viafabricplus.spoof"), true);
|
||||
public final BooleanSetting allowViaLegacyToLoadSkinsInLegacyVersions = new BooleanSetting(this, Text.translatable("authentication.viafabricplus.skin"), true);
|
||||
|
@ -0,0 +1,86 @@
|
||||
/*
|
||||
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
|
||||
* 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.viafabricplus.base.settings.groups;
|
||||
|
||||
import de.florianmichael.viafabricplus.base.settings.base.SettingGroup;
|
||||
import de.florianmichael.viafabricplus.base.settings.type_impl.BooleanSetting;
|
||||
import de.florianmichael.viafabricplus.base.settings.type_impl.ButtonSetting;
|
||||
import de.florianmichael.viafabricplus.definition.bedrock.BedrockAccountHandler;
|
||||
import de.florianmichael.viafabricplus.screen.impl.base.ProtocolSelectionScreen;
|
||||
import de.florianmichael.viafabricplus.screen.impl.settings.SettingsScreen;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.screen.ConfirmScreen;
|
||||
import net.minecraft.client.gui.screen.NoticeScreen;
|
||||
import net.minecraft.client.gui.screen.TitleScreen;
|
||||
import net.minecraft.client.gui.screen.multiplayer.MultiplayerScreen;
|
||||
import net.minecraft.text.MutableText;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Util;
|
||||
import net.raphimc.mcauth.MinecraftAuth;
|
||||
import net.raphimc.mcauth.step.msa.StepMsaDeviceCode;
|
||||
import net.raphimc.mcauth.util.MicrosoftConstants;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class BedrockSettings extends SettingGroup {
|
||||
public final static BedrockSettings INSTANCE = new BedrockSettings();
|
||||
|
||||
public final ButtonSetting BEDROCK_ACCOUNT = new ButtonSetting(this, Text.translatable("bedrock.viafabricplus.authentication"), () -> CompletableFuture.runAsync(() -> {
|
||||
try {
|
||||
try (final CloseableHttpClient httpClient = MicrosoftConstants.createHttpClient()) {
|
||||
final var mcChain = MinecraftAuth.BEDROCK_DEVICE_CODE_LOGIN.getFromInput(httpClient, new StepMsaDeviceCode.MsaDeviceCodeCallback(msaDeviceCode -> {
|
||||
MinecraftClient.getInstance().execute(() -> MinecraftClient.getInstance().setScreen(new ConfirmScreen(consumer -> {
|
||||
if (consumer) {
|
||||
MinecraftClient.getInstance().keyboard.setClipboard(msaDeviceCode.userCode());
|
||||
} else {
|
||||
SettingsScreen.INSTANCE.open(new MultiplayerScreen(new TitleScreen()));
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}, Text.literal("Microsoft Bedrock login"), Text.translatable("bedrocklogin.viafabricplus.text", msaDeviceCode.userCode()), Text.translatable("words.viafabricplus.copy"), Text.translatable("words.viafabricplus.cancel"))));
|
||||
try {
|
||||
Util.getOperatingSystem().open(new URI(msaDeviceCode.verificationUri()));
|
||||
} catch (URISyntaxException e) {
|
||||
e.printStackTrace();
|
||||
MinecraftClient.getInstance().execute(() -> MinecraftClient.getInstance().setScreen(new NoticeScreen(() -> Thread.currentThread().interrupt(), Text.literal("Microsoft Bedrock login"), Text.translatable("bedrocklogin.viafabricplus.error"), Text.translatable("words.viafabricplus.cancel"), false)));
|
||||
}
|
||||
}));
|
||||
BedrockAccountHandler.INSTANCE.setAccount(mcChain, MinecraftAuth.BEDROCK_PLAY_FAB_TOKEN.getFromInput(httpClient, mcChain.prevResult().fullXblSession()));
|
||||
}
|
||||
ProtocolSelectionScreen.INSTANCE.open(new MultiplayerScreen(new TitleScreen()));
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
MinecraftClient.getInstance().execute(() -> MinecraftClient.getInstance().setScreen(new NoticeScreen(() -> Thread.currentThread().interrupt(), Text.literal("Microsoft Bedrock login"), Text.translatable("bedrocklogin.viafabricplus.error"), Text.translatable("words.viafabricplus.cancel"), false)));
|
||||
}
|
||||
})) {
|
||||
@Override
|
||||
public MutableText displayValue() {
|
||||
if (BedrockAccountHandler.INSTANCE.getMcChain() != null) {
|
||||
return Text.literal("Bedrock account: " + BedrockAccountHandler.INSTANCE.getMcChain().displayName());
|
||||
}
|
||||
return super.displayValue();
|
||||
}
|
||||
};
|
||||
public final BooleanSetting confirmServerTransferInBedrockEdition = new BooleanSetting(this, Text.translatable("bedrock.viafabricplus.confirmtransfer"), true);
|
||||
|
||||
public BedrockSettings() {
|
||||
super(Text.translatable("settings.viafabricplus.bedrock"));
|
||||
}
|
||||
}
|
@ -45,7 +45,7 @@ public class MixinJoinPackets {
|
||||
return levelId;
|
||||
}
|
||||
|
||||
@Redirect(method = "lambda$register$2", at = @At(value = "INVOKE", target = "Lcom/viaversion/viaversion/api/protocol/packet/PacketWrapper;read(Lcom/viaversion/viaversion/api/type/Type;)Ljava/lang/Object;", ordinal = 64))
|
||||
@Redirect(method = "lambda$register$2", at = @At(value = "INVOKE", target = "Lcom/viaversion/viaversion/api/protocol/packet/PacketWrapper;read(Lcom/viaversion/viaversion/api/type/Type;)Ljava/lang/Object;", ordinal = 63))
|
||||
private static Object trackEnchantmentSeed(PacketWrapper instance, Type<VarIntType> tType) throws Exception {
|
||||
final Object enchantmentSeed = instance.read(tType);
|
||||
instance.user().get(JoinGameStorage.class).setEnchantmentSeed((Integer) enchantmentSeed);
|
||||
|
@ -28,6 +28,7 @@ import de.florianmichael.viafabricplus.definition.signatures.v1_19_0.provider.Co
|
||||
import de.florianmichael.viafabricplus.protocolhack.provider.ViaFabricPlusCommandArgumentsProvider;
|
||||
import de.florianmichael.viafabricplus.protocolhack.provider.viabedrock.ViaFabricPlusBlobCacheProvider;
|
||||
import de.florianmichael.viafabricplus.protocolhack.provider.viabedrock.ViaFabricPlusNettyPipelineProvider;
|
||||
import de.florianmichael.viafabricplus.protocolhack.provider.viabedrock.ViaFabricPlusTransferProvider;
|
||||
import de.florianmichael.viafabricplus.protocolhack.provider.vialegacy.*;
|
||||
import de.florianmichael.viafabricplus.protocolhack.provider.viaversion.ViaFabricPlusBaseVersionProvider;
|
||||
import de.florianmichael.viafabricplus.protocolhack.provider.viaversion.ViaFabricPlusHandItemProvider;
|
||||
@ -36,6 +37,7 @@ import de.florianmichael.viafabricplus.protocolhack.provider.viaversion.ViaFabri
|
||||
import de.florianmichael.viafabricplus.protocolhack.provider.viaversion.ViaFabricPlusPlayerLookTargetProvider;
|
||||
import net.raphimc.viabedrock.protocol.providers.BlobCacheProvider;
|
||||
import net.raphimc.viabedrock.protocol.providers.NettyPipelineProvider;
|
||||
import net.raphimc.viabedrock.protocol.providers.TransferProvider;
|
||||
import net.raphimc.vialegacy.protocols.classic.protocola1_0_15toc0_28_30.providers.ClassicMPPassProvider;
|
||||
import net.raphimc.vialegacy.protocols.classic.protocola1_0_15toc0_28_30.providers.ClassicWorldHeightProvider;
|
||||
import net.raphimc.vialegacy.protocols.release.protocol1_3_1_2to1_2_4_5.providers.OldAuthProvider;
|
||||
@ -68,5 +70,6 @@ public class ViaFabricPlusVLLoader extends VLLoader {
|
||||
|
||||
providers.use(NettyPipelineProvider.class, new ViaFabricPlusNettyPipelineProvider());
|
||||
providers.use(BlobCacheProvider.class, new ViaFabricPlusBlobCacheProvider());
|
||||
providers.use(TransferProvider.class, new ViaFabricPlusTransferProvider());
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
|
||||
* 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.viafabricplus.protocolhack.provider.viabedrock;
|
||||
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import de.florianmichael.viafabricplus.base.settings.groups.BedrockSettings;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.screen.ConfirmScreen;
|
||||
import net.minecraft.client.gui.screen.ConnectScreen;
|
||||
import net.minecraft.client.gui.screen.TitleScreen;
|
||||
import net.minecraft.client.gui.screen.multiplayer.MultiplayerScreen;
|
||||
import net.minecraft.client.network.ServerAddress;
|
||||
import net.minecraft.client.network.ServerInfo;
|
||||
import net.minecraft.text.Text;
|
||||
import net.raphimc.viabedrock.protocol.providers.TransferProvider;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
public class ViaFabricPlusTransferProvider extends TransferProvider {
|
||||
|
||||
private void connect(final InetSocketAddress newAddress) {
|
||||
final var mc = MinecraftClient.getInstance();
|
||||
mc.world.disconnect();
|
||||
|
||||
final var serverInfo = new ServerInfo(newAddress.getHostName(), newAddress.getHostName() + ":" + newAddress.getPort(), false);
|
||||
ConnectScreen.connect(new MultiplayerScreen(new TitleScreen()), mc, ServerAddress.parse(serverInfo.address), serverInfo, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connectToServer(UserConnection user, InetSocketAddress newAddress) throws Exception {
|
||||
final var mc = MinecraftClient.getInstance();
|
||||
mc.execute(() -> {
|
||||
if (BedrockSettings.INSTANCE.confirmServerTransferInBedrockEdition.getValue()) {
|
||||
mc.setScreen(new ConfirmScreen(
|
||||
(bl) -> {
|
||||
if (bl)
|
||||
connect(newAddress);
|
||||
else
|
||||
MinecraftClient.getInstance().setScreen(null);
|
||||
},
|
||||
Text.of("ViaFabricPlus"),
|
||||
Text.translatable("bedrockplay.viafabricplus.confirmtransfer", newAddress.getHostName() + ":" + newAddress.getPort())
|
||||
));
|
||||
} else {
|
||||
connect(newAddress);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -22,6 +22,7 @@
|
||||
"settings.viafabricplus.visual": "Visual",
|
||||
"settings.viafabricplus.debug": "Debug",
|
||||
"settings.viafabricplus.general": "General",
|
||||
"settings.viafabricplus.bedrock": "Bedrock",
|
||||
|
||||
"general.viafabricplus.secret": "Show Super Secret Settings",
|
||||
"general.viafabricplus.extrainformation": "Show extra information in Debug Hud",
|
||||
@ -31,6 +32,9 @@
|
||||
"general.viafabricplus.autodetect": "Auto detect version",
|
||||
"general.viafabricplus.advertised": "Show advertised/server version in Multiplayer",
|
||||
|
||||
"bedrock.viafabricplus.confirmtransfer": "Open prompt GUI to confirm transferring to other servers",
|
||||
"bedrock.viafabricplus.authentication": "Click to set account for Bedrock edition",
|
||||
|
||||
"experimental.viafabricplus.chunkborderfix": "Fix Chunk borders",
|
||||
"experimental.viafabricplus.watermovement": "Water movement edge detection",
|
||||
"experimental.viafabricplus.fontcachefix": "Fix Font Cache",
|
||||
@ -53,7 +57,6 @@
|
||||
"authentication.viafabricplus.classicube": "Force CPE Version if using ClassiCube",
|
||||
"authentication.viafabricplus.spoof": "Spoof Username to ClassiCube Name if using ClassiCube",
|
||||
"authentication.viafabricplus.skin": "Allow ViaLegacy to load skins in legacy versions",
|
||||
"authentication.viafabricplus.bedrock": "Click to set account for Bedrock edition",
|
||||
"authentication.viafabricplus.error": "ViaFabricPlus failed to verify your session! Please log in into an Account or disable the BetaCraft authentication in the ViaFabricPlus Settings",
|
||||
|
||||
"visual.viafabricplus.secure": "Disable secure chat warning",
|
||||
@ -70,6 +73,7 @@
|
||||
|
||||
"bedrocklogin.viafabricplus.text": "Your browser should have opened.\nPlease enter the following Code: %s\nClosing this screen will cancel the process!",
|
||||
"bedrocklogin.viafabricplus.error": "An error has occurred! See the latest.log for more information,\nplease report the bug at: \nhttps://github.com/ViaVersion/ViaFabricPlus/issues",
|
||||
"bedrockplay.viafabricplus.confirmtransfer": "Do you want to transfer to the following server?\n%s\n\nThis will disconnect the current server and connect to the new one.",
|
||||
|
||||
"forceversion.viafabricplus.title": "Please select the version with which the server should be pinged/connected",
|
||||
|
||||
|
@ -10,6 +10,7 @@ accessible field net/minecraft/client/MinecraftClient fontManager Lnet/minecraft
|
||||
accessible field net/minecraft/client/font/FontManager fontStorages Ljava/util/Map;
|
||||
accessible field net/minecraft/network/ClientConnection EPOLL_CLIENT_IO_GROUP Lnet/minecraft/util/Lazy;
|
||||
accessible field net/minecraft/network/ClientConnection LOCAL_CLIENT_IO_GROUP Lnet/minecraft/util/Lazy;
|
||||
accessible field net/minecraft/client/gui/screen/GameMenuScreen exitButton Lnet/minecraft/client/gui/widget/ButtonWidget;
|
||||
|
||||
accessible method net/minecraft/screen/GenericContainerScreenHandler <init> (Lnet/minecraft/screen/ScreenHandlerType;ILnet/minecraft/entity/player/PlayerInventory;I)V
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user