diff options
Diffstat (limited to 'crawl-ref/source/util/dump_savegame')
-rwxr-xr-x | crawl-ref/source/util/dump_savegame | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/crawl-ref/source/util/dump_savegame b/crawl-ref/source/util/dump_savegame new file mode 100755 index 0000000000..9069c38ac4 --- /dev/null +++ b/crawl-ref/source/util/dump_savegame @@ -0,0 +1,66 @@ +#!/usr/local/bin/python +# +# Tool for examining saved games. + +import os +import sys +import optparse + +try: import crawl.tags +except ImportError: + print "You need to put crawl-ref/source/python in your PYTHONPATH; I'll try." + try: sys.path.append(os.path.join(os.path.dirname(sys.argv[0]), "../python")) + except: pass + import crawl.tags + + +def process_zip(opts, fn): + """Process one or more sub-files from a .zip saved game.""" + if fn.lower().endswith('zip'): + import zipfile + from cStringIO import StringIO + zip = zipfile.ZipFile(fn, 'r') + for n in zip.namelist(): + # Ignore non-tag files for now + if ( n.endswith('.kil') or n.endswith('.nts') or n.endswith('.tc') + or n.endswith('.tut') or n.endswith('.st')): + #print "Skipping %s" % n + continue + + print "Reading %s" % n + try: + save = crawl.tags.TaggedFile(StringIO(zip.read(n))) + except Exception, e: + print " Failed (not a tag file?)" + continue + + process_file(opts, save) + + +def process_file(opts, save): + """Process a file; a portion of a saved game. + Pass a TaggedFile instance""" + # Not much going on here yet + TAG_YOU = crawl.tags.tags_enum.s2i['TAG_YOU'] + if TAG_YOU in save.tags: + print "Dumping YOU's quiver:" + you = save.tags[TAG_YOU] + you.quiver.dump() + print + + +def main(args): + parser = optparse.OptionParser() + parser.add_option("-p", dest='player', help='If .zip, process the player (.sav) portion', + action='store_true') + opts, args = parser.parse_args(args) + + for fn in args: + if fn.lower().endswith('zip'): + process_zip(opts, fn) + else: + process_file(opts, crawl.tags.TaggedFile(fn)) + + +if __name__=='__main__': + main(sys.argv[1:]) |