Skip to content

Commit

Permalink
Update from upstream
Browse files Browse the repository at this point in the history
fix lwjgl issues
  • Loading branch information
SolDev69 committed Jul 28, 2024
2 parents 83d30e5 + ae48e8e commit bbd8df1
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import android.widget.Toast;

import androidx.activity.OnBackPressedCallback;
import androidx.appcompat.app.AlertDialog;

import com.kdt.LoggerView;

Expand Down Expand Up @@ -185,6 +186,7 @@ private void startModInstallerWithUri(Uri uri) {
try {
File cacheFile = new File(getCacheDir(), "mod-installer-temp");
InputStream contentStream = getContentResolver().openInputStream(uri);
if(contentStream == null) throw new IOException("Failed to open content stream");
try (FileOutputStream fileOutputStream = new FileOutputStream(cacheFile)) {
IOUtils.copy(contentStream, fileOutputStream);
}
Expand All @@ -195,23 +197,71 @@ private void startModInstallerWithUri(Uri uri) {
}
}

public Runtime selectRuntime(File modFile) {
int javaVersion = getJavaVersion(modFile);
if(javaVersion == -1) {
finalErrorDialog(getString(R.string.execute_jar_failed_to_read_file));
return null;
}
String nearestRuntime = MultiRTUtils.getNearestJreName(javaVersion);
if(nearestRuntime == null) {
finalErrorDialog(getString(R.string.multirt_nocompatiblert, javaVersion));
return null;
}
Runtime selectedRuntime = MultiRTUtils.forceReread(nearestRuntime);
int selectedJavaVersion = Math.max(javaVersion, selectedRuntime.javaVersion);
// Don't allow versions higher than Java 17 because our caciocavallo implementation does not allow for it
if(selectedJavaVersion > 17) {
finalErrorDialog(getString(R.string.execute_jar_incompatible_runtime, selectedJavaVersion));
return null;
}
return selectedRuntime;
}

private File findModPath(List<String> argList) {
int argsSize = argList.size();
for(int i = 0; i < argsSize; i++) {
// Look for the -jar argument
if(!argList.get(i).equals("-jar")) continue;
int pathIndex = i+1;
// Check if the supposed path is out of the argument bounds
if(pathIndex >= argsSize) return null;
// Use the path as a file
return new File(argList.get(pathIndex));
}
return null;
}

private void startModInstaller(File modFile, String javaArgs) {
new Thread(() -> {
Runtime runtime = pickJreForMod(modFile);
launchJavaRuntime(runtime, modFile, javaArgs);
// Maybe replace with more advanced arg parsing logic later
List<String> argList = javaArgs != null ? Arrays.asList(javaArgs.split(" ")) : null;
File selectedMod = modFile;
if(selectedMod == null && argList != null) {
// If modFile is not specified directly, try to extract the -jar argument from the javaArgs
selectedMod = findModPath(argList);
}
Runtime selectedRuntime;
if(selectedMod == null) {
// We were unable to find out the path to the mod. In that case, use the default runtime.
selectedRuntime = MultiRTUtils.forceReread(LauncherPreferences.PREF_DEFAULT_RUNTIME);
}else {
// Autoselect it properly in the other case.
selectedRuntime = selectRuntime(selectedMod);
// If the selection failed, just return. The autoselect function has already shown the dialog.
if(selectedRuntime == null) return;
}
launchJavaRuntime(selectedRuntime, modFile, argList);
}, "JREMainThread").start();
}

private Runtime pickJreForMod(File modFile) {
String jreName = LauncherPreferences.PREF_DEFAULT_RUNTIME;
if(modFile != null) {
int javaVersion = getJavaVersion(modFile);
if(javaVersion != -1) {
String autoselectRuntime = MultiRTUtils.getNearestJreName(javaVersion);
if (autoselectRuntime != null) jreName = autoselectRuntime;
}
}
return MultiRTUtils.forceReread(jreName);
private void finalErrorDialog(CharSequence msg) {
runOnUiThread(()-> new AlertDialog.Builder(this)
.setTitle(R.string.global_error)
.setMessage(msg)
.setPositiveButton(android.R.string.ok, (d,w)->this.finish())
.setCancelable(false)
.show());
}

@Override
Expand Down Expand Up @@ -301,21 +351,20 @@ public void toggleVirtualMouse(View v) {
Toast.LENGTH_SHORT).show();
}

public void launchJavaRuntime(Runtime runtime, File modFile, String javaArgs) {
public void launchJavaRuntime(Runtime runtime, File modFile, List<String> javaArgs) {
JREUtils.redirectAndPrintJRELog();
try {
List<String> javaArgList = new ArrayList<>();

// Enable Caciocavallo
Tools.getCacioJavaArgs(javaArgList,runtime.javaVersion == 8);

if (javaArgs != null) {
javaArgList.addAll(Arrays.asList(javaArgs.split(" ")));
} else {
if(javaArgs != null) {
javaArgList.addAll(javaArgs);
}
if(modFile != null) {
javaArgList.add("-jar");
javaArgList.add(modFile.getAbsolutePath());
}


if (LauncherPreferences.PREF_JAVA_SANDBOX) {
Collections.reverse(javaArgList);
Expand Down Expand Up @@ -374,7 +423,7 @@ public int getJavaVersion(File modFile) {
Log.i("JavaGUILauncher", majorVersion+","+minorVersion);
return classVersionToJavaVersion(majorVersion);
}catch (Exception e) {
e.printStackTrace();
Log.e("JavaVersion", "Exception thrown", e);
return -1;
}
}
Expand Down
Binary file modified app_pojavlauncher/src/main/jniLibs/arm64-v8a/libgl4es_114.so
100644 → 100755
Binary file not shown.
Binary file modified app_pojavlauncher/src/main/jniLibs/armeabi-v7a/libgl4es_114.so
100644 → 100755
Binary file not shown.
Binary file modified app_pojavlauncher/src/main/jniLibs/x86/libgl4es_114.so
100644 → 100755
Binary file not shown.
Binary file modified app_pojavlauncher/src/main/jniLibs/x86_64/libgl4es_114.so
100644 → 100755
Binary file not shown.
2 changes: 2 additions & 0 deletions app_pojavlauncher/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -391,4 +391,6 @@
<string name="log_view_button_output_off">Output\nOFF</string>
<string name="log_view_button_output_on">Output\nON</string>
<string name="log_view_label_log_output">Log output:</string>
<string name="execute_jar_failed_to_read_file">Failed to read the .jar file</string>
<string name="execute_jar_incompatible_runtime">Execute .jar feature is not compatible with Java %d</string>
</resources>

0 comments on commit bbd8df1

Please sign in to comment.