Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat[pojavexec]: better renderer symbol loading #6220

Merged
merged 2 commits into from
Nov 15, 2024
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
1 change: 1 addition & 0 deletions app_pojavlauncher/src/main/jni/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ LOCAL_SHARED_LIBRARIES := bytehook
LOCAL_SRC_FILES := \
bigcoreaffinity.c \
egl_bridge.c \
ctxbridges/loader_dlopen.c \
ctxbridges/gl_bridge.c \
ctxbridges/osm_bridge.c \
ctxbridges/egl_loader.c \
Expand Down
52 changes: 29 additions & 23 deletions app_pojavlauncher/src/main/jni/ctxbridges/egl_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <stdlib.h>
#include <dlfcn.h>
#include "egl_loader.h"
#include "loader_dlopen.h"

EGLBoolean (*eglMakeCurrent_p) (EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx);
EGLBoolean (*eglDestroyContext_p) (EGLDisplay dpy, EGLContext ctx);
Expand All @@ -24,28 +25,33 @@ EGLint (*eglGetError_p) (void);
EGLContext (*eglCreateContext_p) (EGLDisplay dpy, EGLConfig config, EGLContext share_list, const EGLint *attrib_list);
EGLBoolean (*eglSwapInterval_p) (EGLDisplay dpy, EGLint interval);
EGLSurface (*eglGetCurrentSurface_p) (EGLint readdraw);
__eglMustCastToProperFunctionPointerType (*eglGetProcAddress_p) (const char *procname);

void dlsym_EGL() {
void* dl_handle = NULL;
if(getenv("POJAVEXEC_EGL")) dl_handle = dlopen(getenv("POJAVEXEC_EGL"), RTLD_LAZY);
if(dl_handle == NULL) dl_handle = dlopen("libEGL.so", RTLD_LAZY);
if(dl_handle == NULL) abort();
eglBindAPI_p = dlsym(dl_handle,"eglBindAPI");
eglChooseConfig_p = dlsym(dl_handle, "eglChooseConfig");
eglCreateContext_p = dlsym(dl_handle, "eglCreateContext");
eglCreatePbufferSurface_p = dlsym(dl_handle, "eglCreatePbufferSurface");
eglCreateWindowSurface_p = dlsym(dl_handle, "eglCreateWindowSurface");
eglDestroyContext_p = dlsym(dl_handle, "eglDestroyContext");
eglDestroySurface_p = dlsym(dl_handle, "eglDestroySurface");
eglGetConfigAttrib_p = dlsym(dl_handle, "eglGetConfigAttrib");
eglGetCurrentContext_p = dlsym(dl_handle, "eglGetCurrentContext");
eglGetDisplay_p = dlsym(dl_handle, "eglGetDisplay");
eglGetError_p = dlsym(dl_handle, "eglGetError");
eglInitialize_p = dlsym(dl_handle, "eglInitialize");
eglMakeCurrent_p = dlsym(dl_handle, "eglMakeCurrent");
eglSwapBuffers_p = dlsym(dl_handle, "eglSwapBuffers");
eglReleaseThread_p = dlsym(dl_handle, "eglReleaseThread");
eglSwapInterval_p = dlsym(dl_handle, "eglSwapInterval");
eglTerminate_p = dlsym(dl_handle, "eglTerminate");
eglGetCurrentSurface_p = dlsym(dl_handle,"eglGetCurrentSurface");
bool dlsym_EGL() {
void* dl_handle = loader_dlopen(getenv("POJAVEXEC_EGL"),"libEGL.so", RTLD_LOCAL|RTLD_LAZY);
if(dl_handle == NULL) return false;
eglGetProcAddress_p = dlsym(dl_handle, "eglGetProcAddress");
if(eglGetProcAddress_p == NULL) {
printf("%s\n", dlerror());
return false;
}
eglBindAPI_p = (void*) eglGetProcAddress_p("eglBindAPI");
eglChooseConfig_p = (void*) eglGetProcAddress_p("eglChooseConfig");
eglCreateContext_p = (void*) eglGetProcAddress_p("eglCreateContext");
eglCreatePbufferSurface_p = (void*) eglGetProcAddress_p("eglCreatePbufferSurface");
eglCreateWindowSurface_p = (void*) eglGetProcAddress_p("eglCreateWindowSurface");
eglDestroyContext_p = (void*) eglGetProcAddress_p("eglDestroyContext");
eglDestroySurface_p = (void*) eglGetProcAddress_p("eglDestroySurface");
eglGetConfigAttrib_p = (void*) eglGetProcAddress_p("eglGetConfigAttrib");
eglGetCurrentContext_p = (void*) eglGetProcAddress_p("eglGetCurrentContext");
eglGetDisplay_p = (void*) eglGetProcAddress_p("eglGetDisplay");
eglGetError_p = (void*) eglGetProcAddress_p("eglGetError");
eglInitialize_p = (void*) eglGetProcAddress_p("eglInitialize");
eglMakeCurrent_p = (void*) eglGetProcAddress_p("eglMakeCurrent");
eglSwapBuffers_p = (void*) eglGetProcAddress_p("eglSwapBuffers");
eglReleaseThread_p = (void*) eglGetProcAddress_p("eglReleaseThread");
eglSwapInterval_p = (void*) eglGetProcAddress_p("eglSwapInterval");
eglTerminate_p = (void*) eglGetProcAddress_p("eglTerminate");
eglGetCurrentSurface_p = (void*) eglGetProcAddress_p("eglGetCurrentSurface");
return true;
}
4 changes: 3 additions & 1 deletion app_pojavlauncher/src/main/jni/ctxbridges/egl_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Created by maks on 21.09.2022.
//
#include <EGL/egl.h>
#include <stdbool.h>
#ifndef POJAVLAUNCHER_EGL_LOADER_H
#define POJAVLAUNCHER_EGL_LOADER_H

Expand All @@ -23,7 +24,8 @@ extern EGLint (*eglGetError_p) (void);
extern EGLContext (*eglCreateContext_p) (EGLDisplay dpy, EGLConfig config, EGLContext share_list, const EGLint *attrib_list);
extern EGLBoolean (*eglSwapInterval_p) (EGLDisplay dpy, EGLint interval);
extern EGLSurface (*eglGetCurrentSurface_p) (EGLint readdraw);
extern __eglMustCastToProperFunctionPointerType (*eglGetProcAddress_p) (const char *procname);

void dlsym_EGL();
bool dlsym_EGL();

#endif //POJAVLAUNCHER_EGL_LOADER_H
2 changes: 1 addition & 1 deletion app_pojavlauncher/src/main/jni/ctxbridges/gl_bridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ static __thread gl_render_window_t* currentBundle;
static EGLDisplay g_EglDisplay;

bool gl_init() {
dlsym_EGL();
if(!dlsym_EGL()) return false;
g_EglDisplay = eglGetDisplay_p(EGL_DEFAULT_DISPLAY);
if (g_EglDisplay == EGL_NO_DISPLAY) {
__android_log_print(ANDROID_LOG_ERROR, g_LogTag, "%s",
Expand Down
24 changes: 24 additions & 0 deletions app_pojavlauncher/src/main/jni/ctxbridges/loader_dlopen.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// Created by maks on 26.10.2024.
//
#include <string.h>
#include <stdio.h>
#include <dlfcn.h>
#include <linux/limits.h>
void* loader_dlopen(char* primaryName, char* secondaryName, int flags) {
void* dl_handle;
if(primaryName == NULL) goto secondary;

dl_handle = dlopen(primaryName, flags);
if(dl_handle != NULL) return dl_handle;
if(secondaryName == NULL) goto dl_error;

secondary:
dl_handle = dlopen(secondaryName, flags);
if(dl_handle == NULL) goto dl_error;
return dl_handle;

dl_error:
printf("%s", dlerror());
return NULL;
}
10 changes: 10 additions & 0 deletions app_pojavlauncher/src/main/jni/ctxbridges/loader_dlopen.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//
// Created by maks on 26.10.2024.
//

#ifndef POJAVLAUNCHER_LOADER_DLOPEN_H
#define POJAVLAUNCHER_LOADER_DLOPEN_H

void* loader_dlopen(char* primaryName, char* secondaryName, int flags);

#endif //POJAVLAUNCHER_LOADER_DLOPEN_H
4 changes: 2 additions & 2 deletions app_pojavlauncher/src/main/jni/ctxbridges/osm_bridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ static char no_render_buffer[4];
void setNativeWindowSwapInterval(struct ANativeWindow* nativeWindow, int swapInterval);

bool osm_init() {
dlsym_OSMesa();
return true; // no more specific initialization required
if(!dlsym_OSMesa()) return false;
return true;
}

osm_render_window_t* osm_get_current() {
Expand Down
40 changes: 20 additions & 20 deletions app_pojavlauncher/src/main/jni/ctxbridges/osmesa_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <dlfcn.h>
#include "loader_dlopen.h"
#include "osmesa_loader.h"

GLboolean (*OSMesaMakeCurrent_p) (OSMesaContext ctx, void *buffer, GLenum type,
Expand All @@ -17,26 +18,25 @@ void (*glFinish_p) (void);
void (*glClearColor_p) (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha);
void (*glClear_p) (GLbitfield mask);
void (*glReadPixels_p) (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void * data);
void* (*OSMesaGetProcAddress_p)(const char* funcName);

void dlsym_OSMesa() {
char* main_path = NULL;
char* alt_path = NULL;
if(asprintf(&main_path, "%s/libOSMesa.so", getenv("POJAV_NATIVEDIR")) == -1 ||
asprintf(&alt_path, "%s/libOSMesa.so.8", getenv("POJAV_NATIVEDIR")) == -1) {
abort();
bool dlsym_OSMesa() {
void* dl_handle = loader_dlopen("libOSMesa.so.8", "libOSMesa.so", RTLD_LOCAL | RTLD_LAZY);
if(dl_handle == NULL) return false;
OSMesaGetProcAddress_p = dlsym(dl_handle, "OSMesaGetProcAddress");
if(OSMesaGetProcAddress_p == NULL) {
printf("%s\n", dlerror());
return false;
}
void* dl_handle = NULL;
dl_handle = dlopen(alt_path, RTLD_GLOBAL);
if(dl_handle == NULL) dl_handle = dlopen(main_path, RTLD_GLOBAL);
if(dl_handle == NULL) abort();
OSMesaMakeCurrent_p = dlsym(dl_handle, "OSMesaMakeCurrent");
OSMesaGetCurrentContext_p = dlsym(dl_handle,"OSMesaGetCurrentContext");
OSMesaCreateContext_p = dlsym(dl_handle, "OSMesaCreateContext");
OSMesaDestroyContext_p = dlsym(dl_handle, "OSMesaDestroyContext");
OSMesaPixelStore_p = dlsym(dl_handle,"OSMesaPixelStore");
glGetString_p = dlsym(dl_handle,"glGetString");
glClearColor_p = dlsym(dl_handle, "glClearColor");
glClear_p = dlsym(dl_handle,"glClear");
glFinish_p = dlsym(dl_handle,"glFinish");
glReadPixels_p = dlsym(dl_handle,"glReadPixels");
OSMesaMakeCurrent_p = OSMesaGetProcAddress_p("OSMesaMakeCurrent");
OSMesaGetCurrentContext_p = OSMesaGetProcAddress_p("OSMesaGetCurrentContext");
OSMesaCreateContext_p = OSMesaGetProcAddress_p("OSMesaCreateContext");
OSMesaDestroyContext_p = OSMesaGetProcAddress_p("OSMesaDestroyContext");
OSMesaPixelStore_p = OSMesaGetProcAddress_p("OSMesaPixelStore");
glGetString_p = OSMesaGetProcAddress_p("glGetString");
glClearColor_p = OSMesaGetProcAddress_p("glClearColor");
glClear_p = OSMesaGetProcAddress_p("glClear");
glFinish_p = OSMesaGetProcAddress_p("glFinish");
glReadPixels_p = OSMesaGetProcAddress_p("glReadPixels");
return true;
}
5 changes: 4 additions & 1 deletion app_pojavlauncher/src/main/jni/ctxbridges/osmesa_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define POJAVLAUNCHER_OSMESA_LOADER_H

#include <GL/osmesa.h>
#include <stdbool.h>

extern GLboolean (*OSMesaMakeCurrent_p) (OSMesaContext ctx, void *buffer, GLenum type,
GLsizei width, GLsizei height);
Expand All @@ -18,5 +19,7 @@ extern void (*glFinish_p) (void);
extern void (*glClearColor_p) (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha);
extern void (*glClear_p) (GLbitfield mask);
extern void (*glReadPixels_p) (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void * data);
void dlsym_OSMesa();
extern void* (*OSMesaGetProcAddress_p)(const char* funcName);

bool dlsym_OSMesa();
#endif //POJAVLAUNCHER_OSMESA_LOADER_H
Loading