瀏覽代碼

Version 3.6.0

 * FEATURE - 'Translation Aggregator'-like view that enables viewing translations for displayed texts from multiple different translators (press ALT+1)
 * FEATURE - Substitution support. Enable dictionary lookup for strings (usually proper nouns) embedded in text to replace them with a manual translation
 * FEATURE - Papago translator support
 * MISC - Removed hard dependency on UnityEngine.UI to support older versions of the Unity engine
 * MISC - Automatically initialize LEC installation path if installed when creating configuration file
 * MISC - Automatically enable experimental hooks when installed in single mod scenario (ReiPatcher) and it is required by the runtime
 * BUG FIX - Fixed bug where LEC was not working when run in a .NET 4.x equivalent runtime
randoman 5 年之前
父節點
當前提交
3c2d07353d

+ 1 - 0
CHANGELOG.md

@@ -4,6 +4,7 @@
  * FEATURE - Papago translator support
  * MISC - Removed hard dependency on UnityEngine.UI to support older versions of the Unity engine
  * MISC - Automatically initialize LEC installation path if installed when creating configuration file
+ * MISC - Automatically enable experimental hooks when installed in single mod scenario (ReiPatcher) and it is required by the runtime
  * BUG FIX - Fixed bug where LEC was not working when run in a .NET 4.x equivalent runtime
 
 ### 3.5.0

+ 2 - 0
src/XUnity.AutoTranslator.Plugin.BepIn-5x/AutoTranslatorPlugin.cs

@@ -41,6 +41,8 @@ namespace XUnity.AutoTranslator.Plugin.BepIn_5x
 
       public string TranslationPath { get; }
 
+      public bool AllowRuntimeHooksByDefault => false;
+
       public IniFile ReloadConfig()
       {
          if( !File.Exists( _configPath ) )

+ 2 - 0
src/XUnity.AutoTranslator.Plugin.BepIn/AutoTranslatorPlugin.cs

@@ -39,6 +39,8 @@ namespace XUnity.AutoTranslator.Plugin.BepIn
 
       public string ConfigPath => _dataPath;
 
+      public bool AllowRuntimeHooksByDefault => false;
+
       public IniFile ReloadConfig()
       {
          if( !File.Exists( _configPath ) )

+ 1 - 1
src/XUnity.AutoTranslator.Plugin.Core/Configuration/Settings.cs

@@ -157,7 +157,7 @@ namespace XUnity.AutoTranslator.Plugin.Core.Configuration
             WhitespaceRemovalStrategy = PluginEnvironment.Current.Preferences.GetOrDefault( "Behaviour", "WhitespaceRemovalStrategy", WhitespaceHandlingStrategy.TrimPerNewline );
             RomajiPostProcessing = PluginEnvironment.Current.Preferences.GetOrDefault( "Behaviour", "RomajiPostProcessing", TextPostProcessing.ReplaceMacronWithCircumflex | TextPostProcessing.RemoveApostrophes );
             TranslationPostProcessing = PluginEnvironment.Current.Preferences.GetOrDefault( "Behaviour", "TranslationPostProcessing", TextPostProcessing.ReplaceMacronWithCircumflex );
-            EnableExperimentalHooks = PluginEnvironment.Current.Preferences.GetOrDefault( "Behaviour", "EnableExperimentalHooks", false );
+            EnableExperimentalHooks = PluginEnvironment.Current.Preferences.GetOrDefault( "Behaviour", "EnableExperimentalHooks", PluginEnvironment.Current.AllowRuntimeHooksByDefault && !Features.SupportsReflectionEmit );
             ForceExperimentalHooks = PluginEnvironment.Current.Preferences.GetOrDefault( "Behaviour", "ForceExperimentalHooks", false );
             CacheRegexLookups = PluginEnvironment.Current.Preferences.GetOrDefault( "Behaviour", "CacheRegexLookups", false );
             CacheWhitespaceDifferences = PluginEnvironment.Current.Preferences.GetOrDefault( "Behaviour", "CacheWhitespaceDifferences", true );

+ 2 - 0
src/XUnity.AutoTranslator.Plugin.Core/DefaultPluginEnvironment.cs

@@ -33,6 +33,8 @@ namespace XUnity.AutoTranslator.Plugin.Core
 
       public string ConfigPath => _dataFolder;
 
+      public bool AllowRuntimeHooksByDefault => true;
+
       public void SaveConfig()
       {
          _file.Save( _configPath );

+ 21 - 0
src/XUnity.AutoTranslator.Plugin.Core/Features.cs

@@ -1,5 +1,6 @@
 using System;
 using System.Linq;
+using System.Reflection.Emit;
 using System.Text;
 using UnityEngine;
 using XUnity.AutoTranslator.Plugin.Core.Constants;
@@ -15,6 +16,8 @@ namespace XUnity.AutoTranslator.Plugin.Core
 
       internal static bool SupportsClipboard { get; } = false;
 
+      internal static bool SupportsReflectionEmit { get; } = false;
+
       /// <summary>
       /// Gets a bool indicating if the class CustomYieldInstruction is available.
       /// </summary>
@@ -76,6 +79,24 @@ namespace XUnity.AutoTranslator.Plugin.Core
          {
 
          }
+
+         try
+         {
+            TestReflectionEmit();
+
+            SupportsReflectionEmit = true;
+         }
+         catch( Exception )
+         {
+            SupportsReflectionEmit = false;
+         }
+      }
+
+      private static void TestReflectionEmit()
+      {
+         MethodToken t1 = default( MethodToken );
+         MethodToken t2 = default( MethodToken );
+         var ok = t1 == t2;
       }
    }
 }

+ 5 - 0
src/XUnity.AutoTranslator.Plugin.Core/IPluginEnvironment.cs

@@ -38,5 +38,10 @@ namespace XUnity.AutoTranslator.Plugin.Core
       /// Saves the preferences file.
       /// </summary>
       void SaveConfig();
+
+      /// <summary>
+      /// Gets a bool indicating whether the plugin environment allows experimental hooks by default.
+      /// </summary>
+      bool AllowRuntimeHooksByDefault { get; }
    }
 }

+ 2 - 0
src/XUnity.AutoTranslator.Plugin.IPA/AutoTranslatorPlugin.cs

@@ -38,6 +38,8 @@ namespace XUnity.AutoTranslator.Plugin.IPA
 
       public string ConfigPath => _dataPath;
 
+      public bool AllowRuntimeHooksByDefault => false;
+
       public IniFile ReloadConfig()
       {
          if( !File.Exists( _configPath ) )

+ 2 - 0
src/XUnity.AutoTranslator.Plugin.UnityInjector/AutoTranslatorPlugin.cs

@@ -20,6 +20,8 @@ namespace XUnity.AutoTranslator.Plugin.UnityInjector
 
       public string ConfigPath => DataPath;
 
+      public bool AllowRuntimeHooksByDefault => false;
+
       void IPluginEnvironment.SaveConfig()
       {
          SaveConfig();