diff --git a/crates/benilla-app/src/area.rs b/crates/benilla-app/src/area.rs index d51c645c1..b9e7bc949 100644 --- a/crates/benilla-app/src/area.rs +++ b/crates/benilla-app/src/area.rs @@ -254,7 +254,8 @@ fn pvp_faction_text(pvp: Option<(&str, &str)>) -> Option { pvp.map(|(_, faction)| faction.to_string()) } -/// `GetZonePVPInfo` (`0x48d540`): `(pvpType, isArena)`. isArena is the leaf's Flags `0x80`, read +/// `GetZonePVPInfo` (`0x48d540`) returns three values, `pvpType, factionName, isArena`; this gives +/// the first and third, [`pvp_faction_text`] the second. isArena is the leaf's Flags `0x80`, read /// before any bail. The type is nil with no zone row, no faction template, or the display gate /// closed: it opens on a PvP realm ([`RealmPvp`]) or in a zone whose Flags carry `0x10`, the six /// capitals (`0x48d5c2`/`0x48d5cc`). Open, it is the zone's FactionGroupMask against the template's diff --git a/crates/benilla-app/src/game_plugins.rs b/crates/benilla-app/src/game_plugins.rs index b3d8503d3..247e653e8 100644 --- a/crates/benilla-app/src/game_plugins.rs +++ b/crates/benilla-app/src/game_plugins.rs @@ -1657,6 +1657,72 @@ pub(crate) mod schedule_tests { ); } + /// Every latched window's show reads `"npc"` (`GossipFrame.lua:33-35`, `QuestFrame.lua:63-65`, + /// `BankFrame.lua:127-128`, …), which the reference seats before the show: the packet's handler + /// writes `[0xb4e2d0]` (`0x4e26fa` → `0x4e1fe9` → `0x4930d0`) and only then fires + /// `GOSSIP_SHOW` (`0x4e27df`). Here the latch reaches the token through `feed_interact_npc` and + /// `feed_units`, so each window's feed runs after both, or a show whose text is cached fires in + /// the same frame as the open with the token unset. Read off the declared graph. + #[test] + fn every_latched_windows_show_reads_the_token_its_latch_seated() { + let mut app = headless_client(); + let c = census(&mut app, Update, SyncPoints::Declared); + if !type_names_available(&c) { + eprintln!( + "skipped: this build carries no type names (bevy/debug rides with the dev feature)" + ); + return; + } + let one = |suffix: &str| -> SystemKey { + let mut hits = c.systems.iter().filter(|(_, s)| s.name.ends_with(suffix)); + match (hits.next(), hits.next()) { + (Some((k, _)), None) => *k, + _ => panic!("exactly one system named `…{suffix}` in Update"), + } + }; + let mut succ: HashMap> = HashMap::new(); + for (a, b) in &c.dependencies { + succ.entry(*a).or_default().push(*b); + } + let after = |from: SystemKey| -> HashSet { + let (mut seen, mut stack) = (HashSet::new(), vec![from]); + while let Some(n) = stack.pop() { + for m in succ.get(&n).into_iter().flatten() { + if seen.insert(*m) { + stack.push(*m); + } + } + } + seen + }; + let units = one("::ui_unit::feed_units"); + assert!( + after(one("::ui_session::feed_interact_npc")).contains(&units), + "feed_units runs after feed_interact_npc, which publishes the latch it names \"npc\" by" + ); + let seated = after(units); + let stale: Vec<&str> = [ + "::ui_gossip::feed_gossip", + "::ui_quest::feed_quest", + "::ui_bank::feed_bank", + "::ui_taxi::feed_taxi", + "::ui_stable::feed_stable", + "::ui_tabard::feed_tabard", + "::ui_petition::feed::feed_petition", + "::ui_merchant::feed_merchant", + "::ui_trainer::feed_trainer", + "::ui_auction::feed_auction", + "::ui_trade::feed_trade", + ] + .into_iter() + .filter(|feed| !seated.contains(&one(feed))) + .collect(); + assert!( + stale.is_empty(), + "these windows' shows can read \"npc\" before feed_units seats it: {stale:?}" + ); + } + /// The VM ticks once a frame (`extract::tick_script`, in `UiInput`): a push the tick must /// see rides `UiFeed`, chained after the net drain and before the tick; a drain of what it /// produced is `.after(UiInput)`. Read off the built graph. Fails a holder with no path to or diff --git a/crates/benilla-app/src/spell/bind_gates.rs b/crates/benilla-app/src/spell/bind_gates.rs index 4c24e4076..e46cee454 100644 --- a/crates/benilla-app/src/spell/bind_gates.rs +++ b/crates/benilla-app/src/spell/bind_gates.rs @@ -1,7 +1,7 @@ //! `BindTarget 0x6e5b40`'s gates: the five silent exits a unit meets before any relation arm //! (`6e5bd8`-`6e5ca2`). A refused unit binds nothing, so `ArmCast` falls to its next candidate, //! the player behind `autoSelfCast`, and then to the enemy-word refusal or the targeting cursor. -//! The read-only mirror `SpellCanTargetUnit 0x6e6460` runs the same five (`6e6507`-`6e65ab`), so +//! The read-only mirror `SpellCanTargetObject 0x6e6460` runs the same five (`6e6507`-`6e65ab`), so //! the press, the cursor's click, `SpellTargetUnit` and the hover verdict share this one gate //! through [`super::cast_target::unit_binds`]. diff --git a/crates/benilla-app/src/spell/targeting/cursor.rs b/crates/benilla-app/src/spell/targeting/cursor.rs index c2ae58ac4..5628c708b 100644 --- a/crates/benilla-app/src/spell/targeting/cursor.rs +++ b/crates/benilla-app/src/spell/targeting/cursor.rs @@ -953,7 +953,7 @@ mod tests { ); } - /// The unit leg's range compare, the tail of `SpellCanTargetUnit 0x6e6460`, hands + /// The unit leg's range compare, the tail of `SpellCanTargetObject 0x6e6460`, hands /// `GetMinMaxRange` the hovered unit (`0x6e679b`, `0x6e67d1`): a melee spell is in range to /// 7.667 yards while the caster and that unit both run, and to the 5.0 floor otherwise. #[test] diff --git a/crates/benilla-app/src/spell/targeting/mod.rs b/crates/benilla-app/src/spell/targeting/mod.rs index 84fad3cd7..e140c9ec3 100644 --- a/crates/benilla-app/src/spell/targeting/mod.rs +++ b/crates/benilla-app/src/spell/targeting/mod.rs @@ -239,7 +239,7 @@ impl BindChecks<'_, '_> { /// - `Location`: `TargetingWantsLocation 0x6e6320`, `word & 0x60`, the terrain click. /// - `Item`: `TargetingWantsItem 0x6e6330`, `word & 0x4010`, the bag and paper-doll clicks. /// - `GameObject`: `TargetingWantsGameObject 0x6e62d0`, `word & 0x4800`, the world object click. -/// - `Unit`: `SpellCanTargetUnit 0x6e6460`, the unit arm of the world click. +/// - `Unit`: `SpellCanTargetObject 0x6e6460`, the unit arm of the world click. /// - `Corpse`: `0x6e6230`, `word & 0x8600`, the pick's corpse flag `0x40` ([`corpse`]). /// /// The masks overlap on `TARGET_FLAG_LOCKED`, so a lock spell answers both the item and the @@ -254,8 +254,8 @@ pub(crate) enum TargetingWants { Corpse, } -/// The unit-shaped bits of the flag_word, the first gate `SpellCanTargetUnit` tests before it runs -/// the candidate through the unit arm's relation and liveness checks. +/// The unit-shaped bits of the flag_word, the first gate `SpellCanTargetObject 0x6e6460` tests +/// before it runs the candidate through the unit arm's relation and liveness checks. const UNIT_WORD_BITS: u16 = 0x0002 | 0x0004 | 0x0008 | 0x0080 | 0x0100 | 0x0200 | 0x0400 | 0x8000; impl TargetingWants { @@ -346,8 +346,8 @@ impl SpellTargeting { self.0.as_ref().is_some_and(|t| wants.matches(t.word)) } - /// `SpellCanTargetUnit`'s predicate `0x6e6460`, its unit leg, with the range flag both callers - /// pass (the world hover `0x4828d0` at `48290b`, the Lua `SpellCanTargetUnit 0x6e6d00`): + /// `SpellCanTargetObject 0x6e6460`, its unit leg, with the range flag both callers pass (the + /// world hover `0x4828d0` at `48290b`, the Lua `SpellCanTargetUnit 0x6e6d00`): /// `BindTarget`'s gates and relation checks (`6e6507`–`6e65ab`), then min² ≤ d² ≤ max² /// (`6e677c`–`6e6802`), so a unit inside the minimum is out too. There is no line-of-sight /// test. diff --git a/crates/benilla-app/src/target/relations/fixture.rs b/crates/benilla-app/src/target/relations/fixture.rs index 9e201eee0..4a11495dc 100644 --- a/crates/benilla-app/src/target/relations/fixture.rs +++ b/crates/benilla-app/src/target/relations/fixture.rs @@ -47,13 +47,16 @@ pub(crate) fn factions() -> Factions { )) } -/// A player-controlled player of this template. +/// A player-controlled Human Warrior of this template: race and class 1, the bytes a reputation +/// slot's masks test (`0x4d5512`), where a 0 would test bit 31. pub(crate) fn player(guid: u64, template: u32) -> RelUnit { RelUnit { guid, is_player: true, flags: PC, template: Some(template), + race: 1, + class: 1, ..Default::default() } } diff --git a/crates/benilla-app/src/ui_auction/mod.rs b/crates/benilla-app/src/ui_auction/mod.rs index f8f8a0533..b808a7af7 100644 --- a/crates/benilla-app/src/ui_auction/mod.rs +++ b/crates/benilla-app/src/ui_auction/mod.rs @@ -531,6 +531,7 @@ impl Plugin for UiAuctionPlugin { feed_auction .after(crate::ui_unit::UnitFeed) .in_set(UiFeed) + .in_set(crate::ui_session::NpcWindowFeed) .run_if(crate::ui_script::ingame_ui_up), drain_auction.in_set(crate::ui_script::UiDrain), ), diff --git a/crates/benilla-app/src/ui_bank/mod.rs b/crates/benilla-app/src/ui_bank/mod.rs index 8bb10cf5f..52e1ad095 100644 --- a/crates/benilla-app/src/ui_bank/mod.rs +++ b/crates/benilla-app/src/ui_bank/mod.rs @@ -102,7 +102,9 @@ impl Plugin for UiBankPlugin { .add_systems( Update, ( - feed_bank.in_set(UiFeed), + feed_bank + .in_set(UiFeed) + .in_set(crate::ui_session::NpcWindowFeed), drain_bank.in_set(crate::ui_script::UiDrain), ), ); diff --git a/crates/benilla-app/src/ui_chat/idle.rs b/crates/benilla-app/src/ui_chat/idle.rs index 85685e4ad..59a03a604 100644 --- a/crates/benilla-app/src/ui_chat/idle.rs +++ b/crates/benilla-app/src/ui_chat/idle.rs @@ -19,9 +19,10 @@ use bevy::time::Real; use super::away::{afk_line, push_system, AfkMirror}; use super::feed::ChatLog; -/// `[0xcf0bc8]`, the last-input stamp: elapsed real time on the clock (`0x42c010`) both its one -/// writer (`0x42d7bb`) and the handler (`0x482ebe`) read. Process-global, zero at start and never -/// reset, not even at world entry, so a client untouched from launch is idle at five minutes. +/// `[0xcf0bc8]`, the last-input stamp: elapsed real time on the clock (`0x42c010`) that stamps each +/// queued input (`0x42d7bb`) and the handler (`0x482ebe`) reads; its seven writers are listed at +/// [`stamp_input`]. Process-global, zero at start and never reset, not even at world entry, so a +/// client untouched from launch is idle at five minutes. #[derive(Resource, Debug, Clone, Copy, Default)] pub(crate) struct LastInput(Duration); diff --git a/crates/benilla-app/src/ui_gossip/mod.rs b/crates/benilla-app/src/ui_gossip/mod.rs index dbf0081ae..78ed248f5 100644 --- a/crates/benilla-app/src/ui_gossip/mod.rs +++ b/crates/benilla-app/src/ui_gossip/mod.rs @@ -174,7 +174,9 @@ impl Plugin for UiGossipPlugin { .add_systems( Update, ( - feed_gossip.in_set(UiFeed), + feed_gossip + .in_set(UiFeed) + .in_set(crate::ui_session::NpcWindowFeed), drain_gossip.in_set(crate::ui_script::UiDrain), ), ); diff --git a/crates/benilla-app/src/ui_merchant/mod.rs b/crates/benilla-app/src/ui_merchant/mod.rs index 63800d589..204ad7d3c 100644 --- a/crates/benilla-app/src/ui_merchant/mod.rs +++ b/crates/benilla-app/src/ui_merchant/mod.rs @@ -122,7 +122,10 @@ impl Plugin for UiMerchantPlugin { ( // After `UnitFeed`: `MERCHANT_SHOW`'s paint reads the item and // player-requirement stores for `GetMerchantItemInfo`'s `isUsable`. - feed_merchant.after(crate::ui_unit::UnitFeed).in_set(UiFeed), + feed_merchant + .after(crate::ui_unit::UnitFeed) + .in_set(UiFeed) + .in_set(crate::ui_session::NpcWindowFeed), // Before `feed_char`: the `UPDATE_INVENTORY_ALERTS` its doll push fires, a // repair's through the durability watcher's recompute (`0x5d9920` → // `0x4c7ee0`, `0x4c8080`), repaints each doll slot, which refreshes the Repair diff --git a/crates/benilla-app/src/ui_pet/bar.rs b/crates/benilla-app/src/ui_pet/bar.rs index 6a2975a9f..f95673555 100644 --- a/crates/benilla-app/src/ui_pet/bar.rs +++ b/crates/benilla-app/src/ui_pet/bar.rs @@ -1,8 +1,6 @@ //! The pet action bar's feed: the ten packed words of the last `SMSG_PET_SPELLS`, which the //! server owns whole, rendered as ten `PetActionView`s each frame. -use std::time::Instant; - use bevy::prelude::*; use benilla_protocol::messages::{ @@ -188,7 +186,8 @@ pub(super) fn feed_pet_bar( return; }; let memory = memory.get(script); - let now = Instant::now(); + // Every read takes the frame's anchor, the instant its starts project from: one frame, + // one time, however long the frame runs. let (anchor, ui_now) = (clock.anchor, clock.ui_now); let has_bar = bar.has_bar(); // An unstreamed pet is not usable (`0x4bd034`), and no slot shows active. @@ -219,7 +218,7 @@ pub(super) fn feed_pet_bar( .flatten(); let cooldown = display.and_then(|d| { bar.cooldowns - .info(entry.action(), 0, Some(d), now) + .info(entry.action(), 0, Some(d), anchor) .ui_triple(anchor, ui_now) }); slot_view( diff --git a/crates/benilla-app/src/ui_pet/flush_tests.rs b/crates/benilla-app/src/ui_pet/flush_tests.rs index 73b5feac3..5b6f944bd 100644 --- a/crates/benilla-app/src/ui_pet/flush_tests.rs +++ b/crates/benilla-app/src/ui_pet/flush_tests.rs @@ -87,13 +87,25 @@ impl Rig { .record_count() } - /// Whether the pet's list still holds a record that has run out. - fn elapsed_pending(&self) -> bool { + /// Whether the pet's list still holds a record that has run out by `at`. + fn elapsed_pending(&self, at: Instant) -> bool { self.app .world() .resource::() .cooldowns - .sweep_pending(Instant::now()) + .sweep_pending(at) + } + + /// The frame's clock pair stepped to `ahead` past the wall clock, as the UI step re-anchors it + /// each frame: every record armed so far is then `ahead` older, however long the run took. + fn step_clock(&mut self, ahead: Duration) { + let mut clock = self + .app + .world_mut() + .resource_mut::(); + let anchor = Instant::now() + ahead; + clock.ui_now += anchor.duration_since(clock.anchor).as_secs_f64(); + clock.anchor = anchor; } } @@ -306,7 +318,7 @@ fn a_natural_expiry_fires_nothing() { assert_eq!(rig.frame(), FLUSH); assert!(rig.cooldown(1).1 > 0.0, "running"); - std::thread::sleep(Duration::from_millis(80)); + rig.step_clock(Duration::from_millis(80)); assert!( rig.frame().is_empty(), @@ -518,11 +530,12 @@ fn an_insert_leaves_the_pets_list_its_live_records_alone() { rig.press(1); } let_the_gcds_run_out(); - assert!(rig.elapsed_pending(), "the forty GCDs have run out"); + let pressed = Instant::now(); + assert!(rig.elapsed_pending(pressed), "the forty GCDs have run out"); rig.press(1); - assert!(!rig.elapsed_pending(), "the insert dropped them"); + assert!(!rig.elapsed_pending(pressed), "the insert dropped them"); assert_eq!( rig.record_count(), 3, @@ -553,7 +566,8 @@ fn an_inserts_prune_fires_only_the_inserts_own_flush() { assert_eq!(rig.frame(), FLUSH, "the presses' own flush"); let held = rig.generation(); let_the_gcds_run_out(); - assert!(rig.elapsed_pending()); + let pressed = Instant::now(); + assert!(rig.elapsed_pending(pressed)); // Growl has no GCD pair: nothing is armed, so nothing is dropped or flushed. rig.press(2); @@ -564,7 +578,7 @@ fn an_inserts_prune_fires_only_the_inserts_own_flush() { assert_eq!(rig.generation(), held); rig.press(1); - assert!(!rig.elapsed_pending(), "the insert dropped the five"); + assert!(!rig.elapsed_pending(pressed), "the insert dropped the five"); assert_eq!(rig.frame(), FLUSH, "the insert's flush, once"); assert_eq!( rig.generation(), @@ -601,10 +615,11 @@ fn an_insert_changes_no_bar_read_of_the_records_that_stay() { "the parked record shows disabled: {parked_read:?}" ); let_the_gcds_run_out(); - assert!(rig.elapsed_pending()); + let pressed = Instant::now(); + assert!(rig.elapsed_pending(pressed)); rig.press(1); - assert!(!rig.elapsed_pending(), "the insert pruned"); + assert!(!rig.elapsed_pending(pressed), "the insert pruned"); rig.frame(); assert_eq!( diff --git a/crates/benilla-app/src/ui_pet_book.rs b/crates/benilla-app/src/ui_pet_book.rs index f9e38570c..bdf0f5113 100644 --- a/crates/benilla-app/src/ui_pet_book.rs +++ b/crates/benilla-app/src/ui_pet_book.rs @@ -67,7 +67,7 @@ pub(crate) fn feed_pet_book( let Some(spells) = spells.as_deref() else { return; }; - let now = Instant::now(); + // Every read takes the frame's anchor, the instant its starts project from. let (anchor, ui_now) = (clock.anchor, clock.ui_now); let pet_store = index .0 @@ -97,7 +97,7 @@ pub(crate) fn feed_pet_book( } fresh .slots - .push(slot_view(entry, d, &bar, pet_store, now, anchor, ui_now)); + .push(slot_view(entry, d, &bar, pet_store, anchor, ui_now)); } // `0x4b2fd0`'s re-sort, with the player book's own comparator. fresh.slots.sort_by_key(|s| { @@ -139,7 +139,6 @@ fn slot_view( d: &SpellDisplay, bar: &PetBar, pet_store: Option<&ObjectStore>, - now: Instant, anchor: Instant, ui_now: f64, ) -> SpellSlotView { @@ -157,7 +156,7 @@ fn slot_view( // The pet's own cooldown store, the one `GetPetActionCooldown` reads. cooldown: bar .cooldowns - .info(spell_id, 0, Some(d), now) + .info(spell_id, 0, Some(d), anchor) .ui_triple(anchor, ui_now), // Off the raw word; `0x4bdd65` also requires a `Spell.dbc` record, which every slot has. autocast: Some((entry.autocast_allowed(), entry.autocast_on())), diff --git a/crates/benilla-app/src/ui_petition/mod.rs b/crates/benilla-app/src/ui_petition/mod.rs index 3b7669d32..f7e8a3cde 100644 --- a/crates/benilla-app/src/ui_petition/mod.rs +++ b/crates/benilla-app/src/ui_petition/mod.rs @@ -380,7 +380,9 @@ impl Plugin for UiPetitionPlugin { .add_systems( Update, ( - feed::feed_petition.in_set(UiFeed), + feed::feed_petition + .in_set(UiFeed) + .in_set(crate::ui_session::NpcWindowFeed), feed::drain_petition.in_set(crate::ui_script::UiDrain), ), ); diff --git a/crates/benilla-app/src/ui_quest/mod.rs b/crates/benilla-app/src/ui_quest/mod.rs index a1a7629a7..293b6a49c 100644 --- a/crates/benilla-app/src/ui_quest/mod.rs +++ b/crates/benilla-app/src/ui_quest/mod.rs @@ -282,7 +282,9 @@ impl Plugin for UiQuestPlugin { ( // The feed before the input pass and the drain after it, so a click goes out // the same frame. - feed_quest.in_set(UiFeed), + feed_quest + .in_set(UiFeed) + .in_set(crate::ui_session::NpcWindowFeed), drain_quest.in_set(crate::ui_script::UiDrain), ), ); diff --git a/crates/benilla-app/src/ui_session.rs b/crates/benilla-app/src/ui_session.rs index 777ec4ad1..2b9c93032 100644 --- a/crates/benilla-app/src/ui_session.rs +++ b/crates/benilla-app/src/ui_session.rs @@ -33,6 +33,7 @@ pub(crate) struct UiSessionPlugin; impl Plugin for UiSessionPlugin { fn build(&self, app: &mut App) { + app.configure_sets(Update, NpcWindowFeed.after(crate::ui_unit::UnitFeed)); app.init_resource::() .add_message::() .init_resource::() @@ -65,6 +66,14 @@ impl Plugin for UiSessionPlugin { } } +/// The feeds of the windows on the latch, each also in [`crate::ui_script::UiFeed`], whose show +/// events the stock handlers answer with `UnitName("npc")` and `SetPortraitTexture(…, "npc")`: +/// after [`crate::ui_unit::UnitFeed`], which seats the token. The reference writes `[0xb4e2d0]` as +/// the packet is handled (`0x4e26fa` → `0x4e1fe9` → `0x4930d0`), before the show it fires +/// (`0x4e27df`), so no show reads it stale. +#[derive(SystemSet, Debug, Clone, Copy, PartialEq, Eq, Hash)] +pub(crate) struct NpcWindowFeed; + /// A question bound to a live NPC with a guid of its own, not the latch: the binder and /// talent-wipe questions and the pet trainer's, as the reference re-runs its interact-range test /// against each one's latched guid. Each registers [`close_npc_session_out_of_range::`] ahead diff --git a/crates/benilla-app/src/ui_stable/mod.rs b/crates/benilla-app/src/ui_stable/mod.rs index 2a12b3e68..bbd1a94ea 100644 --- a/crates/benilla-app/src/ui_stable/mod.rs +++ b/crates/benilla-app/src/ui_stable/mod.rs @@ -38,7 +38,9 @@ impl Plugin for UiStablePlugin { .add_systems( Update, ( - feed_stable.in_set(UiFeed), + feed_stable + .in_set(UiFeed) + .in_set(crate::ui_session::NpcWindowFeed), drain_stable.in_set(crate::ui_script::UiDrain), ), ); diff --git a/crates/benilla-app/src/ui_tabard.rs b/crates/benilla-app/src/ui_tabard.rs index 95ed1c3db..3aaa1e60c 100644 --- a/crates/benilla-app/src/ui_tabard.rs +++ b/crates/benilla-app/src/ui_tabard.rs @@ -348,7 +348,9 @@ impl Plugin for TabardUiPlugin { ( // Moves what the save's call reads, so ahead of every host. reset_on_world_enter.before(crate::vm_pass::VmPass::Start), - feed_tabard.in_set(UiFeed), + feed_tabard + .in_set(UiFeed) + .in_set(crate::ui_session::NpcWindowFeed), drain_tabard.in_set(crate::ui_script::UiDrain), ), ); diff --git a/crates/benilla-app/src/ui_taxi/mod.rs b/crates/benilla-app/src/ui_taxi/mod.rs index 2bfceb9ab..20e15b00e 100644 --- a/crates/benilla-app/src/ui_taxi/mod.rs +++ b/crates/benilla-app/src/ui_taxi/mod.rs @@ -369,6 +369,7 @@ impl Plugin for UiTaxiPlugin { // After the roster publish, whose party slots the master's reaction reads. feed_taxi .in_set(UiFeed) + .in_set(crate::ui_session::NpcWindowFeed) .after(crate::spell::group_relation::publish_group_roster), feed_on_taxi.in_set(UiFeed), drain_taxi.in_set(crate::ui_script::UiDrain), diff --git a/crates/benilla-app/src/ui_trade/mod.rs b/crates/benilla-app/src/ui_trade/mod.rs index d89b409d8..7c68d6f75 100644 --- a/crates/benilla-app/src/ui_trade/mod.rs +++ b/crates/benilla-app/src/ui_trade/mod.rs @@ -621,7 +621,10 @@ impl Plugin for UiTradePlugin { // The feed runs after `UnitFeed`, whose item templates it reads, and before // the input pass, with the drain after it, so each lands the same frame. The // latch's watchdog leashes the partner at 14 yd. - feed_trade.after(crate::ui_unit::UnitFeed).in_set(UiFeed), + feed_trade + .after(crate::ui_unit::UnitFeed) + .in_set(UiFeed) + .in_set(crate::ui_session::NpcWindowFeed), // Ahead of the feed, so an accepted partner shows the frame the window opens. answer_trade_request .after(crate::player::ControlRestore) diff --git a/crates/benilla-app/src/ui_trainer/mod.rs b/crates/benilla-app/src/ui_trainer/mod.rs index 0a05647b1..bf5b2595c 100644 --- a/crates/benilla-app/src/ui_trainer/mod.rs +++ b/crates/benilla-app/src/ui_trainer/mod.rs @@ -178,6 +178,7 @@ impl Plugin for UiTrainerPlugin { feed_trainer .in_set(UiFeed) .in_set(TrainerFeed) + .in_set(crate::ui_session::NpcWindowFeed) .after(crate::ui_unit::UnitFeed), drain_trainer.in_set(crate::ui_script::UiDrain), ), diff --git a/crates/benilla-formats/src/factions.rs b/crates/benilla-formats/src/factions.rs index 5b1ca28b0..13d2129e2 100644 --- a/crates/benilla-formats/src/factions.rs +++ b/crates/benilla-formats/src/factions.rs @@ -91,6 +91,12 @@ impl FactionTemplate { } } +/// The mask bit for a 1-based race or class byte, `dec ecx; shl reg,cl` (`0x4d5512`, `0x52a7dd`): +/// x86 masks the count to five bits, so 0 tests bit 31 and 33 tests bit 0. +fn unit_byte_bit(byte: u8) -> u32 { + 1u32.wrapping_shl(u32::from(byte).wrapping_sub(1)) +} + /// One `Faction.dbc` row's reputation identity: its list slot and the race/class-gated base values /// the reference adds to the wire standing. #[derive(Debug, Clone, Copy)] @@ -115,8 +121,7 @@ impl FactionInfo { /// only in this loop's accept block (`0x4d5555`). Unlike vmangos's `GetIndexFitTo`, a slot /// with both masks zero is rejected (`0x4d550b`), and the last matching slot wins. pub fn slot_for(&self, race: u8, class: u8) -> Option { - let race_mask = 1u32 << (race.max(1) - 1); - let class_mask = 1u32 << (class.max(1) - 1); + let (race_mask, class_mask) = (unit_byte_bit(race), unit_byte_bit(class)); (0..4).rfind(|&i| { let (races, classes) = (self.race_masks[i], self.class_masks[i]); (races != 0 || classes != 0) @@ -142,8 +147,7 @@ impl FactionInfo { /// builder `0x529fe0` takes the first matching slot, not the last, and shows the line unless /// its flags carry `0x4`. A zero race mask matches on the class mask instead. pub fn tooltip_shows_for(&self, race: u8, class: u8) -> bool { - let race_bit = 1u32 << (race.max(1) - 1); - let class_bit = 1u32 << (class.max(1) - 1); + let (race_bit, class_bit) = (unit_byte_bit(race), unit_byte_bit(class)); for i in 0..4 { let race_match = if self.race_masks[i] == 0 { self.class_masks[i] @@ -821,4 +825,30 @@ mod tests { cat.faction_description(529) ); } + + /// The slot pick builds its bits with `dec ecx; shl reg,cl` on the zero-extended unit bytes + /// (`0x4d5512`..`0x4d552d`, and the tooltip's `0x52a7dd`..`0x52a802`): x86 masks the count to + /// five bits, so byte 33 tests bit 0 and byte 0 tests bit 31, and no byte panics. + #[test] + fn slot_bits_mask_the_shift_count_like_shl() { + let info = FactionInfo { + rep_index: 0, + team: 0, + race_masks: [1, 1 << 31, 0, 0], + class_masks: [1, 1 << 31, 0, 0], + base: [100, 200, 0, 0], + flags: [0, 0x4, 0, 0], + }; + assert_eq!(info.slot_for(1, 1), Some(0)); + assert_eq!(info.slot_for(33, 33), Some(0), "count 32 masks to bit 0"); + assert_eq!(info.slot_for(32, 32), Some(1)); + assert_eq!(info.slot_for(0, 0), Some(1), "count -1 masks to bit 31"); + assert_eq!(info.slot_for(34, 1), None, "bit 1 is in no race mask"); + assert_eq!(info.slot_for(255, 255), None, "count 254 masks to bit 30"); + assert_eq!(info.base_for(33, 33), 100); + assert!(info.tooltip_shows_for(33, 33)); + assert!(!info.tooltip_shows_for(32, 32), "slot 1 hides the line"); + assert!(!info.tooltip_shows_for(0, 0), "and so does byte 0's bit 31"); + assert!(!info.tooltip_shows_for(255, 255)); + } } diff --git a/crates/benilla-formats/src/spells/display.rs b/crates/benilla-formats/src/spells/display.rs index 97fabf0b1..cc90b5da0 100644 --- a/crates/benilla-formats/src/spells/display.rs +++ b/crates/benilla-formats/src/spells/display.rs @@ -434,7 +434,7 @@ impl SpellDisplay { } /// `AttributesEx & 0x80000`: the caster is never a bind candidate, not in `BindTarget` - /// (`0x6e5b40` at `6e5bf7`), not for `SpellCanTargetUnit`'s unit leg (`0x6e6460` at `6e6507`) + /// (`0x6e5b40` at `6e5bf7`), not for `SpellCanTargetObject`'s unit leg (`0x6e6460` at `6e6507`) /// and not for the world pick (`0x6e61a0` at `6e61cf`). pub fn excludes_caster(&self) -> bool { self.attributes_ex & ATTR_EX_EXCLUDE_CASTER != 0 diff --git a/crates/benilla-formats/src/spells/mod.rs b/crates/benilla-formats/src/spells/mod.rs index daa1e930a..73ed3ed8c 100644 --- a/crates/benilla-formats/src/spells/mod.rs +++ b/crates/benilla-formats/src/spells/mod.rs @@ -85,7 +85,7 @@ const COL_SPELL_FAMILY_FLAGS_LOW: usize = 161; /// `Targets` (`+0x34`): the seed the cast arm loads into its targeting word (`0x6e525a`). const COL_TARGETS: usize = 13; /// `TargetCreatureType` (`+0x38`): the creature-type mask `BindTarget` (`0x6e5c26`) and -/// `SpellCanTargetUnit`'s mirror (`0x6e6544`) test the unit's type against, bit `type - 1`. +/// `SpellCanTargetObject`'s mirror (`0x6e6544`) test the unit's type against, bit `type - 1`. const COL_TARGET_CREATURE_TYPE: usize = 14; /// `EffectImplicitTargetA[0]` (`+0x148`), the key of the cast arm's 62-case switch (`0x6e5484`). const COL_IMPLICIT_TARGET_A1: usize = 82; diff --git a/docs/DEVIATIONS.md b/docs/DEVIATIONS.md index aa914dc3e..bab333e66 100644 --- a/docs/DEVIATIONS.md +++ b/docs/DEVIATIONS.md @@ -345,7 +345,7 @@ Each entry is the first sentence of a `Deviation:` comment, linking to where it #### ui_gossip -- 14 (a NULL, pushed as `nil`) and 15 up (a read past the table's end) give `"gossip"`, because the reference's behaviour there is a missing bounds check. ([`src/ui_gossip/mod.rs:228`](../crates/benilla-app/src/ui_gossip/mod.rs#L228)) +- 14 (a NULL, pushed as `nil`) and 15 up (a read past the table's end) give `"gossip"`, because the reference's behaviour there is a missing bounds check. ([`src/ui_gossip/mod.rs:230`](../crates/benilla-app/src/ui_gossip/mod.rs#L230)) #### ui_guild