Skip to content

Instantly share code, notes, and snippets.

@ihaveamac
Last active June 15, 2016 10:45
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ihaveamac/74a950f98908c55c3749921bd14d8884 to your computer and use it in GitHub Desktop.
Save ihaveamac/74a950f98908c55c3749921bd14d8884 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python2
import sys, binascii
if len(sys.argv) < 2:
print "usage: parse_seeddb_list.py seeddb_list.txt [--includeseed]"
print "- a seeddb.bin file will be generated in the current working directory"
print "- --includeseed will include the game's seed in the table"
print "- seeddb list could be obtained from http://pastebin.com/zNM8zYwa"
sys.exit()
titles = []
# currentTitle format: name1, name2, titleid, seed
currentTitle = ["", "", "", ""]
# seed comes after titleid in the list
readSeedNext = False
seedlist = open(sys.argv[1], "r")
for i in seedlist.read().splitlines():
if readSeedNext:
currentTitle[3] = i
readSeedNext = False
elif i[:4] == "0004":
currentTitle[2] = i
readSeedNext = True
elif i == "":
if currentTitle != ["", "", "", ""]:
titles.append(currentTitle)
currentTitle = ["", "", "", ""]
else:
if currentTitle[0] == "":
currentTitle[0] = i
else:
currentTitle[1] = i
if "--includeseed" in sys.argv:
print "Game | Title ID | Seed"
print "--- | --- | ---"
else:
print "Game | Title ID"
print "--- | ---"
for i in titles:
toPrint = i[0]
if i[1] != "":
toPrint += "<br>" + i[1]
toPrint += " | " + i[2]
if "--includeseed" in sys.argv:
toPrint += " | `" + i[3] + "`"
print toPrint
seeddb = open("seeddb.bin", "wb")
ts = list(format(len(titles), 'x').rjust(4, '0'))
ts[::2], ts[1::2] = ts[1::2], ts[::2]
ts = "".join(ts)[::-1].ljust(32, '0')
ts = binascii.unhexlify(ts)
seeddb.write(ts)
for i in titles:
s = list(i[2])
s[::2], s[1::2] = s[1::2], s[::2]
s = "".join(s)[::-1]
s += i[3].ljust(48, '0')
s = binascii.unhexlify(s)
seeddb.write(s)
seeddb.close()
seedlist.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment