From 81d6fe3922cf818386d9c87076671dbd6c5582f4 Mon Sep 17 00:00:00 2001 From: WiseDev <83840010+wisedevik@users.noreply.github.com> Date: Sun, 23 Aug 2026 15:04:51 +0300 Subject: [PATCH] take the checksum from before the closing checkpoint LogicGameMode::encode reads its return value out of getCheckSum() and only then writes it: v15 = ChecksumEncoder::getCheckSum(a2); (...vptr+88)(a2, v15); // the checkpoint vint return v15; we were reading ours after that write, so the closing checkpoint was folded into the number we compared. the two could never match, whatever the simulation did - which is why tick 41 disagreed with six untouched towers on the field. write() now hands back the value it wrote, the way encode() does. --- crates/logic/src/battle/logic_game_mode.rs | 12 ++++++------ crates/titan/src/io/writer.rs | 3 ++- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/crates/logic/src/battle/logic_game_mode.rs b/crates/logic/src/battle/logic_game_mode.rs index effece9..0035c1b 100644 --- a/crates/logic/src/battle/logic_game_mode.rs +++ b/crates/logic/src/battle/logic_game_mode.rs @@ -23,7 +23,7 @@ impl LogicGameMode { } } impl LogicGameMode { - pub fn write(&self, writer: &mut ByteStreamWriter, with_commands: bool) -> Result<()> { + pub fn write(&self, writer: &mut ByteStreamWriter, with_commands: bool) -> Result { writer.write_vint(self.time.tick); writer.write_checksum_checkpoint(); writer.write_vint(SECTION_BATTLE); @@ -36,21 +36,21 @@ impl LogicGameMode { } writer.write_vint(SECTION_TUTORIAL); self.tutorial_manager.encode(writer)?; - writer.write_checksum_checkpoint(); + let checksum = writer.write_checksum_checkpoint(); if with_commands { writer.write_vint(0); } - Ok(()) + Ok(checksum) } pub fn calculate_checksum(&self) -> Result { let mut writer = ByteStreamWriter::new(); - self.write(&mut writer, false)?; - Ok(writer.checksum() as i32) + self.write(&mut writer, false) } } impl Payload for LogicGameMode { fn encode(&self, writer: &mut ByteStreamWriter) -> Result<()> { - self.write(writer, true) + self.write(writer, true)?; + Ok(()) } fn decode(_reader: &mut titan::ByteStreamReader<'_>) -> Result { Err(titan::Error::Unsupported("LogicGameMode is encode only")) diff --git a/crates/titan/src/io/writer.rs b/crates/titan/src/io/writer.rs index 71c3939..f152597 100644 --- a/crates/titan/src/io/writer.rs +++ b/crates/titan/src/io/writer.rs @@ -33,9 +33,10 @@ impl ByteStreamWriter { pub fn checksum(&self) -> u32 { self.checksum.value() } - pub fn write_checksum_checkpoint(&mut self) { + pub fn write_checksum_checkpoint(&mut self) -> i32 { let running = self.checksum.value() as i32; self.write_vint(running); + running } pub fn write_byte(&mut self, value: u8) { self.checksum.write_byte(value as i8);