From 869b3bc39102572ec6eda0285ac908f04b60aafd Mon Sep 17 00:00:00 2001 From: Maschell Date: Sun, 18 Feb 2018 17:47:03 +0100 Subject: [PATCH] [Loader] Now show config GUI when entering Mii Maker - Added for methods to the plugin loader. --- loader/src/main.cpp | 45 +++++++++------------------ loader/src/menu/MainWindow.cpp | 3 +- loader/src/patcher/function_patcher.h | 2 ++ loader/src/plugin/PluginLoader.cpp | 21 +++++++++++++ loader/src/plugin/PluginLoader.h | 23 +++++++++++++- 5 files changed, 61 insertions(+), 33 deletions(-) diff --git a/loader/src/main.cpp b/loader/src/main.cpp index bebb771..bb0477b 100644 --- a/loader/src/main.cpp +++ b/loader/src/main.cpp @@ -56,8 +56,6 @@ void CallHook(wups_loader_hook_type_t hook_type); static void RestorePatches(); s32 isInMiiMakerHBL(); -u8 isFirstBoot __attribute__((section(".data"))) = 1; - /* Entry point */ extern "C" int Menu_Main(int argc, char **argv){ if(gAppStatus == 2){ @@ -86,8 +84,12 @@ extern "C" int Menu_Main(int argc, char **argv){ DEBUG_FUNCTION_LINE("Mount SD partition\n"); Init_SD_USB(); - if(isFirstBoot){ - memset((void*)&gbl_replacement_data,0,sizeof(gbl_replacement_data)); + s32 result = 0; + + //Reset everything when were going back to the Mii Maker + if(isInMiiMakerHBL()){ + // Restore patches as the patched functions could change. + RestorePatches(); PluginLoader * pluginLoader = PluginLoader::getInstance(); std::vector pluginList = pluginLoader->getPluginInformation("sd:/wiiu/plugins/"); @@ -100,50 +102,33 @@ extern "C" int Menu_Main(int argc, char **argv){ memoryInitialize(); DEBUG_FUNCTION_LINE("Start main application\n"); - s32 result = Application::instance()->exec(); + result = Application::instance()->exec(); DEBUG_FUNCTION_LINE("Main application stopped result: %d\n",result); Application::destroyInstance(); DEBUG_FUNCTION_LINE("Release memory\n"); memoryRelease(); CSettings::destroyInstance(); - if(result == APPLICATION_CLOSE_MIIMAKER){ - DeInit(); - return EXIT_SUCCESS; - } + PluginLoader::destroyInstance(); } + DEBUG_FUNCTION_LINE("Apply patches.\n"); + ApplyPatches(); - //Reset everything when were going back to the Mii Maker - if(!isFirstBoot && isInMiiMakerHBL()){ - DEBUG_FUNCTION_LINE("Returing to the Homebrew Launcher!\n"); - isFirstBoot = 0; - DeInit(); - RestorePatches(); - return EXIT_SUCCESS; - } else { - DEBUG_FUNCTION_LINE("Apply patches.\n"); - ApplyPatches(); - } - - if(!isInMiiMakerHBL()){ //Starting the application - DEBUG_FUNCTION_LINE("Calling init hook.\n"); + if(!isInMiiMakerHBL()){ CallHook(WUPS_LOADER_HOOK_INIT_FUNCTION); return EXIT_RELAUNCH_ON_LOAD; } - if(isFirstBoot){ // First boot back to SysMenu - DEBUG_FUNCTION_LINE("Loading the System Menu\n"); - isFirstBoot = 0; + if(result == APPLICATION_CLOSE_APPLY){ + DEBUG_FUNCTION_LINE("Loading the system menu.\n"); SYSLaunchMenu(); return EXIT_RELAUNCH_ON_LOAD; } - DEBUG_FUNCTION_LINE("Application is ending now.\n"); - - DeInit(); + DEBUG_FUNCTION_LINE("Going back to the Homebrew Launcher\n"); RestorePatches(); - + DeInit(); return EXIT_SUCCESS; } diff --git a/loader/src/menu/MainWindow.cpp b/loader/src/menu/MainWindow.cpp index e44699b..99847b5 100644 --- a/loader/src/menu/MainWindow.cpp +++ b/loader/src/menu/MainWindow.cpp @@ -30,8 +30,7 @@ MainWindow::MainWindow(s32 w, s32 h) : width(w) , height(h) { - for(s32 i = 0; i < 4; i++) - { + for(s32 i = 0; i < 4; i++) { std::string filename = StringTools::strfmt("player%i_point.png", i+1); pointerImgData[i] = Resources::GetImageData(filename.c_str()); pointerImg[i] = new GuiImage(pointerImgData[i]); diff --git a/loader/src/patcher/function_patcher.h b/loader/src/patcher/function_patcher.h index b81eeb7..66244c3 100644 --- a/loader/src/patcher/function_patcher.h +++ b/loader/src/patcher/function_patcher.h @@ -38,6 +38,7 @@ struct rpl_handling { #define DYNAMIC_FUNCTION 1 #define FUNCTION_PATCHER_METHOD_STORE_SIZE 7 +#define MAXIMUM_PLUGIN_PATH_NAME_LENGTH 256 #define MAXIMUM_PLUGIN_NAME_LENGTH 51 #define MAXIMUM_FUNCTION_NAME_LENGTH 51 @@ -66,6 +67,7 @@ struct replacement_data_hook_t{ #define MAXIMUM_FUNCTION_PER_PLUGIN 100 struct replacement_data_plugin_t{ + char path[MAXIMUM_PLUGIN_PATH_NAME_LENGTH]; char plugin_name[MAXIMUM_PLUGIN_NAME_LENGTH] = ""; // Name of this plugin int priority; // Priority of this plugin int number_used_functions; // Number of used function. Maximum is MAXIMUM_FUNCTION_PER_PLUGIN diff --git a/loader/src/plugin/PluginLoader.cpp b/loader/src/plugin/PluginLoader.cpp index 84dc82e..8f70d00 100644 --- a/loader/src/plugin/PluginLoader.cpp +++ b/loader/src/plugin/PluginLoader.cpp @@ -77,6 +77,18 @@ std::vector PluginLoader::getPluginInformation(const char * return result; } +std::vector PluginLoader::getPluginsLoadedInMemory(){ + std::vector pluginInformation; + for(s32 i = 0; i < gbl_replacement_data.number_used_plugins; i++){ + replacement_data_plugin_t * pluginInfo = &gbl_replacement_data.plugin_data[i]; + PluginInformation * curPlugin = PluginInformation::loadPluginInformation(pluginInfo->path); + if(curPlugin != NULL){ + pluginInformation.push_back(curPlugin); + } + } + return pluginInformation; +} + void PluginLoader::loadAndLinkPlugins(std::vector pluginInformation){ std::vector loadedPlugins; for(size_t i = 0;i < pluginInformation.size(); i++){ @@ -104,6 +116,14 @@ void PluginLoader::clearPluginData(std::vector pluginData){ } } +void PluginLoader::clearPluginInformation(std::vector pluginInformation){ + for(size_t i = 0;i < pluginInformation.size(); i++){ + PluginInformation * curPluginInformation = pluginInformation[i]; + if(curPluginInformation != NULL){ + delete curPluginInformation; + } + } +} PluginData * PluginLoader::loadAndLinkPlugin(PluginInformation * pluginInformation){ DEBUG_FUNCTION_LINE("\n"); @@ -376,6 +396,7 @@ void PluginLoader::copyPluginDataIntoGlobalStruct(std::vector plug replacement_data_plugin_t * plugin_data = &gbl_replacement_data.plugin_data[plugin_index]; strncpy(plugin_data->plugin_name,cur_pluginInformation->getName().c_str(),MAXIMUM_PLUGIN_NAME_LENGTH-1); + strncpy(plugin_data->path,cur_pluginInformation->getPath().c_str(),MAXIMUM_PLUGIN_PATH_NAME_LENGTH-1); for(size_t j = 0; j < entry_data_list.size();j++){ replacement_data_function_t * function_data = &plugin_data->functions[j]; diff --git a/loader/src/plugin/PluginLoader.h b/loader/src/plugin/PluginLoader.h index 0f82558..3d2de5e 100644 --- a/loader/src/plugin/PluginLoader.h +++ b/loader/src/plugin/PluginLoader.h @@ -29,6 +29,7 @@ #include #include "PluginInformation.h" #include "PluginData.h" +#include "dynamic_libs/os_types.h" #ifdef __cplusplus extern "C" { @@ -75,7 +76,7 @@ public: \return a list of MetaInformation objects for all plugins currently loaded and linked (relocated). Will only contain plugin which are still on the sd card. **/ - //std::vector getPluginsLoadedInMemory(); + std::vector getPluginsLoadedInMemory(); /** \brief Takes a list of plugins that should be linked (relocated) loaded into the memory. @@ -86,6 +87,26 @@ public: \param A list of plugin that should be linked (relocated) an loaded into memory **/ void loadAndLinkPlugins(std::vector pluginInformation); + + /** + \brief Iterates through the vector and delete all it's elements + + \param A list of PluginInformation* that should be deleted. + **/ + void clearPluginInformation(std::vector PluginInformation); + + size_t getTotalSpace(){ + return ((u32) this->endAddress - (u32) this->startAddress); + } + + size_t getAvailableSpace(){ + return ((u32) this->currentStoreAddress - (u32) this->startAddress); + } + + size_t getUsedSpace(){ + return getTotalSpace() - getAvailableSpace(); + } + private: PluginLoader(void * startAddress, void * endAddress){ // TODO: Check if endAddress > startAddress.