コード例 #1
0
        private IEnumerator HookTranslator()
        {
            Logger.Log("Waiting for hook...",Level.Info);
            yield return new WaitForEndOfFrame();

            var success = true;

            try
            {
                success = HookHelper.HookTranslationEvent(this);
            }
            catch (Exception e)
            {
                Logger.LogError("Exception while hooking:",e);
                success = false;
            }
            if (!success)
            {
                Destroy(this);
                yield break;
            }
            Logger.Log("Hook successful!",Level.Info);
        }
コード例 #2
0
        public void Awake()
        {
            Logger.Init(this.DataPath, Preferences);
            try
            {
                DontDestroyOnLoad(this);
                LoadConfig();
                Logger.Log($"Starting {CoreUtil.PLUGIN_NAME} v{CoreUtil.PLUGIN_VERSION}", Level.General);
                if (!_pluginActive)
                {
                    Logger.Log("Plugin is disabled.", Level.General);
                    if (CoreUtil.FinishLoadingConfig())
                    {
                        SaveConfig();
                    }
                    Destroy(this);
                    return;
                }

                var success = LoadTranslator();
                if (!success)
                {
                    Logger.LogError($"Failed to load Translation module '{_activeTranslator}'");
                    if (CoreUtil.FinishLoadingConfig())
                    {
                        SaveConfig();
                    }
                    Destroy(this);
                    return;
                }

                Translator.LoadConfig();
                _preprocessor.LoadConfig();
                if (CoreUtil.FinishLoadingConfig())
                {
                    SaveConfig();
                }

                LoadIgnores();

                var translatorPlugin = HookHelper.DetectTranslationPlugin();
                if (translatorPlugin == HookHelper.ParentTranslationPlugin.None)
                {
                    var bldr = new StringBuilder("Found none of the supported translation plugins!\n");
                    bldr.AppendLine("Make sure, that one of the following is installed:");
                    bldr.AppendLine(" - Yet Another Translator (recommended)");
                    bldr.AppendLine(" - Unified Translation loader (only for ReiPatcher)");
                    bldr.AppendLine(" - Translation Plus (only for Sybaris)");
                    Logger.LogError(bldr.ToString());
                    Destroy(this);
                    return;
                }

                Logger.Log($"Initializing Module {_activeTranslator}", Level.Info);
                success = Translator.Init();
                if (!success)
                {
                    Logger.LogError($"Failed to load Translation module {_activeTranslator}");
                    Destroy(this);
                    return;
                }

                StartCoroutine(HookTranslator());

                Logger.Log($"Using translation cache file @: {TranslationFilePath}", Level.Info);
                LoadCacheFromDisk();

                if (_dumpCache && _cacheDumpFrequenzy == CacheDumpFrequenzy.Periodic)
                {
                    StartCoroutine(PeriodicDumpCache());
                }

                if (_preprocessor.Init(DataPath))
                {
                    Logger.Log("Successfully loaded text preprocessor", Level.Info);
                }
            }
            catch (Exception e)
            {
                Logger.LogError(e);
                Destroy(this);
            }
        }