Skip to content

Commit

Permalink
Merge pull request #59 from Depal1/fixRegression
Browse files Browse the repository at this point in the history
Change behaviour of the _UIMenuBuilder swizzle
  • Loading branch information
Depal1 committed Dec 22, 2022
2 parents e0bbef0 + 13cd62b commit 9d58e34
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions PlayTools/Controls/PTFakeTouch/NSObject+Swizzle.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,9 @@ + (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)];
}

bool menuWasCreated = false;
- (id) initWithRootMenuHook:(id)rootMenu {
self = [self initWithRootMenuHook:rootMenu];
if (!menuWasCreated) {
[PlayCover initMenuWithMenu: self];
menuWasCreated = TRUE;
}

return self;
[self swizzleInstanceMethod:@selector(init) withMethod:@selector(hook_init)];
}

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

bool menuWasCreated = false;

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

return self;
}
@end

0 comments on commit 9d58e34

Please sign in to comment.