mirror of
https://github.com/vgmstream/vgmstream.git
synced 2024-11-24 15:00:11 +01:00
Add TXT multi txth, name table for subsongs, special subsong value
This commit is contained in:
parent
332587359b
commit
0a6cb11a30
236
doc/TXTH.md
236
doc/TXTH.md
@ -1,18 +1,13 @@
|
||||
# TXTH FORMAT
|
||||
|
||||
TXTH is a simple text file that uses text commands to simulate a header for files unsupported by vgmstream, mainly headerless audio.
|
||||
TXTH is a simple text file with text commands to simulate a header for files unsupported by vgmstream, mainly headerless audio.
|
||||
|
||||
When an unsupported file is loaded (for instance "bgm01.snd"), vgmstream tries to find a TXTH header in the same dir, in this order:
|
||||
When an unsupported file is loaded (for instance `bgm01.snd`), vgmstream tries to find a TXTH header in the same dir, in this order:
|
||||
- `(filename.ext).txth`
|
||||
- `.(ext).txth`
|
||||
- `.txth`
|
||||
|
||||
If found and parsed correctly (the .txth may be rejected if incorrect commands are found) vgmstream will try to play the file as described. Extension must be accepted/added to vgmstream (plugins like foobar2000 only load extensions from a whitelist in formats.c), or one could rename to any supported extension (like .vgmstream), or leave the file extensionless.
|
||||
|
||||
You can also use `.(sub).(ext).txth` (if the file is `filename.sub.ext`), to allow mixing slightly different files in the same folder. The `sub` part doesn't need to be an extension, for example:
|
||||
- `001.1ch.str`, `001.1ch.str` may use `.1ch.txth`
|
||||
- `003.2ch.str`, `003.2ch.str` may use `.2ch.txth`
|
||||
- etc
|
||||
If found and parsed correctly, vgmstream will play the file as described.
|
||||
|
||||
## Example of a TXTH file
|
||||
For an unsupported `bgm01.vag` this would be a simple TXTH for it:
|
||||
@ -29,10 +24,19 @@ A text file with the above commands must be saved as `.vag.txth` or `.txth` (pre
|
||||
|
||||
While the main point is playing the file, many of TXTH's features are aimed towards keeping original data intact, for documentation and preservation purposes; try leaving data as untouched as possible and consider how the game plays the file, as there is a good chance some feature can mimic it.
|
||||
|
||||
Also check the [examples](#examples) section for some quick recipes, of varying complexity.
|
||||
|
||||
|
||||
## Issues
|
||||
The `.txth` may be rejected if incorrect commands are found. Since at the moment vgmstream can't communicate why a file is rejected, try starting with a simple case (see examples) then add more complex commands until it fully works.
|
||||
|
||||
Extension must be accepted/added to vgmstream (plugins like foobar2000 only load extensions from an accepted list in `formats.c`), or one could rename to any supported extension (like `.vgmstream`), or leave the file extensionless. Before renaming consider reporting the unknown extension so it can be added to the list (so similar games benefit, as long as the extension is a good fit). Some plugins allow playing unknown extensions too.
|
||||
|
||||
Note that TXTH has *lower* priority than most (not all) vgmstream formats, by design. This means your `.txth` may be ignored if vgmstream thinks it can play your file better. If vgmstream plays your file somewhat off, rather renaming to force a `.txth`, report the bug so that and similar cases can be fixed. TXTH isn't meant to be a replacement of vgmstream's parsers, but a way to play cases that aren't a good fit be added directly to vgmstream.
|
||||
|
||||
|
||||
## Available commands
|
||||
|
||||
The file is made of lines with `key = value` commands describing a header. Commands are all case sensitive and spaces are optional: `key=value`, `key = value`, and so on are all ok. Comments start with # and can be inlined.
|
||||
The file is made of lines with `key = value` commands describing a header. Commands are all case sensitive and spaces are optional: `key=value`, `key = value`, and so on are all ok, while `Key = VaLuE` is not. Comments start with `#` and can be inlined.
|
||||
|
||||
The parser is fairly simple and may be buggy or unexpected in some cases. The order of keys is variable but some things won't work if others aren't defined (ex. bytes-to-samples may not work without channels or interleave) or need to be done in a certain order (due to technical reasons) as explained below.
|
||||
|
||||
@ -50,9 +54,9 @@ The following can be used in place of `(value)` for `(key) = (value)` commands.
|
||||
* Example: `@0x10:BE$2` means `get big endian 16b value at 0x10`
|
||||
- `(field)`: uses current value of some fields. Accepted strings:
|
||||
- `interleave, interleave_last, channels, sample_rate, start_offset, data_size, num_samples, loop_start_sample, loop_end_sample, subsong_count, subsong_spacing, subfile_offset, subfile_size, base_offset, name_valueX`
|
||||
- `subsong` is a special field for current subsong
|
||||
- `(other)`: other special values for certain keys, described per key
|
||||
|
||||
|
||||
The above may be combined with math operations (+-*/&): `(key) = (number) (op) (offset) (op) (field) (...)`
|
||||
|
||||
### KEYS
|
||||
@ -201,12 +205,12 @@ interleave_last = (value)|auto
|
||||
```
|
||||
|
||||
#### ID VALUES
|
||||
Validates that `id_value` (normally set as constant value) matches value read at `id_offset`. The file will be rejected and won't play if values don't match.
|
||||
Validates that `id_value` (normally set as constant value) matches value read at `id_check`. The file will be rejected and won't play if values don't match.
|
||||
|
||||
Can be redefined several times, it's checked whenever a new id_offset is found.
|
||||
Can be redefined several times, it's checked whenever a new id_offset is found. `id_offset` can be used as an alt for `id_check`
|
||||
```
|
||||
id_value = (value)
|
||||
id_offset = (value)
|
||||
id_check = (value)
|
||||
```
|
||||
|
||||
#### NUMBER OF CHANNELS [REQUIRED]
|
||||
@ -262,7 +266,7 @@ Those tell vgmstream how long the song is. Define loop points for the track to r
|
||||
|
||||
You can use `loop_start` and `loop_end` instead as aliases of `loop_start_sample` and `loop_end_sample` (no difference).
|
||||
|
||||
To activate loops you need to define both `loop_start` and `loop_end` (rather than say, only defining `start` and defaulting `end` to `num_samples`). This is to make the *.txtp* more descriptive, and avoid ambiguity in cases where `start` value is 0. See loop settings below to fine tune when to loop.
|
||||
To activate loops you need to define both `loop_start` and `loop_end` (rather than say, only defining `start` and defaulting `end` to `num_samples`). This is to make the *.txth* more descriptive, and avoid ambiguity in cases where `start` value is 0. See loop settings below to fine tune when to loop.
|
||||
|
||||
Special values:
|
||||
- `data_size`: automatically converts bytes-to-samples (a few codecs don't allow this)
|
||||
@ -397,7 +401,7 @@ File is first "dechunked" then played with using other settings (`start_offset`
|
||||
You need to set:
|
||||
- `chunk_count`: total number of interleaved chunks (ex. 3=3 interleaved songs)
|
||||
- `chunk_number`: first chunk to start (ex. 1=0x00000, 2=0x10000, 3=0x20000...)
|
||||
* If you set `subsong_count` first `chunk_number` will be auto-set per subsong (subsong 1 starts from chunk number 1, subsong 2 from chunk 2, etc)
|
||||
* If you set `subsong_count` and `chunk_count` first, `chunk_number` will be auto-set per subsong (subsong 1 starts from chunk number 1, subsong 2 from chunk 2, etc)
|
||||
- `chunk_start`: absolute offset where chunks start (normally 0x00)
|
||||
- `chunk_size`: amount of data in a single chunk (ex. 0x10000)
|
||||
For fine-tuning you can optionally set (before `chunk_size`, for reasons):
|
||||
@ -442,6 +446,16 @@ bgm*: 2 # 2ch: all other files, notice order matters
|
||||
|
||||
While you can put anything in the values, this feature is meant to be used to store some number that points to the actual data inside a real multi-header, that could be set with `header_file`. If you feel the need to store many constant values per file, there is good chance it can be done in some better, simpler way.
|
||||
|
||||
This function also works with subsongs, with this syntax:
|
||||
```
|
||||
# for subsong 1 in filename
|
||||
(filename)#1: (value 1)
|
||||
# for any subsong 2
|
||||
#2: (value 2)
|
||||
...
|
||||
```
|
||||
Then subsong N would automatically use its own `name_value`.
|
||||
|
||||
|
||||
#### BASE OFFSET MODIFIER
|
||||
You can set a default offset that affects next `@(offset)` reads making them `@(offset + base_offset)`, for cleaner parsing.
|
||||
@ -450,12 +464,40 @@ This is particularly interesting when combined with offsets to some long value.
|
||||
|
||||
It also allows parsing formats that set offsets to another offset, by "chaining" `base_offset`. With `base_offset = @0x10` (pointing to `0x40`) then `base_offset = @0x20`, it reads value at `0x60`. Set to 0 when you want to disable/reset the chain: `base_offset = @0x10` then `base_offset = 0` then `base_offset = @0x20` reads value at `0x20`
|
||||
|
||||
|
||||
```
|
||||
base_offset = (value)
|
||||
```
|
||||
|
||||
|
||||
#### MULTI-TXTH
|
||||
TXTH can't do conditions (`if`) but sometimes you have have variations of the same format in the same dir. You can set multiple `.txth` files to try until one works. Use `id_value/id_check` to reject wrong `.txth` (otherwise the first one will be selected).
|
||||
|
||||
```
|
||||
multi_txth = (filename), (filename), ...
|
||||
```
|
||||
For example:
|
||||
```
|
||||
multi_txth = .2ch.txth, .4ch.txth
|
||||
```
|
||||
|
||||
*.2ch.txth*
|
||||
```
|
||||
id_value = 2
|
||||
id_check = @0x00 # 2ch only
|
||||
|
||||
... #some settings for stereo
|
||||
|
||||
```
|
||||
*.4ch.txth*
|
||||
```
|
||||
id_value = 4
|
||||
id_check = @0x00 # 4ch only
|
||||
|
||||
... #different settings for 4ch
|
||||
|
||||
```
|
||||
|
||||
|
||||
## Complex usages
|
||||
|
||||
### Temporary values
|
||||
@ -701,39 +743,12 @@ sample_rate = @0x04 #reads at 0x1204
|
||||
|
||||
## Examples
|
||||
|
||||
#### Colin McRae DiRT (PC) .wip.txth
|
||||
#### Spy Hunter (GC) .pcm.txth
|
||||
```
|
||||
id_value = 0x00000000 #check that value at 0x00 is really 0x00000000
|
||||
id_offset = @0x00:BE
|
||||
|
||||
codec = PCM16LE
|
||||
channels = 2
|
||||
codec = PCM8
|
||||
sample_rate = 32000
|
||||
start_offset = 0x04
|
||||
num_samples = data_size
|
||||
loop_start_sample = 0
|
||||
loop_end_sample = data_size
|
||||
```
|
||||
|
||||
#### Kim Possible: What's the Switch (PS2) .str.txth
|
||||
```
|
||||
codec = PSX
|
||||
interleave = 0x2000
|
||||
channels = 2
|
||||
sample_rate = 48000
|
||||
num_samples = data_size
|
||||
interleave_last = auto
|
||||
```
|
||||
|
||||
#### Manhunt (Xbox) .rib.txth
|
||||
```
|
||||
codec = XBOX
|
||||
codec_mode = 1 #interleaved XBOX
|
||||
interleave = 0xD800
|
||||
|
||||
channels = 12
|
||||
sample_rate = 44100
|
||||
start_offset = 0x00
|
||||
channels = 1
|
||||
start_offset = 0
|
||||
num_samples = data_size
|
||||
```
|
||||
|
||||
@ -747,12 +762,50 @@ sample_rate = 44100
|
||||
num_samples = data_size
|
||||
```
|
||||
|
||||
#### Spy Hunter (GC) .pcm.txth
|
||||
#### Aladdin in Nasira's Revenge (PS1) .cvs.txth
|
||||
```
|
||||
codec = PCM8
|
||||
sample_rate = 32000
|
||||
codec = PSX
|
||||
interleave = 0x10
|
||||
sample_rate = 24000
|
||||
channels = 1
|
||||
start_offset = 0
|
||||
padding_size = auto-empty
|
||||
num_samples = data_size
|
||||
```
|
||||
|
||||
#### Kim Possible: What's the Switch (PS2) .str.txth
|
||||
```
|
||||
codec = PSX
|
||||
interleave = 0x2000
|
||||
channels = 2
|
||||
sample_rate = 48000
|
||||
num_samples = data_size
|
||||
interleave_last = auto
|
||||
```
|
||||
|
||||
#### Colin McRae DiRT (PC) .wip.txth
|
||||
```
|
||||
# first check that value at 0x00 is really 0x00000000 (rarely needed though)
|
||||
id_value = 0x00000000
|
||||
id_check = @0x00:BE
|
||||
|
||||
codec = PCM16LE
|
||||
channels = 2
|
||||
sample_rate = 32000
|
||||
start_offset = 0x04
|
||||
num_samples = data_size
|
||||
loop_start_sample = 0
|
||||
loop_end_sample = data_size
|
||||
```
|
||||
|
||||
#### Manhunt (Xbox) .rib.txth
|
||||
```
|
||||
codec = XBOX
|
||||
codec_mode = 1 #interleaved XBOX
|
||||
interleave = 0xD800
|
||||
|
||||
channels = 12
|
||||
sample_rate = 44100
|
||||
start_offset = 0x00
|
||||
num_samples = data_size
|
||||
```
|
||||
|
||||
@ -776,16 +829,6 @@ coef_spacing = 0x10000
|
||||
coef_endianness = BE
|
||||
```
|
||||
|
||||
#### Aladdin in Nasira's Revenge (PS1) .cvs.txth
|
||||
```
|
||||
codec = PSX
|
||||
interleave = 0x10
|
||||
sample_rate = 24000
|
||||
channels = 1
|
||||
padding_size = auto-empty
|
||||
num_samples = data_size
|
||||
```
|
||||
|
||||
#### Shikigami no Shiro - Nanayozuki Gensoukyoku (PS2) bgm.txth
|
||||
```
|
||||
codec = PSX
|
||||
@ -1121,3 +1164,72 @@ loop_end = @0x24:BE #0x2c?
|
||||
loop_start = @0x28:BE
|
||||
loop_flag = @0x2c:BE
|
||||
```
|
||||
|
||||
#### Grand Theft Auto: San Andreas .vgmstream.txth
|
||||
```
|
||||
# once extracted from bigfiles there are 2 types of files with hardcoded settings,
|
||||
# so we need 2 .txth
|
||||
multi_txth = .type2.txth, .type4.txth
|
||||
```
|
||||
|
||||
*.type2.txth*
|
||||
```
|
||||
id_value = 2
|
||||
id_check = @0x1f80
|
||||
|
||||
codec = PSX
|
||||
channels = 2
|
||||
sample_rate = @0x1F44
|
||||
interleave = 0x10000
|
||||
start_offset = 0x00
|
||||
|
||||
chunk_count = 1
|
||||
chunk_start = 0x1f84
|
||||
chunk_data_size = 0x20000
|
||||
chunk_size = 0x21000
|
||||
|
||||
num_samples = data_size
|
||||
```
|
||||
|
||||
*.type4.txth*
|
||||
```
|
||||
id_value = 4
|
||||
id_check = @0x1F80
|
||||
|
||||
name_table = .names.txt
|
||||
|
||||
subsong_count = 2
|
||||
|
||||
base_offset = name_value1
|
||||
|
||||
codec = PSX
|
||||
channels = 2
|
||||
sample_rate = @0x04
|
||||
interleave = name_value2
|
||||
start_offset = 0x00
|
||||
|
||||
chunk_count = 1
|
||||
chunk_start = 0x1f84
|
||||
chunk_header_size = name_value3
|
||||
chunk_data_size = name_value4
|
||||
chunk_size = 0x21000
|
||||
|
||||
num_samples = data_size
|
||||
|
||||
# base_offset = 0x1F40
|
||||
# 00: stream size without padding
|
||||
# 04: stream 1 sample rate
|
||||
# 08: stream size without padding (same)
|
||||
# 0c: stream 2 sample rate (same)
|
||||
# repeat for stream 3 and 4 if any
|
||||
# 1/2 are mini streams (interleave 0x800, chunk size 0x1000, padding 0x20000)
|
||||
# 1/2 are standard streams (interleave 0x10000, padding 0x1000, chunk size 0x20000)
|
||||
# (mini streams are muffled versions of the standard ones)
|
||||
```
|
||||
|
||||
*.names.txt*
|
||||
```
|
||||
# base_offset, interleave, chunk_header_size, chunk_data_size
|
||||
#1: 0x1F40, 0x800, 0x00, 0x1000
|
||||
#2: 0x1F50, 0x10000, 0x1000, 0x20000
|
||||
```
|
||||
|
149
src/meta/txth.c
149
src/meta/txth.c
@ -54,7 +54,7 @@ typedef struct {
|
||||
uint32_t value_sub;
|
||||
|
||||
uint32_t id_value;
|
||||
uint32_t id_offset;
|
||||
uint32_t id_check;
|
||||
|
||||
uint32_t interleave;
|
||||
uint32_t interleave_last;
|
||||
@ -122,6 +122,8 @@ typedef struct {
|
||||
uint32_t name_values[16];
|
||||
int name_values_count;
|
||||
|
||||
int is_multi_txth;
|
||||
|
||||
/* original STREAMFILE and its type (may be an unsupported "base" file or a .txth) */
|
||||
STREAMFILE* sf;
|
||||
int streamfile_is_txth;
|
||||
@ -571,7 +573,7 @@ VGMSTREAM* init_vgmstream_txth(STREAMFILE* sf) {
|
||||
vgmstream->allow_dual_stereo = 1;
|
||||
|
||||
|
||||
if ( !vgmstream_open_stream(vgmstream,txth.sf_body,txth.start_offset) )
|
||||
if (!vgmstream_open_stream(vgmstream, txth.sf_body, txth.start_offset))
|
||||
goto fail;
|
||||
|
||||
clean_txth(&txth);
|
||||
@ -750,7 +752,7 @@ static void set_body_chunk(txth_header* txth) {
|
||||
return;
|
||||
|
||||
/* treat chunks as subsongs */
|
||||
if (txth->subsong_count > 1)
|
||||
if (txth->subsong_count > 1 && txth->subsong_count == txth->chunk_count)
|
||||
txth->chunk_number = txth->target_subsong;
|
||||
if (txth->chunk_number == 0)
|
||||
txth->chunk_number = 1;
|
||||
@ -798,6 +800,7 @@ static int parse_num(STREAMFILE* sf, txth_header* txth, const char* val, uint32_
|
||||
static int parse_string(STREAMFILE* sf, txth_header* txth, const char* val, char* str);
|
||||
static int parse_coef_table(STREAMFILE* sf, txth_header* txth, const char* val, uint8_t* out_value, size_t out_size);
|
||||
static int parse_name_table(txth_header* txth, char* val);
|
||||
static int parse_multi_txth(txth_header* txth, char* val);
|
||||
static int is_string(const char* val, const char* cmp);
|
||||
static int get_bytes_to_samples(txth_header* txth, uint32_t bytes);
|
||||
static int get_padding_size(txth_header* txth, int discard_empty);
|
||||
@ -944,9 +947,9 @@ static int parse_keyval(STREAMFILE* sf_, txth_header* txth, const char* key, cha
|
||||
else if (is_string(key,"id_value")) {
|
||||
if (!parse_num(txth->sf_head,txth,val, &txth->id_value)) goto fail;
|
||||
}
|
||||
else if (is_string(key,"id_offset")) {
|
||||
if (!parse_num(txth->sf_head,txth,val, &txth->id_offset)) goto fail;
|
||||
if (txth->id_value != txth->id_offset) /* evaluate current ID */
|
||||
else if (is_string(key,"id_check") || is_string(key,"id_offset")) {
|
||||
if (!parse_num(txth->sf_head,txth,val, &txth->id_check)) goto fail;
|
||||
if (txth->id_value != txth->id_check) /* evaluate current ID */
|
||||
goto fail;
|
||||
}
|
||||
|
||||
@ -1327,6 +1330,11 @@ static int parse_keyval(STREAMFILE* sf_, txth_header* txth, const char* key, cha
|
||||
if (!parse_name_table(txth,val)) goto fail;
|
||||
}
|
||||
|
||||
/* MULTI TXTH */
|
||||
else if (is_string(key,"multi_txth")) {
|
||||
if (!parse_multi_txth(txth,val)) goto fail;
|
||||
}
|
||||
|
||||
|
||||
/* DEFAULT */
|
||||
else {
|
||||
@ -1511,8 +1519,52 @@ fail:
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int read_name_table_keyval(txth_header* txth, const char* line, char* key, char* val) {
|
||||
int ok;
|
||||
int subsong;
|
||||
|
||||
/* get key/val (ignores lead spaces, stops at space/comment/separator) */
|
||||
//todo names with # and subsongs don't work
|
||||
|
||||
/* ignore comments (that aren't subsongs) */
|
||||
if (line[0] == '#' && strchr(line,':') < 0)
|
||||
return 0;
|
||||
|
||||
/* try "(name): (val))" */
|
||||
ok = sscanf(line, " %[^\t#:] : %[^\t#\r\n] ", key, val);
|
||||
if (ok == 2) {
|
||||
;VGM_LOG("TXTH: name %s get\n", key);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* try "(empty): (val))" */
|
||||
key[0] = '\0';
|
||||
ok = sscanf(line, " : %[^\t#\r\n] ", val);
|
||||
if (ok == 1) {
|
||||
;VGM_LOG("TXTH: default get\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* try "(name)#subsong: (val))" */
|
||||
ok = sscanf(line, " %[^\t#:]#%i : %[^\t#\r\n] ", key, &subsong, val);
|
||||
if (ok == 3 && subsong == txth->target_subsong) {
|
||||
VGM_LOG("TXTH: name %s + subsong %i get\n", key, subsong);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* try "(empty)#subsong: (val))" */
|
||||
key[0] = '\0';
|
||||
ok = sscanf(line, " #%i: %[^\t#\r\n] ", &subsong, val);
|
||||
if (ok == 2 && subsong == txth->target_subsong) {
|
||||
VGM_LOG("TXTH: default + subsong %i get\n", subsong);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int parse_name_table(txth_header* txth, char* name_list) {
|
||||
STREAMFILE* nameFile = NULL;
|
||||
STREAMFILE* sf_names = NULL;
|
||||
off_t txt_offset, file_size;
|
||||
char fullname[PATH_LIMIT];
|
||||
char filename[PATH_LIMIT];
|
||||
@ -1536,8 +1588,8 @@ static int parse_name_table(txth_header* txth, char* name_list) {
|
||||
//;VGM_LOG("TXTH: name_list='%s'\n", name_list);
|
||||
|
||||
/* open companion file near .txth */
|
||||
nameFile = open_streamfile_by_filename(txth->sf_text, name_list);
|
||||
if (!nameFile) goto fail;
|
||||
sf_names = open_streamfile_by_filename(txth->sf_text, name_list);
|
||||
if (!sf_names) goto fail;
|
||||
|
||||
get_streamfile_name(txth->sf_body, fullname, sizeof(filename));
|
||||
get_streamfile_filename(txth->sf_body, filename, sizeof(filename));
|
||||
@ -1545,14 +1597,14 @@ static int parse_name_table(txth_header* txth, char* name_list) {
|
||||
//;VGM_LOG("TXTH: names full=%s, file=%s, base=%s\n", fullname, filename, basename);
|
||||
|
||||
txt_offset = 0x00;
|
||||
file_size = get_streamfile_size(nameFile);
|
||||
file_size = get_streamfile_size(sf_names);
|
||||
|
||||
/* skip BOM if needed */
|
||||
if ((uint16_t)read_16bitLE(0x00, nameFile) == 0xFFFE ||
|
||||
(uint16_t)read_16bitLE(0x00, nameFile) == 0xFEFF) {
|
||||
if ((uint16_t)read_16bitLE(0x00, sf_names) == 0xFFFE ||
|
||||
(uint16_t)read_16bitLE(0x00, sf_names) == 0xFEFF) {
|
||||
txt_offset = 0x02;
|
||||
}
|
||||
else if (((uint32_t)read_32bitBE(0x00, nameFile) & 0xFFFFFF00) == 0xEFBBBF00) {
|
||||
else if (((uint32_t)read_32bitBE(0x00, sf_names) & 0xFFFFFF00) == 0xEFBBBF00) {
|
||||
txt_offset = 0x03;
|
||||
}
|
||||
|
||||
@ -1569,22 +1621,14 @@ static int parse_name_table(txth_header* txth, char* name_list) {
|
||||
while (txt_offset < file_size) {
|
||||
int ok, bytes_read, line_ok;
|
||||
|
||||
bytes_read = read_line(line, sizeof(line), txt_offset, nameFile, &line_ok);
|
||||
bytes_read = read_line(line, sizeof(line), txt_offset, sf_names, &line_ok);
|
||||
if (!line_ok) goto fail;
|
||||
//;VGM_LOG("TXTH: line=%s\n",line);
|
||||
|
||||
txt_offset += bytes_read;
|
||||
|
||||
/* get key/val (ignores lead spaces, stops at space/comment/separator) */
|
||||
ok = sscanf(line, " %[^\t#:] : %[^\t#\r\n] ", key,val);
|
||||
if (ok != 2) { /* ignore line if no key=val (comment or garbage) */
|
||||
/* try again with " (empty): (val)) */
|
||||
key[0] = '\0';
|
||||
ok = sscanf(line, " : %[^\t#\r\n] ", val);
|
||||
if (ok != 1)
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!read_name_table_keyval(txth, line, key, val))
|
||||
continue;
|
||||
|
||||
//;VGM_LOG("TXTH: compare name '%s'\n", key);
|
||||
/* parse values if key (name) matches default ("") or filename with/without extension */
|
||||
@ -1619,14 +1663,66 @@ static int parse_name_table(txth_header* txth, char* name_list) {
|
||||
|
||||
/* ignore if name is not actually found (values will return 0) */
|
||||
|
||||
close_streamfile(nameFile);
|
||||
close_streamfile(sf_names);
|
||||
return 1;
|
||||
fail:
|
||||
close_streamfile(nameFile);
|
||||
close_streamfile(sf_names);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int parse_multi_txth(txth_header* txth, char* names) {
|
||||
STREAMFILE* sf_text = NULL;
|
||||
char name[PATH_LIMIT];
|
||||
int n, ok;
|
||||
|
||||
/* temp save */
|
||||
sf_text = txth->sf_text;
|
||||
txth->sf_text = NULL;
|
||||
|
||||
/* to avoid potential infinite recursion plus stack overflows */
|
||||
if (txth->is_multi_txth > 3)
|
||||
goto fail;
|
||||
txth->is_multi_txth++;
|
||||
|
||||
while (names[0] != '\0') {
|
||||
STREAMFILE* sf_test = NULL;
|
||||
int found;
|
||||
|
||||
ok = sscanf(names, " %[^\t#\r\n,]%n ", name, &n);
|
||||
if (ok != 1)
|
||||
goto fail;
|
||||
|
||||
//;VGM_LOG("TXTH: multi name %s\n", name);
|
||||
sf_test = open_streamfile_by_filename(txth->sf, name);
|
||||
if (!sf_test)
|
||||
goto fail;
|
||||
|
||||
/* re-parse with current txth and hope */
|
||||
txth->sf_text = sf_test;
|
||||
found = parse_txth(txth);
|
||||
close_streamfile(sf_test);
|
||||
//todo may need to close header/body streamfiles?
|
||||
|
||||
if (found) {
|
||||
//;VGM_LOG("TXTH: found valid multi txth %s\n", name);
|
||||
break; /* found, otherwise keep trying */
|
||||
}
|
||||
|
||||
names += n;
|
||||
if (names[0] == ',')
|
||||
names++;
|
||||
}
|
||||
|
||||
txth->is_multi_txth--;
|
||||
txth->sf_text = sf_text;
|
||||
return 1;
|
||||
fail:
|
||||
txth->is_multi_txth--;
|
||||
txth->sf_text = sf_text;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int parse_num(STREAMFILE* sf, txth_header* txth, const char* val, uint32_t* out_value) {
|
||||
/* out_value can be these, save before modifying */
|
||||
uint32_t value_mul = txth->value_mul;
|
||||
@ -1734,6 +1830,7 @@ static int parse_num(STREAMFILE* sf, txth_header* txth, const char* val, uint32_
|
||||
else if ((n = is_string_field(val,"loop_start"))) value = txth->loop_start_sample;
|
||||
else if ((n = is_string_field(val,"loop_end_sample"))) value = txth->loop_end_sample;
|
||||
else if ((n = is_string_field(val,"loop_end"))) value = txth->loop_end_sample;
|
||||
else if ((n = is_string_field(val,"subsong"))) value = txth->target_subsong;
|
||||
else if ((n = is_string_field(val,"subsong_count"))) value = txth->subsong_count;
|
||||
else if ((n = is_string_field(val,"subsong_spacing"))) value = txth->subsong_spacing;
|
||||
else if ((n = is_string_field(val,"subsong_offset"))) value = txth->subsong_spacing;
|
||||
|
Loading…
Reference in New Issue
Block a user