#!/system/bin/sh

DIR="$(cd "$(dirname "$0")" && pwd)"
INJECTOR="$DIR/AndKittyInjector"
LIB="$DIR/libpubgm.so"

[ ! -f "$INJECTOR" ] && { echo "错误: 未找到 AndKittyInjector"; exit 1; }
[ ! -f "$LIB" ] && { echo "错误: 未找到 libpubgm.so"; exit 1; }

chmod +x "$INJECTOR"

echo "目录: $DIR"
echo ""
echo "选择游戏:"
echo "1. com.tencent.ig"
echo "2. com.vng.pubgmobile"
echo "3. com.rekoo.pubgm"
echo "4. com.pubg.krmobile"
echo "5. com.tencent.tmgp.cf"
echo "6. com.proxima.dfm"
printf "输入数字 (1-6): "
read n

case "$n" in
    1) PKG="com.tencent.ig" ;;
    2) PKG="com.vng.pubgmobile" ;;
    3) PKG="com.rekoo.pubgm" ;;
    4) PKG="com.pubg.krmobile" ;;
    5) PKG="com.tencent.tmgp.cf" ;;
    6) PKG="com.proxima.dfm" ;;
    *) echo "错误: 无效选择"; exit 1 ;;
esac

# 根据包名选择注入的 SO 文件
if [ "$PKG" = "com.tencent.tmgp.cf" ]; then
    LIB="$DIR/libFuck.so"
elif [ "$PKG" = "com.proxima.dfm" ]; then
    LIB="$DIR/libGame.so"
else
    LIB="$$DIR/libpubgm.so"
fi

echo ""
echo "包名: $PKG"
echo "注入库: $LIB"
[ ! -f "$LIB" ] && { echo "错误: 未找到 $LIB"; exit 1; }
echo "[1] 启动注入器并等待游戏进程..."
echo "    请手动打开游戏，注入器将自动检测并注入"
echo ""

# 使用 -watch 参数循环检测目标进程，一旦检测到立即注入
$INJECTOR -pkg $PKG -lib $LIB -dl_memfd -hide_maps -hide_solist -watch -delay 50000

if [ $? -eq 0 ]; then
    echo ""
    echo "[OK] 注入成功!"
else
    echo ""
    echo "[失败] 注入出错"
fi