From 0a0dec390901f7b2466f39f1aca03ecac4e8d552 Mon Sep 17 00:00:00 2001 From: asm512 <31016869+asm512@users.noreply.github.com> Date: Sun, 22 Nov 2026 20:36:13 +0000 Subject: [PATCH] psin: typed XML view with in-place edits, hashed-name recovery - PSIN files are shown and exported as XML with typed values; edited values are patched into a same-size copy - name table for hashed struct, field and enum names: built-in list, word lists and name tables in the names folder, names recovered from the open archives - schema names are joaat without lower-casing, which is why they did not resolve before - recovery combines known words and measures chance matches with decoy hashes; built names are marked with ? Recovered names and method: https://asm512.github.io/gta6-name-recovery/ Source: https://github.com/asm512/gta6-name-recovery --- src/main.rs | 237 +++++++++++- src/names.rs | 959 ++++++++++++++++++++++++++++++++++++++++++++++++ src/psin.rs | 14 +- src/psin_xml.rs | 926 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 2132 insertions(+), 4 deletions(-) create mode 100644 src/names.rs create mode 100644 src/psin_xml.rs diff --git a/src/main.rs b/src/main.rs index 6ef3181..e1661fe 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,7 +8,9 @@ mod dat; mod dxbc; mod mapdata; mod meta7a; +mod names; mod psin; +mod psin_xml; mod rsc9; mod sgd5; mod world_gpu; @@ -852,6 +854,8 @@ struct Rpf9App { // camera yaw pitch zoom pan carried across a lod switch lod_keep_cam: Option<[f32; 5]>, export_busy: Arc, + // the entry on screen is a psin file shown as xml + psin_selected: bool, export_cancel: Arc, mv_drawer_open: bool, mv_entries: Vec<(usize, ModelCat, String)>, @@ -1044,6 +1048,7 @@ impl Rpf9App { tex_from_model: false, lod_keep_cam: None, export_busy: Arc::new(AtomicBool::new(false)), + psin_selected: false, export_cancel: Arc::new(AtomicBool::new(false)), mv_drawer_open: true, mv_entries: Vec::new(), @@ -1075,6 +1080,10 @@ impl Rpf9App { sgd5_selected: None, sgd5_cached_text: (None, String::new()), }; + psin::seed_names(); + if let Some(dir) = names_dir() { + names::load_dir(&dir); + } load_ui_state(&mut app); spawn_update_check(Arc::clone(&app.update), cc.egui_ctx.clone()); // a path on the command line (open with, drag onto the exe) wins over the last folder @@ -1151,6 +1160,7 @@ impl Rpf9App { self.tex_pick = false; self.tex_from_model = false; self.lod_keep_cam = None; + self.psin_selected = false; self.preview.clear(); self.last_dock_rect = [0; 4]; self.mesh3d = None; @@ -2316,7 +2326,14 @@ impl Rpf9App { self.preview = format_hex(&data[..data.len().min(2048)]); } } else if e.kind == "PSIN" { - self.preview = psin::parse_psin(&data); + // typed xml when the schema is readable, the plain dump otherwise + match psin_xml::export_xml(&data, PSIN_PREVIEW_CHARS) { + Ok(xml) => { + self.preview = xml; + self.psin_selected = true; + } + Err(_) => self.preview = psin::parse_psin(&data), + } } else if e.kind == "ANIM" { self.preview = anim::parse_anim_dict(&data); let (dur, trk, seed) = anim::extract_anim_summary(&data); @@ -3588,6 +3605,130 @@ impl Rpf9App { } + // export, edit and name tools for the psin file on screen + fn psin_tools_ui(&mut self, ui: &mut egui::Ui) { + let complete = !self.preview.contains(PSIN_CUT_MARK); + ui.horizontal(|ui| { + if ui.button("Export XML…").on_hover_text("Save the whole file as editable XML").clicked() { + self.psin_export_xml(); + } + if ui + .add_enabled(complete, egui::Button::new("Save edits shown here…")) + .on_hover_text("Write the values edited in the text below into a patched copy of the file") + .on_disabled_hover_text("The view is cut short for this file: export the XML, edit it, then use Apply XML file") + .clicked() + { + let xml = self.preview.clone(); + self.psin_apply_xml(xml); + } + if ui.button("Apply XML file…").on_hover_text("Write the values of an edited XML export into a patched copy of the file").clicked() { + if let Some(p) = rfd::FileDialog::new().add_filter("XML", &["xml"]).pick_file() { + match fs::read_to_string(&p) { + Ok(xml) => self.psin_apply_xml(xml), + Err(err) => self.state.lock().unwrap().status = format!("Read error: {err}"), + } + } + } + ui.separator(); + if ui + .button("Recover names") + .on_hover_text("Match the hashed names of every metadata file against words found in the open archives and in the names folder") + .clicked() + { + self.recover_names(); + } + ui.label(RichText::new(format!("{} names known", names::len())).size(11.0).color(Color32::from_rgb(150, 160, 180))); + }); + } + + fn selected_entry(&self) -> Option { + self.selected.and_then(|i| self.state.lock().unwrap().entries.get(i).cloned()) + } + + fn psin_export_xml(&self) { + let Some(e) = self.selected_entry() else { return }; + let stem = safe_file_name(&e.name); + let Some(out) = rfd::FileDialog::new().set_file_name(format!("{stem}.xml")).add_filter("XML", &["xml"]).save_file() else { return }; + let state = Arc::clone(&self.state); + state.lock().unwrap().status = format!("Exporting {} as XML...", e.name); + std::thread::spawn(move || { + let res = read_entry_bytes(&e) + .map_err(|err| err.to_string()) + .and_then(|data| psin_xml::export_xml(&data, 0)) + .and_then(|xml| fs::write(&out, xml).map_err(|err| err.to_string())); + state.lock().unwrap().status = match res { + Ok(()) => format!("Saved {}", out.display()), + Err(err) => format!("XML export failed: {err}"), + }; + }); + } + + // patches a copy of the selected file with the values in the xml and saves it where the user picks + fn psin_apply_xml(&self, xml: String) { + let Some(e) = self.selected_entry() else { return }; + let res = read_entry_bytes(&e).map_err(|err| err.to_string()).and_then(|data| psin_xml::apply_xml(&data, &xml)); + let status = match res { + Err(err) => format!("XML not applied: {err}"), + Ok(done) if done.changes.is_empty() => "The XML has the same values as the file, nothing to save".to_string(), + Ok(done) => { + let name = format!("{}.patched.psin", safe_file_name(e.name.trim_end_matches(".psin"))); + match rfd::FileDialog::new().set_file_name(name).save_file() { + None => "Patched copy not saved".to_string(), + Some(out) => match fs::write(&out, &done.data) { + Ok(()) => format!( + "{} value(s) changed, first: {}. Saved {} (same size as the original, its checksum section is not updated)", + done.changes.len(), + done.changes[0], + out.display() + ), + Err(err) => format!("Write error: {err}"), + }, + } + } + }; + self.state.lock().unwrap().status = status; + } + + // looks for the words behind hashed struct, field and enum names in the open archives + fn recover_names(&self) { + if self.export_busy.swap(true, Ordering::SeqCst) { + return; + } + let busy = Arc::clone(&self.export_busy); + let state = Arc::clone(&self.state); + let entries: Vec = + state.lock().unwrap().entries.iter().filter(|e| matches!(e.kind, "PSIN" | "XML" | "RBF0" | "DAT" | "GFX" | "ZLIB")).cloned().collect(); + std::thread::spawn(move || { + let mut last_note = Instant::now(); + let (targets, tokens) = gather_names(&entries, |n| { + if last_note.elapsed() > Duration::from_millis(200) { + last_note = Instant::now(); + state.lock().unwrap().status = format!("Reading metadata {}/{}...", n + 1, entries.len()); + } + }); + state.lock().unwrap().status = format!("Matching {} words against the hashed names...", tokens.len()); + let found = names::recover(&tokens, &targets); + names::add(found.exact.iter().map(|f| f.1.as_str())); + names::add_built(found.built.iter().map(|f| f.1.as_str())); + let all = targets.all(); + let resolved = all.iter().filter(|h| names::lookup(**h).is_some()).count(); + let note = match names_dir() { + Some(dir) if names::save_list(&dir, names::RECOVERED_FILE, &found.exact).is_ok() && names::save_list(&dir, names::BUILT_FILE, &found.built).is_ok() => { + format!(" Saved in {}; extra word lists (.txt, one name per line) placed there are used too.", dir.display()) + } + _ => String::new(), + }; + state.lock().unwrap().status = format!( + "Names: {resolved} of {} hashed names resolved. {} found written out, {} built from word combinations and shown with a ? (about {:.0} of those are chance matches).{note}", + all.len(), + found.exact.len(), + found.built.len(), + found.built_noise + ); + busy.store(false, Ordering::SeqCst); + }); + } + fn export_entries(&self, indices: &[usize]) { let Some(out_dir) = rfd::FileDialog::new().pick_folder() else { return }; let entries: Vec = { @@ -3702,6 +3843,41 @@ fn spawn_media_job( }); } +// preview length of a psin shown as xml and the comment the exporter leaves when it stops there +const PSIN_PREVIEW_CHARS: usize = 200_000; +const PSIN_CUT_MARK: &str = " +\n", + data.len(), + l.schema, + l.blocks.len() + ); + for i in 0..l.blocks.len() { + if w.full() { + break; + } + w.block(i); + } + if w.cut { + w.out.push_str(" \n"); + } + w.out.push_str("\n"); + Ok(w.out) +} + +fn unesc(s: &str) -> String { + if !s.contains('&') { + return s.to_string(); + } + let mut out = String::with_capacity(s.len()); + let mut rest = s; + while let Some(i) = rest.find('&') { + out.push_str(&rest[..i]); + rest = &rest[i..]; + let Some(end) = rest.find(';') else { break }; + let ent = &rest[1..end]; + match ent { + "amp" => out.push('&'), + "lt" => out.push('<'), + "gt" => out.push('>'), + "quot" => out.push('"'), + "apos" => out.push('\''), + _ => match ent.strip_prefix('#').and_then(|n| n.parse::().ok()).and_then(char::from_u32) { + Some(c) => out.push(c), + None => out.push_str(&rest[..=end]), + }, + } + rest = &rest[end + 1..]; + } + out.push_str(rest); + out +} + +// attributes of the tag that starts at the given text, which ends at the first unquoted > +fn attrs(tag: &str) -> HashMap<&str, String> { + let mut map = HashMap::new(); + let b = tag.as_bytes(); + let mut i = 0; + while i < b.len() && b[i] != b'>' { + if !(b[i].is_ascii_alphabetic()) { + i += 1; + continue; + } + let ks = i; + while i < b.len() && (b[i].is_ascii_alphanumeric() || b[i] == b'_') { + i += 1; + } + let key = &tag[ks..i]; + if b.get(i) != Some(&b'=') || b.get(i + 1) != Some(&b'"') { + continue; + } + let vs = i + 2; + let Some(len) = tag[vs..].find('"') else { break }; + map.insert(key, unesc(&tag[vs..vs + len])); + i = vs + len + 1; + } + map +} + +fn parse_int(s: &str) -> Option { + let s = s.trim(); + let (neg, body) = match s.strip_prefix('-') { + Some(b) => (true, b), + None => (false, s), + }; + let v = match body.strip_prefix("0x").or_else(|| body.strip_prefix("0X")) { + Some(h) => i128::from_str_radix(h, 16).ok()?, + None => body.parse::().ok()?, + }; + Some(if neg { -v } else { v }) +} + +fn parse_f32(s: &str) -> Option { + let s = s.trim(); + match s.strip_prefix("bits:") { + Some(b) => parse_int(b).and_then(|v| u32::try_from(v).ok()).map(f32::from_bits), + None => s.parse::().ok(), + } +} + +// bytes a value of the given xml type is stored as +fn encode(ty: &str, v: &str) -> Result, String> { + let bad = || format!("\"{v}\" is not a valid {ty}"); + let int = |min: i128, max: i128| parse_int(v).filter(|x| (min..=max).contains(x)).ok_or_else(bad); + Ok(match ty { + "bool" => vec![match v.trim() { + "true" | "1" => 1, + "false" | "0" => 0, + _ => return Err(bad()), + }], + "s8" | "enum8" => vec![int(i8::MIN as i128, u8::MAX as i128)? as u8], + "u8" | "flags8" => vec![int(0, u8::MAX as i128)? as u8], + "s16" | "enum16" => (int(i16::MIN as i128, u16::MAX as i128)? as u16).to_le_bytes().to_vec(), + "u16" | "flags16" => (int(0, u16::MAX as i128)? as u16).to_le_bytes().to_vec(), + "s32" | "enum32" => (int(i32::MIN as i128, u32::MAX as i128)? as u32).to_le_bytes().to_vec(), + "u32" | "flags32" => (int(0, u32::MAX as i128)? as u32).to_le_bytes().to_vec(), + "s64" => (int(i64::MIN as i128, u64::MAX as i128)? as u64).to_le_bytes().to_vec(), + "u64" | "hash64" => (int(0, u64::MAX as i128)? as u64).to_le_bytes().to_vec(), + "f32" => parse_f32(v).ok_or_else(bad)?.to_bits().to_le_bytes().to_vec(), + "f16" => match v.trim().strip_prefix("bits:") { + Some(b) => (parse_int(b).filter(|x| (0..=0xffff).contains(x)).ok_or_else(bad)? as u16).to_le_bytes().to_vec(), + None => f32_to_half(v.trim().parse::().map_err(|_| bad())?).to_le_bytes().to_vec(), + }, + // a hash may be given as the name it stands for + "hash" => match parse_int(v) { + Some(x) => u32::try_from(x).map_err(|_| bad())?.to_le_bytes().to_vec(), + None if names::is_name(v.trim()) => joaat(v.trim()).to_le_bytes().to_vec(), + None => return Err(bad()), + }, + _ => { + let n = float_count(ty).ok_or_else(|| format!("type {ty} cannot be edited"))?; + let parts: Vec<&str> = v.split_whitespace().collect(); + if parts.len() != n { + return Err(format!("{ty} needs {n} numbers, got {}", parts.len())); + } + let mut out = Vec::with_capacity(n * 4); + for p in parts { + out.extend_from_slice(&parse_f32(p).ok_or_else(bad)?.to_bits().to_le_bytes()); + } + out + } + }) +} + +pub struct Applied { + pub data: Vec, + // one line per value that differs from the file + pub changes: Vec, +} + +// writes the values of an edited xml into a copy of the file it was exported from +pub fn apply_xml(data: &[u8], xml: &str) -> Result { + let l = layout(data)?; + let root = xml.find(" element found")?; + let head = attrs(&xml[root + 5..]); + let size_ok = head.get("size").and_then(|s| s.parse::().ok()) == Some(data.len()); + let schema_ok = head.get("schema").and_then(|s| parse_int(s)) == Some(l.schema as i128); + if !size_ok || !schema_ok { + return Err("This XML was exported from a different file (size or schema differs)".into()); + } + let (lo, hi) = (l.payload, l.payload + l.payload_len); + let mut out = data.to_vec(); + let mut changes = Vec::new(); + let mut rest = &xml[root..]; + while let Some(i) = rest.find(" hi { + return Err(format!("{label}: offset {o} is outside the data")); + } + if out[pos..pos + bytes.len()] != bytes[..] { + // a bool stored as something other than 0 or 1 reads as true and is left alone + if ty == "bool" && bytes[0] == 1 && out[pos] != 0 { + continue; + } + changes.push(format!("{label} ({ty}) at {o} = {v}")); + out[pos..pos + bytes.len()].copy_from_slice(&bytes); + } + } + Ok(Applied { data: out, changes }) +} + +#[cfg(test)] +mod tests { + use super::*; + + fn section(tag: &[u8; 4], body: &[u8]) -> Vec { + let mut v = tag.to_vec(); + v.extend_from_slice(&((body.len() + 8) as u32).to_be_bytes()); + v.extend_from_slice(body); + v + } + + fn field(name: u32, offset: u32, ty: u32, reference: u32) -> Vec { + [name, offset, ty, reference].iter().flat_map(|v| v.to_le_bytes()).collect() + } + + // one struct holding one of each common value, a second block of floats it points at + fn sample() -> Vec { + let st = joaat("TestThing"); + let mut item = vec![0u8; 64]; + item[8..12].copy_from_slice(&1630.0f32.to_bits().to_le_bytes()); + item[12..16].copy_from_slice(&(-7i32).to_le_bytes()); + item[16..20].copy_from_slice(&joaat("cheetah2").to_le_bytes()); + item[20] = 1; + item[22..24].copy_from_slice(&0x3c00u16.to_le_bytes()); + for (k, v) in [1.0f32, 2.0, 3.0, 0.5].iter().enumerate() { + item[32 + k * 4..36 + k * 4].copy_from_slice(&v.to_bits().to_le_bytes()); + } + // array of two floats in block 1 + item[48..56].copy_from_slice(&2u64.to_le_bytes()); + item[56..58].copy_from_slice(&2u16.to_le_bytes()); + item[58..60].copy_from_slice(&2u16.to_le_bytes()); + let mut floats = Vec::new(); + floats.extend_from_slice(&0.25f32.to_bits().to_le_bytes()); + floats.extend_from_slice(&f32::NAN.to_bits().to_le_bytes()); + + let mut body = Vec::new(); + for (tag, size) in [(st, 64u32), (0x21, 8)] { + body.extend_from_slice(&tag.to_le_bytes()); + body.extend_from_slice(&size.to_le_bytes()); + body.extend_from_slice(&[0xAA; 8]); + } + body.extend_from_slice(b"pppppppp"); + body.extend_from_slice(&item); + body.extend_from_slice(&floats); + body.extend_from_slice(&[0u8; 8]); + + let mut lsch = Vec::new(); + lsch.extend_from_slice(&st.to_le_bytes()); + lsch.extend_from_slice(&[0u8; 12]); + lsch.extend_from_slice(&[0xAA; 8]); + lsch.extend_from_slice(&64u32.to_le_bytes()); + lsch.extend_from_slice(&(8u32 << 16).to_le_bytes()); + lsch.extend(field(joaat("Mass"), 8, 0x21, 0)); + lsch.extend(field(joaat("Gears"), 12, 0x14, 0)); + lsch.extend(field(joaat("Model"), 16, 0x4a, 0)); + lsch.extend(field(joaat("Enabled"), 20, 0x01, 0)); + lsch.extend(field(joaat("Ratio"), 22, 0x20, 0)); + lsch.extend(field(joaat("Offset"), 32, 0x33, 0)); + lsch.extend(field(joaat("Curve"), 48, 0x52 | (7 << 16), 0)); + lsch.extend(field(ELEMENT_NAME, 0, 0x21, 0)); + + let mut file = section(b"PSIN", &body); + file.extend(section(b"LSCH", &lsch)); + file.extend(section(b"LENM", &[])); + file + } + + #[test] + fn export_then_apply_is_identity_and_edits_patch_in_place() { + names::add(["TestThing", "Mass", "Gears", "Model", "Enabled", "Ratio", "Offset", "Curve", "cheetah2"]); + let file = sample(); + let xml = export_xml(&file, 0).expect("export"); + for want in [ + "type=\"TestThing\"", + "n=\"Mass\" t=\"f32\"", + "v=\"1630\"", + "n=\"Gears\" t=\"s32\"", + "v=\"-7\"", + "s=\"cheetah2\"", + "v=\"true\"", + "n=\"Ratio\" t=\"f16\"", + "v=\"1 2 3 0.5\"", + "t=\"array\" count=\"2\" to=\"1+0x0\"", + "v=\"0.25\"", + "v=\"bits:0x7fc00000\"", + ] { + assert!(xml.contains(want), "{want} missing in\n{xml}"); + } + let same = apply_xml(&file, &xml).expect("apply unchanged"); + assert!(same.changes.is_empty(), "{:?}", same.changes); + assert_eq!(same.data, file); + + let edited = xml.replace("v=\"1630\"", "v=\"1800.5\"").replace("v=\"0x", "v=\"coach\" was=\"0x").replace("v=\"1 2 3 0.5\"", "v=\"1 2 3 4\""); + let done = apply_xml(&file, &edited).expect("apply edits"); + assert_eq!(done.changes.len(), 3, "{:?}", done.changes); + assert_eq!(done.data.len(), file.len()); + let diff = file.iter().zip(&done.data).filter(|(a, b)| a != b).count(); + assert!(diff > 0 && diff <= 12); + let again = export_xml(&done.data, 0).expect("re export"); + assert!(again.contains("v=\"1800.5\"") && again.contains("v=\"1 2 3 4\"")); + assert!(again.contains(&format!("v=\"0x{:08x}\"", joaat("coach")))); + + assert!(apply_xml(&file, &xml.replace("v=\"-7\"", "v=\"seven\"")).is_err()); + assert!(apply_xml(&file[..file.len() - 8], &xml).is_err()); + } + + #[test] + fn half_floats_round_trip() { + for h in [0u16, 0x8000, 0x3c00, 0xbc00, 0x3126, 0x4f80, 0x0001, 0x03ff, 0x7bff] { + assert_eq!(f32_to_half(half_to_f32(h)), h, "0x{h:04x}"); + } + assert_eq!(half_to_f32(0x4f80), 30.0); + } + + // inflates the consecutive zlib streams of the vehicle physics file in data.rpf + fn vehicle_physics() -> Option> { + use std::io::{Read, Seek, SeekFrom}; + let levels = std::env::var("PERCYSTAR_LEVELS_RPF").ok()?; + let path = std::path::Path::new(&levels).parent()?.join("data.rpf"); + let mut f = std::fs::File::open(path).ok()?; + f.seek(SeekFrom::Start(0x1c35_b000)).ok()?; + let mut raw = vec![0u8; 0x40000]; + let n = f.read(&mut raw).ok()?; + raw.truncate(n); + let mut out = Vec::new(); + let mut pos = 0usize; + while pos + 2 <= raw.len() { + let mut dec = flate2::Decompress::new(true); + let mut chunk = Vec::with_capacity(1 << 17); + if dec.decompress_vec(&raw[pos..], &mut chunk, flate2::FlushDecompress::Finish).is_err() || chunk.is_empty() { + break; + } + out.extend_from_slice(&chunk); + pos += dec.total_in() as usize; + match (pos..(pos + 64).min(raw.len().saturating_sub(1))).find(|&k| raw[k] == 0x78 && matches!(raw[k + 1], 0x01 | 0x5e | 0x9c | 0xda)) { + Some(next) if out.len() < 3_811_200 => pos = next, + _ => break, + } + } + (out.len() == 3_811_200).then_some(out) + } + + // every psin file in a folder exports and applies back unchanged, PERCYSTAR_PSIN_DIR names the folder + #[test] + fn extracted_files_round_trip() { + let Ok(dir) = std::env::var("PERCYSTAR_PSIN_DIR") else { return }; + let Ok(rd) = std::fs::read_dir(dir) else { return }; + let (mut files, mut values, mut raw, mut dangling, mut skipped) = (0usize, 0usize, 0usize, 0usize, 0usize); + for entry in rd.flatten() { + let Ok(file) = std::fs::read(entry.path()) else { continue }; + let Ok(xml) = export_xml(&file, 0) else { + skipped += 1; + continue; + }; + let same = apply_xml(&file, &xml).unwrap_or_else(|e| panic!("{}: {e}", entry.path().display())); + assert!(same.changes.is_empty(), "{}: {:?}", entry.path().display(), &same.changes[..same.changes.len().min(3)]); + files += 1; + values += xml.matches(" o=\"0x").count(); + raw += xml.matches(" t=\"raw:").count(); + dangling += xml.matches(" to=\"?").count(); + } + eprintln!("{files} files round trip, {skipped} without schema, {values} editable values, {raw} raw fields, {dangling} unresolved pointers"); + assert!(dangling * 200 <= values.max(1), "too many pointers do not resolve"); + } + + #[test] + fn real_vehicle_file_round_trips() { + let Some(file) = vehicle_physics() else { return }; + eprintln!("vehicle physics file loaded, {} bytes", file.len()); + names::seed(); + if let Ok(dir) = std::env::var("PERCYSTAR_NAMES_DIR") { + names::load_dir(std::path::Path::new(&dir)); + } + let xml = export_xml(&file, 0).expect("export"); + let named = xml.matches(" n=\"").count() - xml.matches(" n=\"0x").count(); + eprintln!("{named} of {} field lines carry a name", xml.matches(" n=\"").count()); + assert!(xml.contains("v=\"1630\"") && xml.contains("v=\"16500\"")); + // the mass field carries the same name earlier games used + let mass = xml.lines().find(|l| l.contains("n=\"fMass\"") && l.contains("v=\"1630\"")).expect("fMass 1630 line"); + assert!(mass.contains("t=\"f32\""), "{mass}"); + if let Some(at) = xml.find(mass) { + eprintln!("{}", xml[at.saturating_sub(40)..].lines().skip(1).take(30).collect::>().join(" +")); + } + let same = apply_xml(&file, &xml).expect("apply unchanged"); + assert!(same.changes.is_empty(), "{:?}", &same.changes[..same.changes.len().min(5)]); + assert!(same.data == file); + let cut = export_xml(&file, 20_000).expect("preview"); + assert!(cut.len() < 40_000 && cut.ends_with("\n")); + } +}