>(emptyList())
private var linuxSteam by mutableStateOf("")
private var linuxDesktop by mutableStateOf("")
@@ -116,6 +120,7 @@ class MainActivity : ComponentActivity() {
onFrameGen = { showFrameGen = true },
onProtons = { refreshProtons(); showProtons = true },
onDrivers = { refreshDrivers(); showDrivers = true },
+ onAudio = { directAudio = SessionPrefs.directAudio(this); mic = SessionPrefs.micEnabled(this); showAudio = true },
onCredits = { showCredits = true },
)
if (showApps) DesktopAppsDialog(
@@ -142,6 +147,20 @@ class MainActivity : ComponentActivity() {
onRemoveAndroid = { id -> TurnipDriver(this).remove(id); refreshDrivers() },
onDismiss = { showDrivers = false },
)
+ if (showAudio) AudioDialog(
+ directAudio = directAudio, mic = mic,
+ onDirectAudio = { on -> SessionPrefs.setDirectAudio(this, on); directAudio = on },
+ onMic = { on ->
+ SessionPrefs.setMicEnabled(this, on)
+ mic = on
+ // The session checks the grant itself at start; asking here means the
+ // answer is in before the first session that wants it.
+ if (on && checkSelfPermission(Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) {
+ requestPermissions(arrayOf(Manifest.permission.RECORD_AUDIO), 2)
+ }
+ },
+ onDismiss = { showAudio = false },
+ )
if (showRemove) ConfirmDialog(
title = "Remove Linux runtime",
text = "This deletes the runtime, the Steam client inside it, and every game installed there.",
diff --git a/app/src/main/java/com/steamdeck/launcher/audio/DirectAudioRelayComponent.java b/app/src/main/java/com/steamdeck/launcher/audio/DirectAudioRelayComponent.java
new file mode 100644
index 0000000000..9f872e1d43
--- /dev/null
+++ b/app/src/main/java/com/steamdeck/launcher/audio/DirectAudioRelayComponent.java
@@ -0,0 +1,108 @@
+package com.steamdeck.launcher.audio;
+
+import android.os.Process;
+import android.util.Log;
+
+import com.steamdeck.launcher.core.EnvironmentComponent;
+import com.steamdeck.launcher.core.ProcessHelper;
+
+import java.io.File;
+import java.util.ArrayList;
+
+/**
+ * The DirectAudio relay helper, which owns Android's speaker and microphone on behalf of a Linux
+ * session.
+ *
+ * Nothing inside the session can open Android's audio itself. A game is a glibc process in a
+ * rootfs that binds no {@code /system}, and a glibc process cannot call libaaudio at all; the
+ * session is also never given a way to spawn a bionic helper of its own. So the helper runs out
+ * here, under the app's own uid, and the driver inside Wine talks to it over a unix socket. The uid
+ * matters for more than tidiness: Android checks the microphone permission against whoever opens
+ * the stream, so a helper started any other way could play but never record.
+ *
+ *
It is executed from the app's native library directory because Android will not execute a
+ * binary from anywhere else - the same reason the PulseAudio daemon ships as {@code
+ * libpulseaudio.so} despite being a program rather than a library.
+ *
+ *
Started before the client, because the driver asks once whether a helper is there, when Wine
+ * picks an audio driver, and reports itself unavailable if not. Ported from Bannerlator (GPL-3.0);
+ * the helper binary is the one built by The412Banner/directaudio's relay workflow.
+ */
+public class DirectAudioRelayComponent extends EnvironmentComponent {
+ private static final String TAG = "DirectAudioRelay";
+ /** The helper, named as a library so Android will run it. */
+ public static final String BINARY = "libdirectaudiorelay.so";
+
+ private final File socketPath;
+ /** Null when the microphone was not asked for; the helper then opens no input stream. */
+ private final File micFifoPath;
+ private int pid = -1;
+
+ public DirectAudioRelayComponent(File socketPath, File micFifoPath) {
+ this.socketPath = socketPath;
+ this.micFifoPath = micFifoPath;
+ }
+
+ @Override
+ public void start() {
+ stop();
+ File binary = new File(context.getApplicationInfo().nativeLibraryDir, BINARY);
+ if (!binary.isFile()) {
+ Log.w(TAG, "helper missing at " + binary + "; DirectAudio will report itself unavailable");
+ return;
+ }
+ File parent = socketPath.getParentFile();
+ if (parent != null) {
+ //noinspection ResultOfMethodCallIgnored
+ parent.mkdirs();
+ }
+ // A socket left by a session that did not shut down cleanly is not a listener, and the
+ // helper would fail to bind onto it.
+ //noinspection ResultOfMethodCallIgnored
+ socketPath.delete();
+
+ // PulseAudio's pipe module insists on creating the pipe itself and fails if one is already
+ // there. The helper creates one too when the path is missing, and it starts a few
+ // milliseconds after the daemon is exec'd - well before the daemon has read its config. So
+ // left to itself the helper won its own race, the daemon's mkfifo failed with EEXIST, and
+ // the microphone was lost while everything else came up. Wait for the daemon to make the
+ // pipe before the helper runs; it appears within a second, and if it never does the helper
+ // starts anyway and creates it, which is the right thing when the daemon is not involved.
+ if (micFifoPath != null) {
+ long deadline = System.currentTimeMillis() + 3000L;
+ while (!micFifoPath.exists() && System.currentTimeMillis() < deadline) {
+ try {
+ Thread.sleep(50L);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ break;
+ }
+ }
+ Log.i(TAG, micFifoPath.exists() ? "microphone pipe made by the daemon; starting helper"
+ : "daemon did not make the microphone pipe in 3 s; helper will make it");
+ }
+
+ StringBuilder command = new StringBuilder(binary.getAbsolutePath());
+ command.append(" --socket ").append(socketPath.getAbsolutePath());
+ if (micFifoPath != null) {
+ // The helper creates the pipe if it is not there. PulseAudio is told the same path and
+ // reads from the other end of it.
+ command.append(" --mic-fifo ").append(micFifoPath.getAbsolutePath());
+ }
+ ArrayList env = new ArrayList<>();
+ env.add("HOME=" + context.getFilesDir());
+ pid = ProcessHelper.exec(command.toString(), env.toArray(new String[0]), context.getFilesDir());
+ Log.i(TAG, "started pid=" + pid + " socket=" + socketPath
+ + (micFifoPath != null ? " mic=" + micFifoPath : " (no microphone)"));
+ }
+
+ @Override
+ public void stop() {
+ if (pid != -1) {
+ // The helper exits on a signal and tears down its streams; there is nothing below it to
+ // orphan, unlike the proot tree.
+ Process.killProcess(pid);
+ pid = -1;
+ }
+ }
+}
diff --git a/app/src/main/java/com/steamdeck/launcher/audio/PulseAudioComponent.java b/app/src/main/java/com/steamdeck/launcher/audio/PulseAudioComponent.java
index 54d696ffd3..7ea51058df 100644
--- a/app/src/main/java/com/steamdeck/launcher/audio/PulseAudioComponent.java
+++ b/app/src/main/java/com/steamdeck/launcher/audio/PulseAudioComponent.java
@@ -32,10 +32,23 @@ public class PulseAudioComponent extends EnvironmentComponent {
public static final String SOCKET_NAME = "PS0";
private final File workingDir;
+ /**
+ * A named pipe carrying microphone audio, or null for no microphone. The bundle ships
+ * module-aaudio-sink but no matching source, and the daemon runs where Android permits
+ * recording - so pointing module-pipe-source at a pipe the DirectAudio relay helper writes
+ * turns that one stream into a source the client can see, named DirectAudioMic.
+ */
+ private final String micFifoPath;
private int pid = -1;
public PulseAudioComponent(Context context) {
+ this(context, null);
+ }
+
+ /** As above, with a microphone fed from {@code micFifoPath}; null for output only. */
+ public PulseAudioComponent(Context context, String micFifoPath) {
this.workingDir = new File(context.getFilesDir(), "pulseaudio");
+ this.micFifoPath = micFifoPath;
}
public File socket() {
@@ -60,13 +73,32 @@ public class PulseAudioComponent extends EnvironmentComponent {
//noinspection ResultOfMethodCallIgnored
socket().delete();
- FileUtils.writeString(new File(workingDir, "default.pa"), String.join("\n",
- "load-module module-native-protocol-unix auth-anonymous=1 auth-cookie-enabled=0 socket=\""
- + socket().getAbsolutePath() + "\"",
- // volume=1.0 is not optional: with no volume argument module-aaudio-sink defaults
- // the sink to 0% and the session plays silence.
- "load-module module-aaudio-sink performance_mode=1 adaptive=1 volume=1.0",
- "set-default-sink AAudioSink"));
+ // module-pipe-source creates the pipe with mkfifo and fails outright if one is already
+ // there - EEXIST, reported as "Unknown error 17" - and the module then does not load at
+ // all, so the source never appears and the client reports no microphone. Ours lives in the
+ // app's files directory and survives a session, so after the very first run the path would
+ // always be occupied. Removed here, before the daemon reads this config: the daemon makes
+ // it, and the relay helper starts afterwards and is content to find one already made.
+ if (micFifoPath != null && !micFifoPath.isEmpty()) {
+ //noinspection ResultOfMethodCallIgnored
+ new File(micFifoPath).delete();
+ }
+ ArrayList config = new ArrayList<>();
+ config.add("load-module module-native-protocol-unix auth-anonymous=1 auth-cookie-enabled=0 socket=\""
+ + socket().getAbsolutePath() + "\"");
+ // volume=1.0 is not optional: with no volume argument module-aaudio-sink defaults
+ // the sink to 0% and the session plays silence.
+ config.add("load-module module-aaudio-sink performance_mode=1 adaptive=1 volume=1.0");
+ config.add("set-default-sink AAudioSink");
+ if (micFifoPath != null && !micFifoPath.isEmpty()) {
+ // The format is the helper's, fixed at s16le/48000/mono: it resamples when the device
+ // grants another input rate, so the daemon is never told a rate the bytes are not.
+ // A pipe has no clock, so nothing here corrects drift - acceptable for voice.
+ config.add("load-module module-pipe-source source_name=DirectAudioMic file=\""
+ + micFifoPath + "\" format=s16le rate=48000 channels=1");
+ config.add("set-default-source DirectAudioMic");
+ }
+ FileUtils.writeString(new File(workingDir, "default.pa"), String.join("\n", config));
File modules = new File(workingDir, "modules/arm64");
ArrayList env = new ArrayList<>();
diff --git a/app/src/main/java/com/steamdeck/launcher/session/SessionFiles.kt b/app/src/main/java/com/steamdeck/launcher/session/SessionFiles.kt
index 89094434c3..0719803d4b 100644
--- a/app/src/main/java/com/steamdeck/launcher/session/SessionFiles.kt
+++ b/app/src/main/java/com/steamdeck/launcher/session/SessionFiles.kt
@@ -11,6 +11,8 @@ import java.io.File
object SessionFiles {
private const val TAG = "SessionFiles"
private const val NO_PAD_SWITCH = "Download/steamdeck-no-pad"
+ /** Where the DirectAudio driver lives inside the runtime; the wrappers get it as BL_DIRECTAUDIO. */
+ const val DIRECTAUDIO_DIR = "usr/local/lib/directaudio"
/**
* The libraries and scripts the session runs, refreshed from the apk at every launch.
@@ -59,6 +61,31 @@ object SessionFiles {
}
if (!installed) Log.e(TAG, "$relative NOT staged")
}
+ // The DirectAudio driver for games under Proton: the glibc build of winedirectaudio, which
+ // the Proton wrappers add to WINEDLLPATH when the session asks for it (BL_DIRECTAUDIO).
+ // Staged like the scripts, so a driver fix reaches an installed runtime without re-hosting.
+ val directAudio = arrayOf(
+ "aarch64-unix/winedirectaudio.so",
+ "aarch64-windows/winedirectaudio.drv",
+ "i386-windows/winedirectaudio.drv",
+ )
+ for (relative in directAudio) {
+ val target = File(root, "$DIRECTAUDIO_DIR/lib/wine/$relative")
+ val staged = File(target.parentFile, target.name + ".staged")
+ var installed = false
+ try {
+ target.parentFile?.mkdirs()
+ context.assets.open("directaudio/linux-wine11/$relative").use { input ->
+ staged.outputStream().use { output -> FileUtils.copy(input, output) }
+ }
+ installed = staged.setReadable(true, false) && staged.renameTo(target)
+ } catch (e: Exception) {
+ Log.w(TAG, "could not stage DirectAudio $relative", e)
+ } finally {
+ if (!installed) staged.delete()
+ }
+ if (!installed) Log.e(TAG, "DirectAudio $relative NOT staged")
+ }
// What every process in the session preloads. LD_PRELOAD in the environment would not
// survive: the Steam client rebuilds it for each process it starts and appends its own
// overlay entry without a separator, which silently drops whatever was there.
diff --git a/app/src/main/java/com/steamdeck/launcher/session/SessionPrefs.kt b/app/src/main/java/com/steamdeck/launcher/session/SessionPrefs.kt
index b8c74fea84..ae989e1f6a 100644
--- a/app/src/main/java/com/steamdeck/launcher/session/SessionPrefs.kt
+++ b/app/src/main/java/com/steamdeck/launcher/session/SessionPrefs.kt
@@ -63,6 +63,23 @@ object SessionPrefs {
prefs(context).edit().putString("linuxDriver.$mode", id).apply()
}
+ /**
+ * DirectAudio for the games the client launches: Wine's audio driver inside them replaced by
+ * ours, which talks to a helper on this side. The client itself keeps PulseAudio either way.
+ */
+ fun directAudio(context: Context): Boolean = prefs(context).getBoolean("directAudio", false)
+
+ fun setDirectAudio(context: Context, on: Boolean) {
+ prefs(context).edit().putBoolean("directAudio", on).apply()
+ }
+
+ /** The microphone, its own opt-in: the helper opens an input stream only when asked. */
+ fun micEnabled(context: Context): Boolean = prefs(context).getBoolean("mic", false)
+
+ fun setMicEnabled(context: Context, on: Boolean) {
+ prefs(context).edit().putBoolean("mic", on).apply()
+ }
+
/** The Android driver the compositor loads: "" = pick by GPU, else a bundled or imported id. */
@JvmStatic
fun androidDriver(context: Context): String = prefs(context).getString("androidDriver", "") ?: ""
diff --git a/app/src/main/java/com/steamdeck/launcher/session/SessionService.kt b/app/src/main/java/com/steamdeck/launcher/session/SessionService.kt
index 648c6ea04a..493df896cf 100644
--- a/app/src/main/java/com/steamdeck/launcher/session/SessionService.kt
+++ b/app/src/main/java/com/steamdeck/launcher/session/SessionService.kt
@@ -10,6 +10,7 @@ import android.app.PendingIntent
import android.app.Service
import android.content.Context
import android.content.Intent
+import android.content.pm.PackageManager
import android.net.wifi.WifiManager
import android.os.Build
import android.os.Environment
@@ -18,6 +19,7 @@ import android.os.PowerManager
import android.util.Log
import com.steamdeck.launcher.R
import com.steamdeck.launcher.SessionActivity
+import com.steamdeck.launcher.audio.DirectAudioRelayComponent
import com.steamdeck.launcher.audio.PulseAudioComponent
import com.steamdeck.launcher.core.EnvVars
import com.steamdeck.launcher.core.EnvironmentComponent
@@ -133,10 +135,41 @@ class SessionService : Service() {
// its authors advise for those GPUs and what nothing else in the list needs.
tuDebug(linuxDriverId)?.let { guest.add("TU_DEBUG=$it") }
- val pulse = PulseAudioComponent(this)
+ // PulseAudio always: the client is a native Linux program and has no other way to make a
+ // sound - its menus, its music and its voice chat all go through here. DirectAudio is not
+ // an alternative to it on this path: it replaces the audio driver INSIDE Wine, so it
+ // changes what games do and leaves the client alone. The microphone is its own opt-in on
+ // top, and the helper only opens an input stream when asked - so a user who wants game
+ // sound but no recording gets exactly that, and Android's recording indicator stays off.
+ val wantsDirectAudio = SessionState.mode == MODE_STEAM && SessionPrefs.directAudio(this)
+ val wantsMic = SessionPrefs.micEnabled(this) &&
+ checkSelfPermission(android.Manifest.permission.RECORD_AUDIO) == PackageManager.PERMISSION_GRANTED
+ // Both paths sit under the app's files directory, which the session binds at its own path,
+ // so the same string is valid on both sides and nothing has to be translated.
+ val audioDir = File(filesDir, "directaudio").apply { mkdirs() }
+ val relaySocket = File(audioDir, "relay.sock")
+ val micFifo = if (wantsMic) File(audioDir, "mic.fifo") else null
+
+ val pulse = PulseAudioComponent(this, micFifo?.absolutePath)
pulse.setContext(this)
guest.add("PULSE_SERVER=unix:" + pulse.socket().absolutePath)
components.add(pulse)
+ if (wantsDirectAudio || wantsMic) {
+ // After the daemon in the list, so it can wait for the pipe the daemon makes.
+ val relay = DirectAudioRelayComponent(relaySocket, micFifo)
+ relay.setContext(this)
+ components.add(relay)
+ }
+ if (wantsDirectAudio) {
+ // Read by the Proton wrappers, which point Wine at the driver and name it in the
+ // prefix. Absent, they take an early return and the game uses Proton's own audio - so
+ // this variable is the whole of the selection.
+ guest.add("BL_DIRECTAUDIO=/" + SessionFiles.DIRECTAUDIO_DIR)
+ guest.add("BANNER_AUDIO_DIRECT_RELAY=" + relaySocket.absolutePath)
+ }
+ Log.i(TAG, "audio: PulseAudio" + (if (wantsDirectAudio) " + DirectAudio for games" else "")
+ + (if (wantsMic) " + microphone" else "") +
+ (if (SessionPrefs.micEnabled(this) && !wantsMic) " (microphone wanted but RECORD_AUDIO not granted)" else ""))
guest.add("BL_WIDTH=" + size.first)
guest.add("BL_HEIGHT=" + size.second)
diff --git a/app/src/main/java/com/steamdeck/launcher/ui/AudioDialog.kt b/app/src/main/java/com/steamdeck/launcher/ui/AudioDialog.kt
new file mode 100644
index 0000000000..c2a6d13259
--- /dev/null
+++ b/app/src/main/java/com/steamdeck/launcher/ui/AudioDialog.kt
@@ -0,0 +1,69 @@
+package com.steamdeck.launcher.ui
+
+import androidx.compose.foundation.layout.Column
+import androidx.compose.foundation.layout.Row
+import androidx.compose.foundation.layout.Spacer
+import androidx.compose.foundation.layout.fillMaxWidth
+import androidx.compose.foundation.layout.height
+import androidx.compose.foundation.layout.padding
+import androidx.compose.material3.AlertDialog
+import androidx.compose.material3.MaterialTheme
+import androidx.compose.material3.Switch
+import androidx.compose.material3.Text
+import androidx.compose.material3.TextButton
+import androidx.compose.runtime.Composable
+import androidx.compose.ui.Alignment
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.unit.dp
+
+/**
+ * The two audio opt-ins. The client always has PulseAudio; these change what the games get and
+ * whether anything can record. Both apply at the next session start.
+ */
+@Composable
+fun AudioDialog(
+ directAudio: Boolean,
+ mic: Boolean,
+ onDirectAudio: (Boolean) -> Unit,
+ onMic: (Boolean) -> Unit,
+ onDismiss: () -> Unit,
+) {
+ AlertDialog(
+ onDismissRequest = onDismiss,
+ title = { Text("Audio") },
+ text = {
+ Column {
+ Text(
+ "The Steam client itself always plays through PulseAudio. These two change what happens around it, at the next session start.",
+ style = MaterialTheme.typography.bodySmall,
+ color = MaterialTheme.colorScheme.onSurfaceVariant,
+ )
+ Spacer(Modifier.height(12.dp))
+ Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxWidth().padding(vertical = 4.dp)) {
+ Column(modifier = Modifier.weight(1f)) {
+ Text("DirectAudio for games", style = MaterialTheme.typography.bodyMedium)
+ Text(
+ "Replaces Wine's audio driver inside the games the client launches with one that talks straight to Android — lower latency, no PulseAudio in between. Wine 11 Protons only (Valve's ARM64, GE, cachyos); on anything else it stays off rather than play silence. A game's first launch after turning this on still uses Proton's own audio; the second uses this.",
+ style = MaterialTheme.typography.bodySmall,
+ color = MaterialTheme.colorScheme.onSurfaceVariant,
+ )
+ }
+ Switch(checked = directAudio, onCheckedChange = onDirectAudio)
+ }
+ Spacer(Modifier.height(8.dp))
+ Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxWidth().padding(vertical = 4.dp)) {
+ Column(modifier = Modifier.weight(1f)) {
+ Text("Microphone", style = MaterialTheme.typography.bodyMedium)
+ Text(
+ "Gives the session Android's microphone: the Steam client shows an input device named DirectAudioMic, for voice chat. Asks for the recording permission; with it off, nothing in the session can record and Android's indicator stays off.",
+ style = MaterialTheme.typography.bodySmall,
+ color = MaterialTheme.colorScheme.onSurfaceVariant,
+ )
+ }
+ Switch(checked = mic, onCheckedChange = onMic)
+ }
+ }
+ },
+ confirmButton = { TextButton(onClick = onDismiss) { Text("OK") } },
+ )
+}
diff --git a/app/src/main/java/com/steamdeck/launcher/ui/MainScreen.kt b/app/src/main/java/com/steamdeck/launcher/ui/MainScreen.kt
index a51109338a..888b55c05a 100644
--- a/app/src/main/java/com/steamdeck/launcher/ui/MainScreen.kt
+++ b/app/src/main/java/com/steamdeck/launcher/ui/MainScreen.kt
@@ -67,6 +67,7 @@ fun MainScreen(
onFrameGen: () -> Unit,
onProtons: () -> Unit,
onDrivers: () -> Unit,
+ onAudio: () -> Unit,
onOffline: () -> Unit,
onCredits: () -> Unit,
) {
@@ -182,6 +183,10 @@ fun MainScreen(
onClick = onDrivers,
modifier = Modifier.fillMaxWidth().padding(top = 5.dp * k).height(buttonHeight + 5.dp * k),
) { Text("Graphics drivers", fontSize = 13.sp * k) }
+ OutlinedButton(
+ onClick = onAudio,
+ modifier = Modifier.fillMaxWidth().padding(top = 5.dp * k).height(buttonHeight + 5.dp * k),
+ ) { Text("Audio", fontSize = 13.sp * k) }
Spacer(Modifier.height(10.dp * k))
Text(
"by The412Banner and maxjivi05 · credits",
diff --git a/app/src/main/jniLibs/arm64-v8a/libdirectaudiorelay.so b/app/src/main/jniLibs/arm64-v8a/libdirectaudiorelay.so
new file mode 100644
index 0000000000..d530b848ff
Binary files /dev/null and b/app/src/main/jniLibs/arm64-v8a/libdirectaudiorelay.so differ
diff --git a/tools/linuxfs/overlay/usr/local/bin/bannerlator-steam-compat b/tools/linuxfs/overlay/usr/local/bin/bannerlator-steam-compat
index 7669773638..b7c0659ad1 100755
--- a/tools/linuxfs/overlay/usr/local/bin/bannerlator-steam-compat
+++ b/tools/linuxfs/overlay/usr/local/bin/bannerlator-steam-compat
@@ -70,6 +70,58 @@ TOOL_MANIFEST_VDF = """"manifest"
}
""" % LAUNCHER
+# Resolves the depot at launch time, so the tool can be registered before the depot exists and
+# survives the client updating or replacing it. Proton takes its base directory from
+# dirname(sys.argv[0]) without resolving it, so it is run from the depot itself.
+# Cores for a game the client launches, kept separate from the client's own. One mask suits the
+# client's menus and another suits a game, and they are wanted at the same time - so the game's is
+# applied here, in the launch path every game goes through, rather than to the session as a whole.
+BL_GAME_CPUS_SETUP = """
+bl_game_cpus() {
+ [ -n "${BL_GAME_CPUS:-}" ] || return 0
+ command -v taskset >/dev/null 2>&1 || return 0
+ # exec'd through taskset rather than set afterwards: a mask applied to a pid races the process
+ # into spawning its own threads, and this way every thread inherits it from the first instruction.
+ BL_TASKSET="taskset -c $BL_GAME_CPUS"
+ echo "bannerlator-proton: game cores $BL_GAME_CPUS" >&2
+}
+"""
+
+BL_DIRECTAUDIO_SETUP = """
+bl_directaudio() {
+ base=$1
+ [ -n "${BL_DIRECTAUDIO:-}" ] || return 0
+ [ -d "$BL_DIRECTAUDIO/lib/wine" ] || return 0
+ version=$("$base/files/bin-arm64/wine" --version 2>/dev/null)
+ major=${version#wine-}
+ major=${major%%.*}
+ if [ "$major" != "11" ]; then
+ echo "bannerlator-proton: DirectAudio left off - it is built for Wine 11 and this Proton is '${version:-unknown}'. Pairing them would be silent rather than broken, so it is not worth guessing." >&2
+ return 0
+ fi
+ # Wine appends the per-architecture subdirectory to each entry, so the directory holding
+ # aarch64-unix/ and aarch64-windows/ is what goes here.
+ WINEDLLPATH="$BL_DIRECTAUDIO/lib/wine${WINEDLLPATH:+:$WINEDLLPATH}"
+ export WINEDLLPATH
+ # mmdevapi only tries the drivers named in the registry; its built-in list is pulse, alsa, oss and
+ # coreaudio and knows nothing about this one. The key is appended to the prefix's user.reg rather
+ # than written with `wine reg`, which would start a wineserver here just to set one value.
+ reg="${STEAM_COMPAT_DATA_PATH:-}/pfx/user.reg"
+ if [ -f "$reg" ]; then
+ if ! grep -q '"Audio"="directaudio"' "$reg" 2>/dev/null; then
+ printf '\n[Software\\\\Wine\\\\Drivers] %s\n"Audio"="directaudio"\n' "$(date +%s)" >> "$reg"
+ echo "bannerlator-proton: DirectAudio selected in the prefix" >&2
+ fi
+ else
+ # A prefix that does not exist yet is created by Proton moments from now, after this runs, so
+ # the key lands on the NEXT launch of that game. Said out loud because silent audio on a first
+ # launch would otherwise look like a fault.
+ echo "bannerlator-proton: no prefix yet - DirectAudio takes effect the next time this game starts" >&2
+ fi
+ echo "bannerlator-proton: DirectAudio ready (Wine $major)" >&2
+}
+"""
+
# Resolves the depot at launch time, so the tool can be registered before the depot exists and
# survives the client updating or replacing it. Proton takes its base directory from
# dirname(sys.argv[0]) without resolving it, so it is run from the depot itself.
@@ -98,12 +150,19 @@ fi
for name in %s; do
depot="$steam_root/steamapps/common/$name"
if [ -d "$depot/files/bin-arm64" ] && [ -x "$depot/proton" ]; then
- exec "$depot/proton" "$verb" "$@"
+ bl_directaudio "$depot"
+ bl_game_cpus
+ exec ${BL_TASKSET:-} "$depot/proton" "$verb" "$@"
fi
done
echo "bannerlator-proton: no ARM64 Proton depot yet - the client downloads one as this tool's dependency; retry the launch once it has" >&2
exit 1
""" % " ".join('"%s"' % n for n in SOURCES)
+# Spliced in after the formatting above, never through it: the function body contains ${major%%.*}
+# and a % format would eat that into a single %, leaving a shell expansion that silently does
+# something else.
+LAUNCHER_SH = LAUNCHER_SH.replace(
+ "verb=$1; shift", "verb=$1; shift\n" + BL_DIRECTAUDIO_SETUP + BL_GAME_CPUS_SETUP, 1)
# A third-party Proton dropped into compatibilitytools.d - GE-Proton, proton-cachyos, anything of
# that shape - is adopted rather than used as shipped, for the same two reasons Valve's ARM64 depot
@@ -135,9 +194,11 @@ if [ -f "$fake" ]; then
*) LD_PRELOAD="$fake${LD_PRELOAD:+:$LD_PRELOAD}"; export LD_PRELOAD ;;
esac
fi
+bl_directaudio "$here"
+bl_game_cpus
# Proton takes its base directory from dirname(sys.argv[0]) without resolving it, so it has to be
# started from its own tree.
-exec "$here/%s" "$verb" "$@"
+exec ${BL_TASKSET:-} "$here/%s" "$verb" "$@"
"""
EXTRA_COMPAT_TOOL_VDF = """"compatibilitytools"
{
@@ -292,8 +353,13 @@ def adopt_extras(tools):
name = first_key(compat_vdf, ["compatibilitytools", "compat_tools"]) or entry
wrapper = os.path.join(tool_dir, EXTRA_WRAPPER)
try:
+ # Formatted first, spliced second: the function carries a printf %s and a
+ # ${major%%.*} of its own, and putting it through the format would eat both.
+ body = (EXTRA_WRAPPER_SH % entry_point).replace(
+ 'here=$(dirname "$0")',
+ 'here=$(dirname "$0")\n' + BL_DIRECTAUDIO_SETUP + BL_GAME_CPUS_SETUP, 1)
with open(wrapper, "w", encoding="utf-8") as f:
- f.write(EXTRA_WRAPPER_SH % entry_point)
+ f.write(body)
os.chmod(wrapper, 0o755)
with open(manifest, "w", encoding="utf-8") as f:
f.write(EXTRA_MANIFEST_VDF)