From 13cd62bd1a54f50bf723793592f1704228eca579 Mon Sep 17 00:00:00 2001 From: Depal1 <47154119+Depal1@users.noreply.github.com> Date: Thu, 22 Dec 2022 00:08:36 -0600 Subject: [PATCH] Change behaviour of the _UIMenuBuilder swizzle --- .../Controls/PTFakeTouch/NSObject+Swizzle.m | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/PlayTools/Controls/PTFakeTouch/NSObject+Swizzle.m b/PlayTools/Controls/PTFakeTouch/NSObject+Swizzle.m index 42e6fa5f..0c432746 100644 --- a/PlayTools/Controls/PTFakeTouch/NSObject+Swizzle.m +++ b/PlayTools/Controls/PTFakeTouch/NSObject+Swizzle.m @@ -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 { @@ -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