<commit_before>﻿using System;
using System.Linq;
using ColossalFramework;
using ColossalFramework.Plugins;
using ICities;
using UnityEngine;

namespace ModTools
{

    public class ModToolsBootstrap
    {

        private static GameObject modToolsGameObject;
        private static ModTools modTools;
        private static bool bootstrapped;

        public static bool IsModToolsActive()
        {
#if MODTOOLS_DEBUG
            return true;
#else
            var pluginManager = PluginManager.instance;
            var plugins = pluginManager.GetPluginsInfo();

            foreach (var item in plugins)
            {
                var instances = item.GetInstances<IUserMod>();
                if (instances.FirstOrDefault() is Mod)
                {
                    return item.isEnabled;
                }
            }

            return false;
#endif
        }

        public static void Bootstrap()
        {
            if (bootstrapped)
            {
                return;
            }
            try
            {
                CODebugBase<LogChannel>.verbose = true;
                CODebugBase<LogChannel>.EnableChannels(LogChannel.All);

                InitModTools(SimulationManager.UpdateMode.Undefined);

                RedirectionHelper.RedirectCalls(
                    typeof(LoadingWrapper).GetMethod("OnLevelLoaded", new[] { typeof(SimulationManager.UpdateMode) }),
                    typeof(IsolatedFailures).GetMethod("OnLevelLoaded", new[] { typeof(SimulationManager.UpdateMode) }));
                bootstrapped = true;
            }
            catch (Exception ex)
            {
                DebugOutputPanel.AddMessage(PluginManager.MessageType.Error, ex.Message);
            }
        }

        public static void InitModTools(SimulationManager.UpdateMode mode)
        {
            if (!IsModToolsActive())
            {
                return;
            }

            if (modToolsGameObject != null)
            {
                return;
            }

            modToolsGameObject = new GameObject("ModTools");
            modTools = modToolsGameObject.AddComponent<ModTools>();
            modTools.Initialize(mode);
        }

    }

    public class Mod : LoadingExtensionBase, IUserMod
    {

        public string Name
        {
            get { ModToolsBootstrap.Bootstrap(); return "ModTools"; }
        }

        public string Description
        {
            get { return "Debugging toolkit for modders"; }
        }

        public override void OnLevelLoaded(LoadMode mode)
        {
            ModToolsBootstrap.InitModTools((SimulationManager.UpdateMode)mode);
        }
    }

}
<commit_msg>Fix not working on exiting to main menu<commit_after>﻿using System;
using System.Linq;
using ColossalFramework;
using ColossalFramework.Plugins;
using ICities;
using UnityEngine;

namespace ModTools
{

    public class ModToolsBootstrap
    {

        private static GameObject modToolsGameObject;
        private static ModTools modTools;
        public static bool initialized;
        private static bool bootstrapped;
        public static bool inMainMenu = true;

        public static bool IsModToolsActive()
        {
#if MODTOOLS_DEBUG
            return true;
#else
            var pluginManager = PluginManager.instance;
            var plugins = pluginManager.GetPluginsInfo();

            foreach (var item in plugins)
            {
                var instances = item.GetInstances<IUserMod>();
                if (instances.FirstOrDefault() is Mod)
                {
                    return item.isEnabled;
                }
            }

            return false;
#endif
        }

        public static void Bootstrap()
        {
            if (initialized)
            {
                return;
            }
            try
            {
                if (!bootstrapped)
                {
                    CODebugBase<LogChannel>.verbose = true;
                    CODebugBase<LogChannel>.EnableChannels(LogChannel.All);
                    RedirectionHelper.RedirectCalls(
                        typeof(LoadingWrapper).GetMethod("OnLevelLoaded", new[] { typeof(SimulationManager.UpdateMode) }),
                        typeof(IsolatedFailures).GetMethod("OnLevelLoaded", new[] { typeof(SimulationManager.UpdateMode) }));
                    bootstrapped = true;
                }
                if (inMainMenu)
                {
                    InitModTools(SimulationManager.UpdateMode.Undefined);                    
                }
                initialized = true;
            }
            catch (Exception ex)
            {
                DebugOutputPanel.AddMessage(PluginManager.MessageType.Error, ex.Message);
            }
        }

        public static void InitModTools(SimulationManager.UpdateMode mode)
        {
            if (!IsModToolsActive())
            {
                return;
            }

            if (modToolsGameObject != null)
            {
                return;
            }

            modToolsGameObject = new GameObject("ModTools");
            modTools = modToolsGameObject.AddComponent<ModTools>();
            modTools.Initialize(mode);
        }

    }

    public class Mod : LoadingExtensionBase, IUserMod
    {

        public string Name
        {
            get { ModToolsBootstrap.Bootstrap(); return "ModTools"; }
        }

        public string Description
        {
            get { return "Debugging toolkit for modders"; }
        }

        public override void OnLevelLoaded(LoadMode mode)
        {
            ModToolsBootstrap.inMainMenu = false;
            ModToolsBootstrap.InitModTools((SimulationManager.UpdateMode)mode);
        }

        public override void OnLevelUnloading()
        {
            ModToolsBootstrap.initialized = false;
            ModToolsBootstrap.inMainMenu = true;
        }
    }

}

{'fraction_non_alphanumeric': 0.07342716635577412, 'fraction_numerical': 0.0, 'mean_word_length': 1.5356835769561479, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '3166241', 'n_tokens_mistral': 1458, 'n_tokens_neox': 1392, 'n_words': 296}