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