Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ xcl shaders D:\data\shaders.rpf --top 50 # pack statistics; --recomp / --compi
xcl rpf D:\data\shaders.rpf --extract NAME --out folder
```

- **Without a command line** (xcl.exe opened from Explorer) XCL shows a small menu: *Choose a
game…* (pick its exe or `MicrosoftGame.config`) or *Run again* (the last one). On an error the
window stays open until Enter.
- **Without a command line** (xcl.exe opened from Explorer) XCL shows a small menu: *Add a game
folder…* (pick the folder of the game's unpacked files), *Choose a game…* (pick its exe or
`MicrosoftGame.config`) or *Run again* (the last one). On an error the window stays open until Enter.
- XCL works on **unpacked** game files you own; it contains nothing for decrypting or
circumventing DRM.
- **The game folder is never modified** – writes go to the overlay.
Expand Down
2 changes: 2 additions & 0 deletions crates/xcl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ features = [
"Win32_System_Com",
"Win32_System_LibraryLoader",
"Win32_System_Threading",
"Win32_UI_Shell",
"Win32_UI_Shell_Common",
"Win32_UI_WindowsAndMessaging",
]

Expand Down
30 changes: 28 additions & 2 deletions crates/xcl/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ fn run_picked_game() -> i32 {
Choice::Again => last.clone(),
Choice::Cancel => None,
Choice::Choose | Choice::NoMenu => pick_game_file(),
Choice::Folder => pick_game_folder(),
};
// MicrosoftGame.config stands for its folder: XCL picks the exe the config names
picked.map(|file| match file.file_name() {
Expand Down Expand Up @@ -186,6 +187,7 @@ impl Drop for Ui {

enum Choice {
Choose,
Folder,
Again,
Cancel,
/// no task dialog on this system: straight to the file dialog
Expand All @@ -197,17 +199,20 @@ fn menu(last: Option<&std::path::Path>) -> Choice {
use windows_sys::Win32::UI::Controls::*;
const CHOOSE: i32 = 100;
const AGAIN: i32 = 101;
const FOLDER: i32 = 102;
type TaskDialogIndirect = unsafe extern "system" fn(*const TASKDIALOGCONFIG, *mut i32, *mut i32, *mut i32) -> i32;
let Some(f) = (unsafe { system_proc("comctl32.dll", "TaskDialogIndirect") }) else { return Choice::NoMenu };
let title = wide("XCL");
let heading = wide("Run an Xbox Series game");
let content = wide("XCL runs the game from its unpacked files. Choose the game's exe or its MicrosoftGame.config.");
let content = wide("XCL runs the game from its unpacked files. Choose the game's folder, its exe or its MicrosoftGame.config.");
let folder = wide("Add a game folder…\nThe folder with the game's unpacked files");
let again = last.map(|p| wide(&format!("Run again\n{}", p.display())));
let choose = wide("Choose a game…\nThe game's exe or MicrosoftGame.config");
let mut buttons = Vec::new();
if let Some(a) = &again {
buttons.push(TASKDIALOG_BUTTON { nButtonID: AGAIN, pszButtonText: a.as_ptr() });
}
buttons.push(TASKDIALOG_BUTTON { nButtonID: FOLDER, pszButtonText: folder.as_ptr() });
buttons.push(TASKDIALOG_BUTTON { nButtonID: CHOOSE, pszButtonText: choose.as_ptr() });
let mut c: TASKDIALOGCONFIG = unsafe { std::mem::zeroed() };
c.cbSize = std::mem::size_of::<TASKDIALOGCONFIG>() as u32;
Expand All @@ -219,17 +224,38 @@ fn menu(last: Option<&std::path::Path>) -> Choice {
c.pszContent = content.as_ptr();
c.cButtons = buttons.len() as u32;
c.pButtons = buttons.as_ptr();
c.nDefaultButton = if again.is_some() { AGAIN } else { CHOOSE };
c.nDefaultButton = if again.is_some() { AGAIN } else { FOLDER };
let mut pressed = 0i32;
let hr = unsafe { std::mem::transmute::<usize, TaskDialogIndirect>(f)(&c, &mut pressed, std::ptr::null_mut(), std::ptr::null_mut()) };
match (hr, pressed) {
(h, _) if h < 0 => Choice::NoMenu,
(_, CHOOSE) => Choice::Choose,
(_, AGAIN) => Choice::Again,
(_, FOLDER) => Choice::Folder,
_ => Choice::Cancel,
}
}

/// The standard Windows folder picker (None: cancelled). COM only, through ole32 – no dialog
/// library is imported for it.
fn pick_game_folder() -> Option<PathBuf> {
use windows::Win32::Foundation::HWND;
use windows::Win32::System::Com::{CoCreateInstance, CoTaskMemFree, CLSCTX_INPROC_SERVER};
use windows::Win32::UI::Shell::{FileOpenDialog, IFileOpenDialog, FOS_FORCEFILESYSTEM, FOS_PICKFOLDERS, SIGDN_FILESYSPATH};
unsafe {
let dialog: IFileOpenDialog = CoCreateInstance(&FileOpenDialog, None, CLSCTX_INPROC_SERVER).ok()?;
let options = dialog.GetOptions().ok()?;
dialog.SetOptions(options | FOS_PICKFOLDERS | FOS_FORCEFILESYSTEM).ok()?;
let _ = dialog.SetTitle(windows::core::w!("XCL – choose the game's folder"));
let owner = HWND(windows_sys::Win32::System::Console::GetConsoleWindow() as _);
dialog.Show(Some(owner)).ok()?;
let name = dialog.GetResult().ok()?.GetDisplayName(SIGDN_FILESYSPATH).ok()?;
let path = name.to_string().ok().map(PathBuf::from);
CoTaskMemFree(Some(name.0 as _));
path
}
}

/// The standard Windows open dialog (None: cancelled).
fn pick_game_file() -> Option<PathBuf> {
use windows_sys::Win32::UI::Controls::Dialogs::*;
Expand Down
Loading