Add warning when no environment was found

This commit is contained in:
Maschell 2021-12-30 16:10:59 +01:00
parent 9d95d6ad29
commit 66d282afcc

View File

@ -3,6 +3,7 @@
#include <elfio/elfio.hpp>
#include <proc_ui/procui.h>
#include <sysapp/launch.h>
#include <sysapp/title.h>
#include <coreinit/foreground.h>
#include <coreinit/cache.h>
#include <coreinit/ios.h>
@ -13,6 +14,7 @@
#include <whb/log_module.h>
#include <vector>
#include <coreinit/dynload.h>
#include <coreinit/title.h>
#include <coreinit/screen.h>
#include <memory>
#include <malloc.h>
@ -111,6 +113,8 @@ int main(int argc, char **argv) {
auto gModuleData = (module_information_t *) (textSectionStart - sizeof(module_information_t));
bool noEnvironmentsFound = false;
std::string environment_path = std::string(environmentPath);
if (strncmp(environmentPath, "fs:/vol/external01/wiiu/environments/", strlen("fs:/vol/external01/wiiu/environments/")) != 0) {
DirList environmentDirs("fs:/vol/external01/wiiu/environments/", nullptr, DirList::Dirs, 1);
@ -150,15 +154,19 @@ int main(int argc, char **argv) {
if (forceMenu || (btn & VPAD_BUTTON_X) == VPAD_BUTTON_X) {
DEBUG_FUNCTION_LINE("Open menu!");
environment_path = EnvironmentSelectionScreen(environmentPaths, autobootIndex);
if (environmentPaths.empty()) {
noEnvironmentsFound = true;
} else {
DEBUG_FUNCTION_LINE("Selected %s", environment_path.c_str());
}
}
}
RevertMainHook();
if (!noEnvironmentsFound) {
DirList setupModules(environment_path + "/modules/setup", ".rpx", DirList::Files, 1);
setupModules.SortList();
RevertMainHook();
for (int i = 0; i < setupModules.GetFilecount(); i++) {
uint32_t destination_address_end = ((uint32_t) gModuleData) & 0xFFFF0000;
memset((void *) gModuleData, 0, sizeof(module_information_t));
@ -186,6 +194,22 @@ int main(int argc, char **argv) {
((int (*)(int, char **)) moduleData.value()->getEntrypoint())(1, arr);
DEBUG_FUNCTION_LINE("Back from module");
}
} else {
DEBUG_FUNCTION_LINE("Return to Wii U Menu");
ProcUIInit(OSSavesDone_ReadyToRelease);
for (int i = 0; i < argc; i++) {
if(strcmp(argv[i], "void forceDefaultTitleIDToWiiUMenu(void)") == 0){
if((i + 1) < argc){
i++;
DEBUG_FUNCTION_LINE("call forceDefaultTitleIDToWiiUMenu");
auto forceDefaultTitleIDToWiiUMenu = (void (*)()) argv[i];
forceDefaultTitleIDToWiiUMenu();
}
}
}
DEBUG_FUNCTION_LINE("Launch menu");
SYSLaunchMenu();
}
ProcUIInit(OSSavesDone_ReadyToRelease);
@ -201,6 +225,7 @@ int main(int argc, char **argv) {
#define COLOR_WHITE Color(0xffffffff)
#define COLOR_BLACK Color(0, 0, 0, 255)
#define COLOR_RED Color(237, 28, 36, 255)
#define COLOR_BACKGROUND Color(0, 40, 100, 255)
#define COLOR_TEXT COLOR_WHITE
#define COLOR_TEXT2 Color(0xB3ffffff)
@ -264,6 +289,7 @@ std::string EnvironmentSelectionScreen(const std::map<std::string, std::string>
// draw buttons
uint32_t index = 8 + 24 + 8 + 4;
uint32_t i = 0;
if (!payloads.empty()) {
for (auto const&[key, val]: payloads) {
if (i == selected) {
DrawUtils::drawRect(16, index, SCREEN_WIDTH - 16 * 2, 44, 4, COLOR_BORDER_HIGHLIGHTED);
@ -277,6 +303,12 @@ std::string EnvironmentSelectionScreen(const std::map<std::string, std::string>
index += 42 + 8;
i++;
}
} else {
DrawUtils::setFontSize(24);
DrawUtils::setFontColor(COLOR_RED);
const char *noEnvironmentsWarning = "No valid environments found. Press \ue000 to launch the Wii U Menu";
DrawUtils::print(SCREEN_WIDTH / 2 + DrawUtils::getTextWidth(noEnvironmentsWarning) / 2, SCREEN_HEIGHT / 2, noEnvironmentsWarning, true);
}
DrawUtils::setFontColor(COLOR_TEXT);
@ -305,7 +337,11 @@ std::string EnvironmentSelectionScreen(const std::map<std::string, std::string>
DrawUtils::deinitFont();
if (OSGetTitleID() == _SYSGetSystemApplicationTitleId(SYSTEM_APP_ID_MII_MAKER)) {
// When we're in the Mii Maker "OSScreenShutdown" will cause a black screen.
} else {
OSScreenShutdown();
}
free(screenBuffer);