@@ -78,24 +78,36 @@ public static AudioClip LoadPlayMusicHook(AudioClip audioClip, string id)
7878 pack . PackId + Salt == int . Parse ( id ) ) ;
7979 if ( pack == null ) return audioClip ;
8080
81- // var audioDir = Path.Combine("osu!mania_beatmaps", "Audio!");
82- // if (!Directory.Exists(audioDir)) Directory.CreateDirectory(audioDir);
81+ var audioDir = Path . Combine ( Directory . GetCurrentDirectory ( ) , Path . Combine ( "osu!mania_beatmaps" , "Audio!" ) ) ;
82+ if ( ! Directory . Exists ( audioDir ) ) Directory . CreateDirectory ( audioDir ) ;
83+
84+ var songPath = Path . Combine ( audioDir , $ "{ pack . PackId } _{ pack . PackName } _{ pack . Beatmaps [ 0 ] . AudioFilename } ") ;
85+ if ( File . Exists ( songPath ) )
86+ {
87+ var www = new WWW ( "file:///" + songPath ) ;
88+ while ( ! www . isDone && www . error == null )
89+ Thread . Sleep ( 10 ) ;
90+
91+ return www . GetAudioClip ( true , true ,
92+ pack . Beatmaps [ 0 ] . AudioFilename . Split ( '.' ) . Last ( ) . ToLower ( ) switch
93+ {
94+ "mp3" => AudioType . MPEG ,
95+ "wav" => AudioType . WAV ,
96+ "ogg" => AudioType . OGGVORBIS
97+ }
98+ ) ;
99+ }
83100
84101 var archive = ZipArchive . Open ( new MemoryStream ( File . ReadAllBytes ( pack . PackFile ) ) ) ;
85102 foreach ( var entry in archive . Entries )
86103 {
87104 if ( entry . IsDirectory || ! entry . FilePath . EndsWith ( pack . Beatmaps [ 0 ] . AudioFilename ) ) continue ;
88105 var bytes = new byte [ entry . Size ] ;
89106 var _ = entry . OpenEntryStream ( ) . Read ( bytes , 0 , ( int ) entry . Size ) ;
90- var tempFilePath = Path . GetTempFileName ( ) ;
91- var newTemptPath = tempFilePath
92- . Replace ( "\\ " , "/" )
93- . TrimEnd ( '/' ) +
94- "_" + pack . PackName + "_" + pack . Beatmaps [ 0 ] . AudioFilename ;
95- File . Move ( tempFilePath , newTemptPath ) ;
96- File . WriteAllBytes ( newTemptPath , bytes ) ;
97-
98- var www = new WWW ( "file:///" + newTemptPath ) ;
107+
108+ File . WriteAllBytes ( songPath , bytes ) ;
109+
110+ var www = new WWW ( "file:///" + songPath ) ;
99111 while ( ! www . isDone && www . error == null )
100112 Thread . Sleep ( 10 ) ;
101113
0 commit comments