<commit_before>﻿using System.Reflection;
using KSP.UI.Screens;
using LmpClient.Base;
using LmpCommon.Locks;

namespace LmpClient.Systems.KscScene
{
    public class KscSceneEvents: SubSystem<KscSceneSystem>
    {
        private static readonly MethodInfo ClearVesselMarkers = typeof(KSCVesselMarkers).GetMethod("ClearVesselMarkers", BindingFlags.NonPublic | BindingFlags.Instance);

        public void OnLockAcquire(LockDefinition lockdefinition)
        {
            if (KSCVesselMarkers.fetch) KSCVesselMarkers.fetch.RefreshMarkers();
        }

        public void OnLockRelease(LockDefinition lockdefinition)
        {
            if (KSCVesselMarkers.fetch) KSCVesselMarkers.fetch.RefreshMarkers();
        }

        /// <summary>
        /// Sometimes the vessel markers stay there with corrupt values so here we force clearing them
        /// </summary>
        public void OnSceneRequested(GameScenes requestedScene)
        {
            if (requestedScene > GameScenes.SPACECENTER && KSCVesselMarkers.fetch != null)
            {
                ClearVesselMarkers?.Invoke(KSCVesselMarkers.fetch, null);
            }
        }

        /// <summary>
        /// Sometimes the vessel markers stay there with corrupt values so here we force clearing them
        /// </summary>
        public void LevelLoaded(GameScenes data)
        {
            if (data == GameScenes.SPACECENTER && KSCVesselMarkers.fetch)
            {
                KSCVesselMarkers.fetch.RefreshMarkers();
            }
        }
    }
}
<commit_msg>Stronger code to remove markers<commit_after>﻿using Harmony;
using KSP.UI.Screens;
using LmpClient.Base;
using LmpCommon.Locks;
using System.Reflection;
using UnityEngine;

namespace LmpClient.Systems.KscScene
{
    public class KscSceneEvents: SubSystem<KscSceneSystem>
    {
        private static readonly MethodInfo ClearVesselMarkers = typeof(KSCVesselMarkers).GetMethod("ClearVesselMarkers", AccessTools.all);

        public void OnLockAcquire(LockDefinition lockdefinition)
        {
            if (KSCVesselMarkers.fetch) KSCVesselMarkers.fetch.RefreshMarkers();
        }

        public void OnLockRelease(LockDefinition lockdefinition)
        {
            if (KSCVesselMarkers.fetch) KSCVesselMarkers.fetch.RefreshMarkers();
        }

        /// <summary>
        /// Sometimes the vessel markers stay there with corrupt values so here we force clearing them
        /// </summary>
        public void OnSceneRequested(GameScenes requestedScene)
        {
            if (requestedScene > GameScenes.SPACECENTER)
            {
                ClearMarkers();
            }
        }

        /// <summary>
        /// Sometimes the vessel markers stay there with corrupt values so here we force clearing them
        /// </summary>
        public void LevelLoaded(GameScenes data)
        {
            if (data == GameScenes.SPACECENTER)
            {
                ClearMarkers();
                KSCVesselMarkers.fetch.RefreshMarkers();
            }
        }

        private static void ClearMarkers()
        {
            if (KSCVesselMarkers.fetch)
                ClearVesselMarkers?.Invoke(KSCVesselMarkers.fetch, null);

            foreach (var kscVesselMarker in Object.FindObjectsOfType<KSCVesselMarker>())
            {
                kscVesselMarker.Terminate();
                Object.DestroyImmediate(kscVesselMarker);
            }
        }
    }
}

{'fraction_non_alphanumeric': 0.08104956268221575, 'fraction_numerical': 0.0, 'mean_word_length': 2.179796107506951, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5757575', 'n_tokens_mistral': 964, 'n_tokens_neox': 913, 'n_words': 199}