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