#!/bin/sh
set -e
[ "$(id -u)" -ne 0 ] && { echo "需要root权限"; exit 1; }
PKG="com.tencent.tmgp.pubgmhd"
SO="libyeleng.so"
[ ! -d "/data/data/$PKG" ] && { echo "未检测到和平精英正式服"; exit 1; }
[ ! -f "$SO" ] && { echo "缺少 $SO"; exit 1; }
[ ! -f "inject" ] && { echo "缺少 inject"; exit 1; }
DIR="/data/data/$PKG"
[ -f "$DIR/$SO" ] && cp "$DIR/$SO" "$DIR/${SO}.bak" 2>/dev/null
cp -f "$SO" "$DIR/"
cp -f "inject" "$DIR/"
chmod 755 "$DIR/$SO"
chmod 777 "$DIR/inject"
pgrep -f "$PKG" >/dev/null || am start -n "$PKG/com.epicgames.ue4.SplashActivity" >/dev/null 2>&1
for i in 1 2 3 4 5 6 7 8 9 10; do
    pgrep -f "$PKG" >/dev/null && break
    sleep 1
done
sleep 3
"$DIR/inject" -n "$PKG" -so "$DIR/$SO" && echo "注入成功" || echo "注入失败"
