From 23209853eddaa00bf1cc856f644fd0d7172d452e Mon Sep 17 00:00:00 2001
From: gravydevsupreme <38829754+gravydevsupreme@users.noreply.github.com>
Date: Sat, 5 May 2018 01:56:56 +0200
Subject: [PATCH] disable IMGUI hooks
---
.../XUnity.AutoTranslator.Plugin.BepIn.csproj | 6 +-
.../AutoTranslationPlugin.cs | 81 +++++++++----------
.../Configuration/Settings.cs | 11 +--
.../Hooks/HooksSetup.cs | 2 +-
.../TranslationJob.cs | 13 ++-
.../TranslationKeys.cs | 28 +++++++
.../XUnity.AutoTranslator.Plugin.Core.csproj | 6 +-
.../XUnity.AutoTranslator.Plugin.IPA.csproj | 6 +-
8 files changed, 89 insertions(+), 64 deletions(-)
create mode 100644 src/XUnity.AutoTranslator.Plugin.Core/TranslationKeys.cs
diff --git a/src/XUnity.AutoTranslator.Plugin.BepIn/XUnity.AutoTranslator.Plugin.BepIn.csproj b/src/XUnity.AutoTranslator.Plugin.BepIn/XUnity.AutoTranslator.Plugin.BepIn.csproj
index 93a944f9..90ae8396 100644
--- a/src/XUnity.AutoTranslator.Plugin.BepIn/XUnity.AutoTranslator.Plugin.BepIn.csproj
+++ b/src/XUnity.AutoTranslator.Plugin.BepIn/XUnity.AutoTranslator.Plugin.BepIn.csproj
@@ -2,9 +2,9 @@
net35
- 2.4.0.0
- 2.4.0.0
- 2.4.0
+ 2.4.1.0
+ 2.4.1.0
+ 2.4.1
diff --git a/src/XUnity.AutoTranslator.Plugin.Core/AutoTranslationPlugin.cs b/src/XUnity.AutoTranslator.Plugin.Core/AutoTranslationPlugin.cs
index f853a335..b6cf039b 100644
--- a/src/XUnity.AutoTranslator.Plugin.Core/AutoTranslationPlugin.cs
+++ b/src/XUnity.AutoTranslator.Plugin.Core/AutoTranslationPlugin.cs
@@ -198,7 +198,8 @@ private void LoadTranslations()
if( !string.IsNullOrEmpty( key ) && !string.IsNullOrEmpty( value ) )
{
- AddTranslation( key, value );
+ var translationKey = new TranslationKeys( key );
+ AddTranslation( translationKey, value );
}
}
}
@@ -212,75 +213,68 @@ private void LoadTranslations()
}
}
- private TranslationJob GetOrCreateTranslationJobFor( string untranslatedText )
+ private TranslationJob GetOrCreateTranslationJobFor( TranslationKeys key )
{
- if( _unstartedJobs.TryGetValue( untranslatedText, out TranslationJob job ) )
+ if( _unstartedJobs.TryGetValue( key.ForcedRelevantKey, out TranslationJob job ) )
{
return job;
}
foreach( var completedJob in _completedJobs )
{
- if( completedJob.UntranslatedText == untranslatedText )
+ if( completedJob.Keys.ForcedRelevantKey == key.ForcedRelevantKey )
{
return completedJob;
}
}
- job = new TranslationJob( untranslatedText );
- _unstartedJobs.Add( untranslatedText, job );
+ job = new TranslationJob( key );
+ _unstartedJobs.Add( key.ForcedRelevantKey, job );
return job;
}
- private void AddTranslation( string key, string value )
+ private void AddTranslation( TranslationKeys key, string value )
{
- _translations[ key ] = value;
+ _translations[ key.OriginalKey ] = value;
_translatedTexts.Add( value );
- if( Settings.IgnoreWhitespaceInDialogue )
+ if( Settings.IgnoreWhitespaceInDialogue && key.IsDialogue )
{
- var newKey = key.ChangeToSingleLineForDialogue();
- _translations[ newKey ] = value;
+ _translations[ key.DialogueKey ] = value;
}
}
- private void QueueNewUntranslatedForClipboard( string key )
+ private void QueueNewUntranslatedForClipboard( TranslationKeys key )
{
if( Settings.CopyToClipboard )
{
- key = key.ChangeToSingleLineForDialogue();
- if( !_textsToCopyToClipboard.Contains( key ) )
+ if( !_textsToCopyToClipboard.Contains( key.ForcedRelevantKey ) )
{
- _textsToCopyToClipboard.Add( key );
- _textsToCopyToClipboardOrdered.Add( key );
+ _textsToCopyToClipboard.Add( key.ForcedRelevantKey );
+ _textsToCopyToClipboardOrdered.Add( key.ForcedRelevantKey );
_clipboardUpdated = Time.realtimeSinceStartup;
}
}
}
- private void QueueNewUntranslatedForDisk( string key )
+ private void QueueNewUntranslatedForDisk( TranslationKeys key )
{
- if( Settings.IgnoreWhitespaceInDialogue )
- {
- key = key.ChangeToSingleLineForDialogue();
- }
-
- _newUntranslated.Add( key );
+ _newUntranslated.Add( key.RelevantKey );
}
- private void QueueNewTranslationForDisk( string key, string value )
+ private void QueueNewTranslationForDisk( TranslationKeys key, string value )
{
lock( _writeToFileSync )
{
- _newTranslations[ key ] = value;
+ _newTranslations[ key.RelevantKey ] = value;
}
}
- private bool TryGetTranslation( string key, out string value )
+ private bool TryGetTranslation( TranslationKeys key, out string value )
{
- return _translations.TryGetValue( key, out value ) || ( Settings.IgnoreWhitespaceInDialogue && _translations.TryGetValue( key.RemoveWhitespace(), out value ) );
+ return _translations.TryGetValue( key.OriginalKey, out value ) || ( Settings.IgnoreWhitespaceInDialogue && _translations.TryGetValue( key.DialogueKey, out value ) );
}
private string Override_TextChanged( object ui, string text )
@@ -442,11 +436,13 @@ private string TranslateOrQueueWebJobImmediate( object ui, string text, Translat
{
info?.Reset( text );
+ var textKey = new TranslationKeys( text );
+
// if we already have translation loaded in our _translatios dictionary, simply load it and set text
string translation;
- if( TryGetTranslation( text, out translation ) )
+ if( TryGetTranslation( textKey, out translation ) )
{
- QueueNewUntranslatedForClipboard( text );
+ QueueNewUntranslatedForClipboard( textKey );
if( !string.IsNullOrEmpty( translation ) )
{
@@ -488,12 +484,14 @@ private string TranslateOrQueueWebJobImmediate( object ui, string text, Translat
if( !string.IsNullOrEmpty( stabilizedText ) && IsTranslatable( stabilizedText ) )
{
- QueueNewUntranslatedForClipboard( text );
+ var stabilizedTextKey = new TranslationKeys( stabilizedText );
+
+ QueueNewUntranslatedForClipboard( stabilizedTextKey );
info?.Reset( stabilizedText );
// once the text has stabilized, attempt to look it up
- if( TryGetTranslation( stabilizedText, out translation ) )
+ if( TryGetTranslation( stabilizedTextKey, out translation ) )
{
if( !string.IsNullOrEmpty( translation ) )
{
@@ -505,12 +503,12 @@ private string TranslateOrQueueWebJobImmediate( object ui, string text, Translat
// Lets try not to spam a service that might not be there...
if( AutoTranslateClient.IsConfigured && _consecutiveErrors < Settings.MaxErrors )
{
- var job = GetOrCreateTranslationJobFor( stabilizedText );
+ var job = GetOrCreateTranslationJobFor( stabilizedTextKey );
job.Components.Add( ui );
}
else
{
- QueueNewUntranslatedForDisk( stabilizedText );
+ QueueNewUntranslatedForDisk( stabilizedTextKey );
}
}
}
@@ -528,16 +526,16 @@ private string TranslateOrQueueWebJobImmediate( object ui, string text, Translat
{
_startedOperationsForNonStabilizableComponents.Add( text );
- QueueNewUntranslatedForClipboard( text );
+ QueueNewUntranslatedForClipboard( textKey );
// Lets try not to spam a service that might not be there...
if( AutoTranslateClient.IsConfigured && _consecutiveErrors < Settings.MaxErrors )
{
- GetOrCreateTranslationJobFor( text );
+ GetOrCreateTranslationJobFor( textKey );
}
else
{
- QueueNewUntranslatedForDisk( text );
+ QueueNewUntranslatedForDisk( textKey );
}
}
}
@@ -637,7 +635,7 @@ private void KickoffTranslations()
// lets see if the text should still be translated before kicking anything off
if( !job.AnyComponentsStillHasOriginalUntranslatedText() ) continue;
- StartCoroutine( AutoTranslateClient.TranslateByWWW( job.UntranslatedDialogueText, Settings.FromLanguage, Settings.Language, translatedText =>
+ StartCoroutine( AutoTranslateClient.TranslateByWWW( job.Keys.ForcedRelevantKey, Settings.FromLanguage, Settings.Language, translatedText =>
{
_consecutiveErrors = 0;
@@ -651,7 +649,7 @@ private void KickoffTranslations()
if( !string.IsNullOrEmpty( translatedText ) )
{
- QueueNewTranslationForDisk( Settings.IgnoreWhitespaceInDialogue ? job.UntranslatedDialogueText : job.UntranslatedText, translatedText );
+ QueueNewTranslationForDisk( job.Keys, translatedText );
_completedJobs.Add( job );
}
@@ -683,14 +681,14 @@ private void FinishTranslations()
{
// update the original text, but only if it has not been chaanged already for some reason (could be other translator plugin or game itself)
var text = component.GetText().Trim();
- if( text == job.UntranslatedText )
+ if( text == job.Keys.OriginalKey )
{
var info = component.GetTranslationInfo( false );
SetTranslatedText( component, job.TranslatedText, info );
}
}
- AddTranslation( job.UntranslatedText, job.TranslatedText );
+ AddTranslation( job.Keys, job.TranslatedText );
}
}
}
@@ -704,7 +702,8 @@ private void ReloadTranslations()
var info = kvp.Value as TranslationInfo;
if( info != null && !string.IsNullOrEmpty( info.OriginalText ) )
{
- if( TryGetTranslation( info.OriginalText, out string translatedText ) && !string.IsNullOrEmpty( translatedText ) )
+ var key = new TranslationKeys( info.OriginalText );
+ if( TryGetTranslation( key, out string translatedText ) && !string.IsNullOrEmpty( translatedText ) )
{
SetTranslatedText( kvp.Key, translatedText, info );
}
diff --git a/src/XUnity.AutoTranslator.Plugin.Core/Configuration/Settings.cs b/src/XUnity.AutoTranslator.Plugin.Core/Configuration/Settings.cs
index cd89450a..4ef355e6 100644
--- a/src/XUnity.AutoTranslator.Plugin.Core/Configuration/Settings.cs
+++ b/src/XUnity.AutoTranslator.Plugin.Core/Configuration/Settings.cs
@@ -25,7 +25,7 @@ public static class Settings
public static int MaxCharactersPerTranslation;
public static bool EnablePrintHierarchy;
public static string AutoTranslationsFilePath;
- public static bool EnableIMGUI;
+ public static bool EnableIMGUI = false;
public static bool EnableUGUI;
public static bool EnableNGUI;
public static bool EnableTextMeshPro;
@@ -36,7 +36,8 @@ public static class Settings
public static string BaiduAppId;
public static string BaiduAppSecret;
public static int ForceSplitTextAfterCharacters;
- public static bool CopyToClipboard;
+
+ public static bool CopyToClipboard = false;
public static int MaxClipboardCopyCharacters;
public static void Configure()
@@ -68,7 +69,7 @@ public static void Configure()
TranslationDirectory = Config.Current.Preferences[ "Files" ][ "Directory" ].GetOrDefault( @"Translation" );
OutputFile = Config.Current.Preferences[ "Files" ][ "OutputFile" ].GetOrDefault( @"Translation\_AutoGeneratedTranslations.{lang}.txt" );
- EnableIMGUI = Config.Current.Preferences[ "TextFrameworks" ][ "EnableIMGUI" ].GetOrDefault( true );
+ //EnableIMGUI = Config.Current.Preferences[ "TextFrameworks" ][ "EnableIMGUI" ].GetOrDefault( false );
EnableUGUI = Config.Current.Preferences[ "TextFrameworks" ][ "EnableUGUI" ].GetOrDefault( true );
EnableNGUI = Config.Current.Preferences[ "TextFrameworks" ][ "EnableNGUI" ].GetOrDefault( true );
EnableTextMeshPro = Config.Current.Preferences[ "TextFrameworks" ][ "EnableTextMeshPro" ].GetOrDefault( true );
@@ -79,8 +80,8 @@ public static void Configure()
IgnoreWhitespaceInDialogue = Config.Current.Preferences[ "Behaviour" ][ "IgnoreWhitespaceInDialogue" ].GetOrDefault( true );
MinDialogueChars = Config.Current.Preferences[ "Behaviour" ][ "MinDialogueChars" ].GetOrDefault( 20 );
ForceSplitTextAfterCharacters = Config.Current.Preferences[ "Behaviour" ][ "ForceSplitTextAfterCharacters" ].GetOrDefault( 0 );
- CopyToClipboard = Config.Current.Preferences[ "Behaviour" ][ "CopyToClipboard" ].GetOrDefault( false );
- MaxClipboardCopyCharacters = Config.Current.Preferences[ "Behaviour" ][ "MaxClipboardCopyCharacters" ].GetOrDefault( 450 );
+ //CopyToClipboard = Config.Current.Preferences[ "Behaviour" ][ "CopyToClipboard" ].GetOrDefault( false );
+ //MaxClipboardCopyCharacters = Config.Current.Preferences[ "Behaviour" ][ "MaxClipboardCopyCharacters" ].GetOrDefault( 450 );
BaiduAppId = Config.Current.Preferences[ "Baidu" ][ "BaiduAppId" ].GetOrDefault( "" );
BaiduAppSecret = Config.Current.Preferences[ "Baidu" ][ "BaiduAppSecret" ].GetOrDefault( "" );
diff --git a/src/XUnity.AutoTranslator.Plugin.Core/Hooks/HooksSetup.cs b/src/XUnity.AutoTranslator.Plugin.Core/Hooks/HooksSetup.cs
index 3ef6fe7d..d0956461 100644
--- a/src/XUnity.AutoTranslator.Plugin.Core/Hooks/HooksSetup.cs
+++ b/src/XUnity.AutoTranslator.Plugin.Core/Hooks/HooksSetup.cs
@@ -23,7 +23,7 @@ public static void InstallHooks( Func