Przeglądaj źródła

Version 3.5.0

 * FEATURE - Harmony 2.0-prerelease support (in order to support BepInEx 5.0.0-RC1)
 * BUG FIX - Fixed a bug where the plugin would sometimes dump textures if 'DetectDuplicateTextureNames' was turned on, even though 'EnableTextureDumping' was turned off
 * BUG FIX - Correct whitespace handling of source languages requiring whitelines between words
randoman 6 lat temu
rodzic
commit
4394f3a70a
32 zmienionych plików z 480 dodań i 361 usunięć
  1. 6 1
      CHANGELOG.md
  2. 1 1
      src/XUnity.AutoTranslator.Patcher/Patcher.cs
  3. 1 1
      src/XUnity.AutoTranslator.Plugin.BepIn-5x/XUnity.AutoTranslator.Plugin.BepIn-5x.csproj
  4. 1 1
      src/XUnity.AutoTranslator.Plugin.BepIn/XUnity.AutoTranslator.Plugin.BepIn.csproj
  5. 6 1
      src/XUnity.AutoTranslator.Plugin.Core/AutoTranslationPlugin.cs
  6. 4 1
      src/XUnity.AutoTranslator.Plugin.Core/Constants/ClrTypes.cs
  7. 1 1
      src/XUnity.AutoTranslator.Plugin.Core/Constants/PluginData.cs
  8. 3 3
      src/XUnity.AutoTranslator.Plugin.Core/Endpoints/Www/WwwEndpoint.cs
  9. 38 29
      src/XUnity.AutoTranslator.Plugin.Core/Extensions/HarmonyInstanceExtensions.cs
  10. 3 3
      src/XUnity.AutoTranslator.Plugin.Core/Extensions/TextureComponentExtensions.cs
  11. 3 3
      src/XUnity.AutoTranslator.Plugin.Core/Extensions/TextureExtensions.cs
  12. 34 0
      src/XUnity.AutoTranslator.Plugin.Core/HarmonyLoader.cs
  13. 34 0
      src/XUnity.AutoTranslator.Plugin.Core/Hooks/AccessToolsShim.cs
  14. 17 0
      src/XUnity.AutoTranslator.Plugin.Core/Hooks/HarmonyPriorityShimAttribute.cs
  15. 11 3
      src/XUnity.AutoTranslator.Plugin.Core/Hooks/HooksSetup.cs
  16. 53 53
      src/XUnity.AutoTranslator.Plugin.Core/Hooks/IMGUIHooks.cs
  17. 104 132
      src/XUnity.AutoTranslator.Plugin.Core/Hooks/ImageHooks.cs
  18. 9 9
      src/XUnity.AutoTranslator.Plugin.Core/Hooks/NGUIHooks.cs
  19. 8 11
      src/XUnity.AutoTranslator.Plugin.Core/Hooks/TextGetterCompatHooks.cs
  20. 37 37
      src/XUnity.AutoTranslator.Plugin.Core/Hooks/TextMeshProHooks.cs
  21. 9 9
      src/XUnity.AutoTranslator.Plugin.Core/Hooks/UGUIHooks.cs
  22. 19 25
      src/XUnity.AutoTranslator.Plugin.Core/Hooks/UtageHooks.cs
  23. 3 3
      src/XUnity.AutoTranslator.Plugin.Core/TextTranslationInfo.cs
  24. 13 12
      src/XUnity.AutoTranslator.Plugin.Core/UntranslatedText.cs
  25. 0 1
      src/XUnity.AutoTranslator.Plugin.Core/Web/XUnityWebClient.cs
  26. 4 4
      src/XUnity.AutoTranslator.Plugin.Core/XUnity.AutoTranslator.Plugin.Core.csproj
  27. 1 1
      src/XUnity.AutoTranslator.Plugin.IPA/XUnity.AutoTranslator.Plugin.IPA.csproj
  28. 1 1
      src/XUnity.AutoTranslator.Plugin.UnityInjector/XUnity.AutoTranslator.Plugin.UnityInjector.csproj
  29. 1 1
      src/XUnity.AutoTranslator.Setup/XUnity.AutoTranslator.Setup.csproj
  30. 15 0
      src/XUnity.RuntimeHooker.Core/Utilities/ExpressionHelper.cs
  31. 25 0
      test/XUnity.AutoTranslator.Plugin.Core.Tests/UntranslatedTextTests.cs
  32. 15 14
      test/XUnity.RuntimeHooker.ConsoleTests/Program.cs

+ 6 - 1
CHANGELOG.md

@@ -1,4 +1,9 @@
-### 3.4.0
+### 3.5.0
+ * FEATURE - Harmony 2.0-prerelease support (in order to support BepInEx 5.0.0-RC1)
+ * BUG FIX - Fixed a bug where the plugin would sometimes dump textures if 'DetectDuplicateTextureNames' was turned on, even though 'EnableTextureDumping' was turned off
+ * BUG FIX - Correct whitespace handling of source languages requiring whitelines between words
+
+### 3.4.0
  * FEATURE - Added capability of plugin to detect textures that shares the same resource name and identify these resources in an alternative way
  * BUG FIX - Fixed an issue with TextMeshPro that could cause text to glitch in certain situations
 

+ 1 - 1
src/XUnity.AutoTranslator.Patcher/Patcher.cs

@@ -29,7 +29,7 @@ namespace XUnity.AutoTranslator.Patcher
       {
          get
          {
-            return "3.4.0";
+            return "3.5.0";
          }
       }
 

+ 1 - 1
src/XUnity.AutoTranslator.Plugin.BepIn-5x/XUnity.AutoTranslator.Plugin.BepIn-5x.csproj

@@ -2,7 +2,7 @@
 
   <PropertyGroup>
     <TargetFramework>net35</TargetFramework>
-    <Version>3.4.0</Version>
+    <Version>3.5.0</Version>
   </PropertyGroup>
 
   <ItemGroup>

+ 1 - 1
src/XUnity.AutoTranslator.Plugin.BepIn/XUnity.AutoTranslator.Plugin.BepIn.csproj

@@ -2,7 +2,7 @@
 
    <PropertyGroup>
       <TargetFramework>net35</TargetFramework>
-      <Version>3.4.0</Version>
+      <Version>3.5.0</Version>
    </PropertyGroup>
 
    <ItemGroup>

+ 6 - 1
src/XUnity.AutoTranslator.Plugin.Core/AutoTranslationPlugin.cs

@@ -24,7 +24,6 @@ using XUnity.AutoTranslator.Plugin.Core.Hooks.NGUI;
 using UnityEngine.SceneManagement;
 using XUnity.AutoTranslator.Plugin.Core.Constants;
 using XUnity.AutoTranslator.Plugin.Core.Debugging;
-using Harmony;
 using XUnity.AutoTranslator.Plugin.Core.Parsing;
 using System.Diagnostics;
 using XUnity.AutoTranslator.Plugin.Core.UI;
@@ -91,6 +90,12 @@ namespace XUnity.AutoTranslator.Plugin.Core
          // Setup 'singleton'
          Current = this;
 
+         // because we only use harmony through reflection due to
+         // version compatibility issues, we call this method to
+         // ensure that harmony is loaded before we attempt to obtain
+         // various harmony classes through reflection
+         HarmonyLoader.Load();
+
          // Setup logger, if it was not already initialized by a plugin-version
          if( XuaLogger.Current == null )
          {

+ 4 - 1
src/XUnity.AutoTranslator.Plugin.Core/Constants/ClrTypes.cs

@@ -64,8 +64,11 @@ namespace XUnity.AutoTranslator.Plugin.Core.Constants
       public static readonly Type CubismRenderer = FindType( "Live2D.Cubism.Rendering.CubismRenderer" );
 
       // Harmony
+      public static readonly Type AccessTools = FindType( "Harmony.AccessTools" ) ?? FindType( "HarmonyLib.AccessTools" );
+
       public static readonly Type HarmonyInstance = FindType( "Harmony.HarmonyInstance" );
-      public static readonly Type HarmonyMethod = FindType( "Harmony.HarmonyMethod" );
+      public static readonly Type HarmonyMethod = FindType( "Harmony.HarmonyMethod" ) ?? FindType( "HarmonyLib.HarmonyMethod" );
+      public static readonly Type Harmony = FindType( "HarmonyLib.Harmony" );
 
       // Mono / .NET
       public static readonly Type MethodBase = FindType( "System.Reflection.MethodBase" );

+ 1 - 1
src/XUnity.AutoTranslator.Plugin.Core/Constants/PluginData.cs

@@ -23,6 +23,6 @@ namespace XUnity.AutoTranslator.Plugin.Core.Constants
       /// <summary>
       /// Gets the version of the plugin.
       /// </summary>
-      public const string Version = "3.4.0";
+      public const string Version = "3.5.0";
    }
 }

+ 3 - 3
src/XUnity.AutoTranslator.Plugin.Core/Endpoints/Www/WwwEndpoint.cs

@@ -4,10 +4,10 @@ using System.Collections.Generic;
 using System.Net;
 using System.Reflection;
 using System.Text;
-using Harmony;
 using UnityEngine;
 using XUnity.AutoTranslator.Plugin.Core.Configuration;
 using XUnity.AutoTranslator.Plugin.Core.Constants;
+using XUnity.AutoTranslator.Plugin.Core.Hooks;
 using XUnity.AutoTranslator.Plugin.Core.Web;
 
 namespace XUnity.AutoTranslator.Plugin.Core.Endpoints.Www
@@ -113,11 +113,11 @@ namespace XUnity.AutoTranslator.Plugin.Core.Endpoints.Www
          yield return www;
 
          // extract error
-         string error = (string)AccessTools.Property( ClrTypes.WWW, "error" ).GetValue( www, null );
+         string error = (string)AccessToolsShim.Property( ClrTypes.WWW, "error" ).GetValue( www, null );
          if( error != null ) wwwContext.Fail( "Error occurred while retrieving translation. " + error );
 
          // extract text
-         var text = (string)AccessTools.Property( ClrTypes.WWW, "text" ).GetValue( www, null );
+         var text = (string)AccessToolsShim.Property( ClrTypes.WWW, "text" ).GetValue( www, null );
          if( text == null ) wwwContext.Fail( "Error occurred while extracting text from response." ); 
 
          wwwContext.ResponseData = text;

+ 38 - 29
src/XUnity.AutoTranslator.Plugin.Core/Extensions/HarmonyInstanceExtensions.cs

@@ -3,8 +3,6 @@ using System.Collections.Generic;
 using System.Linq;
 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;
@@ -17,9 +15,10 @@ namespace XUnity.AutoTranslator.Plugin.Core.Extensions
 {
    internal static class HarmonyInstanceExtensions
    {
-      public static readonly MethodInfo PatchMethod = ClrTypes.HarmonyInstance.GetMethod( "Patch", new Type[] { ClrTypes.MethodBase, ClrTypes.HarmonyMethod, ClrTypes.HarmonyMethod, ClrTypes.HarmonyMethod } );
+      public static readonly MethodInfo PatchMethod12 = ClrTypes.HarmonyInstance?.GetMethod( "Patch", new Type[] { ClrTypes.MethodBase, ClrTypes.HarmonyMethod, ClrTypes.HarmonyMethod, ClrTypes.HarmonyMethod } );
+      public static readonly MethodInfo PatchMethod20 = ClrTypes.Harmony?.GetMethod( "Patch", new Type[] { ClrTypes.MethodBase, ClrTypes.HarmonyMethod, ClrTypes.HarmonyMethod, ClrTypes.HarmonyMethod, ClrTypes.HarmonyMethod } );
 
-      public static void PatchAll( this HarmonyInstance instance, IEnumerable<Type> types )
+      public static void PatchAll( this object instance, IEnumerable<Type> types )
       {
          foreach( var type in types )
          {
@@ -27,7 +26,23 @@ namespace XUnity.AutoTranslator.Plugin.Core.Extensions
          }
       }
 
-      public static void PatchType( this HarmonyInstance instance, Type type )
+      private static object CreateHarmonyMethod( MethodInfo method, int? priority )
+      {
+         var harmonyMethod = ClrTypes.HarmonyMethod.GetConstructor( new Type[] { typeof( MethodInfo ) } )
+            .Invoke( new object[] { method } );
+
+         if( priority.HasValue )
+         {
+            var field = ClrTypes.HarmonyMethod.GetField( "priority", BindingFlags.Public | BindingFlags.Instance )
+               ?? ClrTypes.HarmonyMethod.GetField( "prioritiy", BindingFlags.Public | BindingFlags.Instance );
+
+            field.SetValue( harmonyMethod, priority.Value );
+         }
+
+         return harmonyMethod;
+      }
+
+      public static void PatchType( this object instance, Type type )
       {
          MethodBase original = null;
          try
@@ -41,31 +56,18 @@ namespace XUnity.AutoTranslator.Plugin.Core.Extensions
                {
                   var requireRuntimeHooker = (bool?)type.GetProperty( "RequireRuntimeHooker", flags )?.GetValue( null, null ) == true;
 
-                  var priority = type.GetCustomAttributes( typeof( HarmonyPriority ), false )
-                     .OfType<HarmonyPriority>()
+                  var priority = type.GetCustomAttributes( typeof( HarmonyPriorityShimAttribute ), false )
+                     .OfType<HarmonyPriorityShimAttribute>()
                      .FirstOrDefault()
-                     ?.info.prioritiy;
+                     ?.priority;
 
                   var prefix = type.GetMethod( "Prefix", flags );
                   var postfix = type.GetMethod( "Postfix", flags );
                   var transpiler = type.GetMethod( "Transpiler", flags );
 
-                  var harmonyPrefix = prefix != null ? new HarmonyMethod( prefix ) : null;
-                  var harmonyPostfix = postfix != null ? new HarmonyMethod( postfix ) : null;
-                  var harmonyTranspiler = transpiler != null ? new HarmonyMethod( transpiler ) : null;
-
-                  if( priority.HasValue )
-                  {
-                     if( harmonyPrefix != null )
-                     {
-                        harmonyPrefix.prioritiy = priority.Value;
-                     }
-
-                     if( harmonyPostfix != null )
-                     {
-                        harmonyPostfix.prioritiy = priority.Value;
-                     }
-                  }
+                  var harmonyPrefix = prefix != null ? CreateHarmonyMethod( prefix, priority ) : null;
+                  var harmonyPostfix = postfix != null ? CreateHarmonyMethod( postfix, priority ) : null;
+                  var harmonyTranspiler = transpiler != null ? CreateHarmonyMethod( transpiler, priority ) : null;
 
                   if( requireRuntimeHooker || Settings.ForceExperimentalHooks )
                   {
@@ -73,8 +75,8 @@ namespace XUnity.AutoTranslator.Plugin.Core.Extensions
                      {
                         XuaLogger.Current.Info( $"Hooking '{original.DeclaringType.FullName}.{original.Name}' through experimental hooks." );
 
-                        var hookPrefix = harmonyPrefix != null ? new HookMethod( harmonyPrefix.method, harmonyPrefix.prioritiy ) : null;
-                        var hookPostfix = harmonyPostfix != null ? new HookMethod( harmonyPostfix.method, harmonyPostfix.prioritiy ) : null;
+                        var hookPrefix = harmonyPrefix != null ? new HookMethod( prefix, priority ?? -1 ) : null;
+                        var hookPostfix = harmonyPostfix != null ? new HookMethod( postfix, priority ?? -1 ) : null;
 
                         RuntimeMethodPatcher.Patch( original, hookPrefix, hookPostfix );
                      }
@@ -87,7 +89,14 @@ namespace XUnity.AutoTranslator.Plugin.Core.Extensions
                   {
                      try
                      {
-                        PatchMethod.Invoke( instance, new object[] { original, harmonyPrefix, harmonyPostfix, harmonyTranspiler } );
+                        if( PatchMethod12 != null )
+                        {
+                           PatchMethod12.Invoke( instance, new object[] { original, harmonyPrefix, harmonyPostfix, harmonyTranspiler } );
+                        }
+                        else
+                        {
+                           PatchMethod20.Invoke( instance, new object[] { original, harmonyPrefix, harmonyPostfix, harmonyTranspiler, null } );
+                        }
                      }
                      catch( Exception e ) when( e.IsCausedBy<PlatformNotSupportedException>() )
                      {
@@ -95,8 +104,8 @@ namespace XUnity.AutoTranslator.Plugin.Core.Extensions
                         {
                            XuaLogger.Current.Info( $"Harmony is not supported in this runtime. Hooking '{original.DeclaringType.FullName}.{original.Name}' through experimental hooks." );
 
-                           var hookPrefix = harmonyPrefix != null ? new HookMethod( harmonyPrefix.method, harmonyPrefix.prioritiy ) : null;
-                           var hookPostfix = harmonyPostfix != null ? new HookMethod( harmonyPostfix.method, harmonyPostfix.prioritiy ) : null;
+                           var hookPrefix = harmonyPrefix != null ? new HookMethod( prefix, priority ?? -1 ) : null;
+                           var hookPostfix = harmonyPostfix != null ? new HookMethod( postfix, priority ?? -1 ) : null;
 
                            RuntimeMethodPatcher.Patch( original, hookPrefix, hookPostfix );
                         }

+ 3 - 3
src/XUnity.AutoTranslator.Plugin.Core/Extensions/TextureComponentExtensions.cs

@@ -1,6 +1,6 @@
-using Harmony;
-using UnityEngine;
+using UnityEngine;
 using UnityEngine.UI;
+using XUnity.AutoTranslator.Plugin.Core.Hooks;
 
 namespace XUnity.AutoTranslator.Plugin.Core.Extensions
 {
@@ -62,7 +62,7 @@ namespace XUnity.AutoTranslator.Plugin.Core.Extensions
             // lets attempt some reflection for several known types
             var type = ui.GetType();
 
-            AccessTools.Method( type, MarkAsChangedMethodName )?.Invoke( ui, null );
+            AccessToolsShim.Method( type, MarkAsChangedMethodName )?.Invoke( ui, null );
          }
       }
    }

+ 3 - 3
src/XUnity.AutoTranslator.Plugin.Core/Extensions/TextureExtensions.cs

@@ -4,17 +4,17 @@ using System.Drawing;
 using System.Linq;
 using System.Reflection;
 using System.Text;
-using Harmony;
 using UnityEngine;
 using UnityEngine.UI;
 using XUnity.AutoTranslator.Plugin.Core.Constants;
+using XUnity.AutoTranslator.Plugin.Core.Hooks;
 
 namespace XUnity.AutoTranslator.Plugin.Core.Extensions
 {
    internal static class TextureExtensions
    {
-      private static readonly MethodInfo LoadImage = AccessTools.Method( ClrTypes.ImageConversion, "LoadImage", new[] { typeof( Texture2D ), typeof( byte[] ), typeof( bool ) } );
-      private static readonly MethodInfo EncodeToPNG = AccessTools.Method( ClrTypes.ImageConversion, "EncodeToPNG", new[] { typeof( Texture2D ) } );
+      private static readonly MethodInfo LoadImage = AccessToolsShim.Method( ClrTypes.ImageConversion, "LoadImage", new[] { typeof( Texture2D ), typeof( byte[] ), typeof( bool ) } );
+      private static readonly MethodInfo EncodeToPNG = AccessToolsShim.Method( ClrTypes.ImageConversion, "EncodeToPNG", new[] { typeof( Texture2D ) } );
 
       //public static bool IsNonReadable( this Texture2D texture )
       //{

+ 34 - 0
src/XUnity.AutoTranslator.Plugin.Core/HarmonyLoader.cs

@@ -0,0 +1,34 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Text;
+
+namespace XUnity.AutoTranslator.Plugin.Core
+{
+   internal static class HarmonyLoader
+   {
+      public static void Load()
+      {
+         // Ensure that we have loaded Harmony
+         try
+         {
+            Harmony12Loader.Load();
+         }
+         catch
+         {
+            // will throw an exception if 2.0 is used. But that does not matter
+            // because the assembly will be loaded, even if it is 2.0 and that
+            // is the only purpose of this method
+         }
+      }
+   }
+
+   internal static class Harmony12Loader
+   {
+      public static void Load()
+      {
+         var flags = Harmony.AccessTools.all;
+      }
+   }
+}

+ 34 - 0
src/XUnity.AutoTranslator.Plugin.Core/Hooks/AccessToolsShim.cs

@@ -0,0 +1,34 @@
+using System;
+using System.Reflection;
+using XUnity.AutoTranslator.Plugin.Core.Constants;
+using XUnity.RuntimeHooker.Core.Utilities;
+
+namespace XUnity.AutoTranslator.Plugin.Core.Hooks
+{
+   internal static class AccessToolsShim
+   {
+      private static readonly BindingFlags All = BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public;
+
+      private static readonly Func<Type, string, Type[], Type[], MethodInfo> AccessTools_Method;
+      private static readonly Func<Type, string, PropertyInfo> AccessTools_Property;
+
+      static AccessToolsShim()
+      {
+         var method = ClrTypes.AccessTools.GetMethod( "Method", All, null, new Type[] { typeof( Type ), typeof( string ), typeof( Type[] ), typeof( Type[] ) }, null );
+         var property = ClrTypes.AccessTools.GetMethod( "Property", All, null, new Type[] { typeof( Type ), typeof( string ) }, null );
+
+         AccessTools_Method = (Func<Type, string, Type[], Type[], MethodInfo>)ExpressionHelper.CreateTypedFastInvoke( method );
+         AccessTools_Property = (Func<Type, string, PropertyInfo>)ExpressionHelper.CreateTypedFastInvoke( property );
+      }
+
+      public static MethodInfo Method( Type type, string name, params Type[] parameters )
+      {
+         return AccessTools_Method( type, name, parameters, null );
+      }
+
+      public static PropertyInfo Property( Type type, string name )
+      {
+         return AccessTools_Property( type, name );
+      }
+   }
+}

+ 17 - 0
src/XUnity.AutoTranslator.Plugin.Core/Hooks/HarmonyPriorityShimAttribute.cs

@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace XUnity.AutoTranslator.Plugin.Core.Hooks
+{
+   internal class HarmonyPriorityShimAttribute : Attribute
+   {
+      public int priority;
+
+      public HarmonyPriorityShimAttribute( int priority )
+      {
+         this.priority = priority;
+      }
+   }
+}

+ 11 - 3
src/XUnity.AutoTranslator.Plugin.Core/Hooks/HooksSetup.cs

@@ -4,7 +4,6 @@ using System.IO;
 using System.Linq;
 using System.Reflection;
 using System.Text;
-using Harmony;
 using UnityEngine;
 using XUnity.AutoTranslator.Plugin.Core.Configuration;
 using XUnity.AutoTranslator.Plugin.Core.Constants;
@@ -20,11 +19,20 @@ namespace XUnity.AutoTranslator.Plugin.Core.Hooks
 
    internal static class HooksSetup
    {
-      private static HarmonyInstance _harmony;
+      private static object _harmony;
 
       static HooksSetup()
       {
-         _harmony = HarmonyInstance.Create( "gravydevsupreme.xunity.autotranslator" );
+         if( ClrTypes.HarmonyInstance != null )
+         {
+            _harmony = ClrTypes.HarmonyInstance.GetMethod( "Create", BindingFlags.Static | BindingFlags.Public )
+               .Invoke( null, new object[] { PluginData.Identifier } );
+         }
+         else if( ClrTypes.Harmony != null )
+         {
+            _harmony = ClrTypes.Harmony.GetConstructor( new Type[] { typeof( string ) } )
+               .Invoke( new object[] { PluginData.Identifier } );
+         }
       }
 
       public static void InstallOverrideTextHooks()

+ 53 - 53
src/XUnity.AutoTranslator.Plugin.Core/Hooks/IMGUIHooks.cs

@@ -3,9 +3,9 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Reflection;
 using System.Text;
-using Harmony;
 using UnityEngine;
 using XUnity.AutoTranslator.Plugin.Core.Constants;
+using XUnity.RuntimeHooker.Core;
 using static UnityEngine.GUI;
 
 namespace XUnity.AutoTranslator.Plugin.Core.Hooks.IMGUI
@@ -34,15 +34,15 @@ namespace XUnity.AutoTranslator.Plugin.Core.Hooks.IMGUI
    }
 
 
-   //[Harmony, HarmonyPriority( Priority.Last )]
+   //[HarmonyPriority( HookPriority.Last )]
    //internal static class GUIContent_text_Hook
    //{
-   //   static bool Prepare( HarmonyInstance instance )
+   //   static bool Prepare( object instance )
    //   {
    //      return ClrTypes.GUIContent != null;
    //   }
 
-   //   static MethodBase TargetMethod( HarmonyInstance instance )
+   //   static MethodBase TargetMethod( object instance )
    //   {
    //      return AccessTools.Property( ClrTypes.GUIContent, "text" )?.GetSetMethod();
    //   }
@@ -56,15 +56,15 @@ namespace XUnity.AutoTranslator.Plugin.Core.Hooks.IMGUI
    //   }
    //}
 
-   //[Harmony, HarmonyPriority( Priority.Last )]
+   //[HarmonyPriority( HookPriority.Last )]
    //internal static class GUIContent_Temp_Hook1
    //{
-   //   static bool Prepare( HarmonyInstance instance )
+   //   static bool Prepare( object instance )
    //   {
    //      return ClrTypes.GUIContent != null;
    //   }
 
-   //   static MethodBase TargetMethod( HarmonyInstance instance )
+   //   static MethodBase TargetMethod( object instance )
    //   {
    //      return AccessTools.Method( ClrTypes.GUIContent, "Temp", new[] { typeof( string ) } );
    //   }
@@ -78,15 +78,15 @@ namespace XUnity.AutoTranslator.Plugin.Core.Hooks.IMGUI
    //   }
    //}
 
-   //[Harmony, HarmonyPriority( Priority.Last )]
+   //[HarmonyPriority( HookPriority.Last )]
    //internal static class GUIContent_Temp_Hook2
    //{
-   //   static bool Prepare( HarmonyInstance instance )
+   //   static bool Prepare( object instance )
    //   {
    //      return ClrTypes.GUIContent != null;
    //   }
 
-   //   static MethodBase TargetMethod( HarmonyInstance instance )
+   //   static MethodBase TargetMethod( object instance )
    //   {
    //      return AccessTools.Method( ClrTypes.GUIContent, "Temp", new[] { typeof( string ), typeof( string ) } );
    //   }
@@ -100,15 +100,15 @@ namespace XUnity.AutoTranslator.Plugin.Core.Hooks.IMGUI
    //   }
    //}
 
-   //[Harmony, HarmonyPriority( Priority.Last )]
+   //[HarmonyPriority( HookPriority.Last )]
    //internal static class GUIContent_Temp_Hook3
    //{
-   //   static bool Prepare( HarmonyInstance instance )
+   //   static bool Prepare( object instance )
    //   {
    //      return ClrTypes.GUIContent != null;
    //   }
 
-   //   static MethodBase TargetMethod( HarmonyInstance instance )
+   //   static MethodBase TargetMethod( object instance )
    //   {
    //      return AccessTools.Method( ClrTypes.GUIContent, "Temp", new[] { typeof( string ), typeof( Texture ) } );
    //   }
@@ -133,17 +133,17 @@ namespace XUnity.AutoTranslator.Plugin.Core.Hooks.IMGUI
 
 
 
-   [Harmony, HarmonyPriority( Priority.Last )]
+   [HarmonyPriorityShim( HookPriority.Last )]
    internal static class GUI_BeginGroup_Hook
    {
-      static bool Prepare( HarmonyInstance instance )
+      static bool Prepare( object instance )
       {
          return Constants.ClrTypes.GUI != null;
       }
 
-      static MethodBase TargetMethod( HarmonyInstance instance )
+      static MethodBase TargetMethod( object instance )
       {
-         return AccessTools.Method( Constants.ClrTypes.GUI, "BeginGroup", new[] { typeof( Rect ), typeof( GUIContent ), typeof( GUIStyle ) } );
+         return AccessToolsShim.Method( Constants.ClrTypes.GUI, "BeginGroup", new[] { typeof( Rect ), typeof( GUIContent ), typeof( GUIStyle ) } );
       }
 
       static void Prefix( GUIContent content )
@@ -155,17 +155,17 @@ namespace XUnity.AutoTranslator.Plugin.Core.Hooks.IMGUI
       }
    }
 
-   [Harmony, HarmonyPriority( Priority.Last )]
+   [HarmonyPriorityShim( HookPriority.Last )]
    internal static class GUI_Box_Hook
    {
-      static bool Prepare( HarmonyInstance instance )
+      static bool Prepare( object instance )
       {
          return Constants.ClrTypes.GUI != null;
       }
 
-      static MethodBase TargetMethod( HarmonyInstance instance )
+      static MethodBase TargetMethod( object instance )
       {
-         return AccessTools.Method( Constants.ClrTypes.GUI, "Box", new[] { typeof( Rect ), typeof( GUIContent ), typeof( GUIStyle ) } );
+         return AccessToolsShim.Method( Constants.ClrTypes.GUI, "Box", new[] { typeof( Rect ), typeof( GUIContent ), typeof( GUIStyle ) } );
       }
 
       static void Prefix( GUIContent content )
@@ -178,17 +178,17 @@ namespace XUnity.AutoTranslator.Plugin.Core.Hooks.IMGUI
 
    }
 
-   [Harmony, HarmonyPriority( Priority.Last )]
+   [HarmonyPriorityShim( HookPriority.Last )]
    internal static class GUI_DoRepeatButton_Hook
    {
-      static bool Prepare( HarmonyInstance instance )
+      static bool Prepare( object instance )
       {
          return Constants.ClrTypes.GUI != null;
       }
 
-      static MethodBase TargetMethod( HarmonyInstance instance )
+      static MethodBase TargetMethod( object instance )
       {
-         return AccessTools.Method( Constants.ClrTypes.GUI, "DoRepeatButton", new[] { typeof( Rect ), typeof( GUIContent ), typeof( GUIStyle ), typeof( FocusType ) } );
+         return AccessToolsShim.Method( Constants.ClrTypes.GUI, "DoRepeatButton", new[] { typeof( Rect ), typeof( GUIContent ), typeof( GUIStyle ), typeof( FocusType ) } );
       }
 
       static void Prefix( GUIContent content )
@@ -200,17 +200,17 @@ namespace XUnity.AutoTranslator.Plugin.Core.Hooks.IMGUI
       }
    }
 
-   [Harmony, HarmonyPriority( Priority.Last )]
+   [HarmonyPriorityShim( HookPriority.Last )]
    internal static class GUI_DoLabel_Hook
    {
-      static bool Prepare( HarmonyInstance instance )
+      static bool Prepare( object instance )
       {
          return Constants.ClrTypes.GUI != null;
       }
 
-      static MethodBase TargetMethod( HarmonyInstance instance )
+      static MethodBase TargetMethod( object instance )
       {
-         return AccessTools.Method( Constants.ClrTypes.GUI, "DoLabel", new[] { typeof( Rect ), typeof( GUIContent ), typeof( IntPtr ) } );
+         return AccessToolsShim.Method( Constants.ClrTypes.GUI, "DoLabel", new[] { typeof( Rect ), typeof( GUIContent ), typeof( IntPtr ) } );
       }
 
       static void Prefix( GUIContent content )
@@ -222,17 +222,17 @@ namespace XUnity.AutoTranslator.Plugin.Core.Hooks.IMGUI
       }
    }
 
-   [Harmony, HarmonyPriority( Priority.Last )]
+   [HarmonyPriorityShim( HookPriority.Last )]
    internal static class GUI_DoButton_Hook
    {
-      static bool Prepare( HarmonyInstance instance )
+      static bool Prepare( object instance )
       {
          return Constants.ClrTypes.GUI != null;
       }
 
-      static MethodBase TargetMethod( HarmonyInstance instance )
+      static MethodBase TargetMethod( object instance )
       {
-         return AccessTools.Method( Constants.ClrTypes.GUI, "DoButton", new[] { typeof( Rect ), typeof( GUIContent ), typeof( IntPtr ) } );
+         return AccessToolsShim.Method( Constants.ClrTypes.GUI, "DoButton", new[] { typeof( Rect ), typeof( GUIContent ), typeof( IntPtr ) } );
       }
 
       static void Prefix( GUIContent content )
@@ -244,17 +244,17 @@ namespace XUnity.AutoTranslator.Plugin.Core.Hooks.IMGUI
       }
    }
 
-   [Harmony, HarmonyPriority( Priority.Last )]
+   [HarmonyPriorityShim( HookPriority.Last )]
    internal static class GUI_DoModalWindow_Hook
    {
-      static bool Prepare( HarmonyInstance instance )
+      static bool Prepare( object instance )
       {
          return Constants.ClrTypes.GUI != null;
       }
 
-      static MethodBase TargetMethod( HarmonyInstance instance )
+      static MethodBase TargetMethod( object instance )
       {
-         return AccessTools.Method( Constants.ClrTypes.GUI, "DoModalWindow", new[] { typeof( int ), typeof( Rect ), typeof( WindowFunction ), typeof( GUIContent ), typeof( GUIStyle ), typeof( GUISkin ) } );
+         return AccessToolsShim.Method( Constants.ClrTypes.GUI, "DoModalWindow", new[] { typeof( int ), typeof( Rect ), typeof( WindowFunction ), typeof( GUIContent ), typeof( GUIStyle ), typeof( GUISkin ) } );
       }
 
       static void Prefix( GUIContent content )
@@ -266,17 +266,17 @@ namespace XUnity.AutoTranslator.Plugin.Core.Hooks.IMGUI
       }
    }
 
-   [Harmony, HarmonyPriority( Priority.Last )]
+   [HarmonyPriorityShim( HookPriority.Last )]
    internal static class GUI_DoWindow_Hook
    {
-      static bool Prepare( HarmonyInstance instance )
+      static bool Prepare( object instance )
       {
          return Constants.ClrTypes.GUI != null;
       }
 
-      static MethodBase TargetMethod( HarmonyInstance instance )
+      static MethodBase TargetMethod( object instance )
       {
-         return AccessTools.Method( Constants.ClrTypes.GUI, "DoWindow", new[] { typeof( int ), typeof( Rect ), typeof( WindowFunction ), typeof( GUIContent ), typeof( GUIStyle ), typeof( GUISkin ), typeof( bool ) } );
+         return AccessToolsShim.Method( Constants.ClrTypes.GUI, "DoWindow", new[] { typeof( int ), typeof( Rect ), typeof( WindowFunction ), typeof( GUIContent ), typeof( GUIStyle ), typeof( GUISkin ), typeof( bool ) } );
       }
 
       static void Prefix( GUIContent title )
@@ -288,17 +288,17 @@ namespace XUnity.AutoTranslator.Plugin.Core.Hooks.IMGUI
       }
    }
 
-   [Harmony, HarmonyPriority( Priority.Last )]
+   [HarmonyPriorityShim( HookPriority.Last )]
    internal static class GUI_DoButtonGrid_Hook
    {
-      static bool Prepare( HarmonyInstance instance )
+      static bool Prepare( object instance )
       {
          return Constants.ClrTypes.GUI != null;
       }
 
-      static MethodBase TargetMethod( HarmonyInstance instance )
+      static MethodBase TargetMethod( object instance )
       {
-         return AccessTools.Method( Constants.ClrTypes.GUI, "DoButtonGrid", new[] { typeof( Rect ), typeof( int ), typeof( GUIContent[] ), typeof( int ), typeof( GUIStyle ), typeof( GUIStyle ), typeof( GUIStyle ), typeof( GUIStyle ) } );
+         return AccessToolsShim.Method( Constants.ClrTypes.GUI, "DoButtonGrid", new[] { typeof( Rect ), typeof( int ), typeof( GUIContent[] ), typeof( int ), typeof( GUIStyle ), typeof( GUIStyle ), typeof( GUIStyle ), typeof( GUIStyle ) } );
       }
 
       static void Prefix( GUIContent[] contents )
@@ -313,17 +313,17 @@ namespace XUnity.AutoTranslator.Plugin.Core.Hooks.IMGUI
       }
    }
 
-   [Harmony, HarmonyPriority( Priority.Last )]
+   [HarmonyPriorityShim( HookPriority.Last )]
    internal static class GUI_DoTextField_Hook
    {
-      static bool Prepare( HarmonyInstance instance )
+      static bool Prepare( object instance )
       {
          return Constants.ClrTypes.GUI != null;
       }
 
-      static MethodBase TargetMethod( HarmonyInstance instance )
+      static MethodBase TargetMethod( object instance )
       {
-         return AccessTools.Method( Constants.ClrTypes.GUI, "DoTextField", new[] { typeof( Rect ), typeof( int ), typeof( GUIContent ), typeof( bool ), typeof( int ), typeof( GUIStyle ), typeof( string ) } );
+         return AccessToolsShim.Method( Constants.ClrTypes.GUI, "DoTextField", new[] { typeof( Rect ), typeof( int ), typeof( GUIContent ), typeof( bool ), typeof( int ), typeof( GUIStyle ), typeof( string ) } );
       }
 
       static void Prefix( GUIContent content )
@@ -335,17 +335,17 @@ namespace XUnity.AutoTranslator.Plugin.Core.Hooks.IMGUI
       }
    }
 
-   [Harmony, HarmonyPriority( Priority.Last )]
+   [HarmonyPriorityShim( HookPriority.Last )]
    internal static class GUI_DoToggle_Hook
    {
-      static bool Prepare( HarmonyInstance instance )
+      static bool Prepare( object instance )
       {
          return Constants.ClrTypes.GUI != null;
       }
 
-      static MethodBase TargetMethod( HarmonyInstance instance )
+      static MethodBase TargetMethod( object instance )
       {
-         return AccessTools.Method( Constants.ClrTypes.GUI, "DoToggle", new[] { typeof( Rect ), typeof( int ), typeof( bool ), typeof( GUIContent ), typeof( IntPtr ) } );
+         return AccessToolsShim.Method( Constants.ClrTypes.GUI, "DoToggle", new[] { typeof( Rect ), typeof( int ), typeof( bool ), typeof( GUIContent ), typeof( IntPtr ) } );
       }
 
       static void Prefix( GUIContent content )

+ 104 - 132
src/XUnity.AutoTranslator.Plugin.Core/Hooks/ImageHooks.cs

@@ -4,7 +4,6 @@ using System.Diagnostics;
 using System.Linq;
 using System.Reflection;
 using System.Text;
-using Harmony;
 using UnityEngine;
 using UnityEngine.UI;
 using XUnity.AutoTranslator.Plugin.Core.Constants;
@@ -47,18 +46,17 @@ namespace XUnity.AutoTranslator.Plugin.Core.Hooks
          typeof( DicingTextures_GetTexture_Hook ),
       };
    }
-
-   [Harmony]
+   
    internal static class DicingTextures_GetTexture_Hook
    {
-      static bool Prepare( HarmonyInstance instance )
+      static bool Prepare( object instance )
       {
          return ClrTypes.DicingTextures != null;
       }
 
-      static MethodBase TargetMethod( HarmonyInstance instance )
+      static MethodBase TargetMethod( object instance )
       {
-         return AccessTools.Method( ClrTypes.DicingTextures, "GetTexture", new[] { typeof( string ) } );
+         return AccessToolsShim.Method( ClrTypes.DicingTextures, "GetTexture", new[] { typeof( string ) } );
       }
 
       public static void Postfix( object __instance, Texture2D __result )
@@ -66,18 +64,17 @@ namespace XUnity.AutoTranslator.Plugin.Core.Hooks
          AutoTranslationPlugin.Current.Hook_ImageChanged( __result, false );
       }
    }
-
-   [Harmony]
+   
    internal static class Sprite_texture_Hook
    {
-      static bool Prepare( HarmonyInstance instance )
+      static bool Prepare( object instance )
       {
          return ClrTypes.Sprite != null;
       }
 
-      static MethodBase TargetMethod( HarmonyInstance instance )
+      static MethodBase TargetMethod( object instance )
       {
-         return AccessTools.Property( ClrTypes.Sprite, "texture" )?.GetGetMethod();
+         return AccessToolsShim.Property( ClrTypes.Sprite, "texture" )?.GetGetMethod();
       }
 
       static void Postfix( Texture2D __result )
@@ -87,18 +84,17 @@ namespace XUnity.AutoTranslator.Plugin.Core.Hooks
 
       static bool RequireRuntimeHooker => true;
    }
-
-   [Harmony]
+   
    internal static class SpriteRenderer_sprite_Hook
    {
-      static bool Prepare( HarmonyInstance instance )
+      static bool Prepare( object instance )
       {
          return ClrTypes.SpriteRenderer != null;
       }
 
-      static MethodBase TargetMethod( HarmonyInstance instance )
+      static MethodBase TargetMethod( object instance )
       {
-         return AccessTools.Property( ClrTypes.SpriteRenderer, "sprite" )?.GetSetMethod();
+         return AccessToolsShim.Property( ClrTypes.SpriteRenderer, "sprite" )?.GetSetMethod();
       }
 
       public static void Postfix( object __instance )
@@ -106,18 +102,17 @@ namespace XUnity.AutoTranslator.Plugin.Core.Hooks
          AutoTranslationPlugin.Current.Hook_ImageChangedOnComponent( __instance, null, false, false );
       }
    }
-
-   [Harmony]
+   
    internal static class CubismRenderer_MainTexture_Hook
    {
-      static bool Prepare( HarmonyInstance instance )
+      static bool Prepare( object instance )
       {
          return ClrTypes.CubismRenderer != null;
       }
 
-      static MethodBase TargetMethod( HarmonyInstance instance )
+      static MethodBase TargetMethod( object instance )
       {
-         return AccessTools.Property( ClrTypes.CubismRenderer, "MainTexture" )?.GetSetMethod();
+         return AccessToolsShim.Property( ClrTypes.CubismRenderer, "MainTexture" )?.GetSetMethod();
       }
 
       public static void Prefix( object __instance, Texture2D value )
@@ -125,18 +120,17 @@ namespace XUnity.AutoTranslator.Plugin.Core.Hooks
          AutoTranslationPlugin.Current.Hook_ImageChangedOnComponent( __instance, value, true , false);
       }
    }
-
-   [Harmony]
+   
    internal static class CubismRenderer_TryInitialize_Hook
    {
-      static bool Prepare( HarmonyInstance instance )
+      static bool Prepare( object instance )
       {
          return ClrTypes.CubismRenderer != null;
       }
 
-      static MethodBase TargetMethod( HarmonyInstance instance )
+      static MethodBase TargetMethod( object instance )
       {
-         return AccessTools.Method( ClrTypes.CubismRenderer, "TryInitialize" );
+         return AccessToolsShim.Method( ClrTypes.CubismRenderer, "TryInitialize" );
       }
 
       public static void Prefix( object __instance )
@@ -144,18 +138,17 @@ namespace XUnity.AutoTranslator.Plugin.Core.Hooks
          AutoTranslationPlugin.Current.Hook_ImageChangedOnComponent( __instance, null, true, true );
       }
    }
-
-   [Harmony]
+   
    internal static class Material_mainTexture_Hook
    {
-      static bool Prepare( HarmonyInstance instance )
+      static bool Prepare( object instance )
       {
          return true;
       }
 
-      static MethodBase TargetMethod( HarmonyInstance instance )
+      static MethodBase TargetMethod( object instance )
       {
-         return AccessTools.Property( typeof( Material ), "mainTexture" )?.GetSetMethod();
+         return AccessToolsShim.Property( typeof( Material ), "mainTexture" )?.GetSetMethod();
       }
 
       public static void Prefix( object __instance, Texture value )
@@ -166,18 +159,17 @@ namespace XUnity.AutoTranslator.Plugin.Core.Hooks
          }
       }
    }
-
-   [Harmony]
+   
    internal static class MaskableGraphic_OnEnable_Hook
    {
-      static bool Prepare( HarmonyInstance instance )
+      static bool Prepare( object instance )
       {
          return true;
       }
 
-      static MethodBase TargetMethod( HarmonyInstance instance )
+      static MethodBase TargetMethod( object instance )
       {
-         return AccessTools.Method( typeof( MaskableGraphic ), "OnEnable" );
+         return AccessToolsShim.Method( typeof( MaskableGraphic ), "OnEnable" );
       }
 
       public static void Postfix( object __instance )
@@ -188,18 +180,17 @@ namespace XUnity.AutoTranslator.Plugin.Core.Hooks
          }
       }
    }
-
-   [Harmony]
+   
    internal static class Image_sprite_Hook
    {
-      static bool Prepare( HarmonyInstance instance )
+      static bool Prepare( object instance )
       {
          return true;
       }
 
-      static MethodBase TargetMethod( HarmonyInstance instance )
+      static MethodBase TargetMethod( object instance )
       {
-         return AccessTools.Property( typeof( Image ), "sprite" )?.GetSetMethod();
+         return AccessToolsShim.Property( typeof( Image ), "sprite" )?.GetSetMethod();
       }
 
       public static void Postfix( object __instance )
@@ -207,18 +198,17 @@ namespace XUnity.AutoTranslator.Plugin.Core.Hooks
          AutoTranslationPlugin.Current.Hook_ImageChangedOnComponent( __instance, null, false, false );
       }
    }
-
-   [Harmony]
+   
    internal static class Image_overrideSprite_Hook
    {
-      static bool Prepare( HarmonyInstance instance )
+      static bool Prepare( object instance )
       {
          return true;
       }
 
-      static MethodBase TargetMethod( HarmonyInstance instance )
+      static MethodBase TargetMethod( object instance )
       {
-         return AccessTools.Property( typeof( Image ), "overrideSprite" )?.GetSetMethod();
+         return AccessToolsShim.Property( typeof( Image ), "overrideSprite" )?.GetSetMethod();
       }
 
       public static void Postfix( object __instance )
@@ -226,18 +216,17 @@ namespace XUnity.AutoTranslator.Plugin.Core.Hooks
          AutoTranslationPlugin.Current.Hook_ImageChangedOnComponent( __instance, null, false, false );
       }
    }
-
-   [Harmony]
+   
    internal static class Image_material_Hook
    {
-      static bool Prepare( HarmonyInstance instance )
+      static bool Prepare( object instance )
       {
          return true;
       }
 
-      static MethodBase TargetMethod( HarmonyInstance instance )
+      static MethodBase TargetMethod( object instance )
       {
-         return AccessTools.Property( typeof( Image ), "material" )?.GetSetMethod();
+         return AccessToolsShim.Property( typeof( Image ), "material" )?.GetSetMethod();
       }
 
       public static void Postfix( object __instance )
@@ -245,18 +234,17 @@ namespace XUnity.AutoTranslator.Plugin.Core.Hooks
          AutoTranslationPlugin.Current.Hook_ImageChangedOnComponent( __instance, null, false, false );
       }
    }
-
-   [Harmony]
+   
    internal static class RawImage_texture_Hook
    {
-      static bool Prepare( HarmonyInstance instance )
+      static bool Prepare( object instance )
       {
          return true;
       }
 
-      static MethodBase TargetMethod( HarmonyInstance instance )
+      static MethodBase TargetMethod( object instance )
       {
-         return AccessTools.Property( typeof( RawImage ), "texture" )?.GetSetMethod();
+         return AccessToolsShim.Property( typeof( RawImage ), "texture" )?.GetSetMethod();
       }
 
       public static void Prefix( object __instance, Texture value )
@@ -267,18 +255,17 @@ namespace XUnity.AutoTranslator.Plugin.Core.Hooks
          }
       }
    }
-
-   [Harmony]
+   
    internal static class Cursor_SetCursor_Hook
    {
-      static bool Prepare( HarmonyInstance instance )
+      static bool Prepare( object instance )
       {
          return true;
       }
 
-      static MethodBase TargetMethod( HarmonyInstance instance )
+      static MethodBase TargetMethod( object instance )
       {
-         return AccessTools.Method( typeof( Cursor ), "SetCursor", new[] { typeof( Texture2D ), typeof( Vector2 ), typeof( CursorMode ) } );
+         return AccessToolsShim.Method( typeof( Cursor ), "SetCursor", new[] { typeof( Texture2D ), typeof( Vector2 ), typeof( CursorMode ) } );
       }
 
       public static void Prefix( Texture2D texture )
@@ -286,18 +273,17 @@ namespace XUnity.AutoTranslator.Plugin.Core.Hooks
          AutoTranslationPlugin.Current.Hook_ImageChanged( texture, true );
       }
    }
-
-   [Harmony]
+   
    internal static class UIAtlas_spriteMaterial_Hook
    {
-      static bool Prepare( HarmonyInstance instance )
+      static bool Prepare( object instance )
       {
          return ClrTypes.UIAtlas != null;
       }
 
-      static MethodBase TargetMethod( HarmonyInstance instance )
+      static MethodBase TargetMethod( object instance )
       {
-         return AccessTools.Property( ClrTypes.UIAtlas, "spriteMaterial" )?.GetSetMethod();
+         return AccessToolsShim.Property( ClrTypes.UIAtlas, "spriteMaterial" )?.GetSetMethod();
       }
 
       public static void Postfix( object __instance )
@@ -305,18 +291,17 @@ namespace XUnity.AutoTranslator.Plugin.Core.Hooks
          AutoTranslationPlugin.Current.Hook_ImageChangedOnComponent( __instance, null, false, false );
       }
    }
-
-   [Harmony]
+   
    internal static class UISprite_OnInit_Hook
    {
-      static bool Prepare( HarmonyInstance instance )
+      static bool Prepare( object instance )
       {
          return ClrTypes.UISprite != null;
       }
 
-      static MethodBase TargetMethod( HarmonyInstance instance )
+      static MethodBase TargetMethod( object instance )
       {
-         return AccessTools.Method( Constants.ClrTypes.UISprite, "OnInit" );
+         return AccessToolsShim.Method( Constants.ClrTypes.UISprite, "OnInit" );
       }
 
       public static void Postfix( object __instance )
@@ -324,18 +309,17 @@ namespace XUnity.AutoTranslator.Plugin.Core.Hooks
          AutoTranslationPlugin.Current.Hook_ImageChangedOnComponent( __instance, null, false, true );
       }
    }
-
-   [Harmony]
+   
    internal static class UISprite_material_Hook
    {
-      static bool Prepare( HarmonyInstance instance )
+      static bool Prepare( object instance )
       {
          return ClrTypes.UISprite != null;
       }
 
-      static MethodBase TargetMethod( HarmonyInstance instance )
+      static MethodBase TargetMethod( object instance )
       {
-         return AccessTools.Property( ClrTypes.UISprite, "material" )?.GetSetMethod();
+         return AccessToolsShim.Property( ClrTypes.UISprite, "material" )?.GetSetMethod();
       }
 
       public static void Postfix( object __instance )
@@ -343,18 +327,17 @@ namespace XUnity.AutoTranslator.Plugin.Core.Hooks
          AutoTranslationPlugin.Current.Hook_ImageChangedOnComponent( __instance, null, false, false );
       }
    }
-
-   [Harmony]
+   
    internal static class UISprite_atlas_Hook
    {
-      static bool Prepare( HarmonyInstance instance )
+      static bool Prepare( object instance )
       {
          return ClrTypes.UISprite != null;
       }
 
-      static MethodBase TargetMethod( HarmonyInstance instance )
+      static MethodBase TargetMethod( object instance )
       {
-         return AccessTools.Property( ClrTypes.UISprite, "atlas" )?.GetSetMethod();
+         return AccessToolsShim.Property( ClrTypes.UISprite, "atlas" )?.GetSetMethod();
       }
 
       public static void Postfix( object __instance )
@@ -362,18 +345,17 @@ namespace XUnity.AutoTranslator.Plugin.Core.Hooks
          AutoTranslationPlugin.Current.Hook_ImageChangedOnComponent( __instance, null, false, false );
       }
    }
-
-   [Harmony]
+   
    internal static class UITexture_mainTexture_Hook
    {
-      static bool Prepare( HarmonyInstance instance )
+      static bool Prepare( object instance )
       {
          return ClrTypes.UITexture != null;
       }
 
-      static MethodBase TargetMethod( HarmonyInstance instance )
+      static MethodBase TargetMethod( object instance )
       {
-         return AccessTools.Property( ClrTypes.UITexture, "mainTexture" )?.GetSetMethod();
+         return AccessToolsShim.Property( ClrTypes.UITexture, "mainTexture" )?.GetSetMethod();
       }
 
       public static void Postfix( object __instance )
@@ -381,18 +363,17 @@ namespace XUnity.AutoTranslator.Plugin.Core.Hooks
          AutoTranslationPlugin.Current.Hook_ImageChangedOnComponent( __instance, null, false, false );
       }
    }
-
-   [Harmony]
+   
    internal static class UITexture_material_Hook
    {
-      static bool Prepare( HarmonyInstance instance )
+      static bool Prepare( object instance )
       {
          return ClrTypes.UITexture != null;
       }
 
-      static MethodBase TargetMethod( HarmonyInstance instance )
+      static MethodBase TargetMethod( object instance )
       {
-         return AccessTools.Property( ClrTypes.UITexture, "material" )?.GetSetMethod();
+         return AccessToolsShim.Property( ClrTypes.UITexture, "material" )?.GetSetMethod();
       }
 
       public static void Postfix( object __instance )
@@ -400,18 +381,17 @@ namespace XUnity.AutoTranslator.Plugin.Core.Hooks
          AutoTranslationPlugin.Current.Hook_ImageChangedOnComponent( __instance, null, false, false );
       }
    }
-
-   [Harmony]
+   
    internal static class UIRect_OnInit_Hook
    {
-      static bool Prepare( HarmonyInstance instance )
+      static bool Prepare( object instance )
       {
          return ClrTypes.UIRect != null;
       }
 
-      static MethodBase TargetMethod( HarmonyInstance instance )
+      static MethodBase TargetMethod( object instance )
       {
-         return AccessTools.Method( ClrTypes.UIRect, "OnInit" );
+         return AccessToolsShim.Method( ClrTypes.UIRect, "OnInit" );
       }
 
       public static void Postfix( object __instance )
@@ -419,18 +399,17 @@ namespace XUnity.AutoTranslator.Plugin.Core.Hooks
          AutoTranslationPlugin.Current.Hook_ImageChangedOnComponent( __instance, null, false, true );
       }
    }
-
-   [Harmony]
+   
    internal static class UI2DSprite_sprite2D_Hook
    {
-      static bool Prepare( HarmonyInstance instance )
+      static bool Prepare( object instance )
       {
          return ClrTypes.UI2DSprite != null;
       }
 
-      static MethodBase TargetMethod( HarmonyInstance instance )
+      static MethodBase TargetMethod( object instance )
       {
-         return AccessTools.Property( ClrTypes.UI2DSprite, "sprite2D" )?.GetSetMethod();
+         return AccessToolsShim.Property( ClrTypes.UI2DSprite, "sprite2D" )?.GetSetMethod();
       }
 
       public static void Postfix( object __instance )
@@ -438,18 +417,17 @@ namespace XUnity.AutoTranslator.Plugin.Core.Hooks
          AutoTranslationPlugin.Current.Hook_ImageChangedOnComponent( __instance, null, false, false );
       }
    }
-
-   [Harmony]
+   
    internal static class UI2DSprite_material_Hook
    {
-      static bool Prepare( HarmonyInstance instance )
+      static bool Prepare( object instance )
       {
          return ClrTypes.UI2DSprite != null;
       }
 
-      static MethodBase TargetMethod( HarmonyInstance instance )
+      static MethodBase TargetMethod( object instance )
       {
-         return AccessTools.Property( ClrTypes.UI2DSprite, "material" )?.GetSetMethod();
+         return AccessToolsShim.Property( ClrTypes.UI2DSprite, "material" )?.GetSetMethod();
       }
 
       public static void Postfix( object __instance )
@@ -457,18 +435,17 @@ namespace XUnity.AutoTranslator.Plugin.Core.Hooks
          AutoTranslationPlugin.Current.Hook_ImageChangedOnComponent( __instance, null, false, false );
       }
    }
-
-   [Harmony]
+   
    internal static class UIPanel_clipTexture_Hook
    {
-      static bool Prepare( HarmonyInstance instance )
+      static bool Prepare( object instance )
       {
          return ClrTypes.UIPanel != null;
       }
 
-      static MethodBase TargetMethod( HarmonyInstance instance )
+      static MethodBase TargetMethod( object instance )
       {
-         return AccessTools.Property( ClrTypes.UIPanel, "clipTexture" )?.GetSetMethod();
+         return AccessToolsShim.Property( ClrTypes.UIPanel, "clipTexture" )?.GetSetMethod();
       }
 
       public static void Postfix( object __instance )
@@ -476,19 +453,17 @@ namespace XUnity.AutoTranslator.Plugin.Core.Hooks
          AutoTranslationPlugin.Current.Hook_ImageChangedOnComponent( __instance, null, false, false );
       }
    }
-
-
-   [Harmony]
+   
    internal static class UIFont_material_Hook
    {
-      static bool Prepare( HarmonyInstance instance )
+      static bool Prepare( object instance )
       {
          return ClrTypes.UIFont != null;
       }
 
-      static MethodBase TargetMethod( HarmonyInstance instance )
+      static MethodBase TargetMethod( object instance )
       {
-         return AccessTools.Property( ClrTypes.UIFont, "material" )?.GetSetMethod();
+         return AccessToolsShim.Property( ClrTypes.UIFont, "material" )?.GetSetMethod();
       }
 
       public static void Postfix( object __instance )
@@ -496,18 +471,17 @@ namespace XUnity.AutoTranslator.Plugin.Core.Hooks
          AutoTranslationPlugin.Current.Hook_ImageChangedOnComponent( __instance, null, false, false );
       }
    }
-
-   [Harmony]
+   
    internal static class UIFont_dynamicFont_Hook
    {
-      static bool Prepare( HarmonyInstance instance )
+      static bool Prepare( object instance )
       {
          return ClrTypes.UIFont != null;
       }
 
-      static MethodBase TargetMethod( HarmonyInstance instance )
+      static MethodBase TargetMethod( object instance )
       {
-         return AccessTools.Property( ClrTypes.UIFont, "dynamicFont" )?.GetSetMethod();
+         return AccessToolsShim.Property( ClrTypes.UIFont, "dynamicFont" )?.GetSetMethod();
       }
 
       public static void Postfix( object __instance )
@@ -515,18 +489,17 @@ namespace XUnity.AutoTranslator.Plugin.Core.Hooks
          AutoTranslationPlugin.Current.Hook_ImageChangedOnComponent( __instance, null, false, false );
       }
    }
-
-   [Harmony]
+   
    internal static class UILabel_bitmapFont_Hook
    {
-      static bool Prepare( HarmonyInstance instance )
+      static bool Prepare( object instance )
       {
          return ClrTypes.UILabel != null;
       }
 
-      static MethodBase TargetMethod( HarmonyInstance instance )
+      static MethodBase TargetMethod( object instance )
       {
-         return AccessTools.Property( ClrTypes.UILabel, "bitmapFont" )?.GetSetMethod();
+         return AccessToolsShim.Property( ClrTypes.UILabel, "bitmapFont" )?.GetSetMethod();
       }
 
       public static void Postfix( object __instance )
@@ -534,18 +507,17 @@ namespace XUnity.AutoTranslator.Plugin.Core.Hooks
          AutoTranslationPlugin.Current.Hook_ImageChangedOnComponent( __instance, null, false, false );
       }
    }
-
-   [Harmony]
+   
    internal static class UILabel_trueTypeFont_Hook
    {
-      static bool Prepare( HarmonyInstance instance )
+      static bool Prepare( object instance )
       {
          return ClrTypes.UILabel != null;
       }
 
-      static MethodBase TargetMethod( HarmonyInstance instance )
+      static MethodBase TargetMethod( object instance )
       {
-         return AccessTools.Property( ClrTypes.UILabel, "trueTypeFont" )?.GetSetMethod();
+         return AccessToolsShim.Property( ClrTypes.UILabel, "trueTypeFont" )?.GetSetMethod();
       }
 
       public static void Postfix( object __instance )

+ 9 - 9
src/XUnity.AutoTranslator.Plugin.Core/Hooks/NGUIHooks.cs

@@ -4,9 +4,9 @@ using System.Linq;
 using System.Reflection;
 using System.Reflection.Emit;
 using System.Text;
-using Harmony;
 using UnityEngine;
 using XUnity.AutoTranslator.Plugin.Core.Constants;
+using XUnity.RuntimeHooker.Core;
 
 namespace XUnity.AutoTranslator.Plugin.Core.Hooks.NGUI
 {
@@ -20,17 +20,17 @@ namespace XUnity.AutoTranslator.Plugin.Core.Hooks.NGUI
       };
    }
 
-   [Harmony, HarmonyPriority( Priority.Last )]
+   [HarmonyPriorityShim( HookPriority.Last )]
    internal static class UILabel_text_Hook
    {
-      static bool Prepare( HarmonyInstance instance )
+      static bool Prepare( object instance )
       {
          return Constants.ClrTypes.UILabel != null;
       }
 
-      static MethodBase TargetMethod( HarmonyInstance instance )
+      static MethodBase TargetMethod( object instance )
       {
-         return AccessTools.Property( Constants.ClrTypes.UILabel, "text" )?.GetSetMethod();
+         return AccessToolsShim.Property( Constants.ClrTypes.UILabel, "text" )?.GetSetMethod();
       }
 
       public static void Postfix( object __instance )
@@ -43,17 +43,17 @@ namespace XUnity.AutoTranslator.Plugin.Core.Hooks.NGUI
       }
    }
 
-   [Harmony, HarmonyPriority( Priority.Last )]
+   [HarmonyPriorityShim( HookPriority.Last )]
    internal static class UILabel_OnEnable_Hook
    {
-      static bool Prepare( HarmonyInstance instance )
+      static bool Prepare( object instance )
       {
          return Constants.ClrTypes.UILabel != null;
       }
 
-      static MethodBase TargetMethod( HarmonyInstance instance )
+      static MethodBase TargetMethod( object instance )
       {
-         return AccessTools.Method( Constants.ClrTypes.UILabel, "OnEnable" );
+         return AccessToolsShim.Method( Constants.ClrTypes.UILabel, "OnEnable" );
       }
 
       public static void Postfix( object __instance )

+ 8 - 11
src/XUnity.AutoTranslator.Plugin.Core/Hooks/TextGetterCompatHooks.cs

@@ -1,6 +1,5 @@
 using System;
 using System.Reflection;
-using Harmony;
 using XUnity.AutoTranslator.Plugin.Core.Constants;
 using XUnity.AutoTranslator.Plugin.Core.Utilities;
 
@@ -13,18 +12,17 @@ namespace XUnity.AutoTranslator.Plugin.Core.Hooks.TextGetterCompat
          typeof( TMP_Text_text_Hook ),
       };
    }
-
-   [Harmony]
+   
    internal static class Text_text_Hook
    {
-      static bool Prepare( HarmonyInstance instance )
+      static bool Prepare( object instance )
       {
          return ClrTypes.Text != null;
       }
 
-      static MethodBase TargetMethod( HarmonyInstance instance )
+      static MethodBase TargetMethod( object instance )
       {
-         return AccessTools.Property( ClrTypes.Text, "text" )?.GetGetMethod();
+         return AccessToolsShim.Property( ClrTypes.Text, "text" )?.GetGetMethod();
       }
 
       static void Postfix( object __instance, ref string __result )
@@ -32,18 +30,17 @@ namespace XUnity.AutoTranslator.Plugin.Core.Hooks.TextGetterCompat
          TextGetterCompatModeHelper.ReplaceTextWithOriginal( __instance, ref __result );
       }
    }
-
-   [Harmony]
+   
    internal static class TMP_Text_text_Hook
    {
-      static bool Prepare( HarmonyInstance instance )
+      static bool Prepare( object instance )
       {
          return ClrTypes.TMP_Text != null;
       }
 
-      static MethodBase TargetMethod( HarmonyInstance instance )
+      static MethodBase TargetMethod( object instance )
       {
-         return AccessTools.Property( ClrTypes.TMP_Text, "text" )?.GetGetMethod();
+         return AccessToolsShim.Property( ClrTypes.TMP_Text, "text" )?.GetGetMethod();
       }
 
       static void Postfix( object __instance, ref string __result )

+ 37 - 37
src/XUnity.AutoTranslator.Plugin.Core/Hooks/TextMeshProHooks.cs

@@ -4,8 +4,8 @@ using System.Diagnostics;
 using System.Linq;
 using System.Reflection;
 using System.Text;
-using Harmony;
 using XUnity.AutoTranslator.Plugin.Core.Constants;
+using XUnity.RuntimeHooker.Core;
 
 namespace XUnity.AutoTranslator.Plugin.Core.Hooks.TextMeshPro
 {
@@ -26,17 +26,17 @@ namespace XUnity.AutoTranslator.Plugin.Core.Hooks.TextMeshPro
       };
    }
 
-   [Harmony, HarmonyPriority( Priority.Last )]
+   [HarmonyPriorityShim( HookPriority.Last )]
    internal static class TeshMeshProUGUI_OnEnable_Hook
    {
-      static bool Prepare( HarmonyInstance instance )
+      static bool Prepare( object instance )
       {
          return ClrTypes.TextMeshProUGUI != null;
       }
 
-      static MethodBase TargetMethod( HarmonyInstance instance )
+      static MethodBase TargetMethod( object instance )
       {
-         return AccessTools.Method( ClrTypes.TextMeshProUGUI, "OnEnable" );
+         return AccessToolsShim.Method( ClrTypes.TextMeshProUGUI, "OnEnable" );
       }
 
       static void Postfix( object __instance )
@@ -49,17 +49,17 @@ namespace XUnity.AutoTranslator.Plugin.Core.Hooks.TextMeshPro
       }
    }
 
-   [Harmony, HarmonyPriority( Priority.Last )]
+   [HarmonyPriorityShim( HookPriority.Last )]
    internal static class TeshMeshPro_OnEnable_Hook
    {
-      static bool Prepare( HarmonyInstance instance )
+      static bool Prepare( object instance )
       {
          return ClrTypes.TextMeshPro != null;
       }
 
-      static MethodBase TargetMethod( HarmonyInstance instance )
+      static MethodBase TargetMethod( object instance )
       {
-         return AccessTools.Method( ClrTypes.TextMeshPro, "OnEnable" );
+         return AccessToolsShim.Method( ClrTypes.TextMeshPro, "OnEnable" );
       }
 
       static void Postfix( object __instance )
@@ -72,17 +72,17 @@ namespace XUnity.AutoTranslator.Plugin.Core.Hooks.TextMeshPro
       }
    }
 
-   [Harmony, HarmonyPriority( Priority.Last )]
+   [HarmonyPriorityShim( HookPriority.Last )]
    internal static class TMP_Text_text_Hook
    {
-      static bool Prepare( HarmonyInstance instance )
+      static bool Prepare( object instance )
       {
          return ClrTypes.TMP_Text != null;
       }
 
-      static MethodBase TargetMethod( HarmonyInstance instance )
+      static MethodBase TargetMethod( object instance )
       {
-         return AccessTools.Property( ClrTypes.TMP_Text, "text" )?.GetSetMethod();
+         return AccessToolsShim.Property( ClrTypes.TMP_Text, "text" )?.GetSetMethod();
       }
 
       static void Postfix( object __instance )
@@ -108,17 +108,17 @@ namespace XUnity.AutoTranslator.Plugin.Core.Hooks.TextMeshPro
       //}
    }
 
-   [Harmony, HarmonyPriority( Priority.Last )]
+   [HarmonyPriorityShim( HookPriority.Last )]
    internal static class TMP_Text_SetText_Hook1
    {
-      static bool Prepare( HarmonyInstance instance )
+      static bool Prepare( object instance )
       {
          return ClrTypes.TMP_Text != null;
       }
 
-      static MethodBase TargetMethod( HarmonyInstance instance )
+      static MethodBase TargetMethod( object instance )
       {
-         return AccessTools.Method( ClrTypes.TMP_Text, "SetText", new[] { typeof( StringBuilder ) } );
+         return AccessToolsShim.Method( ClrTypes.TMP_Text, "SetText", new[] { typeof( StringBuilder ) } );
       }
 
       static void Postfix( object __instance )
@@ -131,17 +131,17 @@ namespace XUnity.AutoTranslator.Plugin.Core.Hooks.TextMeshPro
       }
    }
 
-   [Harmony, HarmonyPriority( Priority.Last )]
+   [HarmonyPriorityShim( HookPriority.Last )]
    internal static class TMP_Text_SetText_Hook2
    {
-      static bool Prepare( HarmonyInstance instance )
+      static bool Prepare( object instance )
       {
          return ClrTypes.TMP_Text != null;
       }
 
-      static MethodBase TargetMethod( HarmonyInstance instance )
+      static MethodBase TargetMethod( object instance )
       {
-         return AccessTools.Method( ClrTypes.TMP_Text, "SetText", new[] { typeof( string ), typeof( bool ) } );
+         return AccessToolsShim.Method( ClrTypes.TMP_Text, "SetText", new[] { typeof( string ), typeof( bool ) } );
       }
 
       static void Postfix( object __instance )
@@ -154,17 +154,17 @@ namespace XUnity.AutoTranslator.Plugin.Core.Hooks.TextMeshPro
       }
    }
 
-   [Harmony, HarmonyPriority( Priority.Last )]
+   [HarmonyPriorityShim( HookPriority.Last )]
    internal static class TMP_Text_SetText_Hook3
    {
-      static bool Prepare( HarmonyInstance instance )
+      static bool Prepare( object instance )
       {
          return ClrTypes.TMP_Text != null;
       }
 
-      static MethodBase TargetMethod( HarmonyInstance instance )
+      static MethodBase TargetMethod( object instance )
       {
-         return AccessTools.Method( ClrTypes.TMP_Text, "SetText", new[] { typeof( string ), typeof( float ), typeof( float ), typeof( float ) } );
+         return AccessToolsShim.Method( ClrTypes.TMP_Text, "SetText", new[] { typeof( string ), typeof( float ), typeof( float ), typeof( float ) } );
       }
 
       static void Postfix( object __instance )
@@ -177,17 +177,17 @@ namespace XUnity.AutoTranslator.Plugin.Core.Hooks.TextMeshPro
       }
    }
 
-   [Harmony, HarmonyPriority( Priority.Last )]
+   [HarmonyPriorityShim( HookPriority.Last )]
    internal static class TMP_Text_SetCharArray_Hook1
    {
-      static bool Prepare( HarmonyInstance instance )
+      static bool Prepare( object instance )
       {
          return ClrTypes.TMP_Text != null;
       }
 
-      static MethodBase TargetMethod( HarmonyInstance instance )
+      static MethodBase TargetMethod( object instance )
       {
-         return AccessTools.Method( ClrTypes.TMP_Text, "SetCharArray", new[] { typeof( char[] ) } );
+         return AccessToolsShim.Method( ClrTypes.TMP_Text, "SetCharArray", new[] { typeof( char[] ) } );
       }
 
       static void Postfix( object __instance )
@@ -200,17 +200,17 @@ namespace XUnity.AutoTranslator.Plugin.Core.Hooks.TextMeshPro
       }
    }
 
-   [Harmony, HarmonyPriority( Priority.Last )]
+   [HarmonyPriorityShim( HookPriority.Last )]
    internal static class TMP_Text_SetCharArray_Hook2
    {
-      static bool Prepare( HarmonyInstance instance )
+      static bool Prepare( object instance )
       {
          return ClrTypes.TMP_Text != null;
       }
 
-      static MethodBase TargetMethod( HarmonyInstance instance )
+      static MethodBase TargetMethod( object instance )
       {
-         return AccessTools.Method( ClrTypes.TMP_Text, "SetCharArray", new[] { typeof( char[] ), typeof( int ), typeof( int ) } );
+         return AccessToolsShim.Method( ClrTypes.TMP_Text, "SetCharArray", new[] { typeof( char[] ), typeof( int ), typeof( int ) } );
       }
 
       static void Postfix( object __instance )
@@ -223,17 +223,17 @@ namespace XUnity.AutoTranslator.Plugin.Core.Hooks.TextMeshPro
       }
    }
 
-   [Harmony, HarmonyPriority( Priority.Last )]
+   [HarmonyPriorityShim( HookPriority.Last )]
    internal static class TMP_Text_SetCharArray_Hook3
    {
-      static bool Prepare( HarmonyInstance instance )
+      static bool Prepare( object instance )
       {
          return ClrTypes.TMP_Text != null;
       }
 
-      static MethodBase TargetMethod( HarmonyInstance instance )
+      static MethodBase TargetMethod( object instance )
       {
-         return AccessTools.Method( ClrTypes.TMP_Text, "SetCharArray", new[] { typeof( int[] ), typeof( int ), typeof( int ) } );
+         return AccessToolsShim.Method( ClrTypes.TMP_Text, "SetCharArray", new[] { typeof( int[] ), typeof( int ), typeof( int ) } );
       }
 
       static void Postfix( object __instance )

+ 9 - 9
src/XUnity.AutoTranslator.Plugin.Core/Hooks/UGUIHooks.cs

@@ -3,8 +3,8 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Reflection;
 using System.Text;
-using Harmony;
 using XUnity.AutoTranslator.Plugin.Core.Constants;
+using XUnity.RuntimeHooker.Core;
 
 namespace XUnity.AutoTranslator.Plugin.Core.Hooks.UGUI
 {
@@ -18,17 +18,17 @@ namespace XUnity.AutoTranslator.Plugin.Core.Hooks.UGUI
       };
    }
 
-   [Harmony, HarmonyPriority( Priority.Last )]
+   [HarmonyPriorityShim( HookPriority.Last )]
    internal static class Text_text_Hook
    {
-      static bool Prepare( HarmonyInstance instance )
+      static bool Prepare( object instance )
       {
          return ClrTypes.Text != null;
       }
 
-      static MethodBase TargetMethod( HarmonyInstance instance )
+      static MethodBase TargetMethod( object instance )
       {
-         return AccessTools.Property( ClrTypes.Text, "text" )?.GetSetMethod();
+         return AccessToolsShim.Property( ClrTypes.Text, "text" )?.GetSetMethod();
       }
 
       static void Postfix( object __instance )
@@ -41,17 +41,17 @@ namespace XUnity.AutoTranslator.Plugin.Core.Hooks.UGUI
       }
    }
 
-   [Harmony, HarmonyPriority( Priority.Last )]
+   [HarmonyPriorityShim( HookPriority.Last )]
    internal static class Text_OnEnable_Hook
    {
-      static bool Prepare( HarmonyInstance instance )
+      static bool Prepare( object instance )
       {
          return ClrTypes.Text != null;
       }
 
-      static MethodBase TargetMethod( HarmonyInstance instance )
+      static MethodBase TargetMethod( object instance )
       {
-         return AccessTools.Method( ClrTypes.Text, "OnEnable" );
+         return AccessToolsShim.Method( ClrTypes.Text, "OnEnable" );
       }
 
       static void Postfix( object __instance )

+ 19 - 25
src/XUnity.AutoTranslator.Plugin.Core/Hooks/UtageHooks.cs

@@ -3,7 +3,6 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Reflection;
 using System.Text;
-using Harmony;
 using XUnity.AutoTranslator.Plugin.Core.Configuration;
 using XUnity.AutoTranslator.Plugin.Core.Constants;
 using XUnity.AutoTranslator.Plugin.Core.Utilities;
@@ -20,16 +19,15 @@ namespace XUnity.AutoTranslator.Plugin.Core.Hooks
          typeof( AdvPage_RemakeTextData_Hook ),
       };
    }
-
-   //[Harmony]
+   
    //internal static class AdvCommand_ParseCellLocalizedText_Hook
    //{
-   //   static bool Prepare( HarmonyInstance instance )
+   //   static bool Prepare( object instance )
    //   {
    //      return ClrTypes.AdvCommand != null && AdvPage_RemakeTextData_Hook.TargetMethod( instance ) == null;
    //   }
 
-   //   static MethodBase TargetMethod( HarmonyInstance instance )
+   //   static MethodBase TargetMethod( object instance )
    //   {
    //      return AccessTools.Method( ClrTypes.AdvCommand, "ParseCellLocalizedText", new Type[] { } );
    //   }
@@ -43,18 +41,17 @@ namespace XUnity.AutoTranslator.Plugin.Core.Hooks
    //      }
    //   }
    //}
-
-   [Harmony]
+   
    internal static class AdvEngine_JumpScenario_Hook
    {
-      static bool Prepare( HarmonyInstance instance )
+      static bool Prepare( object instance )
       {
          return ClrTypes.AdvEngine != null;
       }
 
-      static MethodBase TargetMethod( HarmonyInstance instance )
+      static MethodBase TargetMethod( object instance )
       {
-         return AccessTools.Method( ClrTypes.AdvEngine, "JumpScenario", new Type[] { typeof( string ) } );
+         return AccessToolsShim.Method( ClrTypes.AdvEngine, "JumpScenario", new Type[] { typeof( string ) } );
       }
 
       static void Prefix( ref string label )
@@ -62,18 +59,17 @@ namespace XUnity.AutoTranslator.Plugin.Core.Hooks
          UtageHelper.FixLabel( ref label );
       }
    }
-
-   [Harmony]
+   
    internal static class UnityEventBase_Invoke_Hook
    {
-      static bool Prepare( HarmonyInstance instance )
+      static bool Prepare( object instance )
       {
          return ClrTypes.UnityEventBase != null;
       }
 
-      static MethodBase TargetMethod( HarmonyInstance instance )
+      static MethodBase TargetMethod( object instance )
       {
-         return AccessTools.Method( ClrTypes.UnityEventBase, "Invoke", new Type[] { typeof( object[] ) } );
+         return AccessToolsShim.Method( ClrTypes.UnityEventBase, "Invoke", new Type[] { typeof( object[] ) } );
       }
 
       static bool Prefix()
@@ -81,18 +77,17 @@ namespace XUnity.AutoTranslator.Plugin.Core.Hooks
          return Settings.InvokeEvents;
       }
    }
-
-   [Harmony]
+   
    internal static class UnityEventBase_PrepareInvoke_Hook
    {
       private static MethodInfo Method;
       private static object DefaultResult;
 
-      static bool Prepare( HarmonyInstance instance )
+      static bool Prepare( object instance )
       {
          try
          {
-            Method = AccessTools.Method( ClrTypes.UnityEventBase, "PrepareInvoke" );
+            Method = AccessToolsShim.Method( ClrTypes.UnityEventBase, "PrepareInvoke" );
             DefaultResult = Activator.CreateInstance( typeof( List<> ).MakeGenericType( ClrTypes.BaseInvokableCall ) );
 
             return Method != null;
@@ -105,7 +100,7 @@ namespace XUnity.AutoTranslator.Plugin.Core.Hooks
          return false;
       }
 
-      static MethodBase TargetMethod( HarmonyInstance instance )
+      static MethodBase TargetMethod( object instance )
       {
          return Method;
       }
@@ -118,18 +113,17 @@ namespace XUnity.AutoTranslator.Plugin.Core.Hooks
          }
       }
    }
-
-   [Harmony]
+   
    internal static class AdvPage_RemakeTextData_Hook
    {
-      static bool Prepare( HarmonyInstance instance )
+      static bool Prepare( object instance )
       {
          return ClrTypes.AdvPage != null;
       }
 
-      static MethodBase TargetMethod( HarmonyInstance instance )
+      static MethodBase TargetMethod( object instance )
       {
-         return AccessTools.Method( ClrTypes.AdvPage, "RemakeTextData" );
+         return AccessToolsShim.Method( ClrTypes.AdvPage, "RemakeTextData" );
       }
 
       static bool Prefix( object __instance )

+ 3 - 3
src/XUnity.AutoTranslator.Plugin.Core/TextTranslationInfo.cs

@@ -2,13 +2,13 @@
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
-using Harmony;
 using UnityEngine;
 using UnityEngine.UI;
 using XUnity.AutoTranslator.Plugin.Core.Configuration;
 using XUnity.AutoTranslator.Plugin.Core.Constants;
 using XUnity.AutoTranslator.Plugin.Core.Extensions;
 using XUnity.AutoTranslator.Plugin.Core.Fonts;
+using XUnity.AutoTranslator.Plugin.Core.Hooks;
 
 namespace XUnity.AutoTranslator.Plugin.Core
 {
@@ -44,7 +44,7 @@ namespace XUnity.AutoTranslator.Plugin.Core
          {
             _hasCheckedTypeWriter = true;
 
-            if( Constants.ClrTypes.Typewriter != null )
+            if( ClrTypes.Typewriter != null )
             {
                var ui = graphic as Component;
                if( ui != null )
@@ -56,7 +56,7 @@ namespace XUnity.AutoTranslator.Plugin.Core
 
          if( _typewriter != null )
          {
-            AccessTools.Method( Constants.ClrTypes.Typewriter, "OnEnable" )?.Invoke( _typewriter, null );
+            AccessToolsShim.Method( ClrTypes.Typewriter, "OnEnable" )?.Invoke( _typewriter, null );
          }
       }
 

+ 13 - 12
src/XUnity.AutoTranslator.Plugin.Core/UntranslatedText.cs

@@ -88,6 +88,7 @@ namespace XUnity.AutoTranslator.Plugin.Core
                   u++;
                   o--;
                   int l = o - u;
+                  char lastCharAdded = default( char );
                   if( l > 0 )
                   {
                      char currentWhitespaceChar = text[ u ];
@@ -108,26 +109,26 @@ namespace XUnity.AutoTranslator.Plugin.Core
                            }
 
                            builder.Append( ch );
+                           lastCharAdded = ch;
                         }
                         else
                         {
                            addedCurrentWhitespace = false;
                            currentWhitespaceChar = ch;
                         }
+                     }
+                  }
 
-                        // FIXME: Test this...
-                        if( Settings.UsesWhitespaceBetweenWords && ( ch == '\n' || ch == '\r' ) )
+                  // we know we have just handled a newline
+                  // now we need to check if the last character added is a whitespace character
+                  // if it is not, we should add a space
+                  if( Settings.UsesWhitespaceBetweenWords )
+                  {
+                     if( !char.IsWhiteSpace( lastCharAdded ) )
+                     {
+                        if( builder.Length > 0 && builder[ builder.Length - 1 ] != ' ' )
                         {
-                           if( builder.Length > 0 && builder[ builder.Length - 1 ] != ' ' )
-                           {
-                              builder.Append( ' ' );
-                           }
-
-                           var nextK = k + 1;
-                           if( nextK < lastNonWhitespace && text[ nextK ] == '\n' )
-                           {
-                              k++;
-                           }
+                           builder.Append( ' ' );
                         }
                      }
                   }

+ 0 - 1
src/XUnity.AutoTranslator.Plugin.Core/Web/XUnityWebClient.cs

@@ -7,7 +7,6 @@ using System.Linq;
 using System.Net;
 using System.Reflection;
 using System.Text;
-using Harmony;
 using UnityEngine;
 using XUnity.AutoTranslator.Plugin.Core.Configuration;
 using XUnity.AutoTranslator.Plugin.Core.Endpoints.Http;

+ 4 - 4
src/XUnity.AutoTranslator.Plugin.Core/XUnity.AutoTranslator.Plugin.Core.csproj

@@ -2,7 +2,7 @@
 
    <PropertyGroup>
       <TargetFramework>net35</TargetFramework>
-      <Version>3.4.0</Version>
+      <Version>3.5.0</Version>
    </PropertyGroup>
 
    <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
@@ -10,9 +10,9 @@
    </PropertyGroup>
 
    <ItemGroup>
-      <Reference Include="0Harmony">
-         <HintPath>..\..\libs\0Harmony.dll</HintPath>
-      </Reference>
+     <Reference Include="0Harmony">
+       <HintPath>..\..\libs\0Harmony.dll</HintPath>
+     </Reference>
       <Reference Include="ExIni">
          <HintPath>..\..\libs\ExIni.dll</HintPath>
       </Reference>

+ 1 - 1
src/XUnity.AutoTranslator.Plugin.IPA/XUnity.AutoTranslator.Plugin.IPA.csproj

@@ -2,7 +2,7 @@
 
    <PropertyGroup>
       <TargetFramework>net35</TargetFramework>
-      <Version>3.4.0</Version>
+      <Version>3.5.0</Version>
    </PropertyGroup>
 
    <ItemGroup>

+ 1 - 1
src/XUnity.AutoTranslator.Plugin.UnityInjector/XUnity.AutoTranslator.Plugin.UnityInjector.csproj

@@ -2,7 +2,7 @@
 
    <PropertyGroup>
       <TargetFramework>net35</TargetFramework>
-      <Version>3.4.0</Version>
+      <Version>3.5.0</Version>
    </PropertyGroup>
 
    <ItemGroup>

+ 1 - 1
src/XUnity.AutoTranslator.Setup/XUnity.AutoTranslator.Setup.csproj

@@ -4,7 +4,7 @@
       <OutputType>Exe</OutputType>
       <TargetFramework>net40</TargetFramework>
       <AssemblyName>SetupReiPatcherAndAutoTranslator</AssemblyName>
-      <Version>3.4.0</Version>
+      <Version>3.5.0</Version>
       <ApplicationIcon>icon.ico</ApplicationIcon>
       <Win32Resource />
    </PropertyGroup>

+ 15 - 0
src/XUnity.RuntimeHooker.Core/Utilities/ExpressionHelper.cs

@@ -9,6 +9,21 @@ namespace XUnity.RuntimeHooker.Core.Utilities
 {
    public static class ExpressionHelper
    {
+      public static Delegate CreateTypedFastInvoke( MethodInfo method )
+      {
+         if( method == null ) throw new ArgumentNullException( "method" );
+         if( !method.IsStatic ) throw new ArgumentException( "The provided method must be static.", "method" );
+         if( method.IsGenericMethod )  throw new ArgumentException( "The provided method must not be generic.", "method" );
+
+         var parameters = method.GetParameters()
+            .Select( p => Expression.Parameter( p.ParameterType, p.Name ) )
+            .ToArray();
+
+         var call = Expression.Call( null, method, parameters );
+
+         return Expression.Lambda( call, parameters ).Compile();
+      }
+
       public static Func<object, object[], object> CreateFastInvoke( MethodInfo method )
       {
          var instanceParameterExpression = Expression.Parameter( typeof( object ), "instance" );

+ 25 - 0
test/XUnity.AutoTranslator.Plugin.Core.Tests/UntranslatedTextTests.cs

@@ -4,6 +4,7 @@ using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 using Xunit;
+using XUnity.AutoTranslator.Plugin.Core.Configuration;
 using XUnity.AutoTranslator.Plugin.Core.Extensions;
 
 namespace XUnity.AutoTranslator.Plugin.Core.Tests
@@ -19,6 +20,8 @@ namespace XUnity.AutoTranslator.Plugin.Core.Tests
       [InlineData( "\r\r\r\r\n \n Hello  \r\n", "Hello", "\r\r\r\r\n \n ", "  \r\n" )]
       public void Can_Trim_Surrounding_Whitespace( string input, string expectedTrimmedText, string expectedLeadingWhitespace, string expectedTrailingWhitespace )
       {
+         Settings.UsesWhitespaceBetweenWords = false;
+
          var untranslatedText = new UntranslatedText( input, false, false );
 
          Assert.Equal( input, untranslatedText.TranslatableText );
@@ -27,6 +30,22 @@ namespace XUnity.AutoTranslator.Plugin.Core.Tests
          Assert.Equal( expectedTrailingWhitespace, untranslatedText.TrailingWhitespace );
       }
 
+      [Theory( DisplayName = "Can_Trim_Internal_Whitespace_English" )]
+      [InlineData( "What are you doing?", "What are you doing?" )]
+      [InlineData( "What are\nyou doing?", "What are you doing?" )]
+      [InlineData( "What are\n\nyou doing?", "What are\n\nyou doing?" )]
+      [InlineData( "What are\n\n \n\nyou doing?", "What are\n\n\n\nyou doing?" )]
+      [InlineData( "What are\n\n  \n\nyou doing?", "What are\n\n  \n\nyou doing?" )]
+      [InlineData( "What are\n  \nyou doing?", "What are  you doing?" )]
+      public void Can_Trim_Internal_Whitespace_English( string input, string expectedTrimmedText )
+      {
+         Settings.UsesWhitespaceBetweenWords = true;
+
+         var untranslatedText = new UntranslatedText( input, false, true );
+
+         Assert.Equal( expectedTrimmedText, untranslatedText.TrimmedTranslatableText );
+      }
+
       [Theory( DisplayName = "Can_Trim_Internal_Whitespace" )]
       [InlineData( "Hel lo", "Hel lo" )]
       [InlineData( "Hel\r\n lo", "Hello" )]
@@ -35,6 +54,8 @@ namespace XUnity.AutoTranslator.Plugin.Core.Tests
       [InlineData( "Hello\n\nWhat\nYou", "Hello\n\nWhatYou" )]
       public void Can_Trim_Internal_Whitespace( string input, string expectedTrimmedText )
       {
+         Settings.UsesWhitespaceBetweenWords = false;
+
          var untranslatedText = new UntranslatedText( input, false, true );
          
          Assert.Equal( expectedTrimmedText, untranslatedText.TrimmedTranslatableText );
@@ -53,6 +74,8 @@ namespace XUnity.AutoTranslator.Plugin.Core.Tests
       [InlineData( "\r\r\r\r\n \n Hell\no  \r\n", "Hello", "\r\r\r\r\n \n ", "  \r\n" )]
       public void Can_Trim_Internal_And_Surrounding_Whitespace( string input, string expectedTrimmedText, string expectedLeadingWhitespace, string expectedTrailingWhitespace )
       {
+         Settings.UsesWhitespaceBetweenWords = false;
+
          var untranslatedText = new UntranslatedText( input, false, true );
 
          Assert.Equal( expectedTrimmedText, untranslatedText.TrimmedTranslatableText );
@@ -69,6 +92,8 @@ namespace XUnity.AutoTranslator.Plugin.Core.Tests
       [InlineData( "\r\n \r\nFPS:\n  \n 60.53", "FPS:  {{A}}", "\r\n \r\n", null )]
       public void Can_Trim_Internal_And_Surrounding_Whitespace_And_Template( string input, string expectedTrimmedText, string expectedLeadingWhitespace, string expectedTrailingWhitespace )
       {
+         Settings.UsesWhitespaceBetweenWords = false;
+
          var untranslatedText = new UntranslatedText( input, true, true );
 
          Assert.Equal( expectedTrimmedText, untranslatedText.TrimmedTranslatableText );

+ 15 - 14
test/XUnity.RuntimeHooker.ConsoleTests/Program.cs

@@ -6,6 +6,7 @@ using System.Reflection;
 using System.Runtime.CompilerServices;
 using System.Text;
 using XUnity.RuntimeHooker.Core;
+using XUnity.RuntimeHooker.Core.Utilities;
 
 namespace XUnity.RuntimeHooker.ConsoleTests
 {
@@ -13,24 +14,24 @@ namespace XUnity.RuntimeHooker.ConsoleTests
    {
       static void Main( string[] args )
       {
-         var sayHello = typeof( Program ).GetMethod( "SayHello" );
-         var sayGoodbye = typeof( Program ).GetMethod( "SayGoodbye" );
-         RuntimeMethodPatcher.Patch( sayHello, new HookMethod( sayGoodbye ), null );
-         SayHello();
+         //var sayHello = typeof( Program ).GetMethod( "SayHello" );
+         //var sayGoodbye = typeof( Program ).GetMethod( "SayGoodbye" );
+         //RuntimeMethodPatcher.Patch( sayHello, new HookMethod( sayGoodbye ), null );
+         //SayHello();
 
-         var textComponent = new TextComponent();
-         textComponent.Text = "こんにちは";
+         //var textComponent = new TextComponent();
+         //textComponent.Text = "こんにちは";
 
-         var textGetter = typeof( TextComponent ).GetProperty( "Text" ).GetGetMethod();
-         var textGetterHook = typeof( Program ).GetMethod( "TextGetterHook" );
-         RuntimeMethodPatcher.Patch( textGetter, null, new HookMethod( textGetterHook ) );
+         //var textGetter = typeof( TextComponent ).GetProperty( "Text" ).GetGetMethod();
+         //var textGetterHook = typeof( Program ).GetMethod( "TextGetterHook" );
+         //RuntimeMethodPatcher.Patch( textGetter, null, new HookMethod( textGetterHook ) );
 
-         Console.WriteLine( textComponent.Text );
+         //Console.WriteLine( textComponent.Text );
 
-         var printValue = typeof( Program ).GetMethod( "PrintValue" );
-         var printValueHook = typeof( Program ).GetMethod( "PrintValueHook" );
-         RuntimeMethodPatcher.Patch( printValue, new HookMethod( printValueHook ), null );
-         PrintValue( 7331 );
+         //var printValue = typeof( Program ).GetMethod( "PrintValue" );
+         //var printValueHook = typeof( Program ).GetMethod( "PrintValueHook" );
+         //RuntimeMethodPatcher.Patch( printValue, new HookMethod( printValueHook ), null );
+         //PrintValue( 7331 );
       }
 
       [MethodImpl( MethodImplOptions.NoInlining )]