Fix[datedetect]: Read original release date instead of the modded release date

This commit is contained in:
artdeell 2023-12-10 10:40:36 +03:00 committed by Maksim Belov
parent ce145b50e9
commit b021a1fd5c
3 changed files with 22 additions and 6 deletions

View File

@ -82,13 +82,10 @@ 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")
@ -346,11 +343,11 @@ public final class Tools {
String userType = "mojang";
try {
Date creationDate = DateUtils.parseReleaseDate(versionInfo.releaseTime);
Date creationDate = DateUtils.getOriginalReleaseDate(versionInfo);
// 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)) {
if(creationDate != null && !DateUtils.dateBefore(creationDate, 2022, 9, 26)) {
userType = "msa";
}
}catch (ParseException e) {

View File

@ -4,6 +4,9 @@ import android.util.Log;
import androidx.annotation.NonNull;
import net.kdt.pojavlaunch.JMinecraftVersionList;
import net.kdt.pojavlaunch.Tools;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
@ -41,4 +44,21 @@ public class DateUtils {
Log.i("DateUtils","isBefore:"+date.before(comparsionDate));
return date.before(comparsionDate);
}
/**
* Extracts the original release date of a game version, ignoring any mods (if present)
* @param gameVersion the JMinecraftVersionList.Version object
* @return the game's original release date
*/
public static Date getOriginalReleaseDate(JMinecraftVersionList.Version gameVersion) throws ParseException {
if(Tools.isValidString(gameVersion.inheritsFrom)) {
gameVersion = Tools.getVersionInfo(gameVersion.inheritsFrom, true);
}else {
// The launcher's inheritor mutilates the version object, causing it to have the original
// version's ID but modded version's dates. Work around it by re-reading the version without
// inheriting.
gameVersion = Tools.getVersionInfo(gameVersion.id, true);
}
return parseReleaseDate(gameVersion.releaseTime);
}
}

View File

@ -9,7 +9,6 @@ import net.kdt.pojavlaunch.extra.ExtraCore;
import java.text.ParseException;
import java.util.Date;
import java.util.GregorianCalendar;
/** Class here to help with various stuff to help run lower versions smoothly */
public class OldVersionsUtils {