y_scriptinit.inc 11 KB

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