Skip to content

Commit b4a30d8

Browse files
committed
Add support for The Last Chieftains in the fast parser
Make the necessary changes to support savegames from the Last Chieftains DLC. The full parser changes are not sufficient to make it work yet, more investigation is needed.
1 parent cf20473 commit b4a30d8

4 files changed

Lines changed: 14 additions & 2 deletions

File tree

mgz/fast/header.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,8 @@ def parse_de(data, version, save, skip=False):
468468
data.read(8)
469469
if save >= 64.3:
470470
data.read(4)
471+
if save >= 67.2:
472+
_ = de_string(data)
471473

472474
players.append(dict(
473475
number=number,
@@ -550,6 +552,9 @@ def parse_de(data, version, save, skip=False):
550552
data.read(c * 4)
551553
if not skip:
552554
de_string(data)
555+
if save >= 67.2:
556+
_ = de_string(data)
557+
_ = de_string(data)
553558
data.read(8)
554559
if save >= 37:
555560
timestamp, x = unpack('<II', data)

mgz/header/de.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"custom_ai"/Flag,
4646
If(lambda ctx: find_save_version(ctx) >= 25.06, "handicap"/Bytes(8)),
4747
If(lambda ctx: find_save_version(ctx) >= 64.3, "unknown_de_64_3" / Int32ul),
48+
If(lambda ctx: find_save_version(ctx) >= 67.2, "unknown_de_67_2" / de_string),
4849
)
4950

5051
string_block = Struct(
@@ -167,6 +168,10 @@
167168
If(lambda ctx: find_save_version(ctx) >= 66.3, Bytes(12)),
168169
If(lambda ctx: find_save_version(ctx) >= 66.3, Array(lambda ctx: ctx.unknown_count, Bytes(4))),
169170
de_string,
171+
If(lambda ctx: find_save_version(ctx) >= 67.2, Struct(
172+
de_string,
173+
de_string,
174+
)),
170175
Bytes(5),
171176
If(lambda ctx: find_save_version(ctx) >= 13.13, Byte),
172177
If(lambda ctx: find_save_version(ctx) < 13.17, Struct(
@@ -178,5 +183,5 @@
178183
"ver37"/If(lambda ctx: find_save_version(ctx) >= 37, Struct(
179184
Int32ul,
180185
Int32ul
181-
))
186+
)),
182187
)

mgz/header/initial.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
Int32ul, Padding, Struct, Tell, this, Bytes, Const, IfThenElse)
77

88
from mgz.enums import MyDiplomacyEnum, TheirDiplomacyEnum
9+
from mgz.header.de import de_string
910
from mgz.header.objects import existing_object
1011
from mgz.header.playerstats import player_stats
1112
from mgz.util import Find, GotoObjectsEnd, RepeatUpTo, Version, find_save_version, find_version
@@ -42,6 +43,7 @@
4243
"y"/Int16ul
4344
),
4445
"culture"/Byte,
46+
"name"/If(lambda ctx: find_save_version(ctx) >= 67.2, de_string),
4547
"civilization"/Byte,
4648
"game_status"/Byte,
4749
"resigned"/Flag,

mgz/model/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ def parse_match(handle):
171171
player['name'].decode(encoding),
172172
consts['player_colors'][str(player['color_id'])],
173173
player['color_id'],
174-
dataset['civilizations'][str(player['civilization_id'])]['name'],
174+
dataset['civilizations'].get(str(player['civilization_id']), {'name': f"<Unknown civ: {player['civilization_id']}>"})['name'],
175175
player['civilization_id'],
176176
Position(pos_x, pos_y),
177177
[

0 commit comments

Comments
 (0)