How to use the sc2reader.load_replay function in sc2reader

To help you get started, we’ve selected a few sc2reader examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github GraylinKim / sc2reader / test_replays / test_all.py View on Github external
def test_encrypted(self):
        replay = sc2reader.load_replay("test_replays/1.2.2.17811/4.SC2Replay")
github GraylinKim / sc2reader / test_replays / test_all.py View on Github external
def test_referee(self):
        replay = sc2reader.load_replay("test_replays/1.2.2.17811/14.SC2Replay")
github GraylinKim / sc2reader / game_events_debug.py View on Github external
"""I find it easier to read hex when spaced by byte"""
    bytes = bytes.encode("hex")
    ret = ""
    for i in range(len(bytes)):
        if i%2:
            ret += " "
        else:
            ret += bytes[i:i+2]
    return ret

def get_name(obj):
    return obj.__class__.__name__

for filename in set(sum((list(get_files(arg)) for arg in sys.argv[1:]),list())):
    try:
        replay = sc2reader.load_replay(filename, debug=True)
    except ReadError as e:
        print filename
        if len(e.game_events):
            print "  Cursor  Time  P# EventType             Bytes"
            for event in e.game_events[-3:-1]:
                print "  ....... {:0>2}:{:0>2} P{} {: <19} - {}".format(event.second/60, event.second%60, event.pid, get_name(event), format_bytes(event.bytes))
            last_event = e.game_events[-1]
            line1_end = e.location+BYTES_WIDTH-len(last_event.bytes)-1
            line1 = e.buffer.read_range(e.location, line1_end)
            line2 = e.buffer.read_range(line1_end,line1_end+BYTES_WIDTH)
            print "  0x{:0>5X} {:0>2}:{:0>2} P{} {: <19} - {} | {}".format(e.location, last_event.second/60, last_event.second%60, last_event.pid, get_name(last_event), format_bytes(last_event.bytes), format_bytes(line1))
            print " "*41+format_bytes(line2)
            print e
        else:
            print "  0x{:0>5X} {: <19} - {}".format(0, "None", format_bytes(e.buffer.read_range(0,BYTES_WIDTH+1)))
        print
github GraylinKim / sc2reader / examples / sc2autosave.py View on Github external
if args.reset:
        reset(args)

    #Set up validates the destination and source directories.
    #It also loads the previous state or creates one as necessary.
    state = setup(args)

    #We break out of this loop in batch mode and on KeyboardInterrupt
    while True:

        #The file scan uses the arguments and the state to filter down to
        #only new (since the last sync time) files.
        for path in scan(args, state):
            try:
                #Read the file and expose useful aspects for renaming/filtering
                replay = sc2reader.load_replay(path, load_level=2)
            except KeyboardInterrupt:
                raise
            except:
                #Failure to parse
                file_name = os.path.basename(path)
                directory = make_directory(args, ('parse_error',))
                new_path = os.path.join(directory, file_name)
                source_path = path[len(args.source):]
                args.log.write("Error parsing replay: {0}".format(source_path))
                if not args.dryrun:
                    args.action.run(path, new_path)

                #Skip to the next replay
                continue

            aspects = generate_aspects(args, replay)
github ybhartia / 170Starcraft / parsing / parser.py View on Github external
def getPrintData(myReplay):

    sc2reader.engine.register_plugin(APMTracker())
    replay = sc2reader.load_replay(myReplay, load_level=4)
    data = [[]]
    unitStatusComments = [[]]

    players = initiatePlayers(replay)
    # printPlayers(players)

    data, unitStatusComments = getTrackerEvents(data, unitStatusComments,players, replay.tracker_events, "test")
    data, unitStatusComments = getGameEvents(data, unitStatusComments, players, replay.events, "test")
    # print(data)
    # print(unitStatusComments)

    return unitStatusComments[1:]
github ybhartia / 170Starcraft / GameEventVector.py View on Github external
def loadReplay(path):
	return sc2reader.load_replay(path, load_level=4)
github GraylinKim / sc2reader / sc2reader / scripts / sc2parse.py View on Github external
parser.add_argument('--ladder_only', help="If a non-ladder game fails, ignore it", action="store_true")
    parser.add_argument('folders', metavar='folder', type=str, nargs='+', help="Path to a folder")
    args = parser.parse_args()

    releases_parsed = set()
    for folder in args.folders:
        print("dealing with {0}".format(folder))
        for path in sc2reader.utils.get_files(folder, extension='SC2Replay'):
            try:
                rs = sc2reader.load_replay(path, load_level=0).release_string
                already_did = rs in releases_parsed
                releases_parsed.add(rs)
                if not args.one_each or not already_did:
                    replay = sc2reader.load_replay(path, debug=True, load_level=1)
                    if not args.one_each or replay.is_ladder:
                        replay = sc2reader.load_replay(path, debug=True)

                        human.pids = set([human.pid for human in replay.humans])
                        event_pids = set([event.player.pid for event in replay.events if getattr(event, 'player', None)])
                        player_pids = set([player.pid for player in replay.players if player.is_human])
                        ability_pids = set([event.player.pid for event in replay.events if 'CommandEvent' in event.name])
                        if human.pids != event_pids:
                            print('Event Pid problem!  pids={pids} but event pids={event_pids}'.format(pids=human.pids, event_pids=event_pids))
                            print(' with {path}: {build} - {real_type} on {map_name} - Played {start_time}'.format(path=path, **replay.__dict__))
                        elif player_pids != ability_pids:
                            print('Ability Pid problem!  pids={pids} but event pids={event_pids}'.format(pids=player_pids, event_pids=ability_pids))
                            print(' with {path}: {build} - {real_type} on {map_name} - Played {start_time}'.format(path=path, **replay.__dict__))
                        else:
                            print('No problems with {path}: {build} - {real_type} on {map_name} - Played {start_time}'.format(path=path, **replay.__dict__))
                            print('Units were: {units}'.format(units=set([obj.name for obj in replay.objects.values()])))

            except sc2reader.exceptions.ReadError as e:
github eqy / vroMAD / GameProcessor.py View on Github external
def processFiles_mp(self, progQueue, errqueue):
        players = list()
        fileCount = len(self.files)
        for filepath in self.files:
            if filepath not in self.processed:
                self.processed[filepath] = 1
                try:
                    curReplay = sc2reader.load_replay(filepath)
                except Exception as e:
                    progQueue.put('FATAL') 
                    errqueue.put([filepath,e,traceback.format_exc()])
                    #This file was bad
                    if isinstance(e, AttributeError):
                        progQueue.put(str(100.0/fileCount))        
                        continue    
                    else:
                        return None
                    #return players
                total_time = curReplay.frames/GameProcessor.CONST_FPS
                freqDists = dict()
                print(curReplay.filename)
                for player in curReplay.players:
                    freqDists[player.uid] = [0]*10
                    print(player.uid)
github GraylinKim / sc2reader / sc2reader / scripts / sc2parse.py View on Github external
parser = argparse.ArgumentParser(description="Recursively parses replay files, inteded for debugging parse issues.")
    parser.add_argument('--one_each', help="Attempt to parse only one Ladder replay for each release_string", action="store_true")
    parser.add_argument('--ladder_only', help="If a non-ladder game fails, ignore it", action="store_true")
    parser.add_argument('folders', metavar='folder', type=str, nargs='+', help="Path to a folder")
    args = parser.parse_args()

    releases_parsed = set()
    for folder in args.folders:
        print("dealing with {0}".format(folder))
        for path in sc2reader.utils.get_files(folder, extension='SC2Replay'):
            try:
                rs = sc2reader.load_replay(path, load_level=0).release_string
                already_did = rs in releases_parsed
                releases_parsed.add(rs)
                if not args.one_each or not already_did:
                    replay = sc2reader.load_replay(path, debug=True, load_level=1)
                    if not args.one_each or replay.is_ladder:
                        replay = sc2reader.load_replay(path, debug=True)

                        human.pids = set([human.pid for human in replay.humans])
                        event_pids = set([event.player.pid for event in replay.events if getattr(event, 'player', None)])
                        player_pids = set([player.pid for player in replay.players if player.is_human])
                        ability_pids = set([event.player.pid for event in replay.events if 'CommandEvent' in event.name])
                        if human.pids != event_pids:
                            print('Event Pid problem!  pids={pids} but event pids={event_pids}'.format(pids=human.pids, event_pids=event_pids))
                            print(' with {path}: {build} - {real_type} on {map_name} - Played {start_time}'.format(path=path, **replay.__dict__))
                        elif player_pids != ability_pids:
                            print('Ability Pid problem!  pids={pids} but event pids={event_pids}'.format(pids=player_pids, event_pids=ability_pids))
                            print(' with {path}: {build} - {real_type} on {map_name} - Played {start_time}'.format(path=path, **replay.__dict__))
                        else:
                            print('No problems with {path}: {build} - {real_type} on {map_name} - Played {start_time}'.format(path=path, **replay.__dict__))
                            print('Units were: {units}'.format(units=set([obj.name for obj in replay.objects.values()])))