LWJGL3 repacker

Since the Java module system doesn't allow multiple JARs to declare the same module, it has to be packed into one in order for Forge 1.17+ to work.
By this way, Forge started working but there's no input for some reasons.
This commit is contained in:
khanhduytran0 2022-05-09 09:43:30 +07:00
parent 97d95d9ef4
commit 051b6e456b
5 changed files with 49 additions and 4 deletions

View File

@ -1 +1 @@
1647645869468
1652063179136

View File

@ -58,16 +58,22 @@ import net.kdt.pojavlaunch.value.PerVersionConfig;
import net.kdt.pojavlaunch.value.launcherprofiles.LauncherProfiles;
import net.kdt.pojavlaunch.value.launcherprofiles.MinecraftProfile;
import org.apache.commons.compress.utils.IOUtils;
import org.apache.commons.io.FileUtils;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Locale;
import java.util.jar.Attributes;
import java.util.jar.JarEntry;
import java.util.jar.JarInputStream;
import java.util.jar.JarOutputStream;
public class PojavLoginActivity extends BaseActivity {
private final Object mLockStoragePerm = new Object();
@ -261,8 +267,41 @@ public class PojavLoginActivity extends BaseActivity {
PojavProfile.setCurrentProfile(this, null);
}
private void unpackComponent(AssetManager am, String component) throws IOException {
private void repackLWJGL3(boolean ignoreExistence) throws IOException {
File outFile = new File(Tools.DIR_GAME_HOME + "/lwjgl3/lwjgl-fat.jar");
File outTmpFile = new File(Tools.DIR_GAME_HOME + "/lwjgl3/lwjgl-fat.jar.tmp");
File[] innerFiles = outTmpFile.getParentFile().listFiles();
if (outFile.exists() && !ignoreExistence) {
return;
}
outFile.delete();
outTmpFile.delete();
java.util.jar.Manifest manifest = new java.util.jar.Manifest();
manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
JarOutputStream outJar = new JarOutputStream(new FileOutputStream(outTmpFile), manifest);
outJar.setLevel(9);
for (File file : innerFiles) {
if (!file.getName().endsWith(".jar")) continue;
JarInputStream inJar = new JarInputStream(new FileInputStream(file));
JarEntry entry;
while ((entry = inJar.getNextJarEntry()) != null) {
// avoid some duplicated entries
if (entry.getSize() == 0 || entry.getName().equals("META-INF/INDEX.LIST") || entry.getName().startsWith("META-INF/versions")) continue;
outJar.putNextEntry(new JarEntry(entry.getName()));
IOUtils.copy(inJar, outJar);
}
inJar.close();
file.delete();
}
outJar.close();
outTmpFile.renameTo(outFile);
}
private boolean unpackComponent(AssetManager am, String component) throws IOException {
File versionFile = new File(Tools.DIR_GAME_HOME + "/" + component + "/version");
InputStream is = am.open("components/" + component + "/version");
if(!versionFile.exists()) {
@ -292,8 +331,10 @@ public class PojavLoginActivity extends BaseActivity {
}
} else {
Log.i("UnpackPrep", component + ": Pack is up-to-date with the launcher, continuing...");
return false;
}
}
return true;
}
public static void disableSplash(String dir) {
mkdirs(dir + "/config");
@ -340,7 +381,11 @@ public class PojavLoginActivity extends BaseActivity {
AssetManager am = this.getAssets();
unpackComponent(am, "caciocavallo");
unpackComponent(am, "lwjgl3");
// Since the Java module system doesn't allow multiple JARs to declare the same module,
// we repack them to a single file here
repackLWJGL3(unpackComponent(am, "lwjgl3"));
if(!installRuntimeAutomatically(am,MultiRTUtils.getRuntimes().size() > 0)) {
MultiRTConfigDialog.openRuntimeSelector(this, MultiRTConfigDialog.MULTIRT_PICK_RUNTIME_STARTUP);
synchronized (mLockSelectJRE) {