Skip to content

Commit 4ffe9ad

Browse files
de string block
1 parent 44cd0a6 commit 4ffe9ad

File tree

5 files changed

+31
-19
lines changed

5 files changed

+31
-19
lines changed

mgz/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ async def extract_rec(playback, path, select=None):
7575
def print_info(path):
7676
"""Print basic info."""
7777
with open(path, 'rb') as handle:
78-
summary = Summary(handle)
78+
summary = Summary(handle, fallback=True)
7979
dataset = summary.get_dataset()
8080
print('-------------')
8181
print(tabulate([

mgz/fast/header.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,17 @@ def parse_scenario(data, num_players, version, save):
273273
)
274274

275275

276+
def string_block(data):
277+
"""Parse DE header string block."""
278+
strings = []
279+
while True:
280+
crc = unpack("<I", data)
281+
if crc == 47:
282+
break
283+
strings.append(de_string(data).decode('utf-8').split(':'))
284+
return strings
285+
286+
276287
def parse_de(data, version, save, skip=False):
277288
"""Parse DE-specific header."""
278289
if version is not Version.DE:
@@ -335,13 +346,12 @@ def parse_de(data, version, save, skip=False):
335346
hidden_civs = unpack('b', data)
336347
data.read(1)
337348
spec_delay = unpack('<I', data)
338-
data.read(5)
339-
strings = []
340-
for _ in range(23):
341-
strings.append(de_string(data).decode('utf-8').split(':'))
342-
c = unpack('<I', data)
343-
while c in [3, 21, 23, 42, 44, 45, 46, 47]:
344-
c = unpack('<I', data)
349+
data.read(1)
350+
strings = string_block(data)
351+
data.read(8)
352+
for _ in range(20):
353+
strings += string_block(data)
354+
data.read(4)
345355
if save < 25.22:
346356
data.read(236)
347357
if save >= 25.22:

mgz/header/de.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@
4343
If(lambda ctx: find_save_version(ctx) >= 25.06, "handicap"/Bytes(8)),
4444
)
4545

46+
string_block = Struct(
47+
"strings"/RepeatUntil(lambda x, lst, ctx: lst[-1].crc == 47, Struct(
48+
"crc"/Int32ul,
49+
"string"/If(lambda ctx: ctx.crc != 47, de_string)
50+
))
51+
)
52+
4653
de = "de"/Struct(
4754
"build"/If(lambda ctx: find_save_version(ctx) >= 25.22, Int32ul),
4855
"timestamp"/If(lambda ctx: find_save_version(ctx) >= 26.16, Int32ul),
@@ -107,15 +114,10 @@
107114
"matchmaking"/Flag,
108115
"spec_delay"/Int32ul,
109116
"scenario_civ"/If(lambda ctx: find_save_version(ctx) >= 13.13, Byte),
110-
"rms_crc"/If(lambda ctx: find_save_version(ctx) >= 13.13, Bytes(4)),
111-
"strings"/Array(23,
112-
Struct(
113-
"string"/de_string,
114-
"nums"/RepeatUntil(lambda x, lst, ctx: lst[-1] not in [3, 21, 23, 42, 44, 45, 46, 47], Int32ul)
115-
)
116-
),
117-
# There's probably a right way to do this, but this is not it.
118-
"num_sn"/Computed(lambda ctx: ctx.strings[22].nums[1]),
117+
"rms_strings"/string_block,
118+
Bytes(8),
119+
"other_strings"/Array(20, string_block),
120+
"num_sn"/Int32ul,
119121
"strategic_numbers"/Array(lambda ctx: ctx.num_sn if find_save_version(ctx) >= 25.22 else 59, Int32sl),
120122
"num_ai_files"/Int64ul,
121123
"ai_files"/Array(lambda ctx: ctx.num_ai_files, Struct(

mgz/summary/full.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ def get_map(self):
332332
self.reference,
333333
tiles,
334334
de_seed=self._header.lobby.de.map_seed if self._header.lobby.de else None,
335-
de_strings=self._header.de.strings if self._header.de else []
335+
de_strings=self._header.de.rms_strings.strings if self._header.de else []
336336
)
337337
return self._cache['map']
338338

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
setup(
55
name='mgz',
6-
version='1.7.10',
6+
version='1.7.11',
77
description='Parse Age of Empires 2 recorded games.',
88
url='https://github.com/happyleavesaoc/aoc-mgz/',
99
license='MIT',

0 commit comments

Comments
 (0)