-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_addon.py
More file actions
71 lines (51 loc) · 2.24 KB
/
build_addon.py
File metadata and controls
71 lines (51 loc) · 2.24 KB
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
63
64
65
66
67
68
69
70
71
"""
Builds an instance of the mod in your addon folder
"""
import os
import shutil
import winreg
ROOT: str = os.getcwd()
BUILD_FOLDER: str = os.path.join(ROOT, "Build")
def get_addon_path() -> str:
try:
key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\WOW6432Node\\Valve\\Steam")
value, type = winreg.QueryValueEx(key, "InstallPath")
addon_path = os.path.join(value, "steamapps", "common", "Battlezone 98 Redux", "addon")
if not os.path.exists(addon_path):
raise RuntimeError("Couldn't find steam directory, do you have steam installed?")
except Exception as e:
print(f"An error occured: {e}")
return addon_path
def set_local_dll_path(reloaded_path) -> None:
lua_code1 = rf'package.path = package.path .. ";{rf"{reloaded_path}"}\?.lua"'.replace('\\', '\\\\')
lua_code2 = rf'package.cpath = package.cpath .. ";{rf"{reloaded_path}"}\?.dll"'.replace('\\', '\\\\')
reloaded = os.path.join(reloaded_path, "reloaded.lua")
with open(reloaded, 'r+') as f:
lines = f.readlines()
f.seek(0)
f.truncate()
for line in lines:
f.write(line)
if line.strip() == 'RequireFix.Initialize("3522264415")':
f.write('\n')
f.write("-- Code generated by addon build script, sets local module search path\n")
f.write(lua_code1 + '\n')
f.write(lua_code2 + '\n')
def build_addon() -> None:
if not os.path.exists(BUILD_FOLDER):
raise FileNotFoundError("Couldn't find workshop build folder, make sure to run squish first")
addon_path: str = get_addon_path()
reloaded_path = os.path.join(addon_path, "reloaded")
if os.path.exists(reloaded_path):
shutil.rmtree(reloaded_path)
os.mkdir(reloaded_path)
for path, _, files in os.walk(BUILD_FOLDER):
for file in files:
shutil.copyfile(os.path.join(path, file), os.path.join(reloaded_path, file))
set_local_dll_path(reloaded_path)
print(f"Built addon at {reloaded_path}")
if __name__ == "__main__":
try:
build_addon()
except Exception as e:
print(f"An error occurred: {e}")