Skip to content

Commit

Permalink
Merge branch 'master' into server/breakObject
Browse files Browse the repository at this point in the history
  • Loading branch information
FileEX authored May 24, 2024
2 parents 9797f09 + ee7d32a commit eff2694
Show file tree
Hide file tree
Showing 569 changed files with 45,968 additions and 29,479 deletions.
2 changes: 1 addition & 1 deletion Client/cefweb/CWebView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ bool CWebView::SetAudioVolume(float fVolume)

for (auto& name : frameNames)
{
auto frame = m_pWebView->GetFrame(name);
auto frame = m_pWebView->GetFrameByName(name);
frame->ExecuteJavaScript(strJSCode, "", 0);
}
m_fVolume = fVolume;
Expand Down
6 changes: 3 additions & 3 deletions Client/loader/MainFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -863,9 +863,9 @@ void CheckDataFiles()
{
const char* expected;
const char* fileName;
} integrityCheckList[] = {{"DFACEEEB636240C0190C7B1B0145C89E", "bass.dll"}, {"FBE6A48C4E9FAAA6569C360DD49CCE06", "bass_aac.dll"},
{"E7E69A3B369F0ABA1A4A18C831BC4364", "bass_ac3.dll"}, {"8164042444F819CA107297CA4A0408F3", "bass_fx.dll"},
{"9F48DD702AB5BE002F9223E3B45A2261", "bassflac.dll"}, {"4E89426025D1E1F524495D910B60C709", "bassmidi.dll"},
} integrityCheckList[] = {{"36CB1B284BC7CBB4F25CD00BBB044550", "bass.dll"}, {"1B909B47946167D153FB94020393E781", "bass_aac.dll"},
{"E7E69A3B369F0ABA1A4A18C831BC4364", "bass_ac3.dll"}, {"E20A57EA7D845FADC9A48A0AA919121A", "bass_fx.dll"},
{"F47DCE69DAFAA06A55A4BC1F07F80C8A", "bassflac.dll"}, {"F246D72BA73E9624FE8BE66E785FB5C5", "bassmidi.dll"},
{"5DEEC10A943E352EF7E0223327E8B48C", "bassmix.dll"}, {"2F87C5E0A1B7B28C8FC0D7E74116DDFC", "bassopus.dll"},
{"0F1B2FC6C0C703A43A24DC05352E7ADA", "basswebm.dll"}, {"893113C6C49DC1E1EF288310E68DB306", "basswma.dll"},
{"C6A44FC3CF2F5801561804272217B14D", "D3DX9_42.dll"}, {"D439E8EDD8C93D7ADE9C04BCFE9197C6", "sa.dat"},
Expand Down
1 change: 1 addition & 0 deletions Server/mods/deathmatch/logic/CGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1591,6 +1591,7 @@ void CGame::AddBuiltInEvents()
m_Events.AddEvent("onPlayerProjectileCreation", "weaponType, posX, posY, posZ, force, target, rotX, rotY, rotZ, velX, velY, velZ", nullptr, false);
m_Events.AddEvent("onPlayerDetonateSatchels", "", nullptr, false);
m_Events.AddEvent("onPlayerTriggerEventThreshold", "", nullptr, false);
m_Events.AddEvent("onPlayerTeamChange", "oldTeam, newTeam", nullptr, false);

// Ped events
m_Events.AddEvent("onPedVehicleEnter", "vehicle, seat, jacked", NULL, false);
Expand Down
155 changes: 120 additions & 35 deletions Server/mods/deathmatch/logic/CResource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "lua/CLuaFunctionParseHelpers.h"
#include <net/SimHeaders.h>
#include <zip.h>
#include <glob/glob.h>

#ifdef WIN32
#include <zip/iowin32.h>
Expand Down Expand Up @@ -388,6 +389,7 @@ void CResource::TidyUp()
delete pResourceFile;

m_ResourceFiles.clear();
m_ResourceFilesCountPerDir.clear();

// Go through each included resource item and delete it
for (CIncludedResources* pIncludedResources : m_IncludedResources)
Expand Down Expand Up @@ -595,8 +597,12 @@ bool CResource::GenerateChecksums()
bool CResource::HasResourceChanged()
{
std::string strPath;
std::string_view strDirPath = m_strResourceDirectoryPath;

if (IsResourceZip())
{
strDirPath = m_strResourceCachePath;

// Zip file might have changed
CChecksum checksum = CChecksum::GenerateChecksumFromFileUnsafe(m_strResourceZip);
if (checksum != m_zipHash)
Expand Down Expand Up @@ -633,6 +639,14 @@ bool CResource::HasResourceChanged()
}
}

for (const auto& [strGlob, uiFileCount] : m_ResourceFilesCountPerDir)
{
std::vector<std::filesystem::path> files = glob::rglob(strDirPath.data() + strGlob);

if (files.size() != uiFileCount)
return true;
}

if (GetFilePath("meta.xml", strPath))
{
CChecksum checksum = CChecksum::GenerateChecksumFromFileUnsafe(strPath);
Expand Down Expand Up @@ -1341,6 +1355,23 @@ bool CResource::GetFilePath(const char* szFilename, string& strPath)
return FileExists(strPath);
}

std::vector<std::string> CResource::GetFilePaths(const char* szFilename)
{
std::vector<std::string> vecFiles;
const std::string& strDirectory = IsResourceZip() ? m_strResourceCachePath : m_strResourceDirectoryPath;
const std::string strFilePath = strDirectory + szFilename;

for (const std::filesystem::path& path : glob::rglob(strFilePath))
{
std::string strPath = std::filesystem::relative(path, strDirectory).string();
ReplaceSlashes(strPath);

vecFiles.push_back(std::move(strPath));
}

return vecFiles;
}

// Return true if file name is used by this resource
bool CResource::IsFilenameUsed(const SString& strFilename, bool bClient)
{
Expand Down Expand Up @@ -1586,37 +1617,59 @@ bool CResource::ReadIncludedFiles(CXMLNode* pRoot)

if (!strFilename.empty())
{
std::string strFullFilename;
ReplaceSlashes(strFilename);

if (IsFilenameUsed(strFilename, true))
if (!IsValidFilePath(strFilename.c_str()))
{
m_strFailureReason = SString("Couldn't find file(s) %s for resource %s\n", strFilename.c_str(), m_strResourceName.c_str());
CLogger::ErrorPrintf(m_strFailureReason);
return false;
}

std::vector<std::string> vecFiles = GetFilePaths(strFilename.c_str());

if (vecFiles.empty())
{
CLogger::LogPrintf("WARNING: Ignoring duplicate client file in resource '%s': '%s'\n", m_strResourceName.c_str(), strFilename.c_str());
continue;
if (glob::has_magic(strFilename))
{
m_ResourceFilesCountPerDir[strFilename] = vecFiles.size();
continue;
}

m_strFailureReason = SString("Couldn't find file(s) %s for resource %s\n", strFilename.c_str(), m_strResourceName.c_str());
CLogger::ErrorPrintf(m_strFailureReason);
return false;
}

bool bDownload = true;
CXMLAttribute* pDownload = Attributes.Find("download");

if (pDownload)
{
const char* szDownload = pDownload->GetValue().c_str();
const std::string strDownload = pDownload->GetValue();

if (!stricmp(szDownload, "no") || !stricmp(szDownload, "false"))
if (strDownload == "no" || strDownload == "false")
bDownload = false;
}

// Create a new resourcefile item
if (IsValidFilePath(strFilename.c_str()) && GetFilePath(strFilename.c_str(), strFullFilename))
for (const std::string& strFilePath : vecFiles)
{
m_ResourceFiles.push_back(new CResourceClientFileItem(this, strFilename.c_str(), strFullFilename.c_str(), &Attributes, bDownload));
}
else
{
m_strFailureReason = SString("Couldn't find file %s for resource %s\n", strFilename.c_str(), m_strResourceName.c_str());
CLogger::ErrorPrintf(m_strFailureReason);
return false;
std::string strFullFilename;

if (IsFilenameUsed(strFilePath, true))
{
CLogger::LogPrintf("WARNING: Ignoring duplicate client file in resource '%s': '%s'\n", m_strResourceName.c_str(), strFilePath.c_str());
continue;
}

if (GetFilePath(strFilePath.c_str(), strFullFilename))
{
m_ResourceFiles.push_back(new CResourceClientFileItem(this, strFilePath.c_str(), strFullFilename.c_str(), &Attributes, bDownload));
}
}

if (glob::has_magic(strFilename))
m_ResourceFilesCountPerDir[strFilename] = vecFiles.size();
}
else
{
Expand Down Expand Up @@ -1766,35 +1819,67 @@ bool CResource::ReadIncludedScripts(CXMLNode* pRoot)

if (!strFilename.empty())
{
std::string strFullFilename;
ReplaceSlashes(strFilename);

if (bClient && IsFilenameUsed(strFilename, true))
{
CLogger::LogPrintf("WARNING: Ignoring duplicate client script file in resource '%s': '%s'\n", m_strResourceName.c_str(),
strFilename.c_str());
bClient = false;
}
if (bServer && IsFilenameUsed(strFilename, false))
if (!IsValidFilePath(strFilename.c_str()))
{
CLogger::LogPrintf("WARNING: Duplicate script file in resource '%s': '%s'\n", m_strResourceName.c_str(), strFilename.c_str());
m_strFailureReason = SString("Couldn't find script(s) %s for resource %s\n", strFilename.c_str(), m_strResourceName.c_str());
CLogger::ErrorPrintf(m_strFailureReason);
return false;
}

// Extract / get the filepath of the file
if (IsValidFilePath(strFilename.c_str()) && GetFilePath(strFilename.c_str(), strFullFilename))
{
// Create it depending on the type (client or server or shared) and add it to the list of resource files
if (bServer)
m_ResourceFiles.push_back(new CResourceScriptItem(this, strFilename.c_str(), strFullFilename.c_str(), &Attributes));
if (bClient)
m_ResourceFiles.push_back(new CResourceClientScriptItem(this, strFilename.c_str(), strFullFilename.c_str(), &Attributes));
}
else
std::vector<std::string> vecFiles = GetFilePaths(strFilename.c_str());

if (vecFiles.empty())
{
m_strFailureReason = SString("Couldn't find script %s for resource %s\n", strFilename.c_str(), m_strResourceName.c_str());
if (glob::has_magic(strFilename))
{
m_ResourceFilesCountPerDir[strFilename] = vecFiles.size();
continue;
}

m_strFailureReason = SString("Couldn't find script(s) %s for resource %s\n", strFilename.c_str(), m_strResourceName.c_str());
CLogger::ErrorPrintf(m_strFailureReason);
return false;
}

for (const std::string& strFilePath : vecFiles)
{
std::string strFullFilename;
bool bLoadClient = bClient;
bool bLoadServer = bServer;

if (GetFilePath(strFilePath.c_str(), strFullFilename))
{
// Check if the filename is already used by this resource

if (bClient && IsFilenameUsed(strFilePath, true))
{
CLogger::LogPrintf("WARNING: Ignoring duplicate client script file in resource '%s': '%s'\n", m_strResourceName.c_str(),
strFilePath.c_str());
bLoadClient = false;
}

if (bServer && IsFilenameUsed(strFilePath, false))
{
CLogger::LogPrintf("WARNING: Ignoring duplicate script file in resource '%s': '%s'\n", m_strResourceName.c_str(),
strFilePath.c_str());

bLoadServer = false;
}

// Create it depending on the type (client or server or shared) and add it to the list of resource files

if (bLoadServer)
m_ResourceFiles.push_back(new CResourceScriptItem(this, strFilePath.c_str(), strFullFilename.c_str(), &Attributes));

if (bLoadClient)
m_ResourceFiles.push_back(new CResourceClientScriptItem(this, strFilePath.c_str(), strFullFilename.c_str(), &Attributes));
}
}

if (glob::has_magic(strFilename))
m_ResourceFilesCountPerDir[strFilename] = vecFiles.size();
}
else
{
Expand Down
9 changes: 6 additions & 3 deletions Server/mods/deathmatch/logic/CResource.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,11 @@ class CResource : public EHS
bool CheckIfStartable();
void DisplayInfo();

bool GetFilePath(const char* szFilename, std::string& strPath);
const std::string& GetResourceDirectoryPath() const { return m_strResourceDirectoryPath; }
const std::string& GetResourceCacheDirectoryPath() const { return m_strResourceCachePath; }
bool GetFilePath(const char* szFilename, std::string& strPath);
std::vector<std::string> GetFilePaths(const char* szFilename);

const std::string& GetResourceDirectoryPath() const { return m_strResourceDirectoryPath; }
const std::string& GetResourceCacheDirectoryPath() const { return m_strResourceCachePath; }

std::list<CResourceFile*>& GetFiles() { return m_ResourceFiles; }
size_t GetFileCount() const noexcept { return m_ResourceFiles.size(); }
Expand Down Expand Up @@ -395,6 +397,7 @@ class CResource : public EHS
KeyValueMap m_Info;
std::list<CIncludedResources*> m_IncludedResources; // we store them here temporarily, then read them once all the resources are loaded
std::list<CResourceFile*> m_ResourceFiles;
std::map<std::string, int> m_ResourceFilesCountPerDir;
std::list<CResource*> m_Dependents; // resources that have "included" or loaded this one
std::list<CExportedFunction> m_ExportedFunctions;
std::list<CResource*> m_TemporaryIncludes; // started by startResource script command
Expand Down
54 changes: 42 additions & 12 deletions Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,19 +328,36 @@ bool CStaticFunctionDefinitions::DestroyElement(CElement* pElement)

// We can't destroy the root or a player/remote client/console
int iType = pElement->GetType();
if (pElement == m_pMapManager->GetRootElement() || iType == CElement::PLAYER || iType == CElement::CONSOLE ||
if (pElement == m_pMapManager->GetRootElement() || iType == CElement::PLAYER || iType == CElement::CONSOLE ||
g_pGame->GetResourceManager()->IsAResourceElement(pElement))
{
return false;
}

if (iType == CElement::TEAM) { // Its team trigger onPlayerTeamChange for each player in the team
CTeam* pTeam = static_cast<CTeam*>(pElement);

auto iterBegin = pTeam->PlayersBegin();
auto iterEnd = pTeam->PlayersEnd();
CLuaArguments arguments;

for (auto iter = iterBegin; iter != iterEnd; ++iter)
{
CPlayer* player = *iter;
arguments.PushElement(pTeam); // Return team element as oldteam
arguments.PushNil(); // No new team return nil
player->CallEvent("onPlayerTeamChange", arguments);
arguments.DeleteArguments();
}
}

// Tell everyone to destroy it if this is not a per-player entity
if (IS_PERPLAYER_ENTITY(pElement))
{
// Unsync it (will destroy it for those that know about it)
CPerPlayerEntity* pEntity = static_cast<CPerPlayerEntity*>(pElement);
pEntity->Sync(false);
}
}

// Tell everyone to destroy it
CEntityRemovePacket Packet;
Expand Down Expand Up @@ -9222,21 +9239,34 @@ bool CStaticFunctionDefinitions::SetPlayerTeam(CPlayer* pPlayer, CTeam* pTeam)
{
assert(pPlayer);

CTeam* currentTeam = pPlayer->GetTeam();
// If its a different team
if (pTeam != pPlayer->GetTeam())
if (pTeam == currentTeam)
return false;

// Call the Event
CLuaArguments Arguments;
if (currentTeam)
{
// Change his team
pPlayer->SetTeam(pTeam, true);
Arguments.PushElement(currentTeam);
}
else
{
Arguments.PushNil(); // No oldTeam return nil
}
Arguments.PushElement(pTeam);
if (!pPlayer->CallEvent("onPlayerTeamChange", Arguments))
return false; // Event cancelled, return false

// Tell everyone his new team
CBitStream BitStream;
BitStream.pBitStream->Write(pTeam ? pTeam->GetID() : INVALID_ELEMENT_ID);
m_pPlayerManager->BroadcastOnlyJoined(CElementRPCPacket(pPlayer, SET_PLAYER_TEAM, *BitStream.pBitStream));
// Change his team
pPlayer->SetTeam(pTeam, true);

return true;
}
// Tell everyone his new team
CBitStream BitStream;
BitStream.pBitStream->Write(pTeam ? pTeam->GetID() : INVALID_ELEMENT_ID);
m_pPlayerManager->BroadcastOnlyJoined(CElementRPCPacket(pPlayer, SET_PLAYER_TEAM, *BitStream.pBitStream));

return false;
return true;
}

bool CStaticFunctionDefinitions::SetTeamFriendlyFire(CTeam* pTeam, bool bFriendlyFire)
Expand Down
3 changes: 2 additions & 1 deletion Server/mods/deathmatch/premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ project "Deathmatch"
"../../../vendor/bochs",
"../../../vendor/pme",
"../../../vendor/zip",
"../../../vendor/glob/include",
"../../../vendor/zlib",
"../../../vendor/pcre",
"../../../vendor/json-c",
Expand All @@ -33,7 +34,7 @@ project "Deathmatch"

defines { "SDK_WITH_BCRYPT" }
links {
"Lua_Server", "sqlite", "ehs", "cryptopp", "pme", "pcre", "json-c", "zip", "zlib", "blowfish_bcrypt",
"Lua_Server", "sqlite", "ehs", "cryptopp", "pme", "pcre", "json-c", "zip", "glob", "zlib", "blowfish_bcrypt",
}

vpaths {
Expand Down
Binary file modified Shared/data/MTA San Andreas/MTA/bass.dll
Binary file not shown.
Binary file modified Shared/data/MTA San Andreas/MTA/bass_aac.dll
Binary file not shown.
Binary file modified Shared/data/MTA San Andreas/MTA/bass_fx.dll
Binary file not shown.
Binary file modified Shared/data/MTA San Andreas/MTA/bassflac.dll
Binary file not shown.
Binary file modified Shared/data/MTA San Andreas/MTA/bassmidi.dll
Binary file not shown.
Binary file modified Shared/data/launchers/CEFLauncher.exe
Binary file not shown.
Binary file modified Shared/data/launchers/MTA Server ARM64.exe
Binary file not shown.
Binary file modified Shared/data/launchers/MTA Server.exe
Binary file not shown.
Binary file modified Shared/data/launchers/MTA Server64.exe
Binary file not shown.
Binary file modified Shared/data/launchers/Multi Theft Auto.exe
Binary file not shown.
Binary file modified Shared/data/launchers/wow64_helper.exe
Binary file not shown.
4 changes: 2 additions & 2 deletions Shared/mods/deathmatch/logic/luadefs/CLuaFileDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ int CLuaFileDefs::File(lua_State* luaVM)

if (CResourceManager::ParseResourcePathInput(strInputPath, pResource, &strAbsPath, &strMetaPath))
{
CheckCanModifyOtherResource(argStream, pResource, pResource);
CheckCanAccessOtherResourceFile(argStream, pResource, pResource, strAbsPath);
CheckCanModifyOtherResource(argStream, pThisResource, pResource);
CheckCanAccessOtherResourceFile(argStream, pThisResource, pResource, strAbsPath);

if (!argStream.HasErrors())
{
Expand Down
Loading

0 comments on commit eff2694

Please sign in to comment.