Skip to content

Commit

Permalink
Merge pull request #76 from PlayCover/master
Browse files Browse the repository at this point in the history
ACTUALLY Fix 13.2 Issues (#75)
  • Loading branch information
JoseMoreville committed Jan 30, 2023
2 parents a5cc11c + d8bc7ee commit 65b608f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
25 changes: 25 additions & 0 deletions PlayTools/Controls/PTFakeTouch/NSObject+Swizzle.m
Expand Up @@ -61,10 +61,28 @@ - (CGRect) hook_bounds {
return [PlayScreen bounds:[self hook_bounds]];
}

- (CGRect) hook_nativeBounds {
return [PlayScreen nativeBounds:[self hook_nativeBounds]];
}

- (CGSize) hook_size {
return [PlayScreen sizeAspectRatio:[self hook_size]];
}


- (long long) hook_orientation {
return 0;
}

- (double) hook_nativeScale {
return 2.0;
}

- (double) hook_scale {
return 2.0;
}


bool menuWasCreated = false;
- (id) initWithRootMenuHook:(id)rootMenu {
self = [self initWithRootMenuHook:rootMenu];
Expand Down Expand Up @@ -104,9 +122,16 @@ -(CGRect) hook_frame {
@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)];
}

[objc_getClass("_UIMenuBuilder") swizzleInstanceMethod:sel_getUid("initWithRootMenu:") withMethod:@selector(initWithRootMenuHook:)];
Expand Down
18 changes: 16 additions & 2 deletions PlayTools/PlayScreen.swift
Expand Up @@ -26,6 +26,10 @@ extension CGSize {
return CGSize(width: mainScreenHeight, height: mainScreenWidth)
}
}

func toAspectRatioInternal() -> CGSize {
return CGSize(width: mainScreenHeight, height: mainScreenWidth)
}
}

extension CGRect {
Expand All @@ -37,8 +41,8 @@ extension CGRect {
}
}

func toAspectRatio() -> CGRect {
return CGRect(x: minX, y: minY, width: mainScreenWidth, height: mainScreenHeight)
func toAspectRatio(_ multiplier: CGFloat = 1) -> CGRect {
return CGRect(x: minX, y: minY, width: mainScreenWidth * multiplier, height: mainScreenHeight * multiplier)
}

func toAspectRatioReversed() -> CGRect {
Expand Down Expand Up @@ -76,6 +80,10 @@ public class PlayScreen: NSObject {
return rect.toAspectRatio()
}

@objc public static func nativeBounds(_ rect: CGRect) -> CGRect {
return rect.toAspectRatio(2)
}

@objc public static func width(_ size: Int) -> Int {
return size
}
Expand All @@ -87,6 +95,7 @@ public class PlayScreen: NSObject {
@objc public static func sizeAspectRatio(_ size: CGSize) -> CGSize {
return size.toAspectRatio()
}

var fullscreen: Bool {
return AKInterface.shared!.isFullscreen
}
Expand Down Expand Up @@ -145,18 +154,23 @@ extension CGFloat {
var relativeY: CGFloat {
self / screen.height
}

var relativeX: CGFloat {
self / screen.width
}

var relativeSize: CGFloat {
self / screen.percent
}

var absoluteSize: CGFloat {
self * screen.percent
}

var absoluteX: CGFloat {
self * screen.width
}

var absoluteY: CGFloat {
self * screen.height
}
Expand Down

0 comments on commit 65b608f

Please sign in to comment.