diff --git a/patches/tModLoader/Terraria/ModLoader/Engine/Steam.cs b/patches/tModLoader/Terraria/ModLoader/Engine/Steam.cs index 57516875b56..629e425fda9 100644 --- a/patches/tModLoader/Terraria/ModLoader/Engine/Steam.cs +++ b/patches/tModLoader/Terraria/ModLoader/Engine/Steam.cs @@ -44,11 +44,12 @@ internal class Steam } internal static void SetAppId(AppId_t appId) { - Environment.SetEnvironmentVariable("STEAMGAMEID", appId.ToString()); - Environment.SetEnvironmentVariable("STEAMOVERLAYGAMEID", appId.ToString()); - Environment.SetEnvironmentVariable("STEAMAPPID", appId.ToString()); - //File.WriteAllText("steam_appid.txt", appId.ToString()); - File.Delete("steam_appid.txt"); + if (Environment.GetEnvironmentVariable("SteamClientLaunch") != "1") { + File.WriteAllText("steam_appid.txt", appId.ToString()); + } + else if (Environment.GetEnvironmentVariable("SteamAppId") != appId.ToString()) { + throw new Exception("Cannot overwrite steam env. SteamAppId=" + Environment.GetEnvironmentVariable("SteamAppId")); + } } } } diff --git a/patches/tModLoader/Terraria/ModLoader/Engine/TerrariaSteamClient.cs b/patches/tModLoader/Terraria/ModLoader/Engine/TerrariaSteamClient.cs index 7302c140996..5807e3f52bb 100644 --- a/patches/tModLoader/Terraria/ModLoader/Engine/TerrariaSteamClient.cs +++ b/patches/tModLoader/Terraria/ModLoader/Engine/TerrariaSteamClient.cs @@ -1,9 +1,12 @@ using log4net; using Steamworks; using System; +using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.IO.Pipes; +using System.Linq; +using System.Reflection; using System.Threading; namespace Terraria.ModLoader.Engine @@ -28,20 +31,29 @@ public enum LaunchResult } internal static LaunchResult Launch() { - if (Environment.GetEnvironmentVariable("STEAMCLIENTLAUNCH") != "1") { + if (Environment.GetEnvironmentVariable("SteamClientLaunch") != "1") { Logger.Debug("Disabled. Launched outside steam client."); return LaunchResult.Ok; } serverPipe = new AnonymousPipeServerStream(PipeDirection.Out, HandleInheritability.Inheritable); + var tMLName = Path.GetFileName(Assembly.GetExecutingAssembly().Location); var proc = new Process() { StartInfo = { FileName = Environment.ProcessPath, - Arguments = $"tmodloader.dll -terrariasteamclient {serverPipe.GetClientHandleAsString()}", + Arguments = $"{tMLName} -terrariasteamclient {serverPipe.GetClientHandleAsString()}", UseShellExecute = false, RedirectStandardOutput = true } }; + + // clear steam env vars + foreach (var k in ((IEnumerable)proc.StartInfo.EnvironmentVariables.Keys).ToArray()) { + if (k.StartsWith("steam", StringComparison.InvariantCultureIgnoreCase)) { + proc.StartInfo.EnvironmentVariables.Remove(k); + } + } + proc.Start(); while (true) { diff --git a/patches/tModLoader/Terraria/release_extras/LaunchUtils/BashUtils.sh b/patches/tModLoader/Terraria/release_extras/LaunchUtils/BashUtils.sh index 9acae888902..1540cc19c26 100644 --- a/patches/tModLoader/Terraria/release_extras/LaunchUtils/BashUtils.sh +++ b/patches/tModLoader/Terraria/release_extras/LaunchUtils/BashUtils.sh @@ -28,5 +28,7 @@ file_download() { # Call a script setting its permission right for execution run_script() { chmod a+x "$1" - "$@" + + # LD_PRELOAD="" fixes error messages from steams library linking polluting the stdout of all programs(in tree) run by run_script + LD_PRELOAD="" "$@" } diff --git a/patches/tModLoader/Terraria/release_extras/LaunchUtils/InstallNetFramework.sh b/patches/tModLoader/Terraria/release_extras/LaunchUtils/InstallNetFramework.sh index 2088ace31db..62959ba3e6d 100644 --- a/patches/tModLoader/Terraria/release_extras/LaunchUtils/InstallNetFramework.sh +++ b/patches/tModLoader/Terraria/release_extras/LaunchUtils/InstallNetFramework.sh @@ -78,14 +78,12 @@ if [[ ! -f "$install_dir/dotnet" && ! -f "$install_dir/dotnet.exe" ]]; then # *nix binaries are various and not worth detecting the required one here, always use "on-the-fly" script install file_download dotnet-install.sh https://dot.net/v1/dotnet-install.sh - run_script ./dotnet-install.sh --channel "$channel" --install-dir "$install_dir" --runtime "dotnet" --version "$dotnet_version" + run_script ./dotnet-install.sh --channel "$channel" --install-dir "$install_dir" --runtime "dotnet" --version "$dotnet_version" --verbose fi fi echo "Dotnet should be present in \"$install_dir\"" -# @TODO: Re-evaluate if this needed if [[ ! -f "$install_dir/dotnet" && ! -f "$install_dir/dotnet.exe" ]]; then echo -e "${TXTCOLOR_RED}Download of portable dotnet runtime seems to have failed,${TXTCOLOR_NC}" - echo -e "${TXTCOLOR_RED}proceeding will probably use system wide installed runtime${TXTCOLOR_NC}" - read -p "Please press Enter to try to run the game anyway... " + echo -e "${TXTCOLOR_RED}Proceeding will probably fall back to system wide installed runtime${TXTCOLOR_NC}" fi diff --git a/patches/tModLoader/Terraria/release_extras/LaunchUtils/ScriptCaller.sh b/patches/tModLoader/Terraria/release_extras/LaunchUtils/ScriptCaller.sh index 1506342339a..e36ae08202f 100644 --- a/patches/tModLoader/Terraria/release_extras/LaunchUtils/ScriptCaller.sh +++ b/patches/tModLoader/Terraria/release_extras/LaunchUtils/ScriptCaller.sh @@ -65,20 +65,25 @@ echo "Attempting Launch..." # Move to the root folder cd "$root_dir" -export STEAMGAMEID="" -export STEAMOVERLAYGAMEID="" -export STEAMAPPID="" - if [[ "$_uname" == *"_NT"* ]]; then # Replace / with \\ in WINDIR env var to not confuse MonoMod about the current platform # somehow busybox-w64 replaces paths in envs with normalized paths (no clue why..., maybe open an issue there?) export WINDIR=${WINDIR////\\} + + clear + sleep 1 # wait a little extra time for steam to realise that our parent process has exited +else + # Kill the Steam reaper process on Linux/Mac? + # Sed replace all null bytes(and spaces) with spaces, grep for reaper marker. + if $(sed 's/\x0/ /g' /proc/$PPID/cmdline | grep -q "reaper SteamLaunch AppId=1281930"); then + echo "Running under Steam reaper process. Killing.." 2>&1 | tee -a "$LogFile" + kill -9 $PPID # _yeet_ + fi fi -clear if [[ -f "$install_dir/dotnet" || -f "$install_dir/dotnet.exe" ]]; then echo "Launched Using Local Dotnet" 2>&1 | tee -a "$LogFile" - chmod a+x "$install_dir/dotnet" + [[ -f "$install_dir/dotnet" ]] && chmod a+x "$install_dir/dotnet" exec "$install_dir/dotnet" tModLoader.dll "$@" 2>"$NativeLog" else echo "Launched Using System Dotnet" 2>&1 | tee -a "$LogFile" diff --git a/patches/tModLoader/Terraria/release_extras/start-tModLoader.sh b/patches/tModLoader/Terraria/release_extras/start-tModLoader.sh index dbf00287f78..634dde0e3b4 100644 --- a/patches/tModLoader/Terraria/release_extras/start-tModLoader.sh +++ b/patches/tModLoader/Terraria/release_extras/start-tModLoader.sh @@ -2,5 +2,5 @@ cd "$(dirname "$0")" chmod a+x ./LaunchUtils/ScriptCaller.sh -./LaunchUtils/ScriptCaller.sh "$@" & -disown -r +# forward our parent process id to the child in case ScriptCaller needs to kill the parent to break free of steam's process lifetime tracker (reaper) +PPID=$PPID ./LaunchUtils/ScriptCaller.sh "$@" & diff --git a/patches/tModLoader/Terraria/release_extras/start-tModLoaderServer.sh b/patches/tModLoader/Terraria/release_extras/start-tModLoaderServer.sh index 93228c083f2..d20bdeefa6e 100644 --- a/patches/tModLoader/Terraria/release_extras/start-tModLoaderServer.sh +++ b/patches/tModLoader/Terraria/release_extras/start-tModLoaderServer.sh @@ -22,4 +22,4 @@ if [ $steam = "y" ]; then fi chmod +x ./LaunchUtils/ScriptCaller.sh -./start-tModLoader.sh $launch_args \ No newline at end of file +./LaunchUtils/ScriptCaller.sh $launch_args