mirror of
https://github.com/vgmstream/vgmstream.git
synced 2025-01-17 23:36:41 +01:00
Improved EA HDR/DAT support
This commit is contained in:
parent
52f2cb9333
commit
47d7b5a0ed
@ -375,7 +375,7 @@ VGMSTREAM * init_vgmstream_ea_sbr(STREAMFILE *streamFile) {
|
||||
snr_offset = sns_offset;
|
||||
sns_offset = snr_offset + (read_32bitBE(snr_offset, sbsFile) & 0x00FFFFFF);
|
||||
snr_offset += 0x04;
|
||||
vgmstream = init_vgmstream_eaaudiocore_header(sbsFile, sbsFile, snr_offset, sns_offset, meta_EA_SNR_SNS);
|
||||
vgmstream = init_vgmstream_eaaudiocore_header(sbsFile, sbsFile, snr_offset, sns_offset, meta_EA_SPS);
|
||||
if (!vgmstream)
|
||||
goto fail;
|
||||
} else if (sns_offset == 0xFFFFFFFF) {
|
||||
@ -410,12 +410,12 @@ fail:
|
||||
/* EA HDR/STH/DAT - seen in older 7th gen games, used for storing speech */
|
||||
VGMSTREAM * init_vgmstream_ea_hdr_sth_dat(STREAMFILE *streamFile) {
|
||||
int target_stream = streamFile->stream_index;
|
||||
uint32_t i;
|
||||
uint8_t userdata_size, total_sounds, block_id;
|
||||
off_t snr_offset, sns_offset;
|
||||
size_t file_size, block_size;
|
||||
off_t snr_offset, sns_offset, sth_offset, sth_offset2;
|
||||
size_t dat_size, block_size;
|
||||
STREAMFILE *datFile = NULL, *sthFile = NULL;
|
||||
VGMSTREAM *vgmstream;
|
||||
int32_t(*read_32bit)(off_t, STREAMFILE*);
|
||||
|
||||
/* 0x00: ID */
|
||||
/* 0x02: userdata size */
|
||||
@ -423,10 +423,20 @@ VGMSTREAM * init_vgmstream_ea_hdr_sth_dat(STREAMFILE *streamFile) {
|
||||
/* 0x04: sub-ID (used for different police voices in NFS games) */
|
||||
/* 0x08: alt number of files? */
|
||||
/* 0x09: zero */
|
||||
/* 0x0A: ??? */
|
||||
/* 0x0A: related to size? */
|
||||
/* 0x0C: zero */
|
||||
/* 0x10: table start */
|
||||
|
||||
if (read_8bit(0x09, streamFile) != 0)
|
||||
goto fail;
|
||||
|
||||
if (read_32bitBE(0x0c, streamFile) != 0)
|
||||
goto fail;
|
||||
|
||||
/* first offset is always zero */
|
||||
if (read_16bitBE(0x10, streamFile) != 0)
|
||||
goto fail;
|
||||
|
||||
sthFile = open_streamfile_by_ext(streamFile, "sth");
|
||||
if (!sthFile)
|
||||
goto fail;
|
||||
@ -436,7 +446,7 @@ VGMSTREAM * init_vgmstream_ea_hdr_sth_dat(STREAMFILE *streamFile) {
|
||||
goto fail;
|
||||
|
||||
/* STH always starts with the first offset of zero */
|
||||
sns_offset = read_32bitLE(0x00, sthFile);
|
||||
sns_offset = read_32bitBE(0x00, sthFile);
|
||||
if (sns_offset != 0)
|
||||
goto fail;
|
||||
|
||||
@ -447,6 +457,7 @@ VGMSTREAM * init_vgmstream_ea_hdr_sth_dat(STREAMFILE *streamFile) {
|
||||
|
||||
userdata_size = read_8bit(0x02, streamFile);
|
||||
total_sounds = read_8bit(0x03, streamFile);
|
||||
|
||||
if (read_8bit(0x08, streamFile) > total_sounds)
|
||||
goto fail;
|
||||
|
||||
@ -455,23 +466,25 @@ VGMSTREAM * init_vgmstream_ea_hdr_sth_dat(STREAMFILE *streamFile) {
|
||||
goto fail;
|
||||
|
||||
/* offsets in HDR are always big endian */
|
||||
//snr_offset = (off_t)read_16bitBE(0x10 + (0x02+userdata_size) * (target_stream-1), streamFile) + 0x04;
|
||||
//sns_offset = read_32bit(snr_offset, sthFile);
|
||||
sth_offset = (uint16_t)read_16bitBE(0x10 + (0x02 + userdata_size) * (target_stream - 1), streamFile);
|
||||
|
||||
#if 0
|
||||
snr_offset = sth_offset + 0x04;
|
||||
sns_offset = read_32bit(sth_offset + 0x00, sthFile);
|
||||
#else
|
||||
/* we can't reliably detect byte endianness so we're going to find the sound the hacky way */
|
||||
/* go through blocks until we reach the goal sound */
|
||||
file_size = get_streamfile_size(datFile);
|
||||
dat_size = get_streamfile_size(datFile);
|
||||
snr_offset = 0;
|
||||
sns_offset = 0;
|
||||
|
||||
for (i = 0; i < total_sounds; i++) {
|
||||
snr_offset = (uint16_t)read_16bitBE(0x10 + (0x02+userdata_size) * i, streamFile) + 0x04;
|
||||
|
||||
if (i == target_stream - 1)
|
||||
break;
|
||||
|
||||
if (total_sounds == 1) {
|
||||
/* always 0 */
|
||||
snr_offset = sth_offset + 0x04;
|
||||
sns_offset = 0x00;
|
||||
} else {
|
||||
/* find the first sound size and match it up with the second sound offset to detect endianness */
|
||||
while (1) {
|
||||
if (sns_offset >= file_size)
|
||||
if (sns_offset >= dat_size)
|
||||
goto fail;
|
||||
|
||||
block_id = read_8bit(sns_offset, datFile);
|
||||
@ -487,7 +500,20 @@ VGMSTREAM * init_vgmstream_ea_hdr_sth_dat(STREAMFILE *streamFile) {
|
||||
if (block_id == EAAC_BLOCKID0_END)
|
||||
break;
|
||||
}
|
||||
|
||||
sth_offset2 = (uint16_t)read_16bitBE(0x10 + (0x02 + userdata_size) * 1, streamFile);
|
||||
if (sns_offset == read_32bitBE(sth_offset2, sthFile)) {
|
||||
read_32bit = read_32bitBE;
|
||||
} else if (sns_offset == read_32bitLE(sth_offset2, sthFile)) {
|
||||
read_32bit = read_32bitLE;
|
||||
} else {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
snr_offset = sth_offset + 0x04;
|
||||
sns_offset = read_32bit(sth_offset + 0x00, sthFile);
|
||||
}
|
||||
#endif
|
||||
|
||||
block_id = read_8bit(sns_offset, datFile);
|
||||
if (block_id != EAAC_BLOCKID0_DATA && block_id != EAAC_BLOCKID0_END)
|
||||
|
@ -458,26 +458,35 @@ fail:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* EA HDR/DAT combo - seen in late 6th-gen games, used for storing speech and other streamed sounds (except for music) */
|
||||
/* EA HDR/DAT v1 (2004-2005) - used for storing speech and other streamed sounds (except for music) */
|
||||
VGMSTREAM * init_vgmstream_ea_hdr_dat(STREAMFILE *streamFile) {
|
||||
int target_stream = streamFile->stream_index;
|
||||
uint8_t userdata_size, total_sounds;
|
||||
size_t dat_size;
|
||||
off_t schl_offset, offset_mult;
|
||||
STREAMFILE *datFile = NULL;
|
||||
VGMSTREAM *vgmstream;
|
||||
|
||||
/* main header's endianness is platform-native but we only care about one byte values */
|
||||
/* main header is machine endian but it's not important here */
|
||||
/* 0x00: ID */
|
||||
/* 0x02: sub-ID (used for different police voices in NFS games) */
|
||||
/* 0x04: (low nibble) userdata size */
|
||||
/* 0x04: (high nibble) ??? */
|
||||
/* 0x05: number of files */
|
||||
/* 0x06: ??? */
|
||||
/* 0x06: alt number of files? */
|
||||
/* 0x07: offset multiplier flag */
|
||||
/* 0x08: combined size of all sounds without padding divided by offset mult */
|
||||
/* 0x0C: table start */
|
||||
/* 0x0a: zero */
|
||||
/* 0x0c: table start */
|
||||
|
||||
/* no nice way to validate these so we do what we can */
|
||||
if (read_16bitBE(0x0a, streamFile) != 0)
|
||||
goto fail;
|
||||
|
||||
/* first offset is always zero */
|
||||
if (read_16bitBE(0x0c, streamFile) != 0)
|
||||
goto fail;
|
||||
|
||||
/* must be accompanied by DAT file with SCHl sounds */
|
||||
datFile = open_streamfile_by_ext(streamFile, "dat");
|
||||
if (!datFile)
|
||||
@ -490,12 +499,90 @@ VGMSTREAM * init_vgmstream_ea_hdr_dat(STREAMFILE *streamFile) {
|
||||
total_sounds = read_8bit(0x05, streamFile);
|
||||
offset_mult = (uint8_t)read_8bit(0x07, streamFile) * 0x0100 + 0x0100;
|
||||
|
||||
if (read_8bit(0x06, streamFile) > total_sounds)
|
||||
goto fail;
|
||||
|
||||
dat_size = get_streamfile_size(datFile);
|
||||
if ((uint16_t)read_16bitLE(0x08, streamFile) * offset_mult > dat_size &&
|
||||
(uint16_t)read_16bitBE(0x08, streamFile) * offset_mult > dat_size)
|
||||
goto fail;
|
||||
|
||||
if (target_stream == 0) target_stream = 1;
|
||||
if (target_stream < 0 || total_sounds == 0 || target_stream > total_sounds)
|
||||
goto fail;
|
||||
|
||||
/* offsets are always big endian */
|
||||
schl_offset = (uint16_t)read_16bitBE(0x0C + (0x02+userdata_size) * (target_stream-1), streamFile) * offset_mult;
|
||||
schl_offset = (uint16_t)read_16bitBE(0x0C + (0x02 + userdata_size) * (target_stream - 1), streamFile) * offset_mult;
|
||||
if (read_32bitBE(schl_offset, datFile) != EA_BLOCKID_HEADER)
|
||||
goto fail;
|
||||
|
||||
vgmstream = parse_schl_block(datFile, schl_offset, 0);
|
||||
if (!vgmstream)
|
||||
goto fail;
|
||||
|
||||
vgmstream->num_streams = total_sounds;
|
||||
close_streamfile(datFile);
|
||||
return vgmstream;
|
||||
|
||||
fail:
|
||||
close_streamfile(datFile);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* EA HDR/DAT v2 (2006-2014) */
|
||||
VGMSTREAM * init_vgmstream_ea_hdr_dat_v2(STREAMFILE *streamFile) {
|
||||
int target_stream = streamFile->stream_index;
|
||||
uint8_t userdata_size, total_sounds;
|
||||
size_t dat_size;
|
||||
off_t schl_offset, offset_mult;
|
||||
STREAMFILE *datFile = NULL;
|
||||
VGMSTREAM *vgmstream;
|
||||
|
||||
/* main header is machine endian but it's not important here */
|
||||
/* 0x00: ID */
|
||||
/* 0x02: userdata size */
|
||||
/* 0x03: number of files */
|
||||
/* 0x04: sub-ID (used for different police voices in NFS games) */
|
||||
/* 0x08: alt number of files? */
|
||||
/* 0x09: offset mult */
|
||||
/* 0x0a: DAT size divided by offset mult */
|
||||
/* 0x0c: zero */
|
||||
/* 0x10: table start */
|
||||
|
||||
/* no nice way to validate these so we do what we can */
|
||||
if (read_32bitBE(0x0c, streamFile) != 0)
|
||||
goto fail;
|
||||
|
||||
/* first offset is always zero */
|
||||
if (read_16bitBE(0x10, streamFile) != 0)
|
||||
goto fail;
|
||||
|
||||
/* must be accompanied by DAT file with SCHl sounds */
|
||||
datFile = open_streamfile_by_ext(streamFile, "dat");
|
||||
if (!datFile)
|
||||
goto fail;
|
||||
|
||||
if (read_32bitBE(0x00, datFile) != EA_BLOCKID_HEADER)
|
||||
goto fail;
|
||||
|
||||
userdata_size = read_8bit(0x02, streamFile);
|
||||
total_sounds = read_8bit(0x03, streamFile);
|
||||
offset_mult = (uint8_t)read_8bit(0x09, streamFile) * 0x0100 + 0x0100;
|
||||
|
||||
if (read_8bit(0x08, streamFile) > total_sounds)
|
||||
goto fail;
|
||||
|
||||
dat_size = get_streamfile_size(datFile);
|
||||
if ((uint16_t)read_16bitLE(0x0a, streamFile) * offset_mult != dat_size &&
|
||||
(uint16_t)read_16bitBE(0x0a, streamFile) * offset_mult != dat_size)
|
||||
goto fail;
|
||||
|
||||
if (target_stream == 0) target_stream = 1;
|
||||
if (target_stream < 0 || total_sounds == 0 || target_stream > total_sounds)
|
||||
goto fail;
|
||||
|
||||
/* offsets are always big endian */
|
||||
schl_offset = (uint16_t)read_16bitBE(0x10 + (0x02 + userdata_size) * (target_stream - 1), streamFile) * offset_mult;
|
||||
if (read_32bitBE(schl_offset, datFile) != EA_BLOCKID_HEADER)
|
||||
goto fail;
|
||||
|
||||
|
@ -648,6 +648,7 @@ VGMSTREAM * init_vgmstream_ea_schl_video(STREAMFILE *streamFile);
|
||||
VGMSTREAM * init_vgmstream_ea_bnk(STREAMFILE * streamFile);
|
||||
VGMSTREAM * init_vgmstream_ea_abk(STREAMFILE * streamFile);
|
||||
VGMSTREAM * init_vgmstream_ea_hdr_dat(STREAMFILE * streamFile);
|
||||
VGMSTREAM * init_vgmstream_ea_hdr_dat_v2(STREAMFILE * streamFile);
|
||||
VGMSTREAM * init_vgmstream_ea_map_mus(STREAMFILE * steeamFile);
|
||||
VGMSTREAM * init_vgmstream_ea_mpf_mus(STREAMFILE * steeamFile);
|
||||
|
||||
|
@ -354,6 +354,7 @@ VGMSTREAM * (*init_vgmstream_functions[])(STREAMFILE *streamFile) = {
|
||||
init_vgmstream_ea_bnk,
|
||||
init_vgmstream_ea_abk,
|
||||
init_vgmstream_ea_hdr_dat,
|
||||
init_vgmstream_ea_hdr_dat_v2,
|
||||
init_vgmstream_ea_map_mus,
|
||||
init_vgmstream_ea_mpf_mus,
|
||||
init_vgmstream_ea_schl_fixed,
|
||||
|
Loading…
x
Reference in New Issue
Block a user