y_hooks_macros.inc 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. Legal:
  3. Version: MPL 1.1
  4. The contents of this file are subject to the Mozilla Public License Version
  5. 1.1 the "License"; you may not use this file except in compliance with
  6. the License. You may obtain a copy of the License at
  7. http://www.mozilla.org/MPL/
  8. Software distributed under the License is distributed on an "AS IS" basis,
  9. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  10. for the specific language governing rights and limitations under the
  11. License.
  12. The Original Code is the YSI framework.
  13. The Initial Developer of the Original Code is Alex "Y_Less" Cole.
  14. Portions created by the Initial Developer are Copyright C 2011
  15. the Initial Developer. All Rights Reserved.
  16. Contributors:
  17. Y_Less
  18. koolk
  19. JoeBullet/Google63
  20. g_aSlice/Slice
  21. Misiur
  22. samphunter
  23. tianmeta
  24. maddinat0r
  25. spacemud
  26. Crayder
  27. Dayvison
  28. Ahmad45123
  29. Zeex
  30. irinel1996
  31. Yiin-
  32. Chaprnks
  33. Konstantinos
  34. Masterchen09
  35. Southclaws
  36. PatchwerkQWER
  37. m0k1
  38. paulommu
  39. udan111
  40. Thanks:
  41. JoeBullet/Google63 - Handy arbitrary ASM jump code using SCTRL.
  42. ZeeX - Very productive conversations.
  43. koolk - IsPlayerinAreaEx code.
  44. TheAlpha - Danish translation.
  45. breadfish - German translation.
  46. Fireburn - Dutch translation.
  47. yom - French translation.
  48. 50p - Polish translation.
  49. Zamaroht - Spanish translation.
  50. Los - Portuguese translation.
  51. Dracoblue, sintax, mabako, Xtreme, other coders - Producing other modes for
  52. me to strive to better.
  53. Pixels^ - Running XScripters where the idea was born.
  54. Matite - Pestering me to release it and using it.
  55. Very special thanks to:
  56. Thiadmer - PAWN, whose limits continue to amaze me!
  57. Kye/Kalcor - SA:MP.
  58. SA:MP Team past, present and future - SA:MP.
  59. Optional plugins:
  60. Gamer_Z - GPS.
  61. Incognito - Streamer.
  62. Me - sscanf2, fixes2, Whirlpool.
  63. */
  64. /*
  65. ad88888ba
  66. d8" "8b ,d
  67. Y8, 88
  68. `Y8aaaaa, ,adPPYba, MM88MMM 88 88 8b,dPPYba,
  69. `"""""8b, a8P_____88 88 88 88 88P' "8a
  70. `8b 8PP""""""" 88 88 88 88 d8
  71. Y8a a8P "8b, ,aa 88, "8a, ,a88 88b, ,a8"
  72. "Y88888P" `"Ybbd8"' "Y888 `"YbbdP'Y8 88`YbbdP"'
  73. 88
  74. 88
  75. */
  76. //#define @yH_public%0\32;%1(%2);%3(%4) HOOK_REDO__ %0%1(%2)
  77. #define @yH_native%0\32;%1(%2);%3(%4) HOOK_REDO__ %0%1(%2)
  78. #define @yH_stock%0\32;%1(%2);%3(%4) HOOK_REDO__ %0%1(%2)
  79. #define @yH_function%0\32;%1(%2);%3(%4) HOOK_REDO__ %0%1(%2)
  80. //#define HOOK_PUBLIC__%1(%2) forward UNIQUE_FUNCTION<@H_y%1@...>(%2);UNIQUE_FUNCTION<@H_y%1@...>(%2)
  81. //#define HOOK_public__%1(%2) forward UNIQUE_FUNCTION<@H_y%1@...>(%2);UNIQUE_FUNCTION<@H_y%1@...>(%2)
  82. #define HOOK__%1(%2) forward UNIQUE_FUNCTION<@yH_%1@...>(%2);UNIQUE_FUNCTION<@yH_%1@...>(%2)
  83. #define REHOOK__ HOOK__
  84. #define Y_HOOKS_CONTINUE_RETURN_1 (1) // Continue the hook chain, return 1
  85. #define Y_HOOKS_CONTINUE_RETURN_0 (0) // Continue the hook chain, return 0
  86. #define Y_HOOKS_BREAK_RETURN_0 (~0) // Break the hook chain, return 0
  87. #define Y_HOOKS_BREAK_RETURN_1 (~1) // Break the hook chain, return 1
  88. #if !defined MAX_HOOK_REPLACEMENTS
  89. #define MAX_HOOK_REPLACEMENTS (16)
  90. #endif
  91. // Generate a function name using only ONE of the parts, so two replacements for
  92. // the same long name will collide at compile-time
  93. #define DEFINE_HOOK_REPLACEMENT__(%0,%1); forward @_yH%0(); public @_yH%0() { _Hooks_AddReplacement(#%0, #%1); }
  94. // Strip spaces from the generated function names.
  95. #define @yH_%0\32; @yH_ // hook
  96. #define @_Hy%0\32; @_Hy // extra stock/native info
  97. #define @Hy_%0\32; @Hy_ // hook stock/native
  98. #define @H_y%0\32; @H_y // hook public
  99. #define @y_H%0\32; @y_H // DEFINE_HOOK_RETURN
  100. #define @_yH%0\32; @_yH // DEFINE_HOOK_REPLACEMENT
  101. #define DEFINE_HOOK_RETURN__(%0,%1); forward @y_H%0(); public @y_H%0() { return (%1); }
  102. #if YSI_KEYWORD(HOOK_REPLACEMENT)
  103. #define DEFINE_HOOK_REPLACEMENT DEFINE_HOOK_REPLACEMENT__
  104. #endif
  105. #if YSI_KEYWORD(HOOK_RET)
  106. #define HOOK_RET:%0(%1) forward @y_H%0(); public @y_H%0()
  107. #endif
  108. #if YSI_KEYWORD(hook)
  109. #define hook HOOK__
  110. #endif
  111. #if YSI_KEYWORD(rehook)
  112. #define rehook HOOK__
  113. #endif
  114. #if YSI_KEYWORD(Hook)
  115. #define Hook:%0_%1(%2) forward public @yH_%1@%0(%2);@yH_%1@%0(%2)
  116. #endif