-
Notifications
You must be signed in to change notification settings - Fork 3
/
Tweak.xm
214 lines (183 loc) · 6.27 KB
/
Tweak.xm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#import <UIKit/UIKit.h>
#include <substrate.h>
//@import UIKit;
@interface SBSystemApertureViewController : UIViewController
@end
#define kHeight [UIScreen mainScreen].bounds.size.width
NSMutableDictionary *MutDiction;
static uint16_t forcePadIdiom = 0;
static Boolean isUseDefault;
static Boolean isHide;
static Boolean isCustomPosition;
static CGFloat valueX;
static CGFloat valueY;
static Boolean isScalePosition;
static CGFloat percent;
static Boolean isCustomAlpha;
static CGFloat valueAlpha;
static Boolean isUpsideDown;
static Boolean isUpsideDownFixedForDynamicIsland;
static Boolean isTransparent;
void loadprefs() {
MutDiction = [[NSMutableDictionary alloc] initWithContentsOfFile:@"/var/mobile/Library/Preferences/com.34306.mineland.plist"];
isUpsideDown = [[MutDiction objectForKey:@"isUpsideDown"] boolValue] ?: FALSE;
isUpsideDownFixedForDynamicIsland = [[MutDiction objectForKey:@"isUpsideDownFixedForDynamicIsland"] boolValue] ?: FALSE;
isUseDefault = [[MutDiction objectForKey:@"isUseDefault"] boolValue] ?: FALSE;
isHide = [[MutDiction objectForKey:@"isHide"] boolValue] ?: FALSE;
isCustomPosition = [[MutDiction objectForKey:@"isCustomPosition"] boolValue] ?: FALSE;
valueX = [[MutDiction objectForKey:@"valueX"] floatValue] ?: 20;
valueY = [[MutDiction objectForKey:@"valueY"] floatValue] ?: 20;
isScalePosition = [[MutDiction objectForKey:@"isScalePosition"] boolValue] ?: FALSE;
percent = [[MutDiction objectForKey:@"percent"] floatValue] ?: 0.065;
isCustomAlpha = [[MutDiction objectForKey:@"isCustomAlpha"] boolValue] ?: FALSE;
valueAlpha = [[MutDiction objectForKey:@"valueAlpha"] floatValue] ?: 0.6;
isTransparent = [[MutDiction objectForKey:@"isTransparent"] boolValue] ?: FALSE;
}
//Upside down part
%hook UIDevice
- (UIUserInterfaceIdiom)userInterfaceIdiom {
if (forcePadIdiom > 0 && isUpsideDown) {
return UIUserInterfaceIdiomPad;
} else {
return %orig;
}
}
%end
%hook SBTraitsSceneParticipantDelegate
// Allow upside down
- (BOOL)_isAllowedToHavePortraitUpsideDown {
if(isUpsideDown){
return YES;
}
return %orig;
}
- (NSInteger)_orientationMode {
forcePadIdiom++;
NSInteger result = %orig;
forcePadIdiom--;
return result;
}
%end
%hook SpringBoard
// Allow landscape Home Screen
- (NSInteger)homeScreenRotationStyle {
if(isUpsideDown){
return 1;
}
return %orig;
}
%end
%hook SBApplication
- (BOOL)isMedusaCapable {
if(isUpsideDown){
return YES;
}
return %orig;
}
%end
// Allow upside down Home Screen
%hook SBHomeScreenViewController
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
if(isUpsideDown){
return %orig | UIInterfaceOrientationMaskPortraitUpsideDown;
}
return %orig;
}
%end
// Allow upside down Lock Screen
%hook SBCoverSheetPrimarySlidingViewController
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
if(isUpsideDown){
return %orig | UIInterfaceOrientationMaskPortraitUpsideDown;
}
return %orig;
}
%end
//Upside down applied for dynamic island
@import UIKit;
@interface UIWindow()
- (void)setAutorotates:(BOOL)autorotates forceUpdateInterfaceOrientation:(BOOL)force;
@end
@interface SBSystemApertureWindow : UIWindow
@end
// SBSystemApertureWindow has a hidden override to always set autorotates to false, we must call super
@implementation SBSystemApertureWindow(hook)
- (void)setAutorotates:(BOOL)autorotates forceUpdateInterfaceOrientation:(BOOL)force {
[super setAutorotates:YES forceUpdateInterfaceOrientation:force];
}
@end
%hook SBSystemApertureController
- (void)_applyOrientation:(UIInterfaceOrientation)orientation withPreviousOrientation:(UIInterfaceOrientation)prevOrientation animationSettings:(id)settings {
if(isUpsideDown && isUpsideDownFixedForDynamicIsland){
UIView *apertureView = MSHookIvar<UIViewController *>(self, "_systemApertureViewController").view;
CGRect frame = apertureView.frame;
if (orientation == UIInterfaceOrientationPortraitUpsideDown) {
orientation = UIInterfaceOrientationPortrait;
// put your code here to reset y offset, for example:
frame = CGRectMake(0, -7, apertureView.frame.size.width, apertureView.frame.size.height);
} else if (orientation == UIInterfaceOrientationPortrait) {
// put your code here to set y offset, for example:
frame = CGRectMake(0, 20, apertureView.frame.size.width, apertureView.frame.size.height);
}
[UIView animateWithDuration:1 animations:^{
apertureView.frame = frame;
}];
%orig;
} else {
%orig;
}
}
%end
// allow upside down
%hook SBSystemApertureCaptureVisibilityShimViewController
- (UIInterfaceOrientationMask)__supportedInterfaceOrientations {
if(isUpsideDown && isUpsideDownFixedForDynamicIsland){
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
}
return %orig;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(NSInteger)orientation {
if(isUpsideDown && isUpsideDownFixedForDynamicIsland){
return YES;
}
return %orig;
}
%end
@interface _SBGainMapView : UIView
@end
%hook _SBGainMapView
- (void)setFrame:(CGRect)frame {
%orig;
if(isHide){
[self removeFromSuperview];
}
}
%end
%hook SBSystemApertureViewController
- (void)viewWillAppear:(BOOL)animated {
%orig;
if(isUseDefault){
self.view.frame = CGRectOffset(self.view.frame, 0, kHeight*0.065);
MSHookIvar<UIView *>(self, "_containerBackgroundParent").alpha = 1.0;
}
else if(isCustomPosition){
self.view.frame = CGRectOffset(self.view.frame, valueX, valueY);
}
else if(isScalePosition){
self.view.frame = CGRectOffset(self.view.frame, 0, kHeight*percent);
}
if(isCustomAlpha){
MSHookIvar<UIView *>(self, "_containerBackgroundParent").alpha = valueAlpha;
}
else if(isTransparent){
MSHookIvar<UIView *>(self, "_containerBackgroundParent").alpha = - 1.0;
}
else {
MSHookIvar<UIView *>(self, "_containerBackgroundParent").alpha = 1.0;
}
}
%end
%ctor {
loadprefs();
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, (CFNotificationCallback)loadprefs, CFSTR("com.34306.mineland.settingschanged"), NULL, CFNotificationSuspensionBehaviorCoalesce);
}