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
3 changes: 3 additions & 0 deletions apps/victory/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ mod census;
mod inspect;
mod run;
mod shader;
#[cfg(windows)]
mod translate;

use std::path::PathBuf;
Expand Down Expand Up @@ -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<PathBuf>,
/// Check emitted DXIL with dxil.dll's validator (`VICTORY_DXIL`,
Expand Down Expand Up @@ -146,6 +148,7 @@ fn main() -> Result<()> {
verbose,
disasm,
} => shader::run(paths, verbose || disasm, disasm),
#[cfg(windows)]
Command::Translate {
paths,
validate,
Expand Down
1 change: 1 addition & 0 deletions crates/victory-gpu/src/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u32> {
let own = pc_format(resource(this).desc.format);
let host = host_resource(this)?;
Expand Down
2 changes: 2 additions & 0 deletions crates/victory-hle/src/modules/d3d12x.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
22 changes: 15 additions & 7 deletions crates/victory-hle/src/modules/kernel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u16> {
Expand Down Expand Up @@ -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()),
Expand Down
46 changes: 29 additions & 17 deletions crates/victory-hle/src/modules/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -190,23 +191,34 @@ mod tests {
});

// The path is a drive root, never the host folder.
let mut size = 0;
assert_eq!(method::<Size>(&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::<Get>(&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<u16> = 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::<Size>(&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::<Get>(&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<u16> = 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::<Size>(&OBJECT, 0x18)(this, &mut size),
NOT_SUPPORTED
);
}

let mut info = SpaceInfo {
available_free: 0,
Expand Down
20 changes: 14 additions & 6 deletions crates/victory-hle/src/modules/xgame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}

Expand Down
8 changes: 7 additions & 1 deletion crates/victory-hle/src/modules/xgameui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,18 +111,24 @@ 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<String> {
dialog::ask(title, description, default, max)
}

#[cfg(all(not(test), not(windows)))]
fn ask(_: &str, _: &str, _: &str, _: u32) -> Option<String> {
None
}

/// Tests answer for the user: "typed" for a title starting with "Type",
/// cancelled otherwise.
#[cfg(test)]
fn ask(title: &str, _: &str, default: &str, _: u32) -> Option<String> {
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;
Expand Down
3 changes: 2 additions & 1 deletion crates/victory-loader/src/prepare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;

Expand Down
15 changes: 11 additions & 4 deletions crates/victory-pe/src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8> {
std::fs::read(std::env::current_exe().unwrap()).unwrap()
}

#[cfg(windows)]
#[test]
fn parses_own_test_binary() {
let info = ImageInfo::parse(&own_image()).unwrap();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -460,7 +467,7 @@ mod tests {
}
}

#[cfg(test)]
#[cfg(all(test, windows))]
mod dbg_tls {
#[test]
fn dump_tls() {
Expand Down