Преглед на файлове

Version 3.1.0

 * 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
randoman преди 6 години
родител
ревизия
ea028c0d11

+ 1 - 0
src/XUnity.AutoTranslator.Plugin.Core/Extensions/HarmonyInstanceExtensions.cs

@@ -5,6 +5,7 @@ using System.Reflection;
 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;

+ 2 - 4
src/XUnity.AutoTranslator.Plugin.Core/Hooks/ImageHooks.cs

@@ -58,11 +58,9 @@ namespace XUnity.AutoTranslator.Plugin.Core.Hooks
          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;

+ 38 - 35
src/XUnity.RuntimeHooker.Core/TrampolineHandler.cs

@@ -2,6 +2,7 @@
 using System.Collections.Generic;
 using System.IO;
 using System.Reflection;
+using System.Threading;
 using XUnity.RuntimeHooker.Core;
 using XUnity.RuntimeHooker.Core.Utilities;
 
@@ -9,74 +10,76 @@ 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 );
+         }
       }
    }
 }