From edfc1fe27b3f7bb507862a8556a9e9f273da727e Mon Sep 17 00:00:00 2001 From: ohaiibuzzle <23693150+ohaiibuzzle@users.noreply.github.com> Date: Tue, 7 Feb 2023 18:15:21 +0700 Subject: [PATCH] fix: void out unavailable VSS calls --- .../Controls/PTFakeTouch/NSObject+Swizzle.m | 93 +++---------------- 1 file changed, 12 insertions(+), 81 deletions(-) diff --git a/PlayTools/Controls/PTFakeTouch/NSObject+Swizzle.m b/PlayTools/Controls/PTFakeTouch/NSObject+Swizzle.m index e6614c6c..99e0012b 100644 --- a/PlayTools/Controls/PTFakeTouch/NSObject+Swizzle.m +++ b/PlayTools/Controls/PTFakeTouch/NSObject+Swizzle.m @@ -54,23 +54,6 @@ - (BOOL) hook_prefersPointerLocked { return false; } -- (CGRect) hook_frameDefault { - return [PlayScreen frameDefault:[self hook_frameDefault]]; -} - -- (CGRect) hook_boundsDefault { - return [PlayScreen boundsDefault:[self hook_boundsDefault]]; -} - -- (CGRect) hook_nativeBoundsDefault { - return [PlayScreen nativeBoundsDefault:[self hook_nativeBoundsDefault]]; -} - -- (CGSize) hook_sizeDelfault { - return [PlayScreen sizeAspectRatioDefault:[self hook_sizeDelfault]]; -} - - - (CGRect) hook_frame { return [PlayScreen frame:[self hook_frame]]; } @@ -88,7 +71,6 @@ - (CGSize) hook_size { } - - (long long) hook_orientation { return 0; } @@ -101,16 +83,6 @@ - (double) hook_scale { return 2.0; } -- (double) get_default_height { - return [[UIScreen mainScreen] bounds].size.height; - -} -- (double) get_default_width { - return [[UIScreen mainScreen] bounds].size.width; - -} - - - (void) hook_setCurrentSubscription:(VSSubscription *)currentSubscription { // do nothing } @@ -152,62 +124,21 @@ -(CGRect) hook_frame { However, doing this would require generating @interface declarations (either with class-dump or by hand) which would add a lot of code and complexity. I'm not sure this trade-off is "worth it", at least at the time of writing. */ - @implementation PTSwizzleLoader + (void)load { - // This might need refactor soon - if(@available(iOS 16.3, *)) { - if ([[PlaySettings shared] adaptiveDisplay]) { - // This is an experimental fix - if ([[PlaySettings shared] inverseScreenValues]) { - // This lines set External Scene settings and other IOS10 Runtime services by swizzling - [objc_getClass("FBSSceneSettings") swizzleInstanceMethod:@selector(frame) withMethod:@selector(hook_frameDefault)]; - [objc_getClass("FBSSceneSettings") swizzleInstanceMethod:@selector(bounds) withMethod:@selector(hook_boundsDefault)]; - [objc_getClass("FBSDisplayMode") swizzleInstanceMethod:@selector(size) withMethod:@selector(hook_sizeDelfault)]; - - // Fixes Apple mess at MacOS 13.2 - [objc_getClass("UIDevice") swizzleInstanceMethod:@selector(orientation) withMethod:@selector(hook_orientation)]; - [objc_getClass("UIScreen") swizzleInstanceMethod:@selector(nativeBounds) withMethod:@selector(hook_nativeBoundsDefault)]; - [objc_getClass("UIScreen") swizzleInstanceMethod:@selector(nativeScale) withMethod:@selector(hook_nativeScale)]; - [objc_getClass("UIScreen") swizzleInstanceMethod:@selector(scale) withMethod:@selector(hook_scale)]; - } else { - // This acutally runs when adaptiveDisplay is normally triggered - [objc_getClass("FBSSceneSettings") swizzleInstanceMethod:@selector(frame) withMethod:@selector(hook_frame)]; - [objc_getClass("FBSSceneSettings") swizzleInstanceMethod:@selector(bounds) withMethod:@selector(hook_bounds)]; - [objc_getClass("FBSDisplayMode") swizzleInstanceMethod:@selector(size) withMethod:@selector(hook_size)]; - - [objc_getClass("UIDevice") swizzleInstanceMethod:@selector(orientation) withMethod:@selector(hook_orientation)]; - [objc_getClass("UIScreen") swizzleInstanceMethod:@selector(nativeBounds) withMethod:@selector(hook_nativeBounds)]; - [objc_getClass("UIScreen") swizzleInstanceMethod:@selector(nativeScale) withMethod:@selector(hook_nativeScale)]; - [objc_getClass("UIScreen") swizzleInstanceMethod:@selector(scale) withMethod:@selector(hook_scale)]; - } - } - else { - CGFloat newValueW = (CGFloat) [self get_default_width]; - [[PlaySettings shared] setValue:@(newValueW) forKey:@"windowSizeWidth"]; - - CGFloat newValueH = (CGFloat)[self get_default_height]; - [[PlaySettings shared] setValue:@(newValueH) forKey:@"windowSizeHeight"]; - if (![[PlaySettings shared] inverseScreenValues]) { - [objc_getClass("FBSSceneSettings") swizzleInstanceMethod:@selector(frame) withMethod:@selector(hook_frameDefault)]; - [objc_getClass("FBSSceneSettings") swizzleInstanceMethod:@selector(bounds) withMethod:@selector(hook_boundsDefault)]; - [objc_getClass("FBSDisplayMode") swizzleInstanceMethod:@selector(size) withMethod:@selector(hook_sizeDelfault)]; - } - [objc_getClass("UIDevice") swizzleInstanceMethod:@selector(orientation) withMethod:@selector(hook_orientation)]; - [objc_getClass("UIScreen") swizzleInstanceMethod:@selector(nativeBounds) withMethod:@selector(hook_nativeBoundsDefault)]; - - [objc_getClass("UIScreen") swizzleInstanceMethod:@selector(nativeScale) withMethod:@selector(hook_nativeScale)]; - [objc_getClass("UIScreen") swizzleInstanceMethod:@selector(scale) withMethod:@selector(hook_scale)]; - } - } - else { - if ([[PlaySettings shared] adaptiveDisplay]) { - [objc_getClass("FBSSceneSettings") swizzleInstanceMethod:@selector(frame) withMethod:@selector(hook_frame)]; - [objc_getClass("FBSSceneSettings") swizzleInstanceMethod:@selector(bounds) withMethod:@selector(hook_bounds)]; - [objc_getClass("FBSDisplayMode") swizzleInstanceMethod:@selector(size) withMethod:@selector(hook_size)]; - } + if ([[PlaySettings shared] adaptiveDisplay]) { + // This lines set external Scene (frame and those things) settings and other IOS10 Runtime services by swizzling + [objc_getClass("FBSSceneSettings") swizzleInstanceMethod:@selector(frame) withMethod:@selector(hook_frame)]; + [objc_getClass("FBSSceneSettings") swizzleInstanceMethod:@selector(bounds) withMethod:@selector(hook_bounds)]; + [objc_getClass("FBSDisplayMode") swizzleInstanceMethod:@selector(size) withMethod:@selector(hook_size)]; + + // This actually fixes Apple mess at MacOS 13.2 + [objc_getClass("UIDevice") swizzleInstanceMethod:@selector(orientation) withMethod:@selector(hook_orientation)]; + [objc_getClass("UIScreen") swizzleInstanceMethod:@selector(nativeBounds) withMethod:@selector(hook_nativeBounds)]; + [objc_getClass("UIScreen") swizzleInstanceMethod:@selector(nativeScale) withMethod:@selector(hook_nativeScale)]; + [objc_getClass("UIScreen") swizzleInstanceMethod:@selector(scale) withMethod:@selector(hook_scale)]; } - + [objc_getClass("_UIMenuBuilder") swizzleInstanceMethod:sel_getUid("initWithRootMenu:") withMethod:@selector(initWithRootMenuHook:)]; [objc_getClass("IOSViewController") swizzleInstanceMethod:@selector(prefersPointerLocked) withMethod:@selector(hook_prefersPointerLocked)];