Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion dm/gfx/tools/shader_split.py
Original file line number Diff line number Diff line change
Expand Up @@ -2117,7 +2117,8 @@ def sarc_members(d, label='SARC'):
for i in range(n):
h, attr, s, e = struct.unpack_from('<IIII', d, hl + 12 + 16 * i)
if not s <= e <= len(d) - doff: red(f'{label}: SARC member {i} at {s:#x}..{e:#x} of the data lies outside its {len(d) - doff:#x} bytes')
nm = d[names + (attr & 0xffffff) * 4:].split(b'\0')[0].decode('utf-8', 'replace') if attr >> 24 else f'#{i}'
o = names + (attr & 0xffffff) * 4; z = d.find(b'\0', o) # up to the name's own NUL: splitting the rest of the archive per member was quadratic (Fire Emblem Fortune's Weave's Layout/Common.arc.zst: 6 minutes)
nm = d[o:z if z >= 0 else len(d)].decode('utf-8', 'replace') if attr >> 24 else f'#{i}'
yield nm, d[doff + s:doff + e]

NV_STAGES = ['vs', 'ps', 'gs', 'hs', 'ds', 'cs'] # NVN stage order
Expand Down
10 changes: 10 additions & 0 deletions dm/tools/tests/test_split_nesting.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,15 @@ def test_yaz0_expansion_is_charged_before_it_is_decoded(self):
self.assertEqual(dec.call_count, 0)


class MemberNames(unittest.TestCase):
def test_names_and_time(self): # each name ends at its own NUL; splitting the rest of the archive per member made Fire Emblem Fortune's Weave's 9.8 MB layout SARC take 6 minutes
members = [(b'tex%04d.bntx' % i, bytes(0x4000)) for i in range(800)]
import time
archive = fz.sarc(members) # built outside the timing: only the member reading is measured (about 1 ms here, 47 s with the per-member split)
t = time.monotonic(); got = list(ss.sarc_members(archive)); took = time.monotonic() - t
self.assertEqual(got, [(n.decode(), m) for n, m in members])
self.assertLess(took, 1.0)


if __name__ == '__main__':
unittest.main()