Fix BGI Bp parse bug

This commit is contained in:
2025-08-12 13:45:57 +08:00
parent 2ca4f6475f
commit c54c7fe4e6
4 changed files with 9 additions and 5 deletions

2
Cargo.lock generated
View File

@@ -805,7 +805,7 @@ dependencies = [
[[package]] [[package]]
name = "msg_tool" name = "msg_tool"
version = "0.1.1" version = "0.1.2"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"byteorder", "byteorder",

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "msg_tool" name = "msg_tool"
version = "0.1.1" version = "0.1.2"
edition = "2024" edition = "2024"
repository = "https://github.com/lifegpc/msg-tool" repository = "https://github.com/lifegpc/msg-tool"
description = "A command-line tool for exporting, importing, packing, and unpacking script files." description = "A command-line tool for exporting, importing, packing, and unpacking script files."

View File

@@ -73,10 +73,14 @@ impl BGIBpScript {
} }
let mut last_instr_pos = 0; let mut last_instr_pos = 0;
reader.seek(SeekFrom::Start(header_size as u64))?; reader.seek(SeekFrom::Start(header_size as u64))?;
for _ in 0..instr_size / 4 { let max_instr_len = reader.data.len() - 4;
let instr = reader.read_u32()?; while reader.pos < max_instr_len {
let instr = reader.cpeek_u32()?;
if instr == 0x17 { if instr == 0x17 {
last_instr_pos = reader.pos; last_instr_pos = reader.pos;
reader.pos += 4;
} else {
reader.pos += 1;
} }
} }
if last_instr_pos == 0 { if last_instr_pos == 0 {

View File

@@ -56,7 +56,7 @@ pub struct SrcXmlScript {
impl SrcXmlScript { impl SrcXmlScript {
/// Creates a new `SrcXmlScript` from the provided buffer and encoding. /// Creates a new `SrcXmlScript` from the provided buffer and encoding.
/// ///
/// * `buf` - The buffer containing the XML data. /// * `buf` - The buffer containing the XML data.
/// * `encoding` - The encoding of the XML data. /// * `encoding` - The encoding of the XML data.
/// * `config` - Additional configuration options. /// * `config` - Additional configuration options.