y_remote.inc 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. /*----------------------------------------------------------------------------*\
  2. ==========
  3. y_remote
  4. ==========
  5. Description:
  6. Wrapper for "__CallRemoteFunction". Enforces some features like no returns
  7. and arrays being followed by their length.
  8. Legal:
  9. Version: MPL 1.1
  10. The contents of this file are subject to the Mozilla Public License Version
  11. 1.1 (the "License"); you may not use this file except in compliance with
  12. the License. You may obtain a copy of the License at
  13. http://www.mozilla.org/MPL/
  14. Software distributed under the License is distributed on an "AS IS" basis,
  15. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  16. for the specific language governing rights and limitations under the
  17. License.
  18. The Original Code is the YSI master systems include.
  19. The Initial Developer of the Original Code is Alex "Y_Less" Cole.
  20. Portions created by the Initial Developer are Copyright (C) 2011
  21. the Initial Developer. All Rights Reserved.
  22. Contributors:
  23. ZeeX, koolk, JoeBullet/Google63, g_aSlice/Slice
  24. Thanks:
  25. JoeBullet/Google63 - Handy arbitrary ASM jump code using SCTRL.
  26. ZeeX - Very productive conversations.
  27. koolk - IsPlayerinAreaEx code.
  28. TheAlpha - Danish translation.
  29. breadfish - German translation.
  30. Fireburn - Dutch translation.
  31. yom - French translation.
  32. 50p - Polish translation.
  33. Zamaroht - Spanish translation.
  34. Dracoblue, sintax, mabako, Xtreme, other coders - Producing other modes
  35. for me to strive to better.
  36. Pixels^ - Running XScripters where the idea was born.
  37. Matite - Pestering me to release it and using it.
  38. Very special thanks to:
  39. Thiadmer - PAWN, whose limits continue to amaze me!
  40. Kye/Kalcor - SA:MP.
  41. SA:MP Team past, present and future - SA:MP.
  42. Version:
  43. 1.0
  44. Changelog:
  45. 04/10/12:
  46. Added local versions of the function for no master system servers.
  47. Functions:
  48. Public:
  49. -
  50. Core:
  51. -
  52. Stock:
  53. -
  54. Static:
  55. -
  56. Inline:
  57. -
  58. API:
  59. -
  60. Hooks:
  61. -
  62. Callbacks:
  63. -
  64. Definitions:
  65. -
  66. Enums:
  67. -
  68. Macros:
  69. remotefunc - Define a function to be called remotely (use like "stock").
  70. broadcastfunc - Call the function, but in all scripts.
  71. localfunc - Call the function by name, not address, in the current script.
  72. Tags:
  73. -
  74. Variables:
  75. Global:
  76. -
  77. Static:
  78. -
  79. Commands:
  80. -
  81. Compile options:
  82. YSI_NO_MASTER - Disable all knowledge of other scripts.
  83. Operators:
  84. -
  85. Natives:
  86. -
  87. \*----------------------------------------------------------------------------*/
  88. #include "internal\y_version"
  89. #include "internal\y_shortfunc"
  90. #include "y_utils"
  91. /*#if !defined YSIM_HAS_MASTER
  92. #include "internal\y_masterresolve"
  93. #define _Y_REMOTE_MASTER_CLEANUP
  94. #endif*/
  95. // This VERY LOOSELY uses the master system to figure out if it should even
  96. // bother with complex remote calls. However, it isn't fully bound by the
  97. // whole system because it's rules are different (and will work regardless).
  98. #if defined YSI_NO_MASTER
  99. // This DOESN'T use "stock" as it can't be called from another script.
  100. #define remotefunc
  101. #define localfunc%0(%1) (%0(%1))
  102. #define broadcastfunc%0(%1) (%0(%1))
  103. #define targetfunc%3<%2>%0(%1) (%3%0(%1))
  104. #else
  105. // IMPORTANT NOTE! To avoid polluting the global name space (any more that
  106. // is), "y_inline" uses @Ru, @Rv, @Rw, @Rx and @Ry, as both files are low
  107. // usage. "y_testing" uses @Rf-@Ro.
  108. //#define remote remote%0(%1) stock%0@(%1)if(J@)W@(#%0,@Ra:@Rb:@Rc:#i#,I@);
  109. //#define remote%0(%1) stock%0@(%1) {return I@==-1?(J@?(W@(_:@Rz:#%0##,_YM@CR:%1,,))
  110. //#define remote%0(%1) stock%0@(%1)return I@==-1?(J@?(W@(_:@Rz:#%0##,_YM@CR:%1,,)):(P@(#%0))):(W@(#%0_@));%0_@(__m,%1);%0(%1);public %0_@(__m,%1)
  111. // This uses "stock" as it may be called from another script.
  112. #define remotefunc%0(%1) stock%0_(%1)return J@?(W@(_:@Rz:#%0@##,_YM@CR:%1,,)):(%0());%0@(__m);public %0@(__m)if(__m==-1||__m==_@)%0();%0(%1)
  113. //:(P@(#%0##%1,,))):(W@(#%0_@##%1,,));%0(%1);}//_YM@CT:%0_@(%1,_YM@CU);public _YM@CT:%0_@(%1,_YM@CU)//if(_@==_:_YM@CV:_YM@CU)%0(%1,,);public%0(%1)
  114. //if(FALSE){}else
  115. //#define _YM@CR:%0,%1)):P@(%0##%2,%3))): @Ra:@Rb:@Rc:##|||%0|||%1)):P@(%0##,##|||%2|||%3))):
  116. // One macro to rule them all. Instead of doing the parameter validation
  117. // and extraction multiple times, we just do it once and copy the values
  118. // when we're done with them all. The macro is designed to be almost
  119. // entirely right if the function has no parameters.
  120. #define _YM@CR:%0,%1) @Ra:@Rb:@Rc:##|||%0|||%1)
  121. #define @Ra:@Rb:@Rc:#%0#%1|||%3[%4]%9|||%5,%6) @Rd:@Re:#%0#%1|||%3|||%5,%6)
  122. #define @Rd:@Re:#%0#%1|||%2string:%3|||%5,%6) @Ra:@Rb:@Rc:#%0s#%1,%3|||%5|||%6)
  123. #define @Re:#%0#%1|||%3|||%5,%6,%7) @Ra:@Rb:@Rc:#%0a#%1,%3|||%5|||%6,%7)
  124. #define @Rb:@Rc:#%0#%1|||%3|||%5,%6) @Ra:@Rb:@Rc:#%0i#%1,%3|||%5|||%6)
  125. #define @Rc:#%0#,%1||||||)):(%2());%3(__m);%5(__m)if(%7)%8();%4(%6) #%0i,%1,I@)):(%2(%1));%3(%6,__m);%5(%6,__m)if(%7)%8(%1);%4(%6)
  126. #define @Rz:#%0##,_YM@CR:,,) #%0,#i,I@)
  127. //#define __m,) __m)
  128. #define localfunc%0(%1) (J@=0,I@=-1,%0_(%1))
  129. #define broadcastfunc%0(%1) (J@=1,I@=-1,%0_(%1))
  130. // This supports "target<master> func()" and "target func<master>()".
  131. #define targetfunc%3<%2>%0(%1) (J@=1,I@=(%2),%3%0_(%1))
  132. /*#define @Rp:#%0##,_YM@CR:,I@,,) #%0##,#i,I@)
  133. #define local%0(%1) (J@=0,%0@(%1))
  134. #define broadcastfunc%0(%1) (J@=1,I@=-1,%0@(%1))
  135. #define target%0(%1)<%2> (J@=1,I@=(%2),%0@(%1))
  136. #define _YM@CT:%0(,%1) _YM@CT:%0(__m)
  137. //#define @Rq:@Rr:@Rs:@Rt:__m)%0(%1|||%2string:%3[%4]%9|||%7,%8) @Rq:@Rr:@Rs:@Rt:__m)%0(%1,%3|||%7|||%8)
  138. //#define @Rr:@Rs:@Rt:__m)%0(%1|||%3[%4]%9|||%7,%8) @Rq:@Rr:@Rs:@Rt:__m)%0(%1,%3|||%7|||%8)
  139. //#define @Rs:@Rt:__m)%0(%1|||%3|||%7,%8) @Rq:@Rr:@Rs:@Rt:__m)%0(%1,%3|||%7|||%8)
  140. //#define @Rt:__m)%0(%1||||||) __m)%0(%1)
  141. #define _YM@CV:_YM@CU)%0(,,) __m)%0()
  142. #define _YM@CU)%0(%1,%2) @Rq:@Rr:@Rs:@Rt:__m)%0(|||%1|||%2)*/
  143. /*#define remote%0(%1) stock%0@(%1)if(J@)W@(_:@Rz:#%0##,_YM@CR:%1,,);else P@(_:@Rz:#%0##,_YM@CR:%1,,);%0(%1);public%0(%1)//if(FALSE){}else
  144. #define _YM@CR:%0,%1) @Ra:@Rb:@Rc:##|||%0|||%1)
  145. #define @Ra:@Rb:@Rc:#%0#%1|||%3[%4]|||%5,%6) @Rd:@Re:#%0#%1|||%3|||%5,%6)
  146. #define @Rd:@Re:#%0#%1|||%2string:%3|||%5,%6) @Ra:@Rb:@Rc:#%0s#%1,%3|||%5|||%6)
  147. #define @Re:#%0#%1|||%3|||%5,%6,%7) @Ra:@Rb:@Rc:#%0a#%1,%3|||%5|||%6,%7)
  148. #define @Rb:@Rc:#%0#%1|||%3|||%5,%6) @Ra:@Rb:@Rc:#%0i#%1,%3|||%5|||%6)
  149. #define @Rc:%0||||||) %0)
  150. #define @Rz:#%0##,_YM@CR:,,) #%0##,#i,I@)*/
  151. //if(I@==-1){if(J@);else ;}else ;
  152. //return I@==-1?(J@?():()):();
  153. //target Moo(5, 6)<7>;
  154. //target Moo<7>(5, 6);
  155. //target<7> Moo(5, 6);
  156. #endif
  157. /*#if defined _Y_REMOTE_MASTER_CLEANUP
  158. #undef _Y_REMOTE_MASTER_CLEANUP
  159. #undef YSIM_HAS_MASTER
  160. #undef _YSIM_IS_CLIENT
  161. #undef _YSIM_IS_SERVER
  162. #undef _YSIM_IS_STUB
  163. #undef _YSIM_IS_CLOUD
  164. #endif*/