fix glfw namespace bug

This commit is contained in:
Tungstend 2023-07-22 00:56:34 +08:00
parent b84b748761
commit 1f40a9d0ab
16 changed files with 108 additions and 86 deletions

View File

@ -1 +1 @@
1689073232516
1689956796346

View File

@ -40,7 +40,8 @@ public class ProcessService extends Service {
getApplicationContext().getDir("runtime", 0).getAbsolutePath() + "/java/jre8",
getApplicationContext().getCacheDir() + "/fclauncher",
null,
command);
command,
false);
startProcess(config);
return super.onStartCommand(intent, flags, startId);
}

View File

@ -396,7 +396,8 @@ public class DefaultLauncher extends Launcher {
options.getJava().getVersion() == 8 ? FCLPath.JAVA_8_PATH : FCLPath.JAVA_17_PATH,
repository.getRunDirectory(version.getId()).getAbsolutePath(),
renderer,
finalArgs);
finalArgs,
version.getMinimumLauncherVersion() >= 21);
return FCLauncher.launchMinecraft(config);
}
}

View File

@ -54,14 +54,16 @@ public class FCLConfig implements Serializable {
private final String workingDir;
private final Renderer renderer;
private final String[] args;
private final boolean isLwjgl3;
public FCLConfig(Context context, String logDir, String javaPath, String workingDir, Renderer renderer, String[] args) {
public FCLConfig(Context context, String logDir, String javaPath, String workingDir, Renderer renderer, String[] args, boolean isLwjgl3) {
this.context = context;
this.logDir = logDir;
this.javaPath = javaPath;
this.workingDir = workingDir;
this.renderer = renderer;
this.args = args;
this.isLwjgl3 = isLwjgl3;
}
public Context getContext() {
@ -88,4 +90,7 @@ public class FCLConfig implements Serializable {
return args;
}
public boolean isLwjgl3() {
return isLwjgl3;
}
}

View File

@ -211,6 +211,7 @@ public class FCLauncher {
bridge.dlopen(nativeDir + "/libopenal.so");
// Todo : mesa
if (!config.isLwjgl3()) {
FCLConfig.Renderer renderer = config.getRenderer() == null ? FCLConfig.Renderer.RENDERER_GL4ES : config.getRenderer();
bridge.dlopen(nativeDir + "/" + renderer.getGlLibName());
bridge.dlopen(nativeDir + "/" + renderer.getEglLibName());
@ -220,6 +221,7 @@ public class FCLauncher {
bridge.dlopen(nativeDir + "/zink_dri.so");
}
}
}
private static void launch(FCLConfig config, FCLBridge bridge, String task) throws IOException {
printTaskTitle(bridge, task + " Arguments");

View File

@ -73,7 +73,6 @@ public class FCLBridge implements Serializable {
static {
System.loadLibrary("xhook");
System.loadLibrary("fcl");
System.loadLibrary("glfw");
System.loadLibrary("fcl_awt");
}

View File

@ -14,7 +14,7 @@ jint JNI_OnLoad(JavaVM *vm, void *reserved) {
dalvikJavaVMPtr = vm;
JNIEnv *env = NULL;
(*vm)->GetEnv(vm, (void **) &env, JNI_VERSION_1_4);
class_FCLBridge = fcl.class_FCLBridge;
class_FCLBridge = fcl->class_FCLBridge;
method_OpenLink = (*env)->GetStaticMethodID(env, class_FCLBridge, "openLink",
"(Ljava/lang/String;)V");
}

View File

@ -7,11 +7,30 @@
#include <android/native_window_jni.h>
#include <jni.h>
#include <android/log.h>
#include <assert.h>
FCLInternal fcl;
struct FCLInternal *fcl;
__attribute__((constructor)) void env_init() {
char* strptr_env = getenv("FCL_ENVIRON");
if (strptr_env == NULL) {
__android_log_print(ANDROID_LOG_INFO, "Environ", "No environ found, creating...");
fcl = malloc(sizeof(struct FCLInternal));
assert(fcl);
memset(fcl, 0 , sizeof(struct FCLInternal));
if (asprintf(&strptr_env, "%p", fcl) == -1)
abort();
setenv("FCL_ENVIRON", strptr_env, 1);
free(strptr_env);
} else {
__android_log_print(ANDROID_LOG_INFO, "Environ", "Found existing environ: %s", strptr_env);
fcl = (void*) strtoul(strptr_env, NULL, 0x10);
}
__android_log_print(ANDROID_LOG_INFO, "Environ", "%p", fcl);
}
ANativeWindow* fclGetNativeWindow() {
return fcl.window;
return fcl->window;
}
void fclSetPrimaryClipString(const char* string) {
@ -21,37 +40,36 @@ void fclSetPrimaryClipString(const char* string) {
const char* fclGetPrimaryClipString() {
PrepareFCLBridgeJNI();
if (fcl.clipboard_string != NULL) {
free(fcl.clipboard_string);
fcl.clipboard_string = NULL;
if (fcl->clipboard_string != NULL) {
free(fcl->clipboard_string);
fcl->clipboard_string = NULL;
}
CallFCLBridgeJNIFunc(jstring clipstr = , Object, getPrimaryClipString, "()Ljava/lang/String;");
const char* string = NULL;
if (clipstr != NULL) {
string = (*env)->GetStringUTFChars(env, clipstr, NULL);
if (string != NULL) {
fcl.clipboard_string = strdup(string);
fcl->clipboard_string = strdup(string);
}
}
return fcl.clipboard_string;
return fcl->clipboard_string;
}
JNIEXPORT void JNICALL Java_com_tungsten_fclauncher_bridge_FCLBridge_setFCLNativeWindow(JNIEnv* env, jclass clazz, jobject surface) {
fcl.window = ANativeWindow_fromSurface(env, surface);
FCL_INTERNAL_LOG("setFCLNativeWindow : %p, size : %dx%d", fcl.window,ANativeWindow_getWidth(fcl.window),ANativeWindow_getHeight(fcl.window));
fcl->window = ANativeWindow_fromSurface(env, surface);
FCL_INTERNAL_LOG("setFCLNativeWindow : %p, size : %dx%d", fcl->window, ANativeWindow_getWidth(fcl->window), ANativeWindow_getHeight(fcl->window));
}
JNIEXPORT void JNICALL
Java_com_tungsten_fclauncher_bridge_FCLBridge_setFCLBridge(JNIEnv *env, jobject thiz,
jobject fcl_bridge) {
fcl.object_FCLBridge = (jclass)(*env)->NewGlobalRef(env, thiz);
JNIEXPORT void JNICALL Java_com_tungsten_fclauncher_bridge_FCLBridge_setFCLBridge(JNIEnv *env, jobject thiz, jobject fcl_bridge) {
fcl->object_FCLBridge = (jclass)(*env)->NewGlobalRef(env, thiz);
}
JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) {
memset(&fcl, 0, sizeof(fcl));
fcl.android_jvm = vm;
env_init();
if (fcl->android_jvm == NULL) {
fcl->android_jvm = vm;
JNIEnv* env = 0;
jint result = (*fcl.android_jvm)->AttachCurrentThread(fcl.android_jvm, &env, 0);
jint result = (*fcl->android_jvm)->AttachCurrentThread(fcl->android_jvm, &env, 0);
if (result != JNI_OK || env == 0) {
FCL_INTERNAL_LOG("Failed to attach thread to JavaVM.");
abort();
@ -61,6 +79,7 @@ JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) {
FCL_INTERNAL_LOG("Failed to find class: com/tungsten/fclauncher/bridge/FCLBridge.");
abort();
}
fcl.class_FCLBridge = (jclass)(*env)->NewGlobalRef(env, class_FCLBridge);
fcl->class_FCLBridge = (jclass)(*env)->NewGlobalRef(env, class_FCLBridge);
}
return JNI_VERSION_1_2;
}

View File

@ -68,7 +68,7 @@ int fclGetInjectorMode() {
}
void fclSetHitResultType(int type) {
if (!fcl.has_event_pipe) {
if (!fcl->has_event_pipe) {
return;
}
PrepareFCLBridgeJNI();
@ -76,7 +76,7 @@ void fclSetHitResultType(int type) {
}
void fclSetCursorMode(int mode) {
if (!fcl.has_event_pipe) {
if (!fcl->has_event_pipe) {
return;
}
PrepareFCLBridgeJNI();
@ -84,18 +84,18 @@ void fclSetCursorMode(int mode) {
}
int fclGetEventFd() {
if (!fcl.has_event_pipe) {
if (!fcl->has_event_pipe) {
return -1;
}
return fcl.event_pipe_fd[0];
return fcl->event_pipe_fd[0];
}
int fclWaitForEvent(int timeout) {
if (!fcl.has_event_pipe) {
if (!fcl->has_event_pipe) {
return 0;
}
struct epoll_event ev;
int ret = epoll_wait(fcl.epoll_fd, &ev, 1, timeout);
int ret = epoll_wait(fcl->epoll_fd, &ev, 1, timeout);
if (ret > 0 && (ev.events & EPOLLIN)) {
return 1;
}
@ -103,19 +103,19 @@ int fclWaitForEvent(int timeout) {
}
int fclPollEvent(FCLEvent* event) {
if (!fcl.has_event_pipe) {
if (!fcl->has_event_pipe) {
return 0;
}
if (pthread_mutex_lock(&fcl.event_queue_mutex)) {
if (pthread_mutex_lock(&fcl->event_queue_mutex)) {
FCL_INTERNAL_LOG("Failed to acquire mutex");
return 0;
}
char c;
int ret = 0;
if (read(fcl.event_pipe_fd[0], &c, 1) > 0) {
ret = EventQueue_take(&fcl.event_queue, event);
if (read(fcl->event_pipe_fd[0], &c, 1) > 0) {
ret = EventQueue_take(&fcl->event_queue, event);
}
if (pthread_mutex_unlock(&fcl.event_queue_mutex)) {
if (pthread_mutex_unlock(&fcl->event_queue_mutex)) {
FCL_INTERNAL_LOG("Failed to release mutex");
return 0;
}
@ -127,14 +127,14 @@ JNIEXPORT void JNICALL Java_com_tungsten_fclauncher_bridge_FCLBridge_refreshHitR
}
JNIEXPORT void JNICALL Java_com_tungsten_fclauncher_bridge_FCLBridge_pushEvent(JNIEnv* env, jclass clazz, jlong time, jint type, jint p1, jint p2) {
if (!fcl.has_event_pipe) {
if (!fcl->has_event_pipe) {
return;
}
if (pthread_mutex_lock(&fcl.event_queue_mutex)) {
if (pthread_mutex_lock(&fcl->event_queue_mutex)) {
FCL_INTERNAL_LOG("Failed to acquire mutex");
return;
}
FCLEvent* event = EventQueue_add(&fcl.event_queue);
FCLEvent* event = EventQueue_add(&fcl->event_queue);
if (event == NULL) {
FCL_INTERNAL_LOG("Failed to add event to event queue");
return;
@ -164,31 +164,31 @@ JNIEXPORT void JNICALL Java_com_tungsten_fclauncher_bridge_FCLBridge_pushEvent(J
event->message = p1;
break;
}
write(fcl.event_pipe_fd[1], "E", 1);
if (pthread_mutex_unlock(&fcl.event_queue_mutex)) {
write(fcl->event_pipe_fd[1], "E", 1);
if (pthread_mutex_unlock(&fcl->event_queue_mutex)) {
FCL_INTERNAL_LOG("Failed to release mutex");
}
}
JNIEXPORT void JNICALL Java_com_tungsten_fclauncher_bridge_FCLBridge_setEventPipe(JNIEnv* env, jclass clazz) {
if (pipe(fcl.event_pipe_fd) == -1) {
if (pipe(fcl->event_pipe_fd) == -1) {
FCL_INTERNAL_LOG("Failed to create event pipe : %s", strerror(errno));
return;
}
fcl.epoll_fd = epoll_create(3);
if (fcl.epoll_fd == -1) {
fcl->epoll_fd = epoll_create(3);
if (fcl->epoll_fd == -1) {
FCL_INTERNAL_LOG("Failed to get epoll fd : %s", strerror(errno));
return;
}
struct epoll_event ev;
ev.events = EPOLLIN;
ev.data.fd = fcl.event_pipe_fd[0];
if (epoll_ctl(fcl.epoll_fd, EPOLL_CTL_ADD, fcl.event_pipe_fd[0], &ev) == -1) {
ev.data.fd = fcl->event_pipe_fd[0];
if (epoll_ctl(fcl->epoll_fd, EPOLL_CTL_ADD, fcl->event_pipe_fd[0], &ev) == -1) {
FCL_INTERNAL_LOG("Failed to add epoll event : %s", strerror(errno));
return;
}
EventQueue_init(&fcl.event_queue);
pthread_mutex_init(&fcl.event_queue_mutex, NULL);
fcl.has_event_pipe = 1;
EventQueue_init(&fcl->event_queue);
pthread_mutex_init(&fcl->event_queue_mutex, NULL);
fcl->has_event_pipe = 1;
FCL_INTERNAL_LOG("Succeeded to set event pipe");
}

View File

@ -70,7 +70,7 @@ JNIEXPORT void JNICALL Java_com_tungsten_fclauncher_bridge_FCLBridge_redirectStd
if (!method_setLogPipeReady) {
__android_log_print(ANDROID_LOG_ERROR, "FCL", "Failed to find setLogPipeReady method!");
}
fcl.logFile = fdopen(fclFd[1],"a");
fcl->logFile = fdopen(fclFd[1], "a");
FCL_INTERNAL_LOG("Log pipe ready.");
(*env) -> CallVoidMethod(env, jobject, method_setLogPipeReady);
log_method = (*env) -> GetMethodID(env, bridge, "receiveLog", "(Ljava/lang/String;)V");

View File

@ -29,7 +29,7 @@ typedef struct {
QueueElement* tail;
} EventQueue;
typedef struct {
struct FCLInternal {
JavaVM* android_jvm;
jclass class_FCLBridge;
jobject object_FCLBridge;
@ -41,19 +41,19 @@ typedef struct {
int event_pipe_fd[2];
int epoll_fd;
FILE* logFile;
} FCLInternal;
};
extern FCLInternal fcl;
extern struct FCLInternal *fcl;
#define FCL_INTERNAL_LOG(x...) do { \
fprintf(fcl.logFile, "[FCL Internal] %s:%d\n", __FILE__, __LINE__); \
fprintf(fcl.logFile, x); \
fprintf(fcl.logFile, "\n"); \
fflush(fcl.logFile); \
fprintf(fcl->logFile, "[FCL Internal] %s:%d\n", __FILE__, __LINE__); \
fprintf(fcl->logFile, x); \
fprintf(fcl->logFile, "\n"); \
fflush(fcl->logFile); \
} while (0)
#define PrepareFCLBridgeJNI() \
JavaVM* vm = fcl.android_jvm; \
JavaVM* vm = fcl->android_jvm; \
JNIEnv* env = NULL; \
jint attached = (*vm)->GetEnv(vm, (void**)&env, JNI_VERSION_1_2); \
if (attached == JNI_EDETACHED) { \
@ -65,11 +65,11 @@ extern FCLInternal fcl;
do {} while(0)
#define CallFCLBridgeJNIFunc(return_exp, func_type, func_name, signature, args...) \
jmethodID FCLBridge_##func_name = (*env)->GetMethodID(env, fcl.class_FCLBridge, #func_name, signature); \
jmethodID FCLBridge_##func_name = (*env)->GetMethodID(env, fcl->class_FCLBridge, #func_name, signature); \
if (FCLBridge_##func_name == NULL) { \
FCL_INTERNAL_LOG("Failed to find method FCLBridge_"#func_name ); \
} \
return_exp (*env)->Call##func_type##Method(env, fcl.object_FCLBridge, FCLBridge_##func_name, ##args); \
return_exp (*env)->Call##func_type##Method(env, fcl->object_FCLBridge, FCLBridge_##func_name, ##args); \
do {} while(0)
#endif //FOLD_CRAFT_LAUNCHER_FCL_INTERNAL_H

View File

@ -343,6 +343,7 @@ GLFWbool _glfwCreateContextEGL(_GLFWwindow* window,
// eglGetConfigAttrib(_glfw.egl.display, config, EGL_NATIVE_VISUAL_ID, 0);
int client = 0;
const char* render = getenv("LIBGL_NAME");
_glfw_dlopen(render);
if (strcmp(render, "libgl4es_114.so") == 0) {
client = 0;
} else if (strcmp(render, "libtinywrapper.so") == 0) {

View File

@ -30,9 +30,9 @@ typedef VkResult (APIENTRY *PFN_vkCreateAndroidSurfaceKHR)(VkInstance, const VkA
#include "egl_context.h"
#include "osmesa_context.h"
#define _glfw_dlopen(name) by_dlopen(name, RTLD_LAZY | RTLD_GLOBAL)
#define _glfw_dlclose(handle) by_dlclose(handle)
#define _glfw_dlsym(handle, name) by_dlsym(handle, name)
#define _glfw_dlopen(name) dlopen(name, RTLD_LAZY | RTLD_GLOBAL)
#define _glfw_dlclose(handle) dlclose(handle)
#define _glfw_dlsym(handle, name) dlsym(handle, name)
#define _GLFW_EGL_NATIVE_WINDOW ((EGLNativeWindowType) window->fcl.handle)
#define _GLFW_EGL_NATIVE_DISPLAY EGL_DEFAULT_DISPLAY

View File

@ -34,7 +34,7 @@ hooked_ProcessImpl_forkAndExec(JNIEnv *env, jobject process, jint mode, jbyteArr
(*env)->DeleteLocalRef(env, argBlock);
FCL_INTERNAL_LOG("forkAndExec:%s", cs);
JavaVM *androidVm = fcl.android_jvm;
JavaVM *androidVm = fcl->android_jvm;
JNIEnv *androidEnv = NULL;
char detachable = 0;
if ((*androidVm)->GetEnv(androidVm, (void **) &androidEnv, JNI_VERSION_1_2) == JNI_EDETACHED) {
@ -44,9 +44,9 @@ hooked_ProcessImpl_forkAndExec(JNIEnv *env, jobject process, jint mode, jbyteArr
if (!androidEnv) {
FCL_INTERNAL_LOG("forkAndExec error:androidEnv in null");
}
jmethodID method_OpenLink = (*androidEnv)->GetStaticMethodID(androidEnv, fcl.class_FCLBridge, "openLink",
jmethodID method_OpenLink = (*androidEnv)->GetStaticMethodID(androidEnv, fcl->class_FCLBridge, "openLink",
"(Ljava/lang/String;)V");
(*androidEnv)->CallStaticVoidMethod(androidEnv, fcl.class_FCLBridge, method_OpenLink,
(*androidEnv)->CallStaticVoidMethod(androidEnv, fcl->class_FCLBridge, method_OpenLink,
(*androidEnv)->NewStringUTF(androidEnv, cs));
if (detachable) (*androidVm)->DetachCurrentThread(androidVm);

View File

@ -18,9 +18,6 @@ JNIEXPORT jlong JNICALL Java_org_lwjgl_system_fcl_DynamicLinkLoader_ndlopen(JNIE
if (!glesHandle) {
glesHandle = dlopen("libGLESv2.so", RTLD_LAZY | RTLD_GLOBAL);
}
if (strstr(filename, "glfw") != 0) {
return (jlong)(intptr_t)by_dlopen(filename, RTLD_LAZY | RTLD_GLOBAL);
}
return (jlong)(intptr_t)dlopen(filename, RTLD_LAZY | RTLD_GLOBAL);
}
@ -33,9 +30,6 @@ JNIEXPORT jlong JNICALL Java_org_lwjgl_system_fcl_DynamicLinkLoader_ndlsym(JNIEn
void *handle = (void *)(intptr_t)handleAddress;
char const *name = (char const *)(intptr_t)nameAddress;
UNUSED_PARAMS(__env, clazz)
if (strstr(name,"glfw") != 0) {
return (jlong)(intptr_t)by_dlsym(handle, name);
}
jlong retval = (jlong)(intptr_t)dlsym(handle, name);
if (!retval && name[0] == 'g' && name[1] == 'l') {
retval = (jlong)(intptr_t)dlsym(glesHandle, name);