Fix some broken .wav [Cross Gate (PC)]

This commit is contained in:
bnnm 2022-02-28 23:54:04 +01:00
parent 0f0c1b89ec
commit ca65796ba6

View File

@ -340,6 +340,7 @@ VGMSTREAM* init_vgmstream_riff(STREAMFILE* sf) {
int mwv = 0; int mwv = 0;
off_t mwv_pflt_offset = -1; off_t mwv_pflt_offset = -1;
off_t mwv_ctrl_offset = -1; off_t mwv_ctrl_offset = -1;
int ignore_riff_size = 0;
/* checks*/ /* checks*/
@ -445,10 +446,15 @@ VGMSTREAM* init_vgmstream_riff(STREAMFILE* sf) {
else if (codec == 0x0002 && riff_size + 0x08 + 0x1c == file_size) else if (codec == 0x0002 && riff_size + 0x08 + 0x1c == file_size)
riff_size += 0x1c; /* [Mega Man X Legacy Collection (PC)] (adds "ver /tIME/ver " chunks but RIFF size wasn't updated) */ riff_size += 0x1c; /* [Mega Man X Legacy Collection (PC)] (adds "ver /tIME/ver " chunks but RIFF size wasn't updated) */
else if (codec == 0x0001 && (
riff_size + 0x08 + 0x08 == file_size || riff_size + 0x08 + 0x09 == file_size ||
riff_size + 0x08 - 0x3E == file_size || riff_size + 0x08 - 0x02 == file_size))
ignore_riff_size = 1; /* [Cross Gate (PC)] (last info LIST chunk has wrong size) */
} }
/* check for truncated RIFF */ /* check for truncated RIFF */
if (file_size != riff_size + 0x08) { if (file_size != riff_size + 0x08 && !ignore_riff_size) {
vgm_logi("RIFF: wrong expected size (report/re-rip?)\n"); vgm_logi("RIFF: wrong expected size (report/re-rip?)\n");
VGM_LOG("riff: file_size = %x, riff_size+8 = %x\n", file_size, riff_size + 0x08); /* don't log to user */ VGM_LOG("riff: file_size = %x, riff_size+8 = %x\n", file_size, riff_size + 0x08); /* don't log to user */
goto fail; goto fail;
@ -456,14 +462,17 @@ VGMSTREAM* init_vgmstream_riff(STREAMFILE* sf) {
/* read through chunks to verify format and find metadata */ /* read through chunks to verify format and find metadata */
{ {
off_t current_chunk = 0x0c; /* start with first chunk */ uint32_t current_chunk = 0x0c; /* start with first chunk */
while (current_chunk < file_size) { while (current_chunk < file_size) {
uint32_t chunk_id = read_32bitBE(current_chunk + 0x00,sf); /* FOURCC */ uint32_t chunk_id = read_u32be(current_chunk + 0x00,sf); /* FOURCC */
size_t chunk_size = read_32bitLE(current_chunk + 0x04,sf); uint32_t chunk_size = read_u32le(current_chunk + 0x04,sf);
if (current_chunk + 0x08 + chunk_size > file_size) /* allow broken last chunk [Cross Gate (PC)] */
goto fail; if (current_chunk + 0x08 + chunk_size > file_size) {
VGM_LOG("RIFF: broken chunk at %x + 0x08 + %x > %x\n", current_chunk, chunk_size, file_size);
break; /* truncated */
}
switch(chunk_id) { switch(chunk_id) {
case 0x666d7420: /* "fmt " */ case 0x666d7420: /* "fmt " */
@ -490,7 +499,7 @@ VGMSTREAM* init_vgmstream_riff(STREAMFILE* sf) {
switch (read_32bitBE(current_chunk+0x08, sf)) { switch (read_32bitBE(current_chunk+0x08, sf)) {
case 0x6164746C: /* "adtl" */ case 0x6164746C: /* "adtl" */
/* yay, atdl is its own little world */ /* yay, atdl is its own little world */
parse_adtl(current_chunk + 8, chunk_size, parse_adtl(current_chunk + 0x8, chunk_size,
sf, sf,
&loop_start_ms,&loop_end_ms,&loop_flag); &loop_start_ms,&loop_end_ms,&loop_flag);
break; break;