diff --git a/JavaApp/src/main/java/org/lwjgl/glfw/CallbackBridge.java b/JavaApp/src/main/java/org/lwjgl/glfw/CallbackBridge.java index 2ed6f9d5..a7cc2e0b 100644 --- a/JavaApp/src/main/java/org/lwjgl/glfw/CallbackBridge.java +++ b/JavaApp/src/main/java/org/lwjgl/glfw/CallbackBridge.java @@ -212,11 +212,8 @@ public class CallbackBridge { inputReady = ready; return true; } - public static String nativeClipboard(int action, String copy) { - // TODO copy paste - return ""; - } + public static native String nativeClipboard(int action, String copy); private static native void nativeSetGrabbing(boolean grab, int xset, int yset); } diff --git a/Natives/CMakeLists.txt b/Natives/CMakeLists.txt index 4f311ced..d406c5c3 100644 --- a/Natives/CMakeLists.txt +++ b/Natives/CMakeLists.txt @@ -13,7 +13,7 @@ set_target_properties(PojavLauncher PROPERTIES MACOSX_FRAMEWORK_IDENTIFIER org.cmake.ExecutableTarget MACOSX_BUNDLE_INFO_PLIST "../Info.plist") -add_library(pojavexec SHARED log.m AppDelegate.m SceneDelegate.m UILauncher.m LauncherViewController.m LoginViewController.m SurfaceViewController.m egl_bridge_ios.m ios_uikit_bridge.m customcontrols/ControlButton.m egl_bridge.c input_bridge_v3.c utils.c) +add_library(pojavexec SHARED log.m AppDelegate.m SceneDelegate.m UILauncher.m LauncherViewController.m LauncherPreferencesViewController.m LoginViewController.m SurfaceViewController.m egl_bridge_ios.m ios_uikit_bridge.m customcontrols/ControlButton.m egl_bridge.c input_bridge_v3.c utils.c) target_link_libraries(pojavexec "-Fresources/Frameworks" "-framework UIKit" diff --git a/Natives/JavaLauncher.c b/Natives/JavaLauncher.c index e26c43ab..6154c929 100644 --- a/Natives/JavaLauncher.c +++ b/Natives/JavaLauncher.c @@ -16,8 +16,8 @@ #include "JavaLauncher.h" // PojavLancher: fixme: are these wrong? -#define FULL_VERSION "1.16.0-internal" -#define DOT_VERSION "1.16" +#define FULL_VERSION "1.8.0-internal" +#define DOT_VERSION "1.8" static const char *java_libs_dir = "/Applications/PojavLauncher.app/libs"; static const char *args_path = "/var/mobile/Documents/.pojavlauncher/overrideargs.txt"; diff --git a/Natives/LauncherPreferencesViewController.h b/Natives/LauncherPreferencesViewController.h new file mode 100644 index 00000000..1a0309eb --- /dev/null +++ b/Natives/LauncherPreferencesViewController.h @@ -0,0 +1,23 @@ +#import + +@interface LauncherPreferencesViewController : UIViewController + +@end + + + +/* + +void LauncherPreferences_load() { + +} + +void LauncherPreferences_save() { + +} + +void LauncherPreferences_change(char* key, char* value) { + +} + +*/ diff --git a/Natives/LauncherPreferencesViewController.m b/Natives/LauncherPreferencesViewController.m new file mode 100644 index 00000000..5c2eb8e8 --- /dev/null +++ b/Natives/LauncherPreferencesViewController.m @@ -0,0 +1,79 @@ +#import "LauncherPreferencesViewController.h" + +#include "utils.h" + +@interface LauncherPreferencesViewController () { +} + +// - (void)method + +@end + +@implementation LauncherPreferencesViewController + +UITextField* versionTextField; + +- (void)viewDidLoad +{ + [super viewDidLoad]; + + [self setNeedsUpdateOfScreenEdgesDeferringSystemGestures]; + [self setNeedsUpdateOfHomeIndicatorAutoHidden]; + + [self setTitle:@"Launcher preferences"]; + + CGRect screenBounds = [[UIScreen mainScreen] bounds]; + CGFloat screenScale = [[UIScreen mainScreen] scale]; + + int width = (int) roundf(screenBounds.size.width); + int height = (int) roundf(screenBounds.size.height) - self.navigationController.navigationBar.frame.size.height; + + UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:self.view.frame]; + [self.view addSubview:scrollView]; + scrollView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; + + // Update color mode once + if(@available(iOS 13.0, *)) { + [self traitCollectionDidChange:nil]; + } else { + self.view.backgroundColor = [UIColor whiteColor]; + } + +// not yet finished, empty view controller for now +/* + UILabel *btnsizeTextView = [[UILabel alloc] initWithFrame:CGRectMake(4.0, 4.0, 0.0, 30.0)]; + btnsizeTextView.text = @"Button size: "; + btnsizeTextView.numberOfLines = 0; + [btnsizeTextView sizeToFit]; + [scrollView addSubview:btnsizeTextView]; + + UISlider *buttonSizeSlider = [[UISlider alloc] initWithFrame:CGRectMake(8.0 + btnsizeTextView.frame.x, 4.0, 200.0, 30.0)]; + // [buttonSizeSlider addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventValueChanged]; + [buttonSizeSlider setBackgroundColor:[UIColor clearColor]]; + buttonSizeSlider.minimumValue = 50.0; + buttonSizeSlider.maximumValue = 200.0; + buttonSizeSlider.continuous = YES; + buttonSizeSlider.value = 50.0; + [scrollView addSubview:buttonSizeSlider]; +*/ +} + +- (UIRectEdge)preferredScreenEdgesDeferringSystemGestures { + return UIRectEdgeAll; +} + +- (BOOL)prefersHomeIndicatorAutoHidden { + return NO; +} + +-(void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection { + if(@available(iOS 13.0, *)) { + if (UITraitCollection.currentTraitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) { + self.view.backgroundColor = [UIColor blackColor]; + } else { + self.view.backgroundColor = [UIColor whiteColor]; + } + } +} + +@end diff --git a/Natives/LauncherViewController.m b/Natives/LauncherViewController.m index dbfae3e2..35f9aced 100644 --- a/Natives/LauncherViewController.m +++ b/Natives/LauncherViewController.m @@ -1,4 +1,5 @@ #import "LauncherViewController.h" +#import "LauncherPreferencesViewController.h" #include "utils.h" @@ -30,7 +31,8 @@ UITextField* versionTextField; int width = (int) roundf(screenBounds.size.width); int height = (int) roundf(screenBounds.size.height) - self.navigationController.navigationBar.frame.size.height; - UIScrollView *scrollView = self.view = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, width, height)]; + UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:self.view.frame]; + [self.view addSubview:scrollView]; scrollView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; // Update color mode once @@ -58,11 +60,16 @@ UITextField* versionTextField; fclose(configver_file); [scrollView addSubview:versionTextField]; + UIButton *preferences_button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; + [preferences_button setTitle:@"Settings" forState:UIControlStateNormal]; + preferences_button.frame = CGRectMake(10.0, height - 108.0, 100.0, 50.0); + [preferences_button addTarget:self action:@selector(enterPreferences) forControlEvents:UIControlEventTouchUpInside]; + [scrollView addSubview:preferences_button]; + install_progress_bar = [[UIProgressView alloc] initWithFrame:CGRectMake(4.0, height - 58.0, width - 8.0, 6.0)]; [scrollView addSubview:install_progress_bar]; install_button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; - install_button.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleWidth; [install_button setTitle:@"Play" forState:UIControlStateNormal]; install_button.frame = CGRectMake(10.0, height - 54.0, 100.0, 50.0); [install_button addTarget:self action:@selector(launchMinecraft:) forControlEvents:UIControlEventTouchUpInside]; @@ -80,7 +87,7 @@ UITextField* versionTextField; return NO; } --(void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection API_AVAILABLE(ios(13.0)) { +-(void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection { if(@available(iOS 13.0, *)) { if (UITraitCollection.currentTraitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) { self.view.backgroundColor = [UIColor blackColor]; @@ -98,4 +105,10 @@ UITextField* versionTextField; callback_LauncherViewController_installMinecraft(); } +- (void)enterPreferences +{ + LauncherPreferencesViewController *vc = [[LauncherPreferencesViewController alloc] init]; + [self.navigationController pushViewController:vc animated:YES]; +} + @end diff --git a/Natives/LoginViewController.h b/Natives/LoginViewController.h index 5ccc2117..2e475e9a 100644 --- a/Natives/LoginViewController.h +++ b/Natives/LoginViewController.h @@ -1,7 +1,7 @@ #import @interface LoginViewController : UIViewController -- (void)enterLauncher; + @end @interface LoginListViewController : UITableViewController diff --git a/Natives/LoginViewController.m b/Natives/LoginViewController.m index 35cbfb01..1c87d6d6 100644 --- a/Natives/LoginViewController.m +++ b/Natives/LoginViewController.m @@ -123,7 +123,7 @@ void loginAccountInput(UINavigationController *controller, int type, const char* return NO; } -- (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection API_AVAILABLE(ios(13.0)) { +- (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection { if(@available(iOS 13.0, *)) { if (UITraitCollection.currentTraitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) { self.view.backgroundColor = [UIColor blackColor]; @@ -246,7 +246,7 @@ void loginAccountInput(UINavigationController *controller, int type, const char* NSString *jsonString = [NSString stringWithFormat:@"{\"agent\": {\"name\": \"Minecraft\", \"version\": 1}, \"username\": \"%@\", \"password\": \"%@\", \"clientToken\": \"%@\"}", input_username, input_password, input_uuid]; // NSLog(jsonString); [request setValue:[NSString stringWithFormat:@"%d", - [jsonString length]] forHTTPHeaderField:@"Content-length"]; + (int) [jsonString length]] forHTTPHeaderField:@"Content-length"]; [request setHTTPBody:[jsonString dataUsingEncoding:NSUTF8StringEncoding]]; NSURLSessionDataTask *postDataTask = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { @@ -290,7 +290,7 @@ void loginAccountInput(UINavigationController *controller, int type, const char* #pragma mark - ASWebAuthenticationPresentationContextProviding - (ASPresentationAnchor)presentationAnchorForWebAuthenticationSession:(ASWebAuthenticationSession *)session API_AVAILABLE(ios(13.0)){ - return UIApplication.sharedApplication.keyWindow; + return UIApplication.sharedApplication.windows.firstObject; } @end diff --git a/Natives/SurfaceViewController.m b/Natives/SurfaceViewController.m index b4a8aab9..f3af8179 100644 --- a/Natives/SurfaceViewController.m +++ b/Natives/SurfaceViewController.m @@ -35,8 +35,6 @@ togglableVisibleButtons[++togglableVisibleButtonIndex] = button_##KEY; \ } -#define BTN_RECT 80.0, 30.0 -#define BTN_SQUARE 50.0, 50.0 #define INPUT_SPACE_CHAR @" " #define INPUT_SPACE_LENGTH 20 @@ -55,7 +53,7 @@ int notchOffset; // TODO: key modifiers impl -@interface SurfaceViewController () { +@interface SurfaceViewController () { } @property (strong, nonatomic) MGLContext *context; @@ -76,7 +74,7 @@ int notchOffset; CGRect screenBounds = [[UIScreen mainScreen] bounds]; CGFloat screenScale = [[UIScreen mainScreen] scale]; - UIEdgeInsets insets = [[[UIApplication sharedApplication] keyWindow] safeAreaInsets]; + UIEdgeInsets insets = UIApplication.sharedApplication.windows.firstObject.safeAreaInsets; int width = (int) roundf(screenBounds.size.width); int height = (int) roundf(screenBounds.size.height); @@ -84,8 +82,9 @@ int notchOffset; savedWidth = roundf(width * screenScale); savedHeight = roundf(height * screenScale); - width = width - insets.left - insets.right; - notchOffset = insets.left; + // get both left and right for just in case orientation is changed + notchOffset = insets.left + insets.right; + width = width - notchOffset * 2; touchView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, width, height)]; @@ -114,15 +113,19 @@ int notchOffset; mouseWheelGesture.delaysTouchesEnded = NO; [touchView addGestureRecognizer:mouseWheelGesture]; } - + + CGFloat rectBtnWidth = 80.0; + CGFloat rectBtnHeight = 30.0; + CGFloat squareBtnSize = 50.0; + #ifndef DEBUG_VISIBLE_TEXT_FIELD - inputView = [[UITextField alloc] initWithFrame:CGRectMake(5 * 3 + 80 * 2, 5, BTN_RECT)]; + inputView = [[UITextField alloc] initWithFrame:CGRectMake(5 * 3 + rectBtnWidth * 2, 5, rectBtnWidth, rectBtnHeight)]; inputView.backgroundColor = [UIColor colorWithWhite:0.0f alpha:0.0f]; #else - inputView = [[UITextField alloc] initWithFrame:CGRectMake(5 * 3 + 80 * 2, 5 * 2 + 30, 200, 30)]; + inputView = [[UITextField alloc] initWithFrame:CGRectMake(5 * 3 + rectBtnWidth * 2, 5 * 2 + rectBtnHeight, 200, rectBtnHeight)]; inputView.backgroundColor = [UIColor colorWithWhite:0.0f alpha:0.5f]; - inputLengthView = [[UILabel alloc] initWithFrame:CGRectMake(5 * 2 + 80, 5 * 2 + 30, BTN_RECT)]; + inputLengthView = [[UILabel alloc] initWithFrame:CGRectMake(5 * 2 + rectBtnWidth, 5 * 2 + rectBtnHeight, rectBtnWidth, rectBtnHeight)]; inputLengthView.text = @"length=?"; inputLengthView.backgroundColor = [UIColor colorWithWhite:1.0f alpha:0.6f]; [self.view addSubview:inputLengthView]; @@ -178,31 +181,31 @@ int notchOffset; } if (cc_fallback == YES) { - ADD_BUTTON(@"GUI", SPECIALBTN_TOGGLECTRL, CGRectMake(5, height - 5 - 50, BTN_SQUARE), NO); - ADD_BUTTON(@"Keyboard", SPECIALBTN_KEYBOARD, CGRectMake(5 * 3 + 80 * 2, 5, BTN_RECT), YES); + ADD_BUTTON(@"GUI", SPECIALBTN_TOGGLECTRL, CGRectMake(5, height - 5 - 50, squareBtnSize, squareBtnSize), NO); + ADD_BUTTON(@"Keyboard", SPECIALBTN_KEYBOARD, CGRectMake(5 * 3 + rectBtnWidth * 2, 5, rectBtnWidth, rectBtnHeight), YES); - ADD_BUTTON(@"Pri", SPECIALBTN_MOUSEPRI, CGRectMake(5, height - 5 * 3 - 50 * 3, BTN_SQUARE), YES); - ADD_BUTTON(@"Sec", SPECIALBTN_MOUSESEC, CGRectMake(5 * 3 + 50 * 2, height - 5 * 3 - 50 * 3, BTN_SQUARE), YES); + ADD_BUTTON(@"Pri", SPECIALBTN_MOUSEPRI, CGRectMake(5, height - 5 * 3 - 50 * 3, squareBtnSize, squareBtnSize), YES); + ADD_BUTTON(@"Sec", SPECIALBTN_MOUSESEC, CGRectMake(5 * 3 + 50 * 2, height - 5 * 3 - 50 * 3, squareBtnSize, squareBtnSize), YES); - ADD_BUTTON(@"Debug", GLFW_KEY_F3, CGRectMake(5, 5, BTN_RECT), YES); - ADD_BUTTON(@"Chat", GLFW_KEY_T, CGRectMake(5 * 2 + 80, 5, BTN_RECT), YES); - ADD_BUTTON(@"Tab", GLFW_KEY_TAB, CGRectMake(5 * 4 + 80 * 3, 5, BTN_RECT), YES); - ADD_BUTTON(@"Opti-Zoom", GLFW_KEY_C, CGRectMake(5 * 5 + 80 * 4, 5, BTN_RECT), YES); - ADD_BUTTON(@"Offhand", GLFW_KEY_F, CGRectMake(5 * 6 + 80 * 5, 5, BTN_RECT), YES); - ADD_BUTTON(@"3rd", GLFW_KEY_F5, CGRectMake(5, 5 * 2 + 30.0, BTN_RECT), YES); + ADD_BUTTON(@"Debug", GLFW_KEY_F3, CGRectMake(5, 5, rectBtnWidth, rectBtnHeight), YES); + ADD_BUTTON(@"Chat", GLFW_KEY_T, CGRectMake(5 * 2 + rectBtnWidth, 5, rectBtnWidth, rectBtnHeight), YES); + ADD_BUTTON(@"Tab", GLFW_KEY_TAB, CGRectMake(5 * 4 + rectBtnWidth * 3, 5, rectBtnWidth, rectBtnHeight), YES); + ADD_BUTTON(@"Opti-Zoom", GLFW_KEY_C, CGRectMake(5 * 5 + rectBtnWidth * 4, 5, rectBtnWidth, rectBtnHeight), YES); + ADD_BUTTON(@"Offhand", GLFW_KEY_F, CGRectMake(5 * 6 + rectBtnWidth * 5, 5, rectBtnWidth, rectBtnHeight), YES); + ADD_BUTTON(@"3rd", GLFW_KEY_F5, CGRectMake(5, 5 * 2 + rectBtnHeight, rectBtnWidth, rectBtnHeight), YES); - ADD_BUTTON(@"▲", GLFW_KEY_W, CGRectMake(5 * 2 + 50, height - 5 * 3 - 50 * 3, BTN_SQUARE), YES); - ADD_BUTTON(@"◀", GLFW_KEY_A, CGRectMake(5, height - 5 * 2 - 50 * 2, BTN_SQUARE), YES); - ADD_BUTTON(@"▼", GLFW_KEY_S, CGRectMake(5 * 2 + 50, height - 5 - 50, BTN_SQUARE), YES); - ADD_BUTTON(@"▶", GLFW_KEY_D, CGRectMake(5 * 3 + 50 * 2, height - 5 * 2 - 50 * 2, BTN_SQUARE), YES); - ADD_BUTTON(@"◇", GLFW_KEY_LEFT_SHIFT, CGRectMake(5 * 2 + 50, height - 5 * 2 - 50 * 2, BTN_SQUARE), YES); - ADD_BUTTON(@"Inv", GLFW_KEY_E, CGRectMake(5 * 3 + 50 * 2, height - 5 - 50, BTN_SQUARE), YES); + ADD_BUTTON(@"▲", GLFW_KEY_W, CGRectMake(5 * 2 + 50, height - 5 * 3 - 50 * 3, squareBtnSize, squareBtnSize), YES); + ADD_BUTTON(@"◀", GLFW_KEY_A, CGRectMake(5, height - 5 * 2 - 50 * 2, squareBtnSize, squareBtnSize), YES); + ADD_BUTTON(@"▼", GLFW_KEY_S, CGRectMake(5 * 2 + 50, height - 5 - 50, squareBtnSize, squareBtnSize), YES); + ADD_BUTTON(@"▶", GLFW_KEY_D, CGRectMake(5 * 3 + 50 * 2, height - 5 * 2 - 50 * 2, squareBtnSize, squareBtnSize), YES); + ADD_BUTTON(@"◇", GLFW_KEY_LEFT_SHIFT, CGRectMake(5 * 2 + 50, height - 5 * 2 - 50 * 2, squareBtnSize, squareBtnSize), YES); + ADD_BUTTON(@"Inv", GLFW_KEY_E, CGRectMake(5 * 3 + 50 * 2, height - 5 - 50, squareBtnSize, squareBtnSize), YES); - ADD_BUTTON(@"⬛", GLFW_KEY_SPACE, CGRectMake(width - 5 * 2 - 50 * 2, height - 5 * 2 - 50 * 2, BTN_SQUARE), YES); + ADD_BUTTON(@"⬛", GLFW_KEY_SPACE, CGRectMake(width - 5 * 2 - 50 * 2, height - 5 * 2 - 50 * 2, squareBtnSize, squareBtnSize), YES); - ADD_BUTTON(@"Esc", GLFW_KEY_ESCAPE, CGRectMake(width - 5 - 80, height - 5 - 30, BTN_RECT), YES); + ADD_BUTTON(@"Esc", GLFW_KEY_ESCAPE, CGRectMake(width - 5 - rectBtnWidth, height - 5 - rectBtnHeight, rectBtnWidth, rectBtnHeight), YES); - // ADD_BUTTON(@"Fullscreen", f11, CGRectMake(width - 5 - 80, 5, BTN_RECT), YES); + // ADD_BUTTON(@"Fullscreen", f11, CGRectMake(width - 5 - rectBtnWidth, 5, rectBtnWidth, rectBtnHeight), YES); } [self.view addSubview:inputView]; @@ -432,7 +435,7 @@ BOOL isNotifRemoved; if (sender.state == UIGestureRecognizerStateBegan || sender.state == UIGestureRecognizerStateChanged || sender.state == UIGestureRecognizerStateEnded) { - CGPoint velocity = [sender velocityInView:self]; + CGPoint velocity = [sender velocityInView:self.view]; if (velocity.x > 0.0f) { velocity.x = -1.0; @@ -458,7 +461,7 @@ BOOL isNotifRemoved; point.x -= origin.x; point.y -= origin.y; - NSLog(@"UIPointerInteraction pos changed: x=%d, y=%d", point.x, point.y); + NSLog(@"UIPointerInteraction pos changed: x=%d, y=%d", (int) point.x, (int) point.y); // TODO FIXME callback_SurfaceViewController_onTouch(ACTION_DOWN, (int)point.x, (int)point.y); diff --git a/Natives/aminimake.sh b/Natives/aminimake.sh index 6aaf99e3..dd9c8b21 100644 --- a/Natives/aminimake.sh +++ b/Natives/aminimake.sh @@ -5,10 +5,28 @@ #!/bin/bash set -e -CFLAGS="-fmessage-length=0 -fdiagnostics-show-note-include-stack -fmacro-backtrace-limit=0 -Wno-trigraphs -fpascal-strings -O3 -miphoneos-version-min=12.0 -Wno-missing-field-initializers -Wno-missing-prototypes -Wno-return-type -Wno-missing-braces -Wparentheses -Wswitch -Wno-unused-function -Wno-unused-label -Wno-unused-parameter -Wno-unused-variable -Wunused-value -Wno-empty-body -Wno-uninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion -Wno-constant-conversion -Wno-int-conversion -Wno-bool-conversion -Wno-enum-conversion -Wno-float-conversion -Wno-non-literal-null-conversion -Wno-objc-literal-conversion -Wshorten-64-to-32 -Wpointer-sign -Wno-newline-eof -Wl,-rpath,/Applications/PojavLauncher.app/Frameworks -fobjc-arc -x objective-c -Fresources/Frameworks -Iresources/Frameworks/MetalANGLE.framework/Headers -isysroot /var/mobile/theos/sdks/iPhoneOS13.4.sdk" +CFLAGS="-Wl,-rpath,/Applications/PojavLauncher.app/Frameworks -fobjc-arc -x objective-c -Fresources/Frameworks -Iresources/Frameworks/MetalANGLE.framework/Headers -isysroot /var/mobile/theos/sdks/iPhoneOS13.4.sdk" clang -framework UIKit $CFLAGS -o PojavLauncher main.c log.m JavaLauncher.c -clang -framework UIKit -framework MetalANGLE -framework CoreGraphics -framework AuthenticationServices -dynamiclib $CFLAGS -o libpojavexec.dylib log.m AppDelegate.m SceneDelegate.m UILauncher.m LauncherViewController.m LoginViewController.m SurfaceViewController.m egl_bridge_ios.m ios_uikit_bridge.m customcontrols/ControlButton.m egl_bridge.c input_bridge_v3.c utils.c -DGLES_TESTZ -DUSE_EGLZ -Wl,-undefined,dynamic_lookup +clang -framework UIKit -framework MetalANGLE -framework CoreGraphics -framework AuthenticationServices \ + -dynamiclib $CFLAGS -o libpojavexec.dylib \ + log.m \ + AppDelegate.m \ + SceneDelegate.m \ + UILauncher.m \ + LauncherViewController.m \ + LauncherPreferencesViewController.m \ + LoginViewController.m \ + SurfaceViewController.m \ + egl_bridge_ios.m \ + ios_uikit_bridge.m \ + customcontrols/ControlButton.m \ + egl_bridge.c \ + input_bridge_v3.c \ + utils.c \ +\ + -DGLES_TESTZ -DUSE_EGLZ +# -Wl,-undefined,dynamic_lookup ldid -S../entitlements.xml PojavLauncher ldid -S../entitlements.xml libpojavexec.dylib diff --git a/Natives/customcontrols/ControlButton.m b/Natives/customcontrols/ControlButton.m index c64d070e..b1906930 100644 --- a/Natives/customcontrols/ControlButton.m +++ b/Natives/customcontrols/ControlButton.m @@ -49,7 +49,7 @@ - (float)insertDynamicPos:(NSString*)string { CGRect screenBounds = [[UIScreen mainScreen] bounds]; CGFloat screenScale = 2.0; // [[UIScreen mainScreen] scale]; - UIEdgeInsets insets = [[[UIApplication sharedApplication] keyWindow] safeAreaInsets]; + UIEdgeInsets insets = UIApplication.sharedApplication.windows.firstObject.safeAreaInsets; // width: offset the notch parts int screenWidth = (int) roundf((screenBounds.size.width - insets.left - insets.right) * screenScale); @@ -80,7 +80,7 @@ // net/kdt/pojavlaunch/customcontrols/ControlData.update() float screenScale = (float) 2.0; // [[UIScreen mainScreen] scale]; - UIEdgeInsets insets = [[[UIApplication sharedApplication] keyWindow] safeAreaInsets]; + UIEdgeInsets insets = UIApplication.sharedApplication.windows.firstObject.safeAreaInsets; NSString *propDynamicX = (NSString *) [self.properties valueForKey:@"dynamicX"]; NSString *propDynamicY = (NSString *) [self.properties valueForKey:@"dynamicY"]; diff --git a/Natives/egl_bridge.c b/Natives/egl_bridge.c index 382bd150..3827347c 100644 --- a/Natives/egl_bridge.c +++ b/Natives/egl_bridge.c @@ -80,7 +80,7 @@ void terminateEgl() { } JNIEXPORT jlong JNICALL Java_org_lwjgl_glfw_GLFW_nativeEglGetCurrentContext(JNIEnv* env, jclass clazz) { - return eglGetCurrentContext(); + return (jlong) eglGetCurrentContext(); } static const EGLint ctx_attribs[] = { @@ -164,7 +164,7 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_glfw_GLFW_nativeEglInit(JNIEnv* env, j JNIEXPORT jboolean JNICALL Java_org_lwjgl_glfw_GLFW_nativeEglMakeCurrent(JNIEnv* env, jclass clazz, jlong window) { if (window != 0x1) { - debug("Making current on window %p", window); + debug("Making current on window %llx", window); EGLBoolean success; #ifdef USE_EGL success = eglMakeCurrent( @@ -178,7 +178,7 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_glfw_GLFW_nativeEglMakeCurrent(JNIEnv* #endif if (success == EGL_FALSE) { - debug("Error: eglMakeCurrent() failed: %p", eglGetError()); + debug("Error: eglMakeCurrent() failed: %x", eglGetError()); } debug("EGLBridge: Trigger an initial swapBuffers"); @@ -189,7 +189,7 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_glfw_GLFW_nativeEglMakeCurrent(JNIEnv* glClearColor(0.4f, 0.4f, 0.4f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); eglSwapBuffers(potatoBridge.eglDisplay, potatoBridge.eglSurface); - debug("First frame error: %p", eglGetError()); + debug("First frame error: %x", eglGetError()); #endif if (success == EGL_TRUE) { GL4ES_HANDLE = dlopen(getenv("POJAV_OPENGL_LIBNAME"), RTLD_GLOBAL); @@ -208,7 +208,7 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_glfw_GLFW_nativeEglMakeCurrent(JNIEnv* return success == EGL_TRUE ? JNI_TRUE : JNI_FALSE; } else { (*env)->ThrowNew(env,(*env)->FindClass(env,"java/lang/Exception"),"Trace exception"); - //return JNI_TRUE; + return JNI_FALSE; } } @@ -221,7 +221,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_glfw_GLFW_nativeEglDetachOnCurrentThread(J } JNIEXPORT jlong JNICALL Java_org_lwjgl_glfw_GLFW_nativeEglCreateContext(JNIEnv *env, jclass clazz, jlong contextSrc) { - EGLContext* ctx; + void* ctx; if (contextSrc == 0) { #ifdef USE_EGL EGLint numConfigs; @@ -233,16 +233,16 @@ JNIEXPORT jlong JNICALL Java_org_lwjgl_glfw_GLFW_nativeEglCreateContext(JNIEnv * assert(result != EGL_FALSE ); config = configs[0]; - ctx = eglCreateContext(potatoBridge.eglDisplay, config,(void*)potatoBridge.eglContext, ctx_attribs); + ctx = (void*) eglCreateContext(potatoBridge.eglDisplay, config, (void*)potatoBridge.eglContext, ctx_attribs); - debug("Created CTX pointer=%p, shareCtx=%p, error=%p", ctx, potatoBridge.eglContext, eglGetError()); + debug("Created CTX pointer=%p, shareCtx=%x, error=%x", ctx, potatoBridge.eglContext, eglGetError()); #else - ctx = potatoBridge.eglContext; + ctx = (void*) potatoBridge.eglContext; debug("Using CTX pointer=%p, shareCtx=NULL", ctx); #endif } else { - ctx = eglCreateContext(potatoBridge.eglDisplay,config,(void*)contextSrc,ctx_attribs); - debug("Created CTX pointer=%p, shareCtx=%p, error=%p", ctx, contextSrc, eglGetError()); + ctx = (void*) eglCreateContext(potatoBridge.eglDisplay,config,(void*)contextSrc,ctx_attribs); + debug("Created CTX pointer=%p, shareCtx=%p, error=%x", ctx, (void*)contextSrc, eglGetError()); } //(*env)->ThrowNew(env,(*env)->FindClass(env,"java/lang/Exception"),"Trace exception"); return (long)ctx; @@ -265,7 +265,7 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_glfw_GLFW_nativeEglSwapBuffers(JNIEnv if (!result) { EGLint error = eglGetError(); - debug("eglSwapBuffers error: %p", error); + debug("eglSwapBuffers error: %x", error); if (error == EGL_BAD_SURFACE) { stopMakeCurrent = true; closeGLFWWindow(); diff --git a/Natives/input_bridge_v3.c b/Natives/input_bridge_v3.c index 6d18e227..8f375df2 100644 --- a/Natives/input_bridge_v3.c +++ b/Natives/input_bridge_v3.c @@ -6,7 +6,7 @@ * - Works with some bugs: * + Modded versions gives broken stuff.. * - * + * TODO: * - Implements glfwSetCursorPos() to handle grab camera pos correctly. */ @@ -287,17 +287,9 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeAttachThread return result; } -JNIEXPORT jstring JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeClipboard(JNIEnv* env, jclass clazz, jint action, jstring copy) { -#ifdef DEBUG - LOGD("Debug: Clipboard access is going on\n", isUseStackQueueCall); -#endif - // TODO: if crash here, then convert jstring to jstring (diff JVM) - jclass bridgeClazz = (*dalvikJNIEnvPtr_JRE)->FindClass(dalvikJNIEnvPtr_JRE, "org/lwjgl/glfw/CallbackBridge"); - assert(bridgeClazz != NULL); - jmethodID bridgeMethod = (*dalvikJNIEnvPtr_JRE)->GetStaticMethodID(dalvikJNIEnvPtr_JRE, bridgeClazz, "accessAndroidClipboard", "(ILjava/lang/String;)Ljava/lang/String;"); - assert(bridgeMethod != NULL); - - return (jstring) (*dalvikJNIEnvPtr_JRE)->CallStaticObjectMethod(dalvikJNIEnvPtr_JRE, bridgeClazz, bridgeMethod, action, copy); +JNIEXPORT jstring JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeClipboard(JNIEnv* env, jclass clazz, jint action, jstring copySrc) { + DEBUG_LOGD("Debug: Clipboard access is going on\n"); + return UIKit_accessClipboard(env, copySrc); } JNIEXPORT jboolean JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSetInputReady(JNIEnv* env, jclass clazz, jboolean inputReady) { @@ -326,7 +318,7 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSendChar(JNI if (isUseStackQueueCall) { sendData(EVENT_TYPE_CHAR, codepoint, 0, 0, 0); } else { - GLFW_invoke_Char(showingWindow, (unsigned int) codepoint); + GLFW_invoke_Char((void*) showingWindow, (unsigned int) codepoint); // return lwjgl2_triggerCharEvent(codepoint); } return JNI_TRUE; @@ -339,7 +331,7 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSendCharMods if (isUseStackQueueCall) { sendData(EVENT_TYPE_CHAR_MODS, (unsigned int) codepoint, mods, 0, 0); } else { - GLFW_invoke_CharMods(showingWindow, codepoint, mods); + GLFW_invoke_CharMods((void*) showingWindow, codepoint, mods); } return JNI_TRUE; } @@ -360,7 +352,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSendCursorPos(JN if (isUseStackQueueCall) { sendData(EVENT_TYPE_CURSOR_ENTER, 1, 0, 0, 0); } else { - GLFW_invoke_CursorEnter(showingWindow, 1); + GLFW_invoke_CursorEnter((void*) showingWindow, 1); } } else if (isGrabbing) { // Some Minecraft versions does not use GLFWCursorEnterCallback @@ -385,7 +377,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSendCursorPos(JN } if (!isUseStackQueueCall) { - GLFW_invoke_CursorPos(showingWindow, (double) (x), (double) (y)); + GLFW_invoke_CursorPos((void*) showingWindow, (double) (x), (double) (y)); } else { sendData(EVENT_TYPE_CURSOR_POS, (isGrabbing ? grabCursorX : x), (isGrabbing ? grabCursorY : y), 0, 0); } @@ -400,7 +392,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSendKey(JNIEnv* if (isUseStackQueueCall) { sendData(EVENT_TYPE_KEY, key, scancode, action, mods); } else { - GLFW_invoke_Key(showingWindow, key, scancode, action, mods); + GLFW_invoke_Key((void*) showingWindow, key, scancode, action, mods); } } } @@ -423,7 +415,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSendMouseButton( if (isUseStackQueueCall) { sendData(EVENT_TYPE_MOUSE_BUTTON, button, action, mods, 0); } else { - GLFW_invoke_MouseButton(showingWindow, button, action, mods); + GLFW_invoke_MouseButton((void*) showingWindow, button, action, mods); } } } @@ -438,7 +430,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSendScreenSize(J if (isUseStackQueueCall) { sendData(EVENT_TYPE_FRAMEBUFFER_SIZE, width, height, 0, 0); } else { - GLFW_invoke_FramebufferSize(showingWindow, width, height); + GLFW_invoke_FramebufferSize((void*) showingWindow, width, height); } } @@ -446,7 +438,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSendScreenSize(J if (isUseStackQueueCall) { sendData(EVENT_TYPE_WINDOW_SIZE, width, height, 0, 0); } else { - GLFW_invoke_WindowSize(showingWindow, width, height); + GLFW_invoke_WindowSize((void*) showingWindow, width, height); } } } @@ -459,7 +451,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSendScroll(JNIEn if (isUseStackQueueCall) { sendData(EVENT_TYPE_SCROLL, xoffset, yoffset, 0, 0); } else { - GLFW_invoke_Scroll(showingWindow, (double) xoffset, (double) yoffset); + GLFW_invoke_Scroll((void*) showingWindow, (double) xoffset, (double) yoffset); } } } @@ -469,7 +461,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSendWindowPos(JN if (isUseStackQueueCall) { sendData(EVENT_TYPE_WINDOW_POS, x, y, 0, 0); } else { - GLFW_invoke_WindowPos(showingWindow, x, y); + GLFW_invoke_WindowPos((void*) showingWindow, x, y); } } } diff --git a/Natives/ios_uikit_bridge.h b/Natives/ios_uikit_bridge.h index 1e24c19f..2f443470 100644 --- a/Natives/ios_uikit_bridge.h +++ b/Natives/ios_uikit_bridge.h @@ -3,6 +3,7 @@ #include "jni.h" void showDialog(UIViewController *viewController, NSString* title, NSString* message); +jstring UIKit_accessClipboard(JNIEnv* env, jstring copySrc); jboolean UIKit_updateProgress(float progress, const char* message); void UIKit_launchMinecraftSurfaceVC(); void UIKit_setButtonSkippable(); diff --git a/Natives/ios_uikit_bridge.m b/Natives/ios_uikit_bridge.m index d47bb1be..9178c12b 100644 --- a/Natives/ios_uikit_bridge.m +++ b/Natives/ios_uikit_bridge.m @@ -66,7 +66,7 @@ dispatch_async(dispatch_get_main_queue(), ^{ UIAlertAction* copyAction = [UIAlertAction actionWithTitle:@"Copy" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { - [[UIPasteboard generalPasteboard] setString:@(message_c)]; + UIPasteboard.generalPasteboard.string = @(message_c); (*env)->ReleaseStringUTFChars(env, message, message_c); if (exitIfOk == JNI_TRUE) { exit(-1); @@ -80,6 +80,19 @@ dispatch_async(dispatch_get_main_queue(), ^{ }); } +jstring UIKit_accessClipboard(JNIEnv* env, jstring copySrc) { + if (copySrc == NULL && UIPasteboard.generalPasteboard.hasStrings) { + // paste request + return (*env)->NewStringUTF(env, [UIPasteboard.generalPasteboard.string UTF8String]); + } else { + // copy request + const char* copySrcC = (*env)->GetStringUTFChars(env, copySrc, 0); + UIPasteboard.generalPasteboard.string = @(copySrcC); + (*env)->ReleaseStringUTFChars(env, copySrc, copySrcC); + return NULL; + } +} + jboolean UIKit_updateProgress(float progress, const char* message) { dispatch_async(dispatch_get_main_queue(), ^{ install_progress_bar.progress = progress; diff --git a/Natives/log.h b/Natives/log.h index 39bb644a..5d27a8cb 100644 --- a/Natives/log.h +++ b/Natives/log.h @@ -9,6 +9,18 @@ extern "C" { #define LOGI(...) printf(__VA_ARGS__) #define LOGD(...) printf(__VA_ARGS__) +#ifdef DEBUG +# define DEBUG_LOGE(...) LOGE(__VA_ARGS__) +# define DEBUG_LOGW(...) LOGW(__VA_ARGS__) +# define DEBUG_LOGI(...) LOGI(__VA_ARGS__) +# define DEBUG_LOGD(...) LOGD(__VA_ARGS__) +#else +# define DEBUG_LOGE(...) +# define DEBUG_LOGW(...) +# define DEBUG_LOGI(...) +# define DEBUG_LOGD(...) +#endif + void debug(const char *message, ...) __attribute__((format(printf, 1, 2))); #ifdef __cplusplus diff --git a/Natives/main.c b/Natives/main.c index 9116e0f3..41cfd4de 100644 --- a/Natives/main.c +++ b/Natives/main.c @@ -6,10 +6,11 @@ int main(int argc, char * argv[]) { if (getppid() != 1) { // Not running from launchd, so UI won't work. printf("ERROR: ppid was %d\n", getppid()); - printf("ERROR: UIKit could not be connected when run on command line! Please run from home screen instead. If you didn't see PojavLauncher on home screen, run this command:\n"); + printf("ERROR: UIKit is unavailable when run on command line! Please run from home screen instead. If you didn't see PojavLauncher on home screen, run this command:\n"); printf("uicache -p /Applications/PojavLauncher.app\n"); return -1; } launchJVM(argc, argv); + return 0; } diff --git a/Natives/utils.c b/Natives/utils.c index 57574c5c..42cf378f 100644 --- a/Natives/utils.c +++ b/Natives/utils.c @@ -46,6 +46,17 @@ void free_char_array(JNIEnv *env, jobjectArray jstringArray, const char **charAr } } +jstring convertStringJVM(JNIEnv* srcEnv, JNIEnv* dstEnv, jstring srcStr) { + if (srcStr == NULL) { + return NULL; + } + + const char* srcStrC = (*srcEnv)->GetStringUTFChars(srcEnv, srcStr, 0); + jstring dstStr = (*dstEnv)->NewStringUTF(dstEnv, srcStrC); + (*srcEnv)->ReleaseStringUTFChars(srcEnv, srcStr, srcStrC); + return dstStr; +} + JNIEXPORT void JNICALL Java_net_kdt_pojavlaunch_utils_JREUtils_setupBridgeSurfaceAWT(JNIEnv *env, jclass clazz, jlong surface) { shared_awt_surface = surface; } diff --git a/Natives/utils.h b/Natives/utils.h index c2836781..d364d887 100644 --- a/Natives/utils.h +++ b/Natives/utils.h @@ -40,6 +40,7 @@ jboolean attachThread(bool isAndroid, JNIEnv** secondJNIEnvPtr); char** convert_to_char_array(JNIEnv *env, jobjectArray jstringArray); 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 sendData(int type, int i1, int i2, int i3, int i4);