Skip to content

Commit

Permalink
Merge branch 'master' of github.com:happyleavesaoc/aoc-mgz
Browse files Browse the repository at this point in the history
  • Loading branch information
happyleavesaoc committed Aug 31, 2022
2 parents 4a8dd94 + 44447e1 commit ace0250
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 30 deletions.
4 changes: 3 additions & 1 deletion mgz/fast/header.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,9 @@ def parse_scenario(data, num_players, version, save):
map_id, difficulty_id = unpack('<II', data)
remainder = data.read()
if version is Version.DE:
if save >= 26.16:
if save >= 26.21:
settings_version = 3.2
elif save >= 26.16:
settings_version = 3.0
elif save >= 25.22:
settings_version = 2.6
Expand Down
30 changes: 15 additions & 15 deletions mgz/header/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,30 +330,30 @@
)

unit_ai = "ai"/Struct(
"mood"/Int32ul,
"current_order"/Int32ul,
"current_order_priority"/Int32ul,
"current_action"/Int32ul,
"current_target"/Int32ul,
"current_target_type"/Int16ul,
"mood"/Int32sl,
"current_order"/Int32sl,
"current_order_priority"/Int32sl,
"current_action"/Int32sl,
"current_target"/Int32sl,
"current_target_type"/Int16sl,
Padding(2),
"current_target_location"/vector,
"desired_target_distance"/Float32l,
"last_action"/Int32ul,
"last_order"/Int32ul,
"last_target"/Int32ul,
"last_target_type"/Int32ul,
"last_update_type"/Int32ul,
"last_action"/Int32sl,
"last_order"/Int32sl,
"last_target"/Int32sl,
"last_target_type"/Int32sl,
"last_update_type"/Int32sl,
"idle_timer"/Int32ul,
"idle_timeout"/Int32ul,
"adjusted_idle_timeout"/Int32ul,
"secondary_timer"/Int32ul,
"look_around_timer"/Int32ul,
"look_around_timeout"/Int32ul,
"defend_target"/Int32ul,
"defend_target"/Int32sl,
"defense_buffer"/Float32l,
"last_world_position"/waypoint,
"de_2006_unk"/If(lambda ctx: find_save_version(ctx) >= 20.06, Struct(
"de_2006_unk"/If(lambda ctx: 26.21 > find_save_version(ctx) >= 20.06, Struct(
"unk_float"/Float32l,
"unk"/Int32ul
)),
Expand All @@ -369,7 +369,7 @@
"state_position_y"/Float32l,
"time_since_enemy_sighting"/Int32ul,
"alert_mode"/Byte,
"alert_mode_object_id"/Int32ul,
"alert_mode_object_id"/Int32sl,
"has_patrol_path"/Int32ul,
If(lambda ctx: ctx.has_patrol_path > 0, path),
"patrol_current_waypoint"/Int32ul,
Expand All @@ -379,7 +379,7 @@
"randomized_retarget_timer"/Int32ul,
"num_retarget_entries"/Int32ul,
"retarget_entries"/Array(lambda ctx: ctx.num_retarget_entries, retarget),
"best_unit_to_attack"/Int32ul,
"best_unit_to_attack"/Int32sl,
"formation_type"/Byte,
"de_unk"/If(lambda ctx: find_version(ctx) == Version.DE, Bytes(4)),
"de_unk_byte"/If(lambda ctx: find_save_version(ctx) >= 25.22, Byte)
Expand Down
19 changes: 10 additions & 9 deletions mgz/header/scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@

# Scenarios have intro text, a bitmap, and cinematics.
messages = "messages"/Struct(
"instruction_id"/Int32ul,
"hints_id"/Int32ul,
"victory_id"/Int32ul,
"defeat_id"/Int32ul,
"history_id"/Int32ul,
"scouts_id"/If(lambda ctx: ctx._._.version != Version.AOK, Int32ul),
"instruction_id"/Int32sl,
"hints_id"/Int32sl,
"victory_id"/Int32sl,
"defeat_id"/Int32sl,
"history_id"/Int32sl,
"scouts_id"/If(lambda ctx: ctx._._.version != Version.AOK, Int32sl),
"instructions_length"/Int16ul,
"instructions"/Bytes(lambda ctx: ctx.instructions_length),
"hints"/PascalString(lengthfield="hints_length"/Int16ul),
Expand Down Expand Up @@ -129,11 +129,11 @@
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))
If(lambda ctx: 26.21 > find_save_version(ctx) >= 25.06, Padding(4))
)
),
Array(9, "player_info"/Struct(
"data_ref"/Int32ul,
"slot"/Int32sl,
PlayerTypeEnum("type"/Int32ul),
"name"/PascalString(lengthfield="name_length"/Int32ul)
)),
Expand All @@ -145,7 +145,8 @@
If(lambda ctx: 25.06 > find_save_version(ctx) >= 13.34, Find(struct.pack('<d', 2.4), None)),
If(lambda ctx: 25.22 > find_save_version(ctx) >= 25.06, Find(struct.pack('<d', 2.5), None)),
If(lambda ctx: 26.16 > find_save_version(ctx) >= 25.22, Find(struct.pack('<d', 2.6), None)),
If(lambda ctx: find_save_version(ctx) >= 26.16, Find(struct.pack('<d', 3.0), None))
If(lambda ctx: 26.21 > find_save_version(ctx) >= 26.16, Find(struct.pack('<d', 3.0), None)),
If(lambda ctx: find_save_version(ctx) >= 26.21, Find(struct.pack('<d', 3.2), None))
),
"end_of_game_settings"/Find(b'\x9a\x99\x99\x99\x99\x99\xf9\\x3f', None)
)
Expand Down
11 changes: 10 additions & 1 deletion mgz/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@ def get_starting_age(data):
return data['de']['starting_age_id']
return None


def get_map_id(data):
if data['version'] is Version.HD:
return data['hd']['map_id']
if data['version'] is Version.DE:
return data['de']['rms_map_id']
return data['scenario']['map_id']


def get_hash(data):
if data['version'] is Version.DE:
return data['de']['hash']
Expand All @@ -96,7 +105,7 @@ def parse_match(handle):
consts = get_consts()

dataset_id, dataset = get_dataset(data['version'], data['mod'])
map_id = data['hd']['map_id'] if data['version'] is Version.HD else data['scenario']['map_id']
map_id = get_map_id(data)
try:
map_data, encoding, language = get_map_data(
map_id,
Expand Down
10 changes: 9 additions & 1 deletion mgz/summary/full.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,12 +311,20 @@ def get_language(self):
self.get_map()
return self._cache['language']

def get_map_id(self):
"""Get map ID."""
if self._header.hd:
return self._header.hd.selected_map_id
if self._header.de:
return self._header.de.selected_map_id
return self._header.scenario.game_settings.map_id

def get_map(self):
"""Get map."""
tiles = tiles = [(tile.terrain_type, tile.elevation) for tile in self._header.map_info.tile]
if not self._cache['map']:
self._cache['map'], self._cache['encoding'], self._cache['language'] = get_map_data(
self._header.hd.selected_map_id if self._header.hd else self._header.scenario.game_settings.map_id,
self.get_map_id(),
self._header.scenario.messages.instructions,
self._header.map_info.size_x,
self._header.version,
Expand Down
4 changes: 3 additions & 1 deletion mgz/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,9 @@ def _parse(self, stream, context, path):
marker_aok = read_bytes.find(b"\x9a\x99\x99\x3f")
marker_up = read_bytes.find(b"\xf6\x28\x9c\x3f")
marker_hd = read_bytes.find(b"\xae\x47\xa1\x3f")
if save_version >= 26.16:
if save_version >= 26.21:
marker_de = read_bytes.find(b"\xf6\x28\xbc\x3f")
elif save_version >= 26.16:
marker_de = read_bytes.find(b"\x48\xe1\xba\x3f")
elif save_version >= 25.06:
marker_de = read_bytes.find(b"\x9a\x99\xb9\x3f")
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

setup(
name='mgz',
version='1.7.7',
version='1.7.10',
description='Parse Age of Empires 2 recorded games.',
url='https://github.com/happyleavesaoc/aoc-mgz/',
license='MIT',
Expand All @@ -12,7 +12,7 @@
packages=find_packages(),
install_requires=[
'aiohttp>=3.6.2',
'aocref>=2.0.5',
'aocref>=2.0.6',
'construct==2.8.16',
'dataclasses==0.8; python_version < "3.7"',
'flatbuffers>=1.10',
Expand Down
Binary file added tests/recs/de-26.21.aoe2record
Binary file not shown.

0 comments on commit ace0250

Please sign in to comment.