mirror of
https://github.com/P3D-Legacy/P3D-Legacy.git
synced 2025-07-31 01:35:20 +02:00
* Replaced existing Gen 2 SFX with better sounding ones (no ugly reverb) Replaced MediaPlayer with NAudio(and NAudio.Vorbis) for playing music in order to fix random stopping issues. The game now directly loads .ogg files instead of the .wma/.xnb combination from before. ContentPacks are now able to replace Music and SFX again (I haven't added a menu yet for choosing ContentPacks). To make older GameModes work with current versions, you can add the GameMode property EnterType and set it to "1", this will make the game use the older 2D NewGameScreen. * Delete GameController.vb * Add gamecontroller.vb back * Fix sfx missing * Battleintro doodle now doesn't loop anymore (for no trainer) Changed the shutter sound (aka Large Door sound) to something more large door-y Made the enter sound slightly louder The enter sound now plays when going through any warp to or from an indoor map (including falling through holes) The flying sound effect is played earlier in the animation after selecting a location Changed played sound effect when using the Escape Rope to "teleport" instead of "destroy" The bump noise now also plays when bumping into something in first person Fixed small gap between the end of the intro song and the start of the main song Replaced some songs with better songs * Fixed some more intro issues * Forgot to change a thing * Fixed an error where the main music would play, ignoring the muted musicmanager. * fix indenting in musicmanager * The music player will now only start playback on a new song if the music player is not muted, fixed the end time calculation of the intro of a song after muting, Music can't be unmuted now as long as a sound effect plays that stops the music. * Fixed league restplace position, fixed sound effects sharing the volume slider of the music, sound effects are now also muted when pressing M, changed music on/off popup to audio on/off, removed bump delay in first person, added more control on whether played songs should be looping or not. * Fixed some more scripts that turn on thirdperson mode but don't check if it was on before or set it back to what it was before afterwards, also fixed a small error in creditsscreen.vb. * Fixed indenting error in musicmanager.vb, fixed an error of mine where the loopsong parameter would be seen as the playintro parameter. * Added more music commands, added quite some menu select noises, will add more later * More select sound effects! * Fix music not resuming after soundeffect * Trainer using item now plays the single_heal soundeffect * Pokémon cries now sound louder * Possibly fixing crash when playing Pokémon cry at volume higher than 0.71 * Added better quality Pokémon cries, made random overworld cries slightly less loud, added cries for 719 and 720. * Sound effects now sound louder * Revert "Added better quality Pokémon cries, made random overworld cries slightly less loud, added cries for 719 and 720." This reverts commit 8c9296ed1a82144d17f303a52c3f2e9e65a5bfea. * Fixed the cause of why the title screen music plays even when the game is muted * Tabs to spaces * Revert Co-authored-by: darkfire006 <blazer257@live.com> Co-authored-by: JappaWakkaP3D <66885565+JappaWakkaP3D@users.noreply.github.com> Co-authored-by: JappaWakkaP3D <jasper.speelman@outlook.com> Co-authored-by: Vitaly Mikhailov <personal@aragas.org>
166 lines
6.9 KiB
VB.net
166 lines
6.9 KiB
VB.net
Public Class SoundManager
|
|
|
|
Const POKEMON_CRY_VOLUME_MULTIPLIER As Single = 1.0F
|
|
|
|
Shared _sounds As Dictionary(Of String, SoundContainer) = New Dictionary(Of String, SoundContainer)
|
|
|
|
Public Shared Volume As Single = 1.0F
|
|
Public Shared Muted As Boolean = False
|
|
|
|
Private Declare Function GetAudioOutputDevices Lib "winmm.dll" Alias "waveOutGetNumDevs" () As Integer
|
|
Private Shared Function HasOutputDeviceAvailable() As Boolean
|
|
Return GetAudioOutputDevices() > 0
|
|
End Function
|
|
|
|
Private Shared Function AddSound(ByVal Name As String, ByVal forceReplace As Boolean) As Boolean
|
|
Try
|
|
Dim cContent As ContentManager = ContentPackManager.GetContentManager("Sounds\" & Name, ".xnb,.wav")
|
|
|
|
Dim loadSound As Boolean = False
|
|
Dim removeSound As Boolean = False
|
|
|
|
If _sounds.ContainsKey(Name.ToLower()) = False Then
|
|
loadSound = True
|
|
ElseIf forceReplace = True And _sounds(Name.ToLower()).IsStandardSound = True Then
|
|
removeSound = True
|
|
loadSound = True
|
|
End If
|
|
|
|
If loadSound = True Then
|
|
Dim sound As SoundEffect = Nothing
|
|
|
|
If System.IO.File.Exists(GameController.GamePath & "\" & cContent.RootDirectory & "\Sounds\" & Name & ".xnb") = False Then
|
|
If System.IO.File.Exists(GameController.GamePath & "\" & cContent.RootDirectory & "\Sounds\" & Name & ".wav") = True Then
|
|
Using stream As System.IO.Stream = System.IO.File.Open(GameController.GamePath & "\" & cContent.RootDirectory & "\Sounds\" & Name & ".wav", IO.FileMode.OpenOrCreate)
|
|
sound = SoundEffect.FromStream(stream)
|
|
End Using
|
|
Else
|
|
Logger.Log(Logger.LogTypes.Warning, "SoundManager.vb: Sound at """ & GameController.GamePath & "\" & cContent.RootDirectory & "\Songs\" & Name & """ was not found!")
|
|
Return False
|
|
End If
|
|
Else
|
|
sound = cContent.Load(Of SoundEffect)("Sounds\" & Name)
|
|
End If
|
|
|
|
If Not sound Is Nothing Then
|
|
If removeSound = True Then
|
|
_sounds.Remove(Name.ToLower())
|
|
End If
|
|
_sounds.Add(Name.ToLower(), New SoundContainer(sound, cContent.RootDirectory))
|
|
End If
|
|
End If
|
|
Catch ex As Exception
|
|
Logger.Log(Logger.LogTypes.Warning, "SoundManager.vb: File at ""Sounds\" & Name & """ is not a valid sound file. They have to be a PCM wave file, mono or stereo, 8 or 16 bit and have to have a sample rate between 8k and 48k Hz.")
|
|
Return False
|
|
End Try
|
|
Return True
|
|
End Function
|
|
|
|
Public Shared Sub Clear()
|
|
_sounds.Clear()
|
|
LoadSounds(False)
|
|
End Sub
|
|
|
|
Public Shared Sub PlaySound(soundFile As String)
|
|
PlaySound(soundFile, 0.0F, 0.0F, Volume, False)
|
|
End Sub
|
|
|
|
Public Shared Sub PlaySound(soundFile As String, stopMusic As Boolean)
|
|
PlaySound(soundFile, 0.0F, 0.0F, Volume, stopMusic)
|
|
End Sub
|
|
|
|
Public Shared Sub PlaySound(soundFile As String, pitch As Single, pan As Single, volume As Single, stopMusic As Boolean)
|
|
|
|
If Not Muted Then
|
|
|
|
Dim key = soundFile.ToLowerInvariant()
|
|
Dim sound As SoundContainer = Nothing
|
|
sound = GetSoundEffect(key)
|
|
|
|
If sound IsNot Nothing Then
|
|
|
|
If HasOutputDeviceAvailable() Then
|
|
|
|
Logger.Debug("SoundEffect [" & soundFile & "]")
|
|
|
|
sound.Sound.Play(volume, pitch, pan)
|
|
|
|
If stopMusic = True Then
|
|
MusicManager.PauseForSound(sound.Sound)
|
|
End If
|
|
|
|
Else
|
|
|
|
Logger.Log(Logger.LogTypes.ErrorMessage, "Failed to play sound: no audio device available.")
|
|
|
|
End If
|
|
|
|
End If
|
|
|
|
End If
|
|
|
|
End Sub
|
|
|
|
Public Shared Sub PlayPokemonCry(pokemonId As Integer)
|
|
PlaySound("Cries\" + pokemonId.ToString(), 0F, 0F, Volume * POKEMON_CRY_VOLUME_MULTIPLIER, False)
|
|
End Sub
|
|
|
|
Public Shared Sub PlayPokemonCry(pokemonId As Integer, pitch As Single, pan As Single)
|
|
PlaySound("Cries\" + pokemonId.ToString(), pitch, pan, Volume * POKEMON_CRY_VOLUME_MULTIPLIER, False)
|
|
End Sub
|
|
|
|
Public Shared Sub PlayPokemonCry(pokemonId As Integer, pitch As Single, pan As Single, volume As Single)
|
|
PlaySound("Cries\" + pokemonId.ToString(), pitch, pan, volume * POKEMON_CRY_VOLUME_MULTIPLIER, False)
|
|
End Sub
|
|
|
|
Public Shared Sub LoadSounds(ByVal forceReplace As Boolean)
|
|
For Each soundfile As String In System.IO.Directory.GetFiles(GameController.GamePath & "\Content\Sounds\")
|
|
If soundfile.EndsWith(".wav") = True Then
|
|
soundfile = System.IO.Path.GetFileNameWithoutExtension(soundfile)
|
|
AddSound(soundfile, forceReplace)
|
|
End If
|
|
Next
|
|
If Core.GameOptions.ContentPackNames.Count > 0 Then
|
|
For Each c As String In Core.GameOptions.ContentPackNames
|
|
Dim path As String = GameController.GamePath & "\ContentPacks\" & c & "\Sounds\"
|
|
|
|
If System.IO.Directory.Exists(path) = True Then
|
|
For Each soundfile As String In System.IO.Directory.GetFiles(path, "*.*", IO.SearchOption.AllDirectories)
|
|
If soundfile.EndsWith(".wav") = True Then
|
|
soundfile = System.IO.Path.GetFileNameWithoutExtension(soundfile)
|
|
AddSound(soundfile, forceReplace)
|
|
End If
|
|
Next
|
|
End If
|
|
Next
|
|
End If
|
|
End Sub
|
|
|
|
Private Shared Function GetSoundEffect(ByVal Name As String) As SoundContainer
|
|
|
|
If _sounds.ContainsKey(Name.ToLower()) = True Then
|
|
Return _sounds(Name.ToLower())
|
|
Else
|
|
If TryAddGameModeSound(Name) = True Then
|
|
Return _sounds(Name.ToLower())
|
|
Else
|
|
Logger.Log(Logger.LogTypes.Warning, "SoundManager.vb: Cannot find sound file """ & Name & """. Return nothing.")
|
|
Return Nothing
|
|
End If
|
|
End If
|
|
End Function
|
|
|
|
Private Shared Function TryAddGameModeSound(ByVal Name As String) As Boolean
|
|
Dim defaultSoundFilePath As String = GameController.GamePath & "\Content\" & "Sounds\" & Name & ".wav"
|
|
Dim soundFilePath As String = GameController.GamePath & GameModeManager.ActiveGameMode.ContentPath & "Sounds\" & Name & ".wav"
|
|
If System.IO.File.Exists(soundFilePath) = True Then
|
|
Return AddSound(Name, False)
|
|
Else
|
|
If System.IO.File.Exists(defaultSoundFilePath) = True Then
|
|
Return AddSound(Name, False)
|
|
End If
|
|
End If
|
|
Return False
|
|
End Function
|
|
|
|
End Class |