diff --git a/Client/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.cpp b/Client/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.cpp index 98beb384c9d..f67957dee6a 100644 --- a/Client/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.cpp +++ b/Client/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.cpp @@ -658,8 +658,9 @@ bool ReadMatrix ( lua_State* luaVM, uint uiArgIndex, CMatrix& outMatrix ) // // Check min client is correct +// Return false if below required // -void MinClientReqCheck ( CScriptArgReader& argStream, const char* szVersionReq, const char* szReason ) +bool MinClientReqCheck ( CScriptArgReader& argStream, const char* szVersionReq, const char* szReason ) { CLuaMain* pLuaMain = g_pClientGame->GetLuaManager()->GetVirtualMachine ( argStream.m_luaVM ); if ( pLuaMain ) @@ -670,11 +671,14 @@ void MinClientReqCheck ( CScriptArgReader& argStream, const char* szVersionReq, if ( pResource->GetMinClientReq () < szVersionReq ) { #if MTASA_VERSION_TYPE == VERSION_TYPE_RELEASE - argStream.SetVersionWarning ( szVersionReq, "client", szReason ); + if (szReason) + argStream.SetVersionWarning ( szVersionReq, "client", szReason ); #endif + return false; } } } + return true; } // diff --git a/Client/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.h b/Client/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.h index 0d52aa6aa4a..8e44d636e24 100644 --- a/Client/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.h +++ b/Client/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.h @@ -276,7 +276,7 @@ void MixedReadDxFontString ( CScriptArgReader& argStream, eFontType& outFontType void MixedReadGuiFontString ( CScriptArgReader& argStream, SString& strFontName, const char* szDefaultFontName, CClientGuiFont*& poutGuiFontElement ); void MixedReadMaterialString ( CScriptArgReader& argStream, CClientMaterial*& pMaterialElement ); bool ReadMatrix ( lua_State* luaVM, uint uiArgIndex, CMatrix& outMatrix ); -void MinClientReqCheck ( CScriptArgReader& argStream, const char* szVersionReq, const char* szReason ); +bool MinClientReqCheck ( CScriptArgReader& argStream, const char* szVersionReq, const char* szReason = nullptr ); void ReadPregFlags( CScriptArgReader& argStream, pcrecpp::RE_Options& pOptions ); void CheckCanModifyOtherResource( CScriptArgReader& argStream, CResource* pThisResource, CResource* pOtherResource, CResource* pOtherResource2 = nullptr ); void CheckCanAccessOtherResourceFile( CScriptArgReader& argStream, CResource* pThisResource, CResource* pOtherResource, const SString& strAbsPath, bool* pbReadOnly = nullptr ); diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp index 96d2a492b2d..eabe3abe507 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp @@ -10,6 +10,7 @@ *****************************************************************************/ #include "StdInc.h" +#define MIN_CLIENT_REQ_GETVEHICLECOMPONENT_OOP "1.5.5-9.11710" void CLuaVehicleDefs::LoadFunctions ( void ) { @@ -189,9 +190,9 @@ void CLuaVehicleDefs::AddClass ( lua_State* luaVM ) lua_classfunction ( luaVM, "getSirenParams", "getVehicleSirenParams" ); lua_classfunction ( luaVM, "getSirens", "getVehicleSirens" ); lua_classfunction ( luaVM, "getSirensOn", "getVehicleSirensOn" ); - lua_classfunction ( luaVM, "getComponentPosition", "getVehicleComponentPosition" ); + lua_classfunction ( luaVM, "getComponentPosition", OOP_GetVehicleComponentPosition ); lua_classfunction ( luaVM, "getComponentVisible", "getVehicleComponentVisible" ); - lua_classfunction ( luaVM, "getComponentRotation", "getVehicleComponentRotation" ); + lua_classfunction ( luaVM, "getComponentRotation", OOP_GetVehicleComponentRotation ); lua_classfunction ( luaVM, "getUpgrades", "getVehicleUpgrades" ); lua_classfunction ( luaVM, "getUpgradeSlotName", "getVehicleUpgradeSlotName" ); lua_classfunction ( luaVM, "getCompatibleUpgrades", "getVehicleCompatibleUpgrades" ); @@ -3040,7 +3041,6 @@ int CLuaVehicleDefs::SetVehicleComponentPosition ( lua_State* luaVM ) return 1; } - int CLuaVehicleDefs::GetVehicleComponentPosition ( lua_State* luaVM ) { // float, float, float getVehicleComponentPosition ( vehicle theVehicle, string theComponent [, string base = "root"] ) @@ -3071,6 +3071,41 @@ int CLuaVehicleDefs::GetVehicleComponentPosition ( lua_State* luaVM ) return 1; } +int CLuaVehicleDefs::OOP_GetVehicleComponentPosition ( lua_State* luaVM ) +{ + // float, float, float getVehicleComponentPosition ( vehicle theVehicle, string theComponent [, string base = "root"] ) + SString strComponent; + CClientVehicle * pVehicle = NULL; + EComponentBaseType outputBase; + + CScriptArgReader argStream ( luaVM ); + argStream.ReadUserData ( pVehicle ); + argStream.ReadString ( strComponent ); + argStream.ReadEnumString ( outputBase, EComponentBase::ROOT ); + + if ( !argStream.HasErrors () ) + { + CVector vecPosition; + if ( pVehicle->GetComponentPosition ( strComponent, vecPosition, outputBase ) ) + { + if (!MinClientReqCheck(argStream, MIN_CLIENT_REQ_GETVEHICLECOMPONENT_OOP)) + { + lua_pushnumber(luaVM, vecPosition.fX); + lua_pushnumber(luaVM, vecPosition.fY); + lua_pushnumber(luaVM, vecPosition.fZ); + return 3; + } + lua_pushvector ( luaVM, vecPosition ); + return 1; + } + } + else + m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); + + lua_pushboolean ( luaVM, false ); + return 1; +} + int CLuaVehicleDefs::SetVehicleComponentRotation ( lua_State* luaVM ) { // bool setVehicleComponentRotation ( vehicle theVehicle, string theComponent, float rotX, float rotY, float rotZ [, string base = "parent"] ) @@ -3132,6 +3167,43 @@ int CLuaVehicleDefs::GetVehicleComponentRotation ( lua_State* luaVM ) return 1; } +int CLuaVehicleDefs::OOP_GetVehicleComponentRotation ( lua_State* luaVM ) +{ + // float, float, float getVehicleComponentRotation ( vehicle theVehicle, string theComponent [, string base = "parent"] ) + SString strComponent; + CClientVehicle * pVehicle = NULL; + EComponentBaseType outputBase; + + CScriptArgReader argStream ( luaVM ); + argStream.ReadUserData ( pVehicle ); + argStream.ReadString ( strComponent ); + argStream.ReadEnumString ( outputBase, EComponentBase::PARENT ); + + if ( !argStream.HasErrors () ) + { + CVector vecRotation; + if ( pVehicle->GetComponentRotation ( strComponent, vecRotation, outputBase ) ) + { + // Script uses degrees + ConvertRadiansToDegrees ( vecRotation ); + if (!MinClientReqCheck(argStream, MIN_CLIENT_REQ_GETVEHICLECOMPONENT_OOP)) + { + lua_pushnumber(luaVM, vecRotation.fX); + lua_pushnumber(luaVM, vecRotation.fY); + lua_pushnumber(luaVM, vecRotation.fZ); + return 3; + } + lua_pushvector ( luaVM, vecRotation ); + return 1; + } + } + else + m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); + + lua_pushboolean ( luaVM, false ); + return 1; +} + int CLuaVehicleDefs::ResetVehicleComponentPosition ( lua_State* luaVM ) { CScriptArgReader argStream ( luaVM ); diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.h b/Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.h index 7852583be18..5d34911a84f 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.h +++ b/Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.h @@ -136,9 +136,9 @@ class CLuaVehicleDefs : public CLuaDefs // Components LUA_DECLARE ( SetVehicleComponentPosition ); - LUA_DECLARE ( GetVehicleComponentPosition ); + LUA_DECLARE_OOP ( GetVehicleComponentPosition ); LUA_DECLARE ( SetVehicleComponentRotation ); - LUA_DECLARE ( GetVehicleComponentRotation ); + LUA_DECLARE_OOP ( GetVehicleComponentRotation ); LUA_DECLARE ( ResetVehicleComponentPosition ); LUA_DECLARE ( ResetVehicleComponentRotation ); LUA_DECLARE ( SetVehicleComponentVisible ); diff --git a/Server/mods/deathmatch/logic/CResourceChecker.Data.h b/Server/mods/deathmatch/logic/CResourceChecker.Data.h index 1b24c4530db..90043a262b0 100644 --- a/Server/mods/deathmatch/logic/CResourceChecker.Data.h +++ b/Server/mods/deathmatch/logic/CResourceChecker.Data.h @@ -255,6 +255,7 @@ namespace bool bRemoved; SString strOldName; SString strNewName; + SString strVersion; }; SDeprecatedItem clientDeprecatedList[] = { @@ -322,6 +323,9 @@ namespace { false, "guiMemoSetCaratIndex", "guiMemoSetCaretIndex" }, // XML { false, "xmlNodeFindChild", "xmlFindChild" }, + + { false, "getComponentPosition", "will return 3 floats instead of a Vector3", "1.5.4-9.11520" }, + { false, "getComponentRotation", "will return 3 floats instead of a Vector3", "1.5.4-9.11520" }, }; diff --git a/Server/mods/deathmatch/logic/CResourceChecker.cpp b/Server/mods/deathmatch/logic/CResourceChecker.cpp index 4506622a04b..0a321d8cbd5 100644 --- a/Server/mods/deathmatch/logic/CResourceChecker.cpp +++ b/Server/mods/deathmatch/logic/CResourceChecker.cpp @@ -23,6 +23,8 @@ extern CNetServer* g_pRealNetServer; /////////////////////////////////////////////////////////////// void CResourceChecker::CheckResourceForIssues( CResource* pResource, const string& strResourceZip ) { + m_strMinClientReqFromMetaXml = pResource->GetMinClientReqFromMetaXml(); + m_strMinServerReqFromMetaXml = pResource->GetMinServerReqFromMetaXml(); m_strReqClientVersion = ""; m_strReqServerVersion = ""; m_strReqClientReason = ""; @@ -324,32 +326,17 @@ void CResourceChecker::CheckMetaFileForIssues ( const string& strPath, const str /////////////////////////////////////////////////////////////// void CResourceChecker::CheckMetaSourceForIssues ( CXMLNode* pRootNode, const string& strFileName, const string& strResourceName, ECheckerModeType checkerMode, bool* pbOutHasChanged ) { - // Find the client and server version requirements - SString strMinClientReqFromMetaXml = ""; - SString strMinServerReqFromMetaXml = ""; - CXMLNode* pNodeMinMtaVersion = pRootNode->FindSubNode ( "min_mta_version", 0 ); - - if ( pNodeMinMtaVersion ) - { - if ( CXMLAttribute* pAttr = pNodeMinMtaVersion->GetAttributes ().Find ( "server" ) ) - strMinServerReqFromMetaXml = pAttr->GetValue (); - if ( CXMLAttribute* pAttr = pNodeMinMtaVersion->GetAttributes ().Find ( "client" ) ) - strMinClientReqFromMetaXml = pAttr->GetValue (); - if ( CXMLAttribute* pAttr = pNodeMinMtaVersion->GetAttributes ().Find ( "both" ) ) - strMinServerReqFromMetaXml = strMinClientReqFromMetaXml = pAttr->GetValue (); - } - - // Is it right? - if ( m_strReqClientVersion > strMinClientReqFromMetaXml || m_strReqServerVersion > strMinServerReqFromMetaXml ) + // Check min_mta_version is correct + if ( m_strReqClientVersion > m_strMinClientReqFromMetaXml || m_strReqServerVersion > m_strMinServerReqFromMetaXml ) { // It's not right. What to do? if ( checkerMode == ECheckerMode::WARNINGS ) { SString strTemp = " section in the meta.xml is incorrect or missing (expected at least "; - if ( m_strReqClientVersion > strMinClientReqFromMetaXml ) + if ( m_strReqClientVersion > m_strMinClientReqFromMetaXml ) strTemp += SString ( "client %s because of '%s')", *m_strReqClientVersion, *m_strReqClientReason ); else - if ( m_strReqServerVersion > strMinServerReqFromMetaXml ) + if ( m_strReqServerVersion > m_strMinServerReqFromMetaXml ) strTemp += SString ( "server %s because of '%s')", *m_strReqServerVersion, *m_strReqServerReason ); CLogger::LogPrint ( SString ( "WARNING: %s %s\n", strResourceName.c_str (), *strTemp ) ); @@ -358,6 +345,7 @@ void CResourceChecker::CheckMetaSourceForIssues ( CXMLNode* pRootNode, const str if ( checkerMode == ECheckerMode::UPGRADE ) { // Create min_mta_version node if required + CXMLNode* pNodeMinMtaVersion = pRootNode->FindSubNode("min_mta_version", 0); if ( !pNodeMinMtaVersion ) pNodeMinMtaVersion = pRootNode->CreateSubNode ( "min_mta_version" ); @@ -692,8 +680,8 @@ long CResourceChecker::FindLuaIdentifier ( const char* szLuaSource, long* plOutL /////////////////////////////////////////////////////////////// bool CResourceChecker::UpgradeLuaFunctionName ( const string& strFunctionName, bool bClientScript, string& strOutUpgraded ) { - string strHow; - ECheckerWhatType what = GetLuaFunctionNameUpgradeInfo ( strFunctionName, bClientScript, strHow ); + string strHow, strVersion; + ECheckerWhatType what = GetLuaFunctionNameUpgradeInfo ( strFunctionName, bClientScript, strHow, strVersion ); if ( what == ECheckerWhat::REPLACED ) { @@ -714,8 +702,8 @@ bool CResourceChecker::UpgradeLuaFunctionName ( const string& strFunctionName, b /////////////////////////////////////////////////////////////// void CResourceChecker::IssueLuaFunctionNameWarnings ( const string& strFunctionName, const string& strFileName, const string& strResourceName, bool bClientScript, unsigned long ulLineNumber ) { - string strHow; - ECheckerWhatType what = GetLuaFunctionNameUpgradeInfo ( strFunctionName, bClientScript, strHow ); + string strHow, strVersion; + ECheckerWhatType what = GetLuaFunctionNameUpgradeInfo ( strFunctionName, bClientScript, strHow, strVersion ); if ( what == ECheckerWhat::NONE ) return; @@ -731,6 +719,11 @@ void CResourceChecker::IssueLuaFunctionNameWarnings ( const string& strFunctionN { strTemp.Format ( "%s no longer works. %s", strFunctionName.c_str (), strHow.c_str () ); } + else + if ( what == ECheckerWhat::MODIFIED ) + { + strTemp.Format ( "%s %s because %s setting in meta.xml is below %s", strFunctionName.c_str (), strHow.c_str (), bClientScript ? "Client" : "Server", strVersion.c_str() ); + } CLogger::LogPrint ( SString ( "WARNING: %s/%s(Line %lu) [%s] %s\n", strResourceName.c_str (), strFileName.c_str (), ulLineNumber, bClientScript ? "Client" : "Server", *strTemp ) ); } @@ -743,7 +736,7 @@ void CResourceChecker::IssueLuaFunctionNameWarnings ( const string& strFunctionN // // /////////////////////////////////////////////////////////////// -ECheckerWhatType CResourceChecker::GetLuaFunctionNameUpgradeInfo ( const string& strFunctionName, bool bClientScript, string& strOutHow ) +ECheckerWhatType CResourceChecker::GetLuaFunctionNameUpgradeInfo ( const string& strFunctionName, bool bClientScript, string& strOutHow, string& strOutVersion ) { static CHashMap < SString, SDeprecatedItem* > clientUpgradeInfoMap; static CHashMap < SString, SDeprecatedItem* > serverUpgradeInfoMap; @@ -764,6 +757,15 @@ ECheckerWhatType CResourceChecker::GetLuaFunctionNameUpgradeInfo ( const string& return ECheckerWhat::NONE; // Nothing found strOutHow = pItem->strNewName; + strOutVersion = pItem->strVersion; + if (!strOutVersion.empty()) + { + // Function behaviour depends on min_mta_version setting + const SString& strMinReqFromMetaXml = bClientScript ? m_strMinClientReqFromMetaXml : m_strMinServerReqFromMetaXml; + if (strMinReqFromMetaXml < strOutVersion) + return ECheckerWhat::MODIFIED; + return ECheckerWhat::NONE; + } return pItem->bRemoved ? ECheckerWhat::REMOVED : ECheckerWhat::REPLACED; } diff --git a/Server/mods/deathmatch/logic/CResourceChecker.h b/Server/mods/deathmatch/logic/CResourceChecker.h index 2a17db07e58..29544693364 100644 --- a/Server/mods/deathmatch/logic/CResourceChecker.h +++ b/Server/mods/deathmatch/logic/CResourceChecker.h @@ -39,6 +39,7 @@ namespace ECheckerWhat NONE, REMOVED, REPLACED, + MODIFIED, }; }; using ECheckerWhat::ECheckerWhatType; @@ -63,7 +64,7 @@ class CResourceChecker long FindLuaIdentifier ( const char* szLuaSource, long* plOutLength, long* plLineNumber ); bool UpgradeLuaFunctionName ( const string& strFunctionName, bool bClientScript, string& strOutUpgraded ); void IssueLuaFunctionNameWarnings ( const string& strFunctionName, const string& strFileName, const string& strResourceName, bool bClientScript, unsigned long ulLineNumber ); - ECheckerWhatType GetLuaFunctionNameUpgradeInfo ( const string& strFunctionName, bool bClientScript, string& strOutHow ); + ECheckerWhatType GetLuaFunctionNameUpgradeInfo ( const string& strFunctionName, bool bClientScript, string& strOutHow, string& strOutVersion ); int ReplaceFilesInZIP ( const string& strOrigZip, const string& strTempZip, const vector < string >& pathInArchiveList, const vector < string >& upgradedFullPathList ); bool RenameBackupFile ( const string& strOrigFilename, const string& strBakAppend ); void CheckVersionRequirements ( const string& strIdentifierName, bool bClientScript ); @@ -71,6 +72,8 @@ class CResourceChecker bool m_bUpgradeScripts; unsigned long m_ulDeprecatedWarningCount; vector < string > m_upgradedFullPathList; + SString m_strMinClientReqFromMetaXml; + SString m_strMinServerReqFromMetaXml; SString m_strReqClientVersion; SString m_strReqServerVersion; SString m_strReqClientReason;