-
Notifications
You must be signed in to change notification settings - Fork 1
/
PGoControl
executable file
·241 lines (219 loc) · 11.2 KB
/
PGoControl
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
#!/usr/bin/env bash
## Author: Emiliano Sauvisky
## Nível de logging (pode ser setado como variavel de ambiente)
LOG_LEVEL="${LOG_LEVEL:-7}"
## Dependências
__deps=( "sed" "grep" "adb" "xclip" )
PGO_DATA='/data/data/com.nianticlabs.pokemongo/'
#############################################################################
####### Funções e configurações (normalmente não é necessário editar) #######
#############################################################################
## Parâmetros posicionais do bash
# set -o errexit # Exit on error. Append "|| true" if you expect an error.
set -o errtrace # Exit on error inside any functions or subshells.
#set -o nounset # Do not allow use of undefined vars. Use ${VAR:-} to use an undefined VAR
#set -o pipefail # Catch the error in case mysqldump fails (but gzip succeeds) in `mysqldump |gzip`
#set -o xtrace # Turn on traces, useful while debugging.
## Variáveis mágicas
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
#__dir="$(cd "$(dirname $(realpath "${BASH_SOURCE[0]}"))" && pwd)" # com resolução de Symlinks
__base=$(basename "${BASH_SOURCE[0]}")
## Funções de Logging
function __log () {
local log_level="${1}"; shift; local color_debug="\x1b[35m"; local color_info="\x1b[32m"; local color_notice="\x1b[34m"; local color_warning="\x1b[33m"; local color_error="\x1b[31m"; local color_critical="\x1b[1;31m"; local color_alert="\x1b[1;33;41m"; local color_emergency="\x1b[1;4;5;33;41m"; local colorvar="color_${log_level}"; local color="${!colorvar:-$color_error}"; local color_reset="\x1b[0m"; local log_line=""
while IFS=$'\n' read -r log_line; do
echo -e "${__base}: ${color}$(printf "[%9s]" ${log_level})${color_reset} $log_line" 1>&2
done <<< "${@:-}"
}
function emergency () { $(__log emergency "${@}") || true; exit 1; }
function alert () { [ "${LOG_LEVEL:-0}" -ge 1 ] && $(__log alert "${@}") || true; exit 1; }
function critical () { [ "${LOG_LEVEL:-0}" -ge 2 ] && $(__log critical "${@}") || true; exit 1; }
function error () { [ "${LOG_LEVEL:-0}" -ge 3 ] && $(__log error "${@}") || true; }
function warning () { [ "${LOG_LEVEL:-0}" -ge 4 ] && $(__log warning "${@}") || true; }
function notice () { [ "${LOG_LEVEL:-0}" -ge 5 ] && $(__log notice "${@}") || true; }
function info () { [ "${LOG_LEVEL:-0}" -ge 6 ] && $(__log info "${@}") || true; }
function debug () { [ "${LOG_LEVEL:-0}" -ge 7 ] && $(__log debug "${@}") || true; }
## Verifica se dependências existem em $PATH
for dep in ${__deps[@]}; do
hash $dep &>/dev/null || emergency "$dep was not found. Please install it and try again.";
done
#############################################################################
####### Argumentos #######
#############################################################################
function usage {
echo -e "Usage: ${__base} [OPTIONS]"
echo -e "\nPretty much everything here requires a rooted device and adb running."
echo -e "\nOptions:"
echo -e " -h, --help \tThis page"
echo -e " -d, --device [ID] \tSelects which device to use (see adb devices)."
echo -e " \t If not passed, all devices are used simultaneously."
echo -e " \t If it's a integer number, uses only the nth device listed."
echo -e " -f, --fetch-clipboard\tSyncs clipboard from device -> to computer."
echo -e " \t Requires Android 7 or higher and clipper installed."
echo -e " -p, --paste-clipboard\tSyncs the clipboard from computer -> to device, while pasting."
echo -e " \t Requires Android 7 or higher and clipper installed."
echo -e " -l, --pointer-location\tToggles pointer-location (tracking) on the device(s)."
echo -e " -t, --auto-teleport \tTeleports all connected devices to any coordinate in your clipboard."
echo -e " -s, --switch \tMakes a backup of the current profile, and switches to a new one."
echo -e " \t Useful for using multiple accounts, as all your data (incl. teams,"
echo -e " \t sound configs, etc) will actually be backed up as well."
echo -e " -b, --backup \tMakes a backup of the current profile."
}
[[ $# -eq 0 ]] && usage
# Obsolete becuase of Niklas implementation
# function backupPoGo {
# if [[ -z $1 && -z $2 ]]; then
# backupTo=/sdcard/PGoBackups/$(date +%s)/
# elif [[ ! -z $1 && ! -z $2 ]]; then
# backupTo=/sdcard/PGoBackups/$1/
# movePreviousBackupTo=/sdcard/PGoBackups/$2/
# if ! $(adb shell test -d $backupTo); then
# info "No alt profile exists. Creating a new one..."
# elif $(adb shell test -d $movePreviousBackupTo); then
# info "ERROR! $movePreviousBackupTo already exists."
# exit
# else
# info "Moving last profile to temporary directory..."
# adb shell mv $backupTo $movePreviousBackupTo
# fi
# else
# critical "Something is wrong. backupPoGo takes 2 or 0 arguments."
# fi
# info "Copying PoGo data to $backupTo..."
# adb shell mkdir -p $backupTo
# adb shell su -c cp -R /data/data/com.nianticlabs.pokemongo/databases $backupTo || true
# adb shell su -c cp -R /data/data/com.nianticlabs.pokemongo/files $backupTo
# adb shell su -c cp -R /data/data/com.nianticlabs.pokemongo/no_backup $backupTo || true
# adb shell su -c cp -R /data/data/com.nianticlabs.pokemongo/shared_prefs $backupTo
# }
# function restorePoGo {
# [[ -z $1 || -z $PGO_DATA ]] && critical "restorePoGo() needs a parameter."
# profileToRestore=/sdcard/PGoBackups/$1/
# if ! adb shell test -d $profileToRestore; then
# critical "Error, something happened and the profile doesn't exist."
# exit
# fi
# info "Restoring last profile..."
# adb shell su -c cp -R $profileToRestore/* $PGO_DATA
# # PGO_ACC=$(adb shell su -c grep 'accountName' $PGO_DATA/shared_prefs/com.nianticlabs.pokemongo.PREFS.xml | sed 's/..*>\(..*\)<..*$/\1/')
# # TMP_ACC=$(adb shell su -c grep 'accountName' /sdcard/PGoBackups/$1/shared_prefs/com.nianticlabs.pokemongo.PREFS.xml | sed 's/..*>\(..*\)<..*$/\1/')
# if adb shell su -c diff -rq $profileToRestore/shared_prefs/ $PGO_DATA/shared_prefs/; then
# if [[ $1 == 'tempProfile' ]]; then
# info "Deleting temporary folders"
# adb shell rm -r $profileToRestore
# fi
# else
# adb shell su -c diff -rq $profileToRestore/shared_prefs/ $PGO_DATA/shared_prefs/ > ./error_log
# critical "Somehow the accounts are different! Log was saved to ./error_log."
# fi
# }
function pasteClipboard {
local_clipboard=$(xclip -selection clipboard -o)
for device in ${devices[@]}; do
echo "Sending $device"
adb -s $device shell am broadcast -a clipper.set -e text \'${local_clipboard}\' && adb -s $device shell input keyevent KEYCODE_PASTE || true &
done
}
## Stuff that deals with --device-id.
## If existent, those args get stripped from the param list for the main loop below.
for (( n = 1; n <= $#; n++ )); do
if [[ ${!n} == '-d' || ${!n} == '--device' ]]; then
let n++
devices_array=($(adb devices | \grep device$ | sed 's/[ \t][ \t]*device.*$//'))
# # echo ${!n}
# if [[ $(adb -s ${!n} get-state 2>/dev/null) =~ 'device' ]]; then
# devices=${!n}
# info "Using device $devices"
# elif [[ ${!n} -le ${#devices_array[@]} ]]; then
# devices=${devices_array[${!n} - 1]}
# info "Using device $devices"
if [[ ${!n} -le ${#devices_array[@]} ]]; then
devices=(${devices_array[${!n} - 1]})
info "Using device $devices"
else
error "You must specify a device!"
exit
fi
else
params+=("${!n}")
devices=($(adb devices | \grep device$ | sed 's/[\t ][\t ]*..*$//'))
fi
done
set -- "${params[@]}"
## The "main loop below"
for (( n = 1; n <= $#; n++ )); do
case "${!n}" in
-h | --help )
usage
exit ;;
-p | --paste-clipboard )
pasteClipboard
exit ;;
-f | --fetch-clipboard)
if [[ ${#devices[@]} -gt 1 ]]; then
info "Select device..."
device=$(zenity --list --title="Multiple devices connected!" --text="Choose which device to grab the clipboard from: " --column "Device ID" ${devices[@]})
else
device=${devices[0]}
fi
info "Getting clipboard from device $device"
adb -s $device shell am broadcast -a clipper.get| tail -n1 | sed "s/..*data=\"\(..*\)\".*/\1/" | xclip -i -r -selection clipboard
;;
-l | --pointer-location )
for device in ${devices[@]}; do
(
status=$(adb -s $device shell content query --uri content://settings/system/pointer_location | sed 's/^..*value=//')
if [[ $status -eq 1 ]]; then
info "Disabling pointer tracking on $device..."
adb -s $device shell content insert --uri content://settings/system --bind name:s:pointer_location --bind value:i:0
else
info "Enabling pointer tracking on $device..."
adb -s $device shell content insert --uri content://settings/system --bind name:s:pointer_location --bind value:i:1
fi
) &
done
exit ;;
-t | --teleport )
let n++
if echo ${!n} | grep -P '^\-*\d+\.\d+,-*\d+\.\d+$'; then
location=${!n}
lat=$(echo ${location} | sed 's/\,..*//')
lon=$(echo ${location} | sed 's/..*\,//')
elif echo ${!n} | grep -P '^\-*\d+\.\d+$'; then
lat=${!n}
let n++
lon=${!n}
location=$lat,$lon
else
let n--
location=$(xclip -o -selection clipboard | sed 's/ //g' | perl -lpe 's/[^-0-9]*(-{0,1}\d+\.\d+ {0,2}, {0,2}-{0,1}\d{0,3}\.\d+).*/$1/')
lat=$(echo ${location} | sed 's/\,..*//')
lon=$(echo ${location} | sed 's/..*\,//')
if ! echo ${location} | grep -P '^\-*\d+\.\d+,-*\d+\.\d+$'; then
echo "ERROR: Doesn't look we have a coordinate."
exit
fi
fi
echo "Location is ${location}"
for device in ${devices[@]}; do
(
echo "Teleporting $device to lat:$lat lon:$lon..."
adb -s $device shell am start-foreground-service -a theappninjas.gpsjoystick.TELEPORT --ef lat $lat --ef lng $lon
) &
done
exit ;;
-s | --switch )
adb shell am force-stop com.nianticlabs.pokemongo
backupPoGo lastProfile tempProfile
restorePoGo tempProfile
adb shell monkey -p com.nianticlabs.pokemongo 1
exit ;;
-b | --backup )
backupPoGo
exit ;;
* )
error "Invalid option ${!n}"
usage
;;
esac
done