void MenuSetup(void)
{
	if ( ( isMenu = !isMenu ) )
	{
		STOP_MOBILE_PHONE_RINGING();
		DESTROY_MOBILE_PHONE();
		TERMINATE_ALL_SCRIPTS_WITH_THIS_NAME( isNetGame?"mpcellphone":"spcellphone" );
		DISABLE_FRONTEND_RADIO();
		if ( !IS_FONT_LOADED( MYFONT ) ) LOAD_TEXT_FONT( MYFONT );
	}
	else
	{
		ENABLE_FRONTEND_RADIO();
		if ( !isNetGame ) LoadScript("spcellphone");
		else if ( isNetPhoneEnabled ) LoadScript("mpcellphone");
	}
	
	DISPLAY_AREA_NAME(FALSE);
	DISPLAY_CASH(FALSE);
	DISPLAY_FRONTEND_MAP_BLIPS(FALSE);
	DISPLAY_HUD(FALSE);
	DISPLAY_RADAR(FALSE);
	PAUSE_GAME();
	DRAW_FRONTEND_HELPER_TEXT("SELECT", "PAD_DPAD_UPDOWN", 0);
	DRAW_FRONTEND_HELPER_TEXT("QUIT", "INPUT_F_CANCEL", 0);
	DRAW_FRONTEND_HELPER_TEXT("CONFIRM", "INPUT_F_ACCEPT", 0);
}
Example #2
0
void CLuaMain::InitVM()
{
    assert(!m_luaVM);

    // Create a new VM
    m_luaVM = lua_open();
    lua_pushlightuserdata(m_luaVM, m_luaVM);
    lua_setfield(m_luaVM, LUA_REGISTRYINDEX, "lua.mainstate");
    m_pLuaManager->OnLuaMainOpenVM(this, m_luaVM);

    // Set the instruction count hook
    lua_sethook(m_luaVM, InstructionCountHook, LUA_MASKCOUNT, HOOK_INSTRUCTION_COUNT);

    // Load LUA libraries
    luaL_openlibs(m_luaVM);
    /*
    luaopen_base(m_luaVM);
    luaopen_math(m_luaVM);
    luaopen_string(m_luaVM);
    luaopen_table(m_luaVM);
    luaopen_debug(m_luaVM);
    luaopen_utf8(m_luaVM);
    luaopen_os(m_luaVM);
    */

    // Initialize security restrictions. Very important to prevent lua trojans and viruses!
    //InitSecurity();

    // Registering C functions
    CLuaCFunctions::RegisterFunctionsWithVM(m_luaVM);

    // Create class metatables
    InitClasses(m_luaVM);

    // Oli: Don't forget to add new ones to CLuaManager::LoadCFunctions. Thanks!

    // create global vars
    lua_pushelement(m_luaVM, g_pGame->GetMapManager()->GetRootElement());
    lua_setglobal(m_luaVM, "root");

    lua_pushresource(m_luaVM, m_pResource);
    lua_setglobal(m_luaVM, "resource");

    lua_pushelement(m_luaVM, m_pResource->GetResourceRootElement());
    lua_setglobal(m_luaVM, "resourceRoot");

    // Load pre-loaded lua scripts
    LoadScript(EmbeddedLuaCode::exports);
    LoadScript(EmbeddedLuaCode::coroutine_debug);
    LoadScript(EmbeddedLuaCode::inspect);
}
void CLuaScriptLoader::LoadScripts(const TCHAR *scriptDir, int iGroup)
{
	TCHAR buf[4096];
	mir_sntprintf(buf, _T("Loading scripts from %s"), scriptDir);
	CallService(MS_NETLIB_LOGW, (WPARAM)hNetlib, (LPARAM)buf);

	RegisterScriptsFolder(ptrA(mir_utf8encodeT(scriptDir)));

	TCHAR searchMask[MAX_PATH];
	mir_sntprintf(searchMask, _T("%s\\%s"), scriptDir, _T("*.lua"));

	TCHAR fullPath[MAX_PATH], path[MAX_PATH];

	WIN32_FIND_DATA fd;
	HANDLE hFind = FindFirstFile(searchMask, &fd);
	if (hFind != INVALID_HANDLE_VALUE)
	{
		do
		{
			if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
			{
				mir_sntprintf(fullPath, _T("%s\\%s"), scriptDir, fd.cFileName);
				PathToRelativeT(fullPath, path);
				if (db_get_b(NULL, MODULE, _T2A(fd.cFileName), 1))
					LoadScript(fullPath, iGroup);
			}
		} while (FindNextFile(hFind, &fd));
		FindClose(hFind);
	}
}
Example #4
0
int PythonIntegration::RunScript(ScriptId scriptId, EventId evt, PyObject* args) {

	ScriptRecord script;
	if (!LoadScript(scriptId, script)) {
		return 1;
	}

	auto dict = PyModule_GetDict(script.module);
	auto eventName = GetFunctionName(evt);
	auto callback = PyDict_GetItemString(dict, eventName);

	if (!callback || !PyCallable_Check(callback)) {
		logger->error("Script {} attached as {} is missing the corresponding function.",
			script.filename, eventName);
		return 1;
	}

	auto resultObj = PyObject_CallObject(callback, args);

	if (!resultObj) {
		logger->error("An error occurred while calling event {} for script {}.", eventName, script.filename);
		PyErr_Print();
		return 1;
	}

	auto result = -1;
	if (PyInt_Check(resultObj)) {
		result = PyInt_AsLong(resultObj);
	}
	Py_DECREF(resultObj);

	return result;
}
Example #5
0
bool CDialogLoader::LoadScriptsFromPath(const string& path, TDialogScriptMap& outScriptMap)
{
	ICryPak * pCryPak = gEnv->pCryPak;
	_finddata_t fd;
	int numLoaded = 0;

	string realPath (path);
	realPath.TrimRight("/\\");
	string search (realPath);
	search += "/*.xml";

	intptr_t handle = pCryPak->FindFirst( search.c_str(), &fd );
	if (handle != -1)
	{
		do
		{
			// fd.name contains the profile name
			string filename = realPath;
			filename += "/" ;
			filename += fd.name;
			bool ok = LoadScript(filename, outScriptMap);
			if (ok)
				++numLoaded;
		} while ( pCryPak->FindNext( handle, &fd ) >= 0 );

		pCryPak->FindClose( handle );
	}

	return numLoaded > 0;
}
void CNetwork::decideParse(char* param1, char* param2) {
	CPlugins *plugin = new CPlugins;
	char string[256];
	for(int i = 0; i < sizeof(GMVars)/sizeof(*GMVars); ++i) {
		if(strcmp((char *)GMVars[i].c_str(),param1) == false) {
			switch(i) {
				case TYPE_GAMEMODE: {
					engineModule *engine = new engineModule;
					sprintf_s(string, "%s/%s.amx",GAMEMODES_DIR, param2);
					loadTime = GetTickCount();
					if(LoadScript(string))
						initAMXGM();
					else
						engine->SHOW_TO_CONSOLE_AND_EXIT("The server will now close, please specify an AMX file or run without gamemode support by specifying it in the iniMod.cfg file.\n");
						delete engine;
					break;
				}
				case TYPE_UPDATERATE: {
					break;
				}
				case TYPE_PLUGIN: {
					plugin->ParsePlugins(param2);
					GMLoaded = true;
					break;
				}
			}
		}
	}
	delete plugin;
	return;
}
Example #7
0
HRESULT WScriptJsrt::ModuleMessage::Call(LPCSTR fileName)
{
    JsErrorCode errorCode;
    JsValueRef result = JS_INVALID_REFERENCE;
    HRESULT hr;
    if (specifier == nullptr)
    {
        errorCode = ChakraRTInterface::JsModuleEvaluation(moduleRecord, &result);
        if (errorCode != JsNoError)
        {
            PrintException(fileName, errorCode);
        }
    }
    else
    {
        LPCSTR fileContent = nullptr;
        char* specifierStr = nullptr;
        size_t length;
        errorCode = ChakraRTInterface::JsStringToPointerUtf8Copy(specifier, &specifierStr, &length);
        if (errorCode == JsNoError)
        {
            hr = Helpers::LoadScriptFromFile(specifierStr, fileContent);
            if (FAILED(hr))
            {
                fprintf(stderr, "Couldn't load file.\n");
            }
            else
            {
                LoadScript(nullptr, specifierStr, fileContent, "module", true);
            }
        }
    }
    return errorCode;
}
Example #8
0
JsValueRef WScriptJsrt::LoadScriptHelper(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState, bool isSourceModule)
{
    HRESULT hr = E_FAIL;
    JsErrorCode errorCode = JsNoError;
    LPCWSTR errorMessage = _u("");
    JsValueRef returnValue = JS_INVALID_REFERENCE;

    if (argumentCount < 2 || argumentCount > 4)
    {
        errorCode = JsErrorInvalidArgument;
        errorMessage = _u("Need more or fewer arguments for WScript.LoadScript");
    }
    else
    {
        AutoString fileContent;
        AutoString fileName;
        AutoString scriptInjectType;
        size_t fileContentLength;
        size_t scriptInjectTypeLength;

        IfJsrtErrorSetGo(ChakraRTInterface::JsStringToPointerUtf8Copy(arguments[1], &fileContent, &fileContentLength));

        if (argumentCount > 2)
        {
            IfJsrtErrorSetGo(ChakraRTInterface::JsStringToPointerUtf8Copy(arguments[2], &scriptInjectType, &scriptInjectTypeLength));

            if (argumentCount > 3)
            {
                size_t unused;
                IfJsrtErrorSetGo(ChakraRTInterface::JsStringToPointerUtf8Copy(arguments[3], &fileName, &unused));
            }
        }

        if (*fileContent)
        {
            // TODO: This is CESU-8. How to tell the engine?
            // TODO: How to handle this source (script) life time?
            returnValue = LoadScript(callee, *fileName, *fileContent, *scriptInjectType ? *scriptInjectType : "self", isSourceModule);
        }
    }

Error:
    if (errorCode != JsNoError)
    {
        JsValueRef errorObject;
        JsValueRef errorMessageString;

        if (wcscmp(errorMessage, _u("")) == 0) {
            errorMessage = ConvertErrorCodeToMessage(errorCode);
        }

        ERROR_MESSAGE_TO_STRING(errCode, errorMessage, errorMessageString);

        ChakraRTInterface::JsCreateError(errorMessageString, &errorObject);
        ChakraRTInterface::JsSetException(errorObject);
    }

    return returnValue;
}
Example #9
0
JsValueRef WScriptJsrt::LoadScriptFileHelper(JsValueRef callee, JsValueRef *arguments, unsigned short argumentCount, bool isSourceModule)
{
    HRESULT hr = E_FAIL;
    JsValueRef returnValue = JS_INVALID_REFERENCE;
    JsErrorCode errorCode = JsNoError;
    LPCWSTR errorMessage = _u("");

    if (argumentCount < 2 || argumentCount > 4)
    {
        errorCode = JsErrorInvalidArgument;
        errorMessage = _u("Need more or fewer arguments for WScript.LoadScript");
    }
    else
    {
        LPCSTR fileContent;
        AutoString fileName;
        AutoString scriptInjectType;
        size_t fileNameLength;
        size_t scriptInjectTypeLength;

        IfJsrtErrorSetGo(ChakraRTInterface::JsStringToPointerUtf8Copy(arguments[1], &fileName, &fileNameLength));

        if (argumentCount > 2)
        {
            IfJsrtErrorSetGo(ChakraRTInterface::JsStringToPointerUtf8Copy(arguments[2], &scriptInjectType, &scriptInjectTypeLength));
        }

        if (errorCode == JsNoError)
        {
            hr = Helpers::LoadScriptFromFile(*fileName, fileContent);
            if (FAILED(hr))
            {
                fwprintf(stderr, _u("Couldn't load file.\n"));
            }
            else
            {
                returnValue = LoadScript(callee, *fileName, fileContent, *scriptInjectType ? *scriptInjectType : "self", isSourceModule);
            }
        }
    }

Error:
    if (errorCode != JsNoError)
    {
        JsValueRef errorObject;
        JsValueRef errorMessageString;

        if (wcscmp(errorMessage, _u("")) == 0) {
            errorMessage = ConvertErrorCodeToMessage(errorCode);
        }

        ERROR_MESSAGE_TO_STRING(errCode, errorMessage, errorMessageString);

        ChakraRTInterface::JsCreateError(errorMessageString, &errorObject);
        ChakraRTInterface::JsSetException(errorObject);
    }

    return returnValue;
}
Script::Script(string scriptName)
{
	// init Lua and load all libraries
	L = lua_open();
	LoadLibraries();
	
	LoadScript(scriptName);	
}
Example #11
0
void LuaParser::LoadItemScript(std::string filename, ItemInst *item) {
	if (item == nullptr)
		return;
	std::string package_name = "item_";
	package_name += std::to_string(item->GetID());

	LoadScript(filename, package_name);
}
Example #12
0
JsValueRef WScriptJsrt::LoadScriptFileHelper(JsValueRef callee, JsValueRef *arguments, unsigned short argumentCount, bool isSourceModule)
{
    HRESULT hr = E_FAIL;
    JsValueRef returnValue = JS_INVALID_REFERENCE;
    JsErrorCode errorCode = JsNoError;
    LPCWSTR errorMessage = L"";

    if (argumentCount < 2 || argumentCount > 4)
    {
        errorCode = JsErrorInvalidArgument;
        errorMessage = L"Need more or fewer arguments for WScript.LoadScript";
    }
    else
    {
        const wchar_t *fileContent;
        const wchar_t *fileName;
        const wchar_t *scriptInjectType = L"self";
        size_t fileNameLength;
        size_t scriptInjectTypeLength;

        IfJsrtErrorSetGo(ChakraRTInterface::JsStringToPointer(arguments[1], &fileName, &fileNameLength));

        if (argumentCount > 2)
        {
            IfJsrtErrorSetGo(ChakraRTInterface::JsStringToPointer(arguments[2], &scriptInjectType, &scriptInjectTypeLength));
        }

        if (errorCode == JsNoError)
        {
            hr = Helpers::LoadScriptFromFile(fileName, fileContent);
            if (FAILED(hr))
            {
                fwprintf(stderr, L"Couldn't load file.\n");
            }
            else
            {
                returnValue = LoadScript(callee, fileName, fileNameLength, fileContent, scriptInjectType, isSourceModule);
            }
        }
    }

Error:
    if (errorCode != JsNoError)
    {
        JsValueRef errorObject;
        JsValueRef errorMessageString;

        if (wcscmp(errorMessage, L"") == 0) {
            errorMessage = ConvertErrorCodeToMessage(errorCode);
        }

        ChakraRTInterface::JsPointerToString(errorMessage, wcslen(errorMessage), &errorMessageString);
        ChakraRTInterface::JsCreateError(errorMessageString, &errorObject);
        ChakraRTInterface::JsSetException(errorObject);
    }

    return returnValue;
}
int main(int argc,char *argv[])
{
	aPrefs		aP;

	char*		script;
	OptInfo		opt;
	AlignInfo	ainf;

	fullPath	infile;
	//fullPath	outfile;

	//	

	SetAdjustDefaults(&aP);

	if(argc != 2)
	{
		printf(PT_OPTIMIZER_VERSION);
		printf("Usage: %s /path/to/script.txt\n", argv[0]);
		exit(1);
	}

	StringtoFullPath(&infile, argv[1]);

	script = LoadScript( &infile );
	if( script != NULL )
	{
		if (ParseScript( script, &ainf ) == 0)
		{
			if( CheckParams( &ainf ) == 0 )
			{
				ainf.fcn	= fcnPano;
				
				SetGlobalPtr( &ainf ); 
				
				opt.numVars 		= ainf.numParam;
				opt.numData 		= ainf.numPts;
				opt.SetVarsToX		= SetLMParams;
				opt.SetXToVars		= SetAlignParams;
				opt.fcn			= ainf.fcn;
				*opt.message		= 0;

				RunLMOptimizer( &opt );
				ainf.data		= opt.message;
				WriteResults( script, &infile, &ainf, distSquared, 0);
				exit(0);
			}
      //TODO: if optCreatePano is 1 then should call stitcher  OR  the option removed
      //if (ainf.sP.optCreatePano == 1)
      //{
      //   Stitch();
      //}
			DisposeAlignInfo( &ainf );
		}
		free( script );
	}
	exit(1);
}
Example #14
0
int LoadScripts() {
	int res = 1;
	for (int i=0; i<numFiles; i++) {
		if (files[i].loaded != -1) continue;
		int res2 = LoadScript(i);
		res &= res2;
	}
	return res;
}
Example #15
0
bool CSquirrelVM::LoadScripts(std::list<CScript> scripts)
{
	for(auto Script : scripts)
		if (Script.GetType() != CLIENT_SCRIPT)
			if (!LoadScript(Script.GetScriptFileName()))
				return false;
	
	return true;
}
Example #16
0
CNetwork::CNetwork() :
mInterface( 0 ),
mModule( 0 )
{
	//ZeroMemory( mConnectionIndex, sizeof( mConnectionIndex ) );
	//ZeroMemory( m_CheckSum, sizeof( m_CheckSum ) );

	LoadScript();
}
Example #17
0
bool SceneLuaScript::Load(File* f) 
{
  std::string filename;
  if (!f->GetDataLine(&filename))
  {
    f->ReportError("Expected lua script file name.");
    return false;
  }
  return LoadScript(filename);
}
Example #18
0
void Creature::OnPushToWorld()
{
	if(proto)
	{
		set<uint32>::iterator itr = proto->start_auras.begin();
		SpellEntry * sp;
		for(; itr != proto->start_auras.end(); ++itr)
		{
			sp = dbcSpell.LookupEntry((*itr));
			if(sp == 0) continue;

			CastSpell(this, sp, 0);
		}
	}
	LoadScript();
	Unit::OnPushToWorld();

	if(_myScriptClass)
		_myScriptClass->OnLoad();

	if(m_spawn)
	{
		if(m_aiInterface->m_formationLinkSqlId)
		{
			// add event
			sEventMgr.AddEvent(this, &Creature::FormationLinkUp, m_aiInterface->m_formationLinkSqlId,
				EVENT_CREATURE_FORMATION_LINKUP, 1000, 0,EVENT_FLAG_DO_NOT_EXECUTE_IN_WORLD_CONTEXT);
			haslinkupevent = true;
		}

		if(m_spawn->channel_target_creature)
		{
			sEventMgr.AddEvent(this, &Creature::ChannelLinkUpCreature, m_spawn->channel_target_creature, EVENT_CREATURE_CHANNEL_LINKUP, 1000, 5, 0);	// only 5 attempts
		}
		
		if(m_spawn->channel_target_go)
		{
			sEventMgr.AddEvent(this, &Creature::ChannelLinkUpGO, m_spawn->channel_target_go, EVENT_CREATURE_CHANNEL_LINKUP, 1000, 5, 0);	// only 5 attempts
		}
	}

	m_aiInterface->m_is_in_instance = (m_mapMgr->GetMapInfo()->type!=INSTANCE_NULL) ? true : false;
	if (this->HasItems())
	{
		for(std::vector<CreatureItem>::iterator itr = m_SellItems->begin(); itr != m_SellItems->end(); ++itr)
		{
				if (itr->max_amount == 0)
					itr->available_amount=0;
				else if (itr->available_amount<itr->max_amount)				
					sEventMgr.AddEvent(this, &Creature::UpdateItemAmount, itr->itemid, EVENT_ITEM_UPDATE, VENDOR_ITEMS_UPDATE_TIME, 1,0);
		}

	}
}
Example #19
0
JsValueRef WScriptJsrt::LoadScriptHelper(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState, bool isSourceModule)
{
    HRESULT hr = E_FAIL;
    JsErrorCode errorCode = JsNoError;
    LPCWSTR errorMessage = L"";
    JsValueRef returnValue = JS_INVALID_REFERENCE;

    if (argumentCount < 2 || argumentCount > 4)
    {
        errorCode = JsErrorInvalidArgument;
        errorMessage = L"Need more or fewer arguments for WScript.LoadScript";
    }
    else
    {
        const wchar_t *fileContent;
        const wchar_t *fileName;
        const wchar_t *scriptInjectType = L"self";
        size_t fileContentLength;
        size_t fileNameLength;
        size_t scriptInjectTypeLength;

        IfJsrtErrorSetGo(ChakraRTInterface::JsStringToPointer(arguments[1], &fileContent, &fileContentLength));

        if (argumentCount > 2)
        {
            IfJsrtErrorSetGo(ChakraRTInterface::JsStringToPointer(arguments[2], &scriptInjectType, &scriptInjectTypeLength));
        }

        fileName = L"script.js";
        fileNameLength = wcslen(fileName);
        if (argumentCount > 3)
        {
            IfJsrtErrorSetGo(ChakraRTInterface::JsStringToPointer(arguments[3], &fileName, &fileNameLength));
        }
        returnValue = LoadScript(callee, fileName, fileNameLength, fileContent, scriptInjectType, isSourceModule);
    }

Error:
    if (errorCode != JsNoError)
    {
        JsValueRef errorObject;
        JsValueRef errorMessageString;

        if (wcscmp(errorMessage, L"") == 0) {
            errorMessage = ConvertErrorCodeToMessage(errorCode);
        }

        ChakraRTInterface::JsPointerToString(errorMessage, wcslen(errorMessage), &errorMessageString);
        ChakraRTInterface::JsCreateError(errorMessageString, &errorObject);
        ChakraRTInterface::JsSetException(errorObject);
    }

    return returnValue;
}
void JavascriptInstance::Load()
{
    PROFILE(JSInstance_Load);
    if (!engine_)
        CreateEngine();

    if (sourceFile.isEmpty() && scriptRefs_.empty())
    {
        LogError("JavascriptInstance::Load: No script content to load!");
        return;
    }
    // Can't specify both a file source and an Asset API source.
    if (!sourceFile.isEmpty() && !scriptRefs_.empty())
    {
        LogError("JavascriptInstance::Load: Cannot specify both an local input source file and a list of script refs to load!");
        return;
    }

    bool useAssetAPI = !scriptRefs_.empty();
    size_t numScripts = useAssetAPI ? scriptRefs_.size() : 1;

    // Determine based on code origin whether it can be trusted with system access or not
    if (useAssetAPI)
    {
        trusted_ = true;
        for(unsigned i = 0; i < scriptRefs_.size(); ++i)
            trusted_ = trusted_ && scriptRefs_[i]->IsTrusted();
    }
    else // Local file: always trusted.
    {
        program_ = LoadScript(sourceFile);
        trusted_ = true; // This is a file on the local filesystem. We are making an assumption nobody can inject untrusted code here.
        // Actually, we are assuming the attacker does not know the absolute location of the asset cache locally here, since if he makes
        // the client to load a script into local cache, he could use this code path to automatically load that unsafe script from cache, and make it trusted. -jj.
    }

    // Check the validity of the syntax in the input.
    for (size_t i = 0; i < numScripts; ++i)
    {
        QString scriptSourceFilename = (useAssetAPI ? scriptRefs_[i]->Name() : sourceFile);
        QString &scriptContent = (useAssetAPI ? scriptRefs_[i]->scriptContent : program_);

        QScriptSyntaxCheckResult syntaxResult = engine_->checkSyntax(scriptContent);
        if (syntaxResult.state() != QScriptSyntaxCheckResult::Valid)
        {
            LogError("Syntax error in script " + scriptSourceFilename + "," + QString::number(syntaxResult.errorLineNumber()) +
                ": " + syntaxResult.errorMessage());

            // Delete our loaded script content (if any exists).
            program_ == "";
        }
    }
}
Example #21
0
int CEntityClass::GetEventCount()
{
	if (m_pEventHandler)
		return m_pEventHandler->GetEventCount();

	if (!m_bScriptLoaded)
		LoadScript(false);
	
	if (!m_pEntityScript)
		return 0;

	return ((CEntityScript*)m_pEntityScript)->GetEventCount();
}
Example #22
0
void CommandMgr::LoadActorScript(const int actornum)
{
	std::stringstream filename;
	filename.flush();
	filename << "a";
	if (actornum < 100)
		filename << "0";
	if (actornum < 10)
		filename << "0";
	filename << actornum << ".sfs";

	LoadScript(FilePathMgr::Instance().GetMapScriptPath() + filename.str());
}
Example #23
0
void CommandMgr::LoadEventScript(const int eventnum)
{
	std::stringstream filename;
	filename.flush();
	filename << "e";
	if (eventnum < 100)
		filename << "0";
	if (eventnum < 10)
		filename << "0";
	filename << eventnum << ".sfs";

	LoadScript(FilePathMgr::Instance().GetMapScriptPath() + filename.str());
}
Example #24
0
   //---------------------------------------------------------------------------
   int LoadAndRunScript(const char* scriptName)
   {
      lastMsg = "LoadAndRunScript is not yet ready for use.";
      return -1;

      int retval = LoadScript(scriptName);

      if (retval == 0)
      {
         retval = RunScript();
      }

      return retval;
   }
void LuaScriptUtilities::RequireLuaModule(
    lua_State* const luaVM, const Ogre::String luaScriptFileName)
{
    LuaFileManager* const fileManager = LuaFileManager::getSingletonPtr();

    const LuaFilePtr script = fileManager->load(
                                  luaScriptFileName,
                                  Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);

    LoadScript(
        luaVM,
        script->GetData(),
        script->GetDataLength(),
        script->getName().c_str());
}
Example #26
0
void CDialogLoaderMK2::InternalLoadFromPath(const string& stripPath, const string& path, TDialogScriptMap& outScriptMap, int& numLoaded, const char *levelName)
{
	ICryPak * pCryPak = gEnv->pCryPak;
	_finddata_t fd;

	string realPath (path);
	realPath.TrimRight("/\\");
	string search (realPath);
	search += "/*.*";

	intptr_t handle = pCryPak->FindFirst( search.c_str(), &fd );
	if (handle != -1)
	{
		do
		{
			if (strcmp(fd.name, ".") == 0 || strcmp(fd.name, "..") == 0)
				continue;

			if (fd.attrib & _A_SUBDIR)
			{
				if(!gEnv->IsEditor())	//only load current levels dialogs
				{
					if(!levelName || stricmp(levelName, fd.name))
						continue;
				}

				string subPath = realPath;
				subPath+="/";
				subPath+=fd.name;
				InternalLoadFromPath(stripPath, subPath, outScriptMap, numLoaded, levelName);
				continue;
			}

			if (stricmp(PathUtil::GetExt(fd.name), "dlg") != 0)
				continue;

			// fd.name contains the profile name
			string filename = realPath;
			filename += "/" ;
			filename += fd.name;
			bool ok = LoadScript(stripPath, filename, outScriptMap);
			if (ok)
				++numLoaded;
		} while ( pCryPak->FindNext( handle, &fd ) >= 0 );

		pCryPak->FindClose( handle );
	}
}
Example #27
0
bool MyFrame::CreateThread(MyFrame *m_frame, const wxString&sFPath, unsigned long &TID){
	wxString sScript;
	if (!LoadScript(sFPath, sScript) )return false;
	
	wxString sFName = wxFileName(sFPath).GetFullName();
	MyThread *thread = new MyThread(m_frame, sScript, sFName, sFPath);
	if ( thread->Create() != wxTHREAD_NO_ERROR ){
		wxLogError(wxT("Can't create thread!"));
		return false;
	}
	TID = vciMailingList.insert(thread);
	thread->setID(TID);

	m_listCtrl1->AddItem(sFName, TID);
	return true;
}
void ScriptingManager::OnScriptMenu(wxCommandEvent& event)
{
    MenuIDToScript::iterator it = m_MenuIDToScript.find(event.GetId());
    if (it == m_MenuIDToScript.end())
    {
        cbMessageBox(_("No script associated with this menu?!?"), _("Error"), wxICON_ERROR);
        return;
    }

    MenuBoundScript& mbs = it->second;

    // is it a function?
    if (mbs.isFunc)
    {
        try
        {
            SqPlus::SquirrelFunction<void> f(cbU2C(mbs.scriptOrFunc));
            f();
        }
        catch (SquirrelError exception)
        {
            DisplayErrors(&exception);
        }
        return;
    }

    // script loading below

    if (wxGetKeyState(WXK_SHIFT))
    {
        wxString script = ConfigManager::LocateDataFile(mbs.scriptOrFunc, sdScriptsUser | sdScriptsGlobal);
        Manager::Get()->GetEditorManager()->Open(script);
        return;
    }

    // run script
    try
    {
        if (!LoadScript(mbs.scriptOrFunc))
            cbMessageBox(_("Could not run script: ") + mbs.scriptOrFunc, _("Error"), wxICON_ERROR);
    }
    catch (SquirrelError exception)
    {
        DisplayErrors(&exception);
    }
}
Example #29
0
int main (int argc, char *argv[])
{
	int inc=0;
	
	start_time = time(NULL);
	
	GetArguments(argc, argv); /* Get the script filename */
	PrintVersion();  /* Print info */
	InitGFX();       /* Setup SDL  */	
	DisplayTitle();  /* Show the irixbasic titles */
	DisplayReady();  /* Display the ready text */
	
	LoadScript(); 
	
	SDL_Flip(screen);
	ubasic_init(program); /* Setup uBasic  */	
	
	
	/* Start the program when the user is ready */
	PrintTextLine("Click to Run.");
	SDL_Delay(200);
	do
	{
		GetInput();   /* Read the inputs */
	}while (!GetMouseButton());
	
	
	do
	{
		GetInput();   /* Read the inputs */
		ubasic_run(); /* Process a line of code*/
	}while (!ubasic_finished() && !done);
	
	PrintTextLine("");
	PrintTextLine("Click or Press ESC to quit.");
	SDL_Flip(screen);
	
	while(!done && !GetMouseButton()){
		GetInput();
	}
	
	TTF_CloseFont( fntc64 );
	
	return 0;
}
Example #30
0
bool CScripts::LoadFromConfig(CConfig * pConfig)
{
	int iScriptCount = pConfig->GetConfigArrayCount("SCRIPT");
		iScriptCount++;
	int iScriptsLoaded = 0;

	for(int i = 1; i < iScriptCount; i++) {
		char * szScriptName = pConfig->GetConfigEntryAsString("SCRIPT", i);

		if(!LoadScript(szScriptName)) {
			logprintf("Failed to load script %s.", szScriptName);
		} else {
			iScriptsLoaded++;
		}
	}

	return (iScriptsLoaded > 0);
}