-
Notifications
You must be signed in to change notification settings - Fork 13
/
parse_stage_config.py
51 lines (41 loc) · 1.13 KB
/
parse_stage_config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from construct import *
import sys
String = PascalString(Byte)
Word = Int16ul
Dword = Int32ul
def inc(ctx, var):
res = ctx[var]
ctx[var] += 1
return res
CFG = Struct(
"Magic" / Const("CFG\0"),
# Bool - if to use the objects specified in GameObject.bin
"UseGameObjects" / Byte,
"Objects" / PrefixedArray(Byte, String),
"Palettes" / Array(8, Struct(
"Bitmap" / Word,
"i" / Computed(0),
"Columns" / Array(16, Struct(
"Pixels" / If(lambda ctx: (1 << inc(ctx._, "i")) & ctx._.Bitmap,
Array(16, Struct(
"R" / Byte,
"G" / Byte,
"B" / Byte
))
)
))
)),
"WavConfiguration" / PrefixedArray(Byte, Struct(
"Path" / String,
"MaxConcurrentPlay" / Byte
)),
)
if __name__ == "__main__":
if len(sys.argv) != 2:
print "Usage: parse_stage_config.py StageConfig.bin"
sys.exit(-1)
if not sys.argv[1].endswith(".bin"):
print "Expected .bin file"
sys.exit(-1)
cfg = CFG.parse(open(sys.argv[1], "rb").read())
print(cfg)