Exemplo n.º 1
0
	def __init__(self, replay_path):
		self.replay_path = replay_path
		self.archive = mpyq.MPQArchive(replay_path)

		# Read the protocol header, this can be read with any protocol
		self.contents = self.archive.header['user_data_header']['content']
		# header = heroprotocol.protocol29406.decode_replay_header(contents)
		self.header = protocol29406.decode_replay_header(self.contents)
		# The header's baseBuild determines which protocol to use
		self.baseBuild = self.header['m_version']['m_baseBuild']

		module = 'heroprotocol.protocol%s' % self.baseBuild
		try:
			self.protocol = __import__(module, fromlist=['heroprotocol'])
		except ImportError as e:
			raise TypeError('Unsupported base build: %d' % baseBuild)
Exemplo n.º 2
0
def read_and_decode(filename, do_attributes=1, do_initdata=1):
    global initdata, details, attributes, lobby_data
    archive = mpyq.MPQArchive(filename)
    header = protocol29406.decode_replay_header(
        archive.header['user_data_header']['content'])
    baseBuild = header['m_version']['m_baseBuild']
    protocol = import_module('heroprotocol.protocol%s' % baseBuild, )
    details = protocol.decode_replay_details(
        archive.read_file('replay.details'))
    lobby_data = archive.read_file(
        'replay.server.battlelobby')  #loby_data is not decoded file content
    if do_initdata:  # for game type
        initdata = protocol.decode_replay_initdata(
            archive.read_file('replay.initData'))
    if do_attributes:  # for hero level
        attributes = protocol.decode_replay_attributes_events(
            archive.read_file('replay.attributes.events'))
Exemplo n.º 3
0
    seconds = loops / 16
    mins = seconds / 60
    secs = seconds % 60
    timestring = ""
    if mins > 0:
        timestring = "%02dm" % mins
    timestring += "%02ds" % secs
    return {'sec': seconds, 'duration': { 'min': mins, 'sec': secs, 'string': timestring }}

parser = argparse.ArgumentParser()
parser.add_argument('replay_file', help='.SC2Replay file to load')
args = parser.parse_args()
archive = mpyq.MPQArchive(args.replay_file)

contents = archive.header['user_data_header']['content']
header = protocol29406.decode_replay_header(contents)

# The header's baseBuild determines which protocol to use
baseBuild = header['m_version']['m_baseBuild']
try:
    protocol_name = 'protocol%s' % (baseBuild,)
    protocols = __import__('heroprotocol', globals(), locals(), [protocol_name])
    protocol = getattr(protocols, protocol_name)
except Exception as e:
    print >> sys.stderr, 'Unsupported base build: %d, %s' % (baseBuild, e)
    sys.exit(1)

contents = archive.read_file('replay.details')
details = protocol.decode_replay_details(contents)

contents = archive.read_file('replay.initData')
Exemplo n.º 4
0
import heroprotocol, sys, os, os.path, pprint
from heroprotocol.mpyq import mpyq
sys.path.append(os.path.join(os.getcwd(), "heroprotocol"))

from heroprotocol import protocol29406

archive = mpyq.MPQArchive(sys.argv[-1])

contents = archive.header['user_data_header']['content']
header = protocol29406.decode_replay_header(contents)
baseBuild = header['m_version']['m_baseBuild']
try:
    protocol = __import__('protocol%s' % (baseBuild,))
except:
    print >> sys.stderr, 'Unsupported base build: %d' % baseBuild
    sys.exit(1)

message_events = protocol.decode_replay_message_events(archive.read_file('replay.message.events'))

for message in message_events:
    if 'm_string' in message:
        print(message['m_string'])