Эх сурвалжийг харах

override Jump Scenario to fix softlock #4

Scrublord1336 6 жил өмнө
parent
commit
b2bf4501bc

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

@@ -49,6 +49,7 @@ namespace XUnity.AutoTranslator.Plugin.Core
       /// All the translations are stored in this dictionary.
       /// </summary>
       private Dictionary<string, string> _translations = new Dictionary<string, string>();
+      private Dictionary<string, string> _reverseTranslations = new Dictionary<string, string>();
 
       /// <summary>
       /// These are the new translations that has not yet been persisted to the file system.
@@ -349,12 +350,14 @@ namespace XUnity.AutoTranslator.Plugin.Core
       private void AddTranslation( string key, string value )
       {
          _translations[ key ] = value;
+         _reverseTranslations[ value ] = key;
          _translatedTexts.Add( value );
       }
 
       private void AddTranslation( TranslationKey key, string value )
       {
          _translations[ key.GetDictionaryLookupKey() ] = value;
+         _reverseTranslations[ value ] = key.GetDictionaryLookupKey();
          _translatedTexts.Add( value );
       }
 
@@ -390,6 +393,11 @@ namespace XUnity.AutoTranslator.Plugin.Core
          return _translations.TryGetValue( key.GetDictionaryLookupKey(), out value );
       }
 
+      public bool TryGetReverseTranslation( string value, out string key )
+      {
+         return _reverseTranslations.TryGetValue( value, out key );
+      }
+
       public string Hook_TextChanged_WithResult( object ui, string text )
       {
          if( _hooksEnabled )

+ 25 - 2
src/XUnity.AutoTranslator.Plugin.Core/Hooks/UtageHooks.cs

@@ -10,11 +10,12 @@ namespace XUnity.AutoTranslator.Plugin.Core.Hooks
    public static class UtageHooks
    {
       public static readonly Type[] All = new[] {
-         typeof( AdvCommand_ParseCellLocalizedTextHook )
+         typeof( AdvCommand_ParseCellLocalizedTextHook ),
+         typeof( AdvEngine_JumpScenario ),
       };
    }
 
-   [Harmony, HarmonyAfter( Constants.KnownPlugins.DynamicTranslationLoader )]
+   [Harmony]
    public static class AdvCommand_ParseCellLocalizedTextHook
    {
       static bool Prepare( HarmonyInstance instance )
@@ -36,4 +37,26 @@ namespace XUnity.AutoTranslator.Plugin.Core.Hooks
          }
       }
    }
+
+   [Harmony]
+   public static class AdvEngine_JumpScenario
+   {
+      static bool Prepare( HarmonyInstance instance )
+      {
+         return Constants.Types.AdvEngine != null;
+      }
+
+      static MethodBase TargetMethod( HarmonyInstance instance )
+      {
+         return AccessTools.Method( Constants.Types.AdvEngine, "JumpScenario", new Type[] { typeof( string ) } );
+      }
+
+      static void Prefix( ref string label )
+      {
+         if( AutoTranslationPlugin.Current.TryGetReverseTranslation( label, out string key ) )
+         {
+            label = key;
+         }
+      }
+   }
 }