Skip to content

Instantly share code, notes, and snippets.

@hillexed
Last active January 10, 2017 21:53
Show Gist options
  • Save hillexed/870851cd390d3727e58f93d42452dc30 to your computer and use it in GitHub Desktop.
Save hillexed/870851cd390d3727e58f93d42452dc30 to your computer and use it in GitHub Desktop.
alytDumper.py v1.0
"""
* alytDumper.c
* by Reisyukaku
* translated to python by hillexed
*
* Dumps media from GameFreak's ALYT format.
"""
version = 1.1
import sys
def getUnsignedBytes(bytestring, offset, numBytes=4):
return int.from_bytes(bytestring[offset:offset+numBytes],byteorder='little')
def main():
if(len(sys.argv) != 2):
print("Usage: %s <alyt file>\n" % sys.argv[0])
return 1
with open(sys.argv[1],'rb') as fp:
fileBuf = fp.read()
fileSize = len(fileBuf)
if(fileBuf[0:4] != b'ALYT'):
return 1
ltblOff = getUnsignedBytes(fileBuf,0x8,4)
lmtlOff = getUnsignedBytes(fileBuf,0x10,4)
lfnlOff = getUnsignedBytes(fileBuf,0x18,4)
ltblSize = getUnsignedBytes(fileBuf,0xC,4)
lmtlSize = getUnsignedBytes(fileBuf,0x14,4)
lfnlSize = getUnsignedBytes(fileBuf,0x1C,4)
symbolTbl = getUnsignedBytes(fileBuf,0x20,4)
numOfEntries = getUnsignedBytes(fileBuf,symbolTbl,4)
print(
"""ALYT parser\n
-----------\n
Entries: %d\n\n""" % numOfEntries
)
for i in range(numOfEntries):
#I haven't found a good way to say 'keep printing till you hit a null terminator
#C, you've got me there
currentByteCounter = symbolTbl+4+(i*0x40) #start point
filename = ""
while fileBuf[currentByteCounter] != 0x00:
filename += chr(fileBuf[currentByteCounter])
currentByteCounter += 1
print(filename)
return 0
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment