From 44cab660bc59edcec366a26d99e1cda4d803063b Mon Sep 17 00:00:00 2001 From: "Joseph C. Osborn" Date: Thu, 30 Oct 2025 10:24:02 -0700 Subject: [PATCH] Fix encoding, test with patched retroarch --- src/rply.rs | 6 ------ src/statestream.rs | 5 +++-- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src/rply.rs b/src/rply.rs index 0dbeb2c..28abd1c 100644 --- a/src/rply.rs +++ b/src/rply.rs @@ -423,7 +423,6 @@ pub fn decode(rply: &mut R) -> Result> pub struct ReplayEncoder<'a, W: std::io::Write + std::io::Seek> { rply: &'a mut W, pub header: Header, - // pub initial_state: Vec, pub frame_number: u64, last_pos: u64, ss_state: statestream::Ctx, @@ -572,8 +571,6 @@ impl<'w, W: std::io::Write + std::io::Seek> ReplayEncoder<'w, W> { Ok(()) } fn encode_initial_checkpoint(&mut self, checkpoint: &[u8]) -> Result<()> { - // let initial = std::mem::take(&mut self.initial_state); - let old_pos = self.rply.stream_position()?; self.rply .seek(std::io::SeekFrom::Start(HEADERV2_LEN_BYTES as u64))?; self.encode_checkpoint(checkpoint, 0)?; @@ -581,12 +578,9 @@ impl<'w, W: std::io::Write + std::io::Seek> ReplayEncoder<'w, W> { self.header.set_initial_state_size( u32::try_from(encoded_size).map_err(ReplayError::CheckpointTooBig)?, ); - // self.initial_state = initial; - // dbg!("initial state size", self.header.initial_state_size()); // Have to rewrite header to account for initial state size self.write_header()?; self.last_pos = self.rply.stream_position()?; - self.rply.seek(std::io::SeekFrom::Start(old_pos))?; Ok(()) } diff --git a/src/statestream.rs b/src/statestream.rs index 7c90d11..9f417d8 100644 --- a/src/statestream.rs +++ b/src/statestream.rs @@ -278,6 +278,7 @@ impl<'w, 'c, W: std::io::Write> Encoder<'w, 'c, W> { }; superblock_contents[block_i] = found_block.index; if found_block.is_new { + let block_out_bytes = self.ctx.block_index.get(found_block.index); bytes_out += rmp_size(r::write_uint( self.writer, u64::from(u8::from(SSToken::NewBlock)), @@ -285,8 +286,8 @@ impl<'w, 'c, W: std::io::Write> Encoder<'w, 'c, W> { bytes_out += rmp_size(r::write_uint(self.writer, u64::from(found_block.index))?); bytes_out += rmp_size(r::write_bin_len(self.writer, self.ctx.block_size)?); - self.writer.write_all(block_bytes)?; - bytes_out += block_bytes.len(); + self.writer.write_all(block_out_bytes)?; + bytes_out += block_out_bytes.len(); } } let found_superblock = self