TextGetterCompatHooks.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using System;
  2. using System.Reflection;
  3. using Harmony;
  4. using XUnity.AutoTranslator.Plugin.Core.Constants;
  5. using XUnity.AutoTranslator.Plugin.Core.Utilities;
  6. namespace XUnity.AutoTranslator.Plugin.Core.Hooks.TextGetterCompat
  7. {
  8. internal static class TextGetterCompatHooks
  9. {
  10. public static readonly Type[] All = new[] {
  11. typeof( Text_text_Hook ),
  12. typeof( TMP_Text_text_Hook ),
  13. };
  14. }
  15. [Harmony, HarmonyAfter( Constants.KnownPlugins.DynamicTranslationLoader )]
  16. internal static class Text_text_Hook
  17. {
  18. static bool Prepare( HarmonyInstance instance )
  19. {
  20. return ClrTypes.Text != null;
  21. }
  22. static MethodBase TargetMethod( HarmonyInstance instance )
  23. {
  24. var text = AccessTools.Property( ClrTypes.Text, "text" );
  25. return text.GetGetMethod();
  26. }
  27. static void Postfix( object __instance, ref string __result )
  28. {
  29. TextGetterCompatModeHelper.ReplaceTextWithOriginal( __instance, ref __result );
  30. }
  31. }
  32. [Harmony, HarmonyAfter( Constants.KnownPlugins.DynamicTranslationLoader )]
  33. internal static class TMP_Text_text_Hook
  34. {
  35. static bool Prepare( HarmonyInstance instance )
  36. {
  37. return ClrTypes.TMP_Text != null;
  38. }
  39. static MethodBase TargetMethod( HarmonyInstance instance )
  40. {
  41. return AccessTools.Property( ClrTypes.TMP_Text, "text" ).GetGetMethod();
  42. }
  43. static void Postfix( object __instance, ref string __result )
  44. {
  45. TextGetterCompatModeHelper.ReplaceTextWithOriginal( __instance, ref __result );
  46. }
  47. }
  48. }