diff --git a/apps/victory/src/main.rs b/apps/victory/src/main.rs index 31392ffb08..0c8961eaf2 100644 --- a/apps/victory/src/main.rs +++ b/apps/victory/src/main.rs @@ -7,6 +7,7 @@ mod census; mod inspect; mod run; mod shader; +#[cfg(windows)] mod translate; use std::path::PathBuf; @@ -69,6 +70,7 @@ enum Command { }, /// Run every shader found (containers, SGD5 files) through the /// translator and report what it cannot handle yet. + #[cfg(windows)] Translate { paths: Vec, /// Check emitted DXIL with dxil.dll's validator (`VICTORY_DXIL`, @@ -146,6 +148,7 @@ fn main() -> Result<()> { verbose, disasm, } => shader::run(paths, verbose || disasm, disasm), + #[cfg(windows)] Command::Translate { paths, validate, diff --git a/crates/victory-gpu/src/resource.rs b/crates/victory-gpu/src/resource.rs index 46c5c71abf..5a6ab31119 100644 --- a/crates/victory-gpu/src/resource.rs +++ b/crates/victory-gpu/src/resource.rs @@ -279,6 +279,7 @@ pub(crate) const SRGB: [(u32, u32); 3] = [(29, 28), (91, 87), (93, 88)]; /// The format a view of a title texture must name when its host copy is /// typeless (see [`DEPTH_FORMATS`], [`SRGB`]): the title's own; `None` if /// the host copy is typed. +#[cfg(windows)] pub(crate) fn view_format(this: This) -> Option { let own = pc_format(resource(this).desc.format); let host = host_resource(this)?; diff --git a/crates/victory-hle/src/modules/d3d12x.rs b/crates/victory-hle/src/modules/d3d12x.rs index ef8b2313c5..87f8c485c0 100644 --- a/crates/victory-hle/src/modules/d3d12x.rs +++ b/crates/victory-hle/src/modules/d3d12x.rs @@ -17,7 +17,9 @@ extern "system" fn create_device( iid: *const Iid, out: *mut *const Object, ) -> HRESULT { + #[cfg(windows)] victory_gpu::resource::use_allocator(super::xmem::XMemAlloc, super::xmem::XMemFree); + #[cfg(windows)] victory_gpu::resource::use_page_mapper(super::xmem::map_alias); #[cfg(windows)] victory_gpu::on_failure(host_gpu_failed); diff --git a/crates/victory-hle/src/modules/kernel.rs b/crates/victory-hle/src/modules/kernel.rs index 3ab3067122..e1fecc73ab 100644 --- a/crates/victory-hle/src/modules/kernel.rs +++ b/crates/victory-hle/src/modules/kernel.rs @@ -599,20 +599,23 @@ mod tests { #[test] fn title_images_report_their_original_path() { let base = 0x7000_0000_0000; - runtime::set_image_path(base, std::path::Path::new(r"C:\title\game.exe")); + let path = if cfg!(windows) { + r"C:\title\game.exe" + } else { + "/title/game.exe" + }; + runtime::set_image_path(base, std::path::Path::new(path)); let module = base as *mut c_void; let mut buf = [0xFFFFu16; 32]; let n = GetModuleFileNameW(module, buf.as_mut_ptr(), buf.len() as u32); - assert_eq!( - String::from_utf16_lossy(&buf[..n as usize]), - r"C:\title\game.exe" - ); + assert_eq!(String::from_utf16_lossy(&buf[..n as usize]), path); assert_eq!(buf[n as usize], 0); // Too small: truncated, NUL-terminated, the buffer size returned. let mut small = [0u8; 4]; assert_eq!(GetModuleFileNameA(module, small.as_mut_ptr(), 4), 4); - assert_eq!(&small, &[b'C', b':', b'\\', 0]); + assert_eq!(&small[..3], &path.as_bytes()[..3]); + assert_eq!(small[3], 0); } fn w(text: &str) -> Vec { @@ -657,7 +660,12 @@ mod tests { #[test] fn title_dlls_and_pseudo_modules_are_found_by_name() { let base = 0x7100_0000_0000usize; - runtime::set_image_path(base, std::path::Path::new(r"C:\title\Mapped.dll")); + let path = if cfg!(windows) { + r"C:\title\Mapped.dll" + } else { + "/title/Mapped.dll" + }; + runtime::set_image_path(base, std::path::Path::new(path)); runtime::set_title_dll_loader(Box::new(|file| match file { "late.dll" => Ok(Some(0x7200_0000_0000)), "broken.dll" => Err("bad image".into()), diff --git a/crates/victory-hle/src/modules/storage.rs b/crates/victory-hle/src/modules/storage.rs index c8863fb4ef..7fc09b647d 100644 --- a/crates/victory-hle/src/modules/storage.rs +++ b/crates/victory-hle/src/modules/storage.rs @@ -175,6 +175,7 @@ mod tests { #[test] fn serves_a_drive_over_the_title_folder_and_its_quota() { type Size = extern "system" fn(This, *mut usize) -> HRESULT; + #[cfg(windows)] type Get = extern "system" fn(This, usize, *mut u8, *mut usize) -> HRESULT; type Space = extern "system" fn(This, *mut SpaceInfo) -> HRESULT; type Prompt = extern "system" fn(This, u64, *mut AsyncBlock) -> HRESULT; @@ -190,23 +191,34 @@ mod tests { }); // The path is a drive root, never the host folder. - let mut size = 0; - assert_eq!(method::(&OBJECT, 0x18)(this, &mut size), S_OK); - assert_eq!(size, 4, "X:\\ and its NUL"); - let (mut buffer, mut used) = ([0u8; 4], 0); - let get = method::(&OBJECT, 0x20); - assert_eq!(get(this, 4, buffer.as_mut_ptr(), &mut used), S_OK); - let drive = std::str::from_utf8(&buffer[..3]).unwrap(); - assert!(drive.ends_with(":\\"), "{drive}"); - // Title file calls on it reach the folder. - let path = format!("{drive}save.dat\0"); - let mut attributes = [0u8; 36]; - let get_attributes = super::super::files::GetFileAttributesExW; - let wide: Vec = path.encode_utf16().collect(); - assert_ne!( - get_attributes(wide.as_ptr(), 0, attributes.as_mut_ptr().cast()), - 0 - ); + #[cfg(windows)] + { + let mut size = 0; + assert_eq!(method::(&OBJECT, 0x18)(this, &mut size), S_OK); + assert_eq!(size, 4, "X:\\ and its NUL"); + let (mut buffer, mut used) = ([0u8; 4], 0); + let get = method::(&OBJECT, 0x20); + assert_eq!(get(this, 4, buffer.as_mut_ptr(), &mut used), S_OK); + let drive = std::str::from_utf8(&buffer[..3]).unwrap(); + assert!(drive.ends_with(":\\"), "{drive}"); + // Title file calls on it reach the folder. + let path = format!("{drive}save.dat\0"); + let mut attributes = [0u8; 36]; + let get_attributes = super::super::files::GetFileAttributesExW; + let wide: Vec = path.encode_utf16().collect(); + assert_ne!( + get_attributes(wide.as_ptr(), 0, attributes.as_mut_ptr().cast()), + 0 + ); + } + #[cfg(not(windows))] + { + let mut size = 0; + assert_eq!( + method::(&OBJECT, 0x18)(this, &mut size), + NOT_SUPPORTED + ); + } let mut info = SpaceInfo { available_free: 0, diff --git a/crates/victory-hle/src/modules/xgame.rs b/crates/victory-hle/src/modules/xgame.rs index c54f8378f5..3335084084 100644 --- a/crates/victory-hle/src/modules/xgame.rs +++ b/crates/victory-hle/src/modules/xgame.rs @@ -81,12 +81,20 @@ extern "system" fn launch_new_game( .unwrap_or_default(); let ours: Vec<_> = std::env::args_os().skip(1).collect(); let command = relaunch_args(ours, current.as_os_str(), &exe, &args); - super::lifecycle::end_title( - "XLaunchNewGame", - Box::new(move || super::lifecycle::relaunch(command)), - ); - loop { - std::thread::park(); + #[cfg(windows)] + { + super::lifecycle::end_title( + "XLaunchNewGame", + Box::new(move || super::lifecycle::relaunch(command)), + ); + loop { + std::thread::park(); + } + } + #[cfg(not(windows))] + { + let _ = command; + tracing::warn!("XLaunchNewGame requires Windows"); } } diff --git a/crates/victory-hle/src/modules/xgameui.rs b/crates/victory-hle/src/modules/xgameui.rs index ab2d9e0094..4d340ba92c 100644 --- a/crates/victory-hle/src/modules/xgameui.rs +++ b/crates/victory-hle/src/modules/xgameui.rs @@ -111,11 +111,16 @@ fn limit(typed: &str, max: u32) -> String { } /// Asks the user in a modal host dialog; `None` if dismissed. -#[cfg(not(test))] +#[cfg(all(not(test), windows))] fn ask(title: &str, description: &str, default: &str, max: u32) -> Option { dialog::ask(title, description, default, max) } +#[cfg(all(not(test), not(windows)))] +fn ask(_: &str, _: &str, _: &str, _: u32) -> Option { + None +} + /// Tests answer for the user: "typed" for a title starting with "Type", /// cancelled otherwise. #[cfg(test)] @@ -123,6 +128,7 @@ fn ask(title: &str, _: &str, default: &str, _: u32) -> Option { title.starts_with("Type").then(|| format!("{default}typed")) } +#[cfg(windows)] mod dialog { use windows_sys::Win32::Foundation::{HWND, LPARAM, WPARAM}; use windows_sys::Win32::System::LibraryLoader::GetModuleHandleW; diff --git a/crates/victory-loader/src/prepare.rs b/crates/victory-loader/src/prepare.rs index 9895db121f..25825c2dc6 100644 --- a/crates/victory-loader/src/prepare.rs +++ b/crates/victory-loader/src/prepare.rs @@ -158,7 +158,8 @@ fn write(bytes: &mut [u8], at: usize, v: &[u8]) -> Result<(), PrepareError> { Ok(()) } -#[cfg(test)] +// These tests use the test executable itself as a PE image. +#[cfg(all(test, windows))] mod tests { use super::*; diff --git a/crates/victory-pe/src/image.rs b/crates/victory-pe/src/image.rs index 4acc6e3b27..a9a7e25248 100644 --- a/crates/victory-pe/src/image.rs +++ b/crates/victory-pe/src/image.rs @@ -402,10 +402,12 @@ mod tests { use super::*; /// The test binary itself is a real MSVC-linked PE32+ image. + #[cfg(windows)] fn own_image() -> Vec { std::fs::read(std::env::current_exe().unwrap()).unwrap() } + #[cfg(windows)] #[test] fn parses_own_test_binary() { let info = ImageInfo::parse(&own_image()).unwrap(); @@ -425,6 +427,7 @@ mod tests { assert!(info.tls.is_some()); } + #[cfg(windows)] #[test] fn rva_to_file_offset_maps_entry_point() { let data = own_image(); @@ -437,11 +440,15 @@ mod tests { fn rejects_garbage_without_panicking() { assert!(ImageInfo::parse(b"").is_err()); assert!(ImageInfo::parse(b"MZ not really").is_err()); - let mut truncated = own_image(); - truncated.truncate(0x200); - assert!(ImageInfo::parse(&truncated).is_err()); + #[cfg(windows)] + { + let mut truncated = own_image(); + truncated.truncate(0x200); + assert!(ImageInfo::parse(&truncated).is_err()); + } } + #[cfg(windows)] #[test] fn rejects_iat_outside_image() { let mut data = own_image(); @@ -460,7 +467,7 @@ mod tests { } } -#[cfg(test)] +#[cfg(all(test, windows))] mod dbg_tls { #[test] fn dump_tls() {