From a7a4f62a0481542b91322952c652e66a42a14872 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Sat, 14 Nov 2026 21:54:12 +0400 Subject: fix(script): copy live DWORD values between script cells The native record-copy branch covers 73 DWORD-to-DWORD instructions in the shipped shared varset. Stock mission 11 now copies the protection request value and reaches group assignment at Handler(25). --- crates/fparkan-script/src/lib.rs | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) (limited to 'crates') diff --git a/crates/fparkan-script/src/lib.rs b/crates/fparkan-script/src/lib.rs index 336828ea..4577cb3d 100644 --- a/crates/fparkan-script/src/lib.rs +++ b/crates/fparkan-script/src/lib.rs @@ -216,7 +216,7 @@ pub enum ScriptInitResolveError { /// Raw disk word at index 3. found: u32, }, - /// A formula record requests the separate whole-varset-record copy path. + /// A record requests an unsupported copy between variable cells. UnsupportedFormulaCopySource { /// Raw disk word at index 2. found: u32, @@ -273,7 +273,7 @@ impl std::fmt::Display for ScriptInitResolveError { ), Self::UnsupportedFormulaCopySource { found } => write!( formatter, - "unsupported formula source 0x{found:08x}; whole-varset copy is not modeled" + "unsupported variable copy from cell 0x{found:08x}; expected two DWORD cells" ), Self::MissingFormulaTable => write!(formatter, "formula assignment has no FML table"), Self::FormulaIndexOutOfBounds { index, rows } => write!( @@ -1023,11 +1023,19 @@ impl VarSet { }])) } u32::MAX => { - if instruction.header_words[2] != u32::MAX { + let source = instruction.header_words[2]; + let target = instruction.header_words[1]; + if source != u32::MAX { + if let (Some(VarSetDefault::Dword(value)), Some(VarSetDefault::Dword(_))) = + (values.get(source as usize), values.get(target as usize)) + { + return Ok(InitInstructionResolution::Executed(vec![ScriptInitWrite { + index: target, + value: VarSetDefault::Dword(*value), + }])); + } return Ok(InitInstructionResolution::Unsupported( - ScriptInitResolveError::UnsupportedFormulaCopySource { - found: instruction.header_words[2], - }, + ScriptInitResolveError::UnsupportedFormulaCopySource { found: source }, )); } let Some(formulas) = formulas else { @@ -2415,6 +2423,25 @@ mod tests { } } + #[test] + fn periodic_assignment_copies_a_live_dword_cell() { + let varset = parse_varset(b"VAR(DWORD, destination, 0)\nVAR(DWORD, source, 0)\n").unwrap(); + let event = ScriptEvent { + name_len: 4, + name_raw: b"Test\0".to_vec(), + event_word: 0, + instructions: vec![ScriptInstruction { + header_words: [u32::MAX, 0, 1, u32::MAX, 6, 0, u32::MAX], + references: Vec::new(), + }], + }; + let mut values = [VarSetDefault::Dword(23), VarSetDefault::Dword(0x8000_000c)]; + varset + .execute_event_prefix(&event, None, &mut values, |_, _| unreachable!()) + .unwrap(); + assert_eq!(values, [VarSetDefault::Dword(0x8000_000c); 2]); + } + #[test] fn active_jump_skips_to_the_raw_instruction_index_and_leaves_conditions() { let varset = parse_varset(b"VAR(DWORD, left, 0)\nVAR(DWORD, right, 0)\n").unwrap(); -- cgit v1.2.3