diff --git a/Cargo.lock b/Cargo.lock index 296352c41..69638db77 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -538,6 +538,7 @@ dependencies = [ "rand 0.8.6", "raw-window-handle", "regex", + "rfd", "rtrb", "serde", "sha1", @@ -4715,6 +4716,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d49e936b501e5c5bf01fda3a9452ff86dc3ea98ad5f283e1455153142d97518c" dependencies = [ "bitflags 2.11.1", + "block2 0.6.2", "objc2 0.6.4", "objc2-core-graphics", "objc2-foundation 0.3.2", @@ -5320,6 +5322,12 @@ dependencies = [ "windows-sys 0.61.2", ] +[[package]] +name = "pollster" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f3a9f18d041e6d0e102a0a46750538147e5e8992d3b4873aaafee2520b00ce3" + [[package]] name = "portable-atomic" version = "1.13.1" @@ -5702,6 +5710,30 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "19b30a45b0cd0bcca8037f3d0dc3421eaf95327a17cad11964fb8179b4fc4832" +[[package]] +name = "rfd" +version = "0.17.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20dafead71c16a34e1ff357ddefc8afc11e7d51d6d2b9fbd07eaa48e3e540220" +dependencies = [ + "block2 0.6.2", + "dispatch2", + "js-sys", + "libc", + "log", + "objc2 0.6.4", + "objc2-app-kit 0.3.2", + "objc2-core-foundation", + "objc2-foundation 0.3.2", + "percent-encoding", + "pollster", + "raw-window-handle", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "windows-sys 0.61.2", +] + [[package]] name = "robust" version = "1.2.0" diff --git a/crates/benilla-app/Cargo.toml b/crates/benilla-app/Cargo.toml index 5bab73c26..84ea97db1 100644 --- a/crates/benilla-app/Cargo.toml +++ b/crates/benilla-app/Cargo.toml @@ -42,6 +42,10 @@ regex = "1" libc = "0.2" # PNG encoding only: the macOS cursor's NSImage data and screenshots. image = { version = "0.25", default-features = false, features = ["png"] } +# The "no WoW install" error dialog (`no_install`): AppKit, Win32 and, on Linux, `zenity`; no GTK. +# `xdg-portal` is the Linux backend that carries the message dialog; `wayland` is its file-dialog +# parent handle, which a message dialog without a parent never reads. +rfd = { version = "0.17", default-features = false, features = ["xdg-portal"] } # Thread-to-ECS channels: crossbeam's `Receiver` is `Sync`, so it is a resource without a mutex. crossbeam-channel = "0.5" benilla-assets = { path = "../benilla-assets", default-features = false } diff --git a/crates/benilla-app/src/lib.rs b/crates/benilla-app/src/lib.rs index 11c207a37..1b2376ef1 100644 --- a/crates/benilla-app/src/lib.rs +++ b/crates/benilla-app/src/lib.rs @@ -69,6 +69,7 @@ mod minimap; mod nameplates; mod names; mod net; +mod no_install; mod npc_text; /// Ships in part (the FPS journal and the clocks it reads); the rest is `dev`. mod perf; @@ -265,6 +266,13 @@ fn launch(build: BuildId, extend: Option>) -> AppExit { // `App` exists, so a panic while plugins build is reported too. crash::install(build); + // Fonts, art and the stock interface all come from the install, so without one the client + // ends here, before any window or plugin exists (`no_install`). + let data_dir = match no_install::resolve() { + Ok(data_dir) => data_dir, + Err(err) => return no_install::fail(&err, run_mode::unattended()), + }; + let mut app = App::new(); // The panel footer and the build banner read the stamp back. app.insert_resource(build); @@ -315,18 +323,13 @@ fn launch(build: BuildId, extend: Option>) -> AppExit { } // The `mpq://` source must be registered before `AssetPlugin` (in `DefaultPlugins`) builds. The - // install is found by `benilla_formats::wow_data`, as everywhere; without one the source is - // absent and terrain loads fail gracefully. - match benilla_formats::wow_data() { - Some(data_dir) => { - if let Err(e) = benilla_assets::register_mpq_source(&mut app, &data_dir) { - eprintln!("benilla-assets: mpq:// source unavailable ({e:#})"); - } - } - None => eprintln!( - "benilla: no WoW install found — looked in {:?}", - benilla_formats::candidates() - ), + // install is found by `benilla_formats::wow_data`, as everywhere, and is required above; one + // whose archives will not open ends the boot the same way (`no_install`). + if let Err(e) = benilla_assets::register_mpq_source(&mut app, &data_dir) { + return no_install::fail( + &no_install::NoInstall::unreadable(&data_dir, &e), + run_mode::unattended(), + ); } // No `game://` source: the five UI shaders are compiled in by `crate::shaders` diff --git a/crates/benilla-app/src/no_install.rs b/crates/benilla-app/src/no_install.rs new file mode 100644 index 000000000..19dc0b288 --- /dev/null +++ b/crates/benilla-app/src/no_install.rs @@ -0,0 +1,169 @@ +//! The boot with no WoW install: fatal. Fonts, art and the stock interface all come from the +//! install, so a client without one is a window of textless buttons. The reference ships inside its +//! install; its archive mount (`0x403740`, `0x403b00`) logs a missing base archive and goes on, and +//! ends the process with a fatal error dialog (`SErrDisplayAppFatal2`, `0x403b6f`) only for one +//! that is present and fails its checks. +//! +//! Deviation: a boot with no install at all ends at a fatal error dialog, where the reference logs +//! each missing archive and goes on (`0x403b00`), because nothing past this point can draw a word. +//! +//! [`require`] is the decision, pure; [`fail`] is the exit, which shows a native dialog only to a +//! person: an [unattended](crate::run_mode::unattended) run prints the same message and exits. + +use std::path::PathBuf; + +use bevy::app::AppExit; + +/// Why the client cannot start: the message a person is shown and a log carries. +#[derive(Debug, PartialEq, Eq)] +pub(crate) struct NoInstall { + title: &'static str, + message: String, +} + +impl NoInstall { + pub(crate) fn message(&self) -> &str { + &self.message + } + + /// A `Data` folder whose archives will not open, a corrupt one or none the chain knows: as fatal + /// as no folder, the case the reference's `0x403b6f` covers for a base archive. + pub(crate) fn unreadable(data_dir: &std::path::Path, err: &anyhow::Error) -> Self { + Self { + title: "benilla: the WoW install cannot be read", + message: format!( + "benilla found a World of Warcraft install at\n {}\nbut cannot read its archives:\n \ + {err:#}\n\nCheck that this is an unmodified 1.12.1 Data folder.", + data_dir.display() + ), + } + } +} + +/// The install the boot goes on with, or the fatal error: `found` is [`benilla_formats::wow_data`] +/// and `looked_in` its [`benilla_formats::candidates`], named in order in the message. +pub(crate) fn require(found: Option, looked_in: &[PathBuf]) -> Result { + found.ok_or_else(|| NoInstall { + title: "benilla: no WoW install found", + message: message(looked_in), + }) +} + +/// What to tell the player: the folders searched and the two ways to supply an install. +fn message(looked_in: &[PathBuf]) -> String { + let mut out = + String::from("benilla needs a World of Warcraft 1.12.1 install and found none.\n"); + if looked_in.is_empty() { + // `$WOW_DATA` set and empty ends the search with nothing in it. + out.push_str("\nWOW_DATA is set and empty, which means no install.\n"); + } else { + out.push_str("\nIt looked in:\n"); + for dir in looked_in { + out.push_str(&format!(" {}\n", dir.display())); + } + } + out.push_str( + "\nPut the install's Data folder at Data/ or WoW/Data/ beside the benilla binary, \ + or point WOW_DATA at it.", + ); + out +} + +/// Report `err` and end the boot with a failing exit: stderr always, the dialog too unless the run +/// is `unattended`, so an instrumented run never waits on a click. +pub(crate) fn fail(err: &NoInstall, unattended: bool) -> AppExit { + eprintln!("benilla: {}", err.message()); + if !unattended { + // Linux shows it through `zenity` and logs nothing when that is missing, which stderr covers. + rfd::MessageDialog::new() + .set_level(rfd::MessageLevel::Error) + .set_title(err.title) + .set_description(err.message()) + .set_buttons(rfd::MessageButtons::Ok) + .show(); + } + AppExit::error() +} + +/// [`require`] on the real resolver. +pub(crate) fn resolve() -> Result { + require(benilla_formats::wow_data(), &benilla_formats::candidates()) +} + +#[cfg(test)] +mod tests { + use super::*; + use std::path::Path; + + fn dirs() -> Vec { + [ + "/opt/wow/Data", + "/games/benilla/Data", + "/games/benilla/WoW/Data", + ] + .map(PathBuf::from) + .to_vec() + } + + /// With no install the boot is fatal, and the message names every folder searched, in order, + /// and both ways to supply one. + #[test] + fn no_install_is_fatal_and_names_every_folder_searched() { + let looked_in = dirs(); + let err = require(None, &looked_in).expect_err("no install must be fatal"); + let msg = err.message(); + let mut from = 0; + for dir in &looked_in { + let at = msg[from..] + .find(&dir.display().to_string()) + .unwrap_or_else(|| panic!("{dir:?} not named in order in:\n{msg}")); + from += at; + } + assert!( + msg.contains("Data/ or WoW/Data/ beside the benilla binary"), + "{msg}" + ); + assert!(msg.contains("WOW_DATA"), "{msg}"); + } + + /// `WOW_DATA=` (set, empty) searches nowhere, and the message says why instead of listing none. + #[test] + fn an_empty_wow_data_is_named_as_the_reason() { + let err = require(None, &[]).expect_err("no install must be fatal"); + assert!( + err.message().contains("WOW_DATA is set and empty"), + "{}", + err.message() + ); + assert!(!err.message().contains("looked in")); + } + + /// An install found goes on, whatever else was searched. + #[test] + fn a_found_install_boots() { + let found = Path::new("/games/benilla/Data").to_path_buf(); + assert_eq!(require(Some(found.clone()), &dirs()), Ok(found)); + } + + /// The unattended exit is a failing one: `AppExit::error()` is what the launcher returns as the + /// process status. (The attended branch shows a dialog, so no test takes it.) + #[test] + fn the_unattended_exit_fails() { + let err = require(None, &dirs()).unwrap_err(); + assert_ne!(fail(&err, true), AppExit::Success); + } + + /// A folder whose archives will not open names the folder and the error, under its own title. + #[test] + fn an_unreadable_install_names_the_folder_and_the_error() { + let err = NoInstall::unreadable( + Path::new("/games/benilla/Data"), + &anyhow::anyhow!("no known vanilla MPQs found in /games/benilla/Data"), + ); + assert!(err + .message() + .contains("/games/benilla/Data\nbut cannot read")); + assert!(err.message().contains("no known vanilla MPQs")); + assert_ne!(err.title, "benilla: no WoW install found"); + } +} diff --git a/docs/CONTRIBUTING.md b/docs/CONTRIBUTING.md index a9a46b33f..8ac5412df 100644 --- a/docs/CONTRIBUTING.md +++ b/docs/CONTRIBUTING.md @@ -106,7 +106,8 @@ out of scope is closed with the reason. - **A 1.12.1 install of your own.** `WOW_DATA=`, or a `WoW` link at the repo root, which only a dev build sees: the player build looks for `Data/` or `WoW/Data/` beside the binary. benilla reads the install and never writes into it. `WOW_DATA=` (set, empty) - means "no install", which is how the no-install boot is tested on a machine that has one. + means "no install": the client refuses to start (an error dialog, or stderr alone in an + unattended run) and the no-install tests run on a machine that has one. - **Without the install, green is hollow.** Well over a thousand tests read the install and skip when it is absent, and a few dozen more read a corpus of vanilla addons (`BENILLA_ADDON_CORPUS=`, or a `wow-addons-vanilla` link at the root), diff --git a/docs/DEVIATIONS.md b/docs/DEVIATIONS.md index cb83e8667..b2ea69a21 100644 --- a/docs/DEVIATIONS.md +++ b/docs/DEVIATIONS.md @@ -29,7 +29,7 @@ A setting boots at the reference's default unless it is listed here (`docs/METHO Each entry is the first sentence of a `Deviation:` comment, linking to where it lives. -- [benilla-app](#benilla-app): 216 +- [benilla-app](#benilla-app): 217 - [benilla-assets](#benilla-assets): 6 - [benilla-blp](#benilla-blp): 1 - [benilla-formats](#benilla-formats): 17 @@ -169,6 +169,10 @@ Each entry is the first sentence of a `Deviation:` comment, linking to where it - The reference paces a self move through the same replay chain as a remote's, which would only delay a correction to our own pose. ([`src/net/motion/remote.rs:55`](../crates/benilla-app/src/net/motion/remote.rs#L55)) - Its rate-limited hover climb (`0x636fa1`, 7 yd/s) is not reproduced, because the cache gate needs a pure function; it converges to this answer. ([`src/net/motion/spline.rs:568`](../crates/benilla-app/src/net/motion/spline.rs#L568)) +#### no_install + +- A boot with no install at all ends at a fatal error dialog, where the reference logs each missing archive and goes on (`0x403b00`), because nothing past this point can draw a word. ([`src/no_install.rs:7`](../crates/benilla-app/src/no_install.rs#L7)) + #### player - The reference re-projects the point's height onto the first walkable facet a zero-size box gather finds at the enemy (`0x60fe25`-`0x60fe51`); here it keeps the enemy's height. ([`src/player/approach.rs:263`](../crates/benilla-app/src/player/approach.rs#L263)) diff --git a/docs/MAP.md b/docs/MAP.md index 5e4d1d66f..7fc5788bc 100644 --- a/docs/MAP.md +++ b/docs/MAP.md @@ -105,7 +105,7 @@ ## Modules (top-level, per crate) - **benilla-adt** (lib.rs): combined_alpha -- **benilla-app** (lib.rs): addon_harness area area_poi area_trigger asset_churn aura_visual bindings blob_shadow bowstring camera_shake capture chat_bubble chr_classes cinematic client_state combat_log combat_text console crash creature_anim creature_type cursor cvars death debug_panel dev doodad_events entities field_watch fishing_line footprints game_plugins game_tip glue_session go_anim go_templates hover_log item_watch items loading_screen local_state minimap name_persist nameplates names net npc_text opaque2d perf pipe_warm player poi_marker portrait preflight probe_shield query_cache quest_markers raid_marks ranged_flex realmlist run_mode screen_fade screenshot script_calls shaders shutdown smart_rect sound spell swing_refusal target test_support text_filter text_reshape textinput transport tutorial ui_action ui_auction ui_aura ui_bank ui_battlefield ui_battlefield_positions ui_battlefield_score ui_bind_confirm ui_binder ui_cast ui_char ui_chat ui_craft ui_dialog_verbs ui_dressup ui_duel ui_follow ui_gamma ui_gm_ticket ui_gossip ui_guild ui_honor ui_inspect ui_instance ui_item_text ui_items ui_layout ui_logout ui_loot ui_loot_roll ui_macro ui_mail ui_merchant ui_mirror ui_models ui_net ui_panes ui_party ui_pass ui_pet ui_pet_book ui_pet_doll ui_pet_stats ui_petition ui_quest ui_quest_log ui_quest_share ui_reputation ui_saved ui_script ui_session ui_shapeshift ui_social ui_spellbook ui_stable ui_summon ui_tabard ui_talent ui_talent_wipe ui_taxi ui_text ui_tooltip ui_trade ui_tradeskill ui_trainer ui_unit ui_world_map video vplates weapon_trail world_backdrop world_state world_state_ui +- **benilla-app** (lib.rs): addon_harness area area_poi area_trigger asset_churn aura_visual bindings blob_shadow bowstring camera_shake capture chat_bubble chr_classes cinematic client_state combat_log combat_text console crash creature_anim creature_type cursor cvars death debug_panel dev doodad_events entities field_watch fishing_line footprints game_plugins game_tip glue_session go_anim go_templates hover_log item_watch items loading_screen local_state minimap name_persist nameplates names net no_install npc_text opaque2d perf pipe_warm player poi_marker portrait preflight probe_shield query_cache quest_markers raid_marks ranged_flex realmlist run_mode screen_fade screenshot script_calls shaders shutdown smart_rect sound spell swing_refusal target test_support text_filter text_reshape textinput transport tutorial ui_action ui_auction ui_aura ui_bank ui_battlefield ui_battlefield_positions ui_battlefield_score ui_bind_confirm ui_binder ui_cast ui_char ui_chat ui_craft ui_dialog_verbs ui_dressup ui_duel ui_follow ui_gamma ui_gm_ticket ui_gossip ui_guild ui_honor ui_inspect ui_instance ui_item_text ui_items ui_layout ui_logout ui_loot ui_loot_roll ui_macro ui_mail ui_merchant ui_mirror ui_models ui_net ui_panes ui_party ui_pass ui_pet ui_pet_book ui_pet_doll ui_pet_stats ui_petition ui_quest ui_quest_log ui_quest_share ui_reputation ui_saved ui_script ui_session ui_shapeshift ui_social ui_spellbook ui_stable ui_summon ui_tabard ui_talent ui_talent_wipe ui_taxi ui_text ui_tooltip ui_trade ui_tradeskill ui_trainer ui_unit ui_world_map video vplates weapon_trail world_backdrop world_state world_state_ui - **benilla-assets** (lib.rs): adt anim_rng blp column_grid coords gpu_blp m2 materials minimap_grid model spatial_cache terrain tex_filter trace wdt wmo world_assets - **benilla-formats** (lib.rs): anim_data area_poi area_sound area_table area_trigger auction_house bank_bag_slot_prices camera_shakes cfg_categories cfg_configs chain characters chat_channels chr_classes chr_races cinematics creature_families creature_sound creature_types creatures dbc death_thud durability elevators emit_timing emote_text emotes environmental_damage exhaustion factions footsteps game_tips gameobjects garble gm_survey gm_ticket_category ground_effects install item_random_properties item_sounds item_visuals itembagfamily itemclass items itemsets itemsubclass languages lfg_dungeons light liquid loading_screen locale locale_routing lock lock_type loose macro_icons maps material minimap_translate models npc_greeting packages page_text_material particles pet_stats quest_headers quest_info race_creature_type race_pvp_team race_sound ribbons server_messages sheathe skill_lines skill_tiers sound_entries sound_provider sound_water spell_focus spell_mechanic spell_visual spells stable_slot_prices stationery talents taxi taxi_nodes taxi_path terrain text_filter_lists tga transport_period transports unit_blood value_track vocal_ui_sounds wdl weapon_impact weapon_swing wmo_area world_map_area world_map_continent world_map_overlay world_state_ui wow_ini zone_map - **benilla-lua** (lib.rs): api cfmt compile heap lex lib_base lib_math lib_string lib_table number parse proto reload table value vm @@ -206,7 +206,7 @@ - `WOW_CULL_TRACE` — benilla-world/src/exterior_cull.rs - `WOW_CULLDUMP` — benilla-world/src/wmo_portal/mod.rs - `WOW_CURSOR_TRACE` — benilla-app/src/cursor.rs -- `WOW_DATA` — benilla-app/src/local_state.rs, benilla-formats/src/install.rs, benilla-formats/tests/project_folder.rs, benilla-formats/tests/wow_data_env.rs, benilla-formats/tests/wow_data_none.rs +- `WOW_DATA` — benilla-app/src/local_state.rs, benilla-app/src/no_install.rs, benilla-formats/src/install.rs, benilla-formats/tests/project_folder.rs, benilla-formats/tests/wow_data_env.rs, benilla-formats/tests/wow_data_none.rs - `WOW_DEMO_BOTTOM_BARS` — benilla-app/src/ui_script/mod.rs - `WOW_DEPTH` — benilla-app/src/capture/depth_probe.rs, benilla-app/src/dev.rs, benilla-world/src/bgwin.rs - `WOW_DEPTH_AFTER` — benilla-app/src/capture/depth_probe.rs