Пример #1
0
        public void DisplayFor(AudioSourceMgr mgr)
        {
            if (!Enabled)
            {
                return;
            }

            lastPlayed     = mgr.audiosource;
            lastPlayedName = mgr.FileName;
            currentAudioTracker.Stop();

            string soundName = Path.GetFileNameWithoutExtension(mgr.FileName);

            subtitleText.text = AUDIOCLIP_PREFIX + soundName;

            if (subtitleText.text == soundName)
            {
                lastWasTranslated = false;
                if (!showUntranslatedText)
                {
                    subtitleText.text = string.Empty;
                }

                Logger.DumpVoice(soundName, mgr.audiosource.clip, CurrentLevel);
            }
            else
            {
                lastWasTranslated = true;
            }

            TrackAudio(mgr.audiosource);
        }
Пример #2
0
 private void OnArcTextureLoaded(object sender, TextureTranslationEventArgs e)
 {
     if (Logger.CanDump(DumpType.Textures))
     {
         Logger.DumpTexture(DumpType.Textures, e, false, CurrentLevel);
     }
 }
Пример #3
0
        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;
        }
Пример #5
0
        private void OnTranslateString(object sender, StringTranslationEventArgs e)
        {
            string inputText = e.Text;

            if (string.IsNullOrEmpty(inputText))
            {
                return;
            }

            if (inputText.StartsWith(TEMPLATE_STRING_PREFIX))
            {
                if (!isRetranslating)
                {
                    e.Translation = inputText;
                    return;
                }
                inputText = inputText.Substring(1);
            }

            bool isAudioClipName = inputText.StartsWith(Subtitles.AUDIOCLIP_PREFIX);

            if (isAudioClipName)
            {
                inputText = inputText.Substring(Subtitles.AUDIOCLIP_PREFIX.Length);
            }

            TextTranslation translation = Memory.GetTextTranslation(inputText);

            if (translation.Result == TranslationResult.Ok || isRetranslating && translation.Result == TranslationResult.NotFound)
            {
                e.Translation = translation.Text;
            }

            if (e.Type == StringType.Template && e.Translation != null)
            {
                e.Translation = TEMPLATE_STRING_PREFIX + e.Translation;
                return;
            }

            if (translation.Result == TranslationResult.Ok || translation.Result == TranslationResult.Translated)
            {
                return;
            }

            if (!isAudioClipName)
            {
                if (e.Type != StringType.Template) // Don't put templates to clipboard -- let the game replace the values first
                {
                    Clipboard.AddText(inputText, CurrentLevel);
                }
                // Still going to dump, since templates are useful to translators, but not all translateable strings are templates
                Logger.DumpLine(inputText, CurrentLevel);
            }
            else
            {
                e.Translation = inputText;
                Logger.DumpLine(inputText, CurrentLevel, DumpType.Voices);
            }
        }
        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);
        }
Пример #7
0
        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);
        }
Пример #8
0
 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();
     }
 }
Пример #9
0
        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();
        }
Пример #10
0
        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);
        }