Skip to content

Commit

Permalink
fix to TKK retrieval, fix to error message in relation to this
Browse files Browse the repository at this point in the history
  • Loading branch information
randoman committed Sep 22, 2018
1 parent 8f538c5 commit 7fa8103
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 25 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
### 2.15.0
### 2.15.1
* BUG FIX - Updated TKK retrieval logic. Improved error message if it cannot be retrieved.

### 2.15.0
* FEATURE - Manual hooking - press ALT + U. This will lookup all game objects and attempt translation immediately
* FEATURE - Capability for other plugins to tell the Auto Translator not to translate texts
* BUG FIX - Initialization hooking that will attempt to hook any game object that was missed during game initialization
Expand Down
2 changes: 1 addition & 1 deletion src/XUnity.AutoTranslator.Patcher/Patcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public override string Version
{
get
{
return "2.15.0";
return "2.15.1";
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net35</TargetFramework>
<Version>2.15.0</Version>
<Version>2.15.1</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ public static class PluginData

public const string Name = "XUnity Auto Translator";

public const string Version = "2.15.0";
public const string Version = "2.15.1";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class GoogleTranslateEndpoint : KnownHttpEndpoint
//protected static readonly ConstructorInfo WwwConstructor = Constants.Types.WWW?.GetConstructor( new[] { typeof( string ), typeof( byte[] ), typeof( Dictionary<string, string> ) } );
private static readonly string HttpsServicePointTemplateUrl = "https://translate.googleapis.com/translate_a/single?client=t&dt=t&sl={0}&tl={1}&ie=UTF-8&oe=UTF-8&tk={2}&q={3}";
private static readonly string HttpsTranslateUserSite = "https://translate.google.com";
private static readonly string DefaultUserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36";
private static readonly string DefaultUserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36";
//private static readonly string UserAgentRepository = "https://techblog.willshouse.com/2012/01/03/most-common-user-agents/";
private static readonly System.Random RandomNumbers = new System.Random();

Expand Down Expand Up @@ -201,21 +201,58 @@ public IEnumerator SetupTKK()
var html = downloadResult.Result;

const string lookup = "TKK=eval('";
var lookupIndex = html.IndexOf( lookup ) + lookup.Length;
var openClamIndex = html.IndexOf( '{', lookupIndex );
var closeClamIndex = html.IndexOf( '}', openClamIndex );
var functionIndex = html.IndexOf( "function", lookupIndex );
var script = html.Substring( functionIndex, closeClamIndex - functionIndex + 1 );
var decodedScript = script.Replace( "\\x3d", "=" ).Replace( "\\x27", "'" ).Replace( "function", "function FuncName" );

// https://github.com/paulbartrum/jurassic/wiki/Safely-executing-user-provided-scripts
ScriptEngine engine = new ScriptEngine();
engine.Evaluate( decodedScript );
var result = engine.CallGlobalFunction<string>( "FuncName" );

var parts = result.Split( '.' );
m = long.Parse( parts[ 0 ] );
s = long.Parse( parts[ 1 ] );
var index = html.IndexOf( lookup );
if( index > -1 ) // jurassic approach
{
var lookupIndex = index + lookup.Length;
var openClamIndex = html.IndexOf( '{', lookupIndex );
var closeClamIndex = html.IndexOf( '}', openClamIndex );
var functionIndex = html.IndexOf( "function", lookupIndex );
var script = html.Substring( functionIndex, closeClamIndex - functionIndex + 1 );
var decodedScript = script.Replace( "\\x3d", "=" ).Replace( "\\x27", "'" ).Replace( "function", "function FuncName" );

// https://github.com/paulbartrum/jurassic/wiki/Safely-executing-user-provided-scripts
ScriptEngine engine = new ScriptEngine();
engine.Evaluate( decodedScript );
var result = engine.CallGlobalFunction<string>( "FuncName" );

var parts = result.Split( '.' );
if( parts.Length == 2 )
{
m = long.Parse( parts[ 0 ] );
s = long.Parse( parts[ 1 ] );
}
else
{
Logger.Current.Warn( "An error occurred while setting up GoogleTranslate Cookie/TKK. Could not locate TKK value. Using fallback TKK values instead." );
}
}
else
{
const string lookup2 = "TKK='";
index = html.IndexOf( lookup2 );
if( index > -1 ) // simple string approach
{
var startIndex = index + lookup2.Length;
var endIndex = html.IndexOf( "'", startIndex );
var result = html.Substring( startIndex, endIndex - startIndex );

var parts = result.Split( '.' );
if( parts.Length == 2 )
{
m = long.Parse( parts[ 0 ] );
s = long.Parse( parts[ 1 ] );
}
else
{
Logger.Current.Warn( "An error occurred while setting up GoogleTranslate Cookie/TKK. Could not locate TKK value. Using fallback TKK values instead." );
}
}
else
{
Logger.Current.Warn( "An error occurred while setting up GoogleTranslate Cookie/TKK. Could not locate TKK value. Using fallback TKK values instead." );
}
}
}
catch( Exception e )
{
Expand All @@ -226,7 +263,7 @@ public IEnumerator SetupTKK()

if( error != null )
{
Logger.Current.Error( "An error occurred while setting up GoogleTranslate Cookie/TKK." + Environment.NewLine + error );
Logger.Current.Warn( "An error occurred while setting up GoogleTranslate Cookie/TKK. Using fallback TKK values instead." + Environment.NewLine + error );
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net35</TargetFramework>
<Version>2.15.0</Version>
<Version>2.15.1</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net35</TargetFramework>
<Version>2.15.0</Version>
<Version>2.15.1</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net35</TargetFramework>
<Version>2.15.0</Version>
<Version>2.15.1</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<OutputType>Exe</OutputType>
<TargetFramework>net40</TargetFramework>
<AssemblyName>SetupReiPatcherAndAutoTranslator</AssemblyName>
<Version>2.15.0</Version>
<Version>2.15.1</Version>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit 7fa8103

Please sign in to comment.