Esempio n. 1
0
        public void TestLoadBeatmap()
        {
            using (Apk apk = new Apk(baseAPKPath)) {
                byte[]                       data    = apk.ReadEntireEntry(Apk.MainAssetsFile);
                SerializedAssets             assets  = SerializedAssets.FromBytes(data);
                SerializedAssets.AssetObject obj     = assets.objects[62];
                MonoBehaviorAssetData        monob   = (MonoBehaviorAssetData)obj.data;
                BeatmapDataBehaviorData      beatmap = (BeatmapDataBehaviorData)monob.data;

                using (Stream fileStream = new FileStream(repoPath("testoutput/beatmap_deflated.bin"), FileMode.Create)) {
                    using (MemoryStream memoryStream = new MemoryStream(beatmap.projectedData)) {
                        using (DeflateStream ds = new DeflateStream(memoryStream, CompressionMode.Decompress)) {
                            ds.CopyTo(fileStream);
                        }
                    }
                }


                BeatmapSaveData saveData = BeatmapSaveData.DeserializeFromBinary(beatmap.projectedData);
                Assert.NotEmpty(saveData._notes);
                byte[] outData = saveData.SerializeToBinary(false);
                File.WriteAllBytes(repoPath("testoutput/beatmap_roundtrip.bin"), outData);

                BeatmapSaveData saveData2 = BeatmapSaveData.DeserializeFromBinary(outData, false);
                Assert.NotEmpty(saveData._notes);
                byte[] outData2 = saveData.SerializeToBinary(false);
                File.WriteAllBytes(repoPath("testoutput/beatmap_roundtrip2.bin"), outData);
            }
        }
Esempio n. 2
0
 private static void StoreCustomEventsSaveData(BeatmapSaveData beatmapSaveData)
 {
     if (beatmapSaveData is CustomBeatmapSaveData customBeatmapSaveData)
     {
         BeatmapDataLoaderGetBeatmapDataFromBeatmapSaveData.customBeatmapSaveData = customBeatmapSaveData;
     }
 }
Esempio n. 3
0
        public void TestPackBeatmap()
        {
            string          beatmapFile = repoPath("testdata/bubble_tea_song/Hard.dat");
            string          jsonData    = File.ReadAllText(beatmapFile);
            BeatmapSaveData saveData    = JsonConvert.DeserializeObject <BeatmapSaveData>(jsonData);

            Assert.NotEmpty(saveData._notes);
            byte[] outData = saveData.SerializeToBinary(false);
            File.WriteAllBytes(repoPath("testoutput/bubbletea_serialized.bin"), outData);
        }
Esempio n. 4
0
        public void TransformToJsonData()
        {
            if (ProjectedData == null || ProjectedData.Length < 1)
            {
                throw new InvalidOperationException("ProjectedData must be set before transforming to JsonData.");
            }

            var saveData = BeatmapSaveData.DeserializeFromFromBinary(ProjectedData);

            JsonData = saveData.SerializeToJSONString();
        }
Esempio n. 5
0
        public void TransformToProjectedData()
        {
            if (string.IsNullOrWhiteSpace(JsonData))
            {
                throw new InvalidOperationException("JsonData must be set before transforming to ProjectedData.");
            }

            var saveData = BeatmapSaveData.DeserializeFromJSONString(JsonData);

            ProjectedData = saveData.SerializeToBinary();
        }
Esempio n. 6
0
        static void SerializeWrite(string fs)
        {
            var bs = BeatmapSaveData.DeserializeFromJSONString(File.ReadAllText(Path.Combine(required[1].Value, fs)));

            byte[]       bts    = bs.SerializeToBinary();
            StreamWriter writer = new StreamWriter(Path.Combine(required[2].Value, fs));

            Console.WriteLine("Writing Binary Array to: " + fs);
            writer.WriteLine("\t\tArray: [");
            foreach (byte b in bts)
            {
                writer.WriteLine("\t\t\t" + b);
            }
            writer.WriteLine("\t\t]");
            writer.Flush();
            writer.Close();
        }
Esempio n. 7
0
        public static BeatmapDataBehaviorData FromJsonFile(string path, Apk.Version v)
        {
            string jsonData = File.ReadAllText(path);

            if (v < Apk.Version.V1_1_0)
            {
                BeatmapSaveData saveData      = JsonConvert.DeserializeObject <BeatmapSaveData>(jsonData);
                byte[]          projectedData = saveData.SerializeToBinary();

                return(new BeatmapDataBehaviorData()
                {
                    jsonData = "",
                    signature = new byte[128], // all zeros
                    projectedData = projectedData,
                });
            }
            else
            {
                return(new BeatmapDataBehaviorData()
                {
                    jsonData = jsonData,
                });
            }
        }
        public static IEnumerator <BeatmapDetails> CreateBeatmapDetailsFromFilesCoroutine(CustomPreviewBeatmapLevel customLevel)
        {
            StandardLevelInfoSaveData infoData       = customLevel.standardLevelInfoSaveData;
            BeatmapDetails            beatmapDetails = new BeatmapDetails();

            beatmapDetails.LevelID        = BeatmapDetailsLoader.GetSimplifiedLevelID(customLevel);
            beatmapDetails.SongName       = customLevel.songName;
            beatmapDetails.BeatsPerMinute = infoData.beatsPerMinute;

            // load difficulties
            beatmapDetails.DifficultyBeatmapSets = new SimplifiedDifficultyBeatmapSet[infoData.difficultyBeatmapSets.Length];
            for (int i = 0; i < infoData.difficultyBeatmapSets.Length; ++i)
            {
                var currentSimplifiedSet = new SimplifiedDifficultyBeatmapSet();
                beatmapDetails.DifficultyBeatmapSets[i] = currentSimplifiedSet;
                var currentSet = infoData.difficultyBeatmapSets[i];

                currentSimplifiedSet.CharacteristicName = currentSet.beatmapCharacteristicName;
                currentSimplifiedSet.DifficultyBeatmaps = new SimplifiedDifficultyBeatmap[currentSet.difficultyBeatmaps.Length];

                for (int j = 0; j < currentSet.difficultyBeatmaps.Length; ++j)
                {
                    var currentSimplifiedDiff = new SimplifiedDifficultyBeatmap();
                    currentSimplifiedSet.DifficultyBeatmaps[j] = currentSimplifiedDiff;
                    var currentDiff = currentSet.difficultyBeatmaps[j];

                    currentDiff.difficulty.BeatmapDifficultyFromSerializedName(out currentSimplifiedDiff.Difficulty);
                    currentSimplifiedDiff.NoteJumpMovementSpeed = currentDiff.noteJumpMovementSpeed;

                    string diffFilePath             = Path.Combine(customLevel.customLevelPath, currentDiff.beatmapFilename);
                    string fileContents             = null;
                    IEnumerator <string> textLoader = UnityMediaLoader.LoadTextCoroutine(diffFilePath);
                    while (textLoader.MoveNext())
                    {
                        fileContents = textLoader.Current;

                        if (fileContents == null)
                        {
                            yield return(null);
                        }
                    }

                    if (string.IsNullOrEmpty(fileContents))
                    {
                        yield break;
                    }

                    BeatmapSaveData beatmapSaveData = null;
                    try
                    {
                        beatmapSaveData = BeatmapSaveData.DeserializeFromJSONString(fileContents);
                    }
                    catch (Exception e)
                    {
                        Logger.log.Warn($"Exception occurred while trying to deserialize difficulty beatmap to BeatmapSaveData for '{customLevel.songName}'");
                        Logger.log.Debug(e);

                        yield break;
                    }

                    // missing difficulty files
                    if (beatmapSaveData == null)
                    {
                        yield break;
                    }

                    // count notes and bombs
                    currentSimplifiedDiff.NotesCount = 0;
                    currentSimplifiedDiff.BombsCount = 0;
                    foreach (var note in beatmapSaveData.notes)
                    {
                        if (note.type.IsBasicNote())
                        {
                            ++currentSimplifiedDiff.NotesCount;
                        }
                        else if (note.type == NoteType.Bomb)
                        {
                            ++currentSimplifiedDiff.BombsCount;
                        }
                    }

                    // count rotation events
                    currentSimplifiedDiff.SpawnRotationEventsCount = 0;
                    foreach (var mapEvent in beatmapSaveData.events)
                    {
                        if (mapEvent.type.IsRotationEvent())
                        {
                            ++currentSimplifiedDiff.SpawnRotationEventsCount;
                        }
                    }

                    currentSimplifiedDiff.ObstaclesCount = beatmapSaveData.obstacles.Count;
                }
            }

            // load audio
            string    audioFilePath             = Path.Combine(customLevel.customLevelPath, infoData.songFilename);
            AudioClip audioClip                 = null;
            IEnumerator <AudioClip> audioLoader = UnityMediaLoader.LoadAudioClipCoroutine(audioFilePath);

            while (audioLoader.MoveNext())
            {
                audioClip = audioLoader.Current;

                if (audioClip == null)
                {
                    yield return(null);
                }
            }

            if (audioClip == null)
            {
                yield break;
            }

            beatmapDetails.SongDuration = audioClip.length;

            yield return(beatmapDetails);
        }
        /// <summary>
        /// Loads files associated with a custom beatmap and creates a BeatmapDetails object with the information contained in the files.
        /// </summary>
        /// <param name="customLevel">A custom level to create the BeatmapDetails object for.</param>
        /// <returns>BeatmapDetails object on success, otherwise null.</returns>
        public static BeatmapDetails CreateBeatmapDetailsFromFiles(CustomPreviewBeatmapLevel customLevel)
        {
            StandardLevelInfoSaveData infoData       = customLevel.standardLevelInfoSaveData;
            BeatmapDetails            beatmapDetails = new BeatmapDetails();

            beatmapDetails.LevelID        = BeatmapDetailsLoader.GetSimplifiedLevelID(customLevel);
            beatmapDetails.SongName       = customLevel.songName;
            beatmapDetails.BeatsPerMinute = infoData.beatsPerMinute;

            // load difficulties for note info
            beatmapDetails.DifficultyBeatmapSets = new SimplifiedDifficultyBeatmapSet[infoData.difficultyBeatmapSets.Length];
            for (int i = 0; i < infoData.difficultyBeatmapSets.Length; ++i)
            {
                var currentSimplifiedSet = new SimplifiedDifficultyBeatmapSet();
                beatmapDetails.DifficultyBeatmapSets[i] = currentSimplifiedSet;
                var currentSet = infoData.difficultyBeatmapSets[i];

                currentSimplifiedSet.CharacteristicName = currentSet.beatmapCharacteristicName;
                currentSimplifiedSet.DifficultyBeatmaps = new SimplifiedDifficultyBeatmap[currentSet.difficultyBeatmaps.Length];

                for (int j = 0; j < currentSet.difficultyBeatmaps.Length; ++j)
                {
                    var currentSimplifiedDiff = new SimplifiedDifficultyBeatmap();
                    currentSimplifiedSet.DifficultyBeatmaps[j] = currentSimplifiedDiff;
                    var currentDiff = currentSet.difficultyBeatmaps[j];

                    currentDiff.difficulty.BeatmapDifficultyFromSerializedName(out currentSimplifiedDiff.Difficulty);
                    currentSimplifiedDiff.NoteJumpMovementSpeed = currentDiff.noteJumpMovementSpeed;

                    string diffFilePath = Path.Combine(customLevel.customLevelPath, currentDiff.beatmapFilename);
                    if (!File.Exists(diffFilePath))
                    {
                        return(null);
                    }

                    BeatmapSaveData beatmapSaveData = null;
                    try
                    {
                        beatmapSaveData = BeatmapSaveData.DeserializeFromJSONString(File.ReadAllText(diffFilePath));
                    }
                    catch (Exception e)
                    {
                        Logger.log.Debug("Unable to create BeatmapDetails object from files (unexpected exception occurred trying to load BeatmapSaveData from file)");
                        Logger.log.Debug(e);
                        return(null);
                    }

                    if (beatmapSaveData == null)
                    {
                        Logger.log.Debug("Unable to create BeatmapDetails object from files (could not load BeatmapSaveData from file)");
                        return(null);
                    }

                    // count notes and bombs
                    currentSimplifiedDiff.NotesCount = 0;
                    currentSimplifiedDiff.BombsCount = 0;
                    foreach (var note in beatmapSaveData.notes)
                    {
                        if (note.type.IsBasicNote())
                        {
                            ++currentSimplifiedDiff.NotesCount;
                        }
                        else if (note.type == NoteType.Bomb)
                        {
                            ++currentSimplifiedDiff.BombsCount;
                        }
                    }

                    // count rotation events
                    currentSimplifiedDiff.SpawnRotationEventsCount = 0;
                    foreach (var mapEvent in beatmapSaveData.events)
                    {
                        if (mapEvent.type.IsRotationEvent())
                        {
                            ++currentSimplifiedDiff.SpawnRotationEventsCount;
                        }
                    }

                    currentSimplifiedDiff.ObstaclesCount = beatmapSaveData.obstacles.Count;
                }
            }

            // load audio for map length
            string    audioFilePath = Path.Combine(customLevel.customLevelPath, infoData.songFilename);
            AudioClip audioClip     = UnityMediaLoader.LoadAudioClip(audioFilePath);

            if (audioClip == null)
            {
                return(null);
            }

            beatmapDetails.SongDuration = audioClip.length;

            return(beatmapDetails);
        }
Esempio n. 10
0
 private static bool Prefix(ref BeatmapSaveData __result, string stringData)
 {
     __result = CustomBeatmapSaveData.DeserializeFromJSONString(stringData);
     return(false);
 }
Esempio n. 11
0
    public static BeatmapSaveData DeserializeFromJSONString(string stringData)
    {
        BeatmapSaveData beatmapSaveData = JsonConvert.DeserializeObject <BeatmapSaveData>(stringData);

        return(beatmapSaveData);
    }