mirror of
https://git.triforceproject.com/triforce/source
synced 2026-11-21 00:59:59 -04:00
Triforce v0.6.0 "Sage Of Power"
Faster frames (the replay's memory work, held submits, helper threads, collection and capture cuts), the game letting old areas go (QueryMemoryInfo), the 0.5.2 stutter fixed, AMD RX 5000/6000 and integrated-GPU fixes, the GPU device chosen by name, the in-game menus and launcher reworked, controller, Linux and benchmark fixes.
This commit is contained in:
@@ -296,10 +296,28 @@ def output_lines(p, silence):
|
||||
yield line
|
||||
|
||||
|
||||
def run(cmd, env=None, on_line=None, check=True, output=None, show=None, cwd=ROOT, base=None, silence=None):
|
||||
def stop_asked(p, stop, wait):
|
||||
"""A silent step asked to stop by the file `stop` (written here), given `wait` seconds to end by itself, then killed. True:
|
||||
it ended by itself"""
|
||||
try:
|
||||
with open(stop, "wb"):
|
||||
pass
|
||||
except OSError:
|
||||
return False
|
||||
try:
|
||||
p.wait(timeout=wait)
|
||||
return True
|
||||
except subprocess.TimeoutExpired:
|
||||
return False
|
||||
|
||||
|
||||
def run(cmd, env=None, on_line=None, check=True, output=None, show=None, cwd=ROOT, base=None, silence=None, stop=None,
|
||||
stop_wait=60):
|
||||
"""A step, its output printed as it comes. show: what of each line is printed (its None: nothing; on_line and a failure's
|
||||
reason still get the line itself). base: the environment it starts from (os.environ). silence: seconds without a line after
|
||||
which the step is stopped; it returns None then (with check, the build fails)"""
|
||||
which the step is stopped; it returns None then (with check, the build fails). stop: a file the step reads as a request to
|
||||
stop (the game's triforce_prepare.stop): on silence it is written first, and the step killed only if it has not ended
|
||||
stop_wait seconds later"""
|
||||
e = dict(os.environ if base is None else base, PYTHONIOENCODING="utf-8")
|
||||
e.update(env or {})
|
||||
p = subprocess.Popen(cmd, cwd=cwd, env=e, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True, encoding="utf-8",
|
||||
@@ -316,8 +334,9 @@ def run(cmd, env=None, on_line=None, check=True, output=None, show=None, cwd=ROO
|
||||
if on_line:
|
||||
on_line(line)
|
||||
except Silent:
|
||||
p.kill()
|
||||
p.wait()
|
||||
if not (stop and stop_asked(p, stop, stop_wait)):
|
||||
p.kill()
|
||||
p.wait()
|
||||
if check:
|
||||
fail("%s printed nothing for %s and was stopped" % (os.path.basename(cmd[0]), span(silence)))
|
||||
return None
|
||||
@@ -1046,6 +1065,11 @@ NOT_PREPARED = "the shaders were not prepared now"
|
||||
# (a run that prints nothing this long is stopped. Not its whole length: that is 25 minutes on some AMD GPUs, and the driver's own
|
||||
# step near the end can sit at 99% for minutes)
|
||||
PREPARE_SILENCE = 15 * 60
|
||||
# ((Triforce, 11-18) a silent run is asked to stop first (gpu/vk/vk_main.cpp PrepareStopWatch: it ends its driver's part
|
||||
# cleanly and keeps what it made; killed, a start in that part used one of its three tries and left variants out for good),
|
||||
# and killed only when it has not ended this long after)
|
||||
PREPARE_STOP = "triforce_prepare.stop"
|
||||
PREPARE_STOP_WAIT = 60
|
||||
GAME_ENV_DROP = ("HOOKSHOT_", "PYTHON", "APPDIR", "APPIMAGE", "ARGV0", "OWD")
|
||||
|
||||
|
||||
@@ -1084,17 +1108,24 @@ def show_prepared(line):
|
||||
return line if line.startswith(("@@stage ", "@@progress ")) or not line.startswith("@@") else line[2:]
|
||||
|
||||
|
||||
def prepare_shaders(cmd, folder=None, silence=PREPARE_SILENCE):
|
||||
def prepare_shaders(cmd, folder=None, silence=PREPARE_SILENCE, stop=None, stop_wait=PREPARE_STOP_WAIT):
|
||||
"""The shaders prepared now, under the builder's progress bar, not at the game's first start behind a black window (minutes on
|
||||
some GPUs, issue 711): hookshot --prepare-shaders (host/hos_main.c, gpu/vk/vk_main.cpp), the same work as that first start, in
|
||||
the game's folder and environment, as the builders' Play starts it. A PC whose Vulkan can't (exit 3), a run silent for `silence` seconds (then stopped), or
|
||||
any other failure leaves the work to the first start, as before: never a failed build. Returns its exit code (None: stopped)"""
|
||||
any other failure leaves the work to the first start, as before: never a failed build. Returns its exit code (None: stopped).
|
||||
stop: the game's stop request, PREPARE_STOP beside it (a stale one is removed first, and the one written here after)"""
|
||||
stop = stop or os.path.join(os.path.dirname(os.path.abspath(cmd[0])), PREPARE_STOP)
|
||||
with contextlib.suppress(OSError):
|
||||
os.remove(stop)
|
||||
try:
|
||||
code = run(cmd, check=False, show=show_prepared, cwd=folder or os.path.dirname(cmd[0]) or None,
|
||||
base=game_env(), silence=silence)
|
||||
base=game_env(), silence=silence, stop=stop, stop_wait=stop_wait)
|
||||
except OSError as e:
|
||||
not_prepared(str(e))
|
||||
return 1
|
||||
finally:
|
||||
with contextlib.suppress(OSError):
|
||||
os.remove(stop)
|
||||
if code is None:
|
||||
not_prepared("the game printed nothing for %s and was stopped" % span(silence))
|
||||
elif code == 3:
|
||||
@@ -1656,6 +1687,11 @@ def fsr_wanted(a, out):
|
||||
MIT headers are in third_party/fidelityfx and its DLLs are the player's (the readme)"""
|
||||
if getattr(a, "no_fsr", False):
|
||||
return False
|
||||
# ((Triforce) 11-20, ticket "No FSR4 option in game even though provided library apparently loaded": HOOKSHOT_FSR=1, which
|
||||
# nx2/build.py and the docs name, was taken away below unless --fsr was given too, so a Linux build with it set had no FSR 4.
|
||||
# Set in the environment, it asks for FSR 4 as --fsr does)
|
||||
if os.environ.get("HOOKSHOT_FSR", "") == "1":
|
||||
return True
|
||||
return bool(getattr(a, "fsr", False)) or bool(a.update and os.path.isfile(os.path.join(out, FSR_MARK)))
|
||||
|
||||
|
||||
|
||||
@@ -19,6 +19,9 @@ Each is a runtime switch where it can be, so the game's own path stays reachable
|
||||
- The OptimizeChangeBank thread's allocations tried again when their heap is full (host/oot_heap_retry.c): f_804566e0's two
|
||||
calls of f_80522050, its GPU memory (GPU_ALLOC_SITES), and its two tryAllocs of CPU buffers (HEAP_ALLOC_SITES). They went on
|
||||
with a null pointer and crashed writing through it (issue 1697). The supported build only.
|
||||
- ((Triforce) 11-19) The texture data compaction thread's step called through the host (host/oot_tex_compact.c): f_807da3f0's
|
||||
call of f_807da480. The host counts the cycles it starts and, with HOS_OOT_TEX_COMPACT_MS set, holds them to a pace; unset,
|
||||
the step runs as shipped. The supported build only.
|
||||
"""
|
||||
import glob
|
||||
import os
|
||||
@@ -780,6 +783,28 @@ def patch_heap_retry(s):
|
||||
return s, found
|
||||
|
||||
|
||||
# ((Triforce) 11-19) f_807da3f0, the handler of the game's "aglTextureDataMgr::Compaction" thread, calls the compaction's step
|
||||
# (f_807da480: with the compaction idle it plans, and starts a cycle that moves a texture's data in the game's heap) at one
|
||||
# place, for each message that asks. That call is made through host/oot_tex_compact.c hos_oot_tex_compact, which calls the
|
||||
# game's own, counts the cycles started and holds them to a pace when HOS_OOT_TEX_COMPACT_MS says so (unset: as shipped).
|
||||
# f_807da480's other callers, the game's own waits for a compaction, stay as they are.
|
||||
TEX_COMPACT_OLD = "c->x[30] = 0x807da430ULL; f_807da480(c);" # (the call's return address: this one place)
|
||||
TEX_COMPACT_NEW = "c->x[30] = 0x807da430ULL; hos_oot_tex_compact(c, f_807da480); /* (nx2/oot_patches.py: host/oot_tex_compact.c) */"
|
||||
TEX_COMPACT_DECL = "void hos_oot_tex_compact(Ctx *A64_NOESC c, A64Fn game);\n"
|
||||
|
||||
|
||||
def patch_tex_compact(s):
|
||||
"""The call above in one file's text: (text, 1 when made now or found made). apply() wants 1 over the whole lift"""
|
||||
if TEX_COMPACT_NEW in s:
|
||||
return s, 1
|
||||
if s.count(TEX_COMPACT_OLD) != 1 or s.count('#include "a64.h"\n') != 1:
|
||||
return s, 0
|
||||
s = s.replace(TEX_COMPACT_OLD, TEX_COMPACT_NEW, 1)
|
||||
if TEX_COMPACT_DECL not in s:
|
||||
s = s.replace('#include "a64.h"\n', '#include "a64.h"\n' + TEX_COMPACT_DECL, 1)
|
||||
return s, 1
|
||||
|
||||
|
||||
def apply(gen, *, protect_hearts=False, required=False):
|
||||
"""required: the lift of the supported build (LIFE_BUILD_ID), whole: a missing output-size edit stops it (apply_output_size).
|
||||
The other patches only warn when their place is not found once."""
|
||||
@@ -804,6 +829,7 @@ def apply(gen, *, protect_hearts=False, required=False):
|
||||
zstd_sites = 0 # (patch_host_zstd: its two calls, the supported build's alone)
|
||||
mod_size_sites = 0 # ((Triforce) patch_mod_sizes: its one call, the supported build's alone)
|
||||
heap_sites = [0, 0] # (the GPU memory's sites, the CPU buffers': patch_heap_retry, the supported build only)
|
||||
tex_compact_sites = 0 # ((Triforce) patch_tex_compact: its one call, the supported build's alone)
|
||||
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()
|
||||
@@ -931,6 +957,11 @@ def apply(gen, *, protect_hearts=False, required=False):
|
||||
if sized != out:
|
||||
print("oot_patches: room for the mods' files in", os.path.basename(path))
|
||||
out = sized
|
||||
compacted, found = patch_tex_compact(out)
|
||||
tex_compact_sites += found
|
||||
if compacted != out:
|
||||
print("oot_patches: the texture compaction's step through the host in", os.path.basename(path))
|
||||
out = compacted
|
||||
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)
|
||||
@@ -950,6 +981,8 @@ def apply(gen, *, protect_hearts=False, required=False):
|
||||
print("oot_patches: WARNING: the sprint button's calls were found at %d of 2 places" % sprint_sites)
|
||||
if protect_hearts and mod_size_sites != 1: # (without it a mod's bigger model can crash the game: host/mods.c)
|
||||
print("oot_patches: WARNING: the resource size table's lookup was found at %d of 1 place" % mod_size_sites)
|
||||
if protect_hearts and tex_compact_sites != 1: # (without it the compaction is neither counted nor paced: host/oot_tex_compact.c)
|
||||
print("oot_patches: WARNING: the texture compaction's step was found at %d of 1 place" % tex_compact_sites)
|
||||
if protect_hearts and zstd_sites != len(ZSTD_SITES): # (without them HOS_HOST_ZSTD does nothing, or half: host/hos_zstd.c)
|
||||
print("oot_patches: WARNING: the host's zstd decoder's calls were found at %d of %d places" % (zstd_sites, len(ZSTD_SITES)))
|
||||
if protect_hearts and heap_sites != [len(GPU_ALLOC_SITES), len(HEAP_ALLOC_SITES)]: # (the supported build's functions)
|
||||
|
||||
@@ -25,6 +25,10 @@ rework one by hand (nx2/prompt_faces/README.md).
|
||||
The faces' fonts are larger than the game's, and the game drops a file larger than its entry in the resource size table: <out>/
|
||||
rsizetable.zs is the game's table with the font's entry raised to fit the largest, served in its place.
|
||||
|
||||
(Triforce) The title screen's Options entry ("Options / ZELDA NOTES Setting") the same way: <out>/mals/<language>.product.110
|
||||
.sarc.zs is each language's messages with that entry made the game's word for Options, its separator and TITLE_TEXT, and the
|
||||
host serves the one of the language the game runs in (title_messages).
|
||||
|
||||
A .bfotf is an OpenType font behind an 8-byte header and XORed per little-endian word: the header is the magic 0x18029a7f and the
|
||||
font's size (big-endian), each XORed with the same key as the font. The .zs files are zstd frames made with the dictionary zs.zsdic
|
||||
of Pack/ZsDic.pack.zs.
|
||||
@@ -101,14 +105,7 @@ def size_table(romfs, dictionary, game_size, font_size):
|
||||
entry raised from the game's font (game_size bytes) to fit one of font_size: the game drops a file larger than its entry. None
|
||||
when it fits already"""
|
||||
import zlib
|
||||
folder = os.path.join(romfs, "System", "Resource")
|
||||
name = next((n for n in sorted(os.listdir(folder)) if n.startswith("ResourceSizeTable.") and n.endswith(".rsizetable.zs")),
|
||||
None)
|
||||
if not name:
|
||||
raise SystemExit("prompts: no System/Resource/ResourceSizeTable.*.rsizetable.zs")
|
||||
b = bytearray(read_zs(romfs, f"System/Resource/{name}", dictionary))
|
||||
if b[:6] != b"RESTBL":
|
||||
raise SystemExit(f"prompts: {name} is not a RESTBL table")
|
||||
name, b = read_size_table(romfs, dictionary)
|
||||
hashed, = struct.unpack_from("<I", b, 14)
|
||||
want = zlib.crc32(FONT[:-3].encode())
|
||||
for i in range(hashed):
|
||||
@@ -1073,6 +1070,262 @@ def write_camera(path, speeds):
|
||||
f.write(struct.pack("<If", off, v))
|
||||
|
||||
|
||||
# ---- (Triforce) the title screen's third entry, "Options / ZELDA NOTES Setting" in US English: it opens the game's Options,
|
||||
# where Triforce's own tabs are, so it reads "Options / Triforce". The text is label 0002 of LayoutMsg/Title_00.msbt in each
|
||||
# language's messages, Mals/<language>.Product.110.sarc.zs (a SARC, zstd with zs.zsdic): the game's word for Options, a size
|
||||
# tag (the rest is drawn smaller), then the rest. Everything up to the end of that tag is kept, the rest becomes the game's
|
||||
# own separator and TITLE_TEXT. prompts/mals/<language>.product.110.sarc.zs (the file's name in lower case, as host/prompts.c
|
||||
# asks for it) is each language's archive with that one file rewritten, as a zstd frame without the dictionary; the host
|
||||
# serves the one of the language the game runs in, where no mod has that file
|
||||
TITLE_TEXT = "Triforce" # (what the entry says after the game's word for Options and its separator)
|
||||
TITLE_MSBT, TITLE_LABEL = "LayoutMsg/Title_00.msbt", "0002"
|
||||
TITLE_SEPARATORS = "//|" # (the game's own between the two parts, kept with its spaces: "/", the full-width one, "|")
|
||||
TITLE_SEPARATOR = " / " # (where the game has none: the rest in brackets, "Optionen (inkl. ZELDA NOTES-Einstellungen)")
|
||||
MALS = "Mals"
|
||||
SARC_ALIGN = 0x2000 # (the largest alignment a file in an archive is given: textures and models)
|
||||
|
||||
|
||||
def msbt_sections(m):
|
||||
"""an MSBT's sections, [(magic, the 8 bytes after its size, body, the padding after it)], or None when m is not one (only
|
||||
the little-endian kind: "MsgStdBn", the mark ff fe, the text's encoding at +0xc (0 UTF-8, 1 UTF-16), the count of
|
||||
sections at +0xe, the file's size at +0x12, sections from +0x20, each a magic, u32 its body's size, 8 bytes, the body,
|
||||
padded to 16)"""
|
||||
if len(m) < 0x20 or m[:8] != b"MsgStdBn" or m[8:10] != b"\xff\xfe" or m[0xc] not in (0, 1):
|
||||
return None
|
||||
count, = struct.unpack_from("<H", m, 0xe)
|
||||
if struct.unpack_from("<I", m, 0x12)[0] != len(m):
|
||||
return None
|
||||
out, at = [], 0x20
|
||||
for _ in range(count):
|
||||
if at + 16 > len(m):
|
||||
return None
|
||||
n, = struct.unpack_from("<I", m, at + 4)
|
||||
end = at + 16 + n
|
||||
pad = end + (-end % 16)
|
||||
if pad > len(m):
|
||||
return None
|
||||
out.append((bytes(m[at:at + 4]), bytes(m[at + 8:at + 16]), bytes(m[at + 16:end]), bytes(m[end:pad])))
|
||||
at = pad
|
||||
return out if at == len(m) else None
|
||||
|
||||
|
||||
def msbt_build(m, sections):
|
||||
"""the MSBT m (its header) with these sections (msbt_sections' form): a body of another size gets its padding (the byte
|
||||
the section had, else 0xab) and the file its size"""
|
||||
out = bytearray(m[:0x20])
|
||||
for magic, rest, body, pad in sections:
|
||||
need = -(16 + len(body)) % 16
|
||||
out += magic + struct.pack("<I", len(body)) + rest + body
|
||||
out += pad if len(pad) == need else (pad[:1] or b"\xab") * need
|
||||
struct.pack_into("<I", out, 0x12, len(out))
|
||||
return bytes(out)
|
||||
|
||||
|
||||
def msbt_labels(body):
|
||||
"""{label: its text's number} of a LBL1 body: u32 slots, each u32 count and u32 offset; at an offset that many labels, each
|
||||
u8 length, the name, u32 number"""
|
||||
slots, = struct.unpack_from("<I", body, 0)
|
||||
out = {}
|
||||
for i in range(slots):
|
||||
count, at = struct.unpack_from("<II", body, 4 + 8 * i)
|
||||
for _ in range(count):
|
||||
n = body[at]
|
||||
out[body[at + 1:at + 1 + n].decode("ascii")] = struct.unpack_from("<I", body, at + 1 + n)[0]
|
||||
at += 5 + n
|
||||
return out
|
||||
|
||||
|
||||
def txt2_strings(body):
|
||||
"""a TXT2 body's texts (u32 count, u32 offset each from the body's start, the texts with their ends), or None"""
|
||||
count, = struct.unpack_from("<I", body, 0)
|
||||
offs = list(struct.unpack_from(f"<{count}I", body, 4)) + [len(body)]
|
||||
if offs[0] != 4 + 4 * count or offs != sorted(offs):
|
||||
return None
|
||||
return [body[a:z] for a, z in zip(offs, offs[1:])]
|
||||
|
||||
|
||||
def txt2_build(strings):
|
||||
at = 4 + 4 * len(strings)
|
||||
offs = []
|
||||
for s in strings:
|
||||
offs.append(at)
|
||||
at += len(s)
|
||||
return struct.pack(f"<I{len(strings)}I", len(strings), *offs) + b"".join(strings)
|
||||
|
||||
|
||||
def title_text(s, encoding, text=TITLE_TEXT):
|
||||
"""label 0002's text with its rest after the size tag (a tag: 0x0e, u16 group, u16 type, u16 its parameters' size, the
|
||||
parameters; group 0 type 2 the size) the separator and text, or None when it has no size tag before its end"""
|
||||
w, codec = (1, "utf-8") if encoding == 0 else (2, "utf-16-le")
|
||||
at = 0
|
||||
while at + w <= len(s):
|
||||
c = int.from_bytes(s[at:at + w], "little")
|
||||
if c == 0:
|
||||
return None
|
||||
if c == 0x0f: # (a tag's end: u16 group, u16 type)
|
||||
at += w + 4
|
||||
continue
|
||||
if c != 0x0e:
|
||||
at += w
|
||||
continue
|
||||
if at + w + 6 > len(s):
|
||||
return None
|
||||
group, kind, n = struct.unpack_from("<HHH", s, at + w)
|
||||
at += w + 6 + n
|
||||
if group == 0 and kind == 2:
|
||||
break
|
||||
else:
|
||||
return None
|
||||
rest = bytearray() # (the rest's text, up to its first tag or its end)
|
||||
for k in range(at, len(s) - w + 1, w):
|
||||
if int.from_bytes(s[k:k + w], "little") in (0, 0x0e, 0x0f):
|
||||
break
|
||||
rest += s[k:k + w]
|
||||
words = rest.decode(codec, "replace")
|
||||
sep = words[:len(words) - len(words.lstrip())]
|
||||
if words.lstrip()[:1] and words.lstrip()[0] in TITLE_SEPARATORS:
|
||||
after = words.lstrip()[1:]
|
||||
sep += words.lstrip()[0] + after[:len(after) - len(after.lstrip())]
|
||||
else:
|
||||
sep = TITLE_SEPARATOR
|
||||
return s[:at] + (sep + text).encode(codec) + b"\0" * w
|
||||
|
||||
|
||||
def title_msbt(m, text=TITLE_TEXT):
|
||||
"""the MSBT m with label 0002's rest made text (title_text), every other byte as it was, or None when m is not the
|
||||
title's (no LBL1 or TXT2, no label 0002, or a text with no size tag)"""
|
||||
sections = msbt_sections(m)
|
||||
if not sections:
|
||||
return None
|
||||
try:
|
||||
by = {magic: i for i, (magic, _, _, _) in enumerate(sections)}
|
||||
if b"LBL1" not in by or b"TXT2" not in by:
|
||||
return None
|
||||
k = msbt_labels(sections[by[b"LBL1"]][2]).get(TITLE_LABEL)
|
||||
magic, rest, body, pad = sections[by[b"TXT2"]]
|
||||
strings = txt2_strings(body)
|
||||
if strings is None or k is None or k >= len(strings):
|
||||
return None
|
||||
new = title_text(strings[k], m[0xc], text)
|
||||
except (struct.error, IndexError, UnicodeDecodeError):
|
||||
return None
|
||||
if new is None:
|
||||
return None
|
||||
strings[k] = new
|
||||
sections[by[b"TXT2"]] = (magic, rest, txt2_build(strings), pad)
|
||||
return msbt_build(m, sections)
|
||||
|
||||
|
||||
def sarc_replace(b, name, data):
|
||||
"""the SARC b with the file `name` made data: the files before it as they were, those after it moved on together by a
|
||||
multiple of every alignment they may need (an archive does not say which: each one's place's, up to SARC_ALIGN), so
|
||||
each keeps its own, the bytes between them as they were and a gap of zeros after the new file; the nodes' offsets and
|
||||
the archive's size made to agree. A file shorter by less than that moves nothing. None when b is no little-endian
|
||||
SARC, has no such file, or files that overlap it"""
|
||||
if len(b) < 0x20 or b[:4] != b"SARC":
|
||||
return None
|
||||
hl, bom = struct.unpack_from("<HH", b, 4)
|
||||
total, data_at = struct.unpack_from("<II", b, 8)
|
||||
if bom != 0xfeff or total != len(b) or b[hl:hl + 4] != b"SFAT":
|
||||
return None
|
||||
n, = struct.unpack_from("<H", b, hl + 6)
|
||||
nodes = hl + 12
|
||||
at = sarc_member(b, name)
|
||||
if not at:
|
||||
return None
|
||||
start, end = at[0] - data_at, at[1] - data_at
|
||||
entries = [struct.unpack_from("<IIII", b, nodes + 16 * i) for i in range(n)]
|
||||
k = next(i for i, e in enumerate(entries) if (e[2], e[3]) == (start, end))
|
||||
later = [i for i, e in enumerate(entries) if i != k and e[2] >= end]
|
||||
after = set(later)
|
||||
if any(i != k and i not in after and e[3] > start for i, e in enumerate(entries)):
|
||||
return None
|
||||
grow = len(data) - (end - start)
|
||||
if later:
|
||||
first = min(entries[i][2] for i in later)
|
||||
align = max([1] + [min((data_at + entries[i][2]) & -(data_at + entries[i][2]), SARC_ALIGN) for i in later])
|
||||
move = -(-grow // align) * align # (at least grow, the least multiple of the alignment)
|
||||
out = bytearray(b[:data_at + start]) + data + bytes(first + move - start - len(data)) + b[data_at + first:]
|
||||
else:
|
||||
move = grow
|
||||
out = bytearray(b[:data_at + start]) + data + b[data_at + end:]
|
||||
struct.pack_into("<I", out, nodes + 16 * k + 12, start + len(data))
|
||||
for i in later:
|
||||
struct.pack_into("<II", out, nodes + 16 * i + 8, entries[i][2] + move, entries[i][3] + move)
|
||||
struct.pack_into("<I", out, 8, len(out))
|
||||
return bytes(out)
|
||||
|
||||
|
||||
def title_sarc(sarc, text=TITLE_TEXT):
|
||||
"""a language's messages (Mals/*.sarc, decompressed) with the title's Options entry saying text, or None when they are
|
||||
not the ones known"""
|
||||
at = sarc_member(sarc, TITLE_MSBT)
|
||||
m = title_msbt(sarc[at[0]:at[1]], text) if at else None
|
||||
return sarc_replace(sarc, TITLE_MSBT, m) if m else None
|
||||
|
||||
|
||||
def read_size_table(romfs, dictionary):
|
||||
"""(its name, the game's resource size table decompressed: size_table says its form)"""
|
||||
folder = os.path.join(romfs, "System", "Resource")
|
||||
name = next((n for n in sorted(os.listdir(folder)) if n.startswith("ResourceSizeTable.") and n.endswith(".rsizetable.zs")),
|
||||
None)
|
||||
if not name:
|
||||
raise SystemExit("prompts: no System/Resource/ResourceSizeTable.*.rsizetable.zs")
|
||||
b = bytearray(read_zs(romfs, f"System/Resource/{name}", dictionary))
|
||||
if b[:6] != b"RESTBL":
|
||||
raise SystemExit(f"prompts: {name} is not a RESTBL table")
|
||||
return name, b
|
||||
|
||||
|
||||
def size_entry(table, path):
|
||||
"""a file's entry in a resource size table (path without .zs), None when it has none: a named entry (u32 name length
|
||||
after the version, then after the hashed entries each the name in that many bytes and u32 size) over a hashed one"""
|
||||
import zlib
|
||||
room, hashed, named = struct.unpack_from("<III", table, 10)
|
||||
at = 22 + 8 * hashed
|
||||
for i in range(named):
|
||||
e = at + (room + 4) * i
|
||||
if table[e:e + room].split(b"\0")[0] == path.encode():
|
||||
return struct.unpack_from("<I", table, e + room)[0]
|
||||
want = zlib.crc32(path.encode())
|
||||
for i in range(hashed):
|
||||
h, size = struct.unpack_from("<II", table, 22 + 8 * i)
|
||||
if h == want:
|
||||
return size
|
||||
return None
|
||||
|
||||
|
||||
def title_messages(romfs, dictionary, out, text=TITLE_TEXT):
|
||||
"""writes <out>/mals/<language>.product.110.sarc.zs for each language whose messages are the ones known and whose
|
||||
rewritten archive is no larger than the game's file (and within its entry in the size table, where it has one); the
|
||||
languages written. The entry is the file's size plus an allowance the game keeps over it (336 bytes for every Mals
|
||||
archive), as size_table keeps the font's: an archive growing into that allowance is past what the entry holds for it
|
||||
and the game drops a file larger than its entry, so a TITLE_TEXT longer than a language's rest leaves that language as
|
||||
the game has it (the build says so) rather than raising the entry"""
|
||||
import zstandard
|
||||
_, table = read_size_table(romfs, dictionary)
|
||||
done = []
|
||||
for name in sorted(os.listdir(os.path.join(romfs, MALS))):
|
||||
if not name.endswith(".sarc.zs"):
|
||||
continue
|
||||
game = read_zs(romfs, f"{MALS}/{name}", dictionary)
|
||||
new = title_sarc(game, text)
|
||||
if not new:
|
||||
print(f"prompts: {MALS}/{name}: the title keeps its text (its messages are not the ones known)", file=sys.stderr)
|
||||
continue
|
||||
entry = size_entry(table, f"{MALS}/{name[:-3]}")
|
||||
fits = len(game) if entry is None else min(len(game), entry) # (the entry's allowance over the file kept)
|
||||
if len(new) > fits:
|
||||
print(f"prompts: {MALS}/{name}: the title keeps its text ({len(new)} bytes; the game's file is {len(game)}, "
|
||||
f"its size table entry {entry}: a shorter TITLE_TEXT fits)", file=sys.stderr)
|
||||
continue
|
||||
os.makedirs(os.path.join(out, "mals"), exist_ok=True)
|
||||
with open(os.path.join(out, "mals", name.lower()), "wb") as f:
|
||||
f.write(zstandard.ZstdCompressor(level=3).compress(new))
|
||||
done.append(name.split(".")[0])
|
||||
return done
|
||||
|
||||
|
||||
def main():
|
||||
ap = argparse.ArgumentParser()
|
||||
ap.add_argument("--romfs", required=True)
|
||||
@@ -1156,6 +1409,13 @@ def main():
|
||||
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)
|
||||
try:
|
||||
titles = title_messages(a.romfs, dictionary, a.out)
|
||||
except (Exception, SystemExit) as e: # (a romfs without the messages, or one that does not decompress)
|
||||
titles = []
|
||||
print(f"prompts: the title's messages were not read ({e})", file=sys.stderr)
|
||||
if titles:
|
||||
print(f"prompts: the title's Options entry says {TITLE_TEXT} in " + " ".join(titles), file=sys.stderr)
|
||||
if ring:
|
||||
write_ring(os.path.join(a.out, "ring.bin"), ring)
|
||||
print("prompts: the Talk ring", file=sys.stderr)
|
||||
|
||||
@@ -45,7 +45,7 @@ uint64_t max_import_size=128ull<<20;
|
||||
int failures=0,imports=0,retires=0,bg_starts=0;
|
||||
int64_t st_bg_waits=0,st_prefetch_used=0,st_prefetch_sent=0,st_prefetch_dropped=0;
|
||||
struct { bool external_memory_host=true; } dev;
|
||||
std::mutex bg_mu;std::condition_variable bg_done_cv,bg_cv;std::vector<uint64_t> bg_inflight;
|
||||
std::mutex bg_mu;std::condition_variable bg_done_cv,bg_cv;std::vector<uint64_t> bg_inflight;std::atomic<int> bg_waiters{0};
|
||||
std::deque<std::pair<uint64_t,uint64_t>> bg_queue;
|
||||
void bg_start() { bg_starts++; } // Recording spy: no thread or GPU import is started.
|
||||
void logf(const char*,...){} void bg_drain(){}
|
||||
|
||||
Reference in New Issue
Block a user