Skip to content

Commit

Permalink
Start Forge Work
Browse files Browse the repository at this point in the history
Co-Authored-By: Mathias Boulay <[email protected]>
Co-Authored-By: Maksim Belov <[email protected]>
  • Loading branch information
3 people committed Oct 31, 2024
1 parent 8f42cbc commit 507b8ee
Show file tree
Hide file tree
Showing 15 changed files with 215 additions and 54 deletions.
2 changes: 1 addition & 1 deletion src/main/assets/lwjgl/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1728465869857
1730335323711
9 changes: 6 additions & 3 deletions src/main/java/pojlib/InstanceHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
18 changes: 6 additions & 12 deletions src/main/java/pojlib/UnityPlayerActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,16 @@

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;
import android.os.Bundle;
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;
Expand All @@ -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
{
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down
19 changes: 6 additions & 13 deletions src/main/java/pojlib/account/Msa.java
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -28,8 +23,6 @@
import java.util.Collections;
import java.util.Map;

import javax.xml.transform.ErrorListener;


public class Msa {
private static final Map<Long, String> XSTS_ERRORS;
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
37 changes: 37 additions & 0 deletions src/main/java/pojlib/install/ForgeMeta.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
23 changes: 10 additions & 13 deletions src/main/java/pojlib/install/Installer.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,13 @@
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.*;

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;
Expand Down Expand Up @@ -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();
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/pojlib/util/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/pojlib/util/DownloadUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,15 @@
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;
import java.util.Enumeration;
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;
Expand Down Expand Up @@ -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<? extends ZipEntry> entries = zipFile.entries();
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/pojlib/util/ForgeDownloadListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package pojlib.util;

import java.io.File;

public interface ForgeDownloadListener {
void onDownloadFinished(File downloadedFile);
void onDataNotAvailable();
void onDownloadError(Exception e);
}
1 change: 1 addition & 0 deletions src/main/java/pojlib/util/JREUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ public static List<String> 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",
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/pojlib/util/Logger.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,10 @@ private void notifyLogListener(String text){
}
logListener.onEventLogged(text);
}

public static class ParseException extends Exception {
public ParseException(Exception e) {
super(e);
}
}
}
Loading

0 comments on commit 507b8ee

Please sign in to comment.