Merge pull request #2 from soneek/master

Update RedSpark for M&L Dream Team
This commit is contained in:
Chris Moeller 2014-05-26 00:04:43 -07:00
commit 793f236cd1

View File

@ -11,37 +11,53 @@ static uint32_t find_key(uint32_t firstword) {
return firstword ^ expected; return firstword ^ expected;
} }
/* RSD - RedSpark (MadWorld) */ /* RSD - RedSpark (MadWorld)
RS3D - RedSpark (Mario & Luigi: Dream Team I fi*/
VGMSTREAM * init_vgmstream_RedSpark(STREAMFILE *streamFile) { VGMSTREAM * init_vgmstream_RedSpark(STREAMFILE *streamFile) {
VGMSTREAM * vgmstream = NULL; VGMSTREAM * vgmstream = NULL;
char filename[PATH_LIMIT]; char filename[PATH_LIMIT];
off_t start_offset; off_t start_offset;
int loop_flag; int loop_flag;
int channel_count; int channel_count;
int dt_flag = 0;
uint32_t key; uint32_t key;
enum {encsize = 0x1000}; enum {encsize = 0x1000};
uint8_t buf[encsize]; uint8_t buf[encsize];
int32_t(*get_32bit)(uint8_t *p) = NULL;
int16_t(*get_16bit)(uint8_t *p) = NULL;
get_16bit = get_16bitBE;
get_32bit = get_32bitBE;
/* check extension, case insensitive */ /* check extension, case insensitive */
streamFile->get_name(streamFile,filename,sizeof(filename)); streamFile->get_name(streamFile,filename,sizeof(filename));
if (strcasecmp("rsd",filename_extension(filename))) goto fail; if (strcasecmp("rsd", filename_extension(filename))) goto fail;
/* decrypt into buffer */ /* decrypt into buffer */
{ {
uint32_t data; uint32_t data;
int i; int i;
if (read_streamfile(buf,0,encsize,streamFile)!=encsize) goto fail; if (read_streamfile(buf,0,encsize,streamFile)!=encsize) goto fail;
if (memcmp(&buf[0], "RedSpark", 8)) { //Check to see if already decrypted
key = find_key(get_32bitBE(&buf[0]));
data = get_32bitBE(&buf[0]) ^ key;
put_32bitBE(&buf[0], data);
key = rotlwi(key, 11);
key = find_key(get_32bitBE(&buf[0])); for (i = 4; i < encsize; i += 4) {
data = get_32bitBE(&buf[0]) ^ key; key = rotlwi(key, 3) + key;
put_32bitBE(&buf[0], data); data = get_32bitBE(&buf[i]) ^ key;
key = rotlwi(key,11); put_32bitBE(&buf[i], data);
}
}
else {
get_16bit = get_16bitLE;
get_32bit = get_32bitLE;
dt_flag = 1;
for (i=4; i < encsize; i+=4) { for (i = 4; i < encsize; i += 4) {
key = rotlwi(key,3) + key; data = get_32bitBE(&buf[i]);
data = get_32bitBE(&buf[i]) ^ key; put_32bitBE(&buf[i], data);
put_32bitBE(&buf[i], data); }
} }
} }
/* check header */ /* check header */
@ -61,14 +77,23 @@ VGMSTREAM * init_vgmstream_RedSpark(STREAMFILE *streamFile) {
/* fill in the vital statistics */ /* fill in the vital statistics */
start_offset = 0x1000; start_offset = 0x1000;
vgmstream->channels = channel_count; vgmstream->channels = channel_count;
vgmstream->sample_rate = get_32bitBE(&buf[0x3c]); vgmstream->sample_rate = get_32bit(&buf[0x3c]);
vgmstream->coding_type = coding_NGC_DSP; vgmstream->coding_type = coding_NGC_DSP;
vgmstream->num_samples = get_32bitBE(&buf[0x40])*14; if (dt_flag)
vgmstream->num_samples = get_32bit(&buf[0x40]);
else
vgmstream->num_samples = get_32bit(&buf[0x40])*14;
if (loop_flag) { if (loop_flag) {
off_t start = 0x54; off_t start = 0x54;
start += channel_count*8; start += channel_count*8;
vgmstream->loop_start_sample = get_32bitBE(&buf[start+4])*14; if (dt_flag) {
vgmstream->loop_end_sample = (get_32bitBE(&buf[start+0xc])+1)*14; vgmstream->loop_start_sample = get_32bit(&buf[start+4]);
vgmstream->loop_end_sample = (get_32bit(&buf[start+0xc]));
}
else {
vgmstream->loop_start_sample = get_32bit(&buf[start+4])*14;
vgmstream->loop_end_sample = (get_32bit(&buf[start+0xc])+1)*14;
}
if (vgmstream->loop_end_sample > vgmstream->num_samples) { if (vgmstream->loop_end_sample > vgmstream->num_samples) {
vgmstream->loop_end_sample = vgmstream->num_samples; vgmstream->loop_end_sample = vgmstream->num_samples;
} }
@ -95,7 +120,7 @@ VGMSTREAM * init_vgmstream_RedSpark(STREAMFILE *streamFile) {
for (j = 0; j < channel_count; j++) { for (j = 0; j < channel_count; j++) {
for (i=0;i<16;i++) { for (i=0;i<16;i++) {
vgmstream->ch[j].adpcm_coef[i] = vgmstream->ch[j].adpcm_coef[i] =
get_16bitBE(&buf[start+0x2e*j+i*2]); get_16bit(&buf[start+0x2e*j+i*2]);
} }
} }
} }