y_textint.inc 62 KB

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