From fe2e7d6fa9a5794fdf45e3f5fcec0bf74dea15b1 Mon Sep 17 00:00:00 2001 From: Maschell Date: Fri, 1 Oct 2021 17:25:48 +0200 Subject: [PATCH] WUPS 0.6.1 support --- source/common/plugin_defines.h | 2 +- source/hooks.cpp | 2 +- source/plugin/PluginContainerPersistence.cpp | 19 +++++++++++--- source/plugin/PluginMetaInformation.cpp | 2 +- source/plugin/PluginMetaInformation.h | 10 ++++---- .../plugin/PluginMetaInformationFactory.cpp | 6 ++--- source/utils/ConfigUtils.cpp | 4 +++ source/utils/exports.cpp | 25 ++++++++++++------- source/utils/exports.h | 2 +- 9 files changed, 48 insertions(+), 24 deletions(-) diff --git a/source/common/plugin_defines.h b/source/common/plugin_defines.h index 6ae449c..4881093 100644 --- a/source/common/plugin_defines.h +++ b/source/common/plugin_defines.h @@ -56,7 +56,7 @@ struct plugin_meta_info_t { char license[MAXIMUM_PLUGIN_META_FIELD_LENGTH] = ""; char buildTimestamp[MAXIMUM_PLUGIN_META_FIELD_LENGTH] = ""; char descripion[MAXIMUM_PLUGIN_DESCRIPTION_LENGTH] = ""; - char id[MAXIMUM_PLUGIN_META_FIELD_LENGTH] = ""; + char storageId[MAXIMUM_PLUGIN_META_FIELD_LENGTH] = ""; uint32_t size{}; }; diff --git a/source/hooks.cpp b/source/hooks.cpp index c86b3ad..e43468b 100644 --- a/source/hooks.cpp +++ b/source/hooks.cpp @@ -89,7 +89,7 @@ void CallHookEx(plugin_information_t *pluginInformation, wups_loader_hook_type_t wups_loader_init_storage_args_t args; args.open_storage_ptr = &StorageUtils::OpenStorage; args.close_storage_ptr = &StorageUtils::CloseStorage; - args.plugin_id = plugin_data->meta.id; + args.plugin_id = plugin_data->meta.storageId; ((void (*)(wups_loader_init_storage_args_t)) ((uint32_t *) func_ptr))(args); } else { DEBUG_FUNCTION_LINE("######################################"); diff --git a/source/plugin/PluginContainerPersistence.cpp b/source/plugin/PluginContainerPersistence.cpp index c5d956c..febcf60 100644 --- a/source/plugin/PluginContainerPersistence.cpp +++ b/source/plugin/PluginContainerPersistence.cpp @@ -55,10 +55,10 @@ bool PluginContainerPersistence::savePlugin(plugin_information_t *pluginInformat } strncpy(plugin_meta_data->descripion, pluginMetaInfo.getDescription().c_str(), MAXIMUM_PLUGIN_DESCRIPTION_LENGTH - 1); - if (pluginMetaInfo.getId().size() >= MAXIMUM_PLUGIN_META_FIELD_LENGTH) { - DEBUG_FUNCTION_LINE("Warning: plugin id will be truncated."); + if (pluginMetaInfo.getStorageId().length() >= MAXIMUM_PLUGIN_META_FIELD_LENGTH) { + DEBUG_FUNCTION_LINE("Warning: plugin storage id will be truncated."); } - strncpy(plugin_meta_data->id, pluginMetaInfo.getId().c_str(), MAXIMUM_PLUGIN_META_FIELD_LENGTH - 1); + strncpy(plugin_meta_data->storageId, pluginMetaInfo.getStorageId().c_str(), MAXIMUM_PLUGIN_META_FIELD_LENGTH - 1); plugin_meta_data->size = pluginMetaInfo.getSize(); @@ -202,6 +202,7 @@ std::vector PluginContainerPersistence::loadPlugins(plugin_info metaInformation.setDescription(meta->descripion); metaInformation.setSize(meta->size); metaInformation.setName(meta->name); + metaInformation.setStorageId(meta->storageId); plugin_data_t *data = &(plugin_data->data); @@ -237,6 +238,18 @@ std::vector PluginContainerPersistence::loadPlugins(plugin_info curPluginInformation.addHookData(curHook); } + bool storageHasId = true; + for(auto const &value : curPluginInformation.getHookDataList()){ + if(value.getType() == WUPS_LOADER_HOOK_INIT_STORAGE && + metaInformation.getStorageId().empty()){ + storageHasId = false; + } + } + if(!storageHasId){ + DEBUG_FUNCTION_LINE("Plugin is using the storage API but has not set an ID"); + continue; + } + /* load function replacement data */ uint32_t functionReplaceCount = plugin_data->info.number_used_functions; diff --git a/source/plugin/PluginMetaInformation.cpp b/source/plugin/PluginMetaInformation.cpp index 053a8b5..8f55b84 100644 --- a/source/plugin/PluginMetaInformation.cpp +++ b/source/plugin/PluginMetaInformation.cpp @@ -8,5 +8,5 @@ PluginMetaInformation::PluginMetaInformation(const PluginMetaInformation &other) this->buildtimestamp = other.buildtimestamp; this->description = other.description; this->size = other.size; - this->id = other.id; + this->storageId = other.storageId; } \ No newline at end of file diff --git a/source/plugin/PluginMetaInformation.h b/source/plugin/PluginMetaInformation.h index 7096b1e..30e8a13 100644 --- a/source/plugin/PluginMetaInformation.h +++ b/source/plugin/PluginMetaInformation.h @@ -48,8 +48,8 @@ public: return this->description; } - [[nodiscard]] const std::string &getId() const { - return this->id; + [[nodiscard]] const std::string &getStorageId() const { + return this->storageId; } [[nodiscard]] size_t getSize() const { @@ -87,8 +87,8 @@ private: this->size = _size; } - void setId(const std::string &_id) { - this->id = _id; + void setStorageId(const std::string &_storageId) { + this->storageId = _storageId; } std::string name; @@ -97,7 +97,7 @@ private: std::string license; std::string buildtimestamp; std::string description; - std::string id; + std::string storageId; size_t size{}; friend class PluginMetaInformationFactory; diff --git a/source/plugin/PluginMetaInformationFactory.cpp b/source/plugin/PluginMetaInformationFactory.cpp index 10b04ea..a1593be 100644 --- a/source/plugin/PluginMetaInformationFactory.cpp +++ b/source/plugin/PluginMetaInformationFactory.cpp @@ -110,10 +110,10 @@ std::optional PluginMetaInformationFactory::loadPlugin(co pluginInfo.setBuildTimestamp(value); } else if (key == "description") { pluginInfo.setDescription(value); - } else if (key == "id") { - pluginInfo.setId(value); + } else if (key == "storage_id") { + pluginInfo.setStorageId(value); } else if (key == "wups") { - if (value != "0.6") { + if (value != "0.6.1") { DEBUG_FUNCTION_LINE("Warning: Ignoring plugin - Unsupported WUPS version: %s.", value.c_str()); return std::nullopt; } diff --git a/source/utils/ConfigUtils.cpp b/source/utils/ConfigUtils.cpp index cf7fc63..e37b809 100644 --- a/source/utils/ConfigUtils.cpp +++ b/source/utils/ConfigUtils.cpp @@ -146,6 +146,10 @@ void ConfigUtils::displayMenu() { } } + if(configs.empty()){ + return; + } + ConfigDisplayItem *currentConfig = nullptr; WUPSConfigCategory *currentCategory = nullptr; diff --git a/source/utils/exports.cpp b/source/utils/exports.cpp index 297a05c..bb508fa 100644 --- a/source/utils/exports.cpp +++ b/source/utils/exports.cpp @@ -10,13 +10,14 @@ #include void fillPluginInformation(plugin_information *out, PluginMetaInformation *metaInformation) { + out->plugin_information_version = PLUGIN_INFORMATION_VERSION; strncpy(out->author, metaInformation->getAuthor().c_str(), sizeof(out->author) - 1); strncpy(out->buildTimestamp, metaInformation->getBuildTimestamp().c_str(), sizeof(out->buildTimestamp) - 1); strncpy(out->description, metaInformation->getDescription().c_str(), sizeof(out->description) - 1); strncpy(out->name, metaInformation->getName().c_str(), sizeof(out->name) - 1); strncpy(out->license, metaInformation->getLicense().c_str(), sizeof(out->license) - 1); strncpy(out->version, metaInformation->getVersion().c_str(), sizeof(out->version) - 1); - strncpy(out->id, metaInformation->getId().c_str(), sizeof(out->id) - 1); + strncpy(out->storageId, metaInformation->getStorageId().c_str(), sizeof(out->storageId) - 1); out->size = metaInformation->getSize(); } @@ -156,13 +157,14 @@ extern "C" PluginBackendApiErrorType WUPSGetMetaInformation(const plugin_contain auto handle = plugin_container_handle_list[i]; auto *container = (PluginContainer *) handle; - strncpy(plugin_information_list[i].id, container->metaInformation.getId().c_str(), 255); - strncpy(plugin_information_list[i].author, container->metaInformation.getAuthor().c_str(), 255); - strncpy(plugin_information_list[i].buildTimestamp, container->metaInformation.getBuildTimestamp().c_str(), 255); - strncpy(plugin_information_list[i].description, container->metaInformation.getDescription().c_str(), 255); - strncpy(plugin_information_list[i].name, container->metaInformation.getName().c_str(), 255); - strncpy(plugin_information_list[i].license, container->metaInformation.getLicense().c_str(), 255); - strncpy(plugin_information_list[i].version, container->metaInformation.getVersion().c_str(), 255); + plugin_information_list[i].plugin_information_version = PLUGIN_INFORMATION_VERSION; + strncpy(plugin_information_list[i].storageId, container->metaInformation.getStorageId().c_str(), sizeof(plugin_information_list[i].storageId) - 1); + strncpy(plugin_information_list[i].author, container->metaInformation.getAuthor().c_str(), sizeof(plugin_information_list[i].author) - 1); + strncpy(plugin_information_list[i].buildTimestamp, container->metaInformation.getBuildTimestamp().c_str(), sizeof(plugin_information_list[i].buildTimestamp) - 1); + strncpy(plugin_information_list[i].description, container->metaInformation.getDescription().c_str(), sizeof(plugin_information_list[i].description) - 1); + strncpy(plugin_information_list[i].name, container->metaInformation.getName().c_str(), sizeof(plugin_information_list[i].name) - 1); + strncpy(plugin_information_list[i].license, container->metaInformation.getLicense().c_str(), sizeof(plugin_information_list[i].license) - 1); + strncpy(plugin_information_list[i].version, container->metaInformation.getVersion().c_str(), sizeof(plugin_information_list[i].version) - 1); plugin_information_list[i].size = container->metaInformation.getSize(); } } else { @@ -172,7 +174,12 @@ extern "C" PluginBackendApiErrorType WUPSGetMetaInformation(const plugin_contain return res; } -extern "C" PluginBackendApiErrorType WUPSGetLoadedPlugins(plugin_container_handle *io_handles, uint32_t buffer_size, uint32_t *outSize) { +extern "C" PluginBackendApiErrorType WUPSGetLoadedPlugins(plugin_container_handle *io_handles, uint32_t buffer_size, uint32_t *outSize, uint32_t *plugin_information_version) { + DEBUG_FUNCTION_LINE(); + if (plugin_information_version == nullptr) { + return PLUGIN_BACKEND_API_ERROR_INVALID_ARG; + } + *plugin_information_version = PLUGIN_INFORMATION_VERSION; auto plugins = PluginContainerPersistence::loadPlugins(gPluginInformation); uint32_t counter = 0; for (auto &plugin: plugins) { diff --git a/source/utils/exports.h b/source/utils/exports.h index 3c6c2db..8a6331a 100644 --- a/source/utils/exports.h +++ b/source/utils/exports.h @@ -31,7 +31,7 @@ PluginBackendApiErrorType WUPSGetPluginDataForContainerHandles(const plugin_cont PluginBackendApiErrorType WUPSGetMetaInformation(const plugin_container_handle *plugin_container_handle_list, plugin_information *plugin_information_list, uint32_t buffer_size); -PluginBackendApiErrorType WUPSGetLoadedPlugins(plugin_container_handle *io_handles, uint32_t buffer_size, uint32_t *outSize); +PluginBackendApiErrorType WUPSGetLoadedPlugins(plugin_container_handle *io_handles, uint32_t buffer_size, uint32_t *outSize, uint32_t *plugin_information_version); #ifdef __cplusplus }