Skip to content

Commit

Permalink
Cleaned up
Browse files Browse the repository at this point in the history
  • Loading branch information
Thatchapon Unprasert committed Jul 13, 2017
0 parents commit c9fb653
Show file tree
Hide file tree
Showing 103 changed files with 1,708 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitignore
@@ -0,0 +1,6 @@
*.deb
.DS_Store
.theos
theos
obj
_
29 changes: 29 additions & 0 deletions BurstMode.h
@@ -0,0 +1,29 @@
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
#import "../PS.h"

NSString *tweakIdentifier = @"com.PS.BurstMode";
CFStringRef PreferencesNotification = CFSTR("com.PS.BurstMode/ReloadPrefs");

@interface CAMAvalancheSession (BurstMode)
- (void)fakeSetNum:(NSUInteger)fake;
@end

@interface PLCameraButton (BurstMode)
- (void)burst;
- (void)takePhoto;
@end

#define BurstModeEnabledKey @"BurstModeEnabled"
#define BurstModeSafeEnabledKey @"BurstModeSafeEnabled"
#define DisableIrisEnabledKey @"DisableIrisEnabled"
#define DisableAnimEnabledKey @"DisableAnimEnabled"
#define LiveWellEnabledKey @"LiveWellEnabled"
#define AllowHDREnabledKey @"AllowHDREnabled"
#define expFormatKey @"expFormat"
#define AnimIndKey @"AnimInd"
#define noCaptureSoundKey @"noCaptureSound"
#define singleCounterKey @"singleCounter"
#define PhotoLimitCountKey @"PhotoLimitCount"
#define HoldTimeKey @"HoldTime"
#define IntervalKey @"Interval"
1 change: 1 addition & 0 deletions BurstMode.plist
@@ -0,0 +1 @@
{ Filter = { Bundles = ( "com.apple.camera", "com.apple.mobileslideshow", "com.apple.springboard", "com.apple.Preferences" ); }; }
218 changes: 218 additions & 0 deletions BurstModePreferenceController.m
@@ -0,0 +1,218 @@
#define KILL_PROCESS
#import <UIKit/UIKit.h>
#import <Preferences/PSControlTableCell.h>
#import <Cephei/HBListController.h>
#import <Cephei/HBAppearanceSettings.h>
#import <Preferences/PSSpecifier.h>
#import <Social/Social.h>
#import <GraphicsServices/GraphicsServices.h>
#import "BurstMode.h"
#import <dlfcn.h>
#import "../PSPrefs.x"

DeclarePrefsTools()

extern CFStringRef kGSHDRImageCaptureCapability;
static BOOL (*MGGetBoolAnswer)(CFStringRef);

static BOOL hasCapability(CFStringRef capability){
if (!isiOS7Up)
return GSSystemHasCapability(capability);
if (!MGGetBoolAnswer) {
void *libMobileGestalt = dlopen("/usr/lib/libMobileGestalt.dylib", RTLD_LAZY);
if (libMobileGestalt)
MGGetBoolAnswer = dlsym(libMobileGestalt, "MGGetBoolAnswer");
}
if (MGGetBoolAnswer != NULL)
return MGGetBoolAnswer(capability);
return NO;
}

static BOOL hasHDR(){
return hasCapability(kGSHDRImageCaptureCapability);
}

@interface BurstModePreferenceController : HBListController
@property (nonatomic, retain) PSSpecifier *slidersSpec;
@property (nonatomic, retain) PSSpecifier *holdTimeSliderSpec;
@property (nonatomic, retain) PSSpecifier *intervalSpec;
@property (nonatomic, retain) PSSpecifier *burstModeSafeSpec;
@property (nonatomic, retain) PSSpecifier *disableIrisSpec;
@property (nonatomic, retain) PSSpecifier *disableAnimSpec;
@property (nonatomic, retain) PSSpecifier *liveWellSpec;
@property (nonatomic, retain) PSSpecifier *allowHDRSpec;
@property (nonatomic, retain) PSSpecifier *expFormatSpec;
@property (nonatomic, retain) PSSpecifier *animIndSpec;
@property (nonatomic, retain) PSSpecifier *help56Spec;
@property (nonatomic, retain) PSSpecifier *help78Spec;
@property (nonatomic, retain) PSSpecifier *description2Spec;
@end

@interface BMSliderTableCell : PSControlTableCell
@end

@implementation BMSliderTableCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)identifier specifier:(PSSpecifier *)spec {
if (self == [super initWithStyle:style reuseIdentifier:identifier specifier:spec]) {
UISlider *slider = [[[UISlider alloc] init] autorelease];
slider.continuous = NO;
slider.minimumValue = [[spec propertyForKey:@"min"] floatValue];
slider.maximumValue = [[spec propertyForKey:@"max"] floatValue];
NSString *key = [spec propertyForKey:@"key"];
float value = floatForKey(key, [[spec propertyForKey:@"default"] floatValue]);
slider.value = value;
self.control = slider;

UILabel *label = [[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 35, 14)] autorelease];
label.text = [NSString stringWithFormat:@"%.2f", value];
label.lineBreakMode = NSLineBreakByWordWrapping;
label.textAlignment = NSTextAlignmentRight;
label.backgroundColor = [UIColor clearColor];

self.accessoryView = label;
self.textLabel.text = [spec propertyForKey:@"cellName"];
[slider addTarget:self action:@selector(sliderValueChanged:) forControlEvents:UIControlEventValueChanged];
}
return self;
}

- (void)sliderValueChanged:(UISlider *)slider {
setFloatForKey(slider.value, [self.specifier propertyForKey:@"key"]);
UILabel *label = (UILabel *)self.accessoryView;
label.text = [NSString stringWithFormat:@"%.2f", slider.value];
DoPostNotification();
}

- (void)layoutSubviews {
[super layoutSubviews];
CGSize textSize;
CGFloat textWidth;
UILabel *label = self.textLabel;
if (isiOS7Up) {
textSize = [label.text sizeWithAttributes:@{NSFontAttributeName:[label font]}];
textWidth = textSize.width;
} else {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
textSize = [label.text sizeWithFont:label.font];
textWidth = textSize.width;
#pragma clang diagnostic pop
}
CGFloat leftPad = textWidth + 28.0f;
CGFloat rightPad = 14.0f;
UIView *contentView = (UIView *)self.contentView;
UISlider *slider = (UISlider *)self.control;
slider.center = contentView.center;
slider.frame = CGRectMake(leftPad, slider.frame.origin.y, contentView.frame.size.width - leftPad - rightPad, slider.frame.size.height);
}

@end

@implementation BurstModePreferenceController

HavePrefs()

- (void)masterSwitch:(id)value specifier:(PSSpecifier *)spec {
[self setPreferenceValue:value specifier:spec];
killProcess("Camera");
if (isiOS7Up)
killProcess("MobileSlideshow");
}

HaveBanner2(@"Burst Mode", isiOS7Up ? UIColor.systemGrayColor : UIColor.grayColor, @"Extensions for Burst, right here", UIColor.grayColor)

- (id)init {
if (self == [super init]) {
HBAppearanceSettings *appearanceSettings = [[HBAppearanceSettings alloc] init];
appearanceSettings.tintColor = isiOS7Up ? UIColor.systemGrayColor : UIColor.whiteColor;
appearanceSettings.invertedNavigationBar = YES;
self.hb_appearanceSettings = appearanceSettings;
UIButton *heart = [[[UIButton alloc] initWithFrame:CGRectZero] autorelease];
UIImage *image = [UIImage imageNamed:@"Heart" inBundle:[NSBundle bundleWithPath:@"/Library/PreferenceBundles/BurstModeSettings.bundle"]];
if (isiOS7Up)
image = [image _flatImageWithColor:UIColor.whiteColor];
[heart setImage:image forState:UIControlStateNormal];
[heart sizeToFit];
[heart addTarget:self action:@selector(love) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:heart] autorelease];
}
return self;
}

- (void)love {
SLComposeViewController *twitter = [[SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter] retain];
twitter.initialText = @"#BurstMode by @PoomSmart is really awesome!";
[self.navigationController presentViewController:twitter animated:YES completion:nil];
[twitter release];
}

- (void)setPhotosLimit:(id)param {
[self hideKeyboard];
}

- (void)hideKeyboard {
[[super view] endEditing:YES];
}

- (NSArray *)specifiers {
if (_specifiers == nil) {
NSMutableArray *specs = [NSMutableArray arrayWithArray:[self loadSpecifiersFromPlistName:@"BurstMode" target:self]];

for (PSSpecifier *spec in specs) {
NSString *Id = [spec properties][@"id"];
if ([Id isEqualToString:@"Sliders"])
self.slidersSpec = spec;
else if ([Id isEqualToString:@"HoldTimeSlider"])
self.holdTimeSliderSpec = spec;
else if ([Id isEqualToString:@"Interval"])
self.intervalSpec = spec;
else if ([Id isEqualToString:@"BurstModeSafe"])
self.burstModeSafeSpec = spec;
else if ([Id isEqualToString:@"DisableIris"])
self.disableIrisSpec = spec;
else if ([Id isEqualToString:@"DisableAnim"])
self.disableAnimSpec = spec;
else if ([Id isEqualToString:@"LiveWell"])
self.liveWellSpec = spec;
else if ([Id isEqualToString:@"AllowHDR"])
self.allowHDRSpec = spec;
else if ([Id isEqualToString:@"expFormat"])
self.expFormatSpec = spec;
else if ([Id isEqualToString:@"AnimInd"])
self.animIndSpec = spec;
else if ([Id isEqualToString:@"help56"])
self.help56Spec = spec;
else if ([Id isEqualToString:@"help78"])
self.help78Spec = spec;
else if ([Id isEqualToString:@"Description2"])
self.description2Spec = spec;
}

if (isiOS7Up) {
if (!isiOS70)
[specs removeObject:self.allowHDRSpec];
[specs removeObject:self.slidersSpec];
[specs removeObject:self.holdTimeSliderSpec];
[specs removeObject:self.intervalSpec];
[specs removeObject:self.burstModeSafeSpec];
[specs removeObject:self.disableIrisSpec];
[specs removeObject:self.disableAnimSpec];
[specs removeObject:self.liveWellSpec];
[specs removeObject:self.help56Spec];
[specs removeObject:self.description2Spec];
if (isiOS8Up)
[specs removeObject:self.expFormatSpec];
} else {
[specs removeObject:self.expFormatSpec];
[specs removeObject:self.animIndSpec];
[specs removeObject:self.help78Spec];
}
if (!hasHDR())
[specs removeObject:self.allowHDRSpec];
_specifiers = [specs copy];
}
return _specifiers;
}

@end
12 changes: 12 additions & 0 deletions BurstModeiOS10/Makefile
@@ -0,0 +1,12 @@
GO_EASY_ON_ME = 1
SDKVERSION = 10.2

include $(THEOS)/makefiles/common.mk

LIBRARY_NAME = BurstModeiOS10
BurstModeiOS10_FILES = Tweak.xm
BurstModeiOS10_FRAMEWORKS = AudioToolbox UIKit
BurstModeiOS10_LIBRARIES = MobileGestalt substrate
BurstModeiOS10_INSTALL_PATH = /Library/Application Support/BurstMode

include $(THEOS_MAKE_PATH)/library.mk
107 changes: 107 additions & 0 deletions BurstModeiOS10/Tweak.xm
@@ -0,0 +1,107 @@
#import "../BurstMode.h"
#define TWEAK
#import "../Prefs.h"

%hook CUCaptureController

- (void)stopCapturingBurst
{
noSound = noCaptureSound;
%orig;
noSound = NO;
}

- (void)intervalometerDidReachMaximumCount:(id)arg1 {
noSound = noCaptureSound;
%orig;
noSound = NO;
}

- (void)startCapturingBurstWithRequest:(id)arg1 error:(id)arg2 {
noSound = noCaptureSound;
%orig;
noSound = NO;
}

%end

%hook CAMViewfinderViewController

- (void)_stillImageBurstCaptureRequestWithMaximumLength: (int)len
{
%orig(limitedPhotosCount > 0 ? limitedPhotosCount : len);
}

%end

%hook CAMBurstIndicatorView

- (void)_updateCountLabelWithNumberOfPhotos
{
if (singleCounter) {
NSInteger photoCount = MSHookIvar<NSInteger>(self, "__numberOfPhotos");
UILabel *label = MSHookIvar<UILabel *>(self, "__countLabel");
char cString[4];
sprintf(cString, "%ld", (long)photoCount);
NSString *s = [[[NSString alloc] initWithUTF8String:cString] autorelease];
label.text = s;
} else
%orig;
}

- (void)incrementWithCaptureAnimation:(BOOL)animated {
%orig(animInd ? NO : animated);
}

%end

%group MG

extern "C" Boolean MGGetBoolAnswer(CFStringRef);
%hookf(Boolean, MGGetBoolAnswer, CFStringRef string){
if (k("RearFacingCameraBurstCapability") || k("FrontFacingCameraBurstCapability"))
return YES;
return %orig(string);
}

%end

%group AudioHook

extern "C" void AudioServicesPlaySystemSound(SystemSoundID sound);
%hookf(void, AudioServicesPlaySystemSound, SystemSoundID sound){
if (sound == 1122 && noSound)
return;
%orig(sound);
}

extern "C" void AudioServicesStartSystemSound(SystemSoundID sound);
%hookf(void, AudioServicesStartSystemSound, SystemSoundID sound){
if (sound == 1119 && noSound)
return;
%orig(sound);
}

%end

%ctor
{
NSString *identifier = NSBundle.mainBundle.bundleIdentifier;
BOOL isSpringBoard = [identifier isEqualToString:@"com.apple.springboard"];
if (isSpringBoard)
return;
HaveObserver()
callback();
if (BurstMode) {
BOOL isPrefApp = [identifier isEqualToString:@"com.apple.Preferences"];
if (!isPrefApp) {
BOOL isPhotoApp = [identifier isEqualToString:@"com.apple.mobileslideshow"];
if (!isPhotoApp) {
openCamera10();
%init;
}
%init(AudioHook);
}
%init(MG);
}
}
12 changes: 12 additions & 0 deletions BurstModeiOS56/Makefile
@@ -0,0 +1,12 @@
GO_EASY_ON_ME = 1
ARCHS = armv7

include $(THEOS)/makefiles/common.mk

LIBRARY_NAME = BurstModeiOS56
BurstModeiOS56_FILES = Tweak.xm
BurstModeiOS56_FRAMEWORKS = AudioToolbox UIKit
BurstModeiOS56_INSTALL_PATH = /Library/Application Support/BurstMode
BurstModeiOS56_LIBRARIES = substrate

include $(THEOS_MAKE_PATH)/library.mk

0 comments on commit c9fb653

Please sign in to comment.