mirror of
https://github.com/ViaVersion/ViaFabricPlus.git
synced 2024-11-22 11:56:21 +01:00
updated ViaBedrock usage
This commit is contained in:
parent
0af5165f97
commit
2b37095882
@ -49,7 +49,7 @@ public class AuthenticationSettings extends SettingGroup {
|
||||
public final ButtonSetting BEDROCK_ACCOUNT = new ButtonSetting(this, Text.translatable("authentication.viafabricplus.bedrock"), () -> CompletableFuture.runAsync(() -> {
|
||||
try {
|
||||
try (final CloseableHttpClient httpClient = MicrosoftConstants.createHttpClient()) {
|
||||
BedrockAccountHandler.INSTANCE.setAccount(MinecraftAuth.BEDROCK_DEVICE_CODE_LOGIN.getFromInput(httpClient, new StepMsaDeviceCode.MsaDeviceCodeCallback(msaDeviceCode -> {
|
||||
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());
|
||||
@ -64,17 +64,19 @@ public class AuthenticationSettings extends SettingGroup {
|
||||
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.getAccount() != null) {
|
||||
return Text.literal("Bedrock account: " + BedrockAccountHandler.INSTANCE.getAccount().displayName());
|
||||
if (BedrockAccountHandler.INSTANCE.getMcChain() != null) {
|
||||
return Text.literal("Bedrock account: " + BedrockAccountHandler.INSTANCE.getMcChain().displayName());
|
||||
}
|
||||
return super.displayValue();
|
||||
}
|
||||
|
@ -17,17 +17,15 @@
|
||||
*/
|
||||
package de.florianmichael.viafabricplus.definition.bedrock;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import de.florianmichael.viafabricplus.ViaFabricPlus;
|
||||
import de.florianmichael.viafabricplus.base.FileSaver;
|
||||
import net.raphimc.mcauth.MinecraftAuth;
|
||||
import net.raphimc.mcauth.step.bedrock.StepMCChain;
|
||||
import net.raphimc.mcauth.step.bedrock.playfab.StepPlayFabToken;
|
||||
import net.raphimc.mcauth.util.MicrosoftConstants;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class BedrockAccountHandler extends FileSaver {
|
||||
public static BedrockAccountHandler INSTANCE;
|
||||
|
||||
@ -36,7 +34,8 @@ public class BedrockAccountHandler extends FileSaver {
|
||||
BedrockAccountHandler.INSTANCE.init();
|
||||
}
|
||||
|
||||
private StepMCChain.MCChain account;
|
||||
private StepMCChain.MCChain mcChain;
|
||||
private StepPlayFabToken.PlayFabToken playFabToken;
|
||||
|
||||
public BedrockAccountHandler() {
|
||||
super("bedrock.account");
|
||||
@ -44,30 +43,39 @@ public class BedrockAccountHandler extends FileSaver {
|
||||
|
||||
@Override
|
||||
public void write(JsonObject object) {
|
||||
if (account == null) return;
|
||||
if (mcChain == null) return;
|
||||
|
||||
for (Map.Entry<String, JsonElement> entry : account.toJson().entrySet()) {
|
||||
object.add(entry.getKey(), entry.getValue());
|
||||
}
|
||||
object.add("mc-chain", mcChain.toJson());
|
||||
object.add("play-fab-token", playFabToken.toJson());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(JsonObject object) {
|
||||
try {
|
||||
account = MinecraftAuth.BEDROCK_DEVICE_CODE_LOGIN.fromJson(object);
|
||||
mcChain = MinecraftAuth.BEDROCK_DEVICE_CODE_LOGIN.fromJson(object.get("mc-chain").getAsJsonObject());
|
||||
try (final CloseableHttpClient httpClient = MicrosoftConstants.createHttpClient()) {
|
||||
account = MinecraftAuth.BEDROCK_DEVICE_CODE_LOGIN.refresh(httpClient, account);
|
||||
mcChain = MinecraftAuth.BEDROCK_DEVICE_CODE_LOGIN.refresh(httpClient, mcChain);
|
||||
}
|
||||
|
||||
playFabToken = MinecraftAuth.BEDROCK_PLAY_FAB_TOKEN.fromJson(object.get("play-fab-token").getAsJsonObject());
|
||||
try (final CloseableHttpClient httpClient = MicrosoftConstants.createHttpClient()) {
|
||||
playFabToken = MinecraftAuth.BEDROCK_PLAY_FAB_TOKEN.refresh(httpClient, playFabToken);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
ViaFabricPlus.LOGGER.warn("No Bedrock account could be found");
|
||||
}
|
||||
}
|
||||
|
||||
public StepMCChain.MCChain getAccount() {
|
||||
return account;
|
||||
public void setAccount(final StepMCChain.MCChain mcChain, final StepPlayFabToken.PlayFabToken playFabToken) {
|
||||
this.mcChain = mcChain;
|
||||
this.playFabToken = playFabToken;
|
||||
}
|
||||
|
||||
public void setAccount(StepMCChain.MCChain account) {
|
||||
this.account = account;
|
||||
public StepMCChain.MCChain getMcChain() {
|
||||
return mcChain;
|
||||
}
|
||||
|
||||
public StepPlayFabToken.PlayFabToken getPlayFabToken() {
|
||||
return playFabToken;
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,6 @@ package de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft.screen;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.ProfileKey;
|
||||
import net.raphimc.vialoader.util.VersionEnum;
|
||||
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
|
||||
import de.florianmichael.viafabricplus.ViaFabricPlus;
|
||||
import de.florianmichael.viafabricplus.definition.bedrock.BedrockAccountHandler;
|
||||
import de.florianmichael.viafabricplus.definition.c0_30.ClassiCubeAccountHandler;
|
||||
@ -39,7 +38,6 @@ import net.minecraft.network.packet.Packet;
|
||||
import net.minecraft.network.packet.c2s.login.LoginHelloC2SPacket;
|
||||
import net.raphimc.mcauth.step.bedrock.StepMCChain;
|
||||
import net.raphimc.viabedrock.protocol.storage.AuthChainData;
|
||||
import net.raphimc.vialoader.util.VersionEnum;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
@ -50,7 +48,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.UUID;
|
||||
|
||||
@Mixin(targets = "net.minecraft.client.gui.screen.ConnectScreen$1")
|
||||
public class MixinConnectScreen_1 {
|
||||
@ -99,12 +97,13 @@ public class MixinConnectScreen_1 {
|
||||
final VersionEnum targetVersion = ProtocolHack.getTargetVersion(connection.channel);
|
||||
|
||||
if (targetVersion == VersionEnum.bedrockLatest) {
|
||||
final StepMCChain.MCChain account = BedrockAccountHandler.INSTANCE.getAccount();
|
||||
final StepMCChain.MCChain account = BedrockAccountHandler.INSTANCE.getMcChain();
|
||||
if (account == null) return;
|
||||
final UUID deviceId = account.prevResult().initialXblSession().prevResult2().id();
|
||||
final String playFabId = BedrockAccountHandler.INSTANCE.getPlayFabToken().playFabId();
|
||||
|
||||
if (account != null) {
|
||||
userConnection.put(new AuthChainData(userConnection, account.mojangJwt(), account.identityJwt(), account.publicKey(), account.privateKey()));
|
||||
ViaFabricPlus.LOGGER.info("Created AuthChainData for Bedrock authentication!");
|
||||
}
|
||||
userConnection.put(new AuthChainData(userConnection, account.mojangJwt(), account.identityJwt(), account.publicKey(), account.privateKey(), deviceId, playFabId));
|
||||
ViaFabricPlus.LOGGER.info("Created AuthChainData for Bedrock authentication!");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,7 @@ public class PackFormatsMappings {
|
||||
private final static Map<Integer, GameVersion> protocolMap = new HashMap<>();
|
||||
|
||||
public static void load() {
|
||||
registerVersion(VersionEnum.r1_20, 15, "1.20 Pre-release 7", "1.20-pre7");
|
||||
registerVersion(VersionEnum.r1_20, 15, "1.20 Release Candidate 1", "1.20-rc1");
|
||||
registerVersion(VersionEnum.r1_19_4, 13, "1.19.4");
|
||||
registerVersion(VersionEnum.r1_19_3, 12, "1.19.3");
|
||||
registerVersion(VersionEnum.r1_19_1tor1_19_2, 9, "1.19.2");
|
||||
|
Loading…
Reference in New Issue
Block a user