Created
April 4, 2021 07:27
-
-
Save ariscop/114c7300613df87728ff7a10686690c9 to your computer and use it in GitHub Desktop.
Partially reads blueprint-storage.dat, the file appear to be completely auto generated and its a chore to reverse engineer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
from pprint import pprint | |
from construct import * | |
class VersionStringAdapter(Adapter): | |
def _decode(self, obj, context, path): | |
return ".".join(map(str, obj)) | |
Version = VersionStringAdapter(Int16ul[4]) | |
# kind -> id | |
# 0 -> 0 is blank for icons | |
ModList = PrefixedArray(Int8ul, PascalString(Byte, "ascii") >> PascalString(Byte, "ascii")) | |
ent_names = Struct( | |
"prototype" / PascalString(Byte, "ascii"), | |
"count" / IfThenElse(this.prototype == "tile", Int8ul, Int16ul), | |
"entity" / (IfThenElse(this._.prototype == "tile", Int8ul, Int16ul) >> PascalString(Byte, "ascii"))[this.count], | |
) | |
dat = Struct( | |
"Version" / Version, | |
"u1" / Byte, | |
"modlist" / ModList, | |
"u3" / PrefixedArray(Int16ul, ent_names), | |
"u4" / Int16ul, | |
"seqno" / Int32ul, | |
"mtime" / Int32ul, | |
"x" / Bytes(6), | |
"bp_book" / Struct( | |
"kind" / Byte, # blueprint = 0, book = 1, decon = 2, upgrade = 3 | |
"seqno" / Int32ul, # sequence number | |
"item_id" / Int16ul, # item? blueprint book = 71 | |
"title" / PascalString(Byte, "utf-8"), | |
# end of common header? | |
"u1" / Bytes(7), | |
"Version" / Version, | |
"unk1" / Byte, | |
"modlist" / ModList, | |
# Here be dragons | |
"description" / PascalString(Byte, "utf-8"), | |
#"icons" / PrefixedArray(Byte, Byte >> Int16ul), | |
"unk2" / Int8ul, | |
"ent_count" / Int32ul, | |
"ents" / Struct( | |
"entity" / Int16ul, | |
"pos" / Int8sl[2][2], | |
"u1" / Byte, | |
"u2" / Byte, | |
"direction" / Byte, | |
"unk" / Bytes(6), | |
)[this.ent_count] | |
) | |
) | |
with open("blueprint-storage.dat", "rb") as fd: | |
print(dat.parse_stream(fd)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment