-
Notifications
You must be signed in to change notification settings - Fork 3
/
Tweak.x
425 lines (379 loc) · 14.6 KB
/
Tweak.x
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
#import "Youup.h"
%hook CSFullscreenNotificationViewController
- (void)loadView {
%orig;
if (Enabled) {
// You up - Custom UIView:
[YPView removeFromSuperview];
numberOfTries = 0;
YPView = [[UIView alloc] initWithFrame:CGRectMake(0,0,
[[UIScreen mainScreen] bounds].size.width,
[[UIScreen mainScreen] bounds].size.height
)];
[self.view addSubview:YPView];
[[NSNotificationCenter defaultCenter]
postNotificationName:@"com.1di4r.youup/disable"
object:self];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissKeyboard)];
[YPView addGestureRecognizer:tap];
// BlurEffect:
if (!CC) {
UIVisualEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
UIVisualEffectView *visualEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
visualEffectView.frame = YPView.bounds;
[YPView addSubview:visualEffectView];
}else{
UIColor *selectedBG = LCPParseColorString(BGS, @"#000000");
[YPView setBackgroundColor:selectedBG];
}
// CurrentTime:
NSDate *date = [NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"h:mm"];
NSString *dateString = [dateFormatter stringFromDate:date];
UILabel *dateLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 210, 60)];
dateLabel.font = [UIFont systemFontOfSize:80];
if (!CC) {
dateLabel.textColor = [UIColor whiteColor];
}else{
UIColor *selectedCK = LCPParseColorString(CKS, @"#ffffff");
dateLabel.textColor = selectedCK;
}
dateLabel.textAlignment = NSTextAlignmentCenter;
[dateLabel setCenter:CGPointMake(self.view.center.x, 155)];
[dateLabel setText:dateString];
[YPView addSubview:dateLabel];
// Setting Up the Equation:
NSMutableArray *s = [NSMutableArray new]; // Symbols
if (Addition) [s addObject:@"+"];
if (Subtraction) [s addObject:@"-"];
if (Multiplication) [s addObject:@"*"];
if (Division) [s addObject:@"/"];
if ([s count] == 0) [s addObjectsFromArray:@[@"+", @"-", @"*", @"/"]];
uint32_t rnd = arc4random_uniform([s count]);
NSString *randomS = [s objectAtIndex:rnd];
NSInteger randomNumberA = arc4random_uniform(Range);
NSInteger randomNumberB = arc4random_uniform(Range);
if ([randomS isEqual: @"-"]) {
if (randomNumberA < randomNumberB) {
x = (randomNumberB - randomNumberA);
NSInteger temp = randomNumberB;
randomNumberB = randomNumberA;
randomNumberA = temp;
}else{
x = (randomNumberA - randomNumberB);
}
}
else if ([randomS isEqual: @"+"]) {
x = (randomNumberA + randomNumberB);
}
else if ([randomS isEqual: @"*"]) {
x = (randomNumberA * randomNumberB);
}
else if ([randomS isEqual:@"/"]) {
if (randomNumberB == 0) randomNumberB = 1 + arc4random_uniform(Range);
randomNumberA *= randomNumberB;
x = (randomNumberA / randomNumberB);
}
NSString *Equation = [NSString stringWithFormat: @"%ld %@ %ld = ?", randomNumberA, randomS, randomNumberB];
// TextField:
YPField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 295.0, 38.0)];
YPField.layer.cornerRadius = 8;
YPField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
YPField.textAlignment = NSTextAlignmentCenter;
// https://developer.apple.com/documentation/uikit/uitextfield/1619610-attributedplaceholder?language=objc
UIColor *placeholderColor = [UIColor whiteColor];
YPField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:[NSString stringWithFormat: @"%@", Equation] attributes:@{NSForegroundColorAttributeName: placeholderColor}];
if (!CC) {
[YPField setBackgroundColor: [[UIColor clearColor] colorWithAlphaComponent:0.5]];
}else{
UIColor *selectedTF = LCPParseColorString(TFS, @"#ffffff");
[YPField setBackgroundColor: selectedTF];
}
[YPField setText: nil];
YPField.textColor = [UIColor whiteColor];
[YPField setDelegate:self];
[YPField setCenter:CGPointMake(self.view.center.x, 325)];
[YPView addSubview:YPField];
// Done Button:
UIButton *checkButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 240.0, 50.0)];
[checkButton addTarget:self action:@selector(check)
forControlEvents:UIControlEventTouchUpInside];
[checkButton setTitle:@"Done" forState:UIControlStateNormal];
if(!CC) {
[checkButton setBackgroundColor: [[UIColor clearColor] colorWithAlphaComponent:0.5]];
}else{
UIColor *selectedBTN = LCPParseColorString(BTNS, @"#ffffff");
[checkButton setBackgroundColor: selectedBTN];
}
[checkButton setCenter:CGPointMake(self.view.center.x, 445)];
checkButton.layer.cornerRadius = 12;
[YPView addSubview:checkButton];
}
}
- (void)lockButtonPressed:(id)arg1 {
if (Enabled && DisableSideButtons) {
YPField.transform = CGAffineTransformMakeTranslation(20, 0);
[UIView animateWithDuration:0.4 delay:0.0 usingSpringWithDamping:0.2 initialSpringVelocity:1.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
YPField.transform = CGAffineTransformIdentity;
} completion:nil];
}else{
%orig;
}
}
- (void)volumeChanged:(id)arg1 {
if (Enabled && DisableSideButtons) {
YPField.transform = CGAffineTransformMakeTranslation(20, 0);
[UIView animateWithDuration:0.4 delay:0.0 usingSpringWithDamping:0.2 initialSpringVelocity:1.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
YPField.transform = CGAffineTransformIdentity;
} completion:nil];
}else{
%orig;
}
}
%new
- (void)check {
if (SkipBTNEnabled && numberOfTries >= SAttempt) {
[self showSkipBTN];
}
if ([NSString stringWithFormat: @"%ld", (long)x] == YPField.text) {
[UIView animateWithDuration:0.2
animations:^{YPView.alpha = 0.0;}
completion:^(BOOL finished) { [YPView removeFromSuperview];
}];
[[NSNotificationCenter defaultCenter]
postNotificationName:@"com.1di4r.youup/enable"
object:self];
}else{
if ([YPField hasText]) numberOfTries++;
YPField.transform = CGAffineTransformMakeTranslation(20, 0);
[UIView animateWithDuration:0.4 delay:0.0 usingSpringWithDamping:0.2 initialSpringVelocity:1.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
YPField.transform = CGAffineTransformIdentity;
} completion:nil];
}
}
%new
- (void)showSkipBTN {
UIButton *skipButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 240.0, 50.0)];
[skipButton addTarget:self action:@selector(skip)
forControlEvents:UIControlEventTouchUpInside];
[skipButton setTitle:@"Skip" forState:UIControlStateNormal];
if(!CC) {
[skipButton setBackgroundColor: [[UIColor clearColor] colorWithAlphaComponent:0.5]];
}else{
UIColor *selectedBTN = LCPParseColorString(BTNS, @"#ffffff");
[skipButton setBackgroundColor: selectedBTN];
}
[skipButton setCenter:CGPointMake(self.view.center.x, 445 + 60)];
skipButton.layer.cornerRadius = 12;
[YPView addSubview:skipButton];
}
%new
- (void)skip {
[UIView animateWithDuration:0.2
animations:^{YPView.alpha = 0.0;}
completion:^(BOOL finished) { [YPView removeFromSuperview];
}];
}
%new
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
return YES;
}
%new
- (void)dismissKeyboard {
[YPField resignFirstResponder];
}
%end
/*
* AutoUnlockX compatibility
*/
%hook SparkAutoUnlockX
- (BOOL)externalBlocksUnlock {
if (YPView.superview) return TRUE;
return %orig;
}
%end
/*
* Rofi compatibility
*/
%hook RFViewController
- (id)view {
if (YPView.superview) return nil;
return %orig;
}
%end
%hook SBHomeHardwareButton
- (void)longPress:(id)arg1 {
if (Enabled && DisableHomeButton) {
if (YPView.superview) arg1 = NULL;
%orig;
}else{
%orig;
}
}
- (void)_singlePressUp:(id)arg1 {
if (Enabled && DisableHomeButton) {
if (YPView.superview) arg1 = NULL;
%orig;
}else{
%orig;
}
}
- (void)doublePressDown:(id)arg1 {
if (Enabled && DisableHomeButton) {
if (YPView.superview) arg1 = NULL;
%orig;
}else{
%orig;
}
}
%end
/*
Hey reader! if you are here to learn from the code or just look at it for any reason, i recommend you to read this.
so, about disabling TouchID.
There is a "good way" and a "bad way a.k.a kinda good way".
The "good way" only prevents unlocking, the TouchID is still somewhat active
which means that there probably is a chance that somehow the user will be able to unlock the phone and dismiss the alarm.
The "bad way" well, it will disable the TouchID completely which is what we want BUT the reason im not using the "bad way" (and the reason which makes it bad ig)
is that it only gets called once, and thats when the device is booted (or when you press the lock button? i dont remember tbh) so i have to add a notification observer and
send a notification whenever the Tweak's view is present, doing that will disable the TouchID BUT it wont be re-enabled by it self
so i have to send another notf to re-enable TouchID when the Tweaks's view is not present.
anyways, im using the "good way" so we are...good lol
but i will keep both just in case
now why did i write this wall of comment even though im using the "good way", i hear you ask
yes
*/
// the good way
%hook SBDashBoardBiometricUnlockController
- (BOOL)biometricUnlockBehavior:(id)arg1 requestsUnlock:(id)arg2 withFeedback:(id)arg3 {
if (Enabled && DisableHomeButton) {
if (YPView.superview) return NO;
}
return %orig;
}
%end
// the bad way (well it depends it can also be good)
// %hook SBLockScreenManager
// - (id)init {
// [[NSNotificationCenter defaultCenter] addObserver:self
// selector:@selector(disable)
// name:@"com.1di4r.youup/disable"
// object:nil];
// [[NSNotificationCenter defaultCenter] addObserver:self
// selector:@selector(enable)
// name:@"com.1di4r.youup/enable"
// object:nil];
// return %orig;
// }
// %new
// - (void)disable {
// // [self setBiometricAutoUnlockingDisabled:TRUE forReason:@"SBApplicationRequestedDeviceUnlock"];
// }
// %new
// - (void)enable {
// //[self setBiometricAutoUnlockingDisabled:FALSE forReason:@"SBApplicationRequestedDeviceUnlock"];
// }
// - (void)setBiometricAutoUnlockingDisabled:(BOOL)arg1 forReason:(id)arg2 {
// NSLog(@"[Youup] setBiometricAutoUnlockingDisabled - %d - %@", arg1, arg2);
// if (Enabled && Disablebuttons) {
// if (YPView.superview) {
// NSLog(@"[Youup] setBiometricAutoUnlockingDisabled");
// %orig(TRUE, arg2);
// }else{
// %orig;
// }
// }
// }
// %end
%hook SBLockHardwareButton
- (void)longPress:(id)arg1 {
if (Enabled && DisableSideButtons) {
if (YPView.superview) arg1 = NULL;
%orig;
}else{
%orig;
}
}
%end
%hook SBLockHardwareButton
- (void)singlePress:(id)arg1 {
if (Enabled && DisableSideButtons) {
if (YPView.superview) {
// Do nothing.
}else{
%orig;
}
}else{
%orig;
}
}
%end
%hook SBVolumeHardwareButton
- (void)volumeIncreasePress:(id)arg1 {
if (Enabled && DisableSideButtons) {
if (YPView.superview) {
// Do nothing.
}else{
%orig;
}
}else{
%orig;
}
}
- (void)volumeDecreasePress:(id)arg1 {
if (Enabled && DisableSideButtons) {
if (YPView.superview) {
// Do nothing.
}else{
%orig;
}
}else{
%orig;
}
}
%end
// Ringer Switch
%hook SpringBoard
- (void)_updateRingerState:(int)arg1 withVisuals:(BOOL)arg2 updatePreferenceRegister:(BOOL)arg3 {
if (Enabled && DisableSideButtons) {
if (YPView.superview) {
// Do nothing.
}else{
%orig;
}
}else{
%orig;
}
}
%end
static void prefChanged() {
HBPreferences *prefs = [[HBPreferences alloc] initWithIdentifier:@"cf.1di4r.ypprefs"];
Enabled = [([prefs objectForKey:@"kEnabled"] ?: @(YES)) boolValue];
DisableSideButtons = [([prefs objectForKey:@"kDisableSideButtons"] ?: @(YES)) boolValue];
DisableHomeButton = [([prefs objectForKey:@"kDisableHomeButton"] ?: @(YES)) boolValue];
Addition = [([prefs objectForKey:@"kAddition"] ?: @(YES)) boolValue];
Division = [([prefs objectForKey:@"kDivision"] ?: @(YES)) boolValue];
Subtraction = [([prefs objectForKey:@"kSubtraction"] ?: @(YES)) boolValue];
Multiplication = [([prefs objectForKey:@"kMultiplication"] ?: @(YES)) boolValue];
Range = [([prefs objectForKey:@"kRange"] ?: @(5)) intValue];
CC = [([prefs objectForKey:@"kCC"] ?: @(NO)) boolValue];
SkipBTNEnabled = [([prefs objectForKey:@"SkipBTNEnabled"] ?: @(NO)) boolValue];
SAttempt = [([prefs objectForKey:@"SAttempt"] ?: @(5)) intValue];
BGS = [[prefs objectForKey: @"kBG"] stringValue];
CKS = [[prefs objectForKey: @"kCK"] stringValue];
TFS = [[prefs objectForKey: @"kTF"] stringValue];
BTNS = [[prefs objectForKey: @"kBTN"] stringValue];
}
void prefsChanged(
CFNotificationCenterRef center,
void *observer,
CFStringRef name,
const void *object,
CFDictionaryRef userInfo) {
prefChanged();
}
%ctor {
prefChanged();
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, prefsChanged, CFSTR("com.1di4r.youup/ReloadPrefs"), NULL, CFNotificationSuspensionBehaviorCoalesce);
}