From efacca42de11b91f9b940ec4d9147315d4324ffe Mon Sep 17 00:00:00 2001 From: bnnm Date: Sat, 29 Jun 2019 13:25:04 +0200 Subject: [PATCH] Fix subsongs in some .hd3+bd3 --- src/meta/hd3_bd3.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/meta/hd3_bd3.c b/src/meta/hd3_bd3.c index 2a7df89d..c69f2ad9 100644 --- a/src/meta/hd3_bd3.c +++ b/src/meta/hd3_bd3.c @@ -35,8 +35,13 @@ VGMSTREAM * init_vgmstream_hd3_bd3(STREAMFILE *streamFile) { if (read_32bitBE(section_offset+0x00,streamHeader) != 0x50335641) /* "P3VA" */ goto fail; section_size = read_32bitBE(section_offset+0x04,streamHeader); /* (not including first 0x08) */ - /* 0x08 always 0x10? */ - entries = read_32bitBE(section_offset+0x14,streamHeader) + 1; + /* 0x08 size of all subsong headers + 0x10 */ + + entries = read_32bitBE(section_offset+0x14,streamHeader); + /* often there is an extra subsong than written, but may be padding instead */ + if (read_32bitBE(section_offset + 0x20 + entries*0x10 + 0x04,streamHeader)) /* has sample rate */ + entries += 1; + if (entries * 0x10 > section_size) /* just in case, padding after entries is possible */ goto fail;