Example #1
0
bool CResourceManager::Load(String strName, bool bStart)
{
	// if a resource with that name exists, we don't load it
	if(Get(strName))
		return false;
	
	// create a new resource
	CResource* pResource = new CResource(m_strResourceDirectory, strName);

	// if it has no valid meta, stop it from loading
	if(pResource->IsValidMeta())
	{
		// save it into our resources list (this needs to be done -before- starting the resource or some scripting functions (requiring CResource* CResourceManager::Get(SQVM* pVM)) will fail)
		m_pResources.push_back(pResource);

		// attempt to start it if we're told to
		if(!bStart || Start(pResource))
			return true;
		else
		{
			// failed to start, remove it
			m_pResources.remove(pResource);
			delete pResource;
			return false;
		}
	}
	else
	{
		// invalid meta file
		delete pResource;
		return false;
	}
}
int CLuaFunctionDefs::GetResourceExportedFunctions ( lua_State *luaVM )
{
    CResource* pResource = NULL;
    CScriptArgReader argStream ( luaVM );
    argStream.ReadUserData ( pResource, NULL );

    // No resource given, get this resource's root
        if ( pResource == NULL )
        {
        // Find our vm and get the root
            CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM );
            if ( pLuaMain )
            {
                pResource = pLuaMain->GetResource ();
            }
        }

        if ( pResource )
        {
            lua_newtable ( luaVM );
            unsigned int uiIndex = 0;
            list<CExportedFunction *>::iterator iterd = pResource->IterBeginExportedFunctions();
            for ( ; iterd != pResource->IterEndExportedFunctions(); iterd++ )
            {
                lua_pushnumber ( luaVM, ++uiIndex );
                lua_pushstring ( luaVM, (*iterd)->GetFunctionName () );
                lua_settable ( luaVM, -3 );
            }
            return 1;
        }

    m_pScriptDebugging->LogBadType ( luaVM );
    lua_pushboolean ( luaVM, false );
    return 1;
}
int CLuaFunctionDefs::DownloadFile ( lua_State* luaVM )
{
    SString strFile = "";
    CScriptArgReader argStream ( luaVM );
    argStream.ReadString ( strFile );

    if ( !argStream.HasErrors ( ) )
    {
        // Grab our VM
        CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM );
        if ( pLuaMain )
        {
            // Grab its resource
            CResource * pResource = pLuaMain->GetResource();
            if ( pResource )
            {
                std::list < CResourceFile* > ::const_iterator iter = pResource->IterBeginResourceFiles();
                for ( ; iter != pResource->IterEndResourceFiles() ; iter++ ) 
                {
                    if ( strcmp ( strFile, (*iter)->GetShortName() ) == 0 )
                    {
                        if ( CStaticFunctionDefinitions::DownloadFile ( pResource, strFile, (*iter)->GetServerChecksum() ) )
                        {
                            lua_pushboolean ( luaVM, true );
                            return 1;
                        }
                    }
                }
                m_pScriptDebugging->LogCustom ( luaVM, 255, 255, 255, "%s: File doesn't exist", lua_tostring ( luaVM, lua_upvalueindex ( 1 ) ) );
            }
        }
    }
    lua_pushboolean ( luaVM, false );
    return 1;
}
Example #4
0
int CLuaFunctionDefs::ShowCursor ( lua_State* luaVM )
{
    // Get the VM
    CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM );
    if ( pLuaMain )
    {
        // Boolean type passed?
        if ( lua_type ( luaVM, 1 ) == LUA_TBOOLEAN )
        {
            // Grab the argument
            bool bShow = lua_toboolean ( luaVM, 1 ) ?true:false;
            bool bToggleControls = true;
            if ( lua_type ( luaVM, 2 ) == LUA_TBOOLEAN )
                bToggleControls = ( lua_toboolean ( luaVM, 2 ) ) ? true:false;

            // Grab the resource belonging to this VM
            CResource* pResource = pLuaMain->GetResource ();
            if ( pResource )
            {
                // Show/hide it inside that resource
                pResource->ShowCursor ( bShow, bToggleControls );
                lua_pushboolean ( luaVM, true );
                return 1;
            }
        }
        else
            m_pScriptDebugging->LogBadType ( luaVM, "showCursor" );
    }

    // Fail
    lua_pushboolean ( luaVM, false );
    return 1;
}
CResource* CResourceManager::Load(CString strAbsPath, CString strResourceName)
{
	for(auto pResource : m_resources)
	{
		if(pResource->GetName() == strResourceName)
		{
			if(pResource->HasChanged())
			{
				pResource->Stop();
				RemoveResource(pResource);
				delete pResource;
				break;
			}
			else
				return pResource;
		}
	}


	CResource* loadResource = new CResource(strAbsPath, strResourceName);
	if(!loadResource->IsLoaded())
    {
        CLogFile::Printf("Loading of resource '%s' failed\n", strResourceName.Get());
        SAFE_DELETE(loadResource);
    } else {
		CLogFile::Printf("Resource loaded (%s)", strResourceName.Get());
		loadResource->SetCreateVMCallback(m_fnCreateVM);
		AddResource(loadResource);
		return loadResource;
	}


	return 0;
}
int CLuaFunctionDefs::GetResourceDynamicElementRoot ( lua_State* luaVM )
{
    CResource* pResource = NULL;
    CScriptArgReader argStream ( luaVM );
    argStream.ReadUserData ( pResource );

    if ( !argStream.HasErrors () )
    {
        if ( pResource )
        {
            CClientEntity* pEntity = pResource->GetResourceDynamicEntity();
            if ( pEntity )
            {
                lua_pushelement ( luaVM, pEntity );
                return 1;
            }
            else
                m_pScriptDebugging->LogError ( luaVM, "getResourceDynamicElementRoot: Resource %s Is Not Currently Running", pResource->GetName() );
        }
        else
            m_pScriptDebugging->LogBadPointer ( luaVM, "resource", 1 );
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() );

    lua_pushboolean ( luaVM, false );
    return 1;
}
int CLuaFunctionDefs::GetResourceName ( lua_State* luaVM )
{
    // Verify arguments
    CResource* pResource = NULL;
    CScriptArgReader argStream ( luaVM );
    argStream.ReadUserData ( pResource );

    if ( !argStream.HasErrors ( ) )
    {
        if ( pResource )
        {
            // Grab its name and return it
            const char* szName = pResource->GetName ();
            if ( szName )
            {
                lua_pushstring ( luaVM, szName );
                return 1;
            }
        }
        else
            m_pScriptDebugging->LogBadPointer ( luaVM, "resource", 1 );
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() );

    // Failed
    lua_pushboolean ( luaVM, false );
    return 1;
}
int CLuaFunctionDefs::ShowCursor ( lua_State* luaVM )
{
    bool bShow = false, bToggleControls = true;
    CScriptArgReader argStream ( luaVM );
    argStream.ReadBool ( bShow );
    argStream.ReadBool ( bToggleControls, true );

    if ( !argStream.HasErrors ( ) )
    {
        // Get the VM
        CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM );
        if ( pLuaMain )
        {
            // Grab the resource belonging to this VM
            CResource* pResource = pLuaMain->GetResource ();
            if ( pResource )
            {
                // Show/hide it inside that resource
                pResource->ShowCursor ( bShow, bToggleControls );
                lua_pushboolean ( luaVM, true );
                return 1;
            }
        }
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() );

    // Fail
    lua_pushboolean ( luaVM, false );
    return 1;
}
Example #9
0
CResource* CResourceManager::Create( const filePath& absPath, const std::string& name )
{
    CFileTranslator *fileRoot = fileSystem->CreateTranslator( absPath.c_str() );

    if ( !fileRoot )
        return NULL;

    filePath resName( name.c_str(), name.size() );

    CResource *res =
        new CResource(
            this,
            *m_luaManager.Create( name, *fileRoot ),
            0,
            resName,
            *fileRoot
        );

    if ( res )
    {
        // The resource must be made a child of the resource manager.
        bool wasMade = res->SetParent( this );

        assert( wasMade == true );

        m_resources.push_back( res );
        m_resByName[ resName ] = res;
    }
    return res;
}
//
// CFunctionUseLogger::OnFunctionUse
//
void CFunctionUseLogger::OnFunctionUse( lua_State* luaVM, const char* szFunctionName, const char* szArgs, uint uiArgsSize )
{
    if ( m_strLogFilename.empty() )
        return;

    CResource* pResource = g_pGame->GetResourceManager()->GetResourceFromLuaState( luaVM );
    SString strResourceName = pResource ? pResource->GetName() : "Unknown";

    SString strKey( "%s-%s", szFunctionName, *strResourceName );

    SFuncCallRecord* pItem = MapFind( m_FuncCallRecordMap, strKey );
    if ( !pItem )
    {
        // Create new entry for this resource/function combo
        MapSet( m_FuncCallRecordMap, strKey, SFuncCallRecord() );
        pItem = MapFind( m_FuncCallRecordMap, strKey );
        pItem->strFunctionName = szFunctionName;
        pItem->strResourceName = strResourceName;
        pItem->uiCallCount = 0;
        pItem->timeFirstUsed = CTickCount::Now();
    }
    pItem->uiCallCount++;

    if ( pItem->strExampleArgs.empty() )
        pItem->strExampleArgs = SStringX( szArgs ).Left( 40 );
}
int CLuaFunctionDefs::Set ( lua_State* luaVM )
{
    CResource* pResource = m_pLuaManager->GetVirtualMachine ( luaVM )->GetResource ();
    SString strSetting;
    CLuaArguments Args;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadString ( strSetting );
    argStream.ReadLuaArguments ( Args );

    if ( !argStream.HasErrors () )
    {
        std::string strResourceName = pResource->GetName ();
        std::string strJSON;
        Args.WriteToJSONString ( strJSON );

        if ( g_pGame->GetSettings ()->Set ( strResourceName.c_str (), strSetting.c_str (), strJSON.c_str () ) )
        {
            lua_pushboolean ( luaVM, true );
            return 1;
        }
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );

    lua_pushboolean ( luaVM, false );
    return 1;
}
Example #12
0
DWORD SetRichEditData(CRichEditCtrl& ctrl, DWORD format, LPWSTR resourcedId)
{
	CResource resource;
	if (!resource.Load(RT_RCDATA, resourcedId))
		ThrowLastError("RT_RCDATA");
	return SetRichEditData(ctrl, SF_RTF, static_cast<const BYTE*>(resource.Lock()), resource.GetSize());
}
int CLuaFunctionDefs::GetResourceDynamicElementRoot ( lua_State* luaVM )
{
    if ( lua_type ( luaVM, 1 ) == LUA_TLIGHTUSERDATA )
    {
        CResource* pResource = lua_toresource ( luaVM, 1 );
        if ( pResource )
        {
            CClientEntity* pEntity = pResource->GetResourceDynamicEntity();
            if ( pEntity )
            {
                lua_pushelement ( luaVM, pEntity );
                return 1;
            }
            else
                m_pScriptDebugging->LogError ( luaVM, "getResourceDynamicElementRoot: Resource %s Is Not Currently Running", pResource->GetName() );
        }
        else
            m_pScriptDebugging->LogBadPointer ( luaVM, "getResourceDynamicElementRoot", "resource", 1 );
    }
    else
        m_pScriptDebugging->LogBadType ( luaVM, "getResourceDynamicElementRoot" );

    lua_pushboolean ( luaVM, false );
    return 1;
}
Example #14
0
bool CLuaDefs::CanUseFunction ( const char* szFunction, lua_State* luaVM, bool bRestricted )
{
    // Get the belonging resource of the lua state
    CResource* pResource = m_pResourceManager->GetResourceFromLuaState ( luaVM );
    if ( pResource )
    {
        // Can we use the function? Return true so LUA can execute it
        if ( m_pACLManager->CanObjectUseRight ( pResource->GetName().c_str (),
                                                CAccessControlListGroupObject::OBJECT_TYPE_RESOURCE,
                                                szFunction,
                                                CAccessControlListRight::RIGHT_TYPE_FUNCTION,
                                                !bRestricted ) )
        {
            return true;
        }
        else
        {
            // Otherwise just return false
            m_pScriptDebugging->LogBadAccess ( luaVM, szFunction );
            return false;
        }
    }

    // Heh this should never happen
    return true;
}
int CLuaFunctionDefs::GetResourceName ( lua_State* luaVM )
{
    // Verify arguments
    if ( lua_istype ( luaVM, 1, LUA_TLIGHTUSERDATA ) )
    {
        // Grab the resource argument
        CResource* pResource = lua_toresource ( luaVM, 1 );
        if ( pResource )
        {
            // Grab its name and return it
            char* szName = pResource->GetName ();
            if ( szName )
            {
                lua_pushstring ( luaVM, szName );
                return 1;
            }
        }
        else
            m_pScriptDebugging->LogBadPointer ( luaVM, "getResourceName", "resource", 1 );
    }
    else
        m_pScriptDebugging->LogBadType ( luaVM, "getResourceName" );

    // Failed
    lua_pushboolean ( luaVM, false );
    return 1;
}
Example #16
0
SString CResourceManager::GetResourceName ( lua_State* luaVM )
{
    CResource* pResource = GetResourceFromLuaState( luaVM );
    if ( pResource )
        return pResource->GetName();
    return "";
}
Example #17
0
int CLuaEngineDefs::EngineLoadTXD ( lua_State* luaVM )
{
    SString strFile = "";
    bool bFilteringEnabled = true;
    CScriptArgReader argStream ( luaVM );
    // Grab the TXD filename or data
    argStream.ReadString ( strFile );
    if ( argStream.NextIsBool() )   // Some scripts have a number here (in error)
        argStream.ReadBool ( bFilteringEnabled, true );

    if ( !argStream.HasErrors ( ) )
    {
        // Grab our virtual machine and grab our resource from that.
        CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM );
        if ( pLuaMain )
        {
            // Grab this resource
            CResource* pResource = pLuaMain->GetResource ();
            if ( pResource )
            {
                bool bIsRawData = CClientTXD::IsTXDData( strFile );
                SString strPath;
                // Is this a legal filepath?
                if ( bIsRawData || CResourceManager::ParseResourcePathInput( strFile, pResource, &strPath ) )
                {
                    // Grab the resource root entity
                    CClientEntity* pRoot = pResource->GetResourceTXDRoot ();

                    // Create a TXD element
                    CClientTXD* pTXD = new CClientTXD ( m_pManager, INVALID_ELEMENT_ID );

                    // Try to load the TXD file
                    if ( pTXD->LoadTXD ( bIsRawData ? strFile : strPath, bFilteringEnabled, bIsRawData ) )
                    {
                        // Success loading the file. Set parent to TXD root
                        pTXD->SetParent ( pRoot );

                        // Return the TXD
                        lua_pushelement ( luaVM, pTXD );
                        return 1;
                    }
                    else
                    {
                        // Delete it again
                        delete pTXD;
                        argStream.SetCustomError( bIsRawData ? "raw data" : strFile, "Error loading TXD" );
                    }
                }
                else
                    argStream.SetCustomError( bIsRawData ? "raw data" : strFile, "Bad file path" );
            }
        }
    }
    if ( argStream.HasErrors() )
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() );

    // We failed
    lua_pushboolean ( luaVM, false );
    return 1;
}
int CLuaFunctionDefs::GetResourceConfig ( lua_State* luaVM )
{
    CScriptArgReader argStream ( luaVM );
    if ( argStream.NextIsUserData ( ) )
        m_pScriptDebugging->LogCustom ( luaVM, "getResourceConfig may be using an outdated syntax. Please check and update." );

    // Resource and config name
    CResource* pResource = NULL;
    SString strInput;
    SString strAbsPath;
    SString strMetaPath;

    argStream.ReadString ( strInput );

    if ( !argStream.HasErrors () )
    {
        // Grab our lua main
        CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM );
        if ( pLuaMain )
        {
            // Grab resource and the config name from arg
            pResource = pLuaMain->GetResource ();

            // We have both a resource file to grab the config from and a config name?
            if ( pResource )
            {
                if ( CResourceManager::ParseResourcePathInput ( strInput, pResource, strAbsPath, strMetaPath ) )
                {
                    // Loop through the configs in that resource
                    list < CResourceConfigItem* >::iterator iter = pResource->ConfigIterBegin ();
                    for ( ; iter != pResource->ConfigIterEnd (); iter++ )
                    {
                        // Matching name?
                        if ( strcmp ( (*iter)->GetShortName(), strMetaPath.c_str() ) == 0 )
                        {
                            // Return it
                            CResourceConfigItem* pConfig = (CResourceConfigItem*) (*iter);
                            CXMLNode* pNode = pConfig->GetRoot ();
                            if ( pNode )
                            {
                                lua_pushxmlnode ( luaVM, pNode );
                                return 1;
                            }
                        }
                    }
                }
            }
        }
        else
            m_pScriptDebugging->LogBadType ( luaVM );
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() );

    // Failed
    lua_pushboolean ( luaVM, false );
    return 1;
}
Example #19
0
int CLuaEngineDefs::EngineLoadDFF ( lua_State* luaVM )
{
    SString strFile = "";
    CScriptArgReader argStream ( luaVM );
    // Grab the DFF filename or data (model ID ignored after 1.3.1)
    argStream.ReadString ( strFile );

    if ( !argStream.HasErrors ( ) )
    {
        // Grab our virtual machine and grab our resource from that.
        CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM );
        if ( pLuaMain )
        {
            // Get this resource
            CResource* pResource = pLuaMain->GetResource ();
            if ( pResource )
            {
                bool bIsRawData = CClientDFF::IsDFFData( strFile );
                SString strPath;
                // Is this a legal filepath?
                if ( bIsRawData || CResourceManager::ParseResourcePathInput( strFile, pResource, &strPath ) )
                {
                    // Grab the resource root entity
                    CClientEntity* pRoot = pResource->GetResourceDFFRoot ();

                    // Create a DFF element
                    CClientDFF* pDFF = new CClientDFF ( m_pManager, INVALID_ELEMENT_ID );

                    // Try to load the DFF file
                    if ( pDFF->LoadDFF ( bIsRawData ? strFile : strPath, bIsRawData ) )
                    {
                        // Success loading the file. Set parent to DFF root
                        pDFF->SetParent ( pRoot );

                        // Return the DFF
                        lua_pushelement ( luaVM, pDFF );
                        return 1;
                    }
                    else
                    {
                        // Delete it again
                        delete pDFF;
                        argStream.SetCustomError( bIsRawData ? "raw data" : strFile, "Error loading DFF" );
                    }
                }
                else
                    argStream.SetCustomError( bIsRawData ? "raw data" : strFile, "Bad file path" );
            }
        }
    }
    if ( argStream.HasErrors ( ) )
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() );

    // We failed
    lua_pushboolean ( luaVM, false );
    return 1;
}
Example #20
0
int CLuaEngineDefs::EngineLoadCOL ( lua_State* luaVM )
{
    SString strFile = "";
    CScriptArgReader argStream ( luaVM );
    // Grab the COL filename or data
    argStream.ReadString ( strFile );

    if ( !argStream.HasErrors ( ) )
    {
        // Grab the lua main and the resource belonging to this script
        CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM );
        if ( pLuaMain )
        {
            // Get the resource we belong to
            CResource* pResource = pLuaMain->GetResource ();
            if ( pResource )
            {
                bool bIsRawData = CClientColModel::IsCOLData( strFile );
                SString strPath;
                // Is this a legal filepath?
                if ( bIsRawData || CResourceManager::ParseResourcePathInput( strFile, pResource, &strPath ) )
                {
                    // Grab the resource root entity
                    CClientEntity* pRoot = pResource->GetResourceCOLModelRoot ();

                    // Create the col model
                    CClientColModel* pCol = new CClientColModel ( m_pManager, INVALID_ELEMENT_ID );

                    // Attempt loading the file
                    if ( pCol->LoadCol ( bIsRawData ? strFile : strPath, bIsRawData ) )
                    {
                        // Success. Make it a child of the resource collision root
                        pCol->SetParent ( pRoot );

                        // Return the created col model
                        lua_pushelement ( luaVM, pCol );
                        return 1;
                    }
                    else
                    {
                        // Delete it again. We failed
                        delete pCol;
                        argStream.SetCustomError( bIsRawData ? "raw data" : strFile, "Error loading COL" );
                    }
                }
                else
                    argStream.SetCustomError( bIsRawData ? "raw data" : strFile, "Bad file path" );
            }
        }
    }
    if ( argStream.HasErrors ( ) )
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() );

    // We failed for some reason
    lua_pushboolean ( luaVM, false );
    return 1;
}
Example #21
0
int CLuaFileDefs::fileDelete ( lua_State* luaVM )
{
//  bool fileDelete ( string filePath )
    SString strFile;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadString ( strFile );

    if ( argStream.NextIsUserData () )
        m_pScriptDebugging->LogCustom ( luaVM, "fileDelete may be using an outdated syntax. Please check and update." );

    if ( !argStream.HasErrors () )
    {
        // Grab our lua VM
        CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM );
        if ( pLuaMain )
        {
            std::string strPath;

            // We have a resource argument?
            CResource* pThisResource = pLuaMain->GetResource ();
            CResource* pResource = pThisResource;
            if ( CResourceManager::ParseResourcePathInput ( strFile, pResource, &strPath, NULL ) )
            {
                // Do we have permissions?
                if ( pResource == pThisResource ||
                     m_pACLManager->CanObjectUseRight ( pThisResource->GetName ().c_str (),
                                                        CAccessControlListGroupObject::OBJECT_TYPE_RESOURCE,
                                                        "ModifyOtherObjects",
                                                        CAccessControlListRight::RIGHT_TYPE_GENERAL,
                                                        false ) )
                {
                    // Make sure the dir exists so we can remove the file
                    MakeSureDirExists ( strPath.c_str () );
                    if ( remove ( strPath.c_str () ) == 0 )
                    {
                        // If file removed return success
                        lua_pushboolean ( luaVM, true );
                        return 1;
                    }
                    else
                    {
                        // Output error
                        m_pScriptDebugging->LogWarning ( luaVM, "%s; unable to delete file", lua_tostring ( luaVM, lua_upvalueindex ( 1 ) ) );
                    }
                }
                else
                    m_pScriptDebugging->LogError ( luaVM, "%s failed; ModifyOtherObjects in ACL denied resource %s to access %s", lua_tostring ( luaVM, lua_upvalueindex ( 1 ) ), pThisResource->GetName ().c_str (), pResource->GetName ().c_str () );
            }
        }    
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );

    lua_pushboolean ( luaVM, false );
    return 1;
}
int CLuaFunctionDefs::GetResourceConfig ( lua_State* luaVM )
{
    if ( lua_istype ( luaVM, 1, LUA_TLIGHTUSERDATA ) )
        m_pScriptDebugging->LogCustom ( luaVM, "getResourceConfig may be using an outdated syntax. Please check and update." );

    // Resource and config name
    CResource* pResource = NULL;
    const char* szInput = NULL;
    std::string strAbsPath;
    std::string strMetaPath;

    if ( lua_istype ( luaVM, 1, LUA_TSTRING ) )
    {
        // Grab our lua main
        CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM );
        if ( pLuaMain )
        {
            // Grab resource and the config name from arg
            pResource = pLuaMain->GetResource ();
            szInput = lua_tostring ( luaVM, 1 );
        }
    }

    // We have both a resource file to grab the config from and a config name?
    if ( pResource && szInput )
    {
        if ( CResourceManager::ParseResourcePathInput ( szInput, pResource, strAbsPath, strMetaPath ) )
        {
            // Loop through the configs in that resource
            list < CResourceConfigItem* >::iterator iter = pResource->ConfigIterBegin ();
            for ( ; iter != pResource->ConfigIterEnd (); iter++ )
            {
                // Matching name?
                if ( strcmp ( (*iter)->GetShortName(), strMetaPath.c_str() ) == 0 )
                {
                    // Return it
                    CResourceConfigItem* pConfig = (CResourceConfigItem*) (*iter);
                    CXMLNode* pNode = pConfig->GetRoot ();
                    if ( pNode )
                    {
                        lua_pushxmlnode ( luaVM, pNode );
                        return 1;
                    }
                }
            }
        }
    }
    else
        m_pScriptDebugging->LogBadType ( luaVM, "getResourceConfig" );

    // Failed
    lua_pushboolean ( luaVM, false );
    return 1;
}
Example #23
0
int CLuaMarkerDefs::CreateMarker(lua_State* luaVM)
{
    CVector    vecPosition;
    float      fSize;
    SColorRGBA color(0, 0, 255, 255);
    SString    strType;
    CElement*  pVisibleTo;

    CScriptArgReader argStream(luaVM);
    argStream.ReadVector3D(vecPosition);
    argStream.ReadString(strType, "default");
    argStream.ReadNumber(fSize, 4.0f);
    argStream.ReadNumber(color.R, color.R);
    argStream.ReadNumber(color.G, color.G);
    argStream.ReadNumber(color.B, color.B);
    argStream.ReadNumber(color.A, color.A);

    if (argStream.NextIsBool() || argStream.NextIsNil())
    {
        pVisibleTo = NULL;
    }
    else
        argStream.ReadUserData(pVisibleTo, m_pRootElement);

    if (!argStream.HasErrors())
    {
        CLuaMain* pLuaMain = g_pGame->GetLuaManager()->GetVirtualMachine(luaVM);
        if (pLuaMain)
        {
            CResource* pResource = pLuaMain->GetResource();
            if (pResource)
            {
                // Create it
                CMarker* pMarker = CStaticFunctionDefinitions::CreateMarker(pResource, vecPosition, strType, fSize, color, pVisibleTo);
                if (pMarker)
                {
                    CElementGroup* pGroup = pResource->GetElementGroup();
                    if (pGroup)
                    {
                        pGroup->Add(pMarker);
                    }
                    lua_pushelement(luaVM, pMarker);
                    return 1;
                }
            }
        }
    }
    else
        m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage());

    lua_pushboolean(luaVM, false);
    return 1;
}
//
// Read next as resource or resource name.  Result output as string
//
void MixedReadResourceString ( CScriptArgReader& argStream, SString& strOutResourceName )
{
    if ( !argStream.NextIsString () )
    {
        CResource* pResource;
        argStream.ReadUserData ( pResource );
        if ( pResource )
            strOutResourceName = pResource->GetName ();
    }
    else
        argStream.ReadString ( strOutResourceName );
}
Example #25
0
CResource* CResourceManager::Add ( unsigned short usNetID, const char* szResourceName, CClientEntity* pResourceEntity, CClientEntity* pResourceDynamicEntity, const SString& strMinServerReq, const SString& strMinClientReq, bool bEnableOOP )
{
    CResource* pResource = new CResource ( usNetID, szResourceName, pResourceEntity, pResourceDynamicEntity, strMinServerReq, strMinClientReq, bEnableOOP );
    if ( pResource )
    {
        m_resources.push_back ( pResource );
        assert( !MapContains( m_NetIdResourceMap, pResource->GetNetID() ) );
        MapSet( m_NetIdResourceMap, usNetID, pResource );
        return pResource;
    }
    return NULL;
}
Example #26
0
void CGameServer::ReadLevelInfo(tstring sFile)
{
	std::basic_ifstream<tchar> f(sFile.c_str());

	CData* pData = new CData();
	CDataSerializer::Read(f, pData);

	CResource<CLevel> pLevel = CreateLevel();
	pLevel->SetFile(sFile.replace("\\", "/"));
	pLevel->ReadInfoFromData(pData);
	m_apLevels.push_back(pLevel);

	delete pData;
}
Example #27
0
CFunctionBlock * CMonitor::getFbPointer(CDevice *device, CStringDictionary::TStringId resourceNameId, CStringDictionary::TStringId fbNameId){
  if(device == 0){
		return 0;
	}
	// Get functionblock
	C61499Class1ObjectHandler &devObjHand = device->getObjectHandler();
	CResource *pres = (CResource*) devObjHand.getFB(resourceNameId);
	if(pres == 0){
		return 0;
	}
	C61499Class1ObjectHandler &resObjHand = pres->getObjectHandler();
	CFunctionBlock *fb = resObjHand.getFB(fbNameId);
	return fb;
}
Example #28
0
void CResourceManager::OnDownloadGroupFinished( void )
{
    // Clear downloading flags
    for ( std::list < CResource* > ::const_iterator iter = m_resources.begin() ; iter != m_resources.end(); ++iter )
    {
        CResource* pResource = *iter;
        if ( pResource->IsDownloading() )
            pResource->SetIsDownloading( false );
    }

    // Start next download group
    UpdatePendingDownloads();

    // Try to load newly ready resources
    for ( std::list < CResource* > ::const_iterator iter = m_resources.begin() ; iter != m_resources.end(); ++iter )
    {
        CResource* pResource = *iter;
        if ( !pResource->IsActive() )
        {
            // Stop as soon as we hit a resource which hasn't downloaded yet (as per previous behaviour)
            if ( pResource->HasPendingFileDownloads() || pResource->IsDownloading() )
                break;
            pResource->Load();
        }
    }
}
Example #29
0
void CResource::AddDependentHash( const Uint a_Hash )
{
	CResource* resource = CResourceManager::GetInstance()->GetResource( a_Hash );
	m_DependentResources.insert( std::pair<Uint, CResource*>( a_Hash, resource ) );

	if ( resource == NULL  )
	{
		++m_DependenciesLeft;
	}
	else if ( resource->IsLoaded() == false )
	{
		++m_DependenciesLeft;
	}
}
Example #30
0
int CLuaFunctionDefs::CreateObject ( lua_State* luaVM )
{
//  object createObject ( int modelid, float x, float y, float z, [float rx, float ry, float rz, bool lowLOD] )
    ushort usModelID; CVector vecPosition; CVector vecRotation; bool bLowLod;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadNumber ( usModelID );
    argStream.ReadNumber ( vecPosition.fX );
    argStream.ReadNumber ( vecPosition.fY );
    argStream.ReadNumber ( vecPosition.fZ );
    argStream.ReadNumber ( vecRotation.fX, 0 );
    argStream.ReadNumber ( vecRotation.fY, 0 );
    argStream.ReadNumber ( vecRotation.fZ, 0 );
    argStream.ReadBool ( bLowLod, false );

    if ( !argStream.HasErrors () )
    {
        if ( CClientObjectManager::IsValidModel  ( usModelID ) )
        {
            CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM );
            if ( pLuaMain )
            {
                CResource* pResource = pLuaMain->GetResource ();
                if ( pResource )
                {
                    CClientObject* pObject = CStaticFunctionDefinitions::CreateObject ( *pResource, usModelID, vecPosition, vecRotation, bLowLod );
                    if ( pObject )
                    {
                        CElementGroup * pGroup = pResource->GetElementGroup();
                        if ( pGroup )
                        {
                            pGroup->Add ( ( CClientEntity* ) pObject );
                        }

                        lua_pushelement ( luaVM, pObject );
                        return 1;
                    }
                }
            }
        }
        else
            m_pScriptDebugging->LogCustom ( luaVM, SString ( "Bad argument @ '%s' [%s]", "createObject", "Invalid model id" ) );
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, SString ( "Bad argument @ '%s' [%s]", "createObject", *argStream.GetErrorMessage () ) );

    lua_pushboolean ( luaVM, false );
    return 1;
}