Last active
August 6, 2019 21:23
-
-
Save ZephyrBlu/440687783ffd87fc7a5d0cf761ed245e to your computer and use it in GitHub Desktop.
SC2 Replay Example
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
import mpyq | |
from s2protocol import versions | |
from heapq import merge | |
import json | |
archive = mpyq.MPQArchive('training.SC2Replay') | |
# getting correct game version and protocol | |
contents = archive.header['user_data_header']['content'] | |
header = versions.latest().decode_replay_header(contents) | |
baseBuild = header['m_version']['m_baseBuild'] | |
protocol = versions.build(baseBuild) | |
# accessing neccessary parts of file for data | |
contents = archive.read_file('replay.tracker.events') | |
details = archive.read_file('replay.details') | |
gameInfo = archive.read_file('replay.game.events') | |
metadata = json.loads(archive.read_file('replay.gamemetadata.json')) | |
print(metadata) | |
print('\n') | |
# translating data into dict format info | |
gameEvents = protocol.decode_replay_game_events(gameInfo) | |
playerInfo = protocol.decode_replay_details(details) | |
trackerEvents = protocol.decode_replay_tracker_events(contents) | |
# all info is returned as generators | |
# | |
# to paint the full picture of the game | |
# both game and tracker events are needed | |
# so they are combined then sorted in chronological order | |
events = merge(gameEvents, trackerEvents, key=lambda x: x['_gameloop']) | |
events = sorted(events, key=lambda x: x['_gameloop']) | |
for event in events: | |
# 5400 = ~4:02, 5480 = ~4:04 | |
if 5400 < event['_gameloop'] < 5480: | |
if event['_event'] != 'NNet.Game.SSelectionDeltaEvent' or event['_bits'] == 520: | |
print(event) | |
print('\n') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment