Internal, renderer and UI changes + 1.19-pre1 support
Minecraft 1.19 support: - Since 1.19-pre1, LWJGL 3.3.1 is used. However, LWJGL 3.2.3 still works with it, at least for this Minecraft release. - Added a hack to skip calling to ObjC codes (skipped an asset file to skip setting the icon) - JNA version replacing: now only change to 5.8.0 if version < 5.8.0 Internal changes: - Cleanup: moved global functions to a new place - Handle demo user correctly: actually authenticate the game with demo's access token and use the Xbox gamertag as the username - Start moving strings to Localizable.strings (WIP) - Re-wrote the Microsoft authentication and account management to Objective-C - Assets downloading: added a tiny sleep call so that the UI won’t be frozen when too many tasks are executed at the same time Renderers changes - gl4es: `init_constructor` is now enabled, therefore moved the preload part to before `eglInitialize` (or EGL will be de-init after gl4es's hardware test). - gl4es-extra (aka holy gl4es 1.1.4) is now used to replace the regular gl4es. This fixes VBO issue on version < 1.13 and some extra stuff. https://github.com/PojavLauncherTeam/gl4es-114-extra/commit/d6cf5c4 - Removed gl4es 1.1.5 and `Disable gl4es shaderconv` as it's unnecessary for now - Removed vgpu, as it requires some missing extensions when come to shaders User interface: - The account selection list now displays the skin head (or the Xbox gamerpic if demo) and the account type
This commit is contained in:
1 parent
76ad17dd7c
commit
2a9d3909f8
31 files changed
+674
-692
No files matched your search
@@ -11,10 +11,7 @@ import net.kdt.pojavlaunch.utils.*;
|
||||
import net.kdt.pojavlaunch.value.*;
|
||||
|
||||
public class PLaunchApp {
|
||||
private static float currProgress, maxProgress;
|
||||
|
||||
public static volatile JMinecraftVersionList.Version mVersion;
|
||||
public static boolean mIsAssetsProcessing = false;
|
||||
private static float currProgress, maxProgress;
|
||||
|
||||
public static void main(String[] args) throws Throwable {
|
||||
try {
|
||||
@@ -40,10 +37,10 @@ public class PLaunchApp {
|
||||
UIKit.launchUI();
|
||||
}
|
||||
|
||||
public static String getSelectedVersion() {
|
||||
public static String getStringFromPref(String pref) {
|
||||
try {
|
||||
String plistContent = Tools.read(Tools.DIR_APP_DATA + "/launcher_preferences.plist");
|
||||
plistContent = plistContent.substring(plistContent.indexOf("<key>selected_version</key>") + 27);
|
||||
plistContent = plistContent.substring(plistContent.indexOf("<key>" + pref + "</key>") + pref.length() + 11);
|
||||
return plistContent.substring(
|
||||
plistContent.indexOf("<string>") + 8,
|
||||
plistContent.indexOf("</string>"));
|
||||
@@ -56,23 +53,21 @@ public class PLaunchApp {
|
||||
// Called from SurfaceViewController
|
||||
public static void launchMinecraft() {
|
||||
try {
|
||||
if (AccountJNI.CURRENT_ACCOUNT == null) {
|
||||
AccountJNI.CURRENT_ACCOUNT = MinecraftAccount.load(System.getProperty("pojav.selectedAccount"));
|
||||
}
|
||||
mVersion = Tools.getVersionInfo(getSelectedVersion());
|
||||
System.out.println("Launching Minecraft " + mVersion.id);
|
||||
MinecraftAccount account = MinecraftAccount.load(getStringFromPref("internal_selected_account"));
|
||||
JMinecraftVersionList.Version version = Tools.getVersionInfo(getStringFromPref("selected_version"));
|
||||
System.out.println("Launching Minecraft " + version.id);
|
||||
String configPath;
|
||||
if (mVersion.logging != null) {
|
||||
if (mVersion.logging.client.file.id.equals("client-1.12.xml")) {
|
||||
if (version.logging != null) {
|
||||
if (version.logging.client.file.id.equals("client-1.12.xml")) {
|
||||
configPath = Tools.DIR_BUNDLE + "/log4j-rce-patch-1.12.xml";
|
||||
} else if (mVersion.logging.client.file.id.equals("client-1.7.xml")) {
|
||||
} else if (version.logging.client.file.id.equals("client-1.7.xml")) {
|
||||
configPath = Tools.DIR_BUNDLE + "/log4j-rce-patch-1.7.xml";
|
||||
} else {
|
||||
configPath = Tools.DIR_GAME_NEW + "/" + mVersion.logging.client.file.id;
|
||||
configPath = Tools.DIR_GAME_NEW + "/" + version.logging.client.file.id;
|
||||
}
|
||||
System.setProperty("log4j.configurationFile", configPath);
|
||||
}
|
||||
Tools.launchMinecraft(AccountJNI.CURRENT_ACCOUNT, mVersion);
|
||||
Tools.launchMinecraft(account, version);
|
||||
} catch (Throwable th) {
|
||||
Tools.showError(th);
|
||||
}
|
||||
|
||||
@@ -155,7 +155,7 @@ public final class Tools
|
||||
}
|
||||
|
||||
public static String[] getMinecraftArgs(MinecraftAccount profile, JMinecraftVersionList.Version versionInfo) {
|
||||
String username = profile.username;
|
||||
String username = profile.username.replace("Demo.", "");
|
||||
String versionName = versionInfo.id;
|
||||
if (versionInfo.inheritsFrom != null) {
|
||||
versionName = versionInfo.inheritsFrom;
|
||||
@@ -210,7 +210,6 @@ public final class Tools
|
||||
minecraftArgs.add(Integer.toString(GLFW.mGLFWWindowWidth));
|
||||
minecraftArgs.add("--fullscreenHeight");
|
||||
minecraftArgs.add(Integer.toString(GLFW.mGLFWWindowHeight));
|
||||
|
||||
String[] argsFromJson = JSONUtils.insertJSONValueList(
|
||||
splitAndFilterEmpty(
|
||||
versionInfo.minecraftArguments == null ?
|
||||
@@ -235,8 +234,8 @@ public final class Tools
|
||||
|
||||
private static String[] splitAndFilterEmpty(String argStr, MinecraftAccount profile) {
|
||||
List<String> strList = new ArrayList<String>();
|
||||
if(profile.username.equals("demo_user") && profile.accessToken.equals("-1") && profile.profileId.equals("25e00594-cf57-3f87-b3af-3f06591be252")) {
|
||||
strList.add("--demo"); // if statement is this complex to prevent tampering with the .json
|
||||
if(profile.username.startsWith("Demo.")) {
|
||||
strList.add("--demo");
|
||||
}
|
||||
for (String arg : argStr.split(" ")) {
|
||||
if (!arg.isEmpty()) {
|
||||
@@ -409,6 +408,8 @@ public final class Tools
|
||||
} else if (libItem.name.startsWith("net.java.dev.jna:jna:")) {
|
||||
// Special handling for LabyMod 1.8.9 and Forge 1.12.2(?)
|
||||
// we have libjnidispatch 5.8.0 in Frameworks directory
|
||||
int[] version = Arrays.stream(libItem.name.split(":")[2].split("\\.")).mapToInt(Integer::parseInt).toArray();
|
||||
if (version[0] >= 5 && version[1] >= 8) return;
|
||||
System.out.println("Library " + libItem.name + " has been changed to version 5.8.0");
|
||||
libItem.name = "net.java.dev.jna:jna:5.8.0";
|
||||
libItem.downloads.artifact.path = "net/java/dev/jna/jna/5.8.0/jna-5.8.0.jar";
|
||||
|
||||
-58
@@ -1,58 +0,0 @@
|
||||
package net.kdt.pojavlaunch.authenticator.microsoft;
|
||||
|
||||
import android.util.*;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.text.*;
|
||||
import java.util.*;
|
||||
|
||||
import net.kdt.pojavlaunch.*;
|
||||
import net.kdt.pojavlaunch.value.launcherprofiles.*;
|
||||
import net.kdt.pojavlaunch.value.*;
|
||||
|
||||
import org.json.*;
|
||||
|
||||
public class MicrosoftAuthTask {
|
||||
|
||||
//private Gson gson = new Gson();
|
||||
|
||||
public MinecraftAccount run(String... args) throws Throwable {
|
||||
/*
|
||||
publishProgress();
|
||||
String msaAccessToken = acquireAccessToken(args[0]);
|
||||
|
||||
publishProgress();
|
||||
String xblToken = acquireXBLToken(msaAccessToken);
|
||||
|
||||
publishProgress();
|
||||
String[] xstsData = acquireXsts(xblToken);
|
||||
|
||||
publishProgress();
|
||||
String mcAccessToken = acquireMinecraftToken(xstsData[0], xstsData[1]);
|
||||
|
||||
publishProgress();
|
||||
|
||||
*/
|
||||
Msa msa = new Msa(this, Boolean.parseBoolean(args[0]), args[1]);
|
||||
|
||||
MinecraftAccount acc = new MinecraftAccount();
|
||||
if (msa.doesOwnGame) {
|
||||
acc.clientToken = "0"; /* FIXME */
|
||||
acc.accessToken = msa.mcToken;
|
||||
acc.username = msa.mcName;
|
||||
acc.profileId = msa.mcUuid;
|
||||
acc.msaRefreshToken = msa.msRefreshToken;
|
||||
} else if(msa.doesDemo) {
|
||||
acc.clientToken = "0"; /* FIXME */
|
||||
acc.accessToken = "-1"; // Differentiate from local accounts
|
||||
acc.username = "demo_user";
|
||||
acc.profileId = "25e00594-cf57-3f87-b3af-3f06591be252";
|
||||
acc.msaRefreshToken = "0";
|
||||
}
|
||||
acc.save();
|
||||
|
||||
return acc;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,339 +0,0 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package net.kdt.pojavlaunch.authenticator.microsoft;
|
||||
|
||||
import android.util.*;
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.util.*;
|
||||
import net.kdt.pojavlaunch.*;
|
||||
import org.json.*;
|
||||
|
||||
|
||||
public class Msa {
|
||||
/*
|
||||
private static final String loginUrl = "https://login.live.com/oauth20_authorize.srf" +
|
||||
"?client_id=00000000402b5328" +
|
||||
"&response_type=code" +
|
||||
"&scope=service%3A%3Auser.auth.xboxlive.com%3A%3AMBI_SSL" +
|
||||
"&redirect_uri=https%3A%2F%2Flogin.live.com%2Foauth20_desktop.srf";
|
||||
|
||||
private static final String redirectUrlSuffix = "https://login.live.com/oauth20_desktop.srf?code=";
|
||||
*/
|
||||
private static final String authTokenUrl = "https://login.live.com/oauth20_token.srf";
|
||||
private static final String xblAuthUrl = "https://user.auth.xboxlive.com/user/authenticate";
|
||||
private static final String xstsAuthUrl = "https://xsts.auth.xboxlive.com/xsts/authorize";
|
||||
private static final String mcLoginUrl = "https://api.minecraftservices.com/authentication/login_with_xbox";
|
||||
private static final String mcStoreUrl = "https://api.minecraftservices.com/entitlements/mcstore";
|
||||
private static final String mcProfileUrl = "https://api.minecraftservices.com/minecraft/profile";
|
||||
|
||||
private MicrosoftAuthTask task;
|
||||
|
||||
public boolean isRefresh;
|
||||
public String msRefreshToken;
|
||||
public String mcName;
|
||||
public String mcToken;
|
||||
public String mcUuid;
|
||||
public boolean doesOwnGame;
|
||||
public boolean doesDemo;
|
||||
|
||||
public Msa(MicrosoftAuthTask task, boolean isRefresh, String authCode) throws IOException, JSONException {
|
||||
this.task = task;
|
||||
acquireAccessToken(isRefresh, authCode);
|
||||
}
|
||||
|
||||
public void acquireAccessToken(boolean isRefresh, String authcode) throws IOException, JSONException {
|
||||
// task.publishProgressPublic();
|
||||
|
||||
URL url = new URL(authTokenUrl);
|
||||
// Log.i("MicroAuth", "isRefresh=" + isRefresh + ", authCode= "+authcode);
|
||||
Map<Object, Object> data = new HashMap<>();/*Map.of(
|
||||
"client_id", "00000000402b5328",
|
||||
"code", authcode,
|
||||
"grant_type", "authorization_code",
|
||||
"redirect_uri", "https://login.live.com/oauth20_desktop.srf",
|
||||
"scope", "service::user.auth.xboxlive.com::MBI_SSL"
|
||||
);*/
|
||||
data.put("client_id", "00000000402b5328");
|
||||
data.put(isRefresh ? "refresh_token" : "code", authcode);
|
||||
data.put("grant_type", isRefresh ? "refresh_token" : "authorization_code");
|
||||
data.put("redirect_url", "https://login.live.com/oauth20_desktop.srf");
|
||||
data.put("scope", "service::user.auth.xboxlive.com::MBI_SSL");
|
||||
|
||||
//да пошла yf[eq1 она ваша джава 11
|
||||
String req = ofFormData(data);
|
||||
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
|
||||
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
|
||||
conn.setRequestProperty("charset", "utf-8");
|
||||
conn.setRequestProperty("Content-Length", Integer.toString(req.getBytes("UTF-8").length));
|
||||
conn.setRequestMethod("POST");
|
||||
conn.setUseCaches(false);
|
||||
conn.setDoInput(true);
|
||||
conn.setDoOutput(true);
|
||||
conn.connect();
|
||||
try(OutputStream wr = conn.getOutputStream()) {
|
||||
wr.write(req.getBytes("UTF-8"));
|
||||
}
|
||||
if(conn.getResponseCode() >= 200 && conn.getResponseCode() < 300) {
|
||||
JSONObject jo = new JSONObject(Tools.read(conn.getInputStream()));
|
||||
msRefreshToken = jo.getString("refresh_token");
|
||||
// System.out.println("MicroAuth: Acess Token = "+jo.getString("access_token"));
|
||||
acquireXBLToken(jo.getString("access_token"));
|
||||
}else{
|
||||
throwResponseError(conn);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void acquireXBLToken(String accessToken) throws IOException, JSONException {
|
||||
// task.publishProgressPublic();
|
||||
|
||||
URL url = new URL(xblAuthUrl);
|
||||
|
||||
Map<Object, Object> data = new HashMap<>();
|
||||
Map<Object, Object> properties = new HashMap<>();
|
||||
properties.put("AuthMethod", "RPS");
|
||||
properties.put("SiteName", "user.auth.xboxlive.com");
|
||||
properties.put("RpsTicket", accessToken);
|
||||
data.put("Properties",properties);
|
||||
data.put("RelyingParty", "http://auth.xboxlive.com");
|
||||
data.put("TokenType", "JWT");
|
||||
/*Map.of(
|
||||
|
||||
"Properties", Map.of(
|
||||
"AuthMethod", "RPS",
|
||||
"SiteName", "user.auth.xboxlive.com",
|
||||
"RpsTicket", accessToken
|
||||
),
|
||||
"RelyingParty", "http://auth.xboxlive.com",
|
||||
"TokenType", "JWT"
|
||||
);*/
|
||||
String req = ofJSONData(data);
|
||||
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
|
||||
conn.setRequestProperty("Content-Type", "application/json");
|
||||
conn.setRequestProperty("Accept", "application/json");
|
||||
conn.setRequestProperty("charset", "utf-8");
|
||||
conn.setRequestProperty("Content-Length", Integer.toString(req.getBytes("UTF-8").length));
|
||||
conn.setRequestMethod("POST");
|
||||
conn.setUseCaches(false);
|
||||
conn.setDoInput(true);
|
||||
conn.setDoOutput(true);
|
||||
conn.connect();
|
||||
try(OutputStream wr = conn.getOutputStream()) {
|
||||
wr.write(req.getBytes("UTF-8"));
|
||||
}
|
||||
if(conn.getResponseCode() >= 200 && conn.getResponseCode() < 300) {
|
||||
JSONObject jo = new JSONObject(Tools.read(conn.getInputStream()));
|
||||
//Log.i("MicroAuth","Xbl Token = "+jo.getString("Token"));
|
||||
acquireXsts(jo.getString("Token"));
|
||||
}else{
|
||||
throwResponseError(conn);
|
||||
}
|
||||
}
|
||||
|
||||
private void acquireXsts(String xblToken) throws IOException, JSONException {
|
||||
// task.publishProgressPublic();
|
||||
|
||||
URL url = new URL(xstsAuthUrl);
|
||||
Map<Object, Object> data = new HashMap<>();
|
||||
Map<Object, Object> properties = new HashMap<>();
|
||||
properties.put("SandboxId", "RETAIL");
|
||||
properties.put("UserTokens",Collections.singleton(xblToken));
|
||||
data.put("Properties",properties);
|
||||
data.put("RelyingParty", "rp://api.minecraftservices.com/");
|
||||
data.put("TokenType", "JWT");
|
||||
/*Map<Object, Object> data = Map.of(
|
||||
"Properties", Map.of(
|
||||
"SandboxId", "RETAIL",
|
||||
"UserTokens", List.of(xblToken)
|
||||
),
|
||||
"RelyingParty", "rp://api.minecraftservices.com/",
|
||||
"TokenType", "JWT"
|
||||
);
|
||||
*/
|
||||
String req = ofJSONData(data);
|
||||
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
|
||||
conn.setRequestProperty("Content-Type", "application/json");
|
||||
conn.setRequestProperty("Accept", "application/json");
|
||||
conn.setRequestProperty("charset", "utf-8");
|
||||
conn.setRequestProperty("Content-Length", Integer.toString(req.getBytes("UTF-8").length));
|
||||
conn.setRequestMethod("POST");
|
||||
conn.setUseCaches(false);
|
||||
conn.setDoInput(true);
|
||||
conn.setDoOutput(true);
|
||||
conn.connect();
|
||||
try(OutputStream wr = conn.getOutputStream()) {
|
||||
wr.write(req.getBytes("UTF-8"));
|
||||
}
|
||||
|
||||
if(conn.getResponseCode() >= 200 && conn.getResponseCode() < 300) {
|
||||
JSONObject jo = new JSONObject(Tools.read(conn.getInputStream()));
|
||||
String uhs = jo.getJSONObject("DisplayClaims").getJSONArray("xui").getJSONObject(0).getString("uhs");
|
||||
// Log.i("MicroAuth","Xbl Xsts = "+jo.getString("Token")+"; Uhs = " + uhs);
|
||||
acquireMinecraftToken(uhs,jo.getString("Token"));
|
||||
}else{
|
||||
throwResponseError(conn);
|
||||
}
|
||||
}
|
||||
|
||||
private void acquireMinecraftToken(String xblUhs, String xblXsts) throws IOException, JSONException {
|
||||
// task.publishProgressPublic();
|
||||
|
||||
URL url = new URL(mcLoginUrl);
|
||||
|
||||
Map<Object, Object> data = new HashMap<>();
|
||||
data.put("identityToken", "XBL3.0 x=" + xblUhs + ";" + xblXsts);
|
||||
|
||||
String req = ofJSONData(data);
|
||||
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
|
||||
conn.setRequestProperty("Content-Type", "application/json");
|
||||
conn.setRequestProperty("Accept", "application/json");
|
||||
conn.setRequestProperty("charset", "utf-8");
|
||||
conn.setRequestProperty("Content-Length", Integer.toString(req.getBytes("UTF-8").length));
|
||||
conn.setRequestMethod("POST");
|
||||
conn.setUseCaches(false);
|
||||
conn.setDoInput(true);
|
||||
conn.setDoOutput(true);
|
||||
conn.connect();
|
||||
try(OutputStream wr = conn.getOutputStream()) {
|
||||
wr.write(req.getBytes("UTF-8"));
|
||||
}
|
||||
|
||||
if(conn.getResponseCode() >= 200 && conn.getResponseCode() < 300) {
|
||||
JSONObject jo = new JSONObject(Tools.read(conn.getInputStream()));
|
||||
// Log.i("MicroAuth","MC token: "+jo.getString("access_token"));
|
||||
mcToken = jo.getString("access_token");
|
||||
checkMcProfile(jo.getString("access_token"));
|
||||
checkMcStore(jo.getString("access_token"));
|
||||
|
||||
}else{
|
||||
throwResponseError(conn);
|
||||
}
|
||||
}
|
||||
private void checkMcStore(String mcAccessToken) throws IOException, JSONException {
|
||||
// task.publishProgressPublic();
|
||||
|
||||
URL url = new URL(mcStoreUrl);
|
||||
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
|
||||
conn.setRequestProperty("Authorization", "Bearer " + mcAccessToken);
|
||||
conn.setRequestMethod("GET");
|
||||
conn.setUseCaches(false);
|
||||
conn.connect();
|
||||
if(conn.getResponseCode() >= 200 && conn.getResponseCode() < 300) {
|
||||
JSONObject jo = new JSONObject(Tools.read(conn.getInputStream()));
|
||||
JSONArray ja = jo.getJSONArray("items");
|
||||
// Log.i("MicroAuth","Store Len = " + ja.length());
|
||||
for(int i = 0; i < ja.length(); i++) {
|
||||
String prod = ja.getJSONObject(i).getString("name");
|
||||
// Log.i("MicroAuth","Product " + i +": " +prod);
|
||||
}
|
||||
}else{
|
||||
throwResponseError(conn);
|
||||
}
|
||||
/*
|
||||
HttpRequest request = HttpRequest.newBuilder(uri)
|
||||
.header("Authorization", "Bearer " + mcAccessToken)
|
||||
.GET().build();
|
||||
|
||||
HttpClient.newBuilder().build().sendAsync(request, HttpResponse.BodyHandlers.ofString()).thenAccept(resp -> {
|
||||
if (resp.statusCode() >= 200 && resp.statusCode() < 300) {
|
||||
String body = resp.body();
|
||||
Log.i("MicroAuth","store: " + body);
|
||||
}
|
||||
});
|
||||
*/
|
||||
}
|
||||
|
||||
private void checkMcProfile(String mcAccessToken) throws IOException, JSONException {
|
||||
// task.publishProgressPublic();
|
||||
|
||||
URL url = new URL(mcProfileUrl);
|
||||
|
||||
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
|
||||
conn.setRequestProperty("Authorization", "Bearer " + mcAccessToken);
|
||||
conn.setUseCaches(false);
|
||||
conn.connect();
|
||||
|
||||
if(conn.getResponseCode() >= 200 && conn.getResponseCode() < 300) {
|
||||
String s= Tools.read(conn.getInputStream());
|
||||
// Log.i("MicroAuth","profile:" + s);
|
||||
JSONObject jsonObject = new JSONObject(s);
|
||||
String name = (String) jsonObject.get("name");
|
||||
String uuid = (String) jsonObject.get("id");
|
||||
String uuidDashes = uuid .replaceFirst(
|
||||
"(\\p{XDigit}{8})(\\p{XDigit}{4})(\\p{XDigit}{4})(\\p{XDigit}{4})(\\p{XDigit}+)", "$1-$2-$3-$4-$5"
|
||||
);
|
||||
doesOwnGame = true;
|
||||
// Log.i("MicroAuth","UserName = " + name);
|
||||
// Log.i("MicroAuth","Uuid Minecraft = " + uuidDashes);
|
||||
mcName=name;
|
||||
mcUuid=uuidDashes;
|
||||
} else if(conn.getResponseCode() == 404) {
|
||||
// Demo mode stuff
|
||||
doesOwnGame = false;
|
||||
doesDemo = true;
|
||||
} else {
|
||||
// Log.i("MicroAuth","It seems that this Microsoft Account does not own the game.");
|
||||
doesOwnGame = false;
|
||||
doesDemo = false;
|
||||
throwResponseError(conn);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static String ofJSONData(Map<Object, Object> data) {
|
||||
return new JSONObject(data).toString();
|
||||
}
|
||||
|
||||
public static String ofFormData(Map<Object, Object> data) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (Map.Entry<Object, Object> entry : data.entrySet()) {
|
||||
if (builder.length() > 0) {
|
||||
builder.append("&");
|
||||
}
|
||||
try {
|
||||
builder.append(URLEncoder.encode(entry.getKey().toString(), "UTF-8"));
|
||||
builder.append("=");
|
||||
builder.append(URLEncoder.encode(entry.getValue().toString(), "UTF-8"));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
//Should not happen
|
||||
}
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
private static void throwResponseError(HttpURLConnection conn) throws IOException {
|
||||
String otherErrStr = "";
|
||||
String errStr = Tools.read(conn.getErrorStream());
|
||||
// Log.i("MicroAuth","Error code: " + conn.getResponseCode() + ": " + conn.getResponseMessage() + "\n" + errStr);
|
||||
|
||||
// it seems already handled by the demo mode..
|
||||
/*
|
||||
if (errStr.contains("NOT_FOUND") &&
|
||||
errStr.contains("The server has not found anything matching the request URI"))
|
||||
{
|
||||
// TODO localize this
|
||||
otherErrStr = "It seems that this Microsoft Account does not own the game. Make sure that you have bought/migrated to your Microsoft account.";
|
||||
} else {
|
||||
*/
|
||||
try {
|
||||
JSONObject jo = new JSONObject(errStr);
|
||||
switch ((int)(jo.getLong("XErr") - 2148916230l)) {
|
||||
case 8: // AddChildToFamily
|
||||
otherErrStr = "This account is under 18 and needs to be added to a Family by an adult before proceed.";
|
||||
break;
|
||||
case 3: // CreateAccount
|
||||
otherErrStr = "The account isn't created yet.";
|
||||
break;
|
||||
}
|
||||
} catch (Throwable th) { // not a JSON?
|
||||
}
|
||||
//}
|
||||
|
||||
throw new RuntimeException(otherErrStr + "\n\nMSA Error: " + conn.getResponseCode() + ": " + conn.getResponseMessage() + ", error stream:\n" + errStr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
package net.kdt.pojavlaunch.uikit;
|
||||
|
||||
import java.net.UnknownHostException;
|
||||
import net.kdt.pojavlaunch.Tools;
|
||||
import net.kdt.pojavlaunch.authenticator.microsoft.MicrosoftAuthTask;
|
||||
import net.kdt.pojavlaunch.value.MinecraftAccount;
|
||||
|
||||
public class AccountJNI {
|
||||
public static final int TYPE_SELECTACC = 0;
|
||||
public static final int TYPE_MICROSOFT = 1;
|
||||
public static final int TYPE_OFFLINE = 2;
|
||||
|
||||
public static volatile MinecraftAccount CURRENT_ACCOUNT;
|
||||
|
||||
// Call back about account credentials for login
|
||||
public static String loginAccount(int type,
|
||||
String data // One of:
|
||||
// Local username
|
||||
// Microsoft token
|
||||
) {
|
||||
try {
|
||||
switch (type) {
|
||||
case TYPE_SELECTACC:
|
||||
CURRENT_ACCOUNT = MinecraftAccount.load(data);
|
||||
try {
|
||||
if (CURRENT_ACCOUNT.accessToken.length() > 5) {
|
||||
CURRENT_ACCOUNT = new MicrosoftAuthTask().run("true", CURRENT_ACCOUNT.msaRefreshToken);
|
||||
}
|
||||
CURRENT_ACCOUNT = MinecraftAccount.load(data);
|
||||
} catch (UnknownHostException e) {
|
||||
e.printStackTrace();
|
||||
// ignore, since it's likely that the user is offline
|
||||
}
|
||||
return (CURRENT_ACCOUNT.accessToken.equals("0") ? "-" : "$") + CURRENT_ACCOUNT.username;
|
||||
|
||||
case TYPE_MICROSOFT:
|
||||
CURRENT_ACCOUNT = new MicrosoftAuthTask().run("false", data);
|
||||
return "$" + CURRENT_ACCOUNT.username;
|
||||
|
||||
case TYPE_OFFLINE:
|
||||
CURRENT_ACCOUNT = new MinecraftAccount();
|
||||
CURRENT_ACCOUNT.username = data;
|
||||
CURRENT_ACCOUNT.save();
|
||||
return "-" + CURRENT_ACCOUNT.username;
|
||||
}
|
||||
} catch (Throwable th) {
|
||||
Tools.showError(th);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
static {
|
||||
// System.loadLibrary("pojavexec");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user