-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.py
More file actions
174 lines (140 loc) · 4.83 KB
/
Copy pathbuild.py
File metadata and controls
174 lines (140 loc) · 4.83 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
import argparse
import io
import json
import os
import shutil
import subprocess
import urllib.request
import zipfile
from terminut import log
ROOT = os.path.dirname(os.path.abspath(__file__))
IMGUI_DIR = os.path.join(ROOT, "imgui")
MINHOOK_DIR = os.path.join(ROOT, "minhook")
USER_AGENT = (
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 "
"(KHTML, like Gecko) Chrome/149.0.0.0 Safari/537.36"
)
def latest_release_tag(repo):
url = "https://api.github.com/repos/%s/releases/latest" % repo
request = urllib.request.Request(
url,
headers={
"Accept": "application/vnd.github+json",
"User-Agent": USER_AGENT,
},
)
with urllib.request.urlopen(request, timeout=10) as response:
tag = json.load(response).get("tag_name")
if not tag:
log.fatal("Could not read latest release tag for %s." % repo)
raise SystemExit(1)
log.info("Latest %s release: %s" % (repo, tag))
return tag
IMGUI_BACKENDS = ["opengl2", "dx9", "win32"]
def download_zip(url):
log.info("Downloading %s" % url)
request = urllib.request.Request(url, headers={"User-Agent": USER_AGENT})
with urllib.request.urlopen(request) as response:
return zipfile.ZipFile(io.BytesIO(response.read()))
def extract_member(archive, member, dest):
os.makedirs(os.path.dirname(dest), exist_ok=True)
with archive.open(member) as src, open(dest, "wb") as out:
shutil.copyfileobj(src, out)
def fetch_imgui():
shutil.rmtree(IMGUI_DIR, ignore_errors=True)
tag = latest_release_tag("ocornut/imgui")
archive = download_zip(
"https://github.com/ocornut/imgui/archive/refs/tags/%s.zip" % tag
)
root = archive.namelist()[0].split("/")[0] + "/"
wanted_backends = set()
for name in IMGUI_BACKENDS:
wanted_backends.add("imgui_impl_%s.cpp" % name)
wanted_backends.add("imgui_impl_%s.h" % name)
for member in archive.namelist():
if member.endswith("/") or not member.startswith(root):
continue
rel = member[len(root) :]
parts = rel.split("/")
base = parts[-1]
if len(parts) == 1 and (
base.startswith(("imgui", "imstb_")) or base == "imconfig.h"
):
extract_member(archive, member, os.path.join(IMGUI_DIR, base))
elif parts[0] == "backends" and base in wanted_backends:
extract_member(archive, member, os.path.join(IMGUI_DIR, "backends", base))
log.success("imgui ready (%s)." % tag)
def fetch_minhook():
shutil.rmtree(MINHOOK_DIR, ignore_errors=True)
tag = latest_release_tag("TsudaKageyu/minhook")
archive = download_zip(
"https://github.com/TsudaKageyu/minhook/archive/refs/tags/%s.zip" % tag
)
root = archive.namelist()[0].split("/")[0] + "/"
for member in archive.namelist():
if member.endswith("/") or not member.startswith(root):
continue
rel = member[len(root) :]
if rel.startswith("include/") or rel.startswith("src/"):
extract_member(archive, member, os.path.join(MINHOOK_DIR, rel))
log.success("minhook ready (%s)." % tag)
def find_msbuild():
vswhere = os.path.join(
os.environ.get("ProgramFiles(x86)", "C:\\Program Files (x86)"),
"Microsoft Visual Studio",
"Installer",
"vswhere.exe",
)
if os.path.exists(vswhere):
out = (
subprocess.check_output(
[
vswhere,
"-latest",
"-requires",
"Microsoft.Component.MSBuild",
"-find",
"MSBuild\\**\\Bin\\MSBuild.exe",
],
text=True,
)
.strip()
.splitlines()
)
if out:
return out[0]
found = shutil.which("msbuild")
if found:
return found
log.fatal("MSBuild not found. Install Visual Studio Build Tools.")
raise SystemExit(1)
def cleanup_deps():
log.info("Removing fetched dependencies.")
shutil.rmtree(IMGUI_DIR, ignore_errors=True)
shutil.rmtree(MINHOOK_DIR, ignore_errors=True)
def main():
parser = argparse.ArgumentParser(description="Build the injector DLL.")
parser.add_argument("-c", "--config", default="Release")
args = parser.parse_args()
fetch_imgui()
fetch_minhook()
msbuild = find_msbuild()
log.info("MSBuild: %s" % msbuild)
cmd = [
msbuild,
os.path.join(ROOT, "injector.sln"),
"/m",
"/p:Configuration=%s" % args.config,
"/p:Platform=Win32",
"/v:minimal",
]
log.info(" ".join(cmd))
rc = subprocess.call(cmd)
cleanup_deps()
if rc == 0:
log.success("Build complete.")
else:
log.error("Build failed (exit %d)." % rc)
raise SystemExit(rc)
if __name__ == "__main__":
main()