Skip to content

Instantly share code, notes, and snippets.

@bmaia
Last active April 17, 2021 00:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bmaia/466e6a332f9ffe96b1d13c3f2f21b463 to your computer and use it in GitHub Desktop.
Save bmaia/466e6a332f9ffe96b1d13c3f2f21b463 to your computer and use it in GitHub Desktop.
#!/usr/bin/python3
import sys
#
# NBA Jam/Midway IMG format parser
# https://github.com/historicalsource/nba-jam
#
if __name__ == '__main__':
filename = sys.argv[1]
with open(filename, "rb") as fp:
print('=================')
print('image information')
print('=================')
# total images in file
num_images = int.from_bytes(fp.read(1), 'little')
print('total images: ',num_images)
# img list pointer
fp.seek(4)
file_list_offset = bytearray(fp.read(4))
# we need to reverse the order (little endian)
offset = int.from_bytes(file_list_offset, byteorder='little')
fp.seek(offset)
# for each of the images, read 50 bytes to retrieve file names
while num_images > 0:
# print(hex(fp.tell()))
image_metadata = fp.read(50)
file_name_length = image_metadata.find(b'\00')
print(image_metadata[0:file_name_length].decode('utf-8'))
num_images -= 1
# palette metadata is stored right after the image metadata
# in blocks of 26 bytes with the same delimiter on offset[25]
print('===================')
print('palette information')
print('===================')
palette_metadata = fp.read(26)
delimiter = palette_metadata[25]
while True:
# print(hex(fp.tell()))
if len(palette_metadata) == 26:
if palette_metadata[25] == delimiter:
palette_name_length = palette_metadata.find(b'\00')
print(palette_metadata[0:palette_name_length].decode('utf-8'))
palette_offset = int.from_bytes(palette_metadata[14:18], byteorder='little')
print('offset: ', hex(palette_offset))
palette_metadata = fp.read(26)
else:
break
else:
break
@bmaia
Copy link
Author

bmaia commented Apr 17, 2021

Palette LGMDRED2 on offset 0x59c:

font

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment