Ejemplo n.º 1
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;
}
Ejemplo n.º 2
0
int CLuaEngineDefs::EngineReplaceModel ( lua_State* luaVM )
{
    CClientDFF* pDFF;
    SString strModelName;
    bool bAlphaTransparency;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadUserData ( pDFF );
    argStream.ReadString ( strModelName );
    argStream.ReadBool ( bAlphaTransparency, false );

    if ( !argStream.HasErrors () )
    {
        ushort usModelID = CModelNames::ResolveModelID ( strModelName );
        if ( usModelID != INVALID_MODEL_ID )
        {
            if ( pDFF->ReplaceModel ( usModelID, bAlphaTransparency ) )
            {
                lua_pushboolean ( luaVM, true );
                return 1;
            }
            else
                argStream.SetCustomError( SString( "Model ID %d replace failed", usModelID ) );
        }
        else
            argStream.SetCustomError( "Expected valid model ID or name at argument 2" );
    }
    if ( argStream.HasErrors () )
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );

    lua_pushboolean ( luaVM, false );
    return 1;
}
Ejemplo n.º 3
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;
}
Ejemplo n.º 4
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;
}
Ejemplo n.º 5
0
int CLuaOOPDefs::SetPedOccupiedVehicle ( lua_State* luaVM )
{
    //  ped.vehicle = element vehicle
    //  ped.vehicle = nil
    CClientPed* pPed;
    CClientVehicle* pVehicle;
    uint uiSeat = 0;

    CScriptArgReader argStream ( luaVM );

    argStream.ReadUserData ( pPed );
    argStream.ReadUserData ( pVehicle, NULL );
    if ( pVehicle != NULL )
    {
        MinClientReqCheck ( argStream, MIN_CLIENT_REQ_WARPPEDINTOVEHICLE_CLIENTSIDE, "function is being called client side" );
        if ( !argStream.HasErrors () )
        {
            if ( !pPed->IsLocalEntity () || !pVehicle->IsLocalEntity () )
                argStream.SetCustomError ( "This client side function will only work with client created peds and vehicles" );
        }

        if ( !argStream.HasErrors () )
        {
            if ( CStaticFunctionDefinitions::WarpPedIntoVehicle ( pPed, pVehicle, uiSeat ) )
            {
                lua_pushboolean ( luaVM, true );
                return 1;
            }
        }
        else
            m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );
    }
    else
    {
        if ( !argStream.HasErrors () )
        {
            if ( !pPed->IsLocalEntity ()  )
                argStream.SetCustomError ( "This client side function will only work with client created peds" );
        }

        if ( !argStream.HasErrors () )
        {
            if ( CStaticFunctionDefinitions::RemovePedFromVehicle ( pPed ) )
            {
                lua_pushboolean ( luaVM, true );
                return 1;
            }
        }
        else
            m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );
    }

    lua_pushboolean ( luaVM, false );

    return 1;
}
Ejemplo n.º 6
0
int CLuaDatabaseDefs::DbPrepareString ( lua_State* luaVM )
{
    //  string dbPrepareString ( element connection, string query, ... )
    CDatabaseConnectionElement* pElement; SString strQuery; CLuaArguments Args;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadUserData ( pElement );
    argStream.ReadString ( strQuery );
    argStream.ReadLuaArguments ( Args );

    if ( !argStream.HasErrors () )
    {
        SString strResult = g_pGame->GetDatabaseManager ()->PrepareString ( pElement->GetConnectionHandle (), strQuery, &Args );
        SString strError = g_pGame->GetDatabaseManager ()->GetLastErrorMessage ();
        if ( !strResult.empty () || strError.empty () )
        {
            lua_pushstring ( luaVM, strResult );
            return 1;
        }
        if ( !g_pGame->GetDatabaseManager ()->IsLastErrorSuppressed () )
            argStream.SetCustomError ( strError );
    }
    if ( argStream.HasErrors () )
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );

    lua_pushboolean ( luaVM, false );
    return 1;
}
Ejemplo n.º 7
0
int CLuaFunctionDefs::RemoveAccount ( lua_State* luaVM )
{
    //  bool removeAccount ( account theAccount )
    CAccount* pAccount;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadUserData ( pAccount );

    if ( !argStream.HasErrors () )
    {
        if ( CStaticFunctionDefinitions::RemoveAccount ( pAccount ) )
        {
            lua_pushboolean ( luaVM, true );
            return 1;
        }

        CClient* pClient = pAccount->GetClient ();
        if ( pClient )
            argStream.SetCustomError ( "Unable to remove account as unable to log out client. (Maybe onPlayerLogout is cancelled)" );
    }
    if ( argStream.HasErrors () )
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );

    lua_pushboolean ( luaVM, false );
    return 1;
}
Ejemplo n.º 8
0
int CLuaEngineDefs::EngineGetVisibleTextureNames ( lua_State* luaVM )
{
//  table engineGetVisibleTextureNames ( string wildcardMatch = "*" [, string modelName )
    SString strTextureNameMatch; SString strModelName;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadString ( strTextureNameMatch, "*" );
    argStream.ReadString ( strModelName, "" );

    if ( !argStream.HasErrors () )
    {
        ushort usModelID = CModelNames::ResolveModelID ( strModelName );
        if ( usModelID != INVALID_MODEL_ID || strModelName == "" )
        {
            std::vector < SString > nameList;
            g_pCore->GetGraphics ()->GetRenderItemManager ()->GetVisibleTextureNames ( nameList, strTextureNameMatch, usModelID );

            lua_newtable ( luaVM );
            for ( uint i = 0 ; i < nameList.size () ; i++ )
            {                
                lua_pushnumber ( luaVM, i + 1 );
                lua_pushstring ( luaVM, nameList [ i ] );
                lua_settable ( luaVM, -3 );
            }
            return 1;
        }
        argStream.SetCustomError( "Expected valid model ID or name at argument 1" );
    }
    if ( argStream.HasErrors () )
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() );

    // We failed
    lua_pushboolean ( luaVM, false );
    return 1;
}
Ejemplo n.º 9
0
int CLuaEngineDefs::EngineGetModelIDFromName ( lua_State* luaVM )
{
    //  int engineGetModelIDFromName ( string modelName )
    SString strModelName;

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

    if ( !argStream.HasErrors () )
    {
        int iModelID = CModelNames::GetModelID ( strModelName );
        if ( iModelID != INVALID_MODEL_ID )
        {
            lua_pushnumber ( luaVM, iModelID );
            return 1;
        }
        argStream.SetCustomError( "Expected valid model name at argument 1" );
    }
    if ( argStream.HasErrors () )
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() );

    // We failed
    lua_pushboolean ( luaVM, false );
    return 1;
}
Ejemplo n.º 10
0
int CLuaEngineDefs::EngineGetModelNameFromID ( lua_State* luaVM )
{
//  string engineGetModelNameFromID ( int modelID )
    int iModelID;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadNumber ( iModelID );

    if ( !argStream.HasErrors () )
    {
        SString strModelName = CModelNames::GetModelName ( iModelID );
        if ( !strModelName.empty () )
        {
            lua_pushstring ( luaVM, strModelName );
            return 1;
        }
        argStream.SetCustomError( "Expected valid model ID at argument 1" );
    }
    if ( argStream.HasErrors () )
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() );

    // We failed
    lua_pushboolean ( luaVM, false );
    return 1;
}
Ejemplo n.º 11
0
int CLuaFileDefs::fileGetSize ( lua_State* luaVM )
{
//  int fileGetSize ( file theFile )
    CScriptFile* pFile;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadUserData ( pFile );

    if ( !argStream.HasErrors () )
    {
        long lSize = pFile->GetSize ();
        if ( lSize != -1 )
        {
            // Return its size
            lua_pushnumber ( luaVM, lSize );
            return 1;
        }
        else
            argStream.SetCustomError ( "Bad file handle" );
    }

    if ( argStream.HasErrors () )
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );

    // Error
    lua_pushnil ( luaVM );
    return 1;
}
Ejemplo n.º 12
0
int CLuaFunctionDefs::ExecuteBrowserJavascript ( lua_State* luaVM )
{
//  bool executeBrowserJavascript ( browser webBrowser, string jsCode )
    CClientWebBrowser* pWebBrowser; SString strJavascriptCode;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadUserData ( pWebBrowser );
    argStream.ReadString ( strJavascriptCode );

    if ( !argStream.HasErrors () )
    {
        if ( pWebBrowser->ExecuteJavascript ( strJavascriptCode ) )
        {
            lua_pushboolean ( luaVM, true );
            return 1;
        }
        else
            argStream.SetCustomError ( "This function does not work with remote browsers" );
    }
    
    if ( argStream.HasErrors () )
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );

    lua_pushboolean ( luaVM, false );
    return 1;
}
int CLuaFunctionDefs::SetWeaponTarget ( lua_State* luaVM )
{
    CClientWeapon * pWeapon;
    CClientEntity * pTarget;
    CScriptArgReader argStream ( luaVM );
    argStream.ReadUserData ( pWeapon );
    if ( argStream.NextIsUserData() )
    {
        int targetBone;
        argStream.ReadUserData ( pTarget );
        argStream.ReadNumber ( targetBone, 255 );
        if ( !argStream.HasErrors () )
        {
            if ( CStaticFunctionDefinitions::SetWeaponTarget ( pWeapon, pTarget, targetBone ) )
            {
                lua_pushboolean ( luaVM, true );
                return 1;
            }
        }
    }
    else if ( argStream.NextIsNumber() )
    {
        CVector vecTarget;
        argStream.ReadNumber( vecTarget.fX );
        argStream.ReadNumber( vecTarget.fY );
        argStream.ReadNumber( vecTarget.fZ );
        if ( !argStream.HasErrors () )
        {
            if ( CStaticFunctionDefinitions::SetWeaponTarget ( pWeapon, vecTarget ) )
            {
                lua_pushboolean ( luaVM, true );
                return 1;
            }
        }
    }
    else if ( argStream.NextIsNil() )
    {
        if ( !argStream.HasErrors () )
        {
            if ( CStaticFunctionDefinitions::ClearWeaponTarget ( pWeapon ) )
            {
                lua_pushboolean ( luaVM, true );
                return 1;
            }
        }
    }
    else
        argStream.SetCustomError( "Expected element, number or nil at argument 2" );

    if ( argStream.HasErrors () )
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() );

    lua_pushboolean ( luaVM, false );
    return 1;
}
int CLuaFunctionDefs::XMLCreateFile ( lua_State* luaVM )
{
//  xmlnode xmlCreateFile ( string filePath, string rootNodeName )
    SString filePath; SString rootNodeName;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadString ( filePath );
    argStream.ReadString ( rootNodeName );

    // Safety check: Don't allow the rootNodeName "private" incase user forget to declare a node name
    if ( rootNodeName == EnumToString ( ACCESS_PRIVATE ) )
    {
        argStream.SetCustomError( "Expected string at argument 2, got access-type" );
    }

    if ( !argStream.HasErrors () )
    {
        CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine(luaVM);
        if ( pLuaMain )
        {
            CResource* pResource = pLuaMain->GetResource();
            SString strFile;
            if ( CResourceManager::ParseResourcePathInput( filePath, pResource, strFile ) )
            {
                // Make sure the directory exists
                MakeSureDirExists ( strFile.c_str () );

                // Create the XML
                CXMLFile * xmlFile = pLuaMain->CreateXML ( strFile.c_str () );
                if ( xmlFile )
                {
                    // Create its root node
                    CXMLNode* pRootNode = xmlFile->CreateRootNode ( rootNodeName );
                    if ( pRootNode )
                    {
                        lua_pushxmlnode ( luaVM, pRootNode );
                        return 1;
                    }

                    // Delete the XML again
                    pLuaMain->DestroyXML ( xmlFile );
                }
            }
        }
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() );

    lua_pushboolean ( luaVM, false );
    return 1;
}
Ejemplo n.º 15
0
int CLuaFileDefs::fileDelete ( lua_State* luaVM )
{
    //  bool fileDelete ( string filePath )
    SString strInputPath;

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

    // This is only really necessary server side
    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 )
        {
            SString strAbsPath;
            CResource* pThisResource = pLuaMain->GetResource ();
            CResource* pResource = pThisResource;
            if ( CResourceManager::ParseResourcePathInput ( strInputPath, pResource, &strAbsPath ) )
            {
                CheckCanModifyOtherResource( argStream, pThisResource, pResource );
                CheckCanAccessOtherResourceFile( argStream, pThisResource, pResource, strAbsPath );
                if ( !argStream.HasErrors() )
                {
#ifdef MTA_CLIENT
                    // Inform file verifier
                    g_pClientGame->GetResourceManager ()->OnFileModifedByScript ( strAbsPath, "fileDelete" );
#endif
                    if ( FileDelete ( strAbsPath ) )
                    {
                        // If file removed successfully, return true
                        lua_pushboolean ( luaVM, true );
                        return 1;
                    }
                
                    // Output error "Operation failed @ 'fileDelete' [strInputPath]"
                    argStream.SetCustomError ( strInputPath, "Operation failed" );
                }
            }
        }
    }

    if ( argStream.HasErrors () )
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );

    lua_pushboolean ( luaVM, false );
    return 1;
}
Ejemplo n.º 16
0
//
// Material/string
//
void MixedReadMaterialString(CScriptArgReader& argStream, CClientMaterial*& pMaterialElement)
{
    pMaterialElement = NULL;
    if (!argStream.NextIsString())
        argStream.ReadUserData(pMaterialElement);
    else
    {
        SString strFilePath;
        argStream.ReadString(strFilePath);

        // If no element, auto find/create one
        CLuaMain*  pLuaMain = g_pClientGame->GetLuaManager()->GetVirtualMachine(argStream.m_luaVM);
        CResource* pParentResource = pLuaMain ? pLuaMain->GetResource() : NULL;
        if (pParentResource)
        {
            CResource* pFileResource = pParentResource;
            SString    strPath, strMetaPath;
            if (CResourceManager::ParseResourcePathInput(strFilePath, pFileResource, &strPath, &strMetaPath))
            {
                SString strUniqueName = SString("%s*%s*%s", pParentResource->GetName(), pFileResource->GetName(), strMetaPath.c_str()).Replace("\\", "/");
                pMaterialElement = g_pClientGame->GetManager()->GetRenderElementManager()->FindAutoTexture(strPath, strUniqueName);

                if (pMaterialElement)
                {
                    // Check if brand new
                    if (!pMaterialElement->GetParent())
                        // Make it a child of the resource's file root ** CHECK  Should parent be pFileResource, and element added to pParentResource's
                        // ElementGroup? **
                        pMaterialElement->SetParent(pParentResource->GetResourceDynamicEntity());
                }
                else
                    argStream.SetCustomError(strFilePath, "Error loading image");
            }
            else
                argStream.SetCustomError(strFilePath, "Bad file path");
        }
    }
}
Ejemplo n.º 17
0
int CLuaResourceDefs::LoadString ( lua_State* luaVM )
{
    //  func,err loadstring( string text[, string name] )
    SString strInput; SString strName;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadString ( strInput );
    argStream.ReadString ( strName, "" );

    if ( !argStream.HasErrors () )
    {
        const char* szChunkname = strName.empty () ? *strInput : *strName;
        const char* cpInBuffer = strInput;
        uint uiInSize = strInput.length ();

        // Deobfuscate if required
        const char* cpBuffer;
        uint uiSize;
        if ( !g_pNet->DeobfuscateScript ( cpInBuffer, uiInSize, &cpBuffer, &uiSize, m_pResourceManager->GetResourceName ( luaVM ) + "/loadstring" ) )
        {
            SString strMessage ( "argument 1 is invalid. Please re-compile at http://luac.mtasa.com/", 0 );
            argStream.SetCustomError ( strMessage );
            cpBuffer = NULL;
            g_pCore->GetConsole ()->Print ( argStream.GetFullErrorMessage () );
            g_pClientGame->TellServerSomethingImportant ( 1004, argStream.GetFullErrorMessage (), 3 );
        }

        if ( !argStream.HasErrors () )
        {
            CLuaShared::CheckUTF8BOMAndUpdate ( &cpBuffer, &uiSize );
            if ( !CLuaMain::LuaLoadBuffer ( luaVM, cpBuffer, uiSize, szChunkname ) )
            {
                // Ok
                return 1;
            }
            else
            {
                lua_pushnil ( luaVM );
                lua_insert ( luaVM, -2 );  /* put before error message */
                return 2;  /* return nil plus error message */
            }
        }
    }
    if ( argStream.HasErrors () )
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );

    lua_pushboolean ( luaVM, false );
    return 1;
}
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.ReadVector3D ( vecPosition );
    argStream.ReadVector3D ( vecRotation, vecRotation );
    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
            argStream.SetCustomError( "Invalid model id" );
    }
    if ( argStream.HasErrors () )
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() );

    lua_pushboolean ( luaVM, false );
    return 1;
}
//
// Read next as preg option flags
//
void ReadPregFlags( CScriptArgReader& argStream, pcrecpp::RE_Options& pOptions )
{
    if ( argStream.NextIsNumber() )
    {
        uint uiFlags = 0;
        argStream.ReadNumber ( uiFlags );
        pOptions.set_caseless ( ( uiFlags & 1 ) != 0 );
        pOptions.set_multiline ( ( uiFlags & 2 ) != 0 );
        pOptions.set_dotall ( ( uiFlags & 4 ) != 0 );
        pOptions.set_extended ( ( uiFlags & 8 ) != 0 );
        pOptions.set_utf8 ( ( uiFlags & 16 ) != 0 );
    }
    else
    if ( argStream.NextIsString() )
    {
        SString strFlags;
        argStream.ReadString ( strFlags );
        for( uint i = 0 ; i < strFlags.length() ; i++ )
        {
            switch ( strFlags[i] )
            {
                case 'i':
                    pOptions.set_caseless ( true );
                    break;
                case 'm':
                    pOptions.set_multiline ( true );
                    break;
                case 'd':
                    pOptions.set_dotall ( true );
                    break;
                case 'e':
                    pOptions.set_extended ( true );
                    break;
                case 'u':
                    pOptions.set_utf8 ( true );
                    break;
                default:
                    argStream.SetCustomError( "Flags all wrong" );
                    return;       
            }
        }
    }
}
Ejemplo n.º 20
0
int CLuaTimerDefs::SetTimer ( lua_State* luaVM )
{
    //  timer setTimer ( function theFunction, int timeInterval, int timesToExecute, [ var arguments... ] )
    CLuaFunctionRef iLuaFunction; double dTimeInterval; uint uiTimesToExecute; CLuaArguments Arguments;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadFunction ( iLuaFunction );
    argStream.ReadNumber ( dTimeInterval );
    argStream.ReadNumber ( uiTimesToExecute );
    argStream.ReadLuaArguments ( Arguments );
    argStream.ReadFunctionComplete ();

    if ( !argStream.HasErrors () )
    {
        CLuaMain * luaMain = m_pLuaManager->GetVirtualMachine ( luaVM );
        if ( luaMain )
        {
            // Check for the minimum interval
            if ( dTimeInterval < LUA_TIMER_MIN_INTERVAL )
            {
                argStream.SetCustomError ( "Interval is below 50" );
            }
            else
            {
                CLuaTimer* pLuaTimer = luaMain->GetTimerManager ()->AddTimer ( iLuaFunction, CTickCount ( dTimeInterval ), uiTimesToExecute, Arguments );
                if ( pLuaTimer )
                {
                    // Set our timer debug info (in case we don't have any debug info which is usually when you do setTimer(destroyElement, 50, 1) or such)
                    pLuaTimer->SetLuaDebugInfo ( g_pClientGame->GetScriptDebugging ()->GetLuaDebugInfo ( luaVM ) );

                    lua_pushtimer ( luaVM, pLuaTimer );
                    return 1;
                }
            }
        }
    }
    if ( argStream.HasErrors () )
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );

    lua_pushboolean ( luaVM, false );
    return 1;
}
Ejemplo n.º 21
0
int CLuaFileDefs::fileDelete ( lua_State* luaVM )
{
//  bool fileDelete ( string filePath )
    SString filePath;

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

    if ( !argStream.HasErrors () )
    {
        // Grab our lua VM
        CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM );
        if ( pLuaMain )
        {
            std::string strPath;
            CResource* pResource = pLuaMain->GetResource ();
            if ( CResourceManager::ParseResourcePathInput ( filePath, pResource, strPath ) )
            {
                // Inform file verifier
                g_pClientGame->GetResourceManager()->FileModifedByScript( strPath );

                if ( FileDelete ( strPath.c_str () ) )
                {
                    // If file removed return success
                    lua_pushboolean ( luaVM, true );
                    return 1;
                }
                else
                {
                    // Output error
                    argStream.SetCustomError( SString( "unable to delete file '%s'", *filePath ) );
                }
            }
        }
    }
    if ( argStream.HasErrors () )
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() );

    lua_pushboolean ( luaVM, false );
    return 1;
}
Ejemplo n.º 22
0
int CLuaMatrixDefs::Create ( lua_State* luaVM )
{
    CMatrix matrix;

    CScriptArgReader argStream ( luaVM );
    if ( argStream.NextIsVector3D () )
    {
        CVector vecPosition;
        argStream.ReadVector3D ( vecPosition );
        if ( argStream.NextIsVector3D () )
        {
            CVector vecRotation;
            argStream.ReadVector3D ( vecRotation );
            ConvertDegreesToRadiansNoWrap ( vecRotation );
            matrix = CMatrix ( vecPosition, vecRotation );
        }
        else
        {
            matrix = CMatrix ( vecPosition );
        }
    }
    else if ( argStream.NextIsUserDataOfType<CLuaMatrix> () )
    {
        argStream.ReadMatrix ( matrix );
        matrix = CMatrix ( matrix );
    }
    else if ( !argStream.NextIsNone() ) {
        argStream.SetCustomError ( "Expected vector3, matrix or nothing" );
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );
        
        lua_pushboolean ( luaVM, false );
        return 1;
    }

    lua_pushmatrix ( luaVM, matrix );
    return 1;
}
Ejemplo n.º 23
0
int CLuaFunctionDefs::AddAccount ( lua_State* luaVM )
{
    //  account addAccount ( string name, string pass[, bool allowCaseVariations = false ] )
    SString strName; SString strPassword; bool bAllowCaseVariations;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadString ( strName );
    argStream.ReadString ( strPassword );
    argStream.ReadBool ( bAllowCaseVariations, false );

    if ( !argStream.HasErrors () )
    {
        if ( !bAllowCaseVariations )
        {
            // Message for new behaviour
            SString strCaseVariation = m_pAccountManager->GetActiveCaseVariation( strName );
            if ( !strCaseVariation.empty() )
                argStream.SetCustomError ( SString( "Already an account using a case variation of that name ('%s')", *strCaseVariation ) );
        }

        if ( !argStream.HasErrors () )
        {
            CAccount* pAccount;
            if ( ( pAccount = CStaticFunctionDefinitions::AddAccount ( strName, strPassword ) ) )
            {
                lua_pushaccount ( luaVM, pAccount );
                return 1;
            }
        }
    }

    if ( argStream.HasErrors () )
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );

    lua_pushboolean ( luaVM, false );
    return 1;
}
Ejemplo n.º 24
0
int CLuaFunctionDefs::SetServerPassword ( lua_State* luaVM )
{
    //  bool setServerPassword ( [ string password ] )
    SString strPassword;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadString ( strPassword, "" );

    if ( !argStream.HasErrors () )
    {
        if ( CStaticFunctionDefinitions::SetServerPassword ( strPassword, true ) )
        {
            lua_pushboolean ( luaVM, true );
            return 1;
        }
        else
            argStream.SetCustomError ( "password must be shorter than 32 chars and just contain visible characters" );
    }
    if ( argStream.HasErrors () )
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );

    lua_pushboolean ( luaVM, false );
    return 1;
}
Ejemplo n.º 25
0
int CLuaXMLDefs::xmlCreateFile ( lua_State* luaVM )
{
#ifndef MTA_CLIENT
    if ( lua_type ( luaVM, 3 ) == LUA_TLIGHTUSERDATA )
        m_pScriptDebugging->LogCustom ( luaVM, "xmlCreateFile may be using an outdated syntax. Please check and update." );
#endif // !MTA_CLIENT

    // Grab our resource
    CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM );
    if ( pLuaMain )
    {
        SString strInputPath, strRootNodeName;

        CScriptArgReader argStream ( luaVM );
        argStream.ReadString ( strInputPath );
        argStream.ReadString ( strRootNodeName );

        if ( !argStream.HasErrors () )
        {
            SString strPath;
            CResource* pThisResource = pLuaMain->GetResource ();
            CResource* pOtherResource = pThisResource; // clientside, this variable will always be pThisResource

            // Resolve other resource from name
            if ( CResourceManager::ParseResourcePathInput ( strInputPath, pOtherResource, &strPath, nullptr ) )
            {
#ifndef MTA_CLIENT
                // We have access to modify other resource?
                if ( pOtherResource == pThisResource ||
                    m_pACLManager->CanObjectUseRight ( pThisResource->GetName ().c_str (),
                        CAccessControlListGroupObject::OBJECT_TYPE_RESOURCE,
                        "ModifyOtherObjects",
                        CAccessControlListRight::RIGHT_TYPE_GENERAL,
                        false ) )
#endif // !MTA_CLIENT
                {
                    // Make sure the dir exists so we can successfully make the file
                    MakeSureDirExists ( strPath );

                    // Create the XML file
                    CXMLFile * xmlFile = pLuaMain->CreateXML ( strPath );
                    if ( xmlFile )
                    {
                        // Create its root node
                        CXMLNode* pRootNode = xmlFile->CreateRootNode ( strRootNodeName );
                        if ( pRootNode )
                        {
                            lua_pushxmlnode ( luaVM, pRootNode );
                            return 1;
                        }
                        // Destroy it if we failed
                        pLuaMain->DestroyXML ( xmlFile );
                    }
                }
#ifndef MTA_CLIENT
                else
                    argStream.SetCustomError ( SString ( "ModifyOtherObjects in ACL denied resource '%s' to access '%s'", pThisResource->GetName ().c_str (), pOtherResource->GetName ().c_str () ), "Access denied" );
#endif // !MTA_CLIENT
            }
        }

        if ( argStream.HasErrors () )
            m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );
    }

    lua_pushboolean ( luaVM, false );
    return 1;
}
Ejemplo n.º 26
0
int CLuaXMLDefs::xmlCopyFile ( lua_State* luaVM )
{
#ifndef MTA_CLIENT
    if ( lua_type ( luaVM, 3 ) == LUA_TLIGHTUSERDATA )
        m_pScriptDebugging->LogCustom ( luaVM, "xmlCopyFile may be using an outdated syntax. Please check and update." );
#endif // !MTA_CLIENT

    // Grab our resource
    CLuaMain* pLUA = m_pLuaManager->GetVirtualMachine ( luaVM );
    if ( pLUA )
    {
        SString strFile;
        CXMLNode* pSourceNode;

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

        if ( !argStream.HasErrors () )
        {
            SString strPath;
            CResource* pThisResource = pLUA->GetResource ();
            CResource* pOtherResource = pThisResource;

            // Resolve other resource from name
            if ( CResourceManager::ParseResourcePathInput ( strFile, pOtherResource, &strPath, NULL ) )
            {
#ifndef MTA_CLIENT
                // We have access to modify other resource?
                if ( pOtherResource == pThisResource ||
                    m_pACLManager->CanObjectUseRight ( pThisResource->GetName ().c_str (),
                        CAccessControlListGroupObject::OBJECT_TYPE_RESOURCE,
                        "ModifyOtherObjects",
                        CAccessControlListRight::RIGHT_TYPE_GENERAL,
                        false ) )
#endif // !MTA_CLIENT
                {
                    if ( pSourceNode ) {

                        // Make sure the dir exists so we can successfully make the file
                        MakeSureDirExists ( strPath );

                        // Grab the roots tag name
                        std::string strRootTagName;
                        strRootTagName = pSourceNode->GetTagName ();

                        // Create the new XML file and its root node
                        CXMLFile* pNewXML = pLUA->CreateXML ( strPath.c_str () );
                        if ( pNewXML )
                        {
                            // Grab the root of the new XML
                            CXMLNode* pNewRoot = pNewXML->CreateRootNode ( strRootTagName );
                            if ( pNewRoot )
                            {
                                // Copy over the attributes from the root
                                int iAttributeCount = pSourceNode->GetAttributes ().Count ();
                                int i = 0;
                                CXMLAttribute* pAttribute;
                                for ( ; i < iAttributeCount; i++ )
                                {
                                    pAttribute = pSourceNode->GetAttributes ().Get ( i );
                                    if ( pAttribute )
                                        pNewRoot->GetAttributes ().Create ( *pAttribute );
                                }

                                // Copy the stuff from the given source node to the destination root
                                if ( pSourceNode->CopyChildrenInto ( pNewRoot, true ) )
                                {
                                    lua_pushxmlnode ( luaVM, pNewRoot );
                                    return 1;
                                }
                            }

                            // Delete the XML again
                            pLUA->DestroyXML ( pNewXML );
                        }
                    }
                    else
                        argStream.SetCustomError ( SString ( "Unable to copy XML file %s", strFile.c_str () ), "Bad filepath" );
                }
#ifndef MTA_CLIENT
                else
                    argStream.SetCustomError ( SString ( "ModifyOtherObjects in ACL denied resource '%s' to access '%s'", pThisResource->GetName ().c_str (), pOtherResource->GetName ().c_str () ), "Access denied" );
#endif
            }
        }

        if ( argStream.HasErrors () )
            m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );
    }

    // Error
    lua_pushboolean ( luaVM, false );
    return 1;
}
Ejemplo n.º 27
0
int CLuaFileDefs::fileCopy ( lua_State* luaVM )
{
//  bool fileCopy ( string filePath, string newFilePath, bool overwrite = false )
    SString filePath; SString newFilePath; bool bOverwrite;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadString ( filePath );
    argStream.ReadString ( newFilePath );
    argStream.ReadBool ( bOverwrite, false );

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

        if ( !g_pNet->ValidateBinaryFileName ( newFilePath ) )
        {
            argStream.SetCustomError ( SString ( "Filename not allowed %s", *newFilePath ), "File error" );
        }
        else
        if ( pLuaMain )
        {
            std::string strCurAbsPath;
            std::string strNewAbsPath;

            // We have a resource arguments?
            CResource* pThisResource = pLuaMain->GetResource ();
            CResource* pCurResource = pThisResource;
            CResource* pNewResource = pThisResource;
            if ( CResourceManager::ParseResourcePathInput ( filePath, pCurResource, strCurAbsPath ) &&
                 CResourceManager::ParseResourcePathInput ( newFilePath, pNewResource, strNewAbsPath ) )
            {
                 // Does source file exist?
                if ( FileExists ( strCurAbsPath ) )
                {
                    // Does destination file exist?
                    if ( !bOverwrite && FileExists ( strNewAbsPath ) )
                    {
                        argStream.SetCustomError ( SString ( "Destination file already exists (%s)", *newFilePath ), "File error" );
                    }
                    else
                    {
                        // Inform file verifier
                        g_pClientGame->GetResourceManager()->FileModifedByScript( strNewAbsPath );

                        // Make sure the destination folder exists so we can copy the file
                        MakeSureDirExists ( strNewAbsPath );

                        if ( FileCopy ( strCurAbsPath, strNewAbsPath ) )
                        {
                            // If file copied return success
                            lua_pushboolean ( luaVM, true );
                            return 1;
                        }
                        else
                        {
                            argStream.SetCustomError ( SString ( "Unable to copy %s to %s", *filePath, *newFilePath ), "File error" );
                        }
                    }
                }
                else
                {
                    argStream.SetCustomError ( SString ( "Source file doesn't exist (%s)", *filePath ), "File error" );
                }
            }
        }
    }

    if ( argStream.HasErrors () )
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );

    // Failed
    lua_pushboolean ( luaVM, false );
    return 1;
}
Ejemplo n.º 28
0
int CLuaFileDefs::fileCreate ( lua_State* luaVM )
{
//  file fileCreate ( string filePath )
    SString filePath;

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

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

        if ( !g_pNet->ValidateBinaryFileName ( filePath ) )
        {
            argStream.SetCustomError ( SString ( "Filename not allowed %s", *filePath ), "File error" );
        }
        else
        if ( pLuaMain )
        {
            SString strAbsPath;
            SString strMetaPath;
            CResource* pThisResource = pLuaMain->GetResource ();
            CResource* pResource = pThisResource;
            if ( CResourceManager::ParseResourcePathInput ( filePath, pResource, strAbsPath, strMetaPath ) )
            {
                // Inform file verifier
                g_pClientGame->GetResourceManager()->FileModifedByScript( strAbsPath );

                // Make sure the destination folder exist so we can create the file
                MakeSureDirExists ( strAbsPath.c_str () );

                // Create the file to create
                eAccessType accessType = filePath[0] == '@' ? eAccessType::ACCESS_PRIVATE : eAccessType::ACCESS_PUBLIC;
                CScriptFile* pFile = new CScriptFile( pThisResource->GetScriptID( ), strMetaPath.c_str(), DEFAULT_MAX_FILESIZE, accessType);
                assert ( pFile );

                // Try to load it
                if ( pFile->Load ( pResource, CScriptFile::MODE_CREATE ) )
                {
                    // Make it a child of the resource's file root
                    pFile->SetParent ( pResource->GetResourceDynamicEntity () );

                    // Add it to the scrpt resource element group
                    CElementGroup* pGroup = pThisResource->GetElementGroup ();
                    if ( pGroup )
                    {
                        pGroup->Add ( pFile );
                    }

                    // Success. Return the file.
                    lua_pushelement ( luaVM, pFile );
                    return 1;
                }
                else
                {
                    // Delete the file again
                    delete pFile;

                    // Output error
                    argStream.SetCustomError ( SString ( "Unable to create %s", *filePath ), "File error" );
                }
            }
        }
    }

    if ( argStream.HasErrors () )
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );

    // Failed
    lua_pushboolean ( luaVM, false );
    return 1;
}
Ejemplo n.º 29
0
int CLuaFileDefs::fileOpen ( lua_State* luaVM )
{
//  file fileOpen ( string filePath [, bool readOnly = false ] )
    SString filePath; bool readOnly;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadString ( filePath );
    argStream.ReadBool ( readOnly, false );

    if ( !argStream.HasErrors () )
    {
        // Grab our lua VM
        CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM );
        if ( pLuaMain )
        {
            SString strAbsPath;
            SString strMetaPath;
            CResource* pThisResource = pLuaMain->GetResource ();
            CResource* pResource = pThisResource;
            if ( CResourceManager::ParseResourcePathInput ( filePath, pResource, strAbsPath, strMetaPath ) )
            {
                // Inform file verifier
                if ( !readOnly )
                    g_pClientGame->GetResourceManager()->FileModifedByScript( strAbsPath );

                // Create the file to create
                eAccessType accessType = filePath[0] == '@' ? eAccessType::ACCESS_PRIVATE : eAccessType::ACCESS_PUBLIC;
                CScriptFile* pFile = new CScriptFile( pThisResource->GetScriptID( ), strMetaPath.c_str( ), DEFAULT_MAX_FILESIZE, accessType );
                assert ( pFile );

                // Try to load it
                if ( pFile->Load ( pResource, readOnly ? CScriptFile::MODE_READ : CScriptFile::MODE_READWRITE ) )
                {
                    // Make it a child of the resource's file root
                    pFile->SetParent ( pResource->GetResourceDynamicEntity () );

                    // Grab its owner resource
                    CResource* pParentResource = pLuaMain->GetResource ();
                    if ( pParentResource )
                    {
                        // Add it to the scrpt resource element group
                        CElementGroup* pGroup = pParentResource->GetElementGroup ();
                        if ( pGroup )
                        {
                            pGroup->Add ( pFile );
                        }
                    }

                    // Success. Return the file.
                    lua_pushelement ( luaVM, pFile );
                    return 1;
                }
                else
                {
                    // Delete the file again
                    delete pFile;

                    // Output error
                    argStream.SetCustomError( SString( "unable to load file '%s'", *filePath ) );
                }
            }
        }
    }
    if ( argStream.HasErrors () )
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() );

    // Failed
    lua_pushboolean ( luaVM, false );
    return 1;
}
Ejemplo n.º 30
0
int CLuaResourceDefs::Load ( lua_State* luaVM )
{
    //  func,err load( callback callbackFunction[, string name] )
    CLuaFunctionRef iLuaFunction; SString strName;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadFunction ( iLuaFunction );
    argStream.ReadString ( strName, "=(load)" );
    argStream.ReadFunctionComplete ();

    if ( !argStream.HasErrors () )
    {
        // Call supplied function to get all the bits
        // Should apply some limit here?
        SString strInput;
        CLuaArguments callbackArguments;
        CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM );
        while ( pLuaMain )
        {
            CLuaArguments returnValues;
            callbackArguments.Call ( pLuaMain, iLuaFunction, &returnValues );
            if ( returnValues.Count () )
            {
                CLuaArgument* returnedValue = *returnValues.IterBegin ();
                if ( returnedValue->GetType () == LUA_TSTRING )
                {
                    strInput += returnedValue->GetString ();
                    continue;
                }
            }
            break;
        }

        const char* szChunkname = *strName;
        const char* cpInBuffer = strInput;
        uint uiInSize = strInput.length ();

        // Deobfuscate if required
        const char* cpBuffer;
        uint uiSize;
        if ( !g_pNet->DeobfuscateScript ( cpInBuffer, uiInSize, &cpBuffer, &uiSize, m_pResourceManager->GetResourceName ( luaVM ) + "/load" ) )
        {
            SString strMessage ( "argument 2 is invalid. Please re-compile at http://luac.mtasa.com/", 0 );
            argStream.SetCustomError ( strMessage );
            cpBuffer = NULL;
            g_pCore->GetConsole ()->Print ( argStream.GetFullErrorMessage () );
            g_pClientGame->TellServerSomethingImportant ( 1005, argStream.GetFullErrorMessage (), 3 );
        }

        if ( !argStream.HasErrors () )
        {
            CLuaShared::CheckUTF8BOMAndUpdate ( &cpBuffer, &uiSize );
            if ( !CLuaMain::LuaLoadBuffer ( luaVM, cpBuffer, uiSize, szChunkname ) )
            {
                // Ok
                return 1;
            }
            else
            {
                lua_pushnil ( luaVM );
                lua_insert ( luaVM, -2 );  /* put before error message */
                return 2;  /* return nil plus error message */
            }
        }
    }
    if ( argStream.HasErrors () )
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );

    lua_pushboolean ( luaVM, false );
    return 1;
}