Skip to content

Commit

Permalink
Add some checks to restoreOrgVars on startGame (#1161)
Browse files Browse the repository at this point in the history
  • Loading branch information
HanPrower authored Sep 4, 2024
1 parent 4eef095 commit c174a06
Showing 1 changed file with 30 additions and 12 deletions.
42 changes: 30 additions & 12 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.20240903-2"
PROGVERS="v14.0.20240904-1"
PROGCMD="${0##*/}"
PROGINTERNALPROTNAME="Proton-stl"
SHOSTL="stl"
Expand Down Expand Up @@ -7208,7 +7208,7 @@ function extProtonRun {
# Hopefully unsetting is safe and doesn't mean places that need the SLR will lose it from this 'unset'
if [ "$EXTPROTUSESLR" -eq 1 ]; then
writelog "INFO" "${FUNCNAME[0]} - EXTPROTUSESLR is '$EXTPROTUSESLR' -- Attempting to find and use SLR with extProtonRun"

unset "${SLRCMD[@]}"
setSLRReap
fi
Expand Down Expand Up @@ -7782,7 +7782,7 @@ function getGameWindowPID {

return
fi

MAXWAIT=20
COUNTER=0
TESTPID="$NON"
Expand Down Expand Up @@ -12971,7 +12971,7 @@ function launchCustomProg {
writelog "INFO" "${FUNCNAME[0]} - FORK_CUSTOMCMD is set to 1 - forking the custom program in background and continue"
extProtonRun "FC" "$LACO" "$CUSTOMCMD_ARGS" "" "${CUSTOMCMD_USESLR}"
elif [ "$ONLY_CUSTOMCMD" -eq 1 ] && [ -n "${FINALOUTCMD[*]}" ]; then
writelog "INFO" "${FUNCNAME[0]} - ONLY_CUSTOMCMD is set to 1 and we have some arguments in FINALOUTCMD - passing to extProtonRun to build a valid start command"
writelog "INFO" "${FUNCNAME[0]} - ONLY_CUSTOMCMD is set to 1 and we have some arguments in FINALOUTCMD - passing to extProtonRun to build a valid start command"
extProtonRun "R" "$LACO" "$CUSTOMCMD_ARGS" "$FINALOUTCMD" "${CUSTOMCMD_USESLR}" # extProtonRun will handle adding the FINALOUTCMD args to
else
extProtonRun "RC" "$LACO" "$CUSTOMCMD_ARGS" "" "${CUSTOMCMD_USESLR}"
Expand Down Expand Up @@ -13017,7 +13017,7 @@ function launchCustomProg {

writelog "INFO" "${FUNCNAME[0]} - Steam Linux Runtime enabled, attempting to fetch Steam Linux Runtime for native Custom Command"
# "2" is the FORCESLRTYPE, meaning we want to force to get the native SLR -- We do this in case we are trying to launch a native custom command with a Proton title
# In this case, setSLRReap is going to have the Proton SLR vars set from the game launch, so we need to force it here to use the native SLR
# In this case, setSLRReap is going to have the Proton SLR vars set from the game launch, so we need to force it here to use the native SLR
setNonGameSLRReap "2"
fi

Expand Down Expand Up @@ -17859,7 +17859,7 @@ function prepareMO2 {
}

function createMO2SilentModeExeProfilesList {
# Get all of the ModOrganizer 2 executables launch configurations in the instance's INI
# Get all of the ModOrganizer 2 executables launch configurations in the instance's INI
# The user can use this to override which 'moshortcut://' is launched in Silent Mode
MO2SILENTMODEEXEPROFILES="$NON"
MO2GAMES="$GLOBALMISCDIR/mo2games.txt"
Expand Down Expand Up @@ -20308,7 +20308,7 @@ function startGame {
writelog "INFO" "${FUNCNAME[0]} - ## STL LAUNCH COMMAND: '${RUNCMD[*]}'"
writelog "INFO" "${FUNCNAME[0]} - ## GAMESTART HERE ###"

restoreOrgVars # restore original LC_ and friends for the game
restoreOrgVars

GRUNLOG="$STLGLLOGDIRID/${AID}.log"
if [ "$ISORIGIN" -eq 1 ]; then
Expand Down Expand Up @@ -25333,13 +25333,19 @@ function closeSTL {
# main:#################

function saveOrgVars {
# TODO resolve the unused warnings by dynamically assigning the variables like we do in 'restoreOrgVars'

writelog "INFO" "${FUNCNAME[0]} - Storing some original variables to restore them later" "P"

env | grep "=" | sort -o "$VARSIN"

# shellcheck disable=2034
ORG_LD_PRELOAD="$LD_PRELOAD"
# shellcheck disable=2034
ORG_LD_LIBRARY_PATH="$LD_LIBRARY_PATH"
# shellcheck disable=2034
ORG_LC_ALL="$LC_ALL"
# shellcheck disable=2034
ORG_PATH="$PATH"
}

Expand Down Expand Up @@ -25423,11 +25429,23 @@ function unsetSTLvars {
}

function restoreOrgVars {
writelog "INFO" "${FUNCNAME[0]} - Restoring previously cleared Variables"
LD_PRELOAD="$ORG_LD_PRELOAD"
LD_LIBRARY_PATH="$ORG_LD_LIBRARY_PATH"
LC_ALL="$ORG_LC_ALL"
PATH="$ORG_PATH"
writelog "INFO" "${FUNCNAME[0]} - Restoring previously cleared environment variables"

STLRESTOREVARS=( "LD_PRELOAD" "LD_LIBRARY_PATH" "LC_ALL" "PATH" )
for RESTOREVAR in "${STLRESTOREVARS[@]}"; do

# e.g. 'ORG_LD_PRELOAD' for 'LD_PRELOAD' on first iteration of the loop
BUILTORGVARNAME="\$ORG_${RESTOREVAR}"

# Check if the envvar has been defined in a custom-vars conf file, if so don't restore it and continue
if grep -q "^${RESTOREVAR}" "$GLOBCUSTVARS" || grep -q "^${RESTOREVAR}" "$GAMECUSTVARS"; then
writelog "WARN" "${FUNCNAME[0]} - Not restoring '${RESTOREVAR}' to original value as it is defined in a custom-vars conf file. This may potentially cause issues."

continue
fi

eval "${RESTOREVAR}=\"${BUILTORGVARNAME}\""
done
}

function rmOldLog {
Expand Down

0 comments on commit c174a06

Please sign in to comment.