#!/bin/bash

function print_color() {
  local color=$1
  shift
  echo -e "\033[${color}m$@\033[0m"
}

clear

echo -e "\033[1;33m======================================\033[0m"
echo -e "\033[1;35m           启动工具            \033[0m"
echo -e "\033[1;33m======================================\033[0m"
echo ""

if [ $(id -u) != 0 ]; then
    print_color "31" "请使用 root 权限运行本脚本"
    echo ""
    exit 1
fi

sleep 0.3

print_color "32" "[*] 正在部署组件..."
echo ""

cp -f lib幻影大肘.so /data/data/com.tencent.igce/
chmod 755 /data/data/com.tencent.igce/lib幻影大肘.so

cp -f Inject.ig /data/data/com.tencent.igce/
chmod 777 /data/data/com.tencent.igce/Inject.ig

sleep 0.2

if [ -f /data/data/com.tencent.igce/lib幻影大肘.so ] && [ "$(stat -c '%a' /data/data/com.tencent.igce/lib幻影大肘.so)" = "755" ]; then
    print_color "32" "[+] 动态库文件 正常"
else
    print_color "31" "[-] 动态库文件 异常"
    echo ""
    exit 1
fi

if [ -f /data/data/com.tencent.igce/Inject.ig ] && [ "$(stat -c '%a' /data/data/com.tencent.igce/Inject.ig)" = "777" ]; then
    print_color "32" "[+] 注入程序 正常"
else
    print_color "31" "[-] 注入程序 异常"
    echo ""
    exit 1
fi

echo ""
print_color "42;37" "    环境准备完毕，正在启动游戏...    "
echo ""

sleep 0.5

am start com.tencent.igce/com.epicgames.ue4.SplashActivity > /dev/null 2>&1

# 启动游戏后等待 1.8 秒
sleep 2.8

echo ""
print_color "36" "[*] 执行注入..."
su -c /data/data/com.tencent.igce/Inject.ig -n com.tencent.igce -so /data/data/com.tencent.igce/lib幻影大肘.so

echo ""
print_color "32" "[+] 注入完成，祝你游戏愉快！"
echo ""
