disables = "disables" / Struct( Padding(4), Padding(64), 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.
Padding(2), Peek("duration_int"/Int32ul), TimeSecAdapter("duration"/Int32ul), "cheats"/Flag, "complete"/Flag, 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)), )
"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, "lock_teams" / Flag, "lock_speed" / Flag, "multiplayer" / Flag, "cheats" / Flag, "record_game" / Flag, "animals_enabled" / Flag, "predators_enabled" / Flag, "turbo_enabled" / Flag, "shared_exploration" / Flag, "team_positions" / Flag, "unk" / Bytes(1), Embedded( IfThenElse(
If( 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))), )), If(lambda ctx: ctx._._.version == Version.DE, Bytes(196)), If(lambda ctx: ctx._._.version == Version.HD, Bytes(644)), "padding" / Bytes(12)) # Game settings. game_settings = "game_settings" / Struct( Array(16, AgeEnum("starting_ages" / Int32sl)), "hd" / If(lambda ctx: find_version(ctx) == Version.HD, Bytes(16)), 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, Struct( Padding(29), If(lambda ctx: find_save_version(ctx) >= 13.07, Padding(1)), If(lambda ctx: find_save_version(ctx) >= 13.34, Padding(132)), If(lambda ctx: find_save_version(ctx) >= 20.06, Padding(1)), If(lambda ctx: find_save_version(ctx) >= 20.16, Padding(4)), If(lambda ctx: find_save_version(ctx) >= 25.02, Padding(4 * 16)), If(lambda ctx: find_save_version(ctx) >= 25.06, Padding(4)))),
"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 - 2)), "ending_age_id"/Int32ul, "ending_age"/AgeEnum(Computed(lambda ctx: ctx.ending_age_id - 2)), "game_type"/Int32ul, separator, 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,
from construct import (Struct, Int32ul, Float32l, Array, Padding, Flag, Byte, Int16ul, Bytes, Int32sl, Peek, If) from mgz.enums import VictoryEnum, ResourceLevelEnum, AgeEnum # pylint: disable=invalid-name, bad-continuation de = "de" / Struct( "options" / Int32sl, "unk0" / Int32ul, "unk1" / Int32ul, "dlc_count" / Int32ul, "dlc_ids" / Array(lambda ctx: ctx.dlc_count, Int32ul), Padding(4), "difficulty" / Int32ul, "map_size" / Int32ul, "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, Padding(8), "speed" / Float32l, "treaty_length" / Int32ul, "population_limit" / Int32ul, "num_players" / Int32ul, "unknown2" / Int32ul, "unknown3" / Int32ul, Padding(4), "trade_enabled" / Flag, "team_bonus_disabled" / Flag, "random_positions" / Flag, "all_techs" / Flag, "num_starting_units" / Byte, "lock_teams" / Flag, "lock_speed" / Flag, "multiplayer" / Flag, "cheats" / Flag, "record_game" / Flag, "animals_enabled" / Flag, "predators_enabled" / Flag, Padding(6), "players" / Array( 8, Struct("dat_crc" / Bytes(4), "mp_version" / Byte, "color_id" / Int32sl, "civ_id" / Int32sl, Padding(23), "profile_id_length" / Int16ul, "profile_id" / Bytes(lambda ctx: ctx.profile_id_length), Padding(1), "humanity" / Int32sl, "steam_id" / Bytes(8), "p_index" / Int32sl, "unk3" / Int32sl,
"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, "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,