]> git.saurik.com Git - winterboard.git/blob - Library.mm
Positioning adjustment.
[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 bounds.origin.y = -30;
760 indirect = [[[UIView alloc] initWithFrame:bounds] autorelease];
761 [content addSubview:indirect];
762 [indirect zoomToScale:2.4];
763 }
764
765 _release(WallpaperFile_);
766 _release(WallpaperImage_);
767 _release(WallpaperPage_);
768 _release(WallpaperURL_);
769
770 if (NSString *theme = $getTheme$(Wallpapers_, true)) {
771 NSString *mp4 = [theme stringByAppendingPathComponent:@"Wallpaper.mp4"];
772 if ([Manager_ fileExistsAtPath:mp4]) {
773 #if UseAVController
774 NSError *error;
775
776 static AVController *controller_(nil);
777 if (controller_ == nil) {
778 AVQueue *queue([AVQueue avQueue]);
779 controller_ = [[AVController avControllerWithQueue:queue error:&error] retain];
780 }
781
782 AVQueue *queue([controller_ queue]);
783
784 UIView *video([[[UIView alloc] initWithFrame:[indirect bounds]] autorelease]);
785 [controller_ setLayer:[video _layer]];
786
787 AVItem *item([[[AVItem alloc] initWithPath:mp4 error:&error] autorelease]);
788 [queue appendItem:item error:&error];
789
790 [controller_ play:&error];
791 #elif UseMPMoviePlayerController
792 NSURL *url([NSURL fileURLWithPath:mp4]);
793 MPMoviePlayerController *controller = [[$MPMoviePlayerController alloc] initWithContentURL:url];
794 controller.movieControlMode = MPMovieControlModeHidden;
795 [controller play];
796 #else
797 MPVideoView *video = [[[$MPVideoView alloc] initWithFrame:[indirect bounds]] autorelease];
798 [video setMovieWithPath:mp4];
799 [video setRepeatMode:1];
800 [video setRepeatGap:-1];
801 [video playFromBeginning];;
802 #endif
803
804 [indirect addSubview:video];
805 }
806
807 NSString *png = [theme stringByAppendingPathComponent:@"Wallpaper.png"];
808 NSString *jpg = [theme stringByAppendingPathComponent:@"Wallpaper.jpg"];
809
810 NSString *path;
811 if ([Manager_ fileExistsAtPath:png])
812 path = png;
813 else if ([Manager_ fileExistsAtPath:jpg])
814 path = jpg;
815 else path = nil;
816
817 UIImage *image;
818 if (path != nil) {
819 image = [[UIImage alloc] initWithContentsOfFile:path];
820 if (image != nil)
821 image = [image autorelease];
822 } else image = nil;
823
824 if (image != nil) {
825 WallpaperFile_ = [path retain];
826 WallpaperImage_ = [[UIImageView alloc] initWithImage:image];
827 if (NSNumber *number = [Info_ objectForKey:@"WallpaperAlpha"])
828 [WallpaperImage_ setAlpha:[number floatValue]];
829 [indirect addSubview:WallpaperImage_];
830 }
831
832 NSString *html = [theme stringByAppendingPathComponent:@"Wallpaper.html"];
833 if ([Manager_ fileExistsAtPath:html]) {
834 CGRect bounds = [indirect bounds];
835
836 UIWebDocumentView *view([[[UIWebDocumentView alloc] initWithFrame:bounds] autorelease]);
837 [view setAutoresizes:true];
838
839 WallpaperPage_ = [view retain];
840 WallpaperURL_ = [[NSURL fileURLWithPath:html] retain];
841
842 [WallpaperPage_ loadRequest:[NSURLRequest requestWithURL:WallpaperURL_]];
843
844 [view setBackgroundColor:[UIColor clearColor]];
845 if ([view respondsToSelector:@selector(setDrawsBackground:)])
846 [view setDrawsBackground:NO];
847 [[view webView] setDrawsBackground:NO];
848
849 [indirect addSubview:view];
850 }
851 }
852
853 for (size_t i(0), e([themes_ count]); i != e; ++i) {
854 NSString *theme = [themes_ objectAtIndex:(e - i - 1)];
855 NSString *html = [theme stringByAppendingPathComponent:@"Widget.html"];
856 if ([Manager_ fileExistsAtPath:html]) {
857 CGRect bounds = [indirect bounds];
858
859 UIWebDocumentView *view([[[UIWebDocumentView alloc] initWithFrame:bounds] autorelease]);
860 [view setAutoresizes:true];
861
862 NSURL *url = [NSURL fileURLWithPath:html];
863 [view loadRequest:[NSURLRequest requestWithURL:url]];
864
865 [view setBackgroundColor:[UIColor clearColor]];
866 if ([view respondsToSelector:@selector(setDrawsBackground:)])
867 [view setDrawsBackground:NO];
868 [[view webView] setDrawsBackground:NO];
869
870 [indirect addSubview:view];
871 }
872 }
873
874 [content addSubview:layer];
875
876 return self;
877 }
878
879 MSHook(void, SBAwayView$updateDesktopImage$, SBAwayView *self, SEL sel, UIImage *image) {
880 NSString *path = $getTheme$([NSArray arrayWithObject:@"LockBackground.html"]);
881 UIView *&_backgroundView(MSHookIvar<UIView *>(self, "_backgroundView"));
882
883 if (path != nil && _backgroundView != nil)
884 path = nil;
885
886 _SBAwayView$updateDesktopImage$(self, sel, image);
887
888 if (path != nil) {
889 CGRect bounds = [self bounds];
890
891 UIWebDocumentView *view([[[UIWebDocumentView alloc] initWithFrame:bounds] autorelease]);
892 [view setAutoresizes:true];
893
894 if (WallpaperPage_ != nil)
895 [WallpaperPage_ release];
896 WallpaperPage_ = [view retain];
897
898 if (WallpaperURL_ != nil)
899 [WallpaperURL_ release];
900 WallpaperURL_ = [[NSURL fileURLWithPath:path] retain];
901
902 [WallpaperPage_ loadRequest:[NSURLRequest requestWithURL:WallpaperURL_]];
903
904 [[view webView] setDrawsBackground:false];
905 [view setBackgroundColor:[UIColor clearColor]];
906
907 [self insertSubview:view aboveSubview:_backgroundView];
908 }
909 }
910
911 /*extern "C" CGColorRef CGGStateGetSystemColor(void *);
912 extern "C" CGColorRef CGGStateGetFillColor(void *);
913 extern "C" CGColorRef CGGStateGetStrokeColor(void *);
914 extern "C" NSString *UIStyleStringFromColor(CGColorRef);*/
915
916 /* WBTimeLabel {{{ */
917 @interface WBTimeLabel : NSProxy {
918 NSString *time_;
919 _transient SBStatusBarTimeView *view_;
920 }
921
922 - (id) initWithTime:(NSString *)time view:(SBStatusBarTimeView *)view;
923
924 @end
925
926 @implementation WBTimeLabel
927
928 - (void) dealloc {
929 [time_ release];
930 [super dealloc];
931 }
932
933 - (id) initWithTime:(NSString *)time view:(SBStatusBarTimeView *)view {
934 time_ = [time retain];
935 view_ = view;
936 return self;
937 }
938
939 - (NSString *) description {
940 return time_;
941 }
942
943 WBDelegate(time_)
944
945 - (CGSize) drawAtPoint:(CGPoint)point forWidth:(float)width withFont:(UIFont *)font lineBreakMode:(int)mode {
946 if (NSString *custom = [Info_ objectForKey:@"TimeStyle"]) {
947 BOOL &_mode(MSHookIvar<BOOL>(view_, "_mode"));;
948
949 [time_ drawAtPoint:point withStyle:[NSString stringWithFormat:@""
950 "font-family: Helvetica; "
951 "font-weight: bold; "
952 "font-size: 14px; "
953 "color: %@; "
954 "%@", _mode ? @"white" : @"black", custom]];
955
956 return CGSizeZero;
957 }
958
959 return [time_ drawAtPoint:point forWidth:width withFont:font lineBreakMode:mode];
960 }
961
962 @end
963 /* }}} */
964 /* WBBadgeLabel {{{ */
965 @interface WBBadgeLabel : NSProxy {
966 NSString *badge_;
967 }
968
969 - (id) initWithBadge:(NSString *)badge;
970 - (NSString *) description;
971
972 @end
973
974 @implementation WBBadgeLabel
975
976 - (void) dealloc {
977 [badge_ release];
978 [super dealloc];
979 }
980
981 - (id) initWithBadge:(NSString *)badge {
982 badge_ = [badge retain];
983 return self;
984 }
985
986 - (NSString *) description {
987 return [badge_ description];
988 }
989
990 WBDelegate(badge_)
991
992 - (CGSize) drawAtPoint:(CGPoint)point forWidth:(float)width withFont:(UIFont *)font lineBreakMode:(int)mode {
993 if (NSString *custom = [Info_ objectForKey:@"BadgeStyle"]) {
994 [badge_ drawAtPoint:point withStyle:[NSString stringWithFormat:@""
995 "font-family: Helvetica; "
996 "font-weight: bold; "
997 "font-size: 17px; "
998 "color: white; "
999 "%@", custom]];
1000
1001 return CGSizeZero;
1002 }
1003
1004 return [badge_ drawAtPoint:point forWidth:width withFont:font lineBreakMode:mode];
1005 }
1006
1007 @end
1008 /* }}} */
1009
1010 MSHook(void, SBIcon$setAlpha$, SBIcon *self, SEL sel, float alpha) {
1011 if (NSNumber *number = [Info_ objectForKey:@"IconAlpha"])
1012 alpha = [number floatValue];
1013 return _SBIcon$setAlpha$(self, sel, alpha);
1014 }
1015
1016 MSHook(id, SBIconBadge$initWithBadge$, SBIconBadge *self, SEL sel, NSString *badge) {
1017 if ((self = _SBIconBadge$initWithBadge$(self, sel, badge)) != nil) {
1018 id &_badge(MSHookIvar<id>(self, "_badge"));
1019 if (_badge != nil)
1020 if (id label = [[WBBadgeLabel alloc] initWithBadge:[_badge autorelease]])
1021 _badge = label;
1022 } return self;
1023 }
1024
1025 void SBStatusBarController$setStatusBarMode(int &mode) {
1026 if (Debug_)
1027 NSLog(@"WB:Debug:setStatusBarMode:%d", mode);
1028 if (mode < 100) // 104:hidden 105:glowing
1029 if (NSNumber *number = [Info_ objectForKey:@"StatusBarMode"])
1030 mode = [number intValue];
1031 }
1032
1033 /*MSHook(void, SBStatusBarController$setStatusBarMode$orientation$duration$animation$, SBStatusBarController *self, SEL sel, int mode, int orientation, double duration, int animation) {
1034 NSLog(@"mode:%d orientation:%d duration:%f animation:%d", mode, orientation, duration, animation);
1035 SBStatusBarController$setStatusBarMode(mode);
1036 return _SBStatusBarController$setStatusBarMode$orientation$duration$animation$(self, sel, mode, orientation, duration, animation);
1037 }*/
1038
1039 MSHook(void, SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$, SBStatusBarController *self, SEL sel, int mode, int orientation, float duration, int fenceID, int animation) {
1040 //NSLog(@"mode:%d orientation:%d duration:%f fenceID:%d animation:%d", mode, orientation, duration, fenceID, animation);
1041 SBStatusBarController$setStatusBarMode(mode);
1042 return _SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$(self, sel, mode, orientation, duration, fenceID, animation);
1043 }
1044
1045 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) {
1046 //NSLog(@"mode:%d orientation:%d duration:%f fenceID:%d animation:%d startTime:%f", mode, orientation, duration, fenceID, animation, startTime);
1047 SBStatusBarController$setStatusBarMode(mode);
1048 //NSLog(@"mode=%u", mode);
1049 return _SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$startTime$(self, sel, mode, orientation, duration, fenceID, animation, startTime);
1050 }
1051
1052 /*MSHook(id, SBStatusBarContentsView$initWithStatusBar$mode$, SBStatusBarContentsView *self, SEL sel, id bar, int mode) {
1053 if (NSNumber *number = [Info_ objectForKey:@"StatusBarContentsMode"])
1054 mode = [number intValue];
1055 return _SBStatusBarContentsView$initWithStatusBar$mode$(self, sel, bar, mode);
1056 }*/
1057
1058 MSHook(NSString *, SBStatusBarOperatorNameView$operatorNameStyle, SBStatusBarOperatorNameView *self, SEL sel) {
1059 NSString *style(_SBStatusBarOperatorNameView$operatorNameStyle(self, sel));
1060 if (Debug_)
1061 NSLog(@"operatorNameStyle= %@", style);
1062 if (NSString *custom = [Info_ objectForKey:@"OperatorNameStyle"])
1063 style = [NSString stringWithFormat:@"%@; %@", style, custom];
1064 return style;
1065 }
1066
1067 MSHook(void, SBStatusBarOperatorNameView$setOperatorName$fullSize$, SBStatusBarOperatorNameView *self, SEL sel, NSString *name, BOOL full) {
1068 if (Debug_)
1069 NSLog(@"setOperatorName:\"%@\" fullSize:%u", name, full);
1070 return _SBStatusBarOperatorNameView$setOperatorName$fullSize$(self, sel, name, NO);
1071 }
1072
1073 // XXX: replace this with [SBStatusBarTimeView tile]
1074 MSHook(void, SBStatusBarTimeView$drawRect$, SBStatusBarTimeView *self, SEL sel, CGRect rect) {
1075 id &_time(MSHookIvar<id>(self, "_time"));
1076 if (_time != nil && [_time class] != [WBTimeLabel class])
1077 object_setInstanceVariable(self, "_time", reinterpret_cast<void *>([[WBTimeLabel alloc] initWithTime:[_time autorelease] view:self]));
1078 return _SBStatusBarTimeView$drawRect$(self, sel, rect);
1079 }
1080
1081 @interface UIView (WinterBoard)
1082 - (bool) wb$isWBImageView;
1083 - (void) wb$logHierarchy;
1084 @end
1085
1086 @implementation UIView (WinterBoard)
1087
1088 - (bool) wb$isWBImageView {
1089 return false;
1090 }
1091
1092 - (void) wb$logHierarchy {
1093 WBLogHierarchy(self);
1094 }
1095
1096 @end
1097
1098 @interface WBImageView : UIImageView {
1099 }
1100
1101 - (bool) wb$isWBImageView;
1102 - (void) wb$updateFrame;
1103 @end
1104
1105 @implementation WBImageView
1106
1107 - (bool) wb$isWBImageView {
1108 return true;
1109 }
1110
1111 - (void) wb$updateFrame {
1112 CGRect frame([self frame]);
1113 frame.origin.y = 0;
1114
1115 for (UIView *view(self); ; ) {
1116 view = [view superview];
1117 if (view == nil)
1118 break;
1119 frame.origin.y -= [view frame].origin.y;
1120 }
1121
1122 [self setFrame:frame];
1123 }
1124
1125 @end
1126
1127 MSHook(void, SBIconList$setFrame$, SBIconList *self, SEL sel, CGRect frame) {
1128 NSArray *subviews([self subviews]);
1129 WBImageView *view([subviews count] == 0 ? nil : [subviews objectAtIndex:0]);
1130 if (view != nil && [view wb$isWBImageView])
1131 [view wb$updateFrame];
1132 _SBIconList$setFrame$(self, sel, frame);
1133 }
1134
1135 MSHook(void, SBIconController$noteNumberOfIconListsChanged, SBIconController *self, SEL sel) {
1136 SBIconModel *&_iconModel(MSHookIvar<SBIconModel *>(self, "_iconModel"));
1137 NSArray *lists([_iconModel iconLists]);
1138
1139 for (unsigned i(0), e([lists count]); i != e; ++i)
1140 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Page%u.png", i]])) {
1141 SBIconList *list([lists objectAtIndex:i]);
1142 NSArray *subviews([list subviews]);
1143
1144 WBImageView *view([subviews count] == 0 ? nil : [subviews objectAtIndex:0]);
1145 if (view == nil || ![view wb$isWBImageView]) {
1146 view = [[[WBImageView alloc] init] autorelease];
1147 [list insertSubview:view atIndex:0];
1148 }
1149
1150 UIImage *image([UIImage imageWithContentsOfFile:path]);
1151
1152 CGRect frame([view frame]);
1153 frame.size = [image size];
1154 [view setFrame:frame];
1155
1156 [view setImage:image];
1157 [view wb$updateFrame];
1158 }
1159
1160 return _SBIconController$noteNumberOfIconListsChanged(self, sel);
1161 }
1162
1163 MSHook(id, SBIconLabel$initWithSize$label$, SBIconLabel *self, SEL sel, CGSize size, NSString *label) {
1164 self = _SBIconLabel$initWithSize$label$(self, sel, size, label);
1165 if (self != nil)
1166 [self setClipsToBounds:NO];
1167 return self;
1168 }
1169
1170 MSHook(void, SBIconLabel$setInDock$, SBIconLabel *self, SEL sel, BOOL docked) {
1171 id &_label(MSHookIvar<id>(self, "_label"));
1172 if (![Info_ wb$boolForKey:@"UndockedIconLabels"])
1173 docked = true;
1174 if (_label != nil && [_label respondsToSelector:@selector(setInDock:)])
1175 [_label setInDock:docked];
1176 return _SBIconLabel$setInDock$(self, sel, docked);
1177 }
1178
1179 MSHook(NSString *, NSBundle$localizedStringForKey$value$table$, NSBundle *self, SEL sel, NSString *key, NSString *value, NSString *table) {
1180 NSString *identifier = [self bundleIdentifier];
1181 NSLocale *locale = [NSLocale currentLocale];
1182 NSString *language = [locale objectForKey:NSLocaleLanguageCode];
1183 if (Debug_)
1184 NSLog(@"WB:Debug:[NSBundle(%@) localizedStringForKey:\"%@\" value:\"%@\" table:\"%@\"] (%@)", identifier, key, value, table, language);
1185 NSString *file = table == nil ? @"Localizable" : table;
1186 NSString *name = [NSString stringWithFormat:@"%@:%@", identifier, file];
1187 NSDictionary *strings;
1188 if ((strings = [Strings_ objectForKey:name]) != nil) {
1189 if (static_cast<id>(strings) != [NSNull null]) strings:
1190 if (NSString *value = [strings objectForKey:key])
1191 return value;
1192 } else if (NSString *path = $pathForFile$inBundle$([NSString stringWithFormat:@"%@.lproj/%@.strings",
1193 language, file
1194 ], self, false)) {
1195 if ((strings = [[NSDictionary alloc] initWithContentsOfFile:path]) != nil) {
1196 [Strings_ setObject:[strings autorelease] forKey:name];
1197 goto strings;
1198 } else goto null;
1199 } else null:
1200 [Strings_ setObject:[NSNull null] forKey:name];
1201 return _NSBundle$localizedStringForKey$value$table$(self, sel, key, value, table);
1202 }
1203
1204 @class WebCoreFrameBridge;
1205 MSHook(CGSize, WebCoreFrameBridge$renderedSizeOfNode$constrainedToWidth$, WebCoreFrameBridge *self, SEL sel, id node, float width) {
1206 if (node == nil)
1207 return CGSizeZero;
1208 void **core(reinterpret_cast<void **>([node _node]));
1209 if (core == NULL || core[6] == NULL)
1210 return CGSizeZero;
1211 return _WebCoreFrameBridge$renderedSizeOfNode$constrainedToWidth$(self, sel, node, width);
1212 }
1213
1214 MSHook(void, SBIconLabel$drawRect$, SBIconLabel *self, SEL sel, CGRect rect) {
1215 CGRect bounds = [self bounds];
1216
1217 static Ivar drawMoreLegibly = object_getInstanceVariable(self, "_drawMoreLegibly", NULL);
1218
1219 BOOL docked;
1220 Ivar ivar = object_getInstanceVariable(self, "_inDock", reinterpret_cast<void **>(&docked));
1221 docked = (docked & (ivar_getOffset(ivar) == ivar_getOffset(drawMoreLegibly) ? 0x2 : 0x1)) != 0;
1222
1223 NSString *label(MSHookIvar<NSString *>(self, "_label"));
1224
1225 NSString *style = [NSString stringWithFormat:@""
1226 "font-family: Helvetica; "
1227 "font-weight: bold; "
1228 "color: %@; %@"
1229 "", (docked || !SummerBoard_ ? @"white" : @"#b3b3b3"), (IsWild_
1230 ? @"font-size: 12px; "
1231 : @"font-size: 11px; "
1232 )];
1233
1234 if (IsWild_)
1235 style = [style stringByAppendingString:@"text-shadow: rgba(0, 0, 0, 0.5) 0px 1px 0px; "];
1236 else if (docked)
1237 style = [style stringByAppendingString:@"text-shadow: rgba(0, 0, 0, 0.5) 0px -1px 0px; "];
1238
1239 bool ellipsis(false);
1240 float max = 75, width;
1241 width:
1242 width = [(ellipsis ? [label stringByAppendingString:@"..."] : label) sizeWithStyle:style forWidth:320].width;
1243
1244 if (width > max) {
1245 size_t length([label length]);
1246 float spacing((width - max) / (length - 1));
1247
1248 if (spacing > 1.25) {
1249 ellipsis = true;
1250 label = [label substringToIndex:(length - 1)];
1251 goto width;
1252 }
1253
1254 style = [style stringByAppendingString:[NSString stringWithFormat:@"letter-spacing: -%f; ", spacing]];
1255 }
1256
1257 if (ellipsis)
1258 label = [label stringByAppendingString:@"..."];
1259
1260 if (NSString *custom = [Info_ objectForKey:(docked ? @"DockedIconLabelStyle" : @"UndockedIconLabelStyle")])
1261 style = [style stringByAppendingString:custom];
1262
1263 CGSize size = [label sizeWithStyle:style forWidth:bounds.size.width];
1264 [label drawAtPoint:CGPointMake((bounds.size.width - size.width) / 2, 0) withStyle:style];
1265 }
1266
1267 MSHook(void, CKMessageCell$addBalloonView$, id self, SEL sel, CKBalloonView *balloon) {
1268 _CKMessageCell$addBalloonView$(self, sel, balloon);
1269 [balloon setBackgroundColor:[UIColor clearColor]];
1270 }
1271
1272 MSHook(id, CKMessageCell$initWithStyle$reuseIdentifier$, id self, SEL sel, int style, NSString *reuse) {
1273 if ((self = _CKMessageCell$initWithStyle$reuseIdentifier$(self, sel, style, reuse)) != nil) {
1274 [[self contentView] setBackgroundColor:[UIColor clearColor]];
1275 } return self;
1276 }
1277
1278 MSHook(id, CKTimestampView$initWithStyle$reuseIdentifier$, id self, SEL sel, int style, NSString *reuse) {
1279 if ((self = _CKTimestampView$initWithStyle$reuseIdentifier$(self, sel, style, reuse)) != nil) {
1280 UILabel *&_label(MSHookIvar<UILabel *>(self, "_label"));
1281 [_label setBackgroundColor:[UIColor clearColor]];
1282 } return self;
1283 }
1284
1285 MSHook(void, CKTranscriptTableView$setSeparatorStyle$, id self, SEL sel, int style) {
1286 _CKTranscriptTableView$setSeparatorStyle$(self, sel, UITableViewCellSeparatorStyleNone);
1287 }
1288
1289 MSHook(id, CKTranscriptTableView$initWithFrame$style$, id self, SEL sel, CGRect frame, int style) {
1290 _trace();
1291 if ((self = _CKTranscriptTableView$initWithFrame$style$(self, sel, frame, style)) != nil) {
1292 [self setSeparatorStyle:UITableViewCellSeparatorStyleNone];
1293 } return self;
1294 }
1295
1296 MSHook(void, TranscriptController$loadView, mSMSMessageTranscriptController *self, SEL sel) {
1297 _TranscriptController$loadView(self, sel);
1298
1299 if (NSString *path = $getTheme$([NSArray arrayWithObjects:@"SMSBackground.png", @"SMSBackground.jpg", nil]))
1300 if (UIImage *image = [[UIImage alloc] initWithContentsOfFile:path]) {
1301 [image autorelease];
1302
1303 UIView *&_transcriptTable(MSHookIvar<UIView *>(self, "_transcriptTable"));
1304 UIView *&_transcriptLayer(MSHookIvar<UIView *>(self, "_transcriptLayer"));
1305 UIView *table;
1306 if (&_transcriptTable != NULL)
1307 table = _transcriptTable;
1308 else if (&_transcriptLayer != NULL)
1309 table = _transcriptLayer;
1310 else
1311 table = nil;
1312
1313 UIView *placard(table != nil ? [table superview] : MSHookIvar<UIView *>(self, "_backPlacard"));
1314 UIImageView *background([[[UIImageView alloc] initWithImage:image] autorelease]);
1315
1316 if (table == nil)
1317 [placard insertSubview:background atIndex:0];
1318 else {
1319 [table setBackgroundColor:[UIColor clearColor]];
1320 [placard insertSubview:background belowSubview:table];
1321 }
1322 }
1323 }
1324
1325 MSHook(UIImage *, _UIImageWithName, NSString *name) {
1326 int id(_UISharedImageNameGetIdentifier(name));
1327 if (Debug_)
1328 NSLog(@"WB:Debug: _UIImageWithName(\"%@\": %d)", name, id);
1329
1330 if (id == -1)
1331 return _UIImageAtPath(name, _UIKitBundle());
1332 else {
1333 NSNumber *key([NSNumber numberWithInt:id]);
1334 UIImage *image = [UIImages_ objectForKey:key];
1335 if (image != nil)
1336 return reinterpret_cast<id>(image) == [NSNull null] ? _UISharedImageWithIdentifier(id) : image;
1337 if (NSString *path = $pathForFile$inBundle$(name, _UIKitBundle(), true)) {
1338 image = [[UIImage alloc] initWithContentsOfFile:path cache:true];
1339 if (image != nil)
1340 [image autorelease];
1341 }
1342 [UIImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:key];
1343 return image == nil ? _UISharedImageWithIdentifier(id) : image;
1344 }
1345 }
1346
1347 MSHook(UIImage *, _UIImageWithNameInDomain, NSString *name, NSString *domain) {
1348 NSString *key([NSString stringWithFormat:@"D:%zu%@%@", [domain length], domain, name]);
1349 UIImage *image([PathImages_ objectForKey:key]);
1350 if (image != nil)
1351 return reinterpret_cast<id>(image) == [NSNull null] ? __UIImageWithNameInDomain(name, domain) : image;
1352 if (Debug_)
1353 NSLog(@"WB:Debug: UIImageWithNameInDomain(\"%@\", \"%@\")", name, domain);
1354 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Domains/%@/%@", domain, name]])) {
1355 image = [[UIImage alloc] initWithContentsOfFile:path];
1356 if (image != nil)
1357 [image autorelease];
1358 }
1359 [PathImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:key];
1360 return image == nil ? __UIImageWithNameInDomain(name, domain) : image;
1361 }
1362
1363 MSHook(GSFontRef, GSFontCreateWithName, const char *name, GSFontSymbolicTraits traits, float size) {
1364 if (Debug_)
1365 NSLog(@"WB:Debug: GSFontCreateWithName(\"%s\", %f)", name, size);
1366 if (NSString *font = [Info_ objectForKey:[NSString stringWithFormat:@"FontName-%s", name]])
1367 name = [font UTF8String];
1368 return _GSFontCreateWithName(name, traits, size);
1369 }
1370
1371 #define AudioToolbox "/System/Library/Frameworks/AudioToolbox.framework/AudioToolbox"
1372 #define UIKit "/System/Library/Frameworks/UIKit.framework/UIKit"
1373
1374 bool (*_Z24GetFileNameForThisActionmPcRb)(unsigned long a0, char *a1, bool &a2);
1375
1376 MSHook(bool, _Z24GetFileNameForThisActionmPcRb, unsigned long a0, char *a1, bool &a2) {
1377 if (Debug_)
1378 NSLog(@"WB:Debug:GetFileNameForThisAction(%u, %p, %u)", a0, a1, a2);
1379 bool value = __Z24GetFileNameForThisActionmPcRb(a0, a1, a2);
1380 if (Debug_)
1381 NSLog(@"WB:Debug:GetFileNameForThisAction(%u, %s, %u) = %u", a0, value ? a1 : NULL, a2, value);
1382
1383 if (value) {
1384 NSString *path = [NSString stringWithUTF8String:a1];
1385 if ([path hasPrefix:@"/System/Library/Audio/UISounds/"]) {
1386 NSString *file = [path substringFromIndex:31];
1387 for (NSString *theme in themes_) {
1388 NSString *path([NSString stringWithFormat:@"%@/UISounds/%@", theme, file]);
1389 if ([Manager_ fileExistsAtPath:path]) {
1390 strcpy(a1, [path UTF8String]);
1391 continue;
1392 }
1393 }
1394 }
1395 }
1396 return value;
1397 }
1398
1399 static void ChangeWallpaper(
1400 CFNotificationCenterRef center,
1401 void *observer,
1402 CFStringRef name,
1403 const void *object,
1404 CFDictionaryRef info
1405 ) {
1406 if (Debug_)
1407 NSLog(@"WB:Debug:ChangeWallpaper!");
1408
1409 UIImage *image;
1410 if (WallpaperFile_ != nil) {
1411 image = [[UIImage alloc] initWithContentsOfFile:WallpaperFile_];
1412 if (image != nil)
1413 image = [image autorelease];
1414 } else image = nil;
1415
1416 if (WallpaperImage_ != nil)
1417 [WallpaperImage_ setImage:image];
1418 if (WallpaperPage_ != nil)
1419 [WallpaperPage_ loadRequest:[NSURLRequest requestWithURL:WallpaperURL_]];
1420
1421 }
1422
1423 #define WBRename(name, sel, imp) \
1424 _ ## name ## $ ## imp = MSHookMessage($ ## name, @selector(sel), &$ ## name ## $ ## imp)
1425
1426 template <typename Type_>
1427 static void nlset(Type_ &function, struct nlist *nl, size_t index) {
1428 struct nlist &name(nl[index]);
1429 uintptr_t value(name.n_value);
1430 if ((name.n_desc & N_ARM_THUMB_DEF) != 0)
1431 value |= 0x00000001;
1432 function = reinterpret_cast<Type_>(value);
1433 }
1434
1435 template <typename Type_>
1436 static void dlset(Type_ &function, const char *name) {
1437 function = reinterpret_cast<Type_>(dlsym(RTLD_DEFAULT, name));
1438 }
1439
1440 extern "C" void WBInitialize() {
1441 NSAutoreleasePool *pool([[NSAutoreleasePool alloc] init]);
1442
1443 NSString *identifier([[NSBundle mainBundle] bundleIdentifier]);
1444
1445 NSLog(@"WB:Notice: WinterBoard");
1446
1447 dlset(_GSFontGetUseLegacyFontMetrics, "GSFontGetUseLegacyFontMetrics");
1448
1449 struct nlist nl[8];
1450
1451 memset(nl, 0, sizeof(nl));
1452 nl[0].n_un.n_name = (char *) "__UIApplicationImageWithName";
1453 nl[1].n_un.n_name = (char *) "__UIImageAtPath";
1454 nl[2].n_un.n_name = (char *) "__UIImageRefAtPath";
1455 nl[3].n_un.n_name = (char *) "__UIImageWithNameInDomain";
1456 nl[4].n_un.n_name = (char *) "__UIKitBundle";
1457 nl[5].n_un.n_name = (char *) "__UISharedImageNameGetIdentifier";
1458 nl[6].n_un.n_name = (char *) "__UISharedImageWithIdentifier";
1459 nlist(UIKit, nl);
1460
1461 nlset(_UIApplicationImageWithName, nl, 0);
1462 nlset(_UIImageAtPath, nl, 1);
1463 nlset(_UIImageRefAtPath, nl, 2);
1464 nlset(_UIImageWithNameInDomain, nl, 3);
1465 nlset(_UIKitBundle, nl, 4);
1466 nlset(_UISharedImageNameGetIdentifier, nl, 5);
1467 nlset(_UISharedImageWithIdentifier, nl, 6);
1468
1469 MSHookFunction(_UIApplicationImageWithName, &$_UIApplicationImageWithName, &__UIApplicationImageWithName);
1470 MSHookFunction(_UIImageRefAtPath, &$_UIImageRefAtPath, &__UIImageRefAtPath);
1471 MSHookFunction(_UIImageWithName, &$_UIImageWithName, &__UIImageWithName);
1472 MSHookFunction(_UIImageWithNameInDomain, &$_UIImageWithNameInDomain, &__UIImageWithNameInDomain);
1473
1474 MSHookFunction(&GSFontCreateWithName, &$GSFontCreateWithName, &_GSFontCreateWithName);
1475
1476 if (dlopen(AudioToolbox, RTLD_LAZY | RTLD_NOLOAD) != NULL) {
1477 struct nlist nl[2];
1478 memset(nl, 0, sizeof(nl));
1479 nl[0].n_un.n_name = (char *) "__Z24GetFileNameForThisActionmPcRb";
1480 nlist(AudioToolbox, nl);
1481 nlset(_Z24GetFileNameForThisActionmPcRb, nl, 0);
1482 MSHookFunction(_Z24GetFileNameForThisActionmPcRb, &$_Z24GetFileNameForThisActionmPcRb, &__Z24GetFileNameForThisActionmPcRb);
1483 }
1484
1485 $NSBundle = objc_getClass("NSBundle");
1486
1487 _NSBundle$localizedStringForKey$value$table$ = MSHookMessage($NSBundle, @selector(localizedStringForKey:value:table:), &$NSBundle$localizedStringForKey$value$table$);
1488 _NSBundle$pathForResource$ofType$ = MSHookMessage($NSBundle, @selector(pathForResource:ofType:), &$NSBundle$pathForResource$ofType$);
1489
1490 $UIImage = objc_getClass("UIImage");
1491 $UINavigationBar = objc_getClass("UINavigationBar");
1492 $UIToolbar = objc_getClass("UIToolbar");
1493
1494 _UIImage$defaultDesktopImage = MSHookMessage(object_getClass($UIImage), @selector(defaultDesktopImage), &$UIImage$defaultDesktopImage);
1495
1496 //WBRename("UINavigationBar", @selector(initWithCoder:), (IMP) &UINavigationBar$initWithCoder$);
1497 //WBRename("UINavigationBarBackground", @selector(initWithFrame:withBarStyle:withTintColor:), (IMP) &UINavigationBarBackground$initWithFrame$withBarStyle$withTintColor$);
1498
1499 _UINavigationBar$setBarStyle$ = MSHookMessage($UINavigationBar, @selector(setBarStyle:), &$UINavigationBar$setBarStyle$);
1500 _UIToolbar$setBarStyle$ = MSHookMessage($UIToolbar, @selector(setBarStyle:), &$UIToolbar$setBarStyle$);
1501
1502 Manager_ = [[NSFileManager defaultManager] retain];
1503 UIImages_ = [[NSMutableDictionary alloc] initWithCapacity:16];
1504 PathImages_ = [[NSMutableDictionary alloc] initWithCapacity:16];
1505 Strings_ = [[NSMutableDictionary alloc] initWithCapacity:0];
1506 Bundles_ = [[NSMutableDictionary alloc] initWithCapacity:2];
1507 Themed_ = [[NSMutableDictionary alloc] initWithCapacity:128];
1508
1509 themes_ = [[NSMutableArray alloc] initWithCapacity:8];
1510
1511 if (NSDictionary *settings = [NSDictionary dictionaryWithContentsOfFile:[NSString stringWithFormat:@"/User/Library/Preferences/com.saurik.WinterBoard.plist"]]) {
1512 if (NSNumber *value = [settings objectForKey:@"SummerBoard"])
1513 SummerBoard_ = [value boolValue];
1514 if (NSNumber *value = [settings objectForKey:@"Debug"])
1515 Debug_ = [value boolValue];
1516
1517 NSArray *themes([settings objectForKey:@"Themes"]);
1518 if (themes == nil)
1519 if (NSString *theme = [settings objectForKey:@"Theme"])
1520 themes = [NSArray arrayWithObject:[NSDictionary dictionaryWithObjectsAndKeys:
1521 theme, @"Name",
1522 [NSNumber numberWithBool:true], @"Active",
1523 nil]];
1524
1525 if (themes != nil)
1526 for (NSDictionary *theme in themes) {
1527 NSNumber *active([theme objectForKey:@"Active"]);
1528 if (![active boolValue])
1529 continue;
1530
1531 NSString *name([theme objectForKey:@"Name"]);
1532 if (name == nil)
1533 continue;
1534
1535 NSString *theme(nil);
1536
1537 #define testForTheme(format...) \
1538 if (theme == nil) { \
1539 NSString *path = [NSString stringWithFormat:format]; \
1540 if ([Manager_ fileExistsAtPath:path]) { \
1541 [themes_ addObject:path]; \
1542 continue; \
1543 } \
1544 }
1545
1546 testForTheme(@"/Library/Themes/%@.theme", name)
1547 testForTheme(@"/Library/Themes/%@", name)
1548 testForTheme(@"%@/Library/SummerBoard/Themes/%@", NSHomeDirectory(), name)
1549
1550 }
1551 }
1552
1553 Info_ = [[NSMutableDictionary dictionaryWithCapacity:16] retain];
1554
1555 for (NSString *theme in themes_)
1556 if (NSDictionary *info = [NSDictionary dictionaryWithContentsOfFile:[NSString stringWithFormat:@"%@/Info.plist", theme]])
1557 for (NSString *key in [info allKeys])
1558 if ([Info_ objectForKey:key] == nil)
1559 [Info_ setObject:[info objectForKey:key] forKey:key];
1560
1561 bool sms($getTheme$([NSArray arrayWithObjects:@"SMSBackground.png", @"SMSBackground.jpg", nil]) != nil);
1562
1563 if ([NSBundle bundleWithIdentifier:@"com.apple.chatkit"])
1564 if (sms) {
1565 $CKMessageCell = objc_getClass("CKMessageCell");
1566 _CKMessageCell$addBalloonView$ = MSHookMessage($CKMessageCell, @selector(addBalloonView:), &$CKMessageCell$addBalloonView$);
1567 _CKMessageCell$initWithStyle$reuseIdentifier$ = MSHookMessage($CKMessageCell, @selector(initWithStyle:reuseIdentifier:), &$CKMessageCell$initWithStyle$reuseIdentifier$);
1568
1569 $CKTranscriptTableView = objc_getClass("CKTranscriptTableView");
1570 _CKTranscriptTableView$setSeparatorStyle$ = MSHookMessage($CKTranscriptTableView, @selector(setSeparatorStyle:), &$CKTranscriptTableView$setSeparatorStyle$);
1571 _CKTranscriptTableView$initWithFrame$style$ = MSHookMessage($CKTranscriptTableView, @selector(initWithFrame:style:), &$CKTranscriptTableView$initWithFrame$style$);
1572
1573 $CKTimestampView = objc_getClass("CKTimestampView");
1574 _CKTimestampView$initWithStyle$reuseIdentifier$ = MSHookMessage($CKTimestampView, @selector(initWithStyle:reuseIdentifier:), &$CKTimestampView$initWithStyle$reuseIdentifier$);
1575
1576 $CKTranscriptController = objc_getClass("CKTranscriptController");
1577 _TranscriptController$loadView = MSHookMessage($CKTranscriptController, @selector(loadView), &$TranscriptController$loadView);
1578 }
1579
1580 if ([identifier isEqualToString:@"com.apple.MobileSMS"]) {
1581 if (sms) {
1582 if (_TranscriptController$loadView == NULL) {
1583 Class mSMSMessageTranscriptController = objc_getClass("mSMSMessageTranscriptController");
1584 _TranscriptController$loadView = MSHookMessage(mSMSMessageTranscriptController, @selector(loadView), &$TranscriptController$loadView);
1585 }
1586 }
1587 } else if ([identifier isEqualToString:@"com.apple.springboard"]) {
1588 CFNotificationCenterAddObserver(
1589 CFNotificationCenterGetDarwinNotifyCenter(),
1590 NULL, &ChangeWallpaper, (CFStringRef) @"com.saurik.winterboard.lockbackground", NULL, 0
1591 );
1592
1593 if ($getTheme$([NSArray arrayWithObject:@"Wallpaper.mp4"]) != nil) {
1594 NSBundle *MediaPlayer([NSBundle bundleWithPath:@"/System/Library/Frameworks/MediaPlayer.framework"]);
1595 if (MediaPlayer != nil)
1596 [MediaPlayer load];
1597
1598 $MPMoviePlayerController = objc_getClass("MPMoviePlayerController");
1599 $MPVideoView = objc_getClass("MPVideoView");
1600 }
1601
1602 $WebCoreFrameBridge = objc_getClass("WebCoreFrameBridge");
1603
1604 $SBApplication = objc_getClass("SBApplication");
1605 $SBApplicationIcon = objc_getClass("SBApplicationIcon");
1606 $SBAwayView = objc_getClass("SBAwayView");
1607 $SBBookmarkIcon = objc_getClass("SBBookmarkIcon");
1608 $SBButtonBar = objc_getClass("SBButtonBar");
1609 $SBCalendarIconContentsView = objc_getClass("SBCalendarIconContentsView");
1610 $SBIcon = objc_getClass("SBIcon");
1611 $SBIconBadge = objc_getClass("SBIconBadge");
1612 $SBIconController = objc_getClass("SBIconController");
1613 $SBIconLabel = objc_getClass("SBIconLabel");
1614 $SBIconList = objc_getClass("SBIconList");
1615 $SBIconModel = objc_getClass("SBIconModel");
1616 //$SBImageCache = objc_getClass("SBImageCache");
1617 $SBSearchView = objc_getClass("SBSearchView");
1618 $SBSearchTableViewCell = objc_getClass("SBSearchTableViewCell");
1619 $SBStatusBarContentsView = objc_getClass("SBStatusBarContentsView");
1620 $SBStatusBarController = objc_getClass("SBStatusBarController");
1621 $SBStatusBarOperatorNameView = objc_getClass("SBStatusBarOperatorNameView");
1622 $SBStatusBarTimeView = objc_getClass("SBStatusBarTimeView");
1623 $SBUIController = objc_getClass("SBUIController");
1624 $SBWidgetApplicationIcon = objc_getClass("SBWidgetApplicationIcon");
1625
1626 WBRename(WebCoreFrameBridge, renderedSizeOfNode:constrainedToWidth:, renderedSizeOfNode$constrainedToWidth$);
1627
1628 if (SummerBoard_) {
1629 WBRename(SBApplication, pathForIcon, pathForIcon);
1630 WBRename(SBApplicationIcon, icon, icon);
1631 WBRename(SBApplicationIcon, generateIconImage:, generateIconImage$);
1632 }
1633
1634 WBRename(SBBookmarkIcon, icon, icon);
1635 WBRename(SBButtonBar, didMoveToSuperview, didMoveToSuperview);
1636 WBRename(SBCalendarIconContentsView, drawRect:, drawRect$);
1637 WBRename(SBIcon, setAlpha:, setAlpha$);
1638 WBRename(SBIconBadge, initWithBadge:, initWithBadge$);
1639 WBRename(SBIconController, noteNumberOfIconListsChanged, noteNumberOfIconListsChanged);
1640 WBRename(SBUIController, init, init);
1641 WBRename(SBWidgetApplicationIcon, icon, icon);
1642
1643 WBRename(SBIconLabel, drawRect:, drawRect$);
1644 WBRename(SBIconLabel, initWithSize:label:, initWithSize$label$);
1645 WBRename(SBIconLabel, setInDock:, setInDock$);
1646
1647 WBRename(SBIconList, setFrame:, setFrame$);
1648
1649 WBRename(SBIconModel, cacheImageForIcon:, cacheImageForIcon$);
1650 WBRename(SBIconModel, cacheImagesForIcon:, cacheImagesForIcon$);
1651 WBRename(SBIconModel, getCachedImagedForIcon:, getCachedImagedForIcon$);
1652 WBRename(SBIconModel, getCachedImagedForIcon:smallIcon:, getCachedImagedForIcon$smallIcon$);
1653
1654 WBRename(SBSearchView, initWithFrame:, initWithFrame$);
1655 WBRename(SBSearchTableViewCell, drawRect:, drawRect$);
1656 WBRename(SBSearchTableViewCell, initWithStyle:reuseIdentifier:, initWithStyle$reuseIdentifier$);
1657
1658 //WBRename(SBImageCache, initWithName:forImageWidth:imageHeight:initialCapacity:, initWithName$forImageWidth$imageHeight$initialCapacity$);
1659
1660 WBRename(SBAwayView, updateDesktopImage:, updateDesktopImage$);
1661 WBRename(SBStatusBarContentsView, didMoveToSuperview, didMoveToSuperview);
1662 //WBRename(SBStatusBarContentsView, initWithStatusBar:mode:, initWithStatusBar$mode$);
1663 //WBRename(SBStatusBarController, setStatusBarMode:orientation:duration:animation:, setStatusBarMode$orientation$duration$animation$);
1664 WBRename(SBStatusBarController, setStatusBarMode:orientation:duration:fenceID:animation:, setStatusBarMode$orientation$duration$fenceID$animation$);
1665 WBRename(SBStatusBarController, setStatusBarMode:orientation:duration:fenceID:animation:startTime:, setStatusBarMode$orientation$duration$fenceID$animation$startTime$);
1666 WBRename(SBStatusBarOperatorNameView, operatorNameStyle, operatorNameStyle);
1667 WBRename(SBStatusBarOperatorNameView, setOperatorName:fullSize:, setOperatorName$fullSize$);
1668 WBRename(SBStatusBarTimeView, drawRect:, drawRect$);
1669
1670 if (SummerBoard_)
1671 English_ = [[NSDictionary alloc] initWithContentsOfFile:@"/System/Library/CoreServices/SpringBoard.app/English.lproj/LocalizedApplicationNames.strings"];
1672
1673 Cache_ = [[NSMutableDictionary alloc] initWithCapacity:64];
1674 }
1675
1676 Wallpapers_ = [[NSArray arrayWithObjects:@"Wallpaper.mp4", @"Wallpaper.png", @"Wallpaper.jpg", @"Wallpaper.html", nil] retain];
1677 Papered_ = $getTheme$(Wallpapers_) != nil;
1678
1679 UIDevice *device([UIDevice currentDevice]);
1680 IsWild_ = [device respondsToSelector:@selector(isWildcat)] && [device isWildcat];
1681
1682 if ([Info_ objectForKey:@"UndockedIconLabels"] == nil)
1683 [Info_ setObject:[NSNumber numberWithBool:(
1684 Papered_ ||
1685 [Info_ objectForKey:@"DockedIconLabelStyle"] != nil ||
1686 [Info_ objectForKey:@"UndockedIconLabelStyle"] != nil
1687 )] forKey:@"UndockedIconLabels"];
1688
1689 if (Debug_)
1690 NSLog(@"WB:Debug:Info = %@", [Info_ description]);
1691
1692 [pool release];
1693 }