From 893f90d361ffd0a39cc2d617d34d3a106911f51b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Moreno?= <47700212+JoseMoreville@users.noreply.github.com> Date: Tue, 14 Feb 2023 19:02:12 -0700 Subject: [PATCH] Fix: Default app size now shows normally and other Adaptive fixes plus responsive fix on default (#77) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix for default screen * Code cleanup * setting @objc to scene control vars * PR to make default size work correctly (#1) * Reverting cleanup * Testing removing new scaling methods for default * Revert to new methods for testing * Setting orientation to 1 * 4 * commenting suspect stuff * 12 * sd * removing FBS * test * returning back to normal * Test * a * test * x * a * a * a * as * 1 * as * así * aa * as * Change names * testing something * testing 2 * more test * 12 * return * 123 * Testing defaults and auto fix * Testing c * is this ready? * test * 1 * returning adaptive * Delete PlayScreenDefault.swift * Update project.pbxproj Removing All references to PlayScreenDefault.swift * Adds fix for some apps with adaptive display enabled (#3) * testing changing to default bounds * Update project.pbxproj (#2) Removing All references to PlayScreenDefault.swift * test 2 * rest * test * as * asd * test * 123 * Adding inverseScreenValues to settings * Reduced code and added ternaries * added else when inverseScreenValues is false (might rework * Adds MacOSVersion to plist and a 'fix' for screen issue (#4) * testing changing to default bounds * Update project.pbxproj (#2) Removing All references to PlayScreenDefault.swift * test 2 * rest * test * as * asd * test * 123 * Adding inverseScreenValues to settings * Reduced code and added ternaries * added else when inverseScreenValues is false (might rework * Test to fix pre MacOS 13.2 * Check this out * Using float instead of string * v2 * test * lets see * adding print * NSLog(@"macOS version: %f", [[PlaySettings shared] macOSVersion]); * [[PlaySettings shared] macOSVersion] rounded * adding 00000 to every float * testing * return back to normal double * Forgot about floating point error * more than 13.1 * more * 13.199 * setting to latest macOS version * more floating error and macOS fixes * reduced lines and fix some errors * Update project.pbxproj * Update project.pbxproj * Update PlaySettings.swift * Enables responsiveness for some apps for default screen settings if toggle enabled (#5) * test disabling FBSDisplayMode * disabling FBS * Adding experimental fix toggle to fix responsiveness * adding an extra log * extra * moving the function to a better place * back to another place * added CheckResizabilityHasRun * Testing some stuff * name issue * added some comments to test * added fuction stop * True to yes * Changed yes to no * adding observer for resize * adding chess * test * back again * Removing extra check for a future commit * changed macos check to ios check * Remove macOSVersion --- PlayTools.xcodeproj/project.pbxproj | 8 +- .../Controls/PTFakeTouch/NSObject+Swizzle.m | 93 ++++++++++++++++--- PlayTools/PlayLoader.m | 2 + PlayTools/PlayScreen.swift | 40 +++++++- PlayTools/PlaySettings.swift | 7 +- 5 files changed, 129 insertions(+), 21 deletions(-) diff --git a/PlayTools.xcodeproj/project.pbxproj b/PlayTools.xcodeproj/project.pbxproj index e25d9dc2..8c455222 100644 --- a/PlayTools.xcodeproj/project.pbxproj +++ b/PlayTools.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 2847AE48298EFC0F00B0F983 /* PlayScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2847AE47298EFC0F00B0F983 /* PlayScreen.swift */; }; 6E76639B28D0FAE700DE4AF9 /* Plugin.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E76639A28D0FAE700DE4AF9 /* Plugin.swift */; }; 6E76639C28D0FAE700DE4AF9 /* Plugin.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E76639A28D0FAE700DE4AF9 /* Plugin.swift */; }; 6E7663A128D0FB5300DE4AF9 /* AKPlugin.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E7663A028D0FB5300DE4AF9 /* AKPlugin.swift */; }; @@ -14,7 +15,6 @@ 6E84A14528D0F94E00BF7495 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AA818CBA287ABFD5000BEE9D /* UIKit.framework */; }; 6E84A15028D0F97500BF7495 /* AKInterface.bundle in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 6E84A14C28D0F96D00BF7495 /* AKInterface.bundle */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; AA71970B287A44D200623C15 /* PlayLoader.m in Sources */ = {isa = PBXBuildFile; fileRef = AA719702287A44D200623C15 /* PlayLoader.m */; }; - AA71970C287A44D200623C15 /* PlayScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA719703287A44D200623C15 /* PlayScreen.swift */; }; AA71970D287A44D200623C15 /* PlaySettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA719704287A44D200623C15 /* PlaySettings.swift */; }; AA71970E287A44D200623C15 /* PlayLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = AA719705287A44D200623C15 /* PlayLoader.h */; }; AA71970F287A44D200623C15 /* PlayCover.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA719706287A44D200623C15 /* PlayCover.swift */; }; @@ -67,6 +67,7 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 2847AE47298EFC0F00B0F983 /* PlayScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayScreen.swift; sourceTree = ""; }; 6E76639628D0FA6200DE4AF9 /* AKInterface-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "AKInterface-Bridging-Header.h"; sourceTree = ""; }; 6E76639A28D0FAE700DE4AF9 /* Plugin.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Plugin.swift; sourceTree = ""; }; 6E7663A028D0FB5300DE4AF9 /* AKPlugin.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AKPlugin.swift; sourceTree = ""; }; @@ -74,7 +75,6 @@ 6E84A14C28D0F96D00BF7495 /* AKInterface.bundle */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = AKInterface.bundle; sourceTree = BUILT_PRODUCTS_DIR; }; AA7196D8287A447700623C15 /* PlayTools.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = PlayTools.framework; sourceTree = BUILT_PRODUCTS_DIR; }; AA719702287A44D200623C15 /* PlayLoader.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PlayLoader.m; sourceTree = ""; }; - AA719703287A44D200623C15 /* PlayScreen.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PlayScreen.swift; sourceTree = ""; }; AA719704287A44D200623C15 /* PlaySettings.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PlaySettings.swift; sourceTree = ""; }; AA719705287A44D200623C15 /* PlayLoader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlayLoader.h; sourceTree = ""; }; AA719706287A44D200623C15 /* PlayCover.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PlayCover.swift; sourceTree = ""; }; @@ -175,11 +175,11 @@ AA719791287A481500623C15 /* Utils */, AA71970A287A44D200623C15 /* Info.plist */, AA719706287A44D200623C15 /* PlayCover.swift */, - AA719703287A44D200623C15 /* PlayScreen.swift */, AA719704287A44D200623C15 /* PlaySettings.swift */, AA719705287A44D200623C15 /* PlayLoader.h */, AA719702287A44D200623C15 /* PlayLoader.m */, AA719708287A44D200623C15 /* PlayTools.h */, + 2847AE47298EFC0F00B0F983 /* PlayScreen.swift */, ); path = PlayTools; sourceTree = ""; @@ -445,6 +445,7 @@ AA71970D287A44D200623C15 /* PlaySettings.swift in Sources */, AA719759287A480D00623C15 /* PlayAction.swift in Sources */, 6E7663A528D0FEBE00DE4AF9 /* AKPluginLoader.swift in Sources */, + 2847AE48298EFC0F00B0F983 /* PlayScreen.swift in Sources */, AA7197A2287A481500623C15 /* CircleMenu.swift in Sources */, AA71978B287A480D00623C15 /* MenuController.swift in Sources */, AA7197AA287A481500623C15 /* Toast.swift in Sources */, @@ -457,7 +458,6 @@ AA7197A3287A481500623C15 /* CircleMenuButton.swift in Sources */, AA7197A9287A481500623C15 /* PlayInfo.swift in Sources */, AA71986A287A81A000623C15 /* PTFakeMetaTouch.m in Sources */, - AA71970C287A44D200623C15 /* PlayScreen.swift in Sources */, ABCECEE629750BA600746595 /* PlayedApple.swift in Sources */, AA71986C287A81A000623C15 /* NSObject+Swizzle.m in Sources */, AA71970F287A44D200623C15 /* PlayCover.swift in Sources */, diff --git a/PlayTools/Controls/PTFakeTouch/NSObject+Swizzle.m b/PlayTools/Controls/PTFakeTouch/NSObject+Swizzle.m index 63873578..13b0de40 100644 --- a/PlayTools/Controls/PTFakeTouch/NSObject+Swizzle.m +++ b/PlayTools/Controls/PTFakeTouch/NSObject+Swizzle.m @@ -53,6 +53,23 @@ - (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]]; } @@ -70,6 +87,7 @@ - (CGSize) hook_size { } + - (long long) hook_orientation { return 0; } @@ -82,6 +100,16 @@ - (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; + +} + + bool menuWasCreated = false; - (id) initWithRootMenuHook:(id)rootMenu { @@ -119,21 +147,62 @@ -(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 { - 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)]; + // 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)]; + } } - + [objc_getClass("_UIMenuBuilder") swizzleInstanceMethod:sel_getUid("initWithRootMenu:") withMethod:@selector(initWithRootMenuHook:)]; [objc_getClass("IOSViewController") swizzleInstanceMethod:@selector(prefersPointerLocked) withMethod:@selector(hook_prefersPointerLocked)]; } diff --git a/PlayTools/PlayLoader.m b/PlayTools/PlayLoader.m index f4089391..92887d97 100644 --- a/PlayTools/PlayLoader.m +++ b/PlayTools/PlayLoader.m @@ -27,6 +27,7 @@ static int pt_uname(struct utsname *uts) { return 0; } + // Update output of sysctl for key values hw.machine, hw.product and hw.target to match iOS output // This spoofs the device type to apps allowing us to report as any iOS device static int pt_sysctl(int *name, u_int types, void *buf, size_t *size, void *arg0, size_t arg1) { @@ -163,6 +164,7 @@ static OSStatus pt_SecItemDelete(CFDictionaryRef query) { DYLD_INTERPOSE(pt_SecItemDelete, SecItemDelete) + @implementation PlayLoader static void __attribute__((constructor)) initialize(void) { diff --git a/PlayTools/PlayScreen.swift b/PlayTools/PlayScreen.swift index cefacb51..47bc4ff6 100644 --- a/PlayTools/PlayScreen.swift +++ b/PlayTools/PlayScreen.swift @@ -2,13 +2,13 @@ // ScreenController.swift // PlayTools // - import Foundation import UIKit let screen = PlayScreen.shared -let mainScreenWidth = PlaySettings.shared.windowSizeWidth -let mainScreenHeight = PlaySettings.shared.windowSizeHeight +let isInvertFixEnabled = PlaySettings.shared.inverseScreenValues && PlaySettings.shared.adaptiveDisplay +let mainScreenWidth = !isInvertFixEnabled ? PlaySettings.shared.windowSizeWidth : PlaySettings.shared.windowSizeHeight +let mainScreenHeight = !isInvertFixEnabled ? PlaySettings.shared.windowSizeHeight : PlaySettings.shared.windowSizeWidth extension CGSize { func aspectRatio() -> CGFloat { @@ -30,6 +30,12 @@ extension CGSize { func toAspectRatioInternal() -> CGSize { return CGSize(width: mainScreenHeight, height: mainScreenWidth) } + func toAspectRatioDefault() -> CGSize { + return CGSize(width: mainScreenHeight, height: mainScreenWidth) + } + func toAspectRatioInternalDefault() -> CGSize { + return CGSize(width: mainScreenWidth, height: mainScreenHeight) + } } extension CGRect { @@ -48,6 +54,12 @@ extension CGRect { func toAspectRatioReversed() -> CGRect { return CGRect(x: minX, y: minY, width: mainScreenHeight, height: mainScreenWidth) } + func toAspectRatioDefault(_ multiplier: CGFloat = 1) -> CGRect { + return CGRect(x: minX, y: minY, width: mainScreenWidth * multiplier, height: mainScreenHeight * multiplier) + } + func toAspectRatioReversedDefault() -> CGRect { + return CGRect(x: minX, y: minY, width: mainScreenHeight, height: mainScreenWidth) + } } extension UIScreen { @@ -148,6 +160,28 @@ public class PlayScreen: NSObject { AKInterface.shared!.setMenuBarVisible(visible) } + // Default calculation + @objc public static func frameReversedDefault(_ rect: CGRect) -> CGRect { + return rect.toAspectRatioReversedDefault() + } + @objc public static func frameDefault(_ rect: CGRect) -> CGRect { + return rect.toAspectRatioDefault() + } + @objc public static func boundsDefault(_ rect: CGRect) -> CGRect { + return rect.toAspectRatioDefault() + } + + @objc public static func nativeBoundsDefault(_ rect: CGRect) -> CGRect { + return rect.toAspectRatioDefault(2) + } + + @objc public static func sizeAspectRatioDefault(_ size: CGSize) -> CGSize { + return size.toAspectRatioDefault() + } + @objc public static func frameInternalDefault(_ rect: CGRect) -> CGRect { + return rect.toAspectRatioDefault() + } + } extension CGFloat { diff --git a/PlayTools/PlaySettings.swift b/PlayTools/PlaySettings.swift index 0f95eab6..f425bb87 100644 --- a/PlayTools/PlaySettings.swift +++ b/PlayTools/PlaySettings.swift @@ -33,9 +33,11 @@ let settings = PlaySettings.shared lazy var sensitivity = settingsData.sensitivity / 100 - lazy var windowSizeHeight = CGFloat(settingsData.windowHeight) + @objc lazy var windowSizeHeight = CGFloat(settingsData.windowHeight) - lazy var windowSizeWidth = CGFloat(settingsData.windowWidth) + @objc lazy var windowSizeWidth = CGFloat(settingsData.windowWidth) + + @objc lazy var inverseScreenValues = settingsData.inverseScreenValues @objc lazy var adaptiveDisplay = settingsData.resolution == 0 ? false : true @@ -82,4 +84,5 @@ struct AppSettingsData: Codable { var version = "2.0.0" var playChain = false var playChainDebugging = false + var inverseScreenValues = false }