From 4f3acf9cda0af7e8bb3083fda3b84661bb49700a Mon Sep 17 00:00:00 2001 From: Tracer <43095317+TracerDS@users.noreply.github.com> Date: Tue, 23 Jul 2024 14:13:33 +0200 Subject: [PATCH 1/8] Add `getLoadedFiles` --- Client/mods/deathmatch/logic/CResource.h | 2 ++ .../logic/luadefs/CLuaResourceDefs.cpp | 19 ++++++++++++++++++- .../logic/luadefs/CLuaResourceDefs.h | 1 + Server/mods/deathmatch/logic/CResource.h | 4 ++-- .../deathmatch/logic/CResourceManager.cpp | 2 +- .../logic/luadefs/CLuaResourceDefs.cpp | 17 ++++++++++++++++- .../logic/luadefs/CLuaResourceDefs.h | 2 ++ 7 files changed, 42 insertions(+), 5 deletions(-) diff --git a/Client/mods/deathmatch/logic/CResource.h b/Client/mods/deathmatch/logic/CResource.h index 99df87fc3c..1d4499c182 100644 --- a/Client/mods/deathmatch/logic/CResource.h +++ b/Client/mods/deathmatch/logic/CResource.h @@ -87,6 +87,8 @@ class CResource const auto& GetExportedFunctions() const noexcept { return m_exportedFunctions; } + std::list& GetResourceFiles() noexcept { return m_ResourceFiles; } + const std::list& GetResourceFiles() const noexcept { return m_ResourceFiles; } std::list::iterator IterBeginResourceFiles() { return m_ResourceFiles.begin(); } std::list::iterator IterEndResourceFiles() { return m_ResourceFiles.end(); } diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaResourceDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaResourceDefs.cpp index 113d810f68..f84813a7f8 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaResourceDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaResourceDefs.cpp @@ -16,7 +16,8 @@ using std::list; void CLuaResourceDefs::LoadFunctions() { - constexpr static const std::pair functions[]{ + constexpr static const std::pair functions[] + { {"call", Call}, {"getThisResource", GetThisResource}, {"getResourceConfig", GetResourceConfig}, @@ -29,6 +30,7 @@ void CLuaResourceDefs::LoadFunctions() {"getResourceState", GetResourceState}, {"loadstring", LoadString}, {"load", Load}, + {"getLoadedFiles", ArgumentParser}, }; // Add functions @@ -545,3 +547,18 @@ int CLuaResourceDefs::Load(lua_State* luaVM) lua_pushboolean(luaVM, false); return 1; } + +std::vector CLuaResourceDefs::GetLoadedFiles(lua_State* luaVM, std::optional resource) noexcept +{ + if (!resource) + resource = &lua_getownerresource(luaVM); + + const auto resourceFiles = (*resource)->GetResourceFiles(); + + std::vector files; + files.reserve(resourceFiles.size()); + for (const auto& file : resourceFiles) + files.push_back(file->GetName()); + + return files; +} diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaResourceDefs.h b/Client/mods/deathmatch/logic/luadefs/CLuaResourceDefs.h index eba15fa6c7..53038ad8d1 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaResourceDefs.h +++ b/Client/mods/deathmatch/logic/luadefs/CLuaResourceDefs.h @@ -31,4 +31,5 @@ class CLuaResourceDefs : public CLuaDefs LUA_DECLARE(Load); static std::string GetResourceName(lua_State* luaVM, std::optional resourceElement); + static std::vector GetLoadedFiles(lua_State* luaVM, std::optional resource) noexcept; }; diff --git a/Server/mods/deathmatch/logic/CResource.h b/Server/mods/deathmatch/logic/CResource.h index 7c766e69db..c7396ffc89 100644 --- a/Server/mods/deathmatch/logic/CResource.h +++ b/Server/mods/deathmatch/logic/CResource.h @@ -256,8 +256,8 @@ class CResource : public EHS const std::string& GetResourceDirectoryPath() const { return m_strResourceDirectoryPath; } const std::string& GetResourceCacheDirectoryPath() const { return m_strResourceCachePath; } - std::list& GetFiles() { return m_ResourceFiles; } - size_t GetFileCount() const noexcept { return m_ResourceFiles.size(); } + std::list& GetResourceFiles() noexcept { return m_ResourceFiles; } + const std::list& GetResourceFiles() const noexcept { return m_ResourceFiles; } time_t GetTimeStarted() const noexcept { return m_timeStarted; } time_t GetTimeLoaded() const noexcept { return m_timeLoaded; } diff --git a/Server/mods/deathmatch/logic/CResourceManager.cpp b/Server/mods/deathmatch/logic/CResourceManager.cpp index b3b2d2f9c1..f5ee11e4d0 100644 --- a/Server/mods/deathmatch/logic/CResourceManager.cpp +++ b/Server/mods/deathmatch/logic/CResourceManager.cpp @@ -338,7 +338,7 @@ void CResourceManager::ListResourcesLoaded(const SString& strListType) else { if (strListType == "stopped" || strListType == "all") - CLogger::LogPrintf("%-20.20s STOPPED (%d files)\n", res->GetName().c_str(), res->GetFileCount()); + CLogger::LogPrintf("%-20.20s STOPPED (%d files)\n", res->GetName().c_str(), res->GetResourceFiles().size()); } uiCount++; } diff --git a/Server/mods/deathmatch/logic/luadefs/CLuaResourceDefs.cpp b/Server/mods/deathmatch/logic/luadefs/CLuaResourceDefs.cpp index baa2dbba46..c5351a7ff0 100644 --- a/Server/mods/deathmatch/logic/luadefs/CLuaResourceDefs.cpp +++ b/Server/mods/deathmatch/logic/luadefs/CLuaResourceDefs.cpp @@ -804,7 +804,7 @@ int CLuaResourceDefs::getResourceConfig(lua_State* luaVM) CheckCanModifyOtherResource(argStream, pThisResource, pResource); if (!argStream.HasErrors()) { - for (CResourceFile* pResourceFile : pResource->GetFiles()) + for (CResourceFile* pResourceFile : pResource->GetResourceFiles()) { if (pResourceFile->GetType() != CResourceFile::RESOURCE_FILE_TYPE_CONFIG) continue; @@ -1468,3 +1468,18 @@ bool CLuaResourceDefs::isResourceProtected(CResource* const resource) { return resource->IsProtected(); } + +std::vector CLuaResourceDefs::GetLoadedFiles(lua_State* luaVM, std::optional resource) noexcept +{ + if (!resource) + resource = &lua_getownerresource(luaVM); + + const auto resourceFiles = (*resource)->GetResourceFiles(); + + std::vector files; + files.reserve(resourceFiles.size()); + for (const auto& file : resourceFiles) + files.push_back(file->GetName()); + + return files; +} diff --git a/Server/mods/deathmatch/logic/luadefs/CLuaResourceDefs.h b/Server/mods/deathmatch/logic/luadefs/CLuaResourceDefs.h index 29304f402a..fca1f6b379 100644 --- a/Server/mods/deathmatch/logic/luadefs/CLuaResourceDefs.h +++ b/Server/mods/deathmatch/logic/luadefs/CLuaResourceDefs.h @@ -69,4 +69,6 @@ class CLuaResourceDefs : public CLuaDefs LUA_DECLARE(LoadString); LUA_DECLARE(Load); + + static std::vector GetLoadedFiles(lua_State* luaVM, std::optional resource) noexcept; }; From da7617f6c9285d56460014006b6a14d8621b2c33 Mon Sep 17 00:00:00 2001 From: Tracer <43095317+TracerDS@users.noreply.github.com> Date: Tue, 23 Jul 2024 14:22:39 +0200 Subject: [PATCH 2/8] Updated CLuaResourceDefs.cpp --- Client/mods/deathmatch/logic/luadefs/CLuaResourceDefs.cpp | 4 ++++ Server/mods/deathmatch/logic/luadefs/CLuaResourceDefs.cpp | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaResourceDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaResourceDefs.cpp index f84813a7f8..89c3aeeabb 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaResourceDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaResourceDefs.cpp @@ -558,7 +558,11 @@ std::vector CLuaResourceDefs::GetLoadedFiles(lua_State* luaVM, std: std::vector files; files.reserve(resourceFiles.size()); for (const auto& file : resourceFiles) + { + if (file->GetResourceType() != CResourceFile::eResourceType::RESOURCE_FILE_TYPE_CLIENT_FILE) + continue; files.push_back(file->GetName()); + } return files; } diff --git a/Server/mods/deathmatch/logic/luadefs/CLuaResourceDefs.cpp b/Server/mods/deathmatch/logic/luadefs/CLuaResourceDefs.cpp index c5351a7ff0..8dd9374086 100644 --- a/Server/mods/deathmatch/logic/luadefs/CLuaResourceDefs.cpp +++ b/Server/mods/deathmatch/logic/luadefs/CLuaResourceDefs.cpp @@ -73,6 +73,8 @@ void CLuaResourceDefs::LoadFunctions() {"getResourceACLRequests", getResourceACLRequests}, {"loadstring", LoadString}, {"load", Load}, + + {"getLoadedFiles", ArgumentParser}, }; // Add functions @@ -1479,7 +1481,12 @@ std::vector CLuaResourceDefs::GetLoadedFiles(lua_State* luaVM, std: std::vector files; files.reserve(resourceFiles.size()); for (const auto& file : resourceFiles) + { + if (file->GetType() != CResourceFile::eResourceType::RESOURCE_FILE_TYPE_CLIENT_FILE) + continue; + files.push_back(file->GetName()); + } return files; } From 8289dcb58fd46711beb454e8397df0b638f075a2 Mon Sep 17 00:00:00 2001 From: Tracer <43095317+TracerDS@users.noreply.github.com> Date: Sun, 28 Jul 2024 11:22:04 +0200 Subject: [PATCH 3/8] Updated code --- .../deathmatch/logic/CDownloadableResource.cpp | 15 +++++++++++++++ .../deathmatch/logic/CDownloadableResource.h | 11 +++++++++++ .../logic/lua/CLuaFunctionParseHelpers.cpp | 8 ++++++++ .../logic/lua/CLuaFunctionParseHelpers.h | 2 ++ .../logic/luadefs/CLuaResourceDefs.cpp | 15 ++++++++++----- .../deathmatch/logic/luadefs/CLuaResourceDefs.h | 5 ++++- .../logic/CResourceClientConfigItem.cpp | 2 ++ .../logic/CResourceClientFileItem.cpp | 1 + .../logic/CResourceClientScriptItem.cpp | 1 + .../deathmatch/logic/CResourceConfigItem.cpp | 1 + Server/mods/deathmatch/logic/CResourceFile.h | 11 +++++++++++ .../mods/deathmatch/logic/CResourceHTMLItem.cpp | 1 + .../mods/deathmatch/logic/CResourceMapItem.cpp | 1 + .../deathmatch/logic/CResourceScriptItem.cpp | 1 + .../logic/lua/CLuaFunctionParseHelpers.cpp | 8 ++++++++ .../logic/lua/CLuaFunctionParseHelpers.h | 4 +++- .../logic/luadefs/CLuaResourceDefs.cpp | 17 +++++++++++------ .../deathmatch/logic/luadefs/CLuaResourceDefs.h | 5 ++++- 18 files changed, 95 insertions(+), 14 deletions(-) diff --git a/Client/mods/deathmatch/logic/CDownloadableResource.cpp b/Client/mods/deathmatch/logic/CDownloadableResource.cpp index 23098b790b..80ff7e55dd 100644 --- a/Client/mods/deathmatch/logic/CDownloadableResource.cpp +++ b/Client/mods/deathmatch/logic/CDownloadableResource.cpp @@ -14,6 +14,21 @@ CDownloadableResource::CDownloadableResource(CResource* pResource, eResourceType resourceType, const char* szName, const char* szNameShort, uint uiDownloadSize, CChecksum serverChecksum, bool bAutoDownload) { + switch (resourceType) + { + case eResourceType::RESOURCE_FILE_TYPE_SCRIPT: + case eResourceType::RESOURCE_FILE_TYPE_CLIENT_SCRIPT: + m_resourceCategoryType = eResourceCategory::SCRIPTS; + case eResourceType::RESOURCE_FILE_TYPE_MAP: + m_resourceCategoryType = eResourceCategory::MAPS; + case eResourceType::RESOURCE_FILE_TYPE_CONFIG: + case eResourceType::RESOURCE_FILE_TYPE_CLIENT_CONFIG: + m_resourceCategoryType = eResourceCategory::CONFIGS; + case eResourceType::RESOURCE_FILE_TYPE_CLIENT_FILE: + case eResourceType::RESOURCE_FILE_TYPE_HTML: + m_resourceCategoryType = eResourceCategory::FILES; + } + m_pResource = pResource; m_resourceType = resourceType; m_strName = szName; diff --git a/Client/mods/deathmatch/logic/CDownloadableResource.h b/Client/mods/deathmatch/logic/CDownloadableResource.h index 5a1a9d4105..2ed0c2f104 100644 --- a/Client/mods/deathmatch/logic/CDownloadableResource.h +++ b/Client/mods/deathmatch/logic/CDownloadableResource.h @@ -35,6 +35,15 @@ class CDownloadableResource RESOURCE_FILE_TYPE_CLIENT_FILE, }; + enum class eResourceCategory + { + ALL, + SCRIPTS, + MAPS, + CONFIGS, + FILES, + }; + public: CDownloadableResource(CResource* pResource, eResourceType resourceType, const char* szName, const char* szNameShort, uint uiDownloadSize, CChecksum serverChecksum, bool bAutoDownload); @@ -43,6 +52,7 @@ class CDownloadableResource bool DoesClientAndServerChecksumMatch(); eResourceType GetResourceType() { return m_resourceType; }; + eResourceCategory GetResourceCategoryType() const noexcept { return m_resourceCategoryType; } const char* GetName() { return m_strName; }; const char* GetShortName() { return m_strNameShort; }; CResource* GetResource() { return m_pResource; } @@ -66,6 +76,7 @@ class CDownloadableResource protected: CResource* m_pResource; eResourceType m_resourceType; + eResourceCategory m_resourceCategoryType; SString m_strName; SString m_strNameShort; diff --git a/Client/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.cpp b/Client/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.cpp index 7090203704..8fbbe5edf7 100644 --- a/Client/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.cpp +++ b/Client/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.cpp @@ -896,6 +896,14 @@ ADD_ENUM(WEATHER_SANDSTORM, "Sandstorm") ADD_ENUM(WEATHER_RAINBOW, "Rainbow") IMPLEMENT_ENUM_END("world-property") +IMPLEMENT_ENUM_CLASS_BEGIN(CResourceFile::eResourceCategory) +ADD_ENUM(CResourceFile::eResourceCategory::ALL, "all") +ADD_ENUM(CResourceFile::eResourceCategory::CONFIGS, "config") +ADD_ENUM(CResourceFile::eResourceCategory::FILES, "file") +ADD_ENUM(CResourceFile::eResourceCategory::MAPS, "map") +ADD_ENUM(CResourceFile::eResourceCategory::SCRIPTS, "script") +IMPLEMENT_ENUM_CLASS_END("resource-category-type") + // // CResource from userdata // diff --git a/Client/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.h b/Client/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.h index 9b93980d85..24b544c9e6 100644 --- a/Client/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.h +++ b/Client/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.h @@ -14,6 +14,7 @@ #include #include #include +#include "CResourceFile.h" enum eLuaType { @@ -85,6 +86,7 @@ DECLARE_ENUM_CLASS(eRenderStage); DECLARE_ENUM_CLASS(eFxParticleSystems); DECLARE_ENUM(ePools); DECLARE_ENUM(eWorldProperty); +DECLARE_ENUM_CLASS(CResourceFile::eResourceCategory); class CRemoteCall; diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaResourceDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaResourceDefs.cpp index 89c3aeeabb..c7bef23a3c 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaResourceDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaResourceDefs.cpp @@ -30,7 +30,7 @@ void CLuaResourceDefs::LoadFunctions() {"getResourceState", GetResourceState}, {"loadstring", LoadString}, {"load", Load}, - {"getLoadedFiles", ArgumentParser}, + {"getResourceFiles", ArgumentParser}, }; // Add functions @@ -548,8 +548,12 @@ int CLuaResourceDefs::Load(lua_State* luaVM) return 1; } -std::vector CLuaResourceDefs::GetLoadedFiles(lua_State* luaVM, std::optional resource) noexcept +std::vector CLuaResourceDefs::GetResourceFiles(lua_State* luaVM, std::optional type, + std::optional resource) noexcept { + if (!type) + type = CResourceFile::eResourceCategory::ALL; + if (!resource) resource = &lua_getownerresource(luaVM); @@ -559,9 +563,10 @@ std::vector CLuaResourceDefs::GetLoadedFiles(lua_State* luaVM, std: files.reserve(resourceFiles.size()); for (const auto& file : resourceFiles) { - if (file->GetResourceType() != CResourceFile::eResourceType::RESOURCE_FILE_TYPE_CLIENT_FILE) - continue; - files.push_back(file->GetName()); + if (file->GetResourceCategoryType() == type.value() || type.value() == CResourceFile::eResourceCategory::ALL) + { + files.push_back(file->GetName()); + } } return files; diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaResourceDefs.h b/Client/mods/deathmatch/logic/luadefs/CLuaResourceDefs.h index 53038ad8d1..c0537f6ec6 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaResourceDefs.h +++ b/Client/mods/deathmatch/logic/luadefs/CLuaResourceDefs.h @@ -12,6 +12,8 @@ #pragma once #include "CLuaDefs.h" +enum class CResourceFile::eResourceCategory; + class CLuaResourceDefs : public CLuaDefs { public: @@ -31,5 +33,6 @@ class CLuaResourceDefs : public CLuaDefs LUA_DECLARE(Load); static std::string GetResourceName(lua_State* luaVM, std::optional resourceElement); - static std::vector GetLoadedFiles(lua_State* luaVM, std::optional resource) noexcept; + static std::vector GetResourceFiles(lua_State* luaVM, std::optional type, + std::optional resource) noexcept; }; diff --git a/Server/mods/deathmatch/logic/CResourceClientConfigItem.cpp b/Server/mods/deathmatch/logic/CResourceClientConfigItem.cpp index 6f31d31498..8d0dd79ab2 100644 --- a/Server/mods/deathmatch/logic/CResourceClientConfigItem.cpp +++ b/Server/mods/deathmatch/logic/CResourceClientConfigItem.cpp @@ -28,6 +28,8 @@ CResourceClientConfigItem::CResourceClientConfigItem(CResource* resource, const m_pXMLRootNode = NULL; m_bInvalid = false; m_type = RESOURCE_FILE_TYPE_CLIENT_CONFIG; + m_resourceCategoryType = eResourceCategory::CONFIGS; + } CResourceClientConfigItem::~CResourceClientConfigItem() diff --git a/Server/mods/deathmatch/logic/CResourceClientFileItem.cpp b/Server/mods/deathmatch/logic/CResourceClientFileItem.cpp index a86341248e..6dfab9087d 100644 --- a/Server/mods/deathmatch/logic/CResourceClientFileItem.cpp +++ b/Server/mods/deathmatch/logic/CResourceClientFileItem.cpp @@ -22,6 +22,7 @@ CResourceClientFileItem::CResourceClientFileItem(CResource* resource, const char : CResourceFile(resource, szShortName, szResourceFileName, xmlAttributes) { m_type = RESOURCE_FILE_TYPE_CLIENT_FILE; + m_resourceCategoryType = eResourceCategory::FILES; m_bClientAutoDownload = bClientAutoDownload; } diff --git a/Server/mods/deathmatch/logic/CResourceClientScriptItem.cpp b/Server/mods/deathmatch/logic/CResourceClientScriptItem.cpp index cf5426b955..b37f3716c7 100644 --- a/Server/mods/deathmatch/logic/CResourceClientScriptItem.cpp +++ b/Server/mods/deathmatch/logic/CResourceClientScriptItem.cpp @@ -25,6 +25,7 @@ CResourceClientScriptItem::CResourceClientScriptItem(CResource* resource, const : CResourceFile(resource, szShortName, szResourceFileName, xmlAttributes) { m_type = RESOURCE_FILE_TYPE_CLIENT_SCRIPT; + m_resourceCategoryType = eResourceCategory::SCRIPTS; // Check if this file should be cached by the client if (MapGet(m_attributeMap, "protected") == "true" || MapGet(m_attributeMap, "cache") == "false") diff --git a/Server/mods/deathmatch/logic/CResourceConfigItem.cpp b/Server/mods/deathmatch/logic/CResourceConfigItem.cpp index db96d28f56..bb21f705f5 100644 --- a/Server/mods/deathmatch/logic/CResourceConfigItem.cpp +++ b/Server/mods/deathmatch/logic/CResourceConfigItem.cpp @@ -30,6 +30,7 @@ CResourceConfigItem::CResourceConfigItem(CResource* resource, const char* szShor m_bInvalid = true; m_type = RESOURCE_FILE_TYPE_CONFIG; + m_resourceCategoryType = eResourceCategory::CONFIGS; } CResourceConfigItem::~CResourceConfigItem() diff --git a/Server/mods/deathmatch/logic/CResourceFile.h b/Server/mods/deathmatch/logic/CResourceFile.h index e58e61a72f..4fd332d318 100644 --- a/Server/mods/deathmatch/logic/CResourceFile.h +++ b/Server/mods/deathmatch/logic/CResourceFile.h @@ -37,12 +37,22 @@ class CResourceFile RESOURCE_FILE_TYPE_NONE, }; // TODO: sort all client-side enums and use >= (instead of each individual type) on comparisons that use this enum? + enum class eResourceCategory + { + ALL = 0, + SCRIPTS = 1, + MAPS = 2, + CONFIGS = 3, + FILES = 4, + }; + protected: class CResource* m_resource; std::string m_strResourceFileName; // full path std::string m_strShortName; // just the filename std::string m_strWindowsName; // the name with backwards slashes eResourceType m_type; + eResourceCategory m_resourceCategoryType; class CLuaMain* m_pVM; CChecksum m_checksum; // Checksum last time this was loaded, generated by GenerateChecksum() uint m_uiFileSize; @@ -59,6 +69,7 @@ class CResourceFile virtual bool IsNoClientCache() const { return false; } eResourceType GetType() { return m_type; } + eResourceCategory GetResourceCategoryType() const noexcept { return m_resourceCategoryType; } const char* GetName() { return m_strShortName.c_str(); } const char* GetFullName() { return m_strResourceFileName.c_str(); } const char* GetWindowsName() { return m_strWindowsName.c_str(); } diff --git a/Server/mods/deathmatch/logic/CResourceHTMLItem.cpp b/Server/mods/deathmatch/logic/CResourceHTMLItem.cpp index 2216526d94..d0f7f24c54 100644 --- a/Server/mods/deathmatch/logic/CResourceHTMLItem.cpp +++ b/Server/mods/deathmatch/logic/CResourceHTMLItem.cpp @@ -29,6 +29,7 @@ CResourceHTMLItem::CResourceHTMLItem(CResource* resource, const char* szShortNam { m_bIsRaw = bIsRaw; m_type = RESOURCE_FILE_TYPE_HTML; + m_resourceCategoryType = eResourceCategory::FILES; m_bDefault = bIsDefault; m_pVM = NULL; m_bIsBeingRequested = false; diff --git a/Server/mods/deathmatch/logic/CResourceMapItem.cpp b/Server/mods/deathmatch/logic/CResourceMapItem.cpp index 653d192ac2..9563c6cc14 100644 --- a/Server/mods/deathmatch/logic/CResourceMapItem.cpp +++ b/Server/mods/deathmatch/logic/CResourceMapItem.cpp @@ -45,6 +45,7 @@ CResourceMapItem::CResourceMapItem(CResource* pResource, const char* szShortName m_pElementGroup = nullptr; m_iDimension = iDimension; m_type = RESOURCE_FILE_TYPE_MAP; + m_resourceCategoryType = eResourceCategory::MAPS; m_pMapElement = nullptr; } diff --git a/Server/mods/deathmatch/logic/CResourceScriptItem.cpp b/Server/mods/deathmatch/logic/CResourceScriptItem.cpp index c1f183c859..cbe5193698 100644 --- a/Server/mods/deathmatch/logic/CResourceScriptItem.cpp +++ b/Server/mods/deathmatch/logic/CResourceScriptItem.cpp @@ -23,6 +23,7 @@ CResourceScriptItem::CResourceScriptItem(CResource* resource, const char* szShor : CResourceFile(resource, szShortName, szResourceFileName, xmlAttributes) { m_type = RESOURCE_FILE_TYPE_SCRIPT; + m_resourceCategoryType = eResourceCategory::SCRIPTS; } CResourceScriptItem::~CResourceScriptItem() diff --git a/Server/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.cpp b/Server/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.cpp index ef25750c05..31cf77baac 100644 --- a/Server/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.cpp +++ b/Server/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.cpp @@ -285,6 +285,14 @@ ADD_ENUM(ESyncType::LOCAL, "local") ADD_ENUM(ESyncType::SUBSCRIBE, "subscribe") IMPLEMENT_ENUM_CLASS_END("sync-mode") +IMPLEMENT_ENUM_CLASS_BEGIN(CResourceFile::eResourceCategory) +ADD_ENUM(CResourceFile::eResourceCategory::ALL, "all") +ADD_ENUM(CResourceFile::eResourceCategory::CONFIGS, "config") +ADD_ENUM(CResourceFile::eResourceCategory::FILES, "file") +ADD_ENUM(CResourceFile::eResourceCategory::MAPS, "map") +ADD_ENUM(CResourceFile::eResourceCategory::SCRIPTS, "script") +IMPLEMENT_ENUM_CLASS_END("resource-category-type") + // // CResource from userdata // diff --git a/Server/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.h b/Server/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.h index 52a4536012..8b2e100c84 100644 --- a/Server/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.h +++ b/Server/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.h @@ -8,13 +8,14 @@ #pragma once +#include #include "LuaCommon.h" #include "CElementIDs.h" #include "CConsoleClient.h" #include "CAccount.h" #include "CEasingCurve.h" #include "CAccessControlListRight.h" -#include +#include "CResourceFile.h" class CLuaVector2D; class CLuaVector3D; @@ -38,6 +39,7 @@ DECLARE_ENUM(CAccessControlListRight::ERightType); DECLARE_ENUM(CElement::EElementType); DECLARE_ENUM(CAccountPassword::EAccountPasswordType); DECLARE_ENUM_CLASS(ESyncType); +DECLARE_ENUM_CLASS(CResourceFile::eResourceCategory); enum eHudComponent { diff --git a/Server/mods/deathmatch/logic/luadefs/CLuaResourceDefs.cpp b/Server/mods/deathmatch/logic/luadefs/CLuaResourceDefs.cpp index 8dd9374086..30f4fb55d5 100644 --- a/Server/mods/deathmatch/logic/luadefs/CLuaResourceDefs.cpp +++ b/Server/mods/deathmatch/logic/luadefs/CLuaResourceDefs.cpp @@ -74,7 +74,7 @@ void CLuaResourceDefs::LoadFunctions() {"loadstring", LoadString}, {"load", Load}, - {"getLoadedFiles", ArgumentParser}, + {"getResourceFiles", ArgumentParser}, }; // Add functions @@ -1471,8 +1471,12 @@ bool CLuaResourceDefs::isResourceProtected(CResource* const resource) return resource->IsProtected(); } -std::vector CLuaResourceDefs::GetLoadedFiles(lua_State* luaVM, std::optional resource) noexcept +std::vector CLuaResourceDefs::GetResourceFiles(lua_State* luaVM, std::optional type, + std::optional resource) noexcept { + if (!type) + type = CResourceFile::eResourceCategory::ALL; + if (!resource) resource = &lua_getownerresource(luaVM); @@ -1482,10 +1486,11 @@ std::vector CLuaResourceDefs::GetLoadedFiles(lua_State* luaVM, std: files.reserve(resourceFiles.size()); for (const auto& file : resourceFiles) { - if (file->GetType() != CResourceFile::eResourceType::RESOURCE_FILE_TYPE_CLIENT_FILE) - continue; - - files.push_back(file->GetName()); + if (file->GetResourceCategoryType() == type.value() + || type.value() == CResourceFile::eResourceCategory::ALL) + { + files.push_back(file->GetName()); + } } return files; diff --git a/Server/mods/deathmatch/logic/luadefs/CLuaResourceDefs.h b/Server/mods/deathmatch/logic/luadefs/CLuaResourceDefs.h index fca1f6b379..04f9ecff73 100644 --- a/Server/mods/deathmatch/logic/luadefs/CLuaResourceDefs.h +++ b/Server/mods/deathmatch/logic/luadefs/CLuaResourceDefs.h @@ -12,6 +12,8 @@ #pragma once #include "CLuaDefs.h" +enum class CResourceFile::eResourceCategory; + class CLuaResourceDefs : public CLuaDefs { public: @@ -70,5 +72,6 @@ class CLuaResourceDefs : public CLuaDefs LUA_DECLARE(LoadString); LUA_DECLARE(Load); - static std::vector GetLoadedFiles(lua_State* luaVM, std::optional resource) noexcept; + static std::vector GetResourceFiles(lua_State* luaVM, std::optional type, + std::optional resource) noexcept; }; From 17e0c763aa6f2e2e613363c81894554b31d23d62 Mon Sep 17 00:00:00 2001 From: Tracer <43095317+TracerDS@users.noreply.github.com> Date: Sun, 28 Jul 2024 11:50:10 +0200 Subject: [PATCH 4/8] Fix MacOS/Linux builds --- Client/mods/deathmatch/logic/luadefs/CLuaResourceDefs.h | 2 -- Server/mods/deathmatch/logic/luadefs/CLuaResourceDefs.h | 2 -- 2 files changed, 4 deletions(-) diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaResourceDefs.h b/Client/mods/deathmatch/logic/luadefs/CLuaResourceDefs.h index c0537f6ec6..a68707fbcc 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaResourceDefs.h +++ b/Client/mods/deathmatch/logic/luadefs/CLuaResourceDefs.h @@ -12,8 +12,6 @@ #pragma once #include "CLuaDefs.h" -enum class CResourceFile::eResourceCategory; - class CLuaResourceDefs : public CLuaDefs { public: diff --git a/Server/mods/deathmatch/logic/luadefs/CLuaResourceDefs.h b/Server/mods/deathmatch/logic/luadefs/CLuaResourceDefs.h index 04f9ecff73..6dcc29cd6a 100644 --- a/Server/mods/deathmatch/logic/luadefs/CLuaResourceDefs.h +++ b/Server/mods/deathmatch/logic/luadefs/CLuaResourceDefs.h @@ -12,8 +12,6 @@ #pragma once #include "CLuaDefs.h" -enum class CResourceFile::eResourceCategory; - class CLuaResourceDefs : public CLuaDefs { public: From 452dde7c4102360c87ead207624c79821b0b5e68 Mon Sep 17 00:00:00 2001 From: Tracer <43095317+TracerDS@users.noreply.github.com> Date: Sun, 28 Jul 2024 19:36:30 +0200 Subject: [PATCH 5/8] Updated code according to reviews --- Client/mods/deathmatch/logic/luadefs/CLuaResourceDefs.cpp | 2 ++ Server/mods/deathmatch/logic/luadefs/CLuaResourceDefs.cpp | 2 ++ 2 files changed, 4 insertions(+) diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaResourceDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaResourceDefs.cpp index 3822a57e05..b1a7128d49 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaResourceDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaResourceDefs.cpp @@ -54,6 +54,7 @@ void CLuaResourceDefs::AddClass(lua_State* luaVM) lua_classfunction(luaVM, "getDynamicElementRoot", "getResourceDynamicElementRoot"); lua_classfunction(luaVM, "getExportedFunctions", "getResourceExportedFunctions"); lua_classfunction(luaVM, "getState", "getResourceState"); + lua_classfunction(luaVM, "getFiles", "getResourceFiles"); lua_classvariable(luaVM, "config", NULL, "getResourceConfig"); lua_classvariable(luaVM, "dynamicElementRoot", NULL, "getResourceDynamicElementRoot"); @@ -62,6 +63,7 @@ void CLuaResourceDefs::AddClass(lua_State* luaVM) lua_classvariable(luaVM, "state", NULL, "getResourceState"); lua_classvariable(luaVM, "name", NULL, "getResourceName"); lua_classvariable(luaVM, "rootElement", NULL, "getResourceRootElement"); + lua_classvariable(luaVM, "files", nullptr, "getResourceFiles"); lua_registerclass(luaVM, "Resource"); } diff --git a/Server/mods/deathmatch/logic/luadefs/CLuaResourceDefs.cpp b/Server/mods/deathmatch/logic/luadefs/CLuaResourceDefs.cpp index 746c917517..0c3d036b7c 100644 --- a/Server/mods/deathmatch/logic/luadefs/CLuaResourceDefs.cpp +++ b/Server/mods/deathmatch/logic/luadefs/CLuaResourceDefs.cpp @@ -131,6 +131,7 @@ void CLuaResourceDefs::AddClass(lua_State* luaVM) lua_classfunction(luaVM, "getACLRequests", "getResourceACLRequests"); lua_classfunction(luaVM, "isArchived", "isResourceArchived"); lua_classfunction(luaVM, "isProtected", "isResourceProtected"); + lua_classfunction(luaVM, "getFiles", "getResourceFiles"); lua_classvariable(luaVM, "dynamicElementRoot", NULL, "getResourceDynamicElementRoot"); lua_classvariable(luaVM, "exportedFunctions", NULL, "getResourceExportedFunctions"); @@ -144,6 +145,7 @@ void CLuaResourceDefs::AddClass(lua_State* luaVM) lua_classvariable(luaVM, "archived", NULL, "isResourceArchived"); lua_classvariable(luaVM, "protected", nullptr, "isResourceProtected"); lua_classvariable(luaVM, "loadFailureReason", NULL, "getResourceLoadFailureReason"); + lua_classvariable(luaVM, "files", nullptr, "getResourceFiles"); lua_registerclass(luaVM, "Resource"); } From 6f6a8b3acaf47948de496fcb3ff741dea6044c21 Mon Sep 17 00:00:00 2001 From: Tracer <43095317+TracerDS@users.noreply.github.com> Date: Wed, 31 Jul 2024 16:46:16 +0200 Subject: [PATCH 6/8] Update CResourceFile.h --- Server/mods/deathmatch/logic/CResourceFile.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Server/mods/deathmatch/logic/CResourceFile.h b/Server/mods/deathmatch/logic/CResourceFile.h index 916d657c8f..64c97aa6bc 100644 --- a/Server/mods/deathmatch/logic/CResourceFile.h +++ b/Server/mods/deathmatch/logic/CResourceFile.h @@ -39,11 +39,11 @@ class CResourceFile enum class eResourceCategory { - ALL = 0, - SCRIPTS = 1, - MAPS = 2, - CONFIGS = 3, - FILES = 4, + ALL, + SCRIPTS, + MAPS, + CONFIGS, + FILES, }; protected: From 543e6cddb0b27a5eec729f6182a24a5025fe6989 Mon Sep 17 00:00:00 2001 From: Tracer <43095317+TracerDS@users.noreply.github.com> Date: Sun, 4 Aug 2024 18:49:24 +0200 Subject: [PATCH 7/8] Update CLuaResourceDefs.cpp --- .../logic/luadefs/CLuaResourceDefs.cpp | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/Server/mods/deathmatch/logic/luadefs/CLuaResourceDefs.cpp b/Server/mods/deathmatch/logic/luadefs/CLuaResourceDefs.cpp index 0c3d036b7c..b0666320e7 100644 --- a/Server/mods/deathmatch/logic/luadefs/CLuaResourceDefs.cpp +++ b/Server/mods/deathmatch/logic/luadefs/CLuaResourceDefs.cpp @@ -1476,24 +1476,28 @@ bool CLuaResourceDefs::isResourceProtected(CResource* const resource) std::vector CLuaResourceDefs::GetResourceFiles(lua_State* luaVM, std::optional type, std::optional resource) noexcept { + using eResourceCategory = CResourceFile::eResourceCategory; + if (!type) - type = CResourceFile::eResourceCategory::ALL; + type = eResourceCategory::ALL; if (!resource) resource = &lua_getownerresource(luaVM); const auto resourceFiles = (*resource)->GetResourceFiles(); - std::vector files; - files.reserve(resourceFiles.size()); + std::unordered_set files; for (const auto& file : resourceFiles) { - if (file->GetResourceCategoryType() == type.value() - || type.value() == CResourceFile::eResourceCategory::ALL) - { - files.push_back(file->GetName()); - } + if (file->GetResourceCategoryType() != type.value() && type.value() != eResourceCategory::ALL) + continue; + files.insert(file->GetName()); } - return files; + // TODO: Upgrade ArgumentParser so it would accept + // std::set and std::unordered_set as return values + return std::vector( + std::make_move_iterator(files.begin()), + std::make_move_iterator(files.end()) + ); } From df5275ea1e212335c062c847f1f08e8e8e341e15 Mon Sep 17 00:00:00 2001 From: Tracer <43095317+TracerDS@users.noreply.github.com> Date: Sun, 4 Aug 2024 18:50:51 +0200 Subject: [PATCH 8/8] Update CLuaResourceDefs.cpp --- .../logic/luadefs/CLuaResourceDefs.cpp | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaResourceDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaResourceDefs.cpp index b1a7128d49..7e220685e1 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaResourceDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaResourceDefs.cpp @@ -553,23 +553,28 @@ int CLuaResourceDefs::Load(lua_State* luaVM) std::vector CLuaResourceDefs::GetResourceFiles(lua_State* luaVM, std::optional type, std::optional resource) noexcept { + using eResourceCategory = CResourceFile::eResourceCategory; + if (!type) - type = CResourceFile::eResourceCategory::ALL; + type = eResourceCategory::ALL; if (!resource) resource = &lua_getownerresource(luaVM); const auto resourceFiles = (*resource)->GetResourceFiles(); - std::vector files; - files.reserve(resourceFiles.size()); + std::unordered_set files; for (const auto& file : resourceFiles) { - if (file->GetResourceCategoryType() == type.value() || type.value() == CResourceFile::eResourceCategory::ALL) - { - files.push_back(file->GetName()); - } + if (file->GetResourceCategoryType() != type.value() && type.value() != eResourceCategory::ALL) + continue; + files.insert(file->GetName()); } - return files; + // TODO: Upgrade ArgumentParser so it would accept + // std::set and std::unordered_set as return values + return std::vector( + std::make_move_iterator(files.begin()), + std::make_move_iterator(files.end()) + ); }