-
Notifications
You must be signed in to change notification settings - Fork 23
/
Tweak.xm
832 lines (659 loc) · 27.4 KB
/
Tweak.xm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
#import <CoreLocation/CoreLocation.h>
#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
////////------ External ------//////
//
// RSPlayPauseButton.h
//
// Created by Raphael Schaad on 2014-03-22.
// This is free and unencumbered software released into the public domain.
//
#import <UIKit/UIKit.h>
#define RSPlayPauseButtonAnimationStyleSplit 0 // Default
#define RSPlayPauseButtonAnimationStyleSplitAndRotate 1
//
// Displays a ⃝ with either the ► (play) or ❚❚ (pause) icon and nicely morphs between the two states.
// It's targeted for iOS 7+ and is tintColor-aware.
//
@interface RSPlayPauseButton : UIControl
// State
@property (nonatomic, assign, getter = isPaused) BOOL paused; // Default is `YES`; changing this way is not animated
- (void)setPaused:(BOOL)paused animated:(BOOL)animated;
// Style
@property (nonatomic, assign) int animationStyle; // Default is `RSPlayPauseButtonAnimationStyleSplit`
@end
//
// RSPlayPauseButton.m
//
// Created by Raphael Schaad https://github.com/raphaelschaad on 2014-03-22.
// This is free and unencumbered software released into the public domain.
//
#include <tgmath.h> // type generic math, yo: http://en.wikipedia.org/wiki/Tgmath.h#tgmath.h
static const CGFloat kScale = 1.0;
static const CGFloat kBorderSize = 32.0 * kScale;
static const CGFloat kBorderWidth = 0.0 * kScale;
static const CGFloat kSize = kBorderSize + kBorderWidth; // The total size is the border size + 2x half the border width.
static const CGFloat kPauseLineWidth = 4.0 * kScale;
static const CGFloat kPauseLineHeight = 15.0 * kScale;
static const CGFloat kPauseLinesSpace = 4.0 * kScale;
static const CGFloat kPlayTriangleOffsetX = 2.0 * kScale;
static const CGFloat kPlayTriangleTipOffsetX = 2.0 * kScale;
static const CGPoint p1 = {0.0, 0.0}; // line 1, top left
static const CGPoint p2 = {kPauseLineWidth, 0.0}; // line 1, top right
static const CGPoint p3 = {kPauseLineWidth, kPauseLineHeight}; // line 1, bottom right
static const CGPoint p4 = {0.0, kPauseLineHeight}; // line 1, bottom left
static const CGPoint p5 = {kPauseLineWidth + kPauseLinesSpace, 0.0}; // line 2, top left
static const CGPoint p6 = {kPauseLineWidth + kPauseLinesSpace + kPauseLineWidth, 0.0}; // line 2, top right
static const CGPoint p7 = {kPauseLineWidth + kPauseLinesSpace + kPauseLineWidth, kPauseLineHeight}; // line 2, bottom right
static const CGPoint p8 = {kPauseLineWidth + kPauseLinesSpace, kPauseLineHeight}; // line 2, bottom left
@interface RSPlayPauseButton ()
@property (nonatomic, strong) CAShapeLayer *borderShapeLayer;
@property (nonatomic, strong) CAShapeLayer *playPauseShapeLayer;
@property (nonatomic, strong, readonly) UIBezierPath *pauseBezierPath;
@property (nonatomic, strong, readonly) UIBezierPath *pauseRotateBezierPath;
@property (nonatomic, strong, readonly) UIBezierPath *playBezierPath;
@property (nonatomic, strong, readonly) UIBezierPath *playRotateBezierPath;
@end
@implementation RSPlayPauseButton
#pragma mark - Accessors
#pragma mark Public
- (void)setPaused:(BOOL)paused
{
if (_paused != paused) {
[self setPaused:paused animated:NO];
}
}
#pragma mark Private
@synthesize pauseBezierPath = _pauseBezierPath;
- (UIBezierPath *)pauseBezierPath
{
if (!_pauseBezierPath) {
_pauseBezierPath = [UIBezierPath bezierPath];
// Subpath for 1. line
[_pauseBezierPath moveToPoint:p1];
[_pauseBezierPath addLineToPoint:p2];
[_pauseBezierPath addLineToPoint:p3];
[_pauseBezierPath addLineToPoint:p4];
[_pauseBezierPath closePath];
// Subpath for 2. line
[_pauseBezierPath moveToPoint:p5];
[_pauseBezierPath addLineToPoint:p6];
[_pauseBezierPath addLineToPoint:p7];
[_pauseBezierPath addLineToPoint:p8];
[_pauseBezierPath closePath];
}
return _pauseBezierPath;
}
@synthesize pauseRotateBezierPath = _pauseRotateBezierPath;
- (UIBezierPath *)pauseRotateBezierPath
{
if (!_pauseRotateBezierPath) {
_pauseRotateBezierPath = [UIBezierPath bezierPath];
// Subpath for 1. line
[_pauseRotateBezierPath moveToPoint:p7];
[_pauseRotateBezierPath addLineToPoint:p8];
[_pauseRotateBezierPath addLineToPoint:p5];
[_pauseRotateBezierPath addLineToPoint:p6];
[_pauseRotateBezierPath closePath];
// Subpath for 2. line
[_pauseRotateBezierPath moveToPoint:p3];
[_pauseRotateBezierPath addLineToPoint:p4];
[_pauseRotateBezierPath addLineToPoint:p1];
[_pauseRotateBezierPath addLineToPoint:p2];
[_pauseRotateBezierPath closePath];
}
return _pauseRotateBezierPath;
}
@synthesize playBezierPath = _playBezierPath;
- (UIBezierPath *)playBezierPath
{
if (!_playBezierPath) {
_playBezierPath = [UIBezierPath bezierPath];
const CGFloat kPauseLinesHalfSpace = floor(kPauseLinesSpace / 2);
const CGFloat kPauseLineHalfHeight = floor(kPauseLineHeight / 2);
CGPoint _p1 = CGPointMake(p1.x + kPlayTriangleOffsetX, p1.y);
CGPoint _p2 = CGPointMake(p2.x + kPauseLinesHalfSpace, p2.y);
CGPoint _p3 = CGPointMake(p3.x + kPauseLinesHalfSpace, p3.y);
CGPoint _p4 = CGPointMake(p4.x + kPlayTriangleOffsetX, p4.y);
CGPoint _p5 = CGPointMake(p5.x - kPauseLinesHalfSpace, p5.y);
CGPoint _p6 = CGPointMake(p6.x + kPlayTriangleTipOffsetX, p6.y);
CGPoint _p7 = CGPointMake(p7.x + kPlayTriangleTipOffsetX, p7.y);
CGPoint _p8 = CGPointMake(p8.x - kPauseLinesHalfSpace, p8.y);
const CGFloat kPlayTriangleWidth = _p6.x - _p1.x;
_p2.y += kPauseLineHalfHeight * (_p2.x - kPlayTriangleOffsetX) / kPlayTriangleWidth;
_p3.y -= kPauseLineHalfHeight * (_p3.x - kPlayTriangleOffsetX) / kPlayTriangleWidth;
_p5.y += kPauseLineHalfHeight * (_p5.x - kPlayTriangleOffsetX) / kPlayTriangleWidth;
_p6.y = kPauseLineHalfHeight;
_p7.y = kPauseLineHalfHeight;
_p8.y -= kPauseLineHalfHeight * (_p8.x - kPlayTriangleOffsetX) / kPlayTriangleWidth;
[_playBezierPath moveToPoint:_p1];
[_playBezierPath addLineToPoint:_p2];
[_playBezierPath addLineToPoint:_p3];
[_playBezierPath addLineToPoint:_p4];
[_playBezierPath closePath];
[_playBezierPath moveToPoint:_p5];
[_playBezierPath addLineToPoint:_p6];
[_playBezierPath addLineToPoint:_p7];
[_playBezierPath addLineToPoint:_p8];
[_playBezierPath closePath];
}
return _playBezierPath;
}
@synthesize playRotateBezierPath = _playRotateBezierPath;
- (UIBezierPath *)playRotateBezierPath
{
if (!_playRotateBezierPath) {
_playRotateBezierPath = [UIBezierPath bezierPath];
const CGFloat kPauseLineHalfHeight = floor(kPauseLineHeight / 2);
CGPoint _p1, _p2, _p3, _p4, _p5, _p6, _p7, _p8;
_p1 = _p2 = _p5 = _p6 = CGPointMake(p6.x + kPlayTriangleTipOffsetX, kPauseLineHalfHeight);
_p3 = _p8 = CGPointMake(p1.x + kPlayTriangleOffsetX, kPauseLineHalfHeight);
_p4 = CGPointMake(p1.x + kPlayTriangleOffsetX, p1.y);
_p7 = CGPointMake(p4.x + kPlayTriangleOffsetX, p4.y);
[_playRotateBezierPath moveToPoint:_p1];
[_playRotateBezierPath addLineToPoint:_p2];
[_playRotateBezierPath addLineToPoint:_p3];
[_playRotateBezierPath addLineToPoint:_p4];
[_playRotateBezierPath closePath];
[_playRotateBezierPath moveToPoint:_p5];
[_playRotateBezierPath addLineToPoint:_p6];
[_playRotateBezierPath addLineToPoint:_p7];
[_playRotateBezierPath addLineToPoint:_p8];
[_playRotateBezierPath closePath];
}
return _playRotateBezierPath;
}
#pragma mark - Life Cycle
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
_paused = YES;
[self sizeToFit];
}
return self;
}
#pragma mark - UIView Method Overrides
#pragma mark Configuring a View's Visual Appearance
- (void)tintColorDidChange
{
// Refresh view rendering when system calls this method with a changed tint color.
[self setNeedsLayout];
}
#pragma mark Configuring the Resizing Behavior
- (CGSize)sizeThatFits:(CGSize)size
{
// Ignore the current size/new size by super and instead use our default size.
return CGSizeMake(kSize, kSize);
}
#pragma mark Laying out Subviews
- (void)layoutSubviews
{
[super layoutSubviews];
if (!self.playPauseShapeLayer) {
self.playPauseShapeLayer = [[CAShapeLayer alloc] init];
CGRect playPauseRect = CGRectZero;
playPauseRect.origin.x = floor(((self.bounds.size.width) - (kPauseLineWidth + kPauseLinesSpace + kPauseLineWidth)) / 2);
playPauseRect.origin.y = floor(((self.bounds.size.height) - (kPauseLineHeight)) / 2);
playPauseRect.size.width = kPauseLineWidth + kPauseLinesSpace + kPauseLineWidth + kPlayTriangleTipOffsetX;
playPauseRect.size.height = kPauseLineHeight;
self.playPauseShapeLayer.frame = playPauseRect;
UIBezierPath *path = self.isPaused ? self.playRotateBezierPath : self.pauseBezierPath;
self.playPauseShapeLayer.path = path.CGPath;
[self.layer addSublayer:self.playPauseShapeLayer];
}
self.playPauseShapeLayer.fillColor = self.tintColor.CGColor;
}
#pragma mark - Public Methods
- (void)setPaused:(BOOL)paused animated:(BOOL)animated
{
if (_paused != paused) {
_paused = paused;
UIBezierPath *fromPath = nil;
UIBezierPath *toPath = nil;
if (self.animationStyle == RSPlayPauseButtonAnimationStyleSplit) {
fromPath = self.isPaused ? self.pauseBezierPath : self.playBezierPath;
toPath = self.isPaused ? self.playBezierPath : self.pauseBezierPath;
} else if (self.animationStyle == RSPlayPauseButtonAnimationStyleSplitAndRotate) {
fromPath = self.isPaused ? self.pauseBezierPath : self.playRotateBezierPath;
toPath = self.isPaused ? self.playRotateBezierPath : self.pauseRotateBezierPath;
} else {
// Unsupported animation style -- fall back to using default animation style's "to path" but don't animate to it.
toPath = self.isPaused ? self.playBezierPath : self.pauseBezierPath;
animated = NO;
}
NSString * const kMorphAnimationKey = @"morphAnimationKey";
if (animated) {
// Morph between the two states.
CABasicAnimation *morphAnimation = [CABasicAnimation animationWithKeyPath:@"path"];
CAMediaTimingFunction *timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
[morphAnimation setTimingFunction:timingFunction];
// Make the new state stick.
[morphAnimation setRemovedOnCompletion:NO];
[morphAnimation setFillMode:kCAFillModeForwards];
morphAnimation.duration = 0.3;
morphAnimation.fromValue = (__bridge id)fromPath.CGPath;
morphAnimation.toValue = (__bridge id)toPath.CGPath;
[self.playPauseShapeLayer addAnimation:morphAnimation forKey:kMorphAnimationKey];
} else {
// Clear out potential existing morph animations.
[self.playPauseShapeLayer removeAnimationForKey:kMorphAnimationKey];
// Snap to new state.
self.playPauseShapeLayer.path = toPath.CGPath;
}
}
}
@end
////////------ End External ------//////
@interface WCLocation : NSObject
@property CLLocationCoordinate2D coordinate;
@property CLLocationDistance altitude;
@property (nonatomic, strong) CLFloor *floor;
@property CLLocationAccuracy horizontalAccuracy;
@property CLLocationAccuracy verticalAccuracy;
@property (nonatomic, strong) NSDate *timestamp;
@property CLLocationSpeed speed;
@property CLLocationDirection course;
-(id)copyWithZone:(NSZone *) zone;
@end
@implementation WCLocation
-(id)copyWithZone:(NSZone *) zone
{
WCLocation *copy = [WCLocation new];
copy.coordinate = self.coordinate;
copy.altitude = self.altitude;
copy.floor = self.floor;
copy.horizontalAccuracy = self.horizontalAccuracy;
copy.verticalAccuracy = self.verticalAccuracy;
copy.timestamp = self.timestamp;
copy.speed = self.speed;
copy.course = self.course;
return copy;
}
@end
// Globals
bool locChanged;
WCLocation *goLoc;
CLLocationManager *locationManager; //Need to change the location of the manager
bool walkingMode;
CGPoint walkingVec;
bool patrolMode;
bool patrolPaused;
WCLocation *baseLocation;
//
%hook UnityView
@interface UnityView <UIAlertViewDelegate>
- (NSArray *)subviews;
- (void)addSubview:(UIView *)subview;
- (void)setNeedsLayout;
- (void)layoutIfNeeded;
- (bool)processTouches:(NSSet *)touches;
- (void)toggleWalk;
- (void)togglePatrol;
@end
UIButton *speedButton;
UIButton *walkButton;
UIButton *patrolButton;
UIButton *hideUIButton;
UILabel *speedLabel;
UILabel *walkLabel;
UILabel *patrolLabel;
RSPlayPauseButton *patrolPlayPauseButton;
int speed = 1;
bool hideUI = false;
bool locationLoopStarted;
%new
- (void)incrementSpeed
{
switch (speed) {
case 1:
speed = 2;
[speedButton setTitle:@"2x" forState:UIControlStateNormal];
break;
case 2:
speed = 4;
[speedButton setTitle:@"4x" forState:UIControlStateNormal];
break;
case 4:
[speedButton setTitle:@"1x" forState:UIControlStateNormal];
speed = 1;
break;
default:
break;
}
}
%new
- (void)toggleWalk
{
walkingMode = !walkingMode;
if (walkingMode) {
if (patrolMode)
[self togglePatrol];
walkButton.backgroundColor = [UIColor redColor];
} else {
walkButton.backgroundColor = [UIColor whiteColor];
}
}
%new
- (void)togglePatrol
{
patrolMode = !patrolMode;
if (patrolMode) {
if (walkingMode)
[self toggleWalk];
patrolButton.backgroundColor = [UIColor greenColor];
baseLocation = [goLoc copy];
[UIView animateWithDuration:0.2 animations:^{
patrolPlayPauseButton.frame = CGRectOffset(patrolPlayPauseButton.frame, 50, 0);
}];
} else {
patrolPaused = false;
[patrolPlayPauseButton setPaused:NO animated:YES];
patrolButton.backgroundColor = [UIColor whiteColor];
[UIView animateWithDuration:0.2 animations:^{
patrolPlayPauseButton.frame = CGRectOffset(patrolPlayPauseButton.frame, -50, 0);
}];
}
}
%new
- (void)togglePatrolPause
{
patrolPaused = !patrolPaused;
[patrolPlayPauseButton setPaused:patrolPaused animated:YES];
}
%new
- (void)toggleHideUI
{
hideUI = !hideUI;
[self setNeedsLayout];
[self layoutIfNeeded];
}
- (void)layoutSubviews
{
%orig;
if (!speedButton) {
speedButton = [[UIButton alloc] initWithFrame:CGRectMake(13, 250, 40, 40)];
speedButton.backgroundColor = [UIColor whiteColor];
speedButton.layer.cornerRadius = speedButton.frame.size.width/2;
speedButton.clipsToBounds = YES;
[speedButton setTitle:@"1x" forState:UIControlStateNormal];
[speedButton setTitleColor:[UIColor colorWithRed:36/255.0 green:71/255.0 blue:113/255.0 alpha:1.0] forState:UIControlStateNormal];
[speedButton addTarget:self action:@selector(incrementSpeed) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:speedButton];
speedLabel = [[UILabel alloc] initWithFrame:CGRectMake(3, 290, 60, 14)];
speedLabel.textAlignment = NSTextAlignmentCenter;
speedLabel.text = @"Speed";
speedLabel.textColor = [UIColor whiteColor];
speedLabel.font = [UIFont systemFontOfSize:10];
speedLabel.layer.cornerRadius = 7.f;
speedLabel.backgroundColor = [UIColor colorWithWhite:40/255.0 alpha:0.17];
speedLabel.clipsToBounds = YES;
[self addSubview:speedLabel];
walkButton = [[UIButton alloc] initWithFrame:CGRectMake(13, 320, 40, 40)];
walkButton.backgroundColor = [UIColor whiteColor];
walkButton.layer.borderColor = [UIColor whiteColor].CGColor;
walkButton.layer.borderWidth = 3.0f;
walkButton.layer.cornerRadius = speedButton.frame.size.width/2;
walkButton.clipsToBounds = YES;
[walkButton addTarget:self action:@selector(toggleWalk) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:walkButton];
walkLabel = [[UILabel alloc] initWithFrame:CGRectMake(3, 360, 60, 14)];
walkLabel.textAlignment = NSTextAlignmentCenter;
walkLabel.text = @"Tap To Walk";
walkLabel.textColor = [UIColor whiteColor];
walkLabel.font = [UIFont systemFontOfSize:10];
walkLabel.layer.cornerRadius = 7.f;
walkLabel.backgroundColor = [UIColor colorWithWhite:40/255.0 alpha:0.17];
walkLabel.clipsToBounds = YES;
[self addSubview:walkLabel];
patrolButton = [[UIButton alloc] initWithFrame:CGRectMake(13, 390, 40, 40)];
patrolButton.backgroundColor = [UIColor whiteColor];
patrolButton.layer.borderColor = [UIColor whiteColor].CGColor;
patrolButton.layer.borderWidth = 3.0f;
patrolButton.layer.cornerRadius = speedButton.frame.size.width/2;
patrolButton.clipsToBounds = YES;
[patrolButton addTarget:self action:@selector(togglePatrol) forControlEvents:UIControlEventTouchUpInside];
patrolLabel = [[UILabel alloc] initWithFrame:CGRectMake(3, 430, 60, 14)];
patrolLabel.textAlignment = NSTextAlignmentCenter;
patrolLabel.text = @"Patrol";
patrolLabel.textColor = [UIColor whiteColor];
patrolLabel.font = [UIFont systemFontOfSize:10];
patrolLabel.layer.cornerRadius = 7.f;
patrolLabel.backgroundColor = [UIColor colorWithWhite:40/255.0 alpha:0.17];
patrolLabel.clipsToBounds = YES;
[self addSubview:patrolLabel];
patrolPlayPauseButton = [[RSPlayPauseButton alloc] initWithFrame:CGRectMake(15, 393, 40, 40)];
[patrolPlayPauseButton setPaused:NO animated:NO];
patrolPlayPauseButton.tintColor = [UIColor greenColor];
patrolPlayPauseButton.backgroundColor = [UIColor whiteColor];
patrolPlayPauseButton.layer.cornerRadius = patrolPlayPauseButton.frame.size.width/2;
patrolPlayPauseButton.animationStyle = RSPlayPauseButtonAnimationStyleSplitAndRotate;
[patrolPlayPauseButton addTarget:self action:@selector(togglePatrolPause) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:patrolPlayPauseButton];
[self addSubview:patrolButton];
hideUIButton = [[UIButton alloc] initWithFrame:CGRectMake(15, 25, 34, 34)];
hideUIButton.backgroundColor = [UIColor whiteColor];
hideUIButton.layer.cornerRadius = hideUIButton.frame.size.width/2;
[hideUIButton addTarget:self action:@selector(toggleHideUI) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:hideUIButton];
NSInteger alertNum = [[NSUserDefaults standardUserDefaults] integerForKey:@"PokemonGoAlert"];
alertNum++;
[[NSUserDefaults standardUserDefaults] setInteger:alertNum forKey:@"PokemonGoAlert"];
if (alertNum == 7) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Enjoying PokemonGoAnywhere?"
message:@"Consider buying a beer for the developer."
delegate:self
cancelButtonTitle:nil
otherButtonTitles:@"Donate", @"No Thanks", nil];
[alert show];
}
}
[UIView animateWithDuration:0.3 animations:^{
hideUIButton.backgroundColor = hideUI ? [UIColor clearColor] : [UIColor colorWithWhite:1.0 alpha:0.85];
speedButton.alpha = !hideUI;
walkButton.alpha = !hideUI;
patrolButton.alpha = !hideUI;
patrolPlayPauseButton.alpha = !hideUI;
speedLabel.alpha = !hideUI;
walkLabel.alpha = !hideUI;
patrolLabel.alpha = !hideUI;
}];
}
%new
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0)
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=williamlewiscobb%40gmail%2ecom&lc=US&item_name=PokemonGoAnywhere¤cy_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted"]];
}
else if (buttonIndex == 1)
{
[alertView dismissWithClickedButtonIndex:1 animated:TRUE];
}
}
// Return true means call orig
%new
- (bool)processTouches:(NSSet<UITouch *> *)touches
{
if (hideUI) {
return true;
}
if (!goLoc) {
return true;
} else if (!locationManager) {
return true;
} else {
UITouch *touch = [touches anyObject];
if (/*touch.force < 1.5 &&*/ !walkingMode) { //Force too low
return true;
}
UIView *touchedView = touch.view;
CGPoint touchLocation = [touch locationInView:touchedView];
// Get touch vector
CGPoint centerLoc = CGPointMake([UIScreen mainScreen].bounds.size.width / 2, [UIScreen mainScreen].bounds.size.height / 1.4);
//CGPoint centerLoc = CGPointMake(185, 485);
walkingVec = CGPointMake(touchLocation.x - centerLoc.x, touchLocation.y - centerLoc.y);
//
// CGFloat heading = 0;
// if (walkingVec.y > 0 && walkingVec.x > 0) {
// heading = arc4random_uniform(90)
// }
// // = tan(walkingVec.x / walkingVec.y);
// NSLog(@"HEading: %f", heading);
//
// dot = walkingVec.y # dot product
// det = walkingVec.x # determinant
// angle = atan2(det, dot) # atan2(y, x) or atan2(sin, cos)
locChanged = true;
return false;
}
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
if([self processTouches:touches]) {
%orig;
}
}
- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
if([self processTouches:touches]) {
%orig;
}
}
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
%orig;
locChanged = false;
// UITouch *touch = [touches anyObject];
// UIView *touchedView = touch.view;
// CGPoint touchLocation = [touch locationInView:touchedView];
// NSLog(@"%f %f", touchLocation.x, touchLocation.y);
// if (touchLocation.x < 20 && touchLocation.y < 20) {
// hideUI = !hideUI;
// [self setNeedsLayout];
// [self layoutIfNeeded];
// NSLog(@"Toggling UI");
// }
}
%end
%hook NIAIosLocationManager
@interface NIAIosLocationManager
- (void)startLocationLoop;
@end
%new
- (void)startLocationLoop
{
if (locationLoopStarted)
return;
locationLoopStarted = true;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
CFTimeInterval patrolTime = 0;
CFTimeInterval lastLoopTime;
while (true) {
CGFloat sleepTime = 0.1;
if (locChanged) { // Set from walking mode
NSLog(@"Updating location");
// Normalize
CGFloat length = sqrt(walkingVec.x * walkingVec.x + walkingVec.y * walkingVec.y) * (5500 + arc4random_uniform(1000));
walkingVec = CGPointMake(walkingVec.x / length, walkingVec.y / length);
goLoc.coordinate = CLLocationCoordinate2DMake(goLoc.coordinate.latitude - (walkingVec.y * speed),
goLoc.coordinate.longitude + (walkingVec.x * speed));
//locationManager.location = goLoc;
[[locationManager delegate] locationManager:locationManager didUpdateLocations:@[]];
NSLog(@"LMD: %@", [locationManager delegate]);
locChanged = false;
sleepTime = 0.8 + (arc4random_uniform(100) / 400.0);
} else if (patrolMode && !patrolPaused) {
patrolTime += CACurrentMediaTime() - lastLoopTime;
goLoc.coordinate = CLLocationCoordinate2DMake(baseLocation.coordinate.latitude - (sin(patrolTime * 0.03 * speed) * 0.001),
baseLocation.coordinate.longitude + (cos(patrolTime * 0.03 * speed) * 0.001));
//locationManager.location = goLoc;
[[locationManager delegate] locationManager:locationManager didUpdateLocations:@[]];
sleepTime = 0.8 + (arc4random_uniform(100) / 400.0);
}
lastLoopTime = CACurrentMediaTime();
[NSThread sleepForTimeInterval:sleepTime];
}
});
}
CGFloat baseHorizontalAccuracy;
CGFloat baseverticalAccuracy;
CGFloat randomizeValue(CGFloat value)
{
return value - (value / 8) + arc4random_uniform(value/4);
}
NSDate *currentTimestamp()
{
return [NSDate date];
}
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
CLLocation *loc = [locations lastObject];
if (hideUI) {
%orig;
goLoc.coordinate = loc.coordinate;
goLoc.altitude = loc.altitude;
goLoc.floor = loc.floor;
return;
}
if (loc) { //We got a real location
baseHorizontalAccuracy = loc.horizontalAccuracy;
baseverticalAccuracy = loc.verticalAccuracy;
goLoc.course = loc.course;
//Fuzz it a little bit so it's not always the same
goLoc.coordinate = CLLocationCoordinate2DMake(goLoc.coordinate.latitude - .00005 + ((arc4random_uniform(300) / 100) * .00005),
goLoc.coordinate.longitude - .00005 + ((arc4random_uniform(300) / 100) * .00005));
}
if (!goLoc && loc.horizontalAccuracy < 500) {
NSLog(@"Creating Goloc");
goLoc = [WCLocation new];
goLoc.coordinate = loc.coordinate;
goLoc.altitude = loc.altitude;
goLoc.floor = loc.floor;
locationManager = manager;
[self startLocationLoop];
}
if (goLoc) {
goLoc.horizontalAccuracy = randomizeValue(baseHorizontalAccuracy);
goLoc.verticalAccuracy = randomizeValue(baseverticalAccuracy);
goLoc.timestamp = currentTimestamp();
goLoc.speed = randomizeValue(speed * 20);
//goLoc.course = loc.course;
NSArray *locs = @[goLoc];
%orig(manager, locs);
} else {
%orig;
}
}
%end
%hook USActionMap
-(id)init
{
id map = %orig;
NSLog(@"Init Map: %@", map);
return map;
}
%end
%hook USExecuteTriggerTask
-(id)map
{
id m = %orig;
NSLog(@"USExecuteTriggerTask Map: %@", m);
return m;
}
%end
%hook USBaseAction
-(id)map
{
id m = %orig;
NSLog(@"USBaseAction Map: %@", m);
return m;
}
%end
%hook USActionMapManager
-(id)actionMaps
{
id m = %orig;
NSLog(@"USActionMapManager Map: %@", m);
return m;
}
%end