Skip to content

Commit

Permalink
BTW and fix login
Browse files Browse the repository at this point in the history
  • Loading branch information
The Judge committed Aug 23, 2024
1 parent 3992ac4 commit 10e5f81
Show file tree
Hide file tree
Showing 32 changed files with 69 additions and 50,177 deletions.
2 changes: 0 additions & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,3 @@
# These are Windows script files and should use crlf
*.bat text eol=crlf
*.so filter=lfs diff=lfs merge=lfs -text
*.so !text !filter !merge !diff
* !text !filter !merge !diff
4 changes: 2 additions & 2 deletions src/main/java/pojlib/account/LoginHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import pojlib.API;
import pojlib.util.Constants;
import pojlib.util.Logger;
import pojlib.util.MSAException;

public class LoginHelper {
public static Thread loginThread;
Expand Down Expand Up @@ -103,8 +104,7 @@ public static void beginLogin(Activity activity) {
API.profileImage = MinecraftAccount.getSkinFaceUrl(API.currentAcc);
API.profileName = API.currentAcc.username;
} catch (ExecutionException | InterruptedException e) {
API.msaMessage = "Something went wrong! Couldn't reach the Microsoft Auth servers.\n"
+ e;
throw new MSAException("MicrosoftLogin | Something went wrong! Couldn't reach the Microsoft Auth servers.", e);
}
});

Expand Down
4 changes: 1 addition & 3 deletions src/main/java/pojlib/account/MinecraftAccount.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,17 @@
import pojlib.util.Logger;

public class MinecraftAccount {

public String accessToken;
public String uuid;
public String username;
public long expiresIn;

public final String userType = "msa";


public static MinecraftAccount login(String gameDir, String[] response) throws IOException, JSONException {
String mcToken = Msa.acquireXBLToken(response[0]);
Msa instance = new Msa(false, mcToken);
MinecraftAccount account = instance.performLogin();
MinecraftAccount account = instance.performLogin(mcToken);
account.expiresIn = Long.parseLong(response[1]);

GsonUtils.objectToJsonFile(gameDir + "/account.json", account);
Expand Down
48 changes: 4 additions & 44 deletions src/main/java/pojlib/account/Msa.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,9 @@ public Msa(boolean isRefresh, String authCode){
}

/** Performs a full login, calling back listeners appropriately */
public MinecraftAccount performLogin() {
public MinecraftAccount performLogin(String xblToken) {
try {
String accessToken = acquireAccessToken(mIsRefresh, mAuthCode);
String xboxLiveToken = acquireXBLToken(accessToken);
String[] xsts = acquireXsts(xboxLiveToken);
String[] xsts = acquireXsts(xblToken);
if(xsts == null) {
return null;
}
Expand All @@ -74,8 +72,6 @@ public MinecraftAccount performLogin() {
MinecraftAccount acc = MinecraftAccount.load(mcName, null, null);
if (acc == null) acc = new MinecraftAccount();
if (doesOwnGame) {
/*acc.xuid = xsts[0];*/
/*acc.clientToken = "0"; *//* FIXME */
acc.accessToken = mcToken;
acc.username = mcName;
acc.uuid = mcUuid;
Expand All @@ -87,44 +83,8 @@ public MinecraftAccount performLogin() {

return acc;
} catch (Exception e) {
Logger.getInstance().appendToLog("MicrosoftLogin | Exception thrown during authentication" + e);
throw new MSAException("MicrosoftLogin | Exception thrown during authentication", e);
}
}

public String acquireAccessToken(boolean isRefresh, String authcode) throws IOException, JSONException {
URL url = new URL(Constants.OAUTH_TOKEN_URL);
// Logger.getInstance().appendToLog("MicrosoftLogin | isRefresh=" + isRefresh + ", authCode= "+authcode);

String formData = convertToFormData(
"client_id", "00000000402b5328",
isRefresh ? "refresh_token" : "code", authcode,
"grant_type", isRefresh ? "refresh_token" : "authorization_code",
"redirect_url", "https://login.live.com/oauth20_desktop.srf",
"scope", "service::user.auth.xboxlive.com::MBI_SSL"
);

// Logger.getInstance().appendToLog("MicroAuth | " + formData);

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(formData.getBytes(StandardCharsets.UTF_8).length));
conn.setRequestMethod("POST");
conn.setUseCaches(false);
conn.setDoInput(true);
conn.setDoOutput(true);
conn.connect();
try(OutputStream wr = conn.getOutputStream()) {
wr.write(formData.getBytes(StandardCharsets.UTF_8));
}
if(conn.getResponseCode() >= 200 && conn.getResponseCode() < 300) {
JSONObject jo = new JSONObject(FileUtil.read(conn.getInputStream()));
msRefreshToken = jo.getString("refresh_token");
conn.disconnect();
return jo.getString("access_token");
}else{
throw getResponseThrowable(conn);
Logger.getInstance().appendToLog("MicrosoftLogin | Exception thrown during authentication " + e);
throw new MSAException("MicrosoftLogin | Exception thrown during authentication ", e);
}
}

Expand Down
26 changes: 1 addition & 25 deletions src/main/jni/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,6 @@ HERE_PATH := $(LOCAL_PATH)

LOCAL_PATH := $(HERE_PATH)

include $(CLEAR_VARS)
LOCAL_MODULE := regal
LOCAL_SRC_FILES := GL/libRegal.so
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := spirv-cross
LOCAL_SRC_FILES := tinywrapper/SPIRVCross/libspirv-cross-c-shared.so
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := shaderc
LOCAL_SRC_FILES := tinywrapper/shaderc/libshaderc_shared.so
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := tinywrapper
LOCAL_SHARED_LIBRARIES := regal spirv-cross shaderc
LOCAL_LDLIBS := -lGLESv3
LOCAL_SRC_FILES := tinywrapper/main.c tinywrapper/string_utils.c
LOCAL_C_INCLUDES := $(LOCAL_PATH)/tinywrapper
include $(BUILD_SHARED_LIBRARY)


include $(CLEAR_VARS)
LOCAL_MODULE := openxr_loader
LOCAL_SRC_FILES := libopenxr_loader.so
Expand Down Expand Up @@ -69,7 +45,7 @@ LOCAL_LDLIBS := -ldl -llog -landroid -lGLESv3 -lEGL
# -lGLESv2
LOCAL_MODULE := pojavexec
# LOCAL_CFLAGS += -DDEBUG
LOCAL_SHARED_LIBRARIES := openvr_api regal
LOCAL_SHARED_LIBRARIES := openvr_api
# -DGLES_TEST
LOCAL_SRC_FILES := \
egl_bridge.c \
Expand Down
Loading

0 comments on commit 10e5f81

Please sign in to comment.