#!/bin/bash

# figure out the absolute path to the script being run a bit
# non-obvious, the ${0%/*} pulls the path out of $0, cd's into the
# specified directory, then uses $PWD to figure out where that
# directory lives - and all this in a subshell, so we don't affect
# $PWD

source "$(cd "$(dirname "$0")";pwd)/config"

if [ ! -d "${GAMUX_GAME_DATA}" ];then
  mkdir -p "${GAMUX_GAME_DATA}"
fi

if [ ! -d "${GAMUX_GAME_DATA_TMP}" ];then
  mkdir "${GAMUX_GAME_DATA_TMP}"
fi

UNIONFS="unionfs_${PLATFORM}"

#CS1.6需添加direct_io参数

"${HERE}"/${UNIONFS} -o big_writes,umask=0002,auto_cache,sync_read,nonempty,uid=$(id -u),gid=$(id -g),cow "${GAMUX_GAME_DATA}"=RW:"${GAMUX_GAME_READONLY}"=RO ${GAMUX_GAME_DATA_TMP}

#自定义代码
gamux_function1

###############################################################################################

#启动游戏
cd "${GAMUX_GAME_DATA_TMP}"

if [ ${GAMUX_STEAMRUNTIME} -eq 0 ];then 
  "${GAMUX_GAME_DATA_TMP}/${GAMUX_GAME_EXEC}" "$@"
else
  "${HERE}/steam-runtime/run.sh" "${GAMUX_GAME_DATA_TMP}/${GAMUX_GAME_EXEC}" "$@"
fi
