Same keycode names as the on-screen editor to make it easier to identify the possible values. Xbox and PlayStation button names for familiarity. Saving configs handled by the Save and Exit buttons on the navigation bar. Currently known issues: - may be jumpy when cells reload or load onto the screen - loading a new configuration file does not update the value of the cells - loading a new configuration file does not update the "Controller configurator" item in the main Settings window - both of these are solved by closing and reopening the view controller for now
89 lines
2.6 KiB
Objective-C
89 lines
2.6 KiB
Objective-C
#import <Foundation/Foundation.h>
|
|
#import "SurfaceViewController.h"
|
|
#import "ios_uikit_bridge.h"
|
|
#import "utils.h"
|
|
|
|
#include <dlfcn.h>
|
|
#include "external/fishhook/fishhook.h"
|
|
|
|
void (*orig_abort)();
|
|
void* (*orig_dlopen)(const char* path, int mode);
|
|
void (*orig_exit)(int code);
|
|
int (*orig_open)(const char *path, int oflag, ...);
|
|
|
|
void handle_fatal_exit(int code) {
|
|
if (NSThread.isMainThread || !SurfaceViewController.isRunning) {
|
|
return;
|
|
}
|
|
|
|
[SurfaceViewController handleExitCode:code];
|
|
|
|
if (fatalExitGroup != nil) {
|
|
// Likely other threads are crashing, put them to sleep
|
|
sleep(INT_MAX);
|
|
}
|
|
fatalExitGroup = dispatch_group_create();
|
|
dispatch_group_enter(fatalExitGroup);
|
|
dispatch_group_wait(fatalExitGroup, DISPATCH_TIME_FOREVER);
|
|
}
|
|
|
|
void hooked_abort() {
|
|
NSLog(@"abort() called");
|
|
handle_fatal_exit(SIGABRT);
|
|
orig_abort();
|
|
}
|
|
|
|
void* hooked_dlopen(const char* path, int mode) {
|
|
// iOS 12 refuses to dlopen executables, so here we put a workaround
|
|
if (path == NULL || [@(path) hasSuffix:@"/PojavLauncher"]) {
|
|
return orig_dlopen(NULL, mode);
|
|
}
|
|
|
|
if (getenv("POJAV_PREFER_EXTERNAL_JRE") && [@(path) hasSuffix:@"/libawt_xawt.dylib"]) {
|
|
// In this environment, libawt_xawt is not available/X11 only.
|
|
// hook dlopen to use our libawt_xawt
|
|
return orig_dlopen([NSString stringWithFormat:@"%s/Frameworks/libawt_xawt.dylib", getenv("BUNDLE_PATH")].UTF8String, mode);
|
|
}
|
|
|
|
return orig_dlopen(path, mode);
|
|
}
|
|
|
|
void hooked_exit(int code) {
|
|
NSLog(@"exit(%d) called", code);
|
|
if (code == 0) {
|
|
UIKit_returnToSplitView();
|
|
return;
|
|
}
|
|
handle_fatal_exit(code);
|
|
|
|
if (runtimeJavaVMPtr != NULL) {
|
|
(*runtimeJavaVMPtr)->DestroyJavaVM(runtimeJavaVMPtr);
|
|
}
|
|
|
|
UIKit_returnToSplitView();
|
|
}
|
|
|
|
int hooked_open(const char *path, int oflag, ...) {
|
|
va_list args;
|
|
va_start(args, oflag);
|
|
mode_t mode = va_arg(args, int);
|
|
va_end(args);
|
|
if (path && !strcmp(path, "/etc/resolv.conf")) {
|
|
return orig_open([NSString stringWithFormat:@"%s/resolv.conf", getenv("POJAV_HOME")].UTF8String, oflag, mode);
|
|
}
|
|
|
|
return orig_open(path, oflag, mode);
|
|
}
|
|
|
|
void init_hookFunctions() {
|
|
void *orig_dlopen_local;
|
|
rebind_symbols((struct rebinding[4]){
|
|
{"abort", hooked_abort, (void *)&orig_abort},
|
|
{"dlopen", hooked_dlopen, (void *)&orig_dlopen_local},
|
|
{"exit", hooked_exit, (void *)&orig_exit},
|
|
{"open", hooked_open, (void *)&orig_open}
|
|
}, 4);
|
|
// workaround weird pointer overwritten issue in jre 17.0.7
|
|
orig_dlopen = orig_dlopen_local;
|
|
}
|