From eece8aa8abefb4268771957539d23c59a474a44c Mon Sep 17 00:00:00 2001 From: randoman <738b86bb93c44695854182cc459afcbb@lonestar.no> Date: Sat, 22 Aug 2020 19:40:20 +0200 Subject: [PATCH] Version 4.12.1 * MISC - Option to enable Harmony detour bridge (enabled by default for ReiPatcher setup if SRE is not supported) * MISC - Improved ForceUIResizing implementation * MISC - Some performance improvements during text component compatibility checks * BUG FIX - Disabled hooking of SpriteRenderer unless the hooking config is enabled * BUG FIX - Fixed PapagoTranslate API - Thanks to hype5 on Github --- CHANGELOG.md | 9 +- README.md | 3 +- .../PapagoTranslate/PapagoTranslate.cs | 13 +- src/XUnity.AutoTranslator.Patcher/Patcher.cs | 2 +- .../AutoTranslatorPlugin.cs | 2 + ...nity.AutoTranslator.Plugin.BepIn-5x.csproj | 2 +- .../AutoTranslationPlugin.cs | 139 +++++++++++++----- .../Configuration/Settings.cs | 4 +- .../Constants/PluginData.cs | 2 +- .../DefaultPluginEnvironment.cs | 5 +- .../Extensions/GameObjectExtensions.cs | 1 - .../Extensions/TextComponentExtensions.cs | 52 +------ .../Hooks/FairyGUIHooks.cs | 2 - .../Hooks/NGUIHooks.cs | 2 - .../Hooks/TextMeshProHooks.cs | 11 -- .../Hooks/UGUIHooks.cs | 2 - .../IPluginEnvironment.cs | 5 + .../PluginLoader.cs | 2 +- .../TextTranslationInfo.cs | 42 ++++++ .../XUnity.AutoTranslator.Plugin.Core.csproj | 2 +- .../AutoTranslatorPlugin.cs | 2 + .../XUnity.AutoTranslator.Plugin.IPA.csproj | 2 +- .../AutoTranslatorPlugin.cs | 2 + ...AutoTranslator.Plugin.UnityInjector.csproj | 2 +- .../XUnity.AutoTranslator.Setup.csproj | 2 +- 25 files changed, 192 insertions(+), 120 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 01107a4e..51374727 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,11 @@ -### 4.12.0 +### 4.12.1 + * MISC - Option to enable Harmony detour bridge (enabled by default for ReiPatcher setup if SRE is not supported) + * MISC - Improved ForceUIResizing implementation + * MISC - Some performance improvements during text component compatibility checks + * BUG FIX - Disabled hooking of SpriteRenderer unless the hooking config is enabled + * BUG FIX - Fixed PapagoTranslate API - Thanks to hype5 on Github + +### 4.12.0 * FEATURE - Specialized plugin translation support. Can now read text translation files that are only used for specific plugins * FEATURE - Proper IMGUI support in Unity 2018 and 2019+ * MISC - Changed guidance on IMGUI redistribution diff --git a/README.md b/README.md index 6450f637..b64c4982 100644 --- a/README.md +++ b/README.md @@ -283,7 +283,6 @@ TextGetterCompatibilityMode=False ;Indicates whether or not to enable "Text Gett GameLogTextPaths= ;Indicates specific paths for game objects that the game uses as "log components", where it continuously appends or prepends text to. Requires expert knowledge to setup. This is a list seperated by ';'. RomajiPostProcessing=ReplaceMacronWithCircumflex;RemoveApostrophes ;Indicates what type of post processing to do on 'translated' romaji texts. This can be important in certain games because the font used does not support various diacritics properly. This is a list seperated by ';'. Possible values: ["RemoveAllDiacritics", "ReplaceMacronWithCircumflex", "RemoveApostrophes"] TranslationPostProcessing=ReplaceMacronWithCircumflex ;Indicates what type of post processing to do on translated texts (not romaji). Possible values: ["RemoveAllDiacritics", "ReplaceMacronWithCircumflex", "RemoveApostrophes", "ReplaceWideCharacters"] -ForceMonoModHooks=False ;Indicates that the plugin must use MonoMod hooks instead of harmony hooks CacheRegexLookups=False ;Indicates whether or not results of regex lookups should be output to the specified OutputFile CacheWhitespaceDifferences=False ;Indicates whether or not whitespace differences should be output to the specified OutputFile CacheRegexPatternResults=False ;Indicates whether or not the complete result of regex-splitted translations should be output to the specified OutputFile @@ -298,6 +297,8 @@ MaxTextParserRecursion=1 ;Indicates how many levels of recursion are all HtmlEntityPreprocessing=True ;Will preprocess and decode html entities before they are send for translation. Some translators will fail when html entities are sent. HandleRichText=True ;Will enable automated handling of rich text (text with markup) EnableTranslationHelper=False ;Indicates if translator-related helpful log messages should be enabled. May be useful when tranlating based on redirected resources +ForceMonoModHooks=False ;Indicates that the plugin must use MonoMod hooks instead of harmony hooks +InitializeHarmonyDetourBridge=False ;Indicates the plugin should initial harmony detour bridge which allows harmony hooks to work in an environment where System.Reflection.Emit does not exist (usually such settings are handled by plugin managers, so don't use when using a plugin manager) [Texture] TextureDirectory=Translation\{Lang}\Texture ;Directory to dump textures to, and root of directories to load images from. Can use placeholder: {GameExeName}, {Lang} diff --git a/src/Translators/PapagoTranslate/PapagoTranslate.cs b/src/Translators/PapagoTranslate/PapagoTranslate.cs index cf7cfb84..3d7e4ec1 100644 --- a/src/Translators/PapagoTranslate/PapagoTranslate.cs +++ b/src/Translators/PapagoTranslate/PapagoTranslate.cs @@ -28,9 +28,8 @@ public class PapagoTranslate : HttpEndpoint private static readonly string FormUrlEncodedTemplate = "honorific=false&source={0}&target={1}&text={2}"; private static readonly Random RandomNumbers = new Random(); private static readonly Guid UUID = Guid.NewGuid(); - - private static readonly Regex patternSource = new Regex( @"/vendors~main[^""]+", RegexOptions.Compiled | RegexOptions.Singleline ); - private static readonly Regex patternVersion = new Regex( @"v\d\.\d\.\d_[^""]+", RegexOptions.Compiled | RegexOptions.Singleline ); + private static readonly Regex PatternSource = new Regex( @"/vendors~main[^""]+", RegexOptions.Singleline ); + private static readonly Regex PatternVersion = new Regex( @"v\d\.\d\.\d_[^""]+", RegexOptions.Singleline ); private string _version; // for hmac key private bool _isSMT; @@ -66,7 +65,9 @@ public override void Initialize( IInitializationContext context ) _isSMT = SMTLanguages.Contains( fixedSourceLanguage ) || SMTLanguages.Contains( fixedDestinationLanguage ); - if( !SupportedLanguages.Contains( fixedDestinationLanguage ) ) throw new EndpointInitializationException( $"The language '{context.DestinationLanguage}' is not supported by Papago Translate." ); + if( !SupportedLanguages.Contains( fixedDestinationLanguage ) ) + throw new EndpointInitializationException( $"The language '{context.DestinationLanguage}' is not supported by Papago Translate." ); + if( _isSMT ) { // SMT can only be translated into English @@ -170,7 +171,7 @@ private IEnumerator SetupVersion() var iterator = response.GetSupportedEnumerator(); while( iterator.MoveNext() ) yield return iterator.Current; - var match = patternSource.Match( response.Data ); + var match = PatternSource.Match( response.Data ); if( !match.Success ) { XuaLogger.AutoTranslator.Warn( "Could not parse papago page" ); @@ -187,7 +188,7 @@ private IEnumerator SetupVersion() var iterator = response.GetSupportedEnumerator(); while( iterator.MoveNext() ) yield return iterator.Current; - var match = patternVersion.Match( response.Data ); + var match = PatternVersion.Match( response.Data ); if( !match.Success ) { XuaLogger.AutoTranslator.Warn( "Could not parse papago version" ); diff --git a/src/XUnity.AutoTranslator.Patcher/Patcher.cs b/src/XUnity.AutoTranslator.Patcher/Patcher.cs index adab8ecc..e002c6f7 100644 --- a/src/XUnity.AutoTranslator.Patcher/Patcher.cs +++ b/src/XUnity.AutoTranslator.Patcher/Patcher.cs @@ -29,7 +29,7 @@ public override string Version { get { - return "4.12.0"; + return "4.12.1"; } } diff --git a/src/XUnity.AutoTranslator.Plugin.BepIn-5x/AutoTranslatorPlugin.cs b/src/XUnity.AutoTranslator.Plugin.BepIn-5x/AutoTranslatorPlugin.cs index 1e1d634e..c75a7399 100644 --- a/src/XUnity.AutoTranslator.Plugin.BepIn-5x/AutoTranslatorPlugin.cs +++ b/src/XUnity.AutoTranslator.Plugin.BepIn-5x/AutoTranslatorPlugin.cs @@ -38,6 +38,8 @@ public IniFile Preferences public string TranslationPath { get; } + public bool AllowDefaultInitializeHarmonyDetourBridge => false; + public IniFile ReloadConfig() { if( !File.Exists( _configPath ) ) diff --git a/src/XUnity.AutoTranslator.Plugin.BepIn-5x/XUnity.AutoTranslator.Plugin.BepIn-5x.csproj b/src/XUnity.AutoTranslator.Plugin.BepIn-5x/XUnity.AutoTranslator.Plugin.BepIn-5x.csproj index c4efeef2..9cc704bb 100644 --- a/src/XUnity.AutoTranslator.Plugin.BepIn-5x/XUnity.AutoTranslator.Plugin.BepIn-5x.csproj +++ b/src/XUnity.AutoTranslator.Plugin.BepIn-5x/XUnity.AutoTranslator.Plugin.BepIn-5x.csproj @@ -2,7 +2,7 @@ net35 - 4.12.0 + 4.12.1 diff --git a/src/XUnity.AutoTranslator.Plugin.Core/AutoTranslationPlugin.cs b/src/XUnity.AutoTranslator.Plugin.Core/AutoTranslationPlugin.cs index b1435043..03e7bd9c 100644 --- a/src/XUnity.AutoTranslator.Plugin.Core/AutoTranslationPlugin.cs +++ b/src/XUnity.AutoTranslator.Plugin.Core/AutoTranslationPlugin.cs @@ -35,6 +35,7 @@ using XUnity.ResourceRedirector; using XUnity.Common.Extensions; using XUnity.AutoTranslator.Plugin.Core.UIResize; +using MonoMod.RuntimeDetour; namespace XUnity.AutoTranslator.Plugin.Core { @@ -48,6 +49,8 @@ public class AutoTranslationPlugin : MonoBehaviour, IInternalTranslator, ITransl /// internal static AutoTranslationPlugin Current; + private static bool _hasResizedCurrentComponentDuringDiscovery; + internal XuaWindow MainWindow; internal TranslationAggregatorWindow TranslationAggregatorWindow; internal TranslationAggregatorOptionsWindow TranslationAggregatorOptionsWindow; @@ -108,6 +111,8 @@ public void Initialize() // Setup console, if enabled DebugConsole.Enable(); + InitializeHarmonyDetourBridge(); + InitializeTextTranslationCaches(); // Setup hooks @@ -146,6 +151,26 @@ public void Initialize() XuaLogger.AutoTranslator.Info( $"Loaded XUnity.AutoTranslator into Unity [{Application.unityVersion}] game." ); } + private static void InitializeHarmonyDetourBridge() + { + try + { + if( Settings.InitializeHarmonyDetourBridge ) + { + InitializeHarmonyDetourBridgeSafe(); + } + } + catch( Exception e ) + { + XuaLogger.AutoTranslator.Error( e, "An error occurred while initializing harmony detour bridge." ); + } + } + + private static void InitializeHarmonyDetourBridgeSafe() + { + HarmonyDetourBridge.Init(); + } + private void InitializeTextTranslationCaches() { try @@ -566,15 +591,28 @@ internal string Hook_TextChanged_WithResult( object ui, string text, bool onEnab string result = null; if( _textHooksEnabled && !_temporarilyDisabled ) { - var info = ui.GetOrCreateTextTranslationInfo(); - if( onEnable && info != null && CallOrigin.TextCache != null ) + try { - info.TextCache = CallOrigin.TextCache; - } + var info = ui.GetOrCreateTextTranslationInfo(); + var isComponentActive = DiscoverComponent( ui, info ); - CallOrigin.ExpectsTextToBeReturned = true; + if( onEnable && info != null && CallOrigin.TextCache != null ) + { + info.TextCache = CallOrigin.TextCache; + } - result = TranslateOrQueueWebJob( ui, text, false, info ); + CallOrigin.ExpectsTextToBeReturned = true; + + result = TranslateOrQueueWebJob( ui, text, isComponentActive, info ); + } + catch( Exception e ) + { + XuaLogger.AutoTranslator.Warn( e, "An unexpected error occurred." ); + } + finally + { + _hasResizedCurrentComponentDuringDiscovery = false; + } } if( onEnable ) @@ -593,13 +631,26 @@ internal void Hook_TextChanged( object ui, bool onEnable ) { if( _textHooksEnabled && !_temporarilyDisabled ) { - var info = ui.GetOrCreateTextTranslationInfo(); - if( onEnable && info != null && CallOrigin.TextCache != null ) + try { - info.TextCache = CallOrigin.TextCache; - } + var info = ui.GetOrCreateTextTranslationInfo(); + var isComponentActive = DiscoverComponent( ui, info ); - TranslateOrQueueWebJob( ui, null, false, info ); + if( onEnable && info != null && CallOrigin.TextCache != null ) + { + info.TextCache = CallOrigin.TextCache; + } + + TranslateOrQueueWebJob( ui, null, isComponentActive, info ); + } + catch( Exception e ) + { + XuaLogger.AutoTranslator.Warn( e, "An unexpected error occurred." ); + } + finally + { + _hasResizedCurrentComponentDuringDiscovery = false; + } } if( onEnable ) @@ -629,41 +680,41 @@ internal void Hook_ImageChanged( ref Texture2D texture, bool isPrefixHooked ) HandleImage( null, ref texture, isPrefixHooked ); } - internal void Hook_HandleComponent( object ui ) + private bool DiscoverComponent( object ui, TextTranslationInfo info ) { + if( info == null ) return true; + try { - if( _hasValidOverrideFont ) + if( ( _hasValidOverrideFont || Settings.ForceUIResizing ) && ui.IsComponentActive() ) { - var info = ui.GetOrCreateTextTranslationInfo(); - if( _hasOverridenFont ) + if( _hasValidOverrideFont ) { - info?.ChangeFont( ui ); - } - else - { - info?.UnchangeFont( ui ); + if( _hasOverridenFont ) + { + info.ChangeFont( ui ); + } + else + { + info.UnchangeFont( ui ); + } } - } - if( Settings.ForceUIResizing ) - { - var info = ui.GetOrCreateTextTranslationInfo(); - if( info?.IsCurrentlySettingText == false ) + if( Settings.ForceUIResizing ) { - // force UI resizing is highly problematic for NGUI because text should somehow - // be set after changing "resize" properties... brilliant stuff - if( ui.GetType() != ClrTypes.UILabel ) - { - info?.ResizeUI( ui, ResizeCache ); - } + info.ResizeUI( ui, ResizeCache ); + _hasResizedCurrentComponentDuringDiscovery = true; } + + return true; } } catch( Exception e ) { - XuaLogger.AutoTranslator.Error( e, "An error occurred while handling the UI resize/font hooks." ); + XuaLogger.AutoTranslator.Warn( e, "An error occurred while handling the UI discovery." ); } + + return false; } private void CheckSpriteRenderer( object ui ) @@ -721,15 +772,15 @@ private void SetText( object ui, string text, bool isTranslated, string original } } - if( info != null && Settings.EnableUIResizing || Settings.ForceUIResizing ) + if( !_hasResizedCurrentComponentDuringDiscovery && info != null && ( Settings.EnableUIResizing || Settings.ForceUIResizing ) ) { if( isTranslated || Settings.ForceUIResizing ) { - info?.ResizeUI( ui, ResizeCache ); + info.ResizeUI( ui, ResizeCache ); } else { - info?.UnresizeUI( ui ); + info.UnresizeUI( ui ); } } @@ -1143,10 +1194,15 @@ private string TranslateImmediate( object ui, string text, TextTranslationInfo i return null; } - info?.Reset( originalText ); + bool shouldIgnore = false; + if( info != null ) + { + info.Reset( originalText ); + shouldIgnore = info.ShouldIgnore; + } var scope = TranslationScopeProvider.GetScope( ui ); - if( !text.IsNullOrWhiteSpace() && tc.IsTranslatable( text, false, scope ) && ui.ShouldTranslateTextComponent( ignoreComponentState ) && !IsCurrentlySetting( info ) ) + if( !shouldIgnore && !text.IsNullOrWhiteSpace() && tc.IsTranslatable( text, false, scope ) && ( ignoreComponentState || ui.IsComponentActive() ) && !IsCurrentlySetting( info ) ) { //var textKey = new TranslationKey( ui, text, !ui.SupportsStabilization(), false ); var isSpammer = ui.IsSpammingComponent(); @@ -1620,7 +1676,12 @@ private string TranslateOrQueueWebJobImmediate( return null; } - info?.Reset( originalText ); + bool shouldIgnore = false; + if( info != null ) + { + info.Reset( originalText ); + shouldIgnore = info.ShouldIgnore; + } if( scope == TranslationScopes.None && context == null ) { @@ -1628,7 +1689,7 @@ private string TranslateOrQueueWebJobImmediate( } // Ensure that we actually want to translate this text and its owning UI element. - if( !text.IsNullOrWhiteSpace() && tc.IsTranslatable( text, false, scope ) && ui.ShouldTranslateTextComponent( ignoreComponentState ) && !IsCurrentlySetting( info ) ) + if( !shouldIgnore && !text.IsNullOrWhiteSpace() && tc.IsTranslatable( text, false, scope ) && ( ignoreComponentState || ui.IsComponentActive() ) && !IsCurrentlySetting( info ) ) { var isSpammer = ui.IsSpammingComponent(); if( isSpammer && !IsBelowMaxLength( text ) ) return null; // avoid templating long strings every frame for IMGUI, important! diff --git a/src/XUnity.AutoTranslator.Plugin.Core/Configuration/Settings.cs b/src/XUnity.AutoTranslator.Plugin.Core/Configuration/Settings.cs index 4ed3520d..63e0f953 100644 --- a/src/XUnity.AutoTranslator.Plugin.Core/Configuration/Settings.cs +++ b/src/XUnity.AutoTranslator.Plugin.Core/Configuration/Settings.cs @@ -84,6 +84,7 @@ internal static class Settings public static bool EnableTextMeshPro; public static bool EnableTextMesh; public static bool EnableFairyGUI; + public static bool InitializeHarmonyDetourBridge; public static bool IgnoreWhitespaceInDialogue; public static bool IgnoreWhitespaceInNGUI; public static int MinDialogueChars; @@ -207,7 +208,6 @@ public static void Configure() GameLogTextPaths.RemoveWhere( x => !x.StartsWith( "/" ) ); // clean up to ensure no 'empty' entries RomajiPostProcessing = PluginEnvironment.Current.Preferences.GetOrDefault( "Behaviour", "RomajiPostProcessing", TextPostProcessing.ReplaceMacronWithCircumflex | TextPostProcessing.RemoveApostrophes ); TranslationPostProcessing = PluginEnvironment.Current.Preferences.GetOrDefault( "Behaviour", "TranslationPostProcessing", TextPostProcessing.ReplaceMacronWithCircumflex ); - ForceMonoModHooks = PluginEnvironment.Current.Preferences.GetOrDefault( "Behaviour", "ForceMonoModHooks", false ); CacheRegexPatternResults = PluginEnvironment.Current.Preferences.GetOrDefault( "Behaviour", "CacheRegexPatternResults", false ); CacheRegexLookups = PluginEnvironment.Current.Preferences.GetOrDefault( "Behaviour", "CacheRegexLookups", false ); CacheWhitespaceDifferences = PluginEnvironment.Current.Preferences.GetOrDefault( "Behaviour", "CacheWhitespaceDifferences", false ); @@ -227,6 +227,8 @@ public static void Configure() HtmlEntityPreprocessing = PluginEnvironment.Current.Preferences.GetOrDefault( "Behaviour", "HtmlEntityPreprocessing", true ); HandleRichText = PluginEnvironment.Current.Preferences.GetOrDefault( "Behaviour", "HandleRichText", true ); EnableTranslationHelper = PluginEnvironment.Current.Preferences.GetOrDefault( "Behaviour", "EnableTranslationHelper", false ); + ForceMonoModHooks = PluginEnvironment.Current.Preferences.GetOrDefault( "Behaviour", "ForceMonoModHooks", false ); + InitializeHarmonyDetourBridge = PluginEnvironment.Current.Preferences.GetOrDefault( "Behaviour", "InitializeHarmonyDetourBridge", !Features.SupportsReflectionEmit && PluginEnvironment.Current.AllowDefaultInitializeHarmonyDetourBridge ); TextureDirectory = PluginEnvironment.Current.Preferences.GetOrDefault( "Texture", "TextureDirectory", Path.Combine( "Translation", Path.Combine( "{Lang}", "Texture" ) ) ); diff --git a/src/XUnity.AutoTranslator.Plugin.Core/Constants/PluginData.cs b/src/XUnity.AutoTranslator.Plugin.Core/Constants/PluginData.cs index 66d6ae63..4e33b84a 100644 --- a/src/XUnity.AutoTranslator.Plugin.Core/Constants/PluginData.cs +++ b/src/XUnity.AutoTranslator.Plugin.Core/Constants/PluginData.cs @@ -23,6 +23,6 @@ public static class PluginData /// /// Gets the version of the plugin. /// - public const string Version = "4.12.0"; + public const string Version = "4.12.1"; } } diff --git a/src/XUnity.AutoTranslator.Plugin.Core/DefaultPluginEnvironment.cs b/src/XUnity.AutoTranslator.Plugin.Core/DefaultPluginEnvironment.cs index d93ef740..7a9a7f3c 100644 --- a/src/XUnity.AutoTranslator.Plugin.Core/DefaultPluginEnvironment.cs +++ b/src/XUnity.AutoTranslator.Plugin.Core/DefaultPluginEnvironment.cs @@ -14,10 +14,11 @@ internal class DefaultPluginEnvironment : IPluginEnvironment private string _configPath; private string _dataFolder; - public DefaultPluginEnvironment() + public DefaultPluginEnvironment( bool allowDefaultInitializeHarmonyDetourBridge ) { _dataFolder = Path.Combine( Paths.GameRoot, "AutoTranslator" ); _configPath = Path.Combine( _dataFolder, "Config.ini" ); + AllowDefaultInitializeHarmonyDetourBridge = allowDefaultInitializeHarmonyDetourBridge; } public IniFile Preferences @@ -32,6 +33,8 @@ public IniFile Preferences public string ConfigPath => _dataFolder; + public bool AllowDefaultInitializeHarmonyDetourBridge { get; } + public void SaveConfig() { _file.Save( _configPath ); diff --git a/src/XUnity.AutoTranslator.Plugin.Core/Extensions/GameObjectExtensions.cs b/src/XUnity.AutoTranslator.Plugin.Core/Extensions/GameObjectExtensions.cs index 24585664..9901c3f0 100644 --- a/src/XUnity.AutoTranslator.Plugin.Core/Extensions/GameObjectExtensions.cs +++ b/src/XUnity.AutoTranslator.Plugin.Core/Extensions/GameObjectExtensions.cs @@ -77,7 +77,6 @@ public static string[] GetPathSegments( this GameObject obj ) } var result = new string[ i ]; - StringBuilder path = new StringBuilder(); while( --i >= 0 ) { result[ j++ ] = _objects[ i ].name; diff --git a/src/XUnity.AutoTranslator.Plugin.Core/Extensions/TextComponentExtensions.cs b/src/XUnity.AutoTranslator.Plugin.Core/Extensions/TextComponentExtensions.cs index d986e0a8..47f4c617 100644 --- a/src/XUnity.AutoTranslator.Plugin.Core/Extensions/TextComponentExtensions.cs +++ b/src/XUnity.AutoTranslator.Plugin.Core/Extensions/TextComponentExtensions.cs @@ -47,61 +47,23 @@ private static ITextComponentManipulator GetTextManipulator( object ui ) return manipulator; } - public static bool ShouldTranslateTextComponent( this object ui, bool ignoreComponentState ) + public static bool IsComponentActive( this object ui ) { - var component = ui as Component; - if( component != null ) + if( ui is Component component ) { - // dummy check var go = component.gameObject; - var ignore = go.HasIgnoredName(); - if( ignore ) - { - return false; - } - - if( !ignoreComponentState ) + if( go ) { - var behaviour = component as Behaviour; - if( !go.activeInHierarchy || behaviour?.enabled == false ) // legacy "isActiveAndEnabled" + if( component is Behaviour be ) { - return false; + return go.activeInHierarchy && be.enabled; } - } - - var inputField = go.GetFirstComponentInSelfOrAncestor( ClrTypes.InputField ); - if( inputField != null ) - { - if( ClrTypes.InputField_Properties.Placeholder != null ) + else { - var placeholder = ClrTypes.InputField_Properties.Placeholder.Get( inputField ); - return ReferenceEquals( placeholder, ui ); + return go.activeInHierarchy; } } - inputField = go.GetFirstComponentInSelfOrAncestor( ClrTypes.TMP_InputField ); - if( inputField != null ) - { - if( ClrTypes.TMP_InputField_Properties.Placeholder != null ) - { - var placeholder = ClrTypes.TMP_InputField_Properties.Placeholder.Get( inputField ); - return ReferenceEquals( placeholder, ui ); - } - } - - inputField = go.GetFirstComponentInSelfOrAncestor( ClrTypes.UIInput ); - - return inputField == null; - } - - return true; - } - - public static bool IsComponentActive( this object ui ) - { - if( ui is Component component ) - { - return component.gameObject?.activeSelf ?? false; } return true; } diff --git a/src/XUnity.AutoTranslator.Plugin.Core/Hooks/FairyGUIHooks.cs b/src/XUnity.AutoTranslator.Plugin.Core/Hooks/FairyGUIHooks.cs index 6a27356a..4116f620 100644 --- a/src/XUnity.AutoTranslator.Plugin.Core/Hooks/FairyGUIHooks.cs +++ b/src/XUnity.AutoTranslator.Plugin.Core/Hooks/FairyGUIHooks.cs @@ -34,7 +34,6 @@ static MethodBase TargetMethod( object instance ) static void Postfix( object __instance ) { AutoTranslationPlugin.Current.Hook_TextChanged( __instance, false ); - AutoTranslationPlugin.Current.Hook_HandleComponent( __instance ); } static Action _original; @@ -68,7 +67,6 @@ static MethodBase TargetMethod( object instance ) static void Postfix( object __instance ) { AutoTranslationPlugin.Current.Hook_TextChanged( __instance, false ); - AutoTranslationPlugin.Current.Hook_HandleComponent( __instance ); } static Action _original; diff --git a/src/XUnity.AutoTranslator.Plugin.Core/Hooks/NGUIHooks.cs b/src/XUnity.AutoTranslator.Plugin.Core/Hooks/NGUIHooks.cs index f4497e60..d71180aa 100644 --- a/src/XUnity.AutoTranslator.Plugin.Core/Hooks/NGUIHooks.cs +++ b/src/XUnity.AutoTranslator.Plugin.Core/Hooks/NGUIHooks.cs @@ -38,7 +38,6 @@ static MethodBase TargetMethod( object instance ) public static void Postfix( object __instance ) { AutoTranslationPlugin.Current.Hook_TextChanged( __instance, false ); - AutoTranslationPlugin.Current.Hook_HandleComponent( __instance ); } static Action _original; @@ -74,7 +73,6 @@ public static void Postfix( object __instance ) if( ClrTypes.UILabel.IsAssignableFrom( __instance.GetType() ) ) { AutoTranslationPlugin.Current.Hook_TextChanged( __instance, true ); - AutoTranslationPlugin.Current.Hook_HandleComponent( __instance ); } } diff --git a/src/XUnity.AutoTranslator.Plugin.Core/Hooks/TextMeshProHooks.cs b/src/XUnity.AutoTranslator.Plugin.Core/Hooks/TextMeshProHooks.cs index fbaeb302..13faa96d 100644 --- a/src/XUnity.AutoTranslator.Plugin.Core/Hooks/TextMeshProHooks.cs +++ b/src/XUnity.AutoTranslator.Plugin.Core/Hooks/TextMeshProHooks.cs @@ -81,7 +81,6 @@ static MethodBase TargetMethod( object instance ) static void Postfix( object __instance ) { AutoTranslationPlugin.Current.Hook_TextChanged( __instance, true ); - AutoTranslationPlugin.Current.Hook_HandleComponent( __instance ); } static Action _original; @@ -115,7 +114,6 @@ static MethodBase TargetMethod( object instance ) static void Postfix( object __instance ) { AutoTranslationPlugin.Current.Hook_TextChanged( __instance, true ); - AutoTranslationPlugin.Current.Hook_HandleComponent( __instance ); } static Action _original; @@ -149,7 +147,6 @@ static MethodBase TargetMethod( object instance ) static void Postfix( object __instance ) { AutoTranslationPlugin.Current.Hook_TextChanged( __instance, true ); - AutoTranslationPlugin.Current.Hook_HandleComponent( __instance ); } static Action _original; @@ -183,7 +180,6 @@ static MethodBase TargetMethod( object instance ) static void Postfix( object __instance ) { AutoTranslationPlugin.Current.Hook_TextChanged( __instance, true ); - AutoTranslationPlugin.Current.Hook_HandleComponent( __instance ); } static Action _original; @@ -217,7 +213,6 @@ static MethodBase TargetMethod( object instance ) static void Postfix( object __instance ) { AutoTranslationPlugin.Current.Hook_TextChanged( __instance, false ); - AutoTranslationPlugin.Current.Hook_HandleComponent( __instance ); } static Action _original; @@ -251,7 +246,6 @@ static MethodBase TargetMethod( object instance ) static void Postfix( object __instance ) { AutoTranslationPlugin.Current.Hook_TextChanged( __instance, false ); - AutoTranslationPlugin.Current.Hook_HandleComponent( __instance ); } static Action _original; @@ -285,7 +279,6 @@ static MethodBase TargetMethod( object instance ) static void Postfix( object __instance ) { AutoTranslationPlugin.Current.Hook_TextChanged( __instance, false ); - AutoTranslationPlugin.Current.Hook_HandleComponent( __instance ); } static Action _original; @@ -321,7 +314,6 @@ static MethodBase TargetMethod( object instance ) static void Postfix( object __instance ) { AutoTranslationPlugin.Current.Hook_TextChanged( __instance, false ); - AutoTranslationPlugin.Current.Hook_HandleComponent( __instance ); } static OriginalMethod _original; @@ -355,7 +347,6 @@ static MethodBase TargetMethod( object instance ) static void Postfix( object __instance ) { AutoTranslationPlugin.Current.Hook_TextChanged( __instance, false ); - AutoTranslationPlugin.Current.Hook_HandleComponent( __instance ); } static Action _original; @@ -389,7 +380,6 @@ static MethodBase TargetMethod( object instance ) static void Postfix( object __instance ) { AutoTranslationPlugin.Current.Hook_TextChanged( __instance, false ); - AutoTranslationPlugin.Current.Hook_HandleComponent( __instance ); } static Action _original; @@ -423,7 +413,6 @@ static MethodBase TargetMethod( object instance ) static void Postfix( object __instance ) { AutoTranslationPlugin.Current.Hook_TextChanged( __instance, false ); - AutoTranslationPlugin.Current.Hook_HandleComponent( __instance ); } static Action _original; diff --git a/src/XUnity.AutoTranslator.Plugin.Core/Hooks/UGUIHooks.cs b/src/XUnity.AutoTranslator.Plugin.Core/Hooks/UGUIHooks.cs index 72597d70..a842b0b3 100644 --- a/src/XUnity.AutoTranslator.Plugin.Core/Hooks/UGUIHooks.cs +++ b/src/XUnity.AutoTranslator.Plugin.Core/Hooks/UGUIHooks.cs @@ -37,7 +37,6 @@ static MethodBase TargetMethod( object instance ) static void Postfix( object __instance ) { AutoTranslationPlugin.Current.Hook_TextChanged( __instance, false ); - AutoTranslationPlugin.Current.Hook_HandleComponent( __instance ); } static Action _original; @@ -71,7 +70,6 @@ static MethodBase TargetMethod( object instance ) static void Postfix( object __instance ) { AutoTranslationPlugin.Current.Hook_TextChanged( __instance, true ); - AutoTranslationPlugin.Current.Hook_HandleComponent( __instance ); } static Action _original; diff --git a/src/XUnity.AutoTranslator.Plugin.Core/IPluginEnvironment.cs b/src/XUnity.AutoTranslator.Plugin.Core/IPluginEnvironment.cs index e23dbfaa..9c4518c2 100644 --- a/src/XUnity.AutoTranslator.Plugin.Core/IPluginEnvironment.cs +++ b/src/XUnity.AutoTranslator.Plugin.Core/IPluginEnvironment.cs @@ -33,5 +33,10 @@ public interface IPluginEnvironment /// Saves the preferences file. /// void SaveConfig(); + + /// + /// Gets a bool indicating whether or not to allow the default value of InitializeHarmonyDetourBridge to be true. + /// + bool AllowDefaultInitializeHarmonyDetourBridge { get; } } } diff --git a/src/XUnity.AutoTranslator.Plugin.Core/PluginLoader.cs b/src/XUnity.AutoTranslator.Plugin.Core/PluginLoader.cs index 476a1f15..f5cd973c 100644 --- a/src/XUnity.AutoTranslator.Plugin.Core/PluginLoader.cs +++ b/src/XUnity.AutoTranslator.Plugin.Core/PluginLoader.cs @@ -40,7 +40,7 @@ public static void LoadWithConfig( IPluginEnvironment config ) /// public static void Load() { - LoadWithConfig( new DefaultPluginEnvironment() ); + LoadWithConfig( new DefaultPluginEnvironment( true ) ); } /// diff --git a/src/XUnity.AutoTranslator.Plugin.Core/TextTranslationInfo.cs b/src/XUnity.AutoTranslator.Plugin.Core/TextTranslationInfo.cs index a7f270c1..6a332729 100644 --- a/src/XUnity.AutoTranslator.Plugin.Core/TextTranslationInfo.cs +++ b/src/XUnity.AutoTranslator.Plugin.Core/TextTranslationInfo.cs @@ -48,6 +48,7 @@ internal class TextTranslationInfo public string TranslatedText { get; set; } public bool IsTranslated { get; set; } public bool IsCurrentlySettingText { get; set; } // TODO: REMOVE; Why is this even here? + public bool ShouldIgnore { get; set; } public bool IsStabilizingText { get; set; } public bool IsKnownTextComponent { get; set; } @@ -63,9 +64,50 @@ public void Initialize( object ui ) IsKnownTextComponent = ui.IsKnownTextType(); SupportsStabilization = ui.SupportsStabilization(); + ShouldIgnore = ShouldIgnoreTextComponent( ui ); } } + public bool ShouldIgnoreTextComponent( object ui ) + { + if( ui is Component component ) + { + // dummy check + var go = component.gameObject; + var ignore = go.HasIgnoredName(); + if( ignore ) + { + return true; + } + + var inputField = go.GetFirstComponentInSelfOrAncestor( ClrTypes.InputField ); + if( inputField != null ) + { + if( ClrTypes.InputField_Properties.Placeholder != null ) + { + var placeholder = ClrTypes.InputField_Properties.Placeholder.Get( inputField ); + return !ReferenceEquals( placeholder, ui ); + } + } + + inputField = go.GetFirstComponentInSelfOrAncestor( ClrTypes.TMP_InputField ); + if( inputField != null ) + { + if( ClrTypes.TMP_InputField_Properties.Placeholder != null ) + { + var placeholder = ClrTypes.TMP_InputField_Properties.Placeholder.Get( inputField ); + return !ReferenceEquals( placeholder, ui ); + } + } + + inputField = go.GetFirstComponentInSelfOrAncestor( ClrTypes.UIInput ); + + return inputField != null; + } + + return false; + } + public void ResetScrollIn( object graphic ) { if( !_hasCheckedTypeWriter ) diff --git a/src/XUnity.AutoTranslator.Plugin.Core/XUnity.AutoTranslator.Plugin.Core.csproj b/src/XUnity.AutoTranslator.Plugin.Core/XUnity.AutoTranslator.Plugin.Core.csproj index a4bc7dd9..1003f8ac 100644 --- a/src/XUnity.AutoTranslator.Plugin.Core/XUnity.AutoTranslator.Plugin.Core.csproj +++ b/src/XUnity.AutoTranslator.Plugin.Core/XUnity.AutoTranslator.Plugin.Core.csproj @@ -11,7 +11,7 @@ True True net35 - 4.12.0 + 4.12.1 latest diff --git a/src/XUnity.AutoTranslator.Plugin.IPA/AutoTranslatorPlugin.cs b/src/XUnity.AutoTranslator.Plugin.IPA/AutoTranslatorPlugin.cs index 17b1d792..7fc29858 100644 --- a/src/XUnity.AutoTranslator.Plugin.IPA/AutoTranslatorPlugin.cs +++ b/src/XUnity.AutoTranslator.Plugin.IPA/AutoTranslatorPlugin.cs @@ -36,6 +36,8 @@ public IniFile Preferences public string ConfigPath => _dataPath; + public bool AllowDefaultInitializeHarmonyDetourBridge => false; + public IniFile ReloadConfig() { if( !File.Exists( _configPath ) ) diff --git a/src/XUnity.AutoTranslator.Plugin.IPA/XUnity.AutoTranslator.Plugin.IPA.csproj b/src/XUnity.AutoTranslator.Plugin.IPA/XUnity.AutoTranslator.Plugin.IPA.csproj index a7c6eb13..f96c19b7 100644 --- a/src/XUnity.AutoTranslator.Plugin.IPA/XUnity.AutoTranslator.Plugin.IPA.csproj +++ b/src/XUnity.AutoTranslator.Plugin.IPA/XUnity.AutoTranslator.Plugin.IPA.csproj @@ -2,7 +2,7 @@ net35 - 4.12.0 + 4.12.1 diff --git a/src/XUnity.AutoTranslator.Plugin.UnityInjector/AutoTranslatorPlugin.cs b/src/XUnity.AutoTranslator.Plugin.UnityInjector/AutoTranslatorPlugin.cs index 63cc59ad..c71cf751 100644 --- a/src/XUnity.AutoTranslator.Plugin.UnityInjector/AutoTranslatorPlugin.cs +++ b/src/XUnity.AutoTranslator.Plugin.UnityInjector/AutoTranslatorPlugin.cs @@ -18,6 +18,8 @@ public class AutoTranslatorPlugin : PluginBase, IPluginEnvironment public string ConfigPath => DataPath; + public bool AllowDefaultInitializeHarmonyDetourBridge => false; + void IPluginEnvironment.SaveConfig() { SaveConfig(); diff --git a/src/XUnity.AutoTranslator.Plugin.UnityInjector/XUnity.AutoTranslator.Plugin.UnityInjector.csproj b/src/XUnity.AutoTranslator.Plugin.UnityInjector/XUnity.AutoTranslator.Plugin.UnityInjector.csproj index 7c6fb4de..511034ed 100644 --- a/src/XUnity.AutoTranslator.Plugin.UnityInjector/XUnity.AutoTranslator.Plugin.UnityInjector.csproj +++ b/src/XUnity.AutoTranslator.Plugin.UnityInjector/XUnity.AutoTranslator.Plugin.UnityInjector.csproj @@ -2,7 +2,7 @@ net35 - 4.12.0 + 4.12.1 diff --git a/src/XUnity.AutoTranslator.Setup/XUnity.AutoTranslator.Setup.csproj b/src/XUnity.AutoTranslator.Setup/XUnity.AutoTranslator.Setup.csproj index 786f0729..327cc558 100644 --- a/src/XUnity.AutoTranslator.Setup/XUnity.AutoTranslator.Setup.csproj +++ b/src/XUnity.AutoTranslator.Setup/XUnity.AutoTranslator.Setup.csproj @@ -4,7 +4,7 @@ Exe net40 SetupReiPatcherAndAutoTranslator - 4.12.0 + 4.12.1 icon.ico