Replacing vanilla audio clips
Updated 10 months agoWhy should you use this?
Some audio clips and audio sources in Lethal Company are stored and located in fairly obscure places and finding some of them can be a pain, but with this method you do not need to even know where the audio is being played from. This also simplifies making sound replacement mods immensely.
Replacing a sound
Remember to check out some basic tutorials for BepInEx mods first, but this should be fairly easy to follow. First of all, to be able to use any part of LCSoundTool, you want to add using LCSoundTool;
to the top of your CSharp file. Most LCSoundTool functionality can be accessed through the SoundTool
class. Here is some basic pseudo code that uses a custom AudioClip variable called newSound
and replaces the sound the scanner makes when right clicking.
using LCSoundTool;
AudioClip newSound;
SoundTool.ReplaceAudioClip("Scan", newSound);
With this code we are using the SoundTool.ReplaceAudioClip()
method to add our custom audio clip to the list of replaced sounds in LCSoundTool, this list is used by the mod to automatically check when the vanilla sound plays if we have a sound replacing it and then play that new sound instead. The variables it takes in are the name of the vanilla sound, in this case "Scan" and an AudioClip of your choosing. The AudioClip you use can be obtained in many different ways. You could use the built in way of loading raw audio files from the disk or an AssetBundle for an example. For more details on how to get AudioClips into your mod, check out some other tutorials or use the built in loader.
Replacing a sound with multiple random variants
LCSoundTool let's you also specify multiple random variants for a single vanilla sound. This works by you specifying the desired chance as an additional float parameter to SoundTool.ReplaceAudioClip()
. If you do something like ReplaceAudioClip("SoundName", newRandomSound, 0.7f)
, then the vanilla sound called "soundName" will now play with 70% chance as the "newRandomSound" audio clip and then you could add another one like ReplaceAudioClip("SoundName", newRandomSound2, 0.3f)
which would now play with 30% chance each time the vanilla sound called "soundName" would play. The total chance is recommended to land at 100%, but the mod in theory supports anything higher or lower than 100% totals, even though the mod might complain about it in the console. Here is a basic example of how one could add two random sounds to the vanilla scan sound.
using LCSoundTool;
AudioClip newRandomSound1;
AudioClip newRandomSound2;
SoundTool.ReplaceAudioClip("Scan", newRandomSound1, 0.25f);
SoundTool.ReplaceAudioClip("Scan", newRandomSound2, 0.75f);
Replacing a sound based on what is making it
LCSoundTool let's you also specify specific UnityEngine AudioSources for a single vanilla sound. This works by having the AudioSources GameObjects names specified as a string or string array parameter. Here is a simple example:
using LCSoundTool;
AudioClip newSoundPlayer;
AudioClip newSoundEnemy;
SoundTool.ReplaceAudioClip("NewSound", newSoundPlayer, "AudioSourceName1");
SoundTool.ReplaceAudioClip("NewSound", newSoundEnemy, "AudioSourceName2");
Here the sound called "NewSound" will now only play the audio clip "newSoundPlayer" when it is playing from an AudioSource component located on a GameObject called "AudioSourceName1" and the clip "newSoundEnemy" if it is located on the GameObject called "AudioSourceName2". You can also input multiple sources, so if you want it to play on two, you would do something like SoundTool.ReplaceAudioClip("NewSound", newSoundPlayer, "AudioSourceName1,AudioSourceName2")
, as you can see you just need to use "," as the divider between the names. You can also combine this with the random chance from earlier with something like SoundTool.ReplaceAudioClip("NewSound", newSoundPlayer, 0.3f, "AudioSourceName1")
which would now play with 30% chance each time this vanilla sound plays from the AudioSource component located on a GameObject called "AudioSourceName1". The string parameter for this method can either be an array of strings or a single string with "," as the divider between each name, as shown earlier. Here is a simple example using the random chance float parameter.
using LCSoundTool;
AudioClip newSoundPlayer1;
AudioClip newSoundPlayer2;
SoundTool.ReplaceAudioClip("Step1", newSoundPlayer1, 0.25f, "playerAudios");
SoundTool.ReplaceAudioClip("Step1", newSoundPlayer2, 0.75f, "playerAudios");
This will play newSoundPlayer1
and newSoundPlayer2
only when played through an AudioSource attached to GameObject named "playerAudios", with the specified chances for each, 25% for newSoundPlayer1
and 75% for newSoundPlayer2
.
Restoring the vanilla sound
There might be situations where you want to revert your changes to vanilla sounds. This can be simply achieved with the following code:
using LCSoundTool;
SoundTool.RestoreAudioClip("Scan");
Here we use the RestoreAudioClip()
method and just supply it with the name of the original vanilla sound. This will then remove all replacement audio clips we have given to it from the list. If your sound uses the AudioSource names from the previous step you need to specify the AudioSource names as either an array of strings or string with the ',' character as a divider between each name. Here is a simple example.
using LCSoundTool;
SoundTool.RestoreAudioClip("Step1", "playerAudios");
SoundTool.RestoreAudioClip("Step1", "enemyAudios");
There is also a way to only remove one random clip if your sound has multiple random variants like shown in the previous part. This can be done with the following code:
using LCSoundTool;
SoundTool.RemoveRandomAudioClip("Scan", 0.25f, "playerAudios");
This uses the RemoveRandomAudioClip()
method instead and takes in the vanilla sound's name, a similar list of AudioSource names to the previous example, which can be omitted by leaving it blank or removing the parameter completely if your sound has no sources specified, meaning something like this SoundTool.RemoveRandomAudioClip("Scan", 0.25f);
would work too. Lastly it takes in the chance for this specific random clip. If there are multiple with the same chance it will remove the first one it finds with the specified chance. Remember that after removing one your total chance will most likely not match 100% or whatever your total chance was anymore.