Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Client/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand All @@ -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;
}

//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
78 changes: 75 additions & 3 deletions Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*****************************************************************************/

#include "StdInc.h"
#define MIN_CLIENT_REQ_GETVEHICLECOMPONENT_OOP "1.5.5-9.11710"

void CLuaVehicleDefs::LoadFunctions ( void )
{
Expand Down Expand Up @@ -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" );
Expand Down Expand Up @@ -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"] )
Expand Down Expand Up @@ -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"] )
Expand Down Expand Up @@ -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 );
Expand Down
4 changes: 2 additions & 2 deletions Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
4 changes: 4 additions & 0 deletions Server/mods/deathmatch/logic/CResourceChecker.Data.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ namespace
bool bRemoved;
SString strOldName;
SString strNewName;
SString strVersion;
};

SDeprecatedItem clientDeprecatedList[] = {
Expand Down Expand Up @@ -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" },
};


Expand Down
50 changes: 26 additions & 24 deletions Server/mods/deathmatch/logic/CResourceChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";
Expand Down Expand Up @@ -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 = "<min_mta_version> 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 ) );
Expand All @@ -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" );

Expand Down Expand Up @@ -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 )
{
Expand All @@ -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;
Expand All @@ -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 <min_mta_version> %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 ) );
}
Expand All @@ -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;
Expand All @@ -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;
}

Expand Down
5 changes: 4 additions & 1 deletion Server/mods/deathmatch/logic/CResourceChecker.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ namespace ECheckerWhat
NONE,
REMOVED,
REPLACED,
MODIFIED,
};
};
using ECheckerWhat::ECheckerWhatType;
Expand All @@ -63,14 +64,16 @@ 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 );

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;
Expand Down