MCPcopy Create free account
hub / github.com/JRickey/BattleShip / pack

Method pack

tools/save_editor.py:300–340  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

298 # ----- pack / unpack -----------------------------------------------
299
300 def pack(self) -> bytes:
301 body = bytearray()
302 for r in self.vs_records:
303 body += r.pack()
304 assert len(body) == 1104, len(body)
305
306 body += struct.pack(
307 "<BB hh BB H BB",
308 self.is_allow_screenflash & 0xFF,
309 self.sound_mono_or_stereo & 0xFF,
310 self.screen_adjust_h,
311 self.screen_adjust_v,
312 self.characters_fkind & 0xFF,
313 self.unlock_mask & 0xFF,
314 self.fighter_mask & 0xFFFF,
315 self.spgame_difficulty & 0xFF,
316 self.spgame_stock_count & 0xFF,
317 )
318 assert len(body) == 1116, len(body)
319
320 for r in self.spgame_records:
321 body += r.pack()
322 assert len(body) == 1500, len(body)
323
324 # ground_mask, vs_itemswitch_battles, [pad], vs_total_battles,
325 # error_flags, boot, signature, [pad to align s32 checksum]
326 body += struct.pack(
327 "<H B x H B B H xx",
328 self.ground_mask & 0xFFFF,
329 self.vs_itemswitch_battles & 0xFF,
330 self.vs_total_battles & 0xFFFF,
331 self.error_flags & 0xFF,
332 self.boot & 0xFF,
333 self.signature & 0xFFFF,
334 )
335 assert len(body) == CHECKSUM_OFFSET, len(body)
336
337 cksum = compute_checksum(bytes(body))
338 body += struct.pack("<i", cksum)
339 assert len(body) == BACKUP_SIZE, len(body)
340 return bytes(body)
341
342 @classmethod
343 def unpack(cls, buf: bytes) -> "BackupData":

Callers

nothing calls this directly

Calls 2

compute_checksumFunction · 0.85
packMethod · 0.45

Tested by

no test coverage detected