-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tweak.xm
103 lines (94 loc) · 1.9 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
#import "AI.h"
@interface ViewController : UIViewController
-(void)makeMove:(NSInteger)move;
-(void)upSwipeHandle:(id)handle;
-(void)downSwipeHandle:(id)handle;
-(void)leftSwipeHandle:(id)handle;
-(void)rightSwipeHandle:(id)handle;
@end
NSInteger codeCount;
BOOL AIEnabled;
BOOL gameOver;
%hook ViewController
%new
-(void)initializeAI{
AIEnabled = YES;
[[%c(UIApplication) sharedApplication] setIdleTimerDisabled:YES];
while(! gameOver){
NSMutableArray* array = MSHookIvar<NSMutableArray*>(self, "theCubeTab");
int move = [AI bestMoveForArray:array];
dispatch_sync(dispatch_get_main_queue(), ^{
[self makeMove:move];
});
}
}
%new
-(void)makeMove:(NSInteger)move{
switch (move){
case 0:
[self upSwipeHandle:nil];
break;
case 1:
[self downSwipeHandle:nil];
break;
case 2:
[self leftSwipeHandle:nil];
break;
case 3:
[self rightSwipeHandle:nil];
break;
default:
break;
}
}
-(void)rightSwipeHandle:(id)handle{
%orig;
if(! AIEnabled){
if(codeCount == 5 || codeCount == 7) codeCount++;
else codeCount =0;
if(codeCount == 8){
[NSThread detachNewThreadSelector:@selector(initializeAI) toTarget:self withObject:nil];
}
}
}
-(void)leftSwipeHandle:(id)handle{
%orig;
if(! AIEnabled){
if(codeCount == 4 || codeCount==6) codeCount++;
else codeCount = 0;
}
}
-(void)downSwipeHandle:(id)handle{
%orig;
if(! AIEnabled){
if(codeCount>1 && codeCount <4) codeCount++;
else codeCount = 0;
}
}
-(void)upSwipeHandle:(id)handle{
%orig;
if(! AIEnabled){
if(codeCount < 2) codeCount++;
else codeCount = 0;
}
}
-(void)gameOver:(id)over{
%orig;
gameOver = YES;
}
-(void)tryAgain:(id)again{
%orig;
if(AIEnabled){
[NSThread detachNewThreadSelector:@selector(initializeAI) toTarget:self withObject:nil];
}
}
-(void)startGame{
%orig;
AIEnabled = NO;
codeCount = 0;
gameOver = NO;
}
%end
%ctor{
%init;
}