Skip to content

Commit 1b953bf

Browse files
committed
Fixed resource file checksum error caused by scripts modifying downloaded files.
1 parent 71515c3 commit 1b953bf

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

MTA10/mods/deathmatch/logic/CResourceManager.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,19 @@ bool CResourceManager::IsResourceFile( const SString& strInFilename )
232232
return MapContains( m_ResourceFileMap, strFilename );
233233
}
234234

235+
// Remove this file from the checks as it has been changed by script actions
236+
void CResourceManager::FileModifedByScript( const SString& strInFilename )
237+
{
238+
SString strFilename = PathConform( strInFilename ).ToLower();
239+
CDownloadableResource* pResourceFile = MapFindRef( m_ResourceFileMap, strFilename );
240+
if ( pResourceFile )
241+
{
242+
SString strMessage( "Resource file modifed by script: %s ", *ConformResourcePath( strInFilename ) );
243+
AddReportLog( 7059, strMessage + g_pNet->GetConnectedServer( true ), 10 );
244+
MapRemove( m_ResourceFileMap, strFilename );
245+
}
246+
}
247+
235248
// Check resource file data matches server checksum
236249
void CResourceManager::ValidateResourceFile( const SString& strInFilename, const CBuffer& fileData )
237250
{
@@ -259,7 +272,7 @@ void CResourceManager::ValidateResourceFile( const SString& strInFilename, const
259272
CMD5Hasher::ConvertToHex( checksum.md5, szMd5 );
260273
char szMd5Wanted[33];
261274
CMD5Hasher::ConvertToHex( pResourceFile->GetServerChecksum().md5, szMd5Wanted );
262-
SString strMessage( "Resource file checksum failed: %s [Size:%d MD5:%s][Wanted:%s][datasize:%d]", *ConformResourcePath( strInFilename ), (int)FileSize( strInFilename ), szMd5, szMd5Wanted, fileData.GetSize() );
275+
SString strMessage( "Resource file checksum failed: %s [Size:%d MD5:%s][Wanted:%s][datasize:%d] ", *ConformResourcePath( strInFilename ), (int)FileSize( strInFilename ), szMd5, szMd5Wanted, fileData.GetSize() );
263276
g_pClientGame->TellServerSomethingImportant( 1007, strMessage, false );
264277
g_pCore->GetConsole ()->Print( strMessage );
265278
AddReportLog( 7057, strMessage + g_pNet->GetConnectedServer( true ), 10 );
@@ -269,7 +282,7 @@ void CResourceManager::ValidateResourceFile( const SString& strInFilename, const
269282
{
270283
char szMd5[33];
271284
CMD5Hasher::ConvertToHex( checksum.md5, szMd5 );
272-
SString strMessage( "Attempt to load resource file before it is ready: %s [Size:%d MD5:%s]", *ConformResourcePath( strInFilename ), (int)FileSize( strInFilename ), szMd5 );
285+
SString strMessage( "Attempt to load resource file before it is ready: %s [Size:%d MD5:%s] ", *ConformResourcePath( strInFilename ), (int)FileSize( strInFilename ), szMd5 );
273286
g_pClientGame->TellServerSomethingImportant( 1008, strMessage, false );
274287
g_pCore->GetConsole ()->Print( strMessage );
275288
AddReportLog( 7058, strMessage + g_pNet->GetConnectedServer( true ), 10 );

MTA10/mods/deathmatch/logic/CResourceManager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class CResourceManager
5656
void OnRemoveResourceFile ( CDownloadableResource* pResourceFile );
5757
void OnDownloadedResourceFile ( const SString& strFilename );
5858
bool IsResourceFile ( const SString& strFilename );
59+
void FileModifedByScript ( const SString& strFilename );
5960
void ValidateResourceFile ( const SString& strFilename, const CBuffer& fileData );
6061

6162
static bool ParseResourcePathInput ( std::string strInput, CResource* &pResource, std::string &strPath, std::string &strMetaPath );

MTA10/mods/shared_logic/luadefs/CLuaFileDefs.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ int CLuaFileDefs::fileCreate ( lua_State* luaVM )
6060
CResource* pResource = pLuaMain->GetResource ();
6161
if ( CResourceManager::ParseResourcePathInput ( filePath, pResource, strAbsPath ) )
6262
{
63+
// Inform file verifier
64+
g_pClientGame->GetResourceManager()->FileModifedByScript( strAbsPath );
65+
6366
// Make sure the destination folder exist so we can create the file
6467
MakeSureDirExists ( strAbsPath.c_str () );
6568

@@ -163,6 +166,10 @@ int CLuaFileDefs::fileOpen ( lua_State* luaVM )
163166
CResource* pResource = pLuaMain->GetResource ();
164167
if ( CResourceManager::ParseResourcePathInput ( filePath, pResource, strAbsPath ) )
165168
{
169+
// Inform file verifier
170+
if ( !readOnly )
171+
g_pClientGame->GetResourceManager()->FileModifedByScript( strAbsPath );
172+
166173
// Create the file to create
167174
CScriptFile* pFile = new CScriptFile ( strAbsPath.c_str (), DEFAULT_MAX_FILESIZE );
168175
assert ( pFile );
@@ -548,6 +555,9 @@ int CLuaFileDefs::fileDelete ( lua_State* luaVM )
548555
CResource* pResource = pLuaMain->GetResource ();
549556
if ( CResourceManager::ParseResourcePathInput ( filePath, pResource, strPath ) )
550557
{
558+
// Inform file verifier
559+
g_pClientGame->GetResourceManager()->FileModifedByScript( strPath );
560+
551561
if ( FileDelete ( strPath.c_str () ) )
552562
{
553563
// If file removed return success
@@ -610,6 +620,9 @@ int CLuaFileDefs::fileRename ( lua_State* luaVM )
610620
}
611621
else
612622
{
623+
// Inform file verifier
624+
g_pClientGame->GetResourceManager()->FileModifedByScript( strCurAbsPath );
625+
613626
// Make sure the destination folder exist so we can move the file
614627
MakeSureDirExists ( strNewAbsPath.c_str () );
615628

@@ -684,6 +697,9 @@ int CLuaFileDefs::fileCopy ( lua_State* luaVM )
684697
}
685698
else
686699
{
700+
// Inform file verifier
701+
g_pClientGame->GetResourceManager()->FileModifedByScript( strNewAbsPath );
702+
687703
// Make sure the destination folder exists so we can copy the file
688704
MakeSureDirExists ( strNewAbsPath );
689705

0 commit comments

Comments
 (0)