-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSam.sh
More file actions
executable file
·128 lines (110 loc) · 2.79 KB
/
Sam.sh
File metadata and controls
executable file
·128 lines (110 loc) · 2.79 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
#!/bin/bash
# used commands
round=0
PhoneIp=192.168.1.40:35093
GameScript="$1"
echo "Running $GameScript"
PAUSE_FILE="/tmp/script_paused"
rm "$PAUSE_FILE"
install_adb() {
if command -v adb >/dev/null 2>&1; then
echo "✔ adb installed"
return
fi
echo "❌ adb missing, Installing..."
if command -v apt >/dev/null 2>&1; then
sudo apt update
sudo apt install -y android-tools-adb
elif command -v dnf >/dev/null 2>&1; then
sudo dnf install -y android-tools
elif command -v pacman >/dev/null 2>&1; then
sudo pacman -Sy --noconfirm android-tools
else
echo "⚠️ can't install ADB"
echo "Proceed manually"
exit 1
fi
}
click_if_visible() {
POS=$(wait_for_any_image \
gems.png \
next_wave.png \
upgrade_damage.png \
upgrade_health.png)
if [ $? -eq 0 ]; then
X=$(echo "$POS" | cut -d',' -f1)
Y=$(echo "$POS" | cut -d',' -f2)
adb shell input tap $X $Y
sleep 0.5
return 0
fi
return 1
}
wait_for_any_image() {
take_screenshot
python3 vision_click.py "$@"
}
take_screenshot()
{
adb -s $PhoneIp shell screencap -p /sdcard/screenshot.png
adb -s $PhoneIp pull /sdcard/screenshot.png /tmp/screenshot.png
adb -s $PhoneIp shell rm /sdcard/screenshot.png
}
swipe()
{
#adb -s RFCT11CPCMF shell input swipe <start_x> <start_y> <end_x> <end_y> duration_ms>
echo $1 $2
adb -s $PhoneIp shell input swipe $1 $2 $3 $4 $5
}
#### check if ADB is running
SERVICE="adb"
if pgrep -x "$SERVICE" >/dev/null
then
echo "$SERVICE is running"
else
echo "$SERVICE stopped"
adb start
fi
LINE=$(adb shell wm size)
echo "test $LINE"
SIZE=${LINE#*: }
WIDTH=${SIZE%x*}
HEIGHT=${SIZE#*x}
HCENTER=WIDTH/2
VCENTER=HEIGHT/2
PAUSE=0
echo "WIDTH=$WIDTH HEIGHT=$HEIGHT"
echo "Press 'p' to toggle pause/resume"
adb -s $PhoneIp shell settings put system show_touches 1
adb -s $PhoneIp shell settings put system screen_brightness 1
while true; do
read -t 0.1 -rsn1 key
if [[ $key == "p" ]]; then
if [ -f "$PAUSE_FILE" ]; then
rm "$PAUSE_FILE"
clear
echo "▶ Reprise"
else
touch "$PAUSE_FILE"
clear
cols=$(tput cols)
rows=$(tput lines)
message="PAUSE"
padding=$(( (cols - ${#message}) / 2 ))
tput cup $((rows / 2)) 0
printf "%*s%s\n" $padding "" "$message"
fi
fi
while [ -f "$PAUSE_FILE" ]; do
sleep 0.2
read -t 0.1 -rsn1 key
if [[ $key == "p" ]]; then
rm "$PAUSE_FILE"
clear
echo "▶ Reprise"
break
fi
done
source $GameScript
((round++))
done