Update offset in Peek/CPeek trait from usize to u64

This commit is contained in:
2025-08-13 11:18:00 +08:00
parent b9ee9d1e42
commit 270a2d9fdf
11 changed files with 91 additions and 93 deletions

View File

@@ -129,7 +129,7 @@ impl Script for BGIBpScript {
for i in self.strings.iter() {
let text_address = i.offset_pos + i.text_offset as usize - 1;
// println!("offset: {}, text address: {}, text_offset: {}", i.offset_pos, text_address, i.text_offset);
let str = self.data.cpeek_cstring_at(text_address)?;
let str = self.data.cpeek_cstring_at(text_address as u64)?;
let str = decode_to_string(self.encoding, str.as_bytes(), true)?;
messages.push(Message {
name: None,
@@ -157,7 +157,7 @@ impl Script for BGIBpScript {
let text_address = i.offset_pos + i.text_offset as usize - 1;
let old_str_len = self
.data
.cpeek_cstring_at(text_address)?
.cpeek_cstring_at(text_address as u64)?
.as_bytes_with_nul()
.len();
let mut str = mes.message;

View File

@@ -451,13 +451,13 @@ impl<'a> V1Parser<'a> {
pub fn is_empty_string(&self, address: usize) -> Result<bool> {
let start = self.offset + address;
let data = self.buf.cpeek_u8_at(start)?;
let data = self.buf.cpeek_u8_at(start as u64)?;
Ok(data == 0)
}
pub fn read_string_at_address(&mut self, address: usize) -> Result<String> {
let start = self.offset + address;
let buf = self.buf.peek_cstring_at(start)?;
let buf = self.buf.peek_cstring_at(start as u64)?;
// Sometimes string has private use area characters, so we disable strict checking
Ok(decode_to_string(self.encoding, buf.as_bytes(), false)?)
}

View File

@@ -129,7 +129,7 @@ impl BGIScript {
fn read_string(&self, offset: usize) -> Result<String> {
let start = self.offset + offset;
let string_data = self.data.cpeek_cstring_at(start)?;
let string_data = self.data.cpeek_cstring_at(start as u64)?;
// sometimes string has private use area characters, so we disable strict checking
let string = decode_to_string(self.encoding, string_data.as_bytes(), false)?;
Ok(string)
@@ -319,7 +319,7 @@ impl Script for BGIScript {
}
let old_str_len = self
.data
.cpeek_cstring_at(bgi_str_old_offset)?
.cpeek_cstring_at(bgi_str_old_offset as u64)?
.as_bytes_with_nul()
.len();
let nmess = encode_string(encoding, &nmes, false)?;
@@ -382,7 +382,7 @@ impl Script for BGIScript {
}
let old_str_len = self
.data
.cpeek_cstring_at(curs.address + self.offset)?
.cpeek_cstring_at((curs.address + self.offset) as u64)?
.as_bytes_with_nul()
.len();
let nmes = match curs.typ {