impl.inc 71 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370
  1. /**--------------------------------------------------------------------------**\
  2. ===========================
  3. Y Sever Includes - INI Core
  4. ===========================
  5. Description:
  6. Does some internal processing for the text system.
  7. Legal:
  8. Version: MPL 1.1
  9. The contents of this file are subject to the Mozilla Public License Version
  10. 1.1 (the "License"); you may not use this file except in compliance with
  11. the License. You may obtain a copy of the License at
  12. http://www.mozilla.org/MPL/
  13. Software distributed under the License is distributed on an "AS IS" basis,
  14. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  15. for the specific language governing rights and limitations under the
  16. License.
  17. The Original Code is the YSI ini include.
  18. The Initial Developer of the Original Code is Alex "Y_Less" Cole.
  19. Portions created by the Initial Developer are Copyright (C) 2011
  20. the Initial Developer. All Rights Reserved.
  21. Contributors:
  22. ZeeX, koolk, JoeBullet/Google63, g_aSlice/Slice
  23. Thanks:
  24. JoeBullet/Google63 - Handy arbitrary ASM jump code using SCTRL.
  25. ZeeX - Very productive conversations.
  26. koolk - IsPlayerinAreaEx code.
  27. TheAlpha - Danish translation.
  28. breadfish - German translation.
  29. Fireburn - Dutch translation.
  30. yom - French translation.
  31. 50p - Polish translation.
  32. Zamaroht - Spanish translation.
  33. Dracoblue, sintax, mabako, Xtreme, other coders - Producing other modes
  34. for me to strive to better.
  35. Pixels^ - Running XScripters where the idea was born.
  36. Matite - Pestering me to release it and using it.
  37. Very special thanks to:
  38. Thiadmer - PAWN, whose limits continue to amaze me!
  39. Kye/Kalcor - SA:MP.
  40. SA:MP Team past, present and future - SA:MP.
  41. Version:
  42. 1.0
  43. Changelog:
  44. 01/05/11:
  45. First version.
  46. Functions:
  47. Public:
  48. -
  49. Core:
  50. -
  51. Stock:
  52. -
  53. Static:
  54. -
  55. Inline:
  56. -
  57. API:
  58. -
  59. Callbacks:
  60. -
  61. Definitions:
  62. -
  63. Enums:
  64. -
  65. Macros:
  66. -
  67. Tags:
  68. -
  69. Variables:
  70. Global:
  71. -
  72. Static:
  73. -
  74. Commands:
  75. -
  76. Compile options:
  77. -
  78. Operators:
  79. -
  80. </remarks>
  81. \**--------------------------------------------------------------------------**/
  82. enum e_TEXT_DISPLAY_TYPE
  83. {
  84. text_type_print = cellmin,
  85. text_type_3d = -4,
  86. text_type_player = -3,
  87. text_type_alert = -2,
  88. text_type_td = -1,
  89. text_type_client = 0,
  90. text_type_game1,
  91. text_type_game2,
  92. text_type_game3,
  93. text_type_game4,
  94. text_type_game5,
  95. text_type_game6
  96. }
  97. //#include "..\y_master"
  98. // End conditions for the recursive calls (strings and publics).
  99. #define _YT@LE@E%0>
  100. #define _YT@LT@E%0> ;
  101. // Recursive wanted text definition. Needs two levels of indirection to strip
  102. // the excess commas (,%0,%1).
  103. #if defined Y_TEXT_UNIQUE
  104. #define _YT@LO(,%0,%1) UNIQUE_FUNCTION<%0@%1@...@yX_>();public UNIQUE_FUNCTION<%0@%1@...@yX_>(){}
  105. #else
  106. #define _YT@LO(,%0,%1) %0@%1@yX_();public %0@%1@yX_(){}
  107. #endif
  108. #define _YT@LE%0[%1]%2> _YT@LO(%0,%1) _YT@LE%2>
  109. // Recursive local default string definition.
  110. #define _YT@LJ(,%0,%1) #%0":"#%1"|"
  111. #define _YT@LT%0[%1]%2> _YT@LJ(%0,%1)_YT@LT%2>
  112. // Recursive macro with clever ending to load many items from 1 "loadtext"
  113. // keyword. NOW RENAMED FROM JUST "text" - WORST NAMING EVER!
  114. #define loadtext%0[%1]%2; _YT@LE,%0[%1]%2@E>static stock DEFAULT_TEXT_SET[]=_YT@LT,%0[%1]%2@E>
  115. #define Text_RegisterTag(%1) \
  116. loadtext core[%1]
  117. // Clever macros to load default values when not specified.
  118. //#define Text_Send(%0,%1) _Text_Send(%0,DEFAULT_TEXT_SET,#%1)
  119. #define DO_TEXT_SET: _:HAS_TEXT_SET:NO_TEXT_SET:
  120. #define HAS_TEXT_SET:NO_TEXT_SET:%0$%1||| DEFAULT_TEXT_SET,#%1|||
  121. #define NO_TEXT_SET: "\3",
  122. #define DEFAULT_TEXT_SET,#%1->%2||| #core#:#%1#|,#%2|||
  123. // WTF does this do? I can't even remember what slots are!
  124. //#define core":"#%1:%2"|",%3) %1":"#%2"|",%3)
  125. #define core#:#%1[%2]%9#|,%3) %1#:#%2#|,%3)
  126. /*#if defined _inc_y_languages
  127. #define Text_GetLanguageCodes() Langs_GetLanguageCodes()
  128. #define Text_GetPlayerLanguage(%0) Langs_GetPlayerLanguage(%0)
  129. #else
  130. // y_languages doesn't really do much TBH... This used to have three
  131. // langugages, but then I realised that without the "y_languages"
  132. // library there was no way for a player to select their language.
  133. // "XX" is used as a dummy to ensure that the array in the enum is always
  134. // valid and that the compiler doesn't optimise it out.
  135. #define Text_GetLanguageCodes() "EN|XX|" //|NL|ES|"
  136. // Number of "|" separated strings above (always 1).
  137. #define YSI_MAX_LANGUAGES (Language:2)
  138. #define Text_GetPlayerLanguage(%0) (Language:0)
  139. #endif*/
  140. // Return types
  141. enum E_TEXT_FIND
  142. {
  143. E_TEXT_FIND_NONE,
  144. E_TEXT_FIND_JUST,
  145. E_TEXT_FIND_MANY
  146. }
  147. // This holds the data for all entry points.
  148. enum e_TEXT_SETS
  149. {
  150. e_TEXT_SETS_NAME[28],
  151. e_TEXT_SETS_HASH,
  152. e_TEXT_SETS_INDEX,
  153. e_TEXT_SETS_LOADED
  154. }
  155. enum e_TEXT_ENTRY
  156. {
  157. e_TEXT_ENTRY_NAME[MAX_INI_ENTRY_NAME],// char],
  158. e_TEXT_ENTRY_HASH,
  159. e_TEXT_ENTRY_LEFT,
  160. e_TEXT_ENTRY_RIGHT,
  161. e_TEXT_ENTRY_POINTERS[YSI_MAX_LANGUAGES]
  162. }
  163. #define TEXT_MASTER YSI_g_sDistributionID
  164. #if !defined MAX_SINGLE_TEXT_ITEM
  165. #define MAX_SINGLE_TEXT_ITEM (1024)
  166. #endif
  167. static stock
  168. YSI_g_sTextSets[Y_TEXT_MAX_SETS][e_TEXT_SETS],
  169. YSI_g_sTextEntries[MAX_TEXT_ENTRIES][e_TEXT_ENTRY],
  170. YSI_g_sTextStrings[MAX_TEXT_ENTRIES * _:YSI_MAX_LANGUAGES][MAX_INI_ENTRY_TEXT / 4],// char],
  171. YSI_g_sReturnText[MAX_SINGLE_TEXT_ITEM],
  172. YSI_g_sExtraText[MAX_SINGLE_TEXT_ITEM],
  173. YSI_g_sUnusedEntry = 0,
  174. YSI_g_sDistributionID = -1,
  175. YSI_g_sUnusedSlot = 0,
  176. YSI_g_sCurLoadTextFile[64],
  177. //YSI_g_sCallbacks,
  178. YSI_g_sRemaining = sizeof (YSI_g_sTextStrings) * sizeof (YSI_g_sTextStrings[]),
  179. Language:YSI_g_sLangIndex;
  180. // OnFilterScriptInit
  181. // =============================================================================
  182. // | ========================================================================= |
  183. // | | | |
  184. // | | HERE STARTS THE LOADING CODE | |
  185. // | | | |
  186. // | ========================================================================= |
  187. // =============================================================================
  188. /**--------------------------------------------------------------------------**\
  189. <summary>-</summary>
  190. <returns>
  191. -
  192. </returns>
  193. <remarks>
  194. This callback is hard coded in to YSI to be called absolutely last! Note
  195. that this WAS hard coded, but now uses a more generic chaining method not
  196. based on y_scriptinit and instead just uses the regular ALS method.
  197. </remarks>
  198. \**--------------------------------------------------------------------------**/
  199. public OnGameModeInit()
  200. {
  201. P:1("TextInt_OnGameModeInit called");
  202. #if defined TextInt_OnGameModeInit
  203. TextInt_OnGameModeInit();
  204. #endif
  205. if (!YSI_FILTERSCRIPT)
  206. {
  207. //Text_SpecialInit();
  208. Text_RefreshLoaded();
  209. _Styles_SpecialInit();
  210. }
  211. P:1("TextInt_OnGameModeInit ended");
  212. return 1;
  213. }
  214. #if defined _ALS_OnGameModeInit
  215. #undef OnGameModeInit
  216. #else
  217. #define _ALS_OnGameModeInit
  218. #endif
  219. #define OnGameModeInit TextInt_OnGameModeInit
  220. #if defined TextInt_OnGameModeInit
  221. forward TextInt_OnGameModeInit();
  222. #endif
  223. public OnFilterScriptInit()
  224. {
  225. P:1("TextInt_OnFilterScriptInit called");
  226. // DO ALL (MOST) OTHER INITS FIRST. ENSURE WE COME LATER.
  227. #if defined TextInt_OnFilterScriptInit
  228. TextInt_OnFilterScriptInit();
  229. #endif
  230. //Text_SpecialInit();
  231. Text_RefreshLoaded();
  232. _Styles_SpecialInit();
  233. P:1("TextInt_OnFilterScriptInit ended");
  234. return 1;
  235. }
  236. #if defined _ALS_OnFilterScriptInit
  237. #undef OnFilterScriptInit
  238. #else
  239. #define _ALS_OnFilterScriptInit
  240. #endif
  241. #define OnFilterScriptInit TextInt_OnFilterScriptInit
  242. #if defined TextInt_OnFilterScriptInit
  243. forward TextInt_OnFilterScriptInit();
  244. #endif
  245. //forward Text_SpecialInit();
  246. //
  247. //public Text_SpecialInit()
  248. //static stock Text_SpecialInit()
  249. //{
  250. // P:1("Text_SpecialInit called");
  251. // // Scan the AMX for all public functions of the type "XX@YY@NN@yX_". These
  252. // // are the declarations for included texts.
  253. // Text_RefreshLoaded();
  254. // _Styles_SpecialInit();
  255. // P:2("Text_SpecialInit ended");
  256. //}
  257. /**--------------------------------------------------------------------------**\
  258. <summary></summary>
  259. <returns>
  260. -
  261. </returns>
  262. <remarks>
  263. -
  264. </remarks>
  265. \**--------------------------------------------------------------------------**/
  266. //static stock Text_GetDistributionID()
  267. hook OnScriptInit()
  268. {
  269. P:1("Text_OnScriptInit called");
  270. // Initialise.
  271. new
  272. i;
  273. for (i = 0; i != Y_TEXT_MAX_SETS; ++i)
  274. {
  275. YSI_g_sTextSets[i][e_TEXT_SETS_NAME][0] = '\1';
  276. YSI_g_sTextSets[i][e_TEXT_SETS_INDEX] = -1;
  277. }
  278. for (i = 0; i != MAX_TEXT_ENTRIES; ++i)
  279. {
  280. YSI_g_sTextEntries[i][e_TEXT_ENTRY_HASH] = i + 1;
  281. }
  282. // Redirect all the pointers to the last cell.
  283. new
  284. offset = (sizeof (YSI_g_sTextStrings) - 1) * 4;
  285. i = (sizeof (YSI_g_sTextStrings[]) - 1) * 4;
  286. // Get the absolute address of the pointer to the last array.
  287. #emit CONST.pri YSI_g_sTextStrings
  288. #emit LOAD.S.alt offset
  289. #emit ADD
  290. // Get the data at that address (i.e. the RELATIVE pointer).
  291. #emit LOAD.I
  292. // Get the RELATIVE address of the last element.
  293. #emit LOAD.S.alt i
  294. #emit ADD
  295. #emit STOR.S.pri offset
  296. for (i = sizeof (YSI_g_sTextStrings) - 1; i != 0; --i)
  297. {
  298. //YSI_g_sTextStrings[i][0] = i + 1;
  299. #emit CONST.pri YSI_g_sTextStrings
  300. #emit LOAD.S.alt i
  301. #emit SHL.C.alt 2
  302. #emit ADD
  303. #emit MOVE.alt
  304. #emit LOAD.S.pri offset
  305. #emit STOR.I
  306. #emit ADD.C 4
  307. #emit STOR.S.pri offset
  308. }
  309. offset = getproperty(8, YSIM_TEXT_D);
  310. i = 0;
  311. while (i != 32)
  312. {
  313. if (!(offset & (1 << i)))
  314. {
  315. YSI_g_sDistributionID = i;
  316. offset |= 1 << i;
  317. break;
  318. }
  319. ++i;
  320. }
  321. if (i != 32)
  322. {
  323. setproperty(8, YSIM_TEXT_D, offset);
  324. }
  325. P:C(else P:E("y_text distribution ID not set"););
  326. CallRemoteFunction("Text_ResetLoaded", "");
  327. state y_text_ending : n;
  328. state y_text_get_text : n;
  329. state y_render_show : y_render_show_print;
  330. }
  331. /**--------------------------------------------------------------------------**\
  332. <summary>-</summary>
  333. <returns>
  334. -
  335. </returns>
  336. <remarks>
  337. -
  338. </remarks>
  339. \**--------------------------------------------------------------------------**/
  340. hook OnScriptExit()
  341. {
  342. P:1("Textint_OnScriptExit called");
  343. new
  344. idx = 0,
  345. buffer[32],
  346. pos;
  347. while ((idx = AMX_GetPublicNameSuffix(idx, buffer, _A<@yX_>)))
  348. {
  349. pos = chrfind('@', buffer);
  350. if (pos != -1)
  351. {
  352. buffer[pos] = ':';
  353. pos = chrfind('@', buffer, pos);
  354. if (pos != -1)
  355. {
  356. buffer[pos] = '\0';
  357. if (existproperty(7, buffer) && getproperty(7, buffer) == TEXT_MASTER)
  358. {
  359. deleteproperty(7, buffer);
  360. }
  361. }
  362. }
  363. }
  364. state y_text_ending:y;
  365. CallRemoteFunction("Text_RefreshLoaded", "");
  366. }
  367. /**--------------------------------------------------------------------------**\
  368. <summary>Text_ResetLoaded</summary>
  369. <returns>
  370. -
  371. </returns>
  372. <remarks>
  373. When a mode ends this is called so that other scripts can know to re-load
  374. any text which was previously owned by this script that they still need.
  375. </remarks>
  376. \**--------------------------------------------------------------------------**/
  377. forward Text_ResetLoaded();
  378. public Text_ResetLoaded() <>
  379. {
  380. }
  381. public Text_ResetLoaded() <y_text_ending:n>
  382. {
  383. // Called to reset the owners of texts after a gamemode restart.
  384. for (new i = 0; i != Y_TEXT_MAX_SETS; ++i)
  385. {
  386. if (YSI_g_sTextSets[i][e_TEXT_SETS_NAME][0] != '\1')
  387. {
  388. setproperty(7, YSI_g_sTextSets[i][e_TEXT_SETS_NAME], TEXT_MASTER);
  389. }
  390. }
  391. }
  392. /**--------------------------------------------------------------------------**\
  393. <summary>Text_RefreshLoaded</summary>
  394. <returns>
  395. -
  396. </returns>
  397. <remarks>
  398. Loops through all text definition functions in the mode (defined as:
  399. "file@section@unique@yX_" (note that "@unique" is optional but irrelevant).
  400. If any are found and the property "file:section" isn't defined claims
  401. ownership of that section so that the text can be loaded in to this mode.
  402. </remarks>
  403. \**--------------------------------------------------------------------------**/
  404. forward Text_RefreshLoaded();
  405. public Text_RefreshLoaded() <y_text_ending:y>
  406. {
  407. //printf("Text_RefreshLoaded: y");
  408. // Do nothing, only called for other scripts to check that all their text
  409. // items are still loaded.
  410. }
  411. public Text_RefreshLoaded() <y_text_ending:n>
  412. {
  413. //printf("Text_RefreshLoaded: n");
  414. if (Langs_GetLanguageCount() == Language:0)
  415. {
  416. P:E("No languages found - Did you add \"Langs_AddLanguage\" to the script init (NOT \"main\")?");
  417. }
  418. new
  419. idx = 0,
  420. buffer[32],
  421. pos;
  422. while ((idx = AMX_GetPublicNameSuffix(idx, buffer, _A<@yX_>)))
  423. {
  424. strunpack(buffer, buffer);
  425. pos = chrfind('@', buffer);
  426. //printf("%d, %x", pos, buffer[0]);
  427. if (pos != -1)
  428. {
  429. // Get rid of the end parts, doesn't matter if "Y_TEXT_UNIQUE" is
  430. // defined or not as EVERYTHING later is dropped.
  431. buffer[pos] = ':';
  432. pos = chrfind('@', buffer, pos);
  433. if (pos != -1)
  434. {
  435. buffer[pos] = '\0';
  436. //printf("buffer: %s %d", buffer, existproperty(7, buffer));
  437. //buffer[pos + 1] = '\0';
  438. if (!existproperty(7, buffer))
  439. {
  440. setproperty(7, buffer, TEXT_MASTER);
  441. Text_AddLocal(buffer, bernstein(buffer));
  442. }
  443. }
  444. }
  445. }
  446. Text_LoadLocals();
  447. }
  448. /**--------------------------------------------------------------------------**\
  449. <summary>-</summary>
  450. <returns>
  451. -
  452. </returns>
  453. <remarks>
  454. -
  455. </remarks>
  456. \**--------------------------------------------------------------------------**/
  457. static stock Text_AddLocal(buffer[], hash)
  458. {
  459. P:4("Text_AddLocal called: \"%s\", %i", buffer, hash);
  460. for (new i = 0; i != Y_TEXT_MAX_SETS; ++i)
  461. {
  462. if (YSI_g_sTextSets[i][e_TEXT_SETS_NAME][0] == '\1')
  463. {
  464. YSI_g_sTextSets[i][e_TEXT_SETS_HASH] = hash;
  465. strcpy(YSI_g_sTextSets[i][e_TEXT_SETS_NAME], buffer, 28);
  466. return;
  467. }
  468. }
  469. }
  470. /**--------------------------------------------------------------------------**\
  471. <summary>-</summary>
  472. <returns>
  473. -
  474. </returns>
  475. <remarks>
  476. -
  477. </remarks>
  478. \**--------------------------------------------------------------------------**/
  479. forward Text_INILoad(offset, tag[], name[], value[]);
  480. public Text_INILoad(offset, tag[], name[], value[])
  481. {
  482. // Get the path.
  483. // Get the file.
  484. // Get the extension.
  485. P:5("Text_INILoad called: %d, %s, %s, %s", offset, tag, name, value);
  486. P:5("Text_INILoad: IsPacked? %08x%08x", value[0], value[1]);
  487. new
  488. fname[sizeof (YSI_g_sCurLoadTextFile) - (3 + 9)],
  489. len = strlen(YSI_g_sCurLoadTextFile);
  490. //format(fname, sizeof (fname
  491. strcpy(fname, YSI_g_sCurLoadTextFile[9], len - (3 + 9 - 1));
  492. for (new i = 0; i != Y_TEXT_MAX_SETS; ++i)
  493. {
  494. //printf("fname: %s, %d, %d, %s", fname, len, offset, YSI_g_sTextSets[i][e_TEXT_SETS_NAME]);
  495. if (!strcmp(YSI_g_sTextSets[i][e_TEXT_SETS_NAME], fname, true, offset - 1) && !strcmp(YSI_g_sTextSets[i][e_TEXT_SETS_NAME][offset], tag, true))
  496. {
  497. //printf("%d \"%s\" \"%s\" \"%s\"", len, fname, YSI_g_sCurLoadTextFile[len - 2], tag);
  498. len = strlen(name);
  499. new
  500. slot = name[--len],
  501. number,
  502. hash = 1;
  503. P:6("Text_INILoad: Get Number");
  504. while ('0' <= slot <= '9')
  505. {
  506. name[len] = '\0';
  507. number += (slot - '0') * hash;
  508. hash *= 10;
  509. slot = name[--len];
  510. }
  511. // So "MY_TEXT_1" becomes "MY_TEXT", not "MY_TEXT_".
  512. if (slot == '_')
  513. {
  514. name[len] = '\0';
  515. }
  516. hash = bernstein(name);
  517. slot = Text_FindEntry(YSI_g_sTextSets[i][e_TEXT_SETS_INDEX], hash);
  518. P:6("Text_INILoad: Check slot %d", slot);
  519. if (slot == -1)
  520. {
  521. Text_AddEntry(i, name, value, hash);
  522. //P:5("%d,%d,%d,%d,%d", YSI_g_sTextStrings[ss][0], YSI_g_sTextStrings[ss][1], YSI_g_sTextStrings[ss][2], YSI_g_sTextStrings[ss][3], YSI_g_sTextStrings[ss][4]);
  523. }
  524. else
  525. {
  526. P:6("Text_INILoad: Check Collision");
  527. if (strcmp(name, YSI_g_sTextEntries[slot][e_TEXT_ENTRY_NAME], true))
  528. {
  529. P:E("Text collision on \"%s\" and \"%s\"!", name, YSI_g_sTextSets[i][e_TEXT_SETS_NAME]);
  530. return;
  531. }
  532. else if (YSI_g_sTextEntries[slot][e_TEXT_ENTRY_POINTERS][YSI_g_sLangIndex] == -1)
  533. {
  534. new
  535. ss = Text_GetFreeSlot();
  536. if (ss == -1)
  537. {
  538. P:E("Text buffer full!");
  539. return;
  540. }
  541. //strpack(YSI_g_sTextStrings[ss], value, MAX_INI_ENTRY_TEXT * 4);
  542. Text_UpdateFreeSlot(Format_Standardise(value, YSI_g_sTextStrings[ss], MAX_INI_ENTRY_TEXT));
  543. //P:5("%d,%d,%d,%d,%d", YSI_g_sTextStrings[ss][0], YSI_g_sTextStrings[ss][1], YSI_g_sTextStrings[ss][2], YSI_g_sTextStrings[ss][3], YSI_g_sTextStrings[ss][4]);
  544. //strcpy(YSI_g_sTextStrings[ss], value, MAX_INI_ENTRY_TEXT * 4);
  545. YSI_g_sTextEntries[slot][e_TEXT_ENTRY_POINTERS][YSI_g_sLangIndex] = ss;
  546. }
  547. else if (number)
  548. {
  549. // Found a string with multiple entries in the INI file to
  550. // be linked together dynamically.
  551. new
  552. ss = Text_GetFreeSlot();
  553. if (ss == -1)
  554. {
  555. P:E("Text buffer full!");
  556. return;
  557. }
  558. Text_UpdateFreeSlot(Format_Standardise(value, YSI_g_sTextStrings[ss], MAX_INI_ENTRY_TEXT));
  559. hash = YSI_g_sTextEntries[slot][e_TEXT_ENTRY_POINTERS][YSI_g_sLangIndex];
  560. if (hash == -1)
  561. {
  562. // Will happen when the text entry exists in other
  563. // languages but not yet in this one.
  564. YSI_g_sTextEntries[slot][e_TEXT_ENTRY_POINTERS][YSI_g_sLangIndex] = ss;
  565. }
  566. else if (number == 1)
  567. {
  568. YSI_g_sTextEntries[slot][e_TEXT_ENTRY_POINTERS][YSI_g_sLangIndex] = ss;
  569. len = strlen(YSI_g_sTextStrings[ss]);
  570. //if (len < sizeof (YSI_g_sTextStrings[]) - 2)
  571. //{
  572. // Add the linked list.
  573. Text_DoLinkedText(YSI_g_sTextStrings[ss], hash, len);
  574. //}
  575. //else
  576. //{
  577. // P:W("Text size error on \"%s\"!", name);
  578. //}
  579. }
  580. else
  581. {
  582. // Add the string to the chain.
  583. slot = 2;
  584. len = strlen(YSI_g_sTextStrings[hash]);
  585. // Loop through existing strings in this list till we
  586. // find the right position (either the specified ID or
  587. // the last item) at which to add the new string.
  588. while (slot < number)
  589. {
  590. if (len < 2)
  591. {
  592. break;
  593. }
  594. //if (YSI_g_sTextStrings[hash][len - 2] != '\05')
  595. //{
  596. // break;
  597. //}
  598. //hash = YSI_g_sTextStrings[hash][len - 1];
  599. if (!Text_GetLinkedText(YSI_g_sTextStrings[hash], hash, len))
  600. {
  601. break;
  602. }
  603. len = strlen(YSI_g_sTextStrings[hash]);
  604. ++slot;
  605. }
  606. if (len < 2)
  607. {
  608. Text_DoLinkedText(YSI_g_sTextStrings[hash], ss, len);
  609. }
  610. //else if (YSI_g_sTextStrings[hash][len - 2] == '\05')
  611. else if (Text_HasLinkedText(YSI_g_sTextStrings[hash], len))
  612. {
  613. slot = Text_UpdateLinkedText(YSI_g_sTextStrings[hash], ss, len);
  614. //slot = YSI_g_sTextStrings[hash][len - 1];
  615. //YSI_g_sTextStrings[hash][len - 1] = ss;
  616. len = strlen(YSI_g_sTextStrings[ss]);
  617. //if (len < sizeof (YSI_g_sTextStrings[]) - 2)
  618. //{
  619. // // Add the linked list.
  620. // YSI_g_sTextStrings[ss][len] = '\05';
  621. // YSI_g_sTextStrings[ss][len + 1] = slot;
  622. // YSI_g_sTextStrings[ss][len + 2] = '\0';
  623. Text_DoLinkedText(YSI_g_sTextStrings[ss], slot, len);
  624. //}
  625. //else
  626. //{
  627. // P:W("Text size error on \"%s\"!", name);
  628. //}
  629. }
  630. else
  631. {
  632. //if (len < sizeof (YSI_g_sTextStrings[]) - 2)
  633. //{
  634. // // Add the linked list.
  635. // YSI_g_sTextStrings[hash][len] = '\05';
  636. // YSI_g_sTextStrings[hash][len + 1] = ss;
  637. // YSI_g_sTextStrings[hash][len + 2] = '\0';
  638. Text_DoLinkedText(YSI_g_sTextStrings[hash], ss, len);
  639. //}
  640. //else
  641. //{
  642. // P:W("Text size error on \"%s\"!", name);
  643. //}
  644. }
  645. }
  646. }
  647. else
  648. {
  649. P:W("Text repeat on \"%s\"!", name);
  650. }
  651. }
  652. // Add the current value to the current tag.
  653. break;
  654. }
  655. }
  656. }
  657. /**--------------------------------------------------------------------------**\
  658. <summary>-</summary>
  659. <returns>
  660. -
  661. </returns>
  662. <remarks>
  663. -
  664. </remarks>
  665. \**--------------------------------------------------------------------------**/
  666. static stock Text_LoadLocals()
  667. {
  668. //printf("Text_LoadLocals called");
  669. P:4("Text_LoadLocals called");
  670. // This is the interesting part. Load all the sets which have a name not
  671. // '\1' and an index of -1.
  672. for (new i = 0; i != Y_TEXT_MAX_SETS; ++i)
  673. {
  674. P:6("Text_LoadLocals: i = %d, text = %s, %d, %d", i, YSI_g_sTextSets[i][e_TEXT_SETS_NAME], YSI_g_sTextSets[i][e_TEXT_SETS_INDEX], YSI_g_sTextSets[i][e_TEXT_SETS_HASH]);
  675. if (YSI_g_sTextSets[i][e_TEXT_SETS_INDEX] == -1 && YSI_g_sTextSets[i][e_TEXT_SETS_HASH])
  676. {
  677. new
  678. offset = chrfind(':', YSI_g_sTextSets[i][e_TEXT_SETS_NAME]) + 1,
  679. j = i + 1;
  680. while (j != Y_TEXT_MAX_SETS)
  681. {
  682. if (YSI_g_sTextSets[j][e_TEXT_SETS_INDEX] == -1 && YSI_g_sTextSets[j][e_TEXT_SETS_HASH] && !strcmp(YSI_g_sTextSets[i][e_TEXT_SETS_NAME], YSI_g_sTextSets[j][e_TEXT_SETS_NAME], false, offset))
  683. {
  684. break;
  685. }
  686. ++j;
  687. }
  688. // Only load a file one.
  689. if (j != Y_TEXT_MAX_SETS)
  690. {
  691. continue;
  692. }
  693. --offset;
  694. //YSI_g_sTextSets[i][e_TEXT_SETS_NAME][offset] = '\0';
  695. YSI_g_sLangIndex = Language:0;
  696. new
  697. langs[YSI_MAX_STRING],
  698. pos;
  699. langs = Langs_GetLanguageCodes();
  700. while ((pos = chrfind('|', langs, pos)) != -1)
  701. {
  702. format(YSI_g_sCurLoadTextFile, sizeof (YSI_g_sCurLoadTextFile), "YSI/text/%.*s.%.2s", offset, YSI_g_sTextSets[i][e_TEXT_SETS_NAME], langs[pos - 2]);
  703. INI_ParseFile(YSI_g_sCurLoadTextFile, "Text_INILoad", _, true, offset + 1, _, true);
  704. ++pos;
  705. ++YSI_g_sLangIndex;
  706. // We can add code here to load the data from y_styles.
  707. }
  708. //format(YSI_g_sCurLoadTextFile, sizeof (YSI_g_sCurLoadTextFile), "%.*s", offset, YSI_g_sTextSets[i][e_TEXT_SETS_NAME]);
  709. P:6("Text_LoadLocals: Loading style %s (%d)", YSI_g_sCurLoadTextFile, offset);
  710. //_Styles_ParseOne(YSI_g_sCurLoadTextFile);
  711. //YSI_g_sTextSets[i][e_TEXT_SETS_NAME][offset] = ':';
  712. }
  713. }
  714. }
  715. /**--------------------------------------------------------------------------**\
  716. <summary>-</summary>
  717. <returns>
  718. -
  719. </returns>
  720. <remarks>
  721. -
  722. </remarks>
  723. \**--------------------------------------------------------------------------**/
  724. /**--------------------------------------------------------------------------**\
  725. <summary>-</summary>
  726. <returns>
  727. -
  728. </returns>
  729. <remarks>
  730. -
  731. </remarks>
  732. \**--------------------------------------------------------------------------**/
  733. forward Text_CheckLoad(buffer[], hash);
  734. public Text_CheckLoad(buffer[], hash) <y_text_ending:y>
  735. {
  736. for (new i = 0; i != Y_TEXT_MAX_SETS; ++i)
  737. {
  738. YSI_g_sTextSets[i][e_TEXT_SETS_HASH] = 0;
  739. YSI_g_sTextSets[i][e_TEXT_SETS_NAME][0] = '\1';
  740. YSI_g_sTextSets[i][e_TEXT_SETS_NAME][1] = '\0';
  741. }
  742. }
  743. public Text_CheckLoad(buffer[], hash) <y_text_ending:n>
  744. {
  745. // Check if another script is already in charge of this set.
  746. if (getproperty(8, "T_CL"))
  747. {
  748. return;
  749. }
  750. // Nope, are we?
  751. for (new i = 0; i != Y_TEXT_MAX_SETS; ++i)
  752. {
  753. if (hash == YSI_g_sTextSets[i][e_TEXT_SETS_HASH] && !strcmp(buffer, YSI_g_sTextSets[i][e_TEXT_SETS_NAME]))
  754. {
  755. setproperty(8, "T_CL", 1);
  756. return;
  757. }
  758. }
  759. }
  760. /**--------------------------------------------------------------------------**\
  761. <summary>Text_ReturnTheText</summary>
  762. <param name="master">The script which owns this string.</param>
  763. <param name="index">The slot in which this string is stored.</param>
  764. <param name="str[]">The string to display.</param>
  765. <param name="len0">The length of the string array.</param>
  766. <param name="style[E_STYLE_DATA]">The style of the string.</param>
  767. <param name="len1">The length of the style array.</param>
  768. <param name="label[E_3D_DATA]">The 3D label style of the string.</param>
  769. <param name="len2">The length of the 3D array.</param>
  770. <returns>
  771. -
  772. </returns>
  773. <remarks>
  774. This function is used to pass data from the owner script to the script
  775. which is doing the display. It passes the string to format (as an array,
  776. not as a string, to keep the non-standard characters). A copy of the style
  777. data, any 3D text label style data, the index and the master ID. Note that
  778. TD data isn't handled here - if there is need to use a text draw the script
  779. will have to call to the remote script for display functions. TD data is
  780. loaded in all scripts where it is relevant. This does mean that if people
  781. modify a style we need to modify it in ALL scripts.
  782. TODO: Modify the y_text system to store copies of required strings in all
  783. modes, just because it's slightly better.
  784. </remarks>
  785. \**--------------------------------------------------------------------------**/
  786. forward Text_ReturnTheText(master, index, str[], len0, style[E_STYLE_DATA], len1, label[E_3D_DATA], len2);
  787. public Text_ReturnTheText(master, index, str[], len0, style[E_STYLE_DATA], len1, label[E_3D_DATA], len2) <y_text_get_text:n>
  788. {
  789. }
  790. public Text_ReturnTheText(master, index, str[], len0, style[E_STYLE_DATA], len1, label[E_3D_DATA], len2) <y_text_get_text:y>
  791. {
  792. P:4("Text_ReturnTheText called: %d,%d,%d,%d,%d len = %d (%s)", str[0], str[1], str[2], str[3], str[4], len0, str);
  793. strcpy(YSI_g_sReturnText, str, len0);
  794. setproperty(8, YSIM_TXTLEN, _Format_SetStyleData(master, index, style, label));
  795. }
  796. /**--------------------------------------------------------------------------**\
  797. <summary>_Text_CheckOwnership</summary>
  798. <param name="file[]">File to check.</param>
  799. <param name="str[]">Section name to check.</param>
  800. <returns>
  801. Does this script own the named section in the current file?
  802. </returns>
  803. <remarks>
  804. Sets "YSI_g_sReturnText" for use in "_Text_LookupName" too.
  805. </remarks>
  806. \**--------------------------------------------------------------------------**/
  807. stock _Text_CheckOwnership(file[], str[])
  808. {
  809. P:4("_Text_CheckOwnership called: %s, %s", file, str);
  810. format(YSI_g_sReturnText, sizeof (YSI_g_sReturnText), "%s:%s", file, str);
  811. return existproperty(7, YSI_g_sReturnText) && (getproperty(7, YSI_g_sReturnText) == TEXT_MASTER);
  812. }
  813. /**--------------------------------------------------------------------------**\
  814. <summary>_Text_LookupName</summary>
  815. <param name="name[]">Name of the string to look up.</param>
  816. <returns>
  817. Slot storing the pointers for the named section.
  818. </returns>
  819. <remarks>
  820. Assumes this script owns the section based on previously having called
  821. "_Text_CheckOwnership". This is assumed as both functions are called from
  822. only y_styles (hence the private naming convention). Note that the string
  823. "YSI_g_sReturnText" is set in "_Text_CheckOwnership" because we make
  824. guarantees about the order in which these functions are called.
  825. </remarks>
  826. \**--------------------------------------------------------------------------**/
  827. stock _Text_LookupName(name[])
  828. {
  829. P:4("_Text_LookupName called: %s, %s", name, YSI_g_sReturnText);
  830. //format(YSI_g_sReturnText, sizeof (YSI_g_sReturnText), "%s:%s", YSI_g_sCurLoadTextFile, str);
  831. new
  832. sh = bernstein(YSI_g_sReturnText);
  833. for (new i = 0; i != Y_TEXT_MAX_SETS; ++i)
  834. {
  835. if (sh == YSI_g_sTextSets[i][e_TEXT_SETS_HASH] && !strcmp(YSI_g_sReturnText, YSI_g_sTextSets[i][e_TEXT_SETS_NAME]))
  836. {
  837. // Got the start slot.
  838. return Text_FindEntry(YSI_g_sTextSets[i][e_TEXT_SETS_INDEX], bernstein(name));
  839. }
  840. }
  841. return -1;
  842. }
  843. /**--------------------------------------------------------------------------**\
  844. <summary>_Text_ReturnSingle</summary>
  845. <param name="str[]">String to be returned.</param>
  846. <param name="len0">The length of the string.</param>
  847. <returns>
  848. -
  849. </returns>
  850. <remarks>
  851. This function, along with _Text_RemoteSingle, is used to get a single string
  852. from a remote script when the exact ID is known in advance and no other data
  853. like stlyes are required.
  854. </remarks>
  855. \**--------------------------------------------------------------------------**/
  856. forward _Text_ReturnSingle(str[], len0);
  857. public _Text_ReturnSingle(str[], len0) <y_text_get_text : n>
  858. {
  859. }
  860. public _Text_ReturnSingle(str[], len0) <y_text_get_text : y>
  861. {
  862. #pragma unused len0
  863. strcpy(YSI_g_sExtraText, str);
  864. }
  865. forward _Text_RemoteSingle(master, id);
  866. public _Text_RemoteSingle(master, id)
  867. {
  868. if (master == TEXT_MASTER)
  869. {
  870. CallRemoteFunction("_Text_ReturnSingle", "ai", YSI_g_sTextStrings[id], MAX_SINGLE_TEXT_ITEM); //sizeof (YSI_g_sTextStrings[]));
  871. }
  872. }
  873. stock _Text_GetPointer(master, id)
  874. {
  875. if (master == TEXT_MASTER)
  876. {
  877. //new
  878. // ret = id * sizeof (YSI_g_sTextStrings[]);
  879. //printf("%d", ret);
  880. #emit CONST.alt YSI_g_sTextStrings
  881. #emit LOAD.S.pri id
  882. #emit IDXADDR
  883. #emit MOVE.alt
  884. #emit LOAD.i
  885. #emit ADD
  886. #emit RETN
  887. }
  888. state y_text_get_text : y;
  889. CallRemoteFunction("_Text_RemoteSingle", "ii", master, id);
  890. state y_text_get_text : n;
  891. #emit CONST.pri YSI_g_sExtraText
  892. #emit RETN
  893. //#emit STOR.S.pri ret
  894. //printf("%d", ret);
  895. // Never actually called, but shuts up the compiler
  896. return id;
  897. }
  898. /**--------------------------------------------------------------------------**\
  899. <summary>Text_GetStandard</summary>
  900. <param name="search[]">Search blocks to look in.</param>
  901. <param name="nh">Hash of the string name to find.</param>
  902. <param name="Language:l">Language in which to get the text.</param>
  903. <returns>
  904. -
  905. </returns>
  906. <remarks>
  907. Gets a string in a language from a hash and a text set.
  908. </remarks>
  909. \**--------------------------------------------------------------------------**/
  910. forward Text_GetStandard(search[], nh, Language:l);
  911. public Text_GetStandard(search[], nh, Language:l)
  912. {
  913. if (getproperty(8, YSIM_TXTFND) != -1)
  914. {
  915. return;
  916. }
  917. if (getproperty(7, search) != TEXT_MASTER)
  918. {
  919. return;
  920. }
  921. P:4("Text_GetStandard called");
  922. new
  923. sh = bernstein(search);//,
  924. //fail[MAX_INI_ENTRY_TEXT] = "String not found";
  925. for (new i = 0; i != Y_TEXT_MAX_SETS; ++i)
  926. {
  927. P:7("Text_GetStandard: %d, %d, %d", i, sh, YSI_g_sTextSets[i][e_TEXT_SETS_HASH]);
  928. if (sh == YSI_g_sTextSets[i][e_TEXT_SETS_HASH] && !strcmp(search, YSI_g_sTextSets[i][e_TEXT_SETS_NAME]))
  929. {
  930. // Got the start slot.
  931. new
  932. slot = Text_FindEntry(YSI_g_sTextSets[i][e_TEXT_SETS_INDEX], nh);
  933. P:7("Text_GetStandard: found %d, %d, %d", YSI_g_sTextSets[i][e_TEXT_SETS_INDEX], nh, slot);
  934. if (slot != -1)
  935. {
  936. new
  937. pointer = YSI_g_sTextEntries[slot][e_TEXT_ENTRY_POINTERS][l];
  938. P:5("Text_GetStandard: %d, %d, %d, %d", slot, pointer, getproperty(8, YSIM_TXTIND), _@);
  939. if (pointer != -1)
  940. {
  941. //P:5("Text_GetStandard: %08x%08x%08x%08x%08x", YSI_g_sTextStrings[pointer][0], YSI_g_sTextStrings[pointer][1], YSI_g_sTextStrings[pointer][2], YSI_g_sTextStrings[pointer][3], YSI_g_sTextStrings[pointer][4]);
  942. //setproperty(9, "", YSIM_STRING, YSI_g_sTextStrings[pointer]);
  943. setproperty(8, YSIM_TXTFND, _@);
  944. // I reckon this is the only time these functions have ever
  945. // been used together directly...
  946. P:5("Text_GetStandard: %s", YSI_g_sTextStrings[pointer]);
  947. //SetPVarString(getproperty(8, YSIM_TXTIND), "YSI_g_sString", YSI_g_sTextStrings[pointer]);
  948. //printf("%d %d %d %d %d = %d", YSI_g_sTextStrings[pointer][0], YSI_g_sTextStrings[pointer][1], YSI_g_sTextStrings[pointer][2], YSI_g_sTextStrings[pointer][3], YSI_g_sTextStrings[pointer][4], strlen(YSI_g_sTextStrings[pointer]));
  949. // TODO: Fix this for the new parameter list.
  950. new
  951. style[E_STYLE_DATA],
  952. label[E_3D_DATA];
  953. Styles_GetData(slot, style, label);
  954. CallRemoteFunction("Text_ReturnTheText", "iiaiaiai", TEXT_MASTER, pointer, YSI_g_sTextStrings[pointer], MAX_SINGLE_TEXT_ITEM /*sizeof (YSI_g_sTextStrings[])*/, style, _:E_STYLE_DATA, label, _:E_3D_DATA);
  955. //format(fail, sizeof (fail), "%s", YSI_g_sTextStrings[pointer]);
  956. //printf("fail: %s", fail);
  957. //break;
  958. return;
  959. }
  960. }
  961. break;
  962. }
  963. }
  964. //static const
  965. // fail[MAX_INI_ENTRY_TEXT] = "\1";
  966. //setproperty(9, "", YSIM_STRING, "\1");
  967. //return fail;
  968. }
  969. /**--------------------------------------------------------------------------**\
  970. <summary>Text_GetText</summary>
  971. <param name="search[]">A "|" separated list of files and sections to search in.</param>
  972. <param name="name[]">The text entry to look for.</param>
  973. <param name="Language:l">The language to get.</param>
  974. <returns>
  975. The specified string in the specified language.
  976. </returns>
  977. <remarks>
  978. Uses "YSI_g_sReturnText" instead of a normal return because this may call
  979. remote scripts which will need to return a standardised string as an array
  980. to preserve all the non-standard characters (passing data as a string using
  981. __CallRemoteFunction packs the string, which we don't want).
  982. </remarks>
  983. \**--------------------------------------------------------------------------**/
  984. // Get the loaded standardised version of this string.
  985. //forward Text_GetStandard(start[] name[], Language:l);
  986. static stock Text_GetText(search[], name[], Language:l)
  987. {
  988. /*new
  989. start = Text_GetProvider(search),
  990. slot = Text_FindEntry(*/
  991. // TODO: Parse multiple search strings.
  992. //search[strlen(search) - 1] = '\0';
  993. //new loops = 0;
  994. //static
  995. // ret[MAX_INI_ENTRY_TEXT];
  996. new
  997. pos,
  998. lst;
  999. state y_text_get_text:y;
  1000. setproperty(8, YSIM_TXTFND, -1);
  1001. //setproperty(8, YSIM_TXTIND, index);
  1002. while (search[lst])
  1003. {
  1004. pos = strfind(search[lst], "|");
  1005. P:7("Text_GetText: loop1 %s %d %d %s %d", search, lst, pos, search[lst], search[lst + pos + 1]);
  1006. search[lst + pos] = '\0';
  1007. if (existproperty(7, search[lst]))
  1008. {
  1009. // Only call other scripts if ANYONE owns this search.
  1010. CallRemoteFunction("Text_GetStandard", "sii", search[lst], bernstein(name), _:l);
  1011. //P:7("Text_GetText: loop2 %s %d %d %s %d %d", search, lst, pos, search[lst], search[pos + 1], ret[0]);
  1012. search[lst + pos] = '|';
  1013. //if (ret[0] != '\1')
  1014. if (getproperty(8, YSIM_TXTFND) != -1)
  1015. {
  1016. //getproperty(9, "", YSIM_STRING, ret);
  1017. //strunpack(ret, ret)
  1018. //GetPVarString(index, "YSI_g_sString", ret, MAX_INI_ENTRY_TEXT);
  1019. state y_text_get_text:n;
  1020. return;// ret;
  1021. }
  1022. }
  1023. lst += pos + 1;
  1024. //if (++loops == 10) break;
  1025. //break;
  1026. }
  1027. //if (ret[0] == '\1')
  1028. {
  1029. // Need better error reporting here.
  1030. YSI_g_sReturnText = "Text Not Found";
  1031. }
  1032. state y_text_get_text:n;
  1033. return;// ret;
  1034. }
  1035. /**--------------------------------------------------------------------------**\
  1036. <summary>-</summary>
  1037. <returns>
  1038. -
  1039. </returns>
  1040. <remarks>
  1041. -
  1042. </remarks>
  1043. \**--------------------------------------------------------------------------**/
  1044. // To be public.
  1045. //stock Text_GetProvider(search[])
  1046. //{
  1047. //}
  1048. static stock Text_FindEntry(start, hash)
  1049. {
  1050. P:4("Text_FindEntry called: %i, %i", start, hash);
  1051. while (start != -1)
  1052. {
  1053. new
  1054. cmp = YSI_g_sTextEntries[start][e_TEXT_ENTRY_HASH] - hash;
  1055. if (cmp < 0)
  1056. {
  1057. start = YSI_g_sTextEntries[start][e_TEXT_ENTRY_RIGHT];
  1058. }
  1059. else if (cmp > 0)
  1060. {
  1061. start = YSI_g_sTextEntries[start][e_TEXT_ENTRY_LEFT];
  1062. }
  1063. else
  1064. {
  1065. return start;
  1066. }
  1067. }
  1068. return -1;
  1069. }
  1070. /**--------------------------------------------------------------------------**\
  1071. <summary>-</summary>
  1072. <returns>
  1073. -
  1074. </returns>
  1075. <remarks>
  1076. -
  1077. </remarks>
  1078. \**--------------------------------------------------------------------------**/
  1079. static stock Text_AddEntry(set, name[], value[], hash)
  1080. {
  1081. P:4("Text_AddEntry called: %i, \"%s\", \"%s\", %i", set, name, value, hash);
  1082. new
  1083. entry = Text_GetFreeEntry(),
  1084. slot = Text_GetFreeSlot();
  1085. if (entry == -1 || slot == -1)
  1086. {
  1087. P:E("Text buffer full!");
  1088. return;
  1089. }
  1090. // Save the string.
  1091. //strpack(YSI_g_sTextStrings[slot], value, MAX_INI_ENTRY_TEXT * 4);
  1092. Text_UpdateFreeSlot(Format_Standardise(value, YSI_g_sTextStrings[slot], YSI_g_sRemaining));
  1093. //strpack(YSI_g_sTextStrings[slot], value, MAX_INI_ENTRY_TEXT * 4);
  1094. //strcpy(YSI_g_sTextStrings[slot], value, MAX_INI_ENTRY_TEXT * 4);
  1095. // Save the identifier.
  1096. P:5("Text_AddEntry: slot = %d %d,%d,%d,%d,%d", slot, YSI_g_sTextStrings[slot][0], YSI_g_sTextStrings[slot][1], YSI_g_sTextStrings[slot][2], YSI_g_sTextStrings[slot][3], YSI_g_sTextStrings[slot][4]);
  1097. strpack(YSI_g_sTextEntries[entry][e_TEXT_ENTRY_NAME], name, MAX_INI_ENTRY_NAME * 4);
  1098. //strcpy(YSI_g_sTextEntries[entry][e_TEXT_ENTRY_NAME], name, MAX_INI_ENTRY_NAME * 4);
  1099. YSI_g_sTextEntries[entry][e_TEXT_ENTRY_HASH] = hash;
  1100. YSI_g_sTextEntries[entry][e_TEXT_ENTRY_POINTERS][YSI_g_sLangIndex] = slot;
  1101. // Set the default style.
  1102. _Style_Init(entry);
  1103. // Insert the identifier.
  1104. new
  1105. idx = YSI_g_sTextSets[set][e_TEXT_SETS_INDEX],
  1106. next;
  1107. if (idx == -1)
  1108. {
  1109. YSI_g_sTextSets[set][e_TEXT_SETS_INDEX] = entry;
  1110. }
  1111. else
  1112. {
  1113. for ( ; ; )
  1114. {
  1115. new
  1116. cmp = YSI_g_sTextEntries[idx][e_TEXT_ENTRY_HASH] - hash;
  1117. if (cmp < 0)
  1118. {
  1119. next = YSI_g_sTextEntries[idx][e_TEXT_ENTRY_RIGHT];
  1120. if (next == -1)
  1121. {
  1122. YSI_g_sTextEntries[idx][e_TEXT_ENTRY_RIGHT] = entry;
  1123. return;
  1124. }
  1125. }
  1126. else if (cmp > 0)
  1127. {
  1128. next = YSI_g_sTextEntries[idx][e_TEXT_ENTRY_LEFT];
  1129. if (next == -1)
  1130. {
  1131. YSI_g_sTextEntries[idx][e_TEXT_ENTRY_LEFT] = entry;
  1132. return;
  1133. }
  1134. }
  1135. idx = next;
  1136. }
  1137. }
  1138. }
  1139. /**--------------------------------------------------------------------------**\
  1140. <summary>-</summary>
  1141. <returns>
  1142. -
  1143. </returns>
  1144. <remarks>
  1145. -
  1146. </remarks>
  1147. \**--------------------------------------------------------------------------**/
  1148. static stock Text_GetFreeSlot()
  1149. {
  1150. if (YSI_g_sUnusedSlot == MAX_TEXT_ENTRIES * _:YSI_MAX_LANGUAGES)
  1151. {
  1152. return -1;
  1153. }
  1154. return YSI_g_sUnusedSlot++;
  1155. /*P:4("Text_GetFreeSlot called");
  1156. if (YSI_g_sUnusedSlot == MAX_TEXT_ENTRIES * _:YSI_MAX_LANGUAGES)
  1157. {
  1158. return -1;
  1159. }
  1160. new
  1161. ret = YSI_g_sUnusedSlot;
  1162. YSI_g_sUnusedSlot = YSI_g_sTextStrings[ret][0];
  1163. YSI_g_sTextStrings[ret][0] = '\0';
  1164. return ret;*/
  1165. }
  1166. /**--------------------------------------------------------------------------**\
  1167. <summary>Text_UpdateFreeSlot</summary>
  1168. Params:length
  1169. Return:
  1170. -
  1171. </returns>
  1172. <remarks>
  1173. Adjusts the first index table in "YSI_g_sTextStrings" such that the next
  1174. call to "Text_GetFreeSlot" will point to a non-zero length target string.
  1175. </remarks>
  1176. \**--------------------------------------------------------------------------**/
  1177. static stock Text_UpdateFreeSlot(len)
  1178. {
  1179. YSI_g_sRemaining -= len + 3;
  1180. // Get the address of the previous slot's pointer.
  1181. #emit LOAD.pri YSI_g_sUnusedSlot
  1182. #emit ADD.C 0xFFFFFFFF
  1183. #emit SHL.C.pri 2
  1184. #emit CONST.alt YSI_g_sTextStrings
  1185. #emit ADD
  1186. // Get the pointer to the start of the data.
  1187. #emit LOAD.I
  1188. // Get the pointer to the end of the data.
  1189. #emit LOAD.S.alt len
  1190. #emit SHL.C.alt 2
  1191. #emit ADD
  1192. // Add an offset for "\05" (NULL is implicit in the code because we get an
  1193. // extra four bytes of offset from shifting the index up a slot).
  1194. #emit ADD.C 12
  1195. // Temporarily store the data on the stack.
  1196. #emit PUSH.pri
  1197. // Now get the address of the slot of the CURRENT data.
  1198. #emit LOAD.pri YSI_g_sUnusedSlot
  1199. #emit SHL.C.pri 2
  1200. #emit CONST.alt YSI_g_sTextStrings
  1201. #emit ADD
  1202. #emit MOVE.alt
  1203. // Retrieve the data and store it in the new index.
  1204. #emit POP.pri
  1205. #emit STOR.I
  1206. #emit RETN
  1207. //printf("%d %d", len, YSI_g_sUnusedSlot - 1);
  1208. // Bypass compiler warnings.
  1209. return len;
  1210. }
  1211. /**--------------------------------------------------------------------------**\
  1212. <summary>Text_DebugAll</summary>
  1213. <returns>
  1214. -
  1215. </returns>
  1216. <remarks>
  1217. Prints all the strings loaded by the system, including their data offsets
  1218. and storage array lengths (cunning tightly packed array).
  1219. </remarks>
  1220. \**--------------------------------------------------------------------------**/
  1221. stock Text_DebugAllText()
  1222. {
  1223. for (new i = 0; i != YSI_g_sUnusedSlot; ++i)
  1224. {
  1225. new
  1226. next,
  1227. cur;
  1228. printf("%d %d %d %d", i, cur, next, YSI_g_sUnusedSlot);
  1229. Text_GetCurNextOffset(i, cur, next);
  1230. printf("Offset: %d, Length: %d", cur, (next - cur) / 4);
  1231. printf("Text: %s", YSI_g_sTextStrings[i]);
  1232. }
  1233. }
  1234. static stock Text_GetCurNextOffset(i, &cur, &next)
  1235. {
  1236. // Get the address of the previous slot's pointer.
  1237. #emit LOAD.S.pri i
  1238. #emit SHL.C.pri 2
  1239. #emit CONST.alt YSI_g_sTextStrings
  1240. #emit ADD
  1241. // Get the pointer to the start of the data.
  1242. #emit LOAD.I
  1243. #emit SREF.S.pri cur
  1244. // Get the address of the previous slot's pointer.
  1245. #emit LOAD.S.pri i
  1246. #emit ADD.C 0x1
  1247. #emit SHL.C.pri 2
  1248. #emit CONST.alt YSI_g_sTextStrings
  1249. #emit ADD
  1250. // Get the pointer to the start of the data.
  1251. #emit LOAD.I
  1252. #emit SREF.S.pri next
  1253. }
  1254. /**--------------------------------------------------------------------------**\
  1255. <summary>-</summary>
  1256. <returns>
  1257. -
  1258. </returns>
  1259. <remarks>
  1260. Bypass run-time OOB errors when -d0 is disabled. Set the initial "next"
  1261. pointer on the end of the string.
  1262. </remarks>
  1263. \**--------------------------------------------------------------------------**/
  1264. static stock Text_DoLinkedText(entry[], add, len)
  1265. {
  1266. entry[len] = '\05';
  1267. entry[len + 1] = add;
  1268. entry[len + 2] = '\0';
  1269. }
  1270. /**--------------------------------------------------------------------------**\
  1271. <summary>-</summary>
  1272. <returns>
  1273. -
  1274. </returns>
  1275. <remarks>
  1276. Bypass run-time OOB errors when -d0 is disabled. Get and set the "next"
  1277. pointer on the end of the string.
  1278. </remarks>
  1279. \**--------------------------------------------------------------------------**/
  1280. static stock Text_UpdateLinkedText(entry[], add, len)
  1281. {
  1282. new
  1283. ret = entry[len - 1];
  1284. entry[len - 1] = add;
  1285. return ret;
  1286. }
  1287. /**--------------------------------------------------------------------------**\
  1288. <summary>-</summary>
  1289. <returns>
  1290. -
  1291. </returns>
  1292. <remarks>
  1293. Bypass run-time OOB errors when -d0 is disabled. Get the "next" pointer on
  1294. the end of the string.
  1295. </remarks>
  1296. \**--------------------------------------------------------------------------**/
  1297. static stock Text_GetLinkedText(entry[], &ret, len)
  1298. {
  1299. if (entry[len - 2] != '\05')
  1300. {
  1301. return 0;
  1302. }
  1303. ret = entry[len - 1];
  1304. return 1;
  1305. }
  1306. /**--------------------------------------------------------------------------**\
  1307. <summary>-</summary>
  1308. <returns>
  1309. -
  1310. </returns>
  1311. <remarks>
  1312. Bypass run-time OOB errors when -d0 is disabled. Check if there is a "next"
  1313. pointer.
  1314. </remarks>
  1315. \**--------------------------------------------------------------------------**/
  1316. static stock Text_HasLinkedText(entry[], len)
  1317. {
  1318. return (entry[len - 2] == '\05');
  1319. }
  1320. /**--------------------------------------------------------------------------**\
  1321. <summary>-</summary>
  1322. <returns>
  1323. -
  1324. </returns>
  1325. <remarks>
  1326. -
  1327. </remarks>
  1328. \**--------------------------------------------------------------------------**/
  1329. static stock Text_GetFreeEntry()
  1330. {
  1331. P:4("Text_GetFreeEntry called");
  1332. if (YSI_g_sUnusedEntry == MAX_TEXT_ENTRIES)
  1333. {
  1334. return -1;
  1335. }
  1336. new
  1337. ret = YSI_g_sUnusedEntry;
  1338. YSI_g_sUnusedEntry = YSI_g_sTextEntries[ret][e_TEXT_ENTRY_HASH];
  1339. YSI_g_sTextEntries[ret][e_TEXT_ENTRY_HASH] = 0;
  1340. YSI_g_sTextEntries[ret][e_TEXT_ENTRY_LEFT] = -1;
  1341. YSI_g_sTextEntries[ret][e_TEXT_ENTRY_RIGHT] = -1;
  1342. // Reset text storage pointers.
  1343. for (new Language:i = Language:0; i != YSI_MAX_LANGUAGES; ++i)
  1344. {
  1345. YSI_g_sTextEntries[ret][e_TEXT_ENTRY_POINTERS][i] = -1;
  1346. }
  1347. return ret;
  1348. }
  1349. /**--------------------------------------------------------------------------**\
  1350. <summary>Text_IsLocalOwner</summary>
  1351. <returns>
  1352. -
  1353. </returns>
  1354. <remarks>
  1355. Checks if the string we are trying to display is owned by the local script,
  1356. and if so just use that pointer and text directly.
  1357. </remarks>
  1358. \**--------------------------------------------------------------------------**/
  1359. static stock Text_IsLocalOwner(search[], ident[], &len)
  1360. {
  1361. // First, find out if this script owns it's own text for speed reasons, and
  1362. // if it does, save the handle to the text set.
  1363. switch (search[0])
  1364. {
  1365. case '\1', '\2':
  1366. {
  1367. return -1;
  1368. }
  1369. case '\3':
  1370. {
  1371. // TODO...
  1372. }
  1373. default:
  1374. {
  1375. //Text_GetText(search, ident, lang);
  1376. new
  1377. pos,
  1378. lst,
  1379. hash;
  1380. while (search[lst])
  1381. {
  1382. pos = strfind(search[lst], "|");
  1383. search[lst + pos] = '\0';
  1384. if (existproperty(7, search[lst]) && (getproperty(7, search[lst]) == TEXT_MASTER))
  1385. {
  1386. hash = bernstein(search[lst]);
  1387. for (new i = 0; i != Y_TEXT_MAX_SETS; ++i)
  1388. {
  1389. if (hash == YSI_g_sTextSets[i][e_TEXT_SETS_HASH] && !strcmp(search[lst], YSI_g_sTextSets[i][e_TEXT_SETS_NAME]))
  1390. {
  1391. new
  1392. ret = Text_FindEntry(YSI_g_sTextSets[i][e_TEXT_SETS_INDEX], bernstein(ident));
  1393. if (ret != -1)
  1394. {
  1395. search[lst + pos] = '|';
  1396. new
  1397. style[E_STYLE_DATA],
  1398. label[E_3D_DATA];
  1399. Styles_GetData(ret, style, label);
  1400. len = _Format_SetStyleData(TEXT_MASTER, -1, style, label) - 1;
  1401. return ret;
  1402. }
  1403. }
  1404. }
  1405. }
  1406. search[lst + pos] = '|';
  1407. lst += pos + 1;
  1408. }
  1409. }
  1410. }
  1411. return -1;
  1412. }
  1413. static stock
  1414. YSI_g_sLangBuffer[YSI_MAX_LANGUAGES][MAX_SINGLE_TEXT_ITEM];
  1415. /**--------------------------------------------------------------------------**\
  1416. <summary>_Text_Send</summary>
  1417. <param name="@PlayerSet:players">A representation of players to show to.</param>
  1418. <param name="search[]">Text sets to look in for this string.</param>
  1419. <param name="ident[]">The name of the string to look for (or the string itself).</param>
  1420. <param name="GLOBAL_TAG_TYPES:...">All the parameters to pass to the string.</param>
  1421. <returns>
  1422. -
  1423. </returns>
  1424. <remarks>
  1425. Main entry point for showing any sort of code to anyone.
  1426. TODO: Change the code to push the parameters to Format_Render only once and
  1427. reuse the resulting stack.
  1428. </remarks>
  1429. \**--------------------------------------------------------------------------**/
  1430. stock _Text_Send(@PlayerSet:players, search[], ident[], GLOBAL_TAG_TYPES:...)
  1431. {
  1432. setproperty(8, YSIM_TXTLEN, 1023);
  1433. new
  1434. bool:wasOnce[YSI_MAX_LANGUAGES] = {false, ...},
  1435. n = (numargs() - 3) * 4,
  1436. maxlen,
  1437. owned = Text_IsLocalOwner(search, ident, maxlen);
  1438. // Loop through all the players passed to the function (however they were
  1439. // passed to the function). This uses "@PlayerArray" instead of
  1440. // "@PlayerVar" so that we can optimised for multiple languages. Now it
  1441. // uses "@PlayerSet" instead because that's the new one designed for
  1442. // situations like this in which we want direct access to the variable.
  1443. if (n)
  1444. {
  1445. new
  1446. arg_start,
  1447. arg_end;
  1448. // Load the real address of the last static parameter. Do this by
  1449. // loading the address of the parameter and then adding the value of
  1450. // [FRM] (frame pointer).
  1451. #emit CONST.alt ident
  1452. #emit LCTRL 5
  1453. #emit ADD
  1454. #emit STOR.S.pri arg_start
  1455. // Load the address of the last variable parameter. Do this by adding
  1456. // the number of variables on the value just loaded.
  1457. #emit LOAD.S.alt n
  1458. #emit ADD
  1459. #emit STOR.S.pri arg_end
  1460. // Push the variable arguments. This is done by loading the value of
  1461. // each one in reverse order and pushing them. I'd love to be able to
  1462. // rewrite this to use the values of pri and alt for comparison, instead
  1463. // of having or constantly reload two variables.
  1464. foreach (new playerid : PS(players))
  1465. //new playerid = 0;
  1466. {
  1467. new
  1468. Language:lang = Langs_GetPlayerLanguage(playerid);
  1469. if (lang == NO_LANGUAGE)
  1470. {
  1471. lang = Language:0;
  1472. }
  1473. if (wasOnce[lang])
  1474. {
  1475. // Optimisation for sending messages to multiple players.
  1476. Format_JustShow(playerid, YSI_g_sLangBuffer[lang]);
  1477. continue;
  1478. }
  1479. new
  1480. arg_cur = arg_end,
  1481. ret;
  1482. do
  1483. {
  1484. #emit LOAD.S.pri arg_cur
  1485. #emit LOAD.I
  1486. #emit PUSH.pri
  1487. arg_cur -= 4;
  1488. }
  1489. while (arg_cur > arg_start);
  1490. switch (search[0])
  1491. {
  1492. case '\1':
  1493. {
  1494. // Null - error.
  1495. P:E("Text_Send called with NULL");
  1496. }
  1497. case '\2':
  1498. {
  1499. // None - just print the string directly.
  1500. ret = Format_Render(playerid, lang, YSI_g_sLangBuffer[lang], getproperty(8, YSIM_TXTLEN) - 1, 0, 0, ident, n / 4);
  1501. }
  1502. case '\3':
  1503. {
  1504. if (owned == -1)
  1505. {
  1506. new
  1507. pos = strfind(ident, ">"),
  1508. br = strfind(ident, "[");
  1509. if (pos > 1 && br != -1)
  1510. {
  1511. ident[pos - 2] = '\0';
  1512. if (br)
  1513. {
  1514. ident[br] = ':';
  1515. Text_GetText(ident, ident[pos + 1], lang);
  1516. }
  1517. else
  1518. {
  1519. Text_GetText(ident[1], ident[pos + 1], lang);
  1520. }
  1521. ret = Format_Render(playerid, lang, YSI_g_sLangBuffer[lang], getproperty(8, YSIM_TXTLEN) - 1, 0, 0, YSI_g_sReturnText, n / 4);
  1522. }
  1523. else
  1524. {
  1525. // Var - May contain location search information in
  1526. // "name". Maybe add an "all" search parameter...
  1527. ret = Format_Render(playerid, lang, YSI_g_sLangBuffer[lang], getproperty(8, YSIM_TXTLEN) - 1, 0, 0, "Could not find text source", n / 4);
  1528. // The code generated messes up the pushing.
  1529. }
  1530. }
  1531. else
  1532. {
  1533. ret = YSI_g_sTextEntries[owned][e_TEXT_ENTRY_POINTERS][lang];
  1534. if (ret == -1)
  1535. {
  1536. ret = Format_Render(playerid, lang, YSI_g_sLangBuffer[lang], maxlen, 0, 0, "Language text not found", n / 4);
  1537. }
  1538. else
  1539. {
  1540. ret = Format_Render(playerid, lang, YSI_g_sLangBuffer[lang], maxlen, 0, 0, YSI_g_sTextStrings[ret], n / 4);
  1541. }
  1542. }
  1543. }
  1544. default:
  1545. {
  1546. if (owned == -1)
  1547. {
  1548. Text_GetText(search, ident, lang);
  1549. ret = Format_Render(playerid, lang, YSI_g_sLangBuffer[lang], getproperty(8, YSIM_TXTLEN) - 1, 0, 0, YSI_g_sReturnText, n / 4);
  1550. }
  1551. else
  1552. {
  1553. ret = YSI_g_sTextEntries[owned][e_TEXT_ENTRY_POINTERS][lang];
  1554. if (ret == -1)
  1555. {
  1556. ret = Format_Render(playerid, lang, YSI_g_sLangBuffer[lang], maxlen, 0, 0, "Language text not found", n / 4);
  1557. }
  1558. else
  1559. {
  1560. ret = Format_Render(playerid, lang, YSI_g_sLangBuffer[lang], maxlen, 0, 0, YSI_g_sTextStrings[ret], n / 4);
  1561. }
  1562. }
  1563. }
  1564. }
  1565. #emit LCTRL 4
  1566. #emit LOAD.S.alt n
  1567. #emit ADD
  1568. #emit SCTRL 4
  1569. wasOnce[lang] = !ret;
  1570. }
  1571. }
  1572. else
  1573. {
  1574. foreach (new playerid : PS(players))
  1575. {
  1576. new
  1577. Language:lang = Langs_GetPlayerLanguage(playerid);
  1578. if (wasOnce[lang])
  1579. {
  1580. // Optimisation for sending messages to multiple players.
  1581. Format_JustShow(playerid, YSI_g_sLangBuffer[lang]);
  1582. continue;
  1583. }
  1584. switch (search[0])
  1585. {
  1586. case '\1':
  1587. {
  1588. // Null - error.
  1589. P:E("Text_Send called with NULL");
  1590. }
  1591. case '\2':
  1592. {
  1593. // None - just print the string directly.
  1594. wasOnce[lang] = !Format_Render(playerid, lang, YSI_g_sLangBuffer[lang], getproperty(8, YSIM_TXTLEN) - 1, 0, 0, ident, 0);
  1595. }
  1596. case '\3':
  1597. {
  1598. new
  1599. pos = strfind(ident, ">"),
  1600. br = strfind(ident, "[");
  1601. if (pos > 1 && br != -1)
  1602. {
  1603. ident[pos - 2] = '\0';
  1604. if (br)
  1605. {
  1606. ident[br] = ':';
  1607. Text_GetText(ident, ident[pos + 1], lang);
  1608. }
  1609. else
  1610. {
  1611. Text_GetText(ident[1], ident[pos + 1], lang);
  1612. }
  1613. wasOnce[lang] = !Format_Render(playerid, lang, YSI_g_sLangBuffer[lang], getproperty(8, YSIM_TXTLEN) - 1, 0, 0, YSI_g_sReturnText, 0);
  1614. }
  1615. else
  1616. {
  1617. // Var - May contain location search information in
  1618. // "name". Maybe add an "all" search parameter...
  1619. wasOnce[lang] = !Format_Render(playerid, lang, YSI_g_sLangBuffer[lang], getproperty(8, YSIM_TXTLEN) - 1, 0, 0, "Could not find text source", 0);
  1620. }
  1621. }
  1622. default:
  1623. {
  1624. if (owned == -1)
  1625. {
  1626. Text_GetText(search, ident, lang);
  1627. wasOnce[lang] = !Format_Render(playerid, lang, YSI_g_sLangBuffer[lang], getproperty(8, YSIM_TXTLEN) - 1, 0, 0, YSI_g_sReturnText, 0);
  1628. }
  1629. else
  1630. {
  1631. new
  1632. ret = YSI_g_sTextEntries[owned][e_TEXT_ENTRY_POINTERS][lang];
  1633. if (ret == -1)
  1634. {
  1635. wasOnce[lang] = !Format_Render(playerid, lang, YSI_g_sLangBuffer[lang], maxlen, 0, 0, "Language text not found", 0);
  1636. }
  1637. else
  1638. {
  1639. wasOnce[lang] = !Format_Render(playerid, lang, YSI_g_sLangBuffer[lang], maxlen, 0, 0, YSI_g_sTextStrings[ret], 0);
  1640. }
  1641. }
  1642. }
  1643. }
  1644. }
  1645. }
  1646. Format_SetListSeparator(", ");
  1647. return Text_GetLastID();
  1648. }
  1649. /**--------------------------------------------------------------------------**\
  1650. <summary>_Text_Render</summary>
  1651. <param name="search[]">Text sets to look in for this string.</param>
  1652. <param name="ident[]">The name of the string to look for (or the string itself).</param>
  1653. <param name="GLOBAL_TAG_TYPES:...">All the parameters to pass to the string.</param>
  1654. <returns>
  1655. -
  1656. </returns>
  1657. <remarks>
  1658. This function renders some text to an array, but doesn't display it.
  1659. </remarks>
  1660. \**--------------------------------------------------------------------------**/
  1661. stock Text_GetPreRender(Language:lang)
  1662. {
  1663. return YSI_g_sLangBuffer[lang];
  1664. }
  1665. stock _Text_Render(playerid, search[], ident[], GLOBAL_TAG_TYPES:...)
  1666. {
  1667. setproperty(8, YSIM_TXTLEN, 1023);
  1668. new
  1669. bool:wasOnce[YSI_MAX_LANGUAGES] = {false, ...},
  1670. n = (numargs() - 3) * 4,
  1671. maxlen,
  1672. owned = Text_IsLocalOwner(search, ident, maxlen);
  1673. // Loop through all the players passed to the function (however they were
  1674. // passed to the function). This uses "@PlayerArray" instead of
  1675. // "@PlayerVar" so that we can optimised for multiple languages. Now it
  1676. // uses "@PlayerSet" instead because that's the new one designed for
  1677. // situations like this in which we want direct access to the variable.
  1678. if (n)
  1679. {
  1680. new
  1681. arg_start,
  1682. arg_end;
  1683. // Load the real address of the last static parameter. Do this by
  1684. // loading the address of the parameter and then adding the value of
  1685. // [FRM] (frame pointer).
  1686. #emit CONST.alt ident
  1687. #emit LCTRL 5
  1688. #emit ADD
  1689. #emit STOR.S.pri arg_start
  1690. // Load the address of the last variable parameter. Do this by adding
  1691. // the number of variables on the value just loaded.
  1692. #emit LOAD.S.alt n
  1693. #emit ADD
  1694. #emit STOR.S.pri arg_end
  1695. // Push the variable arguments. This is done by loading the value of
  1696. // each one in reverse order and pushing them. I'd love to be able to
  1697. // rewrite this to use the values of pri and alt for comparison, instead
  1698. // of having or constantly reload two variables.
  1699. for (new Language:lang; lang != YSI_MAX_LANGUAGES; ++lang) if (Langs_IsValid(lang))
  1700. {
  1701. new
  1702. arg_cur = arg_end,
  1703. ret;
  1704. do
  1705. {
  1706. #emit LOAD.S.pri arg_cur
  1707. #emit LOAD.I
  1708. #emit PUSH.pri
  1709. arg_cur -= 4;
  1710. }
  1711. while (arg_cur > arg_start);
  1712. switch (search[0])
  1713. {
  1714. case '\1':
  1715. {
  1716. // Null - error.
  1717. P:E("Text_Send called with NULL");
  1718. }
  1719. case '\2':
  1720. {
  1721. // None - just print the string directly.
  1722. ret = Format_Render(playerid, lang, YSI_g_sLangBuffer[lang], getproperty(8, YSIM_TXTLEN) - 1, 0, e_FORMAT_FLAGS_NONE, ident, n / 4);
  1723. }
  1724. case '\3':
  1725. {
  1726. if (owned == -1)
  1727. {
  1728. new
  1729. pos = strfind(ident, ">"),
  1730. br = strfind(ident, "[");
  1731. if (pos > 1 && br != -1)
  1732. {
  1733. ident[pos - 2] = '\0';
  1734. if (br)
  1735. {
  1736. ident[br] = ':';
  1737. Text_GetText(ident, ident[pos + 1], lang);
  1738. }
  1739. else
  1740. {
  1741. Text_GetText(ident[1], ident[pos + 1], lang);
  1742. }
  1743. ret = Format_Render(playerid, lang, YSI_g_sLangBuffer[lang], getproperty(8, YSIM_TXTLEN) - 1, 0, e_FORMAT_FLAGS_NONE, YSI_g_sReturnText, n / 4);
  1744. }
  1745. else
  1746. {
  1747. // Var - May contain location search information in
  1748. // "name". Maybe add an "all" search parameter...
  1749. ret = Format_Render(playerid, lang, YSI_g_sLangBuffer[lang], getproperty(8, YSIM_TXTLEN) - 1, 0, e_FORMAT_FLAGS_NONE, "Could not find text source", n / 4);
  1750. // The code generated messes up the pushing.
  1751. }
  1752. }
  1753. else
  1754. {
  1755. ret = YSI_g_sTextEntries[owned][e_TEXT_ENTRY_POINTERS][lang];
  1756. if (ret == -1)
  1757. {
  1758. ret = Format_Render(playerid, lang, YSI_g_sLangBuffer[lang], maxlen, 0, e_FORMAT_FLAGS_NONE, "Language text not found", n / 4);
  1759. }
  1760. else
  1761. {
  1762. ret = Format_Render(playerid, lang, YSI_g_sLangBuffer[lang], maxlen, 0, e_FORMAT_FLAGS_NONE, YSI_g_sTextStrings[ret], n / 4);
  1763. }
  1764. }
  1765. }
  1766. default:
  1767. {
  1768. if (owned == -1)
  1769. {
  1770. Text_GetText(search, ident, lang);
  1771. ret = Format_Render(playerid, lang, YSI_g_sLangBuffer[lang], getproperty(8, YSIM_TXTLEN) - 1, 0, e_FORMAT_FLAGS_NONE, YSI_g_sReturnText, n / 4);
  1772. }
  1773. else
  1774. {
  1775. ret = YSI_g_sTextEntries[owned][e_TEXT_ENTRY_POINTERS][lang];
  1776. if (ret == -1)
  1777. {
  1778. ret = Format_Render(playerid, lang, YSI_g_sLangBuffer[lang], maxlen, 0, e_FORMAT_FLAGS_NONE, "Language text not found", n / 4);
  1779. }
  1780. else
  1781. {
  1782. ret = Format_Render(playerid, lang, YSI_g_sLangBuffer[lang], maxlen, 0, e_FORMAT_FLAGS_NONE, YSI_g_sTextStrings[ret], n / 4);
  1783. }
  1784. }
  1785. }
  1786. }
  1787. #emit LCTRL 4
  1788. #emit LOAD.S.alt n
  1789. #emit ADD
  1790. #emit SCTRL 4
  1791. wasOnce[lang] = !ret;
  1792. }
  1793. }
  1794. else
  1795. {
  1796. for (new Language:lang; lang != YSI_MAX_LANGUAGES; ++lang) if (Langs_IsValid(lang))
  1797. {
  1798. switch (search[0])
  1799. {
  1800. case '\1':
  1801. {
  1802. // Null - error.
  1803. P:E("Text_Send called with NULL");
  1804. }
  1805. case '\2':
  1806. {
  1807. // None - just print the string directly.
  1808. wasOnce[lang] = !Format_Render(playerid, lang, YSI_g_sLangBuffer[lang], getproperty(8, YSIM_TXTLEN) - 1, 0, e_FORMAT_FLAGS_NONE, ident, 0);
  1809. }
  1810. case '\3':
  1811. {
  1812. new
  1813. pos = strfind(ident, ">"),
  1814. br = strfind(ident, "[");
  1815. if (pos > 1 && br != -1)
  1816. {
  1817. ident[pos - 2] = '\0';
  1818. if (br)
  1819. {
  1820. ident[br] = ':';
  1821. Text_GetText(ident, ident[pos + 1], lang);
  1822. }
  1823. else
  1824. {
  1825. Text_GetText(ident[1], ident[pos + 1], lang);
  1826. }
  1827. wasOnce[lang] = !Format_Render(playerid, lang, YSI_g_sLangBuffer[lang], getproperty(8, YSIM_TXTLEN) - 1, 0, e_FORMAT_FLAGS_NONE, YSI_g_sReturnText, 0);
  1828. }
  1829. else
  1830. {
  1831. // Var - May contain location search information in
  1832. // "name". Maybe add an "all" search parameter...
  1833. wasOnce[lang] = !Format_Render(playerid, lang, YSI_g_sLangBuffer[lang], getproperty(8, YSIM_TXTLEN) - 1, 0, e_FORMAT_FLAGS_NONE, "Could not find text source", 0);
  1834. }
  1835. }
  1836. default:
  1837. {
  1838. if (owned == -1)
  1839. {
  1840. Text_GetText(search, ident, lang);
  1841. wasOnce[lang] = !Format_Render(playerid, lang, YSI_g_sLangBuffer[lang], getproperty(8, YSIM_TXTLEN) - 1, 0, e_FORMAT_FLAGS_NONE, YSI_g_sReturnText, 0);
  1842. }
  1843. else
  1844. {
  1845. new
  1846. ret = YSI_g_sTextEntries[owned][e_TEXT_ENTRY_POINTERS][lang];
  1847. if (ret == -1)
  1848. {
  1849. wasOnce[lang] = !Format_Render(playerid, lang, YSI_g_sLangBuffer[lang], maxlen, 0, e_FORMAT_FLAGS_NONE, "Language text not found", 0);
  1850. }
  1851. else
  1852. {
  1853. wasOnce[lang] = !Format_Render(playerid, lang, YSI_g_sLangBuffer[lang], maxlen, 0, e_FORMAT_FLAGS_NONE, YSI_g_sTextStrings[ret], 0);
  1854. }
  1855. }
  1856. }
  1857. }
  1858. }
  1859. }
  1860. //return Text_GetLastID();
  1861. Format_SetListSeparator(", ");
  1862. }
  1863. static stock
  1864. YSI_g_sCaptionText[YSI_MAX_LANGUAGES][64],
  1865. YSI_g_sButton1Text[YSI_MAX_LANGUAGES][16],
  1866. YSI_g_sButton2Text[YSI_MAX_LANGUAGES][16];
  1867. /**--------------------------------------------------------------------------**\
  1868. <summary>-</summary>
  1869. <returns>
  1870. -
  1871. </returns>
  1872. <remarks>
  1873. -
  1874. </remarks>
  1875. \**--------------------------------------------------------------------------**/
  1876. //stock @PlayerArray:players<MAX_PLAYERS>, callback[], csearch[], cident[], isearch[], iident[], b1search[], b1ident[], b2search[], b2ident[], GLOBAL_TAG_TYPES:...)
  1877. //stock _Text_MessageBox(@PlayerArray:players<MAX_PLAYERS>, callback[], csearch[], cident[], isearch[], iident[], b1search[], b1ident[], b2search[], b2ident[], GLOBAL_TAG_TYPES:...)
  1878. //stock _Text_MessageBox(@PlayerArray:players<MAX_PLAYERS>, callback[], csearch[], cident[], isearch[], iident[], b1search[], b1ident[], b2search[], b2ident[], GLOBAL_TAG_TYPES:...)
  1879. stock _Text_DialogBox(@PlayerSet:players, style, callback:callback, csearch[], cident[], isearch[], iident[], b1search[], b1ident[], b2search[], b2ident[], GLOBAL_TAG_TYPES:...)
  1880. //stock _Text_MessageBox(__ps_addr_t:__ps_addr, callback[], csearch[], cident[], isearch[], iident[], b1search[], b1ident[], b2search[], b2ident[], GLOBAL_TAG_TYPES:...)
  1881. {
  1882. // This is what the "@PlayerArray" macro expands to, but I needed more
  1883. // control to allow me to return a value. The fact that I can't ATM is a
  1884. // serious problem, but not serious enough to warrant fixing.
  1885. new
  1886. bool:wasOnce[YSI_MAX_LANGUAGES] = {false, ...},
  1887. bool:gotExtras[YSI_MAX_LANGUAGES] = {false, ...},
  1888. n = (numargs() - 11) * 4,
  1889. dialog = Dialog_ObtainID();//,
  1890. //maxlen,
  1891. //owned = Text_IsLocalOwner(isearch, iident, maxlen);
  1892. // Loop through all the players passed to the function (however they were
  1893. // passed to the function). This uses "@PlayerArray" instead of
  1894. // "@PlayerVar" so that we can optimised for multiple languages.
  1895. if (n)
  1896. {
  1897. new
  1898. arg_start,
  1899. arg_end;
  1900. // Load the real address of the last static parameter. Do this by
  1901. // loading the address of the parameter and then adding the value of
  1902. // [FRM] (frame pointer).
  1903. #emit CONST.alt b2ident
  1904. #emit LCTRL 5
  1905. #emit ADD
  1906. #emit STOR.S.pri arg_start
  1907. // Load the address of the last variable parameter. Do this by adding
  1908. // the number of variables on the value just loaded.
  1909. #emit LOAD.S.alt n
  1910. #emit ADD
  1911. #emit STOR.S.pri arg_end
  1912. // Push the variable arguments. This is done by loading the value of
  1913. // each one in reverse order and pushing them. I'd love to be able to
  1914. // rewrite this to use the values of pri and alt for comparison, instead
  1915. // of having or constantly reload two variables.
  1916. //for (new PlayerArray:players<MAX_PLAYERS>; __PS_A(_:__ps_addr, players); )
  1917. foreach (new playerid : PS(players))
  1918. {
  1919. new
  1920. Language:lang = Langs_GetPlayerLanguage(playerid);
  1921. if (lang == NO_LANGUAGE)
  1922. {
  1923. lang = Language:0;
  1924. }
  1925. // Only ever do this part once per language.
  1926. if (!gotExtras[lang])
  1927. {
  1928. // Get the text for the caption in this language.
  1929. switch (csearch[0])
  1930. {
  1931. case '\1': P:E("Text_Send called with NULL");
  1932. case '\2': strcpy(YSI_g_sCaptionText[lang], cident, sizeof (YSI_g_sCaptionText[]));
  1933. case '\3':
  1934. {
  1935. new pos = strfind(cident, ">"), br = strfind(cident, "[");
  1936. if (pos > 1 && br != -1)
  1937. {
  1938. cident[pos - 2] = '\0';
  1939. if (br) cident[br] = ':', Text_GetText(cident, cident[pos + 1], lang);
  1940. else Text_GetText(cident[1], cident[pos + 1], lang);
  1941. _Text_SetDialogMode();
  1942. Format_Render(playerid, lang, YSI_g_sCaptionText[lang], sizeof (YSI_g_sCaptionText[]) - 1, 0, e_FORMAT_FLAGS_NONE, YSI_g_sReturnText, 0);
  1943. }
  1944. else YSI_g_sCaptionText[lang] = "Could not find title source";
  1945. }
  1946. default:
  1947. {
  1948. Text_GetText(csearch, cident, lang);
  1949. _Text_SetDialogMode();
  1950. Format_Render(playerid, lang, YSI_g_sCaptionText[lang], sizeof (YSI_g_sCaptionText[]) - 1, 0, e_FORMAT_FLAGS_NONE, YSI_g_sReturnText, 0);
  1951. }
  1952. }
  1953. // Get the text for button 1 in this language.
  1954. switch (b1search[0])
  1955. {
  1956. case '\1': P:E("Text_Send called with NULL");
  1957. case '\2': strcpy(YSI_g_sButton1Text[lang], b1ident, sizeof (YSI_g_sButton1Text[]));
  1958. case '\3':
  1959. {
  1960. new pos = strfind(b1ident, ">"), br = strfind(b1ident, "[");
  1961. if (pos > 1 && br != -1)
  1962. {
  1963. b1ident[pos - 2] = '\0';
  1964. if (br) b1ident[br] = ':', Text_GetText(b1ident, b1ident[pos + 1], lang);
  1965. else Text_GetText(b1ident[1], b1ident[pos + 1], lang);
  1966. _Text_SetDialogMode();
  1967. Format_Render(playerid, lang, YSI_g_sButton1Text[lang], sizeof (YSI_g_sButton1Text[]) - 1, 0, e_FORMAT_FLAGS_NONE, YSI_g_sReturnText, 0);
  1968. }
  1969. else YSI_g_sButton1Text[lang] = "???";
  1970. }
  1971. default:
  1972. {
  1973. Text_GetText(b1search, b1ident, lang);
  1974. _Text_SetDialogMode();
  1975. Format_Render(playerid, lang, YSI_g_sButton1Text[lang], sizeof (YSI_g_sButton1Text[]) - 1, 0, e_FORMAT_FLAGS_NONE, YSI_g_sReturnText, 0);
  1976. }
  1977. }
  1978. // Get the text for button 1 in this language.
  1979. if (b2ident[0])
  1980. {
  1981. switch (b2search[0])
  1982. {
  1983. case '\1': P:E("Text_Send called with NULL");
  1984. case '\2': strcpy(YSI_g_sButton2Text[lang], b2ident, sizeof (YSI_g_sButton2Text[]));
  1985. case '\3':
  1986. {
  1987. new pos = strfind(b2ident, ">"), br = strfind(b2ident, "[");
  1988. if (pos > 1 && br != -1)
  1989. {
  1990. b2ident[pos - 2] = '\0';
  1991. if (br) b2ident[br] = ':', Text_GetText(b2ident, b2ident[pos + 1], lang);
  1992. else Text_GetText(b2ident[1], b2ident[pos + 1], lang);
  1993. _Text_SetDialogMode();
  1994. Format_Render(playerid, lang, YSI_g_sButton2Text[lang], sizeof (YSI_g_sButton2Text[]) - 1, 0, e_FORMAT_FLAGS_NONE, YSI_g_sReturnText, 0);
  1995. }
  1996. else YSI_g_sButton2Text[lang] = "";
  1997. }
  1998. default:
  1999. {
  2000. Text_GetText(b2search, b2ident, lang);
  2001. _Text_SetDialogMode();
  2002. Format_Render(playerid, lang, YSI_g_sButton2Text[lang], sizeof (YSI_g_sButton2Text[]) - 1, 0, e_FORMAT_FLAGS_NONE, YSI_g_sReturnText, 0);
  2003. }
  2004. }
  2005. }
  2006. else YSI_g_sButton2Text[lang] = "";
  2007. gotExtras[lang] = true;
  2008. }
  2009. if (!wasOnce[lang])
  2010. {
  2011. // Optimisation for sending messages to multiple players.
  2012. //Format_DoDisplay(playerid, 0xFF0000AA, YSI_g_sLangBuffer[lang]);
  2013. //continue;
  2014. new
  2015. arg_cur = arg_end,
  2016. ret;
  2017. do
  2018. {
  2019. #emit LOAD.S.pri arg_cur
  2020. #emit LOAD.I
  2021. #emit PUSH.pri
  2022. arg_cur -= 4;
  2023. }
  2024. while (arg_cur > arg_start);
  2025. switch (isearch[0])
  2026. {
  2027. case '\1':
  2028. {
  2029. // Null - error.
  2030. P:E("Text_Send called with NULL");
  2031. }
  2032. case '\2':
  2033. {
  2034. // None - just print the string directly.
  2035. _Text_SetDialogMode();
  2036. ret = Format_Render(playerid, lang, YSI_g_sLangBuffer[lang], sizeof (YSI_g_sLangBuffer[]) - 1, 0, e_FORMAT_FLAGS_NONE, iident, n / 4);
  2037. }
  2038. case '\3':
  2039. {
  2040. new
  2041. pos = strfind(iident, ">"),
  2042. br = strfind(iident, "[");
  2043. if (pos > 1 && br != -1)
  2044. {
  2045. iident[pos - 2] = '\0';
  2046. if (br)
  2047. {
  2048. iident[br] = ':';
  2049. Text_GetText(iident, iident[pos + 1], lang);
  2050. }
  2051. else
  2052. {
  2053. Text_GetText(iident[1], iident[pos + 1], lang);
  2054. }
  2055. _Text_SetDialogMode();
  2056. ret = Format_Render(playerid, lang, YSI_g_sLangBuffer[lang], sizeof (YSI_g_sLangBuffer[]) - 1, 0, e_FORMAT_FLAGS_NONE, YSI_g_sReturnText, n / 4);
  2057. }
  2058. else
  2059. {
  2060. // Var - May contain location isearch information in
  2061. // "name". Maybe add an "all" isearch parameter...
  2062. _Text_SetDialogMode();
  2063. ret = Format_Render(playerid, lang, YSI_g_sLangBuffer[lang], sizeof (YSI_g_sLangBuffer[]) - 1, 0, e_FORMAT_FLAGS_NONE, "Could not find text source", n / 4);
  2064. // The code generated messes up the pushing.
  2065. }
  2066. }
  2067. default:
  2068. {
  2069. Text_GetText(isearch, iident, lang);
  2070. _Text_SetDialogMode();
  2071. ret = Format_Render(playerid, lang, YSI_g_sLangBuffer[lang], sizeof (YSI_g_sLangBuffer[]) - 1, 0, e_FORMAT_FLAGS_NONE, YSI_g_sReturnText, n / 4);
  2072. }
  2073. }
  2074. #emit LCTRL 4
  2075. #emit LOAD.S.alt n
  2076. #emit ADD
  2077. #emit SCTRL 4
  2078. wasOnce[lang] = !ret;
  2079. }
  2080. // Display the message.
  2081. Dialog_Show(playerid, style, YSI_g_sCaptionText[lang], YSI_g_sLangBuffer[lang], YSI_g_sButton1Text[lang], YSI_g_sButton2Text[lang], dialog);
  2082. }
  2083. }
  2084. else
  2085. {
  2086. // Push the variable arguments. This is done by loading the value of
  2087. // each one in reverse order and pushing them. I'd love to be able to
  2088. // rewrite this to use the values of pri and alt for comparison, instead
  2089. // of having or constantly reload two variables.
  2090. foreach (new playerid : PS(players))
  2091. //for (new PlayerArray:players<MAX_PLAYERS>; __PS_A(_:__ps_addr, players); )
  2092. {
  2093. new
  2094. Language:lang = Langs_GetPlayerLanguage(playerid);
  2095. if (lang == NO_LANGUAGE)
  2096. {
  2097. lang = Language:0;
  2098. }
  2099. // Only ever do this part once per language.
  2100. if (!gotExtras[lang])
  2101. {
  2102. // Get the text for the caption in this language.
  2103. switch (csearch[0])
  2104. {
  2105. case '\1': P:E("Text_Send called with NULL");
  2106. case '\2': strcpy(YSI_g_sCaptionText[lang], cident, sizeof (YSI_g_sCaptionText[]));
  2107. case '\3':
  2108. {
  2109. new pos = strfind(cident, ">"), br = strfind(cident, "[");
  2110. if (pos > 1 && br != -1)
  2111. {
  2112. cident[pos - 2] = '\0';
  2113. if (br) cident[br] = ':', Text_GetText(cident, cident[pos + 1], lang);
  2114. else Text_GetText(cident[1], cident[pos + 1], lang);
  2115. _Text_SetDialogMode();
  2116. Format_Render(playerid, lang, YSI_g_sCaptionText[lang], sizeof (YSI_g_sCaptionText[]) - 1, 0, e_FORMAT_FLAGS_NONE, YSI_g_sReturnText, 0);
  2117. }
  2118. else YSI_g_sCaptionText[lang] = "Could not find title source";
  2119. }
  2120. default:
  2121. {
  2122. Text_GetText(csearch, cident, lang);
  2123. _Text_SetDialogMode();
  2124. Format_Render(playerid, lang, YSI_g_sCaptionText[lang], sizeof (YSI_g_sCaptionText[]) - 1, 0, e_FORMAT_FLAGS_NONE, YSI_g_sReturnText, 0);
  2125. }
  2126. }
  2127. // Get the text for button 1 in this language.
  2128. switch (b1search[0])
  2129. {
  2130. case '\1': P:E("Text_Send called with NULL");
  2131. case '\2': strcpy(YSI_g_sButton1Text[lang], b1ident, sizeof (YSI_g_sButton1Text[]));
  2132. case '\3':
  2133. {
  2134. new pos = strfind(b1ident, ">"), br = strfind(b1ident, "[");
  2135. if (pos > 1 && br != -1)
  2136. {
  2137. b1ident[pos - 2] = '\0';
  2138. if (br) b1ident[br] = ':', Text_GetText(b1ident, b1ident[pos + 1], lang);
  2139. else Text_GetText(b1ident[1], b1ident[pos + 1], lang);
  2140. _Text_SetDialogMode();
  2141. Format_Render(playerid, lang, YSI_g_sButton1Text[lang], sizeof (YSI_g_sButton1Text[]) - 1, 0, e_FORMAT_FLAGS_NONE, YSI_g_sReturnText, 0);
  2142. }
  2143. else YSI_g_sButton1Text[lang] = "???";
  2144. }
  2145. default:
  2146. {
  2147. Text_GetText(b1search, b1ident, lang);
  2148. _Text_SetDialogMode();
  2149. Format_Render(playerid, lang, YSI_g_sButton1Text[lang], sizeof (YSI_g_sButton1Text[]) - 1, 0, e_FORMAT_FLAGS_NONE, YSI_g_sReturnText, 0);
  2150. }
  2151. }
  2152. // Get the text for button 1 in this language.
  2153. if (b2ident[0])
  2154. {
  2155. switch (b2search[0])
  2156. {
  2157. case '\1': P:E("Text_Send called with NULL");
  2158. case '\2': strcpy(YSI_g_sButton2Text[lang], b2ident, sizeof (YSI_g_sButton2Text[]));
  2159. case '\3':
  2160. {
  2161. new pos = strfind(b2ident, ">"), br = strfind(b2ident, "[");
  2162. if (pos > 1 && br != -1)
  2163. {
  2164. b2ident[pos - 2] = '\0';
  2165. if (br) b2ident[br] = ':', Text_GetText(b2ident, b2ident[pos + 1], lang);
  2166. else Text_GetText(b2ident[1], b2ident[pos + 1], lang);
  2167. _Text_SetDialogMode();
  2168. Format_Render(playerid, lang, YSI_g_sButton2Text[lang], sizeof (YSI_g_sButton2Text[]) - 1, 0, e_FORMAT_FLAGS_NONE, YSI_g_sReturnText, 0);
  2169. }
  2170. else YSI_g_sButton2Text[lang] = "";
  2171. }
  2172. default:
  2173. {
  2174. Text_GetText(b2search, b2ident, lang);
  2175. _Text_SetDialogMode();
  2176. Format_Render(playerid, lang, YSI_g_sButton2Text[lang], sizeof (YSI_g_sButton2Text[]) - 1, 0, e_FORMAT_FLAGS_NONE, YSI_g_sReturnText, 0);
  2177. }
  2178. }
  2179. }
  2180. else YSI_g_sButton2Text[lang] = "";
  2181. gotExtras[lang] = true;
  2182. }
  2183. if (!wasOnce[lang])
  2184. {
  2185. new
  2186. ret;
  2187. switch (isearch[0])
  2188. {
  2189. case '\1':
  2190. {
  2191. // Null - error.
  2192. P:E("Text_Send called with NULL");
  2193. }
  2194. case '\2':
  2195. {
  2196. // None - just print the string directly.
  2197. _Text_SetDialogMode();
  2198. ret = Format_Render(playerid, lang, YSI_g_sLangBuffer[lang], sizeof (YSI_g_sLangBuffer[]) - 1, 0, e_FORMAT_FLAGS_NONE, iident, 0);
  2199. }
  2200. case '\3':
  2201. {
  2202. new
  2203. pos = strfind(iident, ">"),
  2204. br = strfind(iident, "[");
  2205. if (pos > 1 && br != -1)
  2206. {
  2207. iident[pos - 2] = '\0';
  2208. if (br)
  2209. {
  2210. iident[br] = ':';
  2211. Text_GetText(iident, iident[pos + 1], lang);
  2212. }
  2213. else
  2214. {
  2215. Text_GetText(iident[1], iident[pos + 1], lang);
  2216. }
  2217. _Text_SetDialogMode();
  2218. ret = Format_Render(playerid, lang, YSI_g_sLangBuffer[lang], sizeof (YSI_g_sLangBuffer[]) - 1, 0, e_FORMAT_FLAGS_NONE, YSI_g_sReturnText, 0);
  2219. }
  2220. else
  2221. {
  2222. // Var - May contain location isearch information in
  2223. // "name". Maybe add an "all" isearch parameter...
  2224. _Text_SetDialogMode();
  2225. ret = Format_Render(playerid, lang, YSI_g_sLangBuffer[lang], sizeof (YSI_g_sLangBuffer[]) - 1, 0, e_FORMAT_FLAGS_NONE, "Could not find text source", 0);
  2226. // The code generated messes up the pushing.
  2227. }
  2228. }
  2229. default:
  2230. {
  2231. Text_GetText(isearch, iident, lang);
  2232. _Text_SetDialogMode();
  2233. ret = Format_Render(playerid, lang, YSI_g_sLangBuffer[lang], sizeof (YSI_g_sLangBuffer[]) - 1, 0, e_FORMAT_FLAGS_NONE, YSI_g_sReturnText, 0);
  2234. }
  2235. }
  2236. wasOnce[lang] = !ret;
  2237. }
  2238. // Display the message.
  2239. Dialog_Show(playerid, style, YSI_g_sCaptionText[lang], YSI_g_sLangBuffer[lang], YSI_g_sButton1Text[lang], YSI_g_sButton2Text[lang], dialog);
  2240. }
  2241. }
  2242. // Sort out the callbacks etc for the dialog return.
  2243. new
  2244. cd[E_CALLBACK_DATA];
  2245. Callback_Get(callback, cd, _F<iiiis>);
  2246. Dialog_SetCallbackData(dialog, cd); //AMX_GetPublicPointer(callback));
  2247. // Automatically free the dialog when we're done.
  2248. Dialog_Garbage(dialog);
  2249. Format_SetListSeparator(", ");
  2250. return dialog;
  2251. }