Skip to content

Commit

Permalink
fix: void out unavailable VSS calls
Browse files Browse the repository at this point in the history
  • Loading branch information
ohaiibuzzle authored and IsaacMarovitz committed May 8, 2023
1 parent b70a41c commit edfc1fe
Showing 1 changed file with 12 additions and 81 deletions.
93 changes: 12 additions & 81 deletions PlayTools/Controls/PTFakeTouch/NSObject+Swizzle.m
Original file line number Diff line number Diff line change
Expand Up @@ -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]];
}
Expand All @@ -88,7 +71,6 @@ - (CGSize) hook_size {
}



- (long long) hook_orientation {
return 0;
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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)];

Expand Down

0 comments on commit edfc1fe

Please sign in to comment.