Skip to content

Commit 7ec4555

Browse files
committed
more correct random container parsing
credits for format documentation: https://github.com/bnnm/wwiser
1 parent b00ede8 commit 7ec4555

File tree

1 file changed

+49
-32
lines changed

1 file changed

+49
-32
lines changed

bnk-extract/sound.c

Lines changed: 49 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
int VERBOSE = 0;
1313

1414
// http://wiki.xentax.com/index.php/Wwise_SoundBank_(*.bnk)
15+
16+
// almost full documentation of all types and versions: https://github.com/bnnm/wwiser
17+
1518
struct sound {
1619
uint32_t self_id;
1720
uint32_t file_id;
@@ -111,43 +114,57 @@ int read_random_container_object(FILE* bnk_file, RandomContainerSection* random_
111114
assert(fread(&new_random_container_object.self_id, 4, 1, bnk_file) == 1);
112115
dprintf("at the beginning: %ld\n", ftell(bnk_file));
113116
fseek(bnk_file, 1, SEEK_CUR);
114-
uint8_t unk = getc(bnk_file);
115-
fseek(bnk_file, 5 + (unk != 0) + (unk * 7) - (bnk_version == 0x58), SEEK_CUR);
117+
uint8_t num_fx = getc(bnk_file);
118+
fseek(bnk_file, 5 + (num_fx != 0) - (bnk_version <= 0x59) + (num_fx * 7), SEEK_CUR);
116119
dprintf("reading in switch container id at position %ld\n", ftell(bnk_file));
117120
assert(fread(&new_random_container_object.switch_container_id, 4, 1, bnk_file) == 1);
118-
if (bnk_version == 0x58) {
119-
while(getc(bnk_file) != '\x7a' || getc(bnk_file) != '\x44');
120-
fseek(bnk_file, 18, SEEK_CUR);
121-
} else {
122-
fseek(bnk_file, 1, SEEK_CUR);
123-
uint8_t unk2 = getc(bnk_file);
124-
if (unk2 != 0) {
125-
dprintf("offset here: %ld, unk2: %d\n", ftell(bnk_file), unk2);
126-
fseek(bnk_file, 5 * unk2, SEEK_CUR);
121+
fseek(bnk_file, (bnk_version <= 0x59 ? 2 : 1), SEEK_CUR);
122+
uint8_t prop_count = getc(bnk_file);
123+
fseek(bnk_file, 5 * prop_count, SEEK_CUR);
124+
prop_count = getc(bnk_file);
125+
fseek(bnk_file, 9 * prop_count, SEEK_CUR);
126+
uint8_t positioning_bits = getc(bnk_file);
127+
bool has_positioning = positioning_bits & 1, has_3d = false, has_automation = false;
128+
if (has_positioning) {
129+
if (bnk_version <= 0x59) {
130+
bool has_2d = getc(bnk_file);
131+
has_3d = getc(bnk_file);
132+
if (has_2d) getc(bnk_file);
133+
} else {
134+
has_3d = positioning_bits & 0x2;
135+
}
127136
}
128-
uint8_t unk3 = getc(bnk_file);
129-
dprintf("unk3: %d\n", unk3);
130-
fseek(bnk_file, 9 * unk3, SEEK_CUR);
131-
fseek(bnk_file, 9 + (getc(bnk_file) > 1), SEEK_CUR);
132-
dprintf("where am i? %ld\n", ftello(bnk_file));
133-
uint8_t unk4 = getc(bnk_file);
134-
dprintf("unk4: %d\n", unk4);
135-
if (unk4 > 1) { // skip this object, because I don't understand the format
136-
// examples: ashe skin23 sfx, ivern skin1 sfx, rammus skin6 and 16 sfx, yasuo skin17 sfx with unk4 = 2, and gangplank 8+ with unk4 = 56???
137-
v_printf(2, "Info: Skipping object because I can't read it lol.\n");
138-
return -1;
137+
if (has_positioning && has_3d) {
138+
if (bnk_version <= 0x59) {
139+
has_automation = (getc(bnk_file) & 3) != 1;
140+
fseek(bnk_file, 8, SEEK_CUR);
141+
} else {
142+
has_automation = (positioning_bits >> 5) & 3;
143+
getc(bnk_file);
144+
}
139145
}
140-
int to_seek = 25;
141-
if (unk4) {
142-
fseek(bnk_file, 13, SEEK_CUR);
143-
uint8_t unk5 = getc(bnk_file);
144-
dprintf("unk5: %d\n", unk5);
145-
to_seek += 12 * unk5;
146+
if (has_automation) {
147+
fseek(bnk_file, (bnk_version <= 0x59 ? 9 : 5), SEEK_CUR);
148+
uint32_t num_vertices;
149+
assert(fread(&num_vertices, 4, 1, bnk_file) == 1);
150+
fseek(bnk_file, 16 * num_vertices, SEEK_CUR);
151+
uint32_t num_playlist_items;
152+
assert(fread(&num_playlist_items, 4, 1, bnk_file) == 1);
153+
dprintf("num vertices: %d, prop count: %d, num_playlist items: %d, ftell: %ld\n", num_vertices, prop_count, num_playlist_items, ftell(bnk_file));
154+
fseek(bnk_file, (bnk_version <= 0x59 ? 16 : 20) * num_playlist_items, SEEK_CUR);
155+
} else if (bnk_version <= 0x59) {
156+
getc(bnk_file);
146157
}
147-
dprintf("ftell before the seek: %ld\n", ftell(bnk_file));
148-
dprintf("gonna seek %d\n", to_seek);
149-
fseek(bnk_file, to_seek, SEEK_CUR);
150-
} // end else
158+
fseek(bnk_file, 9, SEEK_CUR);
159+
uint16_t num_rtpc;
160+
assert(fread(&num_rtpc, 2, 1, bnk_file) == 1);
161+
for (int i = 0; i < num_rtpc; i++) {
162+
fseek(bnk_file, 12, SEEK_CUR);
163+
uint16_t point_count;
164+
assert(fread(&point_count, 2, 1, bnk_file) == 1);
165+
fseek(bnk_file, 12 * point_count, SEEK_CUR);
166+
}
167+
fseek(bnk_file, 24, SEEK_CUR);
151168
assert(fread(&new_random_container_object.sound_id_amount, 4, 1, bnk_file) == 1);
152169
dprintf("sound object id amount: %u\n", new_random_container_object.sound_id_amount);
153170
if (new_random_container_object.sound_id_amount > 100) {

0 commit comments

Comments
 (0)