From eb7166980fb1e6f7e7945674c0556bc864056f65 Mon Sep 17 00:00:00 2001
From: Simon McVittie <smcv@collabora.com>
Date: Tue, 8 Sep 2020 15:26:26 +0100
Subject: [PATCH] runtime: Set STEAM_RUNTIME=/ if running in scout

This should go some way towards resolving failures to run games ported
by Feral Interactive, which explicitly check that they have been run
by Steam. See
<https://github.com/ValveSoftware/steam-runtime/issues/202> and
<https://github.com/ValveSoftware/steam-runtime/issues/249>.

Resolves: pressure-vessel#8
Signed-off-by: Simon McVittie <smcv@collabora.com>
---
 src/runtime.c           | 10 ++++++++++
 tests/inside-runtime.py |  6 +++++-
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/src/runtime.c b/src/runtime.c
index a670ddec4..e820ec257 100644
--- a/src/runtime.c
+++ b/src/runtime.c
@@ -3222,6 +3222,16 @@ pv_runtime_bind (PvRuntime *self,
       self->adverb_in_container = "/run/pressure-vessel/pv-from-host/bin/pressure-vessel-adverb";
     }
 
+  /* Some games detect that they have been run outside the Steam Runtime
+   * and try to re-run themselves via Steam. Trick them into thinking
+   * they are in the LD_LIBRARY_PATH Steam Runtime.
+   *
+   * We do not do this for games developed against soldier, because
+   * backwards compatibility is not a concern for game developers who
+   * have specifically opted-in to using the newer runtime. */
+  if (self->is_scout)
+    flatpak_bwrap_set_env (bwrap, "STEAM_RUNTIME", "/", TRUE);
+
   pv_runtime_set_search_paths (self, bwrap);
 
   return TRUE;
diff --git a/tests/inside-runtime.py b/tests/inside-runtime.py
index a283ade91..3d384b5bd 100755
--- a/tests/inside-runtime.py
+++ b/tests/inside-runtime.py
@@ -152,7 +152,11 @@ class TestInsideRuntime(BaseTest):
         logger.info(
             'LD_LIBRARY_PATH: %r', os.environ.get('LD_LIBRARY_PATH')
         )
-        # No actual *tests* here just yet - we just log what's there.
+
+        if os.environ.get('TEST_INSIDE_RUNTIME_IS_SCOUT'):
+            self.assertEqual(os.environ.get('STEAM_RUNTIME'), '/')
+        elif os.environ.get('TEST_INSIDE_RUNTIME_IS_SOLDIER'):
+            self.assertEqual(os.environ.get('STEAM_RUNTIME'), None)
 
     def test_overrides(self) -> None:
         if os.getenv('TEST_INSIDE_RUNTIME_IS_COPY'):
-- 
GitLab