diff --git a/apps/victory/src/run.rs b/apps/victory/src/run.rs index 822a92b..454bdab 100644 --- a/apps/victory/src/run.rs +++ b/apps/victory/src/run.rs @@ -110,6 +110,32 @@ pub fn run( println!("title dll {name} at {:#x}", dll.base()); victory_hle::runtime::set_image_path(dll.base(), &title_dir.join(name)); } + let imported: Vec<&str> = image + .info() + .imports + .iter() + .map(|m| m.dll.as_str()) + .collect(); + let mapped: Vec<&str> = dlls.iter().map(|(name, _)| name.as_str()).collect(); + let absent = absent_title_dlls(&imported, &mapped, &wanted); + if !absent.is_empty() { + let message = format!( + "{} not in {}, and neither the host nor VIctory provides {}: the package is \ + incomplete; copy every file of the package next to the executable", + absent.join(", "), + title_dir.display(), + if absent.len() == 1 { "it" } else { "them" }, + ); + println!("missing dlls {message}"); + // None of their imports can be bound, so the title stops at its first + // call into one (Grand Theft Auto VI 1.0.2.1 at +0x2237178 during + // System Init, #930) with nothing saying why. Stubs only if asked for. + if execute && matches!(unimplemented, Unimplemented::Trap) { + anyhow::bail!( + "the title's own DLLs are missing: {message} (`--unimplemented zero` runs it anyway)" + ); + } + } let policy = match unimplemented { Unimplemented::Trap => UnimplementedPolicy::Trap, @@ -225,6 +251,25 @@ fn title_dll(host: &victory_hle::HostPolicy, dll: &str) -> bool { !host.allows(dll) && !victory_hle::registry().iter().any(|m| m.serves(dll)) } +/// The DLLs among `imported` (the main image's static imports) that must +/// come from the title's folder (`wanted`) but were not mapped from it: +/// none of their imports can be bound. Each named once, case ignored. +#[cfg(any(windows, test))] +fn absent_title_dlls( + imported: &[&str], + mapped: &[&str], + wanted: &dyn Fn(&str) -> bool, +) -> Vec { + let mut absent: Vec = Vec::new(); + for &dll in imported { + let known = |list: &[&str]| list.iter().any(|m| m.eq_ignore_ascii_case(dll)); + if wanted(dll) && !known(mapped) && !absent.iter().any(|a| a.eq_ignore_ascii_case(dll)) { + absent.push(dll.to_owned()); + } + } + absent +} + /// Title DLLs the title loads itself (`LoadLibrary`) that nothing imports, /// e.g. The title's upscaler behind its FidelityFX loader. #[cfg(windows)] @@ -349,6 +394,42 @@ impl LoaderLock { } } +#[cfg(test)] +mod absent_tests { + use super::absent_title_dlls; + + #[test] + fn title_dlls_missing_from_the_folder_are_named_once() { + // The host provides kernel32, our runtime d3d12_xs; the rest are the + // title's own (#930: the four DLLs beside the executable missing). + let wanted = |dll: &str| { + !["KERNEL32.dll", "d3d12_xs.dll"] + .iter() + .any(|h| h.eq_ignore_ascii_case(dll)) + }; + let imported = [ + "KERNEL32.dll", + "d3d12_xs.dll", + "XboxBvhBuilder.dll", + "MSVCP140.dll", + "Bink2Scarlett.dll", + "xboxbvhbuilder.dll", + ]; + let mapped = ["msvcp140.dll"]; + assert_eq!( + absent_title_dlls(&imported, &mapped, &wanted), + ["XboxBvhBuilder.dll", "Bink2Scarlett.dll"] + ); + } + + #[test] + fn a_complete_package_has_nothing_absent() { + let wanted = |dll: &str| dll.starts_with("Title"); + assert!(absent_title_dlls(&["Title.dll", "Host.dll"], &["TITLE.DLL"], &wanted).is_empty()); + assert!(absent_title_dlls(&[], &[], &wanted).is_empty()); + } +} + #[cfg(all(test, windows))] mod tests { use std::sync::{Arc, Mutex};