fix(ubisoft): R2 games get a session matching the subsystems they ask for (#2450)

uplay_r2.dll speaks the same UplayDll.proto as uplay_r1.dll, but its InitReq
names the subsystems the game uses (fields 4 to 11) and its ApiContext only
creates objects for those. It copies gameInstall and storage into their
objects without checking for them, so the gameInstall droiddeck-upc always
sent crashed Prince of Persia: The Lost Crown (6145), which asks for overlay,
product and store only: an access violation reading 0x68 in
uplay_r264.dll+0xaca2 two seconds after the session.

- When the request names subsystems, gameInstall (14) is sent only with
  subSystemInstall and storage (17) only with subSystemStorage, and an empty
  multiplayerInit (20) is added. Requests that name none keep the old session.
- streamingReq (27) is answered: the streaming type is None, other streaming
  queries are not found.
- The log records the subsystems each init asked for.

Co-authored-by: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com>
This commit is contained in:
K11MCH1andKurt Himebauch authored and GitHub committed 2026-11-11 10:34:06 -05:00
1 parent 2848484a99
commit f16b023f0d
3 files changed
+116 -17

No files matched your search

+94 -11
View File
@@ -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<u8> {
/// `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<Subsystems>) -> Vec<u8> {
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<u8>, 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<u8>, 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<u8>, 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<Subsystems> {
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<Subsystems>),
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<u32> {
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();
+4 -3
View File
@@ -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());