Skip to content

Commit 857d7c9

Browse files
Merge pull request #112 from Kjir/master
Add support for recs version 63.0 and above
2 parents 90e0581 + 46f116d commit 857d7c9

File tree

8 files changed

+45
-11
lines changed

8 files changed

+45
-11
lines changed

mgz/fast/actions.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ def parse_action_71094(action_type, player_id, raw):
5151
selected, x, y, target_id, target_type = unpack('<h2xffii', data)
5252
object_ids = list(unpack(f'{selected}I', data, shorten=False))
5353
payload = dict(target_id=target_id, target_type=target_type, x=x, y=y, object_ids=object_ids)
54+
if action_type is Action.DE_MULTI_GATHERPOINT:
55+
target_id, x, y = unpack('<iff', data) # This is a best guess. There is other unknown data in the payload.
56+
payload = dict(target_id=target_id, x=x, y=y)
5457
if action_type is Action.STANCE:
5558
selected, stance_id = unpack('<II', data)
5659
object_ids = list(unpack(f'{selected}I', data, shorten=False))

mgz/fast/enums.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class Action(Enum):
4545
DE_TRANSFORM = 41
4646
RATHA_ABILITY = 43
4747
DE_107_A = 44
48+
DE_MULTI_GATHERPOINT = 45
4849
AI_COMMAND = 53
4950
DE_UNKNOWN_80 = 80
5051
MAKE = 100

mgz/fast/header.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,8 @@ def parse_scenario(data, num_players, version, save):
277277
map_id, difficulty_id = unpack('<II', data)
278278
remainder = data.read()
279279
if version is Version.DE:
280+
if save >= 63:
281+
settings_version = 3.9
280282
if save >= 61.5:
281283
settings_version = 3.6
282284
elif save >= 37:
@@ -406,8 +408,13 @@ def parse_de(data, version, save, skip=False):
406408
team_id = unpack('<b', data)
407409
data.read(9)
408410
civilization_id = unpack('<I', data)
411+
custom_civ_selection = None
409412
if save >= 61.5:
410-
data.read(4)
413+
custom_civ_count = unpack('<I', data)
414+
if save >= 63.0 and custom_civ_count > 0:
415+
custom_civ_selection = []
416+
for _ in range(custom_civ_count):
417+
custom_civ_selection.append(unpack('<I', data))
411418
de_string(data)
412419
data.read(1)
413420
ai_name = de_string(data)
@@ -430,6 +437,7 @@ def parse_de(data, version, save, skip=False):
430437
type=type,
431438
profile_id=profile_id,
432439
civilization_id=civilization_id,
440+
custom_civ_selection=custom_civ_selection,
433441
prefer_random=prefer_random == 1
434442
))
435443
data.read(12)
@@ -490,6 +498,8 @@ def parse_de(data, version, save, skip=False):
490498
data.read(8)
491499
if save >= 61.5:
492500
data.read(1)
501+
if save >= 63:
502+
data.read(5)
493503
if not skip:
494504
de_string(data)
495505
data.read(8)

mgz/header/de.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from construct import (
44
Struct, Int32ul, Float32l, Array, Padding, Flag, If,
55
Byte, Int16ul, Bytes, Int32sl, Peek, Const, RepeatUntil,
6-
Int64ul, Computed
6+
Int64ul, Computed, IfThenElse
77
)
88

99
from mgz.enums import VictoryEnum, ResourceLevelEnum, AgeEnum, PlayerTypeEnum, DifficultyEnum
@@ -28,7 +28,8 @@
2828
"dat_crc"/Bytes(8),
2929
"mp_game_version"/Byte,
3030
"civ_id"/Int32ul,
31-
"unk"/If(lambda ctx: find_save_version(ctx) >= 61.5, Int32ul),
31+
"custom_civ_count"/IfThenElse(lambda ctx: find_save_version(ctx) >= 61.5, Int32ul, Computed(lambda _: 0)),
32+
"custom_civ_ids"/Array(lambda ctx: ctx.custom_civ_count, Int32ul),
3233
"ai_type"/de_string,
3334
"ai_civ_name_index"/Byte,
3435
"ai_name"/de_string,
@@ -158,6 +159,7 @@
158159
If(lambda ctx: find_save_version(ctx) >= 37, Bytes(3)),
159160
If(lambda ctx: find_save_version(ctx) >= 50, Bytes(8)),
160161
If(lambda ctx: find_save_version(ctx) >= 61.5, Flag),
162+
If(lambda ctx: find_save_version(ctx) >= 63, Bytes(5)),
161163
de_string,
162164
Bytes(5),
163165
If(lambda ctx: find_save_version(ctx) >= 13.13, Byte),

mgz/header/objects.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
)
2222

2323
animated_sprite = "animated_sprite"/Struct(
24-
"animate_interval"/Int32ul,
24+
"animate_interval"/Float32l,
2525
"animate_last"/Int32ul,
2626
"last_frame"/Int16ul,
2727
"frame_changed"/Byte,
@@ -109,7 +109,7 @@
109109
# not the right way to do this, needs improvement
110110
If(lambda ctx: find_save_version(ctx) >= 20.16, Struct(
111111
"peek"/Peek(Bytes(6)),
112-
If(lambda ctx: find_save_version(ctx) >= 25.22 and find_type(ctx) == 10, Bytes(1)),
112+
If(lambda ctx: find_save_version(ctx) >= 25.22 and (find_type(ctx) == 10 or find_save_version(ctx) >= 63.0), Bytes(1)),
113113
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)),
114114
If(lambda ctx: find_type(ctx) == 20 and ctx.peek[4] == 0 and ctx.peek[4:6] != b"\x00\x0b", Bytes(1)),
115115
)),
@@ -193,15 +193,16 @@
193193
"user_defined_waypoints"/Array(lambda ctx: ctx.num_user_defined_waypoints, vector),
194194
"has_substitute_position"/Int32ul,
195195
"substitute_position"/vector,
196-
"consecutive_subsitute_count"/Int32ul
196+
"consecutive_substitute_count"/Int32ul
197197
)
198198

199199
moving = "moving"/Struct(
200200
Embedded(base_moving),
201201
"hd_moving"/If(lambda ctx: find_version(ctx) == Version.HD, Bytes(1)),
202202
"de_moving"/If(lambda ctx: find_version(ctx) == Version.DE, Bytes(17)),
203203
"ver2616"/If(lambda ctx: 37 > find_save_version(ctx) >= 26.16, Bytes(8)),
204-
"ver37"/If(lambda ctx: find_save_version(ctx) >= 37, Bytes(5)),
204+
"ver37"/If(lambda ctx: 63 > find_save_version(ctx) >= 37, Bytes(5)),
205+
"ver63"/If(lambda ctx: find_save_version(ctx) >= 63, Bytes(4)),
205206
)
206207

207208
move_to = "move_to"/Struct(
@@ -389,7 +390,8 @@
389390
"best_unit_to_attack"/Int32sl,
390391
"formation_type"/Byte,
391392
"de_unk"/If(lambda ctx: find_version(ctx) == Version.DE, Bytes(4)),
392-
"de_unk_byte"/If(lambda ctx: find_save_version(ctx) >= 25.22, Byte)
393+
"de_unk_byte"/If(lambda ctx: find_save_version(ctx) >= 25.22, Byte),
394+
"de_unknown_2"/If(lambda ctx: find_save_version(ctx) >= 63.0 and ctx._.has_ai in (15, 17), Bytes(4))
393395
)
394396

395397

@@ -398,7 +400,7 @@
398400
"de_pre"/If(lambda ctx: find_version(ctx) == Version.DE and find_save_version(ctx) < 37, Bytes(4)),
399401
"de"/If(lambda ctx: find_version(ctx) == Version.DE, Bytes(14)),
400402
"de_2"/If(lambda ctx: find_save_version(ctx) >= 26.16, Bytes(16)),
401-
"de_3"/If(lambda ctx: find_save_version(ctx) >= 26.18, Bytes(1)),
403+
"de_3"/If(lambda ctx: 63 > find_save_version(ctx) >= 26.18, Bytes(1)),
402404
"de_4"/If(lambda ctx: find_save_version(ctx) >= 61.5, Bytes(4)),
403405
"next_volley"/Byte,
404406
"using_special_animation"/Byte,
@@ -432,7 +434,19 @@
432434
"de_unknown3"/If(lambda ctx: 26.18 > find_save_version(ctx) >= 26.16, Bytes(5)),
433435
"de_unknown4"/If(lambda ctx: find_save_version(ctx) >= 26.18, Bytes(4)),
434436
"de_unknown5"/If(lambda ctx: find_save_version(ctx) >= 50, Bytes(48)),
435-
"de_unknown6"/If(lambda ctx: find_save_version(ctx) >= 61.5, Bytes(44))
437+
"de_unknown6"/If(lambda ctx: find_save_version(ctx) >= 61.5, Bytes(40)),
438+
"de_unknown7"/If(lambda ctx: find_save_version(ctx) >= 61.5, Int16ul),
439+
Embedded(
440+
IfThenElse(lambda ctx: find_save_version(ctx) >= 63.0 and ctx.has_ai == 15,
441+
Struct(
442+
"de_unknown8"/Float32l,
443+
"de_unknown9"/Bytes(4)
444+
),
445+
Struct(
446+
"de_unknown8"/If(lambda ctx: find_save_version(ctx) >= 61.5, Bytes(2))
447+
)
448+
)
449+
),
436450
)
437451

438452
production_queue = "production_queue"/Struct(

mgz/header/playerstats.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,9 @@
214214
Embedded(If(lambda ctx: find_version(ctx) in (Version.DE, Version.HD), Struct(
215215
Array(this._._.num_header_data - 198, Float32l)
216216
))),
217+
Embedded(If(lambda ctx: find_save_version(ctx) >= 63, Struct(
218+
Array(this._._.num_header_data, Float32l)
219+
))),
217220
Embedded(If(lambda ctx: find_version(ctx) in [Version.USERPATCH15, Version.MCP], Struct(
218221
ModVersionAdapter("mod"/Float32l),
219222
Array(6, Float32l),

mgz/header/scenario.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@
150150
If(lambda ctx: 26.21 > find_save_version(ctx) >= 26.16, Find(struct.pack('<d', 3.0), None)),
151151
If(lambda ctx: 37 > find_save_version(ctx) >= 26.21, Find(struct.pack('<d', 3.2), None)),
152152
If(lambda ctx: 61.5 > find_save_version(ctx) >= 37, Find(struct.pack('<d', 3.5), None)),
153-
If(lambda ctx: find_save_version(ctx) >= 61.5, Find(struct.pack('<d', 3.6), None))
153+
If(lambda ctx: 63 > find_save_version(ctx) >= 61.5, Find(struct.pack('<d', 3.6), None)),
154+
If(lambda ctx: find_save_version(ctx) >= 63, Find(struct.pack('<d', 3.9), None)),
154155
),
155156
"end_of_game_settings"/Find(b'\x9a\x99\x99\x99\x99\x99\xf9\\x3f', None)
156157
)

tests/recs/de-63.0.aoe2record

2.86 MB
Binary file not shown.

0 commit comments

Comments
 (0)