Hooks.cs 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. using Harmony;
  2. using System.Reflection;
  3. using TMPro;
  4. namespace DynamicTranslationLoader
  5. {
  6. public static class Hooks
  7. {
  8. public static void InstallHooks()
  9. {
  10. var harmony = HarmonyInstance.Create("com.bepis.bepinex.dynamictranslationloader");
  11. MethodInfo original = AccessTools.Property(typeof(TMP_Text), "text").GetSetMethod();
  12. HarmonyMethod prefix = new HarmonyMethod(typeof(Hooks).GetMethod("LabelTextHook"));
  13. harmony.Patch(original, prefix, null);
  14. original = AccessTools.Method(typeof(TMP_Text), "SetText", new[] { typeof(string) });
  15. prefix = new HarmonyMethod(typeof(Hooks).GetMethod("SetTextHook"));
  16. harmony.Patch(original, prefix, null);
  17. }
  18. public static void LabelTextHook(ref string value)
  19. {
  20. value = DynamicTranslator.Translate(value);
  21. }
  22. public static void SetTextHook(ref string text)
  23. {
  24. text = DynamicTranslator.Translate(text);
  25. }
  26. }
  27. }