Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #####################################################################################################################################################################
- #
- # Script helps installing mods for connecting to a modded Dayz server (as dayz launcher does not yet work in proton).
- #
- # I used dayz-linux-cli-launcher and dayz-dztui as examples to combine and change what I understand and need as
- # both were not running completely for me. To understand what's wrong I need to do it for myself from scratch.
- # So, credits to both the authors for the great work!
- #
- # Script reads what mods the given server needs and downloads them via steamcmd.
- # Mods are downloaded into the Steam-workshop-dayz (221100) directory. After that symlinks will be created
- # from these workshop mods into the Dayz directory (starting with @ followed by the mod-ID).
- # From all the mod-IDs a string is concatenated to be given to the launch command (-mod="@...;@...;").
- # Then the script tries to connect to the dayz server using these mods (Steam application must be running for this).
- #
- # I normally get the server ip:port from web pages listing servers. If the steam query port is not 27016 and not mentioned,
- # then I do not know how to get it. This port is needed for the API to retrieve the server information.
- # In that case I normally try another server until I get a positive response.
- #
- # Start the script with e.g.:
- # ./dayz-mod-launcher.sh \
- # --server <ip>:<gameport> \
- # --port 27016 \
- # --mods \
- # --launch \
- # --name jahan
- #
- # Or in a shorter command:
- # ./dayz-mod-launcher.sh -s <ip>:<gameport> -m -l -n <profilename>
- #
- # I put this in an additional script, like dayz_servername.sh to be able to connect to different servers.
- # So for every server you create a own file with the right ip:port.
- #
- # If all mods are downloaded for server, I edit this script and delete the line for updating the mods (--mods).
- # That way it does not take so long to connect to the server.
- # Also 2 scripts can be created, one for launching and one for updating the mods.
- # 1) ./dayz-mod-launcher.sh --server <ip>:<port> --port 27016 --mods
- # 2) ./dayz-mod-launcher.sh --server <ip>:<port> --port 27016 --launch --name jahan
- # (add -d for more output=
- #
- # The script does not check everything possible and error out. I just wanted to create a short, intuitive solution
- # which does the job automatically for me as simple as possible.
- #
- # In Steam add proton_experimental in the compability tab of the Dayz Properties.
- # I have the following launch options set on the General tab (DXVK_FRAME_RATE to cap my fps):
- # DXVK_FRAME_RATE=60 %command% -skipintro -nolauncher -nosplash
- #
- # Issue:
- # The very first time all mods where downloaded for a server and I tried to connect, it worked but I had only 1-2fps and the game crashed soon.
- # So go to Steam and start Dayz (seöect Run Dayz Client). In the options (Video) menu deactivate vertical sync.
- # After that I was able to play on the modded server and everything worked fine.
- #
- # I do not know why but sometimes steamcmd stays here for long before it starts to validate the mods:
- # Connecting anonymously to Steam Public...OK
- # Waiting for client config...OK
- # Waiting for user info...OK
- # I think it's related to Steam. At other times of the day (in the morning) it works very much faster.
- #
- # It takes a bit to download the mods. If there is a Timeout in steamcmd I copy the last mod-ID and use this page (add the mod-id at the end of the URL)...
- # https://steamcommunity.com/sharedfiles/filedetails/?id=
- # ...to get the name of the mod to download it directly in the Steam workshop of Dayz (Steam-UI).
- # This happens often for the larger mods (>2-3+ GB). You can also try to run the script again....sometimes it finishes downloading.
- #
- #####################################################################################################################################################################
- # Edit/change config options below to your needs.
- #----------------------------------------------------------------------------------
- #BEGIN CONFIG===============
- # Steam Dayz application ID (no need to change)
- DAYZ_ID=221100
- # path to the Steam directory
- STEAM_PATH="/home/jahan/.local/share/Steam/"
- # path from the Steam directory to the Dayz game directory
- GAME_DIR="$STEAM_PATH/steamapps/common/DayZ"
- # path from the Steam directory to the workshop directory
- WORKSHOP_DIR="$STEAM_PATH/steamapps/workshop/content"
- # Dayz ingame name/profile
- INGAMENAME="jahan"
- #END CONFIG=================
- #STEAMCMD CONFIG============
- # user which runs the steamcmd application
- STEAMCMD_USER="jahan"
- # username for steamcmd, anonymous can be used or your real steam user
- STEAMCMD_USERNAME="anonymous"
- #END STEAMCMD CONFIG========
- #----------------------------------------------------------------------------------
- # Only change anything below if something is not working for you or you want to adapt something
- set -eo pipefail
- SELF=$(basename "$(readlink -f "${0}")")
- # program dependencies
- deps=("jq" "steamcmd" "curl" "sed" "steam")
- # DZSA Launcher API (to query server data)
- API_URL="https://dayzsalauncher.com/api/v1/query/@ADDRESS@/@PORT@"
- API_PARAMS=(
- -sSL
- -m 10
- -H "User-Agent: dayz-linux-cli-launcher"
- )
- DEBUG=0
- LAUNCH=0
- SERVER=""
- PORT="27016"
- DLMODS=0
- NAME=""
- print_help() {
- cat <<EOF
- Usage: ${SELF} [OPTION]... [MODID]... [-- [GAME-PARAM]...]
- For a given Dayz server:port the script automatically set up mods,
- launch the game and connect to a server.
- Command line options:
- -h
- --help
- Print this help text.
- -d
- --debug
- Print debug messages to output (more text).
- -s <address[:port]>
- --server <address[:port]>
- Server ip and game port (e.g. from game server listings)
- Needs to be provided...otherwise the script cannot do anything.
- This will query the servers mod list and prints out information.
- Can be used (without --mods / --launch) just to get these information.
- If --mods is set, it will automatically download mods.
- If --launch is set, Dayz will automatically connect to the server/port.
- -m
- --mods
- Download or updates mods automatically via steamcmd.
- Also creates sysmlinks of the workshop mods into the Dayz game directory.
- If mods are up-to-date, this can be left out (to start the game via --launch faster).
- If there are pbo issues connecting to the game, include it again to validate the mods.
- -l
- --launch
- Launch DayZ and connect to given server.
- Steam needs to be open.
- -n <name>
- --name <name>
- Set the profile name when launching the game via --launch.
- Some community servers require a profile name when trying to connect.
- -p <port>
- --port <port>
- The server's query port, not to be confused with the server's game port.
- If option is not used, the default value will be used: 27016
- Needed to query mod information from the server.
- EOF
- }
- while (( "$#" )); do
- case "${1}" in
- -h|--help)
- print_help
- exit
- ;;
- -d|--debug)
- DEBUG=1
- ;;
- -m|--mods)
- DLMODS=1
- ;;
- -l|--launch)
- LAUNCH=1
- ;;
- -s|--server)
- SERVER="${2}"
- shift
- ;;
- -p|--port)
- PORT="${2}"
- shift
- ;;
- -n|--name)
- INGAMENAME="${2}"
- shift
- ;;
- esac
- shift
- done
- depcheck(){
- for dep in "${deps[@]}"; do
- command -v $dep 2>&1>/dev/null || (printf "[ERROR] Program $dep is missing but required. Please install.\n" ; exit 1)
- done
- }
- msg() {
- echo -e "[${SELF}][info] ${@}"
- }
- err() {
- echo -e >&2 "[${SELF}][error] ${@}"
- exit 1
- }
- debug() {
- if [[ ${DEBUG} == 1 ]]; then
- echo -e "[${SELF}][debug] ${@}"
- fi
- }
- check_dir() {
- debug "Checking directory: ${1} - ${2}"
- [[ -d "${1}" ]] || err "Invalid/missing directory: ${1}"
- }
- query_server_api() {
- [[ -z "${SERVER}" ]] && return
- local query
- local response
- msg "Querying API for server: ${SERVER%:*}:${PORT}"
- query="$(sed -e "s/@ADDRESS@/${SERVER%:*}/" -e "s/@PORT@/${PORT}/" <<< "${API_URL}")"
- debug "Querying ${query}"
- response="$(curl "${API_PARAMS[@]}" "${query}")"
- debug $response"\n"
- msg "Parsing API response...\n"
- jq -e ".result.mods[]" >/dev/null 2>&1 <<< "${response}" || err "Missing mods data from API response"
- SERVERNAME=$(jq -r ".result.name" <<< "${response}")
- msg "Servername:\n"$SERVERNAME"\n"
- MODNAMES=$(jq ".result.mods[].name" <<< "${response}")
- MODIDS=$(jq ".result.mods[].steamWorkshopId" <<< "${response}")
- msg "Anzahl Mods: "$(echo $MODIDS | wc -w)"\n"
- debug "Modnames:\n"$MODNAMES"\n"
- debug "ModIds:\n"$MODIDS"\n"
- }
- # create a mod list which can be given to steamcmd to download each of them
- steamcmd_modlist(){
- for i in $MODIDS; do
- printf "+workshop_download_item %s %s " $DAYZ_ID $i
- done
- }
- # download mods to the Steam workshop dir
- auto_download_mods() {
- msg "Downloading mods via steamcmd...\n"
- sudo su -c "steamcmd +force_install_dir $STEAM_PATH +login $STEAMCMD_USERNAME $(steamcmd_modlist) validate +quit" $STEAMCMD_USER
- printf "\n"
- }
- # create symlinks of the Workshop mods into the Steam Dayz directory (mod IDs as names)
- symlinks(){
- printf "\n"
- msg "Creating symlinks for new mods...\n"
- for i in $MODIDS; do
- # create symlink from mods in Steam/steamapps/workshop/DAYZ-ID folder in the Steam/steamapps/common/DAYZ folder (starting with @)
- ln -fs "$WORKSHOP_DIR/$DAYZ_ID/$i" "$GAME_DIR/@$i"
- # MODS=$MODS"@"$i";"
- done
- }
- buildmodstring(){
- # build mod string to be given to the launch command -mod= parameter
- for i in $MODIDS; do
- MODS=$MODS"@"$i";"
- done
- debug "Mod String to launch game (-mod= parameter): "
- debug $MODS"\n"
- }
- main () {
- clear
- msg "Checking a few program dependencies..."
- depcheck
- msg "Ok."
- if [[ -z "$SERVER" ]]; then
- msg "Nothing to do..."
- msg "No --server address set. This is a mandatory option to continue-"
- msg "See --help for all the available options."
- exit
- fi
- msg "Start of Dayz-Mod-Launcher-Script...\n"
- debug "Checking directories..."
- check_dir "${STEAM_PATH}" "STEAM_PATH"
- check_dir "${GAME_DIR}" "GAME_DIR"
- check_dir "${WORKSHOP_DIR}" "WORKSHOP_DIR"
- debug "Directories ok.\n"
- # query mod-information from server
- query_server_api
- buildmodstring
- if [[ "${DLMODS}" == 1 ]]; then
- # download or update mods
- # comment out if all mods are downloaded already
- auto_download_mods
- # create symlinks in the game dir for each mod
- # comment out if all mods are downloaded and links are already installed
- symlinks
- fi
- if [[ "${LAUNCH}" == 1 ]]; then
- msg "Launching DayZ:"
- msg "Trying to connect to server...\n"
- # the next command is needed, otherwise the game crashes or causes a black screen (see protondb dayz comments)
- sudo sysctl -w vm.max_map_count=16777216
- debug "steam -applaunch $DAYZ_ID -connect=$SERVER -nolauncher -skipintro -nosplash -world=empty -name=$INGAMENAME -mod="\"$MODS\""\n"
- # connect to the server via steam applaunch
- steam -applaunch $DAYZ_ID -connect=$SERVER -nolauncher -skipintro -nosplash -world=empty -name=$INGAMENAME -mod="$MODS"
- msg "Good luck out there in the fields...\n"
- fi
- }
- main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement