public void Awake()
        {
            DontDestroyOnLoad(this);

            MethodInfo processAndRequestMethod = typeof(UILabel).GetMethod("ProcessAndRequest");

            processAndRequest = label => processAndRequestMethod?.Invoke(label, null);

            Memory    = new TranslationMemory(DataPath);
            Clipboard = gameObject.AddComponent <Clipboard>();
            Subtitles = gameObject.AddComponent <Subtitles>();

            InitConfig();

            Memory.LoadTranslations();

            TranslationHooks.TranslateText    += OnTranslateString;
            TranslationHooks.AssetTextureLoad += OnAssetTextureLoad;
            TranslationHooks.ArcTextureLoad   += OnTextureLoad;
            TranslationHooks.SpriteLoad       += OnTextureLoad;
            TranslationHooks.ArcTextureLoaded += OnArcTextureLoaded;
            TranslationHooks.TranslateGraphic += OnTranslateGraphic;
            TranslationHooks.PlaySound        += OnPlaySound;
            TranslationHooks.GetOppositePair  += OnGetOppositePair;
            TranslationHooks.GetOriginalText  += OnGetOriginalText;
            Logger.WriteLine("Hooking complete");
        }
        private void OnTextureLoad(object sender, TextureTranslationEventArgs e)
        {
            string textureName = e.Name;

            if (lastFoundTexture != textureName)
            {
                lastFoundTexture = textureName;
                Logger.WriteLine(ResourceType.Textures, LogLevel.Minor, $"FindTexture::{textureName}");
            }

            var replacement = Memory.GetTexture(textureName);
            TextureResource resource = null;

            switch (replacement.TextureType)
            {
                case TextureType.PNG:
                    resource = new TextureResource(1, 1, TextureFormat.ARGB32, File.ReadAllBytes(replacement.FilePath));
                    break;
                case TextureType.TEX:
                    resource = TexUtils.ReadTexture(File.ReadAllBytes(replacement.FilePath), textureName);
                    break;
                case TextureType.None:
                default:
                    if (e.OriginalTexture != null)
                        Logger.DumpTexture(DumpType.TexSprites, e, true, CurrentLevel);
                    return;
            }

            if (lastLoadedTexture != textureName)
                Logger.WriteLine(ResourceType.Textures, $"Texture::{textureName}");
            lastLoadedTexture = textureName;

            e.Data = resource;
        }
        private void OnPlaySound(object sender, SoundEventArgs e)
        {
            if (!Settings.Subtitles.Enable || e.AudioSourceMgr.SoundType < AudioSourceMgr.Type.Voice)
                return;

            Logger.WriteLine(ResourceType.Voices, $"Voices {e.AudioSourceMgr.FileName}");

            Subtitles.DisplayFor(e.AudioSourceMgr);
        }
        private void OnYotogiSubtitleCapture(object sender, StringTranslationEventArgs e)
        {
            if (string.IsNullOrEmpty(e.Text))
            {
                return;
            }
            string voiceFile = DisplayForLast(e.Text);

            if (voiceFile == null)
            {
                return;
            }
            Logger.WriteLine(ResourceType.Strings, "Strings::Captured yotogi subtitle from script");
            Logger.DumpLine($"{AUDIOCLIP_PREFIX}{voiceFile} {e.Text}", CurrentLevel);
        }
 public void Update()
 {
     if (Input.GetKeyDown(KeyCode.F12))
     {
         Logger.WriteLine("Reloading config");
         ReloadConfig();
         InitConfig();
         if (Settings.EnableStringReload)
         {
             Logger.WriteLine("Reloading translations");
             Memory.LoadTranslations();
             Memory.ActivateLevelTranslations(CurrentLevel, false);
         }
         TranslateExisting();
     }
 }
        public void OnDestroy()
        {
            Logger.WriteLine("Removing hooks");
            TranslationHooks.TranslateText    -= OnTranslateString;
            TranslationHooks.AssetTextureLoad -= OnAssetTextureLoad;
            TranslationHooks.ArcTextureLoad   -= OnTextureLoad;
            TranslationHooks.SpriteLoad       -= OnTextureLoad;
            TranslationHooks.ArcTextureLoaded -= OnArcTextureLoaded;
            TranslationHooks.TranslateGraphic -= OnTranslateGraphic;
            TranslationHooks.PlaySound        -= OnPlaySound;
            TranslationHooks.GetOppositePair  -= OnGetOppositePair;
            TranslationHooks.GetOriginalText  -= OnGetOriginalText;

            Destroy(Subtitles);
            Destroy(Clipboard);

            Logger.Dispose();
        }
        private void OnAssetTextureLoad(object sender, TextureTranslationEventArgs e)
        {
            if (lastFoundAsset != e.Name)
            {
                lastFoundAsset = e.Name;
                Logger.WriteLine(ResourceType.Assets, LogLevel.Minor, $"FindAsset::{e.Name} [{e.Meta}::{e.CompoundHash}]");
            }

            string[] namePossibilities =
            {
                e.CompoundHash + "@" + SceneManager.GetActiveScene().buildIndex, e.Name + "@" + SceneManager.GetActiveScene().buildIndex,
                e.CompoundHash,                                                  e.Name
            };

            foreach (string assetName in namePossibilities)
            {
                if (lastFoundAsset != assetName)
                {
                    lastFoundAsset = assetName;
                    Logger.WriteLine(ResourceType.Assets, LogLevel.Minor, $"TryFindAsset::{assetName}");
                }

                string assetPath = Memory.GetAssetPath(assetName);

                if (assetPath == null)
                {
                    continue;
                }
                if (lastLoadedAsset != assetName)
                {
                    Logger.WriteLine(ResourceType.Assets, $"LoadAsset::{assetName}");
                }
                lastLoadedAsset = assetName;

                e.Data = new TextureResource(1, 1, TextureFormat.ARGB32, File.ReadAllBytes(assetPath));
                return;
            }

            Logger.DumpTexture(DumpType.Assets, e, true, CurrentLevel);
        }