Skip to content

Commit

Permalink
Add option to force Medusa for landscape-only
Browse files Browse the repository at this point in the history
games; Fix truncated app name in app switcher;
Revert home button iPhone workaround"
  • Loading branch information
khanhduytran0 committed Mar 11, 2024
1 parent cb43a44 commit 3628470
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 9 deletions.
17 changes: 17 additions & 0 deletions SpringBoard.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#import <UIKit/UIKit.h>

@interface SBApplicationInfo : NSObject
@property(assign, nonatomic) UIInterfaceOrientationMask supportedInterfaceOrientations;
@end

@interface SBApplication : NSObject
@property(nonatomic, readonly) SBApplicationInfo *info;
@end

@interface SBAppSwitcherSettings : NSObject
@property(assign) CGFloat spacingBetweenLeadingEdgeAndIcon, spacingBetweenTrailingEdgeAndLabels;
@end

@interface SBExternalDisplayRuntimeAvailabilitySettings : NSObject
@property(nonatomic, assign) BOOL requirePointer, requireHardwareKeyboard;
@end
2 changes: 1 addition & 1 deletion TPPrefsObserver.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#import <Foundation/Foundation.h>

@interface TPPrefsObserver : NSObject
@property(nonatomic, assign) BOOL allowLandscapeHomeScreen, useiPadAppSwitchingAnimation;
@property(nonatomic, assign) BOOL allowLandscapeHomeScreen, forceEnableMedusaForLandscapeOnlyApps, useiPadAppSwitchingAnimation;
@end
2 changes: 2 additions & 0 deletions TPPrefsObserver.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ @implementation TPPrefsObserver
- (instancetype)init {
self = [super init];
[self observeKey:@"TPAllowLandscapeHomeScreen"];
[self observeKey:@"TPForceEnableMedusaForLandscapeOnlyApps"];
[self observeKey:@"TPUseiPadAppSwitchingAnimation"];
// Fetch keys
[self observeValueForKeyPath:nil ofObject:nil change:nil context:nil];
Expand All @@ -21,6 +22,7 @@ - (void)observeValueForKeyPath:(NSString *)
keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
NSUserDefaults *defaults = NSUserDefaults.standardUserDefaults;
self.allowLandscapeHomeScreen = [defaults boolForKey:@"TPAllowLandscapeHomeScreen"];
self.forceEnableMedusaForLandscapeOnlyApps = [defaults boolForKey:@"TPForceEnableMedusaForLandscapeOnlyApps"];
self.useiPadAppSwitchingAnimation = [defaults boolForKey:@"TPUseiPadAppSwitchingAnimation"];
}
@end
12 changes: 12 additions & 0 deletions TrollPadPrefs/Resources/Root.plist
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,18 @@
<key>label</key>
<string>Miscellaneous</string>
</dict>
<dict>
<key>cell</key>
<string>PSSwitchCell</string>
<key>default</key>
<false/>
<key>defaults</key>
<string>com.apple.springboard</string>
<key>key</key>
<string>TPForceEnableMedusaForLandscapeOnlyApps</string>
<key>label</key>
<string>Allow enable Medusa for games</string>
</dict>
<dict>
<key>cell</key>
<string>PSSwitchCell</string>
Expand Down
24 changes: 16 additions & 8 deletions TweakSB.x
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <objc/runtime.h>
#import "SpringBoard.h"
#import "TPPrefsObserver.h"

#include <assert.h>
Expand Down Expand Up @@ -118,9 +119,9 @@ static uint16_t forcePadIdiom = 0;
%end

// Workaround for iPhones with home button not being able to open Control Center
%hook BSPlatform
- (NSInteger)homeButtonType {
return 2;
%hook SBHomeGestureSettings
- (BOOL)isHomeGestureEnabled {
return YES;
}
%end
%hook SBControlCenterController
Expand All @@ -136,6 +137,15 @@ static uint16_t forcePadIdiom = 0;
}
%end

// Fix truncated app name in app switcher
%hook SBAppSwitcherSettings
- (void)setDefaultValues {
%orig;
self.spacingBetweenLeadingEdgeAndIcon = 0;
self.spacingBetweenTrailingEdgeAndLabels = 0;
}
%end

%hook UIApplication
- (id)_defaultSupportedInterfaceOrientations {
forcePadIdiom++;
Expand Down Expand Up @@ -184,7 +194,8 @@ static uint16_t forcePadIdiom = 0;

%hook SBApplication
- (BOOL)isMedusaCapable {
return YES;
return pref.forceEnableMedusaForLandscapeOnlyApps ||
(self.info.supportedInterfaceOrientations & UIInterfaceOrientationMaskPortrait) != 0;
}

- (BOOL)_supportsApplicationType:(int)arg1 {
Expand Down Expand Up @@ -217,9 +228,6 @@ BOOL hookedExtDisplayEnabledFunc(){
}

// Bypass Keyboard & Mouse requirement
@interface SBExternalDisplayRuntimeAvailabilitySettings : NSObject
@property(nonatomic, assign) BOOL requirePointer, requireHardwareKeyboard;
@end
%hook SBExternalDisplayRuntimeAvailabilitySettings
- (void)setDefaultValues {
self.requireHardwareKeyboard = NO;
Expand All @@ -246,7 +254,7 @@ BOOL MGGetBoolAnswer(NSString* property);
extDisplayEnabledFunc = dlsym(sbFoundationHandle, "SBFIsChamoisExternalDisplayControllerAvailable");
}
if (extDisplayEnabledFunc) {
MSHookFunction(extDisplayEnabledFunc, hookedExtDisplayEnabledFunc, NULL);
MSHookFunction((void *)extDisplayEnabledFunc, (void *)hookedExtDisplayEnabledFunc, NULL);
}

pref = [TPPrefsObserver new];
Expand Down

0 comments on commit 3628470

Please sign in to comment.