How To Replace Music In GB4 For Steam
~ djkidna

You will need:

  • FModel https://fmodel.app/
  • foobar2000 https://www.foobar2000.org/
  • VGMStream decoder for foobar2000 (saved to components folder of foobar2000) https://www.foobar2000.org/components/view/foo_input_vgmstream
  •  VGAudio.Wpf-net47 https://github.com/Sajidur78/VGAudio.Wpf/releases/tag/1.1.1
  • Audio Editing Software of your choice (I use Audacity)

...

Getting started:
  • Go to Steam, right click on the game in your Library, go to Manage, then Browse Local Files
  • Open GB4\Content\Paks
  • Make a folder called mods here if you have not previously done so for other mods.

Getting to the music files:
  • Run FModel.
  • Open pakchunk0-WindowsNoEditor.pak in FModel.
  • Go to GB4\Content\Stream\Sound
  • Right click bgm.awb and export raw data.
  • Go to the output folder, it will have exported the AWB file with the full folder structure intact, mimicking the folder structure of the original game as shown in FModel. DO NOT EDIT THIS FOLDER OR THE FILES IN IT, it's best to have it as a backup just in case anything messes up.

Finding the song you want to replace:
  • Make a new folder elsewhere called modname_P. Copy and paste the GB4 folder that was generated by FModel in your new mod folder. When you open the folder, you should see the same file structure as shown in FModel (GB4\Content\Stream\Sound\bgm.awb).
  • Run foobar2000.
  • Open the bgm.awb file from your mod folder in foobar2000.
  • You can play each track to until you find the one you want to replace. For this guide, we will use Assault Awakening as an example. The Assault Awakening music is bgm#41, which also corresponds with the Item Index, essentially how the game knows which song to queue up for what in-game event or location.

The audio editing process:
  • The music files for the game are HCA files, which we cannot work with. But this will be what you will convert back to. To work with the audio, we will need to save the song as a WAV file.
  • In foobar2000, right click on the song and go Properties. Click on the Details tab and notate the Subsong index, Duration, Sample Rate, Channels, Bits per sample, Bitrate, <LOOP_END>, <LOOP_START>, and <SAMPLES>. These will be important for later.
  • Hit OK, right click on the song again, go to Convert, then [default] to save the track as a WAV file.
  • Run Audacity.
  • Open the WAV file in Audacity.
  • Open another Audacity window (Ctrl+N) and drag the song you are going to use into that Audacity window.
  • If you are worried that the new song might not be loud enough, click on the wave form, hit Ctrl+A to select all, go to Effect, Volume and Compression, and Limiter. Hit Presets & settings, Factory Presets, and Play it Loud. Change the Make-up target to 0, and Apply.
  • The original Assault Awakening song's loop goes from sample 1071792 <LOOP_START> to 2356992 <LOOP_END>. The new song's loop cannot end past the LOOP_END of the original song. The entire track cannot be longer than the original song's duration, and the HCA file that it will eventually be converted into cannot have a bigger file size than the original's HCA file if you were to extract it. But if you keep the song the right length, the file size should not be an issue, which is why I did not recommend extracting the original HCA file since foobar2000 cannot do this and it requires another program (VGMToolbox if you are curious). That said, you will not hear past the LOOP_END anyway, so truthfully you might as well cut the entire song at the LOOP_END timestamp to save some hassle. 
  • Once you have the song you want cut to size, find a good place for the song to loop. You can do this by hitting Enable Looping to the right of the Record button, or pressing L, and then putting the start and end points of the loop where you want it and hitting play to test. This is going to take some trial and error. Once you have found the best place for the song to loop, notate the start and end point of the loop. Easiest way to mark this is at the bottom of Audacity in the Selection section. You are going to want this information in hh:mm:ss + milliseconds since this will be the format needed when we are ready to change it.
  • Export the new song to a new WAV file. Check the metadata to make sure it is still showing the same LOOP_START and LOOP_END as the original song. DO NOT CHANGE THIS YET.

Converting WAV to HCA: 
  • Run VGAudio.
  • Open the new WAV file in VGAudio.
  • Change the dropdown next to "Save as" to HCA if it is not already selected.
  • Expand the Loop File menu. Put in the exact same LOOP_START and LOOP_END as the original song, then hit Save File.

Replacing the original song in the bgm file: 
  • Run ACE.
  • Go to File, Load (AWB), and open the bgm.awb file from your mod folder.
  • You'll notice that the tracks start at ID 0 in ACE, instead of Item Index 1 like in foobar, so you are looking for the track number minus 1. Assault Awakening track/item index 41, so in ACE it is ID 40.
  • Right click on the ID, hit replace, and replace it with the HCA file of the new song.
  • Right click on the ID again and hit Edit Loop. Now you can put in your custom loop. ACE has the loops in hh:mm:ss:ms format instead of sample format, which is why it was recommended you notate your new loop times in this format when in Audacity. 
  • If you ended up notating the loop times in a different format and closed Audacity already, you can go to https://calculator.academy/ultimate-calculator-builder/ and have it generate a calculator to change from one format to another, for instance you can ask it to do an "audio samples to hh:mm:ss:ms" calculator.
  • Save the bgm.awb file in ACE.
  • Drag the mod folder to UnrealPak-With-Compression.bat, when it's done it will show that you can hit a key to end.
  • Copy the modname_P.pak file to the mods folder in the Paks folder for GB4.

Testing the mod: 
  • Launch GB4.
  • Skip the opening cutscene to get to the Title Screen menu.
  • You will immediately know if it worked if you hear the Title Screen music, as this is a track that comes after Assault Awakening in the AWB file. If you hear the Title Screen music, go ahead and load your game, go to My Room, Assembly, and Activate Test Mode. Go ahead into Assault Awakening and you should hear the new music. Try to make Assault Awakening last through to the end of the loop to see if it looped correctly.
  • If it didn't work, either the new HCA file is somehow bigger than the original, or the loop was not setup correctly and it went past the original's LOOP_END. Cutting the new song down to the original's loop end should keep the file size right, so if it is the file size then you should go back and cut the song as recommended.

Article information

Added on

Written by

djkidna

0 comments