diff --git a/Frameworks/vgmstream/libvgmstream.xcodeproj/project.pbxproj b/Frameworks/vgmstream/libvgmstream.xcodeproj/project.pbxproj index 3fdeb5503..7a08dd76d 100644 --- a/Frameworks/vgmstream/libvgmstream.xcodeproj/project.pbxproj +++ b/Frameworks/vgmstream/libvgmstream.xcodeproj/project.pbxproj @@ -261,7 +261,7 @@ 834FE0FC215C79ED000A5D3D /* vai.c in Sources */ = {isa = PBXBuildFile; fileRef = 834FE0D3215C79E9000A5D3D /* vai.c */; }; 834FE0FD215C79ED000A5D3D /* vpk.c in Sources */ = {isa = PBXBuildFile; fileRef = 834FE0D4215C79E9000A5D3D /* vpk.c */; }; 834FE0FE215C79ED000A5D3D /* ps_headerless.c in Sources */ = {isa = PBXBuildFile; fileRef = 834FE0D5215C79E9000A5D3D /* ps_headerless.c */; }; - 834FE0FF215C79ED000A5D3D /* sqex_scd_sscf.c in Sources */ = {isa = PBXBuildFile; fileRef = 834FE0D6215C79E9000A5D3D /* sqex_scd_sscf.c */; }; + 834FE0FF215C79ED000A5D3D /* sscf.c in Sources */ = {isa = PBXBuildFile; fileRef = 834FE0D6215C79E9000A5D3D /* sscf.c */; }; 834FE100215C79ED000A5D3D /* svg.c in Sources */ = {isa = PBXBuildFile; fileRef = 834FE0D7215C79EA000A5D3D /* svg.c */; }; 834FE101215C79ED000A5D3D /* csmp.c in Sources */ = {isa = PBXBuildFile; fileRef = 834FE0D8215C79EA000A5D3D /* csmp.c */; }; 834FE102215C79ED000A5D3D /* rfrm.c in Sources */ = {isa = PBXBuildFile; fileRef = 834FE0D9215C79EA000A5D3D /* rfrm.c */; }; @@ -346,7 +346,7 @@ 836F6F7418BDC2190095E648 /* bgw.c in Sources */ = {isa = PBXBuildFile; fileRef = 836F6E3818BDC2180095E648 /* bgw.c */; }; 836F6F7518BDC2190095E648 /* bnsf.c in Sources */ = {isa = PBXBuildFile; fileRef = 836F6E3918BDC2180095E648 /* bnsf.c */; }; 836F6F7618BDC2190095E648 /* brstm.c in Sources */ = {isa = PBXBuildFile; fileRef = 836F6E3A18BDC2180095E648 /* brstm.c */; }; - 836F6F7818BDC2190095E648 /* Cstr.c in Sources */ = {isa = PBXBuildFile; fileRef = 836F6E3C18BDC2180095E648 /* Cstr.c */; }; + 836F6F7818BDC2190095E648 /* cstr.c in Sources */ = {isa = PBXBuildFile; fileRef = 836F6E3C18BDC2180095E648 /* cstr.c */; }; 836F6F7918BDC2190095E648 /* dc_asd.c in Sources */ = {isa = PBXBuildFile; fileRef = 836F6E3D18BDC2180095E648 /* dc_asd.c */; }; 836F6F7B18BDC2190095E648 /* dc_idvi.c in Sources */ = {isa = PBXBuildFile; fileRef = 836F6E3F18BDC2180095E648 /* dc_idvi.c */; }; 836F6F7C18BDC2190095E648 /* dc_kcey.c in Sources */ = {isa = PBXBuildFile; fileRef = 836F6E4018BDC2180095E648 /* dc_kcey.c */; }; @@ -572,6 +572,8 @@ 838BDB7B1D3B1FC20022CA6F /* CoreMedia.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 838BDB7A1D3B1FC20022CA6F /* CoreMedia.framework */; }; 838BDB7D1D3B1FCC0022CA6F /* CoreVideo.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 838BDB7C1D3B1FCC0022CA6F /* CoreVideo.framework */; }; 838BDB7F1D3B1FD10022CA6F /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 838BDB7E1D3B1FD10022CA6F /* Cocoa.framework */; }; + 8396BE7A2935FC2F00CD0580 /* sscf_encrypted.c in Sources */ = {isa = PBXBuildFile; fileRef = 8396BE782935FC2F00CD0580 /* sscf_encrypted.c */; }; + 8396BE7B2935FC2F00CD0580 /* sscf_encrypted.h in Headers */ = {isa = PBXBuildFile; fileRef = 8396BE792935FC2F00CD0580 /* sscf_encrypted.h */; }; 8399335B2591E896001855AF /* vorbis_custom_utils_awc.c in Sources */ = {isa = PBXBuildFile; fileRef = 839933572591E896001855AF /* vorbis_custom_utils_awc.c */; }; 8399335F2591E8C1001855AF /* ifs.c in Sources */ = {isa = PBXBuildFile; fileRef = 8399335C2591E8C0001855AF /* ifs.c */; }; 839933602591E8C1001855AF /* ubi_sb_garbage_streamfile.h in Headers */ = {isa = PBXBuildFile; fileRef = 8399335D2591E8C0001855AF /* ubi_sb_garbage_streamfile.h */; }; @@ -1088,7 +1090,7 @@ 834FE0D3215C79E9000A5D3D /* vai.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = vai.c; sourceTree = ""; }; 834FE0D4215C79E9000A5D3D /* vpk.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = vpk.c; sourceTree = ""; }; 834FE0D5215C79E9000A5D3D /* ps_headerless.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ps_headerless.c; sourceTree = ""; }; - 834FE0D6215C79E9000A5D3D /* sqex_scd_sscf.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = sqex_scd_sscf.c; sourceTree = ""; }; + 834FE0D6215C79E9000A5D3D /* sscf.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = sscf.c; sourceTree = ""; }; 834FE0D7215C79EA000A5D3D /* svg.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = svg.c; sourceTree = ""; }; 834FE0D8215C79EA000A5D3D /* csmp.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = csmp.c; sourceTree = ""; }; 834FE0D9215C79EA000A5D3D /* rfrm.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = rfrm.c; sourceTree = ""; }; @@ -1174,7 +1176,7 @@ 836F6E3818BDC2180095E648 /* bgw.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bgw.c; sourceTree = ""; }; 836F6E3918BDC2180095E648 /* bnsf.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bnsf.c; sourceTree = ""; }; 836F6E3A18BDC2180095E648 /* brstm.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = brstm.c; sourceTree = ""; }; - 836F6E3C18BDC2180095E648 /* Cstr.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = Cstr.c; sourceTree = ""; }; + 836F6E3C18BDC2180095E648 /* cstr.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = cstr.c; sourceTree = ""; }; 836F6E3D18BDC2180095E648 /* dc_asd.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = dc_asd.c; sourceTree = ""; }; 836F6E3F18BDC2180095E648 /* dc_idvi.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = dc_idvi.c; sourceTree = ""; }; 836F6E4018BDC2180095E648 /* dc_kcey.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = dc_kcey.c; sourceTree = ""; }; @@ -1401,6 +1403,8 @@ 838BDB7A1D3B1FC20022CA6F /* CoreMedia.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreMedia.framework; path = System/Library/Frameworks/CoreMedia.framework; sourceTree = SDKROOT; }; 838BDB7C1D3B1FCC0022CA6F /* CoreVideo.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreVideo.framework; path = System/Library/Frameworks/CoreVideo.framework; sourceTree = SDKROOT; }; 838BDB7E1D3B1FD10022CA6F /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; }; + 8396BE782935FC2F00CD0580 /* sscf_encrypted.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = sscf_encrypted.c; sourceTree = ""; }; + 8396BE792935FC2F00CD0580 /* sscf_encrypted.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sscf_encrypted.h; sourceTree = ""; }; 839933572591E896001855AF /* vorbis_custom_utils_awc.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = vorbis_custom_utils_awc.c; sourceTree = ""; }; 8399335C2591E8C0001855AF /* ifs.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ifs.c; sourceTree = ""; }; 8399335D2591E8C0001855AF /* ubi_sb_garbage_streamfile.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ubi_sb_garbage_streamfile.h; sourceTree = ""; }; @@ -2022,7 +2026,7 @@ 83A8BAE425667AA7000F5F3F /* cpk.c */, 83FC176B23AC58D100E1025F /* csb.c */, 834FE0D8215C79EA000A5D3D /* csmp.c */, - 836F6E3C18BDC2180095E648 /* Cstr.c */, + 836F6E3C18BDC2180095E648 /* cstr.c */, 836F6E3D18BDC2180095E648 /* dc_asd.c */, 836F6E3F18BDC2180095E648 /* dc_idvi.c */, 836F6E4018BDC2180095E648 /* dc_kcey.c */, @@ -2304,10 +2308,12 @@ 836F6EBE18BDC2190095E648 /* spm.c */, 83A21F82201D8981000F04B9 /* sps_n1.c */, 836F6EF318BDC2190095E648 /* spt_spd.c */, - 834FE0D6215C79E9000A5D3D /* sqex_scd_sscf.c */, 836F6EF418BDC2190095E648 /* sqex_scd.c */, 83A21F84201D8981000F04B9 /* sqex_sead.c */, 837CEAF023487F2C00E62A4A /* sqex_streamfile.h */, + 8396BE782935FC2F00CD0580 /* sscf_encrypted.c */, + 8396BE792935FC2F00CD0580 /* sscf_encrypted.h */, + 834FE0D6215C79E9000A5D3D /* sscf.c */, 8339B322280FDF250076F74B /* sspf.c */, 8317C24826982CC1007DD0B8 /* sspr.c */, 836F6EBA18BDC2180095E648 /* ster.c */, @@ -2577,6 +2583,7 @@ 834FE103215C79ED000A5D3D /* ea_schl_streamfile.h in Headers */, 83256CC528666C620036D9C0 /* mpg123.h in Headers */, 83F0AA6021E2028C004BBC04 /* vsv_streamfile.h in Headers */, + 8396BE7B2935FC2F00CD0580 /* sscf_encrypted.h in Headers */, 83FBD506235D31F800D35BCD /* riff_ogg_streamfile.h in Headers */, 8339B327280FDF4B0076F74B /* text_reader.h in Headers */, 836F6F9A18BDC2190095E648 /* meta.h in Headers */, @@ -2853,6 +2860,7 @@ 8306B0E220984590000302D4 /* smv.c in Sources */, 8349A91E1FE6258200E26435 /* bar.c in Sources */, 834FE110215C79ED000A5D3D /* msv.c in Sources */, + 8396BE7A2935FC2F00CD0580 /* sscf_encrypted.c in Sources */, 832389521D224C0800482226 /* hca_decoder.c in Sources */, 836F6F9418BDC2190095E648 /* ivb.c in Sources */, 836F6F8D18BDC2190095E648 /* gsp_gsb.c in Sources */, @@ -2902,7 +2910,7 @@ 83AA7F842519C042004C5298 /* svag_snk.c in Sources */, 834FE107215C79ED000A5D3D /* mib_mih.c in Sources */, 836F703618BDC2190095E648 /* thp.c in Sources */, - 836F6F7818BDC2190095E648 /* Cstr.c in Sources */, + 836F6F7818BDC2190095E648 /* cstr.c in Sources */, 83FC417126D32FF5009A2022 /* hca_decoder_clhca.c in Sources */, 83F1EE30245D4FC10076E182 /* imuse.c in Sources */, 8346D98625BF83B300D1A8B0 /* compresswave_decoder.c in Sources */, @@ -3204,7 +3212,7 @@ 836F6F9118BDC2190095E648 /* ios_psnd.c in Sources */, 836F700618BDC2190095E648 /* vgs_ps.c in Sources */, 834FE10F215C79ED000A5D3D /* sdf.c in Sources */, - 834FE0FF215C79ED000A5D3D /* sqex_scd_sscf.c in Sources */, + 834FE0FF215C79ED000A5D3D /* sscf.c in Sources */, 8373341A23F60C7B00DE14DC /* relic_decoder_mixfft.c in Sources */, 836F6FAA18BDC2190095E648 /* ngc_bh2pcm.c in Sources */, 831BA6211EAC61A500CF89B0 /* x360_pasx.c in Sources */, diff --git a/Frameworks/vgmstream/vgmstream/src/coding/coding.h b/Frameworks/vgmstream/vgmstream/src/coding/coding.h index 0cf109599..013a8adeb 100644 --- a/Frameworks/vgmstream/vgmstream/src/coding/coding.h +++ b/Frameworks/vgmstream/vgmstream/src/coding/coding.h @@ -17,7 +17,7 @@ void g72x_init_state(struct g72x_state* state_ptr); /* ima_decoder */ void decode_standard_ima(VGMSTREAMCHANNEL* stream, sample_t* outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do, int channel, int is_stereo, int is_high_first); -void decode_3ds_ima(VGMSTREAMCHANNEL* stream, sample_t* outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do); +void decode_nw_ima(VGMSTREAMCHANNEL* stream, sample_t* outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do); void decode_snds_ima(VGMSTREAMCHANNEL* stream, sample_t* outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do, int channel); void decode_otns_ima(VGMSTREAM* vgmstream, VGMSTREAMCHANNEL* stream, sample_t* outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do, int channel); void decode_wv6_ima(VGMSTREAMCHANNEL* stream, sample_t* outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do); @@ -638,7 +638,7 @@ typedef struct { /* multichannel-only */ int coupled_count; int stream_count; - int channel_mapping[8]; + uint8_t channel_mapping[255]; /* frame table */ off_t table_offset; int table_count; diff --git a/Frameworks/vgmstream/vgmstream/src/coding/ima_decoder.c b/Frameworks/vgmstream/vgmstream/src/coding/ima_decoder.c index ae136a96c..76c6f49fb 100644 --- a/Frameworks/vgmstream/vgmstream/src/coding/ima_decoder.c +++ b/Frameworks/vgmstream/vgmstream/src/coding/ima_decoder.c @@ -108,8 +108,8 @@ static void std_ima_expand_nibble_mul(VGMSTREAMCHANNEL * stream, off_t byte_offs if (*step_index > 88) *step_index=88; } -/* 3DS IMA (Mario Golf, Mario Tennis; maybe other Camelot games) */ -static void n3ds_ima_expand_nibble(VGMSTREAMCHANNEL * stream, off_t byte_offset, int nibble_shift, int32_t * hist1, int32_t * step_index) { +/* NintendoWare IMA (Mario Golf, Mario Tennis; maybe other Camelot games) */ +static void nw_ima_expand_nibble(VGMSTREAMCHANNEL * stream, off_t byte_offset, int nibble_shift, int32_t * hist1, int32_t * step_index) { int sample_nibble, sample_decoded, step, delta; sample_nibble = (read_8bit(byte_offset,stream->streamfile) >> nibble_shift)&0xf; @@ -402,7 +402,7 @@ void decode_mtf_ima(VGMSTREAMCHANNEL * stream, sample_t * outbuf, int channelspa stream->adpcm_step_index = step_index; } -void decode_3ds_ima(VGMSTREAMCHANNEL * stream, sample_t * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do) { +void decode_nw_ima(VGMSTREAMCHANNEL * stream, sample_t * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do) { int i, sample_count; int32_t hist1 = stream->adpcm_history1_32; int step_index = stream->adpcm_step_index; @@ -415,7 +415,7 @@ void decode_3ds_ima(VGMSTREAMCHANNEL * stream, sample_t * outbuf, int channelspa off_t byte_offset = stream->offset + i/2; int nibble_shift = (i&1?4:0); //low nibble order - n3ds_ima_expand_nibble(stream, byte_offset,nibble_shift, &hist1, &step_index); + nw_ima_expand_nibble(stream, byte_offset,nibble_shift, &hist1, &step_index); outbuf[sample_count] = (short)(hist1); } diff --git a/Frameworks/vgmstream/vgmstream/src/decode.c b/Frameworks/vgmstream/vgmstream/src/decode.c index 55b4bc5c1..ad7e20467 100644 --- a/Frameworks/vgmstream/vgmstream/src/decode.c +++ b/Frameworks/vgmstream/vgmstream/src/decode.c @@ -425,7 +425,7 @@ int get_vgmstream_samples_per_frame(VGMSTREAM* vgmstream) { case coding_PCM4_U: case coding_IMA_int: case coding_DVI_IMA_int: - case coding_3DS_IMA: + case coding_NW_IMA: case coding_WV6_IMA: case coding_HV_IMA: case coding_FFTA2_IMA: @@ -638,7 +638,7 @@ int get_vgmstream_frame_size(VGMSTREAM* vgmstream) { case coding_IMA_int: case coding_DVI_IMA: case coding_DVI_IMA_int: - case coding_3DS_IMA: + case coding_NW_IMA: case coding_WV6_IMA: case coding_HV_IMA: case coding_FFTA2_IMA: @@ -1173,9 +1173,9 @@ void decode_vgmstream(VGMSTREAM* vgmstream, int samples_written, int samples_to_ } break; } - case coding_3DS_IMA: + case coding_NW_IMA: for (ch = 0; ch < vgmstream->channels; ch++) { - decode_3ds_ima(&vgmstream->ch[ch], buffer+ch, + decode_nw_ima(&vgmstream->ch[ch], buffer+ch, vgmstream->channels, vgmstream->samples_into_block, samples_to_do); } break; diff --git a/Frameworks/vgmstream/vgmstream/src/formats.c b/Frameworks/vgmstream/vgmstream/src/formats.c index 85d76a9a9..8a6836aa7 100644 --- a/Frameworks/vgmstream/vgmstream/src/formats.c +++ b/Frameworks/vgmstream/vgmstream/src/formats.c @@ -31,6 +31,7 @@ static const char* extension_list[] = { "800", "9tav", + "a3c", //txth/reserved [Puyo Puyo 20th Anniversary (PSP)] //"aac", //common "aa3", //FFmpeg/not parsed (ATRAC3/ATRAC3PLUS/MP3/LPCM/WMA) "aax", @@ -56,7 +57,6 @@ static const char* extension_list[] = { "ahv", "ai", //"aif", //common - "aif-Loop", "aifc", //common? //"aiff", //common "aix", @@ -649,6 +649,7 @@ static const char* extension_list[] = { "xen", "xma", "xma2", + "xms", "xmu", "xmv", "xnb", @@ -790,7 +791,7 @@ static const coding_info coding_info_list[] = { {coding_IMA_int, "IMA 4-bit ADPCM (mono/interleave)"}, {coding_DVI_IMA, "Intel DVI 4-bit IMA ADPCM"}, {coding_DVI_IMA_int, "Intel DVI 4-bit IMA ADPCM (mono/interleave)"}, - {coding_3DS_IMA, "3DS IMA 4-bit ADPCM"}, + {coding_NW_IMA, "NintendoWare IMA 4-bit ADPCM"}, {coding_SNDS_IMA, "Heavy Iron .snds 4-bit IMA ADPCM"}, {coding_QD_IMA, "Quantic Dream 4-bit IMA ADPCM"}, {coding_WV6_IMA, "Gorilla Systems WV6 4-bit IMA ADPCM"}, @@ -1318,7 +1319,7 @@ static const meta_info meta_info_list[] = { {meta_WAVEBATCH, "Firebrand Games WBAT header"}, {meta_HD3_BD3, "Sony HD3+BD3 header"}, {meta_BNK_SONY, "Sony BNK header"}, - {meta_SCD_SSCF, "Square-Enix SCD (SSCF) header"}, + {meta_SSCF, "Square-Enix SSCF header"}, {meta_DSP_VAG, ".VAG DSP header"}, {meta_DSP_ITL, ".ITL DSP header"}, {meta_A2M, "Artificial Mind & Movement A2M header"}, diff --git a/Frameworks/vgmstream/vgmstream/src/meta/ads.c b/Frameworks/vgmstream/vgmstream/src/meta/ads.c index 4f4f6ea4c..719f2f87a 100644 --- a/Frameworks/vgmstream/vgmstream/src/meta/ads.c +++ b/Frameworks/vgmstream/vgmstream/src/meta/ads.c @@ -363,7 +363,7 @@ VGMSTREAM* init_vgmstream_ads_container(STREAMFILE* sf) { subfile_size = get_streamfile_size(sf) - subfile_offset; - temp_sf = setup_subfile_streamfile(sf, subfile_offset, subfile_size, NULL); + temp_sf = setup_subfile_streamfile(sf, subfile_offset, subfile_size, "ads"); if (!temp_sf) goto fail; vgmstream = init_vgmstream_ads(temp_sf); diff --git a/Frameworks/vgmstream/vgmstream/src/meta/adx_keys.h b/Frameworks/vgmstream/vgmstream/src/meta/adx_keys.h index 9d2055c56..14d2fb0da 100644 --- a/Frameworks/vgmstream/vgmstream/src/meta/adx_keys.h +++ b/Frameworks/vgmstream/vgmstream/src/meta/adx_keys.h @@ -264,6 +264,9 @@ static const adxkey_info adxkey9_list[] = { /* Shin Megami Tensei V (Switch) */ {0x0000,0x0000,0x0000, NULL,1731948526}, // 00000000673B6FEE + /* Persona 5 Royal (PC) */ + {0x0000,0x0000,0x0000, NULL,9923540143823782}, // 002341683D2FDBA6 + }; static const int adxkey8_list_count = sizeof(adxkey8_list) / sizeof(adxkey8_list[0]); diff --git a/Frameworks/vgmstream/vgmstream/src/meta/bcstm.c b/Frameworks/vgmstream/vgmstream/src/meta/bcstm.c index 87603d296..2ad97a8ad 100644 --- a/Frameworks/vgmstream/vgmstream/src/meta/bcstm.c +++ b/Frameworks/vgmstream/vgmstream/src/meta/bcstm.c @@ -104,7 +104,7 @@ VGMSTREAM * init_vgmstream_bcstm(STREAMFILE *streamFile) { vgmstream->coding_type = coding_NGC_DSP; if (is_camelot_ima) { - vgmstream->coding_type = coding_3DS_IMA; + vgmstream->coding_type = coding_NW_IMA; } else { int i, c; diff --git a/Frameworks/vgmstream/vgmstream/src/meta/bfwav.c b/Frameworks/vgmstream/vgmstream/src/meta/bfwav.c index a7298dc05..e348367e8 100644 --- a/Frameworks/vgmstream/vgmstream/src/meta/bfwav.c +++ b/Frameworks/vgmstream/vgmstream/src/meta/bfwav.c @@ -227,7 +227,7 @@ static VGMSTREAM* init_vgmstream_bxwav(STREAMFILE* sf, bxwav_type_t type) { break; case 0x03: - vgmstream->coding_type = coding_3DS_IMA; + vgmstream->coding_type = coding_NW_IMA; /* hist is read below */ break; diff --git a/Frameworks/vgmstream/vgmstream/src/meta/cpk.c b/Frameworks/vgmstream/vgmstream/src/meta/cpk.c index 1dd2ffafc..8ebe4a260 100644 --- a/Frameworks/vgmstream/vgmstream/src/meta/cpk.c +++ b/Frameworks/vgmstream/vgmstream/src/meta/cpk.c @@ -18,6 +18,8 @@ VGMSTREAM* init_vgmstream_cpk_memory(STREAMFILE* sf, STREAMFILE* sf_acb) { off_t subfile_offset = 0; size_t subfile_size = 0; utf_context* utf = NULL; + utf_context* utf_h = NULL; + utf_context* utf_l = NULL; int total_subsongs, target_subsong = sf->stream_index; int subfile_id = 0; cpk_type_t type; @@ -40,14 +42,17 @@ VGMSTREAM* init_vgmstream_cpk_memory(STREAMFILE* sf, STREAMFILE* sf_acb) { /* CPK .cpk is CRI's generic file container, but here we only support CPK .awb used as * early audio bank, that like standard AFS2 .awb comes with .acb */ { - int rows, i; + int rows, rows_l, rows_h, i; const char* name; + const char* name_l; + const char* name_h; const char* Tvers; uint32_t table_offset = 0, offset; uint32_t Files = 0, FilesL = 0, FilesH = 0; uint64_t ContentOffset = 0, ItocOffset = 0; uint16_t Align = 0; uint32_t DataL_offset = 0, DataL_size = 0, DataH_offset = 0, DataH_size = 0; + int id_align; /* base header */ table_offset = 0x10; @@ -65,7 +70,7 @@ VGMSTREAM* init_vgmstream_cpk_memory(STREAMFILE* sf, STREAMFILE* sf_acb) { utf_close(utf); utf = NULL; - if (strncmp(Tvers, "awb", 3) != 0) /* starts with "awb" + ".(version)" (SFvTK, MGS3D) or " for (version)" (ACI) */ + if (strncmp(Tvers, "awb", 3) != 0) /* starts with "awb" + ".(version)" (SFvTK, MGS3D) or " for (version)" (ACI, Puyo) */ goto fail; if (Files <= 0) goto fail; @@ -104,51 +109,77 @@ VGMSTREAM* init_vgmstream_cpk_memory(STREAMFILE* sf, STREAMFILE* sf_acb) { /* DataL header */ table_offset = DataL_offset; - utf = utf_open(sf, table_offset, &rows, &name); - if (!utf || strcmp(name, "CpkItocL") != 0 || rows != FilesL) + utf_l = utf_open(sf, table_offset, &rows_l, &name_l); + if (!utf_l || strcmp(name_l, "CpkItocL") != 0 || rows_l != FilesL) goto fail; - for (i = 0; i < rows; i++) { + /* DataH header */ + table_offset = DataH_offset; + utf_h = utf_open(sf, table_offset, &rows_h, &name_h); + if (!utf_h || strcmp(name_h, "CpkItocH") != 0 || rows_h != FilesH) + goto fail; + + + /* rarely ID doesn't start at 0, adjust values [Puyo Puyo 20th Anniversary (3DS)-3DS_manzai_voice] */ + id_align = 0; + { + uint16_t ID_l = 0; + uint16_t ID_h = 0; + + /* use lower as base, one table may not exist */ + utf_query_u16(utf_l, 0, "ID", &ID_l); + utf_query_u16(utf_h, 0, "ID", &ID_h); + if (rows_l > 0 && rows_h > 0) { + if (ID_l > 0 && ID_h > 0) /* one is 0 = no adjust needed */ + id_align = ID_l < ID_h ? ID_l : ID_h; + } + else if (rows_l) { + id_align = ID_l; + } + else if (rows_h) { + id_align = ID_h; + } + } + + /* save DataL sizes */ + for (i = 0; i < rows_l; i++) { uint16_t ID = 0; uint16_t FileSize, ExtractSize; - if (!utf_query_u16(utf, i, "ID", &ID) || - !utf_query_u16(utf, i, "FileSize", &FileSize) || - !utf_query_u16(utf, i, "ExtractSize", &ExtractSize)) + if (!utf_query_u16(utf_l, i, "ID", &ID) || + !utf_query_u16(utf_l, i, "FileSize", &FileSize) || + !utf_query_u16(utf_l, i, "ExtractSize", &ExtractSize)) goto fail; + ID -= id_align; if (ID >= Files || FileSize != ExtractSize || sizes[ID]) goto fail; sizes[ID] = FileSize; } - utf_close(utf); - utf = NULL; - - /* DataR header */ - table_offset = DataH_offset; - utf = utf_open(sf, table_offset, &rows, &name); - if (!utf || strcmp(name, "CpkItocH") != 0 || rows != FilesH) - goto fail; - - for (i = 0; i < rows; i++) { + /* save DataH sizes */ + for (i = 0; i < rows_h; i++) { uint16_t ID = 0; uint32_t FileSize, ExtractSize; - if (!utf_query_u16(utf, i, "ID", &ID) || - !utf_query_u32(utf, i, "FileSize", &FileSize) || - !utf_query_u32(utf, i, "ExtractSize", &ExtractSize)) + if (!utf_query_u16(utf_h, i, "ID", &ID) || + !utf_query_u32(utf_h, i, "FileSize", &FileSize) || + !utf_query_u32(utf_h, i, "ExtractSize", &ExtractSize)) goto fail; + ID -= id_align; if (ID >= Files || FileSize != ExtractSize || sizes[ID]) goto fail; sizes[ID] = FileSize; } - utf_close(utf); - utf = NULL; + utf_close(utf_l); + utf_l = NULL; + + utf_close(utf_h); + utf_h = NULL; /* find actual offset */ @@ -156,7 +187,7 @@ VGMSTREAM* init_vgmstream_cpk_memory(STREAMFILE* sf, STREAMFILE* sf_acb) { for (i = 0; i < Files; i++) { uint32_t size = sizes[i]; if (i + 1 == target_subsong) { - subfile_id = i; + subfile_id = i + id_align; subfile_offset = offset; subfile_size = size; break; @@ -166,7 +197,7 @@ VGMSTREAM* init_vgmstream_cpk_memory(STREAMFILE* sf, STREAMFILE* sf_acb) { if (Align && (offset % Align)) offset += Align - (offset % Align); } - + free(sizes); sizes = NULL; } @@ -224,6 +255,8 @@ VGMSTREAM* init_vgmstream_cpk_memory(STREAMFILE* sf, STREAMFILE* sf_acb) { fail: free(sizes); utf_close(utf); + utf_close(utf_l); + utf_close(utf_h); close_streamfile(temp_sf); close_vgmstream(vgmstream); return NULL; diff --git a/Frameworks/vgmstream/vgmstream/src/meta/Cstr.c b/Frameworks/vgmstream/vgmstream/src/meta/cstr.c similarity index 90% rename from Frameworks/vgmstream/vgmstream/src/meta/Cstr.c rename to Frameworks/vgmstream/vgmstream/src/meta/cstr.c index 227c72331..ade7e1f18 100644 --- a/Frameworks/vgmstream/vgmstream/src/meta/Cstr.c +++ b/Frameworks/vgmstream/vgmstream/src/meta/cstr.c @@ -3,8 +3,8 @@ /* Cstr - from Namco NuSound v1 games [Mr. Driller (GC), Star Fox Assault (GC), Donkey Konga (GC)] */ -VGMSTREAM * init_vgmstream_cstr(STREAMFILE* sf) { - VGMSTREAM * vgmstream = NULL; +VGMSTREAM* init_vgmstream_cstr(STREAMFILE* sf) { + VGMSTREAM* vgmstream = NULL; off_t start_offset; size_t interleave, first_skip; int loop_flag, channels, sample_rate; @@ -12,11 +12,12 @@ VGMSTREAM * init_vgmstream_cstr(STREAMFILE* sf) { /* checks */ + if (!is_id32be(0x00,sf, "Cstr")) + goto fail; + if (!check_extensions(sf,"dsp")) goto fail; - if (read_u32be(0x00,sf) != 0x43737472) /* "Cstr" */ - goto fail; /* 0x04: version (0x0066 = 0.66 as seen in nus_config .txt) */ interleave = read_u16be(0x06, sf); @@ -31,7 +32,7 @@ VGMSTREAM * init_vgmstream_cstr(STREAMFILE* sf) { /* next is DSP header, with some oddities: * - loop flag isn't always set vs Cstr's flag (won't have DSP loop_ps/etc) - * - loop start nibbles can be wrong even with loop flag set + * - loop start can be wrong even with loop flag set; rarely matches Cstr's loop_start [SF Assault (GC)] * - wonky loop_ps as a result (other fields agree between channels) */ num_samples = read_s32be(0x20 + 0x00, sf); @@ -58,10 +59,8 @@ VGMSTREAM * init_vgmstream_cstr(STREAMFILE* sf) { else start_offset += first_skip; } - if (first_skip > 0 && loop_start >= (interleave - first_skip)) - loop_start = loop_start - (interleave - first_skip); - loop_start = loop_start * 2; + loop_start = loop_start * channels; /* Mr. Driller oddity, unreliable loop flag */ if (loop_end == num_nibbles) { diff --git a/Frameworks/vgmstream/vgmstream/src/meta/hca_bf.h b/Frameworks/vgmstream/vgmstream/src/meta/hca_bf.h index 0dd1cb15e..8a890e9cc 100644 --- a/Frameworks/vgmstream/vgmstream/src/meta/hca_bf.h +++ b/Frameworks/vgmstream/vgmstream/src/meta/hca_bf.h @@ -109,7 +109,7 @@ done: static void bruteforce_hca_key_bin(STREAMFILE* sf, hca_codec_data* hca_data, unsigned long long* p_keycode, uint16_t subkey) { bruteforce_hca_key_bin_type(sf, hca_data, p_keycode, subkey, HBF_TYPE_64LE_1); - //bruteforce_hca_key_bin_type(sf, hca_data, p_keycode, subkey, HBF_TYPE_32LE_1); + bruteforce_hca_key_bin_type(sf, hca_data, p_keycode, subkey, HBF_TYPE_32LE_1); //bruteforce_hca_key_bin_type(sf, hca_data, p_keycode, subkey, HBF_TYPE_64BE_1); //bruteforce_hca_key_bin_type(sf, hca_data, p_keycode, subkey, HBF_TYPE_32BE_1); diff --git a/Frameworks/vgmstream/vgmstream/src/meta/hca_keys.h b/Frameworks/vgmstream/vgmstream/src/meta/hca_keys.h index 90e7b46cb..55bc11e3c 100644 --- a/Frameworks/vgmstream/vgmstream/src/meta/hca_keys.h +++ b/Frameworks/vgmstream/vgmstream/src/meta/hca_keys.h @@ -448,6 +448,7 @@ static const hcakey_info hcakey_list[] = { {0x120db58e6c835175}, //music_0110026 {0x3613e2a7fdfc0784}, //music_0110027 {0xc239d244b6d3b722}, //music_0110028 + {0x2575c136a260e723}, //music_0110029 {0xfb647d074e53fab6}, //music_0120001 {0xc24049b9f7ed3105}, //music_0120002 {0xdc128f2fd48bf4b}, //music_0120003 @@ -468,6 +469,7 @@ static const hcakey_info hcakey_list[] = { {0x3674aba8da7bc84b}, //music_0120018 {0xfd61f2c3b89f3888}, //music_0120019 {0x514fa9879fd07278}, //music_0120021 + {0x3841dd3467659916}, //music_0120022 {0x4fffee4065d22bec}, //music_0210001 {0x7678588b0adf59df}, //music_0210002 {0xa0316b536c8b7540}, //music_0210003 @@ -484,6 +486,7 @@ static const hcakey_info hcakey_list[] = { {0xaecee65d0f181d3b}, //music_0210014 {0x2822bba0a5c4f18c}, //music_0210015 {0xff579d3fcfa8453a}, //music_0210016 + {0x3caa61e8b958f6d8}, //music_0210017 {0x15bb78c31db0a0b6}, //music_0220001 {0x59b1257242c40109}, //music_0220002 {0xdb402bd08d522f34}, //music_0220003 @@ -504,6 +507,7 @@ static const hcakey_info hcakey_list[] = { {0xfceaa73248868ec5}, //music_0220019 {0x3b6b0023a2dd8c3d}, //music_0220020 {0x318f65f564daa549}, //music_0220021 + {0x3dac12b26997f628}, //music_0220022 {0x6a15a9610d10d210}, //music_0310001 {0x57111c24801b44a1}, //music_0310002 {0x40443974a0a86b8b}, //music_0310003 @@ -555,6 +559,7 @@ static const hcakey_info hcakey_list[] = { {0x1da4370c9c20319c}, //music_0410013 {0xd8cdd53589ad3634}, //music_0410014 {0x88007190e0bfa1ce}, //music_0410015 + {0x6fccdd5c3d0d6e3e}, //music_0410016 {0x5d1f3fdbbb036f8d}, //music_0420001 {0xc04264e8f34ad5c0}, //music_0420002 {0x8f0e96b4f71f724f}, //music_0420003 @@ -567,7 +572,7 @@ static const hcakey_info hcakey_list[] = { {0x1bb363adcf4eb3f8}, //music_0420010 {0xd80d3dcc7c75cea}, //music_0420011 {0x52723f026d5238e8}, //music_0420012 - {0xd13a315c0005f0}, //music_0420013 + {0xd13a315c0005f0}, //music_0420013 {0x35f2d3cec84aba1}, //music_0420014 {0xdad11fe0e397ede}, //music_0420015 {0xc94236c936f50cc}, //music_0420016 @@ -632,7 +637,7 @@ static const hcakey_info hcakey_list[] = { {0x1dd21a1244ca12f1}, //music_0620002 {0xfdec74b23d8b494b}, //music_0620003 {0x6f9735c02faf6aae}, //music_0620004 - {0xe978d394512cfd}, //music_0620005 + {0xe978d394512cfd}, //music_0620005 {0xaba147637d52efbe}, //music_0620006 {0xe67f4da6012c5d24}, //music_0620007 {0xc352bbf3d519256e}, //music_0620008 @@ -647,6 +652,7 @@ static const hcakey_info hcakey_list[] = { {0x5c1195d8afcb1901}, //music_0620017 {0x1ad8db767d9ba4a7}, //music_0620018 {0x9bc820aa161b0f08}, //music_0620019 + {0x972b52f3dfaa387a}, //music_0910001 {0x2a47feac8dc3ca9c}, //music_3010001 {0x9ebbaf63ffe9d9ef}, //music_3010002 {0xe553dba6592293d8}, //music_3010003 @@ -673,6 +679,10 @@ static const hcakey_info hcakey_list[] = { {0x729efd67aede1a40}, //music_3020008 {0xb7b9a143742fa51e}, //music_3020009 {0xc7750328bcd329f}, //music_3020010 + {0x5761fe7462b17a3b}, //music_3020012 + {0x98c7a1d1c45df640}, //music_3020013 + {0x3d01826fe053ddda}, //music_3020014 + {0xa6a6426caed68f7c}, //music_3020015 {0xdfad847a86a126bb}, //music_5030001 {0x711ef85045b8c26e}, //music_5030002 {0xff7640b46d72b337}, //music_5030003 @@ -764,6 +774,14 @@ static const hcakey_info hcakey_list[] = { {0xd51e8d88fff1aa5c}, //music_5030089 {0xa2ea81812297bf73}, //music_5030090 {0x276f1e23c97cf8d}, //music_5030091 + {0xb59a0df1213c36c9}, //music_5030092 + {0xebf7bfebb82a4411}, //music_5030093 + {0xb991fcb8b74f46d7}, //music_5030094 + {0x435e2e064bd48ad5}, //music_5030095 + {0xa9824e9baaa354e2}, //music_5030096 + {0xc3a72539b831ea6e}, //music_5030097 + {0x8bc6b7b7a2d2bba3}, //music_5030098 + {0xdbb0f41e90b30452}, //music_5030099 {0x444dda6d55d76095}, //music_5040001 {0xcbf4f1324081e0a6}, //music_5040002 {0xf1db3c1d9542063a}, //music_5040003 @@ -774,7 +792,7 @@ static const hcakey_info hcakey_list[] = { {0xf877dea1180b9b90}, //music_5040008 {0xcd3fb92065d9f373}, //music_5040009 {0xee8da2806a13eecf}, //music_5040010 - {0x46fd87a21859ac}, //music_5040011 + {0x46fd87a21859ac}, //music_5040011 {0x90fefcd350bd2cb8}, //music_5040012 {0xf7edc5d72fdd6ceb}, //music_5040013 {0x4c7d7c251c6bfa95}, //music_5040014 @@ -942,8 +960,21 @@ static const hcakey_info hcakey_list[] = { {0x6f321adde08396e3}, //music_5050163 {0x58afa6381eeb1425}, //music_5050164 {0x751daf7d1a5401cb}, //music_5050165 + {0xbd6b66823f854f68}, //music_5050167 + {0xceb902b93eba45d8}, //music_5050168 {0x2550e145b93723ae}, //music_5050169 + {0xb512188a55b8b698}, //music_5050170 {0x26e5bf2c66a9898d}, //music_5050171 + {0xd93d0a1764e85d4d}, //music_5050176 + {0x59efd868058a402e}, //music_5050178 + {0x93075c0fbb31f463}, //music_5050179 + {0xdedb6ae518faac3d}, //music_5050180 + {0xe997edae32a5fa3d}, //music_5050181 + {0xe19e00aebc8b309b}, //music_5050182 + {0x10574a2abfe8ab99}, //music_5050183 + {0xbd2f4b5ab481d300}, //music_5050184 + {0x1a253c2f40a38917}, //music_5050185 + {0xc735e9f28243ea8a}, //music_5050186 {0x52c250eade92393b}, //music_9010001 {0xf66e6bb5b0599b07}, //music_9010002 {0x8582b5a60dbbf948}, //music_9010003 @@ -1054,6 +1085,18 @@ static const hcakey_info hcakey_list[] = { // Echoes of Mana (Android) {1090221945250803295}, // 0F213F153D026E5F + + // Persona 5 Royal (Switch) + {9923540143823782}, // 002341683D2FDBA6 + + // P Sengoku Otome 6 ~Akatsuki no Sekigahara~ (Android) + {97648135}, // 0000000005d1fe07 + + // CHUNITHM International Version (AC) + {33426922444908636}, // 0076C19BDE43685C + + // Star Ocean: The Divine Force (PC) + {68308868861462528}, // 00f2ae8de77f0800 }; #endif/*_HCA_KEYS_H_*/ diff --git a/Frameworks/vgmstream/vgmstream/src/meta/meta.h b/Frameworks/vgmstream/vgmstream/src/meta/meta.h index deaedab03..8f2c27065 100644 --- a/Frameworks/vgmstream/vgmstream/src/meta/meta.h +++ b/Frameworks/vgmstream/vgmstream/src/meta/meta.h @@ -757,7 +757,7 @@ VGMSTREAM * init_vgmstream_bnk_sony(STREAMFILE *streamFile); VGMSTREAM * init_vgmstream_nus3bank(STREAMFILE *streamFile); VGMSTREAM * init_vgmstream_nus3bank_encrypted(STREAMFILE *streamFile); -VGMSTREAM * init_vgmstream_scd_sscf(STREAMFILE *streamFile); +VGMSTREAM * init_vgmstream_sscf(STREAMFILE *streamFile); VGMSTREAM * init_vgmstream_a2m(STREAMFILE *streamFile); @@ -993,4 +993,6 @@ VGMSTREAM* init_vgmstream_vab(STREAMFILE* sf); VGMSTREAM* init_vgmstream_bigrp(STREAMFILE* sf); +VGMSTREAM* init_vgmstream_sscf_encrypted(STREAMFILE* sf); + #endif /*_META_H*/ diff --git a/Frameworks/vgmstream/vgmstream/src/meta/mpeg.c b/Frameworks/vgmstream/vgmstream/src/meta/mpeg.c index da0d806df..0e6de8ab3 100644 --- a/Frameworks/vgmstream/vgmstream/src/meta/mpeg.c +++ b/Frameworks/vgmstream/vgmstream/src/meta/mpeg.c @@ -32,10 +32,10 @@ VGMSTREAM* init_vgmstream_mpeg(STREAMFILE* sf) { if (!mpeg_get_frame_info(sf, start_offset, &info)) goto fail; - /* .mp3/mp2: standard (is .mp1 ever used in games?) - * .lmp1/2/3: for plugins + /* .mp3/mp2: standard + * .lmp3/lmp2: for plugins * .mus: Marc Ecko's Getting Up (PC) */ - if (!check_extensions(sf, "mp3,mp2,mp1,mus,lmp3,lmp2,lmp1")) + if (!check_extensions(sf, "mp3,mp2,lmp3,lmp2,mus")) goto fail; loop_flag = 0; diff --git a/Frameworks/vgmstream/vgmstream/src/meta/ogg_vorbis.c b/Frameworks/vgmstream/vgmstream/src/meta/ogg_vorbis.c index d8c0bf3f1..b008de651 100644 --- a/Frameworks/vgmstream/vgmstream/src/meta/ogg_vorbis.c +++ b/Frameworks/vgmstream/vgmstream/src/meta/ogg_vorbis.c @@ -158,137 +158,164 @@ fail: return NULL; } - -/* Ogg Vorbis - standard .ogg with (possibly) loop comments/metadata */ -static VGMSTREAM* _init_vgmstream_ogg_vorbis_common(STREAMFILE* sf) { - ogg_vorbis_io_config_data cfg = {0}; - ogg_vorbis_meta_info_t ovmi = {0}; - - int is_ogg = 0; - int is_um3 = 0; - int is_kovs = 0; - int is_sngw = 0; - int is_isd = 0; - int is_rpgmvo = 0; - int is_eno = 0; - int is_gwm = 0; - int is_mus = 0; - int is_lse = 0; - int is_bgm = 0; +static int _init_vgmstream_ogg_vorbis_tests(STREAMFILE* sf, ogg_vorbis_io_config_data* cfg, ogg_vorbis_meta_info_t* ovmi) { - /* check extension */ - /* .ogg: standard/various, .logg: renamed for plugins - * .adx: KID games [Remember11 (PC)] - * .rof: The Rhythm of Fighters (Mobile) - * .acm: Planescape Torment Enhanced Edition (PC) - * .sod: Zone 4 (PC) - * .msa: Metal Slug Attack (Mobile) - * .aif/laif/aif-Loop: Psychonauts (PC) raw extractions (named) - * .bin/lbin: Devil May Cry 3: Special Edition (PC) */ - if (check_extensions(sf,"ogg,logg,adx,rof,acm,sod,msa,aif,laif,aif-Loop,bin,lbin")) { - is_ogg = 1; - } else if (check_extensions(sf,"um3")) { - is_um3 = 1; - } else if (check_extensions(sf,"kvs,kovs")) { - /* .kvs: Atelier Sophie (PC), kovs: header id only? */ - is_kovs = 1; - } else if (check_extensions(sf,"sngw")) { /* .sngw: Capcom [Devil May Cry 4 SE (PC), Biohazard 6 (PC)] */ - is_sngw = 1; - } else if (check_extensions(sf,"isd")) { /* .isd: Inti Creates PC games */ - is_isd = 1; - } else if (check_extensions(sf,"rpgmvo,ogg_")) { - /* .rpgmvo: RPG Maker MV games (PC), .ogg_: RPG Maker MZ games (PC) */ - is_rpgmvo = 1; - } else if (check_extensions(sf,"eno")) { /* .eno: Metronomicon (PC) */ - is_eno = 1; - } else if (check_extensions(sf,"gwm")) { /* .gwm: Adagio: Cloudburst (PC) */ - is_gwm = 1; - } else if (check_extensions(sf,"mus")) { /* .mus: Redux - Dark Matters (PC) */ - is_mus = 1; - } else if (check_extensions(sf,"lse")) { /* .lse: Labyrinth of Refrain: Coven of Dusk (PC) */ - is_lse = 1; - } else if (check_extensions(sf,"bgm")) { /* .bgm: Fortissimo (PC) */ - is_bgm = 1; - } else { - goto fail; + /* standard */ + if (is_id32be(0x00,sf, "OggS")) { + + /* .ogg: common, .logg: renamed for plugins + * .adx: KID games [Remember11 (PC)] + * .rof: The Rhythm of Fighters (Mobile) + * .acm: Planescape Torment Enhanced Edition (PC) + * .sod: Zone 4 (PC) + * .msa: Metal Slug Attack (Mobile) + * .bin/lbin: Devil May Cry 3: Special Edition (PC) */ + if (check_extensions(sf,"ogg,logg,adx,rof,acm,sod,msa,bin,lbin")) + return 1; + /* ignore others to allow stuff like .sngw */ } - if (is_ogg) { - if (read_u32be(0x00,sf) == 0x2c444430) { /* Psychic Software [Darkwind: War on Wheels (PC)] */ - ovmi.decryption_callback = psychic_ogg_decryption_callback; - } - else if (read_u32be(0x00,sf) == 0x4C325344) { /* "L2SD" instead of "OggS" [Lineage II Chronicle 4 (PC)] */ - cfg.is_header_swap = 1; - cfg.is_encrypted = 1; - } - else if (read_u32be(0x00,sf) == 0x048686C5) { /* "OggS" XOR'ed + bitswapped [Ys VIII (PC)] */ - cfg.key[0] = 0xF0; - cfg.key_len = 1; - cfg.is_nibble_swap = 1; - cfg.is_encrypted = 1; + /* Koei Tecmo PC games */ + if (is_id32be(0x00,sf, "KOVS")) { + ovmi->loop_start = read_s32le(0x08,sf); + ovmi->loop_flag = (ovmi->loop_start != 0); + ovmi->decryption_callback = kovs_ogg_decryption_callback; + ovmi->meta_type = meta_OGG_KOVS; - } - else if (read_u32be(0x00,sf) == 0x00000000 && /* null instead of "OggS" [Yuppie Psycho (PC)] */ - read_u32be(0x3a,sf) == 0x4F676753) { /* "OggS" in next page */ - cfg.is_header_swap = 1; - cfg.is_encrypted = 1; - } - else if (read_u32be(0x00,sf) != 0x4F676753 && /* random(?) swap instead of "OggS" [Tobi Tsukihime (PC)] */ - read_u32be(0x3a,sf) == 0x4F676753) { /* "OggS" in next page */ - cfg.is_header_swap = 1; - cfg.is_encrypted = 1; - } - else if (read_u32be(0x00,sf) == 0x4F756F71) { /* "OggS" encrypted [Adventure Field 4 (PC)]*/ - ovmi.decryption_callback = at4_ogg_decryption_callback; - } - else if (read_u32be(0x00,sf) == 0x4F676753) { /* "OggS" (standard) */ - ; - } - else { - goto fail; /* unknown/not Ogg Vorbis (ex. Wwise) */ - } - } + cfg->start = 0x20; - if (is_um3) { /* ["Ultramarine3" (???)] */ - if (read_u32be(0x00,sf) != 0x4f676753) { /* "OggS" (optionally encrypted) */ - ovmi.decryption_callback = um3_ogg_decryption_callback; - } - } - - if (is_kovs) { /* Koei Tecmo PC games */ - if (read_u32be(0x00,sf) != 0x4b4f5653) { /* "KOVS" */ + /* .kvs: Atelier Sophie (PC) + * .kovs: header id only? */ + if (!check_extensions(sf,"kvs,kovs")) goto fail; - } - ovmi.loop_start = read_32bitLE(0x08,sf); - ovmi.loop_flag = (ovmi.loop_start != 0); - ovmi.decryption_callback = kovs_ogg_decryption_callback; - ovmi.meta_type = meta_OGG_KOVS; - cfg.start = 0x20; + return 1; + } + + /* [RPG Maker MV (PC), RPG Maker MZ (PC)] */ + if (is_id64be(0x00,sf, "RPGMV\0\0\0")) { + ovmi->decryption_callback = rpgmvo_ogg_decryption_callback; + + cfg->start = 0x10; + + /* .rpgmvo: RPG Maker MV games (PC), .ogg_: RPG Maker MZ games (PC) */ + if (!check_extensions(sf,"rpgmvo,ogg_")) + goto fail; + + return 1; } - if (is_sngw) { /* [Capcom's MT Framework PC games] */ - if (read_u32be(0x00,sf) != 0x4f676753) { /* "OggS" (optionally encrypted) */ - cfg.key_len = read_streamfile(cfg.key, 0x00, 0x04, sf); - cfg.is_header_swap = 1; - cfg.is_nibble_swap = 1; - cfg.is_encrypted = 1; - } + /* L2SD [Lineage II Chronicle 4 (PC)] */ + if (is_id32be(0x00,sf, "L2SD")) { + cfg->is_header_swap = 1; + cfg->is_encrypted = 1; - ovmi.disable_reordering = 1; /* must be an MT Framework thing */ + if (!check_extensions(sf,"ogg,logg")) + goto fail; + + return 1; } - if (is_isd) { /* Inti Creates PC games */ - const char *isl_name = NULL; + /* NIS's "OggS" XOR'ed + bitswapped [Ys VIII (PC), Yomawari: Midnight Shadows (PC)] */ + if (read_u32be(0x00,sf) == 0x048686C5) { + cfg->key[0] = 0xF0; + cfg->key_len = 0x01; + cfg->is_nibble_swap = 1; + cfg->is_encrypted = 1; + + /* .bgm: Yomawari */ + if (!check_extensions(sf,"ogg,logg,bgm")) + goto fail; + + return 1; + } + + /* Psychic Software [Darkwind: War on Wheels (PC)] */ + if (read_u32be(0x00,sf) == 0x2c444430) { + ovmi->decryption_callback = psychic_ogg_decryption_callback; + + if (!check_extensions(sf,"ogg,logg")) + goto fail; + + return 1; + } + + /* null id + check next page [Yuppie Psycho (PC)] */ + if (read_u32be(0x00,sf) == 0x00000000 && is_id32be(0x3a,sf, "OggS")) { + cfg->is_header_swap = 1; + cfg->is_encrypted = 1; + + if (!check_extensions(sf,"ogg,logg")) + goto fail; + + return 1; + } + + /* random(?) id + check next page [Tobi Tsukihime (PC)] */ + if (!is_id32be(0x00,sf, "OggS") && is_id32be(0x3a,sf, "OggS")) { + cfg->is_header_swap = 1; + cfg->is_encrypted = 1; + + if (!check_extensions(sf,"ogg,logg")) + goto fail; + + return 1; + } + + /* encrypted [Adventure Field 4 (PC)] */ + if (read_u32be(0x00,sf) == 0x4F756F71) { + ovmi->decryption_callback = at4_ogg_decryption_callback; //TODO replace with generic descryption? + + if (!check_extensions(sf,"ogg,logg")) + goto fail; + + return 1; + } + + /* .gwm: Adagio: Cloudburst (PC) */ + if (read_u32be(0x00,sf) == 0x123A3A0E) { + cfg->key[0] = 0x5D; + cfg->key_len = 1; + cfg->is_encrypted = 1; + + if (!check_extensions(sf,"gwm")) + goto fail; + + return 1; + } + + /* .mus: Redux - Dark Matters (PC) */ + if (read_u32be(0x00,sf) == 0x6C381C21) { + static const uint8_t mus_key[16] = { + 0x21,0x4D,0x6F,0x01,0x20,0x4C,0x6E,0x02,0x1F,0x4B,0x6D,0x03,0x20,0x4C,0x6E,0x02 + }; + cfg->key_len = sizeof(mus_key); + memcpy(cfg->key, mus_key, cfg->key_len); + cfg->is_header_swap = 1; /* decrypted header gives "Mus " */ + cfg->is_encrypted = 1; + + if (!check_extensions(sf,"mus")) + goto fail; + + return 1; + } + + + /***************************************/ + /* harder to check (could be improved) */ + + /* .isd: Inti Creates PC games */ + if (check_extensions(sf,"isd")) { + const char* isl_name = NULL; /* check various encrypted "OggS" values */ if (read_u32be(0x00,sf) == 0xAF678753) { /* Azure Striker Gunvolt (PC) */ static const uint8_t isd_gv_key[16] = { 0xe0,0x00,0xe0,0x00,0xa0,0x00,0x00,0x00,0xe0,0x00,0xe0,0x80,0x40,0x40,0x40,0x00 }; - cfg.key_len = sizeof(isd_gv_key); - memcpy(cfg.key, isd_gv_key, cfg.key_len); + cfg->key_len = sizeof(isd_gv_key); + memcpy(cfg->key, isd_gv_key, cfg->key_len); isl_name = "GV_steam.isl"; } else if (read_u32be(0x00,sf) == 0x0FE787D3) { /* Mighty Gunvolt (PC) */ @@ -302,8 +329,8 @@ static VGMSTREAM* _init_vgmstream_ogg_vorbis_common(STREAMFILE* sf) { 0x60,0x00,0xE0,0x80,0x00,0xC0,0x00,0x00,0x60,0x80,0x40,0x80,0x20,0x80,0x20,0x00, 0x80,0x40,0xE0,0x00,0x20,0x00,0x20,0x00, }; - cfg.key_len = sizeof(isd_mgv_key); - memcpy(cfg.key, isd_mgv_key, cfg.key_len); + cfg->key_len = sizeof(isd_mgv_key); + memcpy(cfg->key, isd_mgv_key, cfg->key_len); isl_name = "MGV_steam.isl"; } else if (read_u32be(0x00,sf) == 0x0FA74753) { /* Blaster Master Zero (PC) */ @@ -317,15 +344,15 @@ static VGMSTREAM* _init_vgmstream_ogg_vorbis_common(STREAMFILE* sf) { 0x40,0x40,0x00,0x00,0x20,0x40,0x80,0x00,0xE0,0x80,0x20,0x80,0x40,0x80,0xE0,0x00, 0xA0,0x00,0xC0,0x80,0xE0,0x00,0x20,0x00 }; - cfg.key_len = sizeof(isd_bmz_key); - memcpy(cfg.key, isd_bmz_key, cfg.key_len); + cfg->key_len = sizeof(isd_bmz_key); + memcpy(cfg->key, isd_bmz_key, cfg->key_len); isl_name = "output.isl"; } else { goto fail; } - cfg.is_encrypted = 1; + cfg->is_encrypted = 1; /* .isd have companion files in the prev folder: * - .ish: constant id/names (not always) @@ -348,7 +375,7 @@ static VGMSTREAM* _init_vgmstream_ogg_vorbis_common(STREAMFILE* sf) { if (sf_isl) { STREAMFILE* dec_sf = NULL; - dec_sf = setup_ogg_vorbis_streamfile(sf_isl, &cfg); + dec_sf = setup_ogg_vorbis_streamfile(sf_isl, cfg); if (dec_sf) { off_t loop_offset; char basename[PATH_LIMIT]; @@ -362,10 +389,10 @@ static VGMSTREAM* _init_vgmstream_ogg_vorbis_common(STREAMFILE* sf) { read_string(testname, sizeof(testname), loop_offset+0x2c, dec_sf); if (strcmp(basename, testname) == 0) { - ovmi.loop_start = read_32bitLE(loop_offset+0x1c, dec_sf); - ovmi.loop_end = read_32bitLE(loop_offset+0x20, dec_sf); - ovmi.loop_end_found = 1; - ovmi.loop_flag = (ovmi.loop_end != 0); + ovmi->loop_start = read_32bitLE(loop_offset+0x1c, dec_sf); + ovmi->loop_end = read_32bitLE(loop_offset+0x20, dec_sf); + ovmi->loop_end_found = 1; + ovmi->loop_flag = (ovmi->loop_end != 0); break; } @@ -378,62 +405,61 @@ static VGMSTREAM* _init_vgmstream_ogg_vorbis_common(STREAMFILE* sf) { close_streamfile(sf_isl); } } + + return 1; } - if (is_rpgmvo) { /* [RPG Maker MV (PC), RPG Maker MZ (PC)] */ - if (!is_id64be(0x00,sf, "RPGMV\0\0\0")) - goto fail; + /* Capcom's MT Framework PC games [Devil May Cry 4 SE (PC), Biohazard 6 (PC), Mega Man X Legacy Collection (PC)] */ + if (check_extensions(sf,"sngw")) { + /* optionally(?) encrypted */ + if (!is_id32be(0x00,sf, "OggS") && read_u32be(0x00,sf) == read_u32be(0x10,sf)) { + cfg->key_len = read_streamfile(cfg->key, 0x00, 0x04, sf); + cfg->is_header_swap = 1; + cfg->is_nibble_swap = 1; + cfg->is_encrypted = 1; + } - ovmi.decryption_callback = rpgmvo_ogg_decryption_callback; + ovmi->disable_reordering = 1; /* must be an MT Framework thing */ - cfg.start = 0x10; + return 1; } - if (is_eno) { /* [Metronomicon (PC)] */ - /* first byte probably derives into key, but this works too */ - cfg.key[0] = read_u8(0x05,sf); /* regular ogg have a zero at this offset = easy key */ - cfg.key_len = 1; - cfg.is_encrypted = 1; - cfg.start = 0x01; /* "OggS" starts after key-thing */ - } - - if (is_gwm) { /* [Adagio: Cloudburst (PC)] */ - cfg.key[0] = 0x5D; - cfg.key_len = 1; - cfg.is_encrypted = 1; - } - - if (is_mus) { /* [Redux: Dark Matters (PC)] */ - static const uint8_t mus_key[16] = { - 0x21,0x4D,0x6F,0x01,0x20,0x4C,0x6E,0x02,0x1F,0x4B,0x6D,0x03,0x20,0x4C,0x6E,0x02 - }; - cfg.key_len = sizeof(mus_key); - memcpy(cfg.key, mus_key, cfg.key_len); - cfg.is_header_swap = 1; /* decrypted header gives "Mus " */ - cfg.is_encrypted = 1; - } - - if (is_lse) { /* [Nippon Ichi PC games] */ + /* Nippon Ichi PC games */ + if (check_extensions(sf,"lse")) { if (read_u32be(0x00,sf) == 0xFFFFFFFF) { /* [Operation Abyss: New Tokyo Legacy (PC)] */ - cfg.key[0] = 0xFF; - cfg.key_len = 1; - cfg.is_header_swap = 1; - cfg.is_encrypted = 1; + cfg->key[0] = 0xFF; + cfg->key_len = 1; + cfg->is_header_swap = 1; + cfg->is_encrypted = 1; } else { /* [Operation Babel: New Tokyo Legacy (PC), Labyrinth of Refrain: Coven of Dusk (PC)] */ int i; /* found at file_size-1 but this works too (same key for most files but can vary) */ uint8_t base_key = read_u8(0x04,sf) - 0x04; - cfg.key_len = 256; - for (i = 0; i < cfg.key_len; i++) { - cfg.key[i] = (uint8_t)(base_key + i); + cfg->key_len = 256; + for (i = 0; i < cfg->key_len; i++) { + cfg->key[i] = (uint8_t)(base_key + i); } - cfg.is_encrypted = 1; + cfg->is_encrypted = 1; } + + return 1; } - if (is_bgm) { /* [Fortissimo (PC)] */ + /* .eno: Metronomicon (PC) */ + if (check_extensions(sf,"eno")) { + /* 0x00: first byte probably derives into key, but this works too */ + cfg->key[0] = read_u8(0x05,sf); /* regular ogg have a zero at this offset = easy key */ + cfg->key_len = 0x01; + cfg->is_encrypted = 1; + cfg->start = 0x01; /* encrypted "OggS" starts after key-thing */ + + return 1; + } + + /* .bgm: Fortissimo (PC) */ + if (check_extensions(sf,"bgm")) { uint32_t file_size = get_streamfile_size(sf); uint8_t key[0x04]; uint32_t xor_be; @@ -442,14 +468,38 @@ static VGMSTREAM* _init_vgmstream_ogg_vorbis_common(STREAMFILE* sf) { xor_be = get_u32be(key); if ((read_u32be(0x00,sf) ^ xor_be) == get_id32be("OggS")) { int i; - cfg.key_len = 4; - for (i = 0; i < cfg.key_len; i++) { - cfg.key[i] = key[i]; + cfg->key_len = 4; + for (i = 0; i < cfg->key_len; i++) { + cfg->key[i] = key[i]; } - cfg.is_encrypted = 1; + cfg->is_encrypted = 1; + + return 1; } } + /* "Ultramarine3" (???) */ + if (check_extensions(sf,"um3")) { + if (!is_id32be(0x00,sf, "OggS")) { + ovmi->decryption_callback = um3_ogg_decryption_callback; + } + + return 1; + } + + +fail: + return 0; +} + +/* Ogg Vorbis - standard .ogg with (possibly) loop comments/metadata */ +static VGMSTREAM* _init_vgmstream_ogg_vorbis_common(STREAMFILE* sf) { + ogg_vorbis_io_config_data cfg = {0}; + ogg_vorbis_meta_info_t ovmi = {0}; + + /* checks */ + if (!_init_vgmstream_ogg_vorbis_tests(sf, &cfg, &ovmi)) + goto fail; return _init_vgmstream_ogg_vorbis_cfg_ovmi(sf, &cfg, &ovmi); fail: diff --git a/Frameworks/vgmstream/vgmstream/src/meta/ogg_vorbis_streamfile.h b/Frameworks/vgmstream/vgmstream/src/meta/ogg_vorbis_streamfile.h index b767562eb..95892c0ab 100644 --- a/Frameworks/vgmstream/vgmstream/src/meta/ogg_vorbis_streamfile.h +++ b/Frameworks/vgmstream/vgmstream/src/meta/ogg_vorbis_streamfile.h @@ -26,30 +26,30 @@ static size_t ogg_vorbis_io_read(STREAMFILE *sf, uint8_t *dest, off_t offset, si if (data->cfg.is_encrypted) { int max = bytes; - int header_end = 0x04 + data->cfg.start; + int header_end = 0x04; + + //TODO handle data->cfg.start; - if (data->cfg.max_offset + data->cfg.start) { - if (offset > data->cfg.max_offset + data->cfg.start) { + if (data->cfg.max_offset) { + if (offset > data->cfg.max_offset) { max = 0; } else { - max = data->cfg.max_offset + data->cfg.start - offset; + max = data->cfg.max_offset - offset; if (max > bytes) max = bytes; } } for (i = 0; i < max; i++) { - if (data->cfg.is_header_swap && - (offset + i) >= data->cfg.start && - (offset + i) < header_end) { + if (data->cfg.is_header_swap && (offset + i) < header_end) { dest[i] = header_swap[(offset + i) % 0x04]; } else { if (!data->cfg.key_len && !data->cfg.is_nibble_swap) break; - if (data->cfg.key_len && (offset + i) >= data->cfg.start) - dest[i] ^= data->cfg.key[(offset + i - data->cfg.start) % data->cfg.key_len]; + if (data->cfg.key_len) + dest[i] ^= data->cfg.key[(offset + i) % data->cfg.key_len]; if (data->cfg.is_nibble_swap) dest[i] = ((dest[i] << 4) & 0xf0) | ((dest[i] >> 4) & 0x0f); } diff --git a/Frameworks/vgmstream/vgmstream/src/meta/riff.c b/Frameworks/vgmstream/vgmstream/src/meta/riff.c index eebddadb0..213d19ff6 100644 --- a/Frameworks/vgmstream/vgmstream/src/meta/riff.c +++ b/Frameworks/vgmstream/vgmstream/src/meta/riff.c @@ -378,8 +378,9 @@ VGMSTREAM* init_vgmstream_riff(STREAMFILE* sf) { * .xvag: Uncharted Golden Abyss (Vita)[ATRAC9] * .ogg/logg: Luftrausers (Vita)[ATRAC9] * .p1d: Farming Simulator 15 (Vita)[ATRAC9] + * .xms: Ty the Tasmanian Tiger (Xbox) */ - if ( check_extensions(sf, "wav,lwav,xwav,da,dax,cd,med,snd,adx,adp,xss,xsew,adpcm,adw,wd,,sbv,wvx,str,at3,rws,aud,at9,ckd,saf,ima,nsa,pcm,xvag,ogg,logg,p1d") ) { + if ( check_extensions(sf, "wav,lwav,xwav,da,dax,cd,med,snd,adx,adp,xss,xsew,adpcm,adw,wd,,sbv,wvx,str,at3,rws,aud,at9,ckd,saf,ima,nsa,pcm,xvag,ogg,logg,p1d,xms") ) { ; } else if ( check_extensions(sf, "mwv") ) { diff --git a/Frameworks/vgmstream/vgmstream/src/meta/scd_pcm.c b/Frameworks/vgmstream/vgmstream/src/meta/scd_pcm.c index d28c669a1..87648f2cf 100644 --- a/Frameworks/vgmstream/vgmstream/src/meta/scd_pcm.c +++ b/Frameworks/vgmstream/vgmstream/src/meta/scd_pcm.c @@ -1,65 +1,65 @@ -#include "meta.h" -#include "../coding/coding.h" - - -/* .PCM - from Lunar: Eternal Blue (Sega CD) */ -VGMSTREAM * init_vgmstream_scd_pcm(STREAMFILE *streamFile) { - VGMSTREAM * vgmstream = NULL; - off_t start_offset; - int loop_flag, channel_count; - - - /* checks */ - if (!check_extensions(streamFile, "pcm")) - goto fail; - - if (read_16bitBE(0x00,streamFile) == 0x0002) { - channel_count = 1; - } - else if (read_16bitBE(0x00,streamFile) == 0x0001) { - channel_count = 2; /* RP025.PCM, RP039.PCM */ - } - else { - goto fail; - } - - start_offset = 0x800; - - - /* extra validations since .pcm it's kinda generic */ - { - off_t i; - /* should be empty up to start (~0x0a/~0x10 sometimes has unknown values) */ - for (i = 0x20; i < start_offset; i++) { - if (read_8bit(i, streamFile) != 0) - goto fail; - } - } - - /* loops start 0 is possible, plus all? files loops - * (even sfx/voices loop, but those set loop start in silence near the end) */ - loop_flag = (read_32bitBE(0x06,streamFile) != 0); - - - /* build the VGMSTREAM */ - vgmstream = allocate_vgmstream(channel_count,loop_flag); - if (!vgmstream) goto fail; - - vgmstream->meta_type = meta_SCD_PCM; - vgmstream->sample_rate = 32500; /* looks correct compared to emu/recordings */ - vgmstream->num_samples = pcm_bytes_to_samples(get_streamfile_size(streamFile) - start_offset, channel_count, 8); - vgmstream->loop_start_sample = read_32bitBE(0x02,streamFile)*0x400*2; - vgmstream->loop_end_sample = read_32bitBE(0x06,streamFile)*2; - - vgmstream->coding_type = coding_PCM8_SB; - vgmstream->layout_type = layout_interleave; - vgmstream->interleave_block_size = 0x800; - - if (!vgmstream_open_stream(vgmstream,streamFile,start_offset)) - goto fail; - return vgmstream; - -fail: - close_vgmstream(vgmstream); - return NULL; -} +#include "meta.h" +#include "../coding/coding.h" + + +/* .PCM - from Lunar: Eternal Blue (Sega CD) */ +VGMSTREAM* init_vgmstream_scd_pcm(STREAMFILE* sf) { + VGMSTREAM* vgmstream = NULL; + off_t start_offset; + int loop_flag, channels; + + + /* checks */ + if (!check_extensions(sf, "pcm")) + goto fail; + + if (read_u16be(0x00,sf) == 0x0002) { + channels = 1; + } + else if (read_u16be(0x00,sf) == 0x0001) { + channels = 2; /* RP025.PCM, RP039.PCM */ + } + else { + goto fail; + } + + start_offset = 0x800; + + + /* extra validations since .pcm it's kinda generic */ + { + off_t i; + /* should be empty up to start (~0x0a/~0x10 sometimes has unknown values) */ + for (i = 0x20; i < start_offset; i++) { + if (read_u8(i, sf) != 0) + goto fail; + } + } + + /* loops start 0 is possible, plus all? files loops + * (even sfx/voices loop, but those set loop start in silence near the end) */ + loop_flag = (read_u32be(0x06,sf) != 0); + + + /* build the VGMSTREAM */ + vgmstream = allocate_vgmstream(channels,loop_flag); + if (!vgmstream) goto fail; + + vgmstream->meta_type = meta_SCD_PCM; + vgmstream->sample_rate = 32500; /* looks correct compared to emu/recordings */ + vgmstream->num_samples = pcm_bytes_to_samples(get_streamfile_size(sf) - start_offset, channels, 8); + vgmstream->loop_start_sample = read_s32be(0x02,sf)*0x400*2; + vgmstream->loop_end_sample = read_s32be(0x06,sf)*2; + + vgmstream->coding_type = coding_PCM8_SB; + vgmstream->layout_type = layout_interleave; + vgmstream->interleave_block_size = 0x800; + + if (!vgmstream_open_stream(vgmstream,sf,start_offset)) + goto fail; + return vgmstream; + +fail: + close_vgmstream(vgmstream); + return NULL; +} diff --git a/Frameworks/vgmstream/vgmstream/src/meta/sndz.c b/Frameworks/vgmstream/vgmstream/src/meta/sndz.c index f23c9eccc..919db7df0 100644 --- a/Frameworks/vgmstream/vgmstream/src/meta/sndz.c +++ b/Frameworks/vgmstream/vgmstream/src/meta/sndz.c @@ -2,7 +2,7 @@ #include "../coding/coding.h" -/* SNDZ - Sony/SCE's lib? (cousin of SXD) [Gran Turismo 7 (PS4)] */ +/* SNDZ - Sony/SCE's lib? (cousin of SXD) [Gran Turismo 7 (PS4), Astro's Playroom (PS5)] */ VGMSTREAM* init_vgmstream_sndz(STREAMFILE* sf) { VGMSTREAM* vgmstream = NULL; STREAMFILE* sf_b = NULL; @@ -85,7 +85,7 @@ VGMSTREAM* init_vgmstream_sndz(STREAMFILE* sf) { /* 12: null */ sample_rate = read_u32le(offset + 0x14, sf); num_samples = read_s32le(offset + 0x18, sf); - at9_config = read_u32le(offset + 0x1c, sf); + at9_config = read_u32le(offset + 0x1c, sf); /* null for other codecs */ loop_start = read_s32le(offset + 0x20, sf); loop_end = read_s32le(offset + 0x24, sf); stream_size = read_u32le(offset + 0x28, sf); /* from data start in szd2 or absolute in szd3 */ @@ -131,6 +131,24 @@ VGMSTREAM* init_vgmstream_sndz(STREAMFILE* sf) { read_string(vgmstream->stream_name,STREAM_NAME_SIZE, name_offset, sf); switch (codec) { + case 0x02: + vgmstream->coding_type = coding_PCM16LE; + vgmstream->layout_type = layout_interleave; + vgmstream->interleave_block_size = 0x02; + break; + + case 0x04: + vgmstream->coding_type = coding_PCM24LE; + vgmstream->layout_type = layout_interleave; + vgmstream->interleave_block_size = 0x02; + break; + + case 0x08: + vgmstream->coding_type = coding_PCMFLOAT; + vgmstream->layout_type = layout_interleave; + vgmstream->interleave_block_size = 0x04; + break; + case 0x20: vgmstream->coding_type = coding_HEVAG; vgmstream->layout_type = layout_interleave; diff --git a/Frameworks/vgmstream/vgmstream/src/meta/sqex_scd_sscf.c b/Frameworks/vgmstream/vgmstream/src/meta/sqex_scd_sscf.c deleted file mode 100644 index 2bcb41780..000000000 --- a/Frameworks/vgmstream/vgmstream/src/meta/sqex_scd_sscf.c +++ /dev/null @@ -1,174 +0,0 @@ -#include "meta.h" -#include "../coding/coding.h" - -/* SSCF - Square-Enix games, older version of .scd [Crisis Core -Final Fantasy VII- (PSP), Dissidia 012 (PSP)] */ -VGMSTREAM * init_vgmstream_scd_sscf(STREAMFILE *streamFile) { - VGMSTREAM * vgmstream = NULL; - off_t start_offset, meta_offset, stream_offset; - size_t stream_size; - int loop_flag, channel_count, sample_rate; - int total_subsongs, target_subsong = streamFile->stream_index; - - - /* checks */ - if (!check_extensions(streamFile, "scd")) - goto fail; - - if (read_32bitBE(0x00,streamFile) != 0x53534346) /* "SSCF" "*/ - goto fail; - if (!(read_32bitBE(0x04,streamFile) == 0x002070210 || /* version? [Crisis Core (PSP)] */ - read_32bitBE(0x04,streamFile) == 0x10020702)) /* inverted version? [Dissidia (PSP)] */ - goto fail; - /* 0x08: file size, except for a few files that with a weird value */ - /* 0x10: file id? */ - - - /* find total subsongs (entries can be dummy) and target subsong */ - { - int i,j, is_dupe; - int entries = read_32bitLE(0x0c,streamFile); - off_t stream_offsets[0x800]; - - if (entries > 0x800) /* meh */ - goto fail; - - - if (target_subsong == 0) target_subsong = 1; - - meta_offset = 0; - total_subsongs = 0; - for (i = 0; i < entries; i++) { - off_t entry_offset = 0x20 + (0x20*i); - off_t entry_stream_offset; - - /* skip dummies */ - if (read_32bitLE(entry_offset+0x08,streamFile) == 0) /* size 0 */ - continue; - if (read_16bitLE(entry_offset+0x0c,streamFile) == 0) /* no sample rate */ - continue; - - /* skip repeated sounds */ - is_dupe = 0; - entry_stream_offset = read_32bitLE(entry_offset+0x04,streamFile); - for (j = 0; j < total_subsongs; j++) { - if (entry_stream_offset == stream_offsets[j]) { - is_dupe = 1; - break; - } - } - if (is_dupe) - continue; - stream_offsets[total_subsongs] = entry_stream_offset; - - /* ok */ - total_subsongs++; - if (total_subsongs == target_subsong) { - meta_offset = entry_offset; - } - } - - if (meta_offset == 0) - goto fail; - } - - - /* 0x00(2): config? usually 0x00/0x01 */ - /* 0x02(2): loop config */ //todo when 1 uses PS-ADPCM uses SPU loop flags to set start/end - stream_offset = read_32bitLE(meta_offset+0x04,streamFile); /* absolute */ - stream_size = read_32bitLE(meta_offset+0x08,streamFile); - sample_rate = (uint16_t)read_16bitLE(meta_offset+0x0c,streamFile); - /* 0x0e: config? */ - /* 0x10: config? */ - /* 0x14: 0xCA5F or 0x5FCA */ - /* 0x18: config? */ - /* 0x1c: null / some id? */ - - loop_flag = 0; - channel_count = 1; - start_offset = stream_offset; - - - /* build the VGMSTREAM */ - vgmstream = allocate_vgmstream(channel_count, loop_flag); - if (!vgmstream) goto fail; - - vgmstream->sample_rate = sample_rate; - vgmstream->num_streams = total_subsongs; - vgmstream->stream_size = stream_size; - vgmstream->num_samples = ps_bytes_to_samples(stream_size, channel_count); - if (loop_flag) { - vgmstream->loop_start_sample = 0; - vgmstream->loop_end_sample = vgmstream->num_samples; - } - - vgmstream->meta_type = meta_SCD_SSCF; - vgmstream->coding_type = coding_PSX; - vgmstream->layout_type = layout_none; - - if (!vgmstream_open_stream(vgmstream,streamFile,start_offset)) - goto fail; - return vgmstream; - -fail: - close_vgmstream(vgmstream); - return NULL; -} - -#if 0 -/* SSCF X360 - updated SCD with encrypted data [Final Fantasy XI (360), PlayOnline Viewer (X360)] */ -VGMSTREAM * init_vgmstream_scd_sscf_x360(STREAMFILE *streamFile) { - VGMSTREAM * vgmstream = NULL; - off_t start_offset, meta_offset, stream_offset; - size_t stream_size; - int loop_flag, channel_count, sample_rate; - int total_subsongs, target_subsong = streamFile->stream_index; - - - /* checks */ - if (!check_extensions(streamFile, "scd")) - goto fail; - - if (read_32bitBE(0x00,streamFile) != 0x53534346) /* "SSCF" "*/ - goto fail; - if (read_32bitBE(0x04,streamFile) != 0x20050300)/* version? */ - goto fail; - /* 0x08: file size, except for a few files that with a weird value */ - /* 0x0c: null */ - /* 0x10: file id? */ - /* 0x14: encryption key (different files with the same value encrypt the same) */ - - /* 0x1c: entry count */ - - /* ~0x20: entries start? */ - /* 0x40: num samples? */ - /* 0x44: loop start? */ - /* 0x50: channels */ - /* 0x54: sample rate */ - - /* 0x80: encrypted RIFF data */ - - - loop_flag = 0; - channel_count = 1; - - - /* build the VGMSTREAM */ - vgmstream = allocate_vgmstream(channel_count, loop_flag); - if (!vgmstream) goto fail; - - vgmstream->sample_rate = sample_rate; - vgmstream->num_samples = ...; - - vgmstream->meta_type = meta_SCD_SSCF; - vgmstream->coding_type = coding_...; - vgmstream->layout_type = layout_none; - - if (!vgmstream_open_stream(vgmstream,streamFile,start_offset)) - goto fail; - return vgmstream; - -fail: - close_vgmstream(vgmstream); - return NULL; -} -#endif diff --git a/Frameworks/vgmstream/vgmstream/src/meta/sscf.c b/Frameworks/vgmstream/vgmstream/src/meta/sscf.c new file mode 100644 index 000000000..ce1ef2d40 --- /dev/null +++ b/Frameworks/vgmstream/vgmstream/src/meta/sscf.c @@ -0,0 +1,114 @@ +#include "meta.h" +#include "../coding/coding.h" + +/* SSCF - Square-Enix games, older version of .scd [Crisis Core -Final Fantasy VII- (PSP), Dissidia 012 (PSP)] */ +VGMSTREAM* init_vgmstream_sscf(STREAMFILE* sf) { + VGMSTREAM* vgmstream = NULL; + uint32_t start_offset, meta_offset, stream_offset, stream_size; + int loop_flag, channels, sample_rate; + int total_subsongs, target_subsong = sf->stream_index; + + + /* checks */ + if (!is_id32be(0x00,sf, "SSCF")) + goto fail; + if (!check_extensions(sf, "scd")) + goto fail; + + if (!(read_u32be(0x04,sf) == 0x02070210 || /* version? [Crisis Core (PSP)] */ + read_u32be(0x04,sf) == 0x10020702)) /* inverted version? [Dissidia (PSP)] */ + goto fail; + /* 0x08: file size, except for a few files that with a weird value */ + /* 0x10: file id? */ + + + /* find total subsongs (entries can be dummy) and target subsong */ + { + int i,j, is_dupe; + int entries = read_s32le(0x0c,sf); + uint32_t stream_offsets[0x800]; + + if (entries > 0x800) /* meh */ + goto fail; + + + if (target_subsong == 0) target_subsong = 1; + + meta_offset = 0; + total_subsongs = 0; + for (i = 0; i < entries; i++) { + uint32_t entry_offset = 0x20 + (0x20*i); + uint32_t entry_stream_offset; + + /* skip dummies */ + if (read_u32le(entry_offset+0x08,sf) == 0) /* size 0 */ + continue; + if (read_u16le(entry_offset+0x0c,sf) == 0) /* no sample rate */ + continue; + + /* skip repeated sounds */ + is_dupe = 0; + entry_stream_offset = read_u32le(entry_offset+0x04,sf); + for (j = 0; j < total_subsongs; j++) { + if (entry_stream_offset == stream_offsets[j]) { + is_dupe = 1; + break; + } + } + if (is_dupe) + continue; + stream_offsets[total_subsongs] = entry_stream_offset; + + /* ok */ + total_subsongs++; + if (total_subsongs == target_subsong) { + meta_offset = entry_offset; + } + } + + if (meta_offset == 0) + goto fail; + } + + + /* 0x00(2): config? usually 0x00/0x01 */ + /* 0x02(2): loop config */ //todo when 1 uses PS-ADPCM uses SPU loop flags to set start/end + stream_offset = read_u32le(meta_offset+0x04,sf); /* absolute */ + stream_size = read_u32le(meta_offset+0x08,sf); + sample_rate = read_u16le(meta_offset+0x0c,sf); + /* 0x0e: config? */ + /* 0x10: config? */ + /* 0x14: 0xCA5F or 0x5FCA */ + /* 0x18: config? */ + /* 0x1c: null / some id? */ + + loop_flag = 0; + channels = 1; + start_offset = stream_offset; + + + /* build the VGMSTREAM */ + vgmstream = allocate_vgmstream(channels, loop_flag); + if (!vgmstream) goto fail; + + vgmstream->sample_rate = sample_rate; + vgmstream->num_streams = total_subsongs; + vgmstream->stream_size = stream_size; + vgmstream->num_samples = ps_bytes_to_samples(stream_size, channels); + if (loop_flag) { + vgmstream->loop_start_sample = 0; + vgmstream->loop_end_sample = vgmstream->num_samples; + } + + vgmstream->meta_type = meta_SSCF; + vgmstream->coding_type = coding_PSX; + vgmstream->layout_type = layout_none; + + if (!vgmstream_open_stream(vgmstream,sf,start_offset)) + goto fail; + return vgmstream; + +fail: + close_vgmstream(vgmstream); + return NULL; +} diff --git a/Frameworks/vgmstream/vgmstream/src/meta/sscf_encrypted.c b/Frameworks/vgmstream/vgmstream/src/meta/sscf_encrypted.c new file mode 100644 index 000000000..43cb44c0c --- /dev/null +++ b/Frameworks/vgmstream/vgmstream/src/meta/sscf_encrypted.c @@ -0,0 +1,49 @@ +#include "meta.h" +#include "sscf_encrypted.h" + +/* SSCF - Square-Enix games, older version of .scd with encrypted data [Final Fantasy XI (360), PlayOnline Viewer (X360)] */ +VGMSTREAM* init_vgmstream_sscf_encrypted(STREAMFILE* sf) { + VGMSTREAM* vgmstream = NULL; + STREAMFILE* temp_sf = NULL; + uint32_t xorkey; + + + /* checks */ + if (!is_id32be(0x00,sf, "SSCF")) + goto fail; + if (!check_extensions(sf, "scd")) + goto fail; + + /* LE header even though X360 */ + /* 0x04: version? (0x0003xxxx)*/ + /* 0x08: file size, except for a few files that with a weird value */ + /* 0x0c: null */ + + /* 0x10: file id */ + xorkey = read_u32le(0x14,sf); + /* 0x18: null */ + /* 0x1c: always 1 */ + /* 0x20~0x40: null */ + + /* 0x40: num samples? */ + /* 0x48: loop start? */ + /* 0x50: channels */ + /* 0x54: sample rate */ + /* rest: null */ + + /* 0x80: encrypted RIFF data */ + + temp_sf = setup_sscf_streamfile(sf, xorkey); + if (!temp_sf) goto fail; + + vgmstream = init_vgmstream_xma(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/Frameworks/vgmstream/vgmstream/src/meta/sscf_encrypted.h b/Frameworks/vgmstream/vgmstream/src/meta/sscf_encrypted.h new file mode 100644 index 000000000..c9e7e723a --- /dev/null +++ b/Frameworks/vgmstream/vgmstream/src/meta/sscf_encrypted.h @@ -0,0 +1,46 @@ +#ifndef _SSCF_ENCRYPTED_H_ +#define _SSCF_ENCRYPTED_H_ +#include "../streamfile.h" + +typedef struct { + uint8_t key[0x800]; +} sscf_io; + + +static size_t sscf_io_read(STREAMFILE* sf, uint8_t* dest, off_t offset, size_t length, sscf_io* io) { + int i; + size_t bytes = read_streamfile(dest, offset, length, sf); + + for (i = 0; i < bytes; i++) { + dest[i] ^= io->key[(offset + i) % sizeof(io->key)]; + } + + return bytes; +} + +/* Decrypts SSCF streams */ +static STREAMFILE* setup_sscf_streamfile(STREAMFILE* sf, uint32_t xorkey) { + STREAMFILE *new_sf = NULL; + sscf_io io = {0}; + int i; + uint32_t stream_offset = 0x80; + uint32_t stream_size = get_streamfile_size(sf) - stream_offset; + + /* setup key */ + xorkey = (xorkey >> 21) | (xorkey << 11); + for (i = 0; i < sizeof(io.key); i += 4) { + put_u32le(io.key + i, xorkey); + xorkey += (xorkey >> 29) | (xorkey << 3); + } + + new_sf = open_wrap_streamfile(sf); + new_sf = open_io_streamfile_f(new_sf, &io, sizeof(sscf_io), sscf_io_read, NULL); + if (new_sf) { + stream_size = read_u32le(0x84, new_sf) + 0x08; /* RIFF size */ + } + new_sf = open_clamp_streamfile_f(new_sf, stream_offset, stream_size); + new_sf = open_fakename_streamfile_f(new_sf, NULL, "xma"); + return new_sf; +} + +#endif diff --git a/Frameworks/vgmstream/vgmstream/src/meta/txth.c b/Frameworks/vgmstream/vgmstream/src/meta/txth.c index c40714c98..ca0f2a9ea 100644 --- a/Frameworks/vgmstream/vgmstream/src/meta/txth.c +++ b/Frameworks/vgmstream/vgmstream/src/meta/txth.c @@ -121,7 +121,7 @@ typedef struct { int subfile_set; uint32_t subfile_offset; uint32_t subfile_size; - char subfile_extension[32]; + char subfile_extension[16]; uint32_t chunk_number; uint32_t chunk_start; @@ -130,8 +130,9 @@ typedef struct { uint32_t chunk_header_size; uint32_t chunk_data_size; uint32_t chunk_value; - uint32_t chunk_size_offset; - uint32_t chunk_be; + uint32_t chunk_bsize_offset; + uint32_t chunk_dsize_offset; + uint32_t chunk_big_endian; int chunk_start_set; int chunk_size_set; int chunk_count_set; @@ -820,9 +821,9 @@ static void set_body_chunk(txth_header* txth) { //todo maybe should only be done once, or have some count to retrigger to simplify? if (!txth->chunk_start_set || !txth->chunk_size_set || !txth->chunk_count_set) return; - if ((txth->chunk_size == 0 && ! txth->chunk_size_offset) || - txth->chunk_start > txth->data_size || - txth->chunk_count == 0) + if (txth->chunk_size == 0 && !(txth->chunk_bsize_offset || txth->chunk_dsize_offset)) + return; + if (txth->chunk_start > txth->data_size || txth->chunk_count == 0) return; if (!txth->sf_body) return; @@ -843,8 +844,9 @@ static void set_body_chunk(txth_header* txth) { cfg.chunk_data_size = txth->chunk_data_size; cfg.chunk_value = txth->chunk_value; - cfg.chunk_size_offset = txth->chunk_size_offset; - cfg.chunk_be = txth->chunk_be; + cfg.chunk_bsize_offset = txth->chunk_bsize_offset; + cfg.chunk_dsize_offset = txth->chunk_dsize_offset; + cfg.chunk_be = txth->chunk_big_endian; cfg.chunk_start = txth->chunk_start; cfg.chunk_size = txth->chunk_size; @@ -877,7 +879,7 @@ static void set_body_chunk(txth_header* txth) { static int parse_keyval(STREAMFILE* sf, txth_header* txth, const char* key, char* val); static int parse_num(STREAMFILE* sf, txth_header* txth, const char* val, uint32_t* out_value); -static int parse_string(STREAMFILE* sf, txth_header* txth, const char* val, char* str); +static int parse_string(STREAMFILE* sf, txth_header* txth, const char* val, char* str, int str_len); static int parse_coef_table(STREAMFILE* sf, txth_header* txth, const char* val, uint8_t* out_value, size_t out_size); static int parse_name_table(txth_header* txth, char* val); static int parse_multi_txth(txth_header* txth, char* val); @@ -1328,7 +1330,7 @@ static int parse_keyval(STREAMFILE* sf_, txth_header* txth, const char* key, cha txth->subfile_set = 1; } else if (is_string(key,"subfile_extension")) { - if (!parse_string(txth->sf_head,txth,val, txth->subfile_extension)) goto fail; + if (!parse_string(txth->sf_head,txth,val, txth->subfile_extension, sizeof(txth->subfile_extension))) goto fail; txth->subfile_set = 1; } @@ -1442,10 +1444,15 @@ static int parse_keyval(STREAMFILE* sf_, txth_header* txth, const char* key, cha if (!parse_num(txth->sf_head,txth,val, &txth->chunk_value)) goto fail; } else if (is_string(key,"chunk_size_offset")) { - if (!parse_num(txth->sf_head,txth,val, &txth->chunk_size_offset)) goto fail; + if (!parse_num(txth->sf_head,txth,val, &txth->chunk_bsize_offset)) goto fail; + txth->chunk_size_set = 1; + } + else if (is_string(key,"chunk_data_size_offset")) { + if (!parse_num(txth->sf_head,txth,val, &txth->chunk_dsize_offset)) goto fail; + txth->chunk_size_set = 1; } else if (is_string(key,"chunk_endianness")) { - if (!parse_endianness(txth, val, &txth->chunk_be, NULL)) goto fail; + if (!parse_endianness(txth, val, &txth->chunk_big_endian, NULL)) goto fail; } @@ -1615,9 +1622,13 @@ static int is_string_match(const char* text, const char* pattern) { /* either all chars consumed/matched and both pos point to null, or one didn't so string didn't match */ return text[t_pos] == '\0' && pattern[p_pos] == '\0'; } -static int parse_string(STREAMFILE* sf, txth_header* txth, const char* val, char* str) { + +static int parse_string(STREAMFILE* sf, txth_header* txth, const char* val, char* str, int str_len) { int n = 0; + if (strlen(val) >= str_len) + return 0; + /* read string without trailing spaces */ if (sscanf(val, " %s%n[^ ]%n", str, &n, &n) != 1) return 0; @@ -2001,7 +2012,8 @@ static int parse_num(STREAMFILE* sf, txth_header* txth, const char* val, uint32_ else if ((n = is_string_field(val,"chunk_count"))) value = txth->chunk_count; else if ((n = is_string_field(val,"chunk_start"))) value = txth->chunk_start; else if ((n = is_string_field(val,"chunk_size"))) value = txth->chunk_size; - else if ((n = is_string_field(val,"chunk_size_offset"))) value = txth->chunk_size_offset; + else if ((n = is_string_field(val,"chunk_size_offset"))) value = txth->chunk_bsize_offset; + else if ((n = is_string_field(val,"chunk_data_size_offset")))value = txth->chunk_dsize_offset; else if ((n = is_string_field(val,"chunk_number"))) value = txth->chunk_number; else if ((n = is_string_field(val,"chunk_data_size"))) value = txth->chunk_data_size; else if ((n = is_string_field(val,"chunk_header_size"))) value = txth->chunk_header_size; diff --git a/Frameworks/vgmstream/vgmstream/src/meta/txth_streamfile.h b/Frameworks/vgmstream/vgmstream/src/meta/txth_streamfile.h index 322c359a4..7816ea3bb 100644 --- a/Frameworks/vgmstream/vgmstream/src/meta/txth_streamfile.h +++ b/Frameworks/vgmstream/vgmstream/src/meta/txth_streamfile.h @@ -14,7 +14,8 @@ typedef struct { int chunk_number; uint32_t chunk_value; - uint32_t chunk_size_offset; + uint32_t chunk_bsize_offset; + uint32_t chunk_dsize_offset; int chunk_be; } txth_io_config_data; @@ -71,11 +72,26 @@ static size_t txth_io_read(STREAMFILE* sf, uint8_t* dest, off_t offset, size_t l } /* chunk size reader (overwrites the above) */ - if (data->cfg.chunk_header_size && data->cfg.chunk_size_offset) { + if (data->cfg.chunk_header_size && (data->cfg.chunk_bsize_offset || data->cfg.chunk_dsize_offset)) { read_u32_t read_u32 = data->cfg.chunk_be ? read_u32be : read_u32le; - data->block_size = read_u32(data->physical_offset + data->cfg.chunk_size_offset, sf); - data->data_size = data->block_size - data->cfg.chunk_header_size; + data->block_size = 0; + data->data_size = 0; + + if (data->cfg.chunk_bsize_offset) + data->block_size = read_u32(data->physical_offset + data->cfg.chunk_bsize_offset, sf); + if (data->cfg.chunk_dsize_offset) + data->data_size = read_u32(data->physical_offset + data->cfg.chunk_dsize_offset, sf); + + if (!data->block_size && !data->data_size) { /* bad read? */ + data->block_size = data->cfg.chunk_header_size; + data->data_size = data->cfg.chunk_header_size; + } + + if (!data->block_size) + data->block_size = data->data_size + data->cfg.chunk_header_size; + if (!data->data_size) + data->data_size = data->block_size - data->cfg.chunk_header_size; /* may be 0 */ /* skip chunk if doesn't match expected header value */ if (data->cfg.chunk_value) { diff --git a/Frameworks/vgmstream/vgmstream/src/meta/ubi_sb.c b/Frameworks/vgmstream/vgmstream/src/meta/ubi_sb.c index deb09b496..2e6d7f8fb 100644 --- a/Frameworks/vgmstream/vgmstream/src/meta/ubi_sb.c +++ b/Frameworks/vgmstream/vgmstream/src/meta/ubi_sb.c @@ -1530,7 +1530,7 @@ static VGMSTREAM* init_vgmstream_ubi_sb_silence(ubi_sb_header* sb) { sample_rate = sb->sample_rate; if (sample_rate == 0) sample_rate = 48000; - num_samples = sb->duration * sample_rate; + num_samples = (int)(sb->duration * sample_rate); /* init the VGMSTREAM */ @@ -3563,6 +3563,18 @@ static int config_sb_version(ubi_sb_header* sb, STREAMFILE* sf) { return 1; } + /* Prince of Persia: Warrior Within (Demo)(2004)(Xbox)-bank */ + if (sb->version == 0x00100000 && sb->platform == UBI_XBOX) { + config_sb_entry(sb, 0x68, 0x90); + + config_sb_audio_fs(sb, 0x24, 0x28, 0x40); + config_sb_audio_hs(sb, 0x60, 0x58, 0x44, 0x4c, 0x68, 0x64); + sb->cfg.audio_has_internal_names = 1; + + config_sb_sequence(sb, 0x28, 0x14); + return 1; + } + /* two configs with same id; try to autodetect or use project file as identifier */ if (sb->version == 0x00120006 && sb->platform == UBI_PC) { if (test_version_sb(sb, sf, 0x6c, 0xa4) || check_project_file(sf, "gamesnd_myst4.sp0", 1)) { diff --git a/Frameworks/vgmstream/vgmstream/src/meta/wwise.c b/Frameworks/vgmstream/vgmstream/src/meta/wwise.c index 7440a357c..09f44d6e0 100644 --- a/Frameworks/vgmstream/vgmstream/src/meta/wwise.c +++ b/Frameworks/vgmstream/vgmstream/src/meta/wwise.c @@ -533,16 +533,18 @@ VGMSTREAM* init_vgmstream_wwise_bnk(STREAMFILE* sf, int* p_prefetch) { } case OPUSWW: { /* updated Opus [Assassin's Creed Valhalla (PC)] */ - int mapping; + int i, mapping; opus_config cfg = {0}; if (ww.block_size != 0 || ww.bits_per_sample != 0) goto fail; if (!ww.seek_offset) goto fail; - if (ww.channels > 8) goto fail; /* mapping not defined */ + if (ww.channels > 255) goto fail; /* opus limit */ cfg.channels = ww.channels; cfg.table_offset = ww.seek_offset; + vgmstream->sample_rate = 48000; /* fixed in AK's code */ + /* extra: size 0x10 (though last 2 fields are beyond, AK plz) */ /* 0x12: samples per frame */ vgmstream->num_samples = read_s32(ww.fmt_offset + 0x18, sf); @@ -550,6 +552,7 @@ VGMSTREAM* init_vgmstream_wwise_bnk(STREAMFILE* sf, int* p_prefetch) { cfg.skip = read_u16(ww.fmt_offset + 0x20, sf); /* 0x22: codec version */ mapping = read_u8(ww.fmt_offset + 0x23, sf); + if (mapping == 1 && ww.channels > 8) goto fail; /* mapping not defined */ if (read_u8(ww.fmt_offset + 0x22, sf) != 1) goto fail; @@ -561,9 +564,9 @@ VGMSTREAM* init_vgmstream_wwise_bnk(STREAMFILE* sf, int* p_prefetch) { ww.data_size = ww.file_size - start_offset; } - /* AK does some wonky implicit config for multichannel */ - if (mapping == 1 && ww.channel_type == 1) { /* only allowed values ATM, set when >2ch */ - static const int8_t mapping_matrix[8][8] = { + /* AK does some wonky implicit config for multichannel (only accepted channel type is 1) */ + if (ww.channel_type == 1 && mapping == 1) { + static const int8_t mapping_matrix[8][8] = { /* (DeinterleaveAndRemap)*/ { 0, 0, 0, 0, 0, 0, 0, 0, }, { 0, 1, 0, 0, 0, 0, 0, 0, }, { 0, 2, 1, 0, 0, 0, 0, 0, }, @@ -573,9 +576,11 @@ VGMSTREAM* init_vgmstream_wwise_bnk(STREAMFILE* sf, int* p_prefetch) { { 0, 6, 1, 2, 3, 4, 5, 0, }, { 0, 6, 1, 2, 3, 4, 5, 7, }, }; - int i; - /* find coupled OPUS streams (internal streams using 2ch) */ + if (ww.channels > 8) + goto fail; /* matrix limit */ + + /* find coupled (stereo) OPUS streams (simplification of ChannelConfigToMapping) */ switch(ww.channel_layout) { case mapping_7POINT1_surround: cfg.coupled_count = 3; break; /* 2ch+2ch+2ch+1ch+1ch, 5 streams */ case mapping_5POINT1_surround: /* 2ch+2ch+1ch+1ch, 4 streams */ @@ -589,11 +594,29 @@ VGMSTREAM* init_vgmstream_wwise_bnk(STREAMFILE* sf, int* p_prefetch) { /* total number internal OPUS streams (should be >0) */ cfg.stream_count = ww.channels - cfg.coupled_count; - /* channel assignments */ + /* channel order */ for (i = 0; i < ww.channels; i++) { cfg.channel_mapping[i] = mapping_matrix[ww.channels - 1][i]; } } + else if (ww.channel_type == 1 && mapping == 255) { /* Overwatch 2 (PC) */ + + /* only seen 12ch, but seems to be what ChannelConfigToMapping would output with > 8 */ + cfg.coupled_count = 0; + + cfg.stream_count = ww.channels - cfg.coupled_count; + + //TODO: mapping seems to be 0x2d63f / FL FR FC LFE BL BR SL SR TFL TFR TBL TBR + // while output order seems to swap FC and LFE? (not set in passed channel mapping but reordered later) + for (i = 0; i < ww.channels; i++) { + cfg.channel_mapping[i] = i; + } + } + else { + /* mapping 0: standard opus (implicit mono/stereo) */ + if (ww.channels > 2) + goto fail; + } /* Wwise Opus saves all frame sizes in the seek table */ vgmstream->codec_data = init_ffmpeg_wwise_opus(sf, ww.data_offset, ww.data_size, &cfg); diff --git a/Frameworks/vgmstream/vgmstream/src/util/text_reader.c b/Frameworks/vgmstream/vgmstream/src/util/text_reader.c index 294762fcc..c359ae959 100644 --- a/Frameworks/vgmstream/vgmstream/src/util/text_reader.c +++ b/Frameworks/vgmstream/vgmstream/src/util/text_reader.c @@ -1,187 +1,187 @@ -#include -#include "text_reader.h" -#include "log.h" - - -/* convenience function to init the above struct */ -int text_reader_init(text_reader_t* tr, uint8_t* buf, int buf_size, STREAMFILE* sf, uint32_t offset, uint32_t max_offset) { - memset(tr, 0, sizeof(text_reader_t)); - - if (buf_size <= 1 || !buf || !sf) - return 0; - - tr->buf = buf; - tr->buf_size = buf_size; - tr->sf = sf; - tr->offset = offset; - - if (!max_offset) - max_offset = get_streamfile_size(sf); - tr->max_offset = max_offset; - - return 1; -} - - -/* reads more data into buf and adjust values */ -static void prepare_buf(text_reader_t* tr) { - - /* since we may read N lines in the same buffer, move starting pos each call */ - tr->pos = tr->next_pos; - - /* not more data (but may still read lines so not an error) */ - if (tr->offset >= tr->max_offset) { - return; - } - - /* request more data */ - if (tr->pos >= tr->filled) { - tr->pos = 0; - tr->filled = 0; - } - - /* partially filled, move buffer */ - if (tr->pos > 0) { - int move_size = tr->filled - tr->pos; - - memmove(tr->buf, &tr->buf[tr->pos], move_size); /* memmove = may overlap */ - tr->filled -= tr->pos; /* now less filled */ - tr->pos = 0; - } - - /* has enough data */ - if (tr->filled >= tr->buf_size) { - return; - } - - /* read buf up to max */ - { - int bytes; - int read_size = tr->buf_size - tr->filled; - if (read_size + tr->offset > tr->max_offset) - read_size = tr->max_offset - tr->offset; - - if (read_size <= 0) { /* ??? */ - bytes = 0; - } - else { - if (tr->filled + read_size >= tr->buf_size) - read_size -= 1; /* always leave an extra byte for c-string null */ - - bytes = read_streamfile(tr->buf + tr->filled, tr->offset, read_size, tr->sf); - tr->offset += bytes; - tr->filled += bytes; - } - - /* maybe some internal issue, force EOF */ - if (bytes == 0) { - tr->offset = tr->max_offset; - } - - /* ensure no old data is used as valid (simplifies some checks during parse) */ - tr->buf[tr->filled] = '\0'; - } -} - -static void parse_buf(text_reader_t* tr) { - int i; - - tr->line = (char*)&tr->buf[tr->pos]; - tr->line_len = 0; - tr->line_ok = 0; - - /* detect EOF (this should only happen if no more data was loaded) */ - if (tr->pos == tr->filled) { - tr->line = NULL; - tr->line_ok = 1; - tr->line_len = 0; - return; - } - - /* assumes filled doesn't reach buf_size (to allow trailing \0 after filled) */ - for (i = tr->pos; i < tr->filled; i++) { - char c = (char)tr->buf[i]; - - if (c == '\0') { - i++; - break; /* not a valid file? (line_ok=0) */ - } - - if (c == '\r' && tr->buf[i+1] == '\n') { /* CRLF (0x0d0a) */ - /* i+1 may read past filled but it's pre-set to \0 */ - i += 2; //todo check that i < buf_size-1 - tr->line_ok = 1; - break; - } - else if (c == '\n') { /* LF (0x0a) */ - i++; - tr->line_ok = 1; - break; - } - else if (c == '\r') { /* CR (0x0d) */ - i++; - tr->line_ok = (i < tr->buf_size - 1); - /* if buf ends with a CR, next buf may start be a LF (single CRLF), so line is not ok near buf end - * (old Macs use single \r as lines, but using only that and reaching buf end should happen rarely) */ - break; - } - - tr->line_len++; - } - - /* when lines are small may read up to filled smaller than buf, with no more data */ - if (!tr->line_ok && i == tr->filled) - tr->line_ok = (tr->filled < tr->buf_size - 1); - - /* added after proper line (a \n) or after buf end, so we aren't changing valid data */ - tr->buf[tr->pos + tr->line_len] = '\0'; - tr->next_pos = i; -} - -int text_reader_get_line(text_reader_t* tr, char** p_line) { - - if (!tr->buf) /* no init */ - return 0; - - /* how it works: - * - fills buffer up to max or buf_len, from pos 0 - * - counts from 0 to next '\n' or EOF - * - nulls \n or after EOF to make a proper c-string - * - returns from string from pos 0 to len - * - on next call rather than re-reading continues from pos N (after \n) - * - a buf will likely contain multiple lines - * - if read chars reach buf_end (no proper line found): - * - pos = 0: buf isn't big enough, error - * - pos > 0: move data to pos=0, fill rest of buf, fill rest of buf - * - * ex. - * - parse buf: read chunk full [aaaaa\nbbbb] (pos = 0) - * - get line: returns "aaaaa\0" (next_pos points to first 'b') - * - get line: from 'b', but reaches buf end before \n or EOF: must readjust - * - parse buf: move chunk part [bbbb*******] ('b' to beginning, * is garbage) - * - parse buf: read chunk part [bbbbbb\ncc_] (reaches EOF) - * - get line: returns "bbbbbb\0" (pos points to first c) - * - get line: returns "cc\0" - * - get line: returns NULL (reached EOF, no more bytes) - * - (there is an implicit \0 reserved in buf) - * - * ex. - * - start: read chunk [aaaaaaaaaaa] - * - get line: reaches buf end, but didn't reach EOF nor \n: error, can't store line - */ - - prepare_buf(tr); /* may not do anything */ - parse_buf(tr); /* next line */ - - /* if we are reading a partial line there may be more data */ - if (!tr->line_ok && tr->pos > 0) { - prepare_buf(tr); - parse_buf(tr); /* could continue from prev parse but makes logic more complex for little gain */ - } - - /* always output line even if truncated */ - if (p_line) *p_line = tr->line; - return !tr->line_ok ? - -(tr->line_len + 1) : /* -0 also is possible, force -1 */ - tr->line_len; -} +#include +#include "text_reader.h" +#include "log.h" + + +/* convenience function to init the above struct */ +int text_reader_init(text_reader_t* tr, uint8_t* buf, int buf_size, STREAMFILE* sf, uint32_t offset, uint32_t max_offset) { + memset(tr, 0, sizeof(text_reader_t)); + + if (buf_size <= 1 || !buf || !sf) + return 0; + + tr->buf = buf; + tr->buf_size = buf_size; + tr->sf = sf; + tr->offset = offset; + + if (!max_offset) + max_offset = get_streamfile_size(sf); + tr->max_offset = max_offset; + + return 1; +} + + +/* reads more data into buf and adjust values */ +static void prepare_buf(text_reader_t* tr) { + + /* since we may read N lines in the same buffer, move starting pos each call */ + tr->pos = tr->next_pos; + + /* not more data (but may still read lines so not an error) */ + if (tr->offset >= tr->max_offset) { + return; + } + + /* request more data */ + if (tr->pos >= tr->filled) { + tr->pos = 0; + tr->filled = 0; + } + + /* partially filled, move buffer */ + if (tr->pos > 0) { + int move_size = tr->filled - tr->pos; + + memmove(tr->buf, &tr->buf[tr->pos], move_size); /* memmove = may overlap */ + tr->filled -= tr->pos; /* now less filled */ + tr->pos = 0; + } + + /* has enough data */ + if (tr->filled >= tr->buf_size) { + return; + } + + /* read buf up to max */ + { + int bytes; + int read_size = tr->buf_size - tr->filled; + if (read_size + tr->offset > tr->max_offset) + read_size = tr->max_offset - tr->offset; + + if (read_size <= 0) { /* ??? */ + bytes = 0; + } + else { + if (tr->filled + read_size >= tr->buf_size) + read_size -= 1; /* always leave an extra byte for c-string null */ + + bytes = read_streamfile(tr->buf + tr->filled, tr->offset, read_size, tr->sf); + tr->offset += bytes; + tr->filled += bytes; + } + + /* maybe some internal issue, force EOF */ + if (bytes == 0) { + tr->offset = tr->max_offset; + } + + /* ensure no old data is used as valid (simplifies some checks during parse) */ + tr->buf[tr->filled] = '\0'; + } +} + +static void parse_buf(text_reader_t* tr) { + int i; + + tr->line = (char*)&tr->buf[tr->pos]; + tr->line_len = 0; + tr->line_ok = 0; + + /* detect EOF (this should only happen if no more data was loaded) */ + if (tr->pos == tr->filled) { + tr->line = NULL; + tr->line_ok = 1; + tr->line_len = 0; + return; + } + + /* assumes filled doesn't reach buf_size (to allow trailing \0 after filled) */ + for (i = tr->pos; i < tr->filled; i++) { + char c = (char)tr->buf[i]; + + if (c == '\0') { + i++; + break; /* not a valid file? (line_ok=0) */ + } + + if (c == '\r' && tr->buf[i+1] == '\n') { /* CRLF (0x0d0a) */ + /* i+1 may read past filled but it's pre-set to \0 */ + i += 2; //todo check that i < buf_size-1 + tr->line_ok = 1; + break; + } + else if (c == '\n') { /* LF (0x0a) */ + i++; + tr->line_ok = 1; + break; + } + else if (c == '\r') { /* CR (0x0d) */ + i++; + tr->line_ok = (i < tr->buf_size - 1); + /* if buf ends with a CR, next buf may start be a LF (single CRLF), so line is not ok near buf end + * (old Macs use single \r as lines, but using only that and reaching buf end should happen rarely) */ + break; + } + + tr->line_len++; + } + + /* when lines are small may read up to filled smaller than buf, with no more data */ + if (!tr->line_ok && i == tr->filled) + tr->line_ok = (tr->filled < tr->buf_size - 1); + + /* added after proper line (a \n) or after buf end, so we aren't changing valid data */ + tr->buf[tr->pos + tr->line_len] = '\0'; + tr->next_pos = i; +} + +int text_reader_get_line(text_reader_t* tr, char** p_line) { + + if (!tr->buf) /* no init */ + return 0; + + /* how it works: + * - fills buffer up to max or buf_len, from pos 0 + * - counts from 0 to next '\n' or EOF + * - nulls \n or after EOF to make a proper c-string + * - returns from string from pos 0 to len + * - on next call rather than re-reading continues from pos N (after \n) + * - a buf will likely contain multiple lines + * - if read chars reach buf_end (no proper line found): + * - pos = 0: buf isn't big enough, error + * - pos > 0: move data to pos=0, fill rest of buf, fill rest of buf + * + * ex. + * - parse buf: read chunk full [aaaaa\nbbbb] (pos = 0) + * - get line: returns "aaaaa\0" (next_pos points to first 'b') + * - get line: from 'b', but reaches buf end before \n or EOF: must readjust + * - parse buf: move chunk part [bbbb*******] ('b' to beginning, * is garbage) + * - parse buf: read chunk part [bbbbbb\ncc_] (reaches EOF) + * - get line: returns "bbbbbb\0" (pos points to first c) + * - get line: returns "cc\0" + * - get line: returns NULL (reached EOF, no more bytes) + * - (there is an implicit \0 reserved in buf) + * + * ex. + * - start: read chunk [aaaaaaaaaaa] + * - get line: reaches buf end, but didn't reach EOF nor \n: error, can't store line + */ + + prepare_buf(tr); /* may not do anything */ + parse_buf(tr); /* next line */ + + /* if we are reading a partial line there may be more data */ + if (!tr->line_ok && tr->pos > 0) { + prepare_buf(tr); + parse_buf(tr); /* could continue from prev parse but makes logic more complex for little gain */ + } + + /* always output line even if truncated */ + if (p_line) *p_line = tr->line; + return !tr->line_ok ? + -(tr->line_len + 1) : /* -0 also is possible, force -1 */ + tr->line_len; +} diff --git a/Frameworks/vgmstream/vgmstream/src/vgmstream.c b/Frameworks/vgmstream/vgmstream/src/vgmstream.c index 723b50d1f..3121e0a41 100644 --- a/Frameworks/vgmstream/vgmstream/src/vgmstream.c +++ b/Frameworks/vgmstream/vgmstream/src/vgmstream.c @@ -97,7 +97,6 @@ VGMSTREAM* (*init_vgmstream_functions[])(STREAMFILE* sf) = { init_vgmstream_ps2_kces, init_vgmstream_hxd, init_vgmstream_vsv, - init_vgmstream_scd_pcm, init_vgmstream_ps2_pcm, init_vgmstream_ps2_rkv, init_vgmstream_ps2_vas, @@ -385,7 +384,7 @@ VGMSTREAM* (*init_vgmstream_functions[])(STREAMFILE* sf) = { init_vgmstream_bnk_sony, init_vgmstream_nus3bank, init_vgmstream_nus3bank_encrypted, - init_vgmstream_scd_sscf, + init_vgmstream_sscf, init_vgmstream_dsp_sps_n1, init_vgmstream_dsp_itl_ch, init_vgmstream_a2m, @@ -526,8 +525,10 @@ VGMSTREAM* (*init_vgmstream_functions[])(STREAMFILE* sf) = { init_vgmstream_sndz, init_vgmstream_vab, init_vgmstream_bigrp, + init_vgmstream_sscf_encrypted, /* lower priority metas (no clean header identity, somewhat ambiguous, or need extension/companion file to identify) */ + init_vgmstream_scd_pcm, init_vgmstream_agsc, init_vgmstream_rsf, init_vgmstream_ps2_wmus, diff --git a/Frameworks/vgmstream/vgmstream/src/vgmstream.h b/Frameworks/vgmstream/vgmstream/src/vgmstream.h index 27c5361d7..3d155e154 100644 --- a/Frameworks/vgmstream/vgmstream/src/vgmstream.h +++ b/Frameworks/vgmstream/vgmstream/src/vgmstream.h @@ -117,7 +117,7 @@ typedef enum { coding_IMA_int, /* IMA ADPCM (mono/interleave, low nibble first) */ coding_DVI_IMA, /* DVI IMA ADPCM (stereo or mono, high nibble first) */ coding_DVI_IMA_int, /* DVI IMA ADPCM (mono/interleave, high nibble first) */ - coding_3DS_IMA, /* 3DS IMA ADPCM */ + coding_NW_IMA, coding_SNDS_IMA, /* Heavy Iron Studios .snds IMA ADPCM */ coding_QD_IMA, coding_WV6_IMA, /* Gorilla Systems WV6 4-bit IMA ADPCM */ @@ -674,7 +674,7 @@ typedef enum { meta_WAVEBATCH, /* Firebrand Games */ meta_HD3_BD3, /* Sony PS3 bank */ meta_BNK_SONY, /* Sony Scream Tool bank */ - meta_SCD_SSCF, /* Square Enix SCD old version */ + meta_SSCF, meta_DSP_VAG, /* Penny-Punching Princess (Switch) sfx */ meta_DSP_ITL, /* Charinko Hero (GC) */ meta_A2M, /* Scooby-Doo! Unmasked (PS2) */ diff --git a/Info.plist.template b/Info.plist.template index e82d2ccef..f1d46330e 100644 --- a/Info.plist.template +++ b/Info.plist.template @@ -362,6 +362,7 @@ 8 800 9tav + a3c aa3 aax abc @@ -384,7 +385,6 @@ ahx ahv ai - aif-loop aifc aix akb @@ -940,6 +940,7 @@ xen xma xma2 + xms xmu xmv xnb