Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/build-test' into build-test
Browse files Browse the repository at this point in the history
# Conflicts:
#	README.md
#	src/main/java/pojlib/util/JREUtils.java
#	src/main/jni/Android.mk
#	src/main/jni/OpenOVR/libOCCore.a
#	src/main/jni/egl_bridge.c
#	src/main/jni/libopenxr_loader.so
#	src/main/jni/tinywrapper/main.c
#	src/main/jniLibs/arm64-v8a/libjnidispatch.so
#	src/main/jniLibs/arm64-v8a/liblwjgl.so
#	src/main/jniLibs/arm64-v8a/liblwjgl_nanovg.so
#	src/main/jniLibs/arm64-v8a/liblwjgl_opengl.so
#	src/main/jniLibs/arm64-v8a/liblwjgl_opengles.so
#	src/main/jniLibs/arm64-v8a/liblwjgl_openvr.so
#	src/main/jniLibs/arm64-v8a/liblwjgl_stb.so
#	src/main/jniLibs/arm64-v8a/liblwjgl_tinyfd.so
#	src/main/jniLibs/arm64-v8a/libopenal.so
#	src/main/jniLibs/arm64-v8a/libopuscodec.so
#	wrapper
  • Loading branch information
thewiilover committed Jun 24, 2024
2 parents d6e7e51 + 235e547 commit d486d22
Show file tree
Hide file tree
Showing 17 changed files with 169 additions and 33 deletions.
35 changes: 33 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,33 @@
# Polib-Unity
A library version of PojavLauncher made for use in Unity and other lightweight game-engines.
# Pojlib | Minecraft Launcher Core
[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
![Lines of code](https://img.shields.io/tokei/lines/github/questcraftplusplus/pojlib?style=flat)

A Minecraft: Java Edition launcher library partially made with elements from PojavLauncher.

This library was initially meant for use in QuestCraft but has turned into the perfect library for Minecraft: Java Edition launchers. This includes everything needed for a basic and (soon) even advanced MCJE launchers written in Java (or any other language with interop).

## Contributing

Contributions are always welcome!

Please ensure your code follows the language's naming conventions, here's a list of a few of the most common languages used in our projects:

- [Java's Conventions](https://www.oracle.com/java/technologies/javase/codeconventions-namingconventions.html)
- [C++'s Conventions](https://google.github.io/styleguide/cppguide.html)

Make sure your pull request describes exactly what the code does and explains why you're making the pull request!


## Credits & Third Party Components
### Developers:

* [@TheJudge156](https://github.com/thejudge156) | Senior Maintainer

* [@CADIndie](https://github.com/CADIndie) | Jr. Maintainer

* [@MrNavaStar](https://github.com/MrNavaStar) | Previous Main Feature Implementor

### Components:
- [PojavLauncher](https://github.com/PojavLauncherTeam/PojavLauncher) (Pojlib Base application): [GNU GPLv3](https://github.com/khanhduytran0/PojavLauncher/blob/master/LICENSE).

- [OpenComposite](https://gitlab.com/znixian/OpenOVR) (Used for OpenVR to OpenXR interpretation): [GNU GPLv3](https://gitlab.com/znixian/OpenOVR/-/blob/openxr/LICENSE.txt).
69 changes: 44 additions & 25 deletions src/main/java/pojlib/util/JREUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;

import pojlib.api.API_V1;
import pojlib.API;
import pojlib.util.json.MinecraftInstances;

public class JREUtils {
private JREUtils() {}
Expand Down Expand Up @@ -83,6 +85,7 @@ public static void initJavaRuntime() {
dlopen(f.getAbsolutePath());
}
dlopen(sNativeLibDir + "/libopenal.so");
dlopen(sNativeLibDir + "/libopuscodec.so");
}

public static void redirectAndPrintJRELog() {
Expand Down Expand Up @@ -130,22 +133,22 @@ public void run() {
public static void relocateLibPath(final Context ctx) {
sNativeLibDir = ctx.getApplicationInfo().nativeLibraryDir;

LD_LIBRARY_PATH = ctx.getFilesDir() + "/runtimes/JRE-17/bin" + "/lib64/jli:" + ctx.getFilesDir() + "/runtimes/JRE-17/lib:" +
LD_LIBRARY_PATH = ctx.getFilesDir() + "/runtimes/JRE-22/bin:" + ctx.getFilesDir() + "/runtimes/JRE-22/lib:" +
"/system/lib64:/vendor/lib64:/vendor/lib64/hw:" +
sNativeLibDir;
}

public static void setJavaEnvironment(Activity activity) throws Throwable {
public static void setJavaEnvironment(Activity activity, MinecraftInstances.Instance instance) throws Throwable {
Map<String, String> envMap = new ArrayMap<>();
envMap.put("POJLIB_NATIVEDIR", activity.getApplicationInfo().nativeLibraryDir);
envMap.put("JAVA_HOME", activity.getFilesDir() + "/runtimes/JRE-17");
envMap.put("HOME", Constants.MC_DIR);
envMap.put("JAVA_HOME", activity.getFilesDir() + "/runtimes/JRE-22");
envMap.put("HOME", instance.gameDir);
envMap.put("TMPDIR", activity.getCacheDir().getAbsolutePath());
envMap.put("VR_MODEL", API_V1.model);
envMap.put("VR_MODEL", API.model);
envMap.put("POJLIB_RENDERER", "regal");

envMap.put("LD_LIBRARY_PATH", LD_LIBRARY_PATH);
envMap.put("PATH", activity.getFilesDir() + "/runtimes/JRE-17/bin:" + Os.getenv("PATH"));
envMap.put("PATH", activity.getFilesDir() + "/runtimes/JRE-22/bin:" + Os.getenv("PATH"));

File customEnvFile = new File(Constants.USER_HOME, "custom_env.txt");
if (customEnvFile.exists() && customEnvFile.isFile()) {
Expand All @@ -164,45 +167,60 @@ public static void setJavaEnvironment(Activity activity) throws Throwable {
Os.setenv(env.getKey(), env.getValue(), true);
}

File serverFile = new File(activity.getFilesDir() + "/runtimes/JRE-17/lib/server/libjvm.so");
jvmLibraryPath = activity.getFilesDir() + "/runtimes/JRE-17/lib/" + (serverFile.exists() ? "server" : "client");
File serverFile = new File(activity.getFilesDir() + "/runtimes/JRE-22/lib/server/libjvm.so");
jvmLibraryPath = activity.getFilesDir() + "/runtimes/JRE-22/lib/" + (serverFile.exists() ? "server" : "client");
Log.d("DynamicLoader","Base LD_LIBRARY_PATH: "+LD_LIBRARY_PATH);
Log.d("DynamicLoader","Internal LD_LIBRARY_PATH: "+jvmLibraryPath+":"+LD_LIBRARY_PATH);
setLdLibraryPath(jvmLibraryPath+":"+LD_LIBRARY_PATH);
}

public static int launchJavaVM(final Activity activity, final List<String> JVMArgs, String versionName) throws Throwable {
public static int launchJavaVM(final Activity activity, final List<String> JVMArgs, MinecraftInstances.Instance instance) throws Throwable {
JREUtils.relocateLibPath(activity);
setJavaEnvironment(activity);
setJavaEnvironment(activity, instance);

final String graphicsLib = loadGraphicsLibrary();
List<String> userArgs = getJavaArgs(activity);
List<String> userArgs = getJavaArgs(activity, instance);

//Add automatically generated args

if (API_V1.customRAMValue) {
userArgs.add("-Xms" + API_V1.memoryValue + "M");
userArgs.add("-Xmx" + API_V1.memoryValue + "M");
if (API.customRAMValue) {
userArgs.add("-Xms" + API.memoryValue + "M");
userArgs.add("-Xmx" + API.memoryValue + "M");
} else {
userArgs.add("-Xms" + 1800 + "M");
userArgs.add("-Xmx" + 1800 + "M");
if (API.model.equals("Meta Quest Pro") || API.model.equals("Oculus Headset1")) {
userArgs.add("-Xms" + 2048 + "M");
userArgs.add("-Xmx" + 3072 + "M");
}
else if (API.model.equals("Oculus Quest")) {
userArgs.add("-Xms" + 1800 + "M");
userArgs.add("-Xmx" + 1800 + "M");
} else {
userArgs.add("-Xms" + 2048 + "M");
userArgs.add("-Xmx" + 2048 + "M");
}
}

userArgs.add("-XX:+UseZGC");
userArgs.add("-XX:+ZGenerational");
userArgs.add("-XX:+UnlockExperimentalVMOptions");
userArgs.add("-XX:+AllowUserSignalHandlers");
userArgs.add("-XX:+DisableExplicitGC");
userArgs.add("-XX:+UseCriticalJavaThreadPriority");

userArgs.add("-Dorg.lwjgl.opengl.libname=" + graphicsLib);
userArgs.add("-Dorg.lwjgl.opengles.libname=" + "/system/lib64/libGLESv3.so");
userArgs.add("-Dorg.lwjgl.egl.libname=" + "/system/lib64/libEGL_dri.so");
userArgs.add("-Dfabric.addMods=" + Constants.MC_DIR + "/mods/" + versionName);

userArgs.addAll(JVMArgs);
System.out.println(JVMArgs);

runtimeDir = activity.getFilesDir() + "/runtimes/JRE-17";
runtimeDir = activity.getFilesDir() + "/runtimes/JRE-22";

initJavaRuntime();
chdir(Constants.MC_DIR);
chdir(instance.gameDir);
userArgs.add(0,"java"); //argv[0] is the program name according to C standard.

final int exitCode = VMLauncher.launchJVM(userArgs.toArray(new String[0]));
int exitCode = VMLauncher.launchJVM(userArgs.toArray(new String[0]));
Logger.getInstance().appendToLog("Java Exit code: " + exitCode);
return exitCode;
}
Expand All @@ -213,11 +231,11 @@ public static int launchJavaVM(final Activity activity, final List<String> JVMAr
* @param ctx The application context
* @return A list filled with args.
*/
public static List<String> getJavaArgs(Context ctx) {
public static List<String> getJavaArgs(Context ctx, MinecraftInstances.Instance instance) {
return new ArrayList<>(Arrays.asList(
"-Djava.home=" + new File(ctx.getFilesDir(), "runtimes/JRE-17"),
"-Djava.home=" + new File(ctx.getFilesDir(), "runtimes/JRE-22"),
"-Djava.io.tmpdir=" + ctx.getCacheDir().getAbsolutePath(),
"-Duser.home=" + Constants.MC_DIR,
"-Duser.home=" + instance.gameDir,
"-Duser.language=" + System.getProperty("user.language"),
"-Dos.name=Linux",
"-Dos.version=Android-" + Build.VERSION.RELEASE,
Expand All @@ -229,7 +247,8 @@ public static List<String> getJavaArgs(Context ctx) {
"-Dglfwstub.windowHeight=" + 720,
"-Dglfwstub.initEgl=false",
"-Dlog4j2.formatMsgNoLookups=true", //Log4j RCE mitigation
"-Dnet.minecraft.clientmodname=" + "null"
"-Dnet.minecraft.clientmodname=" + "QuestCraft",
"-Dext.net.resolvPath=" + Constants.USER_HOME + "/hacks/ResConfHack.jar"
));
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/jni/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ LOCAL_SRC_FILES := ./OpenOVR/OCOVR.a
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_LDLIBS := -llog -landroid -lGLESv2 -lvulkan -lEGL
LOCAL_LDLIBS := -llog -landroid -lGLESv3 -lvulkan -lEGL
LOCAL_CFLAGS := -DXR_USE_PLATFORM_ANDROID -DXR_USE_GRAPHICS_API_OPENGL_ES
LOCAL_SHARED_LIBRARIES := openxr_loader
LOCAL_WHOLE_STATIC_LIBRARIES := ocovr
Expand Down
Binary file modified src/main/jni/OpenOVR/libOCCore.a
Binary file not shown.
3 changes: 2 additions & 1 deletion src/main/jni/egl_bridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -700,8 +700,9 @@ void dlsym_OSMesa() {
int pojavInit() {
savedWidth = 1;
savedHeight = 1;
printf("XREGLBridge: Thread name is %d\n", gettid());

xrEglInit();
return xrEglInit();
}

void pojavSetWindowHint(int hint, int value) {
Expand Down
Binary file modified src/main/jni/libopenxr_loader.so
Binary file not shown.
93 changes: 89 additions & 4 deletions src/main/jni/tinywrapper/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <malloc.h>

#include "GL/gl.h"
#include "GLES3/gl32.h"
#include "SPIRVCross/include/spirv_cross_c.h"
#include "shaderc/include/shaderc.h"
#include "string_utils.h"
Expand All @@ -23,9 +22,20 @@ void(*gles_glGetTexLevelParameteriv)(GLenum target, GLint level, GLenum pname, G
void(*gles_glShaderSource)(GLuint shader, GLsizei count, const GLchar * const *string, const GLint *length);
GLuint (*gles_glCreateShader) (GLenum shaderType);
void(*gles_glTexImage2D)(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *data);
void(*gles_glDrawElementsBaseVertex)(GLenum mode,
GLsizei count,
GLenum type,
void *indices,
GLint basevertex);
void (*gles_glGetBufferParameteriv) (GLenum target, GLenum pname, GLint *params);
void * (*gles_glMapBufferRange) (GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access);
const GLubyte * (*gles_glGetString) (GLenum name);
void (*gles_glTexParameterf) (GLenum target, GLenum pname, GLfloat param);

void *glMapBuffer(GLenum target, GLenum access) {
// Use: GL_EXT_map_buffer_range
LOOKUP_FUNC(glGetBufferParameteriv);
LOOKUP_FUNC(glMapBufferRange);

GLenum access_range;
GLint length;
Expand Down Expand Up @@ -63,8 +73,8 @@ void *glMapBuffer(GLenum target, GLenum access) {
break;
}

glGetBufferParameteriv(target, GL_BUFFER_SIZE, &length);
return glMapBufferRange(target, 0, length, access_range);
gles_glGetBufferParameteriv(target, GL_BUFFER_SIZE, &length);
return gles_glMapBufferRange(target, 0, length, access_range);
}

static GLenum currShaderType = GL_VERTEX_SHADER;
Expand Down Expand Up @@ -103,8 +113,8 @@ void glShaderSource(GLuint shader, GLsizei count, const GLchar * const *string,

shaderc_compile_options_t opts = shaderc_compile_options_initialize();
shaderc_compile_options_set_forced_version_profile(opts, 450, shaderc_profile_core);
shaderc_compile_options_set_auto_bind_uniforms(opts, true);
shaderc_compile_options_set_auto_map_locations(opts, true);
shaderc_compile_options_set_auto_bind_uniforms(opts, true);
shaderc_compile_options_set_target_env(opts, shaderc_target_env_opengl, shaderc_env_version_opengl_4_5);

shaderc_compilation_result_t outSPIRVRes = shaderc_compile_into_spv(compiler, *string,
Expand Down Expand Up @@ -184,8 +194,52 @@ void glGetTexLevelParameteriv(GLenum target, GLint level, GLenum pname, GLint *p
}
}

void glTexParameterf(GLenum target, GLenum pname, GLfloat param) {
LOOKUP_FUNC(glTexParameterf);

// Not supported, crashes some mods that check
// for OpenGL errors
if(pname == GL_TEXTURE_LOD_BIAS_EXT) {
return;
}

gles_glTexParameterf(target, pname, param);
}

void glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *data) {
LOOKUP_FUNC(glTexImage2D)

// Regal doesn't handle depth formats well
// Convert it to sized GLES formats instead
if(internalformat == GL_DEPTH_COMPONENT) {
switch (type) {
case GL_UNSIGNED_SHORT:
internalformat = GL_DEPTH_COMPONENT16;
break;
case GL_UNSIGNED_INT:
internalformat = GL_DEPTH_COMPONENT24;
break;
case GL_FLOAT:
internalformat = GL_DEPTH_COMPONENT32F;
break;
default:
printf("Depth texture type %d failed for depth component!\n", type);
break;
}
} else if(internalformat == GL_DEPTH_STENCIL) {
switch (type) {
case GL_UNSIGNED_INT:
internalformat = GL_DEPTH24_STENCIL8;
break;
case GL_FLOAT:
internalformat = GL_DEPTH32F_STENCIL8;
break;
default:
printf("Depth texture type %d failed for depth stencil!\n", type);
break;
}
}

if (isProxyTexture(target)) {
if (!maxTextureSize) {
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize);
Expand All @@ -200,3 +254,34 @@ void glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei widt
gles_glTexImage2D(target, level, internalformat, width, height, border, format, type, data);
}
}

// Sodium
void glMultiDrawElementsBaseVertex( GLenum mode,
const GLsizei *count,
GLenum type,
const void * const *indices,
GLsizei drawcount,
const GLint *basevertex) {
LOOKUP_FUNC(glDrawElementsBaseVertex);
for (int i = 0; i < drawcount; i++) {
if (count[i] > 0)
gles_glDrawElementsBaseVertex(mode,
count[i],
type,
indices[i],
basevertex[i]);
}
}

const GLubyte * glGetString(GLenum name) {
LOOKUP_FUNC(glGetString);

switch (name) {
case GL_VERSION:
return "4.6";
case GL_SHADING_LANGUAGE_VERSION:
return "4.5";
default:
return gles_glGetString(name);
}
}
Binary file modified src/main/jniLibs/arm64-v8a/libjnidispatch.so
Binary file not shown.
Binary file modified src/main/jniLibs/arm64-v8a/liblwjgl.so
Binary file not shown.
Binary file modified src/main/jniLibs/arm64-v8a/liblwjgl_nanovg.so
Binary file not shown.
Binary file modified src/main/jniLibs/arm64-v8a/liblwjgl_opengl.so
Binary file not shown.
Binary file modified src/main/jniLibs/arm64-v8a/liblwjgl_opengles.so
Binary file not shown.
Binary file modified src/main/jniLibs/arm64-v8a/liblwjgl_openvr.so
Binary file not shown.
Binary file modified src/main/jniLibs/arm64-v8a/liblwjgl_stb.so
Binary file not shown.
Binary file modified src/main/jniLibs/arm64-v8a/liblwjgl_tinyfd.so
Binary file not shown.
Binary file modified src/main/jniLibs/arm64-v8a/libopenal.so
Binary file not shown.
Binary file modified src/main/jniLibs/arm64-v8a/libopuscodec.so
Binary file not shown.

0 comments on commit d486d22

Please sign in to comment.