v8.1
[squaddata.git] / script.py
blob443149f37b9f2f8cfbf83079bedd531269f6a06e
1 import unreal
2 import os
3 import json
4 import re
5 from glob import glob
6 def jd(x, p):
7 pp = p.rsplit("/",1)[0]
8 os.makedirs(f"C:/squad_dump/{pp}", exist_ok=1)
9 with open(f"C:/squad_dump/{p}.json", "w") as f:
10 json.dump(x, f, indent=2)
12 def todict(x, dep):
13 def ps(xx, k):
14 expk = ["deployables", "vehicles"]
15 if k in expk and "Object" in str(xx):
16 return todict(xx, 0)
17 res = re.sub("\(0x.*?\)", "", str(xx))
18 return res if len(res) < 1024 else ""
19 d = {}
20 for a in dir(x):
21 try:
22 aa = getattr(x, a)
23 ts = str(type(aa))
24 if "method" not in ts and a[0] != "_":
25 if "Struct" in str(aa) and dep < 1:
26 d[a] = todict(aa, dep + 1)
27 elif "Array" in ts:
28 d[a] = [ps(bb, a) for bb in aa]
29 else:
30 d[a] = ps(aa, a)
31 except:
32 pass
33 return d
35 inst = "C:/SquadEditor/Squad/Content"
36 paths = [
37 "Blueprints/Items/GrenadeLaunchers",
38 "Blueprints/Items/Grenades",
39 "Blueprints/Items/MachineGuns",
40 "Blueprints/Items/Pistols",
41 "Blueprints/Items/Projectiles",
42 "Blueprints/Items/Rifles",
43 "Blueprints/Items/RocketLaunchers",
44 "Blueprints/Items/SubmachineGuns",
46 for path in paths:
47 for w in glob(f"{inst}/{path}/**/BP_*.uasset", recursive = True):
48 bp = w.split("\\", 1)[1].replace("\\", "/")[:-7]
49 bpp = bp.rsplit("/", 1)
50 b = unreal.load_object(None, f"/Game/{path}/{bp}.{bpp[-1]}_C")
51 b = unreal.get_default_object(b)
52 jd(todict(b, 0), f"{path}/{bp}")
53 paths = ["Settings/Roles", "Settings/FactionSetups"]
54 for path in paths:
55 for w in glob(f"{inst}/{path}/**/*.uasset", recursive = True):
56 bp = w.split("\\", 1)[1].replace("\\", "/")[:-7]
57 b = unreal.load_object(None, f"/Game/{path}/{bp}")
58 jd(todict(b, 0), f"{path}/{bp}")