Skip to content

Commit

Permalink
Merge db63bb7 into d8af524
Browse files Browse the repository at this point in the history
  • Loading branch information
Gadgetoid committed Oct 3, 2020
2 parents d8af524 + db63bb7 commit 07b5b22
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/ttblit/tool/metadata.py
Expand Up @@ -55,6 +55,7 @@ def checksum(self, bin):
def run(self, args):
self.working_path = pathlib.Path('.')
game_header = 'BLIT'.encode('ascii')
reloc_header = 'RELO'.encode('ascii')
meta_header = 'BLITMETA'.encode('ascii')
eof = '\0'.encode('ascii')
has_meta = False
Expand All @@ -63,9 +64,14 @@ def run(self, args):
splash = bytes()
checksum = bytes(4)
bin = bytes()
reloc = bytes()

if args.file.is_file():
bin = open(args.file, 'rb').read()
if bin.startswith(reloc_header):
header_start = bin.index(game_header)
reloc = bin[:header_start]
bin = bin[header_start:]
if bin.startswith(game_header):
binary_size = self.binary_size(bin)
checksum = self.checksum(bin[:binary_size])
Expand Down Expand Up @@ -131,7 +137,6 @@ def run(self, args):
return 1

logging.info(f'Adding metadata to {args.file}')
bin = bin + metadata
open(args.file, 'wb').write(bin)
open(args.file, 'wb').write(reloc + bin + metadata)

return 0

0 comments on commit 07b5b22

Please sign in to comment.