int CLuaPlayerDefs::TakePlayerMoney ( lua_State* luaVM ) { // bool takePlayerMoney ( int amount ) int lMoney; CScriptArgReader argStream ( luaVM ); argStream.ReadNumber ( lMoney ); if ( !argStream.HasErrors () ) { if ( CStaticFunctionDefinitions::TakePlayerMoney ( lMoney ) ) { lua_pushboolean ( luaVM, true ); return 1; } } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaPlayerDefs::GetPlayerPing ( lua_State* luaVM ) { // int getPlayerPing ( player thePlayer ) CClientPlayer* pPlayer; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pPlayer ); if ( !argStream.HasErrors () ) { // Grab his ping unsigned int uiPing = pPlayer->GetPing (); lua_pushnumber ( luaVM, uiPing ); return 1; } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); // Failed lua_pushboolean ( luaVM, false ); return 1; }
int CLuaResourceDefs::GetResourceRootElement ( lua_State* luaVM ) { // Verify arguments CResource* pResource = NULL; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pResource, NULL ); // No resource given, get this resource's root if ( !argStream.HasErrors () ) { if ( !pResource ) { // Find our vm and get the root CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM ); if ( pLuaMain ) { pResource = pLuaMain->GetResource (); } } // Did we find a resource? if ( pResource ) { // Grab the root element of it and return it if it existed CClientEntity* pEntity = pResource->GetResourceEntity (); if ( pEntity ) { lua_pushelement ( luaVM, pEntity ); return 1; } } } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); // Failed lua_pushboolean ( luaVM, false ); return 1; }
int CLuaFunctionDefs::SetWeaponClipAmmo ( lua_State* luaVM ) { CClientWeapon * pWeapon = NULL; int iAmmo = 0; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pWeapon ); argStream.ReadNumber ( iAmmo ); if ( !argStream.HasErrors() ) { if ( CStaticFunctionDefinitions::SetWeaponClipAmmo( pWeapon, iAmmo ) ) { lua_pushboolean ( luaVM, true ); return 1; } } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaFunctionDefs::ExecuteCommandHandler ( lua_State* luaVM ) { // bool executeCommandHandler ( string commandName, player thePlayer, [ string args ] ) SString strKey; CElement* pElement; SString strArgs; CScriptArgReader argStream ( luaVM ); argStream.ReadString ( strKey ); argStream.ReadUserData ( pElement ); argStream.ReadString ( strArgs, "" ); if ( !argStream.HasErrors () ) { // Grab our VM CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM ); if ( pLuaMain ) { CClient* pClient = NULL; if ( pElement->GetType () == CElement::PLAYER ) pClient = static_cast <CClient*> ( static_cast <CPlayer*> ( pElement ) ); if ( pClient ) { // Call it if ( m_pRegisteredCommands->ProcessCommand ( strKey, strArgs, pClient ) ) { lua_pushboolean ( luaVM, true ); return 1; } } } } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaFunctionDefs::InjectBrowserMouseWheel ( lua_State* luaVM ) { // bool injectMouseWheel ( browser webBrowser, int scrollVertical, int scrollHorizontal ) CClientWebBrowser* pWebBrowser; int iScrollVert; int iScrollHorz; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pWebBrowser ); argStream.ReadNumber ( iScrollVert ); argStream.ReadNumber ( iScrollHorz ); if ( !argStream.HasErrors() ) { pWebBrowser->InjectMouseWheel ( iScrollVert, iScrollHorz ); lua_pushboolean ( luaVM, true ); return 1; } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaFunctionDefs::SetWeaponState ( lua_State* luaVM ) { CClientWeapon * pWeapon; eWeaponState weaponState; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pWeapon ); argStream.ReadEnumString ( weaponState ); if ( !argStream.HasErrors () ) { if ( CStaticFunctionDefinitions::SetWeaponState ( pWeapon, weaponState ) ) { lua_pushboolean ( luaVM, true ); return 1; } } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaWorldDefs::setOcclusionsEnabled ( lua_State* luaVM ) { // bool setOcclusionsEnabled ( bool enabled ) bool bEnabled; CScriptArgReader argStream ( luaVM ); argStream.ReadBool( bEnabled ); if ( !argStream.HasErrors () ) { if ( CStaticFunctionDefinitions::SetOcclusionsEnabled ( bEnabled ) ) { lua_pushboolean ( luaVM, true ); return 1; } } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaVector4Defs::Destroy ( lua_State* luaVM ) { CLuaVector4D* pVector = NULL; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pVector ); if ( !argStream.HasErrors () ) { delete pVector; lua_pushboolean ( luaVM, true ); return 1; } else { m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() ); } lua_pushboolean ( luaVM, false ); return 1; }
int CLuaWorldDefs::setJetpackWeaponEnabled ( lua_State* luaVM ) { eWeaponType weaponType; bool bEnabled; CScriptArgReader argStream ( luaVM ); argStream.ReadEnumStringOrNumber ( weaponType ); argStream.ReadBool ( bEnabled ); if ( !argStream.HasErrors() ) { if ( CStaticFunctionDefinitions::SetJetpackWeaponEnabled ( weaponType, bEnabled ) ) { lua_pushboolean ( luaVM, true ); return 1; } } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaFileDefs::fileRead ( lua_State* luaVM ) { // string fileRead ( file theFile, int count ) CScriptFile* pFile; unsigned long ulCount = 0; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pFile ); argStream.ReadNumber ( ulCount ); if ( !argStream.HasErrors () ) { // Reading zero bytes from a file results in an empty string if ( ulCount == 0 ) { lua_pushstring ( luaVM, "" ); return 1; } // Allocate a buffer to read the stuff into and read some :~ into it CBuffer buffer; long lBytesRead = pFile->Read ( ulCount, buffer ); if ( lBytesRead != -1 ) { // Push the string onto the Lua stack. Use pushlstring so we are binary // compatible. Normal push string takes zero terminated strings. lua_pushlstring ( luaVM, buffer.GetData(), lBytesRead ); return 1; } m_pScriptDebugging->LogBadPointer ( luaVM, "file", 1 ); } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); // Error lua_pushnil ( luaVM ); 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; }
int CLuaVector4Defs::Eq ( lua_State* luaVM ) { CLuaVector4D* pVector1 = NULL; CLuaVector4D* pVector2 = NULL; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pVector1 ); argStream.ReadUserData ( pVector2 ); if ( !argStream.HasErrors () ) { lua_pushboolean ( luaVM, pVector1 == pVector2 ); return 1; } else { m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() ); } lua_pushboolean ( luaVM, false ); return 1; }
int CLuaFunctionDefs::GetWeaponNameFromID ( lua_State* luaVM ) { unsigned char ucID = 0; CScriptArgReader argStream ( luaVM ); argStream.ReadNumber( ucID ); if ( !argStream.HasErrors ( ) ) { SString strBuffer; if ( CStaticFunctionDefinitions::GetWeaponNameFromID ( ucID, strBuffer ) ) { lua_pushstring ( luaVM, strBuffer ); return 1; } } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() ); 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::textDisplayAddText ( lua_State* luaVM ) { CTextDisplay * pTextDisplay; CTextItem * pTextItem; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pTextDisplay ); argStream.ReadUserData ( pTextItem ); if ( !argStream.HasErrors ( ) ) { pTextDisplay->Add ( pTextItem ); lua_pushboolean ( luaVM, true ); return 1; } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaFunctionDefs::SetMapName ( lua_State* luaVM ) { // bool setMapName ( string mapName ) SString strMapName; CScriptArgReader argStream ( luaVM ); argStream.ReadIfNextIsString ( strMapName, "" ); // Default to empty for backward compat with previous implementation if ( !argStream.HasErrors () ) { if ( CStaticFunctionDefinitions::SetMapName ( strMapName ) ) { lua_pushboolean ( luaVM, true ); return 1; } } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); 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 = SharedUtil::Base64decode(str); 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::GetBrowserURL ( lua_State* luaVM ) { // string getBrowserURL ( browser webBrowser ) CClientWebBrowser* pWebBrowser; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pWebBrowser ); if ( !argStream.HasErrors () ) { SString strURL; pWebBrowser->GetURL ( strURL ); lua_pushstring ( luaVM, strURL ); return 1; } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); lua_pushboolean ( luaVM, false ); return 1; }
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 CLuaFileDefs::fileSetPos ( lua_State* luaVM ) { // bool fileSetPos ( file ) // Grab the file pointer CScriptFile* pFile = NULL; unsigned long ulPosition = 0; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pFile ); argStream.ReadNumber ( ulPosition ); if ( !argStream.HasErrors ( ) ) { if ( pFile ) { long lResultPosition = pFile->SetPointer ( ulPosition ); if ( lResultPosition != -1 ) { // Set the position and return where we actually got it put lua_pushnumber ( luaVM, lResultPosition ); } else { m_pScriptDebugging->LogBadPointer ( luaVM, "file", 1 ); lua_pushnil ( luaVM ); } return 1; } else m_pScriptDebugging->LogBadPointer ( luaVM, "file", 1 ); } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() ); // Error lua_pushnil ( luaVM ); return 1; }
int CLuaFxDefs::fxAddSparks ( lua_State* luaVM ) { // bool fxAddSparks ( float posX, float posY, float posZ, float dirX, float dirY, float dirZ, [float force=1, int count=1, float acrossLineX=0, float acrossLineY=0, float acrossLineZ=0, bool blur=false, float spread=1, float life=1] ) // Verify types CVector vecPosition, vecDirection; float fForce = 1.0f; int iCount = 1; CVector vecAcrossLine; bool bBlur = false; float fSpread = 1.0f; float fLife = 1.0f; CScriptArgReader argStream ( luaVM ); argStream.ReadVector3D ( vecPosition ); argStream.ReadVector3D ( vecDirection ); argStream.ReadNumber ( fForce, 1.0f ); argStream.ReadNumber ( iCount, 1 ); argStream.ReadVector3D ( vecAcrossLine, vecAcrossLine ); argStream.ReadBool ( bBlur, false ); argStream.ReadNumber ( fSpread, 1.0f ); argStream.ReadNumber ( fLife, 1.0f ); if ( !argStream.HasErrors ( ) ) { if ( CStaticFunctionDefinitions::FxAddSparks ( vecPosition, vecDirection, fForce, iCount, vecAcrossLine, bBlur, fSpread, fLife ) ) { lua_pushboolean ( luaVM, true ); return 1; } } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() ); // Failed lua_pushboolean ( luaVM, false ); return 1; }
int CLuaFxDefs::fxAddGlass ( lua_State* luaVM ) { // bool fxAddGlass ( float posX, float posY, float posZ, [int colorR=255, int colorG=0, int colorB=0, int colorA=255, float scale=1.0, int count=1] ) // Verify types CVector vecPosition; RwColor rwColor; rwColor.r = 255; rwColor.g = 0; rwColor.b = 0; rwColor.a = 255; float fScale = 1.0f; int iCount = 1; CScriptArgReader argStream ( luaVM ); argStream.ReadVector3D ( vecPosition ); argStream.ReadNumber ( rwColor.r, 255 ); argStream.ReadNumber ( rwColor.g, 0 ); argStream.ReadNumber ( rwColor.b, 0 ); argStream.ReadNumber ( rwColor.a, 255 ); argStream.ReadNumber ( fScale, 1.0f ); argStream.ReadNumber ( iCount, 1 ); if ( !argStream.HasErrors ( ) ) { if ( CStaticFunctionDefinitions::FxAddGlass ( vecPosition, rwColor, fScale, iCount ) ) { lua_pushboolean ( luaVM, true ); return 1; } } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() ); // Failed lua_pushboolean ( luaVM, false ); return 1; }
int CLuaFunctionDefs::PregMatch ( lua_State* luaVM ) { // table pregMatch ( string base, string pattern, uint flags/string = 0, int maxResults = 100000 ) SString strBase, strPattern; pcrecpp::RE_Options pOptions; int iMaxResults; CScriptArgReader argStream ( luaVM ); argStream.ReadString ( strBase ); argStream.ReadString ( strPattern ); ReadPregFlags ( argStream, pOptions ); argStream.ReadNumber ( iMaxResults, 100000 ); if ( !argStream.HasErrors () ) { lua_newtable ( luaVM ); pcrecpp::RE pPattern ( strPattern, pOptions ); pcrecpp::StringPiece strInput ( strBase ); string strGet; int i = 1; while ( pPattern.FindAndConsume ( &strInput, &strGet ) && i <= iMaxResults ) { lua_pushnumber ( luaVM, i ); lua_pushstring ( luaVM, strGet.c_str () ); lua_settable ( luaVM, -3 ); i++; } return 1; } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); lua_pushboolean ( luaVM, false ); return 1; }
// Call a function on a remote server int CLuaFunctionDefs::FetchRemote ( lua_State* luaVM ) { // bool fetchRemote ( string URL [, string queueName ][, int connectionAttempts = 10, int connectTimeout = 10000 ], callback callbackFunction, [ string postData, bool bPostBinary, arguments... ] ) CScriptArgReader argStream ( luaVM ); SString strURL; SString strQueueName; CLuaFunctionRef iLuaFunction; SString strPostData; bool bPostBinary; CLuaArguments args; uint uiConnectionAttempts; uint uiConnectTimeoutMs; argStream.ReadString ( strURL ); if ( argStream.NextIsString () ) MinServerReqCheck ( argStream, MIN_SERVER_REQ_CALLREMOTE_QUEUE_NAME, "'queue name' is being used" ); argStream.ReadIfNextIsString ( strQueueName, CALL_REMOTE_DEFAULT_QUEUE_NAME ); if ( argStream.NextIsNumber () ) MinServerReqCheck ( argStream, MIN_SERVER_REQ_CALLREMOTE_CONNECTION_ATTEMPTS, "'connection attempts' is being used" ); argStream.ReadIfNextIsNumber ( uiConnectionAttempts, 10 ); if ( argStream.NextIsNumber () ) MinServerReqCheck ( argStream, MIN_SERVER_REQ_CALLREMOTE_CONNECT_TIMEOUT, "'connect timeout' is being used" ); argStream.ReadIfNextIsNumber ( uiConnectTimeoutMs, 10000 ); argStream.ReadFunction ( iLuaFunction ); argStream.ReadString ( strPostData, "" ); argStream.ReadBool ( bPostBinary, false ); argStream.ReadLuaArguments ( args ); argStream.ReadFunctionComplete (); if ( !argStream.HasErrors () ) { CLuaMain * luaMain = m_pLuaManager->GetVirtualMachine ( luaVM ); if ( luaMain ) { g_pGame->GetRemoteCalls ()->Call ( strURL, &args, strPostData, bPostBinary, luaMain, iLuaFunction, strQueueName, uiConnectionAttempts, uiConnectTimeoutMs ); lua_pushboolean ( luaVM, true ); 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; }
int CLuaVector4Defs::GetNormalized ( lua_State* luaVM ) { CLuaVector4D* pVector = NULL; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pVector ); if ( !argStream.HasErrors () ) { CVector4D vector ( *pVector ); vector.Normalize (); lua_pushvector ( luaVM, vector ); return 1; } else { m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() ); } lua_pushboolean ( luaVM, false ); return 1; }
int CLuaXMLDefs::xmlUnloadFile ( lua_State* luaVM ) { CXMLNode* pNode = nullptr; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pNode ); if ( !argStream.HasErrors () ) { CLuaMain * luaMain = m_pLuaManager->GetVirtualMachine ( luaVM ); if ( luaMain ) { luaMain->DestroyXML ( pNode ); lua_pushboolean ( luaVM, true ); return 1; } } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaXMLDefs::xmlNodeSetValue ( lua_State* luaVM ) { CXMLNode* pNode = nullptr; SString strValue = ""; bool bUseCDATA; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pNode ); argStream.ReadString ( strValue ); argStream.ReadBool ( bUseCDATA, false ); if ( !argStream.HasErrors () ) { pNode->SetTagContent ( strValue, bUseCDATA ); lua_pushboolean ( luaVM, true ); return 1; } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaFunctionDefs::IsObjectStatic ( lua_State* luaVM ) { // bool isObjectStatic ( object theObject ) CClientObject* pObject; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pObject ); if ( !argStream.HasErrors () ) { bool bStatic; if ( CStaticFunctionDefinitions::IsObjectStatic ( *pObject, bStatic ) ) { lua_pushboolean ( luaVM, bStatic ); return 1; } } else m_pScriptDebugging->LogBadType ( luaVM ); lua_pushboolean ( luaVM, false ); return 1; }