123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Reflection;
- using System.Text;
- using Harmony;
- using UnityEngine;
- using static UnityEngine.GUI;
- namespace XUnity.AutoTranslator.Plugin.Core.Hooks.IMGUI
- {
- internal static class IMGUIHooks
- {
- public static bool HooksOverriden = false;
- public static readonly Type[] All = new[] {
- typeof( GUI_BeginGroup_Hook ),
- typeof( GUI_Box_Hook ),
- typeof( GUI_DoRepeatButton_Hook ),
- typeof( GUI_DoLabel_Hook ),
- typeof( GUI_DoButton_Hook ),
- typeof( GUI_DoModalWindow_Hook ),
- typeof( GUI_DoWindow_Hook ),
- typeof( GUI_DoTextField_Hook ),
- typeof( GUI_DoButtonGrid_Hook ),
- typeof( GUI_DoToggle_Hook ),
- };
- }
- [Harmony, HarmonyAfter( Constants.KnownPlugins.DynamicTranslationLoader )]
- internal static class GUI_BeginGroup_Hook
- {
- static bool Prepare( HarmonyInstance instance )
- {
- return Constants.ClrTypes.GUI != null;
- }
- static MethodBase TargetMethod( HarmonyInstance instance )
- {
- return AccessTools.Method( Constants.ClrTypes.GUI, "BeginGroup", new[] { typeof( Rect ), typeof( GUIContent ), typeof( GUIStyle ) } );
- }
- static void Prefix( GUIContent content )
- {
- if( !IMGUIHooks.HooksOverriden )
- {
- AutoTranslationPlugin.Current.Hook_TextChanged( content, false );
- }
- }
- }
- [Harmony, HarmonyAfter( Constants.KnownPlugins.DynamicTranslationLoader )]
- internal static class GUI_Box_Hook
- {
- static bool Prepare( HarmonyInstance instance )
- {
- return Constants.ClrTypes.GUI != null;
- }
- static MethodBase TargetMethod( HarmonyInstance instance )
- {
- return AccessTools.Method( Constants.ClrTypes.GUI, "Box", new[] { typeof( Rect ), typeof( GUIContent ), typeof( GUIStyle ) } );
- }
- static void Prefix( GUIContent content )
- {
- if( !IMGUIHooks.HooksOverriden )
- {
- AutoTranslationPlugin.Current.Hook_TextChanged( content, false );
- }
- }
- }
- [Harmony, HarmonyAfter( Constants.KnownPlugins.DynamicTranslationLoader )]
- internal static class GUI_DoRepeatButton_Hook
- {
- static bool Prepare( HarmonyInstance instance )
- {
- return Constants.ClrTypes.GUI != null;
- }
- static MethodBase TargetMethod( HarmonyInstance instance )
- {
- return AccessTools.Method( Constants.ClrTypes.GUI, "DoRepeatButton", new[] { typeof( Rect ), typeof( GUIContent ), typeof( GUIStyle ), typeof( FocusType ) } );
- }
- static void Prefix( GUIContent content )
- {
- if( !IMGUIHooks.HooksOverriden )
- {
- AutoTranslationPlugin.Current.Hook_TextChanged( content, false );
- }
- }
- }
- [Harmony, HarmonyAfter( Constants.KnownPlugins.DynamicTranslationLoader )]
- internal static class GUI_DoLabel_Hook
- {
- static bool Prepare( HarmonyInstance instance )
- {
- return Constants.ClrTypes.GUI != null;
- }
- static MethodBase TargetMethod( HarmonyInstance instance )
- {
- return AccessTools.Method( Constants.ClrTypes.GUI, "DoLabel", new[] { typeof( Rect ), typeof( GUIContent ), typeof( IntPtr ) } );
- }
- static void Prefix( GUIContent content )
- {
- if( !IMGUIHooks.HooksOverriden )
- {
- AutoTranslationPlugin.Current.Hook_TextChanged( content, false );
- }
- }
- }
- [Harmony, HarmonyAfter( Constants.KnownPlugins.DynamicTranslationLoader )]
- internal static class GUI_DoButton_Hook
- {
- static bool Prepare( HarmonyInstance instance )
- {
- return Constants.ClrTypes.GUI != null;
- }
- static MethodBase TargetMethod( HarmonyInstance instance )
- {
- return AccessTools.Method( Constants.ClrTypes.GUI, "DoButton", new[] { typeof( Rect ), typeof( GUIContent ), typeof( IntPtr ) } );
- }
- static void Prefix( GUIContent content )
- {
- if( !IMGUIHooks.HooksOverriden )
- {
- AutoTranslationPlugin.Current.Hook_TextChanged( content, false );
- }
- }
- }
- [Harmony, HarmonyAfter( Constants.KnownPlugins.DynamicTranslationLoader )]
- internal static class GUI_DoModalWindow_Hook
- {
- static bool Prepare( HarmonyInstance instance )
- {
- return Constants.ClrTypes.GUI != null;
- }
- static MethodBase TargetMethod( HarmonyInstance instance )
- {
- return AccessTools.Method( Constants.ClrTypes.GUI, "DoModalWindow", new[] { typeof( int ), typeof( Rect ), typeof( WindowFunction ), typeof( GUIContent ), typeof( GUIStyle ), typeof( GUISkin ) } );
- }
- static void Prefix( GUIContent content )
- {
- if( !IMGUIHooks.HooksOverriden )
- {
- AutoTranslationPlugin.Current.Hook_TextChanged( content, false );
- }
- }
- }
- [Harmony, HarmonyAfter( Constants.KnownPlugins.DynamicTranslationLoader )]
- internal static class GUI_DoWindow_Hook
- {
- static bool Prepare( HarmonyInstance instance )
- {
- return Constants.ClrTypes.GUI != null;
- }
- static MethodBase TargetMethod( HarmonyInstance instance )
- {
- return AccessTools.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 )
- {
- if( !IMGUIHooks.HooksOverriden )
- {
- AutoTranslationPlugin.Current.Hook_TextChanged( title, false );
- }
- }
- }
- [Harmony, HarmonyAfter( Constants.KnownPlugins.DynamicTranslationLoader )]
- internal static class GUI_DoButtonGrid_Hook
- {
- static bool Prepare( HarmonyInstance instance )
- {
- return Constants.ClrTypes.GUI != null;
- }
- static MethodBase TargetMethod( HarmonyInstance 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 ) } );
- }
- static void Prefix( GUIContent[] contents )
- {
- if( !IMGUIHooks.HooksOverriden )
- {
- foreach( var content in contents )
- {
- AutoTranslationPlugin.Current.Hook_TextChanged( content, false );
- }
- }
- }
- }
- [Harmony, HarmonyAfter( Constants.KnownPlugins.DynamicTranslationLoader )]
- internal static class GUI_DoTextField_Hook
- {
- static bool Prepare( HarmonyInstance instance )
- {
- return Constants.ClrTypes.GUI != null;
- }
- static MethodBase TargetMethod( HarmonyInstance instance )
- {
- return AccessTools.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 )
- {
- if( !IMGUIHooks.HooksOverriden )
- {
- AutoTranslationPlugin.Current.Hook_TextChanged( content, false );
- }
- }
- }
- [Harmony, HarmonyAfter( Constants.KnownPlugins.DynamicTranslationLoader )]
- internal static class GUI_DoToggle_Hook
- {
- static bool Prepare( HarmonyInstance instance )
- {
- return Constants.ClrTypes.GUI != null;
- }
- static MethodBase TargetMethod( HarmonyInstance instance )
- {
- return AccessTools.Method( Constants.ClrTypes.GUI, "DoToggle", new[] { typeof( Rect ), typeof( int ), typeof( bool ), typeof( GUIContent ), typeof( IntPtr ) } );
- }
- static void Prefix( GUIContent content )
- {
- if( !IMGUIHooks.HooksOverriden )
- {
- AutoTranslationPlugin.Current.Hook_TextChanged( content, false );
- }
- }
- }
- }
|