From 53fdc2c9addce5de80b3378a0731b6241ba89a7d Mon Sep 17 00:00:00 2001 From: The412Banner <205237651+The412Banner@users.noreply.github.com> Date: Fri, 20 Nov 2026 13:40:12 +0000 Subject: [PATCH] fix(input): skip a leading byte order mark when parsing Steam KeyValues files --- .../launcher/input/SteamTouchConfig.kt | 4 ++-- .../input/SteamTouchConfigFilesTest.kt | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/droiddeck/launcher/input/SteamTouchConfig.kt b/app/src/main/java/com/droiddeck/launcher/input/SteamTouchConfig.kt index 8e5f9a29e3..b71e0b0623 100644 --- a/app/src/main/java/com/droiddeck/launcher/input/SteamTouchConfig.kt +++ b/app/src/main/java/com/droiddeck/launcher/input/SteamTouchConfig.kt @@ -204,7 +204,7 @@ object SteamTouchConfig { } return try { val text = file.readText() - val kv = KeyValues.parse(text.removePrefix("")) + val kv = KeyValues.parse(text) val mappings = kv.child("controller_mappings") ?: kv val layouts = mappings.string("touch_layout")?.let { hex -> decodeLayouts(hexToBytes(hex)) } Log.i(TAG, "steam touch: app $appId uses ${file.path} (${layouts?.layouts?.size ?: 0} layouts)") @@ -618,7 +618,7 @@ class KeyValues private constructor() { private fun escape(text: String) = text.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\n").replace("\t", "\\t") fun parse(text: String): Node { - val tokens = tokenize(text) + val tokens = tokenize(text.removePrefix("\uFEFF")) var i = 0 fun node(): Node { val n = Node() diff --git a/app/src/test/java/com/droiddeck/launcher/input/SteamTouchConfigFilesTest.kt b/app/src/test/java/com/droiddeck/launcher/input/SteamTouchConfigFilesTest.kt index bcb2131711..22f9650bf1 100644 --- a/app/src/test/java/com/droiddeck/launcher/input/SteamTouchConfigFilesTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/input/SteamTouchConfigFilesTest.kt @@ -124,6 +124,25 @@ class SteamTouchConfigFilesTest { assertTrue(text.contains("\"413150\"")) } + private fun withBom(name: String) = File(dir, name).apply { writeText("\uFEFF" + readText()) } + + @Test fun aConfigsetWithAByteOrderMarkKeepsItsOtherEntries() { + configset("configset_controller_mobile_touch.vdf", "8400" to "\"workshop\"\t\t\"7\"") + withBom("configset_controller_mobile_touch.vdf") + val saved = saveDefault(413150) + val root = KeyValues.parse(File(dir, "configset_controller_mobile_touch.vdf").readText()).child("controller_config") + assertEquals("1", root?.child("413150")?.string("autosave")) + assertEquals("7", root?.child("8400")?.string("workshop")) + assertSavedA(413150, saved) + } + + @Test fun aWorkshopPickInAConfigsetWithAByteOrderMarkIsRead() { + val picked = workshop("42", "community") + configset("configset_controller_mobile_touch.vdf", "413150" to "\"workshop\"\t\t\"42\"") + withBom("configset_controller_mobile_touch.vdf") + assertEquals(picked, SteamTouchConfig.load(context, 413150).file) + } + @Test fun aConfigsetMissingItsRootBraceGetsTheEntryAtTheRoot() { File(dir, "configset_controller_mobile_touch.vdf") .writeText("\"controller_config\"\n{\n\t\"8400\"\n\t{\n\t\t\"workshop\"\t\t\"7\"\n\t}\n")