Compare commits

..
Author SHA1 Message Date
The412Banner fb4c99ccf0 fix(game-env): replace x64 DLLs a game's ARM64 images import in ARM64 prefixes
A pure ARM64 process cannot load x64 code, so a plain x64 DLL in an
ARM64 prefix's system32 is now foreign for any name a 0xAA64 (including
ARM64X) image in the game folder imports. ARM64EC importers keep the
Visual C++ runtime-only rule. The same cached walk of the game folder
collects both sets.

The component filter now keeps tracking a saved original whose
restoration is deferred, so it is put back on a later launch.
2026-12-03 22:55:05 +00:00
The412Banner 66b1b3c017 fix(game-env): give ARM64EC games the hybrid Visual C++ runtime in ARM64 prefixes
A plain x64 Visual C++ runtime DLL in an ARM64 prefix's system32 is now
foreign when one of the game's own ARM64EC images imports it, so the
prefix repair and the component filter keep Proton's ARM64EC-capable
builtin there, as Windows on Arm does. x64 games, other x64 DLLs and
launches without a game folder keep the x64 copies.
2026-11-29 17:36:34 +00:00
Kurt Himebauch 80fc5dec07 Fix the Steam home's wall and card fan on portrait screens (#3412) 2026-11-29 10:17:44 -05:00
10 changed files with 338 additions and 90 deletions

No files matched your search

@@ -57,12 +57,17 @@ import com.droiddeck.launcher.stores.StoresState
/** What the Library pretends while a developer previews it. Nothing here is saved: a restart always comes back to [OFF]. */
internal enum class LibraryPreview { OFF, NOTHING_INSTALLED, SIGNED_OUT, SAMPLE }
/** How many games the Steam home pretends are installed. Nothing here is saved. */
internal enum class SteamHomePreview(val games: Int) { OFF(-1), NONE(0), FEW(3), MANY(12) }
internal enum class DrawerPreview { STEAM, DESKTOP, GAME }
/** Developer tools' preview states: screens that are otherwise hard to reach, shown without changing anything real. */
internal object DevPreview {
var library by mutableStateOf(LibraryPreview.OFF)
var drawer by mutableStateOf<DrawerPreview?>(null)
var steamHome by mutableStateOf(SteamHomePreview.OFF)
var openSteam by mutableStateOf(false)
/** The UI zoo sheet: where previews are picked, one at a time, only when asked for. */
var zoo by mutableStateOf(false)
/** Opt-in: a preview button where its state lives (the Library's toolbar), for switching states without the zoo. */
@@ -87,6 +92,41 @@ internal fun sampleOwned(store: Store): List<CatalogItem> =
internal fun sampleInstalled(owned: Map<Store, List<CatalogItem>>): Set<String> =
owned.values.flatMap { items -> items.take(SAMPLE_INSTALLED).map { it.key } }.toSet()
/** The Steam home's games while a developer previews it: this many invented titles, no art, nothing installed. */
internal fun sampleSteamHomeGames(count: Int): List<com.droiddeck.launcher.frontend.Library.SteamGame> = listOf(
"Portal 2", "Hades", "Celeste", "Stardew Valley", "Hollow Knight", "Balatro",
"Dead Cells", "Terraria", "Vampire Survivors", "Slay the Spire", "Cuphead", "Inscryption",
).take(count).mapIndexed { i, name ->
com.droiddeck.launcher.frontend.Library.SteamGame(1000 + i, name, art = null, library = "steam", lastPlayed = 1_700_000_000_000L - i * 86_400_000L)
}
/** The pill a previewed Steam home shows, so the fake state is never mistaken for the real one. */
@Composable
internal fun SteamHomePreviewPill(modifier: Modifier = Modifier) {
val preview = DevPreview.steamHome
if (preview == SteamHomePreview.OFF) return
val colors = MaterialTheme.colorScheme
val pal = LocalPalette.current
val label = stringResource(
when (preview) {
SteamHomePreview.NONE -> R.string.dev_preview_steam_none
SteamHomePreview.FEW -> R.string.dev_preview_steam_few
else -> R.string.dev_preview_steam_many
},
)
val end = stringResource(R.string.dev_preview_end)
Row(
verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(10.dp),
modifier = modifier.background(colors.surface, CircleShape).border(1.dp, pal.signal, CircleShape)
.clickable(role = Role.Button, onClickLabel = end) { DevPreview.steamHome = SteamHomePreview.OFF }
.padding(start = 14.dp, end = 10.dp, top = 8.dp, bottom = 8.dp).testTag("dev-preview-steam-end"),
) {
Icon(Icons.Outlined.Visibility, null, tint = pal.signal, modifier = Modifier.size(18.dp))
Text(stringResource(R.string.dev_preview_banner, label), fontSize = 13.sp, fontWeight = FontWeight.SemiBold, color = colors.onBackground)
Icon(Icons.Filled.Close, end, tint = colors.onSurfaceVariant, modifier = Modifier.size(18.dp))
}
}
/** The pill a previewed Library shows, so the fake state is never mistaken for the real one. */
@Composable
internal fun LibraryPreviewPill(modifier: Modifier = Modifier) {
@@ -215,6 +255,17 @@ internal fun UiZooSheet() {
DrawerPreview.GAME to R.string.session_title_game,
)) ActionRow(stringResource(label), null, show, onClick = { close(); DevPreview.drawer = mode }, modifier = Modifier.testTag("zoo-drawer-${mode.name.lowercase()}"))
}
SettingsGroup(stringResource(R.string.dev_preview_steam_home)) {
for ((mode, label) in listOf(
SteamHomePreview.NONE to R.string.dev_preview_steam_none,
SteamHomePreview.FEW to R.string.dev_preview_steam_few,
SteamHomePreview.MANY to R.string.dev_preview_steam_many,
)) ActionRow(
stringResource(label), null, show,
onClick = { close(); DevPreview.steamHome = mode; DevPreview.openSteam = true },
modifier = Modifier.testTag("zoo-steam-${mode.name.lowercase()}"),
)
}
SettingsGroup(stringResource(R.string.dev_preview_library)) {
for ((mode, label) in listOf(
LibraryPreview.NOTHING_INSTALLED to R.string.dev_preview_library_nothing_installed,
@@ -272,7 +272,10 @@ private fun Content(
return
}
if (selected == "steam") {
SteamHome(s, a, modifier)
Box(modifier) {
SteamHome(s, a, Modifier.fillMaxSize())
SteamHomePreviewPill(Modifier.align(androidx.compose.ui.Alignment.BottomCenter).padding(bottom = 20.dp))
}
return
}
if (selected == "store") {
@@ -658,6 +658,11 @@ private fun FrontEndScreenBody(s: FrontEndState, a: FrontEndActions, page: (@Com
LaunchedEffect(SetupTabs.openSection) {
if (SetupTabs.openSection != null && (railSelection != "setup" || s.pageKey != null)) showRailPage("setup", true)
}
LaunchedEffect(DevPreview.openSteam) {
if (!DevPreview.openSteam) return@LaunchedEffect
DevPreview.openSteam = false
showRailPage("steam", true)
}
LaunchedEffect(DevPreview.openLibrary) {
if (!DevPreview.openLibrary) return@LaunchedEffect
DevPreview.openLibrary = false
@@ -113,7 +113,8 @@ internal fun SteamHome(s: FrontEndState, a: FrontEndActions, modifier: Modifier)
}
val owned = remember(ownedAll, concealed) { ownedAll.filter { it.first.toLong() !in concealed } }
val featured = remember(featuredAll, concealed) { featuredAll.filter { it.appId.toLong() !in concealed } }
val games = remember(s.steamGames, LibraryHidden.keys, LibraryHidden.steam) { s.steamGames.filterNot { LibraryHidden.isHidden(hideKey(it), it) }.sortedWith(compareByDescending<Library.SteamGame> { it.lastPlayed }.thenBy { it.gameId }) }
val previewing = DevPreview.steamHome
val games = remember(s.steamGames, previewing, LibraryHidden.keys, LibraryHidden.steam) { (if (previewing == SteamHomePreview.OFF) s.steamGames else sampleSteamHomeGames(previewing.games)).filterNot { LibraryHidden.isHidden(hideKey(it), it) }.sortedWith(compareByDescending<Library.SteamGame> { it.lastPlayed }.thenBy { it.gameId }) }
val narrow = LocalNarrowPane.current
var words by remember { mutableStateOf<Rect?>(null) }
val mode = com.droiddeck.launcher.session.SessionService.MODE_STEAM
@@ -163,12 +164,12 @@ internal fun SteamHome(s: FrontEndState, a: FrontEndActions, modifier: Modifier)
games.isEmpty() -> EmptyLibrary(
avoid = words,
wall = if (owned.isEmpty() && featured.isEmpty()) null else { { CapsuleWall(emptyList(), owned = owned, featured = featured) } },
) { Box(Modifier.fillMaxSize().graphicsLayer { scaleX = 1.06f; scaleY = 1.06f }) { WallFade() } }
) { Box(Modifier.fillMaxSize().graphicsLayer { scaleX = 1.06f; scaleY = 1.06f }) { WallFade(bottomWhenTall = true) } }
games.size < WALL_MIN_GAMES -> CapsuleFan(games)
else -> CapsuleWall(games, owned = owned, featured = featured)
}
},
scrim = { if (games.size >= WALL_MIN_GAMES) WallFade() },
scrim = { if (games.size >= WALL_MIN_GAMES) WallFade(bottomWhenTall = true) },
words = {
val onboardingActive by com.droiddeck.launcher.session.Onboarding.active.collectAsState()
val onboardingFailed by com.droiddeck.launcher.session.Onboarding.failed.collectAsState()
@@ -232,19 +233,35 @@ internal fun Modifier.overhang(by: androidx.compose.ui.unit.Dp = 4.dp): Modifier
}
@Composable
internal fun WallFade(modifier: Modifier = Modifier.fillMaxSize().overhang()) {
internal fun WallFade(modifier: Modifier = Modifier.fillMaxSize().overhang(), bottomWhenTall: Boolean = false) {
val colors = MaterialTheme.colorScheme
Box(
modifier.background(
Brush.horizontalGradient(
0f to colors.background.copy(alpha = 0.86f),
0.34f to colors.background.copy(alpha = 0.6f),
0.68f to colors.background.copy(alpha = 0.14f),
1f to colors.background.copy(alpha = 0.04f),
),
),
)
Box(modifier.background(Brush.verticalGradient(0.6f to Color.Transparent, 1f to colors.background.copy(alpha = 0.75f))))
BoxWithConstraints(modifier) {
if (bottomWhenTall && maxHeight > maxWidth) {
// The words sit at the bottom of a tall page, so the art stays clear above them and darkens only behind them.
Box(
Modifier.fillMaxSize().background(
Brush.verticalGradient(
0f to colors.background.copy(alpha = 0.12f),
0.5f to colors.background.copy(alpha = 0.18f),
0.72f to colors.background.copy(alpha = 0.72f),
1f to colors.background.copy(alpha = 0.94f),
),
),
)
} else {
Box(
Modifier.fillMaxSize().background(
Brush.horizontalGradient(
0f to colors.background.copy(alpha = 0.86f),
0.34f to colors.background.copy(alpha = 0.6f),
0.68f to colors.background.copy(alpha = 0.14f),
1f to colors.background.copy(alpha = 0.04f),
),
),
)
Box(Modifier.fillMaxSize().background(Brush.verticalGradient(0.6f to Color.Transparent, 1f to colors.background.copy(alpha = 0.75f))))
}
}
}
@Composable
@@ -387,31 +404,45 @@ private fun CapsuleFan(games: List<Library.SteamGame>) {
transition.animateFloat(0f, 1f, infiniteRepeatable(tween(ms, easing = FastOutSlowInEasing), RepeatMode.Reverse), label = "float")
}
val still = Motion.scale == 0f
val slots = listOf(
val landscape = listOf(
FanSlot(0.54f, 0.14f, 0.62f, -9f),
FanSlot(0.70f, 0.24f, 0.56f, 5f),
FanSlot(0.40f, 0.30f, 0.50f, -17f),
)
// A tall page sizes the cards from its width, so they fit any aspect; heights are fractions of the width.
val portrait = listOf(
FanSlot(0.27f, 0.11f, 0.70f, -9f),
FanSlot(0.55f, 0.19f, 0.64f, 5f),
FanSlot(0.04f, 0.26f, 0.56f, -17f),
)
BoxWithConstraints(
Modifier.fillMaxSize().drawBehind {
drawRect(
Brush.radialGradient(
listOf(pal.signal.copy(alpha = 0.14f), Color.Transparent),
center = Offset(size.width * 0.68f, size.height * 0.45f), radius = size.height * 0.6f,
center = if (size.height > size.width) Offset(size.width * 0.55f, size.height * 0.28f) else Offset(size.width * 0.68f, size.height * 0.45f),
radius = if (size.height > size.width) size.width * 0.9f else size.height * 0.6f,
),
)
},
) {
val radius = with(density) { 14.dp.toPx() }
val tall = maxHeight > maxWidth
val slots = if (tall) portrait else landscape
for (i in games.indices.reversed()) {
val slot = slots[i]
val h = maxHeight * slot.height
val h = if (tall) maxWidth * slot.height else maxHeight * slot.height
val x = if (tall) {
// The lean and the float swing the corners out by about h/2 * sin(angle).
val swing = h * kotlin.math.sin(Math.toRadians(kotlin.math.abs(slot.lean) + 2.0)).toFloat() / 2f
(maxWidth * slot.x).coerceIn(swing, (maxWidth - h * 2f / 3f - swing).coerceAtLeast(swing))
} else maxWidth * slot.x
val v: State<Float> = floats[i]
val look = WallCapsule(artBrush(hueOf(games[i].name)), games[i].art)
val art = look.art?.let { rememberCapsuleArt(it, with(density) { Size((h * 2f / 3f).toPx(), h.toPx()) }, radius) }
Spacer(
Modifier
.offset(x = maxWidth * slot.x, y = maxHeight * slot.y)
.offset(x = x, y = maxHeight * slot.y)
.size(h * 2f / 3f, h)
.graphicsLayer {
val t = if (still) 0f else v.value
+4
View File
@@ -4376,6 +4376,10 @@
<string name="dev_ui_zoo_open">Open</string>
<string name="dev_ui_zoo_show">Show</string>
<string name="dev_ui_zoo_note">Previews change nothing real: nothing is installed, removed or signed out, and the menu\'s switches save nothing. A Library preview stays until you end it from its pill or restart.</string>
<string name="dev_preview_steam_home">Steam home</string>
<string name="dev_preview_steam_none">No games installed</string>
<string name="dev_preview_steam_few">3 games installed</string>
<string name="dev_preview_steam_many">12 games installed</string>
<string name="dev_preview_library">Library</string>
<string name="dev_preview_library_nothing_installed">Nothing installed</string>
<string name="dev_preview_library_signed_out">Signed out of every store</string>
@@ -565,22 +565,7 @@ def online_cores():
cores = parse_cores(f.read().strip())
except OSError:
cores = None
return cores or allowed_cores() | set(range(os.cpu_count() or 0))
def allowed_cores(status="/proc/self/status"):
try:
with open(status) as f:
for line in f:
key, _, value = line.partition(":")
if key == "Cpus_allowed_list":
cores = parse_cores(value.strip())
if cores:
return cores
break
except OSError:
pass
return os.sched_getaffinity(0)
return cores or os.sched_getaffinity(0) | set(range(os.cpu_count() or 0))
def game_cores(env):
@@ -649,11 +634,11 @@ def cpu_topology(env, command=()):
fastest = env.get("DROIDDECK_FASTEST_CORES", "").strip() != "0" and game_id(env) is not None
if not (picked or fastest):
return
online = online_cores()
try:
cores = sorted(allowed_cores() & online)
cores = sorted(os.sched_getaffinity(0))
except OSError:
return
online = online_cores()
if not cores or cores[-1] >= len(online):
return
picked = picked and not set(cores) >= online
@@ -1114,6 +1099,7 @@ def newest_foreign_backup(backups):
def restore_compatible_system_dlls(prefix, proton, env=None):
restored = []
game = (env or {}).get("STEAM_COMPAT_INSTALL_PATH")
for folder, name, path, source, machines, builtins, backups in prefix_system_dlls(prefix, proton, env):
if not path.is_symlink() or not path.is_file():
continue
@@ -1126,7 +1112,7 @@ def restore_compatible_system_dlls(prefix, proton, env=None):
if backup is None or backup.is_symlink() or not backup.is_file():
continue
machine = pe_machine(backup)
if machine is None or not PE["machine_compatible"](backup, machines, machine, builtins, name):
if machine is None or not PE["machine_compatible"](backup, machines, machine, builtins, name, game):
continue
try:
os.replace(backup, path)
@@ -1138,11 +1124,12 @@ def restore_compatible_system_dlls(prefix, proton, env=None):
def repair_foreign_system_dlls(prefix, proton, env=None):
repaired = []
game = (env or {}).get("STEAM_COMPAT_INSTALL_PATH")
for folder, name, path, source, machines, builtins, backups in prefix_system_dlls(prefix, proton, env):
if path.is_symlink() or not path.is_file():
continue
machine = pe_machine(path)
if machine is None or PE["machine_compatible"](path, machines, machine, builtins):
if machine is None or PE["machine_compatible"](path, machines, machine, builtins, game=game):
continue
link = path.parent / (name + ".dd-new")
backup = path.parent / (name + FOREIGN_SUFFIX)
@@ -479,7 +479,7 @@ def save_state(compat, state):
os.replace(temp, compat / STATE)
def foreign_component(rel, path, machines, dist=None):
def foreign_component(rel, path, machines, dist=None, game=None):
parts = Path(rel).parts
folder = parts[2] if len(parts) > 2 and parts[:2] == ("drive_c", "windows") else None
if not machines or folder not in PE_MACHINES or not rel.lower().endswith(".dll"):
@@ -487,7 +487,7 @@ def foreign_component(rel, path, machines, dist=None):
machine = pe_machine(path)
libdir, compatible = machines[folder]
builtins = dist / libdir if dist else None
return machine is not None and not machine_compatible(path, compatible, machine, builtins)
return machine is not None and not machine_compatible(path, compatible, machine, builtins, game=game)
def pending_for(app_id, pending=PENDING):
@@ -549,6 +549,7 @@ def apply(compat_path, app_id, selection=SELECTION, store=STORE, pending=PENDING
placed_stems = set()
machines = PE["proton_pe_machines"](proton, env) if proton else None
dist = Path(proton).parent / "files/lib/wine" if proton else None
game = (env or {}).get("STEAM_COMPAT_INSTALL_PATH")
saved_overrides = state.get("overrides") if isinstance(state.get("overrides"), dict) else {}
saved_requires = state.get("requires") if isinstance(state.get("requires"), dict) else {}
recorded = [c for c in state.get("components", []) if isinstance(c, str) and valid_id(c)]
@@ -588,7 +589,7 @@ def apply(compat_path, app_id, selection=SELECTION, store=STORE, pending=PENDING
kept_requires[cid] = list(requires)
values += [(cid, value) for value in registry]
for rel, src in files:
foreign = foreign_component(rel, src, machines, dist)
foreign = foreign_component(rel, src, machines, dist, game)
if foreign:
skipped.add(Path(rel).stem.lower())
changed = False
@@ -609,9 +610,10 @@ def apply(compat_path, app_id, selection=SELECTION, store=STORE, pending=PENDING
path = existing(pfx / rel)
saved = compat / BACKUP / rel
if saved.is_file():
if foreign_component(rel, saved, machines, dist):
if foreign_component(rel, saved, machines, dist, game):
if path is not None and not path.is_symlink():
path.unlink()
keep[rel] = cid
continue
target = path or (pfx / rel)
os.replace(saved, target)
@@ -1,8 +1,12 @@
#!/usr/bin/python3
import mmap
import os
import re
from pathlib import Path
VC_RUNTIME = re.compile(r"(msvc[pr]\d.*|vcruntime\d.*|vcomp\d*|vcamp\d.*|vccorlib\d.*|concrt\d.*|mfcm?\d.*)\.dll",
re.IGNORECASE)
PE_MACHINES = {
"system32": ("aarch64-windows", frozenset((0xAA64, 0xA641))),
"syswow64": ("i386-windows", frozenset((0x14C,))),
@@ -79,8 +83,8 @@ def pe_has_arm64ec_metadata(path):
def pe_imports(path):
try:
with open(path, "rb") as source:
image = source.read()
except OSError:
image = mmap.mmap(source.fileno(), 0, access=mmap.ACCESS_READ)
except (OSError, ValueError):
return None
try:
if image[:2] != b"MZ":
@@ -137,9 +141,13 @@ def pe_imports(path):
return names
except (IndexError, ValueError):
return None
finally:
image.close()
PROGRAM_IMPORTS = {}
GAME_IMPORTS = {}
GAME_DEPTH = 4
def program_imports(builtins):
@@ -166,13 +174,42 @@ def program_imports(builtins):
return PROGRAM_IMPORTS[key]
def machine_compatible(path, machines, machine=None, builtins=None, name=None):
def game_imports(folder):
key = str(folder)
if key not in GAME_IMPORTS:
arm64, arm64ec = set(), set()
root = os.path.realpath(folder)
for top, dirs, files in os.walk(root):
if os.path.relpath(top, root).count(os.sep) >= GAME_DEPTH:
dirs[:] = []
for entry in files:
if not entry.lower().endswith((".exe", ".dll")):
continue
path = os.path.join(top, entry)
machine = pe_machine(path)
if machine == 0xAA64:
found = arm64
elif machine == 0x8664 and pe_has_arm64ec_metadata(path):
found = arm64ec
else:
continue
found |= pe_imports(path) or set()
GAME_IMPORTS[key] = (frozenset(arm64), frozenset(arm64ec))
return GAME_IMPORTS[key]
def machine_compatible(path, machines, machine=None, builtins=None, name=None, game=None):
machine = pe_machine(path) if machine is None else machine
if machine == 0x8664 and 0xA641 in machines:
if pe_has_arm64ec_metadata(path):
return True
imported = program_imports(builtins) if builtins is not None else None
return imported is not None and (name or Path(path).name).lower() not in imported
name = (name or Path(path).name).lower()
if game:
arm64, arm64ec = game_imports(game)
if name in arm64 or (name in arm64ec and VC_RUNTIME.fullmatch(name)):
return False
return imported is not None and name not in imported
if machine == 0x8664 and pe_has_arm64ec_metadata(path):
return False
return machine in machines
+118 -42
View File
@@ -1872,7 +1872,6 @@ class GameEnvironmentTest(unittest.TestCase):
for env, affinity, expected, proton in cases:
env["DROIDDECK_FASTEST_CORES"] = "0"
with mock.patch.dict(MODULE["cpu_topology"].__globals__, online), \
mock.patch.object(MODULE["allowed_cores"], "__defaults__", ("/missing/status",)), \
mock.patch.object(os_mod, "sched_getaffinity", return_value=affinity, create=True):
MODULE["cpu_topology"](env)
self.assertEqual(env.get("WINE_CPU_TOPOLOGY"), expected, env)
@@ -1987,7 +1986,6 @@ class GameEnvironmentTest(unittest.TestCase):
env.setdefault("STEAM_COMPAT_DATA_PATH", "/steam/compatdata/3608888694")
with mock.patch.dict(MODULE["cpu_topology"].__globals__, {"online_cores": lambda: every}), \
mock.patch.dict(MODULE["fastest_first"].__globals__, {"core_speeds": lambda cores, speeds=speeds: speeds}), \
mock.patch.object(MODULE["allowed_cores"], "__defaults__", ("/missing/status",)), \
mock.patch.object(os_mod, "sched_getaffinity", return_value=affinity, create=True):
MODULE["cpu_topology"](env, command)
self.assertEqual(env.get("WINE_CPU_TOPOLOGY"), expected, env)
@@ -1997,46 +1995,6 @@ class GameEnvironmentTest(unittest.TestCase):
self.assertEqual(MODULE["proton_cpu_limit"](command, {"SteamGameId": "1038250"}), "P")
self.assertEqual(MODULE["proton_cpu_limit"](command, {"SteamGameId": "618970"}), 4)
def test_windows_sees_the_same_cores_while_android_pauses_some(self):
os_mod = MODULE["os"]
kalama = {0: 411, 1: 411, 2: 411, 3: 869, 4: 869, 5: 869, 6: 869, 7: 1024}
every = set(range(8))
cases = [
({}, "0-7", {3, 4, 5, 6}, "8:7,3,4,5,6,0,1,2"),
({}, "0-7", {0, 1, 2, 3, 4, 5, 7}, "8:7,3,4,5,6,0,1,2"),
({}, "0-7", every, "8:7,3,4,5,6,0,1,2"),
({"DD_GAME_CPUS": "6,7"}, "6-7", {6}, "2:7,6"),
({"DROIDDECK_GAME_CORES": "3-7"}, "3-7", {3, 4, 5}, "5:7,3,4,5,6"),
({}, "0-9", {3, 4}, "8:7,3,4,5,6,0,1,2"),
({"DROIDDECK_FASTEST_CORES": "0"}, "0-7", {3, 4, 5, 6}, None),
({"STEAM_COMPAT_DATA_PATH": "/steam/compatdata/0"}, "0-7", {3, 4, 5, 6}, None),
]
with tempfile.TemporaryDirectory() as tmp:
status = Path(tmp) / "status"
for env, allowed, active, expected in cases:
env.setdefault("STEAM_COMPAT_DATA_PATH", "/steam/compatdata/1687950")
status.write_text("Name:\tpython3\nCpus_allowed:\tff\nCpus_allowed_list:\t%s\n" % allowed)
with mock.patch.dict(MODULE["cpu_topology"].__globals__, {"online_cores": lambda: every}), \
mock.patch.dict(MODULE["fastest_first"].__globals__, {"core_speeds": lambda cores: kalama}), \
mock.patch.object(MODULE["allowed_cores"], "__defaults__", (str(status),)), \
mock.patch.object(os_mod, "sched_getaffinity", return_value=active, create=True):
MODULE["cpu_topology"](env, ["/missing/proton", "waitforexitandrun", "/game/P5R.exe"])
self.assertEqual(env.get("WINE_CPU_TOPOLOGY"), expected, (env, allowed, active))
self.assertEqual(env.get("PROTON_CPU_TOPOLOGY"), expected, (env, allowed, active))
def test_allowed_cores_read_the_tasks_mask_before_the_active_one(self):
os_mod = MODULE["os"]
allowed = MODULE["allowed_cores"]
with tempfile.TemporaryDirectory() as tmp:
status = Path(tmp) / "status"
with mock.patch.object(os_mod, "sched_getaffinity", return_value={3, 4}, create=True):
status.write_text("Cpus_allowed_list:\t0-2,4,6-7\n")
self.assertEqual(allowed(str(status)), {0, 1, 2, 4, 6, 7})
for text in ("Name:\tpython3\n", "Cpus_allowed_list:\t\n", "Cpus_allowed_list:\tjunk\n"):
status.write_text(text)
self.assertEqual(allowed(str(status)), {3, 4}, text)
self.assertEqual(allowed(str(Path(tmp) / "missing")), {3, 4})
def test_core_speeds_read_capacity_then_top_clock(self):
with tempfile.TemporaryDirectory() as tmp:
for core, capacity, clock in ((0, "379", "2265600"), (1, None, "3302400")):
@@ -3541,6 +3499,22 @@ def program_image(machine, imports):
return bytes(image)
def arm64ec_program_image(imports):
image = bytearray(program_image(0x8664, imports))
directory = 68 + 20 + 112 + 10 * 8
image[directory:directory + 4] = (0x1100).to_bytes(4, "little")
image[directory + 4:directory + 8] = (0xD0).to_bytes(4, "little")
image[0x300:0x304] = (0xD0).to_bytes(4, "little")
image[0x3C8:0x3D0] = (0x10000000).to_bytes(8, "little")
return bytes(image)
def arm64x_program_image(imports):
image = bytearray(arm64ec_program_image(imports))
image[68:70] = (0xAA64).to_bytes(2, "little")
return bytes(image)
def bytes_path(folder, data):
path = folder / "image.exe"
path.write_bytes(data)
@@ -3615,6 +3589,108 @@ class ForeignSystemDllTest(unittest.TestCase):
self.assertFalse((windows / "system32" / name).is_symlink())
self.assertEqual(0x8664, MODULE["pe_machine"](windows / "system32" / name))
def arm64ec_game(self, tmp, shipping):
game = Path(tmp) / "common/Game"
binaries = game / "Game/Binaries/Win64"
binaries.mkdir(parents=True)
(game / "Game.exe").write_bytes(program_image(0x8664, ["kernel32.dll"]))
(binaries / "Game-Win64-Shipping.exe").write_bytes(shipping)
(binaries / "plugin.dll").write_bytes(program_image(0x8664, ["concrt140.dll"]))
return {"STEAM_COMPAT_INSTALL_PATH": str(game)}
def visual_cpp_prefix(self, tmp):
proton, compat, windows = self.prefix(tmp)
builtins = proton.parent / "files/lib/wine/aarch64-windows"
for name in ("vcruntime140.dll", "msvcp140.dll", "concrt140.dll", "vulkan-1.dll", "d3dcompiler_47.dll"):
(builtins / name).write_bytes(program_image(0xAA64, []))
(windows / "system32" / name.upper()).write_bytes(pe_image(0x8664))
return proton, compat, windows
def test_x64_runtime_an_arm64ec_game_image_imports_is_replaced_by_the_builtin(self):
with tempfile.TemporaryDirectory() as tmp:
proton, compat, windows = self.visual_cpp_prefix(tmp)
env = self.arm64ec_game(tmp, arm64ec_program_image(["VCRUNTIME140.dll", "MSVCP140.dll", "vulkan-1.dll"]))
fixed = MODULE["repair_foreign_system_dlls"](str(compat), str(proton), env)
self.assertEqual(["system32/MSVCP140.DLL (machine 0x8664)", "system32/VCRUNTIME140.DLL (machine 0x8664)"], fixed)
for name in ("CONCRT140.DLL", "VULKAN-1.DLL"):
self.assertFalse((windows / "system32" / name).is_symlink())
self.assertEqual(0x8664, MODULE["pe_machine"](windows / "system32" / name))
self.assertEqual([], MODULE["restore_compatible_system_dlls"](str(compat), str(proton), env))
self.assertEqual([], MODULE["repair_foreign_system_dlls"](str(compat), str(proton), env))
restored = MODULE["restore_compatible_system_dlls"](str(compat), str(proton))
self.assertEqual(2, len(restored))
self.assertFalse((windows / "system32/VCRUNTIME140.DLL").is_symlink())
def test_x64_runtime_stays_for_x64_games_and_launches_without_a_game_folder(self):
with tempfile.TemporaryDirectory() as tmp:
proton, compat, windows = self.visual_cpp_prefix(tmp)
env = self.arm64ec_game(tmp, program_image(0x8664, ["VCRUNTIME140.dll", "MSVCP140.dll"]))
self.assertEqual([], MODULE["repair_foreign_system_dlls"](str(compat), str(proton), env))
self.assertEqual([], MODULE["repair_foreign_system_dlls"](str(compat), str(proton), {}))
self.assertEqual([], MODULE["repair_foreign_system_dlls"](
str(compat), str(proton), {"STEAM_COMPAT_INSTALL_PATH": str(Path(tmp) / "missing")}))
for name in ("VCRUNTIME140.DLL", "MSVCP140.DLL"):
self.assertFalse((windows / "system32" / name).is_symlink())
def arm64_game(self, tmp, exe_imports, plugin_imports=()):
game = Path(tmp) / "common/Game"
binaries = game / "BinArm64"
binaries.mkdir(parents=True)
(game / "Game.exe").write_bytes(program_image(0x8664, ["kernel32.dll"]))
(binaries / "Game.arm64.exe").write_bytes(program_image(0xAA64, exe_imports))
(binaries / "plugin.dll").write_bytes(arm64x_program_image(list(plugin_imports)))
return {"STEAM_COMPAT_INSTALL_PATH": str(game)}
def test_x64_dlls_an_arm64_game_image_imports_are_replaced_by_the_builtins(self):
with tempfile.TemporaryDirectory() as tmp:
proton, compat, windows = self.visual_cpp_prefix(tmp)
env = self.arm64_game(tmp, ["MSVCP140.dll", "D3DCOMPILER_47.dll"], ["VCRUNTIME140.dll"])
fixed = MODULE["repair_foreign_system_dlls"](str(compat), str(proton), env)
self.assertEqual(["system32/D3DCOMPILER_47.DLL (machine 0x8664)", "system32/MSVCP140.DLL (machine 0x8664)",
"system32/VCRUNTIME140.DLL (machine 0x8664)"], fixed)
for name in ("D3DCOMPILER_47.DLL", "MSVCP140.DLL", "VCRUNTIME140.DLL"):
self.assertTrue((windows / "system32" / name).is_symlink())
self.assertEqual(0xAA64, MODULE["pe_machine"](windows / "system32" / name))
for name in ("CONCRT140.DLL", "VULKAN-1.DLL"):
self.assertFalse((windows / "system32" / name).is_symlink())
self.assertEqual(0x8664, MODULE["pe_machine"](windows / "system32" / name))
self.assertEqual([], MODULE["restore_compatible_system_dlls"](str(compat), str(proton), env))
self.assertEqual([], MODULE["repair_foreign_system_dlls"](str(compat), str(proton), env))
self.assertEqual(3, len(MODULE["restore_compatible_system_dlls"](str(compat), str(proton))))
self.assertFalse((windows / "system32/D3DCOMPILER_47.DLL").is_symlink())
def test_x64_dlls_an_arm64_game_does_not_import_stay(self):
with tempfile.TemporaryDirectory() as tmp:
proton, compat, windows = self.visual_cpp_prefix(tmp)
env = self.arm64_game(tmp, ["kernel32.dll"], ["user32.dll"])
self.assertEqual([], MODULE["repair_foreign_system_dlls"](str(compat), str(proton), env))
for name in ("D3DCOMPILER_47.DLL", "MSVCP140.DLL", "VCRUNTIME140.DLL"):
self.assertFalse((windows / "system32" / name).is_symlink())
def test_non_runtime_dlls_stay_for_x64_and_arm64ec_games(self):
for shipping in (program_image(0x8664, ["MSVCP140.dll", "D3DCOMPILER_47.dll"]),
arm64ec_program_image(["D3DCOMPILER_47.dll"])):
with tempfile.TemporaryDirectory() as tmp:
proton, compat, windows = self.visual_cpp_prefix(tmp)
env = self.arm64ec_game(tmp, shipping)
self.assertEqual([], MODULE["repair_foreign_system_dlls"](str(compat), str(proton), env))
for name in ("D3DCOMPILER_47.DLL", "MSVCP140.DLL"):
self.assertEqual(0x8664, MODULE["pe_machine"](windows / "system32" / name))
def test_arm64ec_images_below_the_scanned_depth_are_ignored(self):
with tempfile.TemporaryDirectory() as tmp:
proton, compat, windows = self.visual_cpp_prefix(tmp)
game = Path(tmp) / "common/Deep"
deep = game.joinpath(*("d%d" % level for level in range(MODULE["PE"]["GAME_DEPTH"] + 2)))
deep.mkdir(parents=True)
(deep / "tool.exe").write_bytes(arm64ec_program_image(["VCRUNTIME140.dll"]))
env = {"STEAM_COMPAT_INSTALL_PATH": str(game)}
self.assertEqual([], MODULE["repair_foreign_system_dlls"](str(compat), str(proton), env))
(deep.parent / "tool.exe").write_bytes(arm64ec_program_image(["VCRUNTIME140.dll"]))
MODULE["PE"]["GAME_IMPORTS"].clear()
self.assertEqual(["system32/VCRUNTIME140.DLL (machine 0x8664)"],
MODULE["repair_foreign_system_dlls"](str(compat), str(proton), env))
def test_repaired_dll_proton_programs_do_not_import_gets_its_native_copy_back(self):
with tempfile.TemporaryDirectory() as tmp:
proton, compat, windows = self.prefix(tmp)
+52
View File
@@ -6,6 +6,8 @@ import unittest
from pathlib import Path
from unittest import mock
from tools.tests.test_game_environment import arm64ec_program_image, program_image
BIN = Path(__file__).resolve().parents[1] / "linuxfs/overlay/usr/local/bin"
MODULE = runpy.run_path(str(BIN / "droiddeck-wincomponents"))
GAME_ENV = runpy.run_path(str(BIN / "droiddeck-game-env"))
@@ -169,6 +171,56 @@ class WinComponentsTest(unittest.TestCase):
self.assertEqual(MODULE["pe_machine"](self.pfx / "system32/msvcp140.dll"), 0x8664)
self.assertEqual(MODULE["pe_machine"](self.pfx / "system32/vcruntime140.dll"), 0x8664)
def test_x64_runtime_an_arm64ec_game_imports_is_not_placed(self):
proton = self.proton()
game = Path(self.tmp.name) / "common/Game/Game/Binaries/Win64"
game.mkdir(parents=True)
(game / "Game-Win64-Shippingarm64ec.exe").write_bytes(arm64ec_program_image(["MSVCP140.dll", "VCRUNTIME140.dll"]))
names = ["concrt140", "msvcp140", "vcruntime140"]
self.component("vc", names, {"system32/%s.dll" % name: self.pe_image(0x8664) for name in names})
self.pick("vc")
env = {"STEAM_COMPAT_INSTALL_PATH": str(game.parents[2])}
for _ in range(2):
placed, _ = self.apply(proton, env)
self.assertEqual(placed, ["concrt140"])
self.assertEqual(MODULE["pe_machine"](self.pfx / "system32/concrt140.dll"), 0x8664)
self.assertFalse((self.pfx / "system32/msvcp140.dll").exists())
self.assertFalse((self.pfx / "system32/vcruntime140.dll").exists())
def arm64_game(self, imports):
game = Path(self.tmp.name) / "common/Game/BinArm64"
game.mkdir(parents=True)
(game / "Game.arm64.exe").write_bytes(program_image(0xAA64, imports))
return {"STEAM_COMPAT_INSTALL_PATH": str(game.parent)}
def test_x64_dlls_an_arm64_game_imports_are_not_placed(self):
proton = self.proton()
env = self.arm64_game(["MSVCP140.dll", "D3DCOMPILER_47.dll"])
names = ["concrt140", "d3dcompiler_47", "msvcp140", "vcruntime140"]
self.component("vc", names, {"system32/%s.dll" % name: self.pe_image(0x8664) for name in names})
self.pick("vc")
for _ in range(2):
placed, _ = self.apply(proton, env)
self.assertEqual(placed, ["concrt140", "vcruntime140"])
self.assertEqual(MODULE["pe_machine"](self.pfx / "system32/vcruntime140.dll"), 0x8664)
self.assertFalse((self.pfx / "system32/msvcp140.dll").exists())
self.assertFalse((self.pfx / "system32/d3dcompiler_47.dll").exists())
def test_saved_original_stays_tracked_while_a_game_defers_its_restoration(self):
proton = self.proton()
original = self.pe_image(0x8664) + b"original"
self.pfx.joinpath("system32").mkdir(parents=True)
self.pfx.joinpath("system32/msvcp140.dll").write_bytes(original)
self.component("vc", ["msvcp140"], {"system32/msvcp140.dll": self.pe_image(0x8664)})
self.pick("vc")
self.apply(proton)
self.assertNotEqual(original, (self.pfx / "system32/msvcp140.dll").read_bytes())
self.pick()
self.apply(proton, self.arm64_game(["MSVCP140.dll"]))
self.assertFalse((self.pfx / "system32/msvcp140.dll").exists())
self.apply(proton)
self.assertEqual(original, (self.pfx / "system32/msvcp140.dll").read_bytes())
def test_deselected_component_restores_the_saved_x64_dll(self):
proton = self.proton()
self.pfx.joinpath("system32").mkdir(parents=True)