]> git.saurik.com Git - winterboard.git/blobdiff - Library.mm
Various upgrades for 3.x and performance.
[winterboard.git] / Library.mm
index d3170992996d69429f986a37e5e7da33bbc65465..9242b679c3af6b314ed8113bdaace4c4a8606afa 100644 (file)
  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
-#define _trace() NSLog(@"WB:_trace(%u)", __LINE__);
+#include <sys/time.h>
+
+struct timeval _ltv;
+bool _itv;
+
+#define _trace() do { \
+    struct timeval _ctv; \
+    gettimeofday(&_ctv, NULL); \
+    if (!_itv) { \
+        _itv = true; \
+        _ltv = _ctv; \
+    } \
+    fprintf(stderr, "%lu.%.6u[%f]:_trace()@%s:%u[%s]\n", \
+        _ctv.tv_sec, _ctv.tv_usec, \
+        (_ctv.tv_sec - _ltv.tv_sec) + (_ctv.tv_usec - _ltv.tv_usec) / 1000000.0, \
+        __FILE__, __LINE__, __FUNCTION__\
+    ); \
+    _ltv = _ctv; \
+} while (false)
+
 #define _transient
 
 #import <CoreFoundation/CoreFoundation.h>
 #import <Foundation/Foundation.h>
 #import <CoreGraphics/CoreGraphics.h>
 
+#import <Celestial/AVController.h>
+#import <Celestial/AVItem.h>
+#import <Celestial/AVQueue.h>
+
 #include <substrate.h>
 
 #import <UIKit/UIKit.h>
 #import <SpringBoard/SBApplication.h>
 #import <SpringBoard/SBApplicationIcon.h>
 #import <SpringBoard/SBAppWindow.h>
+#import <SpringBoard/SBAwayView.h>
 #import <SpringBoard/SBBookmarkIcon.h>
 #import <SpringBoard/SBButtonBar.h>
 #import <SpringBoard/SBCalendarIconContentsView.h>
-#import <SpringBoard/SBContentLayer.h>
 #import <SpringBoard/SBIconController.h>
 #import <SpringBoard/SBIconLabel.h>
-#import <SpringBoard/SBSlidingAlertDisplay.h>
+#import <SpringBoard/SBIconList.h>
+#import <SpringBoard/SBIconModel.h>
+#import <SpringBoard/SBImageCache.h>
 #import <SpringBoard/SBStatusBarContentsView.h>
 #import <SpringBoard/SBStatusBarController.h>
 #import <SpringBoard/SBStatusBarOperatorNameView.h>
 #import <SpringBoard/SBStatusBarTimeView.h>
 #import <SpringBoard/SBUIController.h>
+#import <SpringBoard/SBWidgetApplicationIcon.h>
 
 #import <MobileSMS/mSMSMessageTranscriptController.h>
 
+#import <MediaPlayer/MPMoviePlayerController.h>
 #import <MediaPlayer/MPVideoView.h>
 #import <MediaPlayer/MPVideoView-PlaybackControl.h>
 
@@ -75,6 +102,7 @@ extern "C" void __clear_cache (char *beg, char *end);
 - (void *) _node;
 @end
 
+Class $MPMoviePlayerController;
 Class $MPVideoView;
 Class $WebCoreFrameBridge;
 
@@ -86,19 +114,23 @@ Class $UIToolbar;
 
 Class $SBApplication;
 Class $SBApplicationIcon;
+Class $SBAwayView;
 Class $SBBookmarkIcon;
 Class $SBButtonBar;
 Class $SBCalendarIconContentsView;
-Class $SBContentLayer;
+Class $SBIcon;
 Class $SBIconBadge;
 Class $SBIconController;
 Class $SBIconLabel;
+Class $SBIconList;
 Class $SBIconModel;
-Class $SBSlidingAlertDisplay;
+//Class $SBImageCache;
 Class $SBStatusBarContentsView;
 Class $SBStatusBarController;
 Class $SBStatusBarOperatorNameView;
 Class $SBStatusBarTimeView;
+Class $SBUIController;
+Class $SBWidgetApplicationIcon;
 
 @interface NSDictionary (WinterBoard)
 - (UIColor *) colorForKey:(NSString *)key;
@@ -131,7 +163,6 @@ static UIImage *(*_UIImageAtPath)(NSString *name, NSBundle *path);
 static CGImageRef (*_UIImageRefAtPath)(NSString *name, bool cache, UIImageOrientation *orientation);
 static UIImage *(*_UIImageWithNameInDomain)(NSString *name, NSString *domain);
 static NSBundle *(*_UIKitBundle)();
-static void (*_UISharedImageInitialize)(bool);
 static int (*_UISharedImageNameGetIdentifier)(NSString *);
 static UIImage *(*_UISharedImageWithIdentifier)(int);
 
@@ -249,6 +280,7 @@ static NSString *$pathForIcon$(SBApplication *self) {
     path = [path stringByDeletingLastPathComponent];
     if (path == nil || [path length] == 0 || [path isEqualToString:@"/"])
         return nil;
+    return [NSBundle mainBundle];
 
     NSBundle *bundle([Bundles_ objectForKey:path]);
     if (reinterpret_cast<id>(bundle) == [NSNull null])
@@ -260,7 +292,7 @@ static NSString *$pathForIcon$(SBApplication *self) {
             bundle = [NSBundle wb$bundleWithFile:path];
         if (Debug_)
             NSLog(@"WB:Debug:PathBundle(%@, %@)", path, bundle);
-        [Bundles_ setObject:(bundle == nil ? [NSNull null] : reinterpret_cast<id>(bundle)) forKey:path];
+        //[Bundles_ setObject:(bundle == nil ? [NSNull null] : reinterpret_cast<id>(bundle)) forKey:path];
     }
 
     return bundle;
@@ -279,6 +311,7 @@ static NSString *$pathForIcon$(SBApplication *self) {
         NSLog(@"WB:Debug:Bypass(\"%@\")", self);
 
     if (NSBundle *bundle = [NSBundle wb$bundleWithFile:self]) {
+        return self;
         NSString *file([self stringByResolvingSymlinksInPath]);
         NSString *prefix([[bundle bundlePath] stringByResolvingSymlinksInPath]);
         if ([file hasPrefix:prefix]) {
@@ -294,27 +327,42 @@ static NSString *$pathForIcon$(SBApplication *self) {
 
 @end
 
-MSHook(void, SBIconModel$cacheImageForIcon$, SBIconModel *self, SEL sel, SBIcon *icon) {
-    _SBIconModel$cacheImageForIcon$(self, sel, icon);
-    NSString *key([icon displayIdentifier]);
+UIImage *$cacheForImage$(UIImage *image) {
+    CGColorSpaceRef space(CGColorSpaceCreateDeviceRGB());
+    CGRect rect = {CGPointMake(1, 1), [image size]};
+    CGSize size = {rect.size.width + 2, rect.size.height + 2};
 
-    if (UIImage *image = [icon icon]) {
-        CGColorSpaceRef space(CGColorSpaceCreateDeviceRGB());
-        CGRect rect = {CGPointMake(1, 1), [image size]};
-        CGSize size = {rect.size.width + 2, rect.size.height + 2};
+    CGContextRef context(CGBitmapContextCreate(NULL, size.width, size.height, 8, 4 * size.width, space, kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst));
+    CGColorSpaceRelease(space);
 
-        CGContextRef context(CGBitmapContextCreate(NULL, size.width, size.height, 8, 4 * size.width, space, kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst));
-        CGColorSpaceRelease(space);
+    CGContextDrawImage(context, rect, [image CGImage]);
+    CGImageRef ref(CGBitmapContextCreateImage(context));
+    CGContextRelease(context);
+
+    UIImage *cache([UIImage imageWithCGImage:ref]);
+    CGImageRelease(ref);
+
+    return cache;
+}
 
-        CGContextDrawImage(context, rect, [image CGImage]);
-        CGImageRef ref(CGBitmapContextCreateImage(context));
-        CGContextRelease(context);
+/*MSHook(id, SBImageCache$initWithName$forImageWidth$imageHeight$initialCapacity$, SBImageCache *self, SEL sel, NSString *name, unsigned width, unsigned height, unsigned capacity) {
+    //if ([name isEqualToString:@"icons"]) return nil;
+    return _SBImageCache$initWithName$forImageWidth$imageHeight$initialCapacity$(self, sel, name, width, height, capacity);
+}*/
 
-        UIImage *image([UIImage imageWithCGImage:ref]);
-        CGImageRelease(ref);
+MSHook(void, SBIconModel$cacheImageForIcon$, SBIconModel *self, SEL sel, SBIcon *icon) {
+    NSString *key([icon displayIdentifier]);
 
-        [Cache_ setObject:image forKey:key];
+    if (UIImage *image = [icon icon]) {
+        CGSize size = [image size];
+        if (size.width != 59 || size.height != 60) {
+            UIImage *cache($cacheForImage$(image));
+            [Cache_ setObject:cache forKey:key];
+            return;
+        }
     }
+
+    _SBIconModel$cacheImageForIcon$(self, sel, icon);
 }
 
 MSHook(UIImage *, SBIconModel$getCachedImagedForIcon$, SBIconModel *self, SEL sel, SBIcon *icon) {
@@ -332,6 +380,14 @@ MSHook(UIImage *, SBApplicationIcon$icon, SBApplicationIcon *self, SEL sel) {
     return _SBApplicationIcon$icon(self, sel);
 }
 
+MSHook(UIImage *, SBWidgetApplicationIcon$icon, SBWidgetApplicationIcon *self, SEL sel) {
+    if (Debug_)
+        NSLog(@"WB:Debug:Widget(%@:%@)", [self displayIdentifier], [self displayName]);
+    if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Icons/%@.png", [self displayName]]]))
+        return [UIImage imageWithContentsOfFile:path];
+    return _SBWidgetApplicationIcon$icon(self, sel);
+}
+
 MSHook(UIImage *, SBBookmarkIcon$icon, SBBookmarkIcon *self, SEL sel) {
     if (Debug_)
         NSLog(@"WB:Debug:Bookmark(%@:%@)", [self displayIdentifier], [self displayName]);
@@ -361,7 +417,7 @@ static UIImage *CachedImageAtPath(NSString *path) {
 MSHook(CGImageRef, _UIImageRefAtPath, NSString *name, bool cache, UIImageOrientation *orientation) {
     if (Debug_)
         NSLog(@"WB:Debug: _UIImageRefAtPath(\"%@\", %s)", name, cache ? "true" : "false");
-    return __UIImageRefAtPath([name wb$themedPath], cache, orientation);
+    return __UIImageRefAtPath(([name wb$themedPath], name), cache, orientation);
 }
 
 /*MSHook(UIImage *, _UIImageAtPath, NSString *name, NSBundle *bundle) {
@@ -491,7 +547,7 @@ MSHook(void, SBCalendarIconContentsView$drawRect$, SBCalendarIconContentsView *s
 }
 
 /*static id UINavigationBarBackground$initWithFrame$withBarStyle$withTintColor$(UINavigationBarBackground<WinterBoard> *self, SEL sel, CGRect frame, int style, UIColor *tint) {
-    _trace();
+_trace();
 
     if (NSNumber *number = [Info_ objectForKey:@"NavigationBarStyle"])
         style = [number intValue];
@@ -558,11 +614,27 @@ static NSURL *WallpaperURL_;
         object = nil; \
     } while (false)
 
-MSHook(id, SBContentLayer$initWithSize$, SBContentLayer *self, SEL sel, CGSize size) {
-    self = _SBContentLayer$initWithSize$(self, sel, size);
+void DumpHierarchy(UIView *view, unsigned index = 0, unsigned indent = 0) {
+    NSLog(@"%*s|%2d:%s", indent * 3, "", index, class_getName([view class]));
+    index = 0;
+    for (UIView *child in [view subviews])
+        DumpHierarchy(child, index++, indent + 1);
+}
+
+MSHook(id, SBUIController$init, SBUIController *self, SEL sel) {
+    self = _SBUIController$init(self, sel);
     if (self == nil)
         return nil;
 
+    UIWindow *&_window(MSHookIvar<UIWindow *>(self, "_window"));
+    UIView *&_contentView(MSHookIvar<UIView *>(self, "_contentView"));
+
+    UIView *content([[[UIView alloc] initWithFrame:[_contentView frame]] autorelease]);
+    [content setBackgroundColor:[_contentView backgroundColor]];
+    [_contentView setBackgroundColor:[UIColor clearColor]];
+    [_contentView setFrame:[content bounds]];
+    [_window setContentView:content];
+
     _release(WallpaperFile_);
     _release(WallpaperImage_);
     _release(WallpaperPage_);
@@ -571,12 +643,38 @@ MSHook(id, SBContentLayer$initWithSize$, SBContentLayer *self, SEL sel, CGSize s
     if (NSString *theme = $getTheme$(Wallpapers_, true)) {
         NSString *mp4 = [theme stringByAppendingPathComponent:@"Wallpaper.mp4"];
         if ([Manager_ fileExistsAtPath:mp4]) {
-            MPVideoView *video = [[[$MPVideoView alloc] initWithFrame:[self bounds]] autorelease];
+#if UseAVController
+            NSError *error;
+
+            static AVController *controller_(nil);
+            if (controller_ == nil) {
+                AVQueue *queue([AVQueue avQueue]);
+                controller_ = [[AVController avControllerWithQueue:queue error:&error] retain];
+            }
+
+            AVQueue *queue([controller_ queue]);
+
+            UIView *video([[[UIView alloc] initWithFrame:[_contentView bounds]] autorelease]);
+            [controller_ setLayer:[video _layer]];
+
+            AVItem *item([[[AVItem alloc] initWithPath:mp4 error:&error] autorelease]);
+            [queue appendItem:item error:&error];
+
+            [controller_ play:&error];
+#elif UseMPMoviePlayerController
+            NSURL *url([NSURL fileURLWithPath:mp4]);
+            MPMoviePlayerController *controller = [[MPMoviePlayerController alloc] initWithContentURL:url];
+           controller.movieControlMode = MPMovieControlModeHidden;
+           [controller play];
+#else
+            MPVideoView *video = [[[$MPVideoView alloc] initWithFrame:[_contentView bounds]] autorelease];
             [video setMovieWithPath:mp4];
             [video setRepeatMode:1];
-            [video setRepeatGap:0];
-            [self addSubview:video];
+            [video setRepeatGap:-1];
             [video playFromBeginning];;
+#endif
+
+            [content addSubview:video];
         }
 
         NSString *png = [theme stringByAppendingPathComponent:@"Wallpaper.png"];
@@ -599,12 +697,12 @@ MSHook(id, SBContentLayer$initWithSize$, SBContentLayer *self, SEL sel, CGSize s
         if (image != nil) {
             WallpaperFile_ = [path retain];
             WallpaperImage_ = [[UIImageView alloc] initWithImage:image];
-            [self addSubview:WallpaperImage_];
+            [content addSubview:WallpaperImage_];
         }
 
         NSString *html = [theme stringByAppendingPathComponent:@"Wallpaper.html"];
         if ([Manager_ fileExistsAtPath:html]) {
-            CGRect bounds = [self bounds];
+            CGRect bounds = [content bounds];
 
             UIWebDocumentView *view([[[UIWebDocumentView alloc] initWithFrame:bounds] autorelease]);
             [view setAutoresizes:true];
@@ -617,7 +715,7 @@ MSHook(id, SBContentLayer$initWithSize$, SBContentLayer *self, SEL sel, CGSize s
             [[view webView] setDrawsBackground:false];
             [view setBackgroundColor:[UIColor clearColor]];
 
-            [self addSubview:view];
+            [content addSubview:view];
         }
     }
 
@@ -625,7 +723,7 @@ MSHook(id, SBContentLayer$initWithSize$, SBContentLayer *self, SEL sel, CGSize s
         NSString *theme = [themes_ objectAtIndex:(e - i - 1)];
         NSString *html = [theme stringByAppendingPathComponent:@"Widget.html"];
         if ([Manager_ fileExistsAtPath:html]) {
-            CGRect bounds = [self bounds];
+            CGRect bounds = [content bounds];
 
             UIWebDocumentView *view([[[UIWebDocumentView alloc] initWithFrame:bounds] autorelease]);
             [view setAutoresizes:true];
@@ -636,21 +734,24 @@ MSHook(id, SBContentLayer$initWithSize$, SBContentLayer *self, SEL sel, CGSize s
             [[view webView] setDrawsBackground:false];
             [view setBackgroundColor:[UIColor clearColor]];
 
-            [self addSubview:view];
+            [content addSubview:view];
         }
     }
 
+    [content addSubview:_contentView];
+    DumpHierarchy(_window);
+
     return self;
 }
 
-MSHook(void, SBSlidingAlertDisplay$updateDesktopImage$, SBSlidingAlertDisplay *self, SEL sel, UIImage *image) {
+MSHook(void, SBAwayView$updateDesktopImage$, SBAwayView *self, SEL sel, UIImage *image) {
     NSString *path = $getTheme$([NSArray arrayWithObject:@"LockBackground.html"]);
     UIView *&_backgroundView(MSHookIvar<UIView *>(self, "_backgroundView"));
 
     if (path != nil && _backgroundView != nil)
         path = nil;
 
-    _SBSlidingAlertDisplay$updateDesktopImage$(self, sel, image);
+    _SBAwayView$updateDesktopImage$(self, sel, image);
 
     if (path != nil) {
         CGRect bounds = [self bounds];
@@ -765,6 +866,12 @@ WBDelegate(badge_)
 @end
 /* }}} */
 
+MSHook(void, SBIcon$setAlpha$, SBIcon *self, SEL sel, float alpha) {
+    if (NSNumber *number = [Info_ objectForKey:@"IconAlpha"])
+        alpha = [number floatValue];
+    return _SBIcon$setAlpha$(self, sel, alpha);
+}
+
 MSHook(id, SBIconBadge$initWithBadge$, SBIconBadge *self, SEL sel, NSString *badge) {
     if ((self = _SBIconBadge$initWithBadge$(self, sel, badge)) != nil) {
         id &_badge(MSHookIvar<id>(self, "_badge"));
@@ -774,20 +881,38 @@ MSHook(id, SBIconBadge$initWithBadge$, SBIconBadge *self, SEL sel, NSString *bad
     } return self;
 }
 
-MSHook(void, SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$, SBStatusBarController *self, SEL sel, int mode, int orientation, float duration, int id, int animation) {
+void SBStatusBarController$setStatusBarMode(int &mode) {
     if (Debug_)
         NSLog(@"WB:Debug:setStatusBarMode:%d", mode);
     if (mode < 100) // 104:hidden 105:glowing
         if (NSNumber *number = [Info_ objectForKey:@"StatusBarMode"])
             mode = [number intValue];
-    return _SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$(self, sel, mode, orientation, duration, id, animation);
 }
 
-MSHook(id, SBStatusBarContentsView$initWithStatusBar$mode$, SBStatusBarContentsView *self, SEL sel, id bar, int mode) {
+/*MSHook(void, SBStatusBarController$setStatusBarMode$orientation$duration$animation$, SBStatusBarController *self, SEL sel, int mode, int orientation, double duration, int animation) {
+    NSLog(@"mode:%d orientation:%d duration:%f animation:%d", mode, orientation, duration, animation);
+    SBStatusBarController$setStatusBarMode(mode);
+    return _SBStatusBarController$setStatusBarMode$orientation$duration$animation$(self, sel, mode, orientation, duration, animation);
+}*/
+
+MSHook(void, SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$, SBStatusBarController *self, SEL sel, int mode, int orientation, float duration, int fenceID, int animation) {
+    NSLog(@"mode:%d orientation:%d duration:%f fenceID:%d animation:%d", mode, orientation, duration, fenceID, animation);
+    SBStatusBarController$setStatusBarMode(mode);
+    return _SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$(self, sel, mode, orientation, duration, fenceID, animation);
+}
+
+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) {
+    NSLog(@"mode:%d orientation:%d duration:%f fenceID:%d animation:%d startTime:%f", mode, orientation, duration, fenceID, animation, startTime);
+    SBStatusBarController$setStatusBarMode(mode);
+    NSLog(@"mode=%u", mode);
+    return _SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$startTime$(self, sel, mode, orientation, duration, fenceID, animation, startTime);
+}
+
+/*MSHook(id, SBStatusBarContentsView$initWithStatusBar$mode$, SBStatusBarContentsView *self, SEL sel, id bar, int mode) {
     if (NSNumber *number = [Info_ objectForKey:@"StatusBarContentsMode"])
         mode = [number intValue];
     return _SBStatusBarContentsView$initWithStatusBar$mode$(self, sel, bar, mode);
-}
+}*/
 
 MSHook(NSString *, SBStatusBarOperatorNameView$operatorNameStyle, SBStatusBarOperatorNameView *self, SEL sel) {
     NSString *style(_SBStatusBarOperatorNameView$operatorNameStyle(self, sel));
@@ -812,10 +937,76 @@ MSHook(void, SBStatusBarTimeView$drawRect$, SBStatusBarTimeView *self, SEL sel,
     return _SBStatusBarTimeView$drawRect$(self, sel, rect);
 }
 
-MSHook(void, SBIconController$appendIconList$, SBIconController *self, SEL sel, SBIconList *list) {
-    if (Debug_)
-        NSLog(@"appendIconList:%@", list);
-    return _SBIconController$appendIconList$(self, sel, list);
+@interface UIView (WinterBoard)
+- (bool) wb$isWBImageView;
+@end
+
+@implementation UIView (WinterBoard)
+
+- (bool) wb$isWBImageView {
+    return false;
+}
+
+@end
+
+@interface WBImageView : UIImageView {
+}
+
+- (bool) wb$isWBImageView;
+- (void) wb$updateFrame;
+@end
+
+@implementation WBImageView
+
+- (bool) wb$isWBImageView {
+    return true;
+}
+
+- (void) wb$updateFrame {
+    CGRect frame([self frame]);
+    frame.origin.y = 0;
+
+    for (UIView *view(self); ; ) {
+        view = [view superview];
+        if (view == nil)
+            break;
+        frame.origin.y -= [view frame].origin.y;
+    }
+
+    [self setFrame:frame];
+}
+
+@end
+
+MSHook(void, SBIconList$setFrame$, SBIconList *self, SEL sel, CGRect frame) {
+    NSArray *subviews([self subviews]);
+    WBImageView *view([subviews count] == 0 ? nil : [subviews objectAtIndex:0]);
+    if (view != nil && [view wb$isWBImageView])
+        [view wb$updateFrame];
+    _SBIconList$setFrame$(self, sel, frame);
+}
+
+MSHook(void, SBIconController$noteNumberOfIconListsChanged, SBIconController *self, SEL sel) {
+    SBIconModel *&_iconModel(MSHookIvar<SBIconModel *>(self, "_iconModel"));
+    NSArray *lists([_iconModel iconLists]);
+
+    for (unsigned i(0), e([lists count]); i != e; ++i)
+        if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Page%u.png", i]])) {
+            SBIconList *list([lists objectAtIndex:i]);
+            NSArray *subviews([list subviews]);
+
+            WBImageView *view([subviews count] == 0 ? nil : [subviews objectAtIndex:0]);
+            if (view == nil || ![view wb$isWBImageView]) {
+                view = [[[WBImageView alloc] init] autorelease];
+                [list insertSubview:view atIndex:0];
+            }
+
+            UIImage *image([UIImage imageWithContentsOfFile:path]);
+            [view setImage:image];
+            [view wb$updateFrame];
+        }
+
+    return _SBIconController$noteNumberOfIconListsChanged(self, sel);
 }
 
 MSHook(id, SBIconLabel$initWithSize$label$, SBIconLabel *self, SEL sel, CGSize size, NSString *label) {
@@ -878,7 +1069,7 @@ MSHook(void, SBIconLabel$drawRect$, SBIconLabel *self, SEL sel, CGRect rect) {
     Ivar ivar = object_getInstanceVariable(self, "_inDock", reinterpret_cast<void **>(&docked));
     docked = (docked & (ivar_getOffset(ivar) == ivar_getOffset(drawMoreLegibly) ? 0x2 : 0x1)) != 0;
 
-    NSString *&label(MSHookIvar<NSString *>(self, "_label"));
+    NSString *label(MSHookIvar<NSString *>(self, "_label"));
 
     NSString *style = [NSString stringWithFormat:@""
         "font-family: Helvetica; "
@@ -889,9 +1080,28 @@ MSHook(void, SBIconLabel$drawRect$, SBIconLabel *self, SEL sel, CGRect rect) {
 
     if (docked)
         style = [style stringByAppendingString:@"text-shadow: rgba(0, 0, 0, 0.5) 0px -1px 0px; "];
-    float max = 75, width = [label sizeWithStyle:style forWidth:320].width;
-    if (width > max)
-        style = [style stringByAppendingString:[NSString stringWithFormat:@"letter-spacing: -%f; ", ((width - max) / ([label length] - 1))]];
+
+    bool ellipsis(false);
+    float max = 75, width;
+  width:
+    width = [(ellipsis ? [label stringByAppendingString:@"..."] : label) sizeWithStyle:style forWidth:320].width;
+
+    if (width > max) {
+        size_t length([label length]);
+        float spacing((width - max) / (length - 1));
+
+        if (spacing > 1.25) {
+            ellipsis = true;
+            label = [label substringToIndex:(length - 1)];
+            goto width;
+        }
+
+        style = [style stringByAppendingString:[NSString stringWithFormat:@"letter-spacing: -%f; ", spacing]];
+    }
+
+    if (ellipsis)
+        label = [label stringByAppendingString:@"..."];
+
     if (NSString *custom = [Info_ objectForKey:(docked ? @"DockedIconLabelStyle" : @"UndockedIconLabelStyle")])
         style = [style stringByAppendingString:custom];
 
@@ -926,7 +1136,7 @@ MSHook(UIImage *, _UIImageWithName, NSString *name) {
         if (image != nil)
             return reinterpret_cast<id>(image) == [NSNull null] ? nil : image;
         if (NSString *path = $pathForFile$inBundle$(name, _UIKitBundle(), true)) {
-            image = [[UIImage alloc] initWithContentsOfFile:path];
+            image = [[UIImage alloc] initWithContentsOfFile:path cache:true];
             if (image != nil)
                 [image autorelease];
         }
@@ -955,6 +1165,12 @@ MSHook(UIImage *, _UIImageWithNameInDomain, NSString *name, NSString *domain) {
     return image;
 }
 
+MSHook(GSFontRef, GSFontCreateWithName, const char *name, GSFontSymbolicTraits traits, float size) {
+    if (NSString *font = [Info_ objectForKey:[NSString stringWithFormat:@"FontName-%s", name]])
+        name = [font UTF8String];
+    return _GSFontCreateWithName(name, traits, size);
+}
+
 #define AudioToolbox "/System/Library/Frameworks/AudioToolbox.framework/AudioToolbox"
 #define UIKit "/System/Library/Frameworks/UIKit.framework/UIKit"
 
@@ -969,7 +1185,6 @@ MSHook(bool, _Z24GetFileNameForThisActionmPcRb, unsigned long a0, char *a1, bool
         NSString *path = [NSString stringWithUTF8String:a1];
         if ([path hasPrefix:@"/System/Library/Audio/UISounds/"]) {
             NSString *file = [path substringFromIndex:31];
-            NSLog(@"%@", file);
             for (NSString *theme in themes_) {
                 NSString *path([NSString stringWithFormat:@"%@/UISounds/%@", theme, file]);
                 if ([Manager_ fileExistsAtPath:path]) {
@@ -1016,7 +1231,7 @@ extern "C" void WBInitialize() {
 
     NSLog(@"WB:Notice: WinterBoard");
 
-    struct nlist nl[9];
+    struct nlist nl[8];
     memset(nl, 0, sizeof(nl));
 
     nl[0].n_un.n_name = (char *) "__UIApplicationImageWithName";
@@ -1024,9 +1239,8 @@ extern "C" void WBInitialize() {
     nl[2].n_un.n_name = (char *) "__UIImageRefAtPath";
     nl[3].n_un.n_name = (char *) "__UIImageWithNameInDomain";
     nl[4].n_un.n_name = (char *) "__UIKitBundle";
-    nl[5].n_un.n_name = (char *) "__UISharedImageInitialize";
-    nl[6].n_un.n_name = (char *) "__UISharedImageNameGetIdentifier";
-    nl[7].n_un.n_name = (char *) "__UISharedImageWithIdentifier";
+    nl[5].n_un.n_name = (char *) "__UISharedImageNameGetIdentifier";
+    nl[6].n_un.n_name = (char *) "__UISharedImageWithIdentifier";
 
     nlist(UIKit, nl);
 
@@ -1035,15 +1249,16 @@ extern "C" void WBInitialize() {
     _UIImageRefAtPath = (CGImageRef (*)(NSString *, bool, UIImageOrientation *)) nl[2].n_value;
     _UIImageWithNameInDomain = (UIImage *(*)(NSString *, NSString *)) nl[3].n_value;
     _UIKitBundle = (NSBundle *(*)()) nl[4].n_value;
-    _UISharedImageInitialize = (void (*)(bool)) nl[5].n_value;
-    _UISharedImageNameGetIdentifier = (int (*)(NSString *)) nl[6].n_value;
-    _UISharedImageWithIdentifier = (UIImage *(*)(int)) nl[7].n_value;
+    _UISharedImageNameGetIdentifier = (int (*)(NSString *)) nl[5].n_value;
+    _UISharedImageWithIdentifier = (UIImage *(*)(int)) nl[6].n_value;
 
     MSHookFunction(_UIApplicationImageWithName, &$_UIApplicationImageWithName, &__UIApplicationImageWithName);
     MSHookFunction(_UIImageRefAtPath, &$_UIImageRefAtPath, &__UIImageRefAtPath);
     MSHookFunction(_UIImageWithName, &$_UIImageWithName, &__UIImageWithName);
     MSHookFunction(_UIImageWithNameInDomain, &$_UIImageWithNameInDomain, &__UIImageWithNameInDomain);
 
+    MSHookFunction(&GSFontCreateWithName, &$GSFontCreateWithName, &_GSFontCreateWithName);
+
     if (dlopen(AudioToolbox, RTLD_LAZY | RTLD_NOLOAD) != NULL) {
         struct nlist nl[2];
         memset(nl, 0, sizeof(nl));
@@ -1070,8 +1285,6 @@ extern "C" void WBInitialize() {
     _UINavigationBar$setBarStyle$ = MSHookMessage($UINavigationBar, @selector(setBarStyle:), &$UINavigationBar$setBarStyle$);
     _UIToolbar$setBarStyle$ = MSHookMessage($UIToolbar, @selector(setBarStyle:), &$UIToolbar$setBarStyle$);
 
-    _UISharedImageInitialize(false);
-
     Manager_ = [[NSFileManager defaultManager] retain];
     UIImages_ = [[NSMutableDictionary alloc] initWithCapacity:16];
     PathImages_ = [[NSMutableDictionary alloc] initWithCapacity:16];
@@ -1124,10 +1337,12 @@ extern "C" void WBInitialize() {
     Info_ = [[NSMutableDictionary dictionaryWithCapacity:16] retain];
 
     for (NSString *theme in themes_)
-        if (NSDictionary *info = [[NSDictionary alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@/Info.plist", theme]])
+        if (NSDictionary *info = [[NSDictionary alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@/Info.plist", theme]]) {
+            [info autorelease];
             for (NSString *key in [info allKeys])
                 if ([Info_ objectForKey:key] == nil)
                     [Info_ setObject:[info objectForKey:key] forKey:key];
+        }
 
     if ([identifier isEqualToString:@"com.apple.MobileSMS"]) {
         Class mSMSMessageTranscriptController = objc_getClass("mSMSMessageTranscriptController");
@@ -1142,24 +1357,29 @@ extern "C" void WBInitialize() {
         if (MediaPlayer != nil)
             [MediaPlayer load];
 
+        $MPMoviePlayerController = objc_getClass("MPMoviePlayerController");
         $MPVideoView = objc_getClass("MPVideoView");
         $WebCoreFrameBridge = objc_getClass("WebCoreFrameBridge");
 
         $SBApplication = objc_getClass("SBApplication");
         $SBApplicationIcon = objc_getClass("SBApplicationIcon");
+        $SBAwayView = objc_getClass("SBAwayView");
         $SBBookmarkIcon = objc_getClass("SBBookmarkIcon");
         $SBButtonBar = objc_getClass("SBButtonBar");
         $SBCalendarIconContentsView = objc_getClass("SBCalendarIconContentsView");
-        $SBContentLayer = objc_getClass("SBContentLayer");
+        $SBIcon = objc_getClass("SBIcon");
         $SBIconBadge = objc_getClass("SBIconBadge");
         $SBIconController = objc_getClass("SBIconController");
         $SBIconLabel = objc_getClass("SBIconLabel");
+        $SBIconList = objc_getClass("SBIconList");
         $SBIconModel = objc_getClass("SBIconModel");
-        $SBSlidingAlertDisplay = objc_getClass("SBSlidingAlertDisplay");
+        //$SBImageCache = objc_getClass("SBImageCache");
         $SBStatusBarContentsView = objc_getClass("SBStatusBarContentsView");
         $SBStatusBarController = objc_getClass("SBStatusBarController");
         $SBStatusBarOperatorNameView = objc_getClass("SBStatusBarOperatorNameView");
         $SBStatusBarTimeView = objc_getClass("SBStatusBarTimeView");
+        $SBUIController = objc_getClass("SBUIController");
+        $SBWidgetApplicationIcon = objc_getClass("SBWidgetApplicationIcon");
 
         WBRename(WebCoreFrameBridge, renderedSizeOfNode:constrainedToWidth:, renderedSizeOfNode$constrainedToWidth$);
 
@@ -1168,29 +1388,34 @@ extern "C" void WBInitialize() {
         WBRename(SBBookmarkIcon, icon, icon);
         WBRename(SBButtonBar, didMoveToSuperview, didMoveToSuperview);
         WBRename(SBCalendarIconContentsView, drawRect:, drawRect$);
-        WBRename(SBContentLayer, initWithSize:, initWithSize$);
+        WBRename(SBIcon, setAlpha:, setAlpha$);
         WBRename(SBIconBadge, initWithBadge:, initWithBadge$);
-        WBRename(SBIconController, appendIconList:, appendIconList$);
+        WBRename(SBIconController, noteNumberOfIconListsChanged, noteNumberOfIconListsChanged);
+        WBRename(SBUIController, init, init);
+        WBRename(SBWidgetApplicationIcon, icon, icon);
 
         WBRename(SBIconLabel, drawRect:, drawRect$);
         WBRename(SBIconLabel, initWithSize:label:, initWithSize$label$);
         WBRename(SBIconLabel, setInDock:, setInDock$);
 
+        WBRename(SBIconList, setFrame:, setFrame$);
+
         WBRename(SBIconModel, cacheImageForIcon:, cacheImageForIcon$);
         WBRename(SBIconModel, getCachedImagedForIcon:, getCachedImagedForIcon$);
 
-        WBRename(SBSlidingAlertDisplay, updateDesktopImage:, updateDesktopImage$);
+        //WBRename(SBImageCache, initWithName:forImageWidth:imageHeight:initialCapacity:, initWithName$forImageWidth$imageHeight$initialCapacity$);
+
+        WBRename(SBAwayView, updateDesktopImage:, updateDesktopImage$);
         WBRename(SBStatusBarContentsView, didMoveToSuperview, didMoveToSuperview);
-        WBRename(SBStatusBarContentsView, initWithStatusBar:mode:, initWithStatusBar$mode$);
+        //WBRename(SBStatusBarContentsView, initWithStatusBar:mode:, initWithStatusBar$mode$);
+        //WBRename(SBStatusBarController, setStatusBarMode:orientation:duration:animation:, setStatusBarMode$orientation$duration$animation$);
         WBRename(SBStatusBarController, setStatusBarMode:orientation:duration:fenceID:animation:, setStatusBarMode$orientation$duration$fenceID$animation$);
+        WBRename(SBStatusBarController, setStatusBarMode:orientation:duration:fenceID:animation:startTime:, setStatusBarMode$orientation$duration$fenceID$animation$startTime$);
         WBRename(SBStatusBarOperatorNameView, operatorNameStyle, operatorNameStyle);
         WBRename(SBStatusBarOperatorNameView, setOperatorName:fullSize:, setOperatorName$fullSize$);
         WBRename(SBStatusBarTimeView, drawRect:, drawRect$);
 
         English_ = [[NSDictionary alloc] initWithContentsOfFile:@"/System/Library/CoreServices/SpringBoard.app/English.lproj/LocalizedApplicationNames.strings"];
-        if (English_ != nil)
-            English_ = [English_ retain];
-
         Cache_ = [[NSMutableDictionary alloc] initWithCapacity:64];
     }