Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
163cc8e687 | ||
|
|
5b99165160 |
No files matched your search
+8
-1
@@ -21,7 +21,14 @@ public class ModpackInstaller {
|
||||
public static ModLoader installModpack(ModDetail modDetail, int selectedVersion, InstallFunction installFunction) throws IOException {
|
||||
String versionUrl = modDetail.versionUrls[selectedVersion];
|
||||
String versionHash = modDetail.versionHashes[selectedVersion];
|
||||
String modpackName = modDetail.title.toLowerCase(Locale.ROOT).trim().replace(" ", "_" );
|
||||
String modpackName = (modDetail.title.toLowerCase(Locale.ROOT) + " " + modDetail.versionNames[selectedVersion])
|
||||
.trim().replaceAll("[\\\\/:*?\"<>| \\t\\n]", "_" );
|
||||
if (versionHash != null) {
|
||||
modpackName += "_" + versionHash;
|
||||
}
|
||||
if (modpackName.length() > 255){
|
||||
modpackName = modpackName.substring(0,255);
|
||||
}
|
||||
|
||||
// Build a new minecraft instance, folder first
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import android.opengl.EGL14;
|
||||
import android.opengl.EGLConfig;
|
||||
import android.opengl.EGLContext;
|
||||
import android.opengl.EGLDisplay;
|
||||
import android.opengl.EGLSurface;
|
||||
import android.opengl.GLES20;
|
||||
import android.opengl.GLES30;
|
||||
import android.util.Log;
|
||||
@@ -46,13 +47,27 @@ public class GLInfoUtils {
|
||||
private static EGLContext tryCreateContext(EGLDisplay eglDisplay, EGLConfig config, int majorVersion) {
|
||||
int[] egl_context_attributes = new int[] { EGL14.EGL_CONTEXT_CLIENT_VERSION, majorVersion, EGL14.EGL_NONE };
|
||||
EGLContext context = EGL14.eglCreateContext(eglDisplay, config, EGL14.EGL_NO_CONTEXT, egl_context_attributes, 0);
|
||||
if(context == EGL14.EGL_NO_CONTEXT) {
|
||||
if(context == EGL14.EGL_NO_CONTEXT || context == null) {
|
||||
Log.e("GLInfoUtils", "Failed to create a context with major version "+majorVersion);
|
||||
return null;
|
||||
}
|
||||
return context;
|
||||
}
|
||||
|
||||
private static EGLContext tryMakeCurrent(EGLDisplay eglDisplay, EGLConfig config, EGLSurface surface, int majorVersion) {
|
||||
EGLContext context = tryCreateContext(eglDisplay, config, majorVersion);
|
||||
if(context == null) return null;
|
||||
// Old Mali drivers are broken, and will actually let us create a context with GLES 3
|
||||
// But won't let us make it current, which will break the check anyway...
|
||||
boolean makeCurrentResult = EGL14.eglMakeCurrent(eglDisplay, surface, surface, context);
|
||||
if(!makeCurrentResult) {
|
||||
Log.i("GLInfoUtils", "Failed to make context GL version "+majorVersion +" current");
|
||||
EGL14.eglDestroyContext(eglDisplay, context);
|
||||
return null;
|
||||
}
|
||||
return context;
|
||||
}
|
||||
|
||||
private static boolean initAndQueryInfo() {
|
||||
// This is here just to satisfy Android M which incorrectly null-checks it
|
||||
int[] egl_version = new int[2];
|
||||
@@ -64,7 +79,7 @@ public class GLInfoUtils {
|
||||
EGL14.EGL_RED_SIZE, 8,
|
||||
EGL14.EGL_ALPHA_SIZE, 8,
|
||||
EGL14.EGL_DEPTH_SIZE, 24,
|
||||
EGL14.EGL_SURFACE_TYPE, EGL14.EGL_PBUFFER_BIT|EGL14.EGL_WINDOW_BIT,
|
||||
EGL14.EGL_SURFACE_TYPE, EGL14.EGL_PBUFFER_BIT,
|
||||
EGL14.EGL_RENDERABLE_TYPE, EGL14.EGL_OPENGL_ES2_BIT,
|
||||
EGL14.EGL_NONE
|
||||
};
|
||||
@@ -76,19 +91,33 @@ public class GLInfoUtils {
|
||||
return false;
|
||||
}
|
||||
|
||||
int contextGLVersion = 3;
|
||||
// Create PBuffer surface as some devices might actually not support surfaceless.
|
||||
int[] pbuffer_attributes = new int[] {
|
||||
EGL14.EGL_WIDTH, 16,
|
||||
EGL14.EGL_HEIGHT, 16,
|
||||
EGL14.EGL_NONE
|
||||
};
|
||||
|
||||
EGLContext context;
|
||||
context = tryCreateContext(eglDisplay, config[0], 3);
|
||||
if(context == null) {
|
||||
contextGLVersion = 2;
|
||||
context = tryCreateContext(eglDisplay, config[0], 2);
|
||||
EGLSurface surface = EGL14.eglCreatePbufferSurface(eglDisplay, config[0], pbuffer_attributes, 0);
|
||||
if(surface == null || surface == EGL14.EGL_NO_SURFACE) {
|
||||
Log.e("GLInfoUtils", "Failed to create pbuffer surface");
|
||||
EGL14.eglTerminate(eglDisplay);
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!EGL14.eglMakeCurrent(eglDisplay, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_SURFACE, context)) {
|
||||
Log.e("GLInfoUtils", "Failed to make context current");
|
||||
EGL14.eglDestroyContext(eglDisplay, context);
|
||||
int contextGLVersion = 3;
|
||||
EGLContext context = tryMakeCurrent(eglDisplay, config[0], surface, contextGLVersion);
|
||||
if(context == null) {
|
||||
contextGLVersion = 2;
|
||||
context = tryMakeCurrent(eglDisplay, config[0], surface, contextGLVersion);
|
||||
}
|
||||
|
||||
// Creation/currenting failed in both cases
|
||||
if(context == null) {
|
||||
Log.e("GLInfoUtils", "Failed to create and make context current");
|
||||
EGL14.eglDestroySurface(eglDisplay, surface);
|
||||
EGL14.eglTerminate(eglDisplay);
|
||||
return false;
|
||||
}
|
||||
|
||||
info = queryInfo(contextGLVersion);
|
||||
|
||||
@@ -104,8 +104,7 @@ public class JREUtils {
|
||||
public void run() {
|
||||
try {
|
||||
if (logcatPb == null) {
|
||||
// No filtering by tag anymore as that relied on incorrect log levels set in log.h
|
||||
logcatPb = new ProcessBuilder().command("logcat", /* "-G", "1mb", */ "-v", "brief", "-s", "jrelog", "LIBGL", "NativeInput").redirectErrorStream(true);
|
||||
logcatPb = new ProcessBuilder().command("logcat", /* "-G", "1mb", */ "-v", "brief", "-s", "jrelog:I", "LIBGL:I", "NativeInput").redirectErrorStream(true);
|
||||
}
|
||||
|
||||
Log.i("jrelog-logcat","Clearing logcat");
|
||||
@@ -317,7 +316,7 @@ public class JREUtils {
|
||||
|
||||
initJavaRuntime(runtimeHome);
|
||||
JREUtils.setupExitMethod(activity.getApplication());
|
||||
JREUtils.initializeHooks();
|
||||
JREUtils.initializeGameExitHook();
|
||||
chdir(gameDirectory == null ? Tools.DIR_GAME_NEW : gameDirectory.getAbsolutePath());
|
||||
userArgs.add(0,"java"); //argv[0] is the program name according to C standard.
|
||||
|
||||
@@ -520,7 +519,7 @@ public class JREUtils {
|
||||
public static native void setLdLibraryPath(String ldLibraryPath);
|
||||
public static native void setupBridgeWindow(Object surface);
|
||||
public static native void releaseBridgeWindow();
|
||||
public static native void initializeHooks();
|
||||
public static native void initializeGameExitHook();
|
||||
public static native void setupExitMethod(Context context);
|
||||
// Obtain AWT screen pixels to render on Android SurfaceView
|
||||
public static native int[] renderAWTScreenFrame(/* Object canvas, int width, int height */);
|
||||
|
||||
@@ -28,13 +28,12 @@ LOCAL_SRC_FILES := \
|
||||
ctxbridges/osmesa_loader.c \
|
||||
ctxbridges/swap_interval_no_egl.c \
|
||||
environ/environ.c \
|
||||
jvm_hooks/emui_iterator_fix_hook.c \
|
||||
jvm_hooks/java_exec_hooks.c \
|
||||
jvm_hooks/lwjgl_dlopen_hook.c \
|
||||
input_bridge_v3.c \
|
||||
jre_launcher.c \
|
||||
utils.c \
|
||||
stdio_is.c \
|
||||
java_exec_hooks.c \
|
||||
lwjgl_dlopen_hook.c \
|
||||
driver_helper/nsbypass.c
|
||||
|
||||
ifeq ($(TARGET_ARCH_ABI),arm64-v8a)
|
||||
@@ -46,9 +45,7 @@ include $(CLEAR_VARS)
|
||||
LOCAL_MODULE := exithook
|
||||
LOCAL_LDLIBS := -ldl -llog
|
||||
LOCAL_SHARED_LIBRARIES := bytehook pojavexec
|
||||
LOCAL_SRC_FILES := \
|
||||
native_hooks/exit_hook.c \
|
||||
native_hooks/chmod_hook.c
|
||||
LOCAL_SRC_FILES := exit_hook.c
|
||||
include $(BUILD_SHARED_LIBRARY)
|
||||
|
||||
#ifeq ($(TARGET_ARCH_ABI),arm64-v8a)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include <EGL/egl.h>
|
||||
#include <android/log.h>
|
||||
#include <android/native_window.h>
|
||||
#include <android/native_window_jni.h>
|
||||
#include <string.h>
|
||||
@@ -10,13 +11,11 @@
|
||||
#include "gl_bridge.h"
|
||||
#include "egl_loader.h"
|
||||
|
||||
#define TAG __FILE_NAME__
|
||||
#include <log.h>
|
||||
|
||||
//
|
||||
// Created by maks on 17.09.2022.
|
||||
//
|
||||
|
||||
static const char* g_LogTag = "GLBridge";
|
||||
static __thread gl_render_window_t* currentBundle;
|
||||
static EGLDisplay g_EglDisplay;
|
||||
|
||||
@@ -24,11 +23,13 @@ bool gl_init() {
|
||||
if(!dlsym_EGL()) return false;
|
||||
g_EglDisplay = eglGetDisplay_p(EGL_DEFAULT_DISPLAY);
|
||||
if (g_EglDisplay == EGL_NO_DISPLAY) {
|
||||
LOGE("%s", "eglGetDisplay_p(EGL_DEFAULT_DISPLAY) returned EGL_NO_DISPLAY");
|
||||
__android_log_print(ANDROID_LOG_ERROR, g_LogTag, "%s",
|
||||
"eglGetDisplay_p(EGL_DEFAULT_DISPLAY) returned EGL_NO_DISPLAY");
|
||||
return false;
|
||||
}
|
||||
if (eglInitialize_p(g_EglDisplay, 0, 0) != EGL_TRUE) {
|
||||
LOGE("eglInitialize_p() failed: %04x", eglGetError_p());
|
||||
__android_log_print(ANDROID_LOG_ERROR, g_LogTag, "eglInitialize_p() failed: %04x",
|
||||
eglGetError_p());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -61,12 +62,14 @@ gl_render_window_t* gl_init_context(gl_render_window_t *share) {
|
||||
EGLint num_configs = 0;
|
||||
|
||||
if (eglChooseConfig_p(g_EglDisplay, egl_attributes, NULL, 0, &num_configs) != EGL_TRUE) {
|
||||
LOGE("eglChooseConfig_p() failed: %04x", eglGetError_p());
|
||||
__android_log_print(ANDROID_LOG_ERROR, g_LogTag, "eglChooseConfig_p() failed: %04x",
|
||||
eglGetError_p());
|
||||
free(bundle);
|
||||
return NULL;
|
||||
}
|
||||
if (num_configs == 0) {
|
||||
LOGE("%s", "eglChooseConfig_p() found no matching config");
|
||||
__android_log_print(ANDROID_LOG_ERROR, g_LogTag, "%s",
|
||||
"eglChooseConfig_p() found no matching config");
|
||||
free(bundle);
|
||||
return NULL;
|
||||
}
|
||||
@@ -93,7 +96,8 @@ gl_render_window_t* gl_init_context(gl_render_window_t *share) {
|
||||
bundle->context = eglCreateContext_p(g_EglDisplay, bundle->config, share == NULL ? EGL_NO_CONTEXT : share->context, egl_context_attributes);
|
||||
|
||||
if (bundle->context == EGL_NO_CONTEXT) {
|
||||
LOGE("eglCreateContext_p() finished with error: %04x", eglGetError_p());
|
||||
__android_log_print(ANDROID_LOG_ERROR, g_LogTag, "eglCreateContext_p() finished with error: %04x",
|
||||
eglGetError_p());
|
||||
free(bundle);
|
||||
return NULL;
|
||||
}
|
||||
@@ -106,14 +110,14 @@ void gl_swap_surface(gl_render_window_t* bundle) {
|
||||
}
|
||||
if(bundle->surface != NULL) eglDestroySurface_p(g_EglDisplay, bundle->surface);
|
||||
if(bundle->newNativeSurface != NULL) {
|
||||
LOGI("Switching to new native surface");
|
||||
__android_log_print(ANDROID_LOG_ERROR, g_LogTag, "Switching to new native surface");
|
||||
bundle->nativeSurface = bundle->newNativeSurface;
|
||||
bundle->newNativeSurface = NULL;
|
||||
ANativeWindow_acquire(bundle->nativeSurface);
|
||||
ANativeWindow_setBuffersGeometry(bundle->nativeSurface, 0, 0, bundle->format);
|
||||
bundle->surface = eglCreateWindowSurface_p(g_EglDisplay, bundle->config, bundle->nativeSurface, NULL);
|
||||
}else{
|
||||
LOGI("No new native surface, switching to 1x1 pbuffer");
|
||||
__android_log_print(ANDROID_LOG_ERROR, g_LogTag, "No new native surface, switching to 1x1 pbuffer");
|
||||
bundle->nativeSurface = NULL;
|
||||
const EGLint pbuffer_attrs[] = {EGL_WIDTH, 1 , EGL_HEIGHT, 1, EGL_NONE};
|
||||
bundle->surface = eglCreatePbufferSurface_p(g_EglDisplay, bundle->config, pbuffer_attrs);
|
||||
@@ -132,11 +136,11 @@ void gl_make_current(gl_render_window_t* bundle) {
|
||||
bool hasSetMainWindow = false;
|
||||
if(pojav_environ->mainWindowBundle == NULL) {
|
||||
pojav_environ->mainWindowBundle = (basic_render_window_t*)bundle;
|
||||
LOGI("Main window bundle is now %p", pojav_environ->mainWindowBundle);
|
||||
__android_log_print(ANDROID_LOG_INFO, g_LogTag, "Main window bundle is now %p", pojav_environ->mainWindowBundle);
|
||||
pojav_environ->mainWindowBundle->newNativeSurface = pojav_environ->pojavWindow;
|
||||
hasSetMainWindow = true;
|
||||
}
|
||||
LOGI("Making current, surface=%p, nativeSurface=%p, newNativeSurface=%p", bundle->surface, bundle->nativeSurface, bundle->newNativeSurface);
|
||||
__android_log_print(ANDROID_LOG_INFO, g_LogTag, "Making current, surface=%p, nativeSurface=%p, newNativeSurface=%p", bundle->surface, bundle->nativeSurface, bundle->newNativeSurface);
|
||||
if(bundle->surface == NULL) { //it likely will be on the first run
|
||||
gl_swap_surface(bundle);
|
||||
}
|
||||
@@ -148,7 +152,7 @@ void gl_make_current(gl_render_window_t* bundle) {
|
||||
gl_swap_surface((gl_render_window_t*)pojav_environ->mainWindowBundle);
|
||||
pojav_environ->mainWindowBundle = NULL;
|
||||
}
|
||||
LOGE("eglMakeCurrent returned with error: %04x", eglGetError_p());
|
||||
__android_log_print(ANDROID_LOG_ERROR, g_LogTag, "eglMakeCurrent returned with error: %04x", eglGetError_p());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -166,14 +170,14 @@ void gl_swap_buffers() {
|
||||
currentBundle->newNativeSurface = NULL;
|
||||
gl_swap_surface(currentBundle);
|
||||
eglMakeCurrent_p(g_EglDisplay, currentBundle->surface, currentBundle->surface, currentBundle->context);
|
||||
LOGI("The window has died, awaiting window change");
|
||||
__android_log_print(ANDROID_LOG_INFO, g_LogTag, "The window has died, awaiting window change");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void gl_setup_window() {
|
||||
if(pojav_environ->mainWindowBundle != NULL) {
|
||||
LOGI("Main window bundle is not NULL, changing state");
|
||||
__android_log_print(ANDROID_LOG_INFO, g_LogTag, "Main window bundle is not NULL, changing state");
|
||||
pojav_environ->mainWindowBundle->state = STATE_RENDERER_NEW_WINDOW;
|
||||
pojav_environ->mainWindowBundle->newNativeSurface = pojav_environ->pojavWindow;
|
||||
}
|
||||
@@ -188,14 +192,14 @@ void gl_swap_interval(int swapInterval) {
|
||||
JNIEXPORT void JNICALL
|
||||
Java_org_lwjgl_opengl_PojavRendererInit_nativeInitGl4esInternals(JNIEnv *env, jclass clazz,
|
||||
jobject function_provider) {
|
||||
LOGI("GL4ES internals initializing...");
|
||||
__android_log_print(ANDROID_LOG_INFO, g_LogTag, "GL4ES internals initializing...");
|
||||
jclass funcProviderClass = (*env)->GetObjectClass(env, function_provider);
|
||||
jmethodID method_getFunctionAddress = (*env)->GetMethodID(env, funcProviderClass, "getFunctionAddress", "(Ljava/lang/CharSequence;)J");
|
||||
#define GETSYM(N) ((*env)->CallLongMethod(env, function_provider, method_getFunctionAddress, (*env)->NewStringUTF(env, N)));
|
||||
|
||||
void (*set_getmainfbsize)(void (*new_getMainFBSize)(int* width, int* height)) = (void*)GETSYM("set_getmainfbsize");
|
||||
if(set_getmainfbsize != NULL) {
|
||||
LOGI("GL4ES internals initialized dimension callback");
|
||||
__android_log_print(ANDROID_LOG_INFO, g_LogTag, "GL4ES internals initialized dimension callback");
|
||||
set_getmainfbsize(gl4esi_get_display_dimensions);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,10 +4,10 @@
|
||||
#include <malloc.h>
|
||||
#include <string.h>
|
||||
#include <environ/environ.h>
|
||||
#include <android/log.h>
|
||||
#include "osm_bridge.h"
|
||||
#define TAG __FILE_NAME__
|
||||
#include <log.h>
|
||||
|
||||
static const char* g_LogTag = "GLBridge";
|
||||
static __thread osm_render_window_t* currentBundle;
|
||||
// a tiny buffer for rendering when there's nowhere t render
|
||||
static char no_render_buffer[4];
|
||||
@@ -49,13 +49,13 @@ void osm_set_no_render_buffer(ANativeWindow_Buffer* buffer) {
|
||||
void osm_swap_surfaces(osm_render_window_t* bundle) {
|
||||
if(bundle->nativeSurface != NULL && bundle->newNativeSurface != bundle->nativeSurface) {
|
||||
if(!bundle->disable_rendering) {
|
||||
LOGI("Unlocking for cleanup...");
|
||||
__android_log_print(ANDROID_LOG_INFO, g_LogTag, "Unlocking for cleanup...");
|
||||
ANativeWindow_unlockAndPost(bundle->nativeSurface);
|
||||
}
|
||||
ANativeWindow_release(bundle->nativeSurface);
|
||||
}
|
||||
if(bundle->newNativeSurface != NULL) {
|
||||
LOGI("Switching to new native surface");
|
||||
__android_log_print(ANDROID_LOG_ERROR, g_LogTag, "Switching to new native surface");
|
||||
bundle->nativeSurface = bundle->newNativeSurface;
|
||||
bundle->newNativeSurface = NULL;
|
||||
ANativeWindow_acquire(bundle->nativeSurface);
|
||||
@@ -63,7 +63,8 @@ void osm_swap_surfaces(osm_render_window_t* bundle) {
|
||||
bundle->disable_rendering = false;
|
||||
return;
|
||||
}else {
|
||||
LOGI("No new native surface, switching to dummy framebuffer");
|
||||
__android_log_print(ANDROID_LOG_ERROR, g_LogTag,
|
||||
"No new native surface, switching to dummy framebuffer");
|
||||
bundle->nativeSurface = NULL;
|
||||
osm_set_no_render_buffer(&bundle->buffer);
|
||||
bundle->disable_rendering = true;
|
||||
@@ -95,7 +96,7 @@ void osm_make_current(osm_render_window_t* bundle) {
|
||||
currentBundle = bundle;
|
||||
if(pojav_environ->mainWindowBundle == NULL) {
|
||||
pojav_environ->mainWindowBundle = (basic_render_window_t*) bundle;
|
||||
LOGI("Main window bundle is now %p", pojav_environ->mainWindowBundle);
|
||||
__android_log_print(ANDROID_LOG_INFO, g_LogTag, "Main window bundle is now %p", pojav_environ->mainWindowBundle);
|
||||
pojav_environ->mainWindowBundle->newNativeSurface = pojav_environ->pojavWindow;
|
||||
hasSetMainWindow = true;
|
||||
}
|
||||
@@ -129,7 +130,7 @@ void osm_swap_buffers() {
|
||||
|
||||
void osm_setup_window() {
|
||||
if(pojav_environ->mainWindowBundle != NULL) {
|
||||
LOGI("Main window bundle is not NULL, changing state");
|
||||
__android_log_print(ANDROID_LOG_INFO, g_LogTag, "Main window bundle is not NULL, changing state");
|
||||
pojav_environ->mainWindowBundle->state = STATE_RENDERER_NEW_WINDOW;
|
||||
pojav_environ->mainWindowBundle->newNativeSurface = pojav_environ->pojavWindow;
|
||||
}
|
||||
|
||||
@@ -5,11 +5,9 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <android/log.h>
|
||||
#include <android/native_window.h>
|
||||
|
||||
#define TAG __FILE_NAME__
|
||||
#include <log.h>
|
||||
|
||||
// Taken from https://android.googlesource.com/platform/frameworks/native/+/41abd67/include/ui/egl/android_natives.h
|
||||
// Might be outdated, if you can find a more recent version please add it there
|
||||
// region android_native_base_t definition
|
||||
@@ -229,17 +227,17 @@ void setNativeWindowSwapInterval(struct ANativeWindow* nativeWindow, int swapInt
|
||||
}
|
||||
struct ANativeWindow_real* nativeWindowReal = (struct ANativeWindow_real*) nativeWindow;
|
||||
if(nativeWindowReal->common.magic != ANDROID_NATIVE_WINDOW_MAGIC) {
|
||||
LOGW("ANativeWindow magic does not match. Expected %i, got %i",
|
||||
__android_log_print(ANDROID_LOG_WARN, "SwapIntervalNoEGL", "ANativeWindow magic does not match. Expected %i, got %i",
|
||||
ANDROID_NATIVE_WINDOW_MAGIC, nativeWindowReal->common.magic);
|
||||
return;
|
||||
}
|
||||
if(nativeWindowReal->common.version != sizeof(struct ANativeWindow_real)) {
|
||||
LOGW("ANativeWindow version does not match. Expected %i, got %i",
|
||||
__android_log_print(ANDROID_LOG_WARN, "SwapIntervalNoEGL", "ANativeWindow version does not match. Expected %i, got %i",
|
||||
sizeof(struct ANativeWindow_real), nativeWindowReal->common.version);
|
||||
return;
|
||||
}
|
||||
int error;
|
||||
if((error = nativeWindowReal->setSwapInterval(nativeWindow, swapInterval)) != 0) {
|
||||
LOGW("Failed to set swap interval: %s", strerror(-error));
|
||||
__android_log_print(ANDROID_LOG_WARN, "SwapIntervalNoEGL", "Failed to set swap interval: %s", strerror(-error));
|
||||
}
|
||||
}
|
||||
@@ -82,6 +82,7 @@ bool linker_ns_load(const char* lib_search_path) {
|
||||
// load the two functions we need
|
||||
android_create_namespace = dlsym(ld_android_handle, "__loader_android_create_namespace");
|
||||
ld_android_link_namespaces_t android_link_namespaces = dlsym(ld_android_handle, "__loader_android_link_namespaces");
|
||||
__android_log_print(ANDROID_LOG_INFO, "nsbypass", "found functions at %p %p", android_create_namespace, android_link_namespaces);
|
||||
if(android_create_namespace == NULL || android_link_namespaces == NULL) {
|
||||
dlclose(ld_android_handle);
|
||||
return false;
|
||||
|
||||
@@ -7,14 +7,11 @@
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include "environ.h"
|
||||
#define TAG __FILE_NAME__
|
||||
#include <log.h>
|
||||
|
||||
struct pojav_environ_s *pojav_environ;
|
||||
__attribute__((constructor)) void env_init() {
|
||||
char* strptr_env = getenv("POJAV_ENVIRON");
|
||||
if(strptr_env == NULL) {
|
||||
LOGI("No environ found, creating...");
|
||||
__android_log_print(ANDROID_LOG_INFO, "Environ", "No environ found, creating...");
|
||||
pojav_environ = malloc(sizeof(struct pojav_environ_s));
|
||||
assert(pojav_environ);
|
||||
memset(pojav_environ, 0 , sizeof(struct pojav_environ_s));
|
||||
@@ -22,8 +19,8 @@ __attribute__((constructor)) void env_init() {
|
||||
setenv("POJAV_ENVIRON", strptr_env, 1);
|
||||
free(strptr_env);
|
||||
}else{
|
||||
LOGI("Found existing environ: %s", strptr_env);
|
||||
__android_log_print(ANDROID_LOG_INFO, "Environ", "Found existing environ: %s", strptr_env);
|
||||
pojav_environ = (void*) strtoul(strptr_env, NULL, 0x10);
|
||||
}
|
||||
LOGI("%p", pojav_environ);
|
||||
__android_log_print(ANDROID_LOG_INFO, "Environ", "%p", pojav_environ);
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
//
|
||||
// Created by maks on 15.01.2025.
|
||||
//
|
||||
|
||||
#include <jni.h>
|
||||
#include <unistd.h>
|
||||
#include <stdbool.h>
|
||||
#include <bytehook.h>
|
||||
#include <dlfcn.h>
|
||||
#include <android/log.h>
|
||||
#include <stdlib.h>
|
||||
#include "stdio_is.h"
|
||||
|
||||
static _Atomic bool exit_tripped = false;
|
||||
|
||||
typedef void (*exit_func)(int);
|
||||
|
||||
static void custom_exit(int code) {
|
||||
// If the exit was already done (meaning it is recursive or from a different thread), pass the call through
|
||||
if(exit_tripped) {
|
||||
BYTEHOOK_CALL_PREV(custom_exit, exit_func, code);
|
||||
BYTEHOOK_POP_STACK();
|
||||
return;
|
||||
}
|
||||
exit_tripped = true;
|
||||
// Perform a nominal exit, as we expect.
|
||||
nominal_exit(code, false);
|
||||
BYTEHOOK_POP_STACK();
|
||||
}
|
||||
|
||||
static void custom_atexit() {
|
||||
// Same as custom_exit, but without the code or the exit passthrough.
|
||||
if(exit_tripped) {
|
||||
return;
|
||||
}
|
||||
exit_tripped = true;
|
||||
nominal_exit(0, false);
|
||||
}
|
||||
|
||||
static bool init_exit_hook() {
|
||||
void* bytehook_handle = dlopen("libbytehook.so", RTLD_NOW);
|
||||
if(bytehook_handle == NULL) {
|
||||
goto dlerror;
|
||||
}
|
||||
|
||||
bytehook_stub_t (*bytehook_hook_all_p)(const char *callee_path_name, const char *sym_name, void *new_func,
|
||||
bytehook_hooked_t hooked, void *hooked_arg);
|
||||
int (*bytehook_init_p)(int mode, bool debug);
|
||||
|
||||
bytehook_hook_all_p = dlsym(bytehook_handle, "bytehook_hook_all");
|
||||
bytehook_init_p = dlsym(bytehook_handle, "bytehook_init");
|
||||
|
||||
if(bytehook_hook_all_p == NULL || bytehook_init_p == NULL) {
|
||||
goto dlerror;
|
||||
}
|
||||
int bhook_status = bytehook_init_p(BYTEHOOK_MODE_AUTOMATIC, false);
|
||||
if(bhook_status == BYTEHOOK_STATUS_CODE_OK) {
|
||||
bytehook_stub_t stub = bytehook_hook_all_p(NULL, "exit", &custom_exit, NULL, NULL);
|
||||
__android_log_print(ANDROID_LOG_INFO, "exit_hook", "Successfully initialized exit hook, stub=%p", stub);
|
||||
return true;
|
||||
} else {
|
||||
__android_log_print(ANDROID_LOG_INFO, "exit_hook", "bytehook_init failed (%i)", bhook_status);
|
||||
dlclose(bytehook_handle);
|
||||
return false;
|
||||
}
|
||||
|
||||
dlerror:
|
||||
if(bytehook_handle != NULL) dlclose(bytehook_handle);
|
||||
__android_log_print(ANDROID_LOG_ERROR, "exit_hook", "Failed to load hook library: %s", dlerror());
|
||||
return false;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_net_kdt_pojavlaunch_utils_JREUtils_initializeGameExitHook(JNIEnv *env, jclass clazz) {
|
||||
bool hookReady = init_exit_hook();
|
||||
if(!hookReady){
|
||||
// If we can't hook, register atexit(). This won't report a proper error code,
|
||||
// but it will prevent a SIGSEGV or a SIGABRT from the depths of Dalvik that happens
|
||||
// on exit().
|
||||
atexit(custom_atexit);
|
||||
}
|
||||
}
|
||||
@@ -19,11 +19,9 @@
|
||||
#include <stdatomic.h>
|
||||
#include <math.h>
|
||||
|
||||
#define TAG __FILE_NAME__
|
||||
#include "log.h"
|
||||
#include "utils.h"
|
||||
#include "environ/environ.h"
|
||||
#include "jvm_hooks/jvm_hooks.h"
|
||||
|
||||
#define EVENT_TYPE_CHAR 1000
|
||||
#define EVENT_TYPE_CHAR_MODS 1001
|
||||
@@ -32,11 +30,12 @@
|
||||
#define EVENT_TYPE_MOUSE_BUTTON 1006
|
||||
#define EVENT_TYPE_SCROLL 1007
|
||||
|
||||
static void installEMUIIteratorMititgation(JNIEnv *vmEnv);
|
||||
static void registerFunctions(JNIEnv *env);
|
||||
|
||||
jint JNI_OnLoad(JavaVM* vm, __attribute__((unused)) void* reserved) {
|
||||
if (pojav_environ->dalvikJavaVMPtr == NULL) {
|
||||
LOGI("Saving DVM environ...");
|
||||
__android_log_print(ANDROID_LOG_INFO, "Native", "Saving DVM environ...");
|
||||
//Save dalvik global JavaVM pointer
|
||||
pojav_environ->dalvikJavaVMPtr = vm;
|
||||
JNIEnv *dvEnv;
|
||||
@@ -46,7 +45,7 @@ jint JNI_OnLoad(JavaVM* vm, __attribute__((unused)) void* reserved) {
|
||||
pojav_environ->method_onGrabStateChanged = (*dvEnv)->GetStaticMethodID(dvEnv, pojav_environ->bridgeClazz, "onGrabStateChanged", "(Z)V");
|
||||
pojav_environ->isUseStackQueueCall = JNI_FALSE;
|
||||
} else if (pojav_environ->dalvikJavaVMPtr != vm) {
|
||||
LOGI("Saving JVM environ...");
|
||||
__android_log_print(ANDROID_LOG_INFO, "Native", "Saving JVM environ...");
|
||||
pojav_environ->runtimeJavaVMPtr = vm;
|
||||
JNIEnv *vmEnv;
|
||||
(*vm)->GetEnv(vm, (void**) &vmEnv, JNI_VERSION_1_4);
|
||||
@@ -232,6 +231,42 @@ void sendData(int type, int i1, int i2, int i3, int i4) {
|
||||
atomic_fetch_add_explicit(&pojav_environ->eventCounter, 1, memory_order_acquire);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is meant as a substitute for SharedLibraryUtil.getLibraryPath() that just returns 0
|
||||
* (thus making the parent Java function return null). This is done to avoid using the LWJGL's default function,
|
||||
* which will hang the crappy EMUI linker by dlopen()ing inside of dl_iterate_phdr().
|
||||
* @return 0, to make the parent Java function return null immediately.
|
||||
* For reference: https://github.com/PojavLauncherTeam/lwjgl3/blob/fix_huawei_hang/modules/lwjgl/core/src/main/java/org/lwjgl/system/SharedLibraryUtil.java
|
||||
*/
|
||||
jint getLibraryPath_fix(__attribute__((unused)) JNIEnv *env,
|
||||
__attribute__((unused)) jclass class,
|
||||
__attribute__((unused)) jlong pLibAddress,
|
||||
__attribute__((unused)) jlong sOutAddress,
|
||||
__attribute__((unused)) jint bufSize){
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Install the linker hang mitigation that is meant to prevent linker hangs on old EMUI firmware.
|
||||
*/
|
||||
static void installEMUIIteratorMititgation(JNIEnv *env) {
|
||||
if(getenv("POJAV_EMUI_ITERATOR_MITIGATE") == NULL) return;
|
||||
__android_log_print(ANDROID_LOG_INFO, "EMUIIteratorFix", "Installing...");
|
||||
jclass sharedLibraryUtil = (*env)->FindClass(env, "org/lwjgl/system/SharedLibraryUtil");
|
||||
if(sharedLibraryUtil == NULL) {
|
||||
__android_log_print(ANDROID_LOG_ERROR, "EMUIIteratorFix", "Failed to find the target class");
|
||||
(*env)->ExceptionClear(env);
|
||||
return;
|
||||
}
|
||||
JNINativeMethod getLibraryPathMethod[] = {
|
||||
{"getLibraryPath", "(JJI)I", &getLibraryPath_fix}
|
||||
};
|
||||
if((*env)->RegisterNatives(env, sharedLibraryUtil, getLibraryPathMethod, 1) != 0) {
|
||||
__android_log_print(ANDROID_LOG_ERROR, "EMUIIteratorFix", "Failed to register the mitigation method");
|
||||
(*env)->ExceptionClear(env);
|
||||
}
|
||||
}
|
||||
|
||||
void critical_set_stackqueue(jboolean use_input_stack_queue) {
|
||||
pojav_environ->isUseStackQueueCall = (int) use_input_stack_queue;
|
||||
}
|
||||
@@ -273,7 +308,7 @@ JNIEXPORT jboolean JNICALL JavaCritical_org_lwjgl_glfw_CallbackBridge_nativeSetI
|
||||
#ifdef DEBUG
|
||||
LOGD("Debug: Changing input state, isReady=%d, pojav_environ->isUseStackQueueCall=%d\n", inputReady, pojav_environ->isUseStackQueueCall);
|
||||
#endif
|
||||
LOGI("Input ready: %i", inputReady);
|
||||
__android_log_print(ANDROID_LOG_INFO, "NativeInput", "Input ready: %i", inputReady);
|
||||
pojav_environ->isInputReady = inputReady;
|
||||
return pojav_environ->isUseStackQueueCall;
|
||||
}
|
||||
@@ -515,9 +550,9 @@ static void registerFunctions(JNIEnv *env) {
|
||||
bool use_critical_cc = tryCriticalNative(env);
|
||||
jclass bridge_class = (*env)->FindClass(env, "org/lwjgl/glfw/CallbackBridge");
|
||||
if(use_critical_cc) {
|
||||
LOGI("CriticalNative is available. Enjoy the 4.6x times faster input!");
|
||||
__android_log_print(ANDROID_LOG_INFO, "pojavexec", "CriticalNative is available. Enjoy the 4.6x times faster input!");
|
||||
}else{
|
||||
LOGI("CriticalNative is not available. Upgrade, maybe?");
|
||||
__android_log_print(ANDROID_LOG_INFO, "pojavexec", "CriticalNative is not available. Upgrade, maybe?");
|
||||
}
|
||||
(*env)->RegisterNatives(env,
|
||||
bridge_class,
|
||||
|
||||
+4
-3
@@ -2,14 +2,15 @@
|
||||
// Created by maks on 05.01.2025.
|
||||
//
|
||||
|
||||
#include "jvm_hooks.h"
|
||||
#include <jni.h>
|
||||
#include <libgen.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <dlfcn.h>
|
||||
|
||||
#include "environ/environ.h"
|
||||
#include "utils.h"
|
||||
#include <environ/environ.h>
|
||||
#include <android/log.h>
|
||||
#include <utils.h>
|
||||
|
||||
static jint (*orig_ProcessImpl_forkAndExec)(JNIEnv *env, jobject process, jint mode, jbyteArray helperpath, jbyteArray prog, jbyteArray argBlock, jint argc, jbyteArray envBlock, jint envc, jbyteArray dir, jintArray std_fds, jboolean redirectErrorStream);
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
//
|
||||
// Created by maks on 23.01.2025.
|
||||
//
|
||||
|
||||
#include "jvm_hooks.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
#define TAG __FILE_NAME__
|
||||
#include <log.h>
|
||||
|
||||
/**
|
||||
* This function is meant as a substitute for SharedLibraryUtil.getLibraryPath() that just returns 0
|
||||
* (thus making the parent Java function return null). This is done to avoid using the LWJGL's default function,
|
||||
* which will hang the crappy EMUI linker by dlopen()ing inside of dl_iterate_phdr().
|
||||
* @return 0, to make the parent Java function return null immediately.
|
||||
* For reference: https://github.com/PojavLauncherTeam/lwjgl3/blob/fix_huawei_hang/modules/lwjgl/core/src/main/java/org/lwjgl/system/SharedLibraryUtil.java
|
||||
*/
|
||||
jint getLibraryPath_fix(__attribute__((unused)) JNIEnv *env,
|
||||
__attribute__((unused)) jclass class,
|
||||
__attribute__((unused)) jlong pLibAddress,
|
||||
__attribute__((unused)) jlong sOutAddress,
|
||||
__attribute__((unused)) jint bufSize){
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Install the linker hang mitigation that is meant to prevent linker hangs on old EMUI firmware.
|
||||
*/
|
||||
void installEMUIIteratorMititgation(JNIEnv *env) {
|
||||
if(getenv("POJAV_EMUI_ITERATOR_MITIGATE") == NULL) return;
|
||||
LOGI("Installing...");
|
||||
jclass sharedLibraryUtil = (*env)->FindClass(env, "org/lwjgl/system/SharedLibraryUtil");
|
||||
if(sharedLibraryUtil == NULL) {
|
||||
LOGE("Failed to find target class");
|
||||
(*env)->ExceptionClear(env);
|
||||
return;
|
||||
}
|
||||
JNINativeMethod getLibraryPathMethod[] = {
|
||||
{"getLibraryPath", "(JJI)I", &getLibraryPath_fix}
|
||||
};
|
||||
if((*env)->RegisterNatives(env, sharedLibraryUtil, getLibraryPathMethod, 1) != 0) {
|
||||
LOGE("Failed to register the mitigation method");
|
||||
(*env)->ExceptionClear(env);
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
//
|
||||
// Created by maks on 23.01.2025.
|
||||
//
|
||||
|
||||
#ifndef POJAVLAUNCHER_JVM_HOOKS_H
|
||||
#define POJAVLAUNCHER_JVM_HOOKS_H
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
void installEMUIIteratorMititgation(JNIEnv *env);
|
||||
void installLwjglDlopenHook(JNIEnv *env);
|
||||
void hookExec(JNIEnv *env);
|
||||
|
||||
#endif //POJAVLAUNCHER_JVM_HOOKS_H
|
||||
@@ -1,9 +1,6 @@
|
||||
#ifndef POJAVLAUNCHER_LOG_H
|
||||
#define POJAVLAUNCHER_LOG_H
|
||||
|
||||
#ifdef __ANDROID__
|
||||
#include <android/log.h>
|
||||
|
||||
#ifndef TAG
|
||||
#define TAG "jrelog"
|
||||
#endif
|
||||
|
||||
@@ -11,14 +8,12 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, TAG, __VA_ARGS__)
|
||||
#define LOGW(...) __android_log_print(ANDROID_LOG_WARN, TAG, __VA_ARGS__)
|
||||
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, TAG, __VA_ARGS__)
|
||||
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, TAG, __VA_ARGS__)
|
||||
#define LOGE(...) __android_log_print(ANDROID_LOG_INFO, TAG, __VA_ARGS__)
|
||||
#define LOGW(...) __android_log_print(ANDROID_LOG_SILENT, TAG, __VA_ARGS__)
|
||||
#define LOGI(...) __android_log_print(ANDROID_LOG_SILENT, TAG, __VA_ARGS__)
|
||||
#define LOGD(...) __android_log_print(ANDROID_LOG_INFO, TAG, __VA_ARGS__)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
+6
-9
@@ -2,19 +2,16 @@
|
||||
// Created by maks on 06.01.2025.
|
||||
//
|
||||
|
||||
#include "jvm_hooks.h"
|
||||
|
||||
#include <android/api-level.h>
|
||||
#include <android/log.h>
|
||||
#include <jni.h>
|
||||
|
||||
#include "environ/environ.h"
|
||||
#include <environ/environ.h>
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define TAG __FILE_NAME__
|
||||
#include <log.h>
|
||||
|
||||
extern void* maybe_load_vulkan();
|
||||
|
||||
/**
|
||||
@@ -49,10 +46,10 @@ static jlong ndlopen_bugfix(__attribute__((unused)) JNIEnv *env,
|
||||
* Install the LWJGL dlopen hook. This allows us to mitigate linker bugs and add custom library overrides.
|
||||
*/
|
||||
void installLwjglDlopenHook(JNIEnv *env) {
|
||||
LOGI("Installing LWJGL dlopen() hook");
|
||||
__android_log_print(ANDROID_LOG_INFO, "LwjglLinkerHook", "Installing LWJGL dlopen() hook");
|
||||
jclass dynamicLinkLoader = (*env)->FindClass(env, "org/lwjgl/system/linux/DynamicLinkLoader");
|
||||
if(dynamicLinkLoader == NULL) {
|
||||
LOGE("Failed to find the target class");
|
||||
__android_log_print(ANDROID_LOG_ERROR, "LwjglLinkerHook", "Failed to find the target class");
|
||||
(*env)->ExceptionClear(env);
|
||||
return;
|
||||
}
|
||||
@@ -60,7 +57,7 @@ void installLwjglDlopenHook(JNIEnv *env) {
|
||||
{"ndlopen", "(JI)J", &ndlopen_bugfix}
|
||||
};
|
||||
if((*env)->RegisterNatives(env, dynamicLinkLoader, ndlopenMethod, 1) != 0) {
|
||||
LOGE("Failed to register the hooked method");
|
||||
__android_log_print(ANDROID_LOG_ERROR, "LwjglLinkerHook", "Failed to register the hooked method");
|
||||
(*env)->ExceptionClear(env);
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
//
|
||||
// Created by maks on 23.01.2025.
|
||||
//
|
||||
|
||||
#include "native_hooks.h"
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#define TAG __FILE_NAME__
|
||||
#include <log.h>
|
||||
|
||||
// Hooks for chmod and fchmod that always return success.
|
||||
// This allows older Android versions to work with Java NIO zipfs inside of the Pojav folder.
|
||||
typedef int (*chmod_func)(const char*, mode_t);
|
||||
typedef int (*fchmod_func)(int, mode_t);
|
||||
|
||||
#define TEMPLATE_HOOK(X, Y, Z, W) static int X(Y, mode_t mode) { \
|
||||
int result = BYTEHOOK_CALL_PREV(X, Z, W, mode); \
|
||||
if(result != 0) errno = 0; \
|
||||
BYTEHOOK_POP_STACK(); \
|
||||
return 0; \
|
||||
} \
|
||||
|
||||
TEMPLATE_HOOK(custom_chmod, const char* filename, chmod_func, filename)
|
||||
TEMPLATE_HOOK(custom_fchmod, int fd, fchmod_func, fd)
|
||||
|
||||
#undef TEMPLATE_HOOK
|
||||
|
||||
void create_chmod_hooks(bytehook_hook_all_t bytehook_hook_all_p) {
|
||||
bytehook_stub_t stub_chmod = bytehook_hook_all_p(NULL, "chmod", &custom_chmod, NULL, NULL);
|
||||
bytehook_stub_t stub_fchmod = bytehook_hook_all_p(NULL, "fchmod", &custom_fchmod, NULL, NULL);
|
||||
LOGI("Successfully initialized chmod hooks, stubs: %p %p", stub_chmod, stub_fchmod);
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
//
|
||||
// Created by maks on 15.01.2025.
|
||||
//
|
||||
#include "native_hooks.h"
|
||||
|
||||
#include <jni.h>
|
||||
#include <stdbool.h>
|
||||
#include <bytehook.h>
|
||||
#include <dlfcn.h>
|
||||
#include <stdlib.h>
|
||||
#include "stdio_is.h"
|
||||
|
||||
#define TAG __FILE_NAME__
|
||||
#include <log.h>
|
||||
|
||||
static _Atomic bool exit_tripped = false;
|
||||
|
||||
static int exit_code = 0;
|
||||
|
||||
typedef void (*exit_func)(int);
|
||||
// Use the exit hook *only* to store the exit code.
|
||||
static void custom_exit(int code) {
|
||||
exit_code = code;
|
||||
BYTEHOOK_CALL_PREV(custom_exit, exit_func, code);
|
||||
BYTEHOOK_POP_STACK();
|
||||
}
|
||||
|
||||
static void custom_atexit() {
|
||||
if(exit_tripped) {
|
||||
return;
|
||||
}
|
||||
exit_tripped = true;
|
||||
nominal_exit(exit_code, false);
|
||||
}
|
||||
|
||||
static void create_hooks(bytehook_hook_all_t bytehook_hook_all_p) {
|
||||
bytehook_stub_t stub_exit = bytehook_hook_all_p(NULL, "exit", &custom_exit, NULL, NULL);
|
||||
LOGI("Successfully initialized exit hook, stub: %p", stub_exit);
|
||||
// Only apply chmod hooks on devices where the game directory is in games/PojavLauncher
|
||||
// which is below API 29
|
||||
if(android_get_device_api_level() < 29) {
|
||||
create_chmod_hooks(bytehook_hook_all_p);
|
||||
}
|
||||
}
|
||||
|
||||
static bool init_hooks() {
|
||||
void* bytehook_handle = dlopen("libbytehook.so", RTLD_NOW);
|
||||
if(bytehook_handle == NULL) {
|
||||
goto dlerror;
|
||||
}
|
||||
|
||||
bytehook_hook_all_t bytehook_hook_all_p;
|
||||
int (*bytehook_init_p)(int mode, bool debug);
|
||||
|
||||
bytehook_hook_all_p = dlsym(bytehook_handle, "bytehook_hook_all");
|
||||
bytehook_init_p = dlsym(bytehook_handle, "bytehook_init");
|
||||
|
||||
if(bytehook_hook_all_p == NULL || bytehook_init_p == NULL) {
|
||||
goto dlerror;
|
||||
}
|
||||
int bhook_status = bytehook_init_p(BYTEHOOK_MODE_AUTOMATIC, false);
|
||||
if(bhook_status == BYTEHOOK_STATUS_CODE_OK) {
|
||||
create_hooks(bytehook_hook_all_p);
|
||||
return true;
|
||||
} else {
|
||||
LOGE("bytehook_init failed (%i)", bhook_status);
|
||||
dlclose(bytehook_handle);
|
||||
return false;
|
||||
}
|
||||
|
||||
dlerror:
|
||||
if(bytehook_handle != NULL) dlclose(bytehook_handle);
|
||||
LOGE("Failed to load hook library: %s", dlerror());
|
||||
return false;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_net_kdt_pojavlaunch_utils_JREUtils_initializeHooks(JNIEnv *env, jclass clazz) {
|
||||
bool hooks_ready = init_hooks();
|
||||
if(!hooks_ready) {
|
||||
LOGE("Failed to initialize native hooks!");
|
||||
}
|
||||
// Always register atexit, because that's what we will call our exit from.
|
||||
// We only use the hook to capture the exit code.
|
||||
atexit(custom_atexit);
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
//
|
||||
// Created by maks on 23.01.2025.
|
||||
//
|
||||
|
||||
#ifndef POJAVLAUNCHER_NATIVE_HOOKS_H
|
||||
#define POJAVLAUNCHER_NATIVE_HOOKS_H
|
||||
|
||||
#include <bytehook.h>
|
||||
|
||||
typedef bytehook_stub_t (*bytehook_hook_all_t)(const char *callee_path_name, const char *sym_name, void *new_func,
|
||||
bytehook_hooked_t hooked, void *hooked_arg);
|
||||
|
||||
void create_chmod_hooks(bytehook_hook_all_t bytehook_hook_all_p);
|
||||
|
||||
#endif //POJAVLAUNCHER_NATIVE_HOOKS_H
|
||||
@@ -11,6 +11,8 @@ jobjectArray convert_from_char_array(JNIEnv *env, char **charArray, int num_rows
|
||||
void free_char_array(JNIEnv *env, jobjectArray jstringArray, const char **charArray);
|
||||
jstring convertStringJVM(JNIEnv* srcEnv, JNIEnv* dstEnv, jstring srcStr);
|
||||
|
||||
void hookExec(JNIEnv *env);
|
||||
void installLwjglDlopenHook(JNIEnv *env);
|
||||
JNIEnv* get_attached_env(JavaVM* jvm);
|
||||
JNIEXPORT jstring JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeClipboard(JNIEnv* env, jclass clazz, jint action, jbyteArray copySrc);
|
||||
|
||||
Reference in new issue
Block a user