y_scriptinit.inc 10.0 KB

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