@@ -84,19 +84,30 @@ struct random_container {
8484 uint32_t * sound_ids ;
8585};
8686
87+ struct switch_container {
88+ uint32_t self_id ;
89+ uint32_t parent_id ;
90+ uint8_t group_type ;
91+ uint32_t group_id ;
92+ uint32_t num_children ;
93+ uint32_t * children ;
94+ };
95+
8796typedef LIST (struct sound ) SoundSection ;
88- typedef LIST (struct music_track ) MusicTrackSection ;
89- typedef LIST (struct music_container ) MusicContainerSection ;
9097typedef LIST (struct event_action ) EventActionSection ;
9198typedef LIST (struct event ) EventSection ;
9299typedef LIST (struct random_container ) RandomContainerSection ;
100+ typedef LIST (struct switch_container ) SwitchContainerSection ;
101+ typedef LIST (struct music_container ) MusicContainerSection ;
102+ typedef LIST (struct music_track ) MusicTrackSection ;
93103typedef LIST (struct music_switch ) MusicSwitchSection ;
94104
95105struct BNKSections {
96106 SoundSection sounds ;
97107 EventActionSection event_actions ;
98108 EventSection events ;
99109 RandomContainerSection random_containers ;
110+ SwitchContainerSection switch_containers ;
100111 MusicContainerSection music_segments ;
101112 MusicTrackSection music_tracks ;
102113 MusicSwitchSection music_switches ;
@@ -267,6 +278,14 @@ void free_random_container_section(RandomContainerSection* section)
267278 free (section -> objects );
268279}
269280
281+ void free_switch_container_section (SwitchContainerSection * section )
282+ {
283+ for (uint32_t i = 0 ; i < section -> length ; i ++ ) {
284+ free (section -> objects [i ].children );
285+ }
286+ free (section -> objects );
287+ }
288+
270289void free_music_container_section (MusicContainerSection * section )
271290{
272291 for (uint32_t i = 0 ; i < section -> length ; i ++ ) {
@@ -323,6 +342,26 @@ int read_random_container_object(FILE* bnk_file, RandomContainerSection* random_
323342 return 0 ;
324343}
325344
345+ int read_switch_container_object (FILE * bnk_file , SwitchContainerSection * switch_containers , uint32_t bnk_version )
346+ {
347+ struct switch_container new_switch_container_object ;
348+ assert (fread (& new_switch_container_object .self_id , 4 , 1 , bnk_file ) == 1 );
349+
350+ new_switch_container_object .parent_id = skip_base_params (bnk_file , bnk_version , NULL );
351+ assert (fread (& new_switch_container_object .group_type , 1 , 1 , bnk_file ) == 1 );
352+ if (bnk_version <= 0x59 ) fseek (bnk_file , 3 , SEEK_CUR );
353+ assert (fread (& new_switch_container_object .group_id , 4 , 1 , bnk_file ) == 1 );
354+ fseek (bnk_file , 5 , SEEK_CUR );
355+
356+ assert (fread (& new_switch_container_object .num_children , 4 , 1 , bnk_file ) == 1 );
357+ new_switch_container_object .children = malloc (new_switch_container_object .num_children * sizeof (uint32_t ));
358+ assert (fread (new_switch_container_object .children , 4 , new_switch_container_object .num_children , bnk_file ) == new_switch_container_object .num_children );
359+
360+ add_object (switch_containers , & new_switch_container_object );
361+
362+ return 0 ;
363+ }
364+
326365int read_sound_object (FILE * bnk_file , SoundSection * sounds , uint32_t bnk_version )
327366{
328367 struct sound new_sound_object ;
@@ -542,6 +581,9 @@ int parse_event_bnk_file(char* path, struct BNKSections* sections)
542581 case 5 :
543582 read_random_container_object (bnk_file , & sections -> random_containers , bnk_version );
544583 break ;
584+ case 6 :
585+ read_switch_container_object (bnk_file , & sections -> switch_containers , bnk_version );
586+ break ;
545587 case 10 :
546588 read_music_container_object (bnk_file , & sections -> music_segments , bnk_version );
547589 break ;
@@ -613,6 +655,15 @@ void add_connected_files(char* string, uint32_t id, uint32_t parent_id, StringHa
613655 return ;
614656 }
615657
658+ struct switch_container * switch_container = NULL ;
659+ find_object_s (& sections -> switch_containers , switch_container , self_id , id );
660+ if (switch_container ) {
661+ for (uint32_t i = 0 ; i < switch_container -> num_children ; i ++ ) {
662+ add_connected_files (string , switch_container -> children [i ], id , stringHashes , sections );
663+ }
664+ return ;
665+ }
666+
616667 struct music_container * music_segment = NULL ;
617668 find_object_s (& sections -> music_segments , music_segment , self_id , id );
618669 if (music_segment ) {
@@ -731,6 +782,7 @@ WemInformation* bnk_extract(int argc, char* argv[])
731782 initialize_list (& sections .event_actions );
732783 initialize_list (& sections .events );
733784 initialize_list (& sections .random_containers );
785+ initialize_list (& sections .switch_containers );
734786 initialize_list (& sections .music_segments );
735787 initialize_list (& sections .music_tracks );
736788 initialize_list (& sections .music_switches );
@@ -745,6 +797,7 @@ WemInformation* bnk_extract(int argc, char* argv[])
745797 sort_list (& sections .event_actions , self_id );
746798 sort_list (& sections .events , self_id );
747799 sort_list (& sections .random_containers , self_id );
800+ sort_list (& sections .switch_containers , self_id );
748801 sort_list (& sections .music_segments , self_id );
749802 sort_list (& sections .music_tracks , self_id );
750803 sort_list (& sections .music_switches , self_id );
@@ -811,6 +864,7 @@ WemInformation* bnk_extract(int argc, char* argv[])
811864 free_simple_section (& sections .event_actions );
812865 free_event_section (& sections .events );
813866 free_random_container_section (& sections .random_containers );
867+ free_switch_container_section (& sections .switch_containers );
814868 free_music_container_section (& sections .music_segments );
815869 free_music_track_section (& sections .music_tracks );
816870 free_music_switch_section (& sections .music_switches );
0 commit comments