private void GameStatusTracker_LevelFinished(object sender, EventArgs e)
        {
            var gameStatus = gameStatusTracker.gameStatus;

            Plugin.Log("LEVEL FINISHED! Game status:");
            Plugin.Log(GameStatusTracker.PrintObjectFields(gameStatus));
            SaveScore(gameStatus);
        }
        public void SceneManagerOnActiveSceneChanged(Scene oldScene, Scene newScene)
        {
            if (gameStatusTracker == null)
            {
                gameStatusTracker = new GameStatusTracker();
                gameStatusTracker.LevelFinished += GameStatusTracker_LevelFinished;
                gameStatusTracker.LevelFailed   += GameStatusTracker_LevelFailed;
            }

            gameStatusTracker.SceneManagerOnActiveSceneChanged(oldScene, newScene);

            if (newScene.name == "Menu")
            {
                LocalProfilesUI.Instance.OnLoad();
                ProfileSongResultUI.Instance.OnLoad();
            }
        }
        private void SaveScore(GameStatus gameStatus)
        {
            try
            {
                var songScores = localProfilesData.SongScores;
                var song       = songScores.ContainsKey(gameStatus.songHash) ? songScores[gameStatus.songHash] : null;
                if (song == null)
                {
                    song = new SongInfo()
                    {
                        Hash        = gameStatus.songHash,
                        BeatSaverID = gameStatus.songBeatSaverID,
                        FilePath    = gameStatus.songFilePath,
                        Name        = gameStatus.songName,
                        SubName     = gameStatus.songSubName,
                        AuthorName  = gameStatus.songAuthorName,
                        BPM         = gameStatus.songBPM,
                        Length      = gameStatus.length
                    };
                    songScores.Add(song.Hash, song);
                }

                localProfilesData.lastSong = song;

                var difficulty = song.Difficulties.FirstOrDefault(x => x.Difficulty == gameStatus.difficulty);
                if (difficulty == null)
                {
                    difficulty = new SongDifficulty()
                    {
                        Difficulty     = gameStatus.difficulty,
                        BombsCount     = gameStatus.bombsCount,
                        MaxRank        = gameStatus.maxRank,
                        MaxScore       = gameStatus.maxScore,
                        NoteJumpSpeed  = gameStatus.noteJumpSpeed,
                        NotesCount     = gameStatus.notesCount,
                        ObstaclesCount = gameStatus.obstaclesCount
                    };
                    song.Difficulties.Add(difficulty);
                }

                localProfilesData.lastDiff = difficulty;

                var profile = difficulty.Profiles.FirstOrDefault(x => x.Name == localProfilesData.CurrentProfile);
                if (profile == null)
                {
                    profile = new Profile()
                    {
                        Name = localProfilesData.CurrentProfile
                    };
                    difficulty.Profiles.Add(profile);
                }

                localProfilesData.lastProfile = profile;


                //var scores = profile.Scores.ContainsKey(gameStatus.songHash) ? profile.Scores[gameStatus.songHash] : null;
                //if (scores == null)
                //{
                //    profile.Scores.Add(gameStatus.songHash, new List<Score>());
                //}

                var score = new Score()
                {
                    score            = gameStatus.score,
                    maxPossibleScore = gameStatus.currentMaxScore,
                    rank             = gameStatus.rank,
                    passedNotes      = gameStatus.passedNotes,
                    hitNotes         = gameStatus.hitNotes,
                    missedNotes      = gameStatus.missedNotes,
                    passedBombs      = gameStatus.passedBombs,
                    hitBombs         = gameStatus.hitBombs,
                    maxCombo         = gameStatus.maxCombo,
                    timePlayed       = GameStatusTracker.GetCurrentTime() - gameStatus.start,
                    timestamp        = (int)(GameStatusTracker.GetCurrentTime() / 1000),

                    modifierMultiplier = gameStatus.modifierMultiplier,

                    batteryLives          = gameStatus.batteryLives,
                    modObstacles          = gameStatus.modObstacles,
                    modInstaFail          = gameStatus.modInstaFail,
                    modNoFail             = gameStatus.modNoFail,
                    modBatteryEnergy      = gameStatus.modBatteryEnergy,
                    modDisappearingArrows = gameStatus.modDisappearingArrows,
                    modNoBombs            = gameStatus.modNoBombs,
                    modSongSpeed          = gameStatus.modSongSpeed,
                    modFailOnSaberClash   = gameStatus.modFailOnSaberClash,
                    modStrictAngles       = gameStatus.modStrictAngles
                };

                profile.Scores.Add(score);

                localProfilesData.lastScore = score;


                //var js = Newtonsoft.Json.JsonConvert.SerializeObject(gameStatus, Newtonsoft.Json.Formatting.Indented);
                //File.WriteAllText(Path.Combine(ScoreDirPath, "score" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".txt"), js);
                var js = Newtonsoft.Json.JsonConvert.SerializeObject(song, Newtonsoft.Json.Formatting.Indented);
                File.WriteAllText(Path.Combine(localProfilesData.ScoreDirPath, song.Hash + ".json"), js);
            }catch (Exception ex)
            {
                Plugin.Log("ERROR SAVING SCORE!! " + ex);
            }
        }