Skip to content

Commit

Permalink
Proper _UIMenuBuilder swizzle
Browse files Browse the repository at this point in the history
Now the check for _UIMenuBuilder won't happen every single time an object is initialized.  Not only was this terrible for performance, the original hook is most likely the cause of some odd bugs.  For example, the hook may return an initialized object when it should return NULL and thus altering the control flow.  This change also fixes the endless `[MenuBuilder] Duplicates existing --` warnings when attached to a debugger.
  • Loading branch information
jslegendre committed Dec 19, 2022
1 parent 2a5a505 commit 7f09b2b
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions PlayTools/Controls/PTFakeTouch/NSObject+Swizzle.m
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,24 @@ + (void) load
[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)];
[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 {
return false;
}
Expand All @@ -78,12 +90,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 7f09b2b

Please sign in to comment.