Exemplo n.º 1
0
def body_raw(gamefile, outputfile):
    """Store the raw body bytes to a file
    """
    with open(gamefile, 'rb') as input:
        rec = janissary.RecordedGame(input)
        with open(outputfile, 'wb') as output:
            output.write(rec.body_bytes())
Exemplo n.º 2
0
def command_summary(gamefile):
    """Print some info about the commands found in the log body (debug)
    """
    with open(gamefile, 'rb') as f:
        rec = janissary.RecordedGame(f)
        body = janissary.BodyParser(janissary.BinReader(rec.body_bytes()))

    command_counts = {}
    for op in body:
        if isinstance(op, janissary.Sync):
            print("Sync %d" % op.time)
        if isinstance(op, janissary.Command):
            if op.type not in command_counts:
                command_counts[op.type] = 0
            command_counts[op.type] += 1
            if op.type == 0x81:
                print("Command %x" % op.type)
                print_hex(op.data)

    print("Cmd  | Count")
    print("------------")

    rows = []
    for k, v in command_counts.items():
        rows.append(("0x%02x" % k, command_name(k), v))
    rows = sorted(rows, key=lambda x: x[0])

    print(tabulate(rows, headers=["CMD ID", "CMD Name", "Count"]))
Exemplo n.º 3
0
def test_header_bytes(datafile):
    with open(datafile('example_v5.8.aoe2record'), 'rb') as f:
        rec = janissary.RecordedGame(f)
        header_bytes = rec.header_bytes()

    assert isinstance(header_bytes, bytes)
    assert len(header_bytes) == 1036223
Exemplo n.º 4
0
def version(gamefile):
    """Read the version info from a log file
    """
    with open(gamefile, 'rb') as f:
        rec = janissary.RecordedGame(f)
        version, sub_version = rec.header().get_version()
    print("Version: %s, subversion: %f" % (version, sub_version))
Exemplo n.º 5
0
def header_yaml(gamefile, outputfile):
    """Store the parsed contents of the header as YAML
    """

    print("Writing header from %s to %s...\n" % (gamefile, outputfile))
    with open(gamefile, 'rb') as input:
        rec = janissary.RecordedGame(input)
        header = rec.header().header_dict()

    with open(outputfile, 'w') as f:
        yaml.dump(header, f, default_flow_style=False)
Exemplo n.º 6
0
def header_raw(gamefile, outputfile):
    """Store the raw, uncompressed bytes of the header
    """

    print("Writing header from %s to %s...\n" % (gamefile, outputfile))
    with open(gamefile, 'rb') as input:
        rec = janissary.RecordedGame(input)
        header = rec.header_bytes()

    with open(outputfile, 'wb') as f:
        f.write(header)
Exemplo n.º 7
0
def command_yaml(gamefile, outputfile):
    """Create a yaml output with commands
    """
    with open(gamefile, 'rb') as f:
        rec = janissary.RecordedGame(f)
        body_reader = janissary.BinReader(rec.body_bytes())
        commands = janissary.body.timestamped_commands(body_reader)

    commands = [c.serializable() for c in commands]
    with open(outputfile, 'w') as f:
        yaml.dump(commands, f)
Exemplo n.º 8
0
def sync_summary(gamefile):
    """Print a list of sync message (debug)
    """
    with open(gamefile, 'rb') as f:
        rec = janissary.RecordedGame(f)
        body_reader = janissary.BinReader(rec.body_bytes())

    body = janissary.BodyParser(body_reader)
    for op in body:
        if isinstance(op, janissary.Sync):
            print("SYNC time_delta=%d, player_id=%d" %
                  (op.time_delta, op.player_index))
Exemplo n.º 9
0
def report(gamefile, outputfile, json_output_flag):
    """Render report as HTML or JSON"""
    with open(gamefile, 'rb') as f:
        rec = janissary.RecordedGame(f)
        header_dict = rec.header().header_dict()
        body_reader = janissary.BinReader(rec.body_bytes())
        timestamped_commands = janissary.body.timestamped_commands(body_reader)

    with open(outputfile, 'w') as f:
        if json_output_flag:
            f.write(
                json.dumps(
                    janissary.reports.report(header_dict,
                                             timestamped_commands)))
        else:
            f.write(
                janissary.reports.render_html(header_dict,
                                              timestamped_commands))
Exemplo n.º 10
0
def test_command_summary_v58(datafile):
    with open(datafile('example_v5.8.aoe2record'), 'rb') as f:
        rec = janissary.RecordedGame(f)
        body_reader = janissary.BinReader(rec.body_bytes())
        timestamped_commands = janissary.body.timestamped_commands(body_reader)
        header_dict = rec.header().header_dict()

    report = CommandSummaryReport(header_dict, timestamped_commands)

    expected_headers = [
        "Player", "ATTACK", "BUILD", "GARRISON", "MOVE", "MULTIPURPOSE",
        "RALLY", "RESEARCH", "TOWNBELL", "TRAIN2", "WALL", "WAYPOINT"
    ]
    expected_rows = [
        ["Squisher", 79, 37, 3, 212, 0, 0, 11, 0, 49, 0, 0],
        ["punkkiri", 74, 37, 1, 124, 3, 5, 3, 1, 36, 5, 1],
    ]
    assert report.player_command_headers() == expected_headers
    assert report.player_command_rows() == expected_rows
Exemplo n.º 11
0
def test_header_length(datafile):
    with open(datafile('example_v5.8.aoe2record'), 'rb') as f:
        rec = janissary.RecordedGame(f)
        assert rec.header_length == 0x17450
Exemplo n.º 12
0
def test_header_version(datafile):
    with open(datafile('example_v5.8.aoe2record'), 'rb') as f:
        rec = janissary.RecordedGame(f)
        assert rec.header().get_version() == ("VER 9.4", 12.5)