mirror of
https://git.triforceproject.com/triforce/source
synced 2026-11-19 16:20:01 -04:00
Triforce v0.4.0
What was merged from NX2navi (DLSS frame generation, AMD FSR 4 in Setup builds, texture detail by video memory, sprint, volume, frame caps, safer saves, the above-60 fixes), the ultrawide HUD at the screen edges, camera speed, movies without the AV1 Video Extension, the 5120x2880 + RenoDX HDR start fix, the renderer work of 11-14 and the first float changes of the lift.
This commit is contained in:
28
nx2/build.py
28
nx2/build.py
@@ -537,6 +537,11 @@ def ffmpeg_version_key():
|
||||
# instead of Windows' write watch (GetWriteWatch over the 6 GB MKW's GPU sees took ~20 ms a scan, in one thread or
|
||||
# four: the race's replay waited ~12 ms a frame for it). RX_SOFT_WRITE_WATCH=0: Windows' write watch (a full rebuild)
|
||||
WRITE_TRACK = [] if os.environ.get("RX_SOFT_WRITE_WATCH") == "0" else ["-DA64_WRITE_TRACK"]
|
||||
# (triforce) RX_MARK_ONE=1: a lifted store marks the page of its first byte alone (one store and three instructions less
|
||||
# at every guest store; the marks were ~5-8% of the game threads' CPU at OoT's Market), and the collection takes a mark
|
||||
# as "this page and the next" (host/rx_backend.c collect_in): a store of up to 4 KB reaches no further. A full rebuild.
|
||||
if WRITE_TRACK and os.environ.get("RX_MARK_ONE") == "1":
|
||||
WRITE_TRACK = WRITE_TRACK + ["-DA64_MARK_ONE"]
|
||||
|
||||
# (hookshot) the host CPU the lifted game and the runtime are built for: x86-64-v3 (AVX2, FMA, BMI1/2, LZCNT,
|
||||
# MOVBE; Haswell and Zen 1 on). With FMA the FPX1 fast paths cover double-precision FMA (RECOMP_FPX_FMA64; it took
|
||||
@@ -802,6 +807,15 @@ def main():
|
||||
# (hookshot) code_hot.c, the lift's hot functions together (A64_HOT_FUNCS + A64_HOT_CHUNK=1): at RX_HOT_OPT
|
||||
# (default O2), so the hot callees inline into their hot callers
|
||||
hot_fl = [("-" + os.environ.get("RX_HOT_OPT", "O2")) if f == "-" + a.opt else f for f in fl]
|
||||
# (triforce) RX_HOT_CAPTURE=<n>: the hot pieces' own -capture-tracking-max-uses-to-explore (see flags()): a hot function
|
||||
# that names the context more often than the limit is compiled as if the context escaped (every guest store may change
|
||||
# it), and the largest functions are among the hottest
|
||||
if os.environ.get("RX_HOT_CAPTURE"):
|
||||
hot_fl = [("-capture-tracking-max-uses-to-explore=" + os.environ["RX_HOT_CAPTURE"])
|
||||
if f.startswith("-capture-tracking-max-uses-to-explore=") else f for f in hot_fl]
|
||||
# (triforce) RX_HOT_FLAGS=<flags>: more flags for the hot pieces alone (a variant of them without building the rest again)
|
||||
if os.environ.get("RX_HOT_FLAGS"):
|
||||
hot_fl = hot_fl + os.environ["RX_HOT_FLAGS"].split()
|
||||
# (hookshot) RX_PGO=gen: code_hot.c counts its branches (host/pgo_rt.c writes them; -O1 builds much sooner, and the counters are
|
||||
# placed before the optimiser, so a profile from it fits the -O2 build). RX_PGO=<merged .prof>: built with that profile
|
||||
if PGO == "gen":
|
||||
@@ -925,6 +939,18 @@ def main():
|
||||
ngx_deps = tree_headers(os.path.join(NGX_SDK, "include")) if NGX_SDK else b""
|
||||
if NGX_SDK:
|
||||
print("the Vulkan back end: with NVIDIA DLSS (NVIDIA's NGX SDK in %s)" % NGX_SDK, flush=True)
|
||||
# (NVIDIA DLSS frame generation, a local build's option: HOOKSHOT_STREAMLINE_SDK=<NVIDIA's Streamline SDK, unpacked>.
|
||||
# Only vk_dlssg.cpp sees its headers; nothing of it is linked (sl.interposer.dll is loaded beside the game at run
|
||||
# time). Without it that file is the stubs that say it is not there. Windows only)
|
||||
sl_sdk = os.environ.get("HOOKSHOT_STREAMLINE_SDK", "")
|
||||
if sl_sdk and (LINUX or not os.path.isfile(os.path.join(sl_sdk, "include", "sl_dlss_g.h"))):
|
||||
print("build: HOOKSHOT_STREAMLINE_SDK=%s has no include/sl_dlss_g.h (or this is not a Windows build): built "
|
||||
"without NVIDIA DLSS frame generation" % sl_sdk, flush=True)
|
||||
sl_sdk = ""
|
||||
sl_flags = ["-DHOOKSHOT_DLSSG", "-I" + os.path.join(sl_sdk, "include")] if sl_sdk else []
|
||||
sl_deps = tree_headers(os.path.join(sl_sdk, "include")) if sl_sdk else b""
|
||||
if sl_sdk:
|
||||
print("the Vulkan back end: with NVIDIA DLSS frame generation (NVIDIA's Streamline SDK in %s)" % sl_sdk, flush=True)
|
||||
# (AMD FSR 4, a build's option too: only vk_fsr4.cpp sees AMD's headers; without them it is the stubs that say FSR is
|
||||
# not there)
|
||||
fsr_flags = ["-DHOOKSHOT_FSR", "-I" + os.path.join(kit.HERE, "..", "third_party", "fidelityfx")] if FSR else []
|
||||
@@ -974,12 +1000,14 @@ def main():
|
||||
vflags + ([shader_stamp] if os.path.basename(src) == "vk_shader.cpp" else []) +
|
||||
([stamp_def] if os.path.basename(src) == "vk_menu.cpp" else []) +
|
||||
(ngx_flags if os.path.basename(src) == "vk_dlss.cpp" else []) +
|
||||
(sl_flags if os.path.basename(src) == "vk_dlssg.cpp" else []) +
|
||||
(imgui_flags if os.path.basename(src) in imgui_users else []) +
|
||||
(fsr_flags if os.path.basename(src) == "vk_fsr4.cpp" else []) +
|
||||
(renodx_flags if os.path.basename(src) == "vk_renodx.cpp" else []),
|
||||
vk_lib_deps if lib else vdeps + (logo_text if os.path.basename(src) == "vk_imgui.cpp" else b"") +
|
||||
(renodx_deps if os.path.basename(src) == "vk_renodx.cpp" else b"") +
|
||||
(ngx_deps if os.path.basename(src) == "vk_dlss.cpp" else b"") +
|
||||
(sl_deps if os.path.basename(src) == "vk_dlssg.cpp" else b"") +
|
||||
(imgui_deps if os.path.basename(src) in imgui_users else b"")))
|
||||
if NGX_SDK and not LINUX and toolchain.mingw():
|
||||
# (llvm-mingw: NVIDIA's static library was built with Microsoft's compiler for its static runtime (/MT). What it asks
|
||||
|
||||
104
nx2/make_game.py
104
nx2/make_game.py
@@ -1255,6 +1255,103 @@ def fetch_ngx_sdk(a):
|
||||
fail("NVIDIA's DLSS SDK could not be downloaded (%s). Check the connection and build again, or untick NVIDIA DLSS." % e)
|
||||
|
||||
|
||||
def fsr_script():
|
||||
"""scripts/fsr_sdk.py: AMD's two FSR 4 libraries; None where the builder carries no scripts/"""
|
||||
import importlib.util
|
||||
path = os.path.join(ROOT, "scripts", "fsr_sdk.py")
|
||||
if not os.path.isfile(path):
|
||||
return None
|
||||
spec = importlib.util.spec_from_file_location("fsr_sdk", path)
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(module)
|
||||
return module
|
||||
|
||||
|
||||
def fsr_runtime_dir(work):
|
||||
"""Where AMD's FSR 4 libraries are kept between builds: HOOKSHOT_FSR_SDK, else the fsr-sdk folder of the work folder"""
|
||||
return os.environ.get("HOOKSHOT_FSR_SDK", "") or os.path.join(work, "fsr-sdk")
|
||||
|
||||
|
||||
def fetch_fsr_runtime(work):
|
||||
"""(--fsr, Windows) AMD's two signed FSR 4 libraries into fsr_runtime_dir, only what is missing. A download that fails
|
||||
is said and the build goes on: the game then does not offer AMD FSR 4 until a build gets them"""
|
||||
fsr = fsr_script()
|
||||
if LINUX or fsr is None:
|
||||
return
|
||||
print(fsr.NOTICE, flush=True)
|
||||
try:
|
||||
fsr.fetch(fsr_runtime_dir(work), say=lambda line: print(line, flush=True))
|
||||
except (OSError, ValueError) as e:
|
||||
print("AMD's FSR 4 libraries could not be downloaded (%s): the game will not offer AMD FSR 4. Build again with a "
|
||||
"connection to get them." % e, flush=True)
|
||||
|
||||
|
||||
def place_fsr_runtime(out, work, wanted):
|
||||
"""(AMD FSR 4) a game built with it gets AMD's two libraries and their license text beside its exe, where
|
||||
gpu/vk/vk_fsr4.cpp looks; a folder built with them before and without FSR 4 now loses them. Returns what was placed"""
|
||||
fsr = fsr_script()
|
||||
if LINUX or fsr is None:
|
||||
return []
|
||||
if not wanted or not fsr.complete(fsr_runtime_dir(work)):
|
||||
if not wanted:
|
||||
fsr.remove_runtime(out)
|
||||
return []
|
||||
placed = fsr.install_runtime(fsr_runtime_dir(work), out)
|
||||
print("AMD FSR 4: %s (AMD's, MIT license)" % ", ".join(os.path.basename(p) for p in placed), flush=True)
|
||||
return placed
|
||||
|
||||
|
||||
def streamline_script():
|
||||
"""scripts/streamline_sdk.py: NVIDIA's Streamline files for DLSS frame generation; None where the builder carries no
|
||||
scripts/ (frame generation is then left out, DLSS itself is not)"""
|
||||
import importlib.util
|
||||
path = os.path.join(ROOT, "scripts", "streamline_sdk.py")
|
||||
if not os.path.isfile(path):
|
||||
return None
|
||||
spec = importlib.util.spec_from_file_location("streamline_sdk", path)
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(module)
|
||||
return module
|
||||
|
||||
|
||||
def fetch_streamline_sdk(a):
|
||||
"""With --fetch-ngx-sdk on Windows (the NVIDIA DLSS tick, NVIDIA's licenses accepted): NVIDIA's Streamline files for DLSS
|
||||
frame generation too, into HOOKSHOT_STREAMLINE_SDK (default: the streamline folder in HOOKSHOT_NGX_SDK), which
|
||||
nx2/build.py then builds gpu/vk/vk_dlssg.cpp with. A download that fails leaves frame generation out of this build and
|
||||
says so: the build goes on, with DLSS as before"""
|
||||
if LINUX or not a.accept_nvidia_license:
|
||||
return
|
||||
sl = streamline_script()
|
||||
if sl is None:
|
||||
return
|
||||
sdk = os.environ.get("HOOKSHOT_STREAMLINE_SDK", "") or os.path.join(os.environ.get("HOOKSHOT_NGX_SDK", ""), "streamline")
|
||||
print(sl.NOTICE, flush=True)
|
||||
try:
|
||||
sl.fetch(sdk, say=lambda line: print(line, flush=True))
|
||||
except (OSError, ValueError) as e:
|
||||
print("NVIDIA's Streamline could not be downloaded (%s): this build has no DLSS frame generation. Build again "
|
||||
"with a connection to get it." % e, flush=True)
|
||||
os.environ.pop("HOOKSHOT_STREAMLINE_SDK", None)
|
||||
return
|
||||
os.environ["HOOKSHOT_STREAMLINE_SDK"] = sdk
|
||||
|
||||
|
||||
def place_dlssg_runtime(out):
|
||||
"""(NVIDIA DLSS frame generation) a game built with NVIDIA's Streamline (HOOKSHOT_STREAMLINE_SDK, as nx2/build.py takes it)
|
||||
gets Streamline's DLLs, nvngx_dlssg.dll and their license texts in its dlssg folder, where gpu/vk/vk_dlssg.cpp looks. A
|
||||
folder built with them before and without them now loses them. Returns the folder, or None"""
|
||||
sl = streamline_script()
|
||||
if sl is None:
|
||||
return None
|
||||
sdk = os.environ.get("HOOKSHOT_STREAMLINE_SDK", "")
|
||||
if LINUX or not sl.complete(sdk):
|
||||
sl.remove_runtime(out)
|
||||
return None
|
||||
dst = sl.install_runtime(sdk, out)
|
||||
print("NVIDIA DLSS frame generation: %s (NVIDIA's, under NVIDIA's licenses: never share this game folder)" % dst, flush=True)
|
||||
return dst
|
||||
|
||||
|
||||
def ngx_built():
|
||||
"""This build has NVIDIA DLSS: HOOKSHOT_NGX_SDK holds this platform's library (what nx2/build.py takes)"""
|
||||
sdk = os.environ.get("HOOKSHOT_NGX_SDK", "")
|
||||
@@ -1350,7 +1447,8 @@ def parse_args():
|
||||
p.add_argument("--fetch-ngx-sdk", action="store_true", help="download NVIDIA's DLSS SDK into HOOKSHOT_NGX_SDK before the build")
|
||||
p.add_argument("--accept-nvidia-license", action="store_true", help="NVIDIA's DLSS SDK license, accepted (with --fetch-ngx-sdk)")
|
||||
# (AMD FSR 4, off unless asked: nothing is downloaded. gpu/vk/vk_fsr4.cpp)
|
||||
p.add_argument("--fsr", action="store_true", help="build with AMD FSR 4 (AMD's DLLs are not included: see the readme)")
|
||||
p.add_argument("--fsr", action="store_true", help="build with AMD FSR 4; on Windows AMD's two libraries are downloaded "
|
||||
"from AMD's repository and put beside the game (scripts/fsr_sdk.py)")
|
||||
p.add_argument("--no-fsr", action="store_true", help="with --update: build without AMD FSR 4 even if the folder had it")
|
||||
# (RenoDX's HDR, in every build since 11-13: its shaders and the Slang compiler are downloaded and compiled here.
|
||||
# scripts/renodx_shaders.py, gpu/vk/vk_renodx.cpp)
|
||||
@@ -1423,9 +1521,11 @@ def main(a=None):
|
||||
drop_stale_objects(work)
|
||||
if getattr(a, "fetch_ngx_sdk", False):
|
||||
fetch_ngx_sdk(a)
|
||||
fetch_streamline_sdk(a) # (DLSS frame generation's files, with the same tick)
|
||||
# (AMD FSR 4: the build's switch for nx2/build.py, and the folder's mark for the next --update)
|
||||
if fsr_wanted(a, out):
|
||||
os.environ["HOOKSHOT_FSR"] = "1"
|
||||
fetch_fsr_runtime(work) # (AMD's two libraries, for the game folder: place_fsr_runtime at the end)
|
||||
open(os.path.join(out, FSR_MARK), "w").close()
|
||||
if os.environ.get("HOOKSHOT_VK_PREBUILT"): # (the AppImage's back end, built without FSR 4)
|
||||
print("--fsr: this build uses the prebuilt Vulkan back end (HOOKSHOT_VK_PREBUILT), which has no AMD FSR 4: the "
|
||||
@@ -1709,6 +1809,8 @@ def main(a=None):
|
||||
pass
|
||||
drop_old_program(out)
|
||||
place_ngx_runtime(out)
|
||||
place_dlssg_runtime(out)
|
||||
place_fsr_runtime(out, work, os.environ.get("HOOKSHOT_FSR") == "1")
|
||||
# every shader of the game, for its first start to translate (gpu/vk/vk_shader.cpp seed_open). Without it the game still runs, compiling them
|
||||
# as it meets them: not worth stopping a finished build for
|
||||
if run(shader_census_cmd(romfs, os.path.join(out, "triforce_shaders.bin")), check=False, output=sys.stderr):
|
||||
|
||||
@@ -372,6 +372,42 @@ SOLVER_NEW = SOLVER_OLD.replace(
|
||||
SOLVER_DECL = "extern uint32_t hos_oot_solver_steps(uint32_t game, uint32_t scaled_bits, uint32_t per_frame_bits);\n"
|
||||
|
||||
|
||||
# Three more places that go wrong with a frame step under one frame (host/oot_high_fps.h has why and the logic; at a cap of 60 the
|
||||
# host hands back what the game computes). Found and fixed for this build by NX2navi (its recomp/patches-v111.txt, the sets
|
||||
# ofollow, owater and orecord: main+0x13d704, +0x13a064, +0x389ac20; +0x3876014, +0x38827f8, +0x632cfc; +0x32926c8, +0x3293410,
|
||||
# +0x3296b08, +0x3296da4; main is at 0x80020000 here), there as code words, here as hooks in the lifted C:
|
||||
# - the character controller's three follow-surface updates compare the physics' inverse step with 100.0 and keep a tenth of
|
||||
# the floor's velocity above it: every update above 100 fps, so a moving platform slid out from under Link. The 100.0 comes
|
||||
# from hos_oot_floor_cut (100 / the frame's 60 fps frames while that is under one).
|
||||
# - the two water managers and the interactive floors (the Deku Tree's ground webs) run seconds / (1/60 s), cut to whole,
|
||||
# fixed steps: none in an update shorter than 1/60 s, so the surfaces stood still above 60 fps. Before the cut the quotient
|
||||
# goes through hos_oot_sim_steps (x19 the object, each function's x0): the whole steps with the object's remainder kept.
|
||||
# - the ocarina recorder's clock adds (unsigned)frame step at four places: 0 above 60 fps, so a recording lost its rests.
|
||||
# hos_oot_record_frames carries the fraction.
|
||||
FLOOR_HEADS = ("void f_8015d490(Ctx *__restrict A64_NOESC c) {\n", "void f_80159dc0(Ctx *__restrict A64_NOESC c) {\n",
|
||||
"void f_838baa40(Ctx *__restrict A64_NOESC c) {\n")
|
||||
# (mov w8, #0x42c80000; fmov s1, w8: the 100.0 of the compare that follows)
|
||||
FLOOR_OLD = (" c->x[8] = 0x42c80000ULL;\n c->x[8] &= 0xFFFFFFFFULL;\n"
|
||||
" { a64_vset64(c->vreg[1],0); memcpy(&c->vreg[1][0],&c->x[8],4); }\n")
|
||||
FLOOR_NEW = FLOOR_OLD.replace("c->x[8] = 0x42c80000ULL;",
|
||||
"c->x[8] = hos_oot_floor_cut(); /* (nx2/oot_patches.py: a floor's carry above 100 fps) */", 1)
|
||||
FLOOR_DECL = "extern uint32_t hos_oot_floor_cut(void);\n"
|
||||
# (a function and the register its cut goes to: fdiv s0, s8, s0 then fcvtzs w<n>, s0, the function's one cut of s0 into that register)
|
||||
SIM_SITES = (("void f_83895f20(Ctx *__restrict A64_NOESC c) {\n", 8), ("void f_838a2660(Ctx *__restrict A64_NOESC c) {\n", 8),
|
||||
("void f_80652cb0(Ctx *__restrict A64_NOESC c) {\n", 22))
|
||||
SIM_OLD = " c->x[%d]=recomp_fp_to_int(c->vreg[0][0]&UINT64_C(0xffffffff),32,32,1,3,c->fpcr,&c->fpsr);\n"
|
||||
SIM_HOOK = (" a64_vset64(c->vreg[0],hos_oot_sim_steps(c->x[19], (uint32_t)c->vreg[0][0]));"
|
||||
" /* (nx2/oot_patches.py: fixed steps above 60 fps) */\n")
|
||||
SIM_DECL = "extern uint32_t hos_oot_sim_steps(uint64_t object, uint32_t quotient_bits);\n"
|
||||
# (a function and how many times it adds the step to the clock: fcvtzu w8, s0)
|
||||
RECORD_SITES = (("void f_832b2690(Ctx *__restrict A64_NOESC c) {\n", 1), ("void f_832b32b0(Ctx *__restrict A64_NOESC c) {\n", 1),
|
||||
("void f_832b6840(Ctx *__restrict A64_NOESC c) {\n", 2))
|
||||
RECORD_OLD = " c->x[8]=recomp_fp_to_int(c->vreg[0][0]&UINT64_C(0xffffffff),32,32,0,3,c->fpcr,&c->fpsr);\n"
|
||||
RECORD_NEW = (" c->x[8]=hos_oot_record_frames((uint32_t)c->vreg[0][0]);"
|
||||
" /* (nx2/oot_patches.py: the ocarina recorder's clock above 60 fps) */\n")
|
||||
RECORD_DECL = "extern uint32_t hos_oot_record_frames(uint32_t step_bits);\n"
|
||||
|
||||
|
||||
def _function(s, head_text):
|
||||
"""(start, end) of the function whose head is head_text, or None"""
|
||||
head = s.find(head_text)
|
||||
@@ -420,6 +456,108 @@ def patch_solver_steps(s):
|
||||
return s, done
|
||||
|
||||
|
||||
def patch_floor_carry(s):
|
||||
"""The follow-surface updates' compare: (s, how many of the three are in s with the hook, made now or before)"""
|
||||
done = 0
|
||||
for head_text in FLOOR_HEADS:
|
||||
at = _function(s, head_text)
|
||||
if at is None:
|
||||
continue
|
||||
head, end = at
|
||||
body = s[head:end]
|
||||
if body.count(FLOOR_NEW) == 1:
|
||||
done += 1
|
||||
elif body.count(FLOOR_OLD) == 1:
|
||||
s = s[:head] + body.replace(FLOOR_OLD, FLOOR_NEW, 1) + s[end:]
|
||||
done += 1
|
||||
if done and FLOOR_DECL not in s:
|
||||
s = s.replace('#include "a64.h"\n', '#include "a64.h"\n' + FLOOR_DECL, 1)
|
||||
return s, done
|
||||
|
||||
|
||||
def patch_sim_steps(s):
|
||||
"""The height-field surfaces' fixed steps: (s, how many of the three places are in s with the hook, made now or before)"""
|
||||
done = 0
|
||||
for head_text, reg in SIM_SITES:
|
||||
at = _function(s, head_text)
|
||||
if at is None:
|
||||
continue
|
||||
head, end = at
|
||||
body = s[head:end]
|
||||
old = SIM_OLD % reg
|
||||
if body.count(SIM_HOOK + old) == 1:
|
||||
done += 1
|
||||
elif body.count(old) == 1 and SIM_HOOK not in body:
|
||||
s = s[:head] + body.replace(old, SIM_HOOK + old, 1) + s[end:]
|
||||
done += 1
|
||||
if done and SIM_DECL not in s:
|
||||
s = s.replace('#include "a64.h"\n', '#include "a64.h"\n' + SIM_DECL, 1)
|
||||
return s, done
|
||||
|
||||
|
||||
def patch_record_clock(s):
|
||||
"""The ocarina recorder's clock: (s, how many of its four adds are in s with the hook, made now or before). A function
|
||||
whose adds are not as many as RECORD_SITES says (another game version) is left as it is."""
|
||||
done = 0
|
||||
for head_text, count in RECORD_SITES:
|
||||
at = _function(s, head_text)
|
||||
if at is None:
|
||||
continue
|
||||
head, end = at
|
||||
body = s[head:end]
|
||||
if body.count(RECORD_NEW) == count and RECORD_OLD not in body:
|
||||
done += count
|
||||
elif body.count(RECORD_OLD) == count and RECORD_NEW not in body:
|
||||
s = s[:head] + body.replace(RECORD_OLD, RECORD_NEW) + s[end:]
|
||||
done += count
|
||||
if done and RECORD_DECL not in s:
|
||||
s = s.replace('#include "a64.h"\n', '#include "a64.h"\n' + RECORD_DECL, 1)
|
||||
return s, done
|
||||
|
||||
|
||||
# The sprint button (host/oot_sprint.h has the rules, host/oot_sprint.c the game's addresses; after NX2navi's set "sprint").
|
||||
# Link sprints while his input flags hold the dash input (bit 4), which the game sets only out of a roll. Two functions load
|
||||
# those flags and test the bit: his movement update f_804caa80 (to start the sprint and to keep it), and the update of his
|
||||
# stance and camera f_80c225d0 (the low byte). After each load the host gets the flags and gives them back, with the bit
|
||||
# while the button's sprint is on. With the Sprint button row off the call returns what it got.
|
||||
SPRINT_LINK_HEAD = "void f_804caa80(Ctx *__restrict A64_NOESC c) {\n"
|
||||
SPRINT_LINK_OLD = (" c->x[10]=recomp_load64(c,c->x[19] + 80);\n"
|
||||
" c->x[9]=recomp_load32(c,c->x[19] + 44);\n"
|
||||
" c->x[10]=recomp_load64(c,c->x[10] + 0);\n")
|
||||
SPRINT_LINK_ADD = " c->x[10]=hos_oot_sprint_link(c,c->x[19],c->x[10]); /* (nx2/oot_patches.py: the sprint button) */\n"
|
||||
SPRINT_STANCE_HEAD = "void f_80c225d0(Ctx *__restrict A64_NOESC c) {\n"
|
||||
SPRINT_STANCE_OLD = (" c->x[8]=recomp_load64(c,c->x[19] + 80);\n"
|
||||
" c->x[8]=recomp_load8(c,c->x[8] + 0);\n"
|
||||
"if (((c->x[8] >> 4) & 1)) { goto L_80c27f54; }\n")
|
||||
SPRINT_STANCE_NEW = (" c->x[8]=recomp_load64(c,c->x[19] + 80);\n"
|
||||
" c->x[8]=recomp_load8(c,c->x[8] + 0);\n"
|
||||
" c->x[8]=hos_oot_sprint_stance(c,c->x[19],c->x[8]); /* (nx2/oot_patches.py: the sprint button) */\n"
|
||||
"if (((c->x[8] >> 4) & 1)) { goto L_80c27f54; }\n")
|
||||
SPRINT_DECL = ("extern uint64_t hos_oot_sprint_link(Ctx *c, uint64_t link, uint64_t flags);\n"
|
||||
"extern uint64_t hos_oot_sprint_stance(Ctx *c, uint64_t link, uint64_t flags);\n")
|
||||
|
||||
|
||||
def patch_sprint(s):
|
||||
"""The sprint button's two calls: (s, how many of the two are in s, made now or before). A function whose code differs
|
||||
(another game version) is left as it is."""
|
||||
done = 0
|
||||
for head_text, old, new in ((SPRINT_LINK_HEAD, SPRINT_LINK_OLD, SPRINT_LINK_OLD + SPRINT_LINK_ADD),
|
||||
(SPRINT_STANCE_HEAD, SPRINT_STANCE_OLD, SPRINT_STANCE_NEW)):
|
||||
at = _function(s, head_text)
|
||||
if at is None:
|
||||
continue
|
||||
head, end = at
|
||||
body = s[head:end]
|
||||
if body.count(new) == 1:
|
||||
done += 1
|
||||
elif body.count(old) == 1:
|
||||
s = s[:head] + body.replace(old, new) + s[end:]
|
||||
done += 1
|
||||
if done and SPRINT_DECL not in s:
|
||||
s = s.replace('#include "a64.h"\n', '#include "a64.h"\n' + SPRINT_DECL, 1)
|
||||
return s, done
|
||||
|
||||
|
||||
def patch_text_speed(s):
|
||||
"""The scale at the head of the letters' block of f_80b1e140; None when the file has no such function, s unchanged when the
|
||||
function is there but its code differs (another game version)."""
|
||||
@@ -476,6 +614,8 @@ def apply(gen, *, protect_hearts=False, required=False):
|
||||
step_sites, step_files = 0, [] # (the divides with the hook, and the files that have it)
|
||||
whole_sites = 0 # (the counters of WHOLE_SITES with the whole frames: patch_whole_frames)
|
||||
sound_jobs = solver_sites = 0 # (patch_sound_job, patch_solver_steps: the places found with their hooks)
|
||||
floor_sites = sim_sites = record_sites = 0 # (patch_floor_carry, patch_sim_steps, patch_record_clock: the same)
|
||||
sprint_sites = 0 # (patch_sprint: its two calls)
|
||||
for path in sorted(glob.glob(os.path.join(glob.escape(gen), "code_*.c"))):
|
||||
with open(path, encoding="utf-8", newline="") as f:
|
||||
s = f.read()
|
||||
@@ -561,12 +701,41 @@ def apply(gen, *, protect_hearts=False, required=False):
|
||||
if solver != out:
|
||||
print("oot_patches: the solver steps rounded up above 60 fps in", os.path.basename(path))
|
||||
out = solver
|
||||
floor, found = patch_floor_carry(out)
|
||||
floor_sites += found
|
||||
if floor != out:
|
||||
print("oot_patches: a floor's carry above 100 fps in", os.path.basename(path))
|
||||
out = floor
|
||||
sim, found = patch_sim_steps(out)
|
||||
sim_sites += found
|
||||
if sim != out:
|
||||
print("oot_patches: the water and floor surfaces' fixed steps above 60 fps in", os.path.basename(path))
|
||||
out = sim
|
||||
record, found = patch_record_clock(out)
|
||||
record_sites += found
|
||||
if record != out:
|
||||
print("oot_patches: the ocarina recorder's clock above 60 fps in", os.path.basename(path))
|
||||
out = record
|
||||
sprinted, found = patch_sprint(out)
|
||||
sprint_sites += found
|
||||
if sprinted != out:
|
||||
print("oot_patches: the sprint button in", os.path.basename(path))
|
||||
out = sprinted
|
||||
if out != s:
|
||||
whole_write.write_whole(path, out, newline="")
|
||||
if sound_jobs != 1: # (without it, above 60 fps sounds and then the music can stop after a few loading zones)
|
||||
print("oot_patches: WARNING: the sound job was found %d times, not once" % sound_jobs)
|
||||
if solver_sites != len(SOLVER_HEADS): # (without them, above 60 fps moving platforms can drop Link)
|
||||
print("oot_patches: WARNING: the solver step count was found at %d of %d places" % (solver_sites, len(SOLVER_HEADS)))
|
||||
if floor_sites != len(FLOOR_HEADS): # (without them, above 100 fps a moving platform carries Link at a tenth of its speed)
|
||||
print("oot_patches: WARNING: a floor's carry was found at %d of %d places" % (floor_sites, len(FLOOR_HEADS)))
|
||||
if sim_sites != len(SIM_SITES): # (without them, above 60 fps the water and web surfaces stand still)
|
||||
print("oot_patches: WARNING: the surfaces' fixed steps were found at %d of %d places" % (sim_sites, len(SIM_SITES)))
|
||||
if record_sites != sum(n for _, n in RECORD_SITES): # (without them, above 60 fps a recorded song loses its rests)
|
||||
print("oot_patches: WARNING: the ocarina recorder's clock was found at %d of %d places"
|
||||
% (record_sites, sum(n for _, n in RECORD_SITES)))
|
||||
if sprint_sites != 2: # (without them the Sprint button row does nothing)
|
||||
print("oot_patches: WARNING: the sprint button's calls were found at %d of 2 places" % sprint_sites)
|
||||
for what, n in done.items():
|
||||
if n != 1:
|
||||
print("oot_patches: WARNING: the %s was found %d times" % (what, n))
|
||||
|
||||
@@ -40,13 +40,15 @@ def _size(name):
|
||||
% (name, name, name))
|
||||
|
||||
|
||||
HUD = ("{ extern volatile float hos_wide_squeeze; const float _q = hos_wide_squeeze; if (_q > 0.0f) { float _m00, _m11; "
|
||||
# (the row goes to the host with the canvas' screen: host/oot_wide_hud.c keeps it for the screens of KEEP_VTABLES, squeezes it
|
||||
# for the rest, and moves the layouts of its table out to an edge with the Insert menu's Ultrawide HUD row on Screen edges)
|
||||
HUD = ("{ extern volatile float hos_wide_squeeze; if (hos_wide_squeeze > 0.0f) { float _m00, _m11; "
|
||||
"memcpy(&_m00, c->vreg[1], 4); memcpy(&_m11, (const uint8_t *)c->vreg[4] + 4, 4); "
|
||||
"if (_m00 == %s && _m11 == %s) { const uint64_t _vt = recomp_load64(c, c->x[0] - 0x1b8); "
|
||||
"extern volatile uint32_t hos_wide_keep_mask; const uint32_t _kb = %s; "
|
||||
"if (!(_kb & hos_wide_keep_mask)) { float _row[4]; memcpy(_row, c->vreg[1], 16); for (int _k = 0; _k < 4; _k++) _row[_k] *= _q; "
|
||||
"memcpy(c->vreg[1], _row, 16); } } } } /* (nx2/oot_wide.py: HUD in the middle 16:9) */"
|
||||
% (UI_M00, UI_M11, " : ".join("_vt == 0x%xULL ? %du" % (v, 1 << k) for k, v in enumerate(KEEP_VTABLES)) + " : 0u"))
|
||||
"if (_m00 == %s && _m11 == %s) { extern void hos_wide_hud_row(Ctx *c, uint64_t screen, float *first, float *move); "
|
||||
"float _row[4], _tx; memcpy(_row, c->vreg[1], 16); memcpy(&_tx, c->vreg[6], 4); "
|
||||
"hos_wide_hud_row(c, c->x[0] - 0x1b8, _row, &_tx); memcpy(c->vreg[1], _row, 16); memcpy(c->vreg[6], &_tx, 4); } } }"
|
||||
" /* (nx2/oot_wide.py: HUD in the middle 16:9, or at the screen's edges) */"
|
||||
% (UI_M00, UI_M11))
|
||||
|
||||
MOVIE = ("{ extern volatile float hos_wide_margin; const float _m = hos_wide_margin; if (_m > 0.0f) { "
|
||||
"const uint64_t _vp = c->x[29] - 40; uint32_t _ua = (uint32_t)recomp_load32(c, _vp + 8), _ub = (uint32_t)recomp_load32(c, _vp + 16); "
|
||||
|
||||
@@ -59,8 +59,9 @@ SWITCH_ICON = {"south": 0xE041, "east": 0xE040, "west": 0xE043, "north": 0xE042,
|
||||
STATIC = {0xE049: "dpad", 0xE064: "dpad_vertical_outline", 0xE065: "dpad_horizontal_outline"}
|
||||
|
||||
|
||||
def zs_dictionary(romfs):
|
||||
"""zs.zsdic, out of Pack/ZsDic.pack.zs (a SARC, itself zstd without a dictionary)"""
|
||||
def zs_dictionary(romfs, which=b"zs.zsdic"):
|
||||
"""zs.zsdic (or another of its dictionaries: pack.zsdic for the packs), out of Pack/ZsDic.pack.zs (a SARC, itself zstd
|
||||
without a dictionary)"""
|
||||
import zstandard
|
||||
with open(os.path.join(romfs, "Pack", "ZsDic.pack.zs"), "rb") as f:
|
||||
b = zstandard.ZstdDecompressor().decompressobj().decompress(f.read())
|
||||
@@ -71,9 +72,9 @@ def zs_dictionary(romfs):
|
||||
for i in range(n):
|
||||
attr, start, end = struct.unpack_from("<III", b, hl + 12 + 16 * i + 4)
|
||||
o = names + (attr & 0xFFFFFF) * 4
|
||||
if b[o:b.index(b"\0", o)] == b"zs.zsdic":
|
||||
if b[o:b.index(b"\0", o)] == which:
|
||||
return b[data + start:data + end]
|
||||
raise SystemExit("prompts: no zs.zsdic in Pack/ZsDic.pack.zs")
|
||||
raise SystemExit("prompts: no %s in Pack/ZsDic.pack.zs" % which.decode())
|
||||
|
||||
|
||||
def read_zs(romfs, rel, dictionary):
|
||||
@@ -893,6 +894,152 @@ def dump(out, face, b, tex, layers):
|
||||
decode(b, tex[layer.texture]).save(game)
|
||||
|
||||
|
||||
# ---- the hearts, the item slot and the small map on a picture wider than 16:9 (in the same archive, four copies of each
|
||||
# layout). With the Insert menu's Ultrawide HUD row on Screen edges host/prompts.c moves these panes out to the picture's
|
||||
# sides (host/oot_wide_hud.h has the rule). They are moved in the layouts because a layout's projection cannot do it:
|
||||
# - PlayerStatus_00 hangs the hearts, the magic bar and the D-pad's shortcuts on a pane at the 16:9 grid's top left corner and
|
||||
# the item slot on one at its top right: two sides in one layout;
|
||||
# - MapMenu_00 is the small map in the corner and the menu's whole-screen map in one layout, and the game sets a layout's
|
||||
# projection once, not as the menu opens. The small map's own panes go out; its icons' layers (N_PatternFieldMini_01,
|
||||
# N_PatternDungeonMini_01) are put at the small map's place by an animation's keys, which go out with them (layout_keys).
|
||||
# prompts/wide.bin: "HPWD", u32 count, then each: u32 offset (an x in prompts/Common.blarc), i8 side (-1 left, 1 right),
|
||||
# u8 0 x3, f32 the x
|
||||
HUD_SIDE_PANES = {
|
||||
"PlayerStatus_00": {"N_ScaleL_00": -1, "N_ScaleR_00": 1, "N_VRS_00": 1, "N_SubItemBaseFishing_00": 1},
|
||||
"MapMenu_00": {"N_VRS_00": 1, "N_MiniMapCap_00": 1, "N_Field_01": 1, "N_Dungeon_01": 1, "N_MiniMapReplace_00": 1,
|
||||
"P_MiniMapFrame_00": 1, "S_Floor_00": 1, "P_CapDungeon_00": 1},
|
||||
}
|
||||
HUD_CORNERS = {"N_ScaleL_00": -1920.0, "N_ScaleR_00": 1920.0} # (the grid's corners: half its width out)
|
||||
|
||||
|
||||
def layout_keys(lay, xs):
|
||||
"""the offsets of the animation keys of a layout that put a pane at one of the places xs: a curve's values are an array (u64
|
||||
offset of the floats, u32 count, u32 4, the floats) of (value, slope) pairs; taken when every slope is 0 and every value is
|
||||
0 or one of xs, with one of xs among them. The float 8 bytes before the array, the curve's value past its last key, too"""
|
||||
out = []
|
||||
for o in range(0, len(lay) - 16, 8):
|
||||
at, n, size = struct.unpack_from("<QII", lay, o)
|
||||
if at != o + 16 or size != 4 or not 2 <= n <= 256 or n % 2 or at + 4 * n > len(lay):
|
||||
continue
|
||||
v = struct.unpack_from(f"<{n}f", lay, at)
|
||||
if any(v[1::2]) or not any(k in xs for k in v[::2]) or any(k and k not in xs for k in v[::2]):
|
||||
continue
|
||||
out += [at + 8 * k for k in range(n // 2) if v[2 * k] in xs]
|
||||
if o >= 8 and struct.unpack_from("<f", lay, o - 8)[0] in xs:
|
||||
out.append(o - 8)
|
||||
return out
|
||||
|
||||
|
||||
def wide_panes(blarc):
|
||||
"""what goes out to a wide picture's sides, in every copy: [(offset of an x, side, x)], or None when a layout is not the
|
||||
one known: a pane missing, a corner pane not at the grid's corner, a place that two sides share, or one of the places held
|
||||
somewhere else in the layout than in those panes and keys (something else the game would leave where it is)"""
|
||||
out = []
|
||||
for name, sides in HUD_SIDE_PANES.items():
|
||||
copies = layout_copies(blarc, name)
|
||||
if not copies:
|
||||
return None
|
||||
for a, z in copies:
|
||||
lay = blarc[a:z]
|
||||
panes = layout_panes(lay)
|
||||
if any(p not in panes for p in sides):
|
||||
return None
|
||||
side_of, at = {}, {}
|
||||
for p, side in sides.items():
|
||||
x = struct.unpack_from("<f", lay, panes[p] + 0x1c)[0]
|
||||
if x == 0.0 or HUD_CORNERS.get(p, x) != x or side_of.setdefault(x, side) != side:
|
||||
return None
|
||||
at[panes[p] + 0x1c] = x
|
||||
for o in layout_keys(lay, set(side_of)):
|
||||
at[o] = struct.unpack_from("<f", lay, o)[0]
|
||||
for x in side_of:
|
||||
pat = struct.pack("<f", x)
|
||||
if any(lay[o:o + 4] == pat and o not in at for o in range(0, len(lay) - 3, 4)):
|
||||
return None
|
||||
out += [(a + o, side_of[x], x) for o, x in sorted(at.items())]
|
||||
return out or None
|
||||
|
||||
|
||||
def write_wide(path, panes):
|
||||
with open(path, "wb") as f:
|
||||
f.write(b"HPWD" + struct.pack("<I", len(panes)))
|
||||
for off, side, x in panes:
|
||||
f.write(struct.pack("<Ib3xf", off, side, x))
|
||||
|
||||
|
||||
# ---- the camera's speed (the Insert menu's Camera speed row, host/prompts.c build_camera; NX2navi's camera speed setting, done
|
||||
# with the files the prompts already use). The game's Options offer five camera sensitivities; their turn rates are the array
|
||||
# StickSensitivity of Component/PlayerCameraParam/PlayerCamera.game__component__PlayerCameraParam.bgyml in
|
||||
# Pack/Actor/PlayerCamera.pack.zs (a SARC, zstd with pack.zsdic). A BYML array keeps its floats in the array itself, so the
|
||||
# host writes each times the row's factor over the old one and nothing else moves. prompts/PlayerCamera.pack is the game's
|
||||
# pack decompressed; prompts/camera.bin: "HPCM", u32 count, then each: u32 offset (a value in the pack), f32 the game's value
|
||||
CAMERA = "Pack/Actor/PlayerCamera.pack.zs"
|
||||
CAMERA_MEMBER = "Component/PlayerCameraParam/PlayerCamera.game__component__PlayerCameraParam.bgyml"
|
||||
CAMERA_KEY = "StickSensitivity"
|
||||
|
||||
|
||||
def sarc_member(b, name):
|
||||
"""(start, end) of the file `name` in the SARC b, or None"""
|
||||
if b[:4] != b"SARC" or len(b) < 0x20:
|
||||
return None
|
||||
hl, = struct.unpack_from("<H", b, 4)
|
||||
data, = struct.unpack_from("<I", b, 12)
|
||||
n, = struct.unpack_from("<H", b, hl + 6)
|
||||
names = hl + 12 + 16 * n + 8
|
||||
for i in range(n):
|
||||
attr, start, end = struct.unpack_from("<III", b, hl + 12 + 16 * i + 4)
|
||||
o = names + (attr & 0xFFFFFF) * 4
|
||||
if 0 <= o < len(b) and b[o:b.find(b"\0", o)] == name.encode():
|
||||
return (data + start, data + end) if data + end <= len(b) and start <= end else None
|
||||
return None
|
||||
|
||||
|
||||
def byml_floats(d, key):
|
||||
"""[(offset, value)] of the floats of the array `key` in the root dictionary of the BYML d (little-endian: "YB", u16
|
||||
version, u32 keys' table, u32 strings' table, u32 root; a dictionary: 0xc1, u24 count, then (u24 key, u8 type, u32 value)
|
||||
each; an array: 0xc0, u24 count, a type byte each, padded to 4, then the values; 0xd2 a float), or None"""
|
||||
try:
|
||||
if d[:2] != b"YB":
|
||||
return None
|
||||
keys, root = struct.unpack_from("<I", d, 4)[0], struct.unpack_from("<I", d, 12)[0]
|
||||
kh, rh = struct.unpack_from("<I", d, keys)[0], struct.unpack_from("<I", d, root)[0]
|
||||
if kh & 0xff != 0xc2 or rh & 0xff != 0xc1:
|
||||
return None
|
||||
for i in range(rh >> 8):
|
||||
e, value = struct.unpack_from("<II", d, root + 4 + 8 * i)
|
||||
if (e & 0xffffff) >= kh >> 8:
|
||||
return None
|
||||
at = keys + struct.unpack_from("<I", d, keys + 4 + 4 * (e & 0xffffff))[0]
|
||||
if d[at:d.index(b"\0", at)] != key.encode():
|
||||
continue
|
||||
ah = struct.unpack_from("<I", d, value)[0]
|
||||
count = ah >> 8
|
||||
if e >> 24 != 0xc0 or ah & 0xff != 0xc0 or not 1 <= count <= 8 or set(d[value + 4:value + 4 + count]) != {0xd2}:
|
||||
return None
|
||||
vals = value + 4 + ((count + 3) & ~3)
|
||||
return [(vals + 4 * j, struct.unpack_from("<f", d, vals + 4 * j)[0]) for j in range(count)]
|
||||
except (struct.error, ValueError):
|
||||
pass
|
||||
return None
|
||||
|
||||
|
||||
def camera_speeds(pack):
|
||||
"""the camera's turn rates in the pack: [(offset in the pack, value)], or None when the pack is not the one known (no such
|
||||
file or array in it, or a rate that is no speed)"""
|
||||
at = sarc_member(pack, CAMERA_MEMBER)
|
||||
floats = byml_floats(pack[at[0]:at[1]], CAMERA_KEY) if at else None
|
||||
if not floats or any(not 0.05 <= v <= 50.0 for _, v in floats):
|
||||
return None
|
||||
return [(at[0] + o, v) for o, v in floats]
|
||||
|
||||
|
||||
def write_camera(path, speeds):
|
||||
with open(path, "wb") as f:
|
||||
f.write(b"HPCM" + struct.pack("<I", len(speeds)))
|
||||
for off, v in speeds:
|
||||
f.write(struct.pack("<If", off, v))
|
||||
|
||||
|
||||
def main():
|
||||
ap = argparse.ArgumentParser()
|
||||
ap.add_argument("--romfs", required=True)
|
||||
@@ -941,9 +1088,28 @@ def main():
|
||||
dump(a.dump, face, textures, tex, layers)
|
||||
print(f"prompts: {face}", file=sys.stderr)
|
||||
ring = ring_entries(blarc)
|
||||
if ring or hint:
|
||||
wide = wide_panes(blarc)
|
||||
if ring or hint or wide:
|
||||
with open(os.path.join(a.out, "Common.blarc"), "wb") as f:
|
||||
f.write(blarc)
|
||||
if wide:
|
||||
write_wide(os.path.join(a.out, "wide.bin"), wide)
|
||||
else:
|
||||
print("prompts: the hearts and the item slot stay in the middle of a wide picture (their layout is not the one known)",
|
||||
file=sys.stderr)
|
||||
speeds = None
|
||||
try:
|
||||
pack = read_zs(a.romfs, CAMERA, zs_dictionary(a.romfs, b"pack.zsdic"))
|
||||
speeds = camera_speeds(pack)
|
||||
except (Exception, SystemExit) as e: # (a romfs without the pack, or one that does not decompress)
|
||||
print(f"prompts: the camera's pack was not read ({e})", file=sys.stderr)
|
||||
if speeds:
|
||||
with open(os.path.join(a.out, "PlayerCamera.pack"), "wb") as f:
|
||||
f.write(pack)
|
||||
write_camera(os.path.join(a.out, "camera.bin"), speeds)
|
||||
print("prompts: the camera's speeds " + " ".join("%.2f" % v for _, v in speeds), file=sys.stderr)
|
||||
else:
|
||||
print("prompts: the camera keeps the game's speed (its pack is not the one known)", file=sys.stderr)
|
||||
if ring:
|
||||
write_ring(os.path.join(a.out, "ring.bin"), ring)
|
||||
print("prompts: the Talk ring", file=sys.stderr)
|
||||
|
||||
@@ -61,8 +61,13 @@ MARK_NATIVE_64 = r"""extern uint8_t a64_dirty[A64_DIRTY_PAGES];
|
||||
/* (Tried 2026-10-21: reading a mark first and writing it only when clear, against cache lines moving between cores:
|
||||
game threads +1.1 ms a frame, the code 18 MB bigger. Not kept.) */
|
||||
#define A64_DIRTY_AT(a) (((uint64_t)(a) >> 12) & (A64_DIRTY_PAGES - 1))
|
||||
#ifdef A64_MARK_ONE /* (triforce, build.py RX_MARK_ONE=1: the first byte's page alone. The collection takes a mark as "this page
|
||||
and the next", host/rx_backend.c collect_in: a store of up to 4 KB reaches no further) */
|
||||
#define A64_MARK(a, n) (__atomic_store_n(&a64_dirty[A64_DIRTY_AT(a)], 1, __ATOMIC_RELEASE))
|
||||
#else
|
||||
#define A64_MARK(a, n) (__atomic_store_n(&a64_dirty[A64_DIRTY_AT(a)], 1, __ATOMIC_RELEASE), \
|
||||
__atomic_store_n(&a64_dirty[A64_DIRTY_AT((a) + (n) - 1)], 1, __ATOMIC_RELEASE))"""
|
||||
__atomic_store_n(&a64_dirty[A64_DIRTY_AT((a) + (n) - 1)], 1, __ATOMIC_RELEASE))
|
||||
#endif"""
|
||||
|
||||
SUBST = {
|
||||
"a64.h": [
|
||||
|
||||
Reference in New Issue
Block a user