LuaInterface.cpp 95 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775
  1. /*
  2. EQ2Emulator: Everquest II Server Emulator
  3. Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net)
  4. This file is part of EQ2Emulator.
  5. EQ2Emulator is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. EQ2Emulator is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with EQ2Emulator. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include "LuaInterface.h"
  17. #include "LuaFunctions.h"
  18. #include "WorldDatabase.h"
  19. #include "SpellProcess.h"
  20. #include "../common/Log.h"
  21. #include "World.h"
  22. #ifndef WIN32
  23. #include <stdio.h>
  24. #include <sys/types.h>
  25. #include <sys/stat.h>
  26. #include <dirent.h>
  27. #include <pthread.h>
  28. #else
  29. #include <process.h>
  30. #endif
  31. extern WorldDatabase database;
  32. extern ZoneList zone_list;
  33. LuaInterface::LuaInterface() {
  34. shutting_down = false;
  35. lua_system_reloading = false;
  36. MDebugClients.SetName("LuaInterface::MDebugClients");
  37. MSpells.SetName("LuaInterface::MSpells");
  38. MSpawnScripts.SetName("LuaInterface::MSpawnScripts");
  39. MZoneScripts.SetName("LuaInterface::MZoneScripts");
  40. MQuests.SetName("LuaInterface::MQuests");
  41. MLUAMain.SetName("LuaInterface::MLUAMain");
  42. MItemScripts.SetName("LuaInterface::MItemScripts");
  43. MSpellDelete.SetName("LuaInterface::MSpellDelete");
  44. MCustomSpell.SetName("LuaInterface::MCustomSpell");
  45. MRegionScripts.SetName("LuaInterface::MRegionScripts");
  46. user_data_timer = new Timer(20000);
  47. user_data_timer->Start();
  48. spell_delete_timer = new Timer(5000);
  49. spell_delete_timer->Start();
  50. }
  51. #ifdef WIN32
  52. vector<string>* LuaInterface::GetDirectoryListing(const char* directory) {
  53. vector<string>* ret = new vector<string>;
  54. WIN32_FIND_DATA fdata;
  55. HANDLE dhandle;
  56. char buf[MAX_PATH];
  57. snprintf(buf, sizeof(buf), "%s\\*", directory);
  58. if((dhandle = FindFirstFile(buf, &fdata)) == INVALID_HANDLE_VALUE) {
  59. safe_delete(ret);
  60. return 0;
  61. }
  62. ret->push_back(string(fdata.cFileName));
  63. while(1) {
  64. if(FindNextFile(dhandle, &fdata)) {
  65. ret->push_back(string(fdata.cFileName));
  66. }
  67. else{
  68. if(GetLastError() == ERROR_NO_MORE_FILES) {
  69. break;
  70. } else {
  71. safe_delete(ret);
  72. FindClose(dhandle);
  73. return 0;
  74. }
  75. }
  76. }
  77. if(FindClose(dhandle) == 0) {
  78. safe_delete(ret);
  79. return 0;
  80. }
  81. return ret;
  82. }
  83. #else
  84. vector<string>* LuaInterface::GetDirectoryListing(const char* directory) {
  85. vector<string>* ret = new vector<string>;
  86. DIR *dp;
  87. struct dirent *ep;
  88. dp = opendir (directory);
  89. if (dp != NULL){
  90. while ((ep = readdir (dp)))
  91. ret->push_back(string(ep->d_name));
  92. (void) closedir (dp);
  93. }
  94. else {
  95. safe_delete(ret);
  96. return 0;
  97. }
  98. return ret;
  99. }
  100. #endif
  101. LuaInterface::~LuaInterface() {
  102. shutting_down = true;
  103. MLUAMain.lock();
  104. DestroySpells();
  105. DestroySpawnScripts();
  106. DestroyQuests();
  107. DestroyItemScripts();
  108. DestroyZoneScripts();
  109. DestroyRegionScripts();
  110. DeleteUserDataPtrs(true);
  111. DeletePendingSpells(true);
  112. safe_delete(user_data_timer);
  113. safe_delete(spell_delete_timer);
  114. MLUAMain.unlock();
  115. }
  116. int LuaInterface::GetNumberOfArgs(lua_State* state) {
  117. return lua_gettop(state);
  118. }
  119. void LuaInterface::Process() {
  120. if(shutting_down)
  121. return;
  122. MLUAMain.lock();
  123. if(user_data_timer && user_data_timer->Check())
  124. DeleteUserDataPtrs(false);
  125. if(spell_delete_timer && spell_delete_timer->Check())
  126. DeletePendingSpells(false);
  127. MLUAMain.unlock();
  128. }
  129. void LuaInterface::DestroySpells() {
  130. map<string, LuaSpell*>::iterator itr;
  131. MSpells.lock();
  132. for(itr = spells.begin(); itr != spells.end(); itr++){
  133. MSpellDelete.lock();
  134. RemoveCurrentSpell(itr->second->state, false);
  135. MSpellDelete.unlock();
  136. lua_close(itr->second->state);
  137. safe_delete(itr->second);
  138. }
  139. spells.clear();
  140. MSpells.unlock();
  141. }
  142. void LuaInterface::DestroyQuests(bool reload) {
  143. map<int32, lua_State*>::iterator itr;
  144. MQuests.lock();
  145. for(itr = quest_states.begin(); itr != quest_states.end(); itr++){
  146. safe_delete(quests[itr->first]);
  147. lua_close(itr->second);
  148. }
  149. quests.clear();
  150. quest_states.clear();
  151. map<int32, Mutex*>::iterator mutex_itr;
  152. for(mutex_itr = quests_mutex.begin(); mutex_itr != quests_mutex.end(); mutex_itr++){
  153. safe_delete(mutex_itr->second);
  154. }
  155. quests_mutex.clear();
  156. if(reload)
  157. database.LoadQuests();
  158. MQuests.unlock();
  159. }
  160. void LuaInterface::DestroyItemScripts() {
  161. map<string, map<lua_State*, bool> >::iterator itr;
  162. map<lua_State*, bool>::iterator state_itr;
  163. Mutex* mutex = 0;
  164. MItemScripts.writelock(__FUNCTION__, __LINE__);
  165. for(itr = item_scripts.begin(); itr != item_scripts.end(); itr++){
  166. mutex = GetItemScriptMutex(itr->first.c_str());
  167. mutex->writelock(__FUNCTION__, __LINE__);
  168. for(state_itr = itr->second.begin(); state_itr != itr->second.end(); state_itr++)
  169. lua_close(state_itr->first);
  170. mutex->releasewritelock(__FUNCTION__, __LINE__);
  171. safe_delete(mutex);
  172. }
  173. item_scripts.clear();
  174. item_inverse_scripts.clear();
  175. item_scripts_mutex.clear();
  176. MItemScripts.releasewritelock(__FUNCTION__, __LINE__);
  177. }
  178. void LuaInterface::DestroySpawnScripts() {
  179. map<string, map<lua_State*, bool> >::iterator itr;
  180. map<lua_State*, bool>::iterator state_itr;
  181. Mutex* mutex = 0;
  182. MSpawnScripts.writelock(__FUNCTION__, __LINE__);
  183. for(itr = spawn_scripts.begin(); itr != spawn_scripts.end(); itr++){
  184. mutex = GetSpawnScriptMutex(itr->first.c_str());
  185. mutex->writelock(__FUNCTION__, __LINE__);
  186. for(state_itr = itr->second.begin(); state_itr != itr->second.end(); state_itr++)
  187. lua_close(state_itr->first);
  188. mutex->releasewritelock(__FUNCTION__, __LINE__);
  189. safe_delete(mutex);
  190. }
  191. spawn_scripts.clear();
  192. spawn_inverse_scripts.clear();
  193. spawn_scripts_mutex.clear();
  194. MSpawnScripts.releasewritelock(__FUNCTION__, __LINE__);
  195. }
  196. void LuaInterface::DestroyZoneScripts() {
  197. map<string, map<lua_State*, bool> >::iterator itr;
  198. map<lua_State*, bool>::iterator state_itr;
  199. Mutex* mutex = 0;
  200. MZoneScripts.writelock(__FUNCTION__, __LINE__);
  201. for (itr = zone_scripts.begin(); itr != zone_scripts.end(); itr++){
  202. mutex = GetZoneScriptMutex(itr->first.c_str());
  203. mutex->writelock(__FUNCTION__, __LINE__);
  204. for(state_itr = itr->second.begin(); state_itr != itr->second.end(); state_itr++)
  205. lua_close(state_itr->first);
  206. mutex->releasewritelock(__FUNCTION__, __LINE__);
  207. safe_delete(mutex);
  208. }
  209. zone_scripts.clear();
  210. zone_inverse_scripts.clear();
  211. zone_scripts_mutex.clear();
  212. MZoneScripts.releasewritelock(__FUNCTION__, __LINE__);
  213. }
  214. void LuaInterface::DestroyRegionScripts() {
  215. map<string, map<lua_State*, bool> >::iterator itr;
  216. map<lua_State*, bool>::iterator state_itr;
  217. Mutex* mutex = 0;
  218. MRegionScripts.writelock(__FUNCTION__, __LINE__);
  219. for (itr = region_scripts.begin(); itr != region_scripts.end(); itr++){
  220. mutex = GetRegionScriptMutex(itr->first.c_str());
  221. mutex->writelock(__FUNCTION__, __LINE__);
  222. for(state_itr = itr->second.begin(); state_itr != itr->second.end(); state_itr++)
  223. lua_close(state_itr->first);
  224. mutex->releasewritelock(__FUNCTION__, __LINE__);
  225. safe_delete(mutex);
  226. }
  227. region_scripts.clear();
  228. region_inverse_scripts.clear();
  229. region_scripts_mutex.clear();
  230. MRegionScripts.releasewritelock(__FUNCTION__, __LINE__);
  231. }
  232. void LuaInterface::ReloadSpells() {
  233. DestroySpells();
  234. database.LoadSpellScriptData();
  235. }
  236. bool LuaInterface::LoadLuaSpell(const char* name) {
  237. LuaSpell* spell = 0;
  238. string lua_script = string(name);
  239. if (lua_script.find(".lua") == string::npos)
  240. lua_script.append(".lua");
  241. lua_State* state = LoadLuaFile(lua_script.c_str());
  242. if(state){
  243. spell = new LuaSpell;
  244. spell->file_name = lua_script;
  245. spell->state = state;
  246. spell->spell = 0;
  247. spell->caster = 0;
  248. spell->initial_target = 0;
  249. spell->resisted = false;
  250. spell->has_damaged = false;
  251. spell->is_damage_spell = false;
  252. spell->interrupted = false;
  253. spell->last_spellattack_hit = false;
  254. spell->crit = false;
  255. spell->MSpellTargets.SetName("LuaSpell.MSpellTargets");
  256. spell->cancel_after_all_triggers = false;
  257. spell->num_triggers = 0;
  258. spell->num_calls = 0;
  259. spell->is_recast_timer = false;
  260. spell->had_triggers = false;
  261. spell->had_dmg_remaining = false;
  262. spell->slot_pos = 0;
  263. spell->damage_remaining = 0;
  264. spell->effect_bitmask = 0;
  265. spell->restored = false;
  266. spell->initial_caster_char_id = 0;
  267. spell->initial_target_char_id = 0;
  268. MSpells.lock();
  269. if (spells.count(lua_script) > 0) {
  270. SetLuaUserDataStale(spells[lua_script]);
  271. MSpellDelete.lock();
  272. RemoveCurrentSpell(spells[lua_script]->state, false);
  273. MSpellDelete.unlock();
  274. lua_close(spells[lua_script]->state);
  275. safe_delete(spells[lua_script]);
  276. }
  277. spells[lua_script] = spell;
  278. MSpells.unlock();
  279. return true;
  280. }
  281. return false;
  282. }
  283. bool LuaInterface::LoadLuaSpell(string name) {
  284. return LoadLuaSpell(name.c_str());
  285. }
  286. bool LuaInterface::LoadItemScript(string name) {
  287. return LoadItemScript(name.c_str());
  288. }
  289. bool LuaInterface::LoadItemScript(const char* name) {
  290. bool ret = false;
  291. if(name){
  292. lua_State* state = LoadLuaFile(name);
  293. if(state){
  294. MItemScripts.writelock(__FUNCTION__, __LINE__);
  295. item_scripts[name][state] = false;
  296. MItemScripts.releasewritelock(__FUNCTION__, __LINE__);
  297. ret = true;
  298. }
  299. }
  300. return ret;
  301. }
  302. bool LuaInterface::LoadSpawnScript(const char* name) {
  303. bool ret = false;
  304. if(name){
  305. lua_State* state = LoadLuaFile(name);
  306. if(state){
  307. MSpawnScripts.writelock(__FUNCTION__, __LINE__);
  308. spawn_scripts[name][state] = false;
  309. MSpawnScripts.releasewritelock(__FUNCTION__, __LINE__);
  310. ret = true;
  311. }
  312. }
  313. return ret;
  314. }
  315. bool LuaInterface::LoadZoneScript(const char* name) {
  316. bool ret = false;
  317. if (name) {
  318. lua_State* state = LoadLuaFile(name);
  319. if (state) {
  320. MZoneScripts.writelock(__FUNCTION__, __LINE__);
  321. zone_scripts[name][state] = false;
  322. MZoneScripts.releasewritelock(__FUNCTION__, __LINE__);
  323. ret = true;
  324. }
  325. }
  326. return ret;
  327. }
  328. bool LuaInterface::LoadRegionScript(const char* name) {
  329. bool ret = false;
  330. if (name) {
  331. lua_State* state = LoadLuaFile(name);
  332. if (state) {
  333. MRegionScripts.writelock(__FUNCTION__, __LINE__);
  334. region_scripts[name][state] = false;
  335. MRegionScripts.releasewritelock(__FUNCTION__, __LINE__);
  336. ret = true;
  337. }
  338. }
  339. return ret;
  340. }
  341. void LuaInterface::ProcessErrorMessage(const char* message) {
  342. MDebugClients.lock();
  343. vector<Client*> delete_clients;
  344. map<Client*, int32>::iterator itr;
  345. for(itr = debug_clients.begin(); itr != debug_clients.end(); itr++){
  346. if((Timer::GetCurrentTime2() - itr->second) > 60000)
  347. delete_clients.push_back(itr->first);
  348. else
  349. itr->first->Message(CHANNEL_COLOR_RED, "LUA Error: %s", message);
  350. }
  351. for(int32 i=0;i<delete_clients.size();i++)
  352. debug_clients.erase(delete_clients[i]);
  353. MDebugClients.unlock();
  354. }
  355. void LuaInterface::RemoveDebugClients(Client* client) {
  356. MDebugClients.lock();
  357. debug_clients.erase(client);
  358. MDebugClients.unlock();
  359. }
  360. void LuaInterface::UpdateDebugClients(Client* client) {
  361. MDebugClients.lock();
  362. debug_clients[client] = Timer::GetCurrentTime2();
  363. MDebugClients.unlock();
  364. }
  365. Mutex* LuaInterface::GetQuestMutex(Quest* quest) {
  366. Mutex* ret = 0;
  367. MQuests.lock();
  368. if(quests_mutex.count(quest->GetQuestID()) == 0){
  369. ret = new Mutex();
  370. quests_mutex[quest->GetQuestID()] = ret;
  371. ret->SetName(string("Quest::").append(quest->GetName()));
  372. }
  373. else
  374. ret = quests_mutex[quest->GetQuestID()];
  375. MQuests.unlock();
  376. return ret;
  377. }
  378. bool LuaInterface::CallQuestFunction(Quest* quest, const char* function, Spawn* player, int32 step_id, int32* returnValue) {
  379. if(shutting_down)
  380. return false;
  381. lua_State* state = 0;
  382. if(quest){
  383. LogWrite(LUA__DEBUG, 0, "LUA", "Quest: %s, function: %s", quest->GetName(), function);
  384. Mutex* mutex = GetQuestMutex(quest);
  385. mutex->readlock(__FUNCTION__, __LINE__);
  386. if(quest_states.count(quest->GetQuestID()) > 0)
  387. state = quest_states[quest->GetQuestID()];
  388. bool success = false; // if no state then we return false
  389. if(state){
  390. int8 arg_count = 3;
  391. lua_getglobal(state, function);
  392. if (!lua_isfunction(state, lua_gettop(state))){
  393. lua_pop(state, 1);
  394. mutex->releasereadlock(__FUNCTION__);
  395. return false;
  396. }
  397. SetQuestValue(state, quest);
  398. Spawn* spawn = player->GetZone()->GetSpawnByDatabaseID(quest->GetQuestGiver());
  399. SetSpawnValue(state, spawn);
  400. SetSpawnValue(state, player);
  401. if(step_id != 0xFFFFFFFF){
  402. SetInt32Value(state, step_id);
  403. arg_count++;
  404. }
  405. success = CallScriptInt32(state, arg_count, returnValue);
  406. }
  407. mutex->releasereadlock(__FUNCTION__, __LINE__);
  408. LogWrite(LUA__DEBUG, 0, "LUA", "Done!");
  409. return success;
  410. }
  411. return false;
  412. }
  413. Quest* LuaInterface::LoadQuest(int32 id, const char* name, const char* type, const char* zone, int8 level, const char* description, char* script_name) {
  414. if(shutting_down)
  415. return 0;
  416. lua_State* state = LoadLuaFile(script_name);
  417. Quest* quest = 0;
  418. if(state){
  419. quest = new Quest(id);
  420. if (name)
  421. quest->SetName(string(name));
  422. if (type)
  423. quest->SetType(string(type));
  424. if (zone)
  425. quest->SetZone(string(zone));
  426. quest->SetLevel(level);
  427. if (description)
  428. quest->SetDescription(string(description));
  429. lua_getglobal(state, "Init");
  430. SetQuestValue(state, quest);
  431. if(lua_pcall(state, 1, 0, 0) != 0){
  432. LogError("Error processing Quest \"%s\" (%u): %s", name ? name : "unknown", id, lua_tostring(state, -1));
  433. lua_pop(state, 1);
  434. SetLuaUserDataStale(quest);
  435. safe_delete(quest);
  436. return 0;
  437. }
  438. if(!quest->GetName()){
  439. SetLuaUserDataStale(quest);
  440. safe_delete(quest);
  441. return 0;
  442. }
  443. quest_states[id] = state;
  444. quests[id] = quest;
  445. }
  446. return quest;
  447. }
  448. const char* LuaInterface::GetScriptName(lua_State* state)
  449. {
  450. map<lua_State*, string>::iterator itr;
  451. MItemScripts.writelock(__FUNCTION__, __LINE__);
  452. itr = item_inverse_scripts.find(state);
  453. if (itr != item_inverse_scripts.end())
  454. {
  455. const char* scriptName = itr->second.c_str();
  456. MItemScripts.releasewritelock(__FUNCTION__, __LINE__);
  457. return scriptName;
  458. }
  459. MItemScripts.releasewritelock(__FUNCTION__, __LINE__);
  460. MSpawnScripts.writelock(__FUNCTION__, __LINE__);
  461. itr = spawn_inverse_scripts.find(state);
  462. if (itr != spawn_inverse_scripts.end())
  463. {
  464. const char* scriptName = itr->second.c_str();
  465. MSpawnScripts.releasewritelock(__FUNCTION__, __LINE__);
  466. return scriptName;
  467. }
  468. MSpawnScripts.releasewritelock(__FUNCTION__, __LINE__);
  469. MZoneScripts.writelock(__FUNCTION__, __LINE__);
  470. itr = zone_inverse_scripts.find(state);
  471. if (itr != zone_inverse_scripts.end())
  472. {
  473. const char* scriptName = itr->second.c_str();
  474. MZoneScripts.releasewritelock(__FUNCTION__, __LINE__);
  475. return scriptName;
  476. }
  477. MZoneScripts.releasewritelock(__FUNCTION__, __LINE__);
  478. MRegionScripts.writelock(__FUNCTION__, __LINE__);
  479. itr = region_inverse_scripts.find(state);
  480. if (itr != region_inverse_scripts.end())
  481. {
  482. const char* scriptName = itr->second.c_str();
  483. MRegionScripts.releasewritelock(__FUNCTION__, __LINE__);
  484. return scriptName;
  485. }
  486. MRegionScripts.releasewritelock(__FUNCTION__, __LINE__);
  487. MSpells.lock();
  488. LuaSpell* spell = GetCurrentSpell(state, false);
  489. if (spell)
  490. {
  491. const char* fileName = (spell->file_name.length() > 0) ? spell->file_name.c_str() : "";
  492. MSpells.unlock();
  493. return fileName;
  494. }
  495. MSpells.unlock();
  496. return "";
  497. }
  498. bool LuaInterface::LoadSpawnScript(string name) {
  499. return LoadSpawnScript(name.c_str());
  500. }
  501. bool LuaInterface::LoadZoneScript(string name) {
  502. return LoadZoneScript(name.c_str());
  503. }
  504. bool LuaInterface::LoadRegionScript(string name) {
  505. return LoadRegionScript(name.c_str());
  506. }
  507. std::string LuaInterface::AddSpawnPointers(LuaSpell* spell, bool first_cast, bool precast, const char* function, SpellScriptTimer* timer, bool passLuaSpell, Spawn* altTarget) {
  508. std::string functionCalled = string("");
  509. if (function)
  510. {
  511. functionCalled = string(function);
  512. lua_getglobal(spell->state, function);
  513. }
  514. else if (precast)
  515. {
  516. functionCalled = "precast";
  517. lua_getglobal(spell->state, "precast");
  518. }
  519. else if(first_cast)
  520. {
  521. functionCalled = "cast";
  522. lua_getglobal(spell->state, "cast");
  523. }
  524. else
  525. {
  526. functionCalled = "tick";
  527. lua_getglobal(spell->state, "tick");
  528. }
  529. LogWrite(SPELL__DEBUG, 0, "Spell", "LuaInterface::AddSpawnPointers spell %s (%u) function %s, caster %s.", spell->spell ? spell->spell->GetName() : "UnknownUnset", spell->spell ? spell->spell->GetSpellID() : 0, functionCalled.c_str(), spell->caster ? spell->caster->GetName() : "Unknown");
  530. if (!lua_isfunction(spell->state, lua_gettop(spell->state))){
  531. lua_pop(spell->state, 1);
  532. return string("");
  533. }
  534. else {
  535. lua_getglobal(spell->state, functionCalled.c_str());
  536. }
  537. if(passLuaSpell)
  538. SetSpellValue(spell->state, spell);
  539. Spawn* temp_spawn = 0;
  540. if (timer && timer->caster && spell->caster && spell->caster->GetZone())
  541. temp_spawn = spell->caster->GetZone()->GetSpawnByID(timer->caster);
  542. if (temp_spawn)
  543. SetSpawnValue(spell->state, temp_spawn);
  544. else if (spell->caster)
  545. SetSpawnValue(spell->state, spell->caster);
  546. temp_spawn = 0;
  547. if (timer && timer->target && spell->caster && spell->caster->GetZone())
  548. temp_spawn = spell->caster->GetZone()->GetSpawnByID(timer->target);
  549. if (temp_spawn)
  550. SetSpawnValue(spell->state, temp_spawn);
  551. else {
  552. if(altTarget)
  553. {
  554. SetSpawnValue(spell->state, altTarget);
  555. }
  556. else if(spell->caster && spell->caster->GetZone() != nullptr && spell->initial_target)
  557. {
  558. // easier to debug target id as ptr
  559. Spawn* new_target = spell->caster->GetZone()->GetSpawnByID(spell->initial_target);
  560. SetSpawnValue(spell->state, new_target);
  561. }
  562. else if(spell->caster && spell->caster->GetTarget())
  563. SetSpawnValue(spell->state, spell->caster->GetTarget());
  564. else
  565. SetSpawnValue(spell->state, 0);
  566. }
  567. return functionCalled;
  568. }
  569. LuaSpell* LuaInterface::GetCurrentSpell(lua_State* state, bool needsLock) {
  570. LuaSpell* spell = 0;
  571. if(needsLock)
  572. MSpells.lock();
  573. if(current_spells.count(state) > 0)
  574. spell = current_spells[state];
  575. if(needsLock)
  576. MSpells.unlock();
  577. return spell;
  578. }
  579. void LuaInterface::RemoveCurrentSpell(lua_State* state, bool needsLock) {
  580. if(needsLock) {
  581. MSpells.lock();
  582. MSpellDelete.lock();
  583. }
  584. map<lua_State*, LuaSpell*>::iterator itr = current_spells.find(state);
  585. if(itr != current_spells.end())
  586. current_spells.erase(itr);
  587. if(needsLock) {
  588. MSpellDelete.unlock();
  589. MSpells.unlock();
  590. }
  591. }
  592. bool LuaInterface::CallSpellProcess(LuaSpell* spell, int8 num_parameters, std::string customFunction) {
  593. if(shutting_down || !spell || !spell->caster)
  594. return false;
  595. MSpells.lock();
  596. current_spells[spell->state] = spell;
  597. MSpells.unlock();
  598. LogWrite(SPELL__DEBUG, 0, "Spell", "LuaInterface::CallSpellProcess spell %s (%u) function %s, caster %s.", spell->spell ? spell->spell->GetName() : "UnknownUnset", spell->spell ? spell->spell->GetSpellID() : 0, customFunction.c_str(), spell->caster->GetName());
  599. if(lua_pcall(spell->state, num_parameters, 0, 0) != 0){
  600. LogError("Error running function '%s' in %s: %s", customFunction.c_str(), spell->spell->GetName(), lua_tostring(spell->state, -1));
  601. lua_pop(spell->state, 1);
  602. RemoveSpell(spell, false); // may be in a lock
  603. return false;
  604. }
  605. return true;
  606. }
  607. void LuaInterface::RemoveSpawnScript(const char* name) {
  608. lua_State* state = 0;
  609. Mutex* mutex = GetSpawnScriptMutex(name);
  610. while((state = GetSpawnScript(name, false))){
  611. mutex->writelock(__FUNCTION__, __LINE__);
  612. lua_close(state);
  613. spawn_scripts[name].erase(state);
  614. mutex->releasewritelock(__FUNCTION__, __LINE__);
  615. }
  616. MSpawnScripts.writelock(__FUNCTION__, __LINE__);
  617. spawn_scripts.erase(name);
  618. MSpawnScripts.releasewritelock(__FUNCTION__, __LINE__);
  619. }
  620. bool LuaInterface::CallItemScript(lua_State* state, int8 num_parameters, std::string* returnValue) {
  621. if(shutting_down)
  622. return false;
  623. if(!state || lua_pcall(state, num_parameters, 1, 0) != 0){
  624. if (state){
  625. const char* err = lua_tostring(state, -1);
  626. LogError("%s: %s", GetScriptName(state), err);
  627. lua_pop(state, 1);
  628. }
  629. return false;
  630. }
  631. std::string result = std::string("");
  632. if(lua_isstring(state, -1)){
  633. size_t size = 0;
  634. const char* str = lua_tolstring(state, -1, &size);
  635. if(str)
  636. result = string(str);
  637. }
  638. if(returnValue)
  639. *returnValue = std::string(result);
  640. return true;
  641. }
  642. bool LuaInterface::CallItemScript(lua_State* state, int8 num_parameters, sint64* returnValue) {
  643. if(shutting_down)
  644. return false;
  645. if(!state || lua_pcall(state, num_parameters, 1, 0) != 0){
  646. if (state){
  647. const char* err = lua_tostring(state, -1);
  648. LogError("%s: %s", GetScriptName(state), err);
  649. lua_pop(state, 1);
  650. }
  651. return false;
  652. }
  653. sint64 result = 0;
  654. if (lua_isnumber(state, -1))
  655. {
  656. result = (sint64)lua_tonumber(state, -1);
  657. lua_pop(state, 1);
  658. }
  659. if(returnValue)
  660. *returnValue = result;
  661. return true;
  662. }
  663. bool LuaInterface::CallSpawnScript(lua_State* state, int8 num_parameters) {
  664. if(shutting_down || lua_system_reloading)
  665. return false;
  666. if(!state || lua_pcall(state, num_parameters, 0, 0) != 0){
  667. if (state){
  668. const char* err = lua_tostring(state, -1);
  669. LogError("%s: %s", GetScriptName(state), err);
  670. lua_pop(state, 1);
  671. }
  672. return false;
  673. }
  674. return true;
  675. }
  676. bool LuaInterface::CallScriptInt32(lua_State* state, int8 num_parameters, int32* returnValue) {
  677. if(shutting_down)
  678. return false;
  679. if (!state || lua_pcall(state, num_parameters, 1, 0) != 0) {
  680. if (state){
  681. const char* err = lua_tostring(state, -1);
  682. LogError("%s: %s", GetScriptName(state), err);
  683. lua_pop(state, 1);
  684. }
  685. return false;
  686. }
  687. int32 result = 0;
  688. if (lua_isnumber(state, -1))
  689. {
  690. result = (int32)lua_tonumber(state, -1);
  691. lua_pop(state, 1);
  692. }
  693. if(returnValue)
  694. *returnValue = result;
  695. return true;
  696. }
  697. bool LuaInterface::CallScriptSInt32(lua_State* state, int8 num_parameters, sint32* returnValue) {
  698. if(shutting_down)
  699. return false;
  700. if (!state || lua_pcall(state, num_parameters, 1, 0) != 0) {
  701. if (state){
  702. const char* err = lua_tostring(state, -1);
  703. LogError("%s: %s", GetScriptName(state), err);
  704. lua_pop(state, 1);
  705. }
  706. return false;
  707. }
  708. sint32 result = 0;
  709. if (lua_isnumber(state, -1))
  710. {
  711. result = (sint32)lua_tointeger(state, -1);
  712. lua_pop(state, 1);
  713. }
  714. if(returnValue)
  715. *returnValue = result;
  716. return true;
  717. }
  718. bool LuaInterface::CallRegionScript(lua_State* state, int8 num_parameters, int32* returnValue) {
  719. if(shutting_down)
  720. return false;
  721. if (!state || lua_pcall(state, num_parameters, 1, 0) != 0) {
  722. if (state){
  723. const char* err = lua_tostring(state, -1);
  724. LogError("%s: %s", GetScriptName(state), err);
  725. lua_pop(state, 1);
  726. }
  727. return false;
  728. }
  729. int32 result = 0;
  730. if (lua_isnumber(state, -1))
  731. {
  732. result = (int32)lua_tonumber(state, -1);
  733. lua_pop(state, 1);
  734. }
  735. if(returnValue)
  736. *returnValue = result;
  737. return true;
  738. }
  739. lua_State* LuaInterface::LoadLuaFile(const char* name) {
  740. if(shutting_down)
  741. return 0;
  742. lua_State* state = luaL_newstate();
  743. luaL_openlibs(state);
  744. if(luaL_dofile(state, name) == 0){
  745. RegisterFunctions(state);
  746. return state;
  747. }
  748. else{
  749. LogError("Error loading %s (file name: '%s')", lua_tostring(state, -1), name);
  750. lua_pop(state, 1);
  751. lua_close(state);
  752. }
  753. return 0;
  754. }
  755. void LuaInterface::RemoveSpell(LuaSpell* spell, bool call_remove_function, bool can_delete, string reason, bool removing_all_spells) {
  756. if(call_remove_function){
  757. lua_getglobal(spell->state, "remove");
  758. LUASpawnWrapper* spawn_wrapper = new LUASpawnWrapper();
  759. spawn_wrapper->spawn = spell->caster;
  760. AddUserDataPtr(spawn_wrapper, spawn_wrapper->spawn);
  761. lua_pushlightuserdata(spell->state, spawn_wrapper);
  762. if(spell->caster && (spell->initial_target || spell->caster->GetTarget())){
  763. spawn_wrapper = new LUASpawnWrapper();
  764. if(!spell->initial_target)
  765. spawn_wrapper->spawn = spell->caster->GetTarget();
  766. else if(spell->caster->GetZone()) {
  767. spawn_wrapper->spawn = spell->caster->GetZone()->GetSpawnByID(spell->initial_target);
  768. }
  769. else {
  770. spawn_wrapper->spawn = nullptr; // we need it set to something or else the ptr could be loose
  771. }
  772. AddUserDataPtr(spawn_wrapper, spawn_wrapper->spawn);
  773. lua_pushlightuserdata(spell->state, spawn_wrapper);
  774. }
  775. else
  776. lua_pushlightuserdata(spell->state, 0);
  777. if (spell->caster && !spell->caster->Alive())
  778. reason = "dead";
  779. lua_pushstring(spell->state, (char*)reason.c_str());
  780. MSpells.lock();
  781. current_spells[spell->state] = spell;
  782. MSpells.unlock();
  783. lua_pcall(spell->state, 3, 0, 0);
  784. ResetFunctionStack(spell->state);
  785. }
  786. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  787. if(spell->caster) {
  788. for (int8 i = 0; i < spell->targets.size(); i++) {
  789. if(!spell->caster->GetZone())
  790. continue;
  791. Spawn* target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  792. if (!target || !target->IsEntity())
  793. continue;
  794. ((Entity*)target)->RemoveProc(0, spell);
  795. ((Entity*)target)->RemoveSpellEffect(spell);
  796. ((Entity*)target)->RemoveSpellBonus(spell);
  797. }
  798. }
  799. multimap<int32,int8>::iterator entries;
  800. for(entries = spell->char_id_targets.begin(); entries != spell->char_id_targets.end(); entries++)
  801. {
  802. Client* tmpClient = zone_list.GetClientByCharID(entries->first);
  803. if(tmpClient && tmpClient->GetPlayer())
  804. {
  805. tmpClient->GetPlayer()->RemoveProc(0, spell);
  806. tmpClient->GetPlayer()->RemoveSpellEffect(spell);
  807. tmpClient->GetPlayer()->RemoveSpellBonus(spell);
  808. }
  809. }
  810. spell->char_id_targets.clear(); // TODO: reach out to those clients in different
  811. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  812. if(removing_all_spells) {
  813. if(spell->caster && spell->caster->GetZone()) {
  814. spell->caster->GetZone()->GetSpellProcess()->RemoveSpellScriptTimerBySpell(spell);
  815. spell->caster->GetZone()->GetSpellProcess()->DeleteSpell(spell);
  816. }
  817. }
  818. else {
  819. AddPendingSpellDelete(spell);
  820. if (spell->caster)
  821. {
  822. if(spell->caster->GetZone()) {
  823. spell->caster->GetZone()->GetSpellProcess()->RemoveSpellScriptTimerBySpell(spell);
  824. }
  825. spell->caster->RemoveProc(0, spell);
  826. spell->caster->RemoveMaintainedSpell(spell);
  827. int8 spell_type = spell->spell->GetSpellData()->spell_type;
  828. if(spell->caster->IsPlayer() && !removing_all_spells)
  829. {
  830. Player* player = (Player*)spell->caster;
  831. switch(spell_type)
  832. {
  833. case SPELL_TYPE_FOOD:
  834. if(player->get_character_flag(CF_FOOD_AUTO_CONSUME) && player->GetClient())
  835. {
  836. Item* item = nullptr;
  837. if(player->GetActiveFoodUniqueID()) {
  838. item = player->item_list.GetItemFromUniqueID(player->GetActiveFoodUniqueID());
  839. }
  840. if(item == nullptr) {
  841. item = player->GetEquipmentList()->GetItem(EQ2_FOOD_SLOT);
  842. }
  843. if(item && player->GetClient()->CheckConsumptionAllowed(EQ2_FOOD_SLOT, false))
  844. player->GetClient()->ConsumeFoodDrink(item, EQ2_FOOD_SLOT);
  845. }
  846. break;
  847. case SPELL_TYPE_DRINK:
  848. if(player->get_character_flag(CF_DRINK_AUTO_CONSUME) && player->GetClient())
  849. {
  850. Item* item = nullptr;
  851. if(player->GetActiveDrinkUniqueID()) {
  852. item = player->item_list.GetItemFromUniqueID(player->GetActiveDrinkUniqueID());
  853. }
  854. if(item == nullptr) {
  855. item = player->GetEquipmentList()->GetItem(EQ2_FOOD_SLOT);
  856. }
  857. item = player->GetEquipmentList()->GetItem(EQ2_DRINK_SLOT);
  858. if(item && player->GetClient()->CheckConsumptionAllowed(EQ2_DRINK_SLOT, false))
  859. player->GetClient()->ConsumeFoodDrink(item, EQ2_DRINK_SLOT);
  860. }
  861. break;
  862. }
  863. }
  864. }
  865. }
  866. }
  867. void LuaInterface::RegisterFunctions(lua_State* state) {
  868. lua_register(state, "SetHP", EQ2Emu_lua_SetCurrentHP);
  869. lua_register(state, "SetMaxHP", EQ2Emu_lua_SetMaxHP);
  870. lua_register(state, "SetMaxHPBase", EQ2Emu_lua_SetMaxHPBase);
  871. lua_register(state, "SetPower", EQ2Emu_lua_SetCurrentPower);
  872. lua_register(state, "SetMaxPower", EQ2Emu_lua_SetMaxPower);
  873. lua_register(state, "SetMaxPowerBase", EQ2Emu_lua_SetMaxPowerBase);
  874. lua_register(state, "ModifyMaxHP", EQ2Emu_lua_ModifyMaxHP);
  875. lua_register(state, "ModifyMaxPower", EQ2Emu_lua_ModifyMaxPower);
  876. lua_register(state, "SetPosition", EQ2Emu_lua_SetPosition);
  877. lua_register(state, "SetHeading", EQ2Emu_lua_SetHeading);
  878. lua_register(state, "SetModelType", EQ2Emu_lua_SetModelType);
  879. lua_register(state, "SetAdventureClass", EQ2Emu_lua_SetAdventureClass);
  880. lua_register(state, "SetTradeskillClass", EQ2Emu_lua_SetTradeskillClass);
  881. lua_register(state, "SetMount", EQ2Emu_lua_SetMount);
  882. lua_register(state, "SetMountColor", EQ2Emu_lua_SetMountColor);
  883. lua_register(state, "GetMount", EQ2Emu_lua_GetMount);
  884. lua_register(state, "GetRace", EQ2Emu_lua_GetRace);
  885. lua_register(state, "GetRaceName", EQ2Emu_lua_GetRaceName);
  886. lua_register(state, "GetClass", EQ2Emu_lua_GetClass);
  887. lua_register(state, "GetClassName", EQ2Emu_lua_GetClassName);
  888. lua_register(state, "GetArchetypeName", EQ2Emu_lua_GetArchetypeName);
  889. lua_register(state, "SetSpeed", EQ2Emu_lua_SetSpeed);
  890. lua_register(state, "ModifyPower", EQ2Emu_lua_ModifyPower);
  891. lua_register(state, "ModifyHP", EQ2Emu_lua_ModifyHP);
  892. lua_register(state, "GetDistance", EQ2Emu_lua_GetDistance);
  893. lua_register(state, "GetHeading", EQ2Emu_lua_GetHeading);
  894. lua_register(state, "GetLevel", EQ2Emu_lua_GetLevel);
  895. lua_register(state, "GetDifficulty", EQ2Emu_lua_GetDifficulty);
  896. lua_register(state, "GetHP", EQ2Emu_lua_GetCurrentHP);
  897. lua_register(state, "GetMaxHP", EQ2Emu_lua_GetMaxHP);
  898. lua_register(state, "GetMaxHPBase", EQ2Emu_lua_GetMaxHPBase);
  899. lua_register(state, "GetMaxPower", EQ2Emu_lua_GetMaxPower);
  900. lua_register(state, "GetMaxPowerBase", EQ2Emu_lua_GetMaxPowerBase);
  901. lua_register(state, "GetName", EQ2Emu_lua_GetName);
  902. lua_register(state, "GetPower", EQ2Emu_lua_GetCurrentPower);
  903. lua_register(state, "GetX", EQ2Emu_lua_GetX);
  904. lua_register(state, "GetY", EQ2Emu_lua_GetY);
  905. lua_register(state, "GetZ", EQ2Emu_lua_GetZ);
  906. lua_register(state, "GetSpawnID", EQ2Emu_lua_GetSpawnID);
  907. lua_register(state, "GetSpawnGroupID", EQ2Emu_lua_GetSpawnGroupID);
  908. lua_register(state, "SetSpawnGroupID", EQ2Emu_lua_SetSpawnGroupID);
  909. lua_register(state, "AddSpawnToGroup", EQ2Emu_lua_AddSpawnToGroup);
  910. lua_register(state, "GetSpawnLocationID", EQ2Emu_lua_GetSpawnLocationID);
  911. lua_register(state, "GetSpawnLocationPlacementID", EQ2Emu_lua_GetSpawnLocationPlacementID);
  912. lua_register(state, "GetSpawnListBySpawnID", EQ2Emu_lua_GetSpawnListBySpawnID);
  913. lua_register(state, "GetSpawnListByRailID", EQ2Emu_lua_GetSpawnListByRailID);
  914. lua_register(state, "GetPassengerSpawnList", EQ2Emu_lua_GetPassengerSpawnList);
  915. lua_register(state, "GetSpawnFromList", EQ2Emu_lua_GetSpawnFromList);
  916. lua_register(state, "GetSpawnListSize", EQ2Emu_lua_GetSpawnListSize);
  917. lua_register(state, "SetFactionID", EQ2Emu_lua_SetFactionID);
  918. lua_register(state, "GetFactionID", EQ2Emu_lua_GetFactionID);
  919. lua_register(state, "GetFactionAmount", EQ2Emu_lua_GetFactionAmount);
  920. lua_register(state, "ChangeFaction", EQ2Emu_lua_ChangeFaction);
  921. lua_register(state, "GetGender", EQ2Emu_lua_GetGender);
  922. lua_register(state, "GetTarget", EQ2Emu_lua_GetTarget);
  923. lua_register(state, "HasFreeSlot", EQ2Emu_lua_HasFreeSlot);
  924. lua_register(state, "HasItemEquipped", EQ2Emu_lua_HasItemEquipped);
  925. lua_register(state, "GetEquippedItemByID", EQ2Emu_lua_GetEquippedItemByID);
  926. lua_register(state, "SetEquippedItemByID", EQ2Emu_lua_SetEquippedItemByID);
  927. lua_register(state, "SetEquippedItem", EQ2Emu_lua_SetEquippedItem);
  928. lua_register(state, "UnequipSlot", EQ2Emu_lua_UnequipSlot);
  929. lua_register(state, "SetEquipment", EQ2Emu_lua_SetEquipment);
  930. lua_register(state, "GetEquippedItemBySlot", EQ2Emu_lua_GetEquippedItemBySlot);
  931. lua_register(state, "GetItemByID", EQ2Emu_lua_GetItemByID);
  932. lua_register(state, "GetItemType", EQ2Emu_lua_GetItemType);
  933. lua_register(state, "GetItemEffectType", EQ2Emu_lua_GetItemEffectType);
  934. lua_register(state, "GetSpellName", EQ2Emu_lua_GetSpellName);
  935. lua_register(state, "PerformCameraShake", EQ2Emu_lua_PerformCameraShake);
  936. lua_register(state, "GetModelType", EQ2Emu_lua_GetModelType);
  937. lua_register(state, "GetSpeed", EQ2Emu_lua_GetSpeed);
  938. lua_register(state, "HasMoved", EQ2Emu_lua_HasMoved);
  939. lua_register(state, "SpellDamage", EQ2Emu_lua_SpellDamage);
  940. lua_register(state, "SpellDamageExt", EQ2Emu_lua_SpellDamageExt);
  941. lua_register(state, "CastSpell", EQ2Emu_lua_CastSpell);
  942. lua_register(state, "SpellHeal", EQ2Emu_lua_SpellHeal);
  943. lua_register(state, "SpellHealPct", EQ2Emu_lua_SpellHealPct);
  944. lua_register(state, "AddItem", EQ2Emu_lua_AddItem);
  945. lua_register(state, "SummonItem", EQ2Emu_lua_SummonItem);
  946. lua_register(state, "RemoveItem", EQ2Emu_lua_RemoveItem);
  947. lua_register(state, "HasItem", EQ2Emu_lua_HasItem);
  948. lua_register(state, "SpawnMob", EQ2Emu_lua_Spawn);
  949. lua_register(state, "SummonPet", EQ2Emu_lua_SummonPet);
  950. lua_register(state, "AddSpawnAccess", EQ2Emu_lua_AddSpawnAccess);
  951. lua_register(state, "GetZone", EQ2Emu_lua_GetZone);
  952. lua_register(state, "GetZoneName", EQ2Emu_lua_GetZoneName);
  953. lua_register(state, "GetZoneID", EQ2Emu_lua_GetZoneID);
  954. lua_register(state, "Zone", EQ2Emu_lua_Zone);
  955. lua_register(state, "AddHate", EQ2Emu_lua_AddHate);
  956. lua_register(state, "IsAlive", EQ2Emu_lua_IsAlive);
  957. lua_register(state, "IsSpawnGroupAlive", EQ2Emu_lua_IsSpawnGroupAlive);
  958. lua_register(state, "IsInCombat", EQ2Emu_lua_IsInCombat);
  959. lua_register(state, "Attack", EQ2Emu_lua_Attack);
  960. lua_register(state, "ApplySpellVisual", EQ2Emu_lua_ApplySpellVisual);
  961. lua_register(state, "IsPlayer", EQ2Emu_lua_IsPlayer);
  962. lua_register(state, "GetCharacterID", EQ2Emu_lua_GetCharacterID);
  963. lua_register(state, "FaceTarget", EQ2Emu_lua_FaceTarget);
  964. lua_register(state, "MoveToLocation", EQ2Emu_lua_MoveToLocation);
  965. lua_register(state, "ClearRunningLocations", EQ2Emu_lua_ClearRunningLocations);
  966. lua_register(state, "Shout", EQ2Emu_lua_Shout);
  967. lua_register(state, "Say", EQ2Emu_lua_Say);
  968. lua_register(state, "SayOOC", EQ2Emu_lua_SayOOC);
  969. lua_register(state, "Emote", EQ2Emu_lua_Emote);
  970. lua_register(state, "MovementLoopAddLocation", EQ2Emu_lua_MovementLoopAdd); // do not remove this function, it is already heavily used by the content team
  971. lua_register(state, "MovementLoopAdd", EQ2Emu_lua_MovementLoopAdd);
  972. // lua_register(state, "GetCurrentZoneSafeLocation", EQ2Emu_lua_GetCurrentZoneSafeLocation); // This is already added below.
  973. lua_register(state, "AddTimer", EQ2Emu_lua_AddTimer);
  974. lua_register(state, "StopTimer", EQ2Emu_lua_StopTimer);
  975. lua_register(state, "Harvest", EQ2Emu_lua_Harvest);
  976. lua_register(state, "SetAttackable", EQ2Emu_lua_SetAttackable);
  977. lua_register(state, "AddSpellBonus", EQ2Emu_lua_AddSpellBonus);
  978. lua_register(state, "RemoveSpellBonus", EQ2Emu_lua_RemoveSpellBonus);
  979. lua_register(state, "AddSkillBonus", EQ2Emu_lua_AddSkillBonus);
  980. lua_register(state, "RemoveSkillBonus", EQ2Emu_lua_RemoveSkillBonus);
  981. lua_register(state, "AddControlEffect", EQ2Emu_lua_AddControlEffect);
  982. lua_register(state, "RemoveControlEffect", EQ2Emu_lua_RemoveControlEffect);
  983. lua_register(state, "HasControlEffect", EQ2Emu_lua_HasControlEffect);
  984. lua_register(state, "GetBaseAggroRadius", EQ2Emu_lua_GetBaseAggroRadius);
  985. lua_register(state, "GetAggroRadius", EQ2Emu_lua_GetAggroRadius);
  986. lua_register(state, "SetAggroRadius", EQ2Emu_lua_SetAggroRadius);
  987. lua_register(state, "GetCurrentZoneSafeLocation", EQ2Emu_lua_GetCurrentZoneSafeLocation);
  988. lua_register(state, "SetDeity", EQ2Emu_lua_SetDeity);
  989. lua_register(state, "GetDeity", EQ2Emu_lua_GetDeity);
  990. lua_register(state, "GetInt", EQ2Emu_lua_GetInt);
  991. lua_register(state, "GetWis", EQ2Emu_lua_GetWis);
  992. lua_register(state, "GetSta", EQ2Emu_lua_GetSta);
  993. lua_register(state, "GetStr", EQ2Emu_lua_GetStr);
  994. lua_register(state, "GetAgi", EQ2Emu_lua_GetAgi);
  995. lua_register(state, "SetInt", EQ2Emu_lua_SetInt);
  996. lua_register(state, "SetWis", EQ2Emu_lua_SetWis);
  997. lua_register(state, "SetSta", EQ2Emu_lua_SetSta);
  998. lua_register(state, "SetStr", EQ2Emu_lua_SetStr);
  999. lua_register(state, "SetAgi", EQ2Emu_lua_SetAgi);
  1000. lua_register(state, "GetIntBase", EQ2Emu_lua_GetIntBase);
  1001. lua_register(state, "GetWisBase", EQ2Emu_lua_GetWisBase);
  1002. lua_register(state, "GetStaBase", EQ2Emu_lua_GetStaBase);
  1003. lua_register(state, "GetStrBase", EQ2Emu_lua_GetStrBase);
  1004. lua_register(state, "GetAgiBase", EQ2Emu_lua_GetAgiBase);
  1005. lua_register(state, "SetIntBase", EQ2Emu_lua_SetIntBase);
  1006. lua_register(state, "SetWisBase", EQ2Emu_lua_SetWisBase);
  1007. lua_register(state, "SetStaBase", EQ2Emu_lua_SetStaBase);
  1008. lua_register(state, "SetStrBase", EQ2Emu_lua_SetStrBase);
  1009. lua_register(state, "SetAgiBase", EQ2Emu_lua_SetAgiBase);
  1010. lua_register(state, "GetSpawn", EQ2Emu_lua_GetSpawn);
  1011. lua_register(state, "GetVariableValue", EQ2Emu_lua_GetVariableValue);
  1012. lua_register(state, "GetCoinMessage", EQ2Emu_lua_GetCoinMessage);
  1013. lua_register(state, "GetSpawnByGroupID", EQ2Emu_lua_GetSpawnByGroupID);
  1014. lua_register(state, "GetSpawnByLocationID", EQ2Emu_lua_GetSpawnByLocationID);
  1015. lua_register(state, "PlayFlavor", EQ2Emu_lua_PlayFlavor);
  1016. lua_register(state, "PlayFlavorID", EQ2Emu_lua_PlayFlavorID);
  1017. lua_register(state, "PlaySound", EQ2Emu_lua_PlaySound);
  1018. lua_register(state, "PlayVoice", EQ2Emu_lua_PlayVoice);
  1019. lua_register(state, "PlayAnimation", EQ2Emu_lua_PlayAnimation);
  1020. lua_register(state, "AddLootItem", EQ2Emu_lua_AddLootItem);
  1021. lua_register(state, "HasLootItem", EQ2Emu_lua_HasLootItem);
  1022. lua_register(state, "RemoveLootItem", EQ2Emu_lua_RemoveLootItem);
  1023. lua_register(state, "AddLootCoin", EQ2Emu_lua_AddLootCoin);
  1024. lua_register(state, "GiveLoot", EQ2Emu_lua_GiveLoot);
  1025. lua_register(state, "HasPendingLootItem", EQ2Emu_lua_HasPendingLootItem);
  1026. lua_register(state, "HasPendingLoot", EQ2Emu_lua_HasPendingLoot);
  1027. lua_register(state, "SetLootCoin", EQ2Emu_lua_SetLootCoin);
  1028. lua_register(state, "HasCoin", EQ2Emu_lua_HasCoin);
  1029. lua_register(state, "GetLootCoin", EQ2Emu_lua_GetLootCoin);
  1030. lua_register(state, "SetPlayerProximityFunction", EQ2Emu_lua_SetPlayerProximityFunction);
  1031. lua_register(state, "SetLocationProximityFunction", EQ2Emu_lua_SetLocationProximityFunction);
  1032. lua_register(state, "CreateConversation", EQ2Emu_lua_CreateConversation);
  1033. lua_register(state, "AddConversationOption", EQ2Emu_lua_AddConversationOption);
  1034. lua_register(state, "StartConversation", EQ2Emu_lua_StartConversation);
  1035. lua_register(state, "CloseConversation", EQ2Emu_lua_CloseConversation);
  1036. lua_register(state, "CloseItemConversation", EQ2Emu_lua_CloseItemConversation);
  1037. //lua_register(state, "StartItemConversation", EQ2Emu_lua_StartItemConversation);
  1038. lua_register(state, "StartDialogConversation", EQ2Emu_lua_StartDialogConversation);
  1039. lua_register(state, "SendStateCommand", EQ2Emu_lua_SendStateCommand);
  1040. lua_register(state, "SpawnSet", EQ2Emu_lua_SpawnSet);
  1041. lua_register(state, "SpawnSetByDistance", EQ2Emu_lua_SpawnSetByDistance);
  1042. lua_register(state, "SpawnMove", EQ2Emu_lua_SpawnMove);
  1043. lua_register(state, "KillSpawn", EQ2Emu_lua_KillSpawn);
  1044. lua_register(state, "KillSpawnByDistance", EQ2Emu_lua_KillSpawnByDistance);
  1045. lua_register(state, "Despawn", EQ2Emu_lua_Despawn);
  1046. lua_register(state, "ChangeHandIcon", EQ2Emu_lua_ChangeHandIcon);
  1047. lua_register(state, "SetVisualFlag", EQ2Emu_lua_SetVisualFlag);
  1048. lua_register(state, "SetInfoFlag", EQ2Emu_lua_SetInfoFlag);
  1049. lua_register(state, "IsBindAllowed", EQ2Emu_lua_IsBindAllowed);
  1050. lua_register(state, "IsGateAllowed", EQ2Emu_lua_IsGateAllowed);
  1051. lua_register(state, "Bind", EQ2Emu_lua_Bind);
  1052. lua_register(state, "Gate", EQ2Emu_lua_Gate);
  1053. lua_register(state, "SendMessage", EQ2Emu_lua_SendMessage);
  1054. lua_register(state, "SendPopUpMessage", EQ2Emu_lua_SendPopUpMessage);
  1055. lua_register(state, "SetServerControlFlag", EQ2Emu_lua_SetServerControlFlag);
  1056. lua_register(state, "ToggleTracking", EQ2Emu_lua_ToggleTracking);
  1057. lua_register(state, "AddPrimaryEntityCommand", EQ2Emu_lua_AddPrimaryEntityCommand);
  1058. lua_register(state, "AddSpellBookEntry", EQ2Emu_lua_AddSpellBookEntry);
  1059. lua_register(state, "DeleteSpellBook", EQ2Emu_lua_DeleteSpellBook);
  1060. lua_register(state, "RemoveSpellBookEntry", EQ2Emu_lua_RemoveSpellBookEntry);
  1061. lua_register(state, "SendNewAdventureSpells", EQ2Emu_lua_SendNewAdventureSpells);
  1062. lua_register(state, "SendNewTradeskillSpells", EQ2Emu_lua_SendNewTradeskillSpells);
  1063. lua_register(state, "HasSpell", EQ2Emu_lua_HasSpell);
  1064. lua_register(state, "Interrupt", EQ2Emu_lua_Interrupt);
  1065. lua_register(state, "Stealth", EQ2Emu_lua_Stealth);
  1066. lua_register(state, "IsInvis", EQ2Emu_lua_IsInvis);
  1067. lua_register(state, "IsStealthed", EQ2Emu_lua_IsStealthed);
  1068. lua_register(state, "AddSpawnIDAccess", EQ2Emu_lua_AddSpawnIDAccess);
  1069. lua_register(state, "RemoveSpawnIDAccess", EQ2Emu_lua_RemoveSpawnIDAccess);
  1070. lua_register(state, "HasRecipeBook", EQ2Emu_lua_HasRecipeBook);
  1071. lua_register(state, "SetRequiredQuest", EQ2Emu_lua_SetRequiredQuest);
  1072. lua_register(state, "SetRequiredHistory", EQ2Emu_lua_SetRequiredHistory);
  1073. lua_register(state, "SetStepComplete", EQ2Emu_lua_SetStepComplete);
  1074. lua_register(state, "AddStepProgress", EQ2Emu_lua_AddStepProgress);
  1075. lua_register(state, "UpdateQuestTaskGroupDescription", EQ2Emu_lua_UpdateQuestTaskGroupDescription);
  1076. lua_register(state, "GetTaskGroupStep", EQ2Emu_lua_GetTaskGroupStep);
  1077. lua_register(state, "GetQuestStep", EQ2Emu_lua_GetQuestStep);
  1078. lua_register(state, "QuestStepIsComplete", EQ2Emu_lua_QuestStepIsComplete);
  1079. lua_register(state, "RegisterQuest", EQ2Emu_lua_RegisterQuest);
  1080. lua_register(state, "SetQuestPrereqLevel", EQ2Emu_lua_SetQuestPrereqLevel);
  1081. lua_register(state, "AddQuestPrereqQuest", EQ2Emu_lua_AddQuestPrereqQuest);
  1082. lua_register(state, "AddQuestPrereqItem", EQ2Emu_lua_AddQuestPrereqItem);
  1083. lua_register(state, "AddQuestPrereqFaction", EQ2Emu_lua_AddQuestPrereqFaction);
  1084. lua_register(state, "AddQuestPrereqRace", EQ2Emu_lua_AddQuestPrereqRace);
  1085. lua_register(state, "AddQuestPrereqModelType", EQ2Emu_lua_AddQuestPrereqModelType);
  1086. lua_register(state, "AddQuestPrereqClass", EQ2Emu_lua_AddQuestPrereqClass);
  1087. lua_register(state, "AddQuestPrereqTradeskillLevel", EQ2Emu_lua_AddQuestPrereqTradeskillLevel);
  1088. lua_register(state, "AddQuestPrereqTradeskillClass", EQ2Emu_lua_AddQuestPrereqTradeskillClass);
  1089. lua_register(state, "AddQuestSelectableRewardItem", EQ2Emu_lua_AddQuestSelectableRewardItem);
  1090. lua_register(state, "HasQuestRewardItem", EQ2Emu_lua_HasQuestRewardItem);
  1091. lua_register(state, "AddQuestRewardItem", EQ2Emu_lua_AddQuestRewardItem);
  1092. lua_register(state, "AddQuestRewardCoin", EQ2Emu_lua_AddQuestRewardCoin);
  1093. lua_register(state, "AddQuestRewardFaction", EQ2Emu_lua_AddQuestRewardFaction);
  1094. lua_register(state, "SetQuestRewardStatus", EQ2Emu_lua_SetQuestRewardStatus);
  1095. lua_register(state, "SetStatusTmpReward", EQ2Emu_lua_SetStatusTmpReward);
  1096. lua_register(state, "SetCoinTmpReward", EQ2Emu_lua_SetCoinTmpReward);
  1097. lua_register(state, "SetQuestRewardComment", EQ2Emu_lua_SetQuestRewardComment);
  1098. lua_register(state, "SetQuestRewardExp", EQ2Emu_lua_SetQuestRewardExp);
  1099. lua_register(state, "AddQuestStepKill", EQ2Emu_lua_AddQuestStepKill);
  1100. lua_register(state, "AddQuestStepKillByRace", EQ2Emu_lua_AddQuestStepKillByRace);
  1101. lua_register(state, "AddQuestStep", EQ2Emu_lua_AddQuestStep);
  1102. lua_register(state, "AddQuestStepChat", EQ2Emu_lua_AddQuestStepChat);
  1103. lua_register(state, "AddQuestStepObtainItem", EQ2Emu_lua_AddQuestStepObtainItem);
  1104. lua_register(state, "AddQuestStepZoneLoc", EQ2Emu_lua_AddQuestStepZoneLoc);
  1105. lua_register(state, "AddQuestStepLocation", EQ2Emu_lua_AddQuestStepLocation);
  1106. lua_register(state, "AddQuestStepSpell", EQ2Emu_lua_AddQuestStepSpell);
  1107. lua_register(state, "AddQuestStepCraft", EQ2Emu_lua_AddQuestStepCraft);
  1108. lua_register(state, "AddQuestStepHarvest", EQ2Emu_lua_AddQuestStepHarvest);
  1109. lua_register(state, "AddQuestStepCompleteAction", EQ2Emu_lua_AddQuestStepCompleteAction);
  1110. lua_register(state, "AddQuestStepProgressAction", EQ2Emu_lua_AddQuestStepProgressAction);
  1111. lua_register(state, "SetQuestCompleteAction", EQ2Emu_lua_SetQuestCompleteAction);
  1112. lua_register(state, "GiveQuestReward", EQ2Emu_lua_GiveQuestReward);
  1113. lua_register(state, "UpdateQuestStepDescription", EQ2Emu_lua_UpdateQuestStepDescription);
  1114. lua_register(state, "UpdateQuestDescription", EQ2Emu_lua_UpdateQuestDescription);
  1115. lua_register(state, "UpdateQuestZone", EQ2Emu_lua_UpdateQuestZone);
  1116. lua_register(state, "SetCompletedDescription", EQ2Emu_lua_SetCompletedDescription);
  1117. lua_register(state, "OfferQuest", EQ2Emu_lua_OfferQuest);
  1118. lua_register(state, "ProvidesQuest", EQ2Emu_lua_ProvidesQuest);
  1119. lua_register(state, "HasQuest", EQ2Emu_lua_HasQuest);
  1120. lua_register(state, "HasCompletedQuest", EQ2Emu_lua_HasCompletedQuest);
  1121. lua_register(state, "QuestIsComplete", EQ2Emu_lua_QuestIsComplete);
  1122. lua_register(state, "QuestReturnNPC", EQ2Emu_lua_QuestReturnNPC);
  1123. lua_register(state, "GetQuest", EQ2Emu_lua_GetQuest);
  1124. lua_register(state, "HasCollectionsToHandIn", EQ2Emu_lua_HasCollectionsToHandIn);
  1125. lua_register(state, "HandInCollections", EQ2Emu_lua_HandInCollections);
  1126. lua_register(state, "UseWidget", EQ2Emu_lua_UseWidget);
  1127. lua_register(state, "SetSpellList", EQ2Emu_lua_SetSpellList);
  1128. lua_register(state, "GetPet", EQ2Emu_lua_GetPet);
  1129. lua_register(state, "Charm", EQ2Emu_lua_Charm);
  1130. lua_register(state, "GetGroup", EQ2Emu_lua_GetGroup);
  1131. lua_register(state, "SetCompleteFlag", EQ2Emu_lua_SetCompleteFlag);
  1132. lua_register(state, "SetQuestYellow", EQ2Emu_lua_SetQuestYellow);
  1133. lua_register(state, "CanReceiveQuest", EQ2Emu_lua_CanReceiveQuest);
  1134. lua_register(state, "AddTransportSpawn", EQ2Emu_lua_AddTransportSpawn);
  1135. lua_register(state, "IsTransportSpawn", EQ2Emu_lua_IsTransportSpawn);
  1136. // Option window
  1137. lua_register(state, "CreateOptionWindow", EQ2Emu_lua_CreateOptionWindow);
  1138. lua_register(state, "AddOptionWindowOption", EQ2Emu_lua_AddOptionWindowOption);
  1139. lua_register(state, "SendOptionWindow", EQ2Emu_lua_SendOptionWindow);
  1140. lua_register(state, "GetTradeskillClass", EQ2Emu_lua_GetTradeskillClass);
  1141. lua_register(state, "GetTradeskillLevel", EQ2Emu_lua_GetTradeskillLevel);
  1142. lua_register(state, "GetTradeskillClassName", EQ2Emu_lua_GetTradeskillClassName);
  1143. lua_register(state, "SetTradeskillLevel", EQ2Emu_lua_SetTradeskillLevel);
  1144. lua_register(state, "SummonDeityPet", EQ2Emu_lua_SummonDeityPet);
  1145. lua_register(state, "SummonCosmeticPet", EQ2Emu_lua_SummonCosmeticPet);
  1146. lua_register(state, "DismissPet", EQ2Emu_lua_DismissPet);
  1147. lua_register(state, "GetCharmedPet", EQ2Emu_lua_GetCharmedPet);
  1148. lua_register(state, "GetDeityPet", EQ2Emu_lua_GetDeityPet);
  1149. lua_register(state, "GetCosmeticPet", EQ2Emu_lua_GetCosmeticPet);
  1150. lua_register(state, "SetQuestFeatherColor", EQ2Emu_lua_SetQuestFeatherColor);
  1151. lua_register(state, "RemoveSpawnAccess", EQ2Emu_lua_RemoveSpawnAccess);
  1152. lua_register(state, "SpawnByLocationID", EQ2Emu_lua_SpawnByLocationID);
  1153. lua_register(state, "CastEntityCommand", EQ2Emu_lua_CastEntityCommand);
  1154. lua_register(state, "SetLuaBrain", EQ2Emu_lua_SetLuaBrain);
  1155. lua_register(state, "SetBrainTick", EQ2Emu_lua_SetBrainTick);
  1156. lua_register(state, "SetFollowTarget", EQ2Emu_lua_SetFollowTarget);
  1157. lua_register(state, "GetFollowTarget", EQ2Emu_lua_GetFollowTarget);
  1158. lua_register(state, "ToggleFollow", EQ2Emu_lua_ToggleFollow);
  1159. lua_register(state, "IsFollowing", EQ2Emu_lua_IsFollowing);
  1160. lua_register(state, "SetTempVariable", EQ2Emu_lua_SetTempVariable);
  1161. lua_register(state, "GetTempVariable", EQ2Emu_lua_GetTempVariable);
  1162. lua_register(state, "GiveQuestItem", EQ2Emu_lua_GiveQuestItem);
  1163. lua_register(state, "SetQuestRepeatable", EQ2Emu_lua_SetQuestRepeatable);
  1164. lua_register(state, "AddWaypoint", EQ2Emu_lua_AddWaypoint);
  1165. lua_register(state, "RemoveWaypoint", EQ2Emu_lua_RemoveWaypoint);
  1166. lua_register(state, "SendWaypoints", EQ2Emu_lua_SendWaypoints);
  1167. lua_register(state, "AddWard", EQ2Emu_lua_AddWard);
  1168. lua_register(state, "AddToWard", EQ2Emu_lua_AddToWard);
  1169. lua_register(state, "RemoveWard", EQ2Emu_lua_RemoveWard);
  1170. lua_register(state, "GetWardAmountLeft", EQ2Emu_lua_GetWardAmountLeft);
  1171. lua_register(state, "GetWardValue", EQ2Emu_lua_GetWardValue);
  1172. lua_register(state, "SetTarget", EQ2Emu_lua_SetTarget);
  1173. lua_register(state, "IsPet", EQ2Emu_lua_IsPet);
  1174. lua_register(state, "GetOwner", EQ2Emu_lua_GetOwner);
  1175. lua_register(state, "SetInCombat", EQ2Emu_lua_SetInCombat);
  1176. lua_register(state, "CompareSpawns", EQ2Emu_lua_CompareSpawns);
  1177. lua_register(state, "ClearRunback", EQ2Emu_lua_ClearRunback);
  1178. lua_register(state, "Runback", EQ2Emu_lua_Runback);
  1179. lua_register(state, "GetRunbackDistance", EQ2Emu_lua_GetRunbackDistance);
  1180. lua_register(state, "IsCasting", EQ2Emu_lua_IsCasting);
  1181. lua_register(state, "IsMezzed", EQ2Emu_lua_IsMezzed);
  1182. lua_register(state, "IsStunned", EQ2Emu_lua_IsStunned);
  1183. lua_register(state, "IsMezzedOrStunned", EQ2Emu_lua_IsMezzedOrStunned);
  1184. lua_register(state, "ProcessSpell", EQ2Emu_lua_ProcessSpell);
  1185. lua_register(state, "ProcessMelee", EQ2Emu_lua_ProcessMelee);
  1186. lua_register(state, "HasRecovered", EQ2Emu_lua_HasRecovered);
  1187. lua_register(state, "GetEncounterSize", EQ2Emu_lua_GetEncounterSize);
  1188. lua_register(state, "GetMostHated", EQ2Emu_lua_GetMostHated);
  1189. lua_register(state, "ClearHate", EQ2Emu_lua_ClearHate);
  1190. lua_register(state, "ClearEncounter", EQ2Emu_lua_ClearEncounter);
  1191. lua_register(state, "GetEncounter", EQ2Emu_lua_GetEncounter);
  1192. lua_register(state, "GetHateList", EQ2Emu_lua_GetHateList);
  1193. lua_register(state, "HasGroup", EQ2Emu_lua_HasGroup);
  1194. lua_register(state, "HasSpellEffect", EQ2Emu_lua_HasSpellEffect);
  1195. lua_register(state, "SetSuccessTimer", EQ2Emu_lua_SetSuccessTimer);
  1196. lua_register(state, "SetFailureTimer", EQ2Emu_lua_SetFailureTimer);
  1197. lua_register(state, "IsGroundSpawn", EQ2Emu_lua_IsGroundSpawn);
  1198. lua_register(state, "CanHarvest", EQ2Emu_lua_CanHarvest);
  1199. lua_register(state, "SummonDumbFirePet", EQ2Emu_lua_SummonDumbFirePet);
  1200. lua_register(state, "GetSkillValue", EQ2Emu_lua_GetSkillValue);
  1201. lua_register(state, "GetSkillMaxValue", EQ2Emu_lua_GetSkillMaxValue);
  1202. lua_register(state, "GetSkillName", EQ2Emu_lua_GetSkillName);
  1203. lua_register(state, "SetSkillMaxValue", EQ2Emu_lua_SetSkillMaxValue);
  1204. lua_register(state, "SetSkillValue", EQ2Emu_lua_SetSkillValue);
  1205. lua_register(state, "GetSkill", EQ2Emu_lua_GetSkill);
  1206. lua_register(state, "GetSkillIDByName", EQ2Emu_lua_GetSkillIDByName);
  1207. lua_register(state, "HasSkill", EQ2Emu_lua_HasSkill);
  1208. lua_register(state, "AddSkill", EQ2Emu_lua_AddSkill);
  1209. lua_register(state, "IncreaseSkillCapsByType", EQ2Emu_lua_IncreaseSkillCapsByType);
  1210. lua_register(state, "RemoveSkill", EQ2Emu_lua_RemoveSkill);
  1211. lua_register(state, "AddProc", EQ2Emu_lua_AddProc);
  1212. lua_register(state, "AddProcExt", EQ2Emu_lua_AddProcExt);
  1213. lua_register(state, "RemoveProc", EQ2Emu_lua_RemoveProc);
  1214. lua_register(state, "Knockback", EQ2Emu_lua_Knockback);
  1215. lua_register(state, "IsEpic", EQ2Emu_lua_IsEpic);
  1216. lua_register(state, "IsHeroic", EQ2Emu_lua_IsHeroic);
  1217. lua_register(state, "ProcDamage", EQ2Emu_lua_ProcDamage);
  1218. lua_register(state, "LastSpellAttackHit", EQ2Emu_lua_LastSpellAttackHit);
  1219. lua_register(state, "IsBehind", EQ2Emu_lua_IsBehind);
  1220. lua_register(state, "IsFlanking", EQ2Emu_lua_IsFlanking);
  1221. lua_register(state, "InFront", EQ2Emu_lua_InFront);
  1222. lua_register(state, "AddSpellTimer", EQ2Emu_lua_AddSpellTimer);
  1223. lua_register(state, "GetItemCount", EQ2Emu_lua_GetItemCount);
  1224. lua_register(state, "SetItemCount", EQ2Emu_lua_SetItemCount);
  1225. lua_register(state, "Resurrect", EQ2Emu_lua_Resurrect);
  1226. lua_register(state, "BreatheUnderwater", EQ2Emu_lua_BreatheUnderwater);
  1227. lua_register(state, "BlurVision", EQ2Emu_lua_BlurVision);
  1228. lua_register(state, "SetVision", EQ2Emu_lua_SetVision);
  1229. lua_register(state, "GetItemSkillReq", EQ2Emu_lua_GetItemSkillReq);
  1230. lua_register(state, "SetSpeedMultiplier", EQ2Emu_lua_SetSpeedMultiplier);
  1231. lua_register(state, "SetIllusion", EQ2Emu_lua_SetIllusion);
  1232. lua_register(state, "ResetIllusion", EQ2Emu_lua_ResetIllusion);
  1233. lua_register(state, "AddThreatTransfer", EQ2Emu_lua_AddThreatTransfer);
  1234. lua_register(state, "RemoveThreatTransfer", EQ2Emu_lua_RemoveThreatTransfer);
  1235. lua_register(state, "CureByType", EQ2Emu_lua_CureByType);
  1236. lua_register(state, "CureByControlEffect", EQ2Emu_lua_CureByControlEffect);
  1237. lua_register(state, "AddSpawnSpellBonus", EQ2Emu_lua_AddSpawnSpellBonus);
  1238. lua_register(state, "RemoveSpawnSpellBonus", EQ2Emu_lua_RemoveSpawnSpellBonus);
  1239. lua_register(state, "CancelSpell", EQ2Emu_lua_CancelSpell);
  1240. lua_register(state, "RemoveStealth", EQ2Emu_lua_RemoveStealth);
  1241. lua_register(state, "RemoveInvis", EQ2Emu_lua_RemoveInvis);
  1242. lua_register(state, "StartHeroicOpportunity", EQ2Emu_lua_StartHeroicOpportunity);
  1243. lua_register(state, "CopySpawnAppearance", EQ2Emu_lua_CopySpawnAppearance);
  1244. lua_register(state, "SetSpellTriggerCount", EQ2Emu_lua_SetSpellTriggerCount);
  1245. lua_register(state, "GetSpellTriggerCount", EQ2Emu_lua_GetSpellTriggerCount);
  1246. lua_register(state, "RemoveTriggerFromSpell", EQ2Emu_lua_RemoveTriggerFromSpell);
  1247. lua_register(state, "HasSpellImmunity", EQ2Emu_lua_HasSpellImmunity);
  1248. lua_register(state, "AddImmunitySpell", EQ2Emu_lua_AddImmunitySpell);
  1249. lua_register(state, "RemoveImmunitySpell", EQ2Emu_lua_RemoveImmunitySpell);
  1250. lua_register(state, "SetSpellSnareValue", EQ2Emu_lua_SetSpellSnareValue);
  1251. lua_register(state, "CheckRaceType", EQ2Emu_lua_CheckRaceType);
  1252. lua_register(state, "GetRaceType", EQ2Emu_lua_GetRaceType);
  1253. lua_register(state, "GetRaceBaseType", EQ2Emu_lua_GetRaceBaseType);
  1254. lua_register(state, "GetQuestFlags", EQ2Emu_lua_GetQuestFlags);
  1255. lua_register(state, "SetQuestFlags", EQ2Emu_lua_SetQuestFlags);
  1256. lua_register(state, "SetQuestTimer", EQ2Emu_lua_SetQuestTimer);
  1257. lua_register(state, "RemoveQuestStep", EQ2Emu_lua_RemoveQuestStep);
  1258. lua_register(state, "ResetQuestStep", EQ2Emu_lua_ResetQuestStep);
  1259. lua_register(state, "SetQuestTimerComplete", EQ2Emu_lua_SetQuestTimerComplete);
  1260. lua_register(state, "AddQuestStepFailureAction", EQ2Emu_lua_AddQuestStepFailureAction);
  1261. lua_register(state, "SetStepFailed", EQ2Emu_lua_SetStepFailed);
  1262. lua_register(state, "GetQuestCompleteCount", EQ2Emu_lua_GetQuestCompleteCount);
  1263. lua_register(state, "SetServerVariable", EQ2Emu_lua_SetServerVariable);
  1264. lua_register(state, "GetServerVariable", EQ2Emu_lua_GetServerVariable);
  1265. lua_register(state, "HasLanguage", EQ2Emu_lua_HasLanguage);
  1266. lua_register(state, "AddLanguage", EQ2Emu_lua_AddLanguage);
  1267. lua_register(state, "IsNight", EQ2Emu_lua_IsNight);
  1268. lua_register(state, "AddMultiFloorLift", EQ2Emu_lua_AddMultiFloorLift);
  1269. lua_register(state, "StartAutoMount", EQ2Emu_lua_StartAutoMount);
  1270. lua_register(state, "EndAutoMount", EQ2Emu_lua_EndAutoMount);
  1271. lua_register(state, "IsOnAutoMount", EQ2Emu_lua_IsOnAutoMount);
  1272. lua_register(state, "SetPlayerHistory", EQ2Emu_lua_SetPlayerHistory);
  1273. lua_register(state, "GetPlayerHistory", EQ2Emu_lua_GetPlayerHistory);
  1274. lua_register(state, "SetGridID", EQ2Emu_lua_SetGridID);
  1275. lua_register(state, "GetQuestStepProgress", EQ2Emu_lua_GetQuestStepProgress);
  1276. lua_register(state, "SetPlayerLevel", EQ2Emu_lua_SetPlayerLevel);
  1277. lua_register(state, "AddCoin", EQ2Emu_lua_AddCoin);
  1278. lua_register(state, "RemoveCoin", EQ2Emu_lua_RemoveCoin);
  1279. lua_register(state, "GetPlayersInZone", EQ2Emu_lua_GetPlayersInZone);
  1280. lua_register(state, "SpawnGroupByID", EQ2Emu_lua_SpawnGroupByID);
  1281. lua_register(state, "SetSpawnAnimation", EQ2Emu_lua_SetSpawnAnimation);
  1282. lua_register(state, "GetClientVersion", EQ2Emu_lua_GetClientVersion);
  1283. lua_register(state, "GetItemID", EQ2Emu_lua_GetItemID);
  1284. lua_register(state, "IsEntity", EQ2Emu_lua_IsEntity);
  1285. lua_register(state, "GetOrigX", EQ2Emu_lua_GetOrigX);
  1286. lua_register(state, "GetOrigY", EQ2Emu_lua_GetOrigY);
  1287. lua_register(state, "GetOrigZ", EQ2Emu_lua_GetOrigZ);
  1288. lua_register(state, "GetPCTOfHP", EQ2Emu_lua_GetPCTOfHP);
  1289. lua_register(state, "GetPCTOfPower", EQ2Emu_lua_GetPCTOfPower);
  1290. lua_register(state, "GetBoundZoneID", EQ2Emu_lua_GetBoundZoneID);
  1291. lua_register(state, "Evac", EQ2Emu_lua_Evac);
  1292. lua_register(state, "GetSpellTier", EQ2Emu_lua_GetSpellTier);
  1293. lua_register(state, "GetSpellID", EQ2Emu_lua_GetSpellID);
  1294. lua_register(state, "StartTransmute", EQ2Emu_lua_StartTransmute);
  1295. lua_register(state, "CompleteTransmute", EQ2Emu_lua_CompleteTransmute);
  1296. lua_register(state, "ProcHate", EQ2Emu_lua_ProcHate);
  1297. lua_register(state, "GetRandomSpawnByID", EQ2Emu_lua_GetRandomSpawnByID);
  1298. lua_register(state, "ShowLootWindow", EQ2Emu_lua_ShowLootWindow);
  1299. lua_register(state, "AddPrimaryEntityCommandAllSpawns", EQ2Emu_lua_AddPrimaryEntityCommandAllSpawns);
  1300. lua_register(state, "InstructionWindow", EQ2Emu_lua_InstructionWindow);
  1301. lua_register(state, "InstructionWindowClose", EQ2Emu_lua_InstructionWindowClose);
  1302. lua_register(state, "InstructionWindowGoal", EQ2Emu_lua_InstructionWindowGoal);
  1303. lua_register(state, "ShowWindow", EQ2Emu_lua_ShowWindow);
  1304. lua_register(state, "FlashWindow", EQ2Emu_lua_FlashWindow);
  1305. lua_register(state, "EnableGameEvent", EQ2Emu_lua_EnableGameEvent);
  1306. lua_register(state, "GetTutorialStep", EQ2Emu_lua_GetTutorialStep);
  1307. lua_register(state, "SetTutorialStep", EQ2Emu_lua_SetTutorialStep);
  1308. lua_register(state, "DisplayText", EQ2Emu_lua_DisplayText);
  1309. lua_register(state, "GiveExp", EQ2Emu_lua_GiveExp);
  1310. lua_register(state, "CheckLOS", EQ2Emu_lua_CheckLOS);
  1311. lua_register(state, "CheckLOSByCoordinates", EQ2Emu_lua_CheckLOSByCoordinates);
  1312. lua_register(state, "SetZoneExpansionFlag", EQ2Emu_lua_SetZoneExpansionFlag);
  1313. lua_register(state, "GetZoneExpansionFlag", EQ2Emu_lua_GetZoneExpansionFlag);
  1314. lua_register(state, "SetZoneHolidayFlag", EQ2Emu_lua_SetZoneHolidayFlag);
  1315. lua_register(state, "GetZoneHolidayFlag", EQ2Emu_lua_GetZoneHolidayFlag);
  1316. lua_register(state, "SetCanBind", EQ2Emu_lua_SetCanBind);
  1317. lua_register(state, "GetCanBind", EQ2Emu_lua_GetCanBind);
  1318. lua_register(state, "GetCanGate", EQ2Emu_lua_GetCanGate);
  1319. lua_register(state, "SetCanGate", EQ2Emu_lua_SetCanGate);
  1320. lua_register(state, "SetCanEvac", EQ2Emu_lua_SetCanEvac);
  1321. lua_register(state, "GetCanEvac", EQ2Emu_lua_GetCanEvac);
  1322. lua_register(state, "AddSpawnProximity", EQ2Emu_lua_AddSpawnProximity);
  1323. lua_register(state, "CanSeeInvis", EQ2Emu_lua_CanSeeInvis);
  1324. lua_register(state, "SetSeeInvis", EQ2Emu_lua_SetSeeInvis);
  1325. lua_register(state, "SetSeeHide", EQ2Emu_lua_SetSeeHide);
  1326. lua_register(state, "SetAccessToEntityCommand", EQ2Emu_lua_SetAccessToEntityCommand);
  1327. lua_register(state, "SetAccessToEntityCommandByCharID", EQ2Emu_lua_SetAccessToEntityCommandByCharID);
  1328. lua_register(state, "RemovePrimaryEntityCommand", EQ2Emu_lua_RemovePrimaryEntityCommand);
  1329. lua_register(state, "SendUpdateDefaultCommand", EQ2Emu_lua_SendUpdateDefaultCommand);
  1330. lua_register(state, "SendTransporters", EQ2Emu_lua_SendTransporters);
  1331. lua_register(state, "SetTemporaryTransportID", EQ2Emu_lua_SetTemporaryTransportID);
  1332. lua_register(state, "GetTemporaryTransportID", EQ2Emu_lua_GetTemporaryTransportID);
  1333. lua_register(state, "SetAlignment", EQ2Emu_lua_SetAlignment);
  1334. lua_register(state, "GetAlignment", EQ2Emu_lua_GetAlignment);
  1335. lua_register(state, "GetSpell", EQ2Emu_lua_GetSpell);
  1336. lua_register(state, "GetSpellData", EQ2Emu_lua_GetSpellData);
  1337. lua_register(state, "SetSpellData", EQ2Emu_lua_SetSpellData);
  1338. lua_register(state, "CastCustomSpell", EQ2Emu_lua_CastCustomSpell);
  1339. lua_register(state, "SetSpellDataIndex", EQ2Emu_lua_SetSpellDataIndex);
  1340. lua_register(state, "GetSpellDataIndex", EQ2Emu_lua_GetSpellDataIndex);
  1341. lua_register(state, "SetSpellDisplayEffect", EQ2Emu_lua_SetSpellDisplayEffect);
  1342. lua_register(state, "GetSpellDisplayEffect", EQ2Emu_lua_GetSpellDisplayEffect);
  1343. lua_register(state, "InWater", EQ2Emu_lua_InWater);
  1344. lua_register(state, "InLava", EQ2Emu_lua_InLava);
  1345. lua_register(state, "DamageSpawn", EQ2Emu_lua_DamageSpawn);
  1346. lua_register(state, "IsInvulnerable", EQ2Emu_lua_IsInvulnerable);
  1347. lua_register(state, "SetInvulnerable", EQ2Emu_lua_SetInvulnerable);
  1348. lua_register(state, "GetRuleFlagBool", EQ2Emu_lua_GetRuleFlagBool);
  1349. lua_register(state, "GetRuleFlagInt32", EQ2Emu_lua_GetRuleFlagInt32);
  1350. lua_register(state, "GetRuleFlagFloat", EQ2Emu_lua_GetRuleFlagFloat);
  1351. lua_register(state, "GetAAInfo", EQ2Emu_lua_GetAAInfo);
  1352. lua_register(state, "SetAAInfo", EQ2Emu_lua_SetAAInfo);
  1353. lua_register(state, "AddMasterTitle", EQ2Emu_lua_AddMasterTitle);
  1354. lua_register(state, "AddCharacterTitle", EQ2Emu_lua_AddCharacterTitle);
  1355. lua_register(state, "SetCharacterTitleSuffix", EQ2Emu_lua_SetCharacterTitleSuffix);
  1356. lua_register(state, "SetCharacterTitlePrefix", EQ2Emu_lua_SetCharacterTitlePrefix);
  1357. lua_register(state, "ResetCharacterTitleSuffix", EQ2Emu_lua_ResetCharacterTitleSuffix);
  1358. lua_register(state, "ResetCharacterTitlePrefix", EQ2Emu_lua_ResetCharacterTitlePrefix);
  1359. lua_register(state, "GetInfoStructString", EQ2Emu_lua_GetInfoStructString);
  1360. lua_register(state, "GetInfoStructUInt", EQ2Emu_lua_GetInfoStructUInt);
  1361. lua_register(state, "GetInfoStructSInt", EQ2Emu_lua_GetInfoStructSInt);
  1362. lua_register(state, "GetInfoStructFloat", EQ2Emu_lua_GetInfoStructFloat);
  1363. lua_register(state, "SetInfoStructString", EQ2Emu_lua_SetInfoStructString);
  1364. lua_register(state, "SetInfoStructUInt", EQ2Emu_lua_SetInfoStructUInt);
  1365. lua_register(state, "SetInfoStructSInt", EQ2Emu_lua_SetInfoStructSInt);
  1366. lua_register(state, "SetInfoStructFloat", EQ2Emu_lua_SetInfoStructFloat);
  1367. lua_register(state, "SetCharSheetChanged", EQ2Emu_lua_SetCharSheetChanged);
  1368. lua_register(state, "AddPlayerMail", EQ2Emu_lua_AddPlayerMail);
  1369. lua_register(state, "AddPlayerMailByCharID", EQ2Emu_lua_AddPlayerMailByCharID);
  1370. lua_register(state, "OpenDoor", EQ2Emu_lua_OpenDoor);
  1371. lua_register(state, "CloseDoor", EQ2Emu_lua_CloseDoor);
  1372. lua_register(state, "IsOpen", EQ2Emu_lua_IsOpen);
  1373. lua_register(state, "MakeRandomInt", EQ2Emu_lua_MakeRandomInt);
  1374. lua_register(state, "MakeRandomFloat", EQ2Emu_lua_MakeRandomFloat);
  1375. lua_register(state, "AddIconValue", EQ2Emu_lua_AddIconValue);
  1376. lua_register(state, "RemoveIconValue", EQ2Emu_lua_RemoveIconValue);
  1377. lua_register(state, "GetShardID", EQ2Emu_lua_GetShardID);
  1378. lua_register(state, "GetShardCharID", EQ2Emu_lua_GetShardCharID);
  1379. lua_register(state, "GetShardCreatedTimestamp", EQ2Emu_lua_GetShardCreatedTimestamp);
  1380. lua_register(state, "DeleteDBShardID", EQ2Emu_lua_DeleteDBShardID);
  1381. lua_register(state, "PauseMovement", EQ2Emu_lua_PauseMovement);
  1382. lua_register(state, "StopMovement", EQ2Emu_lua_StopMovement);
  1383. lua_register(state, "GetArrowColor", EQ2Emu_lua_GetArrowColor);
  1384. lua_register(state, "GetTSArrowColor", EQ2Emu_lua_GetTSArrowColor);
  1385. lua_register(state, "GetSpawnByRailID", EQ2Emu_lua_GetSpawnByRailID);
  1386. lua_register(state, "SetRailID", EQ2Emu_lua_SetRailID);
  1387. lua_register(state, "IsZoneLoading", EQ2Emu_lua_IsZoneLoading);
  1388. lua_register(state, "IsRunning", EQ2Emu_lua_IsRunning);
  1389. lua_register(state, "GetZoneLockoutTimer", EQ2Emu_lua_GetZoneLockoutTimer);
  1390. lua_register(state, "SetWorldTime", EQ2Emu_lua_SetWorldTime);
  1391. lua_register(state, "GetWorldTimeYear", EQ2Emu_lua_GetWorldTimeYear);
  1392. lua_register(state, "GetWorldTimeMonth", EQ2Emu_lua_GetWorldTimeMonth);
  1393. lua_register(state, "GetWorldTimeHour", EQ2Emu_lua_GetWorldTimeHour);
  1394. lua_register(state, "GetWorldTimeMinute", EQ2Emu_lua_GetWorldTimeMinute);
  1395. lua_register(state, "SendTimeUpdate", EQ2Emu_lua_SendTimeUpdate);
  1396. lua_register(state, "GetLootTier", EQ2Emu_lua_GetLootTier);
  1397. lua_register(state, "SetLootTier", EQ2Emu_lua_SetLootTier);
  1398. lua_register(state, "GetLootDropType", EQ2Emu_lua_GetLootDropType);
  1399. lua_register(state, "SetLootDropType", EQ2Emu_lua_SetLootDropType);
  1400. lua_register(state, "DamageEquippedItems", EQ2Emu_lua_DamageEquippedItems);
  1401. lua_register(state, "CreateWidgetRegion", EQ2Emu_lua_CreateWidgetRegion);
  1402. lua_register(state, "RemoveRegion", EQ2Emu_lua_RemoveRegion);
  1403. lua_register(state, "SetPlayerPOVGhost", EQ2Emu_lua_SetPlayerPOVGhost);
  1404. lua_register(state, "SetCastOnAggroComplete", EQ2Emu_lua_SetCastOnAggroComplete);
  1405. lua_register(state, "IsCastOnAggroComplete", EQ2Emu_lua_IsCastOnAggroComplete);
  1406. lua_register(state, "AddRecipeBookToPlayer", EQ2Emu_lua_AddRecipeBookToPlayer);
  1407. lua_register(state, "RemoveRecipeFromPlayer", EQ2Emu_lua_RemoveRecipeFromPlayer);
  1408. lua_register(state, "ReplaceWidgetFromClient", EQ2Emu_lua_ReplaceWidgetFromClient);
  1409. lua_register(state, "RemoveWidgetFromSpawnMap", EQ2Emu_lua_RemoveWidgetFromSpawnMap);
  1410. lua_register(state, "RemoveWidgetFromZoneMap", EQ2Emu_lua_RemoveWidgetFromZoneMap);
  1411. lua_register(state, "SendHearCast", EQ2Emu_lua_SendHearCast);
  1412. lua_register(state, "GetCharacterFlag", EQ2Emu_lua_GetCharacterFlag);
  1413. lua_register(state, "ToggleCharacterFlag", EQ2Emu_lua_ToggleCharacterFlag);
  1414. lua_register(state, "GetSpellInitialTarget", EQ2Emu_lua_GetSpellInitialTarget);
  1415. }
  1416. void LuaInterface::LogError(const char* error, ...) {
  1417. va_list argptr;
  1418. char buffer[4096];
  1419. va_start(argptr, error);
  1420. vsnprintf(buffer, sizeof(buffer), error, argptr);
  1421. va_end(argptr);
  1422. SimpleLogError(buffer);
  1423. }
  1424. void LuaInterface::SimpleLogError(const char* error) {
  1425. ProcessErrorMessage(error);
  1426. LogWrite(LUA__ERROR, 0, "LUA", "%s", error);
  1427. }
  1428. void LuaInterface::ResetFunctionStack(lua_State* state) {
  1429. lua_settop(state, 0);
  1430. }
  1431. void LuaInterface::AddUserDataPtr(LUAUserData* data, void* data_ptr) {
  1432. std::unique_lock lock(MLUAUserData);
  1433. if(data_ptr) {
  1434. user_data_ptr[data_ptr] = data;
  1435. }
  1436. user_data[data] = Timer::GetCurrentTime2() + 300000; //allow a function to use this pointer for 5 minutes
  1437. }
  1438. void LuaInterface::DeletePendingSpells(bool all) {
  1439. MSpells.lock();
  1440. MSpellDelete.lock();
  1441. if (spells_pending_delete.size() > 0) {
  1442. int32 time = Timer::GetCurrentTime2();
  1443. map<LuaSpell*, int32>::iterator itr;
  1444. vector<LuaSpell*> tmp_deletes;
  1445. vector<LuaSpell*>::iterator del_itr;
  1446. for (itr = spells_pending_delete.begin(); itr != spells_pending_delete.end(); itr++) {
  1447. if (all || time >= itr->second)
  1448. tmp_deletes.push_back(itr->first);
  1449. }
  1450. LuaSpell* spell = 0;
  1451. for (del_itr = tmp_deletes.begin(); del_itr != tmp_deletes.end(); del_itr++) {
  1452. spell = *del_itr;
  1453. if(!all) {
  1454. if (spell->caster && spell->caster->GetZone()) {
  1455. spell->caster->GetZone()->GetSpellProcess()->DeleteActiveSpell(spell);
  1456. }
  1457. else if(spell->targets.size() > 0 && spell->caster && spell->caster->GetZone()) {
  1458. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1459. for (int8 i = 0; i < spell->targets.size(); i++) {
  1460. Spawn* target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  1461. if (!target || !target->IsEntity())
  1462. continue;
  1463. target->GetZone()->GetSpellProcess()->DeleteActiveSpell(spell);
  1464. }
  1465. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1466. }
  1467. }
  1468. spells_pending_delete.erase(spell);
  1469. if (spell->spell->IsCopiedSpell())
  1470. {
  1471. RemoveCustomSpell(spell->spell->GetSpellID());
  1472. safe_delete(spell->spell);
  1473. }
  1474. SetLuaUserDataStale(spell);
  1475. RemoveCurrentSpell(spell->state, false);
  1476. safe_delete(spell);
  1477. }
  1478. }
  1479. MSpellDelete.unlock();
  1480. MSpells.unlock();
  1481. }
  1482. void LuaInterface::DeletePendingSpell(LuaSpell* spell) {
  1483. MSpellDelete.lock();
  1484. if (spells_pending_delete.size() > 0) {
  1485. map<LuaSpell*, int32>::iterator itr = spells_pending_delete.find(spell);
  1486. if (itr != spells_pending_delete.end())
  1487. spells_pending_delete.erase(itr);
  1488. }
  1489. MSpellDelete.unlock();
  1490. }
  1491. void LuaInterface::DeleteUserDataPtrs(bool all) {
  1492. std::unique_lock lock(MLUAUserData);
  1493. if(user_data.size() > 0){
  1494. map<LUAUserData*, int32>::iterator itr;
  1495. int32 time = Timer::GetCurrentTime2();
  1496. vector<LUAUserData*> tmp_deletes;
  1497. vector<LUAUserData*>::iterator del_itr;
  1498. for(itr = user_data.begin(); itr != user_data.end(); itr++){
  1499. if(all || time >= itr->second)
  1500. tmp_deletes.push_back(itr->first);
  1501. }
  1502. LUAUserData* data = 0;
  1503. for(del_itr = tmp_deletes.begin(); del_itr != tmp_deletes.end(); del_itr++){
  1504. data = *del_itr;
  1505. void* target = 0;
  1506. if(data->IsConversationOption()) {
  1507. target = data->conversation_options;
  1508. }
  1509. else if(data->IsOptionWindow()) {
  1510. target = data->option_window_option;
  1511. }
  1512. else if(data->IsSpawn()) {
  1513. target = data->spawn;
  1514. }
  1515. else if(data->IsQuest()) {
  1516. target = data->quest;
  1517. }
  1518. else if(data->IsZone()) {
  1519. target = data->zone;
  1520. }
  1521. else if(data->IsItem()) {
  1522. target = data->item;
  1523. }
  1524. else if(data->IsSkill()) {
  1525. target = data->skill;
  1526. }
  1527. else if(data->IsSpell()) {
  1528. target = data->spell;
  1529. }
  1530. if(target) {
  1531. std::map<void*, LUAUserData*>::iterator itr = user_data_ptr.find(target);
  1532. if(itr != user_data_ptr.end()) {
  1533. user_data_ptr.erase(itr);
  1534. }
  1535. }
  1536. user_data.erase(data);
  1537. safe_delete(data);
  1538. }
  1539. }
  1540. }
  1541. Spawn* LuaInterface::GetSpawn(lua_State* state, int8 arg_num) {
  1542. std::shared_lock lock(MLUAUserData);
  1543. Spawn* ret = 0;
  1544. if (lua_islightuserdata(state, arg_num)){
  1545. LUAUserData* data = (LUAUserData*)lua_touserdata(state, arg_num);
  1546. if(!data || !data->IsCorrectlyInitialized()){
  1547. LogError("%s: GetSpawn error while processing %s", GetScriptName(state), lua_tostring(state, -1));
  1548. }
  1549. else if(!data->IsSpawn()){
  1550. lua_Debug ar;
  1551. lua_getstack (state, 1, &ar);
  1552. lua_getinfo(state, "Sln", &ar);
  1553. LogError("%s: Invalid data type used for GetSpawn in %s (line %d)", GetScriptName(state), ar.source, ar.currentline);
  1554. }
  1555. else
  1556. ret = data->spawn;
  1557. }
  1558. return ret;
  1559. }
  1560. vector<ConversationOption>* LuaInterface::GetConversation(lua_State* state, int8 arg_num) {
  1561. std::shared_lock lock(MLUAUserData);
  1562. vector<ConversationOption>* ret = 0;
  1563. if(lua_islightuserdata(state, arg_num)){
  1564. LUAUserData* data = (LUAUserData*)lua_touserdata(state, arg_num);
  1565. if(!data || !data->IsCorrectlyInitialized()){
  1566. LogError("%s: GetConversation error while processing %s", GetScriptName(state), lua_tostring(state, -1));
  1567. }
  1568. else if(!data->IsConversationOption()){
  1569. lua_Debug ar;
  1570. lua_getstack (state, 1, &ar);
  1571. lua_getinfo(state, "Sln", &ar);
  1572. LogError("%s: Invalid data type used for GetConversation in %s (line %d)", GetScriptName(state), ar.source, ar.currentline);
  1573. }
  1574. else
  1575. ret = data->conversation_options;
  1576. }
  1577. return ret;
  1578. }
  1579. vector<OptionWindowOption>* LuaInterface::GetOptionWindow(lua_State* state, int8 arg_num) {
  1580. std::shared_lock lock(MLUAUserData);
  1581. vector<OptionWindowOption>* ret = 0;
  1582. if(lua_islightuserdata(state, arg_num)){
  1583. LUAUserData* data = (LUAUserData*)lua_touserdata(state, arg_num);
  1584. if(!data || !data->IsCorrectlyInitialized()){
  1585. LogError("%s: GetOptionWindow error while processing %s", GetScriptName(state), lua_tostring(state, -1));
  1586. }
  1587. else if(!data->IsOptionWindow()){
  1588. lua_Debug ar;
  1589. lua_getstack (state, 1, &ar);
  1590. lua_getinfo(state, "Sln", &ar);
  1591. LogError("%s: Invalid data type used for GetOptionWindow in %s (line %d)", GetScriptName(state), ar.source, ar.currentline);
  1592. }
  1593. else
  1594. ret = data->option_window_option;
  1595. }
  1596. return ret;
  1597. }
  1598. Quest* LuaInterface::GetQuest(lua_State* state, int8 arg_num) {
  1599. std::shared_lock lock(MLUAUserData);
  1600. Quest* ret = 0;
  1601. if(lua_islightuserdata(state, arg_num)){
  1602. LUAUserData* data = (LUAUserData*)lua_touserdata(state, arg_num);
  1603. if(!data || !data->IsCorrectlyInitialized()){
  1604. LogError("%s: GetQuest error while processing %s", GetScriptName(state), lua_tostring(state, -1));
  1605. }
  1606. else if(!data->IsQuest()){
  1607. lua_Debug ar;
  1608. lua_getstack (state, 1, &ar);
  1609. lua_getinfo(state, "Sln", &ar);
  1610. LogError("%s: Invalid data type used for GetQuest in %s (line %d)", GetScriptName(state), ar.source, ar.currentline);
  1611. }
  1612. else
  1613. ret = data->quest;
  1614. }
  1615. return ret;
  1616. }
  1617. Item* LuaInterface::GetItem(lua_State* state, int8 arg_num) {
  1618. std::shared_lock lock(MLUAUserData);
  1619. Item* ret = 0;
  1620. if(lua_islightuserdata(state, arg_num)){
  1621. LUAUserData* data = (LUAUserData*)lua_touserdata(state, arg_num);
  1622. if(!data || !data->IsCorrectlyInitialized()){
  1623. LogError("%s: GetItem error while processing %s", GetScriptName(state), lua_tostring(state, -1));
  1624. }
  1625. else if(!data->IsItem()){
  1626. lua_Debug ar;
  1627. lua_getstack (state, 1, &ar);
  1628. lua_getinfo(state, "Sln", &ar);
  1629. LogError("%s: Invalid data type used for GetItem in %s (line %d)", GetScriptName(state), ar.source, ar.currentline);
  1630. }
  1631. else
  1632. ret = data->item;
  1633. }
  1634. return ret;
  1635. }
  1636. Skill* LuaInterface::GetSkill(lua_State* state, int8 arg_num) {
  1637. std::shared_lock lock(MLUAUserData);
  1638. Skill* ret = 0;
  1639. if (lua_islightuserdata(state, arg_num)) {
  1640. LUAUserData* data = (LUAUserData*)lua_touserdata(state, arg_num);
  1641. if (!data || !data->IsCorrectlyInitialized()) {
  1642. LogError("%s: GetSkill error while processing %s", GetScriptName(state), lua_tostring(state, -1));
  1643. }
  1644. else if (!data->IsSkill()) {
  1645. lua_Debug ar;
  1646. lua_getstack(state, 1, &ar);
  1647. lua_getinfo(state, "Sln", &ar);
  1648. LogError("%s: Invalid data type used for GetSkill in %s (line %d)", GetScriptName(state), ar.source, ar.currentline);
  1649. }
  1650. else
  1651. ret = data->skill;
  1652. }
  1653. return ret;
  1654. }
  1655. LuaSpell* LuaInterface::GetSpell(lua_State* state, int8 arg_num) {
  1656. std::shared_lock lock(MLUAUserData);
  1657. LuaSpell* ret = 0;
  1658. if (lua_islightuserdata(state, arg_num)) {
  1659. LUAUserData* data = (LUAUserData*)lua_touserdata(state, arg_num);
  1660. if (!data || !data->IsCorrectlyInitialized()) {
  1661. LogError("%s: GetSpell error while processing %s", GetScriptName(state), lua_tostring(state, -1));
  1662. }
  1663. else if (!data->IsSpell()) {
  1664. lua_Debug ar;
  1665. lua_getstack(state, 1, &ar);
  1666. lua_getinfo(state, "Sln", &ar);
  1667. LogError("%s: Invalid data type used for GetSpell in %s (line %d)", GetScriptName(state), ar.source, ar.currentline);
  1668. }
  1669. else
  1670. ret = data->spell;
  1671. }
  1672. return ret;
  1673. }
  1674. ZoneServer* LuaInterface::GetZone(lua_State* state, int8 arg_num) {
  1675. std::shared_lock lock(MLUAUserData);
  1676. ZoneServer* ret = 0;
  1677. if(lua_islightuserdata(state, arg_num)){
  1678. LUAUserData* data = (LUAUserData*)lua_touserdata(state, arg_num);
  1679. if(!data || !data->IsCorrectlyInitialized()){
  1680. LogError("%s: GetZone error while processing %s", GetScriptName(state), lua_tostring(state, -1));
  1681. }
  1682. else if(!data->IsZone()){
  1683. lua_Debug ar;
  1684. lua_getstack (state, 1, &ar);
  1685. lua_getinfo(state, "Sln", &ar);
  1686. LogError("%s: Invalid data type used for GetZone in %s (line %d)", GetScriptName(state), ar.source, ar.currentline);
  1687. }
  1688. else
  1689. ret = data->zone;
  1690. }
  1691. return ret;
  1692. }
  1693. sint64 LuaInterface::GetSInt64Value(lua_State* state, int8 arg_num) {
  1694. sint64 val = 0;
  1695. if(lua_isnumber(state, arg_num)){
  1696. val = (sint64)lua_tointeger(state, arg_num);
  1697. }
  1698. return val;
  1699. }
  1700. int64 LuaInterface::GetInt64Value(lua_State* state, int8 arg_num) {
  1701. int64 val = 0;
  1702. if(lua_isnumber(state, arg_num)){
  1703. val = (int64)lua_tonumber(state, arg_num);
  1704. }
  1705. return val;
  1706. }
  1707. sint32 LuaInterface::GetSInt32Value(lua_State* state, int8 arg_num) {
  1708. sint32 val = 0;
  1709. if(lua_isnumber(state, arg_num)){
  1710. val = lua_tointeger(state, arg_num);
  1711. }
  1712. return val;
  1713. }
  1714. int32 LuaInterface::GetInt32Value(lua_State* state, int8 arg_num) {
  1715. int32 val = 0;
  1716. if(lua_isnumber(state, arg_num)){
  1717. val = (int32)lua_tonumber(state, arg_num);
  1718. }
  1719. return val;
  1720. }
  1721. int16 LuaInterface::GetInt16Value(lua_State* state, int8 arg_num) {
  1722. int16 val = 0;
  1723. if(lua_isnumber(state, arg_num)){
  1724. val = lua_tointeger(state, arg_num);
  1725. }
  1726. return val;
  1727. }
  1728. int8 LuaInterface::GetInt8Value(lua_State* state, int8 arg_num) {
  1729. int8 val = 0;
  1730. if(lua_isnumber(state, arg_num)){
  1731. val = lua_tointeger(state, arg_num);
  1732. }
  1733. return val;
  1734. }
  1735. float LuaInterface::GetFloatValue(lua_State* state, int8 arg_num) {
  1736. float val = 0;
  1737. if(lua_isnumber(state, arg_num))
  1738. val = (float)lua_tonumber(state, arg_num);
  1739. return val;
  1740. }
  1741. string LuaInterface::GetStringValue(lua_State* state, int8 arg_num) {
  1742. string val;
  1743. if(lua_isstring(state, arg_num)){
  1744. size_t size = 0;
  1745. const char* str = lua_tolstring(state, arg_num, &size);
  1746. if(str)
  1747. val = string(str);
  1748. }
  1749. return val;
  1750. }
  1751. bool LuaInterface::GetBooleanValue(lua_State* state, int8 arg_num) {
  1752. return lua_toboolean(state, arg_num) == 1;
  1753. }
  1754. void LuaInterface::SetStringValue(lua_State* state, const char* value) {
  1755. lua_pushstring(state, value);
  1756. }
  1757. void LuaInterface::SetBooleanValue(lua_State* state, bool value) {
  1758. lua_pushboolean(state, value);
  1759. }
  1760. void LuaInterface::SetFloatValue(lua_State* state, float value) {
  1761. lua_pushnumber(state, value);
  1762. }
  1763. void LuaInterface::SetInt32Value(lua_State* state, int32 value) {
  1764. lua_pushinteger(state, value);
  1765. }
  1766. void LuaInterface::SetSInt32Value(lua_State* state, sint32 value) {
  1767. lua_pushinteger(state, value);
  1768. }
  1769. void LuaInterface::SetInt64Value(lua_State* state, int64 value) {
  1770. lua_pushinteger(state, value);
  1771. }
  1772. void LuaInterface::SetSInt64Value(lua_State* state, sint64 value) {
  1773. lua_pushinteger(state, value);
  1774. }
  1775. void LuaInterface::SetSpawnValue(lua_State* state, Spawn* spawn) {
  1776. LUASpawnWrapper* spawn_wrapper = new LUASpawnWrapper();
  1777. spawn_wrapper->spawn = spawn;
  1778. AddUserDataPtr(spawn_wrapper, spawn);
  1779. lua_pushlightuserdata(state, spawn_wrapper);
  1780. }
  1781. void LuaInterface::SetConversationValue(lua_State* state, vector<ConversationOption>* conversation) {
  1782. LUAConversationOptionWrapper* conv_wrapper = new LUAConversationOptionWrapper();
  1783. conv_wrapper->conversation_options = conversation;
  1784. AddUserDataPtr(conv_wrapper, conversation);
  1785. lua_pushlightuserdata(state, conv_wrapper);
  1786. }
  1787. void LuaInterface::SetOptionWindowValue(lua_State* state, vector<OptionWindowOption>* optionWindow) {
  1788. LUAOptionWindowWrapper* option_wrapper = new LUAOptionWindowWrapper();
  1789. option_wrapper->option_window_option = optionWindow;
  1790. AddUserDataPtr(option_wrapper, optionWindow);
  1791. lua_pushlightuserdata(state, option_wrapper);
  1792. }
  1793. void LuaInterface::SetItemValue(lua_State* state, Item* item) {
  1794. LUAItemWrapper* item_wrapper = new LUAItemWrapper();
  1795. item_wrapper->item = item;
  1796. AddUserDataPtr(item_wrapper, item);
  1797. lua_pushlightuserdata(state, item_wrapper);
  1798. }
  1799. void LuaInterface::SetSkillValue(lua_State* state, Skill* skill) {
  1800. LUASkillWrapper* skill_wrapper = new LUASkillWrapper();
  1801. skill_wrapper->skill = skill;
  1802. AddUserDataPtr(skill_wrapper, skill);
  1803. lua_pushlightuserdata(state, skill_wrapper);
  1804. }
  1805. void LuaInterface::SetQuestValue(lua_State* state, Quest* quest) {
  1806. LUAQuestWrapper* quest_wrapper = new LUAQuestWrapper();
  1807. quest_wrapper->quest = quest;
  1808. AddUserDataPtr(quest_wrapper, quest);
  1809. lua_pushlightuserdata(state, quest_wrapper);
  1810. }
  1811. void LuaInterface::SetZoneValue(lua_State* state, ZoneServer* zone) {
  1812. LUAZoneWrapper* zone_wrapper = new LUAZoneWrapper();
  1813. zone_wrapper->zone = zone;
  1814. AddUserDataPtr(zone_wrapper, zone);
  1815. lua_pushlightuserdata(state, zone_wrapper);
  1816. }
  1817. void LuaInterface::SetSpellValue(lua_State* state, LuaSpell* spell) {
  1818. LUASpellWrapper* spell_wrapper = new LUASpellWrapper();
  1819. spell_wrapper->spell = spell;
  1820. AddUserDataPtr(spell_wrapper, spell);
  1821. lua_pushlightuserdata(state, spell_wrapper);
  1822. }
  1823. LuaSpell* LuaInterface::GetSpell(const char* name) {
  1824. string lua_script = string(name);
  1825. if (lua_script.find(".lua") == string::npos)
  1826. lua_script.append(".lua");
  1827. if(spells.count(lua_script) > 0)
  1828. {
  1829. LogWrite(LUA__DEBUG, 0, "LUA", "Found LUA Spell Script: '%s'", lua_script.c_str());
  1830. LuaSpell* spell = spells[lua_script];
  1831. LuaSpell* new_spell = new LuaSpell;
  1832. new_spell->state = spell->state;
  1833. new_spell->file_name = string(spell->file_name);
  1834. new_spell->timer = spell->timer;
  1835. new_spell->timer.Disable();
  1836. new_spell->resisted = false;
  1837. new_spell->is_damage_spell = false;
  1838. new_spell->has_damaged = false;
  1839. new_spell->interrupted = false;
  1840. new_spell->crit = false;
  1841. new_spell->last_spellattack_hit = false;
  1842. new_spell->MSpellTargets.SetName("LuaSpell.MSpellTargets");
  1843. new_spell->cancel_after_all_triggers = false;
  1844. new_spell->num_triggers = 0;
  1845. new_spell->num_calls = 0;
  1846. new_spell->is_recast_timer = false;
  1847. new_spell->had_triggers = false;
  1848. new_spell->had_dmg_remaining = false;
  1849. new_spell->slot_pos = 0;
  1850. new_spell->damage_remaining = 0;
  1851. new_spell->effect_bitmask = 0;
  1852. new_spell->caster = 0;
  1853. new_spell->initial_target = 0;
  1854. new_spell->spell = 0;
  1855. new_spell->restored = false;
  1856. new_spell->initial_caster_char_id = 0;
  1857. new_spell->initial_target_char_id = 0;
  1858. return new_spell;
  1859. }
  1860. else{
  1861. LogWrite(LUA__ERROR, 0, "LUA", "Error LUA Spell Script: '%s'", name);
  1862. return 0;
  1863. }
  1864. }
  1865. Mutex* LuaInterface::GetItemScriptMutex(const char* name) {
  1866. Mutex* mutex = 0;
  1867. if(item_scripts_mutex.count(name) > 0)
  1868. mutex = item_scripts_mutex[name];
  1869. if(!mutex){
  1870. mutex = new Mutex();
  1871. item_scripts_mutex[name] = mutex;
  1872. }
  1873. return mutex;
  1874. }
  1875. Mutex* LuaInterface::GetSpawnScriptMutex(const char* name) {
  1876. Mutex* mutex = 0;
  1877. if(spawn_scripts_mutex.count(string(name)) > 0)
  1878. mutex = spawn_scripts_mutex[name];
  1879. if(!mutex){
  1880. mutex = new Mutex();
  1881. spawn_scripts_mutex[name] = mutex;
  1882. }
  1883. return mutex;
  1884. }
  1885. Mutex* LuaInterface::GetZoneScriptMutex(const char* name) {
  1886. Mutex* mutex = 0;
  1887. if(zone_scripts_mutex.count(name) > 0)
  1888. mutex = zone_scripts_mutex[name];
  1889. if(!mutex){
  1890. mutex = new Mutex();
  1891. zone_scripts_mutex[name] = mutex;
  1892. }
  1893. return mutex;
  1894. }
  1895. Mutex* LuaInterface::GetRegionScriptMutex(const char* name) {
  1896. Mutex* mutex = 0;
  1897. if(region_scripts_mutex.count(name) > 0)
  1898. mutex = region_scripts_mutex[name];
  1899. if(!mutex){
  1900. mutex = new Mutex();
  1901. region_scripts_mutex[name] = mutex;
  1902. }
  1903. return mutex;
  1904. }
  1905. void LuaInterface::UseItemScript(const char* name, lua_State* state, bool val) {
  1906. MItemScripts.writelock(__FUNCTION__, __LINE__);
  1907. item_scripts[name][state] = val;
  1908. item_inverse_scripts[state] = name;
  1909. MItemScripts.releasewritelock(__FUNCTION__, __LINE__);
  1910. }
  1911. void LuaInterface::UseSpawnScript(const char* name, lua_State* state, bool val) {
  1912. MSpawnScripts.writelock(__FUNCTION__, __LINE__);
  1913. spawn_scripts[name][state] = val;
  1914. spawn_inverse_scripts[state] = name;
  1915. MSpawnScripts.releasewritelock(__FUNCTION__, __LINE__);
  1916. }
  1917. void LuaInterface::UseZoneScript(const char* name, lua_State* state, bool val) {
  1918. MZoneScripts.writelock(__FUNCTION__, __LINE__);
  1919. zone_scripts[name][state] = val;
  1920. zone_inverse_scripts[state] = name;
  1921. MZoneScripts.releasewritelock(__FUNCTION__, __LINE__);
  1922. }
  1923. void LuaInterface::UseRegionScript(const char* name, lua_State* state, bool val) {
  1924. MRegionScripts.writelock(__FUNCTION__, __LINE__);
  1925. region_scripts[name][state] = val;
  1926. region_inverse_scripts[state] = name;
  1927. MRegionScripts.releasewritelock(__FUNCTION__, __LINE__);
  1928. }
  1929. lua_State* LuaInterface::GetItemScript(const char* name, bool create_new, bool use) {
  1930. map<string, map<lua_State*, bool> >::iterator itr;
  1931. map<lua_State*, bool>::iterator item_script_itr;
  1932. lua_State* ret = 0;
  1933. Mutex* mutex = 0;
  1934. itr = item_scripts.find(name);
  1935. if(itr != item_scripts.end()) {
  1936. mutex = GetItemScriptMutex(name);
  1937. mutex->readlock(__FUNCTION__, __LINE__);
  1938. for(item_script_itr = itr->second.begin(); item_script_itr != itr->second.end(); item_script_itr++){
  1939. if(!item_script_itr->second){ //not in use
  1940. ret = item_script_itr->first;
  1941. if (use)
  1942. {
  1943. item_script_itr->second = true;
  1944. break; // don't keep iterating, we already have our result
  1945. }
  1946. }
  1947. }
  1948. mutex->releasereadlock(__FUNCTION__, __LINE__);
  1949. }
  1950. if(!ret && create_new){
  1951. if(name && LoadItemScript(name))
  1952. ret = GetItemScript(name, create_new, use);
  1953. else{
  1954. LogError("Error LUA Item Script '%s'", name);
  1955. return 0;
  1956. }
  1957. }
  1958. return ret;
  1959. }
  1960. lua_State* LuaInterface::GetSpawnScript(const char* name, bool create_new, bool use) {
  1961. if (lua_system_reloading)
  1962. return 0;
  1963. map<string, map<lua_State*, bool> >::iterator itr;
  1964. map<lua_State*, bool>::iterator spawn_script_itr;
  1965. lua_State* ret = 0;
  1966. Mutex* mutex = 0;
  1967. itr = spawn_scripts.find(name);
  1968. if(itr != spawn_scripts.end()) {
  1969. mutex = GetSpawnScriptMutex(name);
  1970. mutex->readlock(__FUNCTION__, __LINE__);
  1971. for(spawn_script_itr = itr->second.begin(); spawn_script_itr != itr->second.end(); spawn_script_itr++){
  1972. if(!spawn_script_itr->second){ //not in use
  1973. ret = spawn_script_itr->first;
  1974. if (use)
  1975. {
  1976. spawn_script_itr->second = true;
  1977. break; // don't keep iterating, we already have our result
  1978. }
  1979. }
  1980. }
  1981. mutex->releasereadlock(__FUNCTION__, __LINE__);
  1982. }
  1983. if(!ret && create_new){
  1984. if(name && LoadSpawnScript(name))
  1985. ret = GetSpawnScript(name, create_new, use);
  1986. else{
  1987. LogError("Error LUA Spawn Script '%s'", name);
  1988. return 0;
  1989. }
  1990. }
  1991. return ret;
  1992. }
  1993. lua_State* LuaInterface::GetZoneScript(const char* name, bool create_new, bool use) {
  1994. map<string, map<lua_State*, bool> >::iterator itr;
  1995. map<lua_State*, bool>::iterator zone_script_itr;
  1996. lua_State* ret = 0;
  1997. Mutex* mutex = 0;
  1998. itr = zone_scripts.find(name);
  1999. if(itr != zone_scripts.end()) {
  2000. mutex = GetZoneScriptMutex(name);
  2001. mutex->readlock(__FUNCTION__, __LINE__);
  2002. for(zone_script_itr = itr->second.begin(); zone_script_itr != itr->second.end(); zone_script_itr++){
  2003. if(!zone_script_itr->second){ //not in use
  2004. ret = zone_script_itr->first;
  2005. if (use)
  2006. {
  2007. zone_script_itr->second = true;
  2008. break; // don't keep iterating, we already have our result
  2009. }
  2010. }
  2011. }
  2012. mutex->releasereadlock(__FUNCTION__, __LINE__);
  2013. }
  2014. if(!ret && create_new){
  2015. if(name && LoadZoneScript(name))
  2016. ret = GetZoneScript(name);
  2017. else{
  2018. LogError("Error LUA Zone Script '%s'", name);
  2019. return 0;
  2020. }
  2021. }
  2022. return ret;
  2023. }
  2024. lua_State* LuaInterface::GetRegionScript(const char* name, bool create_new, bool use) {
  2025. map<string, map<lua_State*, bool> >::iterator itr;
  2026. map<lua_State*, bool>::iterator region_script_itr;
  2027. lua_State* ret = 0;
  2028. Mutex* mutex = 0;
  2029. itr = region_scripts.find(name);
  2030. if(itr != region_scripts.end()) {
  2031. mutex = GetRegionScriptMutex(name);
  2032. mutex->readlock(__FUNCTION__, __LINE__);
  2033. for(region_script_itr = itr->second.begin(); region_script_itr != itr->second.end(); region_script_itr++){
  2034. if(!region_script_itr->second){ //not in use
  2035. ret = region_script_itr->first;
  2036. if (use)
  2037. {
  2038. region_script_itr->second = true;
  2039. break; // don't keep iterating, we already have our result
  2040. }
  2041. }
  2042. }
  2043. mutex->releasereadlock(__FUNCTION__, __LINE__);
  2044. }
  2045. if(!ret && create_new){
  2046. if(name && LoadRegionScript(name))
  2047. ret = GetRegionScript(name);
  2048. else{
  2049. LogError("Error LUA Zone Script '%s'", name);
  2050. return 0;
  2051. }
  2052. }
  2053. return ret;
  2054. }
  2055. bool LuaInterface::RunItemScript(string script_name, const char* function_name, Item* item, Spawn* spawn, Spawn* target, sint64* returnValue) {
  2056. if(!item)
  2057. return false;
  2058. lua_State* state = GetItemScript(script_name.c_str(), true, true);
  2059. if(state){
  2060. Mutex* mutex = GetItemScriptMutex(script_name.c_str());
  2061. if(mutex)
  2062. mutex->readlock(__FUNCTION__, __LINE__);
  2063. else{
  2064. LogError("Error getting lock for '%s'", script_name.c_str());
  2065. UseItemScript(script_name.c_str(), state, false);
  2066. return false;
  2067. }
  2068. lua_getglobal(state, function_name);
  2069. if (!lua_isfunction(state, lua_gettop(state))){
  2070. lua_pop(state, 1);
  2071. mutex->releasereadlock(__FUNCTION__);
  2072. UseItemScript(script_name.c_str(), state, false);
  2073. return false;
  2074. }
  2075. SetItemValue(state, item);
  2076. int8 num_parms = 1;
  2077. if(spawn){
  2078. SetSpawnValue(state, spawn);
  2079. num_parms++;
  2080. }
  2081. if(target){
  2082. SetSpawnValue(state, target);
  2083. num_parms++;
  2084. }
  2085. if(!CallItemScript(state, num_parms, returnValue)){
  2086. if(mutex)
  2087. mutex->releasereadlock(__FUNCTION__, __LINE__);
  2088. UseItemScript(script_name.c_str(), state, false);
  2089. return false;
  2090. }
  2091. if(mutex)
  2092. mutex->releasereadlock(__FUNCTION__, __LINE__);
  2093. UseItemScript(script_name.c_str(), state, false);
  2094. return true;
  2095. }
  2096. else
  2097. return false;
  2098. }
  2099. bool LuaInterface::RunItemScriptWithReturnString(string script_name, const char* function_name, Item* item, Spawn* spawn, std::string* returnValue) {
  2100. if(!item)
  2101. return false;
  2102. lua_State* state = GetItemScript(script_name.c_str(), true, true);
  2103. if(state){
  2104. Mutex* mutex = GetItemScriptMutex(script_name.c_str());
  2105. if(mutex)
  2106. mutex->readlock(__FUNCTION__, __LINE__);
  2107. else{
  2108. LogError("Error getting lock for '%s'", script_name.c_str());
  2109. UseItemScript(script_name.c_str(), state, false);
  2110. return false;
  2111. }
  2112. lua_getglobal(state, function_name);
  2113. if (!lua_isfunction(state, lua_gettop(state))){
  2114. lua_pop(state, 1);
  2115. mutex->releasereadlock(__FUNCTION__);
  2116. UseItemScript(script_name.c_str(), state, false);
  2117. return false;
  2118. }
  2119. SetItemValue(state, item);
  2120. int8 num_parms = 1;
  2121. if(spawn){
  2122. SetSpawnValue(state, spawn);
  2123. num_parms++;
  2124. }
  2125. if(!CallItemScript(state, num_parms, returnValue)){
  2126. if(mutex)
  2127. mutex->releasereadlock(__FUNCTION__, __LINE__);
  2128. UseItemScript(script_name.c_str(), state, false);
  2129. return false;
  2130. }
  2131. if(mutex)
  2132. mutex->releasereadlock(__FUNCTION__, __LINE__);
  2133. UseItemScript(script_name.c_str(), state, false);
  2134. return true;
  2135. }
  2136. else
  2137. return false;
  2138. }
  2139. bool LuaInterface::RunSpawnScript(string script_name, const char* function_name, Spawn* npc, Spawn* spawn, const char* message, bool is_door_open, sint32 input_value, sint32* return_value) {
  2140. if(!npc || lua_system_reloading)
  2141. return false;
  2142. bool isUseDoorFunction = false;
  2143. if(!strcmp(function_name,"usedoor"))
  2144. isUseDoorFunction = true;
  2145. lua_State* state = GetSpawnScript(script_name.c_str(), true, true);
  2146. if(state){
  2147. Mutex* mutex = GetSpawnScriptMutex(script_name.c_str());
  2148. if(mutex)
  2149. mutex->readlock(__FUNCTION__, __LINE__);
  2150. else{
  2151. LogError("Error getting lock for '%s'", script_name.c_str());
  2152. UseSpawnScript(script_name.c_str(), state, false);
  2153. return false;
  2154. }
  2155. lua_getglobal(state, function_name);
  2156. if (!lua_isfunction(state, lua_gettop(state))){
  2157. lua_pop(state, 1);
  2158. mutex->releasereadlock(__FUNCTION__);
  2159. UseSpawnScript(script_name.c_str(), state, false);
  2160. return false;
  2161. }
  2162. SetSpawnValue(state, npc);
  2163. int8 num_parms = 1;
  2164. // we always send spawn, even if null (nil) when its 'usedoor' function
  2165. if(spawn || isUseDoorFunction){
  2166. SetSpawnValue(state, spawn);
  2167. num_parms++;
  2168. }
  2169. // usedoor function always passes just npc, spawn and is_door_open
  2170. if(isUseDoorFunction){
  2171. SetBooleanValue(state, is_door_open);
  2172. num_parms++;
  2173. }
  2174. else {
  2175. if(message){
  2176. SetStringValue(state, message);
  2177. num_parms++;
  2178. }
  2179. if(!strcmp(function_name,"healthchanged"))
  2180. {
  2181. // passes as damage dealt
  2182. SetSInt32Value(state, input_value);
  2183. num_parms++;
  2184. }
  2185. }
  2186. if(!CallScriptSInt32(state, num_parms, return_value)){
  2187. if(mutex)
  2188. mutex->releasereadlock(__FUNCTION__, __LINE__);
  2189. UseSpawnScript(script_name.c_str(), state, false);
  2190. return false;
  2191. }
  2192. if(mutex)
  2193. mutex->releasereadlock(__FUNCTION__, __LINE__);
  2194. UseSpawnScript(script_name.c_str(), state, false);
  2195. return true;
  2196. }
  2197. else
  2198. return false;
  2199. }
  2200. bool LuaInterface::RunZoneScript(string script_name, const char* function_name, ZoneServer* zone, Spawn* spawn, int32 int32_arg1, const char* str_arg1, Spawn* spawn_arg1, int32 int32_arg2, const char* str_arg2, Spawn* spawn_arg2) {
  2201. if (!zone)
  2202. return false;
  2203. lua_State* state = GetZoneScript(script_name.c_str(), true, true);
  2204. if (state) {
  2205. Mutex* mutex = GetZoneScriptMutex(script_name.c_str());
  2206. if (mutex)
  2207. mutex->readlock(__FUNCTION__, __LINE__);
  2208. else {
  2209. LogError("Error getting lock for '%s'", script_name.c_str());
  2210. UseZoneScript(script_name.c_str(), state, false);
  2211. return false;
  2212. }
  2213. lua_getglobal(state, function_name);
  2214. if (!lua_isfunction(state, lua_gettop(state))) {
  2215. lua_pop(state, 1);
  2216. mutex->releasereadlock(__FUNCTION__);
  2217. UseZoneScript(script_name.c_str(), state, false);
  2218. return false;
  2219. }
  2220. SetZoneValue(state, zone);
  2221. int8 num_params = 1;
  2222. if (spawn) {
  2223. SetSpawnValue(state, spawn);
  2224. num_params++;
  2225. }
  2226. if (int32_arg1 > 0) {
  2227. SetInt32Value(state, int32_arg1);
  2228. num_params++;
  2229. }
  2230. if (str_arg1) {
  2231. SetStringValue(state, str_arg1);
  2232. num_params++;
  2233. }
  2234. if (spawn_arg1) {
  2235. SetSpawnValue(state, spawn_arg1);
  2236. num_params++;
  2237. }
  2238. if (int32_arg2 > 0) {
  2239. SetInt32Value(state, int32_arg2);
  2240. num_params++;
  2241. }
  2242. if (str_arg2) {
  2243. SetStringValue(state, str_arg2);
  2244. num_params++;
  2245. }
  2246. if (spawn_arg2) {
  2247. SetSpawnValue(state, spawn_arg2);
  2248. num_params++;
  2249. }
  2250. if (!CallScriptInt32(state, num_params)) {
  2251. if (mutex)
  2252. mutex->releasereadlock(__FUNCTION__, __LINE__);
  2253. UseZoneScript(script_name.c_str(), state, false);
  2254. return false;
  2255. }
  2256. if (mutex)
  2257. mutex->releasereadlock(__FUNCTION__, __LINE__);
  2258. UseZoneScript(script_name.c_str(), state, false);
  2259. return true;
  2260. }
  2261. else
  2262. return false;
  2263. }
  2264. bool LuaInterface::RunZoneScriptWithReturn(string script_name, const char* function_name, ZoneServer* zone, Spawn* spawn, int32 int32_arg1, int32 int32_arg2, int32 int32_arg3, int32* returnValue) {
  2265. if (!zone)
  2266. return false;
  2267. lua_State* state = GetZoneScript(script_name.c_str(), true, true);
  2268. if (state) {
  2269. Mutex* mutex = GetZoneScriptMutex(script_name.c_str());
  2270. if (mutex)
  2271. mutex->readlock(__FUNCTION__, __LINE__);
  2272. else {
  2273. LogError("Error getting lock for '%s'", script_name.c_str());
  2274. UseZoneScript(script_name.c_str(), state, false);
  2275. return false;
  2276. }
  2277. lua_getglobal(state, function_name);
  2278. if (!lua_isfunction(state, lua_gettop(state))) {
  2279. lua_pop(state, 1);
  2280. mutex->releasereadlock(__FUNCTION__);
  2281. UseZoneScript(script_name.c_str(), state, false);
  2282. return false;
  2283. }
  2284. SetZoneValue(state, zone);
  2285. int8 num_params = 1;
  2286. SetSpawnValue(state, spawn);
  2287. num_params++;
  2288. SetInt32Value(state, int32_arg1);
  2289. num_params++;
  2290. SetInt32Value(state, int32_arg2);
  2291. num_params++;
  2292. SetInt32Value(state, int32_arg3);
  2293. num_params++;
  2294. if (!CallScriptInt32(state, num_params, returnValue)) {
  2295. if (mutex)
  2296. mutex->releasereadlock(__FUNCTION__, __LINE__);
  2297. UseZoneScript(script_name.c_str(), state, false);
  2298. return false;
  2299. }
  2300. if (mutex)
  2301. mutex->releasereadlock(__FUNCTION__, __LINE__);
  2302. UseZoneScript(script_name.c_str(), state, false);
  2303. return true;
  2304. }
  2305. else
  2306. return false;
  2307. }
  2308. bool LuaInterface::RunRegionScript(string script_name, const char* function_name, ZoneServer* zone, Spawn* spawn, sint32 int32_arg1, int32* returnValue) {
  2309. if (!zone)
  2310. return false;
  2311. lua_State* state = GetRegionScript(script_name.c_str(), true, true);
  2312. if (state) {
  2313. Mutex* mutex = GetRegionScriptMutex(script_name.c_str());
  2314. if (mutex)
  2315. mutex->readlock(__FUNCTION__, __LINE__);
  2316. else {
  2317. LogError("Error getting lock for '%s'", script_name.c_str());
  2318. UseRegionScript(script_name.c_str(), state, false);
  2319. return false;
  2320. }
  2321. lua_getglobal(state, function_name);
  2322. if (!lua_isfunction(state, lua_gettop(state))) {
  2323. lua_pop(state, 1);
  2324. mutex->releasereadlock(__FUNCTION__);
  2325. UseRegionScript(script_name.c_str(), state, false);
  2326. return false;
  2327. }
  2328. SetZoneValue(state, zone);
  2329. int8 num_params = 1;
  2330. if (spawn) {
  2331. SetSpawnValue(state, spawn);
  2332. num_params++;
  2333. }
  2334. if (int32_arg1 > 0) {
  2335. SetSInt32Value(state, int32_arg1);
  2336. num_params++;
  2337. }
  2338. if (!CallRegionScript(state, num_params, returnValue)) {
  2339. if (mutex)
  2340. mutex->releasereadlock(__FUNCTION__, __LINE__);
  2341. UseRegionScript(script_name.c_str(), state, false);
  2342. return false;
  2343. }
  2344. if (mutex)
  2345. mutex->releasereadlock(__FUNCTION__, __LINE__);
  2346. UseRegionScript(script_name.c_str(), state, false);
  2347. return true;
  2348. }
  2349. else
  2350. return false;
  2351. }
  2352. void LuaInterface::AddPendingSpellDelete(LuaSpell* spell) {
  2353. MSpellDelete.lock();
  2354. if ( spells_pending_delete.count(spell) == 0 )
  2355. spells_pending_delete[spell] = Timer::GetCurrentTime2() + 10000;
  2356. MSpellDelete.unlock();
  2357. }
  2358. void LuaInterface::AddCustomSpell(LuaSpell* spell)
  2359. {
  2360. MCustomSpell.writelock();
  2361. custom_spells[spell->spell->GetSpellID()] = spell;
  2362. MCustomSpell.releasewritelock();
  2363. }
  2364. void LuaInterface::RemoveCustomSpell(int32 id)
  2365. {
  2366. MCustomSpell.writelock();
  2367. map<int32, LuaSpell*>::iterator itr = custom_spells.find(id);
  2368. if (itr != custom_spells.end())
  2369. {
  2370. custom_spells.erase(itr);
  2371. custom_free_spell_ids.push_front(id);
  2372. }
  2373. MCustomSpell.releasewritelock();
  2374. }
  2375. // prior to calling FindCustomSpell you should call FindCustomSpellLock and after FindCustomSpellUnlock
  2376. LuaSpell* LuaInterface::FindCustomSpell(int32 id)
  2377. {
  2378. LuaSpell* spell = 0;
  2379. map<int32, LuaSpell*>::iterator itr = custom_spells.find(id);
  2380. if (itr != custom_spells.end())
  2381. spell = itr->second;
  2382. return spell;
  2383. }
  2384. int32 LuaInterface::GetFreeCustomSpellID()
  2385. {
  2386. int32 id = 0;
  2387. MCustomSpell.writelock();
  2388. if (!custom_free_spell_ids.empty())
  2389. {
  2390. id = custom_free_spell_ids.front();
  2391. custom_free_spell_ids.pop_front();
  2392. }
  2393. MCustomSpell.releasewritelock();
  2394. return id;
  2395. }
  2396. void LuaInterface::SetLuaUserDataStale(void* ptr) {
  2397. std::unique_lock lock(MLUAUserData);
  2398. std::map<void*, LUAUserData*>::iterator itr = user_data_ptr.find(ptr);
  2399. if(itr != user_data_ptr.end()) {
  2400. itr->second->correctly_initialized = false;
  2401. }
  2402. }
  2403. LUAUserData::LUAUserData(){
  2404. correctly_initialized = false;
  2405. quest = 0;
  2406. conversation_options = 0;
  2407. spawn = 0;
  2408. zone = 0;
  2409. skill = 0;
  2410. option_window_option = 0;
  2411. item = 0;
  2412. }
  2413. bool LUAUserData::IsCorrectlyInitialized(){
  2414. return correctly_initialized;
  2415. }
  2416. bool LUAUserData::IsConversationOption(){
  2417. return false;
  2418. }
  2419. bool LUAUserData::IsOptionWindow() {
  2420. return false;
  2421. }
  2422. bool LUAUserData::IsSpawn(){
  2423. return false;
  2424. }
  2425. bool LUAUserData::IsQuest(){
  2426. return false;
  2427. }
  2428. bool LUAUserData::IsZone(){
  2429. return false;
  2430. }
  2431. bool LUAUserData::IsItem(){
  2432. return false;
  2433. }
  2434. bool LUAUserData::IsSkill() {
  2435. return false;
  2436. }
  2437. bool LUAUserData::IsSpell() {
  2438. return false;
  2439. }
  2440. LUAConversationOptionWrapper::LUAConversationOptionWrapper(){
  2441. correctly_initialized = true;
  2442. }
  2443. bool LUAConversationOptionWrapper::IsConversationOption(){
  2444. return true;
  2445. }
  2446. LUAOptionWindowWrapper::LUAOptionWindowWrapper() {
  2447. correctly_initialized = true;
  2448. }
  2449. bool LUAOptionWindowWrapper::IsOptionWindow() {
  2450. return true;
  2451. }
  2452. LUASpawnWrapper::LUASpawnWrapper(){
  2453. correctly_initialized = true;
  2454. }
  2455. bool LUASpawnWrapper::IsSpawn(){
  2456. return true;
  2457. }
  2458. LUAZoneWrapper::LUAZoneWrapper(){
  2459. correctly_initialized = true;
  2460. }
  2461. bool LUAZoneWrapper::IsZone(){
  2462. return true;
  2463. }
  2464. LUAQuestWrapper::LUAQuestWrapper(){
  2465. correctly_initialized = true;
  2466. }
  2467. bool LUAQuestWrapper::IsQuest(){
  2468. return true;
  2469. }
  2470. LUAItemWrapper::LUAItemWrapper(){
  2471. correctly_initialized = true;
  2472. }
  2473. bool LUAItemWrapper::IsItem(){
  2474. return true;
  2475. }
  2476. LUASkillWrapper::LUASkillWrapper() {
  2477. correctly_initialized = true;
  2478. }
  2479. bool LUASkillWrapper::IsSkill() {
  2480. return true;
  2481. }
  2482. LUASpellWrapper::LUASpellWrapper() {
  2483. correctly_initialized = true;
  2484. }
  2485. bool LUASpellWrapper::IsSpell() {
  2486. return true;
  2487. }