From 507b8ee73618edd58ddb534c67a29971568c6ecc Mon Sep 17 00:00:00 2001 From: Darien Johnson <84008186+CADIndie@users.noreply.github.com> Date: Wed, 30 Oct 2024 19:50:12 -0500 Subject: [PATCH] Start Forge Work Co-Authored-By: Mathias Boulay Co-Authored-By: Maksim Belov <45949002+artdeell@users.noreply.github.com> --- src/main/assets/lwjgl/version | 2 +- src/main/java/pojlib/InstanceHandler.java | 9 ++- src/main/java/pojlib/UnityPlayerActivity.java | 18 ++--- src/main/java/pojlib/account/Msa.java | 19 ++--- src/main/java/pojlib/install/ForgeMeta.java | 37 +++++++++ src/main/java/pojlib/install/Installer.java | 23 +++--- src/main/java/pojlib/util/Constants.java | 4 + src/main/java/pojlib/util/DownloadUtils.java | 23 ++++++ .../util/{FileUtil.java => FileUtils.java} | 11 +-- .../pojlib/util/ForgeDownloadListener.java | 9 +++ src/main/java/pojlib/util/JREUtils.java | 1 + src/main/java/pojlib/util/Logger.java | 6 ++ .../pojlib/util/forge/ForgeDownloadTask.java | 77 +++++++++++++++++++ .../java/pojlib/util/forge/ForgeUtils.java | 27 +++++++ .../pojlib/util/json/MinecraftInstances.java | 3 - 15 files changed, 215 insertions(+), 54 deletions(-) create mode 100644 src/main/java/pojlib/install/ForgeMeta.java rename src/main/java/pojlib/util/{FileUtil.java => FileUtils.java} (95%) create mode 100644 src/main/java/pojlib/util/ForgeDownloadListener.java create mode 100644 src/main/java/pojlib/util/forge/ForgeDownloadTask.java create mode 100644 src/main/java/pojlib/util/forge/ForgeUtils.java diff --git a/src/main/assets/lwjgl/version b/src/main/assets/lwjgl/version index 83082427..fb84e653 100644 --- a/src/main/assets/lwjgl/version +++ b/src/main/assets/lwjgl/version @@ -1 +1 @@ -1728465869857 \ No newline at end of file +1730335323711 \ No newline at end of file diff --git a/src/main/java/pojlib/InstanceHandler.java b/src/main/java/pojlib/InstanceHandler.java index e8d07429..525c1ca1 100644 --- a/src/main/java/pojlib/InstanceHandler.java +++ b/src/main/java/pojlib/InstanceHandler.java @@ -17,14 +17,15 @@ import java.util.Locale; import pojlib.account.MinecraftAccount; -import pojlib.account.Msa; import pojlib.install.FabricMeta; +import pojlib.install.ForgeMeta; import pojlib.install.Installer; import pojlib.install.MinecraftMeta; import pojlib.install.QuiltMeta; import pojlib.install.VersionInfo; import pojlib.util.Constants; -import pojlib.util.FileUtil; +import pojlib.util.FileUtils; +import pojlib.util.forge.ForgeUtils; import pojlib.util.json.MinecraftInstances; import pojlib.util.json.ProjectInfo; import pojlib.util.GsonUtils; @@ -42,7 +43,7 @@ public static MinecraftInstances.Instance create(Activity activity, MinecraftIns mrpackJson.getParentFile().mkdirs(); File setupFile = new File(Constants.USER_HOME + "/instances/" + instanceName.toLowerCase(Locale.ROOT).replaceAll(" ", "_") + "/setup"); - FileUtil.unzipArchive(mrpackFilePath, setupFile.getPath()); + FileUtils.unzipArchive(mrpackFilePath, setupFile.getPath()); ModrinthIndexJson index = GsonUtils.jsonFileToObject(mrpackJson.getAbsolutePath(), ModrinthIndexJson.class); if(index == null) { @@ -160,6 +161,8 @@ public static MinecraftInstances.Instance create(Activity activity, MinecraftIns modLoaderVersionInfo = QuiltMeta.getVersionInfo(quiltVersion, minecraftVersion); break; } + case Forge: + ForgeMeta.getVersions(); } VersionInfo minecraftVersionInfo = MinecraftMeta.getVersionInfo(minecraftVersion); diff --git a/src/main/java/pojlib/UnityPlayerActivity.java b/src/main/java/pojlib/UnityPlayerActivity.java index 019b07a8..8a19885e 100644 --- a/src/main/java/pojlib/UnityPlayerActivity.java +++ b/src/main/java/pojlib/UnityPlayerActivity.java @@ -7,12 +7,9 @@ import android.annotation.SuppressLint; import android.app.Activity; -import android.app.Activity; import android.app.ActivityGroup; -import android.app.ActivityManager; import android.content.ClipData; import android.content.ClipboardManager; -import android.content.Context; import android.content.Intent; import android.content.res.Configuration; import android.os.Build; @@ -20,8 +17,6 @@ import android.os.Process; import android.util.DisplayMetrics; import android.view.InputDevice; -import android.util.DisplayMetrics; -import android.view.InputDevice; import android.view.KeyEvent; import android.view.MotionEvent; import android.view.Window; @@ -47,8 +42,7 @@ import pojlib.input.gamepad.DefaultDataProvider; import pojlib.input.gamepad.Gamepad; import pojlib.util.Constants; -import pojlib.util.FileUtil; -import pojlib.util.Logger; +import pojlib.util.FileUtils; public class UnityPlayerActivity extends ActivityGroup implements IUnityPlayerLifecycleEvents, GrabListener { @@ -96,7 +90,7 @@ protected String updateUnityCommandLineArguments(String cmdLine) File jre = new File(this.getFilesDir() + "/runtimes/JRE-22"); if (!jre.exists()) { - FileUtil.unzipArchiveFromAsset(this, "JRE-22.zip", this.getFilesDir() + "/runtimes/JRE-22"); + FileUtils.unzipArchiveFromAsset(this, "JRE-22.zip", this.getFilesDir() + "/runtimes/JRE-22"); try { Files.copy(Paths.get(this.getApplicationInfo().nativeLibraryDir + "/libawt_xawt.so"), Paths.get(this.getFilesDir() + "/runtimes/JRE-22/lib/libawt_xawt.so")); } catch (IOException e) { @@ -128,14 +122,14 @@ protected String updateUnityCommandLineArguments(String cmdLine) public static String installLWJGL(Activity activity) throws IOException { File lwjgl = new File(Constants.USER_HOME + "/lwjgl3/lwjgl-glfw-classes.jar"); - byte[] lwjglAsset = FileUtil.loadFromAssetToByte(activity, "lwjgl/lwjgl-glfw-classes.jar"); + byte[] lwjglAsset = FileUtils.loadFromAssetToByte(activity, "lwjgl/lwjgl-glfw-classes.jar"); if (!lwjgl.exists()) { Objects.requireNonNull(lwjgl.getParentFile()).mkdirs(); - FileUtil.write(lwjgl.getAbsolutePath(), lwjglAsset); - } else if (!FileUtil.matchingAssetFile(lwjgl, lwjglAsset)) { + FileUtils.write(lwjgl.getAbsolutePath(), lwjglAsset); + } else if (!FileUtils.matchingAssetFile(lwjgl, lwjglAsset)) { Objects.requireNonNull(lwjgl.getParentFile()).mkdirs(); - FileUtil.write(lwjgl.getAbsolutePath(), lwjglAsset); + FileUtils.write(lwjgl.getAbsolutePath(), lwjglAsset); } return lwjgl.getAbsolutePath(); diff --git a/src/main/java/pojlib/account/Msa.java b/src/main/java/pojlib/account/Msa.java index 3eb33e0b..7ca02e9b 100644 --- a/src/main/java/pojlib/account/Msa.java +++ b/src/main/java/pojlib/account/Msa.java @@ -1,19 +1,14 @@ package pojlib.account; import android.app.Activity; -import android.os.FileUtils; import android.util.ArrayMap; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; - import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; -import pojlib.API; import pojlib.util.Constants; -import pojlib.util.FileUtil; +import pojlib.util.FileUtils; import pojlib.util.Logger; import pojlib.util.MSAException; @@ -28,8 +23,6 @@ import java.util.Collections; import java.util.Map; -import javax.xml.transform.ErrorListener; - public class Msa { private static final Map XSTS_ERRORS; @@ -110,7 +103,7 @@ static String acquireXBLToken(String accessToken) throws IOException, MSAExcepti wr.write(req.getBytes(StandardCharsets.UTF_8)); } if(conn.getResponseCode() >= 200 && conn.getResponseCode() < 300) { - JSONObject jo = new JSONObject(FileUtil.read(conn.getInputStream())); + JSONObject jo = new JSONObject(FileUtils.read(conn.getInputStream())); conn.disconnect(); return jo.getString("Token"); }else{ @@ -142,13 +135,13 @@ private String[] acquireXsts(String xblToken) throws IOException, JSONException, } if(conn.getResponseCode() >= 200 && conn.getResponseCode() < 300) { - JSONObject jo = new JSONObject(FileUtil.read(conn.getInputStream())); + JSONObject jo = new JSONObject(FileUtils.read(conn.getInputStream())); String uhs = jo.getJSONObject("DisplayClaims").getJSONArray("xui").getJSONObject(0).getString("uhs"); String token = jo.getString("Token"); conn.disconnect(); return new String[]{uhs, token}; } else if(conn.getResponseCode() == 401) { - String responseContents = FileUtil.read(conn.getErrorStream()); + String responseContents = FileUtils.read(conn.getErrorStream()); JSONObject jo = new JSONObject(responseContents); long xerr = jo.optLong("XErr", -1); String locale_id = XSTS_ERRORS.get(xerr); @@ -179,7 +172,7 @@ private void acquireMinecraftToken(String xblUhs, String xblXsts) throws IOExcep } if(conn.getResponseCode() >= 200 && conn.getResponseCode() < 300) { - JSONObject jo = new JSONObject(FileUtil.read(conn.getInputStream())); + JSONObject jo = new JSONObject(FileUtils.read(conn.getInputStream())); conn.disconnect(); mcToken = jo.getString("access_token"); mcExpiresOn = System.currentTimeMillis() + (jo.getInt("expires_in") * 1000L); @@ -213,7 +206,7 @@ public static boolean checkMcProfile(String mcAccessToken) throws IOException, M conn.connect(); if(conn.getResponseCode() >= 200 && conn.getResponseCode() < 300) { - String s = FileUtil.read(conn.getInputStream()); + String s = FileUtils.read(conn.getInputStream()); conn.disconnect(); Logger.getInstance().appendToLog("MicrosoftLogin | profile:" + s); JSONObject jsonObject = new JSONObject(s); diff --git a/src/main/java/pojlib/install/ForgeMeta.java b/src/main/java/pojlib/install/ForgeMeta.java new file mode 100644 index 00000000..ae4deb5d --- /dev/null +++ b/src/main/java/pojlib/install/ForgeMeta.java @@ -0,0 +1,37 @@ +package pojlib.install; + +import com.google.gson.annotations.SerializedName; + +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; +import org.xml.sax.helpers.DefaultHandler; + +import java.util.ArrayList; +import java.util.List; + +import pojlib.APIHandler; +import pojlib.util.Constants; + +public class ForgeMeta extends DefaultHandler { + private static final APIHandler handler = new APIHandler(Constants.FORGE_META_URL); + + + public static class ForgeVersion { + @SerializedName("version") + public String version; + } + + public static ForgeVersion[] getVersions() { + return handler.get("forge-versions.json", ForgeMeta.ForgeVersion[].class); + } + + public static ForgeMeta.ForgeVersion getLatestVersion() { + ForgeMeta.ForgeVersion[] versions = getVersions(); + if (versions != null) return versions[0]; + return null; + } + + public static VersionInfo getVersionInfo(QuiltMeta.QuiltVersion quiltVersion, String minecraftVersion) { + return handler.get(String.format("versions/loader/%s/%s/profile/json", minecraftVersion, quiltVersion.version), VersionInfo.class); + } +} diff --git a/src/main/java/pojlib/install/Installer.java b/src/main/java/pojlib/install/Installer.java index 3efbc7c5..d269568b 100644 --- a/src/main/java/pojlib/install/Installer.java +++ b/src/main/java/pojlib/install/Installer.java @@ -6,8 +6,6 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; -import org.apache.commons.io.FileUtils; - import pojlib.APIHandler; import pojlib.util.json.MinecraftInstances; import pojlib.util.*; @@ -15,7 +13,6 @@ import java.io.File; import java.io.IOException; import java.util.Map; -import java.util.Objects; import java.util.StringJoiner; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.ThreadPoolExecutor; @@ -110,16 +107,16 @@ public static String installAssets(VersionInfo minecraftVersionInfo, String game DownloadUtils.downloadFile(minecraftVersionInfo.assetIndex.url, new File(gameDir + "/assets/indexes/" + minecraftVersionInfo.assets + ".json")); - FileUtils.writeByteArrayToFile(new File(instance.gameDir + "/config/sodium-options.json"), FileUtil.loadFromAssetToByte(activity, "sodium-options.json")); - FileUtils.writeByteArrayToFile(new File(instance.gameDir + "/config/vivecraft-config.properties"), FileUtil.loadFromAssetToByte(activity, "vivecraft-config.properties")); - FileUtils.writeByteArrayToFile(new File(instance.gameDir + "/config/smoothboot.json"), FileUtil.loadFromAssetToByte(activity, "smoothboot.json")); - FileUtils.writeByteArrayToFile(new File(instance.gameDir + "/config/immediatelyfast.json"), FileUtil.loadFromAssetToByte(activity, "immediatelyfast.json")); - FileUtils.writeByteArrayToFile(new File(instance.gameDir + "/config/moreculling.toml"), FileUtil.loadFromAssetToByte(activity,"moreculling.toml")); - FileUtils.writeByteArrayToFile(new File(instance.gameDir + "/config/modernfix-mixins.properties"), FileUtil.loadFromAssetToByte(activity,"modernfix-mixins.properties")); - FileUtils.writeByteArrayToFile(new File(instance.gameDir + "/options.txt"), FileUtil.loadFromAssetToByte(activity, "options.txt")); - FileUtils.writeByteArrayToFile(new File(instance.gameDir + "/optionsviveprofiles.txt"), FileUtil.loadFromAssetToByte(activity, "optionsviveprofiles.txt")); - FileUtils.writeByteArrayToFile(new File(instance.gameDir + "/servers.dat"), FileUtil.loadFromAssetToByte(activity, "servers.dat")); - FileUtils.writeByteArrayToFile(new File(Constants.USER_HOME + "/hacks/ResConfHack.jar"), FileUtil.loadFromAssetToByte(activity, "hacks/ResConfHack.jar")); + org.apache.commons.io.FileUtils.writeByteArrayToFile(new File(instance.gameDir + "/config/sodium-options.json"), FileUtils.loadFromAssetToByte(activity, "sodium-options.json")); + org.apache.commons.io.FileUtils.writeByteArrayToFile(new File(instance.gameDir + "/config/vivecraft-config.properties"), FileUtils.loadFromAssetToByte(activity, "vivecraft-config.properties")); + org.apache.commons.io.FileUtils.writeByteArrayToFile(new File(instance.gameDir + "/config/smoothboot.json"), FileUtils.loadFromAssetToByte(activity, "smoothboot.json")); + org.apache.commons.io.FileUtils.writeByteArrayToFile(new File(instance.gameDir + "/config/immediatelyfast.json"), FileUtils.loadFromAssetToByte(activity, "immediatelyfast.json")); + org.apache.commons.io.FileUtils.writeByteArrayToFile(new File(instance.gameDir + "/config/moreculling.toml"), FileUtils.loadFromAssetToByte(activity,"moreculling.toml")); + org.apache.commons.io.FileUtils.writeByteArrayToFile(new File(instance.gameDir + "/config/modernfix-mixins.properties"), FileUtils.loadFromAssetToByte(activity,"modernfix-mixins.properties")); + org.apache.commons.io.FileUtils.writeByteArrayToFile(new File(instance.gameDir + "/options.txt"), FileUtils.loadFromAssetToByte(activity, "options.txt")); + org.apache.commons.io.FileUtils.writeByteArrayToFile(new File(instance.gameDir + "/optionsviveprofiles.txt"), FileUtils.loadFromAssetToByte(activity, "optionsviveprofiles.txt")); + org.apache.commons.io.FileUtils.writeByteArrayToFile(new File(instance.gameDir + "/servers.dat"), FileUtils.loadFromAssetToByte(activity, "servers.dat")); + org.apache.commons.io.FileUtils.writeByteArrayToFile(new File(Constants.USER_HOME + "/hacks/ResConfHack.jar"), FileUtils.loadFromAssetToByte(activity, "hacks/ResConfHack.jar")); return new File(gameDir + "/assets").getAbsolutePath(); } diff --git a/src/main/java/pojlib/util/Constants.java b/src/main/java/pojlib/util/Constants.java index 45a4ad27..46ead83b 100644 --- a/src/main/java/pojlib/util/Constants.java +++ b/src/main/java/pojlib/util/Constants.java @@ -14,6 +14,10 @@ public class Constants { public static String QUILT_META_URL = "https://meta.quiltmc.org/v3"; + public static final String FORGE_META_URL = "https://questcraftplusplus.github.io/ForgeVersionAPI"; + + public static final String FORGE_INSTALLER_URL = "https://maven.minecraftforge.net/net/minecraftforge/forge/%1$s/forge-%1$s-installer.jar"; + public static String OAUTH_TOKEN_URL = "https://login.live.com/oauth20_token.srf"; public static String XBL_AUTH_URL = "https://user.auth.xboxlive.com/user/authenticate"; diff --git a/src/main/java/pojlib/util/DownloadUtils.java b/src/main/java/pojlib/util/DownloadUtils.java index ebd087e0..4bde2cab 100644 --- a/src/main/java/pojlib/util/DownloadUtils.java +++ b/src/main/java/pojlib/util/DownloadUtils.java @@ -76,6 +76,29 @@ public static void downloadFile(String url, File out) throws IOException { throw th3; } } + + public static void downloadFileMonitored(String urlInput, File outputFile, @Nullable byte[] buffer, DownloadUtils.DownloaderFeedback monitor) throws IOException { + FileUtils.ensureParentDirectory(outputFile); + + HttpURLConnection conn = (HttpURLConnection) new URL(urlInput).openConnection(); + InputStream readStr = conn.getInputStream(); + try (FileOutputStream fos = new FileOutputStream(outputFile)) { + int current; + int overall = 0; + int length = conn.getContentLength(); + + if (buffer == null) buffer = new byte[65535]; + + while ((current = readStr.read(buffer)) != -1) { + overall += current; + fos.write(buffer, 0, current); + monitor.updateProgress(overall, length); + } + conn.disconnect(); + } + + } + public static boolean compareSHA1(File f, @Nullable String sourceSHA) { try { String sha1_dst; diff --git a/src/main/java/pojlib/util/FileUtil.java b/src/main/java/pojlib/util/FileUtils.java similarity index 95% rename from src/main/java/pojlib/util/FileUtil.java rename to src/main/java/pojlib/util/FileUtils.java index e149b77b..5833f66b 100644 --- a/src/main/java/pojlib/util/FileUtil.java +++ b/src/main/java/pojlib/util/FileUtils.java @@ -3,8 +3,6 @@ import android.app.Activity; import android.content.Context; -import org.apache.commons.io.FileUtils; - import java.io.*; import java.nio.file.Files; import java.nio.file.Paths; @@ -12,13 +10,8 @@ import java.util.Objects; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; -import java.util.zip.ZipInputStream; - -public class FileUtil { - - public static String DIR_GAME_NEW; - public static String DIR_HOME_VERSION; +public class FileUtils { public static byte[] loadFromAssetToByte(Context ctx, String inFile) { byte[] buffer = null; @@ -101,7 +94,7 @@ public static void unzipArchive(String archivePath, String extractPath) { public static void unzipArchiveFromAsset(Activity activity, String archiveName, String extractPath) { try { File zip = new File(extractPath, archiveName); - FileUtils.writeByteArrayToFile(zip, FileUtil.loadFromAssetToByte(activity, archiveName)); + org.apache.commons.io.FileUtils.writeByteArrayToFile(zip, FileUtils.loadFromAssetToByte(activity, archiveName)); try(ZipFile zipFile = new ZipFile(zip)) { byte[] buf = new byte[1024]; Enumeration entries = zipFile.entries(); diff --git a/src/main/java/pojlib/util/ForgeDownloadListener.java b/src/main/java/pojlib/util/ForgeDownloadListener.java new file mode 100644 index 00000000..221d98c3 --- /dev/null +++ b/src/main/java/pojlib/util/ForgeDownloadListener.java @@ -0,0 +1,9 @@ +package pojlib.util; + +import java.io.File; + +public interface ForgeDownloadListener { + void onDownloadFinished(File downloadedFile); + void onDataNotAvailable(); + void onDownloadError(Exception e); +} diff --git a/src/main/java/pojlib/util/JREUtils.java b/src/main/java/pojlib/util/JREUtils.java index 20467a97..f50f07a7 100644 --- a/src/main/java/pojlib/util/JREUtils.java +++ b/src/main/java/pojlib/util/JREUtils.java @@ -242,6 +242,7 @@ public static List getJavaArgs(Context ctx, MinecraftInstances.Instance "-Dglfwstub.windowHeight=" + 720, "-Dglfwstub.initEgl=false", "-Dlog4j2.formatMsgNoLookups=true", //Log4j RCE mitigation + "-Dfml.earlyprogresswindow=false", //Forge 1.14+ workaround "-Dnet.minecraft.clientmodname=" + "QuestCraft", "-Dext.net.resolvPath=" + Constants.USER_HOME + "/hacks/ResConfHack.jar", "-Dsodium.checks.issue2561=false", diff --git a/src/main/java/pojlib/util/Logger.java b/src/main/java/pojlib/util/Logger.java index 2331768f..076bcd31 100644 --- a/src/main/java/pojlib/util/Logger.java +++ b/src/main/java/pojlib/util/Logger.java @@ -99,4 +99,10 @@ private void notifyLogListener(String text){ } logListener.onEventLogged(text); } + + public static class ParseException extends Exception { + public ParseException(Exception e) { + super(e); + } + } } diff --git a/src/main/java/pojlib/util/forge/ForgeDownloadTask.java b/src/main/java/pojlib/util/forge/ForgeDownloadTask.java new file mode 100644 index 00000000..724f9f4b --- /dev/null +++ b/src/main/java/pojlib/util/forge/ForgeDownloadTask.java @@ -0,0 +1,77 @@ +package pojlib.util.forge; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.List; + +import pojlib.install.ForgeMeta; +import pojlib.util.DownloadUtils; +import pojlib.util.FileUtils; +import pojlib.util.ForgeDownloadListener; + +public class ForgeDownloadTask implements Runnable, DownloadUtils.DownloaderFeedback { + private String mDownloadUrl; + private String mFullVersion; + private String mLoaderVersion; + private String mGameVersion; + private final ForgeDownloadListener mListener; + public ForgeDownloadTask(ForgeDownloadListener listener, String forgeVersion) { + this.mListener = listener; + this.mDownloadUrl = ForgeUtils.getInstallerUrl(forgeVersion); + this.mFullVersion = forgeVersion; + } + + public ForgeDownloadTask(ForgeDownloadListener listener, String gameVersion, String loaderVersion) { + this.mListener = listener; + this.mLoaderVersion = loaderVersion; + this.mGameVersion = gameVersion; + } + @Override + public void run() { + if(determineDownloadUrl()) { + downloadForge(); + } + } + + private void downloadForge() { + try { + File destinationFile = new File(FileUtils.DIR_CACHE, "forge-installer.jar"); + byte[] buffer = new byte[8192]; + DownloadUtils.downloadFileMonitored(mDownloadUrl, destinationFile, buffer, this); + mListener.onDownloadFinished(destinationFile); + }catch (FileNotFoundException e) { + mListener.onDataNotAvailable(); + } catch (IOException e) { + mListener.onDownloadError(e); + } + } + + public boolean determineDownloadUrl() { + if(mDownloadUrl != null && mFullVersion != null) return true; + try { + if(!findVersion()) { + mListener.onDataNotAvailable(); + return false; + } + }catch (IOException e) { + mListener.onDownloadError(e); + return false; + } + return true; + } + + public boolean findVersion() throws IOException { + ForgeMeta.ForgeVersion[] forgeVersions = ForgeMeta.getVersions(); + if(forgeVersions == null) return false; + String versionStart = mGameVersion+"-"+mLoaderVersion; + for(ForgeMeta.ForgeVersion versionName : forgeVersions) { + if(!versionName.startsWith(versionStart)) continue; + mFullVersion = versionName; + mDownloadUrl = ForgeUtils.getInstallerUrl(mFullVersion); + return true; + } + return false; + } + +} \ No newline at end of file diff --git a/src/main/java/pojlib/util/forge/ForgeUtils.java b/src/main/java/pojlib/util/forge/ForgeUtils.java new file mode 100644 index 00000000..51664a40 --- /dev/null +++ b/src/main/java/pojlib/util/forge/ForgeUtils.java @@ -0,0 +1,27 @@ +package pojlib.util.forge; + +import static pojlib.util.Constants.FORGE_INSTALLER_URL; + +import android.content.Context; +import android.content.Intent; + +import java.io.File; + + +public class ForgeUtils { + + public static String getInstallerUrl(String version) { + return String.format(FORGE_INSTALLER_URL, version); + } + + public static void addAutoInstallArgs(Intent intent, File modInstallerJar, boolean createProfile, Context ctx) { + intent.putExtra("javaArgs", "-javaagent:"+ ctx.getFilesDir().getParent() +"/forge_installer/forge_installer.jar" + + (createProfile ? "=NPS" : "") + // No Profile Suppression + " -jar "+modInstallerJar.getAbsolutePath()); + } + public static void addAutoInstallArgs(Intent intent, File modInstallerJar, String modpackFixupId, Context ctx) { + intent.putExtra("javaArgs", "-javaagent:"+ ctx.getFilesDir().getParent() +"/forge_installer/forge_installer.jar" + + "=\"" + modpackFixupId +"\"" + + " -jar "+modInstallerJar.getAbsolutePath()); + } +} diff --git a/src/main/java/pojlib/util/json/MinecraftInstances.java b/src/main/java/pojlib/util/json/MinecraftInstances.java index 03d9f8b1..9052afa3 100644 --- a/src/main/java/pojlib/util/json/MinecraftInstances.java +++ b/src/main/java/pojlib/util/json/MinecraftInstances.java @@ -3,7 +3,6 @@ import java.io.File; import java.io.IOException; import java.nio.file.Files; -import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -11,10 +10,8 @@ import pojlib.account.MinecraftAccount; import pojlib.API; import pojlib.InstanceHandler; -import pojlib.account.Msa; import pojlib.util.Constants; import pojlib.util.DownloadUtils; -import pojlib.util.FileUtil; import pojlib.util.GsonUtils; import pojlib.util.Logger;