-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tweak.xm
58 lines (44 loc) · 1.97 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
#import <substrate.h>
#import <SpringBoard/SpringBoard.h>
@interface NSString (latelyAdded)
-(BOOL)containsSubstring:(id)substring;
@end
static BOOL isRingerSwitch;
static BOOL savedState;
extern "C" Boolean CFPreferencesGetAppBooleanValue (CFStringRef key,CFStringRef applicationID,Boolean *keyExistsAndHasValidFormat);
static Boolean (*orig_CFPreferencesGetAppBooleanValue) (CFStringRef key,CFStringRef applicationID,Boolean *keyExistsAndHasValidFormat);
static Boolean replaced_CFPreferencesGetAppBooleanValue (CFStringRef key,CFStringRef applicationID,Boolean *keyExistsAndHasValidFormat){
if (!isRingerSwitch && [(NSString *)key isEqualToString:@"SBUseHardwareSwitchAsOrientationLock"] )
return true;
return orig_CFPreferencesGetAppBooleanValue(key,applicationID,keyExistsAndHasValidFormat);
}
static void getSettings(){
NSString *path=@"/var/mobile/Library/Preferences/net.limneos.ringerswitchtool.plist";
NSMutableDictionary *settingsDict=[NSMutableDictionary dictionaryWithContentsOfFile:path];
if (!settingsDict){
settingsDict=[NSMutableDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], @"mode",nil];
[settingsDict writeToFile:path atomically:YES];
}
isRingerSwitch=[settingsDict valueForKey:@"mode"] ? [[settingsDict valueForKey:@"mode"] boolValue] : YES;
}
%hook SBIconController
-(void)_finishedUnscattering{
%orig;
getSettings();
if (savedState!=isRingerSwitch)
[(SpringBoard *)[%c(SpringBoard) sharedApplication] relaunchSpringBoard];
}
%end
%hook UIImage
+(id)imageNamed:(id)named{
if ([named containsSubstring:@"RotationLocked"] || [named containsSubstring:@"RotationUnlocked"] || [named containsSubstring:@"MuteOffButton"] || [named containsSubstring:@"MuteOnButton"] )
named= [NSString stringWithFormat:@"RingerSwitchTool%@",named];
return %orig;
}
%end
%ctor {
%init;
getSettings();
savedState=isRingerSwitch;
MSHookFunction(CFPreferencesGetAppBooleanValue,replaced_CFPreferencesGetAppBooleanValue,&orig_CFPreferencesGetAppBooleanValue);
}