From 2d51012315171a4e7a5e50515c730444da9a95c6 Mon Sep 17 00:00:00 2001 From: Eamonn Rea Date: Thu, 20 Jun 2024 19:29:50 +0100 Subject: [PATCH] misc: Fix commands being interpreted as game launch if command included `steamapps/common` (#1125) Noticed this when I tried to run a custom command for an executable in a game folder and it kept trying to launch the game, and realised we default to a game launch if the command contains `steamapps/common` in its string, even if it's part of an argument. Fixes cases where `otr --exe="/home/gaben/.local/share/Steam/steamapps/common/hl3.exe"` would be interpreted as a game launch because the One-Time Run executable path contained `steamapps/common`. This allows One-Time Run to work with executables in the game's install folder. We fix this by introducing a check to the first argument to a script. If the FIRST argument ONLY does not contain any forward-slashes AND if it matches a preset list of keywords, we assume it is a commandline argument and send it straight to the `commandline` function. So with `steamtinkerlaunch otr --exepath="/home/gaben/.local/share/Steam/steamapps/common/hl3.exe"`, we can detect that it is the One-Time Run command because the first command is `otr`. However, `/home/otrlol/.local/share/Steam` would be ignored, so if the first argument is a path to the Steam Linux Runtime or something coming from Steam, we ignore it because `otr` needs to be a whole word. Similarly, even `/home/otr` would be ignored, because this check explicitly ignores the first argument if it contains any slashes at all (SteamTinkerLaunch command names never start with a slash, you can ever have `otr` but you could have `otr --exe="/home/blah/blah"`, but `--exe` is the 2nd argument (`$2`) and we only check the 1st (`$1`). --- steamtinkerlaunch | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/steamtinkerlaunch b/steamtinkerlaunch index 813f50d4..3c0a5a9d 100755 --- a/steamtinkerlaunch +++ b/steamtinkerlaunch @@ -7,7 +7,7 @@ PREFIX="/usr" PROGNAME="SteamTinkerLaunch" NICEPROGNAME="Steam Tinker Launch" -PROGVERS="v14.0.20240619-1" +PROGVERS="v14.0.20240621-1" PROGCMD="${0##*/}" PROGINTERNALPROTNAME="Proton-stl" SHOSTL="stl" @@ -26840,6 +26840,7 @@ function main { writelog "INFO" "${FUNCNAME[0]} - No arguments provided. See '$PROGCMD --help' for possible command line parameters" "E" else writelog "INFO" "${FUNCNAME[0]} - Checking command line: incoming arguments '${*}'" + writelog "INFO" "${FUNCNAME[0]} - Checking command line: first argument '${1}'" if [ -n "$SteamAppId" ] && [ "$SteamAppId" -eq "0" ]; then if grep -q "\"$1\"" <<< "$(sed -n "/^#STARTCMDLINE/,/^#ENDCMDLINE/p;/^#ENDCMDLINE/q" "$0" | grep if)"; then @@ -26856,9 +26857,24 @@ function main { fi fi elif grep -q "$SAC" <<< "$@" || grep -q "$L2EA" <<< "$@"; then + # We check if incoming commands contain 'steamapps/common' to interpret them as game launch commands + # But if $1 is a known command in this list, explicitly pass it to 'commandline' as we know it is NOT a game command + # This prevents commands which contain 'steamapps/common' ANYWHERE in their command (including as paths as parameters to other flags) from being interpreted as a game launch + # + # If $1 is a known steamtinkerlaunch command (with 'steamtinkerlaunch otr', $1 would be 'otr') then intervene and force this to the 'commandline' function as it is a known steamtinkerlaunch command + STLINCOMINGSKIPCOMMANDS="otr|onetimerun" + if grep -q "update" <<< "$@" || grep -q "^play" <<< "$@" ; then commandline "$@" + # HACK: Since we check for steamapps/common ($SAC), commands which contain this (such as a one-time run path) will incorrectly get triggered as a game launch + # As a workaround, skip interpreting a hardcoded set of commands as start parameters and pass directly to commandline (i.e. if we have 'otr' as our first option, pass down to commandline function and run otr) + # + # We also check to make sure the first argument doesn't contain any slashes (i.e. game start commands' first argument could be a path, so it would contain a slash) + # This allows us to distinguish between '/home/otr' which could be a game launch command, and the 'steamtinkerlaunch otr' command (where $1 is 'otr') + elif grep -qwE "${STLINCOMINGSKIPCOMMANDS}" <<< "${1}" && [[ "${1}" != *"/"* ]]; then + commandline "$@" else + # If we get here, this should be an actual game start command! setGameVars "$@" if [ "$ISGAME" -eq 2 ] || [ "$ISGAME" -eq 3 ]; then prepareLaunch