From 9a6558d8b3e65fdaee9ac074eb3277fa788d698a Mon Sep 17 00:00:00 2001 From: The412Banner Date: Fri, 2 Oct 2026 11:17:56 -0400 Subject: [PATCH] VAC diagnostics: game console + vac.txt in the session logs A Source-engine game says whether it started VAC-secure only in its own console, which reaches a file only with -condebug. With the new Setup toggle on (off by default), the launch wrapper adds -condebug to Source and Source 2 titles and notes each launch; at the end of the session each console.log written during it is copied, scrubbed, into vac/ and vac.txt quotes the game's secure/insecure lines, any VAC lines in the client's logs and which client builds are on disk. No connection to a server is reported as inconclusive rather than guessed. --- .../com/droiddeck/launcher/MainActivity.kt | 8 +- .../launcher/session/SessionArtifacts.kt | 2 + .../launcher/session/SessionPrefs.kt | 12 ++ .../launcher/session/SessionService.kt | 1 + .../launcher/session/VacDiagnostics.kt | 186 ++++++++++++++++++ .../droiddeck/launcher/ui/FrontEndScreen.kt | 2 + .../droiddeck/launcher/ui/FrontEndSetup.kt | 1 + app/src/main/res/values-es/strings.xml | 2 + app/src/main/res/values/strings.xml | 2 + .../usr/local/bin/bannerlator-steam-compat | 37 +++- 10 files changed, 250 insertions(+), 3 deletions(-) create mode 100644 app/src/main/java/com/droiddeck/launcher/session/VacDiagnostics.kt diff --git a/app/src/main/java/com/droiddeck/launcher/MainActivity.kt b/app/src/main/java/com/droiddeck/launcher/MainActivity.kt index e270a33441..126165ce60 100644 --- a/app/src/main/java/com/droiddeck/launcher/MainActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/MainActivity.kt @@ -279,6 +279,7 @@ class MainActivity : ComponentActivity() { private var emulatorList by mutableStateOf>(emptyList()) private var runningLabel by mutableStateOf(null) private var logsEnabled by mutableStateOf(true) + private var vacDiagnostics by mutableStateOf(false) private var showRoms by mutableStateOf(false) private var homeAppSelected by mutableStateOf(false) private var homeScreenEnabled by mutableStateOf(false) @@ -363,7 +364,7 @@ class MainActivity : ComponentActivity() { busy = busy, stage = stage, percent = percent, desktopInstalled = desktopInstalled, offlineAccount = offlineAccount, offline = offline, - frameGenLabel = frameGenLabel, romsDir = romsDir, logsEnabled = logsEnabled, + frameGenLabel = frameGenLabel, romsDir = romsDir, logsEnabled = logsEnabled, vacDiagnostics = vacDiagnostics, steamGames = steamGames, emulators = emulatorList, running = runningLabel, frameGen = FrameGen.mode(this), lossless = lossless, @@ -461,6 +462,10 @@ class MainActivity : ComponentActivity() { SessionPrefs.setLogsEnabled(this, !SessionPrefs.logsEnabled(this)) logsEnabled = SessionPrefs.logsEnabled(this) }, + onVacDiagnostics = { + SessionPrefs.setVacDiagnostics(this, !SessionPrefs.vacDiagnostics(this)) + vacDiagnostics = SessionPrefs.vacDiagnostics(this) + }, onShareLogs = { Thread({ val zip = runCatching { SessionLogShare.zipLatest(this) }.getOrNull() @@ -1192,6 +1197,7 @@ class MainActivity : ComponentActivity() { frameGenLabel = FrameGen.label(this) romsDir = SessionPrefs.romsDir(this).takeIf { it.isNotEmpty() } logsEnabled = SessionPrefs.logsEnabled(this) + vacDiagnostics = SessionPrefs.vacDiagnostics(this) runningLabel = if (SessionState.running) when (SessionState.mode) { SessionService.MODE_DESKTOP -> "Desktop" SessionService.MODE_RUN -> Library.nameForProgram(SessionState.program) diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionArtifacts.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionArtifacts.kt index 20e04141f6..659fcf0da8 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionArtifacts.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionArtifacts.kt @@ -45,6 +45,7 @@ object SessionArtifacts { } LogRedactor.learnFromRuntime(LinuxRuntime.rootDir(context)) copySteamLogs(context, dir) + VacDiagnostics.collect(context, dir) // A session the system killed leaves its trace here and nowhere else. SessionLogCapture.dumpCrashBuffer(File(dir, "crash.log")) scrubFolder(dir) @@ -145,6 +146,7 @@ object SessionArtifacts { ) if (newest) { copySteamLogs(context, dir) + VacDiagnostics.collect(context, dir) } SessionLogCapture.dumpCrashBuffer(File(dir, "crash.log")) SessionEvents.record("session.artifacts_recovered", mapOf("newest" to newest), dir) diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt index 9a6c12e09f..308f8b58e4 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt @@ -424,6 +424,18 @@ object SessionPrefs { prefs(context).edit().putBoolean("logs", on).apply() } + /** + * VAC diagnostics (see [VacDiagnostics]): Source-engine games launched with -condebug and their + * console plus the client's VAC lines summarised into vac.txt. Off by default: it changes a + * game's command line. + */ + fun vacDiagnostics(context: Context): Boolean = + prefs(context).getBoolean("vac_diagnostics", false) + + fun setVacDiagnostics(context: Context, on: Boolean) { + prefs(context).edit().putBoolean("vac_diagnostics", on).apply() + } + // ── Per-mode display ──────────────────────────────────────────────────────────────────── /** diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt index cd1ef2e9d7..5777b86e5c 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt @@ -267,6 +267,7 @@ class SessionService : Service() { val runtimeDir = File(filesDir, ".wayland-rt").apply { mkdirs() } killStragglers() SessionFiles.stage(this, root) + VacDiagnostics.arm(this) val sessionDir = openSessionFolder() val sessionLog = File(sessionDir, "session.log") diff --git a/app/src/main/java/com/droiddeck/launcher/session/VacDiagnostics.kt b/app/src/main/java/com/droiddeck/launcher/session/VacDiagnostics.kt new file mode 100644 index 0000000000..bc7795e0a2 --- /dev/null +++ b/app/src/main/java/com/droiddeck/launcher/session/VacDiagnostics.kt @@ -0,0 +1,186 @@ +package com.droiddeck.launcher.session + +import android.content.Context +import android.util.Log +import com.droiddeck.launcher.core.LogRedactor +import com.droiddeck.launcher.runtime.LinuxRuntime +import java.io.File +import java.io.RandomAccessFile +import java.text.SimpleDateFormat +import java.util.Date +import java.util.Locale + +/** + * VAC diagnostics: what a session can show about whether a game ran VAC-secure, from the files + * Valve's own software writes - nothing is inferred from our side of the launch. + * + * The verdict is the game's to give. A Source-engine game decides secure or insecure once, as it + * starts, and says so only in its own console ("You are in insecure mode. You must restart before + * you can connect to secure servers."). That console reaches a file only when the game runs with + * -condebug, as console.log in the game's mod folder. With this on, the launch wrapper + * (bannerlator-proton, bl_vacdiag) adds -condebug to Source titles and notes each launch; at the end + * of the session this copies each console.log written during it into vac/, scrubbed, and writes + * vac.txt: the game's own secure/insecure lines, any VAC lines in the client's logs, and which + * client files are present. + * + * The SteamLite lesson applies: its "INSECURE - VAC may kick" warning was our own parser reading the + * wrong log while the client was secure all along. So vac.txt quotes the lines it found and says + * "inconclusive" when the game never reached a server, rather than guessing either way. + */ +object VacDiagnostics { + private const val TAG = "VacDiagnostics" + + /** In the guest's home; the launch wrapper checks for it. Holds the session's start, epoch seconds. */ + private const val MARKER = "root/.droiddeck-vac-diagnostics" + + /** One line per game launch the wrapper saw: epoch, app id, -condebug added or not, the exe. */ + private const val LAUNCHES = "root/.droiddeck-vac-launches" + + /** The console log grows across launches; the end of it is the session that just ran. */ + private const val CONSOLE_TAIL_BYTES = 4L * 1024 * 1024 + + private const val MAX_QUOTED = 40 + + private val INSECURE = Regex("insecure mode", RegexOption.IGNORE_CASE) + private val CONNECTED = Regex("^(Connected to|Connecting to|Connection to game coordinator)", RegexOption.IGNORE_CASE) + private val NOTABLE = Regex("\\bVAC\\b|secure|Connected to|Connecting to|Disconnect|challenge|game coordinator", RegexOption.IGNORE_CASE) + private val STEAM_VAC = Regex("\\bVAC\\b|anti-?cheat", RegexOption.IGNORE_CASE) + + fun enabled(context: Context): Boolean = SessionPrefs.vacDiagnostics(context) + + /** + * At session start, after the scripts are staged: arms the wrapper for this session (or disarms + * it) and starts a fresh launch list, so the summary names only games this session ran. + */ + fun arm(context: Context) { + val root = LinuxRuntime.rootDir(context) + val marker = File(root, MARKER) + try { + File(root, LAUNCHES).delete() + if (enabled(context)) marker.writeText("${System.currentTimeMillis() / 1000}\n") + else marker.delete() + } catch (e: Exception) { + Log.w(TAG, "could not arm VAC diagnostics", e) + } + } + + /** At the end of a session, into its folder. Does nothing unless the session was armed. */ + fun collect(context: Context, dir: File) { + val root = LinuxRuntime.rootDir(context) + val marker = File(root, MARKER) + if (!marker.isFile) return + try { + val since = (marker.readText().trim().toLongOrNull() ?: 0L) * 1000 - 5_000 + val out = File(dir, "vac").apply { mkdirs() } + val consoles = consoleLogs(context).filter { it.lastModified() >= since } + val report = StringBuilder() + report.appendLine("VAC diagnostics - ${now()}") + report.appendLine("Read from the game's own console (-condebug) and the Steam client's logs.") + report.appendLine() + report.appendLine("== Client") + clientFiles(root).forEach { report.appendLine(" $it") } + report.appendLine() + report.appendLine("== Game launches this session (from the launch wrapper)") + val launches = File(root, LAUNCHES).takeIf { it.isFile }?.readLines().orEmpty().filter { it.isNotBlank() } + if (launches.isEmpty()) report.appendLine(" none - no Windows game was launched through the client") + launches.forEach { report.appendLine(" " + LogRedactor.redact(it)) } + report.appendLine() + report.appendLine("== Game consoles") + if (consoles.isEmpty()) { + report.appendLine(" No console.log was written this session. Only Source-engine games write one,") + report.appendLine(" and only when started with -condebug (this setting adds it).") + } + consoles.forEach { log -> + val name = consoleName(log) + val lines = tail(log) + File(out, "$name-console.log").bufferedWriter().use { w -> + lines.forEach { w.write(LogRedactor.redact(it)); w.newLine() } + } + report.appendLine("-- $name (vac/$name-console.log)") + report.appendLine(" Verdict: " + verdict(lines)) + lines.filter { NOTABLE.containsMatchIn(it) }.takeLast(MAX_QUOTED) + .forEach { report.appendLine(" | " + LogRedactor.redact(it.trim())) } + report.appendLine() + } + report.appendLine("== VAC in the Steam client's logs") + val steamHits = File(dir, "steam").listFiles { f -> f.isFile }?.sortedBy { it.name }.orEmpty() + .flatMap { f -> runCatching { f.readLines() }.getOrDefault(emptyList()).filter { STEAM_VAC.containsMatchIn(it) }.map { "${f.name}: ${it.trim()}" } } + if (steamHits.isEmpty()) report.appendLine(" none - the client logged no VAC activity this session") + steamHits.takeLast(MAX_QUOTED).forEach { report.appendLine(" $it") } + File(dir, "vac.txt").writeText(report.toString()) + Log.i(TAG, "VAC diagnostics: ${consoles.size} console log(s), ${steamHits.size} client VAC line(s), into $dir") + } catch (e: Exception) { + Log.w(TAG, "collecting VAC diagnostics", e) + } + } + + private fun verdict(lines: List): String = when { + lines.any { INSECURE.containsMatchIn(it) } -> + "INSECURE - the game started in insecure mode and cannot join VAC-secured servers until it restarts." + lines.any { CONNECTED.containsMatchIn(it) } -> + "No insecure notice, and the game reached a server. Confirm with the server's own info that it is VAC-secured." + else -> + "Inconclusive - the game never connected to a server. Join a VAC-secured server, then check again." + } + + /** Every console.log in a Steam library: //console.log (Source) and /game//console.log (Source 2). */ + private fun consoleLogs(context: Context): List { + val found = LinkedHashMap() + for (library in libraryRoots(context)) { + val games = File(library, "steamapps/common").listFiles { f -> f.isDirectory } ?: continue + for (game in games) { + val mods = (game.listFiles { f -> f.isDirectory }.orEmpty().toList() + + File(game, "game").listFiles { f -> f.isDirectory }.orEmpty().toList()) + for (mod in mods) { + val log = File(mod, "console.log") + if (log.isFile) found[runCatching { log.canonicalPath }.getOrDefault(log.path)] = log + } + } + } + return found.values.toList() + } + + private fun libraryRoots(context: Context): List { + val root = LinuxRuntime.rootDir(context) + val steam = File(root, "root/.local/share/Steam") + val roots = mutableListOf(steam) + GameStorage.effective(context)?.let { roots.add(File(it.path)) } + runCatching { + Regex("\"path\"\\s+\"([^\"]+)\"").findAll(File(steam, "steamapps/libraryfolders.vdf").readText()).forEach { + roots.add(File(root, it.groupValues[1].removePrefix("/"))) + } + } + return roots.filter { it.isDirectory }.distinctBy { runCatching { it.canonicalPath }.getOrDefault(it.path) } + } + + /** "Team Fortress 2-tf": the game folder and the mod, safe as a file name. */ + private fun consoleName(log: File): String { + val mod = log.parentFile + val game = mod?.parentFile?.let { if (it.name == "game") it.parentFile else it } + return "${game?.name ?: "game"}-${mod?.name ?: "mod"}".replace(Regex("[^A-Za-z0-9._ +-]+"), "_") + } + + private fun tail(file: File): List = try { + RandomAccessFile(file, "r").use { raf -> + val start = (raf.length() - CONSOLE_TAIL_BYTES).coerceAtLeast(0) + raf.seek(start) + val bytes = ByteArray((raf.length() - start).toInt()) + raf.readFully(bytes) + String(bytes, Charsets.UTF_8).lines().let { if (start > 0) it.drop(1) else it } + } + } catch (e: Exception) { + emptyList() + } + + /** Which Steam client builds are on disk - the arm64 one has no VAC module of its own to run. */ + private fun clientFiles(root: File): List { + val steam = File(root, "root/.local/share/Steam") + return listOf( + "linuxarm64/steamclient.so" to "arm64 Linux client", + "linux64/steamclient.so" to "x86-64 Linux client", + "ubuntu12_64/steamclient.so" to "x86-64 Linux client (ubuntu12_64)", + ).map { (path, label) -> "$label: ${if (File(steam, path).isFile) "present" else "absent"} ($path)" } + } + + private fun now(): String = SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US).format(Date()) +} diff --git a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndScreen.kt b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndScreen.kt index 80f5794152..67e90a3e5d 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndScreen.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndScreen.kt @@ -91,6 +91,7 @@ class FrontEndState( val frameGenLabel: String, val romsDir: String?, val logsEnabled: Boolean, + val vacDiagnostics: Boolean = false, val steamGames: List, val emulators: List, val running: String?, @@ -152,6 +153,7 @@ class FrontEndActions( val onFiles: () -> Unit, val onBrowseFiles: (File) -> Unit = {}, val onLogs: () -> Unit, + val onVacDiagnostics: () -> Unit = {}, val onShareLogs: () -> Unit = {}, val onClearLogs: () -> Unit = {}, val onOffline: () -> Unit, diff --git a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndSetup.kt b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndSetup.kt index af7a1470d2..7cc3be3494 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndSetup.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndSetup.kt @@ -289,6 +289,7 @@ internal fun SetupPanel( } } ToggleRow(host, "logs", stringResource(R.string.setup_logs), stringResource(R.string.setup_logs_hint), s.logsEnabled) { a.onLogs() } + ToggleRow(host, "vacdiag", stringResource(R.string.setup_vac_diag), stringResource(R.string.setup_vac_diag_hint), s.vacDiagnostics) { a.onVacDiagnostics() } ActionRow(stringResource(R.string.setup_latest_logs), stringResource(R.string.drawer_logs_hint), stringResource(R.string.drawer_share_logs), a.onShareLogs) ActionRow(stringResource(R.string.setup_saved_logs), stringResource(R.string.setup_saved_logs_hint, com.droiddeck.launcher.session.SessionPaths.KEEP_SESSIONS), stringResource(R.string.setup_clear_logs), a.onClearLogs) ToggleRow( diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 5be0da17a3..60506c2256 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -483,6 +483,8 @@ Sesión Registros de sesión Se guardan tras cada sesión + Diagnóstico de VAC + Los juegos Source registran su consola (-condebug); vac.txt en los registros dice si es seguro o no Últimos registros de sesión Registros de sesión guardados Conserva los %1$d más recientes diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 618b44821a..3aba203d28 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -508,6 +508,8 @@ Session Session logs Saved after each session + VAC diagnostics + Source games log their console (-condebug); vac.txt in the session logs says secure or insecure Latest session logs Saved session logs Keeps the newest %1$d diff --git a/tools/linuxfs/overlay/usr/local/bin/bannerlator-steam-compat b/tools/linuxfs/overlay/usr/local/bin/bannerlator-steam-compat index 1a38c20b88..2bf51da320 100755 --- a/tools/linuxfs/overlay/usr/local/bin/bannerlator-steam-compat +++ b/tools/linuxfs/overlay/usr/local/bin/bannerlator-steam-compat @@ -189,6 +189,37 @@ bl_idtech3() { } """ +# VAC diagnostics (the app's Setup page): a Source-engine game says whether it started VAC-secure +# only in its own console, and writes that console to /console.log only with -condebug. Armed +# per session by the app (~/.droiddeck-vac-diagnostics); each launch is noted for its summary. +# Nothing else about the launch changes - this only asks the game to keep its own log. +BL_VACDIAG_SETUP = """ +bl_vacdiag() { + [ -f "${HOME:-/root}/.droiddeck-vac-diagnostics" ] || return 0 + [ "${verb:-}" = waitforexitandrun ] || return 0 + local exe= a dir added=no app=${SteamAppId:-${STEAM_COMPAT_APP_ID:-0}} + for a in "$@"; do case $a in *.exe|*.EXE) exe=$a ;; esac; done + [ -n "$exe" ] || return 0 + dir=$(dirname "$exe") + # Source: //gameinfo.txt beside the exe. Source 2: /game/bin/win64/ with + # /game//gameinfo.gi. + if ls "$dir"/*/gameinfo.txt >/dev/null 2>&1 || ls "$dir"/../../*/gameinfo.gi >/dev/null 2>&1; then + case " $* " in + *" -condebug "*) echo "bannerlator-proton: vac-diag: app $app already has -condebug" >&2 ;; + *) BL_EXTRA_ARGS+=(-condebug); added=yes + echo "bannerlator-proton: vac-diag: app $app is a Source title; launched with -condebug" >&2 ;; + esac + else + added=not-source + echo "bannerlator-proton: vac-diag: app $app is not a Source title; it keeps no console log to read" >&2 + fi + case " $* " in + *" -insecure "*) echo "bannerlator-proton: vac-diag: app $app has -insecure in its launch options - it can never be VAC-secure this way" >&2 ;; + esac + printf '%s\tapp %s\tcondebug %s\t%s\n' "$(date +%s)" "$app" "$added" "${exe##*/}" >> "${HOME:-/root}/.droiddeck-vac-launches" +} +""" + BL_DIRECTAUDIO_SETUP = """ bl_directaudio() { base=$1 @@ -271,6 +302,7 @@ if [ -n "$depot" ]; then bl_directaudio "$depot" bl_game_cpus bl_idtech3 "$@" + bl_vacdiag "$@" bl_libpath exec ${BL_TASKSET:-} /usr/local/bin/bannerlator-game-env "$depot/proton" "$verb" "$@" "${BL_EXTRA_ARGS[@]}" fi @@ -282,7 +314,7 @@ exit 1 # something else. LAUNCHER_SH = LAUNCHER_SH.replace( "verb=$1; shift", "verb=$1; shift\n" + BL_DIRECTAUDIO_SETUP + BL_GAME_CPUS_SETUP + BL_IDTECH3_SETUP - + BL_COMPONENTS_SETUP + BL_LIBPATH_SETUP, 1) + + BL_VACDIAG_SETUP + BL_COMPONENTS_SETUP + BL_LIBPATH_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 @@ -318,6 +350,7 @@ bl_components "$here" bl_directaudio "$here" bl_game_cpus bl_idtech3 "$@" +bl_vacdiag "$@" bl_libpath # Proton takes its base directory from dirname(sys.argv[0]) without resolving it, so it has to be # started from its own tree. @@ -503,7 +536,7 @@ def adopt_extras(tools): body = (EXTRA_WRAPPER_SH % entry_point).replace( 'here=$(dirname "$0")', 'here=$(dirname "$0")\n' + BL_DIRECTAUDIO_SETUP + BL_GAME_CPUS_SETUP + BL_IDTECH3_SETUP - + BL_COMPONENTS_SETUP + BL_LIBPATH_SETUP, 1) + + BL_VACDIAG_SETUP + BL_COMPONENTS_SETUP + BL_LIBPATH_SETUP, 1) write_changed(wrapper, body, 0o755) write_changed(manifest, EXTRA_MANIFEST_VDF) write_changed(compat_vdf, EXTRA_COMPAT_TOOL_VDF % (name, entry))