diff --git a/docs/development/ubisoft-launch.md b/docs/development/ubisoft-launch.md index f7321f4d72..5c18429758 100644 --- a/docs/development/ubisoft-launch.md +++ b/docs/development/ubisoft-launch.md @@ -34,7 +34,7 @@ followed by a proto2 message, except on `uplay_service_ipc_pipe_`. |---|---|---| | `game_start_ipc_pipe_` | `UbisoftGameLauncher.exe` | `game_starter.Upstream{1:{1:{1: build, 2: product, 10: exe, 11: arguments, ...}}}` → `Downstream{2:{1:{1:0 (overlay off), 2:0, 3: / + "/" + , 4: /, 8:3, 9:{1:{1,113,0,1,0} 1:{3,123,0,0,0}}}}}` | | `uplay_api_process_ipc_pipe_` | game | `Req.initProcessReq{1: product, 2: game pid, 5: env set}` → `Rsp.initProcessRsp(13){1:1, 3:0 (overlay off), 4:3, 6:0}`. Kept open. Answering it is what releases the starter (below). Far Cry 3 Blood Dragon sends only `{2: pid, 5:1}`; a missing pid is taken from the pipe's client process | -| `uplay_ipc_pipe_` | game (`uplay_r1.dll`) | `Req.initReq(1)` → `Rsp.initRsp(1)`, answered every time it is asked. `Req.installerReq(13)` with `initInstallerReq` → `Rsp.installerRsp(10){1:{1:1, 2:"", 3: language}}`. `Req.userReq(11).getCredentialsReq(1){1: id}` → `Rsp.userRsp(8).getCredentialsRsp(1){1: id, 2: username, 3: "" (password), 4: userId, 5: email}` | +| `uplay_ipc_pipe_` | game (`uplay_r1.dll`, `uplay_r2.dll`) | `Req.initReq(1)` → `Rsp.initRsp(1)`, answered every time it is asked. `Req.installerReq(13)` with `initInstallerReq` → `Rsp.installerRsp(10){1:{1:1, 2:"", 3: language}}`. `Req.userReq(11).getCredentialsReq(1){1: id}` → `Rsp.userRsp(8).getCredentialsRsp(1){1: id, 2: username, 3: "" (password), 4: userId, 5: email}`. `Req.streamingReq(27)` → `Rsp.streamingRsp(20){1: id, 2:1, 4:{1:0}}` for the streaming type (not streamed), `{1: id, 2:4}` for any other streaming query | | `uplay_aux_ipc_pipe_` | `uplay_aux_r1(64).dll` (Denuvo) | `{1: rid, 2: init}` → `{1: rid, 2:{1:1, 2: pid, 3:3367, 3:3368, 3:3962}}`; `{1: rid, 3:{2:{2: challenge}}}` → `{1: rid, 3:{2:{2:1, 3:0, 4: game token, 5:""}}}` | | `uplay_service_ipc_pipe_` | Ubisoft helpers | Server sends `{3:{1:1, 3:{1: }}}` once, then only reads, unframed | | `orbit_ipc_pipe_` | game (`ubiorbitapi_r2.dll`) | `mg.protocol.orbitdll` from the DLL's own `proto_orbitdll/OrbitDll.proto`. `Req{1: id, 12: init{1: product}}` → `Rsp{1: id, 12:{1: save folder, 2:1}}`; `getLoginDetails(2)` → `{1: username, 2:"", 3:""}`; `getOsi(3){1: sub}` → `{2:1}` (failed, no online-services pipe) | @@ -53,9 +53,25 @@ followed by a proto2 message, except on `uplay_service_ipc_pipe_`. | 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) | +| 14 gameInstall | `{1:1, 2: installed chunks, 3: language}` | | 17 storage | `{1: "C:/users/steamuser/Saved Games/Ubisoft///"}`; the game appends file names directly, so the trailing slash matters | | 22 ubiServices | `{1: applicationId}` from the account's entitlements, left out when unknown | +### R2 titles + +`uplay_r2.dll` speaks the same `mg.protocol.uplaydll` messages (its embedded `UplayDll.proto` is identical to +`uplay_r1.dll`'s), but its `InitReq` names the subsystems the game uses: fields 4 to 11 (friend, overlay, +product, storage, install, multiplayer, store, streaming). Its `ApiContext` creates one object per requested +subsystem and copies the session into them. Friends, overlay, game session, store and crossboot are checked +for a missing object first; install and storage are not. A `gameInstall` sent to a game that did not ask for +install is copied into a null object: Prince of Persia: The Lost Crown (6145) asks for overlay, product and store +only, and crashed reading `0x68` in `uplay_r264.dll+0xaca2` two seconds after the session arrived. + +So when the request names subsystems, 14 is sent only with `subSystemInstall` (8), 17 only with +`subSystemStorage` (7), and an empty `multiplayerInit` (20) is added, which `uplay_r2.dll` asks for even when +empty. A request that names none gets the session above unchanged. The Lost Crown also opens a second context +that asks for every subsystem, and it gets the full session. + The overlay is reported off in all three places. `uplay_r1.dll` still loads `overlay.dll` from the runtime folder right after the session arrives, whatever the session says; without that file it gives up with `UplayAPI [ERROR]: Startup failed: cannot load uplay library` (Assassin's Creed Chronicles: China @@ -91,7 +107,6 @@ titles without Denuvo never open the aux pipe. ## Not covered yet -- R2 (`UPC_*`) titles use `uplay_r2.dll`; their pipe traffic has not been captured, so whether the - same server answers them is unverified. +- R2 titles other than The Lost Crown, and R2 requests beyond the session, credentials, product list and streaming type. - Orbit's online-services pipe (`getOsi` is declined) and Orbit titles other than Far Cry 3 Blood Dragon. - Achievements, friends, overlay, cloud saves. diff --git a/tools/ubisoft-launcher/src/launcher.rs b/tools/ubisoft-launcher/src/launcher.rs index 3d5fcac4c5..343708dba0 100644 --- a/tools/ubisoft-launcher/src/launcher.rs +++ b/tools/ubisoft-launcher/src/launcher.rs @@ -145,8 +145,10 @@ impl Config { Msg::new().msg(13, Msg::new().uint(1, 1).uint(3, 0).uint(4, OVERLAY_NONE).uint(6, 0)).0 } - /// `Rsp.initRsp`: the account, its products and the PC ticket. - pub fn session(&self) -> Vec { + /// `Rsp.initRsp`: the account, its products and the PC ticket. `uplay_r2.dll` copies the + /// install and storage state into objects it only creates for the subsystems the game asked + /// for, without checking them, so those parts follow the request when it names subsystems. + pub fn session(&self, wants: Option) -> Vec { let account = Msg::new() .text(1, &self.user_id) .text(2, &self.username) @@ -161,16 +163,25 @@ impl Config { body = body .msg(6, Msg::new().uint(1, self.product as u64).text(2, "")) .uint(7, 0) - .text(8, &self.ticket) - .msg(14, Msg::new().uint(1, 1).msg(2, self.chunks()).text(3, &self.language)) + .text(8, &self.ticket); + if wants.map_or(true, |w| w.install) { + body = body.msg(14, Msg::new().uint(1, 1).msg(2, self.chunks()).text(3, &self.language)); + } + body = body .msg(11, Msg::new().uint(1, 0)) .uint(12, 0) .msg(15, Msg::new().uint(1, 0).uint(2, OVERLAY_NONE)) - .msg(16, Msg::new().uint(1, 6211).uint(2, 22395).float(3, 1.0)) - .msg(17, Msg::new().text(1, &self.saves)) + .msg(16, Msg::new().uint(1, 6211).uint(2, 22395).float(3, 1.0)); + if wants.map_or(true, |w| w.storage) { + body = body.msg(17, Msg::new().text(1, &self.saves)); + } + body = body .bytes(18, b"") .msg(19, Msg::new().uint(1, 1).uint(2, 1)) .msg(21, Msg::new().uint(2, 1)); + if wants.is_some() { + body = body.bytes(20, b""); + } if !self.app_id.is_empty() { body = body.msg(22, Msg::new().text(1, &self.app_id)); } @@ -244,9 +255,24 @@ const ACKNOWLEDGED: &[(u32, u32, u32, u32, u64)] = &[ (25, 4, 17, 4, 1), // played with ]; -/// The id-and-result answer to a request in [ACKNOWLEDGED], with a name for the log. +/// `Rsp.streamingRsp` (20) for `Req.streamingReq` (27): the game is not streamed, so its streaming +/// type is `StreamingType_None` and every other streaming query is not found. +fn streaming(req: &[(u32, Value<'_>)]) -> (Vec, String) { + let id = pb::num(req, 1).unwrap_or(0); + let rsp = if pb::has(req, 3) { + Msg::new().uint(1, id).uint(2, 1).msg(4, Msg::new().uint(1, 0)) + } else { + Msg::new().uint(1, id).uint(2, 4) + }; + (Msg::new().msg(20, rsp).0, format!("streaming id {id} -> not streamed")) +} + +/// The id-and-result answer to a request in [ACKNOWLEDGED] or a streaming query, with a name for the log. pub fn acknowledge(body: &[u8]) -> Option<(Vec, String)> { let f = pb::fields(body)?; + if let Some(req) = pb::sub(&f, 27).and_then(pb::fields) { + return Some(streaming(&req)); + } for &(req, sub, rsp, rsp_sub, result) in ACKNOWLEDGED { let Some(inner) = pb::sub(&f, req).and_then(pb::fields) else { continue }; let Some(leaf) = pb::sub(&inner, sub).and_then(pb::fields) else { continue }; @@ -257,8 +283,27 @@ pub fn acknowledge(body: &[u8]) -> Option<(Vec, String)> { None } +/// The subsystems an `InitReq` asks for (fields 4 to 11). +#[derive(Clone, Copy, Debug, Default, PartialEq)] +pub struct Subsystems { + pub install: bool, + pub storage: bool, +} + +impl Subsystems { + /// `None` when the request names no subsystem at all. + pub fn of(init: &[u8]) -> Option { + let f = pb::fields(init)?; + if !(4..=11).any(|n| pb::has(&f, n)) { + return None; + } + let on = |n| pb::num(&f, n).unwrap_or(0) != 0; + Some(Subsystems { storage: on(7), install: on(8) }) + } +} + pub enum SessionReq { - Init, + Init(Option), Installer, ProductList(u64), Credentials(u64), @@ -271,7 +316,7 @@ pub fn session_request(body: &[u8]) -> SessionReq { if pb::sub(&f, 13).and_then(pb::fields).is_some_and(|i| pb::has(&i, 1)) { SessionReq::Installer } else if pb::has(&f, 1) { - SessionReq::Init + SessionReq::Init(pb::sub(&f, 1).and_then(Subsystems::of)) } else if let Some(get) = leaf(11, 1) { SessionReq::Credentials(pb::num(&get, 1).unwrap_or(0)) } else if let Some(list) = leaf(23, 1) { @@ -357,7 +402,7 @@ mod tests { #[test] fn the_session_carries_the_ticket_products_and_save_root() { - let rsp = config().session(); + let rsp = config().session(None); let init = pb::fields(pb::sub(&pb::fields(&rsp).unwrap(), 1).unwrap()).unwrap(); assert_eq!(pb::num(&init, 1), Some(1)); assert_eq!(pb::num(&init, 4), Some(109)); @@ -376,9 +421,47 @@ mod tests { assert_eq!((pb::num(&second, 1), pb::num(&second, 2), pb::sub(&second, 3)), (Some(64), Some(1), Some(&b"custo05"[..]))); } + fn session_fields(rsp: &[u8]) -> Vec { + let init = pb::fields(pb::sub(&pb::fields(rsp).unwrap(), 1).unwrap()).unwrap(); + init.iter().map(|(n, _)| *n).collect() + } + + #[test] + fn an_r2_session_leaves_out_the_install_and_storage_the_game_did_not_ask_for() { + let req = Msg::new().msg(1, Msg::new().uint(1, 6145).uint(2, 512).uint(3, 2).uint(4, 1).uint(5, 1).uint(7, 1).uint(8, 0)); + let SessionReq::Init(wants) = session_request(&req.0) else { panic!() }; + assert_eq!(wants, Some(Subsystems { install: false, storage: true })); + let fields = session_fields(&config().session(wants)); + assert!(!fields.contains(&14)); + assert!(fields.contains(&17)); + assert!(fields.contains(&20)); + let all = session_fields(&config().session(Some(Subsystems { install: true, storage: true }))); + assert!(all.contains(&14) && all.contains(&17)); + } + + #[test] + fn streaming_queries_say_the_game_is_not_streamed() { + let (answer, _) = acknowledge(&[0xda, 0x01, 0x06, 0x08, 0x80, 0x80, 0x08, 0x1a, 0x00]).unwrap(); + let rsp = pb::fields(pb::sub(&pb::fields(&answer).unwrap(), 20).unwrap()).unwrap(); + assert_eq!((pb::num(&rsp, 1), pb::num(&rsp, 2)), (Some(0x20000), Some(1))); + assert_eq!(pb::num(&pb::fields(pb::sub(&rsp, 4).unwrap()).unwrap(), 1), Some(0)); + let (answer, _) = acknowledge(&Msg::new().msg(27, Msg::new().uint(1, 7).bytes(2, b"")).0).unwrap(); + let rsp = pb::fields(pb::sub(&pb::fields(&answer).unwrap(), 20).unwrap()).unwrap(); + assert_eq!((pb::num(&rsp, 1), pb::num(&rsp, 2)), (Some(7), Some(4))); + } + + #[test] + fn an_r1_session_without_subsystems_keeps_install_and_storage() { + let SessionReq::Init(wants) = session_request(&Msg::new().msg(1, Msg::new().uint(1, 109).uint(2, 4242)).0) else { panic!() }; + assert_eq!(wants, None); + let fields = session_fields(&config().session(wants)); + assert!(fields.contains(&14) && fields.contains(&17)); + assert!(!fields.contains(&20)); + } + #[test] fn requests_are_told_apart() { - assert!(matches!(session_request(&Msg::new().msg(1, Msg::new().uint(1, 109)).0), SessionReq::Init)); + assert!(matches!(session_request(&Msg::new().msg(1, Msg::new().uint(1, 109)).0), SessionReq::Init(None))); assert!(matches!(session_request(&Msg::new().msg(13, Msg::new().bytes(1, b"")).0), SessionReq::Installer)); assert!(matches!(session_request(&[0xba, 0x01, 0x06, 0x0a, 0x04, 0x08, 0x80, 0x80, 0x04]), SessionReq::ProductList(65536))); let (answer, _) = acknowledge(&[0x42, 0x08, 0x0a, 0x06, 0x08, 0x80, 0x80, 0x08, 0x10, 0x00]).unwrap(); diff --git a/tools/ubisoft-launcher/src/main.rs b/tools/ubisoft-launcher/src/main.rs index 425522e638..0b7126a919 100644 --- a/tools/ubisoft-launcher/src/main.rs +++ b/tools/ubisoft-launcher/src/main.rs @@ -145,10 +145,11 @@ mod service { let mut pushes = 0; while let Some(req) = frames.next() { match launcher::session_request(&req) { - SessionReq::Init => { + SessionReq::Init(wants) => { pushes += 1; - send(&pipe, &state.cfg.session()); - state.say(&format!("session: init answered ({pushes})")); + 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))); } SessionReq::Installer => { send(&pipe, &state.cfg.installer());