public void ArrangeBeatMapViaDifficulty() { bool audioFileFound = false; //Get Maps Difficulty First for (int i = 0; i < mapObj.mapInfos.Length; i++) { string mapPath = GetMapPath(mapObj.folderName, mapObj.mapInfos[i].mapName); Beatmap beatmap = BeatmapDecoder.Decode(mapPath); mapObj.mapInfos[i].difficulty = beatmap.DifficultySection.OverallDifficulty; //Only initialised Once if (!audioFileFound) { string audioName = beatmap.GeneralSection.AudioFilename; List <string> audioNameSplit = audioName.Split('.').ToList(); audioNameSplit.RemoveAt(audioNameSplit.Count - 1); //Remove the last index audioName = string.Join(".", audioNameSplit); mapObj.audioFile = Resources.Load <AudioClip>(string.Format("Beatmaps/{0}/{1}", mapObj.folderName, audioName)); audioFileFound = true; } } System.Array.Sort(mapObj.mapInfos, (x, y) => x.difficulty.CompareTo(y.difficulty)); }
public void InitialiseBeatMap(/*BeatmapData bmd, BeatmapInfo bmi*/) //BMD to Load Clips, BMI to Load Map. Currently Using Variables instead of Parameters { string mapPath = GetMapPath(OszUnpacker.bmds[bmdIndex].folderName, OszUnpacker.bmds[bmdIndex].mapInfos[bmiIndex].mapName); songPlayer.Stop(); songPlayer.loop = false; songPlayer.clip = OszUnpacker.bmds[bmdIndex].audio; beatmap = BeatmapDecoder.Decode(mapPath); beats = beatmap.HitObjects; spawnHitDist = beatHitPos.transform.position.z - beatSpawnPos.transform.position.z; bufferTime = Mathf.Abs(spawnHitDist) / scrollSpeed; startTimeOffset = trackDelayTime; float firstBeatTime = (float)beats[0].StartTime / 1000; if (firstBeatTime < bufferTime) { startTimeOffset += (bufferTime - firstBeatTime); } trackStartTime = AudioSettings.dspTime + startTimeOffset; trackEndTime = AudioSettings.dspTime + 1.5f + (float)(beats[beats.Count - 1].EndTime) / 1000; //Get the Track End Time print(trackEndTime - trackStartTime); songPlayer.PlayScheduled(trackStartTime); gameState = GameState.OnPlay; }
private void loadFiles() { var bmPath = Path.Combine(osuRoot, "Songs", dmp.FolderName, dmp.FileName); var rpPath = Path.Combine(osuRoot, @"Data\r", $"{dmp.MD5Hash}-{sc.ScoreTimestamp.ToFileTimeUtc()}.osr"); bm = BeatmapDecoder.Decode(bmPath); rp = ReplayDecoder.Decode(rpPath); }
bool songFlag = true; // 노래 재생 플래그 /// 게임 시작과 동시에 호출됨 /// 노트 재생 전에 필요한 작업을 처리함 void Start(int songNumber) { //파서 경로 설정 beatmap = BeatmapDecoder.Decode(Application.dataPath + "/StreamingAssets/LoveDramatic.osu"); //4레인 마니아 비트맵인지 확인 CheckBeatmap(); //기본 비트맵 데이터 얻기 velocity = (float)beatmap.DifficultySection.SliderMultiplier; GetGeneral(); GetMetadata(); //노트 생성 및 노래 재생 CreateNote(); }
public static IEnumerator ScanSongDirectory() { Debug.Log("Scanning song directory"); if (!isScanningSongDirectory) { isScanningSongDirectory = true; } else { yield break; } Songs.Clear(); Songs.Add(Audio.Instance.Triangles); try { osuPaths = Directory.EnumerateFiles(PlayerData.PersistentPlayerData.BeatmapLocation, "*.osu", SearchOption.AllDirectories); } catch (ArgumentException e) { Debug.Log(e.Message); } foreach (string path in osuPaths ?? Enumerable.Empty <string>()) { Beatmap beatmap = BeatmapDecoder.Decode(path); string songFolderPath = path.Substring(0, path.LastIndexOf('\\') + 1); string audioPath = songFolderPath + beatmap.GeneralSection.AudioFilename; string backgroundPath = songFolderPath + beatmap.EventsSection.BackgroundImage; try { Song song = new Song(beatmap, Audio.Mp3ToAudioClip(File.ReadAllBytes(audioPath))); song.Background.LoadImage(File.ReadAllBytes(backgroundPath)); Songs.Add(song); } catch (FileNotFoundException e) { Debug.Log(e.Message); } Debug.Log(path); yield return(null); } isScanningSongDirectory = false; SongList.Instance.UpdateSongList(); SongSelection.Instance.UpdateSongList(); }
public void ParseAll() { foreach (var file in RawFiles) { var timer = new Stopwatch(); timer.Start(); var beatmap = BeatmapDecoder.Decode(file); timer.Stop(); Maps.Add(beatmap); Trace.WriteLine(string.Format( "Beatmap parsed in {0}ms: {1} - {2} [{3}] created by {4}.", timer.Elapsed.Milliseconds, beatmap.MetadataSection.Artist, beatmap.MetadataSection.Title, beatmap.MetadataSection.Version, beatmap.MetadataSection.Creator)); } }
static void RunOptions(Options opts) { // Parse Beatmap and replay var beatmap = new Beatmap(); var replay = new Replay(); try { beatmap = BeatmapDecoder.Decode(opts.BeatmapPath); } catch (Exception) { Console.WriteLine("Can not parse Beatmap " + opts.BeatmapPath); return; } if (opts.ReplayPath != null) { try { replay = ReplayDecoder.Decode(opts.ReplayPath); if (replay.Mods == OsuParsers.Enums.Mods.Relax) { return; } } catch (Exception) { Console.WriteLine("Can not parse Replay " + opts.ReplayPath); return; } } var associated = new AssociatedBeatmap(beatmap, replay); Console.WriteLine("Aim: {0:R}", associated.GetAimPrecision()); Console.WriteLine("Acc: {0:R}", associated.GetAccPrecision()); return; }
public void InitialiseBeatMap(BeatmapObject selectedMap, int mapIndex) //By Scriptable Object. Easier for Testing { this.selectedMap = selectedMap; this.mapIndex = mapIndex; if (mapIndex >= selectedMap.mapInfos.Length) { UnityEngine.Debug.LogError("Map Index Exceeds the Length of the Beat Map. Ensure that the Map Index is within the Array Length"); return; } //SO Method string mapPath = GetMapPath(selectedMap.folderName, selectedMap.mapInfos[mapIndex].mapName); songPlayer.clip = selectedMap.audioFile; beatmap = BeatmapDecoder.Decode(mapPath); beats = beatmap.HitObjects; spawnHitDist = beatHitPos.transform.position.z - beatSpawnPos.transform.position.z; //beatMoveDir = spawnHitDist < 0 ? -1f : 1f; bufferTime = Mathf.Abs(spawnHitDist) / scrollSpeed; startTimeOffset = trackDelayTime; float firstBeatTime = (float)beats[0].StartTime / 1000; if (firstBeatTime < bufferTime) { startTimeOffset += (bufferTime - firstBeatTime); } trackStartTime = AudioSettings.dspTime + startTimeOffset; songPlayer.PlayScheduled(trackStartTime); gameState = GameState.OnPlay; }
/// <summary> /// The main entry point for the application. /// </summary> // [STAThread] static void Main() { var osuPath = @"C:\Users\sunny\Programs\osu!\"; var songsPath = Path.Join(osuPath, "Songs"); var simPath = @"C:\Users\sunny\Programs\StepMania 5.1\Songs\Test"; var osuDbPath = Path.Join(osuPath, "osu!.db"); OsuDatabase db = DatabaseDecoder.DecodeOsu(osuDbPath); var songs = Directory.GetDirectories(songsPath); Dictionary <int, List <DbBeatmap> > bms = db.Beatmaps .GroupBy(x => x.BeatmapSetId, x => x) .ToDictionary(x => x.Key, x => x.ToList()); foreach (var songPath in songs) { var songFolder = Path.GetFileName(songPath); Console.WriteLine(songFolder); var maps = Directory.GetFiles(Path.Join(songsPath, songFolder), "*.osu"); Simfile s = null; List <DbBeatmap> bs = null; foreach (var mapPath in maps) { var songName = Path.GetFileNameWithoutExtension(mapPath); Console.WriteLine(" " + songName); Beatmap beatmap = BeatmapDecoder.Decode(Path.Join(songsPath, songFolder, songName + ".osu")); if (bs == null) { bs = bms[beatmap.MetadataSection.BeatmapSetID]; bs.Sort((x, y) => x.CirclesCount .CompareTo(y.CirclesCount)); } BasicSongInfo songInfo = OsuToAlgorithm.Convert(beatmap); Random rng = new Random(beatmap.MetadataSection.BeatmapID); StepScoreGenerator sg = new StepScoreGenerator { Rng = rng, }; Algorithm a = new Algorithm { Info = songInfo, RecoveryInterval = songInfo.PPQ / 2 / 8, StepScore = sg.RandomStepScore(songInfo), }; if (s == null) { s = AlgorithmToSimfile.Convert(beatmap, songInfo, new List <Simfile.Chart>()); } var x = a.Run(); var chart = AlgorithmToSimfile.ConvertChart(beatmap, songInfo, x, diff: bs.FindIndex(y => y.BeatmapId == beatmap.MetadataSection.BeatmapID) ); s.Charts.Add(chart); } Directory.CreateDirectory(Path.Join(simPath, songFolder)); var sb = new StringBuilder(); s.Append(sb); File.WriteAllText(Path.Join(simPath, songFolder, songFolder + ".sm"), sb.ToString()); File.Copy(Path.Join(songsPath, songFolder, s.Music), Path.Join(simPath, songFolder, s.Music), true); } //Application.SetHighDpiMode(HighDpiMode.SystemAware); //Application.EnableVisualStyles(); //Application.SetCompatibleTextRenderingDefault(false); //Application.Run(new Form1()); }
/// <summary> /// Reads osu data an deserializes it into an <see cref="ManiaBeatMap"/>. /// </summary> /// <param name="path">The osu file path.</param> /// <returns>A <see cref="ManiaBeatMap"/>.</returns> public static ManiaBeatMap ReadFromOsuFile(string path) { Beatmap beatmap = BeatmapDecoder.Decode(path); return((ManiaBeatMap)beatmap); }
/// <summary> /// Parses .osu file. /// </summary> /// <param name="pathToBeatmap">Path to the .osu file.</param> /// <returns>A usable beatmap.</returns> public static Beatmap ParseBeatmap(string pathToBeatmap) => beatmapDecoder.Decode(File.ReadAllLines(pathToBeatmap));
void UnpackOszFile(FileInfo oszFile) { //First, ensure Temp Path Directory is Created. This is where all the Contents of the Osz Files will be dumped before it is moved to the official folder //tempPath = Application.dataPath + osuDumpPath + "Temp/"; //Set Correct Path to Temp Folder if (!Directory.Exists(tempPath)) { Directory.CreateDirectory(tempPath); } ZipFile.ExtractToDirectory(oszFile.FullName, tempPath); string[] allMapPaths = GetAllMapPaths(tempPath); //Gets all Osu files per Osz dumped in the Temp Path //Create Variables that will Store the Beatmap Data that will eventually save it to a Json File string folderName = string.Empty; //Meant to Store the Name for the Folder string dumpPath = string.Empty; //The Folder to Dump the Files BeatmapData bmd = null; //Create a Beatmap Data Class that will be initialised on the first For Loop bool bmdExists = false; //To Check if the Existing BMD exists for (int i = 0; i < allMapPaths.Length; i++) { //Decode the Beatmap Beatmap beatmap = BeatmapDecoder.Decode(allMapPaths[i]); if (i == 0) //If this is the First Map that is Decoded { //Initialise the Folder Name and the Dump Path for the Beatmap folderName = string.Format("{0} - {1}", beatmap.MetadataSection.Title, beatmap.MetadataSection.BeatmapSetID); //Initialise the Folder Name dumpPath = string.Format("{0}{1}{2}/", Application.dataPath, osuDumpPath, folderName); //Set Path to Dump ONLY the required resources for this Game //Check if the a BMD has been Created for the Osz Before bmd = bmds.FirstOrDefault(x => x.folderName == folderName); if (bmd == null) { bmd = new BeatmapData(); //bmdExists remains false } else { bmdExists = true; } bmd.folderName = folderName; bmd.songName = beatmap.MetadataSection.Title; bmd.artistName = beatmap.MetadataSection.Artist; if (!Directory.Exists(dumpPath)) { Directory.CreateDirectory(dumpPath); } //Only Get Audio File if it is missing if (string.IsNullOrEmpty(bmd.audioFilePath)) { string audioName = beatmap.GeneralSection.AudioFilename; string destinationPath = string.Format("{0}{1}", dumpPath, audioName); //Only Move Audio File if it does not Exist if (!File.Exists(destinationPath)) { File.Move(tempPath + audioName, destinationPath); } audioName = GetFileNameNoExt(destinationPath); //Update Audio Name to have no Exts for Resources.Load bmd.audioFilePath = string.Format("Beatmaps/{0}/{1}", folderName, audioName); //Path is Designed for Resources.Load } if (string.IsNullOrEmpty(bmd.imgFilePath)) { string imgName = beatmap.EventsSection.BackgroundImage; string destinationPath = string.Format("{0}{1}", dumpPath, imgName); //Only Move Img File if it does not Exist if (!File.Exists(destinationPath)) { File.Move(tempPath + imgName, destinationPath); } imgName = GetFileNameNoExt(destinationPath); //Update Image Name to have no Exts for Resources.Load bmd.imgFilePath = string.Format("Beatmaps/{0}/{1}", folderName, imgName); //Path is Designed for Resources.Load } } BeatmapInfo bmi = new BeatmapInfo { mapName = GetFileNameNoExt(allMapPaths[i]), creator = beatmap.MetadataSection.Creator, difficulty = beatmap.DifficultySection.OverallDifficulty }; bmi.scores = new List <ScoreInfo>(); //Check for any missing Beatmap Info if (!bmdExists || !bmd.mapInfos.Exists(x => x.mapName == bmi.mapName)) { bmd.mapInfos.Add(bmi); } if (!File.Exists(string.Format("{0}{1}{2}", dumpPath, bmi.mapName, ".osu"))) { File.Move(allMapPaths[i], string.Format("{0}{1}{2}", dumpPath, bmi.mapName, ".osu")); } } bmd.mapInfos.Sort((x, y) => x.difficulty.CompareTo(y.difficulty)); bmd.LoadAssets(); if (!bmdExists) { bmds.Add(bmd); } if (runtimeUnpacking) { lastAddedBmd = bmds.Last(); } /*DirectoryInfo dir = new DirectoryInfo(tempPath); * foreach (FileInfo file in dir.GetFiles()) File.Delete(file.FullName);*/ Directory.Delete(tempPath, true); File.Delete(oszFile.FullName); print("Unpacking File Completed"); }
public OsuManiaReader(String filePath) { bm = BeatmapDecoder.Decode(filePath); }
void RandomizeBeatmap() { if (Directory.Exists("RandomizedMap")) { Directory.Delete("RandomizedMap", true); } if (File.Exists("RandomizedMap.osz")) { File.Delete("RandomizedMap.osz"); } Random r = new Random(); var kmap = LoadedMaps.ElementAt(r.Next(0, LoadedMaps.Count)); var ksong = LoadedMaps.ElementAt(r.Next(0, LoadedMaps.Count)); Beatmap map = BeatmapDecoder.Decode(kmap.FullName); Beatmap song = BeatmapDecoder.Decode(kmap.FullName); while (map.GeneralSection.Mode != song.GeneralSection.Mode && (!checkedListBox1.GetItemChecked(0) && (int)map.BeatLengthAt(0) == (int)song.BeatLengthAt(0))) { kmap = LoadedMaps.ElementAt(r.Next(0, LoadedMaps.Count)); ksong = LoadedMaps.ElementAt(r.Next(0, LoadedMaps.Count)); map = BeatmapDecoder.Decode(kmap.FullName); song = BeatmapDecoder.Decode(kmap.FullName); } while (map.GeneralSection.Mode != song.GeneralSection.Mode && checkedListBox1.GetItemChecked(0)) { kmap = LoadedMaps.ElementAt(r.Next(0, LoadedMaps.Count)); ksong = LoadedMaps.ElementAt(r.Next(0, LoadedMaps.Count)); map = BeatmapDecoder.Decode(kmap.FullName); song = BeatmapDecoder.Decode(kmap.FullName); } //create map directory Directory.CreateDirectory("RandomizedMap"); map.TimingPoints = song.TimingPoints; map.GeneralSection.AudioFilename = song.GeneralSection.AudioFilename; map.GeneralSection.Length = song.GeneralSection.Length; map.EventsSection.Breaks = song.EventsSection.Breaks; //copy audio file File.Copy(Path.Combine(Path.GetDirectoryName(ksong.FullName), song.GeneralSection.AudioFilename), Path.Combine("RandomizedMap", song.GeneralSection.AudioFilename)); //video randomizer if (checkedListBox1.GetItemChecked(2)) { var kvid = LoadedMaps.ElementAt(r.Next(0, LoadedMaps.Count)); Beatmap vid = BeatmapDecoder.Decode(kvid.FullName); while (string.IsNullOrEmpty(map.EventsSection.Video)) { kvid = LoadedMaps.ElementAt(r.Next(0, LoadedMaps.Count)); vid = BeatmapDecoder.Decode(kvid.FullName); } map.EventsSection.Video = vid.EventsSection.Video; map.EventsSection.VideoOffset = vid.EventsSection.VideoOffset; //copy video File.Copy(Path.Combine(Path.GetDirectoryName(kvid.FullName), vid.EventsSection.Video), Path.Combine("RandomizedMap", vid.EventsSection.Video)); } //storyboard randomizer /* * if (checkedListBox1.GetItemChecked(3)) * { * var ksb = LoadedMaps.ElementAt(r.Next(0, LoadedMaps.Count)); * Beatmap sb = BeatmapDecoder.Decode(ksb.FullName); * while (!sb.EventsSection.Storyboard.) * { * ksb = LoadedMaps.ElementAt(r.Next(0, LoadedMaps.Count)); * sb = BeatmapDecoder.Decode(ksb.FullName); * } * map.EventsSection.Video = sb.EventsSection.Video; * map.EventsSection.VideoOffset = sb.EventsSection.VideoOffset; * //copy video * File.Copy(Path.Combine(Path.GetDirectoryName(ksb.FullName), sb.EventsSection.Video), Path.Combine("RandomizedMap", sb.EventsSection.Video)); * } */ if (checkedListBox1.GetItemChecked(4)) { map.DifficultySection.CircleSize = r.Next(0, 100) / 10f; } if (checkedListBox1.GetItemChecked(5)) { map.DifficultySection.ApproachRate = r.Next(0, 100) / 10f; } if (checkedListBox1.GetItemChecked(6)) { map.DifficultySection.OverallDifficulty = r.Next(0, 100) / 10f; } if (checkedListBox1.GetItemChecked(7)) { map.DifficultySection.HPDrainRate = r.Next(0, 100) / 10f; } map.MetadataSection.Artist = "osu!map randomizer"; map.MetadataSection.Title = "Randomized map"; map.MetadataSection.Creator = "osu!map randomizer"; //copy background File.Copy(Path.Combine(Path.GetDirectoryName(kmap.FullName), song.EventsSection.BackgroundImage), Path.Combine("RandomizedMap", song.EventsSection.BackgroundImage)); map.Save(Path.Combine("RandomizedMap", "map.osu")); ZipFile.CreateFromDirectory(Path.GetFullPath("RandomizedMap"), "RandomizedMap.osz"); Process.Start(Path.GetFullPath("RandomizedMap.osz")); }
private Beatmap BuildBeatmapFromFile(string fullMapFilePath) { // TODO: REFACTOR - Build decorated custom-beatmap class object (to reduce external class coupling to BMAPI). return(BeatmapDecoder.Decode(fullMapFilePath)); }