y_scriptinit.inc 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. /**--------------------------------------------------------------------------**\
  2. =======================================
  3. y_scriptinit - Two useful callbacks.
  4. =======================================
  5. Description:
  6. This file provides "OnScriptInit" and "OnScriptExit" which are called at the
  7. start and end of the current script, regardless of what the type of the
  8. script is (note: doesn't support NPC modes). It also provides
  9. "YSI_FILTERSCRIPT" as a (partial) replacement for "FILTERSCRIPT" which
  10. detects what the mode is at runtime for a more reliable system (but it is a
  11. run-time variable, not a compile-time constant).
  12. Legal:
  13. Version: MPL 1.1
  14. The contents of this file are subject to the Mozilla Public License Version
  15. 1.1 (the "License"); you may not use this file except in compliance with
  16. the License. You may obtain a copy of the License at
  17. http://www.mozilla.org/MPL/
  18. Software distributed under the License is distributed on an "AS IS" basis,
  19. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  20. for the specific language governing rights and limitations under the
  21. License.
  22. The Original Code is the YSI scriptinit include.
  23. The Initial Developer of the Original Code is Alex "Y_Less" Cole.
  24. Portions created by the Initial Developer are Copyright (C) 2011
  25. the Initial Developer. All Rights Reserved.
  26. Contributors:
  27. ZeeX, koolk, JoeBullet/Google63, g_aSlice/Slice
  28. Thanks:
  29. JoeBullet/Google63 - Handy arbitrary ASM jump code using SCTRL.
  30. ZeeX - Very productive conversations.
  31. koolk - IsPlayerinAreaEx code.
  32. TheAlpha - Danish translation.
  33. breadfish - German translation.
  34. Fireburn - Dutch translation.
  35. yom - French translation.
  36. 50p - Polish translation.
  37. Zamaroht - Spanish translation.
  38. Dracoblue, sintax, mabako, Xtreme, other coders - Producing other modes
  39. for me to strive to better.
  40. Pixels^ - Running XScripters where the idea was born.
  41. Matite - Pestering me to release it and using it.
  42. Very special thanks to:
  43. Thiadmer - PAWN, whose limits continue to amaze me!
  44. Kye/Kalcor - SA:MP.
  45. SA:MP Team past, present and future - SA:MP.
  46. Version:
  47. 1.0
  48. Changelog:
  49. 23/04/14:
  50. Reduced code complexity.
  51. Supports y_hooks better, without relying on it.
  52. 30/04/11:
  53. First version
  54. \**--------------------------------------------------------------------------**/
  55. /*
  56. ad88888ba
  57. d8" "8b ,d
  58. Y8, 88
  59. `Y8aaaaa, ,adPPYba, MM88MMM 88 88 8b,dPPYba,
  60. `"""""8b, a8P_____88 88 88 88 88P' "8a
  61. `8b 8PP""""""" 88 88 88 88 d8
  62. Y8a a8P "8b, ,aa 88, "8a, ,a88 88b, ,a8"
  63. "Y88888P" `"Ybbd8"' "Y888 `"YbbdP'Y8 88`YbbdP"'
  64. 88
  65. 88
  66. */
  67. #if defined _INC_y_scriptinit
  68. #endinput
  69. #endif
  70. #define _INC_y_scriptinit
  71. #include <a_samp>
  72. #include "..\YSI_Internal\y_natives"
  73. forward _ScriptInit_FixState();
  74. #if !defined CHAIN_ORDER
  75. #define CHAIN_ORDER() 0
  76. #endif
  77. forward @CO_ScriptInit();
  78. public @CO_ScriptInit()
  79. {
  80. return CHAIN_ORDER() + 1;
  81. }
  82. #undef CHAIN_ORDER
  83. #define CHAIN_ORDER @CO_ScriptInit
  84. #define SCRIPT_INIT_FORWARD:%0(%1); \
  85. forward ScriptInit_%0(%1); \
  86. public ScriptInit_%0(%1) <_ALS : _ALS_x0, _ALS : _ALS_x1> { return 1; } \
  87. public ScriptInit_%0(%1) <> { return 1; }
  88. stock
  89. bool:YSI_FILTERSCRIPT = false;
  90. /*
  91. 88 88
  92. 88 "" ,d
  93. 88 88
  94. 88 8b,dPPYba, 88 MM88MMM
  95. 88 88P' `"8a 88 88
  96. 88 88 88 88 88
  97. 88 88 88 88 88,
  98. 88 88 88 88 "Y888
  99. */
  100. public OnFilterScriptInit()
  101. {
  102. YSI_FILTERSCRIPT = true;
  103. state _script_init_fix_state : true;
  104. state _ALS : _ALS_go;
  105. #if defined ScriptInit_OnScriptInit
  106. ScriptInit_OnScriptInit();
  107. #endif
  108. #if defined YSI_LOCK_MODE
  109. #if defined FILTERSCRIPT
  110. if (strlen(YSI_gLockData[5]) !=
  111. floatround(floatlog(_LOCK_LEN_0 + 1), floatround_ceil) + 1 +
  112. floatround(floatlog(_LOCK_LEN_1 + 1), floatround_ceil) + 1 +
  113. floatround(floatlog(_LOCK_LEN_2 + 1), floatround_ceil) + 1 +
  114. floatround(floatlog(_LOCK_LEN_3 + 1), floatround_ceil))
  115. {
  116. y_lock 6;
  117. }
  118. #else
  119. new
  120. str[16];
  121. format(str, sizeof (str), "%c%c%c%c%c%c%c%c%c%c%c", '%', 'd', '.', '%', 'd', '.', '%', 'd', '.', '%', 'd');
  122. format(str, sizeof (str), str, _LOCK_IP_0, _LOCK_IP_1, _LOCK_IP_2, _LOCK_IP_3);
  123. if (strlen(YSI_gLockData[5]) != strlen(str))
  124. {
  125. y_lock 7;
  126. }
  127. #endif
  128. #endif
  129. ScriptInit_OnFilterScriptInit();
  130. return 1;
  131. }
  132. public OnGameModeInit()
  133. {
  134. state _ALS : _ALS_go;
  135. if (!YSI_FILTERSCRIPT)
  136. {
  137. state _script_init_fix_state : false;
  138. #if defined ScriptInit_OnScriptInit
  139. ScriptInit_OnScriptInit();
  140. #endif
  141. #if defined YSI_LOCK_MODE
  142. if (YSI_gLockData[
  143. floatround(floatlog(_LOCK_LEN_0 + 1), floatround_ceil) + 1 +
  144. floatround(floatlog(_LOCK_LEN_1 + 1), floatround_ceil) + 1 +
  145. floatround(floatlog(_LOCK_LEN_2 + 1), floatround_ceil) +
  146. floatround(floatlog(_LOCK_LEN_3 + 1), floatround_ceil)] == '\0'
  147. || YSI_gLockData[
  148. floatround(floatlog(_LOCK_LEN_0 + 1), floatround_ceil) + 1 +
  149. floatround(floatlog(_LOCK_LEN_1 + 1), floatround_ceil) + 1 +
  150. floatround(floatlog(_LOCK_LEN_2 + 1), floatround_ceil) + 1 +
  151. floatround(floatlog(_LOCK_LEN_3 + 1), floatround_ceil) + 1] == '\0')
  152. {
  153. y_lock 8;
  154. }
  155. #endif
  156. }
  157. ScriptInit_OnGameModeInit();
  158. return 1;
  159. }
  160. /*
  161. 88888888888 88
  162. 88 "" ,d
  163. 88 88
  164. 88aaaaa 8b, ,d8 88 MM88MMM
  165. 88""""" `Y8, ,8P' 88 88
  166. 88 )888( 88 88
  167. 88 ,d8" "8b, 88 88,
  168. 88888888888 8P' `Y8 88 "Y888
  169. */
  170. public OnFilterScriptExit()
  171. {
  172. ScriptInit_OnFilterScriptExit();
  173. if (YSI_FILTERSCRIPT)
  174. {
  175. ScriptInit_OnScriptExit();
  176. }
  177. return 1;
  178. }
  179. public OnGameModeExit()
  180. {
  181. ScriptInit_OnGameModeExit();
  182. if (!YSI_FILTERSCRIPT)
  183. {
  184. ScriptInit_OnScriptExit();
  185. }
  186. return 1;
  187. }
  188. /*
  189. 88888888888 88
  190. 88 88
  191. 88 88
  192. 88aaaaa ,adPPYba, 8b,dPPYba, 8b db d8 ,adPPYYba, 8b,dPPYba, ,adPPYb,88 ,adPPYba,
  193. 88""""" a8" "8a 88P' "Y8 `8b d88b d8' "" `Y8 88P' "Y8 a8" `Y88 I8[ ""
  194. 88 8b d8 88 `8b d8'`8b d8' ,adPPPPP88 88 8b 88 `"Y8ba,
  195. 88 "8a, ,a8" 88 `8bd8' `8bd8' 88, ,88 88 "8a, ,d88 aa ]8I
  196. 88 `"YbbdP"' 88 YP YP `"8bbdP"Y8 88 `"8bbdP"Y8 `"YbbdP"'
  197. */
  198. #if defined ScriptInit_OnScriptInit
  199. forward ScriptInit_OnScriptInit();
  200. #endif
  201. #if defined _ALS_OnScriptInit
  202. #undef OnScriptInit
  203. #else
  204. #define _ALS_OnScriptInit
  205. #endif
  206. #define OnScriptInit ScriptInit_OnScriptInit
  207. SCRIPT_INIT_FORWARD:OnFilterScriptInit();
  208. #if defined _ALS_OnFilterScriptInit
  209. #undef OnFilterScriptInit
  210. #else
  211. #define _ALS_OnFilterScriptInit
  212. #endif
  213. #define OnFilterScriptInit(%0) ScriptInit_OnFilterScriptInit(%0) <_ALS : _ALS_go>
  214. SCRIPT_INIT_FORWARD:OnGameModeInit();
  215. #if defined _ALS_OnGameModeInit
  216. #undef OnGameModeInit
  217. #else
  218. #define _ALS_OnGameModeInit
  219. #endif
  220. #define OnGameModeInit(%0) ScriptInit_OnGameModeInit(%0) <_ALS : _ALS_go>
  221. SCRIPT_INIT_FORWARD:OnFilterScriptExit();
  222. #if defined _ALS_OnFilterScriptExit
  223. #undef OnFilterScriptExit
  224. #else
  225. #define _ALS_OnFilterScriptExit
  226. #endif
  227. #define OnFilterScriptExit(%0) ScriptInit_OnFilterScriptExit(%0) <_ALS : _ALS_go>
  228. SCRIPT_INIT_FORWARD:OnGameModeExit();
  229. #if defined _ALS_OnGameModeExit
  230. #undef OnGameModeExit
  231. #else
  232. #define _ALS_OnGameModeExit
  233. #endif
  234. #define OnGameModeExit(%0) ScriptInit_OnGameModeExit(%0) <_ALS : _ALS_go>
  235. SCRIPT_INIT_FORWARD:OnScriptExit();
  236. #if defined _ALS_OnScriptExit
  237. #undef OnScriptExit
  238. #else
  239. #define _ALS_OnScriptExit
  240. #endif
  241. #define OnScriptExit(%0) ScriptInit_OnScriptExit(%0) <_ALS : _ALS_go>
  242. /*
  243. ad88888ba 88 88
  244. d8" "8b 88 ,d 88
  245. Y8, 88 88 88
  246. `Y8aaaaa, 88,dPPYba, 88 88 MM88MMM ,adPPYb,88 ,adPPYba, 8b db d8 8b,dPPYba,
  247. `"""""8b, 88P' "8a 88 88 88 a8" `Y88 a8" "8a `8b d88b d8' 88P' `"8a
  248. `8b 88 88 88 88 88 8b 88 8b d8 `8b d8'`8b d8' 88 88
  249. Y8a a8P 88 88 "8a, ,a88 88, "8a, ,d88 "8a, ,a8" `8bd8' `8bd8' 88 88
  250. "Y88888P" 88 88 `"YbbdP'Y8 "Y888 `"8bbdP"Y8 `"YbbdP"' YP YP 88 88
  251. */
  252. // I'm not quite sure what causes it, but there seems to be a bug in the
  253. // compiler somewhere which messes up the "ysi_debug" automaton and the
  254. // "YSI_FILTERSCRIPT" variable :(.
  255. public _ScriptInit_FixState() <_script_init_fix_state : true>
  256. {
  257. }
  258. public _ScriptInit_FixState() <_script_init_fix_state : false>
  259. {
  260. }
  261. static stock _ScriptInit_IncludeStates() <_ALS : _ALS_x0, _ALS : _ALS_x1, _ALS : _ALS_x2, _ALS : _ALS_x3>
  262. {
  263. }
  264. static stock _ScriptInit_IncludeStates() <_ALS : _ALS_go>
  265. {
  266. }