Skip to content

Commit

Permalink
v1.3 - More options (Goose count, Max. gift count)
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelomer committed Mar 16, 2020
1 parent b7495b2 commit e996b47
Show file tree
Hide file tree
Showing 7 changed files with 176 additions and 6 deletions.
1 change: 1 addition & 0 deletions Goose/MGGooseController.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
__kindof MGContainerView *imageContainer;
}
@property (nonatomic, strong, readonly) MGGooseView *gooseView;
@property (nonatomic, assign) BOOL useSharedContainerArray;
- (instancetype)initWithGoose:(MGGooseView *)goose;
- (void)startLooping;
@end
19 changes: 17 additions & 2 deletions Goose/MGGooseController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
@implementation MGGooseController

static const CGFloat defaultSpeed = 2.6;
static NSPointerArray *sharedContainers;

+ (void)load {
if (self == [MGGooseController class]) {
sharedContainers = [NSPointerArray weakObjectsPointerArray];
}
}

- (void)loadMeme {
BOOL isImage = [imageContainer isKindOfClass:[MGImageContainerView class]];
Expand Down Expand Up @@ -124,7 +131,7 @@ - (void)pullMemeFrameForSender:(MGGooseView *)sender state:(MGGooseFrameState)st
- (void)continueWithRandomAnimation {
uint8_t randomValue = arc4random_uniform(50);
[containers MGCompact];
if ((containers.count >= 5) && (randomValue >= 40)) randomValue += 10;
if ((containers.count >= @(floor(((NSNumber *)(PrefValue(@"MaxGiftCount") ?: @5)).doubleValue)).integerValue) && (randomValue >= 40)) randomValue += 10;
Class cls = nil;
if ([(((NSNumber *)PrefValue(@"BringImages")) ?: @YES) boolValue] &&
(randomValue <= 44) && (randomValue >= 40))
Expand Down Expand Up @@ -233,10 +240,18 @@ - (void)defaultWalkAnimation {
];
}

- (void)setUseSharedContainerArray:(BOOL)newValue {
if (!!newValue != !!_useSharedContainerArray) {
if (newValue) containers = sharedContainers;
else containers = [NSPointerArray weakObjectsPointerArray];
}
_useSharedContainerArray = newValue;
}

- (instancetype)initWithGoose:(MGGooseView *)goose {
if ((self = [super init])) {
_gooseView = goose;
containers = [NSPointerArray weakObjectsPointerArray];
self.useSharedContainerArray = YES;
}
return self;
}
Expand Down
1 change: 1 addition & 0 deletions Prefs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ BUNDLE_NAME = MobileGoose
MobileGoose_FILES = $(wildcard *.mm)
MobileGoose_INSTALL_PATH = /Library/PreferenceBundles
MobileGoose_FRAMEWORKS = UIKit
MobileGoose_LIBRARIES = substrate
MobileGoose_PRIVATE_FRAMEWORKS = Preferences
MobileGoose_CFLAGS = -fobjc-arc

Expand Down
71 changes: 70 additions & 1 deletion Prefs/PXMGPRootListController.mm
Original file line number Diff line number Diff line change
@@ -1,8 +1,34 @@
#include "PXMGPRootListController.h"
#import "PXMGPRootListController.h"
#import <Preferences/PSSpecifier.h>
#import <substrate.h>

@interface UIView(Private)
- (UIViewController *)_viewControllerForAncestor;
@end

static void (*MobileGoose$UILabel$setText$orig)(id,SEL,id) = nil;
static void MobileGoose$UILabel$setText$hook(UILabel *self, SEL _cmd, NSString *text) {
if ([self._viewControllerForAncestor isKindOfClass:[PXMGPRootListController class]]) {
if ([self.superview isKindOfClass:[UISlider class]]) {
text = [text componentsSeparatedByString:@"."].firstObject;
}
}
MobileGoose$UILabel$setText$orig(self, _cmd, text);
}

@implementation PXMGPRootListController

+ (void)load {
if ((self == [PXMGPRootListController class]) && !MobileGoose$UILabel$setText$orig) {
MSHookMessageEx(
UILabel.class,
@selector(setText:),
(IMP)&MobileGoose$UILabel$setText$hook,
(IMP*)&MobileGoose$UILabel$setText$orig
);
}
}

- (NSArray *)specifiers {
if (!_specifiers) {
_specifiers = [self loadSpecifiersFromPlistName:@"Root" target:self];
Expand All @@ -11,6 +37,49 @@ - (NSArray *)specifiers {
return _specifiers;
}

- (void)didRequestRespring:(PSSpecifier *)button {
CFNotificationCenterPostNotification(
CFNotificationCenterGetDarwinNotifyCenter(),
CFSTR("com.pixelomer.mobilegoose/Exit"),
NULL, NULL, YES
);
}

- (void)setPreferenceValue:(id)value specifier:(PSSpecifier *)specifier {
[super setPreferenceValue:value specifier:specifier];
NSNumber *requiresRespring = [specifier propertyForKey:@"requiresRespring"];
if (requiresRespring.boolValue) {
for (PSSpecifier *button in _specifiers) {
SEL action = MSHookIvar<SEL>(button, "action");
if (action == @selector(didRequestRespring:)) {
[button setProperty:@YES forKey:@"enabled"];
[self reloadSpecifier:button];
}
}
}
}

- (void)setPreferenceValue:(NSNumber *)value forDangerousSlider:(PSSpecifier *)specifier {
[self setPreferenceValue:value specifier:specifier];
NSNumber *recommendedMax = [specifier propertyForKey:@"recommendedMax"];
NSNumber *didShowWarning = [specifier propertyForKey:@"__didShowWarning"];
if (!didShowWarning.boolValue && (floor(value.doubleValue) > floor(recommendedMax.doubleValue))) {
NSString *message = [NSString
stringWithFormat:[specifier propertyForKey:@"warningMessage"],
recommendedMax
];
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Warning"
message:message
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil
];
[alert show];
[specifier setProperty:@YES forKey:@"__didShowWarning"];
}
}

- (void)setPreferenceValue:(NSNumber *)value forNotifyingSwitch:(PSSpecifier *)specifier {
[self setPreferenceValue:value specifier:specifier];
NSNotificationName notificationName;
Expand Down
68 changes: 67 additions & 1 deletion Prefs/Resources/Root.plist
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<key>cell</key>
<string>PSGroupCell</string>
<key>label</key>
<string>MobileGooses</string>
<string>MobileGoose</string>
</dict>
<dict>
<key>cell</key>
Expand Down Expand Up @@ -80,6 +80,72 @@
<key>label</key>
<string>Disable Default Gifts</string>
</dict>
<dict>
<key>cell</key>
<string>PSGroupCell</string>
<key>label</key>
<string>Gift Count</string>
<key>footerText</key>
<string>You can tap the gifts to dismiss them.</string>
</dict>
<dict>
<key>cell</key>
<string>PSSliderCell</string>
<key>defaults</key>
<string>com.pixelomer.mobilegoose</string>
<key>key</key>
<string>MaxGiftCount</string>
<key>default</key>
<integer>5</integer>
<key>min</key>
<integer>1</integer>
<key>max</key>
<integer>50</integer>
<key>showValue</key>
<true/>
</dict>
<dict>
<key>cell</key>
<string>PSGroupCell</string>
<key>label</key>
<string>Goose Count</string>
<key>footerText</key>
<string>SpringBoard needs to be restarted for this change to take effect.</string>
</dict>
<dict>
<key>cell</key>
<string>PSSliderCell</string>
<key>defaults</key>
<string>com.pixelomer.mobilegoose</string>
<key>key</key>
<string>GooseCount</string>
<key>requiresRespring</key>
<true/>
<key>default</key>
<integer>1</integer>
<key>min</key>
<integer>1</integer>
<key>max</key>
<integer>50</integer>
<key>recommendedMax</key>
<integer>10</integer>
<key>warningMessage</key>
<string>Having more than %@ geese on-screen could make your device unusable.</string>
<key>set</key>
<string>setPreferenceValue:forDangerousSlider:</string>
<key>showValue</key>
<true/>
</dict>
<dict>
<key>cell</key>
<string>PSButtonCell</string>
<key>label</key>
<string>Restart SpringBoard</string>
<key>action</key>
<string>didRequestRespring:</string>
<key>enabled</key>
<false/>
</dict>
<dict>
<key>cell</key>
<string>PSGroupCell</string>
Expand Down
20 changes: 19 additions & 1 deletion Tweak.xm
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ CGAffineTransform MGGetTransform(void) {
[gooseWindow makeKeyAndVisible];
containers = [NSPointerArray weakObjectsPointerArray];
NSMutableArray *mHonks = [NSMutableArray new];
const NSInteger gooseCount = 1;
const NSInteger gooseCount = @(floor(((NSNumber *)(PrefValue(@"GooseCount") ?: @1)).doubleValue)).integerValue;
NSMutableDictionary *modObjects = [NSMutableDictionary new];
for (NSInteger i=0; i<gooseCount; i++) {
CGRect frame = CGRectMake(0, 0, 0, 0);
Expand Down Expand Up @@ -195,6 +195,16 @@ static void MGResetPreferences(
[NSUserDefaults.standardUserDefaults synchronize];
}

static void MGHandleExitNotification(
CFNotificationCenterRef center,
void *observer,
CFNotificationName name,
const void *object,
CFDictionaryRef userInfo
) {
exit(0);
}

%ctor {
CFNotificationCenterAddObserver(
CFNotificationCenterGetDarwinNotifyCenter(),
Expand All @@ -204,6 +214,14 @@ static void MGResetPreferences(
NULL,
0
);
CFNotificationCenterAddObserver(
CFNotificationCenterGetDarwinNotifyCenter(),
NULL,
&MGHandleExitNotification,
CFSTR("com.pixelomer.mobilegoose/Exit"),
NULL,
0
);
NSString *dir = @"/Library/MobileGoose/Mods";
NSArray *mods = [NSFileManager.defaultManager
contentsOfDirectoryAtPath:dir
Expand Down
2 changes: 1 addition & 1 deletion control
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: com.pixelomer.mobilegoose
Name: MobileGoose
Depends: mobilesubstrate, preferenceloader
Version: 1.2.1
Version: 1.3
Architecture: iphoneos-arm
Description: An annoying goose for your iDevice
Maintainer: PixelOmer
Expand Down

0 comments on commit e996b47

Please sign in to comment.