This repository was archived by the owner on Oct 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathextract_tables.py
62 lines (53 loc) · 2.11 KB
/
extract_tables.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
52
53
54
55
56
57
58
59
60
61
62
from lib.TableService import TableZipFile
import os
import json
from lib.StringCipher import Decrypt
from download_assets import EXT
from lib.TableEncryptionService import XOR
import FlatData as FlatData
lower_name_to_module_dict = {
key.lower(): value for key, value in FlatData.__dict__.items()
}
from FlatData.dump import dump_table
TABLE_FP = os.path.join(EXT, "Preload", "TableBundles")
def main():
for table_file in os.listdir(TABLE_FP):
# only process .zip files
if not table_file.endswith(".zip"):
continue
print("==", table_file, "==")
# create dir for table
table_dir_fp = os.path.join(TABLE_FP, table_file[:-4])
os.makedirs(table_dir_fp, exist_ok=True)
# dump files from zip to dir
tz = TableZipFile(os.path.join(TABLE_FP, table_file))
for name in tz.namelist():
print(name)
data = tz.read(name)
# Battle.zip
# process encryption of those two files
if name.endswith(".json"):
if name == "logiceffectdata.json":
data = Decrypt(data, "LogicEffectData").encode("utf8")
elif name == "newskilldata.json":
data = Decrypt(data, "NewSkillData").encode("utf8")
# Excel.zip
# process encryption and encoding of all excel files
elif table_file == "Excel.zip":
try:
flatbuffer_cls = lower_name_to_module_dict[name[:-6]]
data = XOR(flatbuffer_cls.__name__, data)
flatbuffer = flatbuffer_cls.GetRootAs(data)
data = json.dumps(
dump_table(flatbuffer), indent=4, ensure_ascii=False
).encode("utf8")
name = f"{flatbuffer_cls.__name__}.json"
except Exception as e:
print(e)
continue
# write to file
fp = os.path.join(table_dir_fp, name)
with open(fp, "wb") as f:
f.write(data)
if __name__ == "__main__":
main()