]> git.saurik.com Git - winterboard.git/blobdiff - Library.mm
@thekirbylover fix for @TCcentex Facebook icon bug.
[winterboard.git] / Library.mm
index 369b1d099c4640b1bea2b5b4bea7d95ab2b4c3d0..f661bc035b8d3976d49b3d048ab777a696cb850d 100644 (file)
@@ -350,7 +350,7 @@ static NSString *$getTheme$(NSArray *files, NSArray *themes = Themes_) {
 }
 // }}}
 // $pathForFile$inBundle$() {{{
-static NSString *$pathForFile$inBundle$(NSString *file, NSBundle *bundle, bool ui) {
+static NSString *$pathForFile$inBundle$(NSString *file, NSBundle *bundle, bool ui, bool use) {
     NSString *identifier = [bundle bundleIdentifier];
     NSMutableArray *names = [NSMutableArray arrayWithCapacity:8];
 
@@ -387,7 +387,7 @@ static NSString *$pathForFile$inBundle$(NSString *file, NSBundle *bundle, bool u
 
     [names addObject:[NSString stringWithFormat:@"Fallback/%@", file]];
 
-    if (NSString *path = $getTheme$($useScale$(names, ui)))
+    if (NSString *path = $getTheme$($useScale$(names, use)))
         return path;
 
     return nil;
@@ -490,7 +490,7 @@ static NSString *$pathForIcon$(SBApplication *self, NSString *suffix = @"") {
         if ([file hasPrefix:prefix]) {
             NSUInteger length([prefix length]);
             if (length != [file length])
-                if (NSString *path = $pathForFile$inBundle$([file substringFromIndex:(length + 1)], bundle, false))
+                if (NSString *path = $pathForFile$inBundle$([file substringFromIndex:(length + 1)], bundle, false, false))
                     return path;
         }
     }
@@ -671,7 +671,7 @@ MSHook(UIImage *, _UIApplicationImageWithName, NSString *name) {
     NSBundle *bundle = [NSBundle mainBundle];
     if (Debug_)
         NSLog(@"WB:Debug: _UIApplicationImageWithName(\"%@\", %@)", name, bundle);
-    if (NSString *path = $pathForFile$inBundle$(name, bundle, false))
+    if (NSString *path = $pathForFile$inBundle$(name, bundle, false, false))
         return CachedImageAtPath(path);
     return __UIApplicationImageWithName(name);
 }
@@ -699,7 +699,7 @@ MSInstanceMessageHook2(NSString *, NSBundle, pathForResource,ofType, NSString *,
     NSString *file = type == nil ? resource : [NSString stringWithFormat:@"%@.%@", resource, type];
     if (Debug_)
         NSLog(@"WB:Debug: [NSBundle(%@) pathForResource:\"%@\"]", [self bundleIdentifier], file);
-    if (NSString *path = $pathForFile$inBundle$(file, self, false))
+    if (NSString *path = $pathForFile$inBundle$(file, self, false, false))
         return path;
     return MSOldCall(resource, type);
 }
@@ -1314,9 +1314,23 @@ MSHook(void, SBAwayView$updateDesktopImage$, SBAwayView *self, SEL sel, UIImage
         [view setBackgroundColor:[UIColor clearColor]];
 
         [self insertSubview:view aboveSubview:_backgroundView];
+
+        if ($objc_setAssociatedObject != NULL)
+            $objc_setAssociatedObject(self, @selector(wb$widgetView), view, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
     }
 }
 
+MSHook(void, SBAwayView$_addSubview$positioned$relativeTo$, SBAwayView *self, SEL sel, UIView *view, int positioned, UIView *relative) {
+    UIView *&_backgroundView(MSHookIvar<UIView *>(self, "_backgroundView"));
+    UIView *&_chargingView(MSHookIvar<UIView *>(self, "_chargingView"));
+    if (&_chargingView != NULL)
+        if (positioned == -2 && (relative == _backgroundView && _chargingView == nil || relative == _chargingView))
+            if ($objc_getAssociatedObject != NULL)
+                if (UIView *widget = $objc_getAssociatedObject(self, @selector(wb$widgetView)))
+                    relative = widget;
+    return _SBAwayView$_addSubview$positioned$relativeTo$(self, sel, view, positioned, relative);
+}
+
 /*extern "C" CGColorRef CGGStateGetSystemColor(void *);
 extern "C" CGColorRef CGGStateGetFillColor(void *);
 extern "C" CGColorRef CGGStateGetStrokeColor(void *);
@@ -1693,7 +1707,7 @@ MSInstanceMessageHook3(NSString *, NSBundle, localizedStringForKey,value,table,
                 return value;
     } else if (NSString *path = $pathForFile$inBundle$([NSString stringWithFormat:@"%@.lproj/%@.strings",
         language, file
-    ], self, false)) {
+    ], self, false, false)) {
         if ((strings = [[NSDictionary alloc] initWithContentsOfFile:path]) != nil) {
             [Strings_ setObject:[strings autorelease] forKey:name];
             goto strings;
@@ -1880,28 +1894,28 @@ MSInstanceMessageHook0(void, CKTranscriptController, loadView) {
 }
 // }}}
 
-MSInstanceMessage2(UISharedArtwork *, UISharedArtwork, initWithName,inBundle, NSString *, name, NSBundle *, bundle) {
+MSInstanceMessage2(UIImageTableArtwork *, UIImageTableArtwork, initWithName,inBundle, NSString *, name, NSBundle *, bundle) {
     if ((self = MSOldCall(name, bundle)) != nil) {
         $objc_setAssociatedObject(self, @selector(wb$bundle), bundle, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
     } return self;
 }
 
-MSInstanceMessage1(UIImage *, UIImageTableArtwork, imageNamed, NSString *, name) {
+MSInstanceMessage2(UIImage *, UIImageTableArtwork, imageNamed,device, NSString *, name, int, device) {
     NSBundle *bundle($objc_getAssociatedObject(self, @selector(wb$bundle)));
     if (Debug_)
-        NSLog(@"WB:Debug:[UIImageTableArtwork[%@] imageNamed:\"%@\"]", bundle, name);
+        NSLog(@"WB:Debug:[UIImageTableArtwork[%@] imageNamed:\"%@\" device:%i]", bundle, name, device);
     if (bundle == nil)
-        return MSOldCall(name);
+        return MSOldCall(name, device);
     UIImage *image = [UIImages_ objectForKey:name];
     if (image != nil)
-        return reinterpret_cast<id>(image) == [NSNull null] ? MSOldCall(name) : image;
-    if (NSString *path = $pathForFile$inBundle$(name, bundle, true))
+        return reinterpret_cast<id>(image) == [NSNull null] ? MSOldCall(name, device) : image;
+    if (NSString *path = $pathForFile$inBundle$(name, bundle, true, true))
         image = $getImage$(path);
     [UIImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:name];
     if (image != nil)
         return image;
 
-    image = MSOldCall(name);
+    image = MSOldCall(name, device);
 
     if (UIDebug_) {
         NSString *path([@"/tmp/UIImages/" stringByAppendingString:name]);
@@ -1942,7 +1956,7 @@ MSHook(UIImage *, _UIImageWithName, NSString *name) {
         UIImage *image([UIImages_ objectForKey:key]);
         if (image != nil)
             return reinterpret_cast<id>(image) == [NSNull null] ? __UIImageWithName(name) : image;
-        if (NSString *path = $pathForFile$inBundle$(name, _UIKitBundle(), true))
+        if (NSString *path = $pathForFile$inBundle$(name, _UIKitBundle(), true, true))
             image = $getImage$(path);
         [UIImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:key];
         if (image != nil)
@@ -1990,14 +2004,9 @@ MSHook(GSFontRef, GSFontCreateWithName, const char *name, GSFontSymbolicTraits t
 #define AudioToolbox "/System/Library/Frameworks/AudioToolbox.framework/AudioToolbox"
 #define UIKit "/System/Library/Frameworks/UIKit.framework/UIKit"
 
-bool (*_Z24GetFileNameForThisActionmPcRb)(unsigned long a0, char *a1, bool &a2);
-
-MSHook(bool, _Z24GetFileNameForThisActionmPcRb, unsigned long a0, char *a1, bool &a2) {
-    if (Debug_)
-        NSLog(@"WB:Debug:GetFileNameForThisAction(%u, %p, %u)", a0, a1, a2);
-    bool value = __Z24GetFileNameForThisActionmPcRb(a0, a1, a2);
+static bool GetFileNameForThisAction$(bool value, unsigned long a0, char *a1, unsigned long a2, bool &a3) {
     if (Debug_)
-        NSLog(@"WB:Debug:GetFileNameForThisAction(%u, %s, %u) = %u", a0, value ? a1 : NULL, a2, value);
+        NSLog(@"WB:Debug:GetFileNameForThisAction(%u, %s, %u, %u) = %u", a0, value ? a1 : NULL, a2, a3, value);
 
     if (value) {
         NSString *path = [NSString stringWithUTF8String:a1];
@@ -2015,6 +2024,16 @@ MSHook(bool, _Z24GetFileNameForThisActionmPcRb, unsigned long a0, char *a1, bool
     return value;
 }
 
+MSHook(bool, _Z24GetFileNameForThisActionmPcRb, unsigned long a0, char *a1, bool &a3) {
+    bool value(__Z24GetFileNameForThisActionmPcRb(a0, a1, a3));
+    return GetFileNameForThisAction$(value, a0, a1, 0, a3);
+}
+
+MSHook(bool, _Z24GetFileNameForThisActionmPcmRb, unsigned long a0, char *a1, unsigned long a2, bool &a3) {
+    bool value(__Z24GetFileNameForThisActionmPcmRb(a0, a1, a2, a3));
+    return GetFileNameForThisAction$(value, a0, a1, a2, a3);
+}
+
 static void ChangeWallpaper(
     CFNotificationCenterRef center,
     void *observer,
@@ -2039,6 +2058,41 @@ static void ChangeWallpaper(
 
 }
 
+MSHook(NSArray *, CPBitmapCreateImagesFromPath, NSString *path, NSDictionary **names, void *arg2, void *arg3) {
+    NSArray *images(_CPBitmapCreateImagesFromPath(path, names, arg2, arg3));
+    if (images != NULL && *names != nil && CFGetTypeID((CFTypeRef) *names) == CFDictionaryGetTypeID()) {
+        if (NSBundle *bundle = [NSBundle wb$bundleWithFile:path]) {
+            NSMutableArray *copy([images mutableCopy]);
+            [images release];
+            images = copy;
+
+            NSString *file([path stringByResolvingSymlinksInPath]);
+            NSString *prefix([[bundle bundlePath] stringByResolvingSymlinksInPath]);
+            if ([file hasPrefix:prefix]) {
+                NSUInteger length([prefix length]);
+                if (length != [file length]) {
+                    NSEnumerator *enumerator([*names keyEnumerator]);
+                    while (NSString *name = [enumerator nextObject]) {
+                        NSString *png([name stringByAppendingString:@".png"]);
+                        if (NSString *themed = $pathForFile$inBundle$(png, bundle, false, true)) {
+                            NSUInteger index([[*names objectForKey:name] intValue]);
+                            UIImage *image($getImage$(themed));
+                            CGImageRef cg([image CGImage]);
+                            [copy replaceObjectAtIndex:index withObject:(id)cg];
+                        }
+                    }
+                }
+            }
+        }
+    } return images;
+}
+
+MSHook(void, BKSDisplayServicesSetSystemAppExitedImagePath, NSString *path) {
+    if (NSString *themed = $getTheme$($useScale$([NSArray arrayWithObject:@"SystemAppExited.png"])))
+        path = themed;
+    _BKSDisplayServicesSetSystemAppExitedImagePath(path);
+}
+
 #define WBRename(name, sel, imp) \
     MSHookMessage($ ## name, @selector(sel), &$ ## name ## $ ## imp, &_ ## name ## $ ## imp)
 
@@ -2162,6 +2216,9 @@ static void SBInitialize() {
     //WBRename(SBImageCache, initWithName:forImageWidth:imageHeight:initialCapacity:, initWithName$forImageWidth$imageHeight$initialCapacity$);
 
     WBRename(SBAwayView, updateDesktopImage:, updateDesktopImage$);
+    if (kCFCoreFoundationVersionNumber >= 700)
+        WBRename(SBAwayView, _addSubview:positioned:relativeTo:, _addSubview$positioned$relativeTo$);
+
     WBRename(SBStatusBarContentsView, didMoveToSuperview, didMoveToSuperview);
     //WBRename(SBStatusBarContentsView, initWithStatusBar:mode:, initWithStatusBar$mode$);
     //WBRename(SBStatusBarController, setStatusBarMode:orientation:duration:animation:, setStatusBarMode$orientation$duration$animation$);
@@ -2267,10 +2324,29 @@ MSInitialize {
                     [Info_ setObject:[info objectForKey:key] forKey:key];
     // }}}
 
+    // AppSupport {{{
+    if (MSImageRef image = MSGetImageByName("/System/Library/PrivateFrameworks/AppSupport.framework/AppSupport")) {
+        NSArray *(*CPBitmapCreateImagesFromPath)(NSString *, NSDictionary **, void *, void *);
+        msset(CPBitmapCreateImagesFromPath, image, "_CPBitmapCreateImagesFromPath");
+        MSHookFunction(CPBitmapCreateImagesFromPath, MSHake(CPBitmapCreateImagesFromPath));
+    }
+    // }}}
     // AudioToolbox {{{
     if (MSImageRef image = MSGetImageByName(AudioToolbox)) {
+        bool (*_Z24GetFileNameForThisActionmPcRb)(unsigned long, char *, bool &);
         msset(_Z24GetFileNameForThisActionmPcRb, image, "__Z24GetFileNameForThisActionmPcRb");
         MSHookFunction(_Z24GetFileNameForThisActionmPcRb, &$_Z24GetFileNameForThisActionmPcRb, &__Z24GetFileNameForThisActionmPcRb);
+
+        bool (*_Z24GetFileNameForThisActionmPcmRb)(unsigned long, char *, unsigned long, bool &);
+        msset(_Z24GetFileNameForThisActionmPcmRb, image, "__Z24GetFileNameForThisActionmPcmRb");
+        MSHookFunction(_Z24GetFileNameForThisActionmPcmRb, &$_Z24GetFileNameForThisActionmPcmRb, &__Z24GetFileNameForThisActionmPcmRb);
+    }
+    // }}}
+    // BackBoardServices {{{
+    if (MSImageRef image = MSGetImageByName("/System/Library/PrivateFrameworks/BackBoardServices.framework/BackBoardServices")) {
+        void (*BKSDisplayServicesSetSystemAppExitedImagePath)(NSString *path);
+        msset(BKSDisplayServicesSetSystemAppExitedImagePath, image, "_BKSDisplayServicesSetSystemAppExitedImagePath");
+        MSHookFunction(BKSDisplayServicesSetSystemAppExitedImagePath, MSHake(BKSDisplayServicesSetSystemAppExitedImagePath));
     }
     // }}}
     // GraphicsServices {{{
@@ -2279,10 +2355,17 @@ MSInitialize {
     }
     // }}}
     // ImageIO {{{
-    if (MSImageRef image = MSGetImageByName("/System/Library/Frameworks/ImageIO.framework/ImageIO")) {
-        void *(*CGImageReadCreateWithFile)(NSString *, int);
-        msset(CGImageReadCreateWithFile, image, "_CGImageReadCreateWithFile");
-        MSHookFunction(CGImageReadCreateWithFile, MSHake(CGImageReadCreateWithFile));
+    MSImageRef imageio = MSGetImageByName("/System/Library/Frameworks/ImageIO.framework/ImageIO");
+    if (imageio == NULL)
+        imageio = MSGetImageByName("/System/Library/PrivateFrameworks/ImageIO.framework/ImageIO");
+    if (MSImageRef image = imageio) {
+        void *(*CGImageReadCreateWithFile)(NSString *, int) = NULL;
+        if (kCFCoreFoundationVersionNumber > 700) // XXX: iOS 6.x
+            CGImageReadCreateWithFile = NULL;
+        else {
+            msset(CGImageReadCreateWithFile, image, "_CGImageReadCreateWithFile");
+            MSHookFunction(CGImageReadCreateWithFile, MSHake(CGImageReadCreateWithFile));
+        }
 
         if (CGImageReadCreateWithFile == NULL) {
             void *(*CGImageSourceCreateWithFile)(NSString *, NSDictionary *);
@@ -2325,8 +2408,8 @@ MSInitialize {
         class_addMethod($NSString, @selector(sizeWithStyle:forWidth:), (IMP) &NSString$sizeWithStyle$forWidth$, "{CGSize=ff}16@0:4@8f12");
 
         if (kCFCoreFoundationVersionNumber > 700) { // XXX: iOS 6.x
-            WBRename(UISharedArtwork, initWithName:inBundle:, initWithName$inBundle$);
-            WBRename(UIImageTableArtwork, imageNamed:, imageNamed$);
+            WBRename(UIImageTableArtwork, initWithName:inBundle:, initWithName$inBundle$);
+            WBRename(UIImageTableArtwork, imageNamed:device:, imageNamed$device$);
         } else {
             struct nlist nl[6];
             memset(nl, 0, sizeof(nl));