Skip to content

Commit

Permalink
Fix append_wads to handle the RELO header
Browse files Browse the repository at this point in the history
  • Loading branch information
Daft-Freak committed Dec 9, 2020
1 parent 416776e commit 072498e
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions append_wads.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,22 @@
# grab metadata / length
in_file = open(args.input_file, "rb")
head = in_file.read(20)
head_off = 0

if head[:4] == b'RELO':
num_relocs = struct.unpack('<I', head[4:8])[0]
head_off = num_relocs * 4 + 8
in_file.seek(head_off)
head = in_file.read(20)

in_file_end = struct.unpack('<I', head[16:20])[0] & 0x1FFFFFF

in_file.seek(in_file_end)
in_file.seek(in_file_end + head_off)
metadata = in_file.read()
in_file.seek(0)

out_file = open(args.output_file, "wb")
out_file.write(in_file.read(in_file_end))
out_file.write(in_file.read(in_file_end + head_off))

# header
out_file.write(b"APPFILES")
Expand All @@ -35,9 +42,9 @@
out_file.write(basename.encode())
out_file.write(open(filename, "rb").read())

new_end = out_file.tell()
new_end = out_file.tell() - head_off
out_file.write(metadata)

# patch end pointer
out_file.seek(16)
out_file.seek(head_off + 16)
out_file.write(struct.pack("<I", 0x90000000 | new_end))

0 comments on commit 072498e

Please sign in to comment.