Add SFH .at3 wrapper [Devil May Cry 4 Demo (PS3), Jojo BA HD (PS3)]

This commit is contained in:
bnnm 2019-03-10 00:59:59 +01:00
parent 7f3c09e533
commit 97c9df30aa
7 changed files with 201 additions and 4 deletions

View File

@ -268,6 +268,10 @@
RelativePath=".\meta\vsv_streamfile.h"
>
</File>
<File
RelativePath=".\meta\sfh_streamfile.h"
>
</File>
<File
RelativePath=".\meta\sqex_scd_streamfile.h"
>
@ -1390,10 +1394,14 @@
RelativePath=".\meta\sdt.c"
>
</File>
<File
RelativePath=".\meta\seg.c"
>
</File>
<File
RelativePath=".\meta\seg.c"
>
</File>
<File
RelativePath=".\meta\sfh.c"
>
</File>
<File
RelativePath=".\meta\sfl.c"
>

View File

@ -109,6 +109,7 @@
<ClInclude Include="meta\ppst_streamfile.h" />
<ClInclude Include="meta\vsv_streamfile.h" />
<ClInclude Include="meta\opus_interleave_streamfile.h" />
<ClInclude Include="meta\sfh_streamfile.h" />
<ClInclude Include="meta\sqex_scd_streamfile.h" />
<ClInclude Include="meta\ubi_bao_streamfile.h" />
<ClInclude Include="meta\ubi_sb_streamfile.h" />
@ -183,6 +184,7 @@
<ClCompile Include="meta\sk_aud.c" />
<ClCompile Include="meta\vawx.c" />
<ClCompile Include="meta\seg.c" />
<ClCompile Include="meta\sfh.c" />
<ClCompile Include="meta\sqex_scd.c" />
<ClCompile Include="meta\sqex_scd_sscf.c" />
<ClCompile Include="meta\sqex_sead.c" />

View File

@ -101,6 +101,9 @@
<ClInclude Include="meta\vsv_streamfile.h">
<Filter>meta\Header Files</Filter>
</ClInclude>
<ClInclude Include="meta\sfh_streamfile.h">
<Filter>meta\Header Files</Filter>
</ClInclude>
<ClInclude Include="meta\sqex_scd_streamfile.h">
<Filter>meta\Header Files</Filter>
</ClInclude>
@ -1372,6 +1375,9 @@
<ClCompile Include="meta\seg.c">
<Filter>meta\Source Files</Filter>
</ClCompile>
<ClCompile Include="meta\sfh.c">
<Filter>meta\Source Files</Filter>
</ClCompile>
<ClCompile Include="meta\ps2_wmus.c">
<Filter>meta\Source Files</Filter>
</ClCompile>

View File

@ -837,4 +837,6 @@ VGMSTREAM * init_vgmstream_mus_vc(STREAMFILE * streamFile);
VGMSTREAM * init_vgmstream_strm_abylight(STREAMFILE * streamFile);
VGMSTREAM * init_vgmstream_sfh(STREAMFILE * streamFile);
#endif /*_META_H*/

46
src/meta/sfh.c Normal file
View File

@ -0,0 +1,46 @@
#include "meta.h"
#include "../coding/coding.h"
#include "sfh_streamfile.h"
/* .SFH - Capcom wrapper [Devil May Cry 4 Demo (PS3), Jojo's Bizarre Adventure HD (PS3)] */
VGMSTREAM * init_vgmstream_sfh(STREAMFILE *streamFile) {
VGMSTREAM *vgmstream = NULL;
STREAMFILE *temp_streamFile = NULL;
uint32_t version;
size_t clean_size, block_size;
/* check extensions */
if ( !check_extensions(streamFile,"at3"))
goto fail;
if (read_32bitBE(0x00, streamFile) != 0x00534648) /* "\0SFH" */
goto fail;
if (read_32bitBE(0x10, streamFile) != 0x52494646) /* "RIFF" */
goto fail;
/* mini header */
version = read_32bitBE(0x04,streamFile);
clean_size = read_32bitBE(0x08,streamFile); /* there is padding data at the end */
/* 0x0c: always 0 */
switch(version) {
case 0x00010000: block_size = 0x10010; break; /* DMC4 Demo (not retail) */
case 0x00010001: block_size = 0x20000; break; /* Jojo */
default: goto fail;
}
temp_streamFile = setup_sfh_streamfile(streamFile, 0x00, block_size, clean_size, "at3");
if (!temp_streamFile) goto fail;
dump_streamfile(temp_streamFile, 0);
vgmstream = init_vgmstream_riff(temp_streamFile);
if (!vgmstream) goto fail;
close_streamfile(temp_streamFile);
return vgmstream;
fail:
close_streamfile(temp_streamFile);
close_vgmstream(vgmstream);
return NULL;
}

132
src/meta/sfh_streamfile.h Normal file
View File

@ -0,0 +1,132 @@
#ifndef _SFH_STREAMFILE_H_
#define _SFH_STREAMFILE_H_
#include "../streamfile.h"
typedef struct {
/* config */
off_t stream_offset;
size_t stream_size;
/* state */
off_t logical_offset; /* fake offset */
off_t physical_offset; /* actual offset */
size_t block_size; /* current size */
size_t skip_size; /* size from block start to reach data */
size_t data_size; /* usable size in a block */
size_t logical_size;
} sfh_io_data;
static size_t sfh_io_read(STREAMFILE *streamfile, uint8_t *dest, off_t offset, size_t length, sfh_io_data* data) {
size_t total_read = 0;
/* re-start when previous offset (can't map logical<>physical offsets) */
if (data->logical_offset < 0 || offset < data->logical_offset) {
data->physical_offset = data->stream_offset;
data->logical_offset = 0x00;
data->data_size = 0;
}
/* read blocks */
while (length > 0) {
/* ignore EOF */
if (offset < 0 || data->physical_offset >= data->stream_offset + data->stream_size) {
break;
}
/* process new block */
if (data->data_size == 0) {
data->skip_size = 0x10; /* skip 0x10 garbage on every block */
data->data_size = data->block_size - 0x10;
}
/* move to next block */
if (data->data_size == 0 || offset >= data->logical_offset + data->data_size) {
data->physical_offset += data->block_size;
data->logical_offset += data->data_size;
data->data_size = 0;
continue;
}
/* read data */
{
size_t bytes_consumed, bytes_done, to_read;
bytes_consumed = offset - data->logical_offset;
to_read = data->data_size - bytes_consumed;
if (to_read > length)
to_read = length;
bytes_done = read_streamfile(dest, data->physical_offset + data->skip_size + bytes_consumed, to_read, streamfile);
total_read += bytes_done;
dest += bytes_done;
offset += bytes_done;
length -= bytes_done;
if (bytes_done != to_read || bytes_done == 0) {
break; /* error/EOF */
}
}
}
return total_read;
}
static size_t sfh_io_size(STREAMFILE *streamfile, sfh_io_data* data) {
uint8_t buf[1];
if (data->logical_size)
return data->logical_size;
/* force a fake read at max offset, to get max logical_offset (will be reset next read) */
sfh_io_read(streamfile, buf, 0x7FFFFFFF, 1, data);
data->logical_size = data->logical_offset;
return data->logical_size;
}
/* Handles deinterleaving of SFH blocked streams */
static STREAMFILE* setup_sfh_streamfile(STREAMFILE *streamFile, off_t stream_offset, size_t block_size, size_t clean_size, const char* extension) {
STREAMFILE *temp_streamFile = NULL, *new_streamFile = NULL;
sfh_io_data io_data = {0};
size_t io_data_size = sizeof(sfh_io_data);
io_data.stream_offset = stream_offset;
io_data.stream_size = get_streamfile_size(streamFile) - stream_offset;
io_data.block_size = block_size;
/* setup subfile */
new_streamFile = open_wrap_streamfile(streamFile);
if (!new_streamFile) goto fail;
temp_streamFile = new_streamFile;
new_streamFile = open_io_streamfile(new_streamFile, &io_data,io_data_size, sfh_io_read,sfh_io_size);
if (!new_streamFile) goto fail;
temp_streamFile = new_streamFile;
new_streamFile = open_buffer_streamfile(new_streamFile,0);
if (!new_streamFile) goto fail;
temp_streamFile = new_streamFile;
new_streamFile = open_clamp_streamfile(new_streamFile,0x00, clean_size);
if (!new_streamFile) goto fail;
temp_streamFile = new_streamFile;
if (extension) {
new_streamFile = open_fakename_streamfile(temp_streamFile, NULL,extension);
if (!new_streamFile) goto fail;
temp_streamFile = new_streamFile;
}
return temp_streamFile;
fail:
close_streamfile(temp_streamFile);
return NULL;
}
#endif /* _SFH_STREAMFILE_H_ */

View File

@ -471,6 +471,7 @@ VGMSTREAM * (*init_vgmstream_functions[])(STREAMFILE *streamFile) = {
init_vgmstream_ffdl,
init_vgmstream_mus_vc,
init_vgmstream_strm_abylight,
init_vgmstream_sfh,
/* 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 */