Last active
June 15, 2016 10:45
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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