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