void LuaEngine::Restart() { m_Lock.Acquire(); lua_close(L); L = lua_open(); LoadScripts(); m_Lock.Release(); }
BOOL KScriptManager::LoadScripts(ILuaScriptEx* piScript, const char cszDir[]) { BOOL bResult = false; BOOL bRetCode = false; HANDLE hFind = INVALID_HANDLE_VALUE; WIN32_FIND_DATA FindFileData; char szPath[MAX_PATH]; snprintf(szPath, sizeof(szPath), "%s\\*", cszDir); szPath[sizeof(szPath) - 1] = '\0'; hFind = FindFirstFile(szPath, &FindFileData); KGLOG_PROCESS_ERROR(hFind != INVALID_HANDLE_VALUE); if (hFind == INVALID_HANDLE_VALUE) { KGLogPrintf(KGLOG_ERR, "[Lua] Failed to file file: %s\n", szPath); } do { if (FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { if (strcmp(FindFileData.cFileName, ".") != 0 && strcmp(FindFileData.cFileName, "..") != 0) { snprintf(szPath, sizeof(szPath), "%s\\%s", cszDir, FindFileData.cFileName); szPath[sizeof(szPath) - 1] = '\0'; LoadScripts(piScript, szPath); } } else { snprintf(szPath, sizeof(szPath), "%s\\%s", cszDir, FindFileData.cFileName); szPath[sizeof(szPath) - 1] = '\0'; bRetCode = IsLuaScriptFile(szPath); if (bRetCode) { bRetCode = piScript->LoadFromFile(szPath); if (!bRetCode) { KGLogPrintf(KGLOG_ERR, "[Lua] Failed to load file: %s\n", szPath); } } } } while (FindNextFile(hFind, &FindFileData)); bResult = true; Exit0: if (hFind != INVALID_HANDLE_VALUE) { FindClose(hFind); hFind = INVALID_HANDLE_VALUE; } return bResult; }
void CLuaOptions::OnReload(CCtrlBase*) { isScriptListInit = false; m_scripts.DeleteAllItems(); g_mLua->Unload(); g_mLua->Load(); LoadScripts(); isScriptListInit = true; }
nsresult nsDOMWorkerScriptLoader::LoadScript(JSContext* aCx, const nsString& aURL, PRBool aForWorker) { nsAutoTArray<nsString, 1> url; url.AppendElement(aURL); return LoadScripts(aCx, url, aForWorker); }
void ScriptMgr::LoadQuestStartScripts() { LoadScripts(sQuestStartScripts, "quest_start_scripts"); // check ids for(ScriptMapMap::const_iterator itr = sQuestStartScripts.begin(); itr != sQuestStartScripts.end(); ++itr) { if (!sObjectMgr.GetQuestTemplate(itr->first)) sLog.outErrorDb("Table `quest_start_scripts` has not existing quest (Id: %u) as script id", itr->first); } }
void ScriptMgr::LoadGameObjectScripts() { LoadScripts(sGameObjectScripts, "gameobject_scripts"); // check ids for(ScriptMapMap::const_iterator itr = sGameObjectScripts.begin(); itr != sGameObjectScripts.end(); ++itr) { if (!sObjectMgr.GetGOData(itr->first)) sLog.outErrorDb("Table `gameobject_scripts` has not existing gameobject (GUID: %u) as script id", itr->first); } }
nsresult nsDOMWorkerScriptLoader::LoadWorkerScript(JSContext* aCx, const nsString& aURL) { mForWorker = PR_TRUE; nsAutoTArray<nsString, 1> url; url.AppendElement(aURL); return LoadScripts(aCx, url, PR_FALSE); }
void ScriptMgr::LoadEventScripts() { LoadScripts(sEventScripts, "event_scripts"); std::set<uint32> evt_scripts; // Load all possible script entries from gameobjects for(uint32 i = 1; i < sGOStorage.MaxEntry; ++i) if (GameObjectInfo const* goInfo = sGOStorage.LookupEntry<GameObjectInfo>(i)) if (uint32 eventId = goInfo->GetEventScriptId()) evt_scripts.insert(eventId); // Load all possible script entries from spells for(uint32 i = 1; i < sSpellStore.GetNumRows(); ++i) { SpellEntry const* spell = sSpellStore.LookupEntry(i); if (spell) { for(int j = 0; j < MAX_EFFECT_INDEX; ++j) { if (spell->Effect[j] == SPELL_EFFECT_SEND_EVENT) { if (spell->EffectMiscValue[j]) evt_scripts.insert(spell->EffectMiscValue[j]); } } } } for(size_t path_idx = 0; path_idx < sTaxiPathNodesByPath.size(); ++path_idx) { for(size_t node_idx = 0; node_idx < sTaxiPathNodesByPath[path_idx].size(); ++node_idx) { TaxiPathNodeEntry const& node = sTaxiPathNodesByPath[path_idx][node_idx]; if (node.arrivalEventID) evt_scripts.insert(node.arrivalEventID); if (node.departureEventID) evt_scripts.insert(node.departureEventID); } } // Then check if all scripts are in above list of possible script entries for(ScriptMapMap::const_iterator itr = sEventScripts.begin(); itr != sEventScripts.end(); ++itr) { std::set<uint32>::const_iterator itr2 = evt_scripts.find(itr->first); if (itr2 == evt_scripts.end()) sLog.outErrorDb("Table `event_scripts` has script (Id: %u) not referring to any gameobject_template type 10 data2 field, type 3 data6 field, type 13 data 2 field or any spell effect %u or path taxi node data", itr->first, SPELL_EFFECT_SEND_EVENT); } }
BOOL KScriptManager::LoadScripts(ILuaScriptEx* piScript, const char cszDir[]) { BOOL bResult = false; BOOL bRetCode = false; DIR* pDir = NULL; struct dirent* pDirNode = NULL; char szPath[MAX_PATH]; pDir = opendir(cszDir); KGLOG_PROCESS_ERROR(pDir); while (pDirNode = readdir(pDir)) { if(strcmp(pDirNode->d_name, ".") == 0 || strcmp(pDirNode->d_name, "..") == 0) continue; if(pDirNode->d_type == DT_DIR) { snprintf(szPath, sizeof(szPath), "%s/%s", cszDir, pDirNode->d_name); szPath[sizeof(szPath) - 1] = '\0'; LoadScripts(piScript, szPath); continue; } snprintf(szPath, sizeof(szPath), "%s/%s", cszDir, pDirNode->d_name); szPath[sizeof(szPath) - 1] = '\0'; bRetCode = IsLuaScriptFile(szPath); if (bRetCode) { bRetCode = piScript->LoadFromFile(szPath); if (!bRetCode) { KGLogPrintf(KGLOG_ERR, "[Lua] Failed to load file: %s\n", szPath); } } } bResult = true; Exit0: if (pDir != NULL) { closedir(pDir); pDir = NULL; } return bResult; }
BOOL KScriptManager::Load() { BOOL bResult = false; BOOL bRetCode = false; ILuaScriptEx* piScript = NULL; lua_State* pLuaState = NULL; piScript = CreateLuaInterface(&KMemory::LuaAllocator, NULL); KGLOG_PROCESS_ERROR(piScript); bRetCode = RegisterScriptFunctions(piScript); KGLOG_PROCESS_ERROR(bRetCode); piScript->RegisterConstList(g_LuaServerConstList); pLuaState = piScript->GetLuaState(); KGLOG_PROCESS_ERROR(pLuaState); Luna<KScene>::Register(pLuaState); Luna<KHero>::Register(pLuaState); Luna<KPlayer>::Register(pLuaState); Luna<KAILogic>::Register(pLuaState); Luna<KAIState>::Register(pLuaState); Luna<KAIAction>::Register(pLuaState); Luna<KGItem>::Register(pLuaState); Luna<KGLuaItemInfo>::Register(pLuaState); Luna<KBall>::Register(pLuaState); bRetCode = LoadScripts(piScript, SERVER_SCRIPTS_DIR); KGLOG_PROCESS_ERROR(bRetCode); lua_gc(piScript->GetLuaState(), LUA_GCRESTART, 0); lua_gc(piScript->GetLuaState(), LUA_GCSETPAUSE, 100); lua_gc(piScript->GetLuaState(), LUA_GCSETSTEPMUL, 150); KG_COM_RELEASE(m_piScript); m_piScript = piScript; piScript = NULL; bResult = true; Exit0: KG_COM_RELEASE(piScript); return bResult; }
int LoadScript(unsigned char* fileName) { wchar_t *temp2 = UTF8toUTF16Alloc(fileName); int res = -2; if (temp2) { wchar_t path2[2*MAX_PATH+2]; int l3; l3 = GetModuleFileNameW(0, path2, 2*MAX_PATH+2); int index; res = AddFile(temp2, path2, index); free(temp2); } if (res == -2) { errorPrintf(2, "Error Loading: %s\r\n", fileName); errors++; return 0; } if (res != -1) return 1; return LoadScripts(); }
void CLuaOptions::OnInitDialog() { CDlgBase::OnInitDialog(); m_scripts.SetExtendedListViewStyle(LVS_EX_SUBITEMIMAGES | LVS_EX_FULLROWSELECT | LVS_EX_CHECKBOXES | LVS_EX_INFOTIP); HIMAGELIST hImageList = m_scripts.CreateImageList(LVSIL_SMALL); ImageList_AddIcon(hImageList, GetIcon(IDI_OPEN)); TCHAR scriptDir[MAX_PATH], relativeScriptDir[MAX_PATH], header[MAX_PATH + 100]; FoldersGetCustomPathT(g_hScriptsFolder, scriptDir, _countof(scriptDir), VARST(MIRLUA_PATHT)); PathToRelativeT(scriptDir, relativeScriptDir, NULL); mir_sntprintf(header, _T("%s (%s)"), TranslateT("Common scripts"), relativeScriptDir); m_scripts.AddColumn(0, _T("Script"), 420); m_scripts.AddColumn(1, NULL, 32 - GetSystemMetrics(SM_CXVSCROLL)); LoadScripts(); isScriptListInit = true; }
BOOL KScriptManager::Load() { BOOL bResult = false; BOOL bRetCode = false; ILuaScriptEx* piScript = NULL; piScript = CreateLuaInterface(&KMemory::LuaAllocator, NULL); KGLOG_PROCESS_ERROR(piScript); bRetCode = RegisterScriptFunctions(piScript); KGLOG_PROCESS_ERROR(bRetCode); piScript->RegisterConstList(g_LuaCenterConstList); Luna<KGPQ>::Register(piScript->GetLuaState()); Luna<KGlobalCustomDataManager>::Register(piScript->GetLuaState()); Luna<KGlobalSystemValueManager>::Register(piScript->GetLuaState()); Luna<KRole>::Register(piScript->GetLuaState()); Luna<KTong>::Register(piScript->GetLuaState()); Luna<KActivityManager>::Register(piScript->GetLuaState()); Luna<KMentorCenter>::Register(piScript->GetLuaState()); Luna<KMapInfo>::Register(piScript->GetLuaState()); Luna<KMapCopy>::Register(piScript->GetLuaState()); bRetCode = LoadScripts(piScript, CENTER_SCRIPTS_DIR); KGLOG_PROCESS_ERROR(bRetCode); lua_gc(piScript->GetLuaState(), LUA_GCRESTART, 0); lua_gc(piScript->GetLuaState(), LUA_GCSETPAUSE, 100); lua_gc(piScript->GetLuaState(), LUA_GCSETSTEPMUL, 150); KG_COM_RELEASE(m_piScript); m_piScript = piScript; piScript = NULL; bResult = true; Exit0: KG_COM_RELEASE(piScript); return bResult; }
bool Initialise(bool callConstructor) { if (!LoadScripts(m_AIName)) return false; OsPath path = L"simulation/ai/" + m_AIName + L"/data.json"; CScriptValRooted metadata = m_Worker.LoadMetadata(path); if (metadata.uninitialised()) { LOGERROR(L"Failed to create AI player: can't find %ls", path.string().c_str()); return false; } // Get the constructor name from the metadata std::string constructor; if (!m_ScriptInterface.GetProperty(metadata.get(), "constructor", constructor)) { LOGERROR(L"Failed to create AI player: %ls: missing 'constructor'", path.string().c_str()); return false; } // Get the constructor function from the loaded scripts CScriptVal ctor; if (!m_ScriptInterface.GetProperty(m_ScriptInterface.GetGlobalObject(), constructor.c_str(), ctor) || ctor.undefined()) { LOGERROR(L"Failed to create AI player: %ls: can't find constructor '%hs'", path.string().c_str(), constructor.c_str()); return false; } m_ScriptInterface.GetProperty(metadata.get(), "useShared", m_UseSharedComponent); CScriptVal obj; if (callConstructor) { // Set up the data to pass as the constructor argument CScriptVal settings; m_ScriptInterface.Eval(L"({})", settings); m_ScriptInterface.SetProperty(settings.get(), "player", m_Player, false); ENSURE(m_Worker.m_HasLoadedEntityTemplates); m_ScriptInterface.SetProperty(settings.get(), "templates", m_Worker.m_EntityTemplates, false); obj = m_ScriptInterface.CallConstructor(ctor.get(), settings.get()); } else { // For deserialization, we want to create the object with the correct prototype // but don't want to actually run the constructor again // XXX: actually we don't currently use this path for deserialization - maybe delete it? obj = m_ScriptInterface.NewObjectFromConstructor(ctor.get()); } if (obj.undefined()) { LOGERROR(L"Failed to create AI player: %ls: error calling constructor '%hs'", path.string().c_str(), constructor.c_str()); return false; } m_Obj = CScriptValRooted(m_ScriptInterface.GetContext(), obj); return true; }
void ScriptMgr::LoadGossipScripts() { LoadScripts(sGossipScripts, "gossip_scripts"); // checks are done in LoadGossipMenuItems }
void World::Load() { try { sLog.Write("Connect to database..."); sDatabase.Connect(); sLog.Write("Connected to database."); sLog.Write("Loading creature templates..."); sObjectMgr.LoadCreatureTemplates(); sLog.Write("Creature templates loaded."); sLog.Write("Loading creature quests..."); sObjectMgr.LoadCreatureQuests(); sLog.Write("Creature quests loaded."); sLog.Write("Loading spell templates..."); sObjectMgr.LoadSpellTemplates(); sLog.Write("Spells loaded."); sLog.Write("Loading gameobject templates..."); sObjectMgr.LoadGameObjectTemplates(); sLog.Write("Gameobject templates loaded."); sLog.Write("Loading map templates..."); sObjectMgr.LoadMapTemplates(); sLog.Write("Map templates loaded."); sLog.Write("Loading players login informations..."); sObjectMgr.LoadPlayersLoginInfo(); sLog.Write("Players login informations loaded."); sLog.Write("Loading scripts..."); LoadScripts(); sLog.Write("Scripts loaded."); sLog.Write("Init Pathfinding..."); Pathfinder::Init(); sLog.Write("Pathfinding initialized."); sLog.Write("Loading maps..."); QueryResult Result(sDatabase.Query("SELECT * FROM `map`")); Map* pMap; while(Result->next()) { pMap = new Map(sObjectMgr.GetMapTemplate(Result->getUInt(2)), Result->getUInt(1)); pMap->Load(); Maps.push_back(pMap); sLog.Write("Map %u loaded.", Result->getUInt(1)); } sLog.Write("Maps loaded."); } catch(sql::SQLException &e) { sLog << "SQL Exception: " << e.what() << '\n'; throw; } catch(std::exception &e) { sLog << "Exception: " << e.what() << '\n'; throw; } }
void ScriptMgr::LoadCreatureMovementScripts() { LoadScripts(sCreatureMovementScripts, "creature_movement_scripts"); // checks are done in WaypointManager::Load }