`cargo fmt --all -- --check` has failed on every run in this repository's history, identically on `main` and on every branch. This is #12. Mechanical: `cargo fmt --all`, nothing else. 154 files, all `.rs`, no other extension touched. `cargo check --workspace` exits 0 afterwards, so nothing changed semantically. ON THE ORDERING, WHICH WAS THE REAL QUESTION. HANDOFF-2026-09-06 section 7 warns this is the expensive fix: a whole-tree reformat before #7 and #8 return "would put a conflict in every file of 861 commits and make the reviews those items exist to enable unreadable". That is measurably too pessimistic, and it had been reasoned rather than tested. Measured here by three-way merging a rustfmt'd `main` against both unmerged branches, file by file: file/branch pairs tested 32 merges CLEAN 28 merges CONFLICTING 4 (8 conflict hunks total) sylpheed-cli/src/main.rs 1 hunk sylpheed-export/src/check.rs 1 sylpheed-export/src/screen.rs 4 sylpheed-export/src/video.rs 2 All four are against `auto/frame-blend-draw-path` only; `auto/port-p6-audio` does not conflict anywhere. The earlier framing -- 154 dirty files, 133 that cannot collide, 21 that can, the collision set carrying 147 of 774 hunks (19%) -- reproduces exactly. What it did not say is that most of the 21 still merge cleanly, because rustfmt's edits and the branches' edits rarely land on the same lines. So the cost of sweeping now is 4 files and 8 hunks for one branch, against a check that is otherwise red forever. Deliberately NOT folded into the WASM PR: 154 reformatted files would make that one unreviewable. Closes #12
103 lines
3.8 KiB
Rust
103 lines
3.8 KiB
Rust
//! Where does each declared field sit inside the engine's live definition object?
|
||
//!
|
||
//! A live object carries no names, so the mapping has to be inferred: take a unit
|
||
//! whose disc record SETS a field, look for that value in the dumped words of the
|
||
//! matching live object, and keep the offsets that agree across several units.
|
||
//!
|
||
//! Run: live_offsets <disc-root> <live-dump.txt> <ID=0xVA> ...
|
||
//! e.g. … UN_f106_TCAF_Destroyer=0xbd3ee300 UN_f105_TCAF_Cruiser=0xbd40e200
|
||
use std::collections::BTreeMap;
|
||
use sylpheed_formats::idxd::IdxdObject;
|
||
use sylpheed_formats::pak::PakArchive;
|
||
|
||
fn main() {
|
||
let mut a = std::env::args().skip(1);
|
||
let disc = a.next().expect("disc root");
|
||
let dump = a.next().expect("live dump");
|
||
let pairs: Vec<(String, String)> = a
|
||
.filter_map(|s| {
|
||
s.split_once('=')
|
||
.map(|(i, v)| (i.to_string(), v.to_string()))
|
||
})
|
||
.collect();
|
||
|
||
// live: va -> offset -> f32
|
||
let mut live: BTreeMap<String, BTreeMap<usize, f32>> = BTreeMap::new();
|
||
let mut cur = String::new();
|
||
for line in std::fs::read_to_string(&dump).expect("dump").lines() {
|
||
if let Some(rest) = line.strip_prefix("=== ") {
|
||
cur = rest.trim().to_string();
|
||
continue;
|
||
}
|
||
let f: Vec<&str> = line.split_whitespace().collect();
|
||
if f.len() >= 4 && f[1].starts_with('+') {
|
||
if let (Ok(off), Ok(val)) = (usize::from_str_radix(&f[1][1..], 16), f[3].parse::<f32>())
|
||
{
|
||
live.entry(cur.clone()).or_default().insert(off, val);
|
||
}
|
||
}
|
||
}
|
||
|
||
let pak = PakArchive::open(format!("{disc}/dat/GP_MAIN_GAME_E.pak")).expect("pak");
|
||
// key -> offset -> how many units agree
|
||
let mut votes: BTreeMap<String, BTreeMap<usize, usize>> = BTreeMap::new();
|
||
let mut units = 0usize;
|
||
for entry in pak.entries() {
|
||
let Ok(bytes) = pak.read(entry) else { continue };
|
||
let Ok(obj) = IdxdObject::parse(&bytes) else {
|
||
continue;
|
||
};
|
||
let Some(id) = obj.get_raw("ID") else {
|
||
continue;
|
||
};
|
||
let Some((_, va)) = pairs.iter().find(|(i, _)| i == id) else {
|
||
continue;
|
||
};
|
||
let Some(words) = live.get(va) else { continue };
|
||
units += 1;
|
||
let mut numeric = 0usize;
|
||
let mut hit = 0usize;
|
||
for key in obj.tokens() {
|
||
let Some(v) = obj.get_f32(key) else { continue };
|
||
if !v.is_finite() || v == 0.0 {
|
||
continue; // zero matches everywhere and says nothing
|
||
}
|
||
numeric += 1;
|
||
let mut found = false;
|
||
for (off, w) in words {
|
||
if (*w - v).abs() <= v.abs() * 1e-6 {
|
||
*votes
|
||
.entry(key.clone())
|
||
.or_default()
|
||
.entry(*off)
|
||
.or_default() += 1;
|
||
found = true;
|
||
}
|
||
}
|
||
if found {
|
||
hit += 1;
|
||
}
|
||
}
|
||
eprintln!(" {id}: {numeric} numeric fields set on disc, {hit} found in the dumped window");
|
||
}
|
||
println!("{units} units correlated against their live objects\n");
|
||
println!("{:<28} {:>8} offsets agreeing (votes)", "field", "unique?");
|
||
for (key, offs) in &votes {
|
||
let best = offs.iter().max_by_key(|(_, n)| **n).unwrap();
|
||
if *best.1 < units.max(2) {
|
||
continue; // needs every correlated unit to agree
|
||
}
|
||
let list: Vec<String> = offs
|
||
.iter()
|
||
.filter(|(_, n)| **n == *best.1)
|
||
.map(|(o, n)| format!("+{o:03x}×{n}"))
|
||
.collect();
|
||
println!(
|
||
"{:<28} {:>8} {}",
|
||
key,
|
||
if list.len() == 1 { "unique" } else { "ambig" },
|
||
list.join(" ")
|
||
);
|
||
}
|
||
}
|