y_textint.inc 74 KB

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