Update parse_save.py to use PrefixedArray and PascalString

This commit is contained in:
Earthnuker 2017-10-08 00:03:48 +00:00
parent cf7ce84a43
commit ca979c2ae6

View file

@ -1,24 +1,20 @@
from construct import * from construct import *
from pprint import pprint from pprint import pprint
ScrapSaveStr = Struct( ScrapSaveVar = Struct(
'length'/Int32ul, 'name'/PascalString(Int32ul,encoding='utf-8'),
'data'/String(this.length,encoding='utf-8'), 'data'/PascalString(Int32ul,encoding='utf-8'),
) )
ScrapSaveVar = Struct( ScrapSave = 'ScarpSaveGame'/Struct(
'v_name_size'/Int32ul, 'title'/PascalString(Int32ul,encoding='utf-8'),
'v_name'/String(lambda ctx: ctx.v_name_size,encoding='utf-8'), 'id'/PascalString(Int32ul,encoding='utf-8'),
'v_data_size'/Int32ul, 'data'/PrefixedArray(Int32ul,ScrapSaveVar),
'v_data'/String(lambda ctx: ctx.v_data_size,encoding='utf-8'), Terminated
) )
ScrapSave = 'ScarpSaveGame'/Struct( with open("Save0.sav", 'rb') as sav_file:
'title'/ScrapSaveStr, save = ScrapSave.parse_stream(sav_file)
'id'/ScrapSaveStr, print("ID:",save.id)
'num_vars'/Int32ul, print("Title:",save.title)
'data'/ScrapSaveVar[this.num_vars], for var in save.data:
Terminated print(" - {}: {}".format(var.name,var.data))
) #for block in save.data:
with open("Save0.sav", 'rb') as sav_file: # print("{}: {}".format(block.v_name, block.v_data))
save = ScrapSave.parse_stream(sav_file)
pprint(save)
#for block in save.data:
# print("{}: {}".format(block.v_name, block.v_data))