# Path: mgz/enums.py
# def VictoryEnum(ctx):
#     """Victory Type Enumeration."""
#     return Enum(
#         ctx,
#         standard=0,
#         conquest=1,
#         exploration=2,
#         ruins=3,
#         artifacts=4,
#         discoveries=5,
#         gold=6,
#         time_limit=7,
#         score=8,
#         standard2=9,
#         regicide=10,
#         last_man=11
#     )
# 
# def ResourceLevelEnum(ctx):
#     """Resource Level Enumeration."""
#     return Enum(
#         ctx,
#         none=-1,
#         standard=0,
#         low=1,
#         medium=2,
#         high=3,
#         unknown1=4,
#         unknown2=5,
#         unknown3=6
#     )
# 
# def AgeEnum(ctx):
#     """Age Enumeration."""
#     return Enum(
#         ctx,
#         what=-2,
#         unset=-1,
#         dark=0,
#         feudal=1,
#         castle=2,
#         imperial=3,
#         postimperial=4,
#         dmpostimperial=6,
#         default='unknown'
#     )
# 
# def PlayerTypeEnum(ctx):
#     """Player Type Enumeration."""
#     return Enum(
#         ctx,
#         absent=0,
#         closed=1,
#         human=2,
#         eliminated=3,
#         computer=4,
#         cyborg=5,
#         spectator=6
#     )
# 
# def DifficultyEnum(ctx):
#     """Difficulty Enumeration."""
#     return Enum(
#         ctx,
#         hardest=0,
#         hard=1,
#         moderate=2,
#         standard=3,
#         easiest=4,
#         extreme=5,
#         unknown=6
#     )
# 
# Path: mgz/util.py
# def find_save_version(ctx):
#     """Find save version."""
#     if 'save_version' not in ctx:
#         return find_save_version(ctx._)
#     return ctx.save_version


from construct import (
    Struct, Int32ul, Float32l, Array, Padding, Flag, If,
    Byte, Int16ul, Bytes, Int32sl, Peek, Const, RepeatUntil,
    Int64ul, Computed
)
from mgz.enums import VictoryEnum, ResourceLevelEnum, AgeEnum, PlayerTypeEnum, DifficultyEnum
from mgz.util import find_save_version
    "profile_id"/Int32ul,
    Const(b"\x00\x00\x00\x00"),
    "player_number"/Int32sl,
    "hd_rm_elo"/If(lambda ctx: find_save_version(ctx) < 25.22, Int32ul),
    "hd_dm_elo"/If(lambda ctx: find_save_version(ctx) < 25.22, Int32ul),
    "prefer_random"/Flag,
    "custom_ai"/Flag,
    If(lambda ctx: find_save_version(ctx) >= 25.06, "handicap"/Bytes(8)),
)

de = "de"/Struct(
    "build"/If(lambda ctx: find_save_version(ctx) >= 25.22, Int32ul),
    "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 - 2)),
    "ending_age_id"/Int32ul,

# Path: mgz/enums.py
# def VictoryEnum(ctx):
#     """Victory Type Enumeration."""
#     return Enum(
#         ctx,
#         standard=0,
#         conquest=1,
#         exploration=2,
#         ruins=3,
#         artifacts=4,
#         discoveries=5,
#         gold=6,
#         time_limit=7,
#         score=8,
#         standard2=9,
#         regicide=10,
#         last_man=11
#     )
# 
# def ResourceLevelEnum(ctx):
#     """Resource Level Enumeration."""
#     return Enum(
#         ctx,
#         none=-1,
#         standard=0,
#         low=1,
#         medium=2,
#         high=3,
#         unknown1=4,
#         unknown2=5,
#         unknown3=6
#     )
# 
# def AgeEnum(ctx):
#     """Age Enumeration."""
#     return Enum(
#         ctx,
#         what=-2,
#         unset=-1,
#         dark=0,
#         feudal=1,
#         castle=2,
#         imperial=3,
#         postimperial=4,
#         dmpostimperial=6,
#         default='unknown'
#     )
# 
# def PlayerTypeEnum(ctx):
#     """Player Type Enumeration."""
#     return Enum(
#         ctx,
#         absent=0,
#         closed=1,
#         human=2,
#         eliminated=3,
#         computer=4,
#         cyborg=5,
#         spectator=6
#     )
# 
# def DifficultyEnum(ctx):
#     """Difficulty Enumeration."""
#     return Enum(
#         ctx,
#         hardest=0,
#         hard=1,
#         moderate=2,
#         standard=3,
#         easiest=4,
#         extreme=5,
#         unknown=6
#     )
# 
# Path: mgz/util.py
# def find_save_version(ctx):
#     """Find save version."""
#     if 'save_version' not in ctx:
#         return find_save_version(ctx._)
#     return ctx.save_version


# Path: mgz/header/de.py
from construct import (
    Struct, Int32ul, Float32l, Array, Padding, Flag, If,
    Byte, Int16ul, Bytes, Int32sl, Peek, Const, RepeatUntil,
    Int64ul, Computed
)
from mgz.enums import VictoryEnum, ResourceLevelEnum, AgeEnum, PlayerTypeEnum, DifficultyEnum
from mgz.util import find_save_version

    "profile_id"/Int32ul,
    Const(b"\x00\x00\x00\x00"),
    "player_number"/Int32sl,
    "hd_rm_elo"/If(lambda ctx: find_save_version(ctx) < 25.22, Int32ul),
    "hd_dm_elo"/If(lambda ctx: find_save_version(ctx) < 25.22, Int32ul),
    "prefer_random"/Flag,
    "custom_ai"/Flag,
    If(lambda ctx: find_save_version(ctx) >= 25.06, "handicap"/Bytes(8)),
)

de = "de"/Struct(
    "build"/If(lambda ctx: find_save_version(ctx) >= 25.22, Int32ul),
    "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 - 2)),
    "ending_age_id"/Int32ul,

    "ending_age"/AgeEnum(Computed(lambda ctx: ctx.ending_age_id - 2)),