protected RedirectorTextAssetLoadedHandlerBase(TextResourceRedirector plugin, string extraEnableHelp = null,
                                                       bool allowTranslationRegistration = false)
        {
            CheckDirectory = true;
            AllowTranslationRegistration = allowTranslationRegistration;
            Plugin            = plugin;
            ConfigSectionName = GetType().Name;

            EnableHandler = this.ConfigEntryBind("Enabled", true, new ConfigDescription(
                                                     $"Handle {nameof(TextAsset)} assets {extraEnableHelp ?? string.Empty}".Trim(),
                                                     null, "Advanced"));

            if (allowTranslationRegistration)
            {
                EnableRegisterAsTranslationsHandler = this.ConfigEntryBind(
                    "Register as Translations", true, new ConfigDescription(
                        $"Register strings replaced by {ConfigSectionName} as text translations with " +
                        XUAPluginData.Name, null, "Advanced"));

#if !HS
                SceneManager.sceneLoaded += SceneManagerSceneLoadedRegisterAsTranslations;
#endif
                plugin.TranslatorTranslationsLoaded += TranslatorTranslationsLoadedRegisterAsTranslations;
            }

            Logger.LogInfo($"{GetType()} {(Enabled ? "enabled" : "disabled")}");
        }
コード例 #2
0
        private void ConfigureHandlersForKK(TextResourceRedirector sender, EventArgs eventArgs)
        {
            sender.NickNameHandler        = new NickNameHandler(sender);
            sender.MapInfoHandler         = new MapInfoHandler(sender);
            sender.EventInfoHandler       = new EventInfoHandler(sender);
            sender.MakerCustomDataHandler = new MakerCustomDataHandler(sender);


            // limit what handlers will attempt to handle to speed things up
            if (sender.ScenarioDataHandler is IPathListBoundHandler scenarioHandler)
            {
                scenarioHandler.WhiteListPaths.Add("abdata/adv");
            }

            //if (sender.TextAssetTableHandler is IPathListBoundHandler tableHandler)
            //    tableHandler.WhiteListPaths.Add("abdata/h/list");

            TextAssetTableHandler.TableRulesGetters.Add(HTextRulesGetter);

            if (sender.ChaListDataHandler is IPathListBoundHandler chaListHandler)
            {
                chaListHandler.WhiteListPaths.Add("abdata/list/characustom");
            }

            /*
             * if (sender.TextAssetRawBytesHandler is IPathListBoundHandler textAssetRawBytesHandler)
             * {
             *  TextAssetRawBytesHandler.Enabled = true;
             *  textAssetRawBytesHandler.WhiteListPaths.Add("abdata/action/fixchara");
             * }
             */
        }
コード例 #3
0
        private void ConfigureHandlersForAI(TextResourceRedirector sender, EventArgs eventArgs)
        {
            sender.TitleSkillNameHandler = new TitleSkillNameHandler(this, true);
            sender.ChaListDataHandler.WhiteListPaths.Add("abdata/list/characustom");

            var excelSkipPaths = new[]
            {
                "abdata/list/map/area",
                "abdata/list/map/chunk",
                "abdata/list/map/enviro",
                "abdata/list/map/event_item",
                "abdata/list/map/ikinfo",
                "abdata/list/map/mapinfo",
                "abdata/list/map/minimap",
                "abdata/list/map/openstate",
                "abdata/list/map/particle",
                "abdata/list/map/plant_item",
                "abdata/list/map/storypoint",
                "abdata/list/map/timeinfo",
                "abdata/list/map/vanish"
            };

            foreach (var path in excelSkipPaths)
            {
                sender.ExcelDataHandler.BlackListPaths.Add(path);
            }
        }
コード例 #4
0
        public NickNameHandler(TextResourceRedirector plugin) : base(plugin)
        {
            Instance = this;

            // replacement fires INSIDE the function we need to postfix, so init hooks up front
            InitHooks();
        }
コード例 #5
0
 public NickNameHandler(TextResourceRedirector plugin) : base(plugin, allowTranslationRegistration: true)
 {
     Instance = this;
     plugin.TranslatorTranslationsLoaded += Plugin_TranslatorTranslationsLoaded;
     InitHooks();
     SceneManager.sceneLoaded   += SceneManager_sceneLoaded;
     SceneManager.sceneUnloaded += SceneManager_sceneUnloaded;
 }
        protected UntestedParamAssetLoadedHandler(TextResourceRedirector plugin,
                                                  bool allowTranslationRegistration = false, bool enableSafeModeByDefault = true) :
            base(plugin, allowTranslationRegistration)
        {
            EnableSafeMode = this.ConfigEntryBind("Enable Safe Mode", enableSafeModeByDefault,
                                                  new ConfigDescription($@"
Handle {typeof(T).Name} assets indirectly, enable this if you suspect this handler 
is causing game to misbehave.".ToSingleLineString(),
                                                                        null, "Advanced"));
        }
コード例 #7
0
        public MakerCustomDataHandler(TextResourceRedirector plugin) : base(plugin, true)
        {
            WhiteListPaths.Add("abdata/custom");

            var baseHandler = plugin.ExcelDataHandler;

            SupportedColumnNames.AddRange(baseHandler.SupportedColumnNames.ToList());
            foreach (var pth in WhiteListPaths)
            {
                baseHandler.BlackListPaths.Add(pth);
            }
        }
コード例 #8
0
 internal static void Init(TextResourceRedirector plugin)
 {
     if (Initialized)
     {
         return;
     }
     Initialized      = true;
     EnableTextReflow = plugin.Config.Bind("Text Formatter", "Alternate Text Reflow", true,
                                           "Use whitespace based text reflow for non-Japanese languages.");
     TextResourceRedirector.Logger.LogDebug($"Hooking {typeof(Hooks).FullName}");
     Harmony.CreateAndPatchAll(typeof(Hooks));
 }
コード例 #9
0
            internal static void FormatDoPostfix(Format __instance, List <object> ___parameters)
            {
                if (TextResourceRedirector.Instance == null)
                {
                    return;
                }
                if (!TextResourceRedirector.Instance.TextResourceHelper.FormatKeys.Contains(__instance.name))
                {
                    return;
                }
                try
                {
                    var scope = TextResourceRedirector.GetCurrentTranslationScope();
                    var orig  = __instance.scenario.Vars[__instance.name].o as string;
                    if (string.IsNullOrEmpty(orig) || !LanguageHelper.IsTranslatable(orig))
                    {
                        return;
                    }


                    if (TryGetFormatDoCacheValue(__instance.name, scope, orig, out var cachedTrans))
                    {
                        __instance.scenario.Vars[__instance.name] = new ValData(cachedTrans);
                        return;
                    }

                    var parameters = ___parameters.Select(
                        p => p is string origP && LanguageHelper.IsTranslatable(origP) &&
                        AutoTranslator.Default.TryTranslate(origP, scope, out var transP)
                            ? transP
                            : p).ToArray();

                    var format = __instance.format;
                    format = LanguageHelper.IsTranslatable(format) &&
                             AutoTranslator.Default.TryTranslate(format, out var transFormat)
                        ? transFormat
                        : format;

                    var newResult = string.Format(format, parameters);
                    __instance.scenario.Vars[__instance.name] = new ValData(newResult);
                    if (!string.IsNullOrEmpty(orig) && !string.IsNullOrEmpty(newResult) && orig != newResult)
                    {
                        AddToFormatDoCache(__instance.name, scope, orig, newResult);
                    }
                }
                catch (Exception err)
                {
                    TextResourceRedirector.Logger?.LogWarning(
                        $"{nameof(FormatDoPostfix)}: Unexpected error: {err.Message}");
                    UnityEngine.Debug.LogException(err);
                }
            }
コード例 #10
0
        private void ConfigureHandlersForHS2(TextResourceRedirector sender, EventArgs eventArgs)
        {
            sender.VoiceInfoHandler            = new VoiceInfoHandler(sender);
            sender.BGMNameInfoHandler          = new BGMNameInfoHandler(sender);
            sender.EventContentInfoDataHandler = new EventContentInfoDataHandler(sender);
            sender.MapInfoHandler             = new MapInfoHandler(sender);
            sender.ParameterNameInfoHandler   = new ParameterNameInfoHandler(sender);
            sender.AchievementInfoDataHandler = new AchievementInfoDataHandler(sender);
            sender.ChaListDataHandler.WhiteListPaths.Add("abdata/list/characustom");

            if (TextResourceHelper is HS2_TextResourceHelper helper && helper.IsHS2DX())
            {
                // DX only
                sender.PlanNameInfoHandler = new PlanNameInfoHandler(sender);
            }
        }
コード例 #11
0
        protected StringArrayParamAssetLoadedHandler(TextResourceRedirector plugin, int translatedIndex = -1,
                                                     bool allowTranslationRegistration = true) :
            base(plugin, allowTranslationRegistration)
        {
            EnableInternalAssetTranslation = this.ConfigEntryBind("Use Translation from Asset", true,
                                                                  $"Use translation stored in {typeof(T).Name} assets if possible");

            if (translatedIndex == -1)
            {
                translatedIndex = Plugin.GetCurrentGameLanguage();
            }
            if (translatedIndex > 0)
            {
                DisableEmptyCacheCheck = true;
            }
            TranslatedIndex = translatedIndex;
        }
コード例 #12
0
        internal void Awake()
        {
            _instance          = this;
            Logger             = Logger ?? base.Logger;
            TextResourceHelper = GetTextResourceHelper();

            ExcelDataHandler = new ExcelDataHandler(this);

            ScenarioDataHandler   = new ScenarioDataHandler(this);
            TextAssetTableHandler = new TextAssetTableHandler(this);
#if RAW_DUMP_SUPPORT
            TextAssetRawBytesHandler = new TextAssetRawBytesHandler(this);
#endif

            enabled = false;
#if !HS
            ChaListDataHandler = new ChaListDataHandler(this);
#endif
            XuaHooks.Init();
            OnTextResourceRedirectorAwake(EventArgs.Empty);
        }
        protected RedirectorTextAssetLoadedHandlerBase(TextResourceRedirector plugin, string extraEnableHelp = null,
                                                       bool allowTranslationRegistration = false, bool allowFallbackMapping = false)
        {
            CheckDirectory = true;
            AllowTranslationRegistration = allowTranslationRegistration;
            AllowFallbackMapping         = allowFallbackMapping;
            Plugin            = plugin;
            ConfigSectionName = GetType().Name;

            EnableHandler = this.ConfigEntryBind("Enabled", true, new ConfigDescription(
                                                     $"Handle {nameof(TextAsset)} assets {extraEnableHelp ?? string.Empty}".Trim(),
                                                     null, "Advanced"));

            if (allowTranslationRegistration)
            {
                EnableRegisterAsTranslationsHandler = this.ConfigEntryBind(
                    "Register as Translations", true, new ConfigDescription(
                        $"Register strings replaced by {ConfigSectionName} as text translations with " +
                        XUAPluginData.Name, null, "Advanced"));

#if !HS
                SceneManager.sceneLoaded += SceneManagerSceneLoadedRegisterAsTranslations;
#endif
                plugin.TranslatorTranslationsLoaded += TranslatorTranslationsLoadedRegisterAsTranslations;
            }

            if (allowFallbackMapping)
            {
                EnableFallbackMappingConfig = this.ConfigEntryBind("Allow fallback mapping",
                                                                   TextResourceRedirector.EnableFallbackMappingConfigDefault, new ConfigDescription(
                                                                       $@"
Allow searching related assets for otherwise unhandled {ConfigSectionName} translations.
May slow down load times at cost of improved translations
(especially useful when game has new content).".ToSingleLineString(), null, "Advanced"));
            }

            Logger.LogInfo($"{GetType()} {(Enabled ? "enabled" : "disabled")}");
        }
コード例 #14
0
 public ScenarioDataHandler(TextResourceRedirector _ = null)
 {
 }
コード例 #15
0
 internal void Main()
 {
     _instance = this;
     Logger    = Logger ?? base.Logger;
 }
コード例 #16
0
 public AnimationInfoDataHandler(TextResourceRedirector plugin) :
     base(plugin, true)
 {
     _instance = this;
     InitHooks();
 }
コード例 #17
0
 public ScenarioDataHandler(TextResourceRedirector plugin) : base(plugin)
 {
 }
コード例 #18
0
 public EventInfoHandler(TextResourceRedirector plugin) : base(plugin, true)
 {
 }
コード例 #19
0
        // game searches by personality name against this table
        // can't do an in-place update of personality name table without possibly
        // breaking things

        public VoiceInfoHandler(TextResourceRedirector plugin) : base(plugin, true)
        {
            _instance = this;
            InitHooks();
        }
コード例 #20
0
 public MapThumbnailInfoHandler(TextResourceRedirector plugin) : base(plugin, true)
 {
 }
コード例 #21
0
 protected TextAssetMessagePackHandlerBase(TextResourceRedirector plugin, string mark,
                                           bool allowTranslationRegistration = false) : base(plugin,
                                                                                             $"with {typeof(T).Name} packed inside", allowTranslationRegistration)
 {
     SetObjectMark(mark);
 }
コード例 #22
0
 private void ConfigureHandlersForAI(TextResourceRedirector sender, EventArgs eventArgs)
 {
     sender.TitleSkillNameHandler = new TitleSkillNameHandler(this, true);
     sender.ChaListDataHandler.WhiteListPaths.Add("abdata/list/characustom");
 }
コード例 #23
0
 public EstheticVoiceInfoHandler(TextResourceRedirector plugin) : base(plugin, true)
 {
 }
コード例 #24
0
 public TopicPersonalityGroupHandler(TextResourceRedirector plugin) : base(plugin, true)
 {
 }
コード例 #25
0
 public WhereLiveDataHandler(TextResourceRedirector plugin) : base(plugin, true)
 {
 }
コード例 #26
0
 public MapInfoHandler(TextResourceRedirector plugin) : base(plugin, allowTranslationRegistration: true)
 {
     Instance = this;
 }
コード例 #27
0
 public TopicHandler(TextResourceRedirector plugin) : base(plugin, true)
 {
 }
コード例 #28
0
 public ParameterNameInfoHandler(TextResourceRedirector plugin) : base(plugin)
 {
 }
コード例 #29
0
 public CommunicationInfoHandler(TextResourceRedirector plugin) :
     base(plugin, true)
 {
 }
コード例 #30
0
 public ExcelDataHandler(TextResourceRedirector plugin, bool allowTranslationRegistration = false) :
     base(plugin, null, allowTranslationRegistration)
 {
 }