Esempio n. 1
0
    Padding(2),
    "db_checksum"/Int32ul,
    "code_checksum"/Int32ul,
    "version"/Float32l,
    "map_size"/Byte,
    "map_id"/Byte,
    "population"/Int16ul,
    Peek("victory_type_id"/Byte),
    VictoryEnum("victory_type"/Byte),
    Peek("starting_age_id"/Byte),
    AgeEnum("starting_age"/Byte),
    Peek("starting_resources_id"/Byte),
    ResourceLevelEnum("starting_resources"/Byte),
    "all_techs"/Flag,
    "random_positions"/Flag,
    RevealMapEnum("reveal_map"/Byte),
    "is_deathmatch"/Flag,
    "is_regicide"/Flag,
    "starting_units"/Byte,
    "lock_teams"/Flag,
    "lock_speed"/Flag,
    Padding(1),
    Array(lambda ctx: ctx.player_num, achievements),
    Padding(4),
    Array(lambda ctx: (8 - ctx.player_num) * 63, Padding(4)),
)

de_autoscout = "de_autoscout"/Struct(
    "selected"/Byte,
    Array(lambda ctx: ctx.selected, "unit_ids"/Int32ul)
)
Esempio n. 2
0
from construct import Array, Byte, Bytes, Flag, Int32ul, Padding, Peek, Struct, If

from mgz.enums import GameTypeEnum, RevealMapEnum

# pylint: disable=invalid-name, bad-continuation

# Player inputs in the lobby, and several host settings.
lobby = "lobby" / Struct(
    Array(8, "teams" / Byte),  # team number selected by each player
    If(
        lambda ctx: ctx._.version != 'VER 9.4',
        Padding(1),
    ),
    Peek("reveal_map_id" / Int32ul),
    RevealMapEnum("reveal_map" / Int32ul),
    Padding(4),
    "map_size" / Int32ul,
    "population_limit" / Int32ul,  # multiply by 25 for UserPatch 1.4
    Peek("game_type_id" / Byte),
    GameTypeEnum("game_type" / Byte),
    "lock_teams" / Flag,
    If(lambda ctx: ctx._.version == 'VER 9.4', Padding(5)),
    "num_chat" / Int32ul,
    Array(
        lambda ctx: ctx.num_chat,  # pre-game chat messages
        "messages" / Struct(
            "message_length" / Int32ul,
            "message" / Bytes(lambda ctx: ctx.message_length -
                              (1 if ctx.message_length > 0 else 0)),
            If(lambda ctx: ctx.message_length > 0, Padding(1)))),