]> git.saurik.com Git - winterboard.git/blob - Library.mm
Add support for theming iOS4.0+ keyboard via UIKBColors.plist
[winterboard.git] / Library.mm
1 /* WinterBoard - Theme Manager for the iPhone
2 * Copyright (C) 2008-2010 Jay Freeman (saurik)
3 */
4
5 /*
6 * Redistribution and use in source and binary
7 * forms, with or without modification, are permitted
8 * provided that the following conditions are met:
9 *
10 * 1. Redistributions of source code must retain the
11 * above copyright notice, this list of conditions
12 * and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the
14 * above copyright notice, this list of conditions
15 * and the following disclaimer in the documentation
16 * and/or other materials provided with the
17 * distribution.
18 * 3. The name of the author may not be used to endorse
19 * or promote products derived from this software
20 * without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS''
23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
24 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
33 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
35 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 */
37
38 #include <sys/time.h>
39
40 struct timeval _ltv;
41 bool _itv;
42
43 #define _trace() do { \
44 struct timeval _ctv; \
45 gettimeofday(&_ctv, NULL); \
46 if (!_itv) { \
47 _itv = true; \
48 _ltv = _ctv; \
49 } \
50 fprintf(stderr, "%lu.%.6u[%f]:_trace()@%s:%u[%s]\n", \
51 _ctv.tv_sec, _ctv.tv_usec, \
52 (_ctv.tv_sec - _ltv.tv_sec) + (_ctv.tv_usec - _ltv.tv_usec) / 1000000.0, \
53 __FILE__, __LINE__, __FUNCTION__\
54 ); \
55 _ltv = _ctv; \
56 } while (false)
57
58 #define _transient
59
60 #import <CoreFoundation/CoreFoundation.h>
61 #import <Foundation/Foundation.h>
62 #import <CoreGraphics/CoreGraphics.h>
63 #import <ImageIO/CGImageSource.h>
64
65 #import <Celestial/AVController.h>
66 #import <Celestial/AVItem.h>
67 #import <Celestial/AVQueue.h>
68
69 #include <substrate.h>
70
71 #import <UIKit/UIKit.h>
72
73 #import <SpringBoard/SBApplication.h>
74 #import <SpringBoard/SBApplicationIcon.h>
75 #import <SpringBoard/SBAppWindow.h>
76 #import <SpringBoard/SBAwayView.h>
77 #import <SpringBoard/SBBookmarkIcon.h>
78 #import <SpringBoard/SBButtonBar.h>
79 #import <SpringBoard/SBCalendarIconContentsView.h>
80 #import <SpringBoard/SBIconController.h>
81 #import <SpringBoard/SBIconLabel.h>
82 #import <SpringBoard/SBIconList.h>
83 #import <SpringBoard/SBIconModel.h>
84 #import <SpringBoard/SBImageCache.h>
85 // XXX: #import <SpringBoard/SBSearchView.h>
86 #import <SpringBoard/SBSearchTableViewCell.h>
87 #import <SpringBoard/SBStatusBarContentsView.h>
88 #import <SpringBoard/SBStatusBarController.h>
89 #import <SpringBoard/SBStatusBarOperatorNameView.h>
90 #import <SpringBoard/SBStatusBarTimeView.h>
91 #import <SpringBoard/SBUIController.h>
92 #import <SpringBoard/SBWidgetApplicationIcon.h>
93
94 #import <MobileSMS/mSMSMessageTranscriptController.h>
95
96 #import <MediaPlayer/MPMoviePlayerController.h>
97 #import <MediaPlayer/MPVideoView.h>
98 #import <MediaPlayer/MPVideoView-PlaybackControl.h>
99
100 #import <CoreGraphics/CGGeometry.h>
101
102 #import <ChatKit/CKMessageCell.h>
103
104 extern "C" void __clear_cache (char *beg, char *end);
105
106 @protocol WinterBoard
107 - (void *) _node;
108 @end
109
110 Class $MPMoviePlayerController;
111 Class $MPVideoView;
112 Class $WebCoreFrameBridge;
113
114 Class $NSBundle;
115
116 Class $UIImage;
117 Class $UINavigationBar;
118 Class $UIToolbar;
119
120 Class $CKMessageCell;
121 Class $CKTimestampView;
122 Class $CKTranscriptController;
123 Class $CKTranscriptTableView;
124
125 Class $SBApplication;
126 Class $SBApplicationIcon;
127 Class $SBAwayView;
128 Class $SBBookmarkIcon;
129 Class $SBButtonBar;
130 Class $SBCalendarIconContentsView;
131 Class $SBDockIconListView;
132 Class $SBIcon;
133 Class $SBIconBadge;
134 Class $SBIconController;
135 Class $SBIconLabel;
136 Class $SBIconList;
137 Class $SBIconModel;
138 //Class $SBImageCache;
139 Class $SBSearchView;
140 Class $SBSearchTableViewCell;
141 Class $SBStatusBarContentsView;
142 Class $SBStatusBarController;
143 Class $SBStatusBarOperatorNameView;
144 Class $SBStatusBarTimeView;
145 Class $SBUIController;
146 Class $SBWidgetApplicationIcon;
147
148 static bool IsWild_;
149 static bool Four_;
150
151 @interface NSDictionary (WinterBoard)
152 - (UIColor *) wb$colorForKey:(NSString *)key;
153 - (BOOL) wb$boolForKey:(NSString *)key;
154 @end
155
156 @implementation NSDictionary (WinterBoard)
157
158 - (UIColor *) wb$colorForKey:(NSString *)key {
159 NSString *value = [self objectForKey:key];
160 if (value == nil)
161 return nil;
162 /* XXX: incorrect */
163 return nil;
164 }
165
166 - (BOOL) wb$boolForKey:(NSString *)key {
167 if (NSString *value = [self objectForKey:key])
168 return [value boolValue];
169 return false;
170 }
171
172 @end
173
174 static BOOL (*_GSFontGetUseLegacyFontMetrics)();
175 #define $GSFontGetUseLegacyFontMetrics() \
176 (_GSFontGetUseLegacyFontMetrics == NULL ? YES : _GSFontGetUseLegacyFontMetrics())
177
178 static bool Debug_ = false;
179 static bool Engineer_ = false;
180 static bool SummerBoard_ = true;
181 static bool SpringBoard_;
182
183 static UIImage *(*_UIApplicationImageWithName)(NSString *name);
184 static UIImage *(*_UIImageAtPath)(NSString *name, NSBundle *path);
185 static CGImageRef (*_UIImageRefAtPath)(NSString *name, bool cache, UIImageOrientation *orientation, float *scale);
186 static UIImage *(*_UIImageWithNameInDomain)(NSString *name, NSString *domain);
187 static NSBundle *(*_UIKitBundle)();
188 static bool (*_UIPackedImageTableGetIdentifierForName)(NSString *, int *);
189 static int (*_UISharedImageNameGetIdentifier)(NSString *);
190 CGColorRef (*UIKBGetNamedColor)(CFStringRef colorName);
191
192 static NSMutableDictionary *UIImages_;
193 static NSMutableDictionary *PathImages_;
194 static NSMutableDictionary *Cache_;
195 static NSMutableDictionary *Strings_;
196 static NSMutableDictionary *Themed_;
197 static NSMutableDictionary *Bundles_;
198
199 static NSFileManager *Manager_;
200 static NSDictionary *English_;
201 static NSMutableDictionary *Info_;
202 static NSMutableArray *themes_;
203
204 static NSString *$getTheme$(NSArray *files, bool parent = false) {
205 if (!parent)
206 if (NSString *path = [Themed_ objectForKey:files])
207 return reinterpret_cast<id>(path) == [NSNull null] ? nil : path;
208
209 if (Debug_)
210 NSLog(@"WB:Debug: %@", [files description]);
211
212 NSString *path;
213
214 for (NSString *theme in themes_)
215 for (NSString *file in files) {
216 path = [NSString stringWithFormat:@"%@/%@", theme, file];
217 if ([Manager_ fileExistsAtPath:path]) {
218 path = parent ? theme : path;
219 goto set;
220 }
221 }
222
223 path = nil;
224 set:
225 if (!parent)
226 [Themed_ setObject:(path == nil ? [NSNull null] : reinterpret_cast<id>(path)) forKey:files];
227 return path;
228 }
229
230 static NSString *$pathForFile$inBundle$(NSString *file, NSBundle *bundle, bool ui) {
231 NSString *identifier = [bundle bundleIdentifier];
232 NSMutableArray *names = [NSMutableArray arrayWithCapacity:8];
233
234 if (identifier != nil)
235 [names addObject:[NSString stringWithFormat:@"Bundles/%@/%@", identifier, file]];
236 if (NSString *folder = [[bundle bundlePath] lastPathComponent])
237 [names addObject:[NSString stringWithFormat:@"Folders/%@/%@", folder, file]];
238 if (ui)
239 [names addObject:[NSString stringWithFormat:@"UIImages/%@", file]];
240
241 #define remapResourceName(oldname, newname) \
242 else if ([file isEqualToString:(oldname)]) \
243 [names addObject:[NSString stringWithFormat:@"%@.png", newname]]; \
244
245 bool summer(SpringBoard_ && SummerBoard_);
246
247 if (identifier == nil);
248 else if ([identifier isEqualToString:@"com.apple.chatkit"])
249 [names addObject:[NSString stringWithFormat:@"Bundles/com.apple.MobileSMS/%@", file]];
250 else if ([identifier isEqualToString:@"com.apple.calculator"])
251 [names addObject:[NSString stringWithFormat:@"Files/Applications/Calculator.app/%@", file]];
252 else if (!summer);
253 remapResourceName(@"FSO_BG.png", @"StatusBar")
254 remapResourceName(Four_ ? @"SBDockBG-old.png" : @"SBDockBG.png", @"Dock")
255 remapResourceName(@"SBWeatherCelsius.png", @"Icons/Weather")
256
257 if (NSString *path = $getTheme$(names))
258 return path;
259
260 return nil;
261 }
262
263 static NSString *$pathForIcon$(SBApplication *self, NSString *suffix = @"") {
264 NSString *identifier = [self bundleIdentifier];
265 NSString *path = [self path];
266 NSString *folder = [path lastPathComponent];
267 NSString *dname = [self displayName];
268 NSString *didentifier = [self displayIdentifier];
269
270 if (Debug_)
271 NSLog(@"WB:Debug: [SBApplication(%@:%@:%@:%@) pathForIcon]", identifier, folder, dname, didentifier);
272
273 NSMutableArray *names = [NSMutableArray arrayWithCapacity:8];
274
275 /* XXX: I might need to keep this for backwards compatibility
276 if (identifier != nil)
277 [names addObject:[NSString stringWithFormat:@"Bundles/%@/icon.png", identifier]];
278 if (folder != nil)
279 [names addObject:[NSString stringWithFormat:@"Folders/%@/icon.png", folder]]; */
280
281 #define testForIcon(Name) \
282 if (NSString *name = Name) \
283 [names addObject:[NSString stringWithFormat:@"Icons%@/%@.png", suffix, name]];
284
285 if (![didentifier isEqualToString:identifier])
286 testForIcon(didentifier);
287
288 testForIcon(identifier);
289 testForIcon(dname);
290
291 if ([identifier isEqualToString:@"com.apple.MobileSMS"])
292 testForIcon(@"SMS");
293
294 if (didentifier != nil) {
295 testForIcon([English_ objectForKey:didentifier]);
296
297 NSArray *parts = [didentifier componentsSeparatedByString:@"-"];
298 if ([parts count] != 1)
299 if (NSDictionary *english = [[[NSDictionary alloc] initWithContentsOfFile:[path stringByAppendingString:@"/English.lproj/UIRoleDisplayNames.strings"]] autorelease])
300 testForIcon([english objectForKey:[parts lastObject]]);
301 }
302
303 if (NSString *path = $getTheme$(names))
304 return path;
305
306 return nil;
307 }
308
309 @interface NSBundle (WinterBoard)
310 + (NSBundle *) wb$bundleWithFile:(NSString *)path;
311 @end
312
313 @implementation NSBundle (WinterBoard)
314
315 + (NSBundle *) wb$bundleWithFile:(NSString *)path {
316 path = [path stringByDeletingLastPathComponent];
317 if (path == nil || [path length] == 0 || [path isEqualToString:@"/"])
318 return nil;
319
320 NSBundle *bundle([Bundles_ objectForKey:path]);
321 if (reinterpret_cast<id>(bundle) == [NSNull null])
322 return nil;
323 else if (bundle == nil) {
324 if ([Manager_ fileExistsAtPath:[path stringByAppendingPathComponent:@"Info.plist"]])
325 bundle = [NSBundle bundleWithPath:path];
326 if (bundle == nil)
327 bundle = [NSBundle wb$bundleWithFile:path];
328 if (Debug_)
329 NSLog(@"WB:Debug:PathBundle(%@, %@)", path, bundle);
330 [Bundles_ setObject:(bundle == nil ? [NSNull null] : reinterpret_cast<id>(bundle)) forKey:path];
331 }
332
333 return bundle;
334 }
335
336 @end
337
338 @interface NSString (WinterBoard)
339 - (NSString *) wb$themedPath;
340 @end
341
342 @implementation NSString (WinterBoard)
343
344 - (NSString *) wb$themedPath {
345 if (Debug_)
346 NSLog(@"WB:Debug:Bypass(\"%@\")", self);
347
348 if (NSBundle *bundle = [NSBundle wb$bundleWithFile:self]) {
349 NSString *file([self stringByResolvingSymlinksInPath]);
350 NSString *prefix([[bundle bundlePath] stringByResolvingSymlinksInPath]);
351 if ([file hasPrefix:prefix]) {
352 NSUInteger length([prefix length]);
353 if (length != [file length])
354 if (NSString *path = $pathForFile$inBundle$([file substringFromIndex:(length + 1)], bundle, false))
355 return path;
356 }
357 }
358
359 return self;
360 }
361
362 @end
363
364 void WBLogRect(const char *tag, struct CGRect rect) {
365 NSLog(@"%s:{%f,%f+%f,%f}", tag, rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
366 }
367
368 void WBLogHierarchy(UIView *view, unsigned index = 0, unsigned indent = 0) {
369 CGRect frame([view frame]);
370 NSLog(@"%*s|%2d:%p:%s : {%f,%f+%f,%f} (%@)", indent * 3, "", index, view, class_getName([view class]), frame.origin.x, frame.origin.y, frame.size.width, frame.size.height, [view backgroundColor]);
371 index = 0;
372 for (UIView *child in [view subviews])
373 WBLogHierarchy(child, index++, indent + 1);
374 }
375
376 UIImage *$cacheForImage$(UIImage *image) {
377 CGColorSpaceRef space(CGColorSpaceCreateDeviceRGB());
378 CGRect rect = {CGPointMake(1, 1), [image size]};
379 CGSize size = {rect.size.width + 2, rect.size.height + 2};
380
381 CGContextRef context(CGBitmapContextCreate(NULL, size.width, size.height, 8, 4 * size.width, space, kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst));
382 CGColorSpaceRelease(space);
383
384 CGContextDrawImage(context, rect, [image CGImage]);
385 CGImageRef ref(CGBitmapContextCreateImage(context));
386 CGContextRelease(context);
387
388 UIImage *cache([UIImage imageWithCGImage:ref]);
389 CGImageRelease(ref);
390
391 return cache;
392 }
393
394 /*MSHook(id, SBImageCache$initWithName$forImageWidth$imageHeight$initialCapacity$, SBImageCache *self, SEL sel, NSString *name, unsigned width, unsigned height, unsigned capacity) {
395 //if ([name isEqualToString:@"icons"]) return nil;
396 return _SBImageCache$initWithName$forImageWidth$imageHeight$initialCapacity$(self, sel, name, width, height, capacity);
397 }*/
398
399 MSHook(void, SBIconModel$cacheImageForIcon$, SBIconModel *self, SEL sel, SBIcon *icon) {
400 NSString *key([icon displayIdentifier]);
401
402 if (UIImage *image = [icon icon]) {
403 CGSize size = [image size];
404 if (size.width != 59 || size.height != 60) {
405 UIImage *cache($cacheForImage$(image));
406 [Cache_ setObject:cache forKey:key];
407 return;
408 }
409 }
410
411 _SBIconModel$cacheImageForIcon$(self, sel, icon);
412 }
413
414 MSHook(void, SBIconModel$cacheImagesForIcon$, SBIconModel *self, SEL sel, SBIcon *icon) {
415 /* XXX: do I /really/ have to do this? figure out how to cache the small icon! */
416 _SBIconModel$cacheImagesForIcon$(self, sel, icon);
417
418 NSString *key([icon displayIdentifier]);
419
420 if (UIImage *image = [icon icon]) {
421 CGSize size = [image size];
422 if (size.width != 59 || size.height != 60) {
423 UIImage *cache($cacheForImage$(image));
424 [Cache_ setObject:cache forKey:key];
425 return;
426 }
427 }
428 }
429
430 MSHook(UIImage *, SBIconModel$getCachedImagedForIcon$, SBIconModel *self, SEL sel, SBIcon *icon) {
431 NSString *key([icon displayIdentifier]);
432 if (UIImage *image = [Cache_ objectForKey:key])
433 return image;
434 else
435 return _SBIconModel$getCachedImagedForIcon$(self, sel, icon);
436 }
437
438 MSHook(UIImage *, SBIconModel$getCachedImagedForIcon$smallIcon$, SBIconModel *self, SEL sel, SBIcon *icon, BOOL small) {
439 if (small)
440 return _SBIconModel$getCachedImagedForIcon$smallIcon$(self, sel, icon, small);
441 NSString *key([icon displayIdentifier]);
442 if (UIImage *image = [Cache_ objectForKey:key])
443 return image;
444 else
445 return _SBIconModel$getCachedImagedForIcon$smallIcon$(self, sel, icon, small);
446 }
447
448 MSHook(id, SBSearchView$initWithFrame$, id /* XXX: SBSearchView */ self, SEL sel, struct CGRect frame) {
449 if ((self = _SBSearchView$initWithFrame$(self, sel, frame)) != nil) {
450 [self setBackgroundColor:[UIColor clearColor]];
451 for (UIView *child in [self subviews])
452 [child setBackgroundColor:[UIColor clearColor]];
453 } return self;
454 }
455
456 MSHook(id, SBSearchTableViewCell$initWithStyle$reuseIdentifier$, SBSearchTableViewCell *self, SEL sel, int style, NSString *reuse) {
457 if ((self = _SBSearchTableViewCell$initWithStyle$reuseIdentifier$(self, sel, style, reuse)) != nil) {
458 [self setBackgroundColor:[UIColor clearColor]];
459 } return self;
460 }
461
462 MSHook(void, SBSearchTableViewCell$drawRect$, SBSearchTableViewCell *self, SEL sel, struct CGRect rect, BOOL selected) {
463 _SBSearchTableViewCell$drawRect$(self, sel, rect, selected);
464 float inset([self edgeInset]);
465 [[UIColor clearColor] set];
466 UIRectFill(CGRectMake(0, 0, inset, rect.size.height));
467 UIRectFill(CGRectMake(rect.size.width - inset, 0, inset, rect.size.height));
468 }
469
470 MSHook(UIImage *, SBApplicationIcon$icon, SBApplicationIcon *self, SEL sel) {
471 if (![Info_ wb$boolForKey:@"ComposeStoreIcons"])
472 if (NSString *path = $pathForIcon$([self application]))
473 return [UIImage imageWithContentsOfFile:path];
474 return _SBApplicationIcon$icon(self, sel);
475 }
476
477 MSHook(UIImage *, SBApplicationIcon$generateIconImage$, SBApplicationIcon *self, SEL sel, int type) {
478 if (type == 2)
479 if (![Info_ wb$boolForKey:@"ComposeStoreIcons"]) {
480 if (IsWild_)
481 if (NSString *path72 = $pathForIcon$([self application], @"-72"))
482 return [UIImage imageWithContentsOfFile:path72];
483 if (NSString *path = $pathForIcon$([self application]))
484 if (UIImage *image = [UIImage imageWithContentsOfFile:path]) {
485 float width;
486 if ([$SBIcon respondsToSelector:@selector(defaultIconImageSize)])
487 width = [$SBIcon defaultIconImageSize].width;
488 else
489 width = 59;
490 return width == 59 ? image : [image _imageScaledToProportion:(width / 59.0) interpolationQuality:5];
491 }
492 }
493 return _SBApplicationIcon$generateIconImage$(self, sel, type);
494 }
495
496 MSHook(UIImage *, SBWidgetApplicationIcon$icon, SBWidgetApplicationIcon *self, SEL sel) {
497 if (Debug_)
498 NSLog(@"WB:Debug:Widget(%@:%@)", [self displayIdentifier], [self displayName]);
499 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Icons/%@.png", [self displayName]]]))
500 return [UIImage imageWithContentsOfFile:path];
501 return _SBWidgetApplicationIcon$icon(self, sel);
502 }
503
504 MSHook(UIImage *, SBBookmarkIcon$icon, SBBookmarkIcon *self, SEL sel) {
505 if (Debug_)
506 NSLog(@"WB:Debug:Bookmark(%@:%@)", [self displayIdentifier], [self displayName]);
507 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Icons/%@.png", [self displayName]]]))
508 return [UIImage imageWithContentsOfFile:path];
509 return _SBBookmarkIcon$icon(self, sel);
510 }
511
512 MSHook(NSString *, SBApplication$pathForIcon, SBApplication *self, SEL sel) {
513 if (NSString *path = $pathForIcon$(self))
514 return path;
515 return _SBApplication$pathForIcon(self, sel);
516 }
517
518 static UIImage *CachedImageAtPath(NSString *path) {
519 path = [path stringByResolvingSymlinksInPath];
520 UIImage *image = [PathImages_ objectForKey:path];
521 if (image != nil)
522 return reinterpret_cast<id>(image) == [NSNull null] ? nil : image;
523 image = [[UIImage alloc] initWithContentsOfFile:path cache:true];
524 if (image != nil)
525 image = [image autorelease];
526 [PathImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:path];
527 return image;
528 }
529
530 MSHook(CGImageSourceRef, CGImageSourceCreateWithURL, CFURLRef url, CFDictionaryRef options) {
531 if (Debug_)
532 NSLog(@"WB:Debug: CGImageSourceCreateWithURL(\"%@\", %s)", url, options);
533 NSAutoreleasePool *pool([[NSAutoreleasePool alloc] init]);
534 if (NSString *path = (NSString *) CFURLCopyFileSystemPath(url, kCFURLPOSIXPathStyle))
535 if (NSString *themed = [path wb$themedPath])
536 if (themed != path)
537 url = (CFURLRef) [NSURL fileURLWithPath:themed];
538 CGImageSourceRef source(_CGImageSourceCreateWithURL(url, options));
539 [pool release];
540 return source;
541 }
542
543 MSHook(CGImageRef, _UIImageRefAtPath, NSString *name, bool cache, UIImageOrientation *orientation, float *scale) {
544 if (Debug_)
545 NSLog(@"WB:Debug: _UIImageRefAtPath(\"%@\")", name);
546
547 NSString *themed([name wb$themedPath]);
548
549 if (false && SpringBoard_ && SummerBoard_ && themed == name) {
550 if ([name isEqualToString:@"/System/Library/CoreServices/SpringBoard.app/SBDockBGT-Portrait.png"])
551 if (NSString *path = $getTheme$([NSArray arrayWithObject:@"Dock.png"])) {
552 UIImage *image([UIImage imageWithContentsOfFile:path]);
553 CGImageRef ref([[image _imageScaledToProportion:2.4 interpolationQuality:5] imageRef]);
554 CGImageRetain(ref);
555 return ref;
556 }
557 }
558
559 return __UIImageRefAtPath(themed, cache, orientation, scale);
560 }
561
562 /*MSHook(UIImage *, _UIImageAtPath, NSString *name, NSBundle *bundle) {
563 if (bundle == nil)
564 return __UIImageAtPath(name, nil);
565 else {
566 NSString *key = [NSString stringWithFormat:@"B:%@/%@", [bundle bundleIdentifier], name];
567 UIImage *image = [PathImages_ objectForKey:key];
568 if (image != nil)
569 return reinterpret_cast<id>(image) == [NSNull null] ? nil : image;
570 if (Debug_)
571 NSLog(@"WB:Debug: _UIImageAtPath(\"%@\", %@)", name, bundle);
572 if (NSString *path = $pathForFile$inBundle$(name, bundle, false))
573 image = CachedImageAtPath(path);
574 if (image == nil)
575 image = __UIImageAtPath(name, bundle);
576 [PathImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:key];
577 return image;
578 }
579 }*/
580
581 MSHook(UIImage *, _UIApplicationImageWithName, NSString *name) {
582 NSBundle *bundle = [NSBundle mainBundle];
583 if (Debug_)
584 NSLog(@"WB:Debug: _UIApplicationImageWithName(\"%@\", %@)", name, bundle);
585 if (NSString *path = $pathForFile$inBundle$(name, bundle, false))
586 return CachedImageAtPath(path);
587 return __UIApplicationImageWithName(name);
588 }
589
590 #define WBDelegate(delegate) \
591 - (NSMethodSignature*) methodSignatureForSelector:(SEL)sel { \
592 if (Engineer_) \
593 NSLog(@"WB:MS:%s:(%s)", class_getName([self class]), sel_getName(sel)); \
594 if (NSMethodSignature *sig = [delegate methodSignatureForSelector:sel]) \
595 return sig; \
596 NSLog(@"WB:Error: [%s methodSignatureForSelector:(%s)]", class_getName([self class]), sel_getName(sel)); \
597 return nil; \
598 } \
599 \
600 - (void) forwardInvocation:(NSInvocation*)inv { \
601 SEL sel = [inv selector]; \
602 if ([delegate respondsToSelector:sel]) \
603 [inv invokeWithTarget:delegate]; \
604 else \
605 NSLog(@"WB:Error: [%s forwardInvocation:(%s)]", class_getName([self class]), sel_getName(sel)); \
606 }
607
608 MSHook(NSString *, NSBundle$pathForResource$ofType$, NSBundle *self, SEL sel, NSString *resource, NSString *type) {
609 NSString *file = type == nil ? resource : [NSString stringWithFormat:@"%@.%@", resource, type];
610 if (Debug_)
611 NSLog(@"WB:Debug: [NSBundle(%@) pathForResource:\"%@\"]", [self bundleIdentifier], file);
612 if (NSString *path = $pathForFile$inBundle$(file, self, false))
613 return path;
614 return _NSBundle$pathForResource$ofType$(self, sel, resource, type);
615 }
616
617 void $setBarStyle$_(NSString *name, int &style) {
618 if (Debug_)
619 NSLog(@"WB:Debug:%@Style:%d", name, style);
620 NSNumber *number = nil;
621 if (number == nil)
622 number = [Info_ objectForKey:[NSString stringWithFormat:@"%@Style-%d", name, style]];
623 if (number == nil)
624 number = [Info_ objectForKey:[NSString stringWithFormat:@"%@Style", name]];
625 if (number != nil) {
626 style = [number intValue];
627 if (Debug_)
628 NSLog(@"WB:Debug:%@Style=%d", name, style);
629 }
630 }
631
632 MSHook(void, SBCalendarIconContentsView$drawRect$, SBCalendarIconContentsView *self, SEL sel, CGRect rect) {
633 NSBundle *bundle([NSBundle mainBundle]);
634
635 CFLocaleRef locale(CFLocaleCopyCurrent());
636 CFDateFormatterRef formatter(CFDateFormatterCreate(NULL, locale, kCFDateFormatterNoStyle, kCFDateFormatterNoStyle));
637 CFRelease(locale);
638
639 CFDateRef now(CFDateCreate(NULL, CFAbsoluteTimeGetCurrent()));
640
641 CFDateFormatterSetFormat(formatter, (CFStringRef) [bundle localizedStringForKey:@"CALENDAR_ICON_DAY_NUMBER_FORMAT" value:@"d" table:@"SpringBoard"]);
642 CFStringRef date(CFDateFormatterCreateStringWithDate(NULL, formatter, now));
643 CFDateFormatterSetFormat(formatter, (CFStringRef) [bundle localizedStringForKey:@"CALENDAR_ICON_DAY_NAME_FORMAT" value:@"cccc" table:@"SpringBoard"]);
644 CFStringRef day(CFDateFormatterCreateStringWithDate(NULL, formatter, now));
645
646 CFRelease(now);
647
648 CFRelease(formatter);
649
650 NSString *datestyle([@""
651 "font-family: Helvetica; "
652 "font-weight: bold; "
653 "color: #333333; "
654 "alpha: 1.0; "
655 "" stringByAppendingString:(IsWild_
656 ? @"font-size: 54px; "
657 : @"font-size: 39px; "
658 )]);
659
660 NSString *daystyle([@""
661 "font-family: Helvetica; "
662 "font-weight: bold; "
663 "color: white; "
664 "text-shadow: rgba(0, 0, 0, 0.2) -1px -1px 2px; "
665 "" stringByAppendingString:(IsWild_
666 ? @"font-size: 11px; "
667 : @"font-size: 9px; "
668 )]);
669
670 if (NSString *style = [Info_ objectForKey:@"CalendarIconDateStyle"])
671 datestyle = [datestyle stringByAppendingString:style];
672 if (NSString *style = [Info_ objectForKey:@"CalendarIconDayStyle"])
673 daystyle = [daystyle stringByAppendingString:style];
674
675 float width([self bounds].size.width);
676 float leeway(10);
677 CGSize datesize = [(NSString *)date sizeWithStyle:datestyle forWidth:(width + leeway)];
678 CGSize daysize = [(NSString *)day sizeWithStyle:daystyle forWidth:(width + leeway)];
679
680 unsigned base0(IsWild_ ? 89 : 70);
681 if ($GSFontGetUseLegacyFontMetrics())
682 base0 = base0 + 1;
683 unsigned base1(IsWild_ ? 18 : 16);
684
685 if (Four_) {
686 ++base0;
687 ++base1;
688 }
689
690 [(NSString *)date drawAtPoint:CGPointMake(
691 (width + 1 - datesize.width) / 2, (base0 - datesize.height) / 2
692 ) withStyle:datestyle];
693
694 [(NSString *)day drawAtPoint:CGPointMake(
695 (width + 1 - daysize.width) / 2, (base1 - daysize.height) / 2
696 ) withStyle:daystyle];
697
698 CFRelease(date);
699 CFRelease(day);
700 }
701
702 /*static id UINavigationBarBackground$initWithFrame$withBarStyle$withTintColor$(UINavigationBarBackground<WinterBoard> *self, SEL sel, CGRect frame, int style, UIColor *tint) {
703 _trace();
704
705 if (NSNumber *number = [Info_ objectForKey:@"NavigationBarStyle"])
706 style = [number intValue];
707
708 if (UIColor *color = [Info_ wb$colorForKey:@"NavigationBarTint"])
709 tint = color;
710
711 return [self wb$initWithFrame:frame withBarStyle:style withTintColor:tint];
712 }*/
713
714 /*static id UINavigationBar$initWithCoder$(SBAppWindow<WinterBoard> *self, SEL sel, CGRect frame, NSCoder *coder) {
715 self = [self wb$initWithCoder:coder];
716 if (self == nil)
717 return nil;
718 UINavigationBar$setBarStyle$_(self);
719 return self;
720 }
721
722 static id UINavigationBar$initWithFrame$(SBAppWindow<WinterBoard> *self, SEL sel, CGRect frame) {
723 self = [self wb$initWithFrame:frame];
724 if (self == nil)
725 return nil;
726 UINavigationBar$setBarStyle$_(self);
727 return self;
728 }*/
729
730 MSHook(void, UIToolbar$setBarStyle$, UIToolbar *self, SEL sel, int style) {
731 $setBarStyle$_(@"Toolbar", style);
732 return _UIToolbar$setBarStyle$(self, sel, style);
733 }
734
735 MSHook(void, UINavigationBar$setBarStyle$, UINavigationBar *self, SEL sel, int style) {
736 $setBarStyle$_(@"NavigationBar", style);
737 return _UINavigationBar$setBarStyle$(self, sel, style);
738 }
739
740 MSHook(void, SBButtonBar$didMoveToSuperview, UIView *self, SEL sel) {
741 [[self superview] setBackgroundColor:[UIColor clearColor]];
742 _SBButtonBar$didMoveToSuperview(self, sel);
743 }
744
745 MSHook(void, SBStatusBarContentsView$didMoveToSuperview, UIView *self, SEL sel) {
746 [[self superview] setBackgroundColor:[UIColor clearColor]];
747 _SBStatusBarContentsView$didMoveToSuperview(self, sel);
748 }
749
750 MSHook(UIImage *, UIImage$defaultDesktopImage, UIImage *self, SEL sel) {
751 if (Debug_)
752 NSLog(@"WB:Debug:DefaultDesktopImage");
753 if (NSString *path = $getTheme$([NSArray arrayWithObjects:@"LockBackground.png", @"LockBackground.jpg", nil]))
754 return [UIImage imageWithContentsOfFile:path];
755 return _UIImage$defaultDesktopImage(self, sel);
756 }
757
758 static NSArray *Wallpapers_;
759 static bool Papered_;
760 static bool Docked_;
761 static NSString *WallpaperFile_;
762 static UIImageView *WallpaperImage_;
763 static UIWebDocumentView *WallpaperPage_;
764 static NSURL *WallpaperURL_;
765
766 #define _release(object) \
767 do if (object != nil) { \
768 [object release]; \
769 object = nil; \
770 } while (false)
771
772 MSHook(id, SBUIController$init, SBUIController *self, SEL sel) {
773 self = _SBUIController$init(self, sel);
774 if (self == nil)
775 return nil;
776
777 UIDevice *device([UIDevice currentDevice]);
778 IsWild_ = [device respondsToSelector:@selector(isWildcat)] && [device isWildcat];
779
780 if (Papered_) {
781 UIImageView *&_wallpaperView(MSHookIvar<UIImageView *>(self, "_wallpaperView"));
782 if (&_wallpaperView != NULL) {
783 [_wallpaperView removeFromSuperview];
784 [_wallpaperView release];
785 _wallpaperView = nil;
786 }
787 }
788
789 UIView *&_contentLayer(MSHookIvar<UIView *>(self, "_contentLayer"));
790 UIView *&_contentView(MSHookIvar<UIView *>(self, "_contentView"));
791
792 UIView **player;
793 if (&_contentLayer != NULL)
794 player = &_contentLayer;
795 else if (&_contentView != NULL)
796 player = &_contentView;
797 else
798 player = NULL;
799 UIView *layer(player == NULL ? nil : *player);
800
801 UIWindow *window([[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]);
802 UIView *content([[[UIView alloc] initWithFrame:[window frame]] autorelease]);
803 [window setContentView:content];
804
805 UIWindow *&_window(MSHookIvar<UIWindow *>(self, "_window"));
806 [window setBackgroundColor:[_window backgroundColor]];
807 [_window setBackgroundColor:[UIColor clearColor]];
808
809 [window setLevel:-1000];
810 [window setHidden:NO];
811
812 /*if (player != NULL)
813 *player = content;*/
814
815 [content setBackgroundColor:[layer backgroundColor]];
816 [layer setBackgroundColor:[UIColor clearColor]];
817
818 UIView *indirect;
819 if (!SummerBoard_ || !IsWild_)
820 indirect = content;
821 else {
822 CGRect bounds([content bounds]);
823 bounds.origin.y = -30;
824 indirect = [[[UIView alloc] initWithFrame:bounds] autorelease];
825 [content addSubview:indirect];
826 [indirect zoomToScale:2.4];
827 }
828
829 _release(WallpaperFile_);
830 _release(WallpaperImage_);
831 _release(WallpaperPage_);
832 _release(WallpaperURL_);
833
834 if (NSString *theme = $getTheme$(Wallpapers_, true)) {
835 NSString *mp4 = [theme stringByAppendingPathComponent:@"Wallpaper.mp4"];
836 if ([Manager_ fileExistsAtPath:mp4]) {
837 #if UseAVController
838 NSError *error;
839
840 static AVController *controller_(nil);
841 if (controller_ == nil) {
842 AVQueue *queue([AVQueue avQueue]);
843 controller_ = [[AVController avControllerWithQueue:queue error:&error] retain];
844 }
845
846 AVQueue *queue([controller_ queue]);
847
848 UIView *video([[[UIView alloc] initWithFrame:[indirect bounds]] autorelease]);
849 [controller_ setLayer:[video _layer]];
850
851 AVItem *item([[[AVItem alloc] initWithPath:mp4 error:&error] autorelease]);
852 [queue appendItem:item error:&error];
853
854 [controller_ play:&error];
855 #elif UseMPMoviePlayerController
856 NSURL *url([NSURL fileURLWithPath:mp4]);
857 MPMoviePlayerController *controller = [[$MPMoviePlayerController alloc] initWithContentURL:url];
858 controller.movieControlMode = MPMovieControlModeHidden;
859 [controller play];
860 #else
861 MPVideoView *video = [[[$MPVideoView alloc] initWithFrame:[indirect bounds]] autorelease];
862 [video setMovieWithPath:mp4];
863 [video setRepeatMode:1];
864 [video setRepeatGap:-1];
865 [video playFromBeginning];;
866 #endif
867
868 [indirect addSubview:video];
869 }
870
871 NSString *png = [theme stringByAppendingPathComponent:@"Wallpaper.png"];
872 NSString *jpg = [theme stringByAppendingPathComponent:@"Wallpaper.jpg"];
873
874 NSString *path;
875 if ([Manager_ fileExistsAtPath:png])
876 path = png;
877 else if ([Manager_ fileExistsAtPath:jpg])
878 path = jpg;
879 else path = nil;
880
881 UIImage *image;
882 if (path != nil) {
883 image = [[UIImage alloc] initWithContentsOfFile:path];
884 if (image != nil)
885 image = [image autorelease];
886 } else image = nil;
887
888 if (image != nil) {
889 WallpaperFile_ = [path retain];
890 WallpaperImage_ = [[UIImageView alloc] initWithImage:image];
891 if (NSNumber *number = [Info_ objectForKey:@"WallpaperAlpha"])
892 [WallpaperImage_ setAlpha:[number floatValue]];
893 [indirect addSubview:WallpaperImage_];
894 }
895
896 NSString *html = [theme stringByAppendingPathComponent:@"Wallpaper.html"];
897 if ([Manager_ fileExistsAtPath:html]) {
898 CGRect bounds = [indirect bounds];
899
900 UIWebDocumentView *view([[[UIWebDocumentView alloc] initWithFrame:bounds] autorelease]);
901 [view setAutoresizes:true];
902
903 WallpaperPage_ = [view retain];
904 WallpaperURL_ = [[NSURL fileURLWithPath:html] retain];
905
906 [WallpaperPage_ loadRequest:[NSURLRequest requestWithURL:WallpaperURL_]];
907
908 [view setBackgroundColor:[UIColor clearColor]];
909 if ([view respondsToSelector:@selector(setDrawsBackground:)])
910 [view setDrawsBackground:NO];
911 [[view webView] setDrawsBackground:NO];
912
913 [indirect addSubview:view];
914 }
915 }
916
917 for (size_t i(0), e([themes_ count]); i != e; ++i) {
918 NSString *theme = [themes_ objectAtIndex:(e - i - 1)];
919 NSString *html = [theme stringByAppendingPathComponent:@"Widget.html"];
920 if ([Manager_ fileExistsAtPath:html]) {
921 CGRect bounds = [indirect bounds];
922
923 UIWebDocumentView *view([[[UIWebDocumentView alloc] initWithFrame:bounds] autorelease]);
924 [view setAutoresizes:true];
925
926 NSURL *url = [NSURL fileURLWithPath:html];
927 [view loadRequest:[NSURLRequest requestWithURL:url]];
928
929 [view setBackgroundColor:[UIColor clearColor]];
930 if ([view respondsToSelector:@selector(setDrawsBackground:)])
931 [view setDrawsBackground:NO];
932 [[view webView] setDrawsBackground:NO];
933
934 [indirect addSubview:view];
935 }
936 }
937
938 return self;
939 }
940
941 MSHook(void, SBAwayView$updateDesktopImage$, SBAwayView *self, SEL sel, UIImage *image) {
942 NSString *path = $getTheme$([NSArray arrayWithObject:@"LockBackground.html"]);
943 UIView *&_backgroundView(MSHookIvar<UIView *>(self, "_backgroundView"));
944
945 if (path != nil && _backgroundView != nil)
946 path = nil;
947
948 _SBAwayView$updateDesktopImage$(self, sel, image);
949
950 if (path != nil) {
951 CGRect bounds = [self bounds];
952
953 UIWebDocumentView *view([[[UIWebDocumentView alloc] initWithFrame:bounds] autorelease]);
954 [view setAutoresizes:true];
955
956 if (WallpaperPage_ != nil)
957 [WallpaperPage_ release];
958 WallpaperPage_ = [view retain];
959
960 if (WallpaperURL_ != nil)
961 [WallpaperURL_ release];
962 WallpaperURL_ = [[NSURL fileURLWithPath:path] retain];
963
964 [WallpaperPage_ loadRequest:[NSURLRequest requestWithURL:WallpaperURL_]];
965
966 [[view webView] setDrawsBackground:false];
967 [view setBackgroundColor:[UIColor clearColor]];
968
969 [self insertSubview:view aboveSubview:_backgroundView];
970 }
971 }
972
973 /*extern "C" CGColorRef CGGStateGetSystemColor(void *);
974 extern "C" CGColorRef CGGStateGetFillColor(void *);
975 extern "C" CGColorRef CGGStateGetStrokeColor(void *);
976 extern "C" NSString *UIStyleStringFromColor(CGColorRef);*/
977
978 /* WBTimeLabel {{{ */
979 @interface WBTimeLabel : NSProxy {
980 NSString *time_;
981 _transient SBStatusBarTimeView *view_;
982 }
983
984 - (id) initWithTime:(NSString *)time view:(SBStatusBarTimeView *)view;
985
986 @end
987
988 @implementation WBTimeLabel
989
990 - (void) dealloc {
991 [time_ release];
992 [super dealloc];
993 }
994
995 - (id) initWithTime:(NSString *)time view:(SBStatusBarTimeView *)view {
996 time_ = [time retain];
997 view_ = view;
998 return self;
999 }
1000
1001 - (NSString *) description {
1002 return time_;
1003 }
1004
1005 WBDelegate(time_)
1006
1007 - (CGSize) drawAtPoint:(CGPoint)point forWidth:(float)width withFont:(UIFont *)font lineBreakMode:(int)mode {
1008 if (NSString *custom = [Info_ objectForKey:@"TimeStyle"]) {
1009 BOOL &_mode(MSHookIvar<BOOL>(view_, "_mode"));;
1010
1011 [time_ drawAtPoint:point withStyle:[NSString stringWithFormat:@""
1012 "font-family: Helvetica; "
1013 "font-weight: bold; "
1014 "font-size: 14px; "
1015 "color: %@; "
1016 "%@", _mode ? @"white" : @"black", custom]];
1017
1018 return CGSizeZero;
1019 }
1020
1021 return [time_ drawAtPoint:point forWidth:width withFont:font lineBreakMode:mode];
1022 }
1023
1024 @end
1025 /* }}} */
1026 /* WBBadgeLabel {{{ */
1027 @interface WBBadgeLabel : NSProxy {
1028 NSString *badge_;
1029 }
1030
1031 - (id) initWithBadge:(NSString *)badge;
1032 - (NSString *) description;
1033
1034 @end
1035
1036 @implementation WBBadgeLabel
1037
1038 - (void) dealloc {
1039 [badge_ release];
1040 [super dealloc];
1041 }
1042
1043 - (id) initWithBadge:(NSString *)badge {
1044 badge_ = [badge retain];
1045 return self;
1046 }
1047
1048 - (NSString *) description {
1049 return [badge_ description];
1050 }
1051
1052 WBDelegate(badge_)
1053
1054 - (CGSize) drawAtPoint:(CGPoint)point forWidth:(float)width withFont:(UIFont *)font lineBreakMode:(int)mode {
1055 if (NSString *custom = [Info_ objectForKey:@"BadgeStyle"]) {
1056 [badge_ drawAtPoint:point withStyle:[NSString stringWithFormat:@""
1057 "font-family: Helvetica; "
1058 "font-weight: bold; "
1059 "font-size: 17px; "
1060 "color: white; "
1061 "%@", custom]];
1062
1063 return CGSizeZero;
1064 }
1065
1066 return [badge_ drawAtPoint:point forWidth:width withFont:font lineBreakMode:mode];
1067 }
1068
1069 @end
1070 /* }}} */
1071
1072 MSHook(void, SBIcon$setAlpha$, SBIcon *self, SEL sel, float alpha) {
1073 if (NSNumber *number = [Info_ objectForKey:@"IconAlpha"])
1074 alpha = [number floatValue];
1075 return _SBIcon$setAlpha$(self, sel, alpha);
1076 }
1077
1078 MSHook(id, SBIconBadge$initWithBadge$, SBIconBadge *self, SEL sel, NSString *badge) {
1079 if ((self = _SBIconBadge$initWithBadge$(self, sel, badge)) != nil) {
1080 id &_badge(MSHookIvar<id>(self, "_badge"));
1081 if (_badge != nil)
1082 if (id label = [[WBBadgeLabel alloc] initWithBadge:[_badge autorelease]])
1083 _badge = label;
1084 } return self;
1085 }
1086
1087 void SBStatusBarController$setStatusBarMode(int &mode) {
1088 if (Debug_)
1089 NSLog(@"WB:Debug:setStatusBarMode:%d", mode);
1090 if (mode < 100) // 104:hidden 105:glowing
1091 if (NSNumber *number = [Info_ objectForKey:@"StatusBarMode"])
1092 mode = [number intValue];
1093 }
1094
1095 /*MSHook(void, SBStatusBarController$setStatusBarMode$orientation$duration$animation$, SBStatusBarController *self, SEL sel, int mode, int orientation, double duration, int animation) {
1096 NSLog(@"mode:%d orientation:%d duration:%f animation:%d", mode, orientation, duration, animation);
1097 SBStatusBarController$setStatusBarMode(mode);
1098 return _SBStatusBarController$setStatusBarMode$orientation$duration$animation$(self, sel, mode, orientation, duration, animation);
1099 }*/
1100
1101 MSHook(void, SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$, SBStatusBarController *self, SEL sel, int mode, int orientation, float duration, int fenceID, int animation) {
1102 //NSLog(@"mode:%d orientation:%d duration:%f fenceID:%d animation:%d", mode, orientation, duration, fenceID, animation);
1103 SBStatusBarController$setStatusBarMode(mode);
1104 return _SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$(self, sel, mode, orientation, duration, fenceID, animation);
1105 }
1106
1107 MSHook(void, SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$startTime$, SBStatusBarController *self, SEL sel, int mode, int orientation, double duration, int fenceID, int animation, double startTime) {
1108 //NSLog(@"mode:%d orientation:%d duration:%f fenceID:%d animation:%d startTime:%f", mode, orientation, duration, fenceID, animation, startTime);
1109 SBStatusBarController$setStatusBarMode(mode);
1110 //NSLog(@"mode=%u", mode);
1111 return _SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$startTime$(self, sel, mode, orientation, duration, fenceID, animation, startTime);
1112 }
1113
1114 /*MSHook(id, SBStatusBarContentsView$initWithStatusBar$mode$, SBStatusBarContentsView *self, SEL sel, id bar, int mode) {
1115 if (NSNumber *number = [Info_ objectForKey:@"StatusBarContentsMode"])
1116 mode = [number intValue];
1117 return _SBStatusBarContentsView$initWithStatusBar$mode$(self, sel, bar, mode);
1118 }*/
1119
1120 MSHook(NSString *, SBStatusBarOperatorNameView$operatorNameStyle, SBStatusBarOperatorNameView *self, SEL sel) {
1121 NSString *style(_SBStatusBarOperatorNameView$operatorNameStyle(self, sel));
1122 if (Debug_)
1123 NSLog(@"operatorNameStyle= %@", style);
1124 if (NSString *custom = [Info_ objectForKey:@"OperatorNameStyle"])
1125 style = [NSString stringWithFormat:@"%@; %@", style, custom];
1126 return style;
1127 }
1128
1129 MSHook(void, SBStatusBarOperatorNameView$setOperatorName$fullSize$, SBStatusBarOperatorNameView *self, SEL sel, NSString *name, BOOL full) {
1130 if (Debug_)
1131 NSLog(@"setOperatorName:\"%@\" fullSize:%u", name, full);
1132 return _SBStatusBarOperatorNameView$setOperatorName$fullSize$(self, sel, name, NO);
1133 }
1134
1135 // XXX: replace this with [SBStatusBarTimeView tile]
1136 MSHook(void, SBStatusBarTimeView$drawRect$, SBStatusBarTimeView *self, SEL sel, CGRect rect) {
1137 id &_time(MSHookIvar<id>(self, "_time"));
1138 if (_time != nil && [_time class] != [WBTimeLabel class])
1139 object_setInstanceVariable(self, "_time", reinterpret_cast<void *>([[WBTimeLabel alloc] initWithTime:[_time autorelease] view:self]));
1140 return _SBStatusBarTimeView$drawRect$(self, sel, rect);
1141 }
1142
1143 @interface UIView (WinterBoard)
1144 - (bool) wb$isWBImageView;
1145 - (void) wb$logHierarchy;
1146 @end
1147
1148 @implementation UIView (WinterBoard)
1149
1150 - (bool) wb$isWBImageView {
1151 return false;
1152 }
1153
1154 - (void) wb$logHierarchy {
1155 WBLogHierarchy(self);
1156 }
1157
1158 @end
1159
1160 @interface WBImageView : UIImageView {
1161 }
1162
1163 - (bool) wb$isWBImageView;
1164 - (void) wb$updateFrame;
1165 @end
1166
1167 @implementation WBImageView
1168
1169 - (bool) wb$isWBImageView {
1170 return true;
1171 }
1172
1173 - (void) wb$updateFrame {
1174 CGRect frame([self frame]);
1175 frame.origin.y = 0;
1176
1177 for (UIView *view(self); ; ) {
1178 view = [view superview];
1179 if (view == nil)
1180 break;
1181 frame.origin.y -= [view frame].origin.y;
1182 }
1183
1184 [self setFrame:frame];
1185 }
1186
1187 @end
1188
1189 MSHook(void, SBIconList$setFrame$, SBIconList *self, SEL sel, CGRect frame) {
1190 NSArray *subviews([self subviews]);
1191 WBImageView *view([subviews count] == 0 ? nil : [subviews objectAtIndex:0]);
1192 if (view != nil && [view wb$isWBImageView])
1193 [view wb$updateFrame];
1194 _SBIconList$setFrame$(self, sel, frame);
1195 }
1196
1197 MSHook(void, SBIconController$noteNumberOfIconListsChanged, SBIconController *self, SEL sel) {
1198 SBIconModel *&_iconModel(MSHookIvar<SBIconModel *>(self, "_iconModel"));
1199 NSArray *lists([_iconModel iconLists]);
1200
1201 for (unsigned i(0), e([lists count]); i != e; ++i)
1202 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Page%u.png", i]])) {
1203 SBIconList *list([lists objectAtIndex:i]);
1204 NSArray *subviews([list subviews]);
1205
1206 WBImageView *view([subviews count] == 0 ? nil : [subviews objectAtIndex:0]);
1207 if (view == nil || ![view wb$isWBImageView]) {
1208 view = [[[WBImageView alloc] init] autorelease];
1209 [list insertSubview:view atIndex:0];
1210 }
1211
1212 UIImage *image([UIImage imageWithContentsOfFile:path]);
1213
1214 CGRect frame([view frame]);
1215 frame.size = [image size];
1216 [view setFrame:frame];
1217
1218 [view setImage:image];
1219 [view wb$updateFrame];
1220 }
1221
1222 return _SBIconController$noteNumberOfIconListsChanged(self, sel);
1223 }
1224
1225 MSHook(id, SBIconLabel$initWithSize$label$, SBIconLabel *self, SEL sel, CGSize size, NSString *label) {
1226 self = _SBIconLabel$initWithSize$label$(self, sel, size, label);
1227 if (self != nil)
1228 [self setClipsToBounds:NO];
1229 return self;
1230 }
1231
1232 MSHook(void, SBIconLabel$setInDock$, SBIconLabel *self, SEL sel, BOOL docked) {
1233 id &_label(MSHookIvar<id>(self, "_label"));
1234 if (![Info_ wb$boolForKey:@"UndockedIconLabels"])
1235 docked = true;
1236 if (_label != nil && [_label respondsToSelector:@selector(setInDock:)])
1237 [_label setInDock:docked];
1238 return _SBIconLabel$setInDock$(self, sel, docked);
1239 }
1240
1241 MSHook(BOOL, SBDockIconListView$shouldShowNewDock, id self, SEL sel) {
1242 return SummerBoard_ && Docked_ ? NO : _SBDockIconListView$shouldShowNewDock(self, sel);
1243 }
1244
1245 MSHook(void, SBDockIconListView$setFrame$, id self, SEL sel, CGRect frame) {
1246 _SBDockIconListView$setFrame$(self, sel, frame);
1247 }
1248
1249 MSHook(NSString *, NSBundle$localizedStringForKey$value$table$, NSBundle *self, SEL sel, NSString *key, NSString *value, NSString *table) {
1250 NSString *identifier = [self bundleIdentifier];
1251 NSLocale *locale = [NSLocale currentLocale];
1252 NSString *language = [locale objectForKey:NSLocaleLanguageCode];
1253 if (Debug_)
1254 NSLog(@"WB:Debug:[NSBundle(%@) localizedStringForKey:\"%@\" value:\"%@\" table:\"%@\"] (%@)", identifier, key, value, table, language);
1255 NSString *file = table == nil ? @"Localizable" : table;
1256 NSString *name = [NSString stringWithFormat:@"%@:%@", identifier, file];
1257 NSDictionary *strings;
1258 if ((strings = [Strings_ objectForKey:name]) != nil) {
1259 if (static_cast<id>(strings) != [NSNull null]) strings:
1260 if (NSString *value = [strings objectForKey:key])
1261 return value;
1262 } else if (NSString *path = $pathForFile$inBundle$([NSString stringWithFormat:@"%@.lproj/%@.strings",
1263 language, file
1264 ], self, false)) {
1265 if ((strings = [[NSDictionary alloc] initWithContentsOfFile:path]) != nil) {
1266 [Strings_ setObject:[strings autorelease] forKey:name];
1267 goto strings;
1268 } else goto null;
1269 } else null:
1270 [Strings_ setObject:[NSNull null] forKey:name];
1271 return _NSBundle$localizedStringForKey$value$table$(self, sel, key, value, table);
1272 }
1273
1274 @class WebCoreFrameBridge;
1275 MSHook(CGSize, WebCoreFrameBridge$renderedSizeOfNode$constrainedToWidth$, WebCoreFrameBridge *self, SEL sel, id node, float width) {
1276 if (node == nil)
1277 return CGSizeZero;
1278 void **core(reinterpret_cast<void **>([node _node]));
1279 if (core == NULL || core[6] == NULL)
1280 return CGSizeZero;
1281 return _WebCoreFrameBridge$renderedSizeOfNode$constrainedToWidth$(self, sel, node, width);
1282 }
1283
1284 MSHook(void, SBIconLabel$drawRect$, SBIconLabel *self, SEL sel, CGRect rect) {
1285 CGRect bounds = [self bounds];
1286
1287 static Ivar drawMoreLegibly = object_getInstanceVariable(self, "_drawMoreLegibly", NULL);
1288
1289 int docked;
1290 Ivar ivar = object_getInstanceVariable(self, "_inDock", reinterpret_cast<void **>(&docked));
1291 docked = (docked & (ivar_getOffset(ivar) == ivar_getOffset(drawMoreLegibly) ? 0x2 : 0x1)) != 0;
1292
1293 NSString *label(MSHookIvar<NSString *>(self, "_label"));
1294
1295 NSString *style = [NSString stringWithFormat:@""
1296 "font-family: Helvetica; "
1297 "font-weight: bold; "
1298 "color: %@; %@"
1299 "", (docked || !SummerBoard_ ? @"white" : @"#b3b3b3"), (IsWild_
1300 ? @"font-size: 12px; "
1301 : @"font-size: 11px; "
1302 )];
1303
1304 if (IsWild_)
1305 style = [style stringByAppendingString:@"text-shadow: rgba(0, 0, 0, 0.5) 0px 1px 0px; "];
1306 else if (docked)
1307 style = [style stringByAppendingString:@"text-shadow: rgba(0, 0, 0, 0.5) 0px -1px 0px; "];
1308
1309 bool ellipsis(false);
1310 float max = 75, width;
1311 width:
1312 width = [(ellipsis ? [label stringByAppendingString:@"..."] : label) sizeWithStyle:style forWidth:320].width;
1313
1314 if (width > max) {
1315 size_t length([label length]);
1316 float spacing((width - max) / (length - 1));
1317
1318 if (spacing > 1.25) {
1319 ellipsis = true;
1320 label = [label substringToIndex:(length - 1)];
1321 goto width;
1322 }
1323
1324 style = [style stringByAppendingString:[NSString stringWithFormat:@"letter-spacing: -%f; ", spacing]];
1325 }
1326
1327 if (ellipsis)
1328 label = [label stringByAppendingString:@"..."];
1329
1330 if (NSString *custom = [Info_ objectForKey:(docked ? @"DockedIconLabelStyle" : @"UndockedIconLabelStyle")])
1331 style = [style stringByAppendingString:custom];
1332
1333 CGSize size = [label sizeWithStyle:style forWidth:bounds.size.width];
1334 [label drawAtPoint:CGPointMake((bounds.size.width - size.width) / 2, 0) withStyle:style];
1335 }
1336
1337 MSHook(void, CKMessageCell$addBalloonView$, id self, SEL sel, CKBalloonView *balloon) {
1338 _CKMessageCell$addBalloonView$(self, sel, balloon);
1339 [balloon setBackgroundColor:[UIColor clearColor]];
1340 }
1341
1342 MSHook(id, CKMessageCell$initWithStyle$reuseIdentifier$, id self, SEL sel, int style, NSString *reuse) {
1343 if ((self = _CKMessageCell$initWithStyle$reuseIdentifier$(self, sel, style, reuse)) != nil) {
1344 [[self contentView] setBackgroundColor:[UIColor clearColor]];
1345 } return self;
1346 }
1347
1348 MSHook(id, CKTimestampView$initWithStyle$reuseIdentifier$, id self, SEL sel, int style, NSString *reuse) {
1349 if ((self = _CKTimestampView$initWithStyle$reuseIdentifier$(self, sel, style, reuse)) != nil) {
1350 UILabel *&_label(MSHookIvar<UILabel *>(self, "_label"));
1351 [_label setBackgroundColor:[UIColor clearColor]];
1352 } return self;
1353 }
1354
1355 MSHook(void, CKTranscriptTableView$setSeparatorStyle$, id self, SEL sel, int style) {
1356 _CKTranscriptTableView$setSeparatorStyle$(self, sel, UITableViewCellSeparatorStyleNone);
1357 }
1358
1359 MSHook(id, CKTranscriptTableView$initWithFrame$style$, id self, SEL sel, CGRect frame, int style) {
1360 _trace();
1361 if ((self = _CKTranscriptTableView$initWithFrame$style$(self, sel, frame, style)) != nil) {
1362 [self setSeparatorStyle:UITableViewCellSeparatorStyleNone];
1363 } return self;
1364 }
1365
1366 MSHook(void, TranscriptController$loadView, mSMSMessageTranscriptController *self, SEL sel) {
1367 _TranscriptController$loadView(self, sel);
1368
1369 if (NSString *path = $getTheme$([NSArray arrayWithObjects:@"SMSBackground.png", @"SMSBackground.jpg", nil]))
1370 if (UIImage *image = [[UIImage alloc] initWithContentsOfFile:path]) {
1371 [image autorelease];
1372
1373 UIView *&_transcriptTable(MSHookIvar<UIView *>(self, "_transcriptTable"));
1374 UIView *&_transcriptLayer(MSHookIvar<UIView *>(self, "_transcriptLayer"));
1375 UIView *table;
1376 if (&_transcriptTable != NULL)
1377 table = _transcriptTable;
1378 else if (&_transcriptLayer != NULL)
1379 table = _transcriptLayer;
1380 else
1381 table = nil;
1382
1383 UIView *placard(table != nil ? [table superview] : MSHookIvar<UIView *>(self, "_backPlacard"));
1384 UIImageView *background([[[UIImageView alloc] initWithImage:image] autorelease]);
1385
1386 if (table == nil)
1387 [placard insertSubview:background atIndex:0];
1388 else {
1389 [table setBackgroundColor:[UIColor clearColor]];
1390 [placard insertSubview:background belowSubview:table];
1391 }
1392 }
1393 }
1394
1395 MSHook(UIImage *, _UIImageWithName, NSString *name) {
1396 if (Debug_)
1397 NSLog(@"WB:Debug: _UIImageWithName(\"%@\")", name);
1398
1399 int identifier;
1400 bool packed;
1401
1402 if (_UIPackedImageTableGetIdentifierForName != NULL)
1403 packed = _UIPackedImageTableGetIdentifierForName(name, &identifier);
1404 else if (_UISharedImageNameGetIdentifier != NULL) {
1405 identifier = _UISharedImageNameGetIdentifier(name);
1406 packed = identifier != -1;
1407 } else {
1408 identifier = -1;
1409 packed = false;
1410 }
1411
1412 if (Debug_)
1413 NSLog(@"WB:Debug: _UISharedImageNameGetIdentifier(\"%@\") = %d", name, identifier);
1414
1415 if (!packed)
1416 return __UIImageWithName(name);
1417 else {
1418 NSNumber *key([NSNumber numberWithInt:identifier]);
1419 UIImage *image([UIImages_ objectForKey:key]);
1420 if (image != nil)
1421 return reinterpret_cast<id>(image) == [NSNull null] ? __UIImageWithName(name) : image;
1422 if (NSString *path = $pathForFile$inBundle$(name, _UIKitBundle(), true)) {
1423 image = [[UIImage alloc] initWithContentsOfFile:path cache:true];
1424 if (image != nil)
1425 [image autorelease];
1426 }
1427 [UIImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:key];
1428 return image == nil ? __UIImageWithName(name) : image;
1429 }
1430 }
1431
1432 MSHook(UIImage *, _UIImageWithNameInDomain, NSString *name, NSString *domain) {
1433 NSString *key([NSString stringWithFormat:@"D:%zu%@%@", [domain length], domain, name]);
1434 UIImage *image([PathImages_ objectForKey:key]);
1435 if (image != nil)
1436 return reinterpret_cast<id>(image) == [NSNull null] ? __UIImageWithNameInDomain(name, domain) : image;
1437 if (Debug_)
1438 NSLog(@"WB:Debug: UIImageWithNameInDomain(\"%@\", \"%@\")", name, domain);
1439 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Domains/%@/%@", domain, name]])) {
1440 image = [[UIImage alloc] initWithContentsOfFile:path];
1441 if (image != nil)
1442 [image autorelease];
1443 }
1444 [PathImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:key];
1445 return image == nil ? __UIImageWithNameInDomain(name, domain) : image;
1446 }
1447
1448 MSHook(CGColorRef, UIKBGetNamedColor, CFStringRef colorName)
1449 {
1450 static CFMutableDictionaryRef keyboardColors;
1451 if (!keyboardColors) {
1452 keyboardColors = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
1453 NSString *path = [[NSBundle bundleWithPath:@"/System/Library/Frameworks/UIKit.framework"] pathForResource:@"UIKBColors" ofType:@"plist"];
1454 NSDictionary *colorSettings = [NSDictionary dictionaryWithContentsOfFile:path];
1455 if (colorSettings) {
1456 CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
1457 for (NSString *settingName in [colorSettings allKeys]) {
1458 NSArray *c = [colorSettings objectForKey:settingName];
1459 CGFloat components[4];
1460 switch ([c count]) {
1461 case 1:
1462 components[0] = [[c objectAtIndex:0] floatValue];
1463 components[1] = components[0];
1464 components[2] = components[0];
1465 components[3] = 1.0f;
1466 break;
1467 case 2:
1468 components[0] = [[c objectAtIndex:0] floatValue];
1469 components[1] = components[0];
1470 components[2] = components[0];
1471 components[0] = [[c objectAtIndex:1] floatValue];
1472 break;
1473 case 3:
1474 components[0] = [[c objectAtIndex:0] floatValue];
1475 components[1] = [[c objectAtIndex:1] floatValue];
1476 components[2] = [[c objectAtIndex:2] floatValue];
1477 components[3] = 1.0f;
1478 break;
1479 case 4:
1480 components[0] = [[c objectAtIndex:0] floatValue];
1481 components[1] = [[c objectAtIndex:1] floatValue];
1482 components[2] = [[c objectAtIndex:2] floatValue];
1483 components[3] = [[c objectAtIndex:3] floatValue];
1484 break;
1485 default:
1486 continue;
1487 }
1488 CGColorRef color = CGColorCreate(colorSpace, components);
1489 CFDictionarySetValue(keyboardColors, settingName, color);
1490 CFRelease(color);
1491 }
1492 CGColorSpaceRelease(colorSpace);
1493 }
1494 }
1495 return (CGColorRef)CFDictionaryGetValue(keyboardColors, colorName) ?: _UIKBGetNamedColor(colorName);
1496 }
1497
1498 MSHook(GSFontRef, GSFontCreateWithName, const char *name, GSFontSymbolicTraits traits, float size) {
1499 if (Debug_)
1500 NSLog(@"WB:Debug: GSFontCreateWithName(\"%s\", %f)", name, size);
1501 if (NSString *font = [Info_ objectForKey:[NSString stringWithFormat:@"FontName-%s", name]])
1502 name = [font UTF8String];
1503 //if (NSString *scale = [Info_ objectForKey:[NSString stringWithFormat:@"FontScale-%s", name]])
1504 // size *= [scale floatValue];
1505 return _GSFontCreateWithName(name, traits, size);
1506 }
1507
1508 #define AudioToolbox "/System/Library/Frameworks/AudioToolbox.framework/AudioToolbox"
1509 #define UIKit "/System/Library/Frameworks/UIKit.framework/UIKit"
1510
1511 bool (*_Z24GetFileNameForThisActionmPcRb)(unsigned long a0, char *a1, bool &a2);
1512
1513 MSHook(bool, _Z24GetFileNameForThisActionmPcRb, unsigned long a0, char *a1, bool &a2) {
1514 if (Debug_)
1515 NSLog(@"WB:Debug:GetFileNameForThisAction(%u, %p, %u)", a0, a1, a2);
1516 bool value = __Z24GetFileNameForThisActionmPcRb(a0, a1, a2);
1517 if (Debug_)
1518 NSLog(@"WB:Debug:GetFileNameForThisAction(%u, %s, %u) = %u", a0, value ? a1 : NULL, a2, value);
1519
1520 if (value) {
1521 NSString *path = [NSString stringWithUTF8String:a1];
1522 if ([path hasPrefix:@"/System/Library/Audio/UISounds/"]) {
1523 NSString *file = [path substringFromIndex:31];
1524 for (NSString *theme in themes_) {
1525 NSString *path([NSString stringWithFormat:@"%@/UISounds/%@", theme, file]);
1526 if ([Manager_ fileExistsAtPath:path]) {
1527 strcpy(a1, [path UTF8String]);
1528 continue;
1529 }
1530 }
1531 }
1532 }
1533 return value;
1534 }
1535
1536 static void ChangeWallpaper(
1537 CFNotificationCenterRef center,
1538 void *observer,
1539 CFStringRef name,
1540 const void *object,
1541 CFDictionaryRef info
1542 ) {
1543 if (Debug_)
1544 NSLog(@"WB:Debug:ChangeWallpaper!");
1545
1546 UIImage *image;
1547 if (WallpaperFile_ != nil) {
1548 image = [[UIImage alloc] initWithContentsOfFile:WallpaperFile_];
1549 if (image != nil)
1550 image = [image autorelease];
1551 } else image = nil;
1552
1553 if (WallpaperImage_ != nil)
1554 [WallpaperImage_ setImage:image];
1555 if (WallpaperPage_ != nil)
1556 [WallpaperPage_ loadRequest:[NSURLRequest requestWithURL:WallpaperURL_]];
1557
1558 }
1559
1560 #define WBRename(name, sel, imp) \
1561 _ ## name ## $ ## imp = MSHookMessage($ ## name, @selector(sel), &$ ## name ## $ ## imp)
1562
1563 template <typename Type_>
1564 static void nlset(Type_ &function, struct nlist *nl, size_t index) {
1565 struct nlist &name(nl[index]);
1566 uintptr_t value(name.n_value);
1567 if ((name.n_desc & N_ARM_THUMB_DEF) != 0)
1568 value |= 0x00000001;
1569 function = reinterpret_cast<Type_>(value);
1570 }
1571
1572 template <typename Type_>
1573 static void dlset(Type_ &function, const char *name) {
1574 function = reinterpret_cast<Type_>(dlsym(RTLD_DEFAULT, name));
1575 }
1576
1577 /*static void WBImage(const struct mach_header* mh, intptr_t vmaddr_slide) {
1578 uint32_t count(_dyld_image_count());
1579 for (uint32_t index(0); index != count; ++index)
1580 if (_dyld_get_image_header(index) == mh) {
1581 CGImageSourceRef (*CGImageSourceCreateWithURL)(CFURLRef url, CFDictionaryRef options);
1582 dlset(CGImageSourceCreateWithURL, "CGImageSourceCreateWithURL");
1583 MSHookFunction(&CGImageSourceCreateWithURL, &$CGImageSourceCreateWithURL, &_CGImageSourceCreateWithURL);
1584 }
1585 }*/
1586
1587 extern "C" void WBInitialize() {
1588 NSAutoreleasePool *pool([[NSAutoreleasePool alloc] init]);
1589
1590 NSString *identifier([[NSBundle mainBundle] bundleIdentifier]);
1591
1592 NSLog(@"WB:Notice: WinterBoard");
1593
1594 dlset(_GSFontGetUseLegacyFontMetrics, "GSFontGetUseLegacyFontMetrics");
1595
1596 //if ([NSBundle bundleWithIdentifier:@"com.apple.ImageIO.framework"] != nil)
1597 MSHookFunction(&CGImageSourceCreateWithURL, &$CGImageSourceCreateWithURL, &_CGImageSourceCreateWithURL);
1598 //else
1599 // _dyld_register_func_for_add_image(&WBImage);
1600
1601 struct nlist nl[8];
1602
1603 if ([NSBundle bundleWithIdentifier:@"com.apple.UIKit"] != nil) {
1604 // UIKit {{{
1605 memset(nl, 0, sizeof(nl));
1606 nl[0].n_un.n_name = (char *) "__UIApplicationImageWithName";
1607 nl[1].n_un.n_name = (char *) "__UIImageAtPath";
1608 nl[2].n_un.n_name = (char *) "__UIImageRefAtPath";
1609 nl[3].n_un.n_name = (char *) "__UIImageWithNameInDomain";
1610 nl[4].n_un.n_name = (char *) "__UIKitBundle";
1611 nl[5].n_un.n_name = (char *) "__UIPackedImageTableGetIdentifierForName";
1612 nl[6].n_un.n_name = (char *) "__UISharedImageNameGetIdentifier";
1613 nlist(UIKit, nl);
1614
1615 nlset(_UIApplicationImageWithName, nl, 0);
1616 nlset(_UIImageAtPath, nl, 1);
1617 nlset(_UIImageRefAtPath, nl, 2);
1618 nlset(_UIImageWithNameInDomain, nl, 3);
1619 nlset(_UIKitBundle, nl, 4);
1620 nlset(_UIPackedImageTableGetIdentifierForName, nl, 5);
1621 nlset(_UISharedImageNameGetIdentifier, nl, 6);
1622
1623 MSHookFunction(_UIApplicationImageWithName, &$_UIApplicationImageWithName, &__UIApplicationImageWithName);
1624 MSHookFunction(_UIImageRefAtPath, &$_UIImageRefAtPath, &__UIImageRefAtPath);
1625 MSHookFunction(_UIImageWithName, &$_UIImageWithName, &__UIImageWithName);
1626 MSHookFunction(_UIImageWithNameInDomain, &$_UIImageWithNameInDomain, &__UIImageWithNameInDomain);
1627
1628 dlset(UIKBGetNamedColor, "UIKBGetNamedColor");
1629 if (UIKBGetNamedColor != NULL && identifier) {
1630 MSHookFunction(UIKBGetNamedColor, &$UIKBGetNamedColor, &_UIKBGetNamedColor);
1631 }
1632 // }}}
1633 }
1634
1635 MSHookFunction(&GSFontCreateWithName, &$GSFontCreateWithName, &_GSFontCreateWithName);
1636
1637 if (dlopen(AudioToolbox, RTLD_LAZY | RTLD_NOLOAD) != NULL) {
1638 // AudioToolbox {{{
1639 struct nlist nl[2];
1640 memset(nl, 0, sizeof(nl));
1641 nl[0].n_un.n_name = (char *) "__Z24GetFileNameForThisActionmPcRb";
1642 nlist(AudioToolbox, nl);
1643 nlset(_Z24GetFileNameForThisActionmPcRb, nl, 0);
1644 MSHookFunction(_Z24GetFileNameForThisActionmPcRb, &$_Z24GetFileNameForThisActionmPcRb, &__Z24GetFileNameForThisActionmPcRb);
1645 // }}}
1646 }
1647
1648 $NSBundle = objc_getClass("NSBundle");
1649
1650 _NSBundle$localizedStringForKey$value$table$ = MSHookMessage($NSBundle, @selector(localizedStringForKey:value:table:), &$NSBundle$localizedStringForKey$value$table$);
1651 _NSBundle$pathForResource$ofType$ = MSHookMessage($NSBundle, @selector(pathForResource:ofType:), &$NSBundle$pathForResource$ofType$);
1652
1653 $UIImage = objc_getClass("UIImage");
1654 $UINavigationBar = objc_getClass("UINavigationBar");
1655 $UIToolbar = objc_getClass("UIToolbar");
1656
1657 _UIImage$defaultDesktopImage = MSHookMessage(object_getClass($UIImage), @selector(defaultDesktopImage), &$UIImage$defaultDesktopImage);
1658
1659 //WBRename("UINavigationBar", @selector(initWithCoder:), (IMP) &UINavigationBar$initWithCoder$);
1660 //WBRename("UINavigationBarBackground", @selector(initWithFrame:withBarStyle:withTintColor:), (IMP) &UINavigationBarBackground$initWithFrame$withBarStyle$withTintColor$);
1661
1662 _UINavigationBar$setBarStyle$ = MSHookMessage($UINavigationBar, @selector(setBarStyle:), &$UINavigationBar$setBarStyle$);
1663 _UIToolbar$setBarStyle$ = MSHookMessage($UIToolbar, @selector(setBarStyle:), &$UIToolbar$setBarStyle$);
1664
1665 Manager_ = [[NSFileManager defaultManager] retain];
1666 UIImages_ = [[NSMutableDictionary alloc] initWithCapacity:16];
1667 PathImages_ = [[NSMutableDictionary alloc] initWithCapacity:16];
1668 Strings_ = [[NSMutableDictionary alloc] initWithCapacity:0];
1669 Bundles_ = [[NSMutableDictionary alloc] initWithCapacity:2];
1670 Themed_ = [[NSMutableDictionary alloc] initWithCapacity:128];
1671
1672 themes_ = [[NSMutableArray alloc] initWithCapacity:8];
1673
1674 if (NSDictionary *settings = [NSDictionary dictionaryWithContentsOfFile:[NSString stringWithFormat:@"/User/Library/Preferences/com.saurik.WinterBoard.plist"]]) {
1675 // Load Settings {{{
1676 if (NSNumber *value = [settings objectForKey:@"SummerBoard"])
1677 SummerBoard_ = [value boolValue];
1678 if (NSNumber *value = [settings objectForKey:@"Debug"])
1679 Debug_ = [value boolValue];
1680
1681 NSArray *themes([settings objectForKey:@"Themes"]);
1682 if (themes == nil)
1683 if (NSString *theme = [settings objectForKey:@"Theme"])
1684 themes = [NSArray arrayWithObject:[NSDictionary dictionaryWithObjectsAndKeys:
1685 theme, @"Name",
1686 [NSNumber numberWithBool:true], @"Active",
1687 nil]];
1688
1689 if (themes != nil)
1690 for (NSDictionary *theme in themes) {
1691 NSNumber *active([theme objectForKey:@"Active"]);
1692 if (![active boolValue])
1693 continue;
1694
1695 NSString *name([theme objectForKey:@"Name"]);
1696 if (name == nil)
1697 continue;
1698
1699 NSString *theme(nil);
1700
1701 #define testForTheme(format...) \
1702 if (theme == nil) { \
1703 NSString *path = [NSString stringWithFormat:format]; \
1704 if ([Manager_ fileExistsAtPath:path]) { \
1705 [themes_ addObject:path]; \
1706 continue; \
1707 } \
1708 }
1709
1710 testForTheme(@"/Library/Themes/%@.theme", name)
1711 testForTheme(@"/Library/Themes/%@", name)
1712 testForTheme(@"%@/Library/SummerBoard/Themes/%@", NSHomeDirectory(), name)
1713
1714 }
1715 // }}}
1716 }
1717
1718 Info_ = [[NSMutableDictionary dictionaryWithCapacity:16] retain];
1719
1720 for (NSString *theme in themes_)
1721 if (NSDictionary *info = [NSDictionary dictionaryWithContentsOfFile:[NSString stringWithFormat:@"%@/Info.plist", theme]])
1722 for (NSString *key in [info allKeys])
1723 if ([Info_ objectForKey:key] == nil)
1724 [Info_ setObject:[info objectForKey:key] forKey:key];
1725
1726 bool sms($getTheme$([NSArray arrayWithObjects:@"SMSBackground.png", @"SMSBackground.jpg", nil]) != nil);
1727
1728 SpringBoard_ = [identifier isEqualToString:@"com.apple.springboard"];
1729
1730 if ([NSBundle bundleWithIdentifier:@"com.apple.chatkit"] != nil)
1731 // ChatKit {{{
1732 if (sms) {
1733 $CKMessageCell = objc_getClass("CKMessageCell");
1734 _CKMessageCell$addBalloonView$ = MSHookMessage($CKMessageCell, @selector(addBalloonView:), &$CKMessageCell$addBalloonView$);
1735 _CKMessageCell$initWithStyle$reuseIdentifier$ = MSHookMessage($CKMessageCell, @selector(initWithStyle:reuseIdentifier:), &$CKMessageCell$initWithStyle$reuseIdentifier$);
1736
1737 $CKTranscriptTableView = objc_getClass("CKTranscriptTableView");
1738 _CKTranscriptTableView$setSeparatorStyle$ = MSHookMessage($CKTranscriptTableView, @selector(setSeparatorStyle:), &$CKTranscriptTableView$setSeparatorStyle$);
1739 _CKTranscriptTableView$initWithFrame$style$ = MSHookMessage($CKTranscriptTableView, @selector(initWithFrame:style:), &$CKTranscriptTableView$initWithFrame$style$);
1740
1741 $CKTimestampView = objc_getClass("CKTimestampView");
1742 _CKTimestampView$initWithStyle$reuseIdentifier$ = MSHookMessage($CKTimestampView, @selector(initWithStyle:reuseIdentifier:), &$CKTimestampView$initWithStyle$reuseIdentifier$);
1743
1744 $CKTranscriptController = objc_getClass("CKTranscriptController");
1745 _TranscriptController$loadView = MSHookMessage($CKTranscriptController, @selector(loadView), &$TranscriptController$loadView);
1746 }
1747 // }}}
1748
1749 if ([identifier isEqualToString:@"com.apple.MobileSMS"]) {
1750 // MobileSMS {{{
1751 if (sms) {
1752 if (_TranscriptController$loadView == NULL) {
1753 Class mSMSMessageTranscriptController = objc_getClass("mSMSMessageTranscriptController");
1754 _TranscriptController$loadView = MSHookMessage(mSMSMessageTranscriptController, @selector(loadView), &$TranscriptController$loadView);
1755 }
1756 }
1757 // }}}
1758 } else if (SpringBoard_) {
1759 // SpringBoard {{{
1760 CFNotificationCenterAddObserver(
1761 CFNotificationCenterGetDarwinNotifyCenter(),
1762 NULL, &ChangeWallpaper, (CFStringRef) @"com.saurik.winterboard.lockbackground", NULL, 0
1763 );
1764
1765 if ($getTheme$([NSArray arrayWithObject:@"Wallpaper.mp4"]) != nil) {
1766 NSBundle *MediaPlayer([NSBundle bundleWithPath:@"/System/Library/Frameworks/MediaPlayer.framework"]);
1767 if (MediaPlayer != nil)
1768 [MediaPlayer load];
1769
1770 $MPMoviePlayerController = objc_getClass("MPMoviePlayerController");
1771 $MPVideoView = objc_getClass("MPVideoView");
1772 }
1773
1774 $WebCoreFrameBridge = objc_getClass("WebCoreFrameBridge");
1775
1776 $SBApplication = objc_getClass("SBApplication");
1777 $SBApplicationIcon = objc_getClass("SBApplicationIcon");
1778 $SBAwayView = objc_getClass("SBAwayView");
1779 $SBBookmarkIcon = objc_getClass("SBBookmarkIcon");
1780 $SBButtonBar = objc_getClass("SBButtonBar");
1781 $SBCalendarIconContentsView = objc_getClass("SBCalendarIconContentsView");
1782 $SBDockIconListView = objc_getClass("SBDockIconListView");
1783 $SBIcon = objc_getClass("SBIcon");
1784 $SBIconBadge = objc_getClass("SBIconBadge");
1785 $SBIconController = objc_getClass("SBIconController");
1786 $SBIconLabel = objc_getClass("SBIconLabel");
1787 $SBIconList = objc_getClass("SBIconList");
1788 $SBIconModel = objc_getClass("SBIconModel");
1789 //$SBImageCache = objc_getClass("SBImageCache");
1790 $SBSearchView = objc_getClass("SBSearchView");
1791 $SBSearchTableViewCell = objc_getClass("SBSearchTableViewCell");
1792 $SBStatusBarContentsView = objc_getClass("SBStatusBarContentsView");
1793 $SBStatusBarController = objc_getClass("SBStatusBarController");
1794 $SBStatusBarOperatorNameView = objc_getClass("SBStatusBarOperatorNameView");
1795 $SBStatusBarTimeView = objc_getClass("SBStatusBarTimeView");
1796 $SBUIController = objc_getClass("SBUIController");
1797 $SBWidgetApplicationIcon = objc_getClass("SBWidgetApplicationIcon");
1798
1799 Four_ = $SBDockIconListView != nil;
1800
1801 WBRename(WebCoreFrameBridge, renderedSizeOfNode:constrainedToWidth:, renderedSizeOfNode$constrainedToWidth$);
1802
1803 if (SummerBoard_) {
1804 WBRename(SBApplication, pathForIcon, pathForIcon);
1805 WBRename(SBApplicationIcon, icon, icon);
1806 WBRename(SBApplicationIcon, generateIconImage:, generateIconImage$);
1807 }
1808
1809 WBRename(SBBookmarkIcon, icon, icon);
1810 WBRename(SBButtonBar, didMoveToSuperview, didMoveToSuperview);
1811 WBRename(SBCalendarIconContentsView, drawRect:, drawRect$);
1812 WBRename(SBIcon, setAlpha:, setAlpha$);
1813 WBRename(SBIconBadge, initWithBadge:, initWithBadge$);
1814 WBRename(SBIconController, noteNumberOfIconListsChanged, noteNumberOfIconListsChanged);
1815 WBRename(SBUIController, init, init);
1816 WBRename(SBWidgetApplicationIcon, icon, icon);
1817
1818 WBRename(SBDockIconListView, setFrame:, setFrame$);
1819 MSHookMessage(object_getClass($SBDockIconListView), @selector(shouldShowNewDock), &$SBDockIconListView$shouldShowNewDock, &_SBDockIconListView$shouldShowNewDock);
1820
1821 WBRename(SBIconLabel, drawRect:, drawRect$);
1822 WBRename(SBIconLabel, initWithSize:label:, initWithSize$label$);
1823 WBRename(SBIconLabel, setInDock:, setInDock$);
1824
1825 WBRename(SBIconList, setFrame:, setFrame$);
1826
1827 WBRename(SBIconModel, cacheImageForIcon:, cacheImageForIcon$);
1828 WBRename(SBIconModel, cacheImagesForIcon:, cacheImagesForIcon$);
1829 WBRename(SBIconModel, getCachedImagedForIcon:, getCachedImagedForIcon$);
1830 WBRename(SBIconModel, getCachedImagedForIcon:smallIcon:, getCachedImagedForIcon$smallIcon$);
1831
1832 WBRename(SBSearchView, initWithFrame:, initWithFrame$);
1833 WBRename(SBSearchTableViewCell, drawRect:, drawRect$);
1834 WBRename(SBSearchTableViewCell, initWithStyle:reuseIdentifier:, initWithStyle$reuseIdentifier$);
1835
1836 //WBRename(SBImageCache, initWithName:forImageWidth:imageHeight:initialCapacity:, initWithName$forImageWidth$imageHeight$initialCapacity$);
1837
1838 WBRename(SBAwayView, updateDesktopImage:, updateDesktopImage$);
1839 WBRename(SBStatusBarContentsView, didMoveToSuperview, didMoveToSuperview);
1840 //WBRename(SBStatusBarContentsView, initWithStatusBar:mode:, initWithStatusBar$mode$);
1841 //WBRename(SBStatusBarController, setStatusBarMode:orientation:duration:animation:, setStatusBarMode$orientation$duration$animation$);
1842 WBRename(SBStatusBarController, setStatusBarMode:orientation:duration:fenceID:animation:, setStatusBarMode$orientation$duration$fenceID$animation$);
1843 WBRename(SBStatusBarController, setStatusBarMode:orientation:duration:fenceID:animation:startTime:, setStatusBarMode$orientation$duration$fenceID$animation$startTime$);
1844 WBRename(SBStatusBarOperatorNameView, operatorNameStyle, operatorNameStyle);
1845 WBRename(SBStatusBarOperatorNameView, setOperatorName:fullSize:, setOperatorName$fullSize$);
1846 WBRename(SBStatusBarTimeView, drawRect:, drawRect$);
1847
1848 if (SummerBoard_)
1849 English_ = [[NSDictionary alloc] initWithContentsOfFile:@"/System/Library/CoreServices/SpringBoard.app/English.lproj/LocalizedApplicationNames.strings"];
1850
1851 Cache_ = [[NSMutableDictionary alloc] initWithCapacity:64];
1852 // }}}
1853 }
1854
1855 Wallpapers_ = [[NSArray arrayWithObjects:@"Wallpaper.mp4", @"Wallpaper.png", @"Wallpaper.jpg", @"Wallpaper.html", nil] retain];
1856 Papered_ = $getTheme$(Wallpapers_) != nil;
1857
1858 Docked_ = $getTheme$([NSArray arrayWithObjects:@"Dock.png", nil]);
1859
1860 if ([Info_ objectForKey:@"UndockedIconLabels"] == nil)
1861 [Info_ setObject:[NSNumber numberWithBool:(
1862 !Papered_ ||
1863 [Info_ objectForKey:@"DockedIconLabelStyle"] != nil ||
1864 [Info_ objectForKey:@"UndockedIconLabelStyle"] != nil
1865 )] forKey:@"UndockedIconLabels"];
1866
1867 if (Debug_)
1868 NSLog(@"WB:Debug:Info = %@", [Info_ description]);
1869
1870 [pool release];
1871 }