+ if (WallpaperImage_ != nil)
+ [WallpaperImage_ setImage:image];
+ if (WallpaperPage_ != nil)
+ [WallpaperPage_ loadRequest:[NSURLRequest requestWithURL:WallpaperURL_]];
+
+}
+
+#define WBRename(name, sel, imp) \
+ _ ## name ## $ ## imp = MSHookMessage($ ## name, @selector(sel), &$ ## name ## $ ## imp)
+
+template <typename Type_>
+static void nlset(Type_ &function, struct nlist *nl, size_t index) {
+ struct nlist &name(nl[index]);
+ uintptr_t value(name.n_value);
+ if ((name.n_desc & N_ARM_THUMB_DEF) != 0)
+ value |= 0x00000001;
+ function = reinterpret_cast<Type_>(value);
+}
+
+template <typename Type_>
+static void dlset(Type_ &function, const char *name) {
+ function = reinterpret_cast<Type_>(dlsym(RTLD_DEFAULT, name));
+}
+
+extern "C" void WBInitialize() {
+ NSAutoreleasePool *pool([[NSAutoreleasePool alloc] init]);
+
+ NSString *identifier([[NSBundle mainBundle] bundleIdentifier]);
+
+ NSLog(@"WB:Notice: WinterBoard");
+
+ dlset(_GSFontGetUseLegacyFontMetrics, "GSFontGetUseLegacyFontMetrics");
+
+ struct nlist nl[8];
+
+ memset(nl, 0, sizeof(nl));
+ nl[0].n_un.n_name = (char *) "__UIApplicationImageWithName";
+ nl[1].n_un.n_name = (char *) "__UIImageAtPath";
+ 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 *) "__UISharedImageNameGetIdentifier";
+ nl[6].n_un.n_name = (char *) "__UISharedImageWithIdentifier";
+ nlist(UIKit, nl);
+
+ nlset(_UIApplicationImageWithName, nl, 0);
+ nlset(_UIImageAtPath, nl, 1);
+ nlset(_UIImageRefAtPath, nl, 2);
+ nlset(_UIImageWithNameInDomain, nl, 3);
+ nlset(_UIKitBundle, nl, 4);
+ nlset(_UISharedImageNameGetIdentifier, nl, 5);
+ nlset(_UISharedImageWithIdentifier, nl, 6);
+
+ 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));
+ nl[0].n_un.n_name = (char *) "__Z24GetFileNameForThisActionmPcRb";
+ nlist(AudioToolbox, nl);
+ nlset(_Z24GetFileNameForThisActionmPcRb, nl, 0);
+ MSHookFunction(_Z24GetFileNameForThisActionmPcRb, &$_Z24GetFileNameForThisActionmPcRb, &__Z24GetFileNameForThisActionmPcRb);
+ }
+
+ $NSBundle = objc_getClass("NSBundle");
+
+ _NSBundle$localizedStringForKey$value$table$ = MSHookMessage($NSBundle, @selector(localizedStringForKey:value:table:), &$NSBundle$localizedStringForKey$value$table$);
+ _NSBundle$pathForResource$ofType$ = MSHookMessage($NSBundle, @selector(pathForResource:ofType:), &$NSBundle$pathForResource$ofType$);
+
+ $UIImage = objc_getClass("UIImage");
+ $UINavigationBar = objc_getClass("UINavigationBar");
+ $UIToolbar = objc_getClass("UIToolbar");
+
+ _UIImage$defaultDesktopImage = MSHookMessage(object_getClass($UIImage), @selector(defaultDesktopImage), &$UIImage$defaultDesktopImage);
+
+ //WBRename("UINavigationBar", @selector(initWithCoder:), (IMP) &UINavigationBar$initWithCoder$);
+ //WBRename("UINavigationBarBackground", @selector(initWithFrame:withBarStyle:withTintColor:), (IMP) &UINavigationBarBackground$initWithFrame$withBarStyle$withTintColor$);
+
+ _UINavigationBar$setBarStyle$ = MSHookMessage($UINavigationBar, @selector(setBarStyle:), &$UINavigationBar$setBarStyle$);
+ _UIToolbar$setBarStyle$ = MSHookMessage($UIToolbar, @selector(setBarStyle:), &$UIToolbar$setBarStyle$);
+
+ Manager_ = [[NSFileManager defaultManager] retain];
+ UIImages_ = [[NSMutableDictionary alloc] initWithCapacity:16];
+ PathImages_ = [[NSMutableDictionary alloc] initWithCapacity:16];
+ Strings_ = [[NSMutableDictionary alloc] initWithCapacity:0];
+ Bundles_ = [[NSMutableDictionary alloc] initWithCapacity:2];
+ Themed_ = [[NSMutableDictionary alloc] initWithCapacity:128];
+
+ themes_ = [[NSMutableArray alloc] initWithCapacity:8];
+
+ if (NSDictionary *settings = [NSDictionary dictionaryWithContentsOfFile:[NSString stringWithFormat:@"/User/Library/Preferences/com.saurik.WinterBoard.plist"]]) {
+ if (NSNumber *value = [settings objectForKey:@"SummerBoard"])
+ SummerBoard_ = [value boolValue];
+ if (NSNumber *value = [settings objectForKey:@"Debug"])
+ Debug_ = [value boolValue];
+
+ NSArray *themes([settings objectForKey:@"Themes"]);
+ if (themes == nil)
+ if (NSString *theme = [settings objectForKey:@"Theme"])
+ themes = [NSArray arrayWithObject:[NSDictionary dictionaryWithObjectsAndKeys:
+ theme, @"Name",
+ [NSNumber numberWithBool:true], @"Active",
+ nil]];
+
+ if (themes != nil)
+ for (NSDictionary *theme in themes) {
+ NSNumber *active([theme objectForKey:@"Active"]);
+ if (![active boolValue])
+ continue;
+
+ NSString *name([theme objectForKey:@"Name"]);
+ if (name == nil)
+ continue;
+
+ NSString *theme(nil);
+
+ #define testForTheme(format...) \
+ if (theme == nil) { \
+ NSString *path = [NSString stringWithFormat:format]; \
+ if ([Manager_ fileExistsAtPath:path]) { \
+ [themes_ addObject:path]; \
+ continue; \
+ } \
+ }
+
+ testForTheme(@"/Library/Themes/%@.theme", name)
+ testForTheme(@"/Library/Themes/%@", name)
+ testForTheme(@"%@/Library/SummerBoard/Themes/%@", NSHomeDirectory(), name)
+
+ }
+ }
+
+ Info_ = [[NSMutableDictionary dictionaryWithCapacity:16] retain];
+
+ for (NSString *theme in themes_)
+ if (NSDictionary *info = [NSDictionary dictionaryWithContentsOfFile:[NSString stringWithFormat:@"%@/Info.plist", theme]])
+ for (NSString *key in [info allKeys])
+ if ([Info_ objectForKey:key] == nil)
+ [Info_ setObject:[info objectForKey:key] forKey:key];
+
+ bool sms($getTheme$([NSArray arrayWithObjects:@"SMSBackground.png", @"SMSBackground.jpg", nil]) != nil);
+
+ if ([NSBundle bundleWithIdentifier:@"com.apple.chatkit"])
+ if (sms) {
+ $CKMessageCell = objc_getClass("CKMessageCell");
+ _CKMessageCell$addBalloonView$ = MSHookMessage($CKMessageCell, @selector(addBalloonView:), &$CKMessageCell$addBalloonView$);
+ _CKMessageCell$initWithStyle$reuseIdentifier$ = MSHookMessage($CKMessageCell, @selector(initWithStyle:reuseIdentifier:), &$CKMessageCell$initWithStyle$reuseIdentifier$);
+
+ $CKTranscriptTableView = objc_getClass("CKTranscriptTableView");
+ _CKTranscriptTableView$setSeparatorStyle$ = MSHookMessage($CKTranscriptTableView, @selector(setSeparatorStyle:), &$CKTranscriptTableView$setSeparatorStyle$);
+ _CKTranscriptTableView$initWithFrame$style$ = MSHookMessage($CKTranscriptTableView, @selector(initWithFrame:style:), &$CKTranscriptTableView$initWithFrame$style$);
+
+ $CKTimestampView = objc_getClass("CKTimestampView");
+ _CKTimestampView$initWithStyle$reuseIdentifier$ = MSHookMessage($CKTimestampView, @selector(initWithStyle:reuseIdentifier:), &$CKTimestampView$initWithStyle$reuseIdentifier$);
+
+ $CKTranscriptController = objc_getClass("CKTranscriptController");
+ _TranscriptController$loadView = MSHookMessage($CKTranscriptController, @selector(loadView), &$TranscriptController$loadView);