From 1d99a18670874eec996fa169fabab0c8b4b06155 Mon Sep 17 00:00:00 2001 From: mastrr9 <333127948+mastrr9@users.noreply.github.com> Date: Tue, 24 Nov 2026 02:58:52 -0500 Subject: [PATCH] XGameRuntime: implement XPersistentLocalStorageMountForPackage Mounts the running package's PLS as an XPackage mount handle (path via XPackageGetMountPath(Size), closed with XPackageCloseMountHandle). Any other package has no PLS offline and gets HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), as the GDK reference documents for a title whose PLS does not exist. Null out, null or empty identifier give E_INVALIDARG. Assisted-by: Claude Code (Claude Opus 5.5) --- crates/xcl/src/hle/xgameruntime/api.rs | 2 +- crates/xcl/src/hle/xgameruntime/mod.rs | 46 ++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/crates/xcl/src/hle/xgameruntime/api.rs b/crates/xcl/src/hle/xgameruntime/api.rs index 13406406d..49c75512b 100644 --- a/crates/xcl/src/hle/xgameruntime/api.rs +++ b/crates/xcl/src/hle/xgameruntime/api.rs @@ -792,7 +792,7 @@ fn xgamesave() -> Vec<(&'static str, usize)> { } fn xpls() -> Vec<(&'static str, usize)> { - let mut v = named![XPersistentLocalStorageGetPathSize, XPersistentLocalStorageGetPath, XPersistentLocalStorageGetSpaceInfo]; + let mut v = named![XPersistentLocalStorageGetPathSize, XPersistentLocalStorageGetPath, XPersistentLocalStorageGetSpaceInfo, XPersistentLocalStorageMountForPackage]; // no prompt to show: the space asked for is granted v.extend([("XPersistentLocalStoragePromptUserForSpaceAsync", prompt_space_async as usize), ("XPersistentLocalStoragePromptUserForSpaceResult", empty_result as usize)]); v diff --git a/crates/xcl/src/hle/xgameruntime/mod.rs b/crates/xcl/src/hle/xgameruntime/mod.rs index a52177397..ab65a6d31 100644 --- a/crates/xcl/src/hle/xgameruntime/mod.rs +++ b/crates/xcl/src/hle/xgameruntime/mod.rs @@ -103,6 +103,7 @@ pub fn exports() -> Vec<(&'static str, usize)> { XPersistentLocalStorageGetPathSize, XPersistentLocalStorageGetPath, XPersistentLocalStorageGetSpaceInfo, + XPersistentLocalStorageMountForPackage, XGameSaveFilesGetFolderWithUiAsync, XGameSaveFilesGetFolderWithUiResult, // game save containers @@ -390,6 +391,26 @@ pub unsafe extern "system" fn XPersistentLocalStorageGetPath(size: usize, buf: * write_cstr_out(&pls_path(), buf, size, used) } +/// `XPersistentLocalStorageMountForPackage(packageIdentifier, mountHandle)`: a package's PLS +/// as an XPackage mount handle (path through XPackageGetMountPath(Size), closed with +/// XPackageCloseMountHandle). The only package XCL has is the running game, so its own PLS +/// is mounted (the path XPersistentLocalStorageGetPath gives); any other package has no PLS +/// here: HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), what the GDK reference gives for a title +/// whose PLS does not exist. +pub unsafe extern "system" fn XPersistentLocalStorageMountForPackage(id: *const u8, out: *mut *mut c_void) -> HRESULT { + if out.is_null() { + return E_INVALIDARG; + } + *out = std::ptr::null_mut(); + let Some(id) = crate::util::from_cstr_ptr(id).filter(|s| !s.is_empty()) else { return E_INVALIDARG }; + if !id.eq_ignore_ascii_case(&package_identifier()) { + crate::xlog_warn!("XPersistentLocalStorageMountForPackage({id}) – no such package here"); + return crate::util::hresult_from_win32(2); // ERROR_FILE_NOT_FOUND + } + *out = Box::into_raw(Box::new(Mount { path: pls_path() })) as *mut c_void; + S_OK +} + #[repr(C)] pub struct XPersistentLocalStorageSpaceInfo { pub available_free_bytes: u64, @@ -1166,4 +1187,29 @@ mod tests { let _ = std::fs::remove_file(&probe); } } + + #[test] + fn pls_mounts_for_the_running_package_only() { + unsafe { + let mut m: *mut c_void = 1 as *mut c_void; + assert_eq!(XPersistentLocalStorageMountForPackage(b"x\0".as_ptr(), std::ptr::null_mut()), E_INVALIDARG); + assert_eq!(XPersistentLocalStorageMountForPackage(std::ptr::null(), &mut m), E_INVALIDARG); + assert!(m.is_null()); + assert_eq!(XPersistentLocalStorageMountForPackage(b"\0".as_ptr(), &mut m), E_INVALIDARG); + // another title's package: no PLS here + let other = b"Some.Other.Title_1.0.0.0_x64__8wekyb3d8bbwe\0"; + assert_eq!(XPersistentLocalStorageMountForPackage(other.as_ptr(), &mut m), crate::util::hresult_from_win32(2)); + assert!(m.is_null()); + // the running package, in any case: the same path XPersistentLocalStorageGetPath gives + let id = format!("{}\0", package_identifier().to_ascii_lowercase()); + assert_eq!(XPersistentLocalStorageMountForPackage(id.as_ptr(), &mut m), S_OK); + assert!(!m.is_null()); + let mut size = 0usize; + assert_eq!(XPackageGetMountPathSize(m, &mut size), S_OK); + let mut buf = vec![0u8; size]; + assert_eq!(XPackageGetMountPath(m, size, buf.as_mut_ptr()), S_OK); + assert_eq!(std::ffi::CStr::from_bytes_until_nul(&buf).unwrap().to_str().unwrap(), pls_path()); + XPackageCloseMountHandle(m); + } + } }