Port GARC decoder to Construct 2.8

This commit is contained in:
Eevee (Lexy Munroe) 2016-12-20 19:22:59 -08:00
parent a38cb37e90
commit d7c20809e5

View file

@ -26,34 +26,28 @@ def count_bits(n):
garc_header_struct = c.Struct( garc_header_struct = c.Struct(
'garc_header', c.Const(b'CRAG'),
c.Magic(b'CRAG'), 'header_size' / c.Int32ul, # 28 in XY, 36 in SUMO
c.ULInt32('header_size'), # 28 in XY, 36 in SUMO 'byte_order' / c.Const(c.Int16ul, 0xfeff),
c.Const(c.ULInt16('byte_order'), 0xfeff), 'mystery1' / c.Int16ul, # 0x0400 in XY, 0x0600 in SUMO
c.ULInt16('mystery1'), # 0x0400 in XY, 0x0600 in SUMO
#c.Const(c.ULInt32('chunks_ct'), 4), #c.Const(c.ULInt32('chunks_ct'), 4),
c.ULInt32('chunks_ct'), 'chunks_ct' / c.Int32ul,
c.ULInt32('data_offset'), 'data_offset' / c.Int32ul,
c.ULInt32('garc_length'), 'garc_length' / c.Int32ul,
c.ULInt32('last_length'), 'last_length' / c.Int32ul,
c.Field('unknown_sumo_stuff', lambda ctx: ctx.header_size - 28), 'unknown_sumo_stuff' / c.Bytes(lambda ctx: ctx.header_size - 28),
) )
fato_header_struct = c.Struct( fato_header_struct = c.Struct(
'fato_header', c.Const(b'OTAF'),
c.Magic(b'OTAF'), 'header_size' / c.Int32ul,
c.ULInt32('header_size'), 'count' / c.Int16ul,
c.ULInt16('count'), c.Const(c.Int16ul, 0xffff),
c.Const(c.ULInt16('padding'), 0xffff), 'fatb_offsets' / c.Array(c.this.count, c.Int32ul),
c.Array(
lambda ctx: ctx.count,
c.ULInt32('fatb_offsets'),
),
) )
fatb_header_struct = c.Struct( fatb_header_struct = c.Struct(
'fatb_header', c.Const(b'BTAF'),
c.Magic(b'BTAF'), 'fatb_length' / c.Int32ul,
c.ULInt32('fatb_length'), 'count' / c.Int32ul,
c.ULInt32('count'),
) )