From 34c8025591f58e29294f883541daedbb641b2472 Mon Sep 17 00:00:00 2001 From: The412Banner <205237651+The412Banner@users.noreply.github.com> Date: Fri, 20 Nov 2026 18:07:55 +0000 Subject: [PATCH] fix(rockstar): fetch the Social Club installer from the launcher build when a game ships none --- .../launcher/stores/StoreLaunchRequests.kt | 2 + .../stores/rockstar/RockstarInstaller.kt | 111 +++++++++--------- .../stores/rockstar/RockstarLaunch.kt | 47 +++++++- .../launcher/stores/rockstar/RockstarTest.kt | 9 ++ .../usr/local/bin/droiddeck-store-launch | 22 +++- tools/rockstar-launcher/README.md | 2 +- tools/tests/test_store_launch_rockstar.py | 51 ++++++++ 7 files changed, 182 insertions(+), 62 deletions(-) diff --git a/app/src/main/java/com/droiddeck/launcher/stores/StoreLaunchRequests.kt b/app/src/main/java/com/droiddeck/launcher/stores/StoreLaunchRequests.kt index cc231dfcb8..1536a78d22 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/StoreLaunchRequests.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/StoreLaunchRequests.kt @@ -90,6 +90,8 @@ object StoreLaunchRequests { lastLaunched = Store.ROCKSTAR to request.optString("id") com.droiddeck.launcher.stores.rockstar.RockstarLaunch.prepare(app, request.optString("id")) }.getOrElse { JSONObject().put("ok", false).put("reason", "error-" + it.javaClass.simpleName) } + "rockstar-sdk" -> runCatching { com.droiddeck.launcher.stores.rockstar.RockstarLaunch.sdkInstaller(app, request.optString("id")) } + .getOrElse { JSONObject().put("ok", false).put("reason", "error-" + it.javaClass.simpleName) } "store-service" -> runCatching { val root = com.droiddeck.launcher.runtime.LinuxRuntime.rootDir(app) if (com.droiddeck.launcher.session.SessionFiles.awaitStoreService(app, request.optString("store"), root)) JSONObject().put("ok", true) diff --git a/app/src/main/java/com/droiddeck/launcher/stores/rockstar/RockstarInstaller.kt b/app/src/main/java/com/droiddeck/launcher/stores/rockstar/RockstarInstaller.kt index ac039d95f9..84804a59a2 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/rockstar/RockstarInstaller.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/rockstar/RockstarInstaller.kt @@ -99,6 +99,11 @@ internal object RockstarManifest { } fun key(file: RockstarFile, chunk: RockstarChunk) = "${file.versionId}:${chunk.chunkId}" + + fun sdkInstaller(build: RockstarBuild): RockstarFile? { + val name = RockstarLaunch.SDK_INSTALLER.substringAfterLast('/') + return build.files.filter { it.path.substringAfterLast('/').equals(name, ignoreCase = true) }.minByOrNull { it.path.length } + } } internal class RockstarInstaller( @@ -160,7 +165,7 @@ internal class RockstarInstaller( for (c in batch) { if (cancelled.get()) break val f = fileOf.getValue("${c.fileEntryId}:${c.chunkId}") - fetch({ retry -> (if (retry) null else urls[c.chunkId]) ?: chunkUrls(ticket, branch.accessToken, listOf(c)).getValue(c.chunkId) }, RockstarManifest.inside(folder, f.path), c, progress) { + fetch(cancelled::get, { retry -> (if (retry) null else urls[c.chunkId]) ?: chunkUrls(ticket, branch.accessToken, listOf(c)).getValue(c.chunkId) }, RockstarManifest.inside(folder, f.path), c, progress) { handle.progress(progress.get(), total, "Downloading (${build.files.size} files)") } synchronized(ledgerLock) { ledger.appendText(RockstarManifest.key(f, c) + "\n") } @@ -191,58 +196,6 @@ internal class RockstarInstaller( return folder.path } - private fun chunkUrls(ticket: String, branchToken: String, batch: List): Map { - val csv = batch.joinToString(",") { "${it.fileEntryId}:${it.chunkId}" } - val root = RockstarRos.result("app.asmx/RetrieveFileChunkMulti", listOf("ticket" to ticket, "branchAccessToken" to branchToken, "fileEntryAndChunkIdCsv" to csv)) - return RockstarRos.all(root, "Chunk").mapNotNull { c -> RockstarRos.text(c, "RedirectUrl")?.let { c.getAttribute("FileChunkId") to it } }.toMap() - } - - private fun fetch(url: (Boolean) -> String, target: File, chunk: RockstarChunk, progress: AtomicLong, report: () -> Unit) { - var lastError: Exception? = null - for (attempt in 0 until 3) { - if (cancelled.get()) return - val written = AtomicLong(0) - try { - val c = URL(url(attempt > 0)).openConnection() as HttpURLConnection - c.connectTimeout = 20_000 - c.readTimeout = 60_000 - try { - if (c.responseCode != 200) throw java.io.IOException("chunk ${chunk.chunkId}: HTTP ${c.responseCode}") - val digest = MessageDigest.getInstance("SHA-256") - RandomAccessFile(target, "rw").use { out -> - out.seek(chunk.offset) - c.inputStream.use { input -> - val buf = ByteArray(256 * 1024) - var last = 0L - while (true) { - if (cancelled.get()) { progress.addAndGet(-written.get()); return } - val n = input.read(buf) - if (n < 0) break - if (written.get() + n > chunk.size) throw java.io.IOException("chunk ${chunk.chunkId} is longer than the manifest says") - out.write(buf, 0, n) - digest.update(buf, 0, n) - written.addAndGet(n.toLong()) - progress.addAndGet(n.toLong()) - val now = System.currentTimeMillis() - if (now - last > 400) { last = now; report() } - } - } - } - val hex = digest.digest().joinToString("") { "%02x".format(it) } - if (written.get() != chunk.size || hex != chunk.sha256) throw java.io.IOException("chunk ${chunk.chunkId} failed its check") - report() - return - } finally { - c.disconnect() - } - } catch (e: Exception) { - progress.addAndGet(-written.get()) - lastError = e - } - } - throw lastError ?: java.io.IOException("chunk ${chunk.chunkId} failed") - } - override fun cancel(deleteFiles: Boolean) { cancelled.set(true) if (deleteFiles) StoreInstalls.discard(app, folder, emptyList()) @@ -252,6 +205,58 @@ internal class RockstarInstaller( const val LEDGER = ".droiddeck-rockstar-chunks" private const val WORKERS = 4 + fun chunkUrls(ticket: String, branchToken: String, batch: List): Map { + val csv = batch.joinToString(",") { "${it.fileEntryId}:${it.chunkId}" } + val root = RockstarRos.result("app.asmx/RetrieveFileChunkMulti", listOf("ticket" to ticket, "branchAccessToken" to branchToken, "fileEntryAndChunkIdCsv" to csv)) + return RockstarRos.all(root, "Chunk").mapNotNull { c -> RockstarRos.text(c, "RedirectUrl")?.let { c.getAttribute("FileChunkId") to it } }.toMap() + } + + fun fetch(cancelled: () -> Boolean, url: (Boolean) -> String, target: File, chunk: RockstarChunk, progress: AtomicLong, report: () -> Unit) { + var lastError: Exception? = null + for (attempt in 0 until 3) { + if (cancelled()) return + val written = AtomicLong(0) + try { + val c = URL(url(attempt > 0)).openConnection() as HttpURLConnection + c.connectTimeout = 20_000 + c.readTimeout = 60_000 + try { + if (c.responseCode != 200) throw java.io.IOException("chunk ${chunk.chunkId}: HTTP ${c.responseCode}") + val digest = MessageDigest.getInstance("SHA-256") + RandomAccessFile(target, "rw").use { out -> + out.seek(chunk.offset) + c.inputStream.use { input -> + val buf = ByteArray(256 * 1024) + var last = 0L + while (true) { + if (cancelled()) { progress.addAndGet(-written.get()); return } + val n = input.read(buf) + if (n < 0) break + if (written.get() + n > chunk.size) throw java.io.IOException("chunk ${chunk.chunkId} is longer than the manifest says") + out.write(buf, 0, n) + digest.update(buf, 0, n) + written.addAndGet(n.toLong()) + progress.addAndGet(n.toLong()) + val now = System.currentTimeMillis() + if (now - last > 400) { last = now; report() } + } + } + } + val hex = digest.digest().joinToString("") { "%02x".format(it) } + if (written.get() != chunk.size || hex != chunk.sha256) throw java.io.IOException("chunk ${chunk.chunkId} failed its check") + report() + return + } finally { + c.disconnect() + } + } catch (e: Exception) { + progress.addAndGet(-written.get()) + lastError = e + } + } + throw lastError ?: java.io.IOException("chunk ${chunk.chunkId} failed") + } + fun resolve(folder: File, configured: String): String? { var at = folder for (part in configured.replace('\\', '/').split('/').filter { it.isNotEmpty() }) { diff --git a/app/src/main/java/com/droiddeck/launcher/stores/rockstar/RockstarLaunch.kt b/app/src/main/java/com/droiddeck/launcher/stores/rockstar/RockstarLaunch.kt index 52f1119f90..6dceeb386b 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/rockstar/RockstarLaunch.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/rockstar/RockstarLaunch.kt @@ -10,6 +10,10 @@ import java.security.MessageDigest import java.util.Base64 object RockstarLaunch { + internal const val SDK_INSTALLER = "Redistributables/Social-Club-Setup.exe" + private const val LAUNCHER_APP = "launcher" + private val sdkLock = Any() + internal val pipes = mapOf("gta3" to "GTA3_Pipe", "gtavc" to "GTA-VC_Pipe", "gtasa" to "GTA_SA_Pipe", "gta4" to "GTAIV_Pipe", "lanoire" to "LANOIRE_Pipe") fun usesClassicLauncher(id: String) = id in pipes @@ -22,10 +26,47 @@ object RockstarLaunch { } } + private fun installedFolder(app: Context, id: String) = StoreInstallRoot.gameFolders(app).firstOrNull { folder -> + StoreGameSidecar.read(folder)?.let { it.store == Store.ROCKSTAR && it.id == id && it.isInstalled } == true + } + + fun sdkInstaller(app: Context, id: String): JSONObject = synchronized(sdkLock) { downloadSdkInstaller(app, id) } + + private fun downloadSdkInstaller(app: Context, id: String): JSONObject { + val folder = installedFolder(app, id) ?: return failure("not-installed") + val target = RockstarManifest.inside(folder, SDK_INSTALLER) + if (target.isFile) return JSONObject().put("ok", true) + val ticket = RockstarAuth.ticket(app) ?: RockstarAuth.ticket(app, fresh = true) ?: return failure("signed-out") + val branch = RockstarApps.fetch(ticket.ticket) {}.apps.firstOrNull { it.name == LAUNCHER_APP }?.let(RockstarApps::branch) + ?: return failure("no-launcher-build") + val build = RockstarManifest.parse(RockstarRos.result("app.asmx/GetBuildManifestFull", + listOf("ticket" to ticket.ticket, "branchAccessToken" to branch.accessToken))) + val file = RockstarManifest.sdkInstaller(build) ?: return failure("no-sdk-installer") + if (file.chunks.sumOf { it.size } != file.size) return failure("invalid-sdk-installer") + val part = RockstarManifest.inside(folder, "$SDK_INSTALLER.part") + part.parentFile?.mkdirs() + try { + java.io.RandomAccessFile(part, "rw").use { it.setLength(file.size) } + for (batch in RockstarManifest.batches(file.chunks)) { + val urls = RockstarInstaller.chunkUrls(ticket.ticket, branch.accessToken, batch) + for (chunk in batch) { + RockstarInstaller.fetch({ false }, { retry -> + (if (retry) null else urls[chunk.chunkId]) ?: RockstarInstaller.chunkUrls(ticket.ticket, branch.accessToken, listOf(chunk)).getValue(chunk.chunkId) + }, part, chunk, java.util.concurrent.atomic.AtomicLong()) {} + } + } + if (file.sha256.isNotEmpty() && !RockstarManifest.verified(part, RockstarChunk(file.entryId, "", file.sha256, 0, file.size))) { + return failure("invalid-sdk-installer") + } + if (!part.renameTo(target)) return failure("sdk-installer-unwritable") + } finally { + part.delete() + } + return JSONObject().put("ok", true) + } + fun prepare(app: Context, id: String): JSONObject { - val folder = StoreInstallRoot.gameFolders(app).firstOrNull { folder -> - StoreGameSidecar.read(folder)?.let { it.store == Store.ROCKSTAR && it.id == id && it.isInstalled } == true - } ?: return failure("not-installed") + val folder = installedFolder(app, id) ?: return failure("not-installed") val installed = StoreGameSidecar.read(folder) ?: return failure("not-installed") val exe = installed.exeFile(folder).canonicalFile if (!exe.path.startsWith(folder.canonicalPath + java.io.File.separator) || !exe.isFile) return failure("missing-game-files") diff --git a/app/src/test/java/com/droiddeck/launcher/stores/rockstar/RockstarTest.kt b/app/src/test/java/com/droiddeck/launcher/stores/rockstar/RockstarTest.kt index 755bd7320c..47205bb446 100644 --- a/app/src/test/java/com/droiddeck/launcher/stores/rockstar/RockstarTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/stores/rockstar/RockstarTest.kt @@ -315,6 +315,15 @@ class RockstarTest { assertEquals("ThirdParty/Steam/steam_api64.dll", build.files[1].path) } + @Test fun theSocialClubInstallerIsTakenFromTheLauncherBuild() { + fun file(path: String) = RockstarFile("1", "1", path, 1, "", emptyList()) + val launcher = RockstarBuild("1", "1", false, listOf(file("Launcher.exe"), + file("Redistributables/SocialClub/old/social-club-setup.exe"), file("Redistributables/SocialClub/Social-Club-Setup.exe"))) + assertEquals("Redistributables/SocialClub/Social-Club-Setup.exe", RockstarManifest.sdkInstaller(launcher)?.path) + assertNull(RockstarManifest.sdkInstaller(RockstarBuild("1", "1", false, listOf(file("Launcher.exe"), file("Social-Club-Setup.exe.sig"))))) + assertEquals("Redistributables/Social-Club-Setup.exe", RockstarLaunch.SDK_INSTALLER) + } + @Test fun pathsThatLeaveTheInstallAreRefused() { assertNull(RockstarManifest.safePath("..\\..\\Windows\\x.dll")) assertNull(RockstarManifest.safePath("C:\\x.dll")) diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-store-launch b/tools/linuxfs/overlay/usr/local/bin/droiddeck-store-launch index 5031cb93dc..fc689a5206 100755 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-store-launch +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-store-launch @@ -364,6 +364,12 @@ def rockstar_launcher_log(compat_data, limit=65536): return [line.strip() for line in data.decode("utf-8", "replace").splitlines() if line.strip()] +def ships_sdk(root, exe): + return any(directory.is_dir() and any(p.is_file() and not p.is_symlink() and p.name.lower() in ("socialclub.dll", "socialclub64.dll") + for p in directory.iterdir()) + for directory in {root, exe.parent}) + + def rockstar_sdk(folder, sidecar): if str(sidecar.get("id")) in ("gta4", "lanoire"): return True @@ -371,10 +377,8 @@ def rockstar_sdk(folder, sidecar): exe = (folder / str(sidecar.get("exe") or "").replace("\\", "/")).resolve() if not exe.is_relative_to(root): return False - for directory in {root, exe.parent}: - if directory.is_dir() and any(p.is_file() and not p.is_symlink() and p.name.lower() in ("socialclub.dll", "socialclub64.dll") - for p in directory.iterdir()): - return True + if ships_sdk(root, exe): + return True if str(sidecar.get("id")) in ROCKSTAR_TITLES: return False level = [root] @@ -543,7 +547,15 @@ def prepare_rockstar(folder, sidecar, compat_data, launch_dir, proton="", ask_ap return "prefix-" + made arch = "x86" if signature[4:] == b"\x4c\x01" else "x64" if sdk: - log("rockstar runtime: " + rockstar_runtime(folder, exe, compat_data, arch)) + runtime = rockstar_runtime(folder, exe, compat_data, arch) + if runtime == "game-runtime" and not ships_sdk(root, exe): + answer = (ask_app or ask)(Path(launch_dir) / "stores", {"op": "rockstar-sdk", "store": "rockstar", "id": str(sidecar.get("id"))}, + timeout=SERVICE_WAIT) + if isinstance(answer, dict) and answer.get("ok"): + runtime = rockstar_runtime(folder, exe, compat_data, arch) + else: + runtime = "sdk-" + (str(answer.get("reason") or "refused") if isinstance(answer, dict) else "timeout") + log("rockstar runtime: " + runtime) if not rockstar_registry(folder, title, compat_data, proton, sdk_arch=arch if sdk else None): return "registry-unavailable" target.mkdir(parents=True, exist_ok=True) diff --git a/tools/rockstar-launcher/README.md b/tools/rockstar-launcher/README.md index 020e21dcb7..1c5b7e7e0a 100644 --- a/tools/rockstar-launcher/README.md +++ b/tools/rockstar-launcher/README.md @@ -6,7 +6,7 @@ The handoff is mode 0600, expires after 90 seconds and is deleted before startin GTA III, Vice City and San Andreas use body-length MTLX replies. GTA IV and L.A. Noire use total-length, terminated replies. Titles with installed Social Club metadata or SDK binaries use the SDK IPC adapter, including user-info, login, ticket, initialization and authorized title-state synchronization. The title metadata supplies the ROS identity and principal executable; it is checked against Rockstar's catalog before title authorization. Other titles retain Play and Steam shortcuts and attempt the normal executable launch path. -The SDK runtime is extracted from the game's own Social-Club-Setup.exe when present. Architecture-specific payloads are staged into the prefix, archive paths and sizes are checked, interrupted copies are retried, and both registry views are registered. The helper discovers launcher identity pipe names in the game executable and the executables beside it, because protected game executables resolve that name only at run time, and answers bounded INIT challenges from the launched process. No vendor executables or runtime files are bundled with this tool. SDK initialization has a 90-second deadline. SDK wire tests and fixture clients do not establish gameplay compatibility for every title; per-title ROS ticket exchange and secondary SDK channels remain unverified. +The SDK runtime is extracted from the game's own Social-Club-Setup.exe when present. A title that ships neither the installer nor `socialclub.dll` gets the installer from the account's Rockstar Games Launcher build, downloaded by the app into the game's `Redistributables` folder with each chunk's hash checked. Architecture-specific payloads are staged into the prefix, archive paths and sizes are checked, interrupted copies are retried, and both registry views are registered. The helper discovers launcher identity pipe names in the game executable and the executables beside it, because protected game executables resolve that name only at run time, and answers bounded INIT challenges from the launched process. No vendor executables or runtime files are bundled with this tool. SDK initialization has a 90-second deadline. SDK wire tests and fixture clients do not establish gameplay compatibility for every title; per-title ROS ticket exchange and secondary SDK channels remain unverified. GTA III defaults to full x87 precision for FEX before Wine starts, because reduced precision crashed new-game initialization on the test device. San Andreas defaults to WineD3D, because DXVK intermittently corrupted its textures; full precision and conservative memory ordering did not prevent that corruption. These defaults use DroidDeck's per-game settings and preserve explicit per-game overrides. diff --git a/tools/tests/test_store_launch_rockstar.py b/tools/tests/test_store_launch_rockstar.py index 277d2a9f2b..427a992f4b 100644 --- a/tools/tests/test_store_launch_rockstar.py +++ b/tools/tests/test_store_launch_rockstar.py @@ -234,6 +234,57 @@ class RockstarLaunch(unittest.TestCase): self.assertEqual('ready', result) self.assertEqual([False], stale) + def sdk_launch(self, root, runtimes, sdk_answer=None, ships_runtime=False): + folder, sidecar, prefix, service, answer = self.setup_game(root) + sidecar['id'] = 'gta5' + (folder / 'title.rgl').write_bytes(b'RGLM' + bytes(108)) + if ships_runtime: + (folder / 'socialclub.dll').write_bytes(b'game-runtime') + answer['session'] = {'accountId': '123', 'identity': 'player@example.invalid', 'ticket': 'game-session'} + requests, lines, states = [], [], list(runtimes) + + def ask(channel, request, timeout): + requests.append(request['op']) + return sdk_answer if request['op'] == 'rockstar-sdk' else answer + + with patch.object(store, 'ROCKSTAR_SERVICE', service), patch.object(store, 'rockstar_registry', return_value=True), \ + patch.object(store, 'rockstar_runtime', side_effect=lambda *args: states.pop(0)), \ + patch.object(store, 'log', lines.append): + result = store.prepare_rockstar(folder, sidecar, str(prefix), str(Path(root) / 'channel'), ask_app=ask) + return result, requests, lines, states + + def test_a_title_without_a_social_club_installer_gets_one_from_the_app_before_its_session(self): + with tempfile.TemporaryDirectory() as root: + result, requests, lines, states = self.sdk_launch(root, ['game-runtime', 'installed'], {'ok': True}) + self.assertEqual('ready', result) + self.assertEqual(['rockstar-sdk', 'rockstar-launch'], requests) + self.assertIn('rockstar runtime: installed', lines) + self.assertEqual([], states) + + def test_an_unavailable_social_club_installer_is_logged_and_the_launch_continues(self): + for sdk_answer, reason in (({'ok': False, 'reason': 'no-launcher-build'}, 'sdk-no-launcher-build'), (None, 'sdk-timeout')): + with self.subTest(reason=reason), tempfile.TemporaryDirectory() as root: + result, requests, lines, _ = self.sdk_launch(root, ['game-runtime'], sdk_answer) + self.assertEqual('ready', result) + self.assertEqual(['rockstar-sdk', 'rockstar-launch'], requests) + self.assertIn('rockstar runtime: ' + reason, lines) + + def test_an_installed_or_bundled_social_club_does_not_ask_the_app(self): + for runtimes, ships in ((['present'], False), (['installed'], False), (['game-runtime'], True)): + with self.subTest(runtimes=runtimes, ships=ships), tempfile.TemporaryDirectory() as root: + result, requests, lines, _ = self.sdk_launch(root, runtimes, ships_runtime=ships) + self.assertEqual('ready', result) + self.assertEqual(['rockstar-launch'], requests) + self.assertIn('rockstar runtime: ' + runtimes[0], lines) + + def test_classic_titles_never_ask_for_the_social_club_installer(self): + with tempfile.TemporaryDirectory() as root: + with patch.object(store, 'rockstar_runtime') as runtime: + result, _, requests = self.prepare(root) + self.assertEqual('ready', result) + self.assertEqual(['rockstar-launch'], [request['op'] for request in requests]) + runtime.assert_not_called() + def exit_game(self, root, store_id, log_text=None, link=None): folder = game(root, store_id=store_id, ident='gta5') prefix = Path(root) / 'prefix'