2016-11-12 00:39:40 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2019-06-23 22:25:06 +02:00
|
|
|
#include "meta.h"
|
2019-10-18 19:34:15 +02:00
|
|
|
#include "../coding/coding.h"
|
2019-06-23 22:25:06 +02:00
|
|
|
#include "ogg_vorbis_streamfile.h"
|
2016-11-12 00:39:40 +01:00
|
|
|
|
|
|
|
|
2021-09-27 00:10:28 +02:00
|
|
|
#ifdef VGM_USE_VORBIS
|
|
|
|
static VGMSTREAM* _init_vgmstream_ogg_vorbis(STREAMFILE* sf);
|
|
|
|
static VGMSTREAM* _init_vgmstream_ogg_vorbis_config(STREAMFILE* sf, off_t start, const ogg_vorbis_meta_info_t* ovmi);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
VGMSTREAM* init_vgmstream_ogg_vorbis(STREAMFILE* sf) {
|
|
|
|
#ifdef VGM_USE_VORBIS
|
|
|
|
return _init_vgmstream_ogg_vorbis(sf);
|
|
|
|
#else
|
|
|
|
return NULL;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
VGMSTREAM* init_vgmstream_ogg_vorbis_config(STREAMFILE* sf, off_t start, const ogg_vorbis_meta_info_t* ovmi) {
|
|
|
|
#ifdef VGM_USE_VORBIS
|
|
|
|
return _init_vgmstream_ogg_vorbis_config(sf, start, ovmi);
|
|
|
|
#else
|
|
|
|
return NULL;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef VGM_USE_VORBIS
|
2020-09-27 22:01:14 +02:00
|
|
|
static void um3_ogg_decryption_callback(void* ptr, size_t size, size_t nmemb, void* datasource) {
|
2019-10-18 19:34:15 +02:00
|
|
|
uint8_t *ptr8 = ptr;
|
|
|
|
size_t bytes_read = size * nmemb;
|
|
|
|
ogg_vorbis_io *io = datasource;
|
2018-01-10 21:12:23 +01:00
|
|
|
int i;
|
2016-11-12 00:39:40 +01:00
|
|
|
|
2018-10-04 20:43:23 +02:00
|
|
|
/* first 0x800 bytes are xor'd */
|
2019-10-18 19:34:15 +02:00
|
|
|
if (io->offset < 0x800) {
|
|
|
|
int num_crypt = 0x800 - io->offset;
|
2018-01-10 21:12:23 +01:00
|
|
|
if (num_crypt > bytes_read)
|
|
|
|
num_crypt = bytes_read;
|
2016-11-12 00:39:40 +01:00
|
|
|
|
2018-01-10 21:12:23 +01:00
|
|
|
for (i = 0; i < num_crypt; i++)
|
2019-10-18 19:34:15 +02:00
|
|
|
ptr8[i] ^= 0xff;
|
2018-01-10 21:12:23 +01:00
|
|
|
}
|
|
|
|
}
|
2016-11-12 00:39:40 +01:00
|
|
|
|
2020-09-27 22:01:14 +02:00
|
|
|
static void kovs_ogg_decryption_callback(void* ptr, size_t size, size_t nmemb, void* datasource) {
|
2019-10-18 19:34:15 +02:00
|
|
|
uint8_t *ptr8 = ptr;
|
|
|
|
size_t bytes_read = size * nmemb;
|
|
|
|
ogg_vorbis_io *io = datasource;
|
2018-01-10 21:12:23 +01:00
|
|
|
int i;
|
2016-11-12 00:39:40 +01:00
|
|
|
|
2018-10-04 20:43:23 +02:00
|
|
|
/* first 0x100 bytes are xor'd */
|
2019-10-18 19:34:15 +02:00
|
|
|
if (io->offset < 0x100) {
|
|
|
|
int max_offset = io->offset + bytes_read;
|
2018-01-10 21:12:23 +01:00
|
|
|
if (max_offset > 0x100)
|
|
|
|
max_offset = 0x100;
|
|
|
|
|
2019-10-18 19:34:15 +02:00
|
|
|
for (i = io->offset; i < max_offset; i++) {
|
|
|
|
ptr8[i-io->offset] ^= i;
|
2016-11-12 00:39:40 +01:00
|
|
|
}
|
|
|
|
}
|
2018-01-10 21:12:23 +01:00
|
|
|
}
|
|
|
|
|
2020-09-27 22:01:14 +02:00
|
|
|
static void psychic_ogg_decryption_callback(void* ptr, size_t size, size_t nmemb, void* datasource) {
|
2019-10-18 19:34:15 +02:00
|
|
|
static const uint8_t key[6] = {
|
|
|
|
0x23,0x31,0x20,0x2e,0x2e,0x28
|
|
|
|
};
|
|
|
|
uint8_t *ptr8 = ptr;
|
|
|
|
size_t bytes_read = size * nmemb;
|
|
|
|
ogg_vorbis_io *io = datasource;
|
2018-01-10 21:12:23 +01:00
|
|
|
int i;
|
2016-11-12 00:39:40 +01:00
|
|
|
|
2019-08-10 17:27:06 +02:00
|
|
|
//todo incorrect, picked value changes (fixed order for all files), or key is bigger
|
|
|
|
/* bytes add key that changes every 0x64 bytes */
|
2018-04-20 17:02:56 +02:00
|
|
|
for (i = 0; i < bytes_read; i++) {
|
2019-10-18 19:34:15 +02:00
|
|
|
int pos = (io->offset + i) / 0x64;
|
|
|
|
ptr8[i] += key[pos % sizeof(key)];
|
2016-11-12 00:39:40 +01:00
|
|
|
}
|
2018-01-10 21:12:23 +01:00
|
|
|
}
|
2016-11-12 00:39:40 +01:00
|
|
|
|
2020-09-27 22:01:14 +02:00
|
|
|
static void rpgmvo_ogg_decryption_callback(void* ptr, size_t size, size_t nmemb, void* datasource) {
|
2018-04-07 19:04:06 +02:00
|
|
|
static const uint8_t header[16] = { /* OggS, packet type, granule, stream id(empty) */
|
|
|
|
0x4F,0x67,0x67,0x53,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
|
|
|
|
};
|
2019-10-18 19:34:15 +02:00
|
|
|
uint8_t *ptr8 = ptr;
|
2018-04-07 19:04:06 +02:00
|
|
|
size_t bytes_read = size*nmemb;
|
2019-10-18 19:34:15 +02:00
|
|
|
ogg_vorbis_io *io = datasource;
|
2018-04-07 19:04:06 +02:00
|
|
|
int i;
|
|
|
|
|
2018-10-04 20:43:23 +02:00
|
|
|
/* first 0x10 are xor'd, but header can be easily reconstructed
|
2018-04-07 19:04:06 +02:00
|
|
|
* (key is also in (game)/www/data/System.json "encryptionKey") */
|
|
|
|
for (i = 0; i < bytes_read; i++) {
|
2019-10-18 19:34:15 +02:00
|
|
|
if (io->offset+i < 0x10) {
|
|
|
|
ptr8[i] = header[(io->offset + i) % 16];
|
2018-04-07 19:04:06 +02:00
|
|
|
|
|
|
|
/* last two bytes are the stream id, get from next OggS */
|
2019-10-18 19:34:15 +02:00
|
|
|
if (io->offset+i == 0x0e)
|
|
|
|
ptr8[i] = read_8bit(0x58, io->streamfile);
|
|
|
|
if (io->offset+i == 0x0f)
|
|
|
|
ptr8[i] = read_8bit(0x59, io->streamfile);
|
2018-04-07 19:04:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-21 22:09:11 +01:00
|
|
|
static void at4_ogg_decryption_callback(void* ptr, size_t size, size_t nmemb, void* datasource) {
|
|
|
|
static const uint8_t af4_key[0x10] = {
|
|
|
|
0x00,0x0E,0x08,0x1E, 0x18,0x37,0x12,0x00, 0x48,0x87,0x46,0x0B, 0x9C,0x68,0xA8,0x4B
|
|
|
|
};
|
|
|
|
uint8_t *ptr8 = ptr;
|
|
|
|
size_t bytes_read = size * nmemb;
|
|
|
|
ogg_vorbis_io *io = datasource;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < bytes_read; i++) {
|
|
|
|
ptr8[i] -= af4_key[(io->offset + i) % sizeof(af4_key)];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-04 20:43:23 +02:00
|
|
|
|
2019-03-02 15:57:41 +01:00
|
|
|
static const uint32_t xiph_mappings[] = {
|
|
|
|
0,
|
|
|
|
mapping_MONO,
|
|
|
|
mapping_STEREO,
|
|
|
|
mapping_2POINT1_xiph,
|
|
|
|
mapping_QUAD,
|
|
|
|
mapping_5POINT0_xiph,
|
|
|
|
mapping_5POINT1,
|
|
|
|
mapping_7POINT0,
|
|
|
|
mapping_7POINT1,
|
|
|
|
};
|
|
|
|
|
2018-06-30 13:43:12 +02:00
|
|
|
|
2021-10-31 20:09:18 +01:00
|
|
|
static VGMSTREAM* _init_vgmstream_ogg_vorbis_cfg_ovmi(STREAMFILE* sf, ogg_vorbis_io_config_data* cfg, ogg_vorbis_meta_info_t* ovmi) {
|
2020-09-27 22:01:14 +02:00
|
|
|
VGMSTREAM* vgmstream = NULL;
|
|
|
|
STREAMFILE* temp_sf = NULL;
|
2021-10-31 20:09:18 +01:00
|
|
|
|
|
|
|
|
|
|
|
if (cfg->is_encrypted) {
|
|
|
|
temp_sf = setup_ogg_vorbis_streamfile(sf, cfg);
|
|
|
|
if (!temp_sf) goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ovmi->meta_type == 0) {
|
|
|
|
if (cfg->is_encrypted || ovmi->decryption_callback != NULL)
|
|
|
|
ovmi->meta_type = meta_OGG_encrypted;
|
|
|
|
else
|
|
|
|
ovmi->meta_type = meta_OGG_VORBIS;
|
|
|
|
}
|
|
|
|
|
|
|
|
vgmstream = _init_vgmstream_ogg_vorbis_config(temp_sf != NULL ? temp_sf : sf, cfg->start, ovmi);
|
|
|
|
|
|
|
|
close_streamfile(temp_sf);
|
|
|
|
return vgmstream;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
close_streamfile(temp_sf);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Ogg Vorbis - standard .ogg with (possibly) loop comments/metadata */
|
|
|
|
static VGMSTREAM* _init_vgmstream_ogg_vorbis_common(STREAMFILE* sf) {
|
2019-06-23 22:25:06 +02:00
|
|
|
ogg_vorbis_io_config_data cfg = {0};
|
2018-03-23 16:34:48 +01:00
|
|
|
ogg_vorbis_meta_info_t ovmi = {0};
|
2018-01-10 21:12:23 +01:00
|
|
|
|
|
|
|
int is_ogg = 0;
|
|
|
|
int is_um3 = 0;
|
|
|
|
int is_kovs = 0;
|
2018-01-10 22:34:14 +01:00
|
|
|
int is_sngw = 0;
|
2018-01-13 15:22:58 +01:00
|
|
|
int is_isd = 0;
|
2018-04-07 19:04:06 +02:00
|
|
|
int is_rpgmvo = 0;
|
2018-04-12 22:46:18 +02:00
|
|
|
int is_eno = 0;
|
2018-05-19 11:37:21 +02:00
|
|
|
int is_gwm = 0;
|
2018-06-30 13:43:12 +02:00
|
|
|
int is_mus = 0;
|
2018-09-27 23:41:26 +02:00
|
|
|
int is_lse = 0;
|
2019-08-02 17:31:00 +02:00
|
|
|
int is_bgm = 0;
|
2018-01-10 21:12:23 +01:00
|
|
|
|
|
|
|
|
|
|
|
/* check extension */
|
2018-07-27 17:30:58 +02:00
|
|
|
/* .ogg: standard/various, .logg: renamed for plugins
|
2019-10-18 19:34:15 +02:00
|
|
|
* .adx: KID games [Remember11 (PC)]
|
2018-03-16 17:43:51 +01:00
|
|
|
* .rof: The Rhythm of Fighters (Mobile)
|
2018-09-09 12:24:28 +02:00
|
|
|
* .acm: Planescape Torment Enhanced Edition (PC)
|
2019-04-07 01:47:07 +02:00
|
|
|
* .sod: Zone 4 (PC)
|
2021-05-25 23:34:42 +02:00
|
|
|
* .msa: Metal Slug Attack (Mobile)
|
2019-04-07 01:47:07 +02:00
|
|
|
* .aif/laif/aif-Loop: Psychonauts (PC) raw extractions (named) */
|
2021-05-25 23:34:42 +02:00
|
|
|
if (check_extensions(sf,"ogg,logg,adx,rof,acm,sod,msa,aif,laif,aif-Loop")) {
|
2018-01-10 21:12:23 +01:00
|
|
|
is_ogg = 1;
|
2020-09-27 22:01:14 +02:00
|
|
|
} else if (check_extensions(sf,"um3")) {
|
2018-01-10 21:12:23 +01:00
|
|
|
is_um3 = 1;
|
2020-09-27 22:01:14 +02:00
|
|
|
} else if (check_extensions(sf,"kvs,kovs")) {
|
2019-10-18 19:34:15 +02:00
|
|
|
/* .kvs: Atelier Sophie (PC), kovs: header id only? */
|
2018-01-10 21:12:23 +01:00
|
|
|
is_kovs = 1;
|
2020-09-27 22:01:14 +02:00
|
|
|
} else if (check_extensions(sf,"sngw")) { /* .sngw: Capcom [Devil May Cry 4 SE (PC), Biohazard 6 (PC)] */
|
2018-01-10 22:34:14 +01:00
|
|
|
is_sngw = 1;
|
2020-09-27 22:01:14 +02:00
|
|
|
} else if (check_extensions(sf,"isd")) { /* .isd: Inti Creates PC games */
|
2018-01-13 15:22:58 +01:00
|
|
|
is_isd = 1;
|
2021-10-14 14:58:55 +02:00
|
|
|
} else if (check_extensions(sf,"rpgmvo,ogg_")) {
|
|
|
|
/* .rpgmvo: RPG Maker MV games (PC), .ogg_: RPG Maker MZ games (PC) */
|
2018-04-07 19:04:06 +02:00
|
|
|
is_rpgmvo = 1;
|
2020-09-27 22:01:14 +02:00
|
|
|
} else if (check_extensions(sf,"eno")) { /* .eno: Metronomicon (PC) */
|
2018-04-12 22:46:18 +02:00
|
|
|
is_eno = 1;
|
2020-09-27 22:01:14 +02:00
|
|
|
} else if (check_extensions(sf,"gwm")) { /* .gwm: Adagio: Cloudburst (PC) */
|
2018-05-19 11:37:21 +02:00
|
|
|
is_gwm = 1;
|
2020-09-27 22:01:14 +02:00
|
|
|
} else if (check_extensions(sf,"mus")) { /* .mus: Redux - Dark Matters (PC) */
|
2018-06-30 13:43:12 +02:00
|
|
|
is_mus = 1;
|
2020-09-27 22:01:14 +02:00
|
|
|
} else if (check_extensions(sf,"lse")) { /* .lse: Labyrinth of Refrain: Coven of Dusk (PC) */
|
2018-09-27 23:41:26 +02:00
|
|
|
is_lse = 1;
|
2020-09-27 22:01:14 +02:00
|
|
|
} else if (check_extensions(sf,"bgm")) { /* .bgm: Fortissimo (PC) */
|
2019-08-02 17:31:00 +02:00
|
|
|
is_bgm = 1;
|
2018-01-10 21:12:23 +01:00
|
|
|
} else {
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_ogg) {
|
2021-02-21 22:09:11 +01:00
|
|
|
if (read_u32be(0x00,sf) == 0x2c444430) { /* Psychic Software [Darkwind: War on Wheels (PC)] */
|
2018-03-23 16:34:48 +01:00
|
|
|
ovmi.decryption_callback = psychic_ogg_decryption_callback;
|
2016-11-12 00:39:40 +01:00
|
|
|
}
|
2021-02-21 22:09:11 +01:00
|
|
|
else if (read_u32be(0x00,sf) == 0x4C325344) { /* "L2SD" instead of "OggS" [Lineage II Chronicle 4 (PC)] */
|
2019-06-23 22:25:06 +02:00
|
|
|
cfg.is_header_swap = 1;
|
|
|
|
cfg.is_encrypted = 1;
|
2018-02-17 02:23:45 +01:00
|
|
|
}
|
2021-02-21 22:09:11 +01:00
|
|
|
else if (read_u32be(0x00,sf) == 0x048686C5) { /* "OggS" XOR'ed + bitswapped [Ys VIII (PC)] */
|
2019-06-23 22:25:06 +02:00
|
|
|
cfg.key[0] = 0xF0;
|
|
|
|
cfg.key_len = 1;
|
|
|
|
cfg.is_nibble_swap = 1;
|
|
|
|
cfg.is_encrypted = 1;
|
|
|
|
|
|
|
|
}
|
2021-02-21 22:09:11 +01:00
|
|
|
else if (read_u32be(0x00,sf) == 0x00000000 && /* null instead of "OggS" [Yuppie Psycho (PC)] */
|
|
|
|
read_u32be(0x3a,sf) == 0x4F676753) { /* "OggS" in next page */
|
2019-06-23 22:25:06 +02:00
|
|
|
cfg.is_header_swap = 1;
|
|
|
|
cfg.is_encrypted = 1;
|
2018-04-20 17:02:56 +02:00
|
|
|
}
|
2021-02-21 22:09:11 +01:00
|
|
|
else if (read_u32be(0x00,sf) != 0x4F676753 && /* random(?) swap instead of "OggS" [Tobi Tsukihime (PC)] */
|
|
|
|
read_u32be(0x3a,sf) == 0x4F676753) { /* "OggS" in next page */
|
2020-09-27 22:01:14 +02:00
|
|
|
cfg.is_header_swap = 1;
|
|
|
|
cfg.is_encrypted = 1;
|
|
|
|
}
|
2021-02-21 22:09:11 +01:00
|
|
|
else if (read_u32be(0x00,sf) == 0x4F756F71) { /* "OggS" encrypted [Adventure Field 4 (PC)]*/
|
|
|
|
ovmi.decryption_callback = at4_ogg_decryption_callback;
|
|
|
|
}
|
|
|
|
else if (read_u32be(0x00,sf) == 0x4F676753) { /* "OggS" (standard) */
|
2019-09-14 23:03:31 +02:00
|
|
|
;
|
2018-05-19 11:24:20 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
goto fail; /* unknown/not Ogg Vorbis (ex. Wwise) */
|
2016-11-12 00:39:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-04 20:43:23 +02:00
|
|
|
if (is_um3) { /* ["Ultramarine3" (???)] */
|
2021-02-21 22:09:11 +01:00
|
|
|
if (read_u32be(0x00,sf) != 0x4f676753) { /* "OggS" (optionally encrypted) */
|
2018-03-23 16:34:48 +01:00
|
|
|
ovmi.decryption_callback = um3_ogg_decryption_callback;
|
2018-01-10 21:12:23 +01:00
|
|
|
}
|
2016-11-12 00:39:40 +01:00
|
|
|
}
|
|
|
|
|
2019-06-23 22:25:06 +02:00
|
|
|
if (is_kovs) { /* Koei Tecmo PC games */
|
2021-02-21 22:09:11 +01:00
|
|
|
if (read_u32be(0x00,sf) != 0x4b4f5653) { /* "KOVS" */
|
2018-01-10 21:12:23 +01:00
|
|
|
goto fail;
|
|
|
|
}
|
2020-09-27 22:01:14 +02:00
|
|
|
ovmi.loop_start = read_32bitLE(0x08,sf);
|
2018-03-23 16:34:48 +01:00
|
|
|
ovmi.loop_flag = (ovmi.loop_start != 0);
|
|
|
|
ovmi.decryption_callback = kovs_ogg_decryption_callback;
|
2018-05-19 11:24:20 +02:00
|
|
|
ovmi.meta_type = meta_OGG_KOVS;
|
2018-01-10 21:12:23 +01:00
|
|
|
|
2021-10-31 20:09:18 +01:00
|
|
|
cfg.start = 0x20;
|
2016-11-12 00:39:40 +01:00
|
|
|
}
|
|
|
|
|
2018-10-04 20:43:23 +02:00
|
|
|
if (is_sngw) { /* [Capcom's MT Framework PC games] */
|
2021-02-21 22:09:11 +01:00
|
|
|
if (read_u32be(0x00,sf) != 0x4f676753) { /* "OggS" (optionally encrypted) */
|
2020-09-27 22:01:14 +02:00
|
|
|
cfg.key_len = read_streamfile(cfg.key, 0x00, 0x04, sf);
|
2019-06-23 22:25:06 +02:00
|
|
|
cfg.is_header_swap = 1;
|
|
|
|
cfg.is_nibble_swap = 1;
|
|
|
|
cfg.is_encrypted = 1;
|
2018-01-10 22:34:14 +01:00
|
|
|
}
|
2019-06-23 22:25:06 +02:00
|
|
|
|
2019-03-24 02:45:03 +01:00
|
|
|
ovmi.disable_reordering = 1; /* must be an MT Framework thing */
|
2018-01-10 22:34:14 +01:00
|
|
|
}
|
|
|
|
|
2019-06-23 22:25:06 +02:00
|
|
|
if (is_isd) { /* Inti Creates PC games */
|
2019-06-23 23:20:43 +02:00
|
|
|
const char *isl_name = NULL;
|
2019-06-23 22:25:06 +02:00
|
|
|
|
|
|
|
/* check various encrypted "OggS" values */
|
2021-02-21 22:09:11 +01:00
|
|
|
if (read_u32be(0x00,sf) == 0xAF678753) { /* Azure Striker Gunvolt (PC) */
|
2019-06-23 22:25:06 +02:00
|
|
|
static const uint8_t isd_gv_key[16] = {
|
|
|
|
0xe0,0x00,0xe0,0x00,0xa0,0x00,0x00,0x00,0xe0,0x00,0xe0,0x80,0x40,0x40,0x40,0x00
|
|
|
|
};
|
|
|
|
cfg.key_len = sizeof(isd_gv_key);
|
|
|
|
memcpy(cfg.key, isd_gv_key, cfg.key_len);
|
2019-06-23 23:20:43 +02:00
|
|
|
isl_name = "GV_steam.isl";
|
2019-06-23 22:25:06 +02:00
|
|
|
}
|
2021-02-21 22:09:11 +01:00
|
|
|
else if (read_u32be(0x00,sf) == 0x0FE787D3) { /* Mighty Gunvolt (PC) */
|
2019-06-23 22:25:06 +02:00
|
|
|
static const uint8_t isd_mgv_key[120] = {
|
|
|
|
0x40,0x80,0xE0,0x80,0x40,0x40,0xA0,0x00,0xA0,0x40,0x00,0x80,0x00,0x40,0xA0,0x00,
|
|
|
|
0xC0,0x40,0xE0,0x00,0x60,0x40,0x80,0x00,0xA0,0x00,0xE0,0x00,0x60,0x40,0xC0,0x00,
|
|
|
|
0xA0,0x40,0xC0,0x80,0xE0,0x00,0x60,0x00,0x00,0x40,0x00,0x80,0xE0,0x80,0x40,0x00,
|
|
|
|
0xA0,0x80,0xA0,0x80,0x80,0xC0,0x60,0x00,0xA0,0x00,0xA0,0x80,0x40,0x80,0x60,0x00,
|
|
|
|
0x40,0xC0,0x20,0x00,0x20,0xC0,0x00,0x00,0x00,0xC0,0x20,0x00,0xC0,0xC0,0x60,0x00,
|
|
|
|
0xE0,0xC0,0x80,0x80,0x20,0x00,0x60,0x00,0xE0,0xC0,0xC0,0x00,0x20,0xC0,0xC0,0x00,
|
|
|
|
0x60,0x00,0xE0,0x80,0x00,0xC0,0x00,0x00,0x60,0x80,0x40,0x80,0x20,0x80,0x20,0x00,
|
|
|
|
0x80,0x40,0xE0,0x00,0x20,0x00,0x20,0x00,
|
|
|
|
};
|
|
|
|
cfg.key_len = sizeof(isd_mgv_key);
|
|
|
|
memcpy(cfg.key, isd_mgv_key, cfg.key_len);
|
2019-06-23 23:20:43 +02:00
|
|
|
isl_name = "MGV_steam.isl";
|
2019-06-23 22:25:06 +02:00
|
|
|
}
|
2021-02-21 22:09:11 +01:00
|
|
|
else if (read_u32be(0x00,sf) == 0x0FA74753) { /* Blaster Master Zero (PC) */
|
2019-06-23 22:25:06 +02:00
|
|
|
static const uint8_t isd_bmz_key[120] = {
|
|
|
|
0x40,0xC0,0x20,0x00,0x40,0xC0,0xC0,0x00,0x00,0x80,0xE0,0x80,0x80,0x40,0x20,0x00,
|
|
|
|
0x60,0xC0,0xC0,0x00,0xA0,0x80,0x60,0x00,0x40,0x40,0x20,0x00,0x60,0x40,0xC0,0x00,
|
|
|
|
0x60,0x80,0xC0,0x80,0x40,0xC0,0x00,0x00,0xA0,0xC0,0x80,0x80,0x60,0x80,0xA0,0x00,
|
|
|
|
0x40,0x80,0x60,0x00,0x20,0x00,0xC0,0x00,0x60,0x00,0xA0,0x80,0x40,0x40,0xA0,0x00,
|
|
|
|
0x40,0x40,0xC0,0x80,0x00,0x80,0x60,0x00,0x80,0xC0,0xA0,0x00,0xE0,0x40,0xC0,0x00,
|
|
|
|
0x20,0x80,0xE0,0x00,0x40,0xC0,0xA0,0x00,0xE0,0xC0,0xC0,0x80,0xE0,0x80,0xC0,0x00,
|
|
|
|
0x40,0x40,0x00,0x00,0x20,0x40,0x80,0x00,0xE0,0x80,0x20,0x80,0x40,0x80,0xE0,0x00,
|
|
|
|
0xA0,0x00,0xC0,0x80,0xE0,0x00,0x20,0x00
|
|
|
|
};
|
|
|
|
cfg.key_len = sizeof(isd_bmz_key);
|
|
|
|
memcpy(cfg.key, isd_bmz_key, cfg.key_len);
|
2019-06-23 23:20:43 +02:00
|
|
|
isl_name = "output.isl";
|
2019-06-23 22:25:06 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
goto fail;
|
|
|
|
}
|
2018-01-13 15:22:58 +01:00
|
|
|
|
2019-06-23 22:25:06 +02:00
|
|
|
cfg.is_encrypted = 1;
|
|
|
|
|
|
|
|
/* .isd have companion files in the prev folder:
|
|
|
|
* - .ish: constant id/names (not always)
|
|
|
|
* - .isf: format table, ordered like file id/numbers, 0x18 header with:
|
|
|
|
* 0x00(2): ?, 0x02(2): channels, 0x04: sample rate, 0x08: skip samples (in PCM bytes), always 32000
|
|
|
|
* 0x0c(2): PCM block size, 0x0e(2): PCM bps, 0x10: null, 0x18: samples (in PCM bytes)
|
|
|
|
* - .isl: looping table (encrypted like the files) */
|
2019-06-23 23:20:43 +02:00
|
|
|
if (isl_name) {
|
2021-07-29 23:20:43 +02:00
|
|
|
STREAMFILE* sf_isl = NULL;
|
2019-06-23 23:20:43 +02:00
|
|
|
|
2021-07-29 23:20:43 +02:00
|
|
|
sf_isl = open_streamfile_by_filename(sf, isl_name);
|
2019-09-24 00:51:12 +02:00
|
|
|
|
2021-07-29 23:20:43 +02:00
|
|
|
if (!sf_isl) {
|
2019-09-24 00:51:12 +02:00
|
|
|
/* try in ../(file) too since that's how the .isl is stored on disc */
|
|
|
|
char isl_path[PATH_LIMIT];
|
|
|
|
snprintf(isl_path, sizeof(isl_path), "../%s", isl_name);
|
2021-07-29 23:20:43 +02:00
|
|
|
sf_isl = open_streamfile_by_filename(sf, isl_path);
|
2019-09-24 00:51:12 +02:00
|
|
|
}
|
|
|
|
|
2021-07-29 23:20:43 +02:00
|
|
|
if (sf_isl) {
|
2020-09-27 22:01:14 +02:00
|
|
|
STREAMFILE* dec_sf = NULL;
|
2019-06-23 23:20:43 +02:00
|
|
|
|
2021-10-31 20:09:18 +01:00
|
|
|
dec_sf = setup_ogg_vorbis_streamfile(sf_isl, &cfg);
|
2019-06-23 23:20:43 +02:00
|
|
|
if (dec_sf) {
|
|
|
|
off_t loop_offset;
|
|
|
|
char basename[PATH_LIMIT];
|
|
|
|
|
|
|
|
/* has a bunch of tables then a list with file names without extension and loops */
|
|
|
|
loop_offset = read_32bitLE(0x18, dec_sf);
|
2020-09-27 22:01:14 +02:00
|
|
|
get_streamfile_basename(sf, basename, sizeof(basename));
|
2019-06-23 23:20:43 +02:00
|
|
|
|
|
|
|
while (loop_offset < get_streamfile_size(dec_sf)) {
|
|
|
|
char testname[0x20];
|
|
|
|
|
|
|
|
read_string(testname, sizeof(testname), loop_offset+0x2c, dec_sf);
|
|
|
|
if (strcmp(basename, testname) == 0) {
|
|
|
|
ovmi.loop_start = read_32bitLE(loop_offset+0x1c, dec_sf);
|
|
|
|
ovmi.loop_end = read_32bitLE(loop_offset+0x20, dec_sf);
|
|
|
|
ovmi.loop_end_found = 1;
|
|
|
|
ovmi.loop_flag = (ovmi.loop_end != 0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
loop_offset += 0x50;
|
|
|
|
}
|
|
|
|
|
|
|
|
close_streamfile(dec_sf);
|
|
|
|
}
|
|
|
|
|
2021-07-29 23:20:43 +02:00
|
|
|
close_streamfile(sf_isl);
|
2019-06-23 23:20:43 +02:00
|
|
|
}
|
|
|
|
}
|
2018-01-13 15:22:58 +01:00
|
|
|
}
|
|
|
|
|
2021-10-14 14:58:55 +02:00
|
|
|
if (is_rpgmvo) { /* [RPG Maker MV (PC), RPG Maker MZ (PC)] */
|
2020-09-27 22:01:14 +02:00
|
|
|
if (read_32bitBE(0x00,sf) != 0x5250474D && /* "RPGM" */
|
|
|
|
read_32bitBE(0x00,sf) != 0x56000000) { /* "V\0\0\0" */
|
2018-04-07 19:04:06 +02:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
ovmi.decryption_callback = rpgmvo_ogg_decryption_callback;
|
|
|
|
|
2021-10-31 20:09:18 +01:00
|
|
|
cfg.start = 0x10;
|
2018-04-07 19:04:06 +02:00
|
|
|
}
|
|
|
|
|
2018-10-04 20:43:23 +02:00
|
|
|
if (is_eno) { /* [Metronomicon (PC)] */
|
2019-06-23 22:25:06 +02:00
|
|
|
/* first byte probably derives into key, but this works too */
|
2021-10-31 20:09:18 +01:00
|
|
|
cfg.key[0] = read_u8(0x05,sf); /* regular ogg have a zero at this offset = easy key */
|
2019-06-23 22:25:06 +02:00
|
|
|
cfg.key_len = 1;
|
|
|
|
cfg.is_encrypted = 1;
|
2021-10-31 20:09:18 +01:00
|
|
|
cfg.start = 0x01; /* "OggS" starts after key-thing */
|
2018-04-20 17:02:56 +02:00
|
|
|
}
|
2018-01-10 22:34:14 +01:00
|
|
|
|
2018-10-04 20:43:23 +02:00
|
|
|
if (is_gwm) { /* [Adagio: Cloudburst (PC)] */
|
2019-06-23 22:25:06 +02:00
|
|
|
cfg.key[0] = 0x5D;
|
|
|
|
cfg.key_len = 1;
|
|
|
|
cfg.is_encrypted = 1;
|
2018-05-19 11:37:21 +02:00
|
|
|
}
|
|
|
|
|
2019-10-18 19:34:15 +02:00
|
|
|
if (is_mus) { /* [Redux: Dark Matters (PC)] */
|
2019-06-23 22:25:06 +02:00
|
|
|
static const uint8_t mus_key[16] = {
|
|
|
|
0x21,0x4D,0x6F,0x01,0x20,0x4C,0x6E,0x02,0x1F,0x4B,0x6D,0x03,0x20,0x4C,0x6E,0x02
|
|
|
|
};
|
|
|
|
cfg.key_len = sizeof(mus_key);
|
|
|
|
memcpy(cfg.key, mus_key, cfg.key_len);
|
|
|
|
cfg.is_header_swap = 1; /* decrypted header gives "Mus " */
|
|
|
|
cfg.is_encrypted = 1;
|
2018-06-30 13:43:12 +02:00
|
|
|
}
|
|
|
|
|
2018-10-04 20:43:23 +02:00
|
|
|
if (is_lse) { /* [Nippon Ichi PC games] */
|
2021-07-29 17:08:30 +02:00
|
|
|
if (read_u32be(0x00,sf) == 0xFFFFFFFF) { /* [Operation Abyss: New Tokyo Legacy (PC)] */
|
2019-06-23 22:25:06 +02:00
|
|
|
cfg.key[0] = 0xFF;
|
|
|
|
cfg.key_len = 1;
|
|
|
|
cfg.is_header_swap = 1;
|
|
|
|
cfg.is_encrypted = 1;
|
2018-10-04 20:43:23 +02:00
|
|
|
}
|
|
|
|
else { /* [Operation Babel: New Tokyo Legacy (PC), Labyrinth of Refrain: Coven of Dusk (PC)] */
|
2019-06-23 22:25:06 +02:00
|
|
|
int i;
|
|
|
|
/* found at file_size-1 but this works too (same key for most files but can vary) */
|
2021-10-31 20:09:18 +01:00
|
|
|
uint8_t base_key = read_u8(0x04,sf) - 0x04;
|
2019-06-23 22:25:06 +02:00
|
|
|
|
|
|
|
cfg.key_len = 256;
|
|
|
|
for (i = 0; i < cfg.key_len; i++) {
|
|
|
|
cfg.key[i] = (uint8_t)(base_key + i);
|
|
|
|
}
|
|
|
|
cfg.is_encrypted = 1;
|
2019-08-02 17:31:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_bgm) { /* [Fortissimo (PC)] */
|
2021-10-31 20:09:18 +01:00
|
|
|
uint32_t file_size = get_streamfile_size(sf);
|
2019-08-02 17:31:00 +02:00
|
|
|
uint8_t key[0x04];
|
|
|
|
uint32_t xor_be;
|
|
|
|
|
2021-10-31 20:09:18 +01:00
|
|
|
put_u32le(key, file_size);
|
2021-02-21 22:09:11 +01:00
|
|
|
xor_be = get_u32be(key);
|
2021-10-31 20:09:18 +01:00
|
|
|
if ((read_u32be(0x00,sf) ^ xor_be) == get_id32be("OggS")) {
|
2019-08-02 17:31:00 +02:00
|
|
|
int i;
|
|
|
|
cfg.key_len = 4;
|
|
|
|
for (i = 0; i < cfg.key_len; i++) {
|
|
|
|
cfg.key[i] = key[i];
|
|
|
|
}
|
|
|
|
cfg.is_encrypted = 1;
|
2018-10-04 20:43:23 +02:00
|
|
|
}
|
2018-09-27 23:41:26 +02:00
|
|
|
}
|
|
|
|
|
2019-06-23 22:25:06 +02:00
|
|
|
|
2021-10-31 20:09:18 +01:00
|
|
|
return _init_vgmstream_ogg_vorbis_cfg_ovmi(sf, &cfg, &ovmi);
|
|
|
|
fail:
|
|
|
|
return NULL;
|
|
|
|
}
|
2019-06-23 22:25:06 +02:00
|
|
|
|
2021-10-31 20:09:18 +01:00
|
|
|
/* Ogg Vorbis - encrypted .ogg [Yumekoi Tensei (PC)] */
|
|
|
|
static VGMSTREAM* _init_vgmstream_ogg_vorbis_tink(STREAMFILE* sf) {
|
|
|
|
ogg_vorbis_io_config_data cfg = {0};
|
|
|
|
ogg_vorbis_meta_info_t ovmi = {0};
|
|
|
|
uint32_t start;
|
|
|
|
|
|
|
|
/* checks */
|
|
|
|
if (is_id32be(0x00, sf, "Tink")) {
|
|
|
|
start = 0x00;
|
2019-09-14 23:03:31 +02:00
|
|
|
}
|
2021-10-31 20:09:18 +01:00
|
|
|
else if (is_id32be(0x0c, sf, "Tink")) {
|
|
|
|
ovmi.loop_start = read_u32le(0x00, sf);
|
|
|
|
ovmi.loop_end = read_u32le(0x04, sf);
|
|
|
|
ovmi.loop_flag = read_u32le(0x0c, sf);
|
|
|
|
ovmi.loop_end_found = 1;
|
|
|
|
start = 0x0c;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
goto fail;
|
|
|
|
}
|
2019-09-14 23:03:31 +02:00
|
|
|
|
2021-10-31 20:09:18 +01:00
|
|
|
if (!check_extensions(sf,"u0"))
|
|
|
|
goto fail;
|
2018-05-19 11:37:21 +02:00
|
|
|
|
2021-10-31 20:09:18 +01:00
|
|
|
cfg.is_encrypted = 1;
|
|
|
|
cfg.is_header_swap = 1;
|
|
|
|
cfg.start = start;
|
|
|
|
cfg.max_offset = 0xE1F;
|
|
|
|
cfg.key_len = 0xE1F;
|
|
|
|
|
|
|
|
if (sizeof(cfg.key) < cfg.key_len)
|
|
|
|
goto fail;
|
2016-11-12 00:39:40 +01:00
|
|
|
|
2021-10-31 20:09:18 +01:00
|
|
|
/* copy key */
|
|
|
|
{
|
|
|
|
static const char* keystring = "BB3206F-F171-4885-A131-EC7FBA6FF491 Copyright 2004 Cyberworks \"TinkerBell\"., all rights reserved.";
|
|
|
|
int i, keystring_len;
|
|
|
|
start = 0;
|
|
|
|
|
|
|
|
memset(cfg.key, 0, 0x04);
|
|
|
|
put_u8 (cfg.key + 0x04, 0x44);
|
|
|
|
|
|
|
|
keystring_len = strlen(keystring) + 1; /* including null */
|
|
|
|
for (i = 0x05; i < cfg.key_len; i += keystring_len) {
|
|
|
|
int copy = keystring_len;
|
|
|
|
if (i + copy > cfg.key_len)
|
|
|
|
copy = cfg.key_len - i;
|
|
|
|
memcpy(cfg.key + i, keystring, copy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return _init_vgmstream_ogg_vorbis_cfg_ovmi(sf, &cfg, &ovmi);
|
2016-11-12 00:39:40 +01:00
|
|
|
fail:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2021-10-31 20:09:18 +01:00
|
|
|
static VGMSTREAM* _init_vgmstream_ogg_vorbis(STREAMFILE* sf) {
|
|
|
|
VGMSTREAM* v;
|
|
|
|
|
|
|
|
v = _init_vgmstream_ogg_vorbis_common(sf);
|
|
|
|
if (v) return v;
|
|
|
|
|
|
|
|
v = _init_vgmstream_ogg_vorbis_tink(sf);
|
|
|
|
if (v) return v;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-09-27 00:10:28 +02:00
|
|
|
static VGMSTREAM* _init_vgmstream_ogg_vorbis_config(STREAMFILE* sf, off_t start, const ogg_vorbis_meta_info_t* ovmi) {
|
2020-09-27 22:01:14 +02:00
|
|
|
VGMSTREAM* vgmstream = NULL;
|
2019-10-18 19:34:15 +02:00
|
|
|
ogg_vorbis_codec_data* data = NULL;
|
|
|
|
ogg_vorbis_io io = {0};
|
2019-08-10 17:27:06 +02:00
|
|
|
char name[STREAM_NAME_SIZE] = {0};
|
2019-10-18 19:34:15 +02:00
|
|
|
int channels, sample_rate, num_samples;
|
2016-11-12 00:39:40 +01:00
|
|
|
|
2018-03-23 16:34:48 +01:00
|
|
|
int loop_flag = ovmi->loop_flag;
|
|
|
|
int32_t loop_start = ovmi->loop_start;
|
|
|
|
int loop_length_found = ovmi->loop_length_found;
|
|
|
|
int32_t loop_length = ovmi->loop_length;
|
|
|
|
int loop_end_found = ovmi->loop_end_found;
|
|
|
|
int32_t loop_end = ovmi->loop_end;
|
2021-05-17 00:57:09 +02:00
|
|
|
|
2018-03-23 16:34:48 +01:00
|
|
|
size_t stream_size = ovmi->stream_size ?
|
|
|
|
ovmi->stream_size :
|
2020-09-27 22:01:14 +02:00
|
|
|
get_streamfile_size(sf) - start;
|
2021-03-14 16:25:00 +01:00
|
|
|
int force_seek = 0;
|
2019-10-18 19:34:15 +02:00
|
|
|
int disable_reordering = ovmi->disable_reordering;
|
2016-11-12 00:39:40 +01:00
|
|
|
|
|
|
|
|
2019-10-18 19:34:15 +02:00
|
|
|
//todo improve how to pass config
|
|
|
|
io.decryption_callback = ovmi->decryption_callback;
|
|
|
|
io.scd_xor = ovmi->scd_xor;
|
|
|
|
io.scd_xor_length = ovmi->scd_xor_length;
|
|
|
|
io.xor_value = ovmi->xor_value;
|
2018-01-10 21:12:23 +01:00
|
|
|
|
2020-09-27 22:01:14 +02:00
|
|
|
data = init_ogg_vorbis(sf, start, stream_size, &io);
|
2019-10-18 19:34:15 +02:00
|
|
|
if (!data) goto fail;
|
2019-03-24 02:45:03 +01:00
|
|
|
|
2020-09-10 05:22:05 +02:00
|
|
|
ogg_vorbis_get_info(data, &channels, &sample_rate);
|
|
|
|
ogg_vorbis_get_samples(data, &num_samples); /* let libvorbisfile find total samples */
|
|
|
|
|
2018-01-10 21:12:23 +01:00
|
|
|
/* search for loop comments */
|
2019-06-23 23:20:43 +02:00
|
|
|
{//todo ignore if loop flag already set?
|
2020-09-27 22:01:14 +02:00
|
|
|
const char* comment = NULL;
|
2019-10-18 19:34:15 +02:00
|
|
|
|
|
|
|
while (ogg_vorbis_get_comment(data, &comment)) {
|
|
|
|
|
2021-05-17 00:57:09 +02:00
|
|
|
if (strstr(comment,"loop_start=") == comment || /* Phantasy Star Online: Blue Burst (PC) (no loop_end pair) */
|
|
|
|
strstr(comment,"LOOP_START=") == comment || /* Phantasy Star Online: Blue Burst (PC), common */
|
2020-09-10 04:38:35 +02:00
|
|
|
strstr(comment,"LOOPPOINT=") == comment || /* Sonic Robo Blast 2 */
|
2019-10-18 19:34:15 +02:00
|
|
|
strstr(comment,"COMMENT=LOOPPOINT=") == comment ||
|
|
|
|
strstr(comment,"LOOPSTART=") == comment ||
|
|
|
|
strstr(comment,"um3.stream.looppoint.start=") == comment ||
|
|
|
|
strstr(comment,"LOOP_BEGIN=") == comment || /* Hatsune Miku: Project Diva F (PS3) */
|
2021-05-17 00:57:09 +02:00
|
|
|
strstr(comment,"LoopStart=") == comment || /* Capcom games [Devil May Cry 4 (PC)] */
|
2020-06-26 03:47:49 +02:00
|
|
|
strstr(comment,"LOOP=") == comment || /* Duke Nukem 3D: 20th Anniversary World Tour */
|
2021-05-07 16:33:03 +02:00
|
|
|
strstr(comment,"XIPH_CUE_LOOPSTART=") == comment) { /* DeNa games [Super Mario Run (Android), FF Record Keeper (Android)] */
|
2019-10-18 19:34:15 +02:00
|
|
|
loop_start = atol(strrchr(comment,'=')+1);
|
2018-01-10 21:12:23 +01:00
|
|
|
loop_flag = (loop_start >= 0);
|
2016-11-12 00:39:40 +01:00
|
|
|
}
|
2019-10-18 19:34:15 +02:00
|
|
|
else if (strstr(comment,"LOOPLENGTH=") == comment) {/* (LOOPSTART pair) */
|
|
|
|
loop_length = atol(strrchr(comment,'=')+1);
|
2018-01-10 21:12:23 +01:00
|
|
|
loop_length_found = 1;
|
2016-11-12 00:39:40 +01:00
|
|
|
}
|
2019-10-18 19:34:15 +02:00
|
|
|
else if (strstr(comment,"title=-lps") == comment) { /* KID [Memories Off #5 (PC), Remember11 (PC)] */
|
|
|
|
loop_start = atol(comment+10);
|
2018-01-10 21:12:23 +01:00
|
|
|
loop_flag = (loop_start >= 0);
|
2016-11-12 00:39:40 +01:00
|
|
|
}
|
2019-10-18 19:34:15 +02:00
|
|
|
else if (strstr(comment,"album=-lpe") == comment) { /* (title=-lps pair) */
|
|
|
|
loop_end = atol(comment+10);
|
2018-01-10 21:12:23 +01:00
|
|
|
loop_end_found = 1;
|
2021-05-17 00:57:09 +02:00
|
|
|
loop_flag = 1;
|
2016-11-12 00:39:40 +01:00
|
|
|
}
|
2019-10-18 19:34:15 +02:00
|
|
|
else if (strstr(comment,"LoopEnd=") == comment) { /* (LoopStart pair) */
|
2021-05-17 00:57:09 +02:00
|
|
|
loop_end = atol(strrchr(comment,'=')+1);
|
|
|
|
loop_end_found = 1;
|
2016-11-12 00:39:40 +01:00
|
|
|
}
|
2021-05-17 00:57:09 +02:00
|
|
|
else if (strstr(comment,"LOOP_END=") == comment) { /* (LOOP_START/LOOP_BEGIN pair) */
|
|
|
|
loop_end = atol(strrchr(comment,'=')+1);
|
|
|
|
loop_end_found = 1;
|
2016-11-12 00:39:40 +01:00
|
|
|
}
|
2019-10-18 19:34:15 +02:00
|
|
|
else if (strstr(comment,"lp=") == comment) {
|
|
|
|
sscanf(strrchr(comment,'=')+1,"%d,%d", &loop_start,&loop_end);
|
2018-01-10 21:12:23 +01:00
|
|
|
loop_end_found = 1;
|
2021-05-17 00:57:09 +02:00
|
|
|
loop_flag = 1;
|
2017-02-18 08:04:16 +01:00
|
|
|
}
|
2019-10-18 19:34:15 +02:00
|
|
|
else if (strstr(comment,"LOOPDEFS=") == comment) { /* Fairy Fencer F: Advent Dark Force */
|
|
|
|
sscanf(strrchr(comment,'=')+1,"%d,%d", &loop_start,&loop_end);
|
2018-01-10 21:12:23 +01:00
|
|
|
loop_flag = 1;
|
|
|
|
loop_end_found = 1;
|
2016-11-12 00:39:40 +01:00
|
|
|
}
|
2019-10-18 19:34:15 +02:00
|
|
|
else if (strstr(comment,"COMMENT=loop(") == comment) { /* Zero Time Dilemma (PC) */
|
|
|
|
sscanf(strrchr(comment,'(')+1,"%d,%d", &loop_start,&loop_end);
|
2018-01-10 21:12:23 +01:00
|
|
|
loop_flag = 1;
|
|
|
|
loop_end_found = 1;
|
2016-11-12 00:39:40 +01:00
|
|
|
}
|
2019-10-18 19:34:15 +02:00
|
|
|
else if (strstr(comment, "XIPH_CUE_LOOPEND=") == comment) { /* (XIPH_CUE_LOOPSTART pair) */
|
2021-05-17 00:57:09 +02:00
|
|
|
loop_end = atol(strrchr(comment, '=') + 1);
|
|
|
|
loop_end_found = 1;
|
2018-07-27 17:30:58 +02:00
|
|
|
}
|
2019-10-18 19:34:15 +02:00
|
|
|
else if (strstr(comment, "omment=") == comment) { /* Air (Android) */
|
|
|
|
sscanf(strstr(comment, "=LOOPSTART=") + 11, "%d,LOOPEND=%d", &loop_start, &loop_end);
|
2018-07-20 07:14:41 +02:00
|
|
|
loop_flag = 1;
|
|
|
|
loop_end_found = 1;
|
|
|
|
}
|
2019-10-18 19:34:15 +02:00
|
|
|
else if (strstr(comment,"MarkerNum=0002") == comment) { /* Megaman X Legacy Collection: MMX1/2/3 (PC) flag */
|
2018-07-27 17:30:58 +02:00
|
|
|
/* uses LoopStart=-1 LoopEnd=-1, then 3 secuential comments: "MarkerNum" + "M=7F(start)" + "M=7F(end)" */
|
|
|
|
loop_flag = 1;
|
|
|
|
}
|
2019-10-18 19:34:15 +02:00
|
|
|
else if (strstr(comment,"M=7F") == comment) { /* Megaman X Legacy Collection: MMX1/2/3 (PC) start/end */
|
2018-07-27 17:30:58 +02:00
|
|
|
if (loop_flag && loop_start < 0) { /* LoopStart should set as -1 before */
|
2019-10-18 19:34:15 +02:00
|
|
|
sscanf(comment,"M=7F%x", &loop_start);
|
2018-07-27 17:30:58 +02:00
|
|
|
}
|
|
|
|
else if (loop_flag && loop_start >= 0) {
|
2019-10-18 19:34:15 +02:00
|
|
|
sscanf(comment,"M=7F%x", &loop_end);
|
2018-07-27 17:30:58 +02:00
|
|
|
loop_end_found = 1;
|
|
|
|
}
|
|
|
|
}
|
2021-03-14 16:25:00 +01:00
|
|
|
else if (strstr(comment,"LOOPMS=") == comment) { /* Sonic Robo Blast 2 (PC) */
|
|
|
|
loop_start = atol(strrchr(comment,'=')+1) * sample_rate / 1000; /* ms to samples */
|
2020-09-10 05:22:05 +02:00
|
|
|
loop_flag = (loop_start >= 0);
|
|
|
|
}
|
2021-04-10 19:44:55 +02:00
|
|
|
else if (strstr(comment,"COMMENT=- loopTime ") == comment || /* Aristear Remain (PC) */
|
|
|
|
strstr(comment,"COMMENT=-loopTime ") == comment) { /* Hyakki Ryouran no Yakata x Kawarazaki-ke no Ichizoku (PC) */
|
2021-05-07 16:33:03 +02:00
|
|
|
loop_start = atol(strrchr(comment,' ')) / 1000.0f * sample_rate; /* ms to samples */
|
2021-03-14 16:25:00 +01:00
|
|
|
loop_flag = (loop_start >= 0);
|
|
|
|
|
|
|
|
/* files have all page granule positions -1 except a few close to loop. This throws off
|
|
|
|
* libvorbis seeking (that uses granules), so we need manual fix = slower. Could be detected
|
2021-04-10 19:44:55 +02:00
|
|
|
* by checking granules in the first new OggS pages (other games from the same dev don't use
|
|
|
|
* loopTime nor have wrong granules though) */
|
2021-03-14 16:25:00 +01:00
|
|
|
force_seek = 1;
|
|
|
|
}
|
2018-04-20 17:02:56 +02:00
|
|
|
|
2019-06-09 18:41:26 +02:00
|
|
|
/* Hatsune Miku Project DIVA games, though only 'Arcade Future Tone' has >4ch files
|
|
|
|
* ENCODER tag is common but ogg_vorbis_encode looks unique enough
|
|
|
|
* (arcade ends with "2010-11-26" while consoles have "2011-02-07" */
|
2019-10-18 19:34:15 +02:00
|
|
|
if (strstr(comment, "ENCODER=ogg_vorbis_encode/") == comment) {
|
|
|
|
disable_reordering = 1;
|
2019-06-09 18:41:26 +02:00
|
|
|
}
|
|
|
|
|
2019-10-18 19:34:15 +02:00
|
|
|
if (strstr(comment, "TITLE=") == comment) {
|
|
|
|
strncpy(name, comment + 6, sizeof(name) - 1);
|
2019-08-10 17:27:06 +02:00
|
|
|
}
|
|
|
|
|
2019-10-18 19:34:15 +02:00
|
|
|
;VGM_LOG("OGG: user_comment=%s\n", comment);
|
2016-11-12 00:39:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-18 19:34:15 +02:00
|
|
|
ogg_vorbis_set_disable_reordering(data, disable_reordering);
|
2021-03-14 16:25:00 +01:00
|
|
|
ogg_vorbis_set_force_seek(data, force_seek);
|
2019-10-18 19:34:15 +02:00
|
|
|
|
2018-01-10 21:12:23 +01:00
|
|
|
|
2016-11-12 00:39:40 +01:00
|
|
|
/* build the VGMSTREAM */
|
2021-03-14 16:25:00 +01:00
|
|
|
vgmstream = allocate_vgmstream(channels, loop_flag);
|
2016-11-12 00:39:40 +01:00
|
|
|
if (!vgmstream) goto fail;
|
|
|
|
|
2019-10-18 19:34:15 +02:00
|
|
|
vgmstream->codec_data = data;
|
|
|
|
vgmstream->coding_type = coding_OGG_VORBIS;
|
|
|
|
vgmstream->layout_type = layout_none;
|
|
|
|
vgmstream->meta_type = ovmi->meta_type;
|
2021-04-10 22:47:11 +02:00
|
|
|
if (!vgmstream->meta_type)
|
|
|
|
vgmstream->meta_type = meta_OGG_VORBIS;
|
2019-10-18 19:34:15 +02:00
|
|
|
|
|
|
|
vgmstream->sample_rate = sample_rate;
|
2018-01-28 00:41:25 +01:00
|
|
|
vgmstream->stream_size = stream_size;
|
2016-11-12 00:39:40 +01:00
|
|
|
|
2019-08-10 17:27:06 +02:00
|
|
|
if (ovmi->total_subsongs) /* not setting it has some effect when showing stream names */
|
|
|
|
vgmstream->num_streams = ovmi->total_subsongs;
|
|
|
|
|
|
|
|
if (name[0] != '\0')
|
|
|
|
strcpy(vgmstream->stream_name, name);
|
|
|
|
|
2019-10-18 19:34:15 +02:00
|
|
|
vgmstream->num_samples = num_samples;
|
2016-11-12 00:39:40 +01:00
|
|
|
if (loop_flag) {
|
|
|
|
vgmstream->loop_start_sample = loop_start;
|
|
|
|
if (loop_length_found)
|
2019-10-18 19:34:15 +02:00
|
|
|
vgmstream->loop_end_sample = loop_start + loop_length;
|
2016-11-12 00:39:40 +01:00
|
|
|
else if (loop_end_found)
|
|
|
|
vgmstream->loop_end_sample = loop_end;
|
|
|
|
else
|
2021-03-15 22:35:37 +01:00
|
|
|
vgmstream->loop_end_sample = vgmstream->num_samples;
|
2016-11-12 00:39:40 +01:00
|
|
|
|
|
|
|
if (vgmstream->loop_end_sample > vgmstream->num_samples)
|
|
|
|
vgmstream->loop_end_sample = vgmstream->num_samples;
|
|
|
|
}
|
2018-01-10 21:12:23 +01:00
|
|
|
|
2019-03-02 15:57:41 +01:00
|
|
|
if (vgmstream->channels <= 8) {
|
|
|
|
vgmstream->channel_layout = xiph_mappings[vgmstream->channels];
|
|
|
|
}
|
|
|
|
|
2016-11-12 00:39:40 +01:00
|
|
|
return vgmstream;
|
|
|
|
|
|
|
|
fail:
|
2019-10-18 19:34:15 +02:00
|
|
|
close_vgmstream(vgmstream);
|
2016-11-12 00:39:40 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|