Skip to content

Guide: Adding BGM From Other Missions

NasaNhak edited this page Apr 2, 2017 · 3 revisions

How to add BGM from any other mission:

  1. First find the code associated with the BGM track via the mission specific '_sequence' or '_demo' Lua file. In this example, I have taken the heli pullout BGM from Mission 2 Diamond Dogs:

    TppSound.SetSceneBGM("bgm_mtbs_departure")
    
    TppSound.SetSceneBGMSwitch("Set_Switch_bgm_s10030_departure")
    
  2. Next step is to look in the mission's '_sound' Lua file and identify the BGM information. In this case, that file is 's10030_sound.lua':

     this.bgmList = {
    
       bgm_mtbs_departure = {
    
     	start = "Play_bgm_s10030_departure",
    
     	finish = "Stop_bgm_s10030_departure",
    
     	switch = {
    
     		"Set_Switch_bgm_s10030_helicall",
    
     		"Set_Switch_bgm_s10030_departure",
    
     	}
    
       }
    
     }
    
  3. Now we will look at how to add this BGM track to the Zoo which is a perfect example since it does not have it's own BGM info. For the purposes of this demo, this particular BGM has already been added to Motherbase free roam f30050 correctly and f30050 files will be used to setup the BGM data in f30150(Zoo)

  4. So first things first. The BGM banks are located in the path "\Assets\tpp\sound\asset" in each of the chunk dats. The sound banks are sbp files. These sbp files are loaded via a mission specific sdf file which is present in the '_area.fpkd' file of the mission.

  5. The BGM we are porting over is from M2(s10030) and belongs to chunk3. The paths to the sbp and sdf files are as below:

    chunk3\Assets\tpp\sound\asset\bgm_s10030.sbp
    
    chunk3\Assets\tpp\pack\mission2\story\s10030\s10030_area_fpkd\Assets\tpp\sound\package\bgm_s10030.sdf
    
  6. The sdf file can be unpacked and repacked via the FOX2 tool. It simply has a reference to which sound banks to load from the "\Assets\tpp\sound\asset" folder. So in the case of s10030, the entry in the sdf file looks like this:

    <property name="loadBanks" type="String" container="DynamicArray" arraySize="2">
    
    	  <value>bgm_s10030</value>
    
  7. Any additional sound banks can be added via an extra value tag.

  8. Let's begin porting over this BGM to the Zoo. Unpack f30050.fpkd and f30150.fpkd via GzsTool.

  9. f30150 does not have it's own BGM data so copy the following files:

    f30050_sound.lua
    f30050_sound_music.fox2
    

    from:

    f30050_fpkd\Assets\tpp\level\mission2\free\f30050
    

    to:

    f30150_fpkd\Assets\tpp\level\mission2\free\f30150
    
  10. Rename the copied files to match with the f30150 naming convention:

    f30150_sound.lua
    
    f30150_sound_music.fox2
    
  11. We are only interested in the BGM list present in 'f30150_sound.lua' so change the list to as follows:

    this.bgmList = {
    
    	bgm_mtbs_departure = {
    
    		start = "Play_bgm_s10030_departure",
    
    		finish = "Stop_bgm_s10030_departure",
    
    		switch = {
    
    			"Set_Switch_bgm_s10030_helicall",
    
    			"Set_Switch_bgm_s10030_departure",
    
    		}
    
    	},
    
    }
    
  12. This is an important step. Unpack 'f30150_sequence.fox2' via FOX2 tool. Look for the entity TppSimpleMissionData in the generated xml. Under the subScripts tag, you want to update the sound key so it will now look like this:

    <value key="sound">/Assets/tpp/level/mission2/free/f30150/f30150_sound.lua</value>
    

    For a mission that already uses BGM this step isn't necessary but for Zoo(f30150) and MBQF(f30250) it is important! Once the xml is update, rebuild the FOX2 file via the FOX2 tool.

  13. 'f30150_sound_music.fox2', that we copied over and renamed earlier, holds the reference to the sdf file and can be unpacked via FOX2 tool. Since the file was copied over from f30050, it holds the same sdf file path as for Motherbase(f30050). It should be possible to change the sdf name but have not tried this yet. So in this case, simply use the same name for the sdf file.

  14. Copy 'bgm_mtbs_phase.sdf' from:

    f30050_fpkd\Assets\tpp\sound\package
    

    to:

    f30150_fpkd\Assets\tpp\sound\package
    
  15. Unpack the copied over 'bgm_mtbs_phase.sdf' via FOX2 tool. It will hold the load banks as mentioned earlier. Since this file it from f30050, it already holds sound banks from MB:

    <property name="loadBanks" type="String" container="DynamicArray" arraySize="2">
    
            <value>bgm_mtbs_phase</value>
    
            <value>p51_020030</value>
    
    </property>
    
  16. Change this to:

    <property name="loadBanks" type="String" container="DynamicArray" arraySize="1">
    
            <value>bgm_s10030</value>
    
    </property>
    

    Now repack the xml via FOX2 tool.

    While there is no need to remove the other sound banks at all, Zoo doesn't use any BGM so they are really not necessary. If adding sound banks to a mission that already has BGM sound banks, you would want to add an extra value tag entry.

  17. Now that all our files and data is ready, all we need to do is repack the 'f30150.fpkd' file with the additional files and write the code.

  18. Open 'f30150.fpkd.xml' that GzsTool would have generated and add the following entries:

    <Entry FilePath="/Assets/tpp/level/mission2/free/f30150/f30150_sound_music.fox2" />
    
    <Entry FilePath="/Assets/tpp/sound/package/bgm_mtbs_phase.sdf" />
    
    <Entry FilePath="/Assets/tpp/level/mission2/free/f30150/f30150_sound.lua" />
    

    Entries have to be added in alphabetic order first by file type and then by full path to the file. It's a bit tricky but if you look at 'f30050.fpkd.xml' you will understand.

    Repack the fpkd via GzsTool.

  19. In order to fire this BGM, I have tied it to the pullout message from the heli, but that really isn't necessary:

    function this.Messages()
    
            return Tpp.StrCode32Table{
    
                    GameObject={
    
                            {
    
                                    msg = "StartedPullingOut", sender = {"SupportHeli", "TppHeli2"},
    
                                    func = function ()
    
                                            this.PlayPulloutBGMFromM2()
    
                                    end
    
                            },
    
                    }
    
            }
    
    end
    
    ..................
    
    ..................
    
    ..................
    
    function this.PlayPulloutBGMFromM2()
    
            TppSound.SetSceneBGM("bgm_mtbs_departure")
    
            TppSound.SetSceneBGMSwitch("Set_Switch_bgm_s10030_departure")
    
            TppSoundDaemon.SetMute( 'HeliClosing' )
    
    end
    
  20. If you did everything right, and if I didn't miss any step then you would have ported over the BGM from M2 to the Zoo.

  21. Interesting tidbit: the engine is capable of playing audio files from the middle. The BGM file in this case is present in bgm_s10030.sbp as the file 'File0001'. This actually consists of two separate tracks which the call TppSound.SetSceneBGMSwitch knows how to distinguish based on the bgmList in '_sound' Lua file. A lot of missions use this approach for example the Prologue/M46 have TMWSTW track stitched together with two other tracks. Why they would do something like this is beyond me. Maybe some kind of performance improvement by loading a single track into memory instead of switching tracks?

  22. It may be possible to load sbp sound banks across chunks provided they are added to 00.dat

Final results:

https://youtu.be/4jWel1BPF1Q

https://youtu.be/xpUNNDQW6KY

https://youtu.be/58aX4zDia_8

Clone this wiki locally