Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for recs version 63.0 and above #112

Merged
merged 3 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions mgz/fast/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ def parse_action_71094(action_type, player_id, raw):
selected, x, y, target_id, target_type = unpack('<h2xffii', data)
object_ids = list(unpack(f'{selected}I', data, shorten=False))
payload = dict(target_id=target_id, target_type=target_type, x=x, y=y, object_ids=object_ids)
if action_type is Action.DE_MULTI_GATHERPOINT:
target_id, x, y = unpack('<iff', data) # This is a best guess. There is other unknown data in the payload.
payload = dict(target_id=target_id, x=x, y=y)
if action_type is Action.STANCE:
selected, stance_id = unpack('<II', data)
object_ids = list(unpack(f'{selected}I', data, shorten=False))
Expand Down
1 change: 1 addition & 0 deletions mgz/fast/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class Action(Enum):
DE_TRANSFORM = 41
RATHA_ABILITY = 43
DE_107_A = 44
DE_MULTI_GATHERPOINT = 45
AI_COMMAND = 53
DE_UNKNOWN_80 = 80
MAKE = 100
Expand Down
12 changes: 11 additions & 1 deletion mgz/fast/header.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,8 @@ 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 >= 63:
settings_version = 3.9
if save >= 61.5:
settings_version = 3.6
elif save >= 37:
Expand Down Expand Up @@ -406,8 +408,13 @@ def parse_de(data, version, save, skip=False):
team_id = unpack('<b', data)
data.read(9)
civilization_id = unpack('<I', data)
custom_civ_selection = None
if save >= 61.5:
data.read(4)
custom_civ_count = unpack('<I', data)
if save >= 63.0 and custom_civ_count > 0:
custom_civ_selection = []
for _ in range(custom_civ_count):
custom_civ_selection.append(unpack('<I', data))
de_string(data)
data.read(1)
ai_name = de_string(data)
Expand All @@ -430,6 +437,7 @@ def parse_de(data, version, save, skip=False):
type=type,
profile_id=profile_id,
civilization_id=civilization_id,
custom_civ_selection=custom_civ_selection,
prefer_random=prefer_random == 1
))
data.read(12)
Expand Down Expand Up @@ -490,6 +498,8 @@ def parse_de(data, version, save, skip=False):
data.read(8)
if save >= 61.5:
data.read(1)
if save >= 63:
data.read(5)
if not skip:
de_string(data)
data.read(8)
Expand Down
6 changes: 4 additions & 2 deletions mgz/header/de.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from construct import (
Struct, Int32ul, Float32l, Array, Padding, Flag, If,
Byte, Int16ul, Bytes, Int32sl, Peek, Const, RepeatUntil,
Int64ul, Computed
Int64ul, Computed, IfThenElse
)

from mgz.enums import VictoryEnum, ResourceLevelEnum, AgeEnum, PlayerTypeEnum, DifficultyEnum
Expand All @@ -28,7 +28,8 @@
"dat_crc"/Bytes(8),
"mp_game_version"/Byte,
"civ_id"/Int32ul,
"unk"/If(lambda ctx: find_save_version(ctx) >= 61.5, Int32ul),
"custom_civ_count"/IfThenElse(lambda ctx: find_save_version(ctx) >= 61.5, Int32ul, Computed(lambda _: 0)),
"custom_civ_ids"/Array(lambda ctx: ctx.custom_civ_count, Int32ul),
"ai_type"/de_string,
"ai_civ_name_index"/Byte,
"ai_name"/de_string,
Expand Down Expand Up @@ -158,6 +159,7 @@
If(lambda ctx: find_save_version(ctx) >= 37, Bytes(3)),
If(lambda ctx: find_save_version(ctx) >= 50, Bytes(8)),
If(lambda ctx: find_save_version(ctx) >= 61.5, Flag),
If(lambda ctx: find_save_version(ctx) >= 63, Bytes(5)),
de_string,
Bytes(5),
If(lambda ctx: find_save_version(ctx) >= 13.13, Byte),
Expand Down
28 changes: 21 additions & 7 deletions mgz/header/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
)

animated_sprite = "animated_sprite"/Struct(
"animate_interval"/Int32ul,
"animate_interval"/Float32l,
"animate_last"/Int32ul,
"last_frame"/Int16ul,
"frame_changed"/Byte,
Expand Down Expand Up @@ -109,7 +109,7 @@
# not the right way to do this, needs improvement
If(lambda ctx: find_save_version(ctx) >= 20.16, Struct(
"peek"/Peek(Bytes(6)),
If(lambda ctx: find_save_version(ctx) >= 25.22 and find_type(ctx) == 10, Bytes(1)),
If(lambda ctx: find_save_version(ctx) >= 25.22 and (find_type(ctx) == 10 or find_save_version(ctx) >= 63.0), Bytes(1)),
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)),
)),
Expand Down Expand Up @@ -193,15 +193,16 @@
"user_defined_waypoints"/Array(lambda ctx: ctx.num_user_defined_waypoints, vector),
"has_substitute_position"/Int32ul,
"substitute_position"/vector,
"consecutive_subsitute_count"/Int32ul
"consecutive_substitute_count"/Int32ul
)

moving = "moving"/Struct(
Embedded(base_moving),
"hd_moving"/If(lambda ctx: find_version(ctx) == Version.HD, Bytes(1)),
"de_moving"/If(lambda ctx: find_version(ctx) == Version.DE, Bytes(17)),
"ver2616"/If(lambda ctx: 37 > find_save_version(ctx) >= 26.16, Bytes(8)),
"ver37"/If(lambda ctx: find_save_version(ctx) >= 37, Bytes(5)),
"ver37"/If(lambda ctx: 63 > find_save_version(ctx) >= 37, Bytes(5)),
"ver63"/If(lambda ctx: find_save_version(ctx) >= 63, Bytes(4)),
)

move_to = "move_to"/Struct(
Expand Down Expand Up @@ -389,7 +390,8 @@
"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)
"de_unk_byte"/If(lambda ctx: find_save_version(ctx) >= 25.22, Byte),
"de_unknown_2"/If(lambda ctx: find_save_version(ctx) >= 63.0 and ctx._.has_ai in (15, 17), Bytes(4))
)


Expand All @@ -398,7 +400,7 @@
"de_pre"/If(lambda ctx: find_version(ctx) == Version.DE and find_save_version(ctx) < 37, Bytes(4)),
"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_3"/If(lambda ctx: 63 > 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,
Expand Down Expand Up @@ -432,7 +434,19 @@
"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)),
"de_unknown6"/If(lambda ctx: find_save_version(ctx) >= 61.5, Bytes(44))
"de_unknown6"/If(lambda ctx: find_save_version(ctx) >= 61.5, Bytes(40)),
"de_unknown7"/If(lambda ctx: find_save_version(ctx) >= 61.5, Int16ul),
Embedded(
IfThenElse(lambda ctx: find_save_version(ctx) >= 63.0 and ctx.has_ai == 15,
Struct(
"de_unknown8"/Float32l,
"de_unknown9"/Bytes(4)
),
Struct(
"de_unknown8"/If(lambda ctx: find_save_version(ctx) >= 61.5, Bytes(2))
)
)
),
)

production_queue = "production_queue"/Struct(
Expand Down
3 changes: 3 additions & 0 deletions mgz/header/playerstats.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@
Embedded(If(lambda ctx: find_version(ctx) in (Version.DE, Version.HD), Struct(
Array(this._._.num_header_data - 198, Float32l)
))),
Embedded(If(lambda ctx: find_save_version(ctx) >= 63, Struct(
Array(this._._.num_header_data, Float32l)
))),
Embedded(If(lambda ctx: find_version(ctx) in [Version.USERPATCH15, Version.MCP], Struct(
ModVersionAdapter("mod"/Float32l),
Array(6, Float32l),
Expand Down
3 changes: 2 additions & 1 deletion mgz/header/scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@
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: 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))
If(lambda ctx: 63 > find_save_version(ctx) >= 61.5, Find(struct.pack('<d', 3.6), None)),
If(lambda ctx: find_save_version(ctx) >= 63, Find(struct.pack('<d', 3.9), None)),
),
"end_of_game_settings"/Find(b'\x9a\x99\x99\x99\x99\x99\xf9\\x3f', None)
)
Expand Down
Binary file added tests/recs/de-63.0.aoe2record
Binary file not shown.
Loading