pixeltris / YgoMaster

Offline Yu-Gi-Oh! Master Duel
MIT License
881 stars 126 forks source link

Conflicting behavior between SoundInterceptor.cs and Bgm.json #471

Open Merik2013 opened 2 months ago

Merik2013 commented 2 months ago

First off, thanks for reviewing my code for me and getting SoundInterceptor working. works great. That said, I had to delete Bgm.json from my mod. It takes over when using a user deck in Solo mode and there isn't a setting I can toggle to disable that behavior. That, in itself, isn't the biggest issue, though. When the game pulls from Bgm,json instead of the duel file while a SoundInterceptor.cs setting is enabled the BGM will completely cut out when it tries to swap tracks.

probably simpler than trying to make these work together might be to add a settings.json entry for just disabling the Bgm.json. This would prevent some unneeded complaints from people who have left over files from swapping from a mod that doesn't use custom music to one that does. Mods that use custom music can just adjust this in the settings file before distributing a build to ensure the correct music gets played and to make sure the music doesn't break from this issue.

pixeltris commented 2 months ago

When the game pulls from Bgm,json instead of the duel file while a SoundInterceptor.cs setting is enabled the BGM will completely cut out when it tries to swap tracks

This shouldn't happen. SoundInterceptor.cs has no relation to Bgm.json. If there is a problem with playback the problem is entirely within SoundInterceptor.cs as it's the only thing which messes with the playback of the tracks

settings.json entry for just disabling the Bgm.json

Solo duels where you use a loaner deck it'll use the BGM as defined in the duel settings json. Solo duels where you use your own deck it'll use your own duel field BGM only if the players BGM setting is set to play their own duel field BGM. If the opponents duel field BGM is enabled in the settings it'll play what's inside of duel settings json

https://github.com/pixeltris/YgoMaster/blob/d2c19a4aea9b68d3cbde36804b7ff8c3fe3d3b9a/YgoMasterServer/Acts/Act_Duel.cs#L156-L159

A setting could be added to override the duel field BGM option

Merik2013 commented 2 months ago

I'm currently going through this issue with my AI assistant. I've found that the issue is the timing of when StopBGM is called as indicated here:

[SoundInterceptor] StopBGM called! 
[SoundInterceptor] PlayBGM called: idx = 0, delay = -1
[SoundInterceptor] Current BGM settings - singleBgm: True, doubleBgm: False, noKeycardBGM: False
[SoundInterceptor] Playing new BGM: idx = 0
[SoundInterceptor] StopBGM called! // here
[SoundInterceptor] PlayBGM called: idx = 1, delay = -1
[SoundInterceptor] Current BGM settings - singleBgm: True, doubleBgm: False, noKeycardBGM: False
[SoundInterceptor] Blocked transition, playing idx: 0
[SoundInterceptor] No transition, BGM continues: idx = 0

I'm currently attempting to block StopBGM, but only at the desired points. I need to make sure it isn't still disabled by the end of the duel.

pixeltris commented 2 months ago

I'm not really sure. There are a few places where StopBGM is called:

YgomGame.Duel.DuelEndOperation.PlayWinLose()
YgomGame.Duel.DuelEntryController.PlayTimeline()
YgomGame.Duel.LethalEffect.Play(int, Action, bool, Vector3, bool, bool, LethalEffect.EffectType, Vector3)
YgomGame.Duel.MonsterCutinEffect.Play(Action, Action, double, bool)
YgomGame.Duel.Sound.Term()
YgomGame.Duel.Sound.UnloadBGM()

It's probably just the MonsterCutinEffect one which is causing you problems? You might be able to look at the callstack when StopBGM is called and ignore it if called by MonsterCutinEffect?