2020-12-01 13:06:40 +01:00
|
|
|
#include <cstring>
|
2020-04-28 14:43:07 +02:00
|
|
|
|
|
|
|
#include <elfio/elfio.hpp>
|
2020-12-01 13:06:40 +01:00
|
|
|
#include <nn/act/client_cpp.h>
|
2022-02-04 21:44:03 +01:00
|
|
|
#include <sysapp/launch.h>
|
2020-04-28 14:43:07 +02:00
|
|
|
|
|
|
|
#include "ElfUtils.h"
|
2022-02-04 21:44:03 +01:00
|
|
|
#include "fs/DirList.h"
|
2020-06-25 19:01:25 +02:00
|
|
|
#include "globals.h"
|
2022-02-04 21:44:03 +01:00
|
|
|
#include "kernel.h"
|
|
|
|
#include "module/ModuleDataFactory.h"
|
|
|
|
#include "module/ModuleDataPersistence.h"
|
2020-04-28 14:43:07 +02:00
|
|
|
|
|
|
|
extern "C" uint32_t textStart();
|
2022-01-23 22:15:28 +01:00
|
|
|
extern "C" void __fini();
|
2020-04-28 14:43:07 +02:00
|
|
|
|
2020-05-17 19:05:51 +02:00
|
|
|
int main(int argc, char **argv) {
|
2022-01-23 22:16:51 +01:00
|
|
|
initLogging();
|
2020-04-28 14:43:07 +02:00
|
|
|
|
2021-12-28 18:38:22 +01:00
|
|
|
// We subtract 0x100 to be safe.
|
|
|
|
uint32_t textSectionStart = textStart() - 0x100;
|
2020-04-28 14:43:07 +02:00
|
|
|
|
2020-05-17 19:05:51 +02:00
|
|
|
memset((void *) gModuleData, 0, sizeof(module_information_t));
|
2020-06-07 14:09:58 +02:00
|
|
|
gModuleData->version = MODULE_INFORMATION_VERSION;
|
2020-04-29 11:43:45 +02:00
|
|
|
|
2021-12-28 18:38:22 +01:00
|
|
|
std::string basePath = "fs:/vol/external01/wiiu";
|
|
|
|
if (argc >= 1) {
|
|
|
|
basePath = argv[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
DirList modules(basePath + "/modules", ".wms", DirList::Files, 1);
|
2020-04-28 14:43:07 +02:00
|
|
|
modules.SortList();
|
2020-05-29 17:36:10 +02:00
|
|
|
|
2020-06-25 19:01:25 +02:00
|
|
|
uint32_t destination_address = ((uint32_t) gModuleData + (sizeof(module_information_t) + 0x0000FFFF)) & 0xFFFF0000;
|
2020-05-17 19:05:51 +02:00
|
|
|
for (int i = 0; i < modules.GetFilecount(); i++) {
|
|
|
|
DEBUG_FUNCTION_LINE("Loading module %s", modules.GetFilepath(i));
|
2021-12-28 18:38:22 +01:00
|
|
|
auto moduleData = ModuleDataFactory::load(modules.GetFilepath(i), &destination_address, textSectionStart - destination_address, gModuleData->trampolines,
|
2022-01-27 12:52:45 +01:00
|
|
|
DYN_LINK_TRAMPOLINE_LIST_LENGTH);
|
2020-05-17 19:05:51 +02:00
|
|
|
if (moduleData) {
|
2020-04-29 12:06:47 +02:00
|
|
|
DEBUG_FUNCTION_LINE("Successfully loaded %s", modules.GetFilepath(i));
|
2020-05-17 13:11:52 +02:00
|
|
|
ModuleDataPersistence::saveModuleData(gModuleData, moduleData.value());
|
2020-05-03 00:06:11 +02:00
|
|
|
} else {
|
2020-04-29 12:06:47 +02:00
|
|
|
DEBUG_FUNCTION_LINE("Failed to load %s", modules.GetFilepath(i));
|
2020-04-28 14:43:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-23 22:17:48 +01:00
|
|
|
DEBUG_FUNCTION_LINE("Setup relocator");
|
2020-04-28 14:43:07 +02:00
|
|
|
SetupRelocator();
|
|
|
|
|
2020-12-01 13:07:09 +01:00
|
|
|
nn::act::Initialize();
|
2022-02-04 21:44:03 +01:00
|
|
|
nn::act::SlotNo slot = nn::act::GetSlotNo();
|
2020-12-01 13:07:09 +01:00
|
|
|
nn::act::SlotNo defaultSlot = nn::act::GetDefaultAccount();
|
|
|
|
nn::act::Finalize();
|
|
|
|
|
|
|
|
if (defaultSlot) { //normal menu boot
|
|
|
|
SYSLaunchMenu();
|
|
|
|
} else { //show mii select
|
|
|
|
_SYSLaunchMenuWithCheckingAccount(slot);
|
|
|
|
}
|
2022-01-23 22:15:28 +01:00
|
|
|
|
2022-01-23 22:16:51 +01:00
|
|
|
deinitLogging();
|
|
|
|
|
2022-01-23 22:15:28 +01:00
|
|
|
__fini();
|
2020-04-28 14:43:07 +02:00
|
|
|
return 0;
|
|
|
|
}
|