diff --git a/build.gradle b/build.gradle index c360f25..3e49636 100644 --- a/build.gradle +++ b/build.gradle @@ -106,7 +106,7 @@ dependencies { include "net.lenni0451:Reflect:1.2.0" include "net.lenni0451:LambdaEvents:2.0.3" include "net.raphimc.netminecraft:all:2.3.3" - include("net.raphimc:MinecraftAuth:2.1.3") { + include("net.raphimc:MinecraftAuth:2.1.4-SNAPSHOT") { exclude group: "com.google.code.gson", module: "gson" exclude group: "org.slf4j", module: "slf4j-api" } diff --git a/src/main/java/net/raphimc/viaproxy/proxy/external_interface/ExternalInterface.java b/src/main/java/net/raphimc/viaproxy/proxy/external_interface/ExternalInterface.java index acd3981..5f9346f 100644 --- a/src/main/java/net/raphimc/viaproxy/proxy/external_interface/ExternalInterface.java +++ b/src/main/java/net/raphimc/viaproxy/proxy/external_interface/ExternalInterface.java @@ -117,7 +117,9 @@ public class ExternalInterface { } else if (Options.MC_ACCOUNT instanceof BedrockAccount && proxyConnection.getServerVersion().equals(VersionEnum.bedrockLatest)) { final BedrockAccount bedrockAccount = (BedrockAccount) Options.MC_ACCOUNT; final StepMCChain.MCChain mcChain = bedrockAccount.getMcChain(); - user.put(new AuthChainData(user, mcChain.mojangJwt(), mcChain.identityJwt(), mcChain.publicKey(), mcChain.privateKey())); + final UUID deviceId = mcChain.prevResult().initialXblSession().prevResult2().id(); + final String playFabId = bedrockAccount.getPlayFabToken().playFabId(); + user.put(new AuthChainData(user, mcChain.mojangJwt(), mcChain.identityJwt(), mcChain.publicKey(), mcChain.privateKey(), deviceId, playFabId)); } } diff --git a/src/main/java/net/raphimc/viaproxy/saves/SaveManager.java b/src/main/java/net/raphimc/viaproxy/saves/SaveManager.java index ae9b92d..50546a9 100644 --- a/src/main/java/net/raphimc/viaproxy/saves/SaveManager.java +++ b/src/main/java/net/raphimc/viaproxy/saves/SaveManager.java @@ -52,6 +52,8 @@ public class SaveManager { final JsonObject saveObject = GSON.fromJson(reader, JsonObject.class); reader.close(); + SaveMigrator.migrate(saveObject); + RStream .of(this) .fields() @@ -66,8 +68,6 @@ public class SaveManager { Logger.LOGGER.error("Failed to load save " + save.getName(), e); } }); - - SaveMigrator.migrate(this, saveObject); } catch (Throwable e) { Logger.LOGGER.error("Failed to load saves from file", e); } diff --git a/src/main/java/net/raphimc/viaproxy/saves/SaveMigrator.java b/src/main/java/net/raphimc/viaproxy/saves/SaveMigrator.java index a2cbeef..b66aca9 100644 --- a/src/main/java/net/raphimc/viaproxy/saves/SaveMigrator.java +++ b/src/main/java/net/raphimc/viaproxy/saves/SaveMigrator.java @@ -17,22 +17,26 @@ */ package net.raphimc.viaproxy.saves; -import com.google.gson.JsonElement; +import com.google.gson.JsonArray; import com.google.gson.JsonObject; -import net.raphimc.mcauth.MinecraftAuth; +import net.raphimc.viaproxy.saves.impl.accounts.BedrockAccount; import net.raphimc.viaproxy.util.logging.Logger; public class SaveMigrator { - public static void migrate(final SaveManager saveManager, final JsonObject jsonObject) { + public static void migrate(final JsonObject jsonObject) { try { - if (jsonObject.has("accounts")) { - for (JsonElement element : jsonObject.getAsJsonArray("accounts")) { - final JsonObject object = element.getAsJsonObject(); - if (object.has("is_offline_mode_account") && object.get("is_offline_mode_account").getAsBoolean()) { - saveManager.accountsSave.addAccount(object.get("name").getAsString()); - } else { - saveManager.accountsSave.addAccount(MinecraftAuth.JAVA_DEVICE_CODE_LOGIN.fromJson(object)); + if (jsonObject.has("new_accounts")) { + final JsonArray accountsArray = jsonObject.getAsJsonArray("new_accounts"); + for (int i = 0; i < accountsArray.size(); i++) { + final JsonObject object = accountsArray.get(i).getAsJsonObject(); + final String type = object.get("account_type").getAsString(); + if (BedrockAccount.class.getName().equals(type) && !object.has("mc_chain")) { + final JsonObject newObject = new JsonObject(); + object.remove("account_type"); + newObject.add("mc_chain", object); + newObject.addProperty("account_type", type); + accountsArray.set(i, newObject); } } } diff --git a/src/main/java/net/raphimc/viaproxy/saves/impl/accounts/BedrockAccount.java b/src/main/java/net/raphimc/viaproxy/saves/impl/accounts/BedrockAccount.java index d16c75c..827a773 100644 --- a/src/main/java/net/raphimc/viaproxy/saves/impl/accounts/BedrockAccount.java +++ b/src/main/java/net/raphimc/viaproxy/saves/impl/accounts/BedrockAccount.java @@ -20,6 +20,7 @@ package net.raphimc.viaproxy.saves.impl.accounts; import com.google.gson.JsonObject; import net.raphimc.mcauth.MinecraftAuth; import net.raphimc.mcauth.step.bedrock.StepMCChain; +import net.raphimc.mcauth.step.bedrock.playfab.StepPlayFabToken; import org.apache.http.impl.client.CloseableHttpClient; import java.util.UUID; @@ -27,9 +28,13 @@ import java.util.UUID; public class BedrockAccount extends Account { private StepMCChain.MCChain mcChain; + private StepPlayFabToken.PlayFabToken playFabToken; public BedrockAccount(final JsonObject jsonObject) throws Throwable { - this.mcChain = MinecraftAuth.BEDROCK_DEVICE_CODE_LOGIN.fromJson(jsonObject); + this.mcChain = MinecraftAuth.BEDROCK_DEVICE_CODE_LOGIN.fromJson(jsonObject.getAsJsonObject("mc_chain")); + if (jsonObject.has("play_fab_token")) { + this.playFabToken = MinecraftAuth.BEDROCK_PLAY_FAB_TOKEN.fromJson(jsonObject.getAsJsonObject("play_fab_token")); + } } public BedrockAccount(final StepMCChain.MCChain mcChain) { @@ -38,7 +43,10 @@ public class BedrockAccount extends Account { @Override public JsonObject toJson() { - return this.mcChain.toJson(); + final JsonObject jsonObject = new JsonObject(); + jsonObject.add("mc_chain", this.mcChain.toJson()); + jsonObject.add("play_fab_token", this.playFabToken.toJson()); + return jsonObject; } @Override @@ -55,6 +63,10 @@ public class BedrockAccount extends Account { return this.mcChain; } + public StepPlayFabToken.PlayFabToken getPlayFabToken() { + return this.playFabToken; + } + @Override public String getDisplayString() { return this.getName() + " (Bedrock)"; @@ -63,6 +75,14 @@ public class BedrockAccount extends Account { @Override public void refresh(CloseableHttpClient httpClient) throws Exception { this.mcChain = MinecraftAuth.BEDROCK_DEVICE_CODE_LOGIN.refresh(httpClient, this.mcChain); + try { + if (this.playFabToken == null) { + throw new NullPointerException(); + } + this.playFabToken = MinecraftAuth.BEDROCK_PLAY_FAB_TOKEN.refresh(httpClient, this.playFabToken); + } catch (Throwable e) { + this.playFabToken = MinecraftAuth.BEDROCK_PLAY_FAB_TOKEN.getFromInput(httpClient, this.mcChain.prevResult().fullXblSession()); + } } }