From 21a4afdadd07cf4afed87ffac29937ac4e75051b Mon Sep 17 00:00:00 2001 From: bnnm Date: Sat, 1 Aug 2020 17:04:55 +0200 Subject: [PATCH] Add .bsf [Reign of Fire ((PS2/GC/Xbox)] --- src/libvgmstream.vcproj | 12 ++-- src/libvgmstream.vcxproj | 1 + src/libvgmstream.vcxproj.filters | 3 + src/meta/bsf.c | 97 ++++++++++++++++++++++++++++++++ src/meta/meta.h | 2 + src/vgmstream.c | 1 + 6 files changed, 112 insertions(+), 4 deletions(-) create mode 100644 src/meta/bsf.c diff --git a/src/libvgmstream.vcproj b/src/libvgmstream.vcproj index fdefc4f4..fbb57731 100644 --- a/src/libvgmstream.vcproj +++ b/src/libvgmstream.vcproj @@ -596,10 +596,14 @@ RelativePath=".\meta\brstm.c" > - - + + + + diff --git a/src/libvgmstream.vcxproj b/src/libvgmstream.vcxproj index 3ceec39c..08fb7027 100644 --- a/src/libvgmstream.vcxproj +++ b/src/libvgmstream.vcxproj @@ -300,6 +300,7 @@ + diff --git a/src/libvgmstream.vcxproj.filters b/src/libvgmstream.vcxproj.filters index 1cd1c5c3..ee57706a 100644 --- a/src/libvgmstream.vcxproj.filters +++ b/src/libvgmstream.vcxproj.filters @@ -412,6 +412,9 @@ meta\Source Files + + meta\Source Files + meta\Source Files diff --git a/src/meta/bsf.c b/src/meta/bsf.c new file mode 100644 index 00000000..7e2cc22d --- /dev/null +++ b/src/meta/bsf.c @@ -0,0 +1,97 @@ +#include "meta.h" +#include "../coding/coding.h" + + +/* .bsf - from Kuju games [Reign of Fire ((PS2/GC/Xbox)] */ +VGMSTREAM* init_vgmstream_bsf(STREAMFILE* sf) { + VGMSTREAM* vgmstream = NULL; + STREAMFILE* temp_sf = NULL; + uint32_t subfile_type; + off_t subfile_name; + off_t subfile_offset; + size_t subfile_size; + int total_subsongs, target_subsong = sf->stream_index; + + + /* checks */ + if (!check_extensions(sf,"bsf")) + goto fail; + if (read_u32le(0x00,sf) != 0x42534648) /* "BSFH" (notice chunks are LE even on GC) */ + goto fail; + + total_subsongs = read_u32le(0x08,sf); + if (target_subsong == 0) target_subsong = 1; + if (target_subsong < 0 || target_subsong > total_subsongs || total_subsongs < 1) goto fail; + + /* dumb container of other formats */ + { + int i; + off_t offset = 0x08 + read_u32le(0x04,sf); /* 0x04: chunk size */ + + subfile_type = 0; + for (i = 0; i < total_subsongs; i++) { + /* subsong header "xxxH" */ + //uint32_t head_type = read_u32le(offset + 0x00,sf); + uint32_t head_size = read_u32le(offset + 0x04,sf); + /* 0x08: name + * 0x28: audio config? */ + /* subsong data "xxxD" */ + uint32_t data_type = read_u32le(offset + 0x08 + head_size + 0x00,sf); + uint32_t data_size = read_u32le(offset + 0x08 + head_size + 0x04,sf); + + if (i + 1 == target_subsong) { + subfile_name = offset + 0x08; + subfile_type = data_type; + subfile_size = data_size; + subfile_offset = offset + 0x08 + head_size + 0x08; + break; + } + + offset += 0x08 + head_size + 0x08 + data_size; + } + + if (subfile_type == 0) + goto fail; + } + + + switch(subfile_type) { + case 0x44535044: /* "DSPD" */ + temp_sf = setup_subfile_streamfile(sf, subfile_offset, subfile_size, "dsp"); + if (!temp_sf) goto fail; + + vgmstream = init_vgmstream_ngc_dsp_std(temp_sf); + if (!vgmstream) goto fail; + break; + + case 0x56414744: /* "VAGD" */ + temp_sf = setup_subfile_streamfile(sf, subfile_offset, subfile_size, "vag"); + if (!temp_sf) goto fail; + + vgmstream = init_vgmstream_vag(temp_sf); + if (!vgmstream) goto fail; + break; + + case 0x57415644: /* "WAVD" */ + temp_sf = setup_subfile_streamfile(sf, subfile_offset, subfile_size, "wav"); + if (!temp_sf) goto fail; + + vgmstream = init_vgmstream_riff(temp_sf); + if (!vgmstream) goto fail; + break; + + default: + goto fail; + } + + vgmstream->num_streams = total_subsongs; + read_string(vgmstream->stream_name, 0x20, subfile_name, sf); + + close_streamfile(temp_sf); + return vgmstream; + +fail: + close_streamfile(temp_sf); + close_vgmstream(vgmstream); + return NULL; +} diff --git a/src/meta/meta.h b/src/meta/meta.h index 6da0a01f..25e0387e 100644 --- a/src/meta/meta.h +++ b/src/meta/meta.h @@ -915,4 +915,6 @@ VGMSTREAM* init_vgmstream_zwv(STREAMFILE* sf); VGMSTREAM* init_vgmstream_dsb(STREAMFILE* sf); +VGMSTREAM* init_vgmstream_bsf(STREAMFILE* sf); + #endif /*_META_H*/ diff --git a/src/vgmstream.c b/src/vgmstream.c index 4b3c88e5..ab743e61 100644 --- a/src/vgmstream.c +++ b/src/vgmstream.c @@ -507,6 +507,7 @@ VGMSTREAM* (*init_vgmstream_functions[])(STREAMFILE* sf) = { init_vgmstream_adp_konami, init_vgmstream_zwv, init_vgmstream_dsb, + init_vgmstream_bsf, /* lowest priority metas (should go after all metas, and TXTH should go before raw formats) */ init_vgmstream_txth, /* proper parsers should supersede TXTH, once added */