Skip to content

Commit

Permalink
Version 3.1.0
Browse files Browse the repository at this point in the history
 * FEATURE - Support for games with 'netstandard2.0' API surface through config option 'EnableExperimentalHooks'
 * BUG FIX - Bug fixes and improvements to Utage hooking implementation - EnableUtage config option also removed (always on now)
 * BUG FIX - Rich text parser bug fixes when only a single tag with no ending was used
 * BUG FIX - Fixed potential NullReferenceException in TextGetterCompatibilityMode
 * BUG FIX - Load translator assemblies even if a '#' is present in file path
 * MISC - Determine whether to disable certificate checks at config initialization based on scripting backend and unity version
  • Loading branch information
randoman committed Mar 31, 2019
1 parent fce123c commit ea028c0
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Text;
using Harmony;
using Harmony.ILCopying;
using UnityEngine;
using XUnity.AutoTranslator.Plugin.Core.Configuration;
using XUnity.AutoTranslator.Plugin.Core.Constants;
using XUnity.AutoTranslator.Plugin.Core.Hooks;
Expand Down
6 changes: 2 additions & 4 deletions src/XUnity.AutoTranslator.Plugin.Core/Hooks/ImageHooks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,9 @@ static MethodBase TargetMethod( HarmonyInstance instance )
return AccessTools.Property( ClrTypes.Sprite, "texture" )?.GetGetMethod();
}

static void Postfix( Sprite __instance )
static void Postfix( Texture2D __result )
{
var texture = __instance.texture;

AutoTranslationPlugin.Current.Hook_ImageChanged( texture, true );
AutoTranslationPlugin.Current.Hook_ImageChanged( __result, true );
}

static bool RequireRuntimeHooker => true;
Expand Down
73 changes: 38 additions & 35 deletions src/XUnity.RuntimeHooker.Core/TrampolineHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,81 +2,84 @@
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Threading;
using XUnity.RuntimeHooker.Core;
using XUnity.RuntimeHooker.Core.Utilities;

namespace XUnity.RuntimeHooker.Core
{
public static class TrampolineHandler
{
private static object Null;

public static object Func( object instance, TrampolineData data )
{
var jumpedMethodInfo = data.JumpedMethodInfo;
var parameters = data.Parameters;

var prefixes = data.Prefixes;
var prefixesLen = prefixes.Count;
for( int i = 0 ; i < prefixesLen ; i++ )
{
if( !prefixes[ i ].PrefixInvoke( parameters, instance ) ) return null;
}

object result;
try
{
MemoryHelper.RestoreInstructionsAtLocation( false, jumpedMethodInfo.OriginalMethodLocation, jumpedMethodInfo.OriginalCode );

var prefixes = data.Prefixes;
var prefixesLen = prefixes.Count;
for( int i = 0 ; i < prefixesLen ; i++ )
{
if( !prefixes[ i ].PrefixInvoke( parameters, instance ) ) return null;
}

var fastInvoke = data.FastInvoke;
object result = fastInvoke != null
result = fastInvoke != null
? fastInvoke( instance, parameters )
: data.Method.Invoke( null, parameters );

var postfixes = data.Postfixes;
var postfixesLen = postfixes.Count;
for( int i = 0 ; i < postfixesLen ; i++ )
{
postfixes[ i ].PostfixInvoke( parameters, instance, ref result );
}

return result;
: data.Method.Invoke( instance, parameters );
}
finally
{
MemoryHelper.WriteJump( false, jumpedMethodInfo.OriginalMethodLocation, jumpedMethodInfo.ReplacementMethodLocation );
}

var postfixes = data.Postfixes;
var postfixesLen = postfixes.Count;
for( int i = 0 ; i < postfixesLen ; i++ )
{
postfixes[ i ].PostfixInvoke( parameters, instance, ref result );
}

return result;
}

public static void Action( object instance, TrampolineData data )
{
var jumpedMethodInfo = data.JumpedMethodInfo;
var parameters = data.Parameters;

var prefixes = data.Prefixes;
var prefixesLen = prefixes.Count;
for( int i = 0 ; i < prefixesLen ; i++ )
{
if( !prefixes[ i ].PrefixInvoke( parameters, instance ) ) return;
}

try
{
MemoryHelper.RestoreInstructionsAtLocation( false, jumpedMethodInfo.OriginalMethodLocation, jumpedMethodInfo.OriginalCode );

var prefixes = data.Prefixes;
var prefixesLen = prefixes.Count;
for( int i = 0 ; i < prefixesLen ; i++ )
{
if( !prefixes[ i ].PrefixInvoke( parameters, instance ) ) return;
}

var fastInvoke = data.FastInvoke;
object result = fastInvoke != null
? fastInvoke( instance, parameters )
: data.Method.Invoke( null, parameters );

var postfixes = data.Postfixes;
var postfixesLen = postfixes.Count;
for( int i = 0 ; i < postfixesLen ; i++ )
{
postfixes[ i ].PostfixInvoke( parameters, instance, ref Null );
}
: data.Method.Invoke( instance, parameters );
}
finally
{
MemoryHelper.WriteJump( false, jumpedMethodInfo.OriginalMethodLocation, jumpedMethodInfo.ReplacementMethodLocation );
}

object tmp = null;
var postfixes = data.Postfixes;
var postfixesLen = postfixes.Count;
for( int i = 0 ; i < postfixesLen ; i++ )
{
postfixes[ i ].PostfixInvoke( parameters, instance, ref tmp );
}
}
}
}

0 comments on commit ea028c0

Please sign in to comment.