Files
benilla-octo/crates/benilla-formats/src/gameobjects.rs
T
Sam SungandClaude Opus 5.5 8505187668 Comments in benilla-formats: one line of fact each, no history, no record numbers (#130)
Part of #41: the comments of `benilla-formats` (the library, its extract tools, examples and tests) are rewritten to the rule in `docs/METHOD.md`, which is what the code does and the reference fact behind it, in a line. 19,654 comment lines become 7,264.

Fixes #105: the WMO collision comments now name walking's box-query leaf `0x6bca50` and the camera and line-of-sight segment-query leaf `0x6bc700`, in `models/collision.rs`, `examples/wmo_bsp.rs` and `tests/chain.rs`.

- **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:
  - A placed doodad's material alpha reads file slot 0 on its spawn clock, while the reference reads bone 0's armed sequence, re-rolled every play window. The old text said doodads are armed once at load.
  - The fog end is stored ×36 and scaled once at load (`0x6d6090`). It is not raw.
  - The MCSH bit picks a map doodad's sun scale, 1.0 lit or 0.5 shadowed. 2.5 belongs to an entity's light node.
  - `SpellRec` is the row as stored, column × 4, not a translated copy.
  - A global sequence's clock is anchored at the instance's attach time (`0x714352`).
  - Particle twinkle is a gated size multiplier (`0x7b2adc`).
  - The blob shadow sizes from the Stand box.
  - Data claims are checked against the install: the weapon-trail kits' parameters and alphas, the beam rows' noise, and the maps' `field_16`.
  - Dozens more turned up on the way: renamed or deleted items, docs sitting on the wrong item, stale counts and links.
- **Deviation labels.** "Deviation:" now marks only a choice with a reason. An unbuilt behaviour says so plainly.
- **Verification.** Every file strips to identical code, and `cargo fmt --check` is clean. Four second readers compared every file old against new, restored the facts the rewrite had dropped, and checked each new citation against the reference, the code and the shipped data.

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>
2026-09-24 19:38:53 +07:00

109 lines
3.4 KiB
Rust

//! `GameObjectDisplayInfo.dbc`: a game object's `GAMEOBJECT_DISPLAYID` → a direct model path,
//! with no model-data indirection or skins; mostly `.mdx`/`.mdl`, a few `.wmo`.
use std::collections::HashMap;
use crate::Chain;
use anyhow::{Context, Result};
use benilla_dbc::{FieldType, Schema, SchemaField};
use crate::dbc::{parse, str_at, u32_at};
const GAMEOBJECT_DISPLAY_INFO: &str = "DBFilesClient\\GameObjectDisplayInfo.dbc";
/// `displayId → model path` from GameObjectDisplayInfo.dbc.
pub struct GameObjectCatalog {
models: HashMap<u32, String>,
}
impl GameObjectCatalog {
pub fn model_path(&self, display_id: u32) -> Option<&str> {
self.models.get(&display_id).map(String::as_str)
}
pub fn len(&self) -> usize {
self.models.len()
}
pub fn is_empty(&self) -> bool {
self.models.is_empty()
}
/// Every `(displayId, model path)` pair, in no order.
pub fn iter(&self) -> impl Iterator<Item = (u32, &str)> {
self.models.iter().map(|(&id, p)| (id, p.as_str()))
}
}
fn schema() -> Schema {
let mut s = Schema::new("GameObjectDisplayInfo");
s.add_field(SchemaField::new("ID", FieldType::UInt32));
s.add_field(SchemaField::new("ModelName", FieldType::String));
for i in 0..10 {
s.add_field(SchemaField::new(format!("Sound{i}"), FieldType::UInt32));
}
s
}
/// Load GameObjectDisplayInfo.dbc from the patch chain into a [`GameObjectCatalog`].
pub fn load_gameobject_catalog(chain: &mut Chain) -> Result<GameObjectCatalog> {
let bytes = chain
.read_file(GAMEOBJECT_DISPLAY_INFO)
.with_context(|| format!("reading {GAMEOBJECT_DISPLAY_INFO}"))?;
let rs = parse(&bytes, schema(), "GameObjectDisplayInfo")?;
let mut models = HashMap::with_capacity(rs.records().len());
for r in rs.records() {
if let (Some(id), Some(path)) = (u32_at(r, 0), str_at(&rs, r, 1)) {
models.insert(id, path);
}
}
Ok(GameObjectCatalog { models })
}
/// Each display's ten `SoundEntries` slots (columns 2-11): 0 stand, 1 open, 2 loop, 3 close,
/// 4 destroy, 5 opened, 6-9 custom. Only displays with a nonzero slot are kept.
pub struct GameObjectSounds {
sounds: HashMap<u32, [u32; 10]>,
}
/// `Sound[10]` slot indices, named as wowdev documents them.
pub mod go_sound_slot {
pub const OPEN: usize = 1;
pub const CLOSE: usize = 3;
}
impl GameObjectSounds {
/// A display's ten slots; `None` when every slot is zero.
pub fn slots(&self, display_id: u32) -> Option<&[u32; 10]> {
self.sounds.get(&display_id)
}
pub fn len(&self) -> usize {
self.sounds.len()
}
pub fn is_empty(&self) -> bool {
self.sounds.is_empty()
}
}
/// Load the sound slots off GameObjectDisplayInfo.dbc.
pub fn load_gameobject_sounds(chain: &mut Chain) -> Result<GameObjectSounds> {
let bytes = chain
.read_file(GAMEOBJECT_DISPLAY_INFO)
.with_context(|| format!("reading {GAMEOBJECT_DISPLAY_INFO}"))?;
let rs = parse(&bytes, schema(), "GameObjectDisplayInfo")?;
let mut sounds = HashMap::new();
for r in rs.records() {
let Some(id) = u32_at(r, 0) else { continue };
let mut slots = [0u32; 10];
for (i, slot) in slots.iter_mut().enumerate() {
*slot = u32_at(r, 2 + i).unwrap_or(0);
}
if slots.iter().any(|&s| s != 0) {
sounds.insert(id, slots);
}
}
Ok(GameObjectSounds { sounds })
}