Skip to content

Commit

Permalink
Fix[datedetect]: Read original release date instead of the modded rel…
Browse files Browse the repository at this point in the history
…ease date
  • Loading branch information
artdeell committed Dec 10, 2023
1 parent e622d4e commit 1caf8ed
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,10 @@
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 @@ -346,11 +343,11 @@ public static String[] getMinecraftClientArgs(MinecraftAccount profile, JMinecra

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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

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;
Expand Down Expand Up @@ -41,4 +44,21 @@ public static boolean dateBefore(@NonNull Date date, int year, int month, int da
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

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 {
Expand Down

0 comments on commit 1caf8ed

Please sign in to comment.