LuaInterface.cpp 101 KB

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