Users who are viewing this thread

I'm guessing that once this main issue with the engine not reading the files fixed, playing sounds through code issue can get automatically resolved too.
 
Ah, I read your comment, I think you were only trying to replace native sound? That's not what I'm doing. I'm trying to add a new sound and play it from the code side. It's not playing or finding the sound even though XML is correct - according to documentation.
Gotcha. I was successful in creating/duplicating an animation and make it play custom sounds via xml editing.
 
It is possible to play sound in game. It was hard to find how to do that though. People need to edit project.mbproj file according to the way native project.mbproj file did.
SQ6EPxZ.png
ItDJuJA.png

In the modules you've created all filetypes are loaded as "Module". But the way native do is the only way to add new things. In native, filetypes are loaded as "file".
 
It is possible to play sound in game. It was hard to find how to do that though. People need to edit project.mbproj file according to the way native project.mbproj file did.
Yes, I mentioned this in my previous post but the problem was that the game didn't seem to use the XMLs. Debugging showed that it was detecting the documents, yet changes didn't actually show in-game. skins.xml is loaded the same way, and someone whom had successfully loaded a custom skins.xml before suddenly couldn't get it to work anymore, so we figured something was broken. Let me know if you are successfully able to add and play custom sounds like that right now. I just double-checked my files and it's not working for me.

I'll add a section on loading the files through project.mbproj when I do get it working though.
 
Last edited:
In other words, you still need that bulky Modding Tools even for such a simple operation?
to set up a module, yes you need.

Yes, I mentioned this in my previous post but the problem was that the game didn't seem to use the XMLs. Debugging showed that it was detecting the documents, yet changes didn't actually show in-game. skins.xml is loaded the same way, and someone whom had successfully loaded a custom skins.xml before suddenly couldn't get it to work anymore, so we figured something was broken. Let me know if you are successfully able to add and play custom sounds like that right now. I just double-checked my files and it's not working for me.

I'll add a section on loading the files through project.mbproj when I do get it working though.
Firstly i added this to the module_sounds.xml
XML:
<module_sound name="sam_musket_firing_01" sound_category="mission_foley" path="musket_firing_01.wav"/>
Then put the sound file to the folder named "ModuleSounds".
After this, i edited the project.mbproj file the way i showed above.
Lastly I overrided the release_crossbow animation clip to put sam_musket_firing_01 on sound code. Saved, restarted the game and went to main game to test the musket. It worked. However, you would still have to get proper FMOD tools to make variations for sounds though. You cannot put any other sound name to the sound code section in animation clip. It needs to get only one sound.
 
to set up a module, yes you need.
Well, that's bad and sad. Because there is no packaging happening anyway for audios and they are all read from disk/folder directly - and for module_strings.xml for example, you don't require to have modding tools.
And I would expect the same behaviour from module_sounds.xml as well and in it, it's also claiming that you can play it as long as you have the keys set properly.
- Sounds that dont have valid categories wont be played!
example:
int soundIndex = SoundEvent.GetEventIdFromString("example/voice/charge");//to avoid string operations in runtime soundIndex can be cached.
if (playOneshot)
{
MakeSound(soundIndex, MainAgent.Position, false, true, -1, -1);//plays oneshot sound at position with given parameters.
}
else
{
SoundEvent eventRef = SoundEvent.CreateEvent(soundIndex, Scene);//get a reference to sound and update parameters later.
eventRef.SetPosition(MainAgent.Position);
eventRef.Play();
}
I guess something is not right with sound modding at the moment as Reus and you already mentioned and struggled with. Let's see if they can fix this soon. Playing a sound shouldn't be rocket science and shouldn't require hella different weird changes.
 
Well, that's bad and sad
I guess something is not right with sound modding at the moment as Reus and you already mentioned and struggled with. Let's see if they can fix this soon. Playing a sound shouldn't be rocket science and shouldn't require hella different weird changes.
100% Agreed! This overly convoluted method should be fixed.

Speaking of rocket science, we figured out how to use harmony to force load custom soundtrack.xml (so you can play music from your own mod folder without the need to overwrite any vanilla files.
It can be done by postfixing the path to the xml like this:
C#:
namespace Shokuho
{
    // Music Patching
    [HarmonyPatch(typeof(MBMusicManager), MethodType.Constructor)]
    public class MBMusicManagerPatch
    {
        private static void Postfix(MBMusicManager __instance)
        {
            if (!NativeConfig.DisableSound)
            {
                int num = (int)PsaiCore.Instance.LoadSoundtrackFromProjectFile(BasePath.Name + "Modules/Shokuho/ModuleSounds/Music/soundtrack.xml");
            }

            System.Diagnostics.Debug.WriteLine("Postfix loaded! (Music)");
        }
    }
}

However, I have yet to produce a file that the xml will accept in place of "Maintheme". So far it just results in all music disappearing.
If anyone has better luck with this, be sure to let me know. :smile:

(Note: Not sure if related but https://csharp.hotexamples.com/examples/psai.Editor/Segment/-/php-segment-class-examples.html)
 
Speaking of rocket science, we figured out how to use harmony to force load custom soundtrack.xml (so you can play music from your own mod folder without the need to overwrite any vanilla files.
It can be done by postfixing the path to the xml like this:
I'm not sure but based on that code piece, it appears that this Instance can be called from anywhere - hence you don't need Harmony for that - you can simply call it in your OnSubmoduleLoad or somewhere else, right?


It's related to https://assetstore.unity.com/packages/tools/audio/psai-music-engine-pro-24788
More or less same engine as far as I know - basically PSAI combines music for atmosphere and triggers and plays them smoothly. But to be honest, I see a really weak implementation/usage of this library in Bannerlord. All sounds and music is simply too plain and doesn't reflect actions properly. No proper transition either - as far as I can see.
 
I'm not sure but based on that code piece, it appears that this Instance can be called from anywhere - hence you don't need Harmony for that - you can simply call it in your OnSubmoduleLoad or somewhere else, right?
Technically yes, however, it needs to write to "_battleMode" and "_campaignMode", both of which are readonly (and then probably call Initialize), in order for it to take effect.

(Here is the original code from MBMusicManager.cs, shortened to relevant items only)
C#:
private readonly MBMusicManager.BattleMusicMode _battleMode;
private readonly MBMusicManager.CampaignMusicMode _campaignMode;

private MBMusicManager()
    {
      if (!NativeConfig.DisableSound)
      {
        int num = (int) PsaiCore.Instance.LoadSoundtrackFromProjectFile(BasePath.Name + "music/soundtrack.xml");
      }
      this._battleMode = new MBMusicManager.BattleMusicMode();
      this._campaignMode = new MBMusicManager.CampaignMusicMode();
    }

As far as I know (my programming knowledge is limited), there is no way to reference MBMusicManager in order to call its functions directly from our scripts. If it were possible, then we probably could just directly change the LoadSoundtrackFromProjectFile as you said and then call Initialize() again so it assigns it to the current MBMusicManager.
 
Technically yes, however, it needs to write to "_battleMode" and "_campaignMode", both of which are readonly (and then probably call Initialize), in order for it to take effect.
Yes but it's not related to that line anyway. Because return value isn't used.
If it was something like this
C#:
int num = (int) PsaiCore.Instance.LoadSoundtrackFromProjectFile(BasePath.Name + "music/soundtrack.xml");
this._battleMode = new MBMusicManager.BattleMusicMode(num);
this._campaignMode = new MBMusicManager.CampaignMusicMode(num);
then you would be right. But its not taking any argument and as far as I can see from code, those `modes` are not accessing PsaiCore.Instance directly. So you can call it from anywhere you want - since its Singleton pattern.
And MBMusicManager is only initializing the PsaiCore.Instance with that call. So you can do that after it's execution too. You can give it a shot I think. If you see that it's not working without Harmony solution, it means that I'm missing something.

That being said, 3D sound and Psai are different things as far as I can see - so I still need proper documentation on this :smile:
 
I'm having issues with fire arms. I've added the custom sound to the animations, but I am now running into a few issues.

1. Knowledge based - How do I get the sounds to sound muted with distance or add reverb?
2. Limitations - After a certain number of firearms go off in large battles, eventually all of the firearms sounds muted. Any ideas?

If anyone is interested in taking a look, you can see the mod here: https://www.nexusmods.com/mountandblade2bannerlord/mods/2742?tab=description
 
I need help I want to replace existing combat sounds in the BANK files, is there a guide for that?

Can anyone give me an example of code for the module_sounds.xml to play mission_combat sounds?
 
Last edited:
this guide does not cover the proper way to replace existing /mission/combat/ sounds for new ones, is it even possible to do it? no one has done that since 2020 why do devs hate sound modding?
 
I'm having issues with fire arms. I've added the custom sound to the animations, but I am now running into a few issues.

1. Knowledge based - How do I get the sounds to sound muted with distance or add reverb?
2. Limitations - After a certain number of firearms go off in large battles, eventually all of the firearms sounds muted. Any ideas?

If anyone is interested in taking a look, you can see the mod here: https://www.nexusmods.com/mountandblade2bannerlord/mods/2742?tab=description
I think you need to specify if your sounds are 3d inside your module_sounds.xml, you have to write "false" on is_2d="true"


<module_sound name="example/combat/hit" is_2d="true" sound_category="mission_combat" path="example_sound_modders.ogg" />
 
I think you need to specify if your sounds are 3d inside your module_sounds.xml, you have to write "false" on is_2d="true"


<module_sound name="example/combat/hit" is_2d="true" sound_category="mission_combat" path="example_sound_modders.ogg" />
Actually - there was originally a bug that seems to have been resolved some time ago. This has been fixed by TW!
 
There is a sound situation related to animations, unfortunately we are having trouble adding sound to an animation.

As @Kabraxis stated, adding any sound is successful, but it is possible to run an animation in prefab logic, but this is meaningless for us. Our animation in question is Musket Reload Animation and we have a specially made sound for it. The animation consists of 2 parts.
 
I was playing with adding sounds recently and since this thread was useful to me, I thought I might as well add my findings here. It's not rocket science, but I guess some extra info won't hurt.

As stated previously, you need ModuleData\project.mbproj file for the game to load your module_sounds.xml. However you don't need the modkit to create this file. Here is a minimal .mbproj file that works:
XML:
<base type="solution">
  <file id="soln_module_sound" name="ModuleData/module_sounds.xml" type="module_sound" />
</base>

Another observation is that the is_2d attribute isn't enough to make a sound 2D. You need both this attribute and a 2D sound_category, such as ui or mission_ambient_bed.
Sounds in a 3D sound_category with is_2d=true have some spatial properties disabled (at least spatial volume falloff) but sound event still has a 3D position that affects stereo effect, event max distance and maybe other things.
SoundEvent.PlaySound2D requires that you select an actual 2D sound_category for your sound. The attribute isn't enough.

Finally, here's a video of me adding sound effects to my tutorial mod:
 
Also, I was playing with them too, and I find out that currently using "alert" for the sound category gives the best result. Alert also has limits

The other sound categories limits you. It doesn't lets you play full duration only 2-3 sec at maximum. The only one I found that lets you use full duration of sound clips is ambient ones, but they stay in the loop when you fire them.

XML:
    <module_sound name="serdar" is_2d="false" sound_category="alert" path="serdar.wav" />

Here is a clip tested in mp




Also here you can find my ****ty code below.

C#:
using TaleWorlds.MountAndBlade;
using TaleWorlds.Core;
using TaleWorlds.Localization;
using TaleWorlds.Engine;
using TaleWorlds.InputSystem;

namespace serdar
{
    public class SubModule : MBSubModuleBase
    {
        public override void OnMissionBehaviorInitialize(Mission mission)
        {
            if (mission.CombatType == Mission.MissionCombatType.Combat && mission.IsFriendlyMission)
            {
                mission.AddMissionBehavior(new SerdarBehaviour());
            }
        }


    }

    public class SerdarBehaviour : MissionBehavior
    {
        public override MissionBehaviorType BehaviorType => MissionBehaviorType.Other;

        private SoundEvent eventRef;

        public override void OnMissionTick(float dt)
        {
            if (InputKey.Space.IsPressed())
            {
                int soundIndex = SoundEvent.GetEventIdFromString("hurdaci");
                Mission.Current.MakeSound(soundIndex, Mission.Current.MainAgent.Position, false, true, -1, -1);
                InformationManager.DisplayMessage(new InformationMessage("hurdaci gelieah"));
           
            }
            if (InputKey.M.IsPressed())
            {
                if (eventRef == null || !eventRef.IsPlaying())
                {
                    int soundIndex = SoundEvent.GetEventIdFromString("serdar");
                    eventRef = SoundEvent.CreateEvent(soundIndex, Mission.Current.Scene);//get a reference to sound and update parameters later.
                    eventRef.SetPosition(Mission.Current.MainAgent.Position);
                    eventRef.Play();
                }
                InformationManager.DisplayMessage(new InformationMessage("YAPMA NOLURSUN YABANCI DEGILIM"));
            }
            if (InputKey.N.IsPressed())
            {
                if (eventRef != null)
                {
                    eventRef.Stop();
                    eventRef.Release();
                }
                int soundIndex = SoundEvent.GetEventIdFromString("reload_full");
                eventRef = SoundEvent.CreateEvent(soundIndex, Mission.Current.Scene);//get a reference to sound and update parameters later.
                eventRef.SetPosition(Mission.Current.MainAgent.Position);
                eventRef.Play();
                InformationManager.DisplayMessage(new InformationMessage("reloading"));
            }

            if (eventRef != null && eventRef.IsPlaying())
            {
                eventRef.SetPosition(Mission.Current.MainAgent.Position);
            }
        }
    }

}

This one doesn't follow the agent while playing the sound.

MakeSound(soundIndex, MainAgent.Position, false, true, -1, -1); //plays oneshot sound at position with given parameters.

But this one does

SoundEvent eventRef = SoundEvent.CreateEvent(soundIndex, Scene);//get a reference to sound and update parameters later.
eventRef.SetPosition(MainAgent.Position);
eventRef.Play();




Example in sp

Plays when space is pressed

mission_ambient_3d_big (Because of that its on a loop)

Don't follows the agent because it uses

MakeSound(soundIndex, MainAgent.Position, false, true, -1, -1); //plays oneshot sound at position with given parameters.

 
Last edited:
Has anyone managed to find music play during character creation etc? I want to make a music mod, but I can only replace the ones in "Mount & Blade II Bannerlord\music\PC".
 
Back
Top Bottom