From 86dceb51e58bc6e1744f65757e5d34ca24bb366b Mon Sep 17 00:00:00 2001 From: bnnm Date: Fri, 20 Jan 2023 17:30:17 +0100 Subject: [PATCH] cleanup: tabs, etc --- src/meta/akb.c | 32 ---------- src/meta/aus.c | 85 ++++++++++----------------- src/meta/encrypted_mc161_streamfile.h | 4 +- src/meta/fsb.c | 2 +- src/meta/gca.c | 32 +++++----- src/meta/meta.h | 2 - src/meta/ster.c | 7 ++- src/meta/ubi_bao.c | 2 +- src/meta/vgs.c | 31 +++++----- src/meta/xwc.c | 68 ++++++++++----------- 10 files changed, 103 insertions(+), 162 deletions(-) diff --git a/src/meta/akb.c b/src/meta/akb.c index 327f1ec4..df763f07 100644 --- a/src/meta/akb.c +++ b/src/meta/akb.c @@ -3,38 +3,6 @@ #include "sqex_streamfile.h" -#if defined(VGM_USE_MP4V2) && defined(VGM_USE_FDKAAC) -/* AKB (AAC only) - found in SQEX iOS games */ -VGMSTREAM * init_vgmstream_akb_mp4(STREAMFILE *sf) { - VGMSTREAM * vgmstream = NULL; - - size_t filesize; - uint32_t loop_start, loop_end; - - if ((uint32_t)read_32bitBE(0, sf) != 0x414b4220) goto fail; - - loop_start = read_s32le(0x14, sf); - loop_end = read_s32le(0x18, sf); - - filesize = get_streamfile_size( sf ); - - vgmstream = init_vgmstream_mp4_aac_offset( sf, 0x20, filesize - 0x20 ); - if ( !vgmstream ) goto fail; - - if ( loop_start || loop_end ) { - vgmstream->loop_flag = 1; - vgmstream->loop_start_sample = loop_start; - vgmstream->loop_end_sample = loop_end; - } - - return vgmstream; - -fail: - return NULL; -} -#endif - - /* AKB - found in SQEX 'sdlib' iOS/Android games */ VGMSTREAM* init_vgmstream_akb(STREAMFILE* sf) { VGMSTREAM* vgmstream = NULL; diff --git a/src/meta/aus.c b/src/meta/aus.c index 26a57163..374d0d16 100644 --- a/src/meta/aus.c +++ b/src/meta/aus.c @@ -1,71 +1,48 @@ #include "meta.h" #include "../util.h" -/* AUS (found in various Capcom games) */ -VGMSTREAM * init_vgmstream_aus(STREAMFILE *streamFile) { - VGMSTREAM * vgmstream = NULL; - char filename[PATH_LIMIT]; +/* AUS - Atomic Planet games [Jackie Chan Adventures (PS2), Mega Man Anniversary Collection (PS2/Xbox)] */ +VGMSTREAM* init_vgmstream_aus(STREAMFILE* sf) { + VGMSTREAM* vgmstream = NULL; off_t start_offset; - int loop_flag = 0; - int channel_count; + int loop_flag, channels, codec; - /* check extension, case insensitive */ - streamFile->get_name(streamFile,filename,sizeof(filename)); - if (strcasecmp("aus",filename_extension(filename))) goto fail; - /* check header */ - if (read_32bitBE(0x00,streamFile) != 0x41555320) /* "AUS " */ + /* checks */ + if (!is_id32be(0x00, sf, "AUS ")) + goto fail; + if (!check_extensions(sf, "aus")) goto fail; - loop_flag = (read_32bitLE(0x0c,streamFile)!=0); - channel_count = read_32bitLE(0xC,streamFile); - - /* build the VGMSTREAM */ - vgmstream = allocate_vgmstream(channel_count,loop_flag); + channels = read_u32le(0x0c,sf); + start_offset = 0x800; + codec = read_u16le(0x06,sf); + loop_flag = (read_u32le(0x1c,sf) == 1); /* games seem to just do full loops, even when makes no sense (jingles/megaman stages) */ + + /* build the VGMSTREAM */ + vgmstream = allocate_vgmstream(channels, loop_flag); if (!vgmstream) goto fail; - /* fill in the vital statistics */ - start_offset = 0x800; - vgmstream->channels = channel_count; - vgmstream->sample_rate = read_32bitLE(0x10,streamFile); - vgmstream->num_samples = read_32bitLE(0x08,streamFile); + vgmstream->meta_type = meta_AUS; + vgmstream->sample_rate = read_s32le(0x10,sf); /* uses pretty odd values */ + vgmstream->num_samples = read_s32le(0x08,sf); + vgmstream->loop_start_sample = read_s32le(0x14,sf); /* always 0? */ + vgmstream->loop_end_sample = read_s32le(0x18,sf); /* always samples? */ - if(read_16bitLE(0x06,streamFile)==0x02) { - vgmstream->coding_type = coding_XBOX_IMA; - vgmstream->layout_type=layout_none; - } else { - vgmstream->coding_type = coding_PSX; - vgmstream->layout_type = layout_interleave; - vgmstream->interleave_block_size = 0x800; - } - - if (loop_flag) { - vgmstream->loop_start_sample = read_32bitLE(0x14,streamFile); - vgmstream->loop_end_sample = read_32bitLE(0x08,streamFile); - } - - vgmstream->meta_type = meta_AUS; - - /* open the file for reading */ - { - int i; - STREAMFILE * file; - file = streamFile->open(streamFile,filename,STREAMFILE_DEFAULT_BUFFER_SIZE); - if (!file) goto fail; - for (i=0;ich[i].streamfile = file; - - vgmstream->ch[i].channel_start_offset= - vgmstream->ch[i].offset=start_offset+ - vgmstream->interleave_block_size*i; - - } + if (codec == 0x02) { + vgmstream->coding_type = coding_XBOX_IMA; + vgmstream->layout_type = layout_none; + } + else { + vgmstream->coding_type = coding_PSX; + vgmstream->layout_type = layout_interleave; + vgmstream->interleave_block_size = 0x800; } + if (!vgmstream_open_stream(vgmstream, sf, start_offset)) + goto fail; return vgmstream; - - /* clean up anything we may have opened */ fail: - if (vgmstream) close_vgmstream(vgmstream); + close_vgmstream(vgmstream); return NULL; } diff --git a/src/meta/encrypted_mc161_streamfile.h b/src/meta/encrypted_mc161_streamfile.h index e8a1fde6..8eeb08d0 100644 --- a/src/meta/encrypted_mc161_streamfile.h +++ b/src/meta/encrypted_mc161_streamfile.h @@ -16,8 +16,8 @@ static void decrypt_chunk(uint8_t* buf, int buf_size, mc161_io_data* data) { for (i = 0; i < buf_size; i++) { - buf[i] = (uint8_t)(buf[i] ^ ((hash >> 8) & 0xFF)); - hash = (int32_t)(hash * 498729871) + (85731 * (int8_t)buf[i]); /* signed */ + buf[i] = (uint8_t)(buf[i] ^ ((hash >> 8) & 0xFF)); + hash = (int32_t)(hash * 498729871) + (85731 * (int8_t)buf[i]); /* signed */ } data->curr_key = hash; diff --git a/src/meta/fsb.c b/src/meta/fsb.c index 7d84cf85..8b5cadcb 100644 --- a/src/meta/fsb.c +++ b/src/meta/fsb.c @@ -118,7 +118,7 @@ VGMSTREAM* init_vgmstream_fsb(STREAMFILE* sf) { /* .fsb: standard * .bnk: Hard Corps Uprising (PS3) - * .sfx: Geon Cube (Wii) + * .sfx: Geon Cube (Wii) * .xen: Guitar Hero: World Tour (PC) */ if ( !check_extensions(sf, "fsb,bnk,sfx,xen") ) goto fail; diff --git a/src/meta/gca.c b/src/meta/gca.c index 24606877..bd00b948 100644 --- a/src/meta/gca.c +++ b/src/meta/gca.c @@ -3,39 +3,37 @@ #include "../util.h" /* GCA - Terminal Reality games [Metal Slug Anthology (Wii), BlowOut (GC)] */ -VGMSTREAM * init_vgmstream_gca(STREAMFILE *streamFile) { - VGMSTREAM * vgmstream = NULL; +VGMSTREAM* init_vgmstream_gca(STREAMFILE* sf) { + VGMSTREAM* vgmstream = NULL; off_t start_offset; - int loop_flag, channel_count; + int loop_flag, channels; /* checks */ - if (!check_extensions(streamFile, "gca")) + if (!is_id32be(0x00,sf, "GCA1")) goto fail; - - if (read_32bitBE(0x00,streamFile) != 0x47434131) /* "GCA1" */ + if (!check_extensions(sf, "gca")) goto fail; start_offset = 0x40; loop_flag = 0; - channel_count = 1; + channels = 1; - /* build the VGMSTREAM */ - vgmstream = allocate_vgmstream(channel_count,loop_flag); + /* build the VGMSTREAM */ + vgmstream = allocate_vgmstream(channels,loop_flag); if (!vgmstream) goto fail; - vgmstream->sample_rate = read_32bitBE(0x2A,streamFile); - vgmstream->coding_type = coding_NGC_DSP; - vgmstream->num_samples = dsp_nibbles_to_samples(read_32bitBE(0x26,streamFile));//read_32bitBE(0x26,streamFile)*7/8; - - vgmstream->layout_type = layout_none; /* we have no interleave, so we have no layout */ vgmstream->meta_type = meta_GCA; + vgmstream->sample_rate = read_32bitBE(0x2A,sf); + vgmstream->num_samples = dsp_nibbles_to_samples(read_32bitBE(0x26,sf));//read_32bitBE(0x26,streamFile)*7/8; - dsp_read_coefs_be(vgmstream,streamFile,0x04,0x00); + vgmstream->coding_type = coding_NGC_DSP; + vgmstream->layout_type = layout_none; - if (!vgmstream_open_stream(vgmstream,streamFile,start_offset)) + dsp_read_coefs_be(vgmstream, sf, 0x04, 0x00); + + if (!vgmstream_open_stream(vgmstream,sf,start_offset)) goto fail; return vgmstream; - fail: close_vgmstream(vgmstream); return NULL; diff --git a/src/meta/meta.h b/src/meta/meta.h index cb64d878..389ff70b 100644 --- a/src/meta/meta.h +++ b/src/meta/meta.h @@ -158,8 +158,6 @@ VGMSTREAM* init_vgmstream_mp4_aac_ffmpeg(STREAMFILE* sf); #if defined(VGM_USE_MP4V2) && defined(VGM_USE_FDKAAC) VGMSTREAM * init_vgmstream_mp4_aac(STREAMFILE * streamFile); VGMSTREAM * init_vgmstream_mp4_aac_offset(STREAMFILE *streamFile, uint64_t start, uint64_t size); - -VGMSTREAM * init_vgmstream_akb_mp4(STREAMFILE *streamFile); #endif VGMSTREAM * init_vgmstream_sli_ogg(STREAMFILE * streamFile); diff --git a/src/meta/ster.c b/src/meta/ster.c index 293ea80e..0ca2d0ff 100644 --- a/src/meta/ster.c +++ b/src/meta/ster.c @@ -10,13 +10,14 @@ VGMSTREAM* init_vgmstream_ster(STREAMFILE* sf) { /* checks */ + if (!is_id32be(0x00,sf, "STER")) + goto fail; + /* .ster: header id (no apparent names/extensions) * .sfs: generic bigfile extension (to be removed?)*/ if (!check_extensions(sf, "ster,sfs")) goto fail; - if (!is_id32be(0x00,sf, "STER")) - goto fail; channel_size = read_u32le(0x04, sf); loop_start = read_u32le(0x08, sf); /* absolute (ex. offset 0x50 for full loops) */ /* 0x0c: data size BE */ @@ -28,7 +29,7 @@ VGMSTREAM* init_vgmstream_ster(STREAMFILE* sf) { start_offset = 0x30; - /* build the VGMSTREAM */ + /* build the VGMSTREAM */ vgmstream = allocate_vgmstream(channels, loop_flag); if (!vgmstream) goto fail; diff --git a/src/meta/ubi_bao.c b/src/meta/ubi_bao.c index c91a287a..9093e442 100644 --- a/src/meta/ubi_bao.c +++ b/src/meta/ubi_bao.c @@ -1360,7 +1360,7 @@ static STREAMFILE* open_atomic_bao(ubi_bao_file file_type, uint32_t file_id, int snprintf(buf,buf_size, "%08x.bao", file_id); sf_bao = open_streamfile_by_filename(sf, buf); if (sf_bao) return sf_bao; - } + } else { /* %08x.sbao nomenclature (in addition to %08x.bao) present in Shaun White Snowboarding (Windows Vista) exe. */ snprintf(buf,buf_size, "%08x.sbao", file_id); diff --git a/src/meta/vgs.c b/src/meta/vgs.c index db55f8fb..c4f9940a 100644 --- a/src/meta/vgs.c +++ b/src/meta/vgs.c @@ -4,27 +4,26 @@ #include "../layout/layout.h" /* VGS - from Guitar Hero Encore - Rocks the 80s, Guitar Hero II PS2 */ -VGMSTREAM * init_vgmstream_vgs(STREAMFILE *streamFile) { - VGMSTREAM * vgmstream = NULL; +VGMSTREAM* init_vgmstream_vgs(STREAMFILE *sf) { + VGMSTREAM* vgmstream = NULL; off_t start_offset; size_t channel_size = 0, stream_data_size, stream_frame_count; - int channel_count = 0, loop_flag = 0, sample_rate = 0, stream_sample_rate; + int channels = 0, loop_flag = 0, sample_rate = 0, stream_sample_rate; int i; - /* check extension, case insensitive */ - if (!check_extensions(streamFile,"vgs")) - goto fail; - - /* check header */ - if (read_32bitBE(0x00,streamFile) != 0x56675321) /* "VgS!" */ + /* checks */ + if (!is_id32be(0x00,sf, "VgS!")) goto fail; /* 0x04: version? */ + if (!check_extensions(sf,"vgs")) + goto fail; + /* contains N streams, which can have one less frame, or half frame and sample rate */ for (i = 0; i < 8; i++) { - stream_sample_rate = read_32bitLE(0x08 + 0x08*i + 0x00,streamFile); - stream_frame_count = read_32bitLE(0x08 + 0x08*i + 0x04,streamFile); + stream_sample_rate = read_32bitLE(0x08 + 0x08*i + 0x00,sf); + stream_frame_count = read_32bitLE(0x08 + 0x08*i + 0x04,sf); stream_data_size = stream_frame_count*0x10; if (stream_sample_rate == 0) @@ -47,24 +46,24 @@ VGMSTREAM * init_vgmstream_vgs(STREAMFILE *streamFile) { break; } - channel_count++; + channels++; } start_offset = 0x80; - /* build the VGMSTREAM */ - vgmstream = allocate_vgmstream(channel_count,loop_flag); + /* build the VGMSTREAM */ + vgmstream = allocate_vgmstream(channels, loop_flag); if (!vgmstream) goto fail; vgmstream->meta_type = meta_VGS; vgmstream->sample_rate = sample_rate; - vgmstream->num_samples = ps_bytes_to_samples(channel_size*channel_count, channel_count); + vgmstream->num_samples = ps_bytes_to_samples(channel_size * channels, channels); vgmstream->coding_type = coding_PSX_badflags; /* flag = stream/channel number */ vgmstream->layout_type = layout_blocked_vgs; - if (!vgmstream_open_stream(vgmstream,streamFile,start_offset)) + if (!vgmstream_open_stream(vgmstream, sf, start_offset)) goto fail; return vgmstream; fail: diff --git a/src/meta/xwc.c b/src/meta/xwc.c index 659cf4ee..9ddbdf89 100644 --- a/src/meta/xwc.c +++ b/src/meta/xwc.c @@ -2,40 +2,40 @@ #include "../coding/coding.h" /* .XWC - Starbreeze games [Chronicles of Riddick: Assault on Dark Athena, Syndicate] */ -VGMSTREAM * init_vgmstream_xwc(STREAMFILE *streamFile) { - VGMSTREAM * vgmstream = NULL; - off_t start_offset, extra_offset; - size_t data_size; - int loop_flag, channel_count, codec, num_samples; +VGMSTREAM* init_vgmstream_xwc(STREAMFILE* sf) { + VGMSTREAM* vgmstream = NULL; + off_t start_offset, extra_offset; + size_t data_size; + int loop_flag, channels, codec, num_samples; /* checks */ /* .xwc: extension of the bigfile, individual files don't have one */ - if ( !check_extensions(streamFile,"xwc")) + if ( !check_extensions(sf,"xwc")) goto fail; /* version */ - if (read_32bitBE(0x00,streamFile) == 0x00030000 && - read_32bitBE(0x04,streamFile) == 0x00900000) { /* The Darkness */ - data_size = read_32bitLE(0x08, streamFile) + 0x1c; /* not including subheader */ - channel_count = read_32bitLE(0x0c, streamFile); + if (read_32bitBE(0x00,sf) == 0x00030000 && + read_32bitBE(0x04,sf) == 0x00900000) { /* The Darkness */ + data_size = read_32bitLE(0x08, sf) + 0x1c; /* not including subheader */ + channels = read_32bitLE(0x0c, sf); /* 0x10: num_samples */ /* 0x14: 0x8000? */ /* 0x18: null */ - codec = read_32bitBE(0x1c, streamFile); - num_samples = read_32bitLE(0x20, streamFile); + codec = read_32bitBE(0x1c, sf); + num_samples = read_32bitLE(0x20, sf); /* 0x24: config data >> 2? (0x00(1): channels; 0x01(2): ?, 0x03(2): sample_rate) */ extra_offset = 0x28; } - else if (read_32bitBE(0x00,streamFile) == 0x00040000 && - read_32bitBE(0x04,streamFile) == 0x00900000) { /* Riddick, Syndicate */ - data_size = read_32bitLE(0x08, streamFile) + 0x24; /* not including subheader */ - channel_count = read_32bitLE(0x0c, streamFile); + else if (read_32bitBE(0x00,sf) == 0x00040000 && + read_32bitBE(0x04,sf) == 0x00900000) { /* Riddick, Syndicate */ + data_size = read_32bitLE(0x08, sf) + 0x24; /* not including subheader */ + channels = read_32bitLE(0x0c, sf); /* 0x10: num_samples */ /* 0x14: 0x8000? */ - codec = read_32bitBE(0x24, streamFile); - num_samples = read_32bitLE(0x28, streamFile); + codec = read_32bitBE(0x24, sf); + num_samples = read_32bitLE(0x28, sf); /* 0x2c: config data >> 2? (0x00(1): channels; 0x01(2): ?, 0x03(2): sample_rate) */ /* 0x30+: codec dependant */ extra_offset = 0x30; @@ -48,7 +48,7 @@ VGMSTREAM * init_vgmstream_xwc(STREAMFILE *streamFile) { /* build the VGMSTREAM */ - vgmstream = allocate_vgmstream(channel_count,loop_flag); + vgmstream = allocate_vgmstream(channels,loop_flag); if (!vgmstream) goto fail; vgmstream->meta_type = meta_XWC; @@ -60,10 +60,10 @@ VGMSTREAM * init_vgmstream_xwc(STREAMFILE *streamFile) { mpeg_custom_config cfg = {0}; start_offset = 0x800; - vgmstream->num_samples = read_32bitLE(extra_offset+0x00, streamFile); /* with encoder delay */ //todo improve - cfg.data_size = read_32bitLE(extra_offset+0x04, streamFile); /* without padding */ + vgmstream->num_samples = read_32bitLE(extra_offset+0x00, sf); /* with encoder delay */ //todo improve + cfg.data_size = read_32bitLE(extra_offset+0x04, sf); /* without padding */ - vgmstream->codec_data = init_mpeg_custom(streamFile, start_offset, &vgmstream->coding_type, vgmstream->channels, MPEG_STANDARD, &cfg); + vgmstream->codec_data = init_mpeg_custom(sf, start_offset, &vgmstream->coding_type, vgmstream->channels, MPEG_STANDARD, &cfg); if (!vgmstream->codec_data) goto fail; vgmstream->layout_type = layout_none; @@ -76,23 +76,23 @@ VGMSTREAM * init_vgmstream_xwc(STREAMFILE *streamFile) { uint8_t buf[0x100]; int32_t bytes, seek_size, block_size, block_count, sample_rate, chunk_size; - seek_size = read_32bitLE(extra_offset + 0x00, streamFile); - chunk_size = read_32bitLE(extra_offset + 0x04 + seek_size, streamFile); + seek_size = read_32bitLE(extra_offset + 0x00, sf); + chunk_size = read_32bitLE(extra_offset + 0x04 + seek_size, sf); start_offset = extra_offset+ 0x04 + seek_size + chunk_size + 0x08; start_offset += (start_offset % 0x800) ? 0x800 - (start_offset % 0x800) : 0; /* padded */ data_size = data_size - start_offset; if (chunk_size == 0x34) { /* new XMA2 */ - sample_rate = read_32bitLE(extra_offset+0x04+seek_size+0x08, streamFile); - block_size = read_32bitLE(extra_offset+0x04+seek_size+0x20, streamFile); + sample_rate = read_32bitLE(extra_offset+0x04+seek_size+0x08, sf); + block_size = read_32bitLE(extra_offset+0x04+seek_size+0x20, sf); block_count = data_size / block_size; /* others: standard RIFF XMA2 fmt? */ } else if (chunk_size == 0x2c) { /* old XMA2 */ - sample_rate = read_32bitBE(extra_offset+0x04+seek_size+0x10, streamFile); - block_size = read_32bitBE(extra_offset+0x04+seek_size+0x1c, streamFile); - block_count = read_32bitBE(extra_offset+0x04+seek_size+0x28, streamFile); + sample_rate = read_32bitBE(extra_offset+0x04+seek_size+0x10, sf); + block_size = read_32bitBE(extra_offset+0x04+seek_size+0x1c, sf); + block_count = read_32bitBE(extra_offset+0x04+seek_size+0x28, sf); /* others: scrambled RIFF fmt BE values */ } else { @@ -100,14 +100,14 @@ VGMSTREAM * init_vgmstream_xwc(STREAMFILE *streamFile) { } bytes = ffmpeg_make_riff_xma2(buf,0x100, vgmstream->num_samples, data_size, vgmstream->channels, sample_rate, block_count, block_size); - vgmstream->codec_data = init_ffmpeg_header_offset(streamFile, buf,bytes, start_offset,data_size); + vgmstream->codec_data = init_ffmpeg_header_offset(sf, buf,bytes, start_offset,data_size); if (!vgmstream->codec_data) goto fail; vgmstream->coding_type = coding_FFmpeg; vgmstream->layout_type = layout_none; vgmstream->sample_rate = sample_rate; - xma_fix_raw_samples(vgmstream, streamFile, start_offset,data_size, 0, 0,0); /* samples are ok, fix delay */ + xma_fix_raw_samples(vgmstream, sf, start_offset,data_size, 0, 0,0); /* samples are ok, fix delay */ break; } #endif @@ -116,12 +116,12 @@ VGMSTREAM * init_vgmstream_xwc(STREAMFILE *streamFile) { start_offset = 0x30; data_size = data_size - start_offset; - vgmstream->codec_data = init_ogg_vorbis(streamFile, start_offset, data_size, NULL); + vgmstream->codec_data = init_ogg_vorbis(sf, start_offset, data_size, NULL); if ( !vgmstream->codec_data ) goto fail; vgmstream->coding_type = coding_OGG_VORBIS; vgmstream->layout_type = layout_none; - vgmstream->sample_rate = read_32bitLE(start_offset + 0x28, streamFile); + vgmstream->sample_rate = read_32bitLE(start_offset + 0x28, sf); break; } #endif @@ -130,7 +130,7 @@ VGMSTREAM * init_vgmstream_xwc(STREAMFILE *streamFile) { } - if ( !vgmstream_open_stream(vgmstream, streamFile, start_offset) ) + if ( !vgmstream_open_stream(vgmstream, sf, start_offset) ) goto fail; return vgmstream;