diff options
author | pauldubois <pauldubois@c06c8d41-db1a-0410-9941-cceddc491573> | 2008-04-19 12:20:10 +0000 |
---|---|---|
committer | pauldubois <pauldubois@c06c8d41-db1a-0410-9941-cceddc491573> | 2008-04-19 12:20:10 +0000 |
commit | f605828804f26076d143fbc5ea6e8d2f1702cf22 (patch) | |
tree | d4aa19b0244c7a1144b97022dd7f9a8d217b44f9 /crawl-ref/source/util | |
parent | b0b4d7e1fbb9efed46a590a0045ad270fa409305 (diff) | |
download | crawl-ref-f605828804f26076d143fbc5ea6e8d2f1702cf22.tar.gz crawl-ref-f605828804f26076d143fbc5ea6e8d2f1702cf22.zip |
A utility I've been working on to parse and examine savegames.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@4363 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/util')
-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:]) |