Currently viewing this thread:

Bloc

Duke
WB
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.
 

bestmods168

Sergeant
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.
 

HyperCharge

Section Moderator
M&BWBWF&SNWVC
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".
 

Reus

Sloppy Dabber
Global Moderator
M&BWBNWWF&SVC
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:

HyperCharge

Section Moderator
M&BWBWF&SNWVC
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.
 

Bloc

Duke
WB
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.
 

Alemismun

Recruit
M&BWBWF&SNWVC
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)
 

Bloc

Duke
WB
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.
 

Alemismun

Recruit
M&BWBWF&SNWVC
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.
 

Bloc

Duke
WB
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:
 

KingKilo

Recruit
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
 
Top Bottom