This repository has been archived by the owner on Oct 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_structs.py
48 lines (40 loc) · 1.62 KB
/
generate_structs.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
import re
import os
import json
# path to the dump.cs generated by Perfare's il2cpp dumper
dump_cs_path = "S:\\Datamines\\DRPG global\\Disgaea-RPG---Mine\\dump.cs"
# folder where the structs are saved into
struct_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "structs")
reIMaster = re.compile(r"""\[Serializable\]
public( sealed)? class (\w+?) : (.+?) //.+?
\{
(.+?)
\}""", flags=re.M | re.S)
reSerializeField = re.compile(r""" (private|protected) ([^ ]+?) ([a-z_0-9]+?); // (.+)""")
reSerializeProperty = re.compile(r""" public (virtual )?([^ ]+?) ([a-z_A-Z0-9]+?) \{ get; (set; )?\}()""")
def fetch_structs(fp):
found = {
master[2]: {
"inheritance" : master[3],
"fields" : {
field[3] : field[2]
#"offset": int(field[3], 16)
for field in reSerializeField.finditer(master[4])
},
"properties" : {
field[3] : field[2]
#"offset": int(field[3], 16)
for field in reSerializeProperty.finditer(master[4])
}
}
for master in reIMaster.finditer(open(fp, "rt", encoding="utf8").read())
}
return {clz : data for clz, data in found.items()}# if data["fields"] and data["properties"]}
def read(stream, t, size):
return struct.unpack(t, stream.read(size))
structs = fetch_structs(dump_cs_path)
os.makedirs(struct_path, exist_ok=True)
for name, struct in structs.items():
if struct:
with open(os.path.join(struct_path, f"{name}.json"), "wt", encoding="utf8") as f:
json.dump(struct, f, ensure_ascii=False, indent=4)