LuaInterface.cpp 101 KB

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