Skip to content

Commit

Permalink
Merge pull request #57 from jslegendre/fix-menubuilder-swizzle
Browse files Browse the repository at this point in the history
Fix menubuilder swizzle
  • Loading branch information
Depal1 authored Dec 20, 2022
2 parents 2a5a505 + d19c668 commit 2187d6a
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions PlayTools/Controls/PTFakeTouch/NSObject+Swizzle.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,28 @@ - (void) swizzleInstanceMethod:(SEL)origSelector withMethod:(SEL)newSelector

+ (void) load
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
// TODO: UINSview
// TODO: UINSview

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]) {
[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)];
}

[objc_getClass("IOSViewController") swizzleInstanceMethod:@selector(prefersPointerLocked) withMethod:@selector(hook_prefersPointerLocked)];
[self swizzleInstanceMethod:@selector(init) withMethod:@selector(hook_init)];
});
bool menuWasCreated = false;
- (id) initWithRootMenuHook:(id)rootMenu {
self = [self initWithRootMenuHook:rootMenu];
if (!menuWasCreated) {
[PlayCover initMenuWithMenu: self];
menuWasCreated = TRUE;
}

return self;
}

- (BOOL) hook_prefersPointerLocked {
Expand All @@ -78,12 +87,4 @@ - (CGSize) hook_size {
return [PlayScreen sizeAspectRatio:[self hook_size]];
}

- (id) hook_init {
if ([[self class] isEqual: NSClassFromString(@"_UIMenuBuilder")]) {
[PlayCover initMenuWithMenu: self];
}

return self;
}

@end

0 comments on commit 2187d6a

Please sign in to comment.