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
Binary file removed app_pojavlauncher/libs/lwjgl-build-release.aar
Binary file not shown.
Binary file added app_pojavlauncher/libs/lwjgl3-natives-release.aar
Binary file not shown.
74 changes: 30 additions & 44 deletions app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/Tools.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ public final class Tools {
public static String CTRLMAP_PATH;
public static String CTRLDEF_FILE;
private static RenderersList sCompatibleRenderers;
private static boolean isLwjgl3 = true;


private static File getPojavStorageRoot(Context ctx) {
Expand Down Expand Up @@ -435,7 +436,7 @@ public static void launchMinecraft(final AppCompatActivity activity, MinecraftAc
OldVersionsUtils.selectOpenGlVersion(versionInfo);


String launchClassPath = generateLaunchClassPath(versionInfo, versionId);
String launchClasspath = generateLaunchClasspath(versionInfo, versionId);

List<String> javaArgList = new ArrayList<>();

Expand All @@ -457,12 +458,7 @@ public static void launchMinecraft(final AppCompatActivity activity, MinecraftAc
}

javaArgList.addAll(Arrays.asList(getMinecraftJVMArgs(versionId, gamedir)));
javaArgList.add("-cp");
if (launchClassPath.contains("bta-client-")){ // BTADownloadTask.BASE_JSON sets this. Jank.
// BTA for some reason needs this to be last or else it uses the wrong lwjgl
javaArgList.add(launchClassPath + ":" + getLWJGL3ClassPath());
// Legacy Fabric needs this to be first or else it uses the wrong lwjgl
} else javaArgList.add(getLWJGL3ClassPath() + ":" + launchClassPath);
javaArgList.add("-cp"); javaArgList.add(launchClasspath);

// Forge 1.6.4 crash mitigation
// https://github.com/MinecraftForge/FML/blob/f1b3381e61fac1a0ae90f521223c6bc613eb4888/common/cpw/mods/fml/common/asm/FMLSanityChecker.java#L192-L208
Expand Down Expand Up @@ -797,47 +793,31 @@ public static String artifactToPath(DependentLibrary library) {
return libInfos[0].replaceAll("\\.", "/") + "/" + libInfos[1] + "/" + libInfos[2] + "/" + libInfos[1] + "-" + libInfos[2] + ".jar";
}

public static String getClientClasspath(String version) {
return DIR_HOME_VERSION + "/" + version + "/" + version + ".jar";
}

private static String getLWJGL3ClassPath() {
StringBuilder libStr = new StringBuilder();
File lwjgl3Folder = new File(Tools.DIR_GAME_HOME, "lwjgl3");
File[] lwjgl3Files = lwjgl3Folder.listFiles();
if (lwjgl3Files != null) {
for (File file: lwjgl3Files) {
if (file.getName().endsWith(".jar")) {
libStr.append(file.getAbsolutePath()).append(":");
}
}
private static String getLibClasspath(JMinecraftVersionList.Version info){
StringBuilder libClasspath = new StringBuilder();
String[] classpath = generateLibClasspath(info);
for (String jarFile : classpath) {
libClasspath.append(jarFile).append(":");
}
// Remove the ':' at the end
libStr.setLength(libStr.length() - 1);
return libStr.toString();
libClasspath.setLength(libClasspath.length() - 1);
return libClasspath.toString();
}

private final static boolean isClientFirst = false;
public static String generateLaunchClassPath(JMinecraftVersionList.Version info, String actualname) {
StringBuilder finalClasspath = new StringBuilder(); //versnDir + "/" + version + "/" + version + ".jar:";

String[] classpath = generateLibClasspath(info);

if (isClientFirst) {
finalClasspath.append(getClientClasspath(actualname));
}
for (String jarFile : classpath) {
if (!FileUtils.exists(jarFile)) {
Log.d(APP_NAME, "Ignored non-exists file: " + jarFile);
continue;
}
finalClasspath.append((isClientFirst ? ":" : "")).append(jarFile).append(!isClientFirst ? ":" : "");
}
if (!isClientFirst) {
finalClasspath.append(getClientClasspath(actualname));
}
public static String getClientClasspath(String version) {
return DIR_HOME_VERSION + "/" + version + "/" + version + ".jar";
}
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";

return finalClasspath.toString();
launchClasspath.append(lwjgl3File).append(":");
launchClasspath.append(getLibClasspath(info)).append(":");
launchClasspath.append(getClientClasspath(actualname));
if (!isLwjgl3) launchClasspath.append(":").append(lwjglxFile);
return launchClasspath.toString();
}


Expand Down Expand Up @@ -1123,8 +1103,14 @@ 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;
String libPath = Tools.DIR_HOME_LIBRARY + "/" + artifactToPath(libItem);
if (!FileUtils.exists(libPath)) {
Log.d(APP_NAME, "Ignored non-exists file: " + libPath);
continue;
}
if(!checkRules(libItem.rules)) continue;
libDir.add(Tools.DIR_HOME_LIBRARY + "/" + artifactToPath(libItem));
libDir.add(libPath);
// Mitigation: Babric doesn't use asm-all for some reason so it does a classpath conflict
if (libItem.name.startsWith("org.ow2.asm:asm") && !libItem.name.startsWith("org.ow2.asm:asm-all:")){
libDir.remove(Tools.DIR_HOME_LIBRARY + "/" + artifactToPath(new DependentLibrary(){{
Expand Down
23 changes: 17 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,26 @@ plugins{
id 'com.android.library' version '8.7.2' apply false
}

static void writeVersionFile(File jarFile, File versionFile){
def sha256 = MessageDigest.getInstance("SHA-1")
jarFile.withInputStream { is ->
static void hashFileWithDigest(File fileToHash, MessageDigest digest){
fileToHash.withInputStream { is ->
byte[] buffer = new byte[8192]
int read
while ((read = is.read(buffer)) != -1) {
sha256.update(buffer, 0, read)
digest.update(buffer, 0, read)
}
}
def hash = sha256.digest().collect { String.format("%02x", it) }.join()
versionFile.write(hash)
}

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())
}

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())
}
29 changes: 26 additions & 3 deletions jre_lwjgl3glfw/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,25 @@ 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 {
configurations.default.collect {
// 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)
}
Expand All @@ -23,11 +37,20 @@ jar {
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 {
writeVersionFile(jarFile, versionFile)
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)
}
outputs.file(versionFile) // Adds the versionFile to outputs
// Adds the jank to outputs
outputs.file(versionFile)
outputs.file(lwjglxFinalFile)

exclude 'net/java/openjdk/cacio/ctc/**'
}
Expand Down
Binary file modified jre_lwjgl3glfw/libs/lwjgl-freetype.jar
Binary file not shown.
Binary file modified jre_lwjgl3glfw/libs/lwjgl-glfw.jar
Binary file not shown.
Binary file modified jre_lwjgl3glfw/libs/lwjgl-jemalloc.jar
Binary file not shown.
Binary file modified jre_lwjgl3glfw/libs/lwjgl-lwjglx.jar
Binary file not shown.
Binary file modified jre_lwjgl3glfw/libs/lwjgl-nanovg.jar
Binary file not shown.
Binary file modified jre_lwjgl3glfw/libs/lwjgl-openal.jar
Binary file not shown.
Binary file modified jre_lwjgl3glfw/libs/lwjgl-opengl.jar
Binary file not shown.
Binary file modified jre_lwjgl3glfw/libs/lwjgl-stb.jar
Binary file not shown.
Binary file modified jre_lwjgl3glfw/libs/lwjgl-tinyfd.jar
Binary file not shown.
Binary file modified jre_lwjgl3glfw/libs/lwjgl.jar
Binary file not shown.
87 changes: 79 additions & 8 deletions jre_lwjgl3glfw/src/main/java/org/lwjgl/glfw/GLFW.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.lwjgl.system.MemoryUtil;

import static org.lwjgl.opengl.GL20.*;
import static org.lwjgl.opengl.GL30.*;
import static org.lwjgl.system.APIUtil.*;
import static org.lwjgl.system.Checks.*;
import static org.lwjgl.system.JNI.*;
Expand Down Expand Up @@ -316,13 +317,16 @@ public class GLFW
GLFW_STICKY_KEYS = 0x33002,
GLFW_STICKY_MOUSE_BUTTONS = 0x33003,
GLFW_LOCK_KEY_MODS = 0x33004,
GLFW_RAW_MOUSE_MOTION = 0x33005;
GLFW_RAW_MOUSE_MOTION = 0x33005,
GLFW_UNLIMITED_MOUSE_BUTTONS = 0x33006,
GLFW_IME = 0x33007;

/** Cursor state. */
public static final int
GLFW_CURSOR_NORMAL = 0x34001,
GLFW_CURSOR_HIDDEN = 0x34002,
GLFW_CURSOR_DISABLED = 0x34003;
GLFW_CURSOR_DISABLED = 0x34003,
GLFW_CURSOR_CAPTURED = 0x34004;

/** The regular arrow cursor shape. */
public static final int GLFW_ARROW_CURSOR = 0x36001;
Expand Down Expand Up @@ -493,6 +497,10 @@ public class GLFW
/* volatile */ public static GLFWWindowPosCallback mGLFWWindowPosCallback;
/* volatile */ public static GLFWWindowRefreshCallback mGLFWWindowRefreshCallback;

public static GLFWPreeditCallback mGLFWPreeditCallback;
public static GLFWIMEStatusCallback mGLFWIMEStatusCallback;
public static GLFWPreeditCandidateCallback mGLFWPreeditCandidateCallback;

// Store callback method references directly to avoid a roundtrip through
// JNI when calling the default LWJGL callbacks.
@Nullable public static GLFWFramebufferSizeCallbackI mGLFWFramebufferSizeCallbackI;
Expand Down Expand Up @@ -794,6 +802,28 @@ public static GLFWWindowRefreshCallback glfwSetWindowRefreshCallback(@NativeType
return lastCallback;
}

public static GLFWPreeditCallback glfwSetPreeditCallback(@NativeType("GLFWwindow *") long window, @Nullable @NativeType("GLFWpreeditfun") GLFWPreeditCallbackI cbfun) {
GLFWPreeditCallback lastCallback = mGLFWPreeditCallback;
if (cbfun == null) mGLFWPreeditCallback = null;
else mGLFWPreeditCallback = GLFWPreeditCallback.create(cbfun);

return lastCallback;
}
public static GLFWIMEStatusCallback glfwSetIMEStatusCallback(@NativeType("GLFWwindow *") long window, @NativeType("GLFWimestatusfun") @Nullable GLFWIMEStatusCallbackI cbfun) {
GLFWIMEStatusCallback lastCallback = mGLFWIMEStatusCallback;
if (cbfun == null) mGLFWIMEStatusCallback = null;
else mGLFWIMEStatusCallback = GLFWIMEStatusCallback.create(cbfun);

return lastCallback;
}
public static GLFWPreeditCandidateCallback glfwSetPreeditCandidateCallback(@NativeType("GLFWwindow *") long window, @NativeType("GLFWpreeditcandidatefun") @Nullable GLFWPreeditCandidateCallbackI cbfun) {
GLFWPreeditCandidateCallback lastCallback = mGLFWPreeditCandidateCallback;
if (cbfun == null) mGLFWPreeditCandidateCallback = null;
else mGLFWPreeditCandidateCallback = GLFWPreeditCandidateCallback.create(cbfun);

return lastCallback;
}

public static GLFWWindowSizeCallback glfwSetWindowSizeCallback(@NativeType("GLFWwindow *") long window, @Nullable @NativeType("GLFWwindowsizefun") GLFWWindowSizeCallbackI cbfun) {
GLFWWindowSizeCallback previousCallback = null;
if(mGLFWWindowSizeCallbackI != null) {
Expand Down Expand Up @@ -832,6 +862,10 @@ public static int glfwGetPlatform() {
return GLFW_PLATFORM_X11;
}

public static boolean glfwPlatformSupported(int platform) {
return platform == GLFW_PLATFORM_X11;
}

@NativeType("GLFWwindow *")
public static long glfwGetCurrentContext() {
long __functionAddress = Functions.GetCurrentContext;
Expand Down Expand Up @@ -997,28 +1031,61 @@ public static long glfwCreateWindow(int width, int height, CharSequence title, l
win.width = mGLFWWindowWidth;
win.height = mGLFWWindowHeight;
win.title = title;
win.windowAttribs.put(GLFW_RESIZABLE, GLFW_FALSE);
// I don't understand why Minecraft doesn't set this itself or why it crashes trying to read
// it before set when it controls the cursor status...
win.inputModes.put(GLFW_CURSOR, GLFW_CURSOR_NORMAL);
win.inputModes.put(GLFW_STICKY_KEYS, GLFW_FALSE); // TODO: Fix glfwGetKeyName() to support this
win.inputModes.put(GLFW_STICKY_MOUSE_BUTTONS, GLFW_FALSE); // TODO: Fix glfwGetMouseButton() to support this
win.inputModes.put(GLFW_IME, GLFW_FALSE);

// Set the Open GL version for context because Forge and derivatives ask for it
// If we give them 0.0, some mods don't like it, so we base our assumptions on a per renderer basis
// Default on 3.3 because mod compat
int glMajor = 3;
int glMinor = 3;
// Custom defaults for specific renderers
boolean turnipLoad = System.getenv("POJAV_LOAD_TURNIP") != null &&
System.getenv("POJAV_LOAD_TURNIP").equals("1");
// These values can be found at headings_array.xml
if (turnipLoad && System.getenv("AMETHYST_RENDERER").equals("vulkan_zink")) {
System.out.println("GLFW: Turnip+Zink detected, setting GL context to 4.6");
glMajor = 4;
glMinor = 6;
} else if (System.getenv("AMETHYST_RENDERER").equals("opengles3_virgl")) {
System.out.println("GLFW: virglrenderer detected, setting GL context to 4.3");
glMajor = 4;
glMinor = 3;
} else if (System.getenv("AMETHYST_RENDERER").equals("opengles_mobileglues")) {
System.out.println("GLFW: MobileGlues detected, setting GL context to 4.0");
glMajor = 4;
glMinor = 0;
} else {
System.out.println("GLFW: " + System.getenv("AMETHYST_RENDERER") + " detected, defaulting GL context to 3.3");
}
// Get the real values properly
FunctionProvider functionProvider = org.lwjgl.opengl.GL.getFunctionProvider();
if (functionProvider != null) {
// We don't assume createCapabilities has been called nor do we call it
// This was based from LWJGL GL.createCapabilities()
long GetError = functionProvider.getFunctionAddress("glGetError");
long GetString = functionProvider.getFunctionAddress("glGetString");
long GetIntegerv = functionProvider.getFunctionAddress("glGetIntegerv");

// Change the default to whatever GL_VERSION can be extracted to, only if higher ver
String versionString = memUTF8Safe(callP(GL_VERSION, GetString));
if (versionString != null) {
try {
APIVersion apiVersion = apiParseVersion(versionString);
if (3 <= apiVersion.major && apiVersion.major <= 4) glMajor = apiVersion.major;
if (3 <= apiVersion.minor && apiVersion.minor <= 6) glMinor = apiVersion.minor;
} catch (Throwable ignored){} // In case the string is invalid/garbage
}

// Try to get values from GL30+ driver directly, only use if higher ver
try (MemoryStack stack = stackPush()) {
IntBuffer version = stack.ints(0);
callPV(GL_MAJOR_VERSION, memAddress(version), GetIntegerv);
if (callI(GetError) == GL_NO_ERROR &&
3 <= version.get(0) && version.get(0) <= 4) glMajor = version.get(0);
callPV(GL_MINOR_VERSION, memAddress(version), GetIntegerv);
if (callI(GetError) == GL_NO_ERROR &&
3 <= version.get(0) && version.get(0) <= 4) glMinor = version.get(0);
}
}
win.windowAttribs.put(GLFW_CONTEXT_VERSION_MAJOR, glMajor);
win.windowAttribs.put(GLFW_CONTEXT_VERSION_MINOR, glMinor);
Expand Down Expand Up @@ -1047,6 +1114,10 @@ public static void glfwDestroyWindow(long window) {
nglfwSetShowingWindow(mGLFWWindowMap.size() == 0 ? 0 : mGLFWWindowMap.keyAt(mGLFWWindowMap.size() - 1));
}

public static String glfwGetWindowTitle(long window) {
return internalGetWindow(window).title.toString();
}

public static void glfwDefaultWindowHints() {
mGLFWWindowVisibleOnCreation = true;
}
Expand Down
Loading