From e4c49985945808d74c1766c7347d02c030b8699a Mon Sep 17 00:00:00 2001 From: Eamonn Rea Date: Tue, 5 Mar 2024 20:35:38 +0000 Subject: [PATCH 1/2] GameScope: Properly handle empty GAMESCOPE_ARGS string --- steamtinkerlaunch | 84 ++++++++++++++++++++++++++--------------------- 1 file changed, 46 insertions(+), 38 deletions(-) diff --git a/steamtinkerlaunch b/steamtinkerlaunch index 306d2bbc..fdd9365e 100755 --- a/steamtinkerlaunch +++ b/steamtinkerlaunch @@ -6,7 +6,7 @@ PREFIX="/usr" PROGNAME="SteamTinkerLaunch" NICEPROGNAME="Steam Tinker Launch" -PROGVERS="v14.0.20240218-1" +PROGVERS="v14.0.20240305-1 (better-gamescope-empty-args-fix)" PROGCMD="${0##*/}" PROGINTERNALPROTNAME="Proton-stl" SHOSTL="stl" @@ -19957,49 +19957,57 @@ function gameScopeArgs { # This implementation could be VASTLY improved! ARGSTRING="$1" unset GAMESCOPEARGSARR - if [ "$1" != "$NON" ]; then - # This removes paths from the GameScope args array as spaces in paths can cause issues, then builds the array, and then re-inserts the paths where it finds empty single-quotes which we wrap paths with in GameScopeGui. - # When saving from the main menu, single quotes seem to get cleared, so we need to ensure paths are wrapped with them + # Even if no args are given we always have to end GameScope commands with '--' + # $1 == NON when we save with no arguments, doing this visually preserves the GameScope "none" text while still gracefully handling blank args by forcing '--' + if [ "$1" == "$NON" ] || [ -z "$( trimWhitespaces "$1" )" ]; then # trimWhitespaces accounts for strings that are just whitespaces, i.e. ' ' + writelog "INFO" "${FUNCNAME[0]} - No gamescope arguments given, but we need to end with '--', so forcing GAMESCOPEARGSARR to '--' and returning" + GAMESCOPEARGSARR=("--") + return + fi + + # This removes paths from the GameScope args array as spaces in paths can cause issues, then builds the array, and then re-inserts the paths where it finds empty single-quotes which we wrap paths with in GameScopeGui. + # When saving from the main menu, single quotes seem to get cleared, so we need to ensure paths are wrapped with them + + # Store paths from GameScope array string + IFS_backup=$IFS + IFS=$'\n' + mapfile -t GAMESCOPE_ARGPATHS < <( echo "$ARGSTRING" | grep -oP "'/(.+?)'" ) + writelog "INFO" "${FUNCNAME[0]} - GameScope incoming args are '${ARGSTRING[*]}'" + # If the above is empty, try and surround any existing paths with quotes and then grep for the file paths from the quotes - This means paths cannot contain quotes, but oh well. Compromise! + if [ -z "${GAMESCOPE_ARGPATHS[*]}" ]; then + writelog "INFO" "${FUNCNAME[0]} - Could not find any paths from incoming GameScope arguments, checking if we need to surround any paths in quotes..." + unset GAMESCOPE_ARGPATHS - # Store paths from GameScope array string - IFS_backup=$IFS - IFS=$'\n' + # shellcheck disable=SC2001 + ARGSTRING="$(echo "${ARGSTRING}" | sed "s:\(/\S* \S*\):'\1':g" )" # Finds paths and surrounds them in single quotes so the below grep works! mapfile -t GAMESCOPE_ARGPATHS < <( echo "$ARGSTRING" | grep -oP "'/(.+?)'" ) - writelog "INFO" "${FUNCNAME[0]} - GameScope incoming args are '${ARGSTRING[*]}'" - # If the above is empty, try and surround any existing paths with quotes and then grep for the file paths from the quotes - This means paths cannot contain quotes, but oh well. Compromise! - if [ -z "${GAMESCOPE_ARGPATHS[*]}" ]; then - writelog "INFO" "${FUNCNAME[0]} - Could not find any paths from incoming GameScope arguments, checking if we need to surround any paths in quotes..." - unset GAMESCOPE_ARGPATHS - - # shellcheck disable=SC2001 - ARGSTRING="$(echo "${ARGSTRING}" | sed "s:\(/\S* \S*\):'\1':g" )" # Finds paths and surrounds them in single quotes so the below grep works! - mapfile -t GAMESCOPE_ARGPATHS < <( echo "$ARGSTRING" | grep -oP "'/(.+?)'" ) - if [ -n "${GAMESCOPE_ARGPATHS[*]}" ]; then - writelog "INFO" "${FUNCNAME[0]} - We found some paths we need to update - Updated GameScope args string is '$ARGSTRING'" - else - writelog "INFO" "${FUNCNAME[0]} - Still could not find any paths from incoming GameScope arguments, assuming we don't have any paths in our arguments" - fi + if [ -n "${GAMESCOPE_ARGPATHS[*]}" ]; then + writelog "INFO" "${FUNCNAME[0]} - We found some paths we need to update - Updated GameScope args string is '$ARGSTRING'" + else + writelog "INFO" "${FUNCNAME[0]} - Still could not find any paths from incoming GameScope arguments, assuming we don't have any paths in our arguments" fi - IFS=$IFS_backup + fi + IFS=$IFS_backup - # Remove all text between single quotes -- We assume all text between single quotes in this context will be a GameScope path arg - writelog "INFO" "${FUNCNAME[0]} - GameScope arg paths are '${GAMESCOPE_ARGPATHS[*]}'" - # shellcheck disable=SC2001 - ARGSTRING="$( echo "$ARGSTRING" | sed "s:'[^']*':'':g" )" - mapfile -d " " -t -O "${#GAMESCOPEARGSARR[@]}" GAMESCOPEARGSARR < <(printf '%s' "$ARGSTRING") + # Remove all text between single quotes -- We assume all text between single quotes in this context will be a GameScope path arg + writelog "INFO" "${FUNCNAME[0]} - GameScope arg paths are '${GAMESCOPE_ARGPATHS[*]}'" + # shellcheck disable=SC2001 + ARGSTRING="$( echo "$ARGSTRING" | sed "s:'[^']*':'':g" )" + mapfile -d " " -t -O "${#GAMESCOPEARGSARR[@]}" GAMESCOPEARGSARR < <(printf '%s' "$ARGSTRING") - INSERTARG=$((0)) # Which path arg to insert from the `GAMESCOPE_ARGPATHS` array - GAMESCOPEARGSARR_COPY=("${GAMESCOPEARGSARR[@]}") - for i in "${!GAMESCOPEARGSARR_COPY[@]}"; do - if [[ "${GAMESCOPEARGSARR_COPY[$i]}" == *"'"* ]]; then - GAMESCOPEARGSARR_COPY[$i]="${GAMESCOPE_ARGPATHS[${INSERTARG}]}" - INSERTARG=$((INSERTARG + 1)) - fi - done + INSERTARG=$((0)) # Which path arg to insert from the `GAMESCOPE_ARGPATHS` array + GAMESCOPEARGSARR_COPY=("${GAMESCOPEARGSARR[@]}") + for i in "${!GAMESCOPEARGSARR_COPY[@]}"; do + if [[ "${GAMESCOPEARGSARR_COPY[$i]}" == *"'"* ]]; then + GAMESCOPEARGSARR_COPY[$i]="${GAMESCOPE_ARGPATHS[${INSERTARG}]}" + INSERTARG=$((INSERTARG + 1)) + fi + done - unset GAMESCOPEARGSARR # Reset array and re-assign it to copied array with updated argument values - GAMESCOPEARGSARR=("${GAMESCOPEARGSARR_COPY[@]}") - fi + unset GAMESCOPEARGSARR # Reset array and re-assign it to copied array with updated argument values + GAMESCOPEARGSARR=("${GAMESCOPEARGSARR_COPY[@]}") + + ## TODO handle GameScope arguments that don't end in `--` if [ "${#GAMESCOPEARGSARR[@]}" -ge 1 ]; then writelog "INFO" "${FUNCNAME[0]} - Using following gamescope arguments: '${GAMESCOPEARGSARR[*]}'" From c3c4fc80856b29279b3aba50ec9fee786bd3dd04 Mon Sep 17 00:00:00 2001 From: Eamonn Rea Date: Wed, 6 Mar 2024 21:39:41 +0000 Subject: [PATCH 2/2] version bump --- steamtinkerlaunch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/steamtinkerlaunch b/steamtinkerlaunch index fdd9365e..0983d747 100755 --- a/steamtinkerlaunch +++ b/steamtinkerlaunch @@ -6,7 +6,7 @@ PREFIX="/usr" PROGNAME="SteamTinkerLaunch" NICEPROGNAME="Steam Tinker Launch" -PROGVERS="v14.0.20240305-1 (better-gamescope-empty-args-fix)" +PROGVERS="v14.0.20240307-1" PROGCMD="${0##*/}" PROGINTERNALPROTNAME="Proton-stl" SHOSTL="stl"