#!/bin/bash
#验证版本1.0.2更新时间2025/9/5更新心跳验证11月23发布使用
#官方网站b6w.cn
#云更新m.b6w.cn
#shell卡密验证云更新系统对接
#请使用MT管理器终端扩展包环境执行无需root只需MT管理器终端扩展包执行
#云更新策略是只要后台没有勾选强制更新就会让用户选择是否更新
#勾选了就会系统强制自动更新.不给用户选择是否选择更新版本号不一致会强制更新
#覆盖原有的内容为新版本下载链接里面的内容
#后台更新的链接可以填写sh后缀的还有zip后缀的
#远程文件是sh则是直接替换当前文件的内容为新版本
#远程文件是zip压缩包则是下载需手动移动出来执行
#因为有些人说他们是执行so要更新so所以用户的意见添加了新版本
#这样只需把sh和so放在压缩包里面做下载下来会手动移动出来执行新版本
# ===================== 开发者配置选项 =====================
#APP ID 也就是apikey
API_KEY="e0341650bd5958b3a8775b2081fe86d3"
#版本号判断更新使用
CURRENT_VERSION="1.0.0"
#新版本更新后是否自动重启脚本执行
#  - 填1：更新替换文件内容后，自动重启脚本执行
#  - 填0：更新替换文件内容后，退出脚本，需用户手动重新执行
AUTO_EXEC_AFTER_UPDATE="1"
#心跳验证时间5分钟，也就是300秒（当前配置为300秒，可按需修改）
#不可低于30秒-否则系统检测到异常会封禁
HEARTBEAT_INTERVAL=300
#服务器无响应-无网络尝试次数(不用管)
HEARTBEAT_RETRY=3

# ======================开发者配置完成-下方代码无需修改======================

API_URL_UPDATE=$(echo "aHR0cHM6Ly9tLmI2dy5jbi9hcGkvYjZ3YXBpeWd4LnBocA==" | base64 -d)
API_URL_VERIFY=$(echo "aHR0cHM6Ly9tLmI2dy5jbi9hcGkvYjZ3YXBpa2V5LnBocA==" | base64 -d)
REPORT_URL=$(echo "aHR0cHM6Ly9tLmI2dy5jbi9hcGkvc2IucGhw" | base64 -d)
SIGN_KEY="必6网.免费的云更新验证系统官方网站部分浏览器显示有风险可以换个浏览器-浏览器搜索b6w.cn"
DEVICE_FILE="/data/local/tmp/.device_code.txt"
BACKUP_DEVICE_FILE="./.device_code.txt"
CARD_KEY_MAIN_FILE="/data/local/tmp/.saved_card_key.txt"
CARD_KEY_BACKUP_FILE="./.saved_card_key.txt"
RETRY_INTERVAL=3
get_device_code() {
    local hardware_id=""
    if [ -z "$hardware_id" ] && [ -f "/sys/class/android_usb/android0/iSerial" ]; then
        hardware_id=$(cat /sys/class/android_usb/android0/iSerial 2>/dev/null | tr -d ' \n\r')
    fi
    if [ -z "$hardware_id" ] && [ -f "/proc/cpuinfo" ]; then
        hardware_id=$(grep -i 'serial' /proc/cpuinfo 2>/dev/null | head -n1 | awk -F: '{print $2}' | tr -d ' \n\r')
    fi
    if [ -z "$hardware_id" ] && command -v getprop &>/dev/null; then
        hardware_id=$(getprop ro.serialno 2>/dev/null | tr -d ' \n\r')
        if [ -z "$hardware_id" ]; then
            hardware_id=$(getprop ro.boot.serialno 2>/dev/null | tr -d ' \n\r')
        fi
    fi
    if [ -z "$hardware_id" ] && [ -f "/sys/class/bluetooth/hci0/address" ]; then
        hardware_id=$(cat /sys/class/bluetooth/hci0/address 2>/dev/null | tr -d ':\n\r')
    fi
    if [ -z "$hardware_id" ] && [ -f "/sys/class/net/wlan0/address" ]; then
        hardware_id=$(cat /sys/class/net/wlan0/address 2>/dev/null | tr -d ':\n\r')
    fi
    if [ -z "$hardware_id" ]; then
        if [ -f "$BACKUP_DEVICE_FILE" ]; then
            hardware_id=$(cat "$BACKUP_DEVICE_FILE" 2>/dev/null | tr -d ' \n\r')
        elif [ -f "$DEVICE_FILE" ]; then
            hardware_id=$(cat "$DEVICE_FILE" 2>/dev/null | tr -d ' \n\r')
        else
            hardware_id=$(date +%s | md5sum | head -c 16)
        fi
    fi
    local fixed_code="$hardware_id"
    if [ ${#fixed_code} -gt 32 ]; then
        fixed_code="${fixed_code:0:32}"
    elif [ ${#fixed_code} -lt 32 ]; then
        fixed_code=$(printf "%-32s" "$fixed_code" | tr ' ' '0')
    fi
    if ! echo "$fixed_code" > "$BACKUP_DEVICE_FILE" 2>/dev/null; then
        if echo "$fixed_code" > "$DEVICE_FILE" 2>/dev/null; then
            DEVICE_FILE="$DEVICE_FILE"
        else
            echo "[警告] 设备码文件写入失败，临时生效" >&2
        fi
    else
        DEVICE_FILE="$BACKUP_DEVICE_FILE"
    fi
    chmod 600 "$DEVICE_FILE" 2>/dev/null

    echo "$fixed_code"
}
DEVICE_CODE=$(get_device_code)
[ -z "$DEVICE_CODE" ] && { echo "设备码生成失败" >&2; exit 1; }

request_with_retry() {
    local url="$1"
    local data="$2"
    local retry_count=1

    while true; do
        local response=$(curl -s --connect-timeout 10 -X POST "$url" \
            -H "Content-Type: application/json" \
            -d "$data")

        if [ $? -eq 0 ] && [ -n "$response" ]; then
            echo "$response"
            return 0
        else
            echo "[重试] 接口请求失败（第$retry_count次），$RETRY_INTERVAL秒后重试..."
            sleep $RETRY_INTERVAL
            retry_count=$((retry_count + 1))
        fi
    done
}

extract_field() {
    local key="$1"
    local json="$2"
    echo "$json" | grep -o "\"$key\":\"[^\"]*\"" | sed "s/\"$key\":\"//;s/\"//;s/^[[:space:]]*//;s/[[:space:]]*$//"
}

extract_boolean() {
    local key="$1"
    local json="$2"
    echo "$json" | sed -n "s/.*\"$key\"\s*:\s*\(\(true\)\|\(false\)\).*/\1/p"
}

check_update() {
    echo "===== 开始云更新检查 ====="

    local verify_data='{"action":"verify_api_key", "api_key":"'$API_KEY'"}'
    local verify_response=$(request_with_retry "$API_URL_UPDATE" "$verify_data")
    local app_id=$(extract_field "app_id" "$verify_response")

    if [ -z "$app_id" ]; then
        local error_msg=$(extract_field "error" "$verify_response")
        echo "[错误] 更新验证失败：$error_msg"
        return 1
    fi
    echo "[成功] 应用ID：$app_id"

    local config_data='{"action":"get_config", "app_id":"'$app_id'"}'
    local config_response=$(request_with_retry "$API_URL_UPDATE" "$config_data")

    local announcement=$(extract_field "announcement" "$config_response")
    local latest_version=$(extract_field "latest_version" "$config_response")
    local update_url=$(extract_field "update_url" "$config_response")
    local force_update=$(extract_boolean "force_update" "$config_response")

    local force_update_cn="否"
    [ "$force_update" = "true" ] && force_update_cn="是"

    echo -e "\n[配置信息]:"
    echo -n "  公告内容："
    if [ -n "$announcement" ]; then
        echo -e "$announcement"
    else
        echo "🤡🤡🤡联系方式企鹅🐧:1838183135👾👾👾~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~本项目已稳三个赛季😎本项目进行到现在无拉外挂记录📝拒接动内存😈~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~更新日志:6.29号解决卡框问题🤡8.11号奇思幻想解决卡框问题🤡9.14号奇思幻想解决王者更换底层逻辑导致的卡框问题(遗留问题1分钟闪，1分钟不闪)🤡9.17凭空想象修复闪框问题🤡🤡🤡9.26号更新新赛季🤖🤖🤖10.3号解决部分用户卡框问题(新包加联系方式)👿👿👿11.9号解决卡框问题"
    fi
    echo "  当前版本：$CURRENT_VERSION（本地）"
    echo "  最新版本：$latest_version（云端）"
    echo "  是否强制更新：$force_update_cn"
    echo "  开发者更新配置-更新后自动执行：$( [ "$AUTO_EXEC_AFTER_UPDATE" = "1" ] && echo "是" || echo "否" )"

    update_url=$(echo "$update_url" | sed 's/\\\//\//g')

    if [ "$latest_version" != "$CURRENT_VERSION" ] && [ -n "$update_url" ] && [ "$latest_version" != "" ]; then
        echo -e "\n[发现新版本] $latest_version"
        
        if ! command -v curl &> /dev/null; then
            echo "[错误] 缺少curl工具，请安装后重试"
            exit 1
        fi

        if [ "$force_update" = "true" ]; then
            echo "[强制更新] 必须更新才能继续使用！"
            update_action=1
        else
            echo "[非强制更新] 发现新版本，是否更新？（1=更新，0=不更新，默认0）"
            read -p "请输入选择（1/0）：" user_choice
            if [ -z "$user_choice" ]; then
                user_choice=0
            fi
            if [ "$user_choice" -eq 1 ]; then
                echo "用户选择：执行更新"
                update_action=1
            else
                echo "用户选择：不更新，继续执行后续流程"
                update_action=0
                rm -f "$new_file_path" 2>/dev/null
                return 0
            fi
        fi

        if [ $update_action -eq 1 ]; then
            local script_path=$(cd "$(dirname "$0")" || exit; pwd)
            local script_name=$(basename "$0")
            local new_file_path="${script_path}/temp_update_file"

            while true; do
                if curl -fL "$update_url" -o "$new_file_path" &> /dev/null; then
                    break
                else
                    echo "[重试] 更新文件下载失败，$RETRY_INTERVAL秒后重试..."
                    sleep $RETRY_INTERVAL
                fi
            done

            local file_ext=$(echo "$update_url" | awk -F. '{print $NF}' | tr 'A-Z' 'a-z' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
            echo "[更新文件信息] 后缀：$file_ext"

            if [ "$file_ext" = "zip" ]; then
                echo "[更新处理] 识别ZIP文件，生成唯一文件名（保留所有旧文件）"
                local random_str=$(date +%s%N | md5sum | head -c 8)
                local zip_file_name="${script_name%.sh}-${latest_version}-${random_str}.zip"
                local zip_file_path="${script_path}/${zip_file_name}"
            
                if [ -f "$zip_file_path" ]; then
                    echo "[提示] 极端情况：文件名已存在，重新生成随机字符..."
                    random_str=$(date +%s%N | md5sum | head -c 8)
                    zip_file_name="${script_name%.sh}-${latest_version}-${random_str}.zip"
                    zip_file_path="${script_path}/${zip_file_name}"
                fi

                if cat "$new_file_path" > "$0"; then
                    mv -f "$0" "$zip_file_path"
                    echo "[成功] ZIP更新完成：$zip_file_path"
                    echo "[提示] 所有旧版本ZIP文件已完整保留，新文件通过版本号+随机字符区分"
                    echo "[提示] ZIP文件无法自动执行，已退出"
                    rm -f "$new_file_path"
                    exit 0
                else
                    echo "[错误] ZIP文件内容替换失败"
                    rm -f "$new_file_path"
                    exit 1
                fi
            else
                echo "[更新处理] 识别非ZIP文件，覆盖更新并准备自动执行"
                local backup_script_path="${script_path}/${script_name}.bak"
                cp -f "$0" "$backup_script_path" 2>/dev/null
                if cat "$new_file_path" > "$0"; then
                    chmod +x "$0"
                    echo "[成功] 脚本更新至 $latest_version（旧脚本已备份为 ${script_name}.bak）"
                    rm -f "$new_file_path"
                    if [ "$AUTO_EXEC_AFTER_UPDATE" = "1" ]; then
                        echo "按配置：立即自动执行更新后的脚本..."
                        exec bash "$0"
                        echo "[警告] 自动执行触发失败，请手动运行 $0"
                        exit 1
                    else
                        echo "按配置：不自动执行，请手动重启 $0"
                        exit 0
                    fi
                else
                    echo "[错误] 非ZIP文件更新失败，恢复旧脚本..."
                    cp -f "$backup_script_path" "$0" 2>/dev/null
                    rm -f "$new_file_path" "$backup_script_path"
                    exit 1
                fi
            fi

        fi

    else
        if [ "$latest_version" = "$CURRENT_VERSION" ]; then
            echo -e "\n[状态] 本地版本（$CURRENT_VERSION）与云端版本（$latest_version）一致，无需更新"
        elif [ -z "$update_url" ]; then
            echo -e "\n[状态] 虽有新版本（$latest_version），但云端未配置更新链接，无法更新"
        else
            echo -e "\n[状态] 当前已是最新版本"
        fi
    fi

    echo -e "\n===== 更新检查完成 ====="
}

decode_unicode() {
    local str="$1"
    awk -v str="$str" 'BEGIN {
        while (match(str, /\\u([0-9a-fA-F]{4})/, arr)) {
            c = sprintf("%c", strtonum("0x" arr[1]))
            gsub(/\\u[0-9a-fA-F]{4}/, c, str)
        }
        print str
    }'
}

generate_sign() {
    local data="$1"
    local salt="$2"
    local timestamp="$3"
    echo -n "${data}${salt}${timestamp}${SIGN_KEY}" | md5sum | awk '{print $1}'
}

report_tampering() {
    local request_params="$1"
    local tampered_response="$2"
    local timestamp="$3"
    local client_ip=$(curl -s --connect-timeout 5 http://icanhazip.com 2>/dev/null || \
                      curl -s --connect-timeout 5 http://ip.cn/ip 2>/dev/null | grep -oE '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' || \
                      echo "未知IP")
    client_ip=$(echo "$client_ip" | tr -d '\n\r')

    req_escaped=$(echo "$request_params" | sed 's/\\/\\\\/g')
    resp_escaped=$(echo "$tampered_response" | sed 's/\\/\\\\/g')
    req_escaped=$(echo "$req_escaped" | sed 's/"/\\"/g')
    resp_escaped=$(echo "$resp_escaped" | sed 's/"/\\"/g')
    req_escaped=$(echo "$req_escaped" | sed ':a;N;$!ba;s/\n/\\n/g')
    resp_escaped=$(echo "$resp_escaped" | sed ':a;N;$!ba;s/\n/\\n/g')
    req_escaped=$(echo "$req_escaped" | sed 's/\r/\\r/g; s/\t/\\t/g')
    resp_escaped=$(echo "$resp_escaped" | sed 's/\r/\\r/g; s/\t/\\t/g')

    report_data="{\"ip\":\"$client_ip\",\"timestamp\":\"$timestamp\",\"request_params\":\"$req_escaped\",\"tampered_response\":\"$resp_escaped\"}"
    report_result=$(curl -s --connect-timeout 10 -X POST "$REPORT_URL" \
        -H "Content-Type: application/json" -d "$report_data")
    result_msg=$(echo "$report_result" | sed -n 's/.*"message":"\([^"]*\)".*/\1/p' | decode_unicode)
    echo "数据已记录上传结果：${result_msg:-篡改数据已上传}"
}

verify_card_key() {
    echo -e "\n===== 开始卡密验证 ====="

    local CARD_KEY=""
    # 修复：先读当前目录备份文件（优先级高），再读主路径文件
    if [ -f "$CARD_KEY_BACKUP_FILE" ]; then
        CARD_KEY=$(cat "$CARD_KEY_BACKUP_FILE" 2>/dev/null | tr -d ' \n\r')
        if [ -n "$CARD_KEY" ]; then
            echo "[自动登录] 从当前目录读取到卡密，自动验证..."
            goto_verify=true
        else
            rm -f "$CARD_KEY_BACKUP_FILE"
            CARD_KEY=""
        fi
    fi

    # 若当前目录无有效卡密，再读主路径文件
    if [ -z "$CARD_KEY" ] && [ -f "$CARD_KEY_MAIN_FILE" ]; then
        CARD_KEY=$(cat "$CARD_KEY_MAIN_FILE" 2>/dev/null | tr -d ' \n\r')
        if [ -n "$CARD_KEY" ]; then
            echo "[自动登录] 从主路径读取到卡密，自动验证..."
        else
            rm -f "$CARD_KEY_MAIN_FILE"
            CARD_KEY=""
        fi
    fi

    while true; do
        if [ -z "$CARD_KEY" ]; then
            read -p "请输入卡密：" CARD_KEY
            if [ -z "$CARD_KEY" ]; then
                echo "卡密不能为空，请重新输入"
                continue
            fi
        fi

        TIMESTAMP=$(date +%s)
        REQUEST_PARAMS=$(printf '{"api_key":"%s","key":"%s","device_code":"%s","timestamp":"%s"}' \
            "$API_KEY" "$CARD_KEY" "$DEVICE_CODE" "$TIMESTAMP")

        RESPONSE=$(request_with_retry "$API_URL_VERIFY" "$REQUEST_PARAMS")

        CODE=$(echo "$RESPONSE" | sed -n 's/.*"code":[[:space:]]*\([0-9]*\).*/\1/p; s/.*"code"[[:space:]]*:[[:space:]]*\([0-9]*\),.*/\1/p' | head -n1)
        MESSAGE_RAW=$(echo "$RESPONSE" | sed -n 's/.*"message":[[:space:]]*"\([^"]*\)".*/\1/p; s/.*"message":[[:space:]]*"\([^"]*\)",.*/\1/p' | head -n1)
        MESSAGE=$(decode_unicode "$MESSAGE_RAW")
        DATA=$(echo "$RESPONSE" | sed -n 's/.*"data":[[:space:]]*"\([^"]*\)".*/\1/p' | head -n1)
        SALT=$(echo "$RESPONSE" | sed -n 's/.*"salt":[[:space:]]*"\([^"]*\)".*/\1/p' | head -n1)
        SERVER_SIGN=$(echo "$RESPONSE" | sed -n 's/.*"sign":[[:space:]]*"\([^"]*\)".*/\1/p' | head -n1)

        if [ "$CODE" -eq 200 ] && [ -n "$DATA" ] && [ -n "$SALT" ] && [ -n "$SERVER_SIGN" ]; then
            CLIENT_SIGN=$(generate_sign "$DATA" "$SALT" "$TIMESTAMP")
            if [ "$CLIENT_SIGN" != "$SERVER_SIGN" ]; then
                echo "验证失败：数据被篡改.请勿非法破解.严重的提交至公安机关处理"
                report_tampering "$REQUEST_PARAMS" "$RESPONSE" "$TIMESTAMP"
                CARD_KEY=""
                continue
            fi

            RAW_DATA=$(echo -n "$DATA" | base64 -d 2>/dev/null)
            EXPIRES_AT=$(echo "$RAW_DATA" | sed -n 's/.*"expires_at":[[:space:]]*"\([^"]*\)".*/\1/p; s/.*"expires_at":"\([^"]*\)".*/\1/p' | head -n1 | tr -d ' \n\r}')
            USED_DEVICES=$(echo "$RAW_DATA" | sed -n 's/.*"used_devices":[[:space:]]*\([0-9]*\).*/\1/p; s/.*"used_devices":\([0-9]*\).*/\1/p' | head -n1 | tr -d ' \n\r,}')
            MAX_DEVICES=$(echo "$RAW_DATA" | sed -n 's/.*"max_devices":[[:space:]]*\([0-9]*\).*/\1/p; s/.*"max_devices":\([0-9]*\).*/\1/p' | head -n1 | tr -d ' \n\r,}')

            if [ -n "$EXPIRES_AT" ] && [ -n "$USED_DEVICES" ] && [ -n "$MAX_DEVICES" ]; then
                # 保存卡密：优先当前目录（无需root），失败再试主路径
                if echo "$CARD_KEY" > "$CARD_KEY_BACKUP_FILE" 2>/dev/null; then
                    chmod 600 "$CARD_KEY_BACKUP_FILE"
                    echo "[自动登录] 卡密已保存到当前目录（$CARD_KEY_BACKUP_FILE），下次自动验证"
                elif echo "$CARD_KEY" > "$CARD_KEY_MAIN_FILE" 2>/dev/null; then
                    chmod 600 "$CARD_KEY_MAIN_FILE"
                    echo "[自动登录] 卡密已保存到主路径（$CARD_KEY_MAIN_FILE），下次自动验证"
                else
                    echo "[警告] 卡密保存失败，下次需重新输入" >&2
                fi
                export GLOBAL_CARD_KEY="$CARD_KEY"
                export GLOBAL_EXPIRES_AT="$EXPIRES_AT"
                export GLOBAL_USED_DEVICES="$USED_DEVICES"
                export GLOBAL_MAX_DEVICES="$MAX_DEVICES"
                break
            else
                echo "验证失败：数据不完整，请重新输入"
                CARD_KEY=""
            fi
        else
            [ -z "$MESSAGE" ] && MESSAGE="未知错误"
            echo "验证失败：$MESSAGE，请重新输入"
            CARD_KEY=""
            # 清除无效卡密文件
            [ -f "$CARD_KEY_MAIN_FILE" ] && rm -f "$CARD_KEY_MAIN_FILE"
            [ -f "$CARD_KEY_BACKUP_FILE" ] && rm -f "$CARD_KEY_BACKUP_FILE"
        fi
    done
}

heartbeat_verify() {
    echo -e "\n===== 心跳验证已启动（间隔$HEARTBEAT_INTERVAL秒） ====="
    while true; do
        sleep $HEARTBEAT_INTERVAL
        echo -e "\n[心跳] （$(date "+%Y-%m-%d %H:%M:%S")）"

        local card_key="$GLOBAL_CARD_KEY"
        local device_code="$DEVICE_CODE"

        if [ -z "$card_key" ] || [ -z "$device_code" ]; then
            echo "[心跳] 卡密/设备码缺失，强制中断脚本"
            exit 1
        fi

        local TIMESTAMP=$(date +%s)
        local REQUEST_PARAMS=$(printf '{"api_key":"%s","key":"%s","device_code":"%s","timestamp":"%s"}' \
            "$API_KEY" "$card_key" "$device_code" "$TIMESTAMP")

        local retry_count=1
        local RESPONSE=""
        while [ $retry_count -le $HEARTBEAT_RETRY ]; do
            RESPONSE=$(curl -s --connect-timeout 10 -X POST "$API_URL_VERIFY" \
                -H "Content-Type: application/json" -d "$REQUEST_PARAMS")
            if [ $? -eq 0 ] && [ -n "$RESPONSE" ]; then
                break
            else
                echo "[心跳重试] 请求失败（第$retry_count次），$RETRY_INTERVAL秒后重试..."
                sleep $RETRY_INTERVAL
                retry_count=$((retry_count + 1))
            fi
        done

        if [ -z "$RESPONSE" ]; then
            echo "[心跳] 服务器无响应，本次跳过，下次继续验证(注此提示不影响你正常的源代码脚本执行)"
            continue
        fi

        local CODE=$(echo "$RESPONSE" | sed -n 's/.*"code":[[:space:]]*\([0-9]*\).*/\1/p; s/.*"code"[[:space:]]*:[[:space:]]*\([0-9]*\),.*/\1/p' | head -n1)
        local MESSAGE_RAW=$(echo "$RESPONSE" | sed -n 's/.*"message":[[:space:]]*"\([^"]*\)".*/\1/p; s/.*"message":[[:space:]]*"\([^"]*\)",.*/\1/p' | head -n1)
        local MESSAGE=$(decode_unicode "$MESSAGE_RAW")

        if [ "$CODE" -eq 200 ]; then
            echo "[心跳] 验证成功(注此提示不影响你正常的源代码脚本执行)"
        else
            echo "[心跳] 卡密验证失败：$MESSAGE"
            echo "[心跳] 强制中断脚本运行"
            exit 1
        fi
    done
}

start_heartbeat_in_background() {
    heartbeat_verify &
    # 记录心跳进程ID，确保脚本退出时心跳也退出
    HEARTBEAT_PID=$!
    trap 'kill $HEARTBEAT_PID 2>/dev/null' EXIT
}

check_update
verify_card_key
echo -e "\n卡密验证成功"
echo "到期时间：$GLOBAL_EXPIRES_AT"
echo "设备限制：已用$GLOBAL_USED_DEVICES台，共$GLOBAL_MAX_DEVICES台"

# 启动后台心跳验证
start_heartbeat_in_background

# ===================== 你的源代码填写区域 =====================
#卡密验证之后则会执行你的源代码





echo "验证成功后程序开始执行..."
echo "      

           王者s42赛季

";
echo "\033[35m✿ 企鹅🐧:1838183135 ✿
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━



🚀 正在启动游戏...
🔍 等待游戏启动...
[-] 游戏未启动，等待中... (1/10)\033[0m";
sleep 0.2
am start com.tencent.tmgp.sgame/com.tencent.tmgp.sgame.SGameActivity
sleep 2.0
echo "\033[35m[+] 检测到游戏已启动 (PID: 19062)
[+] 开始注入尝试 (2/10)
🔄 尝试注入方式: -p 19062 -so /data/data/com.tencent.tmgp.sgame/libLavender.so";
echo "                                       🍀注入坐标标识🍀";
sleep 1
a=0
while [ $a -le 99 ]
do
sleep 0.08
let a=a+1
echo " -p 19062 -so /data/data/com.tencent.tmgp.sgame/libLavender.so [Warning]: 注入进度: $a％";
done
echo "



";
echo "                                       🍀已注入坐标标识🍀  
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━";
sleep 1
echo"🍀


";
sleep 1.5
echo "🍀过检已注入 祝您游戏愉快🍀";
echo "🔄 监控模式启动，持续检测注入状态...\033[";

#注：源代码执行期间，心跳会在后台每隔$HEARTBEAT_INTERVAL秒自动验证


# ===================== 上方填写你的源代码 =====================

# 等待用户源代码执行完成（若用户代码是持续运行的，此句可省略）
wait
