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