mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-12 22:26:56 -04:00
Fix[msa]: switch auth type based on game release date
This commit is contained in:
parent
7bfc86cade
commit
ce145b50e9
@ -55,6 +55,7 @@ import net.kdt.pojavlaunch.multirt.MultiRTUtils;
|
||||
import net.kdt.pojavlaunch.multirt.Runtime;
|
||||
import net.kdt.pojavlaunch.plugins.FFmpegPlugin;
|
||||
import net.kdt.pojavlaunch.prefs.LauncherPreferences;
|
||||
import net.kdt.pojavlaunch.utils.DateUtils;
|
||||
import net.kdt.pojavlaunch.utils.DownloadUtils;
|
||||
import net.kdt.pojavlaunch.utils.JREUtils;
|
||||
import net.kdt.pojavlaunch.utils.JSONUtils;
|
||||
@ -80,9 +81,14 @@ import java.io.StringWriter;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.lang.reflect.Field;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
@SuppressWarnings("IOStreamConstructor")
|
||||
@ -339,6 +345,18 @@ public final class Tools {
|
||||
}
|
||||
|
||||
String userType = "mojang";
|
||||
try {
|
||||
Date creationDate = DateUtils.parseReleaseDate(versionInfo.releaseTime);
|
||||
// Minecraft 22w43a which adds chat reporting (and signing) was released on
|
||||
// 26th October 2022. So, if the date is not before that (meaning it is equal or higher)
|
||||
// change the userType to MSA to fix the missing signature
|
||||
if(creationDate != null && !DateUtils.dateBefore(creationDate, 2022, 10, 26)) {
|
||||
userType = "msa";
|
||||
}
|
||||
}catch (ParseException e) {
|
||||
Log.e("CheckForProfileKey", "Failed to determine profile creation date, using \"mojang\"", e);
|
||||
}
|
||||
|
||||
|
||||
Map<String, String> varArgMap = new ArrayMap<>();
|
||||
varArgMap.put("auth_session", profile.accessToken); // For legacy versions of MC
|
||||
@ -447,6 +465,10 @@ public final class Tools {
|
||||
return libStr.toString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public static DisplayMetrics getDisplayMetrics(Activity activity) {
|
||||
DisplayMetrics displayMetrics = new DisplayMetrics();
|
||||
|
||||
|
@ -0,0 +1,44 @@
|
||||
package net.kdt.pojavlaunch.utils;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.Locale;
|
||||
|
||||
// Utils for date-based activation for certain launcher workarounds.
|
||||
public class DateUtils {
|
||||
/**
|
||||
* Parse the release date of a game version from the JMinecraftVersionList.Version time or releaseTime fields
|
||||
* @param releaseTime the time or releaseTime string from JMinecraftVersionList.Version
|
||||
* @return the date object
|
||||
* @throws ParseException if date parsing fails
|
||||
*/
|
||||
public static Date parseReleaseDate(String releaseTime) throws ParseException {
|
||||
if(releaseTime == null) return null;
|
||||
int tIndexOf = releaseTime.indexOf('T');
|
||||
if(tIndexOf != -1) releaseTime = releaseTime.substring(0, tIndexOf);
|
||||
return new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH).parse(releaseTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the Date object is before the date denoted by
|
||||
* year, month, dayOfMonth parameters
|
||||
* @param date the Date object that we compare against
|
||||
* @param year the year
|
||||
* @param month the month (zero-based)
|
||||
* @param dayOfMonth the day of the month
|
||||
* @return true if the Date is before year, month, dayOfMonth, false otherwise
|
||||
*/
|
||||
public static boolean dateBefore(@NonNull Date date, int year, int month, int dayOfMonth) {
|
||||
Date comparsionDate = new Date(new GregorianCalendar(year, month, dayOfMonth).getTimeInMillis());
|
||||
Log.i("DateUtils", "date:"+date);
|
||||
Log.i("DateUtils", "comparsionDate:"+comparsionDate);
|
||||
Log.i("DateUtils","isBefore:"+date.before(comparsionDate));
|
||||
return date.before(comparsionDate);
|
||||
}
|
||||
}
|
@ -8,10 +8,8 @@ import net.kdt.pojavlaunch.extra.ExtraConstants;
|
||||
import net.kdt.pojavlaunch.extra.ExtraCore;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.Locale;
|
||||
|
||||
/** Class here to help with various stuff to help run lower versions smoothly */
|
||||
public class OldVersionsUtils {
|
||||
@ -20,23 +18,20 @@ public class OldVersionsUtils {
|
||||
*/
|
||||
public static void selectOpenGlVersion(JMinecraftVersionList.Version version){
|
||||
// 1309989600 is 2011-07-07 2011-07-07T22:00:00+00:00
|
||||
String creationDate = version.time;
|
||||
if(!Tools.isValidString(creationDate)){
|
||||
String creationTime = version.time;
|
||||
if(!Tools.isValidString(creationTime)){
|
||||
ExtraCore.setValue(ExtraConstants.OPEN_GL_VERSION, "2");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
int tIndexOf = creationDate.indexOf('T');
|
||||
if(tIndexOf != -1) creationDate = creationDate.substring(0, tIndexOf);
|
||||
Date creationDateObj = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH).parse(creationDate);
|
||||
if(creationDateObj == null) {
|
||||
Date creationDate = DateUtils.parseReleaseDate(creationTime);
|
||||
if(creationDate == null) {
|
||||
Log.e("GL_SELECT", "Failed to parse version date");
|
||||
ExtraCore.setValue(ExtraConstants.OPEN_GL_VERSION, "2");
|
||||
return;
|
||||
}
|
||||
|
||||
String openGlVersion = creationDateObj.before(new Date(new GregorianCalendar(2011, 6, 8).getTimeInMillis())) ? "1" : "2";
|
||||
String openGlVersion = DateUtils.dateBefore(creationDate, 2011, 6, 8) ? "1" : "2";
|
||||
Log.i("GL_SELECT", openGlVersion);
|
||||
ExtraCore.setValue(ExtraConstants.OPEN_GL_VERSION, openGlVersion);
|
||||
}catch (ParseException exception){
|
||||
|
Loading…
x
Reference in New Issue
Block a user