1515
1616namespace BombRushRadio
1717{
18- [ BepInPlugin ( "kade.bombrushradio" , "Bomb Rush Radio!" , "1.1.0 .0" ) ]
18+ [ BepInPlugin ( "kade.bombrushradio" , "Bomb Rush Radio!" , "1.1.1 .0" ) ]
1919 [ BepInProcess ( "Bomb Rush Cyberfunk.exe" ) ]
2020 public class BombRushRadio : BaseUnityPlugin
2121 {
22+ public static MusicPlayer mInstance ;
2223 public static BombRushRadio Instance = null ;
2324 public static List < MusicTrack > audios = new ( ) ;
2425 public int shouldBeDone = 0 ;
@@ -53,7 +54,7 @@ public IEnumerator LoadAudioFile(string filePath, AudioType type)
5354 t . AudioClip = myClip ;
5455 t . Artist = songArtist ;
5556 t . Title = songName ;
56- t . isRepeatable = true ;
57+ t . isRepeatable = false ;
5758 audios . Add ( t ) ;
5859
5960 Logger . LogInfo ( "[BRR] Loaded " + songName + " by " + songArtist + " (" + done + "/" + shouldBeDone + ")" ) ;
@@ -78,15 +79,62 @@ public IEnumerator LoadAudioFile(string filePath, AudioType type)
7879
7980 public MusicBundle bundle ;
8081 internal static ConfigEntry < KeyCode > reloadKey ;
82+
83+ public IEnumerator LoadFile ( string f )
84+ {
85+ AudioType type = AudioType . UNKNOWN ;
86+ switch ( f . Split ( '.' ) . Last ( ) . ToLower ( ) )
87+ {
88+ case "mp3" :
89+ type = AudioType . MPEG ;
90+ break ;
91+ case "wav" :
92+ type = AudioType . WAV ;
93+ break ;
94+ case "ogg" :
95+ type = AudioType . OGGVORBIS ;
96+ break ;
97+ default :
98+ yield return null ;
99+ break ;
100+ }
101+ shouldBeDone ++ ;
102+ StartCoroutine ( LoadAudioFile ( f , type ) ) ;
103+ yield return null ;
104+ }
105+
106+ public IEnumerator SearchDirectories ( string path = "" )
107+ {
108+ string p = path . Length == 0 ? Application . streamingAssetsPath + "/Mods/BombRushRadio/Songs" : path ;
109+
110+ foreach ( string f in Directory . GetDirectories ( p ) )
111+ {
112+ Logger . LogInfo ( "[BRR] Searching directory " + f ) ;
113+ StartCoroutine ( SearchDirectories ( f ) ) ;
114+ }
115+
116+ foreach ( string f in Directory . GetFiles ( p ) )
117+ {
118+ StartCoroutine ( LoadFile ( f ) ) ;
119+ }
120+
121+
122+ yield return null ;
123+ }
124+
81125 public void ReloadSongs ( )
82126 {
83127 loading = true ;
84128 if ( audios . Count > 0 )
85129 {
86- if ( Core . Instance . audioManager . musicPlayer . IsPlaying )
130+ if ( Core . Instance . audioManager . musicPlayer . IsPlaying && mInstance != null )
87131 {
88132 Core . Instance . audioManager . musicPlayer . ForcePaused ( ) ;
89- Core . Instance . audioManager . musicPlayer . Clear ( ) ;
133+ foreach ( MusicTrack tra in mInstance . musicTrackQueue . currentMusicTracks )
134+ {
135+ if ( audios . Find ( m => tra . Artist == m . Artist && m . Title == tra . Title ) )
136+ mInstance . musicTrackQueue . currentMusicTracks . Remove ( tra ) ;
137+ }
90138 addOnComplete = true ;
91139 }
92140
@@ -101,28 +149,8 @@ public void ReloadSongs()
101149 Logger . LogInfo ( "[BRR] Loading songs..." ) ;
102150 shouldBeDone = 0 ;
103151 done = 0 ;
104- foreach ( string f in Directory . GetFiles ( Application . streamingAssetsPath + "/Mods/BombRushRadio/Songs" ) )
105- {
106- AudioType type ;
107- switch ( f . Split ( '.' ) . Last ( ) . ToLower ( ) )
108- {
109- case "mp3" :
110- type = AudioType . MPEG ;
111- break ;
112- case "wav" :
113- type = AudioType . WAV ;
114- break ;
115- case "ogg" :
116- type = AudioType . OGGVORBIS ;
117- break ;
118- default :
119- continue ;
120- }
121- shouldBeDone ++ ;
122- StartCoroutine ( LoadAudioFile ( f , type ) ) ;
123- }
124-
125152
153+ StartCoroutine ( SearchDirectories ( ) ) ;
126154 }
127155
128156
0 commit comments