Compare commits

...
8 changed files with 90 additions and 6 deletions

No files matched your search

@@ -37,7 +37,7 @@ object UbisoftLaunch {
.put("country", me?.optString("country")?.takeIf { it.isNotEmpty() } ?: "US")
val appId = runCatching { UbisoftAuth.request(ENTITLEMENTS, "GET", auth, s.sessionId) }.getOrNull()?.takeIf { it.ok }
?.let { applicationId(it.body, product) } ?: sidecar.extra["appId"].orEmpty()
StoresState.logLine("Ubisoft: launch ticket for $product ready (${native.optJSONArray("owned")?.length() ?: 0} products, appId ${if (appId.isEmpty()) "unknown" else "found"})")
StoresState.logLine("Ubisoft: launch ticket for $product ready (${native.optJSONArray("owned")?.length() ?: 0} products, appId ${if (appId.isEmpty()) "unknown" else "found"}, cd key ${if (cdKeyKnown(native, product)) "found" else "none"})")
val language = com.droiddeck.launcher.stores.StoreLanguage.localeFor(null, app).let { "${it.language}-${it.country}" }
val cached = sidecar.extra[CHUNKS]?.let { runCatching { JSONArray(it) }.getOrNull() }
var setup = sidecar.extra[SETUP]?.let { runCatching { JSONObject(it) }.getOrNull() }
@@ -71,6 +71,12 @@ object UbisoftLaunch {
.put("registry", setup?.optJSONArray("registry") ?: JSONArray())
}
internal fun cdKeyKnown(native: JSONObject, product: Long): Boolean {
val products = native.optJSONArray("products") ?: return false
return (0 until products.length()).mapNotNull { products.optJSONObject(it) }
.any { it.optLong("id") == product && it.optString("cdKey").isNotEmpty() }
}
const val CHUNKS = "chunks"
const val SETUP = "setup"
+1 -1
View File
@@ -51,7 +51,7 @@ fn launch(ticket: &str, session: &str, product: u32) -> Result<serde_json::Value
}
let pc_ticket = ownership.pc_ticket(&mut d, product, ticket, session).await?;
let owned: Vec<u32> = games.iter().filter(|g| g.in_session()).map(|g| g.product_id).collect();
let products: Vec<_> = games.iter().filter(|g| g.in_session()).map(|g| json!({ "id": g.product_id, "type": g.product_type })).collect();
let products: Vec<_> = games.iter().filter(|g| g.in_session()).map(|g| g.session_json()).collect();
Ok(json!({ "ticket": pc_ticket, "owned": owned, "products": products }))
})
}
@@ -17,6 +17,7 @@ pub struct Owned {
pub locked_by_subscription: bool,
pub associations: Vec<u32>,
pub download_id: u32,
pub cd_key: String,
}
impl Owned {
@@ -34,6 +35,14 @@ impl Owned {
"associations": self.associations, "downloadId": self.download_id,
})
}
pub fn session_json(&self) -> Json {
let mut p = json!({ "id": self.product_id, "type": self.product_type });
if !self.cd_key.is_empty() {
p["cdKey"] = json!(self.cd_key);
}
p
}
}
pub struct Ownership {
@@ -57,6 +66,7 @@ fn owned_game(b: &[u8]) -> Result<Owned, String> {
locked_by_subscription: pb::num(&f, 37) == Some(1),
associations: f.iter().filter_map(|(n, v)| match v { pb::Value::Varint(x) if *n == 16 => Some(*x as u32), _ => None }).collect(),
download_id: pb::num(&f, 5).unwrap_or(0) as u32,
cd_key: pb::string(&f, 2).unwrap_or_default(),
})
}
@@ -249,3 +259,21 @@ pub async fn cloudsave_urls(d: &mut Demux, ownership_token: &str, product_id: u3
}
Ok(out)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn a_launch_product_carries_its_cd_key_and_the_library_entry_does_not() {
let g = owned_game(&Msg::new().uint(1, 46).text(2, "AAAA-BBBB-CCCC-DDDD").uint(8, 0).uint(13, 3).0).unwrap();
assert_eq!(g.session_json(), json!({ "id": 46, "type": 0, "cdKey": "AAAA-BBBB-CCCC-DDDD" }));
assert!(!g.to_json().to_string().contains("AAAA"));
}
#[test]
fn a_product_without_a_cd_key_is_listed_without_one() {
let g = owned_game(&Msg::new().uint(1, 410).uint(8, 1).0).unwrap();
assert_eq!(g.session_json(), json!({ "id": 410, "type": 1 }));
}
}
@@ -101,6 +101,16 @@ class UbisoftTest {
assertNull(UbisoftLaunch.applicationId(body, 1651))
}
@Test fun onlyTheGamesOwnCdKeyCountsAsFound() {
val native = JSONObject().put("products", JSONArray()
.put(JSONObject().put("id", 82).put("type", 1).put("cdKey", "ADDON"))
.put(JSONObject().put("id", 46).put("type", 0).put("cdKey", "GAME")))
assertTrue(UbisoftLaunch.cdKeyKnown(native, 46))
assertTrue(!UbisoftLaunch.cdKeyKnown(native, 109))
assertTrue(!UbisoftLaunch.cdKeyKnown(JSONObject().put("products", JSONArray().put(JSONObject().put("id", 109).put("type", 0))), 109))
assertTrue(!UbisoftLaunch.cdKeyKnown(JSONObject(), 46))
}
@Test fun theLauncherStartsTheServiceOnlyWithAFreshLaunchFile() {
val text = StoreLaunch.launcherText(StoreGameSidecar(Store.UBISOFT, "space-sc", "Splinter Cell", "system/SplinterCell.exe"))
val lines = text.trimEnd().split("\r\n")
+2 -2
View File
@@ -19,7 +19,7 @@ from the public notes in [Foxtrot47/Ubisoft-Connect-RE](https://github.com/Foxtr
| Ubisoft runtime | `C:\Program Files (x86)\Ubisoft\Ubisoft Game Launcher\` in the shared prefix | Ubisoft's own `uplay_r1(64).dll`, `uplay_aux_r1(64).dll`, `uplay_r2(64).dll`, `ubiorbitapi_r2(64).dll`, `UbisoftGameLauncher(64).exe`, the starter's imports (`discord-rpc.x86/x64.dll`, `steam_api(64).dll`) and `overlay(64).dll`. `droiddeck-store-launch` extracts exactly these 16 files with `7z` from the official `UbisoftConnectInstaller.exe`, then deletes the installer |
| Registry | `HKLM\Software\[Wow6432Node\]Ubisoft\Launcher` | `InstallDir` points at the runtime folder in both views; `Installs\<productId>\InstallDir` points at the game, with forward slashes and a trailing slash, as Connect writes it |
| Shared prefix | `compatdata/2929927072` | Every Ubisoft game runs here (`UbisoftConnect.launchOptions` sets `STEAM_COMPAT_DATA_PATH`), so the runtime is extracted once |
| Launch file | `<game>/.droiddeck-ubisoft.json` | Written by `droiddeck-store-launch` before every launch from the app's `ubisoft-launch` answer: the account, the owned product ids, a fresh PC ticket, the entitlement's application id and the save folder. Removed first, so a failed refresh falls back to starting the game directly |
| Launch file | `<game>/.droiddeck-ubisoft.json` | Written by `droiddeck-store-launch` before every launch from the app's `ubisoft-launch` answer: the account, the owned product ids with their CD keys, a fresh PC ticket, the entitlement's application id and the save folder. Removed first, so a failed refresh falls back to starting the game directly |
| Launcher | `<game>/.droiddeck-launch.bat` | Runs `Z:\usr\local\lib\droiddeck-ubisoft\droiddeck-upc.exe <launch file>` when both exist |
| Tickets | app, Rust `ubisoft/service.rs` | Demux `ownership_service`: initialize (owned products), then `GetUplayPCTicketReq` (field 14) answered in field 13 `{1: success, 2: ticket}` |
@@ -49,7 +49,7 @@ followed by a proto2 message, except on `uplay_service_ipc_pipe_`.
| 3 connected | 1 |
| 4 gameUplayId | the product |
| 5 uplayIds | every owned product whose ownership entry is owned, of type 0 or 1, in state 0 or 3 |
| 6 gameCdKeys | `{1: product, 2: ""}` |
| 6 gameCdKeys | `{1: product, 2: cdKey}`: the key in the game's ownership entry (`OwnedGame.cd_key`, field 2), empty when the account has none |
| 7 isInOfflineMode | 0 |
| 8 upcTicket | the PC ticket from `GetUplayPCTicket`, never the Denuvo token |
| 11, 12, 15, 16, 18, 19, 21, 23 | the values a real launch carries (`{1:0}`, 0, overlay `{1:0, 2:3}`, hardware score `{6211, 22395, 1.0f}`, empty, `{1:1, 2:1}`, `{2:1}`, empty) |
+7
View File
@@ -1106,6 +1106,13 @@ class Ubisoft(unittest.TestCase):
self.assertEqual('C:/users/steamuser/Saved Games/Ubisoft/u1/109/', launch['saves'])
self.assertTrue((self.compat_data / 'pfx/drive_c/users/steamuser/Saved Games/Ubisoft/u1/109').is_dir())
def test_the_launch_file_keeps_each_products_cd_key(self):
self.runtime()
products = [{'id': 109, 'type': 0, 'cdKey': 'GAME-KEY'}, {'id': 82, 'type': 1}]
self.prepare(lambda *_a, **_k: dict(self.answer(), products=products))
launch = json.loads((self.folder / store.UBISOFT_LAUNCH).read_text())
self.assertEqual(products, launch['products'])
def test_a_bionic_launch_names_the_android_files(self):
self.runtime()
tool = self.root / 'DroidDeck-Bionic-12.8-r41-Proton'
+33 -1
View File
@@ -48,6 +48,7 @@ pub struct Config {
pub chunks: Vec<(u32, String)>,
/// Owned products and their ownership type (0 game, 1 add-on).
pub products: Vec<(u32, u32)>,
pub cd_key: String,
}
fn s(j: &Json, k: &str) -> String {
@@ -67,6 +68,10 @@ impl Config {
if !saves.ends_with('/') {
saves.push('/');
}
let cd_key = j.get("products").and_then(|v| v.as_array())
.and_then(|a| a.iter().find(|p| p.get("id").and_then(|i| i.as_u64()) == Some(product as u64)))
.map(|p| s(p, "cdKey"))
.unwrap_or_default();
let c = Config {
product,
exe: s(&j, "exe"),
@@ -90,6 +95,7 @@ impl Config {
products: j.get("products").and_then(|v| v.as_array()).map(|a| a.iter().filter_map(|p| {
Some((p.get("id")?.as_u64()? as u32, p.get("type").and_then(|t| t.as_u64()).unwrap_or(0) as u32))
}).collect()).unwrap_or_default(),
cd_key,
};
if c.exe.is_empty() || c.ticket.is_empty() {
return Err("config: exe and ticket are required".into());
@@ -161,7 +167,7 @@ impl Config {
body = body.uint(5, *id as u64);
}
body = body
.msg(6, Msg::new().uint(1, self.product as u64).text(2, ""))
.msg(6, Msg::new().uint(1, self.product as u64).text(2, &self.cd_key))
.uint(7, 0)
.text(8, &self.ticket);
if wants.map_or(true, |w| w.install) {
@@ -397,6 +403,32 @@ mod tests {
"owned":[82],"appId":"a-b","saves":"Z:/saves/u1/109","chunks":[{"id":0,"tags":""},{"id":64,"tags":"custo05"}]}"#).unwrap()
}
fn game_cd_keys(rsp: &[u8]) -> Vec<(Option<u64>, Option<Vec<u8>>)> {
let init = pb::fields(pb::sub(&pb::fields(rsp).unwrap(), 1).unwrap()).unwrap();
init.iter().filter(|(n, _)| *n == 6).map(|(_, v)| {
let key = pb::fields(match v { Value::Bytes(b) => b, _ => panic!() }).unwrap();
(pb::num(&key, 1), pb::sub(&key, 2).map(|k| k.to_vec()))
}).collect()
}
#[test]
fn the_session_hands_the_game_its_own_cd_key() {
let c = Config::parse(r#"{"productId":46,"exe":"Z:/games/fc3/bin/farcry3.exe","ticket":"T",
"products":[{"id":82,"type":1,"cdKey":"ADDON-KEY"},{"id":46,"type":0,"cdKey":"GAME-KEY"}]}"#).unwrap();
assert_eq!(c.cd_key, "GAME-KEY");
assert_eq!(game_cd_keys(&c.session(None)), vec![(Some(46), Some(b"GAME-KEY".to_vec()))]);
assert_eq!(c.products, vec![(82, 1), (46, 0)]);
}
#[test]
fn a_game_without_a_cd_key_keeps_an_empty_entry() {
let c = config();
assert_eq!(c.cd_key, "");
assert_eq!(game_cd_keys(&c.session(None)), vec![(Some(109), Some(Vec::new()))]);
let other = Config::parse(r#"{"productId":109,"exe":"x.exe","ticket":"T","products":[{"id":82,"type":0,"cdKey":"OTHER"}]}"#).unwrap();
assert_eq!(game_cd_keys(&other.session(None)), vec![(Some(109), Some(Vec::new()))]);
}
#[test]
fn the_owned_list_always_holds_the_game_and_saves_end_with_a_slash() {
let c = config();
+2 -1
View File
@@ -156,7 +156,8 @@ mod service {
pushes += 1;
send(&pipe, &state.cfg.session(wants));
let asked = wants.map_or("no subsystems named".to_string(), |w| format!("install {}, storage {}", w.install, w.storage));
state.say(&format!("session: init answered ({pushes}; {asked}; {})", hex(&req, 48)));
let key = if state.cfg.cd_key.is_empty() { "no cd key" } else { "cd key" };
state.say(&format!("session: init answered ({pushes}; {asked}; {key}; {})", hex(&req, 48)));
}
SessionReq::Installer => {
send(&pipe, &state.cfg.installer());