123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Reflection;
- using System.Text;
- using Harmony;
- using XUnity.AutoTranslator.Plugin.Core.Constants;
- namespace XUnity.AutoTranslator.Plugin.Core.Hooks.TextMeshPro
- {
- public static class TextMeshProHooks
- {
- public static readonly Type[] All = new[] {
- typeof( TeshMeshProUGUIOnEnableHook ),
- typeof( TeshMeshProOnEnableHook ),
- typeof( TextPropertyHook ),
- typeof( SetTextHook1 ),
- typeof( SetTextHook2 ),
- typeof( SetTextHook3 ),
- typeof( SetCharArrayHook1 ),
- typeof( SetCharArrayHook2 ),
- typeof( SetCharArrayHook3 ),
- };
- }
- [Harmony, HarmonyAfter( Constants.KnownPlugins.DynamicTranslationLoader )]
- public static class TeshMeshProUGUIOnEnableHook
- {
- static bool Prepare( HarmonyInstance instance )
- {
- return Types.TextMeshProUGUI != null;
- }
- static MethodBase TargetMethod( HarmonyInstance instance )
- {
- return AccessTools.Method( Types.TextMeshProUGUI, "OnEnable" );
- }
- static void Postfix( object __instance )
- {
- AutoTranslationPlugin.Current.Hook_TextChanged( __instance );
- }
- }
- [Harmony, HarmonyAfter( Constants.KnownPlugins.DynamicTranslationLoader )]
- public static class TeshMeshProOnEnableHook
- {
- static bool Prepare( HarmonyInstance instance )
- {
- return Types.TextMeshPro != null;
- }
- static MethodBase TargetMethod( HarmonyInstance instance )
- {
- return AccessTools.Method( Types.TextMeshPro, "OnEnable" );
- }
- static void Postfix( object __instance )
- {
- AutoTranslationPlugin.Current.Hook_TextChanged( __instance );
- }
- }
- [Harmony, HarmonyAfter( Constants.KnownPlugins.DynamicTranslationLoader )]
- public static class TextPropertyHook
- {
- static bool Prepare( HarmonyInstance instance )
- {
- return Types.TMP_Text != null;
- }
- static MethodBase TargetMethod( HarmonyInstance instance )
- {
- return AccessTools.Property( Types.TMP_Text, "text" ).GetSetMethod();
- }
- static void Postfix( object __instance )
- {
- AutoTranslationPlugin.Current.Hook_TextChanged( __instance );
- }
- }
- [Harmony, HarmonyAfter( Constants.KnownPlugins.DynamicTranslationLoader )]
- public static class SetTextHook1
- {
- static bool Prepare( HarmonyInstance instance )
- {
- return Types.TMP_Text != null;
- }
- static MethodBase TargetMethod( HarmonyInstance instance )
- {
- return AccessTools.Method( Types.TMP_Text, "SetText", new[] { typeof( StringBuilder ) } );
- }
- static void Postfix( object __instance )
- {
- AutoTranslationPlugin.Current.Hook_TextChanged( __instance );
- }
- }
- [Harmony, HarmonyAfter( Constants.KnownPlugins.DynamicTranslationLoader )]
- public static class SetTextHook2
- {
- static bool Prepare( HarmonyInstance instance )
- {
- return Types.TMP_Text != null;
- }
- static MethodBase TargetMethod( HarmonyInstance instance )
- {
- return AccessTools.Method( Types.TMP_Text, "SetText", new[] { typeof( string ), typeof( bool ) } );
- }
- static void Postfix( object __instance )
- {
- AutoTranslationPlugin.Current.Hook_TextChanged( __instance );
- }
- }
- [Harmony, HarmonyAfter( Constants.KnownPlugins.DynamicTranslationLoader )]
- public static class SetTextHook3
- {
- static bool Prepare( HarmonyInstance instance )
- {
- return Types.TMP_Text != null;
- }
- static MethodBase TargetMethod( HarmonyInstance instance )
- {
- return AccessTools.Method( Types.TMP_Text, "SetText", new[] { typeof( string ), typeof( float ), typeof( float ), typeof( float ) } );
- }
- static void Postfix( object __instance )
- {
- AutoTranslationPlugin.Current.Hook_TextChanged( __instance );
- }
- }
- [Harmony, HarmonyAfter( Constants.KnownPlugins.DynamicTranslationLoader )]
- public static class SetCharArrayHook1
- {
- static bool Prepare( HarmonyInstance instance )
- {
- return Types.TMP_Text != null;
- }
- static MethodBase TargetMethod( HarmonyInstance instance )
- {
- return AccessTools.Method( Types.TMP_Text, "SetCharArray", new[] { typeof( char[] ) } );
- }
- static void Postfix( object __instance )
- {
- AutoTranslationPlugin.Current.Hook_TextChanged( __instance );
- }
- }
- [Harmony, HarmonyAfter( Constants.KnownPlugins.DynamicTranslationLoader )]
- public static class SetCharArrayHook2
- {
- static bool Prepare( HarmonyInstance instance )
- {
- return Types.TMP_Text != null;
- }
- static MethodBase TargetMethod( HarmonyInstance instance )
- {
- return AccessTools.Method( Types.TMP_Text, "SetCharArray", new[] { typeof( char[] ), typeof( int ), typeof( int ) } );
- }
- static void Postfix( object __instance )
- {
- AutoTranslationPlugin.Current.Hook_TextChanged( __instance );
- }
- }
- [Harmony, HarmonyAfter( Constants.KnownPlugins.DynamicTranslationLoader )]
- public static class SetCharArrayHook3
- {
- static bool Prepare( HarmonyInstance instance )
- {
- return Types.TMP_Text != null;
- }
- static MethodBase TargetMethod( HarmonyInstance instance )
- {
- return AccessTools.Method( Types.TMP_Text, "SetCharArray", new[] { typeof( int[] ), typeof( int ), typeof( int ) } );
- }
- static void Postfix( object __instance )
- {
- AutoTranslationPlugin.Current.Hook_TextChanged( __instance );
- }
- }
- }
|