This repository has been archived by the owner on Oct 9, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 64
/
Tweak.xm
184 lines (157 loc) · 6.84 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
/**
* @author Hao Nguyen
*/
#include "Tweak.h"
BOOL noads;
BOOL downloadWithoutWatermark;
BOOL autoPlayNextVideo;
BOOL changeRegion;
BOOL showProgressBar;
BOOL canHideUI;
BOOL enableFavoritesCollections;
NSDictionary *region;
static void reloadPrefs() {
NSDictionary *settings = [[NSMutableDictionary alloc] initWithContentsOfFile:@PLIST_PATH] ?: [@{} mutableCopy];
noads = [[settings objectForKey:@"noads"] ?: @(YES) boolValue];
downloadWithoutWatermark = [[settings objectForKey:@"downloadWithoutWatermark"] ?: @(YES) boolValue];
autoPlayNextVideo = [[settings objectForKey:@"autoPlayNextVideo"] ?: @(NO) boolValue];
changeRegion = [[settings objectForKey:@"changeRegion"] ?: @(NO) boolValue];
region = [settings objectForKey:@"region"] ?: [@{} mutableCopy];
showProgressBar = [[settings objectForKey:@"showProgressBar"] ?: @(NO) boolValue];
enableFavoritesCollections = [[settings objectForKey:@"enableFavoritesCollections"] ?: @(NO) boolValue];
canHideUI = [[settings objectForKey:@"canHideUI"] ?: @(YES) boolValue];
}
%group CoreLogic
%hook AWEAwemeModel
- (id)initWithDictionary:(id)arg1 error:(id *)arg2 {
id orig = %orig;
return noads && self.isAds ? nil : orig;
}
- (id)init {
id orig = %orig;
return noads && self.isAds ? nil : orig;
}
- (BOOL)progressBarDraggable {
return showProgressBar || %orig;
}
- (BOOL)progressBarVisible {
return showProgressBar || %orig;
}
%end
%hook CTCarrier
// Thanks chenxk-j for this
// https://github.com/chenxk-j/hookTikTok/blob/master/hooktiktok/hooktiktok.xm#L23
- (NSString *)mobileCountryCode {
return (changeRegion && region[@"mcc"] != nil) ? region[@"mcc"] : %orig;
}
- (NSString *)isoCountryCode {
return (changeRegion && region[@"code"] != nil) ? region[@"code"] : %orig;
}
- (NSString *)mobileNetworkCode {
return (changeRegion && region[@"mnc"] != nil) ? region[@"mnc"] : %orig;
}
%end
%hook AWEPlayVideoPlayerController
- (void)playerWillLoopPlaying:(id)arg1 {
if (autoPlayNextVideo) {
if ([self.container.parentViewController isKindOfClass:%c(AWEFeedTableViewController)]) {
[((AWEFeedTableViewController *)self.container.parentViewController) scrollToNextVideo];
return;
}
}
%orig;
}
%end
%hook AWEFeedContainerViewController
static AWEFeedContainerViewController *__weak sharedInstance;
%property (nonatomic, assign) BOOL isUIHidden;
- (id)init {
id orig = %orig;
self.isUIHidden = NO;
sharedInstance = orig;
return orig;
}
%new
+ (AWEFeedContainerViewController *)sharedInstance {
return sharedInstance;
}
%end
%hook AWEPlayInteractionViewController
%property (nonatomic, retain) UIButton *hideUIButton;
%property (nonatomic, retain) UIButton *downloadButton;
- (void)viewDidLoad {
%orig;
if (downloadWithoutWatermark) {
self.downloadButton = [UIButton buttonWithType:UIButtonTypeCustom];
[self.downloadButton.titleLabel setFont:[UIFont systemFontOfSize:15]];
[self.downloadButton addTarget:self action:@selector(downloadButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
// [self.downloadButton setTitle:@"Download" forState:UIControlStateNormal];
[self.downloadButton setImage:[UIImage imageWithContentsOfFile:@"/Library/Application Support/tiktokgod/download.png"] forState:UIControlStateNormal];
self.downloadButton.imageEdgeInsets = UIEdgeInsetsMake(3.0, 3.0, 3.0, 3.0);
self.downloadButton.frame = CGRectMake(self.view.frame.size.width - 30 - 10, 135.0, 30.0, 30.0);
[self.view addSubview:self.downloadButton];
}
if (canHideUI) {
AWEFeedContainerViewController *afcVC = (AWEFeedContainerViewController *)[%c(AWEFeedContainerViewController) sharedInstance];
self.hideUIButton = [UIButton buttonWithType:UIButtonTypeCustom];
[self.hideUIButton.titleLabel setFont:[UIFont systemFontOfSize:15]];
[self.hideUIButton addTarget:self action:@selector(hideUIButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
// [self.hideUIButton setTitle:afcVC.isUIHidden?@"Show UI":@"Hide UI" forState:UIControlStateNormal];
[self.hideUIButton setImage:[UIImage imageWithContentsOfFile:afcVC.isUIHidden?@"/Library/Application Support/tiktokgod/showui.png":@"/Library/Application Support/tiktokgod/hideui.png"] forState:UIControlStateNormal];
self.hideUIButton.imageView.contentMode = UIViewContentModeScaleAspectFit;
self.hideUIButton.imageEdgeInsets = UIEdgeInsetsMake(3.0, 3.0, 3.0, 3.0);
self.hideUIButton.frame = CGRectMake(self.view.frame.size.width - 30 - 10, 100.0, 30.0, 30.0);
[self.view addSubview:self.hideUIButton];
}
}
- (void)stopLoadingAnimation {
%orig;
if (canHideUI) {
dispatch_async(dispatch_get_main_queue(), ^{
[self updateShowOrHideUI];
});
}
}
%new
- (void)hideUIButtonPressed:(UIButton *)sender {
AWEFeedContainerViewController *afcVC = (AWEFeedContainerViewController *)[%c(AWEFeedContainerViewController) sharedInstance];
afcVC.isUIHidden = !afcVC.isUIHidden;
[self updateShowOrHideUI];
}
%new
- (void)downloadButtonPressed:(UIButton *)sender {
NSString *videoURLString = self.model.video.playURL.originURLList.firstObject;
if ([videoURLString containsString:@".m3u8"]) {
[HCommon showAlertMessage:@"This video format is not supported (.m3u8 file extension)" withTitle:@"Not supported" viewController:nil];
}
[[[HDownloadMediaWithProgress alloc] init] checkPermissionToPhotosAndDownload:videoURLString appendExtension:@"mp4" mediaType:Video toAlbum:@"TikTok" viewController:self];
}
%new
- (void)updateShowOrHideUI {
AWEFeedContainerViewController *afcVC = (AWEFeedContainerViewController *)[%c(AWEFeedContainerViewController) sharedInstance];
[self setHide:afcVC.isUIHidden];
[self.downloadButton setHidden:afcVC.isUIHidden];
// [self.hideUIButton setTitle:afcVC.isUIHidden?@"Show UI":@"Hide UI" forState:UIControlStateNormal];
[self.hideUIButton setImage:[UIImage imageWithContentsOfFile:afcVC.isUIHidden?@"/Library/Application Support/tiktokgod/showui.png":@"/Library/Application Support/tiktokgod/hideui.png"] forState:UIControlStateNormal];
if ([self.parentViewController isKindOfClass:%c(AWEFeedCellViewController)]) {
[afcVC setAccessoriesHidden:afcVC.isUIHidden];
}
afcVC.tabControl.hidden = afcVC.isUIHidden;
afcVC.specialEventEntranceView.hidden = afcVC.isUIHidden;
}
%end
%hook AWEFavoriteAwemeViewController
- (id)init {
if (enableFavoritesCollections) {
return [%c(TTKFavoriteAwemeCollectionsViewController) new];
} else {
return %orig;
}
}
%end
%end
%ctor {
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, (CFNotificationCallback) reloadPrefs, CFSTR(PREF_CHANGED_NOTIF), NULL, CFNotificationSuspensionBehaviorDeliverImmediately);
reloadPrefs();
%init(CoreLogic);
}