fix BEGesture

This commit is contained in:
ShirosakiMio 2024-08-22 17:02:13 +08:00
parent f9d9968ee3
commit 96fc0256ed
10 changed files with 273 additions and 36 deletions

View File

@ -1 +1 @@
1724075588557
1724317165115

View File

@ -12,21 +12,10 @@ void fclSetInjectorCallback(FCLinjectorfun callback) {
}
void fclSetHitResultType(int type) {
if (!fcl->has_event_pipe) {
return;
}
PrepareFCLBridgeJNI();
CallFCLBridgeJNIFunc( , Void, setHitResultType, "(I)V", type);
}
void fclSetCursorMode(int mode) {
if (!fcl->has_event_pipe) {
return;
}
PrepareFCLBridgeJNI();
CallFCLBridgeJNIFunc( , Void, setCursorMode, "(I)V", mode);
}
JNIEXPORT void JNICALL Java_com_tungsten_fclauncher_bridge_FCLBridge_refreshHitResultType(JNIEnv *env, jobject thiz) {
if (injectorCallback)
injectorCallback();

View File

@ -10,14 +10,8 @@
typedef void (* FCLinjectorfun)();
ANativeWindow* fclGetNativeWindow(void);
int fclWaitForEvent(int timeout);
int fclPollEvent(FCLEvent* event);
int fclGetEventFd(void);
void fclLog(const char *buffer);
void fclSetInjectorCallback(FCLinjectorfun callback);
void fclSetHitResultType(int type);
void fclSetCursorMode(int mode);
void fclSetPrimaryClipString(const char* string);
const char* fclGetPrimaryClipString(void);

View File

@ -17,29 +17,12 @@
#include "fcl_bridge.h"
#include "fcl_keycodes.h"
typedef struct _QueueElement {
struct _QueueElement* next;
FCLEvent event;
} QueueElement;
typedef struct {
int count;
int capacity;
QueueElement* head;
QueueElement* tail;
} EventQueue;
struct FCLInternal {
JavaVM* android_jvm;
jclass class_FCLBridge;
jobject object_FCLBridge;
ANativeWindow* window;
char* clipboard_string;
EventQueue event_queue;
pthread_mutex_t event_queue_mutex;
int has_event_pipe;
int event_pipe_fd[2];
int epoll_fd;
FILE* logFile;
};

View File

@ -45,6 +45,7 @@ struct PotatoBridge potatoBridge;
#include "ctxbridges/egl_loader.h"
#include "ctxbridges/osmesa_loader.h"
#include "pojav/virgl/virgl.h"
#include "fcl/include/fcl_bridge.h"
#define RENDERER_GL4ES 1
#define RENDERER_VK_ZINK 2
@ -286,3 +287,10 @@ EXTERNAL_API void pojavSwapInterval(int interval) {
else br_swap_interval(interval);
}
EXTERNAL_API void pojavSetInjectorCallback(FCLinjectorfun callback) {
fclSetInjectorCallback(callback);
}
EXTERNAL_API void pojavSetHitResultType(int type) {
fclSetHitResultType(type);
}

View File

@ -0,0 +1,174 @@
package org.lwjgl.glfw;
import org.lwjgl.system.*;
import javax.annotation.Nullable;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import static org.lwjgl.system.APIUtil.apiGetFunctionAddress;
import static org.lwjgl.system.APIUtil.apiLog;
import static org.lwjgl.system.JNI.invokePP;
import static org.lwjgl.system.MemoryUtil.memAddressSafe;
/**
* By Tungsten
* This class is for Fold Craft Launcher.
*/
public class FCLInjector {
public static final long SetInjectorCallBack = apiGetFunctionAddress(GLFW.GLFW, "pojavSetInjectorCallback");
public static final long SetHitResultType = apiGetFunctionAddress(GLFW.GLFW, "pojavSetHitResultType");
private static boolean get = false;
private static ClassLoader classLoader;
private static final String HIT_RESULT_TYPE_UNKNOWN = "UNKNOWN";
private static final String HIT_RESULT_TYPE_MISS = "MISS";
private static final String HIT_RESULT_TYPE_BLOCK = "BLOCK";
private static final String HIT_RESULT_TYPE_BLOCK_OLD = "TILE";
private static final String HIT_RESULT_TYPE_ENTITY = "ENTITY";
private static final int INJECTOR_LEVEL_0 = 0; // unknown
private static final int INJECTOR_LEVEL_1 = 1; // 1.0 - 1.2
private static final int INJECTOR_LEVEL_2 = 2; // 1.3 - 1.6
private static final int INJECTOR_LEVEL_3 = 3; // 1.7 - 1.13
private static final int INJECTOR_LEVEL_4 = 4; // 1.13+
private static final int INJECTOR_MODE_ENABLE = 1;
private static final int INJECTOR_MODE_DISABLE = 0;
private static int level = 0;
@Nullable
private static String param0 = null;
@Nullable
private static String param1 = null;
@Nullable
private static String param2 = null;
@Nullable
private static String param3 = null;
public static void setClassLoader(ClassLoader classLoader) {
String prop = System.getProperty("fcl.injector");
if (!get && prop != null && !prop.isEmpty()) {
FCLInjector.classLoader = classLoader;
String[] props = prop.split(":");
if (props.length == 5 && (props[0].equals("0") || props[0].equals("1") || props[0].equals("2") || props[0].equals("3") || props[0].equals("4"))) {
int level = Integer.parseInt(props[0]);
String param0 = props[1];
String param1 = props[2];
String param2 = props[3];
String param3 = props[4];
setup(level, param0, param1, param2, param3);
}
}
}
public static void setup(int level, String param0, String param1, String param2, String param3) {
FCLInjector.level = level;
FCLInjector.param0 = param0;
FCLInjector.param1 = param1;
FCLInjector.param2 = param2;
FCLInjector.param3 = param3;
get = true;
FCLInjectorCallback callback = new FCLInjectorCallback() {
@Override
public void invoke() {
getHitResultType();
}
};
glfwSetFCLInjectorCallback(callback);
}
@Nullable
@NativeType("FCLinjectorfun")
public static FCLInjectorCallback glfwSetFCLInjectorCallback(@Nullable @NativeType("FCLinjectorfun") FCLInjectorCallbackI cbfun) {
// boolean a =true;
// if (a) {
// throw new IllegalArgumentException("glfwSetFCLInjectorCallback");
// }
return FCLInjectorCallback.createSafe(nglfwSetFCLInjectorCallback(memAddressSafe(cbfun)));
}
public static long nglfwSetFCLInjectorCallback(long cbfun) {
return invokePP(cbfun, SetInjectorCallBack);
}
public static void nglfwSetHitResultType(String type) {
int typeInt;
switch (type) {
case HIT_RESULT_TYPE_MISS:
typeInt = 1;
break;
case HIT_RESULT_TYPE_BLOCK:
case HIT_RESULT_TYPE_BLOCK_OLD:
typeInt = 2;
break;
case HIT_RESULT_TYPE_ENTITY:
typeInt = 3;
break;
default:
typeInt = 0;
break;
}
JNI.invokeV(typeInt, FCLInjector.SetHitResultType);
}
public static void getHitResultType() {
if (!get) {
nglfwSetHitResultType(HIT_RESULT_TYPE_UNKNOWN);
apiLog("FCL Injector not initialized!\n");
return;
}
if (param0 != null && param1 != null && param2 != null && param3 != null) {
Object type = null;
boolean success = false;
try {
Class<?> minecraftClass = Class.forName(param0, true, classLoader);
Method method = minecraftClass.getDeclaredMethod(param1);
method.setAccessible(true);
Object minecraft = method.invoke(null);
Field targetField = minecraftClass.getDeclaredField(param2);
targetField.setAccessible(true);
Object target = targetField.get(minecraft);
if (target != null) {
switch (level) {
case INJECTOR_LEVEL_2:
case INJECTOR_LEVEL_3:
Field typeField = target.getClass().getDeclaredField(param3);
typeField.setAccessible(true);
type = typeField.get(target);
break;
case INJECTOR_LEVEL_4:
Method typeMethod = target.getClass().getDeclaredMethod(param3);
typeMethod.setAccessible(true);
type = typeMethod.invoke(target);
break;
default:
break;
}
}
success = true;
} catch (ClassNotFoundException | NoSuchFieldException | NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
apiLog(e.getMessage());
}
if (level == INJECTOR_LEVEL_2) {
if (success && type == null) {
nglfwSetHitResultType(HIT_RESULT_TYPE_MISS);
} else if (success && (type.toString().equals(HIT_RESULT_TYPE_BLOCK_OLD) || type.toString().equals(HIT_RESULT_TYPE_ENTITY))) {
nglfwSetHitResultType(type.toString());
} else {
nglfwSetHitResultType(HIT_RESULT_TYPE_UNKNOWN);
}
} else {
if (type != null && (type.toString().equals(HIT_RESULT_TYPE_MISS) || type.toString().equals(HIT_RESULT_TYPE_BLOCK) || type.toString().equals(HIT_RESULT_TYPE_ENTITY))) {
nglfwSetHitResultType(type.toString());
} else {
nglfwSetHitResultType(HIT_RESULT_TYPE_UNKNOWN);
}
}
}
}
}

View File

@ -0,0 +1,55 @@
package org.lwjgl.glfw;
import static org.lwjgl.system.MemoryUtil.NULL;
import org.lwjgl.system.Callback;
import javax.annotation.Nullable;
public abstract class FCLInjectorCallback extends Callback implements FCLInjectorCallbackI {
public static FCLInjectorCallback create(long functionPointer) {
FCLInjectorCallbackI instance = Callback.get(functionPointer);
return instance instanceof FCLInjectorCallback
? (FCLInjectorCallback)instance
: new Container(functionPointer, instance);
}
/** Like {@link #create(long) create}, but returns {@code null} if {@code functionPointer} is {@code NULL}. */
@Nullable
public static FCLInjectorCallback createSafe(long functionPointer) {
return functionPointer == NULL ? null : create(functionPointer);
}
/** Creates a {@code GLFWCursorEnterCallback} instance that delegates to the specified {@code GLFWCursorEnterCallbackI} instance. */
public static FCLInjectorCallback create(FCLInjectorCallbackI instance) {
return instance instanceof FCLInjectorCallback
? (FCLInjectorCallback)instance
: new Container(instance.address(), instance);
}
protected FCLInjectorCallback() {
super(CIF);
}
FCLInjectorCallback(long functionPointer) {
super(functionPointer);
}
private static final class Container extends FCLInjectorCallback {
private final FCLInjectorCallbackI delegate;
Container(long functionPointer, FCLInjectorCallbackI delegate) {
super(functionPointer);
this.delegate = delegate;
}
@Override
public void invoke() {
delegate.invoke();
}
}
}

View File

@ -0,0 +1,33 @@
package org.lwjgl.glfw;
import static org.lwjgl.system.APIUtil.apiCreateCIF;
import static org.lwjgl.system.libffi.LibFFI.FFI_DEFAULT_ABI;
import static org.lwjgl.system.libffi.LibFFI.ffi_type_pointer;
import static org.lwjgl.system.libffi.LibFFI.ffi_type_uint32;
import static org.lwjgl.system.libffi.LibFFI.ffi_type_void;
import org.lwjgl.system.CallbackI;
import org.lwjgl.system.NativeType;
import org.lwjgl.system.libffi.FFICIF;
@FunctionalInterface
@NativeType("FCLinjectorfun")
public interface FCLInjectorCallbackI extends CallbackI {
FFICIF CIF = apiCreateCIF(
FFI_DEFAULT_ABI,
ffi_type_void,
ffi_type_pointer, ffi_type_uint32
);
@Override
default FFICIF getCallInterface() { return CIF; }
@Override
default void callback(long ret, long args) {
invoke();
}
void invoke();
}

View File

@ -608,7 +608,7 @@ public class GLFW
throw new UnsupportedOperationException();
}
private static final SharedLibrary GLFW = Library.loadNative(GLFW.class, "org.lwjgl.glfw", "libpojavexec.so", true);
public static final SharedLibrary GLFW = Library.loadNative(GLFW.class, "org.lwjgl.glfw", "libpojavexec.so", true);
/** Contains the function pointers loaded from the glfw {@link SharedLibrary}. */
public static final class Functions {
@ -818,6 +818,7 @@ public class GLFW
mGLFWInitialTime = (double) System.nanoTime();
long __functionAddress = Functions.Init;
isGLFWReady = invokeI(__functionAddress) != 0;
FCLInjector.setClassLoader(Thread.currentThread().getContextClassLoader());
}
return isGLFWReady;
}