y_scriptinit.inc 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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. \*----------------------------------------------------------------------------*/
  52. #include <a_samp>
  53. #include "internal\y_natives"
  54. forward _ScriptInit_FixState();
  55. #if defined FILTERSCRIPT
  56. #if !defined YSI_FILTERSCRIPT
  57. stock
  58. bool:YSI_FILTERSCRIPT = true;
  59. #endif
  60. public OnFilterScriptInit()
  61. {
  62. state _script_init_fix_state : true;
  63. CallLocalFunction("ScriptInit_OnScriptInit", "");
  64. #if defined YSI_LOCK_MODE
  65. if (strlen(YSI_gLockData[5]) !=
  66. floatround(floatlog(_LOCK_LEN_0 + 1), floatround_ceil) + 1 +
  67. floatround(floatlog(_LOCK_LEN_1 + 1), floatround_ceil) + 1 +
  68. floatround(floatlog(_LOCK_LEN_2 + 1), floatround_ceil) + 1 +
  69. floatround(floatlog(_LOCK_LEN_3 + 1), floatround_ceil))
  70. {
  71. y_lock 6;
  72. }
  73. #endif
  74. //CallRemoteFunction("ScriptInit_OnAnyScriptInit", "");
  75. CallLocalFunction("ScriptInit_OnFilterScriptInit", "");
  76. //CallLocalFunction("ScriptInit_OnScriptInitLate", "");
  77. //CallLocalFunction("Text_Special_OnScriptInit", "");
  78. }
  79. #if defined _ALS_OnFilterScriptInit
  80. #undef OnFilterScriptInit
  81. #else
  82. #define _ALS_OnFilterScriptInit
  83. #endif
  84. #define OnFilterScriptInit ScriptInit_OnFilterScriptInit
  85. forward ScriptInit_OnFilterScriptInit();
  86. #else
  87. // People can't be trusted to use "FILTERSCRIPT"...
  88. new
  89. #if !defined YSI_FILTERSCRIPT
  90. bool:YSI_FILTERSCRIPT = false,
  91. #endif
  92. bool:YSI_g_sScriptInitGM,
  93. bool:YSI_g_sScriptExitGM;
  94. public OnFilterScriptInit()
  95. {
  96. state _script_init_fix_state : true;
  97. //printf("OFSI");
  98. YSI_FILTERSCRIPT = true;
  99. YSI_g_sScriptInitGM = funcidx("ScriptInit_OnGameModeInit") != -1;
  100. YSI_g_sScriptExitGM = funcidx("ScriptInit_OnGameModeExit") != -1;
  101. CallLocalFunction("ScriptInit_OnScriptInit", "");
  102. #if defined YSI_LOCK_MODE
  103. new
  104. str[16];
  105. format(str, sizeof (str), "%c%c%c%c%c%c%c%c%c%c%c", '%', 'd', '.', '%', 'd', '.', '%', 'd', '.', '%', 'd');
  106. format(str, sizeof (str), str, _LOCK_IP_0, _LOCK_IP_1, _LOCK_IP_2, _LOCK_IP_3);
  107. if (strlen(YSI_gLockData[5]) != strlen(str))
  108. {
  109. y_lock 7;
  110. }
  111. #endif
  112. //CallRemoteFunction("ScriptInit_OnAnyScriptInit", "");
  113. CallLocalFunction("ScriptInit_OnFilterScriptInit", "");
  114. //CallLocalFunction("ScriptInit_OnScriptInitLate", "");
  115. //CallLocalFunction("Text_SpecialInit", "");
  116. }
  117. public OnGameModeInit()
  118. {
  119. if (YSI_FILTERSCRIPT)
  120. {
  121. state _script_init_fix_state : true;
  122. if (YSI_g_sScriptInitGM)
  123. {
  124. CallLocalFunction("ScriptInit_OnGameModeInit", "");
  125. }
  126. }
  127. else
  128. {
  129. state _script_init_fix_state : false;
  130. CallLocalFunction("ScriptInit_OnScriptInit", "");
  131. #if defined YSI_LOCK_MODE
  132. if (YSI_gLockData[
  133. floatround(floatlog(_LOCK_LEN_0 + 1), floatround_ceil) + 1 +
  134. floatround(floatlog(_LOCK_LEN_1 + 1), floatround_ceil) + 1 +
  135. floatround(floatlog(_LOCK_LEN_2 + 1), floatround_ceil) +
  136. floatround(floatlog(_LOCK_LEN_3 + 1), floatround_ceil)] == '\0'
  137. || YSI_gLockData[
  138. floatround(floatlog(_LOCK_LEN_0 + 1), floatround_ceil) + 1 +
  139. floatround(floatlog(_LOCK_LEN_1 + 1), floatround_ceil) + 1 +
  140. floatround(floatlog(_LOCK_LEN_2 + 1), floatround_ceil) + 1 +
  141. floatround(floatlog(_LOCK_LEN_3 + 1), floatround_ceil) + 1] == '\0')
  142. {
  143. y_lock 8;
  144. }
  145. #endif
  146. //CallRemoteFunction("ScriptInit_OnAnyScriptInit", "");
  147. CallLocalFunction("ScriptInit_OnGameModeInit", "");
  148. //CallLocalFunction("ScriptInit_OnScriptLate", "");
  149. //CallLocalFunction("Text_SpecialInit", "");
  150. }
  151. }
  152. #if defined _ALS_OnGameModeInit
  153. #undef OnGameModeInit
  154. #else
  155. #define _ALS_OnGameModeInit
  156. #endif
  157. #define OnGameModeInit ScriptInit_OnGameModeInit
  158. #if defined _ALS_OnFilterScriptInit
  159. #undef OnFilterScriptInit
  160. #else
  161. #define _ALS_OnFilterScriptInit
  162. #endif
  163. #define OnFilterScriptInit ScriptInit_OnFilterScriptInit
  164. forward ScriptInit_OnFilterScriptInit();
  165. forward ScriptInit_OnGameModeInit();
  166. #endif
  167. #if defined FILTERSCRIPT
  168. public OnFilterScriptExit()
  169. {
  170. CallLocalFunction("ScriptInit_OnScriptExit", "");
  171. //CallRemoteFunction("ScriptInit_OnAnyScriptExit", "");
  172. CallLocalFunction("ScriptInit_OnFilterScriptExit", "");
  173. //CallLocalFunction("ScriptInit_OnScriptExitLate", "");
  174. }
  175. #if defined _ALS_OnFilterScriptExit
  176. #undef OnFilterScriptExit
  177. #else
  178. #define _ALS_OnFilterScriptExit
  179. #endif
  180. #define OnFilterScriptExit ScriptInit_OnFilterScriptExit
  181. forward ScriptInit_OnFilterScriptExit();
  182. #else
  183. public OnFilterScriptExit()
  184. {
  185. if (YSI_FILTERSCRIPT)
  186. {
  187. CallLocalFunction("ScriptInit_OnScriptExit", "");
  188. //CallRemoteFunction("ScriptInit_OnAnyScriptExit", "");
  189. CallLocalFunction("ScriptInit_OnFilterScriptExit", "");
  190. //CallLocalFunction("ScriptInit_OnScriptExitLate", "");
  191. }
  192. }
  193. public OnGameModeExit()
  194. {
  195. //printf("ScriptInit_OnGameModeExit");
  196. if (YSI_FILTERSCRIPT)
  197. {
  198. if (YSI_g_sScriptExitGM)
  199. {
  200. CallLocalFunction("ScriptInit_OnGameModeExit", "");
  201. }
  202. }
  203. else
  204. {
  205. //printf("NF 0");
  206. CallLocalFunction("ScriptInit_OnScriptExit", "");
  207. //printf("NF 1");
  208. //CallRemoteFunction("ScriptInit_OnAnyScriptExit", "");
  209. CallLocalFunction("ScriptInit_OnGameModeExit", "");
  210. //printf("NF 2");
  211. //CallLocalFunction("ScriptInit_OnScriptExitLate", "");
  212. }
  213. }
  214. #if defined _ALS_OnGameModeExit
  215. #undef OnGameModeExit
  216. #else
  217. #define _ALS_OnGameModeExit
  218. #endif
  219. #define OnGameModeExit ScriptInit_OnGameModeExit
  220. #if defined _ALS_OnFilterScriptExit
  221. #undef OnFilterScriptExit
  222. #else
  223. #define _ALS_OnFilterScriptExit
  224. #endif
  225. #define OnFilterScriptExit ScriptInit_OnFilterScriptExit
  226. forward ScriptInit_OnFilterScriptExit();
  227. forward ScriptInit_OnGameModeExit();
  228. #endif
  229. #define OnScriptInit ScriptInit_OnScriptInit
  230. forward OnScriptInit();
  231. #define OnScriptExit ScriptInit_OnScriptExit
  232. forward OnScriptExit();
  233. /*#define OnScriptInitLate ScriptInit_OnScriptInitLate
  234. forward OnScriptInitLate();
  235. #define OnScriptExitLate ScriptInit_OnScriptExitLate
  236. forward OnScriptExitLate();
  237. #define OnAnyScriptInit ScriptInit_OnAnyScriptInit
  238. forward OnAnyScriptInit();
  239. #define OnAnyScriptExit ScriptInit_OnAnyScriptExit
  240. forward OnAnyScriptExit();*/
  241. // I'm not quite sure what causes it, but there seems to be a bug in the
  242. // compiler somewhere which messes up the "ysi_debug" automaton and the
  243. // "YSI_FILTERSCRIPT" variable :(.
  244. public _ScriptInit_FixState() <_script_init_fix_state : true>
  245. {
  246. }
  247. public _ScriptInit_FixState() <_script_init_fix_state : false>
  248. {
  249. }