Skip to content

Commit

Permalink
Fix[msa]: switch auth type based on game release date
Browse files Browse the repository at this point in the history
  • Loading branch information
artdeell committed Dec 10, 2023
1 parent 7bfc86c commit e622d4e
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 10 deletions.
22 changes: 22 additions & 0 deletions app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/Tools.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
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;
Expand All @@ -80,9 +81,14 @@
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")
Expand Down Expand Up @@ -339,6 +345,18 @@ public static String[] getMinecraftClientArgs(MinecraftAccount profile, JMinecra
}

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
Expand Down Expand Up @@ -447,6 +465,10 @@ public static String generateLaunchClassPath(JMinecraftVersionList.Version info,
return libStr.toString();
}





public static DisplayMetrics getDisplayMetrics(Activity activity) {
DisplayMetrics displayMetrics = new DisplayMetrics();

Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@
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 {
Expand All @@ -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){
Expand Down

0 comments on commit e622d4e

Please sign in to comment.