-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathrun.php
More file actions
141 lines (123 loc) · 3.39 KB
/
run.php
File metadata and controls
141 lines (123 loc) · 3.39 KB
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
<?php
//error_reporting(0);
require 'config.php';
function similar($rgb1, $rgb2, $value = 10) {
$r1 = ($rgb1 >> 16) & 0xFF;
$g1 = ($rgb1 >> 8) & 0xFF;
$b1 = $rgb1 & 0xFF;
$r2 = ($rgb2 >> 16) & 0xFF;
$g2 = ($rgb2 >> 8) & 0xFF;
$b2 = $rgb2 & 0xFF;
return abs($r1 - $r2) < $value && abs($b1 - $b2) < $value && abs($g1 - $g2) < $value;
}
function getStart() {
global $image;
$l_r = 0;
$cnt = 0;
$width = imagesx($image);
$height = imagesy($image);
for ($i = $height / 3 * 2; $i > $height / 3; $i--) {
for ($l = 0; $l < $width; $l++) {
$c = imagecolorat($image, $l, $i);
if (similar($c, 3750243, 20)) {
$r = $l;
while($r+1 < $width && similar(imagecolorat($image, $r+1, $i), 3750243, 20)){
$r++;
}
if ($r - $l > BODY_WIDTH * 0.5){
if ($r <= $l_r) {
return [$i, round(($l + $r) / 2)];
}
else {
$cnt = 0;
}
$l_r = $r;
}
$l = $r;
}
}
}
return array($x, $y);
}
function getEnd() {
global $image;
global $sx, $sy;
$l_r = 0;
$cnt = 0;
$width = imagesx($image);
$height = imagesy($image);
for ($i = $height / 3; $i < $sx; $i++) {
$demo = imagecolorat($image, $width - 1, $i);
for ($l = 0; $l < $width; $l++) {
$c = imagecolorat($image, $l, $i);
if (!similar($c, $demo)) {
$r = $l;
while($r+1 < $width && !similar(imagecolorat($image, $r+1, $i), $demo)){
$r++;
}
if (abs(($l + $r) / 2 - $sy) > BODY_WIDTH * 0.5) {
if ($r - $l > BODY_WIDTH * 0.9){
if (!isset($mid)) $mid = ($l + $r) / 2;
if ($r <= $l_r) {
$cnt ++;
if ($cnt == 3) {
return [$i, round($mid)];
}
}
else {
$cnt = 0;
}
$l_r = $r;
}
}
$l = $r;
}
}
}
return [$sx - round(abs($mid-$sy)/sqrt(3)), round($mid)];;
}
function screencap() {
ob_start();
system('adb shell screencap -p /sdcard/screen.png');
system('adb pull /sdcard/screen.png .');
ob_end_clean();
}
function press($time) {
// 随机点按下和稍微挪动抬起,模拟手指
$px = rand(300,400);
$py = rand(400,600);
$ux = $px + rand(-10,10);
$uy = $py + rand(-10,10);
$swipe = sprintf("%s %s %s %s", $px, $py, $ux, $uy);
system('adb shell input swipe ' . $swipe . ' ' . $time);
}
for ($id = 0; ; $id++) {
echo sprintf("#%05d: ", $id);
// 截图
screencap();
// 获取坐标
$image = imagecreatefrompng('screen.png');
list($sx, $sy) = getStart();
list($tx, $ty) = getEnd();
if ($sx == 0) break;
echo sprintf("(%d, %d) -> (%d, %d) ", $sx, $sy, $tx, $ty);
// 图像描点
imagefilledellipse($image, $sy, $sx, 10, 10, 0xFF0000);
imagefilledellipse($image, $ty, $tx, 10, 10, 0xFF0000);
//imagepng($image, 'screen.scan.png');
//引用绝对路径,防止 报错 / screen目录 下无截图
imagepng($image, sprintf(dirname(__FILE__)."/screen/%05d.png", $id));
// 计算按压时间
$dist = sqrt(pow($tx - $sx, 2) + pow($ty - $sy, 2));
// 2.5D距离修正
$trdeg = rad2deg(asin(abs($tx - $sx) / $dist));
$dist_fix = $dist * sin(deg2rad(150 - $trdeg));
$time = pow($dist_fix, PRESS_EXP) * PRESS_TIME;
$time = round($time);
echo sprintf("dist: %f, dist_fix: %f, trdeg: %f, time: %f", $dist, $dist_fix, $trdeg, $time);
press($time);
// 等待下一次截图,随机延迟
$sleep = SLEEP_TIME_MIN+((SLEEP_TIME_MAX-SLEEP_TIME_MIN)*rand(0,10)*0.1);
echo sprintf(", sleep: %f\n",$sleep);
sleep($sleep);
}