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