mirror of
https://github.com/lifegpc/msg-tool.git
synced 2026-06-07 21:38:58 +08:00
实现 CPeek 特性并在 MemReader 和 MemWriter 中添加支持;重构 V1Parser 和 BGIScript 中的字符串读取逻辑
This commit is contained in:
@@ -441,10 +441,8 @@ impl<'a> V1Parser<'a> {
|
||||
|
||||
pub fn is_empty_string(&self, address: usize) -> Result<bool> {
|
||||
let start = self.offset + address;
|
||||
if start >= self.buf.data.len() {
|
||||
return Err(anyhow::anyhow!("Address out of bounds"));
|
||||
}
|
||||
Ok(self.buf.data[start] == 0)
|
||||
let data = self.buf.cpeek_u8_at(start)?;
|
||||
Ok(data == 0)
|
||||
}
|
||||
|
||||
pub fn read_string_at_address(&mut self, address: usize) -> Result<String> {
|
||||
|
||||
@@ -93,15 +93,8 @@ impl BGIScript {
|
||||
|
||||
fn read_string(&self, offset: usize) -> Result<String> {
|
||||
let start = self.offset + offset;
|
||||
let mut end = start;
|
||||
while self.data.data[end] != 0 {
|
||||
end += 1;
|
||||
if end >= self.data.data.len() {
|
||||
return Err(anyhow::anyhow!("String not null-terminated"));
|
||||
}
|
||||
}
|
||||
let string_data = &self.data.data[start..end];
|
||||
let string = decode_to_string(self.encoding, string_data)?;
|
||||
let string_data = self.data.cpeek_cstring_at(start)?;
|
||||
let string = decode_to_string(self.encoding, string_data.as_bytes())?;
|
||||
Ok(string)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user