- Allow users to enable/disable plugin in the loader

- Fix some memory leaks
- Add assets needed to display plugins
This commit is contained in:
Maschell 2018-07-04 16:31:49 +02:00
parent 860d2ef84e
commit adf9c24ef1
24 changed files with 383 additions and 14 deletions

View File

@ -35,6 +35,7 @@ TARGET := wiiupluginloader
BUILD := build
BUILD_DBG := $(TARGET)_dbg
SOURCES := src/common \
src/custom/gui \
src/libelf \
src/menu/content \
src/menu \

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

View File

@ -1,3 +1,6 @@
msgid "Language"
msgstr ""
# English translations for Wii U Plugin System loader
# This file is distributed under the same license as the PACKAGE package.
msgid ""
@ -13,14 +16,14 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
#: src/menu/content/ContentHome.cpp:20
#: src/menu/content/ContentHome.cpp:23
msgid "Welcome to the Wii U plugin loader"
msgstr ""
#: src/menu/content/ContentHome.cpp:29
#: src/menu/content/ContentHome.cpp:32
msgid "Exit to HBL "
msgstr ""
#: src/menu/content/ContentHome.cpp:32
#: src/menu/content/ContentHome.cpp:35
msgid "Apply Patches"
msgstr ""

View File

@ -183,6 +183,14 @@ void Application::executeThread(void) {
if(controller[i]->data.buttons_d & VPAD_BUTTON_PLUS) {
exitCode = APPLICATION_CLOSE_APPLY;
if(linkPluginsCallback != NULL) {
bool result = linkPluginsCallback();
if(!result) {
// On linking errors return to the HBL.
#warning TODO: proper error handling when linking fails.
exitCode = APPLICATION_CLOSE_MIIMAKER;
}
}
exitApplication = true;
}

View File

@ -19,6 +19,7 @@
#define _APPLICATION_H
#include "menu/MainWindow.h"
#include <functional>
#include <video/CVideo.h>
#include <system/CThread.h>
#include <language/gettext.h>
@ -61,6 +62,11 @@ public:
exitCode = code;
exitApplication = true;
}
void setLinkPluginsCallback(std::function<bool(void)> fun) {
linkPluginsCallback = fun;
DEBUG_FUNCTION_LINE("Set callback to %08X \n",linkPluginsCallback);
}
private:
Application();
@ -80,6 +86,7 @@ private:
MainWindow *mainWindow;
GuiController *controller[5];
int32_t exitCode;
std::function<bool(void)> linkPluginsCallback = NULL;
};
#endif //_APPLICATION_H

View File

@ -0,0 +1,52 @@
/****************************************************************************
* Copyright (C) 2017 Maschell
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/
#include "DefaultGuiSelectBox.h"
/**
* Constructor for the DefaultGuiSelectBox class.
*/
DefaultGuiSelectBox::DefaultGuiSelectBox(std::string caption, GuiFrame *parent)
: GuiSelectBox(NULL,caption)
,topBackgroundImg_imgdata(Resources::GetImageData("gameSettingsButton.png"))
,topBackgroundImg_img(topBackgroundImg_imgdata)
,topHighlightedImg_imgdata(Resources::GetImageData("gameSettingsButtonSelected.png"))
,topHighlightedImg_img(topHighlightedImg_imgdata)
,valueImageData(Resources::GetImageData("gameSettingsButtonEx.png"))
,valueSelectedImageData(Resources::GetImageData("gameSettingsButtonExSelected.png"))
,valueHighlightedImageData(Resources::GetImageData("gameSettingsButtonExHighlighted.png"))
,buttonClickSound(Resources::GetSound("settings_click_2.mp3"))
{
setSize(topBackgroundImg_img.getWidth(),topBackgroundImg_img.getHeight());
this->setImageTopBackground(&topBackgroundImg_img);
this->setImageTopHighlighted(&topHighlightedImg_img);
this->setImageValueBackground(valueImageData);
this->setImageValueHighlighted(valueHighlightedImageData);
this->setImageValueSelected(valueSelectedImageData);
this->setSoundClick(buttonClickSound);
}
/**
* Destructor for the DefaultGuiSelectBox class.
*/
DefaultGuiSelectBox::~DefaultGuiSelectBox()
{
Resources::RemoveImageData(topBackgroundImg_imgdata);
Resources::RemoveImageData(topHighlightedImg_imgdata);
Resources::RemoveImageData(valueImageData);
Resources::RemoveImageData(valueSelectedImageData);
Resources::RemoveImageData(valueHighlightedImageData);
Resources::RemoveSound(buttonClickSound);
}

View File

@ -0,0 +1,45 @@
/****************************************************************************
* Copyright (C) 2017 Maschell
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/
#ifndef DEFAULT_GUI_SELECTBOX_H_
#define DEFAULT_GUI_SELECTBOX_H_
#include <gui/GuiSelectBox.h>
//!A simple select box with default values.
class DefaultGuiSelectBox : public GuiSelectBox{
public:
//!Constructor
//!\param checked Checked
DefaultGuiSelectBox(std::string caption, GuiFrame *parent = NULL);
//!Destructor
virtual ~DefaultGuiSelectBox();
protected:
GuiImageData * topBackgroundImg_imgdata;
GuiImage topBackgroundImg_img;
GuiImageData * topHighlightedImg_imgdata;
GuiImage topHighlightedImg_img;
GuiImageData * valueImageData;
GuiImageData * valueSelectedImageData;
GuiImageData * valueHighlightedImageData;
GuiSound * buttonClickSound;
};
#endif

View File

@ -0,0 +1,48 @@
/****************************************************************************
* Copyright (C) 2017 Maschell
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/
#include "DefaultGuiSwitch.h"
/**
* Constructor for the DefaultGuiSwitch class.
*/
DefaultGuiSwitch::DefaultGuiSwitch(bool checked)
: GuiSwitch(NULL,checked)
,switchbase_imgdata(Resources::GetImageData("switchIconBase.png"))
,switchbase_img(switchbase_imgdata)
,switchbase_highlighted_imgdata(Resources::GetImageData("switchIconBaseHighlighted.png"))
,switchbase_highlighted_img(switchbase_highlighted_imgdata)
,switchOn_imgdata(Resources::GetImageData("switchIconOn.png"))
,switchOn_img(switchOn_imgdata)
,switchOff_imgdata(Resources::GetImageData("switchIconOff.png"))
,switchOff_img(switchOff_imgdata)
{
setSize(switchbase_img.getWidth(),switchbase_img.getHeight());
this->setImageBackground(&switchbase_img);
this->setImageHighlighted(&switchbase_highlighted_img);
this->setImageOn(&switchOn_img);
this->setImageOff(&switchOff_img);
}
/**
* Destructor for the DefaultGuiSwitch class.
*/
DefaultGuiSwitch::~DefaultGuiSwitch()
{
Resources::RemoveImageData(switchbase_imgdata);
Resources::RemoveImageData(switchbase_highlighted_imgdata);
Resources::RemoveImageData(switchOn_imgdata);
Resources::RemoveImageData(switchOff_imgdata);
}

View File

@ -0,0 +1,45 @@
/****************************************************************************
* Copyright (C) 2017 Maschell
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/
#ifndef DEFAULT_GUI_SWTICH_H_
#define DEFAULT_GUI_SWTICH_H_
#include <gui/GuiSwitch.h>
//!A simple switch
class DefaultGuiSwitch : public GuiSwitch{
public:
//!Constructor
//!\param checked Checked
DefaultGuiSwitch(bool checked);
//!Destructor
virtual ~DefaultGuiSwitch();
protected:
GuiImageData * switchbase_imgdata = NULL;
GuiImage switchbase_img;
GuiImageData * switchbase_highlighted_imgdata = NULL;
GuiImage switchbase_highlighted_img;
GuiImageData * switchOn_imgdata = NULL;
GuiImage switchOn_img;
GuiImageData * switchOff_imgdata = NULL;
GuiImage switchOff_img;
};
#endif

View File

@ -107,9 +107,10 @@ extern "C" int32_t Menu_Main(int32_t argc, char **argv) {
DynamicLinkingHelper::getInstance()->clearAll();
PluginLoader * pluginLoader = PluginLoader::getInstance();
std::vector<PluginInformation *> pluginList = pluginLoader->getPluginInformation("sd:/wiiu/plugins/");
pluginLoader->loadAndLinkPlugins(pluginList);
//PluginLoader * pluginLoader = PluginLoader::getInstance();
//std::vector<PluginInformation *> pluginList = pluginLoader->getPluginInformation("sd:/wiiu/plugins/");
//pluginLoader->loadAndLinkPlugins(pluginList);
//pluginLoader->clearPluginInformation(pluginList);
//!*******************************************************************
//! Initialize heap memory *
@ -145,8 +146,6 @@ extern "C" int32_t Menu_Main(int32_t argc, char **argv) {
OSFatal("fillRelocations failed.");
}
if(!isInMiiMakerHBL()) {
DEBUG_FUNCTION_LINE("Apply patches.\n");
ApplyPatchesAndCallHookStartingApp();
@ -166,12 +165,9 @@ extern "C" int32_t Menu_Main(int32_t argc, char **argv) {
DEBUG_FUNCTION_LINE("<----------------- COPY PASTE ME END -----------------> \n");
DEBUG_FUNCTION_LINE("<-----------------------------------------------------> \n");
}
return EXIT_RELAUNCH_ON_LOAD;
}
if(result == APPLICATION_CLOSE_APPLY || result == APPLICATION_CLOSE_APPLY_MEMORY) {
CallHook(WUPS_LOADER_HOOK_INIT_KERNEL);
CallHook(WUPS_LOADER_HOOK_INIT_FS);

View File

@ -15,6 +15,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/
#include "ContentHome.h"
#include "plugin/PluginLoader.h"
#include "custom/gui/DefaultGuiSwitch.h"
#include "Application.h"
ContentHome::ContentHome():ContentTemplate()
, welcomeHeadLineLabel(gettext("Welcome to the Wii U plugin loader"))
@ -29,7 +32,10 @@ ContentHome::ContentHome():ContentTemplate()
, exitHome(gettext("Exit to HBL "))
, plusbutton_imgdata(Resources::GetImageData("PlusButtonIcon.png"))
, plusbutton_img(plusbutton_imgdata)
, exitPlus(gettext("Apply Patches")) {
, exitPlus(gettext("Apply Patches"))
, touchTrigger(GuiTrigger::CHANNEL_1, GuiTrigger::VPAD_TOUCH)
, wpadTouchTrigger(GuiTrigger::CHANNEL_2 | GuiTrigger::CHANNEL_3 | GuiTrigger::CHANNEL_4 | GuiTrigger::CHANNEL_5, GuiTrigger::BUTTON_A)
, buttonClickSound(Resources::GetSound("settings_click_2.mp3")) {
glm::vec4 textColor = glm::vec4(1.0f,1.0f,1.0f,1.0f);
homebutton_img.setAlignment(ALIGN_LEFT);
@ -72,6 +78,70 @@ ContentHome::ContentHome():ContentTemplate()
URLLabel.setAlignment(ALIGN_BOTTOM|ALIGN_LEFT);
URLLabel.setPosition(280,50);
PluginLoader * pluginLoader = PluginLoader::getInstance();
std::vector<PluginInformation *> pluginList = pluginLoader->getPluginInformation("sd:/wiiu/plugins/");
std::vector<PluginInformation *> pluginListLoaded = pluginLoader->getPluginsLoadedInMemory();
pluginsFrame.setAlignment(ALIGN_TOP_CENTER);
pluginsFrame.setPosition(0,-80);
pluginsFrame.setSize(getWidth(),getHeight());
append(&pluginsFrame);
float frameoffset = 0;
float frameheight = 50.0f;
for (std::vector<PluginInformation *>::iterator it = pluginList.begin() ; it != pluginList.end(); ++it) {
PluginInformation * curPlugin = *it;
DefaultGuiSwitch * element = new DefaultGuiSwitch(false);
element->setTrigger(&touchTrigger);
element->setTrigger(&wpadTouchTrigger);
element->setSoundClick(buttonClickSound);
element->valueChanged.connect(this, &ContentHome::OnValueChanged);
for (std::vector<PluginInformation *>::iterator itOther = pluginListLoaded.begin() ; itOther != pluginListLoaded.end(); ++itOther) {
PluginInformation * otherPlugin = *itOther;
if(otherPlugin->getName().compare(curPlugin->getName()) == 0) {
element->setValue(true);
}
}
pluginMapping[element] = curPlugin;
GuiFrame * frame = new GuiFrame();
GuiFrame * left = new GuiFrame();
GuiFrame * right = new GuiFrame();
frame->append(left);
frame->append(right);
frame->setAlignment(ALIGN_TOP_CENTER);
frame->setSize(getWidth()*0.80f,frameheight);
GuiText * text = new GuiText(curPlugin->getName().c_str());
text->setColor(glm::vec4(0.3f,0.3f,0.3f,1.0f));
text->setFontSize(40);
text->setColor(textColor);
text->setAlignment(ALIGN_LEFT);
left->append(text);
left->setAlignment(ALIGN_LEFT);
right->setAlignment(ALIGN_RIGHT);
element->setAlignment(ALIGN_RIGHT);
element->setPosition(0,10);
element->setScale(2.0f);
right->append(element);
frameoffset -= frameheight;
frame->setPosition(0,frameoffset);
pluginsFrame.append(frame);
toDelete.push_back(element);
toDelete.push_back(frame);
toDelete.push_back(left);
toDelete.push_back(right);
toDelete.push_back(text);
}
pluginLoader->clearPluginInformation(pluginListLoaded);
append(&welcomeHeadLineLabel);
append(&twitterLogoImage);
append(&githubLogoImage);
@ -79,6 +149,28 @@ ContentHome::ContentHome():ContentTemplate()
append(&URLLabel);
append(&exitHomeFrame);
append(&exitPlusFrame);
auto fp = std::bind(&ContentHome::linkPlugins, this);
Application::instance()->setLinkPluginsCallback(fp);
}
void ContentHome::OnValueChanged(GuiToggle * toggle,bool value) {
}
bool ContentHome::linkPlugins() {
std::vector<PluginInformation*> willBeLoaded;
for (auto const& x : pluginMapping) {
GuiToggle * guiElement = x.first;
if(guiElement->getValue()) {
PluginInformation* pluginInformation = x.second;
DEBUG_FUNCTION_LINE("We want to link %s\n",pluginInformation->getName().c_str());
willBeLoaded.push_back(pluginInformation);
}
}
return PluginLoader::getInstance()->loadAndLinkPlugins(willBeLoaded);
}
ContentHome::~ContentHome() {
@ -91,4 +183,15 @@ ContentHome::~ContentHome() {
remove(&URLLabel);
remove(&exitHomeFrame);
remove(&exitPlusFrame);
for (auto const& x : pluginMapping) {
// x.first is also in the toDelete vector.
PluginInformation* pluginInformation = x.second;
delete pluginInformation;
}
Resources::RemoveSound(buttonClickSound);
for (std::vector<GuiElement *>::iterator it = toDelete.begin() ; it != toDelete.end(); ++it) {
delete *it;
}
}

View File

@ -20,6 +20,8 @@
#include "gui/Gui.h"
#include "ContentTemplate.h"
#include "language/gettext.h"
#include "plugin/PluginInformation.h"
#include "custom/gui/DefaultGuiSwitch.h"
class ContentHome : public ContentTemplate {
public:
@ -52,6 +54,17 @@ private:
GuiText exitPlus;
GuiFrame exitPlusFrame;
GuiTrigger touchTrigger;
GuiTrigger wpadTouchTrigger;
GuiSound *buttonClickSound;
GuiFrame pluginsFrame;
std::vector<GuiElement*> toDelete;
void OnValueChanged(GuiToggle * toggle,bool value);
bool linkPlugins();
std::map<GuiToggle *, PluginInformation *> pluginMapping;
};
#endif //_CONTENT_HOME_H

View File

@ -223,12 +223,14 @@ int32_t TcpReceiver::loadToMemory(int32_t clientSocket, uint32_t ipAddress) {
if(plugin == NULL) {
return NOT_A_VALID_PLUGIN;
}
delete plugin;
PluginLoader * pluginLoader = PluginLoader::getInstance();
pluginLoader->resetPluginLoader();
std::vector<PluginInformation* > pluginList = pluginLoader->getPluginInformation(WUPS_TEMP_PLUGIN_PATH);
if(pluginList.size() == 0 || !pluginLoader->loadAndLinkPlugins(pluginList)) {
return NOT_A_VALID_PLUGIN;
}
pluginLoader->clearPluginInformation(pluginList);
Application::instance()->quit(APPLICATION_CLOSE_APPLY);
return fileSize;

View File

@ -108,7 +108,13 @@ bool PluginLoader::loadAndLinkPlugins(std::vector<PluginInformation *> pluginInf
PluginLoader::flushCache();
copyPluginDataIntoGlobalStruct(loadedPlugins);
if(success) {
copyPluginDataIntoGlobalStruct(loadedPlugins);
} else {
PluginLoader::resetPluginLoader();
memset((void*)&gbl_replacement_data,0,sizeof(gbl_replacement_data));
}
clearPluginData(loadedPlugins);
return success;

View File

@ -1,7 +1,7 @@
/****************************************************************************
* Resource files.
* This file is generated automatically.
* Includes 5 files.
* Includes 15 files.
*
* NOTE:
* Any manual modification of this file will be overwriten by the generation.
@ -12,6 +12,21 @@
extern const uint8_t font_ttf[];
extern const uint32_t font_ttf_size;
extern const uint8_t gameSettingsButton_png[];
extern const uint32_t gameSettingsButton_png_size;
extern const uint8_t gameSettingsButtonEx_png[];
extern const uint32_t gameSettingsButtonEx_png_size;
extern const uint8_t gameSettingsButtonExHighlighted_png[];
extern const uint32_t gameSettingsButtonExHighlighted_png_size;
extern const uint8_t gameSettingsButtonExSelected_png[];
extern const uint32_t gameSettingsButtonExSelected_png_size;
extern const uint8_t gameSettingsButtonSelected_png[];
extern const uint32_t gameSettingsButtonSelected_png_size;
extern const uint8_t GithubIcon_png[];
extern const uint32_t GithubIcon_png_size;
@ -21,15 +36,40 @@ extern const uint32_t HomeButtonIcon_png_size;
extern const uint8_t PlusButtonIcon_png[];
extern const uint32_t PlusButtonIcon_png_size;
extern const uint8_t settings_click_2_mp3[];
extern const uint32_t settings_click_2_mp3_size;
extern const uint8_t switchIconBase_png[];
extern const uint32_t switchIconBase_png_size;
extern const uint8_t switchIconBaseHighlighted_png[];
extern const uint32_t switchIconBaseHighlighted_png_size;
extern const uint8_t switchIconOff_png[];
extern const uint32_t switchIconOff_png_size;
extern const uint8_t switchIconOn_png[];
extern const uint32_t switchIconOn_png_size;
extern const uint8_t TwitterIcon_png[];
extern const uint32_t TwitterIcon_png_size;
static ResourceFile ResourceList[] =
{
{"font.ttf", font_ttf, font_ttf_size, NULL, 0},
{"gameSettingsButton.png", gameSettingsButton_png, gameSettingsButton_png_size, NULL, 0},
{"gameSettingsButtonEx.png", gameSettingsButtonEx_png, gameSettingsButtonEx_png_size, NULL, 0},
{"gameSettingsButtonExHighlighted.png", gameSettingsButtonExHighlighted_png, gameSettingsButtonExHighlighted_png_size, NULL, 0},
{"gameSettingsButtonExSelected.png", gameSettingsButtonExSelected_png, gameSettingsButtonExSelected_png_size, NULL, 0},
{"gameSettingsButtonSelected.png", gameSettingsButtonSelected_png, gameSettingsButtonSelected_png_size, NULL, 0},
{"GithubIcon.png", GithubIcon_png, GithubIcon_png_size, NULL, 0},
{"HomeButtonIcon.png", HomeButtonIcon_png, HomeButtonIcon_png_size, NULL, 0},
{"PlusButtonIcon.png", PlusButtonIcon_png, PlusButtonIcon_png_size, NULL, 0},
{"settings_click_2.mp3", settings_click_2_mp3, settings_click_2_mp3_size, NULL, 0},
{"switchIconBase.png", switchIconBase_png, switchIconBase_png_size, NULL, 0},
{"switchIconBaseHighlighted.png", switchIconBaseHighlighted_png, switchIconBaseHighlighted_png_size, NULL, 0},
{"switchIconOff.png", switchIconOff_png, switchIconOff_png_size, NULL, 0},
{"switchIconOn.png", switchIconOn_png, switchIconOn_png_size, NULL, 0},
{"TwitterIcon.png", TwitterIcon_png, TwitterIcon_png_size, NULL, 0},
{NULL, NULL, 0, NULL, 0}
};