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