1
Fork 0
mirror of https://github.com/redstrate/Physis.git synced 2025-04-20 11:47:46 +00:00

Restore old string_from_offset

This commit is contained in:
Joshua Goins 2025-04-13 18:16:13 -04:00
parent 24b4d5bff0
commit 670f8aa3dd
2 changed files with 17 additions and 3 deletions

View file

@ -56,19 +56,20 @@ pub(crate) fn strings_parser(
#[binrw::parser(reader)] #[binrw::parser(reader)]
pub(crate) fn string_from_offset(start: u64) -> BinResult<String> { pub(crate) fn string_from_offset(start: u64) -> BinResult<String> {
let offset: u32 = reader.read_le::<u32>()?;
let mut string = String::new(); let mut string = String::new();
let old_pos = reader.stream_position()?; let old_pos = reader.stream_position()?;
reader.seek(SeekFrom::Start(start + offset as u64))?;
reader.seek(SeekFrom::Start(start as u64))?; reader.seek(SeekFrom::Start(start as u64))?;
let mut next_char = reader.read_le::<u8>().unwrap() as char; let mut next_char = reader.read_le::<u8>().unwrap() as char;
while next_char != '\0' { while next_char != '\0' {
string.push(next_char); string.push(next_char);
next_char = reader.read_le::<u8>().unwrap() as char; next_char = reader.read_le::<u8>().unwrap() as char;
} }
reader.seek(SeekFrom::Start(old_pos))?; reader.seek(SeekFrom::Start(old_pos))?;
Ok(string) Ok(string)
} }

View file

@ -183,7 +183,20 @@ impl StringHeap {
where where
R: Read + Seek, R: Read + Seek,
{ {
string_from_offset(reader, Endian::Little, (self.pos + offset as u64,)).unwrap() let offset = self.pos + offset as u64;
let mut string = String::new();
let old_pos = reader.stream_position().unwrap();
reader.seek(SeekFrom::Start(offset as u64)).unwrap();
let mut next_char = reader.read_le::<u8>().unwrap() as char;
while next_char != '\0' {
string.push(next_char);
next_char = reader.read_le::<u8>().unwrap() as char;
}
reader.seek(SeekFrom::Start(old_pos)).unwrap();
string
} }
} }