瀏覽代碼

Merge branch 'feature/safeguards' into release/v2.12.0

Scrublord1336 6 年之前
父節點
當前提交
9c1017555a

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

@@ -547,6 +547,8 @@ namespace XUnity.AutoTranslator.Plugin.Core
 
       public string Hook_TextChanged_WithResult( object ui, string text )
       {
+         if( !ui.IsKnownType() ) return null;
+
          if( _hooksEnabled )
          {
             return TranslateOrQueueWebJob( ui, text, true );

+ 14 - 1
src/XUnity.AutoTranslator.Plugin.Core/Extensions/ObjectExtensions.cs

@@ -14,7 +14,20 @@ namespace XUnity.AutoTranslator.Plugin.Core.Extensions
    {
       private static readonly object Sync = new object();
       private static readonly WeakDictionary<object, object> DynamicFields = new WeakDictionary<object, object>();
-      
+
+      public static bool IsKnownType( this object ui )
+      {
+         if( ui == null ) return false;
+
+         var type = ui.GetType();
+
+         return ui is Text
+            || ui is UnityEngine.GUIContent
+            || ( Types.UILabel != null && Types.UILabel.IsAssignableFrom( type ) )
+            || ( Types.TMP_Text != null && Types.TMP_Text.IsAssignableFrom( type ) )
+            || ( Types.AdvCommand != null && Types.AdvCommand.IsAssignableFrom( type ) );
+      }
+
       public static bool SupportsStabilization( this object ui )
       {
          if( ui == null ) return false;