-
Notifications
You must be signed in to change notification settings - Fork 2
/
Menu (2).mm
598 lines (469 loc) · 25.8 KB
/
Menu (2).mm
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
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
//
// Menu.m
// ModMenu
//
// Created by Joey on 3/14/19.
// Copyright © 2019 Joey. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "Menu.h"
#define UIColorFromHex(hexColor) [UIColor colorWithRed:((float)((hexColor & 0xFF0000) >> 16))/255.0 green:((float)((hexColor & 0xFF00) >> 8))/255.0 blue:((float)(hexColor & 0xFF))/255.0 alpha:1.0]
UIColor *glowColor = UIColorFromHex(0xd12017);
@interface Menu ()
@property (assign, nonatomic) CGPoint lastMenuLocation;
@property (strong, nonatomic) UILabel *menuTitle;
@property (strong, nonatomic) UIView *header;
@property (strong, nonatomic) UIView *footer;
@end
-(id)initWithTitle:(NSString *)title_ watermarkText:(NSString *)watermarkText_ watermarkTextColor:(UIColor *)watermarkTextColor_ watermarkVisible:(float)watermarkVisible_ titleColor:(UIColor *)titleColor_ titleFont:(NSString *)titleFont_ credits:(NSString *)credits_
initWithTitle:(NSString *)footerTitle_ titleColor:(UIColor *)footerTitleColor_ titleFont:(NSString *)footerTitleFont_ initWithTitle:(NSString *)footerTitle1_ titleColor:(UIColor *)footerTitleColor1_ titleFont:(NSString *)footerTitleFont1_
headerColor:(UIColor *)headerColor_ switchOffColor:(UIColor *)switchOffColor_ switchOnColor:(UIColor *)switchOnColor_ switchTitleFont:(NSString *)switchTitleFont_ switchTitleColor:(UIColor *)switchTitleColor_ infoButtonColor:(UIColor *)infoButtonColor_ maxVisibleSwitches:(int)maxVisibleSwitches_ menuWidth:(CGFloat )menuWidth_ menuIcon:(NSString *)menuIconBase64_ menuButton:(NSString *)menuButtonBase64_ {
mainWindow = [UIApplication sharedApplication].keyWindow;
defaults = [NSUserDefaults standardUserDefaults];
menuWidth = menuWidth_;
switchOnColor = switchOnColor_;
credits = credits_;
switchTitleFont = switchTitleFont_;
switchTitleColor = switchTitleColor_;
infoButtonColor = infoButtonColor_;
menuButtonBase64 = menuButtonBase64_;
NSString *WMTEXT = [watermarkText_ stringByReplacingOccurrencesOfString:@"@@OBFS@@" withString:@""];
watermark = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, mainWindow.frame.size.width/4, 20)];
watermark.textColor = [UIColor colorWithRed:arc4random()%256/255.0 green:arc4random()%256/255.0 blue:arc4random()%256/255.0 alpha:1];
watermark.backgroundColor = [UIColor clearColor];
watermark.text = WMTEXT;
watermark.adjustsFontSizeToFitWidth = YES;
watermark.layer.opacity = ([switches isSwitchOn:@"Watermark"]);
watermark.center = CGPointMake(CGRectGetMinX(mainWindow.frame)+watermark.frame.size.width/2+10,
CGRectGetMaxY(mainWindow.frame)-watermark.frame.size.height -5);
[mainWindow addSubview:watermark];
@implementation Menu
NSUserDefaults *defaults;
UIScrollView *scrollView;
CGFloat menuWidth;
CGFloat scrollViewX;
NSString *credits;
UIColor *switchOnColor;
NSString *switchTitleFont;
UIColor *switchTitleColor;
UIColor *infoButtonColor;
NSString *menuIconBase64;
NSString *menuButtonBase64;
float scrollViewHeight = 0;
BOOL hasRestoredLastSession = false;
UIButton *menuButton;
const char *frameworkName = NULL;
UIWindow *mainWindow;
// init the menu
// global variabls, extern in Macros.h
Menu *menu = [[Menu alloc]init];
Switches *switches = [[Switches alloc]init];
-(id)initWithTitle:(NSString *)title_ titleColor:(UIColor *)titleColor_ titleFont:(NSString *)titleFont_ credits:(NSString *)credits_ headerColor:(UIColor *)headerColor_ switchOffColor:(UIColor *)switchOffColor_ switchOnColor:(UIColor *)switchOnColor_ switchTitleFont:(NSString *)switchTitleFont_ switchTitleColor:(UIColor *)switchTitleColor_ infoButtonColor:(UIColor *)infoButtonColor_ maxVisibleSwitches:(int)maxVisibleSwitches_ menuWidth:(CGFloat )menuWidth_ menuIcon:(NSString *)menuIconBase64_ menuButton:(NSString *)menuButtonBase64_ {
mainWindow = [UIApplication sharedApplication].keyWindow;
defaults = [NSUserDefaults standardUserDefaults];
menuWidth = menuWidth_;
switchOnColor = switchOnColor_;
credits = credits_;
switchTitleFont = switchTitleFont_;
switchTitleColor = switchTitleColor_;
infoButtonColor = infoButtonColor_;
menuButtonBase64 = menuButtonBase64_;
// Base of the Menu UI.
self = [super initWithFrame:CGRectMake(0,0,menuWidth_, maxVisibleSwitches_ * 50 + 50)];
self.center = mainWindow.center;
self.layer.opacity = 0.0f;
self.layer.shadowColor = glowColor.CGColor;
self.layer.shadowRadius = 10.0f;
self.layer.shadowOpacity = 1.0f;
self.layer.shadowOffset = CGSizeZero;
self.header = [[UIView alloc]initWithFrame:CGRectMake(0, -5, menuWidth_, 50)];
self.header.backgroundColor = headerColor_;
CAShapeLayer *headerLayer = [CAShapeLayer layer];
headerLayer.path = [UIBezierPath bezierPathWithRoundedRect: self.header.bounds byRoundingCorners: UIRectCornerTopLeft | UIRectCornerTopRight | UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii: (CGSize){5.0, 5.0}].CGPath;
self.header.layer.mask = headerLayer;
[self addSubview:self.header];
NSData* data = [[NSData alloc] initWithBase64EncodedString:menuIconBase64_ options:0];
UIImage* menuIconImage = [UIImage imageWithData:data];
UIButton *menuIcon = [UIButton buttonWithType:UIButtonTypeRoundedRect];
menuIcon.frame = CGRectMake(5, 1, 50, 50);
menuIcon.backgroundColor = [UIColor clearColor];
[menuIcon setBackgroundImage:menuIconImage forState:UIControlStateNormal];
[menuIcon addTarget:self action:@selector(menuIconTapped) forControlEvents:UIControlEventTouchDown];
[self.header addSubview:menuIcon];
scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, CGRectGetHeight(self.header.bounds), menuWidth_, CGRectGetHeight(self.bounds) - CGRectGetHeight(self.header.bounds))];
scrollView.backgroundColor = switchOffColor_;
[self addSubview:scrollView];
// we need this for the switches, do not remove.
scrollViewX = CGRectGetMinX(scrollView.self.bounds);
self.menuTitle = [[UILabel alloc]initWithFrame:CGRectMake(55, -2, menuWidth_ - 60, 50)];
self.menuTitle.text = title_;
self.menuTitle.textColor = titleColor_;
self.menuTitle.font = [UIFont fontWithName:titleFont_ size:30.0f];
self.menuTitle.adjustsFontSizeToFitWidth = true;
self.menuTitle.textAlignment = NSTextAlignmentCenter;
[self.header addSubview: self.menuTitle];
self.footer = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetHeight(self.bounds) - 1, menuWidth_, 20)];
self.footer.backgroundColor = headerColor_;
CAShapeLayer *footerLayer = [CAShapeLayer layer];
footerLayer.path = [UIBezierPath bezierPathWithRoundedRect:self.footer.bounds byRoundingCorners: UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii: (CGSize){5.0, 5.0}].CGPath;
self.footer.layer.mask = footerLayer;
[self addSubview:self.footer];
UIPanGestureRecognizer *dragMenuRecognizer = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(menuDragged:)];
[self.header addGestureRecognizer:dragMenuRecognizer];
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(hideMenu:)];
tapGestureRecognizer.numberOfTapsRequired = 1;
[self.header addGestureRecognizer:tapGestureRecognizer];
[mainWindow addSubview:self];
[self showMenuButton];
return self;
}
// Detects whether the menu is being touched and sets a lastMenuLocation.
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
self.lastMenuLocation = CGPointMake(CGRectGetMinX(self.frame), CGRectGetMinY(self.frame));
[super touchesBegan:touches withEvent:event];
}
// Update the menu's location when it's being dragged
- (void)menuDragged:(UIPanGestureRecognizer *)pan {
CGPoint newLocation = [pan translationInView:self.superview];
self.frame = CGRectMake(self.lastMenuLocation.x + newLocation.x, self.lastMenuLocation.y + newLocation.y, CGRectGetWidth(self.frame), CGRectGetHeight(self.frame));
}
- (void)hideMenu:(UITapGestureRecognizer *)tap {
if(tap.state == UIGestureRecognizerStateEnded) {
[UIView animateWithDuration:0.5 animations:^ {
self.alpha = 0.0f;
menuButton.alpha = 1.0f;
}];
}
}
-(void)showMenu:(UITapGestureRecognizer *)tapGestureRecognizer {
if(tapGestureRecognizer.state == UIGestureRecognizerStateEnded) {
menuButton.alpha = 0.0f;
[UIView animateWithDuration:0.5 animations:^ {
self.alpha = 1.0f;
}];
}
// We should only have to do this once (first launch)
if(!hasRestoredLastSession) {
restoreLastSession();
hasRestoredLastSession = true;
}
}
/**********************************************************************************************
This function will be called when the menu has been opened for the first time on launch.
It'll handle the correct background color and patches the switches do.
***********************************************************************************************/
void restoreLastSession() {
UIColor *clearColor = [UIColor clearColor];
BOOL isOn = false;
for(id switch_ in scrollView.subviews) {
if([switch_ isKindOfClass:[OffsetSwitch class]]) {
isOn = [defaults boolForKey:[switch_ getPreferencesKey]];
std::vector<MemoryPatch> memoryPatches = [switch_ getMemoryPatches];
for(int i = 0; i < memoryPatches.size(); i++) {
if(isOn){
memoryPatches[i].Modify();
} else {
memoryPatches[i].Restore();
}
}
((OffsetSwitch*)switch_).backgroundColor = isOn ? switchOnColor : clearColor;
}
if([switch_ isKindOfClass:[TextFieldSwitch class]]) {
isOn = [defaults boolForKey:[switch_ getPreferencesKey]];
((TextFieldSwitch*)switch_).backgroundColor = isOn ? switchOnColor : clearColor;
}
if([switch_ isKindOfClass:[SliderSwitch class]]) {
isOn = [defaults boolForKey:[switch_ getPreferencesKey]];
((SliderSwitch*)switch_).backgroundColor = isOn ? switchOnColor : clearColor;
}
}
}
-(void)showMenuButton {
NSData* data = [[NSData alloc] initWithBase64EncodedString:menuButtonBase64 options:0];
UIImage* menuButtonImage = [UIImage imageWithData:data];
menuButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
menuButton.frame = CGRectMake((mainWindow.frame.size.width/2), (mainWindow.frame.size.height/2), 35, 35);
menuButton.backgroundColor = [UIColor clearColor];
[menuButton setBackgroundImage:menuButtonImage forState:UIControlStateNormal];
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(showMenu:)];
[menuButton addGestureRecognizer:tapGestureRecognizer];
[menuButton addTarget:self action:@selector(buttonDragged:withEvent:)
forControlEvents:UIControlEventTouchDragInside];
[mainWindow addSubview:menuButton];
}
// handler for when the user is draggin the menu.
- (void)buttonDragged:(UIButton *)button withEvent:(UIEvent *)event {
UITouch *touch = [[event touchesForView:button] anyObject];
CGPoint previousLocation = [touch previousLocationInView:button];
CGPoint location = [touch locationInView:button];
CGFloat delta_x = location.x - previousLocation.x;
CGFloat delta_y = location.y - previousLocation.y;
button.center = CGPointMake(button.center.x + delta_x, button.center.y + delta_y);
}
// When the menu icon(on the header) has been tapped, we want to show proper credits!
-(void)menuIconTapped {
[self showPopup:self.menuTitle.text description:credits];
self.layer.opacity = 0.0f;
}
-(void)showPopup:(NSString *)title_ description:(NSString *)description_ {
SCLAlertView *alert = [[SCLAlertView alloc] initWithNewWindow];
alert.shouldDismissOnTapOutside = NO;
alert.customViewColor = [UIColor purpleColor];
alert.showAnimationType = SCLAlertViewShowAnimationFadeIn;
[alert addButton: @"Ok!" actionBlock: ^(void) {
self.layer.opacity = 1.0f;
}];
[alert showInfo:title_ subTitle:description_ closeButtonTitle:nil duration:9999999.0f];
}
/*******************************************************************
This method adds the given switch to the menu's scrollview.
it also add's an action for when the switch is being clicked.
********************************************************************/
- (void)addSwitchToMenu:(id)switch_ {
[switch_ addTarget:self action:@selector(switchClicked:) forControlEvents:UIControlEventTouchDown];
scrollViewHeight += 35;
scrollView.contentSize = CGSizeMake(menuWidth, scrollViewHeight);
[scrollView addSubview:switch_];
}
- (void)changeSwitchBackground:(id)switch_ isSwitchOn:(BOOL)isSwitchOn_ {
UIColor *clearColor = [UIColor clearColor];
[UIView animateWithDuration:0.3 animations:^ {
if([switch_ isKindOfClass:[TextFieldSwitch class]]) {
((TextFieldSwitch*)switch_).backgroundColor = isSwitchOn_ ? clearColor : switchOnColor;
}
if([switch_ isKindOfClass:[SliderSwitch class]]) {
((SliderSwitch*)switch_).backgroundColor = isSwitchOn_ ? clearColor : switchOnColor;
}
if([switch_ isKindOfClass:[OffsetSwitch class]]) {
((OffsetSwitch*)switch_).backgroundColor = isSwitchOn_ ? clearColor : switchOnColor;
}
}];
[defaults setBool:!isSwitchOn_ forKey:[switch_ getPreferencesKey]];
}
/*********************************************************************************************
This method does the following handles the behaviour when a switch has been clicked
TextfieldSwitch and SliderSwitch only change from color based on whether it's on or not.
A OffsetSwitch does too, but it also applies offset patches
***********************************************************************************************/
-(void)switchClicked:(id)switch_ {
BOOL isOn = [defaults boolForKey:[switch_ getPreferencesKey]];
if([switch_ isKindOfClass:[OffsetSwitch class]]) {
std::vector<MemoryPatch> memoryPatches = [switch_ getMemoryPatches];
for(int i = 0; i < memoryPatches.size(); i++) {
if(!isOn){
memoryPatches[i].Modify();
} else {
memoryPatches[i].Restore();
}
}
}
// Update switch background color and pref value.
[self changeSwitchBackground:switch_ isSwitchOn:isOn];
}
-(void)setFrameworkName:(const char *)name_ {
frameworkName = name_;
}
-(const char *)getFrameworkName {
return frameworkName;
}
@end // End of menu class!
/********************************
OFFSET SWITCH STARTS HERE!
*********************************/
@implementation OffsetSwitch {
std::vector<MemoryPatch> memoryPatches;
}
- (id)initHackNamed:(NSString *)hackName_ description:(NSString *)description_ offsets:(std::vector<uint64_t>)offsets_ bytes:(std::vector<std::string>)bytes_ {
description = description_;
preferencesKey = hackName_;
if(offsets_.size() != bytes_.size()){
[menu showPopup:@"Invalid input count" description:[NSString stringWithFormat:@"Offsets array input count (%d) is not equal to the bytes array input count (%d)", (int)offsets_.size(), (int)bytes_.size()]];
} else {
// For each offset, we create a MemoryPatch.
for(int i = 0; i < offsets_.size(); i++) {
MemoryPatch patch = MemoryPatch::createWithHex([menu getFrameworkName], offsets_[i], bytes_[i]);
if(patch.isValid()) {
memoryPatches.push_back(patch);
} else {
[menu showPopup:@"Invalid patch" description:[NSString stringWithFormat:@"Failing offset: 0x%llx, please re-check the hex you entered.", offsets_[i]]];
}
}
}
self = [super initWithFrame:CGRectMake(-1, scrollViewX + scrollViewHeight - 1, menuWidth + 2, 35)];
self.backgroundColor = [UIColor clearColor];
self.layer.borderWidth = 0.5f;
self.layer.borderColor = [UIColor blackColor].CGColor;
switchLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, 0, menuWidth - 60, 35)];
switchLabel.text = hackName_;
switchLabel.textColor = switchTitleColor;
switchLabel.font = [UIFont fontWithName:switchTitleFont size:18];
switchLabel.adjustsFontSizeToFitWidth = true;
switchLabel.textAlignment = NSTextAlignmentCenter;
[self addSubview:switchLabel];
UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeInfoDark];
infoButton.frame = CGRectMake(menuWidth - 30, 15, 20, 20);
infoButton.tintColor = infoButtonColor;
UITapGestureRecognizer *infoTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showInfo:)];
[infoButton addGestureRecognizer:infoTap];
[self addSubview:infoButton];
return self;
}
-(void)showInfo:(UIGestureRecognizer *)gestureRec {
if(gestureRec.state == UIGestureRecognizerStateEnded) {
[menu showPopup:[self getPreferencesKey] description:[self getDescription]];
menu.layer.opacity = 0.0f;
}
}
-(NSString *)getPreferencesKey {
return preferencesKey;
}
-(NSString *)getDescription {
return description;
}
- (std::vector<MemoryPatch>)getMemoryPatches {
return memoryPatches;
}
@end //end of OffsetSwitch class
/**************************************
TEXTFIELD SWITCH STARTS HERE!
- Note that this extends from OffsetSwitch.
***************************************/
@implementation TextFieldSwitch {
UITextField *textfieldValue;
}
- (id)initTextfieldNamed:(NSString *)hackName_ description:(NSString *)description_ inputBorderColor:(UIColor *)inputBorderColor_ {
preferencesKey = hackName_;
switchValueKey = [hackName_ stringByApplyingTransform:NSStringTransformLatinToCyrillic reverse:false];
description = description_;
self = [super initWithFrame:CGRectMake(-1, scrollViewX + scrollViewHeight -1, menuWidth + 2, 35)];
self.backgroundColor = [UIColor clearColor];
self.layer.borderWidth = 0.5f;
self.layer.borderColor = [UIColor whiteColor].CGColor;
switchLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, 0, menuWidth - 60, 50)];
switchLabel.text = hackName_;
switchLabel.textColor = switchTitleColor;
switchLabel.font = [UIFont fontWithName:switchTitleFont size:18];
switchLabel.adjustsFontSizeToFitWidth = true;
switchLabel.textAlignment = NSTextAlignmentCenter;
[self addSubview:switchLabel];
textfieldValue = [[UITextField alloc]initWithFrame:CGRectMake(menuWidth / 4 - 10, switchLabel.self.bounds.origin.x - 5 + switchLabel.self.bounds.size.height, menuWidth / 2, 20)];
textfieldValue.layer.borderWidth = 2.0f;
textfieldValue.layer.borderColor = inputBorderColor_.CGColor;
textfieldValue.layer.cornerRadius = 10.0f;
textfieldValue.textColor = switchTitleColor;
textfieldValue.textAlignment = NSTextAlignmentCenter;
textfieldValue.delegate = self;
textfieldValue.backgroundColor = [UIColor clearColor];
// get value from the plist & show it (if it's not empty).
if([[NSUserDefaults standardUserDefaults] objectForKey:switchValueKey] != nil) {
textfieldValue.text = [[NSUserDefaults standardUserDefaults] objectForKey:switchValueKey];
}
UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeInfoDark];
infoButton.frame = CGRectMake(menuWidth - 30, 15, 20, 20);
infoButton.tintColor = infoButtonColor;
UITapGestureRecognizer *infoTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showInfo:)];
[infoButton addGestureRecognizer:infoTap];
[self addSubview:infoButton];
[self addSubview:textfieldValue];
return self;
}
// so when click "return" the keyboard goes way, got it from internet. Common thing apparantly
-(BOOL)textFieldShouldReturn:(UITextField*)textfieldValue_ {
switchValueKey = [[self getPreferencesKey] stringByApplyingTransform:NSStringTransformLatinToCyrillic reverse:false];
[defaults setObject:textfieldValue_.text forKey:[self getSwitchValueKey]];
[textfieldValue_ resignFirstResponder];
return true;
}
-(NSString *)getSwitchValueKey {
return switchValueKey;
}
@end // end of TextFieldSwitch Class
/*******************************
SLIDER SWITCH STARTS HERE!
- Note that this extends from TextFieldSwitch
*******************************/
@implementation SliderSwitch {
UISlider *sliderValue;
float valueOfSlider;
}
- (id)initSliderNamed:(NSString *)hackName_ description:(NSString *)description_ minimumValue:(float)minimumValue_ maximumValue:(float)maximumValue_ sliderColor:(UIColor *)sliderColor_{
preferencesKey = hackName_;
switchValueKey = [hackName_ stringByApplyingTransform:NSStringTransformLatinToCyrillic reverse:false];
description = description_;
self = [super initWithFrame:CGRectMake(-1, scrollViewX + scrollViewHeight -1, menuWidth + 2, 50)];
self.backgroundColor = [UIColor clearColor];
self.layer.borderWidth = 0.5f;
self.layer.borderColor = [UIColor blackColor].CGColor;
switchLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, 0, menuWidth - 60, 30)];
switchLabel.text = [NSString stringWithFormat:@"%@ %.2f", hackName_, sliderValue.value];
switchLabel.textColor = switchTitleColor;
switchLabel.font = [UIFont fontWithName:switchTitleFont size:18];
switchLabel.adjustsFontSizeToFitWidth = true;
switchLabel.textAlignment = NSTextAlignmentCenter;
[self addSubview:switchLabel];
sliderValue = [[UISlider alloc]initWithFrame:CGRectMake(menuWidth / 4 - 20, switchLabel.self.bounds.origin.x - 4 + switchLabel.self.bounds.size.height, menuWidth / 2 + 20, 20)];
sliderValue.thumbTintColor = sliderColor_;
sliderValue.minimumTrackTintColor = switchTitleColor;
sliderValue.maximumTrackTintColor = switchTitleColor;
sliderValue.minimumValue = minimumValue_;
sliderValue.maximumValue = maximumValue_;
sliderValue.continuous = true;
[sliderValue addTarget:self action:@selector(sliderValueChanged:) forControlEvents:UIControlEventValueChanged];
valueOfSlider = sliderValue.value;
// get value from the plist & show it (if it's not empty).
if([[NSUserDefaults standardUserDefaults] objectForKey:switchValueKey] != nil) {
sliderValue.value = [[NSUserDefaults standardUserDefaults] floatForKey:switchValueKey];
switchLabel.text = [NSString stringWithFormat:@"%@ %.2f", hackName_, sliderValue.value];
}
UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeInfoLight];
infoButton.frame = CGRectMake(menuWidth - 30, 15, 20, 20);
infoButton.tintColor = infoButtonColor;
UITapGestureRecognizer *infoTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showInfo:)];
[infoButton addGestureRecognizer:infoTap];
[self addSubview:infoButton];
[self addSubview:sliderValue];
return self;
}
-(void)sliderValueChanged:(UISlider *)slider_ {
switchValueKey = [[self getPreferencesKey] stringByApplyingTransform:NSStringTransformLatinToCyrillic reverse:false];
switchLabel.text = [NSString stringWithFormat:@"%@ %.2f", [self getPreferencesKey], slider_.value];
[defaults setFloat:slider_.value forKey:[self getSwitchValueKey]];
}
@end // end of SliderSwitch class
@implementation Switches
-(void)addSwitch:(NSString *)hackName_ description:(NSString *)description_ {
OffsetSwitch *offsetPatch = [[OffsetSwitch alloc]initHackNamed:hackName_ description:description_ offsets:std::vector<uint64_t>{} bytes:std::vector<std::string>{}];
[menu addSwitchToMenu:offsetPatch];
}
- (void)addOffsetSwitch:(NSString *)hackName_ description:(NSString *)description_ offsets:(std::initializer_list<uint64_t>)offsets_ bytes:(std::initializer_list<std::string>)bytes_ {
std::vector<uint64_t> offsetVector;
std::vector<std::string> bytesVector;
offsetVector.insert(offsetVector.begin(), offsets_.begin(), offsets_.end());
bytesVector.insert(bytesVector.begin(), bytes_.begin(), bytes_.end());
OffsetSwitch *offsetPatch = [[OffsetSwitch alloc]initHackNamed:hackName_ description:description_ offsets:offsetVector bytes:bytesVector];
[menu addSwitchToMenu:offsetPatch];
}
- (void)addTextfieldSwitch:(NSString *)hackName_ description:(NSString *)description_ inputBorderColor:(UIColor *)inputBorderColor_ {
TextFieldSwitch *textfieldSwitch = [[TextFieldSwitch alloc]initTextfieldNamed:hackName_ description:description_ inputBorderColor:inputBorderColor_];
[menu addSwitchToMenu:textfieldSwitch];
}
- (void)addSliderSwitch:(NSString *)hackName_ description:(NSString *)description_ minimumValue:(float)minimumValue_ maximumValue:(float)maximumValue_ sliderColor:(UIColor *)sliderColor_ {
SliderSwitch *sliderSwitch = [[SliderSwitch alloc] initSliderNamed:hackName_ description:description_ minimumValue:minimumValue_ maximumValue:maximumValue_ sliderColor:sliderColor_];
[menu addSwitchToMenu:sliderSwitch];
}
- (NSString *)getValueFromSwitch:(NSString *)name {
//getting the correct key for the saved input.
NSString *correctKey = [name stringByApplyingTransform:NSStringTransformLatinToCyrillic reverse:false];
if([[NSUserDefaults standardUserDefaults] objectForKey:correctKey]) {
return [[NSUserDefaults standardUserDefaults] objectForKey:correctKey];
}
else if([[NSUserDefaults standardUserDefaults] floatForKey:correctKey]) {
NSString *sliderValue = [NSString stringWithFormat:@"%f", [[NSUserDefaults standardUserDefaults] floatForKey:correctKey]];
return sliderValue;
}
return 0;
}
-(bool)isSwitchOn:(NSString *)switchName {
return [[NSUserDefaults standardUserDefaults] boolForKey:switchName];
}
@end