Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GameScope: Fix blank GSSHWRES and GSINTRES displaying 'x' #1154

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 64 additions & 31 deletions steamtinkerlaunch
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
PREFIX="/usr"
PROGNAME="SteamTinkerLaunch"
NICEPROGNAME="Steam Tinker Launch"
PROGVERS="v14.0.20240831-1"
PROGVERS="v14.0.20240903-1"
PROGCMD="${0##*/}"
PROGINTERNALPROTNAME="Proton-stl"
SHOSTL="stl"
Expand Down Expand Up @@ -11294,41 +11294,67 @@ function setGameScopeVars {
ARGTYPE="${6,,}" # e.g. "chk", "cb", etc (matches Yad widget types mostly)

# Set values for undefined arguments
if [ -z "$VAR" ]; then
if grep -qw "$FLAG" <<< "$ARGS"; then
if [[ $ARGTYPE =~ "cb" ]] || [[ $ARGTYPE =~ "num" ]]; then
# Get the value given to the argument as the enabled/selected value, e.g. get '2' from '-U 2' if we passed '-U'
tr ' ' '\n' <<< "$ARGS" | grep -wA1 "$FLAG" | tail -n1
elif [[ $ARGTYPE =~ "path" ]] || [[ $ARGTYPE =~ "txt" ]]; then
# Get value given to arguments with two dashes, like `--`
echo "$ARGS" | sed 's:--:\n--:g' | grep -wA1 "$FLAG" | sed "s:${UNESCAPED_FLAG}::g;s:-:\n-:g" | head -n1 | xargs
else
echo "$TRUEVAL"
fi
if [ -n "$VAR" ]; then
return
fi

# If the flag is not in the args string, return the default value for display purposes
if ! grep -qw "$FLAG" <<< "$ARGS"; then
echo "$DEFVAL"
return
fi

if [[ $ARGTYPE =~ "cb" ]] || [[ $ARGTYPE =~ "num" ]]; then
# Get the value given to the argument as the enabled/selected value, e.g. get '2' from '-U 2' if we passed '-U'
# If the value does not contain only numbers (with or without decimals) then this will be blank and we return the default value 'DEFVAL'
GSPARSEDARGVAL="$( tr ' ' '\n' <<< "$ARGS" | grep -wA1 "$FLAG" | tail -n1 )"

# Don't validate parsed value for combobox, this is free-text and could be anything
if ! [[ $ARGTYPE =~ "num" ]]; then
echo "$GSPARSEDARGVAL"
return
fi

# If we get passed an invalid GameScope commandline argument where a flag that is supposed to be followed by a NUMBER is not,
# we could end up returning the next argument, e.g. `-s -f` would return `-s` if we didn't include the `grep -P`
# Using the `grep -P` we filter out potential garbage returned by the rest of the parsing.
#
# We are most likely to encounter problems without this `grep -P` when it comes to the `GSINTRES` and `GSSHWRES`,
# as if these are blank we end up displaying 'x'.
#
# For comboboxes that can display text, we will just have to assume we are passed a valid string, as freetext comboboxes could contain
# anything and we cannot/should not try to assume what is valid for them in this way.
# This logic only exists to filter out non-numerical values for flags which expect to be given a numerical argument
#
# For more background, see: https://github.com/sonic2kk/steamtinkerlaunch/pull/1152#issuecomment-2316286429
GSPARSEDARGNUMVAL="$( echo "${GSPARSEDARGVAL}" | grep -P "^([\d]+)(?:\.([\d]{1,2}?))?$" )"
if [ -n "${GSPARSEDARGNUMVAL}" ]; then
echo "$GSPARSEDARGNUMVAL"
else
echo "$DEFVAL"
fi
elif [[ $ARGTYPE =~ "path" ]] || [[ $ARGTYPE =~ "txt" ]]; then
# Get value given to arguments with two dashes, like `--`
echo "$ARGS" | sed 's:--:\n--:g' | grep -wA1 "$FLAG" | sed "s:${UNESCAPED_FLAG}::g;s:-:\n-:g" | head -n1 | xargs
else
echo "$TRUEVAL"
fi
}

function getGameScopeGeneralOpts {
# GameScope Show Resolution (corresponds to -W, -H options, uppercase) -- Actual GameScope window size -- Dropdown
if [ -z "$GSSHWRES" ]; then
if ! grep -qw "\-W" <<< "$GAMESCOPE_ARGS" || ! grep -qw "\-H" <<< "$GAMESCOPE_ARGS"; then
GSSHWRES="1280x720"
else
GSSHWRES="$(tr ' ' '\n' <<< "$GAMESCOPE_ARGS" | grep -wA1 "\-W" | tail -n1)x$(tr ' ' '\n' <<< "$GAMESCOPE_ARGS" | grep -wA1 "\-H" | tail -n1)"
fi
fi
# GameScope Show Resolution (corresponds to -W, -H options, uppercase) -- Actual GameScope window size (defaults to 1280x720) -- Dropdown
# Although this is a combobox, we still use "num" as the `getGameScopeArg` type because we want numeric validation
GSSHOWRESARGWIDTH="$( getGameScopeArg "$GAMESCOPE_ARGS" "-W" "$GSSHOWRESARGWIDTH" "" "1280" "num")"
GSSHOWRESARGHEIGHT="$( getGameScopeArg "$GAMESCOPE_ARGS" "-H" "$GSSHOWRESARGHEIGHT" "" "720" "num")"

# GameScope Internal Resolution (corresponds to -w, -h options, lowercase) -- Resolution that games see -- Dropdown
if [ -z "$GSINTRES" ]; then
if ! grep -qw "\-w" <<< "$GAMESCOPE_ARGS" || ! grep -qw "\-h" <<< "$GAMESCOPE_ARGS"; then
GSINTRES="1280x720"
else
GSINTRES="$(tr ' ' '\n' <<< "$GAMESCOPE_ARGS" | grep -wA1 "\-w" | tail -n1)x$(tr ' ' '\n' <<< "$GAMESCOPE_ARGS" | grep -wA1 "\-h" | tail -n1)"
fi
fi
GSSHWRES="${GSSHOWRESARGWIDTH}x${GSSHOWRESARGHEIGHT}"

# GameScope Internal Resolution (corresponds to -w, -h options, lowercase) -- Resolution that games see (defaults to 1280x720) -- Dropdown
# Although this is a combobox, we still use "num" as the `getGameScopeArg` type because we want numeric validation
GSINTRESARGWIDTH="$( getGameScopeArg "$GAMESCOPE_ARGS" "-w" "$GSINTRESARGWIDTH" "" "1280" "num")"
GSINTRESARGHEIGHT="$( getGameScopeArg "$GAMESCOPE_ARGS" "-h" "$GSINTRESARGHEIGHT" "" "720" "num")"

GSINTRES="${GSINTRESARGWIDTH}x${GSINTRESARGHEIGHT}"

# Default internal resolution to $NON ('none') if blank -- Ensures we don't pass invalid resolution to GameScope
if [ -z "$GSINTRES" ]; then GSINTRES="$NON"; fi
Expand Down Expand Up @@ -11799,19 +11825,25 @@ function GameScopeGui {

# Build the GameScope arguments string
unset GAMESCOPE_ARGS
GAMESCOPE_ARGS=""

# Internal width/height (-w, -h) broken out from string like '1280x720'
# NOTE: In future if `GSINTW` is blank but `GSINTH` is set, we could calculate a corresponding 16:9 width like GameScope does
GSINTW1="${GSINTRES%x*}"
GSINTW="${GSINTW1%%-*}"
GSINTH1="${GSINTRES#*x}"
GSINTH="${GSINTH1%%-*}"
GAMESCOPE_ARGS="-w ${GSINTW} -h ${GSINTH}"

# Show width/height (-W, -H) broken out from string like '1280x720'
# NOTE: In future if `GSINTW` is blank but `GSINTH` is set, we could calculate a corresponding 16:9 width like GameScope does
GSSHWW1="${GSSHWRES%x*}"
GSSHWW="${GSSHWW1%%-*}"
GSSHWH1="${GSSHWRES#*x}"
GSSHWH="${GSSHWH1%%-*}"
GAMESCOPE_ARGS="${GAMESCOPE_ARGS} -W ${GSSHWW} -H ${GSSHWH}"

### GENERAL OPTIONS ###
if [ -n "$GSINTW" ] && [ -n "$GSINTH" ] ; then GAMESCOPE_ARGS="${GAMESCOPE_ARGS} -w ${GSINTW} -h ${GSINTH}"; fi
if [ -n "$GSSHWW" ] && [ -n "$GSSHWH" ] ; then GAMESCOPE_ARGS="${GAMESCOPE_ARGS} -W ${GSSHWW} -H ${GSSHWH}"; fi
if [ "$GSFLR" -eq "$GSFLR" ] 2>/dev/null ; then GAMESCOPE_ARGS="${GAMESCOPE_ARGS} -r ${GSFLR}"; fi
if [ "$GSFLU" -eq "$GSFLU" ] 2>/dev/null ; then GAMESCOPE_ARGS="${GAMESCOPE_ARGS} -o ${GSFLU}"; fi
if [ "$GSFS" == "TRUE" ] ; then GAMESCOPE_ARGS="${GAMESCOPE_ARGS} -f"; fi
Expand Down Expand Up @@ -11953,7 +11985,8 @@ function GameScopeGui {
if [ "$GSHDLS" == "TRUE" ] ; then GAMESCOPE_ARGS="${GAMESCOPE_ARGS} --headless"; fi
### ADVANCED OPTIONS END ###

GAMESCOPE_ARGS="${GAMESCOPE_ARGS} --"
# Remove trailing whitespace and append '--'
GAMESCOPE_ARGS="${GAMESCOPE_ARGS# } --"

writelog "INFO" "${FUNCNAME[0]} - Saving configured GAMESCOPE_ARGS '$GAMESCOPE_ARGS' into '$STLGAMECFG'"
touch "$FUPDATE"
Expand Down