Compare commits

..
Author SHA1 Message Date
The412Banner 3c8d4c508d fix(gog): download gen1 depot files from the build's main.bin 2026-11-29 23:34:58 +00:00
10 changed files with 49 additions and 120 deletions

No files matched your search

@@ -2987,12 +2987,10 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
Log.i(TAG, "hdr: " + (if (on) "on" else "off") + " for this $mode session")
}
com.droiddeck.launcher.gpu.DriverSetupLog.write(this, "compositor.start driver=$driverId")
val outputRefresh = refreshHz(holder)
CompositorHost.startOrAttach(
this, holder.surface, runtimeDir.path,
driverId?.let { turnip.driverPath(it) }, driverId?.let { turnip.libraryName(it) },
applicationInfo.nativeLibraryDir, size.first, size.second, outputRefresh, outputFpsLimit(),
outputFrameRateVote(outputRefresh),
applicationInfo.nativeLibraryDir, size.first, size.second, refreshHz(holder), outputFpsLimit(),
)
onOutputAttached(holder)
if (SessionState.running && size != previous) {
@@ -3202,9 +3200,6 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
}
}
private fun outputFrameRateVote(hz: Float): Float =
if (glassesScreen == null && !bottomOutputActive && !panelHeld) PerfMode.frameRateVote(this, hz) else hz
private fun applyOutputPacing() {
val frameGen = appliedFrameGenMode
pacedFrameGenMode = frameGen
@@ -3223,7 +3218,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
)
val hz = refreshHz()
val changed = kotlin.math.abs(SessionState.refreshHz - hz) > 0.1f
CompositorHost.updatePacing(hz, outputFpsLimit(), outputFrameRateVote(hz))
CompositorHost.updatePacing(hz, outputFpsLimit())
pushCardboard(activeCardboard)
if (changed && ::surfaceView.isInitialized) applyFrameGen()
}
@@ -82,16 +82,6 @@ object PerfMode {
internal fun panelHeld(requestedHz: Float, activeHz: Float): Boolean =
requestedHz > 1f && activeHz > 1f && Math.abs(requestedHz - activeHz) > 0.5f
fun frameRateVote(a: Activity, activeHz: Float): Float = try {
val display = if (Build.VERSION.SDK_INT >= 30) a.display else @Suppress("DEPRECATION") a.windowManager.defaultDisplay
val wanted = a.window.attributes.preferredDisplayModeId
val requested = display?.supportedModes?.firstOrNull { wanted != 0 && it.modeId == wanted }
frameRateVote(requested?.refreshRate ?: 0f, activeHz)
} catch (t: Throwable) { Log.w(TAG, "frame rate vote", t); activeHz }
internal fun frameRateVote(requestedHz: Float, activeHz: Float): Float =
requestedHz.takeIf { it > 1f } ?: activeHz
fun pacedRate(ownLimit: Int, limiterRate: Int, limiterRefresh: Int, steadyRate: Int): Int = when {
ownLimit > 0 -> ownLimit
limiterRate <= 0 -> steadyRate
@@ -136,7 +136,7 @@ internal object GogContent {
val file = JSONObject().put("path", path).put("size", size).put("directory", directory)
.put("md5", entry.optString("md5").ifBlank { entry.optString("hash") }.takeIf { it.matches(Regex("[a-fA-F0-9]{32}")) }.orEmpty())
.put("sha256", entry.optString("sha256")).put("chunks", chunks).put("product", product)
.put("offset", entry.optLong("offset")).put("remotePath", entry.optString("url").substringBefore('?'))
.put("offset", entry.optLong("offset")).put("remotePath", remotePath(entry.optString("url"), build.generation))
val position = if (build.generation == 2) overlayPositions.putIfAbsent(path, files.length()) else null
if (position == null) files.put(file) else {
require(files.getJSONObject(position).getBoolean("directory") == directory)
@@ -149,6 +149,10 @@ internal object GogContent {
branch = build.branch, language = resolvedLanguage, manifest = sanitize(manifest), files = files, products = products.toList(), verified = true)
}
fun remotePath(url: String, generation: Int): String = url.substringBefore('?').let {
if (generation == 1 && !it.startsWith("https://")) it.substringAfterLast('/') else it
}
fun languageSelected(list: List<String>, selected: String): Boolean = list.any { it.equals("Neutral", true) } || StoreLanguage.depotMatchesResolved(list.toTypedArray(), selected)
fun cdnPath(hash: String): String {
@@ -94,16 +94,17 @@ internal object XboxManifest {
}
fun executable(folder: File): String {
val listed = read(folder).executables
for (path in listed) {
for (path in read(folder).executables) {
require(!path.startsWith('/') && !path.contains(':') && path.split('/').none { it == ".." || it.isEmpty() })
val file = path.split('/').fold<String, File?>(folder) { dir, part ->
dir?.listFiles().orEmpty().filter { it.name.equals(part, true) }.singleOrNull()
} ?: continue
var file = folder
for (part in path.split('/')) {
val matches = file.listFiles().orEmpty().filter { it.name.equals(part, true) }
require(matches.size == 1) { "Missing or ambiguous Xbox launch path." }
file = matches.single()
}
require(file.canonicalPath.startsWith(folder.canonicalPath + File.separator))
if (file.isFile) return forwarded(folder, file) ?: file.relativeTo(folder).invariantSeparatorsPath
}
require(listed.isEmpty()) { "Missing or ambiguous Xbox launch path." }
error("The Xbox package has no supported PC launch executable.")
}
@@ -4,7 +4,6 @@ import android.os.Build
import android.os.Handler
import android.os.HandlerThread
import android.os.Process
import android.util.Log
import android.view.Choreographer
import android.view.Surface
import com.droiddeck.launcher.session.SessionPrefs
@@ -68,14 +67,13 @@ object CompositorHost {
outputHeight: Int,
refreshHz: Float,
fpsLimit: Int,
frameRateVote: Float = refreshHz,
): Boolean {
WaylandCompositor.nativeSetClockControl(java.io.File(context.filesDir, "${com.droiddeck.launcher.runtime.LinuxRuntime.DIR}/tmp/.dd-clock").path)
ownVsyncThread = SessionPrefs.vsyncThread(context)
WaylandCompositor.nativeSetRenderOnCommit(SessionPrefs.renderOnCommit(context))
blackFrameInsertion = SessionPrefs.blackFrameInsertion(context)
WaylandCompositor.nativeSetBlackFrameInsertion(blackFrameInsertion)
pace(refreshHz, fpsLimit, frameRateVote)
pace(refreshHz, fpsLimit)
if (!SessionState.running) WaylandCompositor.nativeSetOutputSize(outputWidth, outputHeight)
if (started) {
attached = surface
@@ -97,21 +95,16 @@ object CompositorHost {
private var blackFrameInsertion = false
private var pictureHolds = 0
private fun pace(refreshHz: Float, fpsLimit: Int, frameRateVote: Float = refreshHz) {
private fun pace(refreshHz: Float, fpsLimit: Int) {
WaylandCompositor.nativeSetFpsLimit(fpsLimit)
surfaceFrameRate = layerFrameRate(frameRateVote, fpsLimit, blackFrameInsertion)
applySurfaceFrameRate()
WaylandCompositor.nativeSetLayerFrameRate(surfaceFrameRate)
WaylandCompositor.nativeSetLayerFrameRate(if (fpsLimit > 0 && !blackFrameInsertion) fpsLimit.toFloat() else refreshHz)
WaylandCompositor.nativeSetOutputRefreshRate(refreshHz)
SessionState.refreshHz = refreshHz
}
internal fun layerFrameRate(refreshHz: Float, fpsLimit: Int, blackFrameInsertion: Boolean): Float =
if (fpsLimit > 0 && !blackFrameInsertion) fpsLimit.toFloat() else refreshHz
@Synchronized
fun updatePacing(refreshHz: Float, fpsLimit: Int, frameRateVote: Float = refreshHz) {
if (started) pace(refreshHz, fpsLimit, frameRateVote)
fun updatePacing(refreshHz: Float, fpsLimit: Int) {
if (started) pace(refreshHz, fpsLimit)
}
@Synchronized
@@ -153,31 +146,7 @@ object CompositorHost {
android.os.Handler(android.os.Looper.getMainLooper()).postDelayed(rearm, 600)
}
private var surfaceFrameRate = 0f
private var appliedSurfaceFrameRate = Float.NaN
private var attached: Surface? = null
set(value) {
field = value
appliedSurfaceFrameRate = Float.NaN
applySurfaceFrameRate()
}
private fun applySurfaceFrameRate() {
val surface = attached ?: return
if (Build.VERSION.SDK_INT < 30 || !surface.isValid || appliedSurfaceFrameRate == surfaceFrameRate) return
try {
if (Build.VERSION.SDK_INT >= 31) {
surface.setFrameRate(surfaceFrameRate, Surface.FRAME_RATE_COMPATIBILITY_DEFAULT, Surface.CHANGE_FRAME_RATE_ALWAYS)
} else {
surface.setFrameRate(surfaceFrameRate, Surface.FRAME_RATE_COMPATIBILITY_DEFAULT)
}
appliedSurfaceFrameRate = surfaceFrameRate
} catch (t: IllegalArgumentException) {
Log.w("CompositorHost", "surface frame rate", t)
} catch (t: IllegalStateException) {
Log.w("CompositorHost", "surface frame rate", t)
}
}
@Synchronized
fun attachXr() {
@@ -270,7 +270,8 @@ pub fn run(req: &GogRequest, cancel: &AtomicBool, events: &dyn GogEvents) -> Gog
let offset = num(file, "offset");
let remote = text(file, "remotePath");
let endpoints = if remote.starts_with("https://") { vec![remote.to_string()] } else { urls(&plan["links"], text(file, "product"), remote.trim_start_matches('/')) };
transfer.fetch(&endpoints, Some((offset, offset + num(file, "size") - 1)), &stage, num(file, "size"))?;
transfer.fetch(&endpoints, Some((offset, offset + num(file, "size") - 1)), &stage, num(file, "size"))
.map_err(|e| format!("{e} file={} remote={remote}", text(file, "path")))?;
} else {
let mut output = OpenOptions::new().create(true).truncate(false).read(true).write(true).open(&stage).map_err(|e| e.to_string())?;
let mut offset = 0u64;
@@ -286,7 +287,8 @@ pub fn run(req: &GogRequest, cancel: &AtomicBool, events: &dyn GogEvents) -> Gog
std::io::copy(&mut source.take(old.size), &mut output).map_err(|e| e.to_string())?;
reused += old.size;
} else {
download_chunk(&mut transfer, &plan["links"], text(file, "product"), chunk, &stage.with_extension("packed"), &mut output)?;
download_chunk(&mut transfer, &plan["links"], text(file, "product"), chunk, &stage.with_extension("packed"), &mut output)
.map_err(|e| format!("{e} file={}", text(file, "path")))?;
}
offset += num(chunk, "size");
}
@@ -462,6 +464,20 @@ mod tests {
assert_eq!(server.bytes.load(Ordering::Relaxed), 4);
}
#[test]
fn failed_fetches_name_the_file_and_remote_path() {
let temp = Temp::new(); let missing = Server::new(HashMap::new(), true);
let ranged = json!([{"path":"support/1/setup.exe", "size":4, "chunks":[], "product":"1", "remotePath":"main.bin", "offset":0}]);
let result = execute(&temp.0, ranged, json!([]), &missing);
assert!(result.link_expiry, "{}", result.error);
assert_eq!(result.error, "HTTP 404 file=support/1/setup.exe remote=main.bin");
let (a, _, _) = chunk(b"data");
let chunked = json!([{"path":"Data/pack.dat", "size":4, "md5":md5_hex(b"data"), "chunks":[a], "product":"1"}]);
let result = execute(&temp.0, chunked, json!([]), &missing);
assert!(result.link_expiry, "{}", result.error);
assert_eq!(result.error, "HTTP 404 file=Data/pack.dat");
}
#[test]
fn bad_chunks_never_replace_original_and_expired_links_are_reported() {
let temp = Temp::new(); fs::write(temp.0.join("game"), b"old!").unwrap();
@@ -17,22 +17,6 @@ class PerfModeTest {
ShadowDisplayManager.ModeBuilder.modeBuilder(id)
.setWidth(width).setHeight(2520).setRefreshRate(hz).build()
@Test fun aPendingModeSwitchVotesForTheSelectedRateWithoutChangingMeasuredPacing() {
assertEquals(185f, PerfMode.frameRateVote(185f, 60f), 0f)
assertEquals(60f, PerfMode.frameRateVote(60f, 185f), 0f)
assertEquals(120f, PerfMode.frameRateVote(120f, 120f), 0f)
assertEquals(60f, PerfMode.frameRateVote(0f, 60f), 0f)
}
@Test fun aSurfaceVoteUsesTheSelectedCapAndGuestCadence() {
val modes = arrayOf(mode(1, 60f), mode(2, 90f), mode(3, 120f), mode(4, 185f))
val current = modes[0]
val capped = PerfMode.selectMode(modes, current, 0, 90f)!!
val limited = PerfMode.selectMode(modes, current, 60, Float.POSITIVE_INFINITY)!!
assertEquals(90f, PerfMode.frameRateVote(capped.refreshRate, 60f), 0f)
assertEquals(120f, PerfMode.frameRateVote(limited.refreshRate, 60f), 0f)
}
@Test fun sixtyHzMirrorChoosesSixtyEvenThoughOneTwentyHasMatchingCadence() {
val low = mode(1, 60f)
val high = mode(2, 120f)
@@ -270,9 +270,20 @@ class GogMaintenanceTest {
val game = snapshot.files.getJSONObject(1)
assertEquals("Data/World/Levels/Raycap/Raycap.snd", game.getString("path"))
assertEquals(384206096L, game.getLong("offset"))
assertEquals("1207658940/main.bin", game.getString("remotePath"))
assertEquals("main.bin", game.getString("remotePath"))
assertEquals("main.bin", support.getString("remotePath"))
assertTrue(requested.drop(1).all { "/1207658940/windows/31847977/" in it })
GogFiles.validate(snapshot.files, temporary.newFolder())
val secureLink = "https://cdn.example.invalid/token=abc/content-system/v1/depots/1207658940/windows/31847977/"
assertEquals(listOf("${secureLink}main.bin"), GogFallback.endpoints(JSONObject().put("1207658940", JSONArray().put(secureLink)),
game.getString("product"), game.getString("remotePath")))
}
@Test fun onlyRelativeGenerationOneUrlsAreReducedToTheirFileName() {
assertEquals("main.bin", GogContent.remotePath("1207663863/main.bin?expires=1", 1))
assertEquals("https://cdn.example.invalid/1207663863/main.bin", GogContent.remotePath("https://cdn.example.invalid/1207663863/main.bin?expires=1", 1))
assertEquals("1207663863/main.bin", GogContent.remotePath("1207663863/main.bin", 2))
assertEquals("", GogContent.remotePath("", 1))
}
@Test fun multipartPatchNamesVersionsLanguageAndChecksumsSurviveParsing() {
@@ -16,34 +16,6 @@ class XboxManifestTest {
java.io.File(root, "MicrosoftGame.Config").writeText("<Game><ExecutableList><Executable Name=\"bin\\GAME.EXE\" TargetDeviceFamily=\"PC\"/></ExecutableList></Game>")
assertEquals("Bin/Game.exe", XboxInstaller.executable(root))
}
@Test fun aListedExecutableThePackageDoesNotShipFallsThroughToTheNextOne() {
val root = temporary.newFolder()
java.io.File(root, "bin/x64_dx12").mkdirs()
java.io.File(root, "bin/x64_dx12/game.exe").writeText("encrypted")
java.io.File(root, "MicrosoftGame.config").writeText("<Game><ExecutableList>" +
"<Executable Name=\"bin\\x64\\game.exe\" TargetDeviceFamily=\"PC\"/>" +
"<Executable Name=\"Launcher\\start.exe\" TargetDeviceFamily=\"PC\"/>" +
"<Executable Name=\"bin\\x64_dx12\\game.exe\" TargetDeviceFamily=\"PC\"/></ExecutableList></Game>")
assertEquals("bin/x64_dx12/game.exe", XboxInstaller.executable(root))
}
@Test fun anAmbiguouslyCasedExecutableFallsThroughToTheNextOne() {
val root = temporary.newFolder()
java.io.File(root, "Game.exe").writeText("one")
java.io.File(root, "GAME.exe").writeText("two")
java.io.File(root, "Other.exe").writeText("three")
org.junit.Assume.assumeTrue(root.listFiles().orEmpty().count { it.name.equals("game.exe", true) } == 2)
java.io.File(root, "MicrosoftGame.config").writeText("<Game><ExecutableList>" +
"<Executable Name=\"game.exe\"/><Executable Name=\"Other.exe\"/></ExecutableList></Game>")
assertEquals("Other.exe", XboxInstaller.executable(root))
}
@Test fun aPackageWithNoneOfItsListedExecutablesStillFails() {
val root = temporary.newFolder()
java.io.File(root, "Unlisted.exe").writeText("encrypted")
java.io.File(root, "MicrosoftGame.config").writeText("<Game><ExecutableList>" +
"<Executable Name=\"bin\\Game.exe\"/><Executable Name=\"Game.exe\"/></ExecutableList></Game>")
val failure = assertThrows(IllegalArgumentException::class.java) { XboxInstaller.executable(root) }
assertEquals("Missing or ambiguous Xbox launch path.", failure.message)
}
@Test fun aLauncherMenuIsSkippedForTheProgramItNames() {
val root = temporary.newFolder()
java.io.File(root, "EmuMenu").mkdir()
@@ -1,13 +0,0 @@
package com.droiddeck.launcher.wayland
import org.junit.Assert.assertEquals
import org.junit.Test
class CompositorHostTest {
@Test fun aPendingRefreshVotePreservesExplicitLimitsAndBlackFrameInsertion() {
assertEquals(185f, CompositorHost.layerFrameRate(185f, 0, false), 0f)
assertEquals(30f, CompositorHost.layerFrameRate(185f, 30, false), 0f)
assertEquals(185f, CompositorHost.layerFrameRate(185f, 30, true), 0f)
assertEquals(60f, CompositorHost.layerFrameRate(60f, 0, false), 0f)
}
}