diff --git a/source/PluginManagement.cpp b/source/PluginManagement.cpp index fde9aca..3a768ed 100644 --- a/source/PluginManagement.cpp +++ b/source/PluginManagement.cpp @@ -2,6 +2,8 @@ #include #include #include +#include +#include #include "patcher/hooks_patcher_static.h" #include "patcher/hooks_patcher.h" #include "PluginManagement.h" @@ -91,11 +93,11 @@ void PluginManagement::unloadPlugins(plugin_information_t *gPluginInformation, M if (plugin->info.allocatedTextMemoryAddress != nullptr) { MEMFreeToExpHeap((MEMHeapHandle) pluginHeap, plugin->info.allocatedTextMemoryAddress); - DEBUG_FUNCTION_LINE("Freed %08X",plugin->info.allocatedTextMemoryAddress); + DEBUG_FUNCTION_LINE("Freed %08X", plugin->info.allocatedTextMemoryAddress); } if (plugin->info.allocatedDataMemoryAddress != nullptr) { MEMFreeToExpHeap((MEMHeapHandle) pluginHeap, plugin->info.allocatedDataMemoryAddress); - DEBUG_FUNCTION_LINE("Freed %08X",plugin->info.allocatedDataMemoryAddress); + DEBUG_FUNCTION_LINE("Freed %08X", plugin->info.allocatedDataMemoryAddress); } } memset((void *) gPluginInformation, 0, sizeof(plugin_information_t)); @@ -125,3 +127,32 @@ void PluginManagement::PatchFunctionsAndCallHooks(plugin_information_t *gPluginI CallHookEx(gPluginInformation, WUPS_LOADER_HOOK_FUNCTIONS_PATCHED, plugin_index); } } + +std::vector PluginManagement::loadPlugins(const std::vector &pluginList, MEMHeapHandle heapHandle, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length) { + std::vector plugins; + + for (auto &pluginData : pluginList) { + DEBUG_FUNCTION_LINE("Load meta information"); + auto metaInfo = PluginMetaInformationFactory::loadPlugin(pluginData); + if (metaInfo) { + PluginContainer container; + container.setMetaInformation(metaInfo.value()); + container.setPluginData(const_cast(pluginData)); + plugins.push_back(container); + } else { + DEBUG_FUNCTION_LINE("Failed to get meta information"); + } + } + for (auto &pluginContainer : plugins) { + uint32_t trampolineId = pluginContainer.getPluginInformation().getTrampolinId(); + std::optional info = PluginInformationFactory::load(pluginContainer.getPluginData(), heapHandle, trampolin_data, trampolin_data_length, trampolineId); + + if (!info) { + DEBUG_FUNCTION_LINE("Failed to load Plugin %s", pluginContainer.getMetaInformation().getName().c_str()); + continue; + } + pluginContainer.setPluginInformation(info.value()); + } + return plugins; +} + diff --git a/source/PluginManagement.h b/source/PluginManagement.h index 40cb8c8..89c20b9 100644 --- a/source/PluginManagement.h +++ b/source/PluginManagement.h @@ -18,4 +18,6 @@ public: static bool doRelocation(const std::vector &relocData, relocation_trampolin_entry_t *tramp_data, uint32_t tramp_length, uint32_t trampolinID); static void unloadPlugins(plugin_information_t * pluginInformation, MEMHeapHandle pluginHeap); + + static std::vector loadPlugins(const std::vector &pluginList, MEMHeapHandle pHeader, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length); }; \ No newline at end of file diff --git a/source/main.cpp b/source/main.cpp index f155d1c..adcdfba 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -77,7 +77,7 @@ int test() { std::vector pluginList = PluginDataFactory::loadDir("fs:/vol/external01/wiiu/plugins/", pluginDataHeap); DEBUG_FUNCTION_LINE("Loaded %d plugin data", pluginList.size()); - std::vector plugins = loadPlugins(pluginList, pluginDataHeap); + std::vector plugins = PluginManagement::loadPlugins(pluginList, pluginDataHeap, gPluginInformation->trampolines, DYN_LINK_TRAMPOLIN_LIST_LENGTH); for (auto &pluginContainer : plugins) { for (const auto &kv : pluginContainer.getPluginInformation().getSectionInfoList()) { @@ -109,31 +109,3 @@ int test() { return 0; } - -std::vector loadPlugins(const std::vector &pluginList, MEMHeapHandle heapHandle) { - std::vector plugins; - - for (auto &pluginData : pluginList) { - DEBUG_FUNCTION_LINE("Load meta information"); - auto metaInfo = PluginMetaInformationFactory::loadPlugin(pluginData); - if (metaInfo) { - PluginContainer container; - container.setMetaInformation(metaInfo.value()); - container.setPluginData(const_cast(pluginData)); - plugins.push_back(container); - } else { - DEBUG_FUNCTION_LINE("Failed to get meta information"); - } - } - for (auto &pluginContainer : plugins) { - uint32_t trampolineId = pluginContainer.getPluginInformation().getTrampolinId(); - std::optional info = PluginInformationFactory::load(pluginContainer.getPluginData(), heapHandle, gPluginInformation->trampolines, DYN_LINK_TRAMPOLIN_LIST_LENGTH, trampolineId); - - if (!info) { - DEBUG_FUNCTION_LINE("Failed to load Plugin %s", pluginContainer.getMetaInformation().getName().c_str()); - continue; - } - pluginContainer.setPluginInformation(info.value()); - } - return plugins; -}