Files
benilla-octo/crates/benilla-ui/src/script/bind_confirm.rs
T
gromandClaude Opus 5 81d96af35d Everwood: the HD/OctoWoW line of benilla, imported onto upstream
This checkout had no git history at all, so this one commit carries the whole
of the Everwood work as a single import on top of chairmanpow/benilla-octo's
`main` (706cd71). The two trees have genuinely diverged — each has files the
other does not — so this is a fork point, not a catch-up.

Today's work, which is the reason a baseline exists at all:

- Booth previews no longer cast world shadows (`NO_BOOTH_SHADOW`). Portrait
  characters were entering the sun's shadow cascades, so every skinned-rig
  shadow specialization compiled live mid-frame; the hitch detector logged
  "main thread blocked 1316 ms" beside a `compiled LIVE` warning. This was
  the Fashion/Tmog stutter.
- Per-pane dress-up: each `DressUpModel` pane assembles and stages its own
  tried-on look instead of every pane mirroring the live player.
- Item template cache is append-only JSONL written on the IO pool, replacing
  an 11.6 MB whole-map JSON rewrite on the main thread every 10 s.
- `WOW_SYSTEM_TIMING` rebuilt per-thread: it took 2 mutexes per system enter
  and 4 per exit, costing 15 ms a frame (590 fps -> 60) and corrupting the
  measurements it was taken to produce.
- The visibility-churn sweep moved to its own `WOW_FLASH_CHURN` switch, so a
  frame-cost reading no longer pays 2.7 ms a frame for it.

Local state (`benilla-config/`, `logs/`, `target/`) is excluded by the
existing .gitignore; the account credential it holds is not in this commit.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SgstFWtn1RxEJ5kVrpgYwn
2026-10-15 15:01:14 -06:00

115 lines
4.2 KiB
Rust

//! The soulbind confirmations other than loot's: `EQUIP_BIND`, `AUTOEQUIP_BIND` and `USE_BIND`.
//! They are client-local: the client reads the cached template's bonding and defers its own send,
//! and an accept re-issues that action with a suppress flag, as 1.12 has no confirm packet. The
//! app owns the pending records; this module holds only the intents.
use mlua::Lua;
use super::Model;
/// One answer to a pending-equip question.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct PendingEquipAnswer {
/// The event's `arg1`, not a slot: a 0-based index into the reference's pending-equip array
/// (`0xc4c298`, stride `0x20`), kept untranslated because Lua only hands it back.
pub index: u32,
/// Accept re-issues the action; cancel sends nothing and only releases the item locks
/// (`0x495420`).
pub accept: bool,
}
impl super::UiScript {
/// The equip answers in call order. The app ignores an index it holds no record for, as the
/// reference's `0x5e1be0` bounds-checks it and returns.
pub fn take_pending_equip_answers(&mut self) -> Vec<PendingEquipAnswer> {
std::mem::take(&mut self.model_mut().pending_equip_answers)
}
/// `ConfirmBindOnUse()` calls since the last drain.
pub fn take_bind_on_use_confirms(&mut self) -> u32 {
std::mem::take(&mut self.model_mut().bind_on_use_confirms)
}
/// The client's item-usable predicate (`0x5ea930`), which the app's equip deferral asks: an
/// item the player cannot equip is never asked about. Entry `0` and an unanswered template
/// read usable.
pub fn item_usable(&self, item_id: u32) -> bool {
super::item_stats::item_usable_by_id(&self.model_ref(), item_id)
}
}
pub(super) fn install(lua: &Lua) -> mlua::Result<()> {
let g = lua.globals();
// `0x4898f0`, the `OnAccept` of `EQUIP_BIND` and `AUTOEQUIP_BIND` (`StaticPopup.lua:612-647`).
g.set(
"EquipPendingItem",
lua.create_function(|lua, index: u32| {
let mut model = lua.app_data_mut::<Model>().expect("model app_data");
model.pending_equip_answers.push(PendingEquipAnswer {
index,
accept: true,
});
Ok(())
})?,
)?;
// `0x489960`, their `OnCancel` and also their `OnHide`: a second bind question hides the
// standing dialog (`exclusive = 1`), and that cancel releases the superseded item's locks.
g.set(
"CancelPendingEquip",
lua.create_function(|lua, index: u32| {
let mut model = lua.app_data_mut::<Model>().expect("model app_data");
model.pending_equip_answers.push(PendingEquipAnswer {
index,
accept: false,
});
Ok(())
})?,
)?;
// `0x48d770`, `USE_BIND`'s `OnAccept`, with no argument and no cancel: the use arm's pending
// state is two globals (item `0xc4c240`, target `0xc4c1d0`), and declining drops it.
g.set(
"ConfirmBindOnUse",
lua.create_function(|lua, ()| {
let mut model = lua.app_data_mut::<Model>().expect("model app_data");
model.bind_on_use_confirms += 1;
Ok(())
})?,
)?;
Ok(())
}
#[cfg(test)]
mod tests {
use crate::script::UiScript;
/// Order matters: a supersede is a cancel of one record arriving between two others.
#[test]
fn the_equip_answers_queue_in_call_order_with_their_verdicts() {
let mut s = UiScript::new().unwrap();
s.run("EquipPendingItem(0) CancelPendingEquip(1) EquipPendingItem(2)")
.unwrap();
let answers = s.take_pending_equip_answers();
assert_eq!(
answers
.iter()
.map(|a| (a.index, a.accept))
.collect::<Vec<_>>(),
vec![(0, true), (1, false), (2, true)]
);
assert!(s.take_pending_equip_answers().is_empty(), "drained");
}
#[test]
fn confirm_bind_on_use_counts() {
let mut s = UiScript::new().unwrap();
assert_eq!(s.take_bind_on_use_confirms(), 0);
s.run("ConfirmBindOnUse() ConfirmBindOnUse()").unwrap();
assert_eq!(s.take_bind_on_use_confirms(), 2);
assert_eq!(s.take_bind_on_use_confirms(), 0, "drained");
}
}