Part of #41: the last of five `benilla-app` pieces. This one is everything the others did not cover: the addon harness, the settings registry, the glue screens (login, realm list, character select and create), key bindings, the minimap, nameplates, the loading screen, transports, the performance instruments, the smaller modules, the integration tests, and the UI asset files (`OptionsFrame.xml`, `benilla.toc` and the rest). Their comments are rewritten to the rule in `docs/METHOD.md`, which is what the code does and the reference fact behind it, in a line. 27,351 comment lines become 11,010. Fixes #33. Fixes #103. - **The mechanical strip.** The citations that were only a private record number go first, and each edit is shown to be a pure removal. - **Wrong facts corrected.** The rewrite corrects the comments that stated wrong facts. Among them: - The weapon trail's emissive is 0 (`0x70ca30`): the trail is a type-5 render record, so its ambient-only light term is exact. - The camera-style dropdown writes "1", "2", "0" (`UIOptionsFrame.lua:525,536,547`); several register-site addresses in the settings table are corrected. - The graphics settings are held until `RestartGx`, as in 1.12; `Fonts.xml`'s early load no longer carries a false reason. - vmangos sends a player-name invalidation after a rename (`CharacterHandler.cpp:839`), and the cinematic camera's announce packet has an empty handler there (`MiscHandler.cpp:919`). - Stock FrameXML and GlueXML line citations are checked against the stock 1.12 files, and vmangos line citations against the pinned revision. - **Deviation labels.** "Deviation:" now marks only a choice with its recorded reason. Declining to copy a reference defect is stated plainly, and so is an unbuilt behaviour or an untraced one. - **Verification.** Every file strips to identical code, apart from test literals in `login/`, `death/` and `ui_script/death_tests.rs` that now use placeholder account and character names, and `cargo fmt --check` is clean. Six second readers compared every file old against new, restored the facts the rewrite had dropped, and checked each new citation against the code, the stock files, vmangos and the reference. A second commit corrects one comment in `benilla-ui` (`unit_is_grey`: the reference's exclusion is players only). A third lowers `ui_script_wall`'s ceiling from 45 to 40: five gameplay files named `UiScript` only in comments the rewrite removed, and the ratchet asks for the number to follow. Behaviour differences the rewrite surfaced are filed as their own issues (#339 to #353 among them). String literals are untouched; they are #92. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
102 lines
4.1 KiB
Rust
102 lines
4.1 KiB
Rust
//! The world-state table, the server's key/value scoreboard from `SMSG_INIT_WORLD_STATES` and
|
|
//! `SMSG_UPDATE_WORLD_STATE`. Read by the NPC-text `$<n>w`/`$<n>e` tokens ([`crate::npc_text`])
|
|
//! and by the world map's landmark pass ([`crate::ui_world_map`]), where an `AreaPOI.dbc` row with
|
|
//! a `WorldStateID` shows only while that state is nonzero.
|
|
//!
|
|
//! The reference keeps an open hash keyed by the raw wire dword (`[0xb71ec8]`, bucket
|
|
//! `mask & key`, value at node `+0x18`); keys stay raw because `$<n>e` reads the negated key
|
|
//! (`$2077e` looks up `0xFFFFF7E3`).
|
|
//!
|
|
//! An init first runs `0x4c5650(ecx = map, edx = area)`: it frees every entry, stores the pair as
|
|
//! the display filter `[0xb71e84]`/`[0xb71ea8]` ([`WorldStates::scope`]) and rebuilds the
|
|
//! world-state UI list, and only then are the packet's pairs applied. The filter is the server's
|
|
//! last init, never the avatar's position; only this clear and the logout reset write it.
|
|
|
|
use std::collections::HashMap;
|
|
|
|
use bevy::prelude::*;
|
|
|
|
/// The live world-state table, keyed and valued by raw wire dwords.
|
|
#[derive(Resource, Default)]
|
|
pub(crate) struct WorldStates {
|
|
values: HashMap<u32, u32>,
|
|
generation: u64,
|
|
scope: Option<(u32, u32)>,
|
|
}
|
|
|
|
impl WorldStates {
|
|
/// Bumped per write and per init, not per pair, the edge readers rebuild on: the reference's
|
|
/// handler re-runs the world-map landmark builder once per packet (`0x48fa0d` to `0x4a67a0`).
|
|
pub(crate) fn generation(&self) -> u64 {
|
|
self.generation
|
|
}
|
|
|
|
/// The reference's getter (`0x4c5810`): a missing key reads 0 (`0x4c5867`). Signed, as the
|
|
/// reference prints it through `"%d"`.
|
|
pub(crate) fn get(&self, key: u32) -> i32 {
|
|
self.values.get(&key).copied().unwrap_or(0) as i32
|
|
}
|
|
|
|
/// Every pair, unordered, for instruments only (`capture::ProbeBgPlugin`); the reference
|
|
/// never enumerates the table.
|
|
pub(crate) fn pairs(&self) -> impl Iterator<Item = (u32, i32)> + '_ {
|
|
self.values.iter().map(|(&k, &v)| (k, v as i32))
|
|
}
|
|
|
|
/// The `(map, area)` of the last init, `[0xb71e84]`/`[0xb71ea8]`; `None` before any init, the
|
|
/// reference's `-1`.
|
|
pub(crate) fn scope(&self) -> Option<(u32, u32)> {
|
|
self.scope
|
|
}
|
|
|
|
/// An init's leading half (`0x4c5650`): drops every entry, then records the filter. The caller
|
|
/// applies the pairs after.
|
|
pub(crate) fn init_scope(&mut self, map: u32, area: u32) {
|
|
self.values.clear();
|
|
self.scope = Some((map, area));
|
|
self.generation = self.generation.wrapping_add(1);
|
|
}
|
|
|
|
/// Writes `(id, value)` pairs, the reference's setter (`0x4c5870`) for both opcodes. Init's
|
|
/// trailing `(0, 0)` is written as data; a zero value is stored, not deleted (`edx` is never
|
|
/// tested in `[0x4c5870, 0x4c5a31)`); a repeated key overwrites in place (`0x4c58bb`).
|
|
pub(crate) fn write(&mut self, states: &[(u32, u32)]) {
|
|
self.values.extend(states.iter().copied());
|
|
self.generation = self.generation.wrapping_add(1);
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn a_miss_reads_zero_and_a_value_keeps_its_sign() {
|
|
let mut table = WorldStates::default();
|
|
assert_eq!(table.get(2077), 0, "empty table — the reference's `\"0\"`");
|
|
table.write(&[(2077, 7), (2264, 0xFFFF_FFFF)]);
|
|
assert_eq!(table.get(2077), 7);
|
|
assert_eq!(table.get(2264), -1, "printed through `%d`");
|
|
assert_eq!(table.get(9999), 0, "still a miss");
|
|
}
|
|
|
|
#[test]
|
|
fn the_negated_key_is_a_separate_entry() {
|
|
let mut table = WorldStates::default();
|
|
table.write(&[(2077, 7)]);
|
|
assert_eq!(table.get(2077u32.wrapping_neg()), 0);
|
|
table.write(&[(2077u32.wrapping_neg(), 42)]);
|
|
assert_eq!(table.get(2077u32.wrapping_neg()), 42);
|
|
assert_eq!(table.get(2077), 7, "the positive key is untouched");
|
|
}
|
|
|
|
#[test]
|
|
fn a_write_replaces_and_the_terminator_is_just_data() {
|
|
let mut table = WorldStates::default();
|
|
table.write(&[(2264, 1), (0, 0)]);
|
|
table.write(&[(2264, 5)]);
|
|
assert_eq!(table.get(2264), 5);
|
|
assert_eq!(table.get(0), 0);
|
|
}
|
|
}
|