y_scriptinit.inc 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  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. 30/04/11:
  50. First version
  51. </remarks>
  52. \**--------------------------------------------------------------------------**/
  53. #include <a_samp>
  54. #include "internal\y_natives"
  55. forward _ScriptInit_FixState();
  56. #if defined FILTERSCRIPT
  57. #if !defined YSI_FILTERSCRIPT
  58. stock
  59. bool:YSI_FILTERSCRIPT = true;
  60. #endif
  61. public OnFilterScriptInit()
  62. {
  63. state _script_init_fix_state : true;
  64. #if defined ScriptInit_OnScriptInit
  65. ScriptInit_OnScriptInit();
  66. #endif
  67. #if defined YSI_LOCK_MODE
  68. if (strlen(YSI_gLockData[5]) !=
  69. floatround(floatlog(_LOCK_LEN_0 + 1), floatround_ceil) + 1 +
  70. floatround(floatlog(_LOCK_LEN_1 + 1), floatround_ceil) + 1 +
  71. floatround(floatlog(_LOCK_LEN_2 + 1), floatround_ceil) + 1 +
  72. floatround(floatlog(_LOCK_LEN_3 + 1), floatround_ceil))
  73. {
  74. y_lock 6;
  75. }
  76. #endif
  77. #if defined ScriptInit_OnFilterScriptInit
  78. return ScriptInit_OnFilterScriptInit();
  79. #else
  80. return 1;
  81. #endif
  82. }
  83. #if defined ScriptInit_OnFilterScriptInit
  84. forward ScriptInit_OnFilterScriptInit();
  85. #endif
  86. #if defined _ALS_OnFilterScriptInit
  87. #undef OnFilterScriptInit
  88. #else
  89. #define _ALS_OnFilterScriptInit
  90. #endif
  91. #define OnFilterScriptInit ScriptInit_OnFilterScriptInit
  92. #else
  93. // People can't be trusted to use "FILTERSCRIPT"...
  94. #if !defined YSI_FILTERSCRIPT
  95. new
  96. bool:YSI_FILTERSCRIPT = false;
  97. #endif
  98. public OnFilterScriptInit()
  99. {
  100. state _script_init_fix_state : true;
  101. YSI_FILTERSCRIPT = true;
  102. #if defined ScriptInit_OnScriptInit
  103. ScriptInit_OnScriptInit();
  104. #endif
  105. #if defined YSI_LOCK_MODE
  106. new
  107. str[16];
  108. format(str, sizeof (str), "%c%c%c%c%c%c%c%c%c%c%c", '%', 'd', '.', '%', 'd', '.', '%', 'd', '.', '%', 'd');
  109. format(str, sizeof (str), str, _LOCK_IP_0, _LOCK_IP_1, _LOCK_IP_2, _LOCK_IP_3);
  110. if (strlen(YSI_gLockData[5]) != strlen(str))
  111. {
  112. y_lock 7;
  113. }
  114. #endif
  115. #if defined ScriptInit_OnFilterScriptInit
  116. return ScriptInit_OnFilterScriptInit();
  117. #else
  118. return 1;
  119. #endif
  120. }
  121. public OnGameModeInit()
  122. {
  123. if (YSI_FILTERSCRIPT)
  124. {
  125. state _script_init_fix_state : true;
  126. #if defined ScriptInit_OnGameModeInit
  127. return ScriptInit_OnGameModeInit();
  128. #else
  129. return 1;
  130. #endif
  131. }
  132. else
  133. {
  134. state _script_init_fix_state : false;
  135. #if defined ScriptInit_OnScriptInit
  136. ScriptInit_OnScriptInit();
  137. #endif
  138. #if defined YSI_LOCK_MODE
  139. if (YSI_gLockData[
  140. floatround(floatlog(_LOCK_LEN_0 + 1), floatround_ceil) + 1 +
  141. floatround(floatlog(_LOCK_LEN_1 + 1), floatround_ceil) + 1 +
  142. floatround(floatlog(_LOCK_LEN_2 + 1), floatround_ceil) +
  143. floatround(floatlog(_LOCK_LEN_3 + 1), floatround_ceil)] == '\0'
  144. || YSI_gLockData[
  145. floatround(floatlog(_LOCK_LEN_0 + 1), floatround_ceil) + 1 +
  146. floatround(floatlog(_LOCK_LEN_1 + 1), floatround_ceil) + 1 +
  147. floatround(floatlog(_LOCK_LEN_2 + 1), floatround_ceil) + 1 +
  148. floatround(floatlog(_LOCK_LEN_3 + 1), floatround_ceil) + 1] == '\0')
  149. {
  150. y_lock 8;
  151. }
  152. #endif
  153. #if defined ScriptInit_OnGameModeInit
  154. return ScriptInit_OnGameModeInit();
  155. #else
  156. return 1;
  157. #endif
  158. }
  159. }
  160. #if defined _ALS_OnGameModeInit
  161. #undef OnGameModeInit
  162. #else
  163. #define _ALS_OnGameModeInit
  164. #endif
  165. #define OnGameModeInit ScriptInit_OnGameModeInit
  166. #if defined ScriptInit_OnGameModeInit
  167. forward ScriptInit_OnGameModeInit();
  168. #endif
  169. #if defined _ALS_OnFilterScriptInit
  170. #undef OnFilterScriptInit
  171. #else
  172. #define _ALS_OnFilterScriptInit
  173. #endif
  174. #define OnFilterScriptInit ScriptInit_OnFilterScriptInit
  175. #if defined ScriptInit_OnFilterScriptInit
  176. forward ScriptInit_OnFilterScriptInit();
  177. #endif
  178. #endif
  179. #if defined FILTERSCRIPT
  180. public OnFilterScriptExit()
  181. {
  182. #if defined ScriptInit_OnScriptExit
  183. ScriptInit_OnScriptExit();
  184. #endif
  185. #if defined ScriptInit_OnFilterScriptExit
  186. new
  187. ret = ScriptInit_OnFilterScriptExit();
  188. #endif
  189. #if defined __YSI_SpecialExit
  190. __YSI_SpecialExit();
  191. #endif
  192. #if defined ScriptInit_OnFilterScriptExit
  193. return ret;
  194. #else
  195. return 1;
  196. #endif
  197. }
  198. #if defined _ALS_OnFilterScriptExit
  199. #undef OnFilterScriptExit
  200. #else
  201. #define _ALS_OnFilterScriptExit
  202. #endif
  203. #define OnFilterScriptExit ScriptInit_OnFilterScriptExit
  204. #if defined ScriptInit_OnFilterScriptExit
  205. forward ScriptInit_OnFilterScriptExit();
  206. #endif
  207. #else
  208. public OnFilterScriptExit()
  209. {
  210. if (YSI_FILTERSCRIPT)
  211. {
  212. #if defined ScriptInit_OnScriptExit
  213. ScriptInit_OnScriptExit();
  214. #endif
  215. #if defined ScriptInit_OnFilterScriptExit
  216. new
  217. ret = ScriptInit_OnFilterScriptExit();
  218. #endif
  219. #if defined __YSI_SpecialExit
  220. __YSI_SpecialExit();
  221. #endif
  222. #if defined ScriptInit_OnFilterScriptExit
  223. return ret;
  224. #else
  225. return 1;
  226. #endif
  227. }
  228. return 1;
  229. }
  230. public OnGameModeExit()
  231. {
  232. if (YSI_FILTERSCRIPT)
  233. {
  234. #if defined ScriptInit_OnGameModeExit
  235. return ScriptInit_OnGameModeExit();
  236. #else
  237. return 1;
  238. #endif
  239. }
  240. else
  241. {
  242. #if defined ScriptInit_OnScriptExit
  243. ScriptInit_OnScriptExit();
  244. #endif
  245. #if defined ScriptInit_OnGameModeExit
  246. new
  247. ret = ScriptInit_OnGameModeExit();
  248. #endif
  249. #if defined __YSI_SpecialExit
  250. __YSI_SpecialExit();
  251. #endif
  252. #if defined ScriptInit_OnGameModeExit
  253. return ret;
  254. #else
  255. return 1;
  256. #endif
  257. }
  258. }
  259. #if defined _ALS_OnGameModeExit
  260. #undef OnGameModeExit
  261. #else
  262. #define _ALS_OnGameModeExit
  263. #endif
  264. #define OnGameModeExit ScriptInit_OnGameModeExit
  265. #if defined _ALS_OnFilterScriptExit
  266. #undef OnFilterScriptExit
  267. #else
  268. #define _ALS_OnFilterScriptExit
  269. #endif
  270. #define OnFilterScriptExit ScriptInit_OnFilterScriptExit
  271. #if defined ScriptInit_OnFilterScriptExit
  272. forward ScriptInit_OnFilterScriptExit();
  273. #endif
  274. #if defined ScriptInit_OnGameModeExit
  275. forward ScriptInit_OnGameModeExit();
  276. #endif
  277. #endif
  278. #define OnScriptInit ScriptInit_OnScriptInit
  279. #define _ALS_OnScriptInit
  280. #if defined ScriptInit_OnScriptInit
  281. forward ScriptInit_OnScriptInit();
  282. #endif
  283. #define OnScriptExit ScriptInit_OnScriptExit
  284. #define _ALS_OnScriptExit
  285. #if defined ScriptInit_OnScriptExit
  286. forward ScriptInit_OnScriptExit();
  287. #endif
  288. #define _YSI_SpecialExit __YSI_SpecialExit
  289. #define _ALS__YSI_SpecialExit
  290. #if defined __YSI_SpecialExit
  291. forward __YSI_SpecialExit();
  292. #endif
  293. // I'm not quite sure what causes it, but there seems to be a bug in the
  294. // compiler somewhere which messes up the "ysi_debug" automaton and the
  295. // "YSI_FILTERSCRIPT" variable :(.
  296. public _ScriptInit_FixState() <_script_init_fix_state : true>
  297. {
  298. }
  299. public _ScriptInit_FixState() <_script_init_fix_state : false>
  300. {
  301. }