From 0a92233e6c51aeedf47f3247810eabad01bb55b4 Mon Sep 17 00:00:00 2001 From: lifegpc Date: Mon, 12 Jan 2026 13:17:25 +0800 Subject: [PATCH] Fix some bp script can not be extracted --- src/scripts/bgi/bp.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/scripts/bgi/bp.rs b/src/scripts/bgi/bp.rs index 7eab142..097d6ac 100644 --- a/src/scripts/bgi/bp.rs +++ b/src/scripts/bgi/bp.rs @@ -74,6 +74,7 @@ impl BGIBpScript { let mut last_instr_pos = 0; reader.seek(SeekFrom::Start(header_size as u64))?; let max_instr_len = reader.data.len() - 4; + let mut last_instr_is_valid = true; while reader.pos < max_instr_len { let instr = reader.cpeek_u32()?; if instr == 0x17 { @@ -86,6 +87,7 @@ impl BGIBpScript { if last_instr_pos == 0 { // return Err(anyhow::anyhow!("No end instruction found in bp script")); last_instr_pos = reader.data.len(); + last_instr_is_valid = false; } reader.seek(SeekFrom::Start(header_size as u64))?; let mut strings = Vec::new(); @@ -94,7 +96,7 @@ impl BGIBpScript { if ins == 5 { let text_offset = reader.peek_u16()?; let text_address = reader.pos + text_offset as usize - 1; - if text_address >= last_instr_pos + if (text_address >= last_instr_pos || !last_instr_is_valid) && text_address < reader.data.len() && (text_address == last_instr_pos || reader.data[text_address - 1] == 0) {