#!/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?)" raise 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:])