Skip to content

Commit

Permalink
support 62.0
Browse files Browse the repository at this point in the history
  • Loading branch information
happyleavesaoc committed Jul 20, 2024
1 parent d20d7fe commit 8fb9969
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 32 deletions.
2 changes: 2 additions & 0 deletions mgz/fast/header.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ def parse_map(data, version, save):
tile_format = '<xbbx'
if version is Version.DE:
tile_format = '<bxb6x'
if save >= 62.0:
tile_format = '<bxxb6x'
data.read(8)
size_x, size_y, zone_num = unpack('<III', data)
tile_num = size_x * size_y
Expand Down
18 changes: 4 additions & 14 deletions mgz/header/initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@
from mgz.enums import MyDiplomacyEnum, TheirDiplomacyEnum
from mgz.header.objects import existing_object
from mgz.header.playerstats import player_stats
from mgz.util import Find, GotoObjectsEnd, RepeatUpTo, Version
from mgz.util import Find, GotoObjectsEnd, RepeatUpTo, Version, find_save_version

# Player attributes.
attributes = "attributes"/Struct(
"FF"/Bytes(12),
Array(lambda ctx: ctx._._._.replay.num_players, TheirDiplomacyEnum("their_diplomacy"/Byte)),
#Array(9, Int32sl), #MyDiplomacyEnum("my_diplomacy"/Int32sl)),
Array(lambda ctx: ctx._._._.replay.num_players if find_save_version(ctx) >= 61.5 else 9, MyDiplomacyEnum("my_diplomacy"/Int32sl)),
"allied_los"/Int32ul,
"allied_victory"/Flag,
"player_name_length"/Int16ul,
Expand Down Expand Up @@ -59,10 +58,6 @@
attributes,
"end_of_attr"/Tell,
"start_of_objects"/Find([b'\x0b\x00.\x00\x00\x00\x02\x00\x00'], None),
"objects"/Array(600, existing_object),
"next"/Bytes(40)
)
x = (
Embedded(IfThenElse(lambda ctx: ctx._.restore_time == 0,
Struct(
"objects"/RepeatUpTo(b'\x00', existing_object),
Expand Down Expand Up @@ -101,11 +96,6 @@
"num_particles"/Int32ul,
"particles"/Bytes(lambda ctx: ctx.num_particles * 27),
"identifier"/Int32ul,
Array(1, player),
"next"/Bytes(40),
#player,
)
x = (
#Array(lambda ctx: ctx._.replay.num_players, player),
#Padding(21),
Array(lambda ctx: ctx._.replay.num_players, player),
Padding(21),
)
3 changes: 1 addition & 2 deletions mgz/header/map_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"terrain_type"/Byte,
Embedded(IfThenElse(lambda ctx: ctx._._.version == Version.DE,
Embedded(Struct(
If(lambda ctx: ctx._._._.save_version >= 62.0, Byte),
Padding(1), # copy of previous byte
"elevation"/Byte,
"unk0"/Int16sl,
Expand All @@ -35,8 +36,6 @@
"size_x"/Int32ul,
"size_y"/Int32ul,
"tile_num"/Computed(lambda ctx: ctx.size_x * ctx.size_y),
)
x = (
"zone_num"/Int32ul,
Array(lambda ctx: ctx.zone_num, Struct(
IfThenElse(lambda ctx: ctx._._.version in (Version.DE, Version.HD),
Expand Down
15 changes: 5 additions & 10 deletions mgz/header/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@
If(lambda ctx: find_save_version(ctx) < 25.22 and find_type(ctx) == 10 and ctx.peek[0] == 0 and ctx.peek[0:2] != b"\x00\x0b", Bytes(1)),
If(lambda ctx: find_type(ctx) == 20 and ctx.peek[4] == 0 and ctx.peek[4:6] != b"\x00\x0b", Bytes(1)),
)),
"x"/Bytes(14)
If(lambda ctx: find_save_version(ctx) >= 61.5, Bytes(14)),
If(lambda ctx: find_save_version(ctx) >= 62.0, Bytes(4))
)),
"hd_extension"/If(lambda ctx: find_version(ctx) == Version.HD and find_save_version(ctx) > 12.36, Struct(
"flag"/Flag,
Expand Down Expand Up @@ -398,6 +399,7 @@
"de"/If(lambda ctx: find_version(ctx) == Version.DE, Bytes(14)),
"de_2"/If(lambda ctx: find_save_version(ctx) >= 26.16, Bytes(16)),
"de_3"/If(lambda ctx: find_save_version(ctx) >= 26.18, Bytes(1)),
"de_4"/If(lambda ctx: find_save_version(ctx) >= 61.5, Bytes(4)),
"next_volley"/Byte,
"using_special_animation"/Byte,
"own_base"/Byte,
Expand Down Expand Up @@ -430,15 +432,7 @@
"de_unknown3"/If(lambda ctx: 26.18 > find_save_version(ctx) >= 26.16, Bytes(5)),
"de_unknown4"/If(lambda ctx: find_save_version(ctx) >= 26.18, Bytes(4)),
"de_unknown5"/If(lambda ctx: find_save_version(ctx) >= 50, Bytes(48)),
#"nn"/Find(b'\x46', 1000)
"de_unknown6"/If(lambda ctx: find_save_version(ctx) >= 61.5, Struct(
"a"/Bytes(40),
"b"/Bytes(40),
"c"/Bytes(40),
"d"/Bytes(40),
"e"/Bytes(40),
"f"/Bytes(8)
)) #Bytes(208)),
"de_unknown6"/If(lambda ctx: find_save_version(ctx) >= 61.5, Bytes(44))
)

production_queue = "production_queue"/Struct(
Expand Down Expand Up @@ -484,6 +478,7 @@
"de_unk_3"/If(lambda ctx: find_save_version(ctx) >= 25.22, Byte),
"de_unk_4"/If(lambda ctx: find_save_version(ctx) >= 26.16, Bytes(4)),
"de_unk_5"/If(lambda ctx: find_save_version(ctx) >= 50.4, Bytes(4)),
"de_unk_6"/If(lambda ctx: find_save_version(ctx) >= 61.5, Bytes(12)),
)


Expand Down
5 changes: 4 additions & 1 deletion mgz/header/scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
scenario_header = "scenario_header"/Struct(
"next_uid"/Int32ul,
"scenario_version"/Float32l,
If(lambda ctx: find_save_version(ctx) >= 61.5, Padding(8)),
Array(16, "names"/String(256)),
Array(16, "player_ids"/Int32ul),
If(lambda ctx: find_save_version(ctx) >= 61.5, Padding(64)),
Array(16, "player_data"/Struct(
"active"/Int32ul,
"human"/Int32ul,
Expand Down Expand Up @@ -147,7 +149,8 @@
If(lambda ctx: 26.16 > find_save_version(ctx) >= 25.22, Find(struct.pack('<d', 2.6), None)),
If(lambda ctx: 26.21 > find_save_version(ctx) >= 26.16, Find(struct.pack('<d', 3.0), None)),
If(lambda ctx: 37 > find_save_version(ctx) >= 26.21, Find(struct.pack('<d', 3.2), None)),
If(lambda ctx: find_save_version(ctx) >= 37, Find(struct.pack('<d', 3.5), None))
If(lambda ctx: 61.5 > find_save_version(ctx) >= 37, Find(struct.pack('<d', 3.5), None)),
If(lambda ctx: find_save_version(ctx) >= 61.5, Find(struct.pack('<d', 3.6), None))
),
"end_of_game_settings"/Find(b'\x9a\x99\x99\x99\x99\x99\xf9\\x3f', None)
)
Expand Down
4 changes: 2 additions & 2 deletions mgz/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ def parse_match(handle):
data['map']['tiles'],
de_seed=data['lobby']['seed']
)
except ValueError:
raise RuntimeError("could not get map data")
except ValueError as e:
raise RuntimeError(f"could not get map data: {e}")

# Handle DE-specific data
rated = None
Expand Down
5 changes: 4 additions & 1 deletion mgz/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,10 @@ def _parse(self, stream, context, path):
marker -= 1
count += 1
# Backtrack through the rest of the next player structure
backtrack = 43 + num_players
offset = 9 * 4
if save_version >= 61.5:
offset = num_players * 4
backtrack = 7 + num_players + offset
# Otherwise, this is the last player
else:
# Search for the scenario header
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@

setup(
name='mgz',
version='1.8.25',
version='1.8.26',
description='Parse Age of Empires 2 recorded games.',
url='https://github.com/happyleavesaoc/aoc-mgz/',
license='MIT',
author='happyleaves',
author_email='[email protected]',
packages=find_packages(),
install_requires=[
'aocref>=2.0.17',
'aocref>=2.0.19',
'construct==2.8.16',
'dataclasses==0.8; python_version < "3.7"',
'tabulate>=0.9.0',
Expand Down
Binary file added tests/recs/de-62.0.aoe2record
Binary file not shown.

0 comments on commit 8fb9969

Please sign in to comment.