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

bernardomr@splinter:~/nba$ python3 imgparser.py LGMD.IMG
=================
image information
=================
total images:  69
BLANK
lgmd_A
lgmd_B
lgmd_C
lgmd_D
lgmd_E
lgmd_F
lgmd_G
lgmd_H
lgmd_I
lgmd_J
lgmd_K
lgmd_L
lgmd_M
lgmd_N
lgmd_O
lgmd_P
lgmd_Q
lgmd_R
lgmd_S
lgmd_T
lgmd_U
lgmd_V
lgmd_W
lgmd_X
lgmd_Y
lgmd_Z
lgmd_0
lgmd_1
lgmd_2
lgmd_3
lgmd_4
lgmd_5
lgmd_6
lgmd_7
lgmd_8
lgmd_9
lgmd_DOT
lgmd_COL
lgmd_EXP
lgmd_NUM
omlgmd_A
omlgmd_B
omlgmd_C
omlgmd_D
omlgmd_E
omlgmd_F
omlgmd_G
omlgmd_H
omlgmd_I
omlgmd_J
omlgmd_K
omlgmd_L
omlgmd_M
omlgmd_N
omlgmd_O
omlgmd_P
omlgmd_Q
omlgmd_R
omlgmd_S
omlgmd_T
omlgmd_U
omlgmd_V
omlgmd_W
omlgmd_X
omlgmd_Y
omlgmd_Z
omlgmd_EXP
omlgmd_DOT
===================
palette information
===================
BLANKPAL
offset:  0x1c
LGGEMD1
offset:  0x21c
LGMDGLD
offset:  0x28c
LGMDBLU
offset:  0x2fc
LGMDCHR
offset:  0x36c
LGMDORNG
offset:  0x3dc
LGMDSLV
offset:  0x44c
LGMDRED
offset:  0x4bc
LGMDWHT
offset:  0x52c
LGMDRED2
offset:  0x59c
LGMDPURP
offset:  0x60c
LGMDGLDlt
offset:  0x67c
LGMDGLDdk
offset:  0x6ec

@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