diff --git a/src/meta/sfh.c b/src/meta/sfh.c index b22a2205..7ca7a902 100644 --- a/src/meta/sfh.c +++ b/src/meta/sfh.c @@ -1,46 +1,65 @@ -#include "meta.h" -#include "../coding/coding.h" -#include "sfh_streamfile.h" - - -/* .SFH - Capcom wrapper [Devil May Cry 4 Demo (PS3), Jojo's Bizarre Adventure HD (PS3)] */ -VGMSTREAM * init_vgmstream_sfh(STREAMFILE *streamFile) { - VGMSTREAM *vgmstream = NULL; - STREAMFILE *temp_streamFile = NULL; - uint32_t version; - size_t clean_size, block_size; - - /* check extensions */ - if ( !check_extensions(streamFile,"at3")) - goto fail; - - if (read_32bitBE(0x00, streamFile) != 0x00534648) /* "\0SFH" */ - goto fail; - if (read_32bitBE(0x10, streamFile) != 0x52494646) /* "RIFF" */ - goto fail; - - /* mini header */ - version = read_32bitBE(0x04,streamFile); - clean_size = read_32bitBE(0x08,streamFile); /* there is padding data at the end */ - /* 0x0c: always 0 */ - - switch(version) { - case 0x00010000: block_size = 0x10010; break; /* DMC4 Demo (not retail) */ - case 0x00010001: block_size = 0x20000; break; /* Jojo */ - default: goto fail; - } - - temp_streamFile = setup_sfh_streamfile(streamFile, 0x00, block_size, clean_size, "at3"); - if (!temp_streamFile) goto fail; - - vgmstream = init_vgmstream_riff(temp_streamFile); - if (!vgmstream) goto fail; - - close_streamfile(temp_streamFile); - return vgmstream; - -fail: - close_streamfile(temp_streamFile); - close_vgmstream(vgmstream); - return NULL; -} +#include "meta.h" +#include "../coding/coding.h" +#include "sfh_streamfile.h" + +typedef VGMSTREAM* (*init_vgmstream_t)(STREAMFILE*); + + +/* .SFH - Capcom wrapper used with common audio extensions [Devil May Cry 4 Demo (PS3), Jojo's Bizarre Adventure HD (PS3), Sengoku Basara 4 Sumeragi (PS3)] */ +VGMSTREAM* init_vgmstream_sfh(STREAMFILE* sf) { + VGMSTREAM* vgmstream = NULL; + STREAMFILE* temp_sf = NULL; + init_vgmstream_t init_vgmstream = NULL; + + + /* checks */ + if (!is_id32be(0x00, sf, "\0SFH")) + return NULL; + if (!check_extensions(sf,"at3,sspr")) + return NULL; + + /* mini header */ + uint32_t version = read_u32be(0x04,sf); + uint32_t clean_size = read_u32be(0x08,sf); /* there is padding data at the end */ + /* 0x0c: always 0 */ + + char* extension; + uint32_t header_id = read_u32be(0x10,sf); + switch(header_id) { + case 0x52494646: // RIFF + init_vgmstream = init_vgmstream_riff; + extension = "at3"; + break; + + case 0x53535052: // SSPR + init_vgmstream = init_vgmstream_sspr; + extension = "sspr"; + break; + + case 0x00434C44: // \0CLD (.dlcp) + case 0x00435241: // \0CRA (.arc) + default: + goto fail; + } + + uint32_t block_size; + switch(version) { + case 0x00010000: block_size = 0x10010; break; /* DMC4 Demo (not retail) */ + case 0x00010001: block_size = 0x20000; break; /* Jojo, SB4 */ + default: goto fail; + } + + temp_sf = setup_sfh_streamfile(sf, 0x00, block_size, clean_size, extension); + if (!temp_sf) goto fail; + + vgmstream = init_vgmstream(temp_sf); + if (!vgmstream) goto fail; + + close_streamfile(temp_sf); + return vgmstream; + +fail: + close_streamfile(temp_sf); + close_vgmstream(vgmstream); + return NULL; +} diff --git a/src/meta/sspr.c b/src/meta/sspr.c index c877be76..3a58b10f 100644 --- a/src/meta/sspr.c +++ b/src/meta/sspr.c @@ -6,23 +6,22 @@ VGMSTREAM* init_vgmstream_sspr(STREAMFILE* sf) { VGMSTREAM* vgmstream = NULL; STREAMFILE* temp_sf = NULL; - uint32_t name_offset, subfile_offset, subfile_size, name_size; - int big_endian; - int total_subsongs, target_subsong = sf->stream_index; - char* extension; - uint32_t (*read_u32)(off_t,STREAMFILE*) = NULL; - /* checks */ - if (!check_extensions(sf,"sspr")) - goto fail; if (!is_id32be(0x00,sf,"SSPR")) - goto fail; + return NULL; + if (!check_extensions(sf,"sspr")) + return NULL; + + uint32_t name_offset, subfile_offset, subfile_size, name_size; + int total_subsongs, target_subsong = sf->stream_index; + char* extension; + read_u32_t read_u32 = NULL; /* Simple (audio only) container used some Capcom games (common engine?). * Some files come with a .stqr with unknown data (cues?). */ - big_endian = guess_endian32(0x04, sf); /* 0x01 (version?) */ + int big_endian = guess_endian32(0x04, sf); /* 0x01 (version?) */ read_u32 = big_endian ? read_u32be : read_u32le; total_subsongs = read_u32(0x08,sf);