mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-02 20:21:59 -05:00
fix(epic): pass the ownership token to Epic games whose catalog requires one
This commit is contained in:
1 parent
9ca6fa064e
commit
922bef3465
9 files changed
+201
-9
No files matched your search
@@ -11,6 +11,8 @@ object StoreLaunch {
|
||||
const val LAUNCHER = ".droiddeck-launch.bat"
|
||||
const val EPIC_CODE = ".droiddeck-epic-code"
|
||||
const val EPIC_ARGS = ".droiddeck-epic-args"
|
||||
const val EPIC_OWNERSHIP = ".droiddeck-epic-ovt"
|
||||
const val EPIC_OWNERSHIP_REQUIRED = "ownershipToken"
|
||||
const val UBISOFT_LAUNCH = ".droiddeck-ubisoft.json"
|
||||
/** DroidDeck-Bionic's Wine has Android's root on Z:; that tool sets this to the guest's root as its Wine names it. */
|
||||
const val GUEST_ROOT = "DROIDDECK_GUEST_ROOT"
|
||||
@@ -70,7 +72,9 @@ object StoreLaunch {
|
||||
lines += "$game %*"
|
||||
lines += "goto :eof"
|
||||
lines += ":signed"
|
||||
lines += "set \"$CODE_VAR=\" & $game -AUTH_LOGIN=unused -AUTH_PASSWORD=%$CODE_VAR% -AUTH_TYPE=exchangecode %*"
|
||||
lines += "set \"$OWNERSHIP_VAR=\""
|
||||
lines += "if exist \"%~dp0$EPIC_OWNERSHIP\" set $OWNERSHIP_VAR=-epicovt=\"%~dp0$EPIC_OWNERSHIP\""
|
||||
lines += "set \"$CODE_VAR=\" & set \"$OWNERSHIP_VAR=\" & $game -AUTH_LOGIN=unused -AUTH_PASSWORD=%$CODE_VAR% -AUTH_TYPE=exchangecode %$OWNERSHIP_VAR% %*"
|
||||
lines += "goto :eof"
|
||||
lines += ":client"
|
||||
lines += "set \"$CLIENT_VAR=\""
|
||||
@@ -131,6 +135,7 @@ object StoreLaunch {
|
||||
private const val CODE_VAR = "DD_X"
|
||||
private const val CLIENT_VAR = "DD_A"
|
||||
private const val PARENT_VAR = "DD_P"
|
||||
private const val OWNERSHIP_VAR = "DD_O"
|
||||
|
||||
fun installedGame(context: Context, store: Store, id: String): Library.SteamGame? {
|
||||
val folder = StoreInstallRoot.gameFolders(context).firstOrNull { folder ->
|
||||
@@ -171,7 +176,7 @@ object StoreLaunch {
|
||||
}, "stores-launch-prep").start()
|
||||
}
|
||||
|
||||
class CodeResult(val written: Boolean, val reason: String)
|
||||
class CodeResult(val written: Boolean, val reason: String, val ownership: Boolean = false)
|
||||
|
||||
fun epicCode(context: Context, id: String): CodeResult {
|
||||
val app = context.applicationContext
|
||||
@@ -183,15 +188,23 @@ object StoreLaunch {
|
||||
if (folder == null) CodeResult(false, "not-installed")
|
||||
else if (options != null && !options.wantsCode) {
|
||||
File(folder, EPIC_CODE).delete()
|
||||
File(folder, EPIC_OWNERSHIP).delete()
|
||||
CodeResult(false, if (options.offline) "offline" else "eos-off")
|
||||
} else {
|
||||
val file = File(folder, EPIC_CODE)
|
||||
val ownershipFile = File(folder, EPIC_OWNERSHIP)
|
||||
file.delete()
|
||||
ownershipFile.delete()
|
||||
val support = StoresState.backend(Store.EPIC) as? EpicLaunchSupport
|
||||
val code = support?.exchangeCode(app)
|
||||
when {
|
||||
support == null -> CodeResult(false, "no-backend")
|
||||
code != null -> { file.writeText(code); CodeResult(true, "ok") }
|
||||
code != null -> {
|
||||
file.writeText(code)
|
||||
val ownership = sidecar?.let { runCatching { epicOwnership(app, folder, it, support) }.getOrNull() }
|
||||
ownership?.let { ownershipFile.writeBytes(it) }
|
||||
CodeResult(true, "ok", ownership != null)
|
||||
}
|
||||
StoreAccounts.signedInAs(app, Store.EPIC) == null -> CodeResult(false, "signed-out")
|
||||
support.signInExpired(app) -> { StoresState.markSignInExpired(Store.EPIC); CodeResult(false, "sign-in-expired") }
|
||||
else -> CodeResult(false, "exchange-failed")
|
||||
@@ -200,10 +213,22 @@ object StoreLaunch {
|
||||
} catch (e: Exception) {
|
||||
CodeResult(false, "error-" + e.javaClass.simpleName)
|
||||
}
|
||||
Log.i(TAG, "epic launch id=$id code=${if (result.written) "yes" else "no"} reason=${result.reason}")
|
||||
Log.i(TAG, "epic launch id=$id code=${if (result.written) "yes" else "no"} ownership=${if (result.ownership) "yes" else "no"} reason=${result.reason}")
|
||||
return result
|
||||
}
|
||||
|
||||
private fun epicOwnership(context: Context, folder: File, sidecar: StoreGameSidecar, support: EpicLaunchSupport): ByteArray? {
|
||||
val namespace = sidecar.extra["namespace"].orEmpty()
|
||||
val item = sidecar.extra["catalogItemId"].orEmpty()
|
||||
if (namespace.isEmpty() || item.isEmpty()) return null
|
||||
val required = sidecar.extra[EPIC_OWNERSHIP_REQUIRED]?.toBooleanStrictOrNull()
|
||||
?: support.requiresOwnershipToken(context, namespace, item)?.also { known ->
|
||||
StoreGameSidecar.read(folder)?.takeIf { it.store == Store.EPIC && it.id == sidecar.id }
|
||||
?.let { it.copy(extra = it.extra + (EPIC_OWNERSHIP_REQUIRED to known.toString())).write(folder) }
|
||||
}
|
||||
return if (required == true) support.ownershipToken(context, namespace, item) else null
|
||||
}
|
||||
|
||||
fun prepare(context: Context, game: Library.SteamGame, onReady: () -> Unit) {
|
||||
val store = Store.byId(game.source)
|
||||
val id = game.storeId
|
||||
@@ -214,5 +239,7 @@ object StoreLaunch {
|
||||
|
||||
interface EpicLaunchSupport {
|
||||
fun exchangeCode(context: Context): String?
|
||||
fun requiresOwnershipToken(context: Context, namespace: String, catalogItemId: String): Boolean?
|
||||
fun ownershipToken(context: Context, namespace: String, catalogItemId: String): ByteArray?
|
||||
fun signInExpired(context: Context): Boolean
|
||||
}
|
||||
@@ -18,6 +18,13 @@ object EpicApiClient {
|
||||
return answer.optString("value", "")
|
||||
}
|
||||
|
||||
fun requiresOwnershipToken(token: String, namespace: String, catalogItemId: String): Boolean? =
|
||||
getCustomAttribute(token, namespace, catalogItemId, "OwnershipToken")?.trim()?.lowercase()?.let { it == "true" }
|
||||
|
||||
fun ownershipToken(token: String, accountId: String, namespace: String, catalogItemId: String): ByteArray? =
|
||||
EpicNative.fetch("launch.ownershipToken", request(token, namespace, catalogItemId).put("accountId", accountId))
|
||||
?.takeIf { it.isNotEmpty() }
|
||||
|
||||
internal fun catalogDetails(token: String, namespace: String, catalogItemId: String): JSONObject? =
|
||||
EpicNative.call("catalog.details", request(token, namespace, catalogItemId))?.optJSONObject("details")
|
||||
|
||||
|
||||
@@ -99,5 +99,16 @@ object EpicBackend : StoreBackend, EpicLaunchSupport {
|
||||
return EpicApiClient.exchangeCode(token)
|
||||
}
|
||||
|
||||
override fun requiresOwnershipToken(context: Context, namespace: String, catalogItemId: String): Boolean? {
|
||||
val token = EpicCredentialStore.getValidAccessToken(context) ?: return null
|
||||
return EpicApiClient.requiresOwnershipToken(token, namespace, catalogItemId)
|
||||
}
|
||||
|
||||
override fun ownershipToken(context: Context, namespace: String, catalogItemId: String): ByteArray? {
|
||||
val token = EpicCredentialStore.getValidAccessToken(context) ?: return null
|
||||
val account = EpicCredentialStore.load(context)?.accountId?.ifEmpty { null } ?: return null
|
||||
return EpicApiClient.ownershipToken(token, account, namespace, catalogItemId)
|
||||
}
|
||||
|
||||
override fun signInExpired(context: Context): Boolean = EpicCredentialStore.expired(context)
|
||||
}
|
||||
@@ -409,8 +409,7 @@ internal object EpicClientLibrary {
|
||||
}
|
||||
|
||||
private fun ownershipToken(token: String, install: Install): Boolean? =
|
||||
runCatching { EpicApiClient.getCustomAttribute(token, install.namespace, install.catalogItemId, "OwnershipToken") }
|
||||
.getOrNull()?.trim()?.lowercase()?.let { it == "true" }
|
||||
runCatching { EpicApiClient.requiresOwnershipToken(token, install.namespace, install.catalogItemId) }.getOrNull()
|
||||
|
||||
private fun egstore(install: Install, guid: String, token: () -> String?) {
|
||||
val dir = File(install.folder, ".egstore")
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
use super::net::{self, Body, Request};
|
||||
|
||||
const ECOMMERCE_HOST: &str = "https://ecommerceintegration-public-service-ecomprod02.ol.epicgames.com";
|
||||
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub struct LaunchData {
|
||||
pub display_name: String,
|
||||
@@ -39,6 +43,26 @@ pub fn arguments(d: &LaunchData) -> Vec<String> {
|
||||
args
|
||||
}
|
||||
|
||||
fn ownership_request(account_id: &str, namespace: &str, item_id: &str) -> (String, Vec<(String, String)>) {
|
||||
let url = format!(
|
||||
"{ECOMMERCE_HOST}/ecommerceintegration/api/public/platforms/EPIC/identities/{}/ownershipToken",
|
||||
net::percent_encode(account_id)
|
||||
);
|
||||
(url, vec![("nsCatalogItemId".to_string(), format!("{namespace}:{item_id}"))])
|
||||
}
|
||||
|
||||
pub fn ownership_token(access_token: &str, account_id: &str, namespace: &str, item_id: &str) -> Option<Vec<u8>> {
|
||||
if access_token.is_empty() || account_id.is_empty() || namespace.is_empty() || item_id.is_empty() {
|
||||
return None;
|
||||
}
|
||||
let (url, form) = ownership_request(account_id, namespace, item_id);
|
||||
let reply = net::send(Request::post(&url, Body::Form(form)).bearer(access_token)).ok()?;
|
||||
if !reply.ok() || reply.body.is_empty() {
|
||||
return None;
|
||||
}
|
||||
Some(reply.body)
|
||||
}
|
||||
|
||||
pub fn split_command(command: &str) -> Vec<String> {
|
||||
let mut args = Vec::new();
|
||||
let mut current = String::new();
|
||||
@@ -105,6 +129,19 @@ mod tests {
|
||||
assert!(split_command(" ").is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ownership_token_request_names_the_account_and_item() {
|
||||
let (url, form) = ownership_request("acc 1", "ns", "item");
|
||||
assert_eq!(
|
||||
url,
|
||||
"https://ecommerceintegration-public-service-ecomprod02.ol.epicgames.com/ecommerceintegration/api/public/platforms/EPIC/identities/acc%201/ownershipToken"
|
||||
);
|
||||
assert_eq!(form, vec![("nsCatalogItemId".to_string(), "ns:item".to_string())]);
|
||||
assert_eq!(ownership_token("", "acc", "ns", "item"), None);
|
||||
assert_eq!(ownership_token("token", "", "ns", "item"), None);
|
||||
assert_eq!(ownership_token("token", "acc", "ns", ""), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn arguments_in_order() {
|
||||
let args = arguments(&LaunchData {
|
||||
|
||||
@@ -131,6 +131,12 @@ pub fn fetch(op: &str, request: &str) -> Option<Vec<u8>> {
|
||||
build_info::download_manifest(&info, &cdns, &|_: &str| {})
|
||||
}
|
||||
"cloud.read" => savesync::read(str_of(&req, "url")).ok(),
|
||||
"launch.ownershipToken" => launch::ownership_token(
|
||||
str_of(&req, "accessToken"),
|
||||
str_of(&req, "accountId"),
|
||||
str_of(&req, "namespace"),
|
||||
str_of(&req, "catalogItemId"),
|
||||
),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,7 +119,9 @@ class StoreGameSidecarTest {
|
||||
assertTrue(text.contains("set \"FOO=bar\"\r\n"))
|
||||
assertTrue(text.contains("\r\n%DD_P% \"%~dp0Binaries\\Win64\\Celeste.exe\" -EpicPortal -epicusername=\"Some One\" %*\r\n"))
|
||||
assertTrue(text.contains("set /p DD_X=<\"%~dp0.droiddeck-epic-code\""))
|
||||
assertTrue(text.contains("set \"DD_X=\" & %DD_P% \"%~dp0Binaries\\Win64\\Celeste.exe\" -EpicPortal -epicusername=\"Some One\" -AUTH_LOGIN=unused -AUTH_PASSWORD=%DD_X% -AUTH_TYPE=exchangecode %*\r\n"))
|
||||
assertTrue(text.contains("\r\n:signed\r\nset \"DD_O=\"\r\nif exist \"%~dp0.droiddeck-epic-ovt\" set DD_O=-epicovt=\"%~dp0.droiddeck-epic-ovt\"\r\n"))
|
||||
assertTrue(text.contains("set \"DD_X=\" & set \"DD_O=\" & %DD_P% \"%~dp0Binaries\\Win64\\Celeste.exe\" -EpicPortal -epicusername=\"Some One\" -AUTH_LOGIN=unused -AUTH_PASSWORD=%DD_X% -AUTH_TYPE=exchangecode %DD_O% %*\r\n"))
|
||||
assertEquals(1, text.split("\r\n").count { it.contains("%DD_O%") })
|
||||
assertFalse(text.contains("AUTH="))
|
||||
assertFalse(text.contains("DD_AUTH"))
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.droiddeck.launcher.stores
|
||||
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
import com.droiddeck.launcher.frontend.AddedGames
|
||||
import com.droiddeck.launcher.session.SessionPrefs
|
||||
import org.junit.Assert.*
|
||||
@@ -48,6 +49,103 @@ class StoreLaunchTest {
|
||||
assertNull(StoreLaunch.installedGame(app, Store.XBOX, "OTHERPRODUCT"))
|
||||
}
|
||||
|
||||
private class FakeEpic(val requires: Boolean?, val code: String? = "code") : StoreBackend, EpicLaunchSupport {
|
||||
val asked = mutableListOf<String>()
|
||||
override val store = Store.EPIC
|
||||
override fun signIn(context: Context) {}
|
||||
override fun signOut(context: Context) {}
|
||||
override fun syncLibrary(context: Context, force: Boolean) {}
|
||||
override fun loadShelves(context: Context, force: Boolean) {}
|
||||
override fun install(context: Context, item: CatalogItem, root: File) {}
|
||||
override fun uninstall(context: Context, game: InstalledStoreGame) {}
|
||||
override fun exchangeCode(context: Context): String? = code
|
||||
override fun signInExpired(context: Context): Boolean = false
|
||||
override fun requiresOwnershipToken(context: Context, namespace: String, catalogItemId: String): Boolean? {
|
||||
asked += "requires $namespace:$catalogItemId"
|
||||
return requires
|
||||
}
|
||||
override fun ownershipToken(context: Context, namespace: String, catalogItemId: String): ByteArray? {
|
||||
asked += "token $namespace:$catalogItemId"
|
||||
return "ovt-$catalogItemId".toByteArray()
|
||||
}
|
||||
}
|
||||
|
||||
private fun epicInstall(id: String, extra: Map<String, String> = mapOf("namespace" to "ns", "catalogItemId" to "item")): File {
|
||||
SessionPrefs.setGameStorage(app, SessionPrefs.GAME_STORAGE_OFF, "")
|
||||
val folder = File(StoreInstallRoot.storeDir(StoreInstallRoot.installRoot(app), Store.EPIC), id)
|
||||
File(folder, "Game.exe").apply { parentFile!!.mkdirs(); writeText("image") }
|
||||
StoreGameSidecar(Store.EPIC, id, "Epic $id", "Game.exe", extra = extra).write(folder)
|
||||
return folder
|
||||
}
|
||||
|
||||
private fun <T> withEpic(backend: FakeEpic, block: () -> T): T {
|
||||
val previous = StoresState.backend(Store.EPIC)
|
||||
StoresState.register(backend)
|
||||
try {
|
||||
return block()
|
||||
} finally {
|
||||
if (previous != null) StoresState.register(previous)
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun anEpicGameThatNeedsAnOwnershipTokenGetsOneWithEveryCode() {
|
||||
val folder = epicInstall("OwnedTitle")
|
||||
val backend = FakeEpic(requires = true)
|
||||
withEpic(backend) {
|
||||
val first = StoreLaunch.epicCode(app, "OwnedTitle")
|
||||
assertTrue(first.written && first.ownership)
|
||||
assertEquals("code", File(folder, StoreLaunch.EPIC_CODE).readText())
|
||||
assertEquals("ovt-item", File(folder, StoreLaunch.EPIC_OWNERSHIP).readText())
|
||||
assertEquals("true", StoreGameSidecar.read(folder)!!.extra[StoreLaunch.EPIC_OWNERSHIP_REQUIRED])
|
||||
assertEquals("ns", StoreGameSidecar.read(folder)!!.extra["namespace"])
|
||||
StoreLaunch.epicCode(app, "OwnedTitle")
|
||||
}
|
||||
assertEquals(listOf("requires ns:item", "token ns:item", "token ns:item"), backend.asked)
|
||||
}
|
||||
|
||||
@Test fun otherEpicGamesGetNoOwnershipTokenAndLoseAStaleOne() {
|
||||
val folder = epicInstall("PlainTitle")
|
||||
File(folder, StoreLaunch.EPIC_OWNERSHIP).writeText("stale")
|
||||
val backend = FakeEpic(requires = false)
|
||||
withEpic(backend) {
|
||||
repeat(2) {
|
||||
val result = StoreLaunch.epicCode(app, "PlainTitle")
|
||||
assertTrue(result.written)
|
||||
assertFalse(result.ownership)
|
||||
}
|
||||
}
|
||||
assertFalse(File(folder, StoreLaunch.EPIC_OWNERSHIP).exists())
|
||||
assertEquals("code", File(folder, StoreLaunch.EPIC_CODE).readText())
|
||||
assertEquals("false", StoreGameSidecar.read(folder)!!.extra[StoreLaunch.EPIC_OWNERSHIP_REQUIRED])
|
||||
assertEquals(listOf("requires ns:item"), backend.asked)
|
||||
}
|
||||
|
||||
@Test fun anUnansweredOwnershipCheckIsAskedAgainAndNeverBlocksTheCode() {
|
||||
val folder = epicInstall("UnknownTitle")
|
||||
val backend = FakeEpic(requires = null)
|
||||
withEpic(backend) {
|
||||
assertTrue(StoreLaunch.epicCode(app, "UnknownTitle").written)
|
||||
assertTrue(StoreLaunch.epicCode(app, "UnknownTitle").written)
|
||||
}
|
||||
assertNull(StoreGameSidecar.read(folder)!!.extra[StoreLaunch.EPIC_OWNERSHIP_REQUIRED])
|
||||
assertFalse(File(folder, StoreLaunch.EPIC_OWNERSHIP).exists())
|
||||
assertEquals(listOf("requires ns:item", "requires ns:item"), backend.asked)
|
||||
}
|
||||
|
||||
@Test fun noOwnershipTokenWithoutACodeOrCatalogIds() {
|
||||
val failed = epicInstall("NoCode")
|
||||
val noCode = FakeEpic(requires = true, code = null)
|
||||
withEpic(noCode) { assertFalse(StoreLaunch.epicCode(app, "NoCode").written) }
|
||||
assertFalse(File(failed, StoreLaunch.EPIC_OWNERSHIP).exists())
|
||||
assertTrue(noCode.asked.isEmpty())
|
||||
|
||||
val bare = epicInstall("NoIds", extra = emptyMap())
|
||||
val backend = FakeEpic(requires = true)
|
||||
withEpic(backend) { assertTrue(StoreLaunch.epicCode(app, "NoIds").written) }
|
||||
assertFalse(File(bare, StoreLaunch.EPIC_OWNERSHIP).exists())
|
||||
assertTrue(backend.asked.isEmpty())
|
||||
}
|
||||
|
||||
@Test fun aMissingExecutableDoesNotBecomeALaunchTarget() {
|
||||
val folder = install()
|
||||
File(folder, "FSD/Binaries/WinGDK/FSD.exe").delete()
|
||||
|
||||
@@ -26,6 +26,7 @@ Library pages are `app:<appId>` for an installed game and `app:<store>:<id>` for
|
||||
.droiddeck-store.json the sidecar (below)
|
||||
.droiddeck-launch.bat only when the game needs arguments or environment (Epic, Amazon)
|
||||
.droiddeck-epic-code one-shot, written right before an Epic launch, read and deleted by the .bat
|
||||
.droiddeck-epic-ovt Epic ownership token, rewritten with each code for games whose catalog item sets OwnershipToken
|
||||
```
|
||||
|
||||
The default root is the app's internal storage - the runtime's tree, `/root/Games/Stores`, no bind
|
||||
@@ -216,7 +217,11 @@ game that needs arguments or environment gets `.droiddeck-launch.bat` (`StoreLau
|
||||
`.droiddeck-epic-code` when present, deletes it, and passes
|
||||
`-AUTH_LOGIN=unused -AUTH_PASSWORD=<code> -AUTH_TYPE=exchangecode` on the game's command line only;
|
||||
the variable it read the code into is cleared on that same line, so nothing of it is left in the
|
||||
game's environment. A launcher from an earlier build is rewritten before the next Epic launch.
|
||||
game's environment. When the game's catalog item sets `OwnershipToken` (usually Denuvo titles),
|
||||
`StoreLaunch.epicCode` also fetches the account's ownership token, as the Epic
|
||||
client and Legendary do, into `.droiddeck-epic-ovt`, and the signed path adds
|
||||
`-epicovt="<that file>"`. Without it these games show "Please use the Epic launcher to start the
|
||||
game". A launcher from an earlier build is rewritten before the next Epic launch.
|
||||
|
||||
The code is minted for every launch, wherever it starts. The game page calls
|
||||
`StoreLaunch.prepare` before they launch; the compat tool (`droiddeck-proton`,
|
||||
@@ -224,7 +229,7 @@ The code is minted for every launch, wherever it starts. The game page calls
|
||||
client's Play button included. It finds the store launcher among Steam's arguments, reads the
|
||||
sidecar beside it, and for an Epic game asks the app through `<session>/stores/req` and `resp`
|
||||
(`StoreLaunchRequests` → `StoreLaunch.epicCode`), waiting up to 5 s; the app writes the code into
|
||||
the game's folder itself. Each attempt logs `epic launch id=… code=yes|no reason=…`, never the code.
|
||||
the game's folder itself. Each attempt logs `epic launch id=… code=yes|no ownership=yes|no reason=…`, never the code.
|
||||
|
||||
An Epic game's launch choices are the Epic card in its page's Launch tab - "Epic sign-in
|
||||
(EOS)" (on) and "Launch offline" (off), stored in the sidecar's `epic` block so both launch paths
|
||||
|
||||
Reference in new issue
Block a user