]> git.saurik.com Git - winterboard.git/blobdiff - Library.mm
Various fixes for 2.x and BigBoss.
[winterboard.git] / Library.mm
index 95dc7ff1891b3e5d8bb4e92b36b746deb68ae223..35500a90058d9fc6c1b5e95555bb4ee90171b0aa 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>
@@ -57,7 +76,6 @@
 #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/SBIconList.h>
@@ -100,7 +118,6 @@ Class $SBAwayView;
 Class $SBBookmarkIcon;
 Class $SBButtonBar;
 Class $SBCalendarIconContentsView;
-Class $SBContentLayer;
 Class $SBIcon;
 Class $SBIconBadge;
 Class $SBIconController;
@@ -112,6 +129,7 @@ Class $SBStatusBarContentsView;
 Class $SBStatusBarController;
 Class $SBStatusBarOperatorNameView;
 Class $SBStatusBarTimeView;
+Class $SBUIController;
 Class $SBWidgetApplicationIcon;
 
 @interface NSDictionary (WinterBoard)
@@ -145,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);
 
@@ -482,7 +499,7 @@ MSHook(void, SBCalendarIconContentsView$drawRect$, SBCalendarIconContentsView *s
 
     CFDateFormatterSetFormat(formatter, (CFStringRef) [bundle localizedStringForKey:@"CALENDAR_ICON_DAY_NUMBER_FORMAT" value:@"" table:@"SpringBoard"]);
     CFStringRef date(CFDateFormatterCreateStringWithDate(NULL, formatter, now));
-    CFDateFormatterSetFormat(formatter, (CFStringRef) [bundle localizedStringForKey:@"CALENDAR_ICON_DAY_NAME_FORMAT" value:@"" table:@"SpringBoard"]);
+    CFDateFormatterSetFormat(formatter, (CFStringRef) [bundle localizedStringForKey:@"CALENDAR_ICON_DAY_NAME_FORMAT" value:@"cccc" table:@"SpringBoard"]);
     CFStringRef day(CFDateFormatterCreateStringWithDate(NULL, formatter, now));
 
     CFRelease(now);
@@ -528,7 +545,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];
@@ -595,11 +612,36 @@ 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 *&_contentLayer(MSHookIvar<UIView *>(self, "_contentLayer"));
+    UIView *&_contentView(MSHookIvar<UIView *>(self, "_contentView"));
+
+    UIView *layer;
+    if (&_contentLayer != NULL)
+        layer = _contentLayer;
+    else if (&_contentView != NULL)
+        layer = _contentView;
+    else
+        layer = nil;
+
+    UIView *content([[[UIView alloc] initWithFrame:[layer frame]] autorelease]);
+    [content setBackgroundColor:[layer backgroundColor]];
+    [layer setBackgroundColor:[UIColor clearColor]];
+    [layer setFrame:[content bounds]];
+    [_window setContentView:content];
+
     _release(WallpaperFile_);
     _release(WallpaperImage_);
     _release(WallpaperPage_);
@@ -619,7 +661,7 @@ MSHook(id, SBContentLayer$initWithSize$, SBContentLayer *self, SEL sel, CGSize s
 
             AVQueue *queue([controller_ queue]);
 
-            UIView *video([[[UIView alloc] initWithFrame:[self bounds]] autorelease]);
+            UIView *video([[[UIView alloc] initWithFrame:[content bounds]] autorelease]);
             [controller_ setLayer:[video _layer]];
 
             AVItem *item([[[AVItem alloc] initWithPath:mp4 error:&error] autorelease]);
@@ -632,14 +674,14 @@ MSHook(id, SBContentLayer$initWithSize$, SBContentLayer *self, SEL sel, CGSize s
            controller.movieControlMode = MPMovieControlModeHidden;
            [controller play];
 #else
-            MPVideoView *video = [[[$MPVideoView alloc] initWithFrame:[self bounds]] autorelease];
+            MPVideoView *video = [[[$MPVideoView alloc] initWithFrame:[content bounds]] autorelease];
             [video setMovieWithPath:mp4];
             [video setRepeatMode:1];
             [video setRepeatGap:-1];
             [video playFromBeginning];;
 #endif
 
-            [self addSubview:video];
+            [content addSubview:video];
         }
 
         NSString *png = [theme stringByAppendingPathComponent:@"Wallpaper.png"];
@@ -662,12 +704,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];
@@ -680,7 +722,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];
         }
     }
 
@@ -688,7 +730,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];
@@ -699,10 +741,13 @@ 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:layer];
+    DumpHierarchy(_window);
+
     return self;
 }
 
@@ -766,6 +811,10 @@ extern "C" NSString *UIStyleStringFromColor(CGColorRef);*/
     return self;
 }
 
+- (NSString *) description {
+    return time_;
+}
+
 WBDelegate(time_)
 
 - (CGSize) drawAtPoint:(CGPoint)point forWidth:(float)width withFont:(UIFont *)font lineBreakMode:(int)mode {
@@ -843,20 +892,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));
@@ -1175,7 +1242,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";
@@ -1183,9 +1250,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);
 
@@ -1194,9 +1260,8 @@ 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);
@@ -1231,8 +1296,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];
@@ -1315,7 +1378,6 @@ extern "C" void WBInitialize() {
         $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");
@@ -1327,6 +1389,7 @@ extern "C" void WBInitialize() {
         $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$);
@@ -1336,10 +1399,10 @@ 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, noteNumberOfIconListsChanged, noteNumberOfIconListsChanged);
+        WBRename(SBUIController, init, init);
         WBRename(SBWidgetApplicationIcon, icon, icon);
 
         WBRename(SBIconLabel, drawRect:, drawRect$);
@@ -1355,8 +1418,10 @@ extern "C" void WBInitialize() {
 
         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$);