mirror of
https://github.com/ivall/xcl.git
synced 2026-11-24 05:14:57 +01:00
A small menu when xcl.exe is opened from Explorer; README trimmed
Without a command line and with a console of its own (double-click), xcl.exe shows a task dialog: "Choose a game…" (the open dialog, for the game's exe or MicrosoftGame.config) or "Run again" (the last one, %LOCALAPPDATA%\XCL\last-game.txt). Without the task dialog it goes straight to the open dialog; on an error the console waits for Enter. From a terminal, xcl without arguments still prints the help. The dialog libraries are looked up at run time and the common controls 6 come from an activation context of the menu's own, so xcl.exe gets no new imports and no manifest – the game runs in this executable. README: the menu; the offline sentence under the games table is gone (What is missing still lists Xbox Live and Store licensing).
This commit is contained in:
@@ -24,8 +24,6 @@ next steps:
|
||||
| **Fortnite** | `436609B6.FortniteClient` 2.0.1461.7919 | ✅ | works fully, as far as the game allows without its online services | the game itself is online-only (multiplayer servers) |
|
||||
| **XDefiant** | `Ubisoft.XDefiant-Game` 1.0.0.186 | ✅ | works fully, as far as the game allows without its servers | the game's own servers have been shut down |
|
||||
|
||||
XCL stays offline: no fake Xbox Live, sign-in, game backends or licences.
|
||||
|
||||
## Highlights
|
||||
|
||||
- **100 % of a retail game's shaders translate** – all 26 698 RDNA2 programs (26 503 records) of its shader pack
|
||||
@@ -106,6 +104,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.
|
||||
- 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.
|
||||
|
||||
@@ -61,5 +61,10 @@ features = [
|
||||
"Win32_System_SystemInformation",
|
||||
"Win32_System_SystemServices",
|
||||
"Win32_System_Threading",
|
||||
"Win32_System_Console",
|
||||
"Win32_System_ApplicationInstallationAndServicing",
|
||||
"Win32_Globalization",
|
||||
"Win32_UI_Controls",
|
||||
"Win32_UI_Controls_Dialogs",
|
||||
"Win32_UI_WindowsAndMessaging",
|
||||
]
|
||||
|
||||
@@ -70,6 +70,7 @@ fn main() {
|
||||
println!("xcl {}", env!("CARGO_PKG_VERSION"));
|
||||
0
|
||||
}
|
||||
None if started_by_double_click() => run_picked_game(),
|
||||
_ => {
|
||||
print!("{HELP}");
|
||||
if args.is_empty() || args[0] == "--help" || args[0] == "-h" {
|
||||
@@ -81,3 +82,174 @@ fn main() {
|
||||
};
|
||||
std::process::exit(code);
|
||||
}
|
||||
|
||||
/// xcl.exe opened from Explorer: the console is its own (from a terminal, the shell shares it).
|
||||
fn started_by_double_click() -> bool {
|
||||
let mut ids = [0u32; 4];
|
||||
unsafe { windows_sys::Win32::System::Console::GetConsoleProcessList(ids.as_mut_ptr(), ids.len() as u32) == 1 }
|
||||
}
|
||||
|
||||
/// No command line: a small menu (choose a game / run the last one again), then the game runs
|
||||
/// in this console. On an error the console stays open until Enter, so the message can be read.
|
||||
fn run_picked_game() -> i32 {
|
||||
let last_file = xcl::launcher::data_root().join("last-game.txt");
|
||||
let last = std::fs::read_to_string(&last_file).ok().map(|s| PathBuf::from(s.trim())).filter(|p| p.exists());
|
||||
let target = {
|
||||
let _ui = Ui::enter();
|
||||
let picked = match menu(last.as_deref()) {
|
||||
Choice::Again => last.clone(),
|
||||
Choice::Cancel => None,
|
||||
Choice::Choose | Choice::NoMenu => pick_game_file(),
|
||||
};
|
||||
// MicrosoftGame.config stands for its folder: XCL picks the exe the config names
|
||||
picked.map(|file| match file.file_name() {
|
||||
Some(n) if n.eq_ignore_ascii_case("MicrosoftGame.config") => file.parent().map(PathBuf::from).unwrap_or(file),
|
||||
_ => file,
|
||||
})
|
||||
};
|
||||
let Some(target) = target else { return 0 };
|
||||
let _ = std::fs::create_dir_all(xcl::launcher::data_root());
|
||||
let _ = std::fs::write(&last_file, target.to_string_lossy().as_bytes());
|
||||
println!("xcl run \"{}\"", target.display());
|
||||
let code = xcl::launcher::run(&target, &[]);
|
||||
if code != 0 {
|
||||
println!("\nXCL ended with code {code}. Press Enter to close.");
|
||||
let _ = std::io::stdin().read_line(&mut String::new());
|
||||
}
|
||||
code
|
||||
}
|
||||
|
||||
fn wide(s: &str) -> Vec<u16> {
|
||||
s.encode_utf16().chain(std::iter::once(0)).collect()
|
||||
}
|
||||
|
||||
/// `name` of system DLL `dll`, looked up when the menu needs it: xcl.exe does not import the
|
||||
/// dialog libraries (the game runs in this executable, and must not get them).
|
||||
unsafe fn system_proc(dll: &str, name: &str) -> Option<usize> {
|
||||
use windows_sys::Win32::System::LibraryLoader::{GetProcAddress, LoadLibraryW};
|
||||
let lib = LoadLibraryW(wide(dll).as_ptr());
|
||||
if lib.is_null() {
|
||||
return None;
|
||||
}
|
||||
GetProcAddress(lib, format!("{name}\0").as_ptr()).map(|f| f as usize)
|
||||
}
|
||||
|
||||
/// While the menu is open: COM for the file dialog, and the common controls 6 (the task
|
||||
/// dialog, the current look) through an activation context of its own – not a manifest of
|
||||
/// xcl.exe, which would apply to the game too.
|
||||
struct Ui {
|
||||
actctx: Option<(windows_sys::Win32::Foundation::HANDLE, usize)>,
|
||||
}
|
||||
|
||||
impl Ui {
|
||||
fn enter() -> Ui {
|
||||
use windows_sys::Win32::System::ApplicationInstallationAndServicing::{ActivateActCtx, CreateActCtxW, ACTCTXW};
|
||||
const MANIFEST: &str = r#"<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
|
||||
<dependency><dependentAssembly>
|
||||
<assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="*" publicKeyToken="6595b64144ccf1df" language="*"/>
|
||||
</dependentAssembly></dependency>
|
||||
</assembly>
|
||||
"#;
|
||||
unsafe {
|
||||
windows_sys::Win32::System::Com::CoInitializeEx(std::ptr::null(), windows_sys::Win32::System::Com::COINIT_APARTMENTTHREADED as u32);
|
||||
}
|
||||
let path = std::env::temp_dir().join("xcl-menu.manifest");
|
||||
let actctx = std::fs::write(&path, MANIFEST).ok().and_then(|()| unsafe {
|
||||
let source = wide(&path.to_string_lossy());
|
||||
let mut c: ACTCTXW = std::mem::zeroed();
|
||||
c.cbSize = std::mem::size_of::<ACTCTXW>() as u32;
|
||||
c.lpSource = source.as_ptr();
|
||||
let h = CreateActCtxW(&c);
|
||||
if h == windows_sys::Win32::Foundation::INVALID_HANDLE_VALUE {
|
||||
return None;
|
||||
}
|
||||
let mut cookie = 0usize;
|
||||
(ActivateActCtx(h, &mut cookie) != 0).then_some((h, cookie))
|
||||
});
|
||||
Ui { actctx }
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for Ui {
|
||||
fn drop(&mut self) {
|
||||
use windows_sys::Win32::System::ApplicationInstallationAndServicing::{DeactivateActCtx, ReleaseActCtx};
|
||||
unsafe {
|
||||
if let Some((h, cookie)) = self.actctx {
|
||||
DeactivateActCtx(0, cookie);
|
||||
ReleaseActCtx(h);
|
||||
}
|
||||
windows_sys::Win32::System::Com::CoUninitialize();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum Choice {
|
||||
Choose,
|
||||
Again,
|
||||
Cancel,
|
||||
/// no task dialog on this system: straight to the file dialog
|
||||
NoMenu,
|
||||
}
|
||||
|
||||
/// The menu: a task dialog with "Choose a game…" and, after a first run, "Run again".
|
||||
fn menu(last: Option<&std::path::Path>) -> Choice {
|
||||
use windows_sys::Win32::UI::Controls::*;
|
||||
const CHOOSE: i32 = 100;
|
||||
const AGAIN: i32 = 101;
|
||||
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 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: CHOOSE, pszButtonText: choose.as_ptr() });
|
||||
let mut c: TASKDIALOGCONFIG = unsafe { std::mem::zeroed() };
|
||||
c.cbSize = std::mem::size_of::<TASKDIALOGCONFIG>() as u32;
|
||||
c.hwndParent = unsafe { windows_sys::Win32::System::Console::GetConsoleWindow() };
|
||||
c.dwFlags = TDF_USE_COMMAND_LINKS | TDF_ALLOW_DIALOG_CANCELLATION | TDF_POSITION_RELATIVE_TO_WINDOW;
|
||||
c.dwCommonButtons = TDCBF_CANCEL_BUTTON;
|
||||
c.pszWindowTitle = title.as_ptr();
|
||||
c.pszMainInstruction = heading.as_ptr();
|
||||
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 };
|
||||
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,
|
||||
_ => Choice::Cancel,
|
||||
}
|
||||
}
|
||||
|
||||
/// The standard Windows open dialog (None: cancelled).
|
||||
fn pick_game_file() -> Option<PathBuf> {
|
||||
use windows_sys::Win32::UI::Controls::Dialogs::*;
|
||||
type GetOpenFileName = unsafe extern "system" fn(*mut OPENFILENAMEW) -> i32;
|
||||
let f = unsafe { system_proc("comdlg32.dll", "GetOpenFileNameW") }?;
|
||||
// pairs of (description, pattern), each ending in NUL, the list in one more
|
||||
let filter: Vec<u16> = "Xbox game (*.exe, MicrosoftGame.config)\0*.exe;MicrosoftGame.config\0All files\0*.*\0\0".encode_utf16().collect();
|
||||
let title = wide("XCL – choose a game");
|
||||
let mut file = vec![0u16; 32768];
|
||||
let mut ofn: OPENFILENAMEW = unsafe { std::mem::zeroed() };
|
||||
ofn.lStructSize = std::mem::size_of::<OPENFILENAMEW>() as u32;
|
||||
ofn.hwndOwner = unsafe { windows_sys::Win32::System::Console::GetConsoleWindow() };
|
||||
ofn.lpstrFilter = filter.as_ptr();
|
||||
ofn.lpstrFile = file.as_mut_ptr();
|
||||
ofn.nMaxFile = file.len() as u32;
|
||||
ofn.lpstrTitle = title.as_ptr();
|
||||
ofn.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_NOCHANGEDIR | OFN_EXPLORER;
|
||||
if unsafe { std::mem::transmute::<usize, GetOpenFileName>(f)(&mut ofn) } == 0 {
|
||||
return None;
|
||||
}
|
||||
let n = file.iter().position(|&c| c == 0).unwrap_or(file.len());
|
||||
Some(PathBuf::from(String::from_utf16_lossy(&file[..n])))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user