Skip to content
Open
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
15 changes: 12 additions & 3 deletions dm/gfx/tools/mvgl.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,15 @@ def doboz(b):
# A file whose stored length is below its length is one LZ4 block (not doboz). The layout is told by its tables ending exactly at the data start.
def wide(h):
nt, nn, nd, start, size = struct.unpack_from('<IIIQQ', h, 4)
return 0x20 + nt * 16 + nn * 0x80 + nd * 16 == start
return 0x20 + nt * 16 + nn * 0x80 + nd * 16 == start or 0x20 + nt * 16 + nn * 0x80 + nd * 24 == start # PEANUTS: or 24-byte data entries (data_entry)
# PEANUTS end


# PEANUTS begin: The Hundred Line -Last Defense Academy- (010093C0215B4000, RomFS *.nx64.mvgl): the same 64-bit layout, but data entries of 24 bytes each
# (u64 offset, u64 length, u64 stored length). Told the same way, by the tables ending exactly at the data start; 16 is tried first, so Digimon's archives read as before
def data_entry(h):
nt, nn, nd, start, size = struct.unpack_from('<IIIQQ', h, 4)
return 16 if 0x20 + nt * 16 + nn * 0x80 + nd * 16 == start else 24 if 0x20 + nt * 16 + nn * 0x80 + nd * 24 == start else 0
# PEANUTS end


Expand All @@ -65,14 +73,15 @@ def __init__(self, path):
h = self.f.read(0x20); self.f.seek(0x14); self.wide = h[:4] == b'MDB1' and wide(h)
if self.wide:
nt, nn, nd, self.start, self.size = struct.unpack_from('<IIIQQ', h, 4); self.f.seek(0x20)
tree, names, data = self.f.read(nt * 16), self.f.read(nn * 0x80), self.f.read(nd * 16)
de = data_entry(h); fmt = '<QII' if de == 16 else '<QQQ' # PEANUTS: 24-byte data entries (data_entry, above)
tree, names, data = self.f.read(nt * 16), self.f.read(nn * 0x80), self.f.read(nd * de)
self.files = {}
for k in range(nt):
idx = struct.unpack_from('<I', tree, k * 16 + 4)[0]
if idx == 0xffffffff: continue
ext = names[k * 0x80:k * 0x80 + 4].rstrip(b'\0 ').decode('latin1')
name = names[k * 0x80 + 4:(k + 1) * 0x80].split(b'\0')[0].decode('latin1')
off, n, cn = struct.unpack_from('<QII', data, idx * 16)
off, n, cn = struct.unpack_from(fmt, data, idx * de) # PEANUTS: the entry size and format of data_entry
self.files[name + '.' + ext] = (self.start + off, n, cn)
return
# PEANUTS end
Expand Down
9 changes: 9 additions & 0 deletions peanuts/UPSTREAM-EDITS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2796,3 +2796,12 @@ Left as they were: the hunks the check also flags that were unmarked before 0.1.
`dm/games/0100A6301214E000/game.tsv`, `dm/games/game.py`, `hle_nvn.c` `nvnWindowGetPresentInterval`, `vka_tex.c` (one line), `dm/host/dm.h`,
`hle_fpslock.c` `limit_raw`, `loader.c` (two lines), `dm/host/tests/t_android_smap.c`, `dm/tools/docs_patches.py`, and the tests `test_android_soc.py`,
`test_fpslocker_plan.py`, `test_game_profile.py`, `test_option_patch.py`, `test_vka_tex_registration.py`.

### MVGL archives with 24-byte data entries (2026-11-26)

The Hundred Line -Last Defense Academy- (`010093C0215B4000`) keeps its shaders in Media.Vision's MVGL archives (`*.nx64.mvgl`) in the 64-bit layout of Digimon Story Time Stranger, but each data entry is 24 bytes (u64 offset, u64 length, u64 stored length), not 16. `mvgl.py` did not take these archives as the 64-bit layout (their tables do not end at the data start with 16-byte entries), so it read them as the 32-bit layout and the split found only the 179 shaders in `main`. `data_entry` now tells the two entry sizes apart by where the tables end, 16 first, so Digimon's archives read as before. The split of The Hundred Line 1.2.1 finds 7,204 shaders (7,026 from the archives).

| File | Hunks | Change | Marker |
|---|---|---|---|
| `dm/gfx/tools/mvgl.py` | 3 | `wide` also takes 24-byte data entries; `data_entry` gives the entry size; `Archive` reads the entries by it | `PEANUTS begin`/`end`, `PEANUTS` |
| `peanuts/tests/test_mvgl_wide.py` | 3 | `test_reader_24`: an archive with 24-byte entries reads, and `data_entry` gives 16 for the 16-byte one | `PEANUTS begin`/`end`, `PEANUTS` (a Peanuts-owned file) |
18 changes: 15 additions & 3 deletions peanuts/tests/test_mvgl_wide.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def nxsh(magic, stage):
return bytes(h) + ctl + code


def wide(files):
def wide(files, de=16): # PEANUTS: de=24, The Hundred Line's data entries (u64 offset, u64 length, u64 stored length)
"""A 64-bit MVGL archive of {'name.ext': (bytes, compress)}; the tree is a flat list (the reader walks every node, as the Patricia tree's order does not matter to it)"""
names = sorted(files)
nt = nn = len(names) + 1; nd = len(names)
Expand All @@ -38,8 +38,8 @@ def wide(files):
stem, ext = n.rsplit('.', 1)
tree += struct.pack('<IIII', i, i, 0, 0)
nm += ext.encode().ljust(4, b'\0') + stem.encode().ljust(0x7c, b'\0')
data += struct.pack('<QII', len(blob), len(raw), len(stored)); blob += stored
start = 0x20 + nt * 16 + nn * 0x80 + nd * 16
data += struct.pack('<QII' if de == 16 else '<QQQ', len(blob), len(raw), len(stored)); blob += stored # PEANUTS: de
start = 0x20 + nt * 16 + nn * 0x80 + nd * de # PEANUTS: de
return struct.pack('<4sIIIQQ', b'MDB1', nt, nn, nd, start, start + len(blob)) + tree + nm + data + blob


Expand All @@ -62,6 +62,18 @@ def test_reader(self):
self.assertEqual(a.read('shaders\\a_fp.shad'), self.ps) # a stored entry
self.assertEqual(a.read('images\\b.img'), b'not a shader' * 40)

# PEANUTS begin: The Hundred Line's 24-byte data entries (mvgl.data_entry)
def test_reader_24(self):
arc = wide({'shaders\\a_vp.shad': (self.vs, True), 'shaders\\a_fp.shad': (self.ps, False)}, de=24)
self.assertTrue(mvgl.wide(arc[:0x20])); self.assertEqual(mvgl.data_entry(arc[:0x20]), 24); self.assertEqual(mvgl.data_entry(self.arc[:0x20]), 16)
with tempfile.TemporaryDirectory() as t:
a = mvgl.Archive(self.write(t, arc))
try:
self.assertEqual(a.read('shaders\\a_vp.shad'), self.vs)
self.assertEqual(a.read('shaders\\a_fp.shad'), self.ps)
finally: a.f.close()
# PEANUTS end

def test_narrow_layout_is_not_wide(self):
"""The 32-bit layout (Cyber Sleuth): u16 counts, u32 start and size; its tables do not end at a 64-bit start"""
h = struct.pack('<4sHHIII', b'MDB1', 2, 2, 1, 0x14 + 16 + 0x80 + 12, 0x1000) + bytes(12)
Expand Down