paavohtl Claude Opus 4.6 (1M context) commited on
Commit
44ed7d6
·
1 Parent(s): 55094ab

fix: trim trailing default bytes in V3 scheme serialization

Browse files

V3 .wsc files only include extended options bytes that differ from
defaults. Parsing padded short files to full size, but to_bytes() wrote
the full payload back, breaking roundtrip equality.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

crates/openwa-core/src/game/scheme.rs CHANGED
@@ -180,11 +180,27 @@ impl SchemeFile {
180
  }
181
 
182
  /// Serialize back to .wsc format.
 
 
 
183
  pub fn to_bytes(&self) -> Vec<u8> {
184
- let mut buf = Vec::with_capacity(SCHEME_HEADER_SIZE + self.payload.len());
 
 
 
 
 
 
 
 
 
 
 
 
 
185
  buf.extend_from_slice(&SCHEME_MAGIC);
186
  buf.push(self.version.to_byte());
187
- buf.extend_from_slice(&self.payload);
188
  buf
189
  }
190
 
 
180
  }
181
 
182
  /// Serialize back to .wsc format.
183
+ ///
184
+ /// For V3 schemes, trailing extended options bytes that match the defaults
185
+ /// are trimmed, matching WA's minimal file format.
186
  pub fn to_bytes(&self) -> Vec<u8> {
187
+ let payload = if self.version == SchemeVersion::V3
188
+ && self.payload.len() == SCHEME_PAYLOAD_V3
189
+ {
190
+ // Trim trailing extended options bytes that match defaults
191
+ let ext = &self.payload[EXTENDED_OPTIONS_OFFSET..];
192
+ let mut trim_len = EXTENDED_OPTIONS_SIZE;
193
+ while trim_len > 0 && ext[trim_len - 1] == EXTENDED_OPTIONS_DEFAULTS[trim_len - 1] {
194
+ trim_len -= 1;
195
+ }
196
+ &self.payload[..EXTENDED_OPTIONS_OFFSET + trim_len]
197
+ } else {
198
+ &self.payload
199
+ };
200
+ let mut buf = Vec::with_capacity(SCHEME_HEADER_SIZE + payload.len());
201
  buf.extend_from_slice(&SCHEME_MAGIC);
202
  buf.push(self.version.to_byte());
203
+ buf.extend_from_slice(payload);
204
  buf
205
  }
206