Example #1
0
    IfThenElse(
        lambda ctx: ctx._._.version != Version.DE,
        Struct(
            Array(16, "num_disabled_techs" / Int32ul),
            Array(16, Array(30, Padding(4))),
            Array(16, "num_disabled_units" / Int32ul),
            Array(16, Array(30, Padding(4))),
            Array(16, "num_disabled_buildings" / Int32ul),
            Array(16, Array(20, Padding(4))),
        ), Padding(196)), Padding(12))

# Game settings.
game_settings = "game_settings" / Struct(
    Array(16, AgeEnum("starting_ages" / Int32sl)), Padding(4), Padding(8),
    "map_id" / If(lambda ctx: ctx._._.version != Version.AOK, Int32ul),
    Peek("difficulty_id" / Int32ul), DifficultyEnum(
        "difficulty" / Int32ul), "lock_teams" / Int32ul,
    If(lambda ctx: ctx._._.version == Version.DE, Padding(29)),
    Array(
        9, "player_info" /
        Struct("data_ref" / Int32ul, PlayerTypeEnum("type" / Int32ul),
               "name" / PascalString(lengthfield="name_length" / Int32ul))),
    Padding(36), Padding(4),
    IfThenElse(
        lambda ctx: ctx._._.version == Version.DE, "end_of_game_settings" /
        Find(b'\x9a\x99\x99\x99\x99\x99\x01\x40', None), "end_of_game_settings"
        / Find(b'\x9a\x99\x99\x99\x99\x99\xf9\x3f', None)))

# Triggers.
triggers = "triggers" / Struct(
    Padding(1),
    "num_triggers" / Int32ul,
Example #2
0
    IfThenElse(
        lambda ctx: ctx._._.version != 'VER 9.4',
        Struct(
            Array(16, "num_disabled_techs" / Int32ul),
            Array(16, Array(30, Padding(4))),
            Array(16, "num_disabled_units" / Int32ul),
            Array(16, Array(30, Padding(4))),
            Array(16, "num_disabled_buildings" / Int32ul),
            Array(16, Array(20, Padding(4))),
        ), Padding(196)), Padding(12))

# Game settings.
game_settings = "game_settings" / Struct(
    Array(16, AgeEnum("starting_ages" / Int32sl)), Padding(4), Padding(8),
    "map_id" / Int32ul, Peek("difficulty_id" / Int32ul),
    DifficultyEnum("difficulty" / Int32ul), "lock_teams" / Int32ul,
    If(lambda ctx: ctx._._.version == 'VER 9.4', Padding(29)),
    Array(
        9, "player_info" /
        Struct("data_ref" / Int32ul, PlayerTypeEnum("type" / Int32ul),
               "name" / PascalString(lengthfield="name_length" / Int32ul))),
    Padding(36), Padding(4),
    IfThenElse(
        lambda ctx: ctx._._.version == 'VER 9.4', "end_of_game_settings" /
        Find(b'\x9a\x99\x99\x99\x99\x99\x01\x40', None), "end_of_game_settings"
        / Find(b'\x9a\x99\x99\x99\x99\x99\xf9\x3f', None)))

# Triggers.
triggers = "triggers" / Struct(
    Padding(1),
    "num_triggers" / Int32ul,
Example #3
0
    Array(16, "num_disabled_techs" / Int32ul),
    Array(16, Array(30, Padding(4))),
    Array(16, "num_disabled_units" / Int32ul),
    Array(16, Array(30, Padding(4))),
    Array(16, "num_disabled_buildings" / Int32ul),
    Array(16, Array(20, Padding(4))),
    Padding(12),
)

# Game settings.
game_settings = "game_settings" / Struct(
    Array(16, StartingAgeEnum("starting_ages" / Int32sl)),
    Padding(4),
    Padding(8),
    "map_id" / Int32ul,
    DifficultyEnum("difficulty" / Int32ul),
    Padding(4),
    Array(
        9, "player_info" /
        Struct("data_ref" / Int32ul, PlayerTypeEnum("type" / Int32ul),
               "name" / PascalString(lengthfield="name_length" / Int32ul))),
    Padding(36),
    Padding(4),
    "end_of_game_settings" / Find(b'\x9a\x99\x99\x99\x99\x99\xf9\x3f', None),
)

# Triggers.
triggers = "triggers" / Struct(
    Padding(1),
    "num_triggers" / Int32ul,
    # parse if num > 0
Example #4
0
    "ai_name" / If(lambda ctx: ctx._._.version >= 1005, hd_string),
    "name" / hd_string, "type" / PlayerTypeEnum(Int32ul), "steam_id" / Int64ul,
    "player_number" / Int32sl,
    Embedded(
        If(lambda ctx: ctx._._.version >= 1006 and not ctx._.test_57.is_57,
           Struct(
               "hd_rm_rating" / Int32ul,
               "hd_dm_rating" / Int32ul,
           ))))

hd = "hd" / Struct(
    "version" / Float32l, "interval_version" / Int32ul,
    "game_options_version" / Int32ul, "dlc_count" / Int32ul,
    "dlc_ids" / Array(lambda ctx: ctx.dlc_count, Int32ul),
    "dataset_ref" / Int32ul, Peek("difficulty_id" / Int32ul),
    DifficultyEnum("difficulty" / Int32ul), "selected_map_id" / Int32ul,
    "resolved_map_id" / Int32ul, "reveal_map" / Int32ul,
    Peek("victory_type_id" / Int32ul), VictoryEnum("victory_type" / Int32ul),
    Peek("starting_resources_id" / Int32ul),
    ResourceLevelEnum("starting_resources" / Int32ul),
    "starting_age_id" / Int32ul, "starting_age" /
    AgeEnum(Computed(lambda ctx: ctx.starting_age_id)), "ending_age_id" /
    Int32ul, "ending_age" / AgeEnum(Computed(lambda ctx: ctx.ending_age_id)),
    "game_type" / If(lambda ctx: ctx.version >= 1006, Int32ul), separator,
    "ver1000" / If(lambda ctx: ctx.version == 1000,
                   Struct("map_name" / hd_string, "unk" / hd_string)),
    separator, "speed" / Float32l, "treaty_length" / Int32ul,
    "population_limit" / Int32ul, "num_players" / Int32ul,
    "unused_player_color" / Int32ul, "victory_amount" / Int32ul, separator,
    "trade_enabled" / Flag, "team_bonus_disabled" / Flag,
    "random_positions" / Flag, "all_techs" / Flag, "num_starting_units" / Byte,
Example #5
0
# pylint: disable=invalid-name, bad-continuation

de_string = Struct(Const(b"\x60\x0A"), "length" / Int16ul,
                   "value" / Bytes(lambda ctx: ctx.length))

separator = Const(b"\xa3_\x02\x00")

de = "de" / Struct(
    "version" / Float32l,
    "interval_version" / Int32ul,
    "game_options_version" / Int32ul,
    "dlc_count" / Int32ul,
    "dlc_ids" / Array(lambda ctx: ctx.dlc_count, Int32ul),
    "dataset_ref" / Int32ul,
    "difficulty" / DifficultyEnum(Int32ul),
    "selected_map_id" / Int32ul,
    "resolved_map_id" / Int32ul,
    "reveal_map" / Int32ul,
    Peek("victory_type_id" / Int32ul),
    VictoryEnum("victory_type" / Int32ul),
    Peek("starting_resources_id" / Int32ul),
    ResourceLevelEnum("starting_resources" / Int32ul),
    Peek("starting_age_id" / Int32ul),
    AgeEnum("starting_age" / Int32ul),
    Peek("ending_age_id" / Int32ul),
    AgeEnum("ending_age" / Int32ul),
    "game_type" / Int32ul,
    separator,
    separator,
    "speed" / Float32l,