Files
Triforce-Source/nx2/version.py
ruckus7382sfgsgdf 4fa4f9188b Triforce v0.8.0
Evil HD (SMAA Ultra, 16x filtering, full textures, ambient occlusion with bounce light, sunlight shafts, foliage drawn 4x as far, the remastered texture pack's loader and the launcher's download of it), FSR 3.1 frame generation for every GPU, Intel XeSS, FSR 4 model choice, ReShade presets, Auto (this PC), HUD placement, the options menu in 13 languages, a second input for every control, hold to toggle, DualSense speaker and haptics, NFC from the player's own dumps, the above-60 fps game fixes, the Debug tab's flight and Inventory fixes, the launcher's full settings, and over 250 fixes.
2026-11-25 10:21:32 -06:00

74 lines
3.1 KiB
Python

"""Which Hookshot a build is: the release it came from and a fingerprint of its sources.
The game prints it as the first line of triforce_log.txt and in the Insert menu, so a report says what was run.
python -I nx2/version.py prints it for this folder
The release name comes from, in order: HOOKSHOT_VERSION; a VERSION file at the root (written when a release is packaged,
since the builder's tools folder has no git history); `git describe --tags --always --dirty` in a checkout, matching
only version tags (`v0.1.0`, not the branch-like tags from before the scheme). The
fingerprint is a hash of the sources in this folder (host/, gpu/, nx2/), line endings aside: every build from the
same release zip gives the same one, so even a build that says "unknown" can be traced to the zip it came from. (A
checkout and a release's tools folder hold different sets of files, so their fingerprints differ.)
"""
import hashlib
import os
import re
import subprocess
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
SOURCES = ("host", "gpu", "nx2")
# ((Triforce) .inl and .def: files an #include names besides headers, as nx2/build.py's HEADER_EXTS)
SOURCE_EXT = (".c", ".cc", ".cpp", ".h", ".hpp", ".inc", ".inl", ".def", ".py", ".glsl", ".comp", ".vert", ".frag", ".spv")
def release(root=ROOT):
name = os.environ.get("HOOKSHOT_VERSION", "").strip()
if not name:
for file in ("VERSION", "version.txt"): # (version.txt: the release's tag, written into the builder's tools when it is packed)
try:
with open(os.path.join(root, file), encoding="utf-8") as f:
name = f.readline().strip()
except OSError:
pass
if name:
break
if not name and os.path.exists(os.path.join(root, ".git")):
try:
r = subprocess.run(["git", "-C", root, "describe", "--tags", "--always", "--dirty", "--match", "v[0-9]*"],
capture_output=True, text=True, timeout=20)
name = r.stdout.strip() if r.returncode == 0 else ""
except (OSError, subprocess.SubprocessError):
pass
return name or "unknown"
def fingerprint(root=ROOT):
h = hashlib.sha1(usedforsecurity=False)
for top in SOURCES:
base = os.path.join(root, top)
for d, dirs, files in os.walk(base):
dirs[:] = sorted(x for x in dirs if x != "__pycache__")
for f in sorted(files):
if not f.endswith(SOURCE_EXT):
continue
p = os.path.join(d, f)
with open(p, "rb") as src:
data = src.read().replace(b"\r\n", b"\n")
h.update(os.path.relpath(p, root).replace("\\", "/").encode() + b"\0" + data + b"\0")
return h.hexdigest()[:8]
def describe(root=ROOT):
"""'movie-sync (source 1a2b3c4d)': safe to pass as a C string literal on any command line."""
text = "%s (source %s)" % (release(root), fingerprint(root))
return re.sub(r"[^A-Za-z0-9 ._+()/-]", "_", text)[:80]
def define(root=ROOT):
return '-DHOOKSHOT_VERSION="%s"' % describe(root)
if __name__ == "__main__":
print(describe())