Created
March 15, 2013 06:09
-
-
Save jontelang/5167807 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%hook SBAwayDateView | |
//@interface SBAwayDateView : UIView | |
//-(NSString*)getTime:(double)elapsedSeconds; | |
//@end | |
@interface SBAwayController | |
+(id)sharedAwayController; | |
@end | |
@interface TPLCDTextView : UIView | |
-(void)setText:(id)arg; | |
-(id)text; | |
-(void)setCenterText:(CGRect)arg; | |
@end | |
static double seconds; | |
static NSTimer* timer; | |
%new | |
-(NSString*)getTime:(double)elapsedSeconds{ | |
NSUInteger h = (int)elapsedSeconds / 3600; | |
NSUInteger m = ((int)elapsedSeconds / 60) % 60; | |
NSUInteger s = (int)elapsedSeconds % 60; | |
double ms = elapsedSeconds - (int)elapsedSeconds; | |
double sandms = s+ms; | |
NSString *formattedTime = [NSString stringWithFormat:@"%02u:%02u:%04.1f", h, m, sandms]; | |
return formattedTime; | |
} | |
%new | |
-(void)IncreaseSeconds | |
{ | |
SBAwayController *sbac = [objc_getClass("SBAwayController") sharedAwayController]; | |
BOOL active = MSHookIvar<BOOL>(sbac, "_isActive"); | |
if(active) | |
{ | |
seconds += 0.1; | |
TPLCDTextView *clock = MSHookIvar<TPLCDTextView *>(self, "_timeLabel"); | |
[clock setText:[self getTime:seconds]]; | |
//[clock setCenterText:CGRectMake(320/2,100,320,100)]; | |
clock.layer.borderWidth = 1; | |
[clock setNeedsDisplay]; | |
} | |
else | |
{ | |
NSLog(@"Invalidating timer"); | |
[timer invalidate]; | |
timer=Nil; | |
} | |
} | |
-(void)update{ | |
} | |
- (void)updateClock{ | |
%orig; | |
SBAwayController *sbac = [objc_getClass("SBAwayController") sharedAwayController]; | |
BOOL active = MSHookIvar<BOOL>(sbac, "_isActive"); | |
if(active) | |
{ | |
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:@"/var/mobile/Library/Preferences/com.apple.mobiletimer.plist"]; | |
BOOL TIMERRUNNING = [[dict valueForKey:@"TIMERRUNNING"] boolValue]; | |
if( TIMERRUNNING ){ | |
NSDate *STARTTIME = [dict valueForKey:@"STARTTIME"]; | |
int LASTTIME = [[dict valueForKey:@"LASTTIME"] intValue]; | |
NSTimeInterval timeInterval = [STARTTIME timeIntervalSinceNow]; | |
seconds = -(int)timeInterval + LASTTIME; | |
TPLCDTextView *clock = MSHookIvar<TPLCDTextView *>(self, "_timeLabel"); | |
[clock setText:[self getTime:seconds]]; | |
TPLCDTextView *date = MSHookIvar<TPLCDTextView *>(self, "_dateAndTetheringLabel"); | |
[date setText:@"Stopwatch"]; | |
[self setNeedsDisplay]; | |
[clock setNeedsDisplay]; | |
if(timer){if([timer isValid]){[timer invalidate];}} | |
timer = [NSTimer scheduledTimerWithTimeInterval:0.1 | |
target:self | |
selector:@selector(IncreaseSeconds) | |
userInfo:nil | |
repeats:YES]; | |
} | |
} | |
} | |
%end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment