#!/bin/bash

# 需ROOT权限
[ "$(id -u)" != 0 ] && echo "请使用ROOT权限执行 !" && exit 1

# 禁止在压缩包内执行
[[ "${0%/*}" == *bin.mt.plus/temp* ]] && echo "请勿在压缩包内直接执行！" && exit 1

TMP_DIR="/data/local/tmp"
INJECTOR="inject"
SO="libWn.so"
GAME="com.tencent.tmgp.pubgmhd"

# 游戏启动命令（如需启动）
# am start "$GAME/com.epicgames.ue4.SplashActivity"

SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"

if [[ "$SCRIPT_DIR" != "$TMP_DIR" ]] || [[ ! -f "$TMP_DIR/$INJECTOR" ]] || [[ ! -f "$TMP_DIR/$SO" ]]; then
    for FILE in "$SO" "$INJECTOR"; do
        DEST="$TMP_DIR/$FILE"
        rm -f "$DEST"
        cp "$FILE" "$DEST"
        chmod 777 "$DEST"
    done
else
    chmod 777 "$TMP_DIR/$INJECTOR" "$TMP_DIR/$SO"
fi

"$TMP_DIR/$INJECTOR" -p "$GAME"
