Skip to content

Commit

Permalink
Version 4.6.0
Browse files Browse the repository at this point in the history
 * FEATURE - Support for ZIP files in redirected resource directory
 * BUG FIX - Fixed bug where you somtimes had to close dialogues before translations would appear
 * BUG FIX - Fixed bug where plugin would not function if a game is launched through a custom launcher not located in the game directory
 * MISC - Automatically enable texture translations if a texture directory is present during initial startup
  • Loading branch information
randoman committed Oct 24, 2019
1 parent e6e8061 commit 30d1b87
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
### 4.6.0
* FEATURE - Support for ZIP files in redirected resource directory
* BUG FIX - Fixed bug where you somtimes had to close dialogues before translations would appear
* BUG FIX - Fixed bug where plugin would not function if a game is launched through a custom launcher not located in the game directory
* MISC - Automatically enable texture translations if a texture directory is present during initial startup

Expand Down
38 changes: 30 additions & 8 deletions src/XUnity.AutoTranslator.Plugin.Core/AutoTranslationPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1860,7 +1860,22 @@ private IEnumerator WaitForTextStablization( object ui, float delay, int maxTrie
while( currentTries < maxTries ) // shortcircuit
{
var beforeText = ui.GetText();
yield return new WaitForSeconds( delay );

var instruction = Features.GetWaitForSecondsRealtime( delay );
if( instruction != null )
{
yield return instruction;
}
else
{
float start = Time.realtimeSinceStartup;
var end = start + delay;
while( Time.realtimeSinceStartup < end )
{
yield return null;
}
}

var afterText = ui.GetText();

if( beforeText == afterText )
Expand Down Expand Up @@ -1895,7 +1910,20 @@ private IEnumerator WaitForTextStablization( UntranslatedText textKey, float del
_immediatelyTranslating.Add( text );
try
{
yield return new WaitForSeconds( delay );
var instruction = Features.GetWaitForSecondsRealtime( delay );
if( instruction != null )
{
yield return instruction;
}
else
{
float start = Time.realtimeSinceStartup;
var end = start + delay;
while( Time.realtimeSinceStartup < end )
{
yield return null;
}
}

bool succeeded = true;
foreach( var otherImmediatelyTranslating in _immediatelyTranslating )
Expand Down Expand Up @@ -1926,12 +1954,6 @@ private IEnumerator WaitForTextStablization( UntranslatedText textKey, float del
}
}

private IEnumerator DelayForSeconds( float delay, Action onContinue )
{
yield return new WaitForSeconds( delay );
onContinue();
}

void Awake()
{
if( !_initialized )
Expand Down
34 changes: 34 additions & 0 deletions src/XUnity.AutoTranslator.Plugin.Core/Features.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections;
using System.Linq;
using System.Reflection.Emit;
using System.Text;
Expand Down Expand Up @@ -34,6 +35,11 @@ public static class Features
/// </summary>
public static bool SupportsNet4x { get; } = false;

/// <summary>
/// Gets a bool indicating if the WaitForSecondsRealtime class is supported.
/// </summary>
public static bool SupportsWaitForSecondsRealtime { get; } = false;

static Features()
{
try
Expand Down Expand Up @@ -81,6 +87,15 @@ static Features()

}

try
{
SupportsWaitForSecondsRealtime = ClrTypes.WaitForSecondsRealtime != null;
}
catch( Exception )
{

}

try
{
TestReflectionEmit();
Expand All @@ -99,5 +114,24 @@ private static void TestReflectionEmit()
MethodToken t2 = default( MethodToken );
var ok = t1 == t2;
}

/// <summary>
/// Gets the WaitForSecondsRealtime CustomYieldInstruction if supported.
/// </summary>
/// <param name="delay"></param>
/// <returns></returns>
public static IEnumerator GetWaitForSecondsRealtime( float delay )
{
if( SupportsWaitForSecondsRealtime )
{
return GetWaitForSecondsRealtimeInternal( delay );
}
return null;
}

private static IEnumerator GetWaitForSecondsRealtimeInternal( float delay )
{
return new WaitForSecondsRealtime( delay );
}
}
}
2 changes: 2 additions & 0 deletions src/XUnity.Common/Constants/ClrTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public static class ClrTypes
public static readonly Type HorizontalWrapMode = FindType( "UnityEngine.HorizontalWrapMode" );
public static readonly Type VerticalWrapMode = FindType( "UnityEngine.VerticalWrapMode" );
public static readonly Type Font = FindType( "UnityEngine.Font" );
public static readonly Type WaitForSecondsRealtime = FindType( "UnityEngine.WaitForSecondsRealtime" );


// Something...
public static readonly Type Typewriter = FindType( "Typewriter" );
Expand Down

0 comments on commit 30d1b87

Please sign in to comment.