NGUIImageHooks.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Reflection;
  5. using System.Text;
  6. using Harmony;
  7. using XUnity.AutoTranslator.Plugin.Core.Constants;
  8. namespace XUnity.AutoTranslator.Plugin.Core.Hooks
  9. {
  10. public static class NGUIImageHooks
  11. {
  12. public static readonly Type[] All = new Type[] {
  13. typeof( UIAtlas_spriteMaterial_Hook ),
  14. typeof( UISprite_OnInit_Hook ),
  15. typeof( UISprite_material_Hook ),
  16. typeof( UISprite_atlas_Hook ),
  17. typeof( UI2DSprite_sprite2D_Hook ),
  18. typeof( UI2DSprite_material_Hook ),
  19. typeof( UITexture_mainTexture_Hook ),
  20. typeof( UITexture_material_Hook ),
  21. typeof( UIPanel_clipTexture_Hook ),
  22. typeof( UIRect_OnInit_Hook ),
  23. //typeof( UIFont_dynamicFont_Hook ),
  24. //typeof( UIFont_material_Hook ),
  25. //typeof( UILabel_bitmapFont_Hook ),
  26. //typeof( UILabel_trueTypeFont_Hook ),
  27. };
  28. }
  29. [Harmony]
  30. public static class UIAtlas_spriteMaterial_Hook
  31. {
  32. static bool Prepare( HarmonyInstance instance )
  33. {
  34. return ClrTypes.UIAtlas != null;
  35. }
  36. static MethodBase TargetMethod( HarmonyInstance instance )
  37. {
  38. return AccessTools.Property( ClrTypes.UIAtlas, "spriteMaterial" ).GetSetMethod();
  39. }
  40. public static void Postfix( object __instance )
  41. {
  42. AutoTranslationPlugin.Current.Hook_ImageChangedOnComponent( __instance, null, false );
  43. }
  44. }
  45. [Harmony]
  46. public static class UISprite_OnInit_Hook
  47. {
  48. static bool Prepare( HarmonyInstance instance )
  49. {
  50. return ClrTypes.UISprite != null;
  51. }
  52. static MethodBase TargetMethod( HarmonyInstance instance )
  53. {
  54. return AccessTools.Method( Constants.ClrTypes.UISprite, "OnInit" );
  55. }
  56. public static void Postfix( object __instance )
  57. {
  58. AutoTranslationPlugin.Current.Hook_ImageChangedOnComponent( __instance );
  59. }
  60. }
  61. [Harmony]
  62. public static class UISprite_material_Hook
  63. {
  64. static bool Prepare( HarmonyInstance instance )
  65. {
  66. return ClrTypes.UISprite != null;
  67. }
  68. static MethodBase TargetMethod( HarmonyInstance instance )
  69. {
  70. return AccessTools.Property( ClrTypes.UISprite, "material" ).GetSetMethod();
  71. }
  72. public static void Postfix( object __instance )
  73. {
  74. AutoTranslationPlugin.Current.Hook_ImageChangedOnComponent( __instance, null, false );
  75. }
  76. }
  77. [Harmony]
  78. public static class UISprite_atlas_Hook
  79. {
  80. static bool Prepare( HarmonyInstance instance )
  81. {
  82. return ClrTypes.UISprite != null;
  83. }
  84. static MethodBase TargetMethod( HarmonyInstance instance )
  85. {
  86. return AccessTools.Property( ClrTypes.UISprite, "atlas" ).GetSetMethod();
  87. }
  88. public static void Postfix( object __instance )
  89. {
  90. AutoTranslationPlugin.Current.Hook_ImageChangedOnComponent( __instance, null, false );
  91. }
  92. }
  93. [Harmony]
  94. public static class UITexture_mainTexture_Hook
  95. {
  96. static bool Prepare( HarmonyInstance instance )
  97. {
  98. return ClrTypes.UITexture != null;
  99. }
  100. static MethodBase TargetMethod( HarmonyInstance instance )
  101. {
  102. return AccessTools.Property( ClrTypes.UITexture, "mainTexture" ).GetSetMethod();
  103. }
  104. public static void Postfix( object __instance )
  105. {
  106. AutoTranslationPlugin.Current.Hook_ImageChangedOnComponent( __instance, null, false );
  107. }
  108. }
  109. [Harmony]
  110. public static class UITexture_material_Hook
  111. {
  112. static bool Prepare( HarmonyInstance instance )
  113. {
  114. return ClrTypes.UITexture != null;
  115. }
  116. static MethodBase TargetMethod( HarmonyInstance instance )
  117. {
  118. return AccessTools.Property( ClrTypes.UITexture, "material" ).GetSetMethod();
  119. }
  120. public static void Postfix( object __instance )
  121. {
  122. AutoTranslationPlugin.Current.Hook_ImageChangedOnComponent( __instance, null, false );
  123. }
  124. }
  125. [Harmony]
  126. public static class UIRect_OnInit_Hook
  127. {
  128. static bool Prepare( HarmonyInstance instance )
  129. {
  130. return ClrTypes.UIRect != null;
  131. }
  132. static MethodBase TargetMethod( HarmonyInstance instance )
  133. {
  134. return AccessTools.Method( ClrTypes.UIRect, "OnInit" );
  135. }
  136. public static void Postfix( object __instance )
  137. {
  138. AutoTranslationPlugin.Current.Hook_ImageChangedOnComponent( __instance );
  139. }
  140. }
  141. [Harmony]
  142. public static class UI2DSprite_sprite2D_Hook
  143. {
  144. static bool Prepare( HarmonyInstance instance )
  145. {
  146. return ClrTypes.UI2DSprite != null;
  147. }
  148. static MethodBase TargetMethod( HarmonyInstance instance )
  149. {
  150. return AccessTools.Property( ClrTypes.UI2DSprite, "sprite2D" ).GetSetMethod();
  151. }
  152. public static void Postfix( object __instance )
  153. {
  154. AutoTranslationPlugin.Current.Hook_ImageChangedOnComponent( __instance, null, false );
  155. }
  156. }
  157. [Harmony]
  158. public static class UI2DSprite_material_Hook
  159. {
  160. static bool Prepare( HarmonyInstance instance )
  161. {
  162. return ClrTypes.UI2DSprite != null;
  163. }
  164. static MethodBase TargetMethod( HarmonyInstance instance )
  165. {
  166. return AccessTools.Property( ClrTypes.UI2DSprite, "material" ).GetSetMethod();
  167. }
  168. public static void Postfix( object __instance )
  169. {
  170. AutoTranslationPlugin.Current.Hook_ImageChangedOnComponent( __instance, null, false );
  171. }
  172. }
  173. [Harmony]
  174. public static class UIPanel_clipTexture_Hook
  175. {
  176. static bool Prepare( HarmonyInstance instance )
  177. {
  178. return ClrTypes.UIPanel != null;
  179. }
  180. static MethodBase TargetMethod( HarmonyInstance instance )
  181. {
  182. return AccessTools.Property( ClrTypes.UIPanel, "clipTexture" ).GetSetMethod();
  183. }
  184. public static void Postfix( object __instance )
  185. {
  186. AutoTranslationPlugin.Current.Hook_ImageChangedOnComponent( __instance );
  187. }
  188. }
  189. [Harmony]
  190. public static class UIFont_material_Hook
  191. {
  192. static bool Prepare( HarmonyInstance instance )
  193. {
  194. return ClrTypes.UIFont != null;
  195. }
  196. static MethodBase TargetMethod( HarmonyInstance instance )
  197. {
  198. return AccessTools.Property( ClrTypes.UIFont, "material" ).GetSetMethod();
  199. }
  200. public static void Postfix( object __instance )
  201. {
  202. AutoTranslationPlugin.Current.Hook_ImageChangedOnComponent( __instance );
  203. }
  204. }
  205. [Harmony]
  206. public static class UIFont_dynamicFont_Hook
  207. {
  208. static bool Prepare( HarmonyInstance instance )
  209. {
  210. return ClrTypes.UIFont != null;
  211. }
  212. static MethodBase TargetMethod( HarmonyInstance instance )
  213. {
  214. return AccessTools.Property( ClrTypes.UIFont, "dynamicFont" ).GetSetMethod();
  215. }
  216. public static void Postfix( object __instance )
  217. {
  218. AutoTranslationPlugin.Current.Hook_ImageChangedOnComponent( __instance );
  219. }
  220. }
  221. [Harmony]
  222. public static class UILabel_bitmapFont_Hook
  223. {
  224. static bool Prepare( HarmonyInstance instance )
  225. {
  226. return ClrTypes.UILabel != null;
  227. }
  228. static MethodBase TargetMethod( HarmonyInstance instance )
  229. {
  230. return AccessTools.Property( ClrTypes.UILabel, "bitmapFont" ).GetSetMethod();
  231. }
  232. public static void Postfix( object __instance )
  233. {
  234. AutoTranslationPlugin.Current.Hook_ImageChangedOnComponent( __instance );
  235. }
  236. }
  237. [Harmony]
  238. public static class UILabel_trueTypeFont_Hook
  239. {
  240. static bool Prepare( HarmonyInstance instance )
  241. {
  242. return ClrTypes.UILabel != null;
  243. }
  244. static MethodBase TargetMethod( HarmonyInstance instance )
  245. {
  246. return AccessTools.Property( ClrTypes.UILabel, "trueTypeFont" ).GetSetMethod();
  247. }
  248. public static void Postfix( object __instance )
  249. {
  250. AutoTranslationPlugin.Current.Hook_ImageChangedOnComponent( __instance );
  251. }
  252. }
  253. }