#!/system/bin/sh

PACKAGE1="com.hortor.juliancysj"
TARGET_BASE="/data/user/0/${PACKAGE1}/app_flutter"
TMP_FILE="${TARGET_BASE}/swap/cysj2.tmp"

if [ "$(id -u)" -ne 0 ]; then
    echo "警告：需要root权限"
fi

# 杀进程
echo "杀进程 $PACKAGE1"
killall $PACKAGE1 2>/dev/null
am force-stop $PACKAGE1

sleep 2

# 删文件
if [ -f "$TMP_FILE" ]; then
    echo "删除 $TMP_FILE"
    rm -f "$TMP_FILE"
fi

# 启动游戏
echo "启动 $PACKAGE1"
monkey -p $PACKAGE1 1 >/dev/null 2>&1 &

echo "等待2秒..."
sleep 2

# 写回文件
echo '{"_sv_userAgree":1,"_lastCacheVer":"1.68.0","_h_user_token":""}' > "$TMP_FILE"
echo "已写回文件"

sleep 1

# 杀游戏
echo "停止 $PACKAGE1"
killall $PACKAGE1 2>/dev/null
am force-stop $PACKAGE1

sleep 1

# 重启游戏
echo "重新启动 $PACKAGE1"
monkey -p $PACKAGE1 1 >/dev/null 2>&1 &

echo "完事"