int CLuaCryptDefs::Base64decode ( lua_State* luaVM ) { SString str; CScriptArgReader argStream ( luaVM ); argStream.ReadString ( str ); if ( !argStream.HasErrors () ) { SString result = SharedUtil::Base64decode(str); lua_pushlstring ( luaVM, result, result.length () ); return 1; } else 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; } } } }
int CLuaFunctionDefs::Base64encode ( lua_State* luaVM ) { SString str; CScriptArgReader argStream ( luaVM ); argStream.ReadString ( str ); if ( !argStream.HasErrors() ) { SString result = Base64::encode ( str ); lua_pushstring ( luaVM, result ); return 1; } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaFunctionDefs::OutputChatBox ( lua_State* luaVM ) { // bool outputChatBox ( string text [, element visibleTo=getRootElement(), int r=231, int g=217, int b=176, bool colorCoded=false ] ) SString ssChat; CElement* pElement; bool bColorCoded; // Default unsigned char ucRed = 231; unsigned char ucGreen = 217; unsigned char ucBlue = 176; CScriptArgReader argStream ( luaVM ); argStream.ReadString ( ssChat ); argStream.ReadUserData ( pElement, m_pRootElement ); if ( argStream.NextIsNumber () && argStream.NextIsNumber ( 1 ) && argStream.NextIsNumber ( 2 ) ) { argStream.ReadNumber ( ucRed ); argStream.ReadNumber ( ucGreen ); argStream.ReadNumber ( ucBlue ); } else argStream.Skip ( 3 ); argStream.ReadBool ( bColorCoded, false ); if ( !argStream.HasErrors () ) { CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM ); if ( pLuaMain ) { CStaticFunctionDefinitions::OutputChatBox ( (const char*) ssChat, pElement, ucRed, ucGreen, ucBlue, bColorCoded, pLuaMain ); lua_pushboolean ( luaVM, true ); return 1; } } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaXMLDefs::xmlNodeSetName ( lua_State* luaVM ) { CXMLNode* pNode = nullptr; SString strTagName = ""; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pNode ); argStream.ReadString ( strTagName ); if ( !argStream.HasErrors () ) { pNode->SetTagName ( strTagName ); lua_pushboolean ( luaVM, true ); return 1; } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaDatabaseDefs::ExecuteSQLDropTable ( lua_State* luaVM ) { SString strTable; CScriptArgReader argStream ( luaVM ); argStream.ReadString ( strTable ); if ( !argStream.HasErrors () ) { CPerfStatSqliteTiming::GetSingleton ()->SetCurrentResource ( luaVM ); CStaticFunctionDefinitions::ExecuteSQLDropTable ( strTable ); lua_pushboolean ( luaVM, true ); return 1; } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaFunctionDefs::GetWeaponIDFromName ( lua_State* luaVM ) { SString strName = ""; unsigned char ucID = 0; CScriptArgReader argStream ( luaVM ); argStream.ReadString( strName ); if ( !argStream.HasErrors ( ) ) { if ( CStaticFunctionDefinitions::GetWeaponIDFromName ( strName, ucID ) ) { lua_pushnumber ( luaVM, ucID ); return 1; } } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaCryptDefs::Sha256 ( lua_State* luaVM ) { // string sha256 ( string str ) SString strSourceData; CScriptArgReader argStream ( luaVM ); argStream.ReadString ( strSourceData ); if ( !argStream.HasErrors () ) { SString strResult = GenerateSha256HexString ( strSourceData ); lua_pushstring ( luaVM, strResult ); return 1; } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); lua_pushboolean ( luaVM, false ); return 1; }
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 () ) { lua_pushboolean ( luaVM, pWebBrowser->ExecuteJavascript ( strJavascriptCode ) ); return 1; } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaFunctionDefs::UtfCode ( lua_State* luaVM ) { SString strInput = ""; CScriptArgReader argStream ( luaVM ); argStream.ReadString ( strInput ); if ( !argStream.HasErrors ( ) ) { std::wstring strUTF = MbUTF8ToUTF16(strInput); unsigned long ulCode = strUTF.c_str()[0]; lua_pushnumber ( luaVM, ulCode ); return 1; } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaFunctionDefs::AddEventHandler ( lua_State* luaVM ) { // bool addEventHandler ( string eventName, element attachedTo, function handlerFunction, [bool getPropagated = true] ) SString strName; CClientEntity* pEntity; CLuaFunctionRef iLuaFunction; bool bPropagated; CScriptArgReader argStream ( luaVM ); argStream.ReadString ( strName ); argStream.ReadUserData ( pEntity ); argStream.ReadFunction ( iLuaFunction ); argStream.ReadBool ( bPropagated, true ); argStream.ReadFunctionComplete (); if ( !argStream.HasErrors () ) { // Grab our virtual machine CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM ); if ( pLuaMain ) { // Check if the handle is in use if ( pEntity->GetEventManager()->HandleExists ( pLuaMain, strName, iLuaFunction ) ) { m_pScriptDebugging->LogCustom ( luaVM, 255, 0, 0, "addEventHandler: '%s' with this function is already handled", *strName ); lua_pushboolean ( luaVM, false ); return 1; } // Do it if ( CStaticFunctionDefinitions::AddEventHandler ( *pLuaMain, strName, *pEntity, iLuaFunction, bPropagated ) ) { lua_pushboolean ( luaVM, true ); return 1; } } } else m_pScriptDebugging->LogCustom ( luaVM, SString ( "Bad argument @ '%s' [%s]", "addEventHandler", *argStream.GetErrorMessage () ) ); // Failed lua_pushboolean ( luaVM, false ); return 1; }
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; }
int CLuaTeamDefs::GetTeamFromName ( lua_State* luaVM ) { SString strName = ""; CScriptArgReader argStream ( luaVM ); argStream.ReadString ( strName ); if ( !argStream.HasErrors () ) { CClientTeam* pTeam = m_pTeamManager->GetTeam ( strName ); if ( pTeam ) { lua_pushelement ( luaVM, pTeam ); return 1; } } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaFunctionDefs::OutputServerLog ( lua_State* luaVM ) { SString strMessage; CScriptArgReader argStream ( luaVM ); argStream.ReadString ( strMessage ); if ( !argStream.HasErrors () ) { // Print it CLogger::LogPrintf ( LOGLEVEL_MEDIUM, "%s\n", strMessage.c_str () ); lua_pushboolean ( luaVM, true ); return 1; } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaFunctionDefs::IsControlEnabled ( lua_State * luaVM ) { SString strControlState = ""; CScriptArgReader argStream ( luaVM ); argStream.ReadString ( strControlState ); if ( !argStream.HasErrors ( ) ) { bool bEnabled; if ( CStaticFunctionDefinitions::IsControlEnabled ( strControlState, bEnabled ) ) { lua_pushboolean ( luaVM, bEnabled ); return 1; } } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaFunctionDefs::GetKeyState ( lua_State * luaVM ) { SString strKey = ""; CScriptArgReader argStream ( luaVM ); argStream.ReadString ( strKey ); if ( !argStream.HasErrors ( ) ) { bool bState; if ( CStaticFunctionDefinitions::GetKeyState ( strKey, bState ) ) { lua_pushboolean ( luaVM, bState ); return 1; } } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaCryptDefs::Hash ( lua_State* luaVM ) { // string hash ( string type, string data ) EHashFunctionType hashFunction; SString strSourceData; CScriptArgReader argStream ( luaVM ); argStream.ReadEnumString ( hashFunction ); argStream.ReadString ( strSourceData ); if ( !argStream.HasErrors () ) { SString strResult = GenerateHashHexString ( hashFunction, strSourceData ); lua_pushstring ( luaVM, strResult.ToLower () ); return 1; } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaACLDefs::isObjectInACLGroup ( lua_State* luaVM ) { // bool isObjectInACLGroup ( string theObject, aclgroup theGroup ) SString strObject; CAccessControlListGroup* pGroup; CAccessControlListGroupObject::EObjectType GroupObjectType; CScriptArgReader argStream ( luaVM ); argStream.ReadString ( strObject ); argStream.ReadUserData ( pGroup ); if ( !argStream.HasErrors () ) { // Figure out what type of object this is const char* szObjectAfterDot = strObject; if ( StringBeginsWith ( strObject, "resource." ) ) { szObjectAfterDot += 9; GroupObjectType = CAccessControlListGroupObject::OBJECT_TYPE_RESOURCE; } else if ( StringBeginsWith ( strObject, "user." ) ) { szObjectAfterDot += 5; GroupObjectType = CAccessControlListGroupObject::OBJECT_TYPE_USER; } else { // Invalid group type lua_pushboolean ( luaVM, false ); return 1; } if ( pGroup->FindObjectMatch ( szObjectAfterDot, GroupObjectType ) ) { lua_pushboolean ( luaVM, true ); return 1; } } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaFunctionDefs::GetTeamFromName ( lua_State* luaVM ) { SString strName; CScriptArgReader argStream ( luaVM ); argStream.ReadString ( strName ); if ( !argStream.HasErrors () ) { CTeam* pTeam = CStaticFunctionDefinitions::GetTeamFromName ( strName ); if ( pTeam ) { lua_pushelement ( luaVM, pTeam ); return 1; } } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaFunctionDefs::ToggleControl ( lua_State * luaVM ) { SString strControl = ""; bool bState = false; CScriptArgReader argStream ( luaVM ); argStream.ReadString ( strControl ); argStream.ReadBool ( bState ); if ( !argStream.HasErrors ( ) ) { if ( CStaticFunctionDefinitions::ToggleControl ( strControl, bState ) ) { lua_pushboolean ( luaVM, true ); return 1; } } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaFunctionDefs::GetKeyBoundToCommand ( lua_State* luaVM ) { SString strCommand = ""; CScriptArgReader argStream ( luaVM ); argStream.ReadString ( strCommand ); if ( !argStream.HasErrors ( ) ) { CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM ); if ( pLuaMain ) { // get the key list < CKeyBind* > ::const_iterator iter = g_pCore->GetKeyBinds ()->IterBegin (); for ( ; iter != g_pCore->GetKeyBinds ()->IterEnd (); iter++ ) { CKeyBind* pKeyBind = *iter; if ( !pKeyBind->IsBeingDeleted () && pKeyBind->bActive ) { if ( pKeyBind->GetType () == KEY_BIND_COMMAND ) { CCommandBind* pBind = static_cast < CCommandBind* > ( pKeyBind ); if ( strcmp ( strCommand, pBind->szCommand ) == 0 ) { lua_pushstring ( luaVM, pBind->boundKey->szKey ); return 1; } } } } lua_pushboolean ( luaVM, false ); return 1; } } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaFunctionDefs::GetAnalogControlState ( lua_State * luaVM ) { SString strControlState = ""; CScriptArgReader argStream ( luaVM ); argStream.ReadString ( strControlState ); if ( !argStream.HasErrors ( ) ) { float fState; if ( CStaticFunctionDefinitions::GetAnalogControlState ( strControlState , fState ) ) { lua_pushnumber ( luaVM, fState ); return 1; } } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaFxDefs::CreateEffect ( lua_State* luaVM ) { // bool createEffect ( string fxName, float posX, float posY, float posZ[, float rotX, float rotY, float rotZ] ) CVector vecPosition; CVector vecRotation; SString strFxName; CScriptArgReader argStream ( luaVM ); argStream.ReadString ( strFxName ); argStream.ReadVector3D ( vecPosition ); argStream.ReadVector3D ( vecRotation, CVector(0, 0, 0) ); if ( !argStream.HasErrors ( ) ) { CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM ); if ( pLuaMain ) { CResource* pResource = pLuaMain->GetResource(); if ( pResource ) { // Create it and return it CClientEffect * pFx = CStaticFunctionDefinitions::CreateEffect ( *pResource, strFxName, vecPosition ); if ( pFx != NULL ) { pFx->SetRotationDegrees ( vecRotation ); lua_pushelement ( luaVM, pFx ); return 1; } } } } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() ); // Failed lua_pushboolean ( luaVM, false ); return 1; }
int CLuaCryptDefs::Md5 ( lua_State* luaVM ) { SString strMd5 = ""; CScriptArgReader argStream ( luaVM ); argStream.ReadString ( strMd5 ); if ( !argStream.HasErrors () ) { MD5 md5bytes; char szResult[33]; CMD5Hasher hasher; hasher.Calculate ( strMd5, strMd5.length (), md5bytes ); hasher.ConvertToHex ( md5bytes, szResult ); lua_pushstring ( luaVM, szResult ); return 1; } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaTextDefs::textItemSetText ( lua_State* luaVM ) { CTextItem * pTextItem; SString strText; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pTextItem ); argStream.ReadString ( strText ); if ( !argStream.HasErrors ( ) ) { pTextItem->SetText( strText ); lua_pushboolean ( luaVM, true ); return 1; } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaFunctionDefs::RemoveRuleValue ( lua_State* luaVM ) { // bool removeRuleValue ( string key ) SString strKey; CScriptArgReader argStream ( luaVM ); argStream.ReadString ( strKey ); if ( !argStream.HasErrors () ) { if ( CStaticFunctionDefinitions::RemoveRuleValue ( strKey ) ) { lua_pushboolean ( luaVM, true ); return 1; } } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); lua_pushboolean ( luaVM, false ); return 1; }
// // 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"); } } }
int CLuaOOPDefs::DxGetTextWidth ( lua_State* luaVM ) { // float dxGetTextWidth ( string text, [float scale=1, mixed font="default", bool colorCoded=false] ) SString strText; float fScale; CClientDxFont* pDxFontElement; bool bColorCoded; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pDxFontElement ); argStream.ReadString ( strText ); argStream.ReadNumber ( fScale, 1 ); argStream.ReadBool ( bColorCoded, false ); if ( !argStream.HasErrors () ) { ID3DXFont* pD3DXFont = CStaticFunctionDefinitions::ResolveD3DXFont ( FONT_DEFAULT, pDxFontElement ); // Retrieve the longest line's extent std::stringstream ssText ( strText ); std::string sLineText; float fWidth = 0.0f, fLineExtent = 0.0f; while ( std::getline ( ssText, sLineText ) ) { fLineExtent = g_pCore->GetGraphics ()->GetDXTextExtent ( sLineText.c_str (), fScale, pD3DXFont, bColorCoded ); if ( fLineExtent > fWidth ) fWidth = fLineExtent; } // Success lua_pushnumber ( luaVM, fWidth ); return 1; } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); // Failed lua_pushboolean ( luaVM, false ); return 1; }
int CLuaCryptDefs::TeaDecode ( lua_State* luaVM ) { SString str; SString key; CScriptArgReader argStream ( luaVM ); argStream.ReadString ( str ); argStream.ReadString ( key ); if ( !argStream.HasErrors () ) { SString result; Base64::decode ( str, result ); SharedUtil::TeaDecode ( result, key, &str ); lua_pushstring ( luaVM, str ); return 1; } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaFunctionDefs::GetRuleValue ( lua_State* luaVM ) { // string getRuleValue ( string key ) SString strKey; CScriptArgReader argStream ( luaVM ); argStream.ReadString ( strKey ); if ( !argStream.HasErrors () ) { const char* szRule = CStaticFunctionDefinitions::GetRuleValue ( strKey ); if ( szRule ) { lua_pushstring ( luaVM, szRule ); return 1; } } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); lua_pushboolean ( luaVM, false ); return 1; }