Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ app_pojavlauncher/.cxx/
.vs/
/curseforge_key.txt
/app_pojavlauncher/libs/ltw-release.aar
/jre_lwjgl3glfw/gradle/
/jre_lwjgl3glfw/**/build/
/jre_lwjgl3glfw/**/.gradle/
Binary file not shown.
Binary file not shown.
Binary file added app_pojavlauncher/libs/spirv-cross-natives.aar
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2016eba00f043842122d7aecb9410cf9371a7693
2e6a5441ad057039d002e6e35ebc6f1d7bd9a7d0
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20260211-java25-fix-backwards-compat
20260408-remove-leftover-surface-manager-stuff
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
d5fc862f0eba62565dee5b8e511544573c281ec1
d26e5744eeccf6b7d4d214f2b555886a04b62012
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
912a97ca94dd06f8a6dfb25608c0024dcd1ec0a2
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
4d7b802102910e7d570874ad36e1e0fa6874117e
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
f090d130b1b02def937f26cc62c38ef429ed7b52
8fc4f7410f7ff1ebea0d604f69d13531814650ca
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,17 @@ public static String archAsString(int arch){
if(arch == ARCH_X86) return "x86";
return "UNSUPPORTED_ARCH";
}
/**
* Convert to a string an architecture.
* @param arch The architecture as an int.
* @return "arm64" || "arm" || "x86_64" || "x86" || "UNSUPPORTED_ARCH"
*/
public static String archAsStringAndroid(int arch) {
if(arch == ARCH_ARM64) return "arm64-v8a";
if(arch == ARCH_ARM) return "armeabi-v7a";
if(arch == ARCH_X86_64) return "x86_64";
if(arch == ARCH_X86) return "x86";
return "UNSUPPORTED_ARCH";
}

}
76 changes: 62 additions & 14 deletions app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/Tools.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import static android.os.Build.VERSION.SDK_INT;
import static android.os.Build.VERSION_CODES.P;
import static net.kdt.pojavlaunch.Architecture.archAsStringAndroid;
import static net.kdt.pojavlaunch.Architecture.getDeviceArchitecture;
import static net.kdt.pojavlaunch.PojavApplication.sExecutorService;
import static net.kdt.pojavlaunch.PojavProfile.getAllProfiles;
import static net.kdt.pojavlaunch.prefs.LauncherPreferences.PREF_IGNORE_NOTCH;
Expand Down Expand Up @@ -145,7 +147,9 @@ public final class Tools {
public static String CTRLMAP_PATH;
public static String CTRLDEF_FILE;
private static RenderersList sCompatibleRenderers;
private static boolean isLwjgl3 = true;
public static int iLwjglVersion = 0;
public static String sLwjglVersion = null;
public static String lwjglNativesDir = null;


private static File getPojavStorageRoot(Context ctx) {
Expand Down Expand Up @@ -454,11 +458,19 @@ public static void launchMinecraft(final AppCompatActivity activity, MinecraftAc
}

File versionSpecificNativesDir = new File(Tools.DIR_CACHE, "natives/"+versionId);
StringBuilder javaLibraryPath = new StringBuilder();

// Add which lwjgl natives to use into classpath
javaLibraryPath.append(lwjglNativesDir).append(":");

// Add JNA native if needed
javaLibraryPath.append(Tools.NATIVE_LIB_DIR).append(":");
if(versionSpecificNativesDir.exists()) {
String dirPath = versionSpecificNativesDir.getAbsolutePath();
javaArgList.add("-Djava.library.path="+dirPath+":"+Tools.NATIVE_LIB_DIR);
javaLibraryPath.append(dirPath).append(":");
javaArgList.add("-Djna.boot.library.path="+dirPath);
}
javaArgList.add("-Djava.library.path="+javaLibraryPath);

javaArgList.addAll(Arrays.asList(getMinecraftJVMArgs(versionId, gamedir)));
javaArgList.add("-cp"); javaArgList.add(launchClasspath);
Expand Down Expand Up @@ -842,21 +854,32 @@ public static String getClientClasspath(String version) {
}
public static String generateLaunchClasspath(JMinecraftVersionList.Version info, String actualname) {
StringBuilder launchClasspath = new StringBuilder(); //versnDir + "/" + version + "/" + version + ".jar:";
String lwjgl3Folder = new File(Tools.DIR_GAME_HOME, "lwjgl3").getAbsolutePath();
String lwjgl3File = lwjgl3Folder + "/lwjgl-glfw-classes.jar";
String lwjglxFile = lwjgl3Folder + "/lwjglx-classes.jar";

launchClasspath.append(lwjgl3File).append(":");
launchClasspath.append(getLibClasspath(info)).append(":");
String libClasspath = getLibClasspath(info); // Sets lwjglVersion, janky, but we can't get it any simpler
String internalLwjglVersion = iLwjglVersion >= 341 ? "3.4.1" : "3.3.3";
File lwjgl3Folder = new File(Tools.DIR_GAME_HOME, "lwjgl3/"+internalLwjglVersion);
String lwjglCore = lwjgl3Folder.getAbsolutePath() + "/lwjgl.jar";
String lwjglxFile = lwjgl3Folder + "/lwjgl-lwjglx.jar";

launchClasspath.append(lwjglCore).append(":");

File[] lwjglModules = lwjgl3Folder.listFiles(pathname ->
pathname.getName().endsWith(".jar") &&
// Exclude our two special jars which goes first and last
!pathname.getName().equals("lwjgl.jar") &&
!pathname.getName().endsWith("lwjglx.jar"));

if (lwjglModules != null) {
for (File lwjglModule : lwjglModules)
launchClasspath.append(lwjglModule.getAbsolutePath()).append(":");
} else Log.e("generateLaunchClasspath", "lwjgl modules are missing from components!");

launchClasspath.append(libClasspath).append(":");
launchClasspath.append(getClientClasspath(actualname));
if (!isLwjgl3) launchClasspath.append(":").append(lwjglxFile);
// Anything LWJGL2 gets LWJGLX
if (iLwjglVersion <= 299) launchClasspath.append(":").append(lwjglxFile);
return launchClasspath.toString();
}





public static DisplayMetrics getDisplayMetrics(Activity activity) {
DisplayMetrics displayMetrics = new DisplayMetrics();

Expand Down Expand Up @@ -1136,7 +1159,28 @@ private static void createLibraryInfo(DependentLibrary library) {
public static String[] generateLibClasspath(JMinecraftVersionList.Version info) {
List<String> libDir = new ArrayList<>();
for (DependentLibrary libItem: info.libraries) {
if(libItem.name.startsWith("org.lwjgl.lwjgl:lwjgl:2.")) isLwjgl3 = false;
// Look for LWJGL version
int libItemVersionStringOffset = 0;
if(libItem.name.startsWith("org.lwjgl.lwjgl:lwjgl:")) {
libItemVersionStringOffset = "org.lwjgl.lwjgl:lwjgl:".length();
} else if (libItem.name.startsWith("org.lwjgl:lwjgl:")) {
libItemVersionStringOffset = "org.lwjgl:lwjgl:".length();
}
// If we already have a valid LWJGL version, skip this block
if (libItemVersionStringOffset != 0 && (iLwjglVersion < 200 || iLwjglVersion > 999)) {
while (libItemVersionStringOffset < libItem.name.length()) {
char c = libItem.name.charAt(libItemVersionStringOffset);
if (c >= '0' && c <= '9') {
iLwjglVersion = iLwjglVersion * 10 + (c - '0');
} else if (c == '.') {
// skip dots
} else {
break; // If the dots and numbers stop then its time to finish
}
libItemVersionStringOffset++;
}
}

String libPath = Tools.DIR_HOME_LIBRARY + "/" + artifactToPath(libItem);
if (!FileUtils.exists(libPath)) {
Log.d(APP_NAME, "Ignored non-exists file: " + libPath);
Expand All @@ -1151,6 +1195,10 @@ public static String[] generateLibClasspath(JMinecraftVersionList.Version info)
}} ));
}
}
// Scary message, but we aren't getting LWJGL 1.9.9 or 3.10.100 any time soon
if (iLwjglVersion < 200 || iLwjglVersion > 999) throw new RuntimeException("Unable to determine LWJGL version, JSON may be corrupt.");
sLwjglVersion = iLwjglVersion >= 341 ? "3.4.1" : "3.3.3";
lwjglNativesDir = String.format("%s/lwjgl-%s-natives/%s", Tools.DIR_DATA, sLwjglVersion, archAsStringAndroid(getDeviceArchitecture()));
return libDir.toArray(new String[0]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@


import static net.kdt.pojavlaunch.Architecture.archAsString;
import static net.kdt.pojavlaunch.Architecture.archAsStringAndroid;
import static net.kdt.pojavlaunch.Architecture.getDeviceArchitecture;
import static net.kdt.pojavlaunch.PojavApplication.sExecutorService;

import android.content.Context;
Expand All @@ -10,6 +12,7 @@

import com.kdt.mcgui.ProgressLayout;

import net.kdt.pojavlaunch.Architecture;
import net.kdt.pojavlaunch.Tools;
import net.kdt.pojavlaunch.multirt.MultiRTUtils;

Expand Down Expand Up @@ -83,7 +86,9 @@ public static void unpackComponents(Context ctx){
unpackComponent(ctx, "caciocavallo17", false);
// Since the Java module system doesn't allow multiple JARs to declare the same module,
// we repack them to a single file here
unpackComponent(ctx, "lwjgl3", false);
unpackLwjglNatives(ctx);
unpackComponent(ctx, "lwjgl3/3.3.3", false);
unpackComponent(ctx, "lwjgl3/3.4.1", false);
unpackComponent(ctx, "security", true);
unpackComponent(ctx, "arc_dns_injector", true);
unpackComponent(ctx, "methods_injector_agent", true);
Expand All @@ -94,6 +99,39 @@ public static void unpackComponents(Context ctx){
ProgressLayout.clearProgress(ProgressLayout.EXTRACT_COMPONENTS);
});
}
// Piggybacks off of the java modules extracting later to use their version files for update checks
// This is indeed prone to breaking.
private static void unpackLwjglNatives(Context ctx) throws IOException {
AssetManager am = ctx.getAssets();
String rootDir = Tools.DIR_DATA;
String sArch = archAsStringAndroid(getDeviceArchitecture());

String[] lwjglVersions = {"3.3.3", "3.4.1"};
for (String lwjglVer : lwjglVersions) {
File versionFile = new File(Tools.DIR_GAME_HOME + String.format("/lwjgl3/%s/version", lwjglVer));
InputStream is = am.open("components/lwjgl3/" + lwjglVer + "/version");
String pathToLwjglNatives = String.format("lwjgl-%s-natives/", lwjglVer) + sArch;

boolean shouldUpdate = true;
if (versionFile.exists()) {
FileInputStream fis = new FileInputStream(versionFile);
String release1 = Tools.read(is);
String release2 = Tools.read(fis);
if (release1.equals(release2))
shouldUpdate = false;
}

if (shouldUpdate) {
Log.i("UnpackLwjgl", lwjglVer + " was installed manually, or does not exist, unpacking new...");
String[] fileList = am.list("components/" + pathToLwjglNatives);
for (String fileName : fileList) {
Tools.copyAssetFile(ctx, "components/" + pathToLwjglNatives + "/" + fileName, rootDir + "/" + pathToLwjglNatives, true);
}
} else {
Log.i("UnpackLwjgl", lwjglVer + " is up-to-date with the launcher, continuing...");
}
}
}

private static void unpackComponent(Context ctx, String component, boolean privateDirectory) throws IOException {
AssetManager am = ctx.getAssets();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,12 @@ public static void launchJavaVM(final AppCompatActivity activity, final Runtime

// Force LWJGL to use the Freetype library intended for it, instead of using the one
// that we ship with Java (since it may be older than what's needed)
userArgs.add("-Dorg.lwjgl.freetype.libname="+ NATIVE_LIB_DIR+"/libfreetype.so");
userArgs.add("-Dorg.lwjgl.freetype.libname="+ Tools.lwjglNativesDir +"/libfreetype.so");
// Our spirv-cross is compiled shared, so it gets named shared.
userArgs.add("-Dorg.lwjgl.spvc.libname=spirv-cross-c-shared");

// We don't have jemalloc for our LWJGL so set the allocator to system to avoid error logs
userArgs.add("-Dorg.lwjgl.system.allocator=system");

// Some phones are not using the right number of cores, fix that
userArgs.add("-XX:ActiveProcessorCount=" + java.lang.Runtime.getRuntime().availableProcessors());
Expand Down
82 changes: 26 additions & 56 deletions jre_lwjgl3glfw/build.gradle
Original file line number Diff line number Diff line change
@@ -1,65 +1,35 @@
import java.security.MessageDigest

plugins {
id 'java'
}

group = 'org.lwjgl.glfw'

configurations.default.setCanBeResolved(true)

jar {
String lwjglxJarName = "lwjgl-lwjglx.jar" // Name of the jar with LWJGLX (LWJGL2 Compatibility) Classes
String lwjglxFinalJarName = "lwjglx-classes.jar" // What lwjglxJarName is renamed to
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
archiveBaseName.set("lwjgl-glfw-classes")
destinationDirectory.set(file("../app_pojavlauncher/src/main/assets/components/lwjgl3/"))

// Mark as using multiple Java versions.
manifest {
attributes "Multi-Release": "true"
}

from {
// Ensure that the core lwjgl jar is processed first so duplicates in META-INF from other classes
// are ignored. This avoids InvalidModuleDescriptorException due to say, using the module-info.class
// from lwjgl-jemalloc.
def files = configurations.default.findAll { it.name != lwjglxJarName }
def coreJar = files.find { it.name == "lwjgl.jar" }
def others = files - coreJar
([coreJar] + others).collect {
println(it.getName())
it.isDirectory() ? it : zipTree(it)
// Yes this is duplicate, no I don't care, this makes it able to live on its own
// You, yes you! can copy paste this anywhere and it will build! (just remember to change the destinationDir).

static void hashFileWithDigest(File fileToHash, MessageDigest digest){
fileToHash.withInputStream { is ->
byte[] buffer = new byte[8192]
int read
while ((read = is.read(buffer)) != -1) {
digest.update(buffer, 0, read)
}
}
// Makes the jar reproducible so the version file actually is a version file
preserveFileTimestamps = false
reproducibleFileOrder = true
// Write version file
def versionFile = new File(project(":app_pojavlauncher").projectDir, "src/main/assets/components/lwjgl3/version")
def lwjglxFinalFile = new File(project(":app_pojavlauncher").projectDir, "src/main/assets/components/lwjgl3/" + lwjglxFinalJarName)
def jarFile = archiveFile.get().asFile
doLast {
copy {
// Copy lwjglx to the lwjgl classes dir
from configurations.default.find { it.name == lwjglxJarName }
into archiveFile.get().asFile.parentFile
rename lwjglxJarName, lwjglxFinalJarName
}
writeVersionFile([jarFile, lwjglxFinalFile] as File[], versionFile)
}
// Adds the jank to outputs
outputs.file(versionFile)
outputs.file(lwjglxFinalFile)

exclude 'net/java/openjdk/cacio/ctc/**'
}

java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
static void writeVersionFile(File jarFile, File versionFile){
def sha1 = MessageDigest.getInstance("SHA-1")
hashFileWithDigest(jarFile, sha1)
versionFile.write(sha1.digest().collect { String.format("%02x", it) }.join())
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
static void writeVersionFile(File[] jarFileArray, File versionFile){
def sha1 = MessageDigest.getInstance("SHA-1")
jarFileArray.each {jarFile ->
hashFileWithDigest(jarFile, sha1)
}
versionFile.write(sha1.digest().collect { String.format("%02x", it) }.join())
}
def lwjglVersions = ["lwjgl-3.3.3", "lwjgl-3.4.1"]

tasks.register("jar") {
lwjglVersions.each { version ->
dependsOn(":jre_lwjgl3glfw:$version:jar")
}
}
Loading
Loading