diff --git a/src/fs/CFile.cpp b/src/fs/CFile.cpp index c8e78d2..c3d7700 100644 --- a/src/fs/CFile.cpp +++ b/src/fs/CFile.cpp @@ -7,7 +7,7 @@ CFile::CFile() { iFd = -1; - mem_file = NULL; + mem_file = nullptr; filesize = 0; pos = 0; } diff --git a/src/fs/CFile.hpp b/src/fs/CFile.hpp index 6c0421b..756d4f6 100644 --- a/src/fs/CFile.hpp +++ b/src/fs/CFile.hpp @@ -63,9 +63,9 @@ public: protected: int32_t iFd; - const uint8_t *mem_file; - uint64_t filesize; - uint64_t pos; + const uint8_t *mem_file{}; + uint64_t filesize{}; + uint64_t pos{}; }; #endif diff --git a/src/fs/FSUtils.cpp b/src/fs/FSUtils.cpp index 885318a..16c7315 100644 --- a/src/fs/FSUtils.cpp +++ b/src/fs/FSUtils.cpp @@ -44,7 +44,7 @@ int32_t FSUtils::LoadFileToMem(const char *filepath, uint8_t **inbuffer, uint32_ if (done != filesize) { free(buffer); - buffer = NULL; + buffer = nullptr; return -3; } @@ -62,7 +62,7 @@ int32_t FSUtils::CheckFile(const char *filepath) { if (!filepath) return 0; - struct stat filestat; + struct stat filestat{}; char dirnoslash[strlen(filepath) + 2]; snprintf(dirnoslash, sizeof(dirnoslash), "%s", filepath); diff --git a/src/main.cpp b/src/main.cpp index e5502a0..64a2251 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,28 +1,31 @@ #include #include #include +#include #include #include #include #include #include #include +#include #include #include #include #include "utils/StringTools.h" #include -#include +#include #include "readFileWrapper.h" #include #include "fs/FSUtils.h" #include "romfs_helper.h" #include "filelist.h" +#include "utils/utils.h" -struct _ACPMetaData { +typedef struct ACPMetaData { char bootmovie[80696]; char bootlogo[28604]; -} _ACPMetaData; +} ACPMetaData; WUPS_PLUGIN_NAME("Homebrew in Wii U menu"); WUPS_PLUGIN_DESCRIPTION("Allows the user to load homebrew from the Wii U menu"); @@ -31,6 +34,7 @@ WUPS_PLUGIN_AUTHOR("Maschell"); WUPS_PLUGIN_LICENSE("GPL"); #define UPPER_TITLE_ID_HOMEBREW 0x0005000F + #define TITLE_ID_HOMEBREW_MASK (((uint64_t) UPPER_TITLE_ID_HOMEBREW) << 32) char gIconCache[65580] __attribute__((section(".data"))); @@ -49,9 +53,9 @@ INITIALIZE_PLUGIN() { gHomebrewLaunched = FALSE; } + ON_APPLICATION_START(args) { WHBLogUdpInit(); - DEBUG_FUNCTION_LINE("IN PLUGIN"); if (_SYSGetSystemApplicationTitleId(SYSTEM_APP_ID_HEALTH_AND_SAFETY) != OSGetTitleID()) { DEBUG_FUNCTION_LINE("gHomebrewLaunched to FALSE"); @@ -158,7 +162,6 @@ DECL_FUNCTION(int32_t, MCP_TitleList, uint32_t handle, uint32_t *outTitleCount, const char *indexedDevice = "mlc"; strcpy(template_title.indexedDevice, indexedDevice); - // System apps don't have a splash screen. template_title.appType = MCP_APP_TYPE_SYSTEM_APPS; @@ -392,6 +395,9 @@ DECL_FUNCTION(int32_t, ACPGetTitleMetaDirByDevice, uint32_t titleid_upper, uint3 return result; } +/* + * Load the H&S app instead + */ DECL_FUNCTION(int32_t, _SYSLaunchTitleByPathFromLauncher, char *pathToLoad, uint32_t u2) { const char *start = "/custom/"; if (strncmp(pathToLoad, start, strlen(start)) == 0) { @@ -422,6 +428,9 @@ DECL_FUNCTION(uint32_t, ACPGetApplicationBox, uint32_t *u1, uint32_t *u2, uint32 return result; } +/* + * Redirect the launchable check to H&S + */ DECL_FUNCTION(uint32_t, PatchChkStart__3RplFRCQ3_2nn6drmapp8StartArg, uint32_t *param) { if (param[2] == UPPER_TITLE_ID_HOMEBREW) { uint64_t titleID = _SYSGetSystemApplicationTitleId(SYSTEM_APP_ID_HEALTH_AND_SAFETY); @@ -432,6 +441,9 @@ DECL_FUNCTION(uint32_t, PatchChkStart__3RplFRCQ3_2nn6drmapp8StartArg, uint32_t * return result; } +/* + * Redirect the launchable check to H&S + */ DECL_FUNCTION(uint32_t, MCP_RightCheckLaunchable, uint32_t *u1, uint32_t *u2, uint32_t u3, uint32_t u4, uint32_t u5) { if (u3 == UPPER_TITLE_ID_HOMEBREW) { uint64_t titleID = _SYSGetSystemApplicationTitleId(SYSTEM_APP_ID_HEALTH_AND_SAFETY); @@ -442,6 +454,9 @@ DECL_FUNCTION(uint32_t, MCP_RightCheckLaunchable, uint32_t *u1, uint32_t *u2, ui return result; } +/* + * Patch the meta xml for the home menu + */ DECL_FUNCTION(int32_t, HBM_NN_ACP_ACPGetTitleMetaXmlByDevice, uint32_t titleid_upper, uint32_t titleid_lower, ACPMetaXml *metaxml, uint32_t device) { if (gHomebrewLaunched) { memcpy(metaxml, &gLaunchXML, sizeof(gLaunchXML)); @@ -451,26 +466,29 @@ DECL_FUNCTION(int32_t, HBM_NN_ACP_ACPGetTitleMetaXmlByDevice, uint32_t titleid_u return result; } - -DECL_FUNCTION(uint32_t, ACPGetLaunchMetaData, struct _ACPMetaData *metadata) { +/* + * Patch the boot movie and and boot logo + */ +DECL_FUNCTION(uint32_t, ACPGetLaunchMetaData, struct ACPMetaData *metadata) { uint32_t result = real_ACPGetLaunchMetaData(metadata); if (gHomebrewLaunched) { memcpy(metadata->bootmovie, bootMovie_h264, bootMovie_h264_size); memcpy(metadata->bootlogo, bootLogoTex_tga, bootLogoTex_tga_size); + DCFlushRange(metadata->bootmovie, bootMovie_h264_size); + DCFlushRange(metadata->bootlogo, bootMovie_h264_size); + } return result; } + WUPS_MUST_REPLACE_PHYSICAL_FOR_PROCESS(HBM_NN_ACP_ACPGetTitleMetaXmlByDevice, 0x2E36CE44, 0x0E36CE44, WUPS_FP_TARGET_PROCESS_HOME_MENU); WUPS_MUST_REPLACE(ACPGetApplicationBox, WUPS_LOADER_LIBRARY_NN_ACP, ACPGetApplicationBox); WUPS_MUST_REPLACE(PatchChkStart__3RplFRCQ3_2nn6drmapp8StartArg, WUPS_LOADER_LIBRARY_DRMAPP, PatchChkStart__3RplFRCQ3_2nn6drmapp8StartArg); WUPS_MUST_REPLACE(MCP_RightCheckLaunchable, WUPS_LOADER_LIBRARY_COREINIT, MCP_RightCheckLaunchable); -WUPS_MUST_REPLACE(FSReadFile, WUPS_LOADER_LIBRARY_COREINIT, FSReadFile); -WUPS_MUST_REPLACE(FSOpenFile, WUPS_LOADER_LIBRARY_COREINIT, FSOpenFile); -WUPS_MUST_REPLACE(FSCloseFile, WUPS_LOADER_LIBRARY_COREINIT, FSCloseFile); WUPS_MUST_REPLACE(MCP_TitleList, WUPS_LOADER_LIBRARY_COREINIT, MCP_TitleList); WUPS_MUST_REPLACE(MCP_GetTitleInfoByTitleAndDevice, WUPS_LOADER_LIBRARY_COREINIT, MCP_GetTitleInfoByTitleAndDevice); @@ -480,3 +498,7 @@ WUPS_MUST_REPLACE(ACPGetLaunchMetaXml, WUPS_LOADER_LIBRARY_NN_ACP, ACPGetLaunchM WUPS_MUST_REPLACE(ACPGetTitleMetaDirByDevice, WUPS_LOADER_LIBRARY_NN_ACP, ACPGetTitleMetaDirByDevice); WUPS_MUST_REPLACE(_SYSLaunchTitleByPathFromLauncher, WUPS_LOADER_LIBRARY_SYSAPP, _SYSLaunchTitleByPathFromLauncher); WUPS_MUST_REPLACE(ACPGetLaunchMetaData, WUPS_LOADER_LIBRARY_NN_ACP, ACPGetLaunchMetaData); + +WUPS_MUST_REPLACE(FSReadFile, WUPS_LOADER_LIBRARY_COREINIT, FSReadFile); +WUPS_MUST_REPLACE(FSOpenFile, WUPS_LOADER_LIBRARY_COREINIT, FSOpenFile); +WUPS_MUST_REPLACE(FSCloseFile, WUPS_LOADER_LIBRARY_COREINIT, FSCloseFile); diff --git a/src/readFileWrapper.cpp b/src/readFileWrapper.cpp index efc0d78..4d03d52 100644 --- a/src/readFileWrapper.cpp +++ b/src/readFileWrapper.cpp @@ -1,11 +1,11 @@ #include "readFileWrapper.h" #include "fs/FSUtils.h" #include "utils/logger.h" -#include -#include -#include + +#include #include #include "romfs_helper.h" +#include fileReadInformation gFileReadInformation[FILE_READ_INFO_SIZE] __attribute__((section(".data"))); @@ -117,7 +117,7 @@ void DeInitAllFiles() { int fileReadInformation_getSlot() { for (int i = 0; i < 32; i++) { - if (gFileReadInformation[i].inUse == false) { + if (!gFileReadInformation[i].inUse) { gFileReadInformation[i].inUse = true; return i; } @@ -127,7 +127,7 @@ int fileReadInformation_getSlot() { bool initCompressedFileReadInformation(fileReadInformation *info) { - if (info == NULL || !info->compressed) { + if (info == nullptr || !info->compressed) { info->cInitDone = false; return false; } @@ -213,11 +213,13 @@ int32_t FSOpenFile_for_ID(uint32_t id, const char *filepath, int *handle) { bool nonCompressed = false; if (!FSUtils::CheckFile(buffer)) { snprintf(buffer, 256, "%s:/%s", romName, test); + free(test); if (!FSUtils::CheckFile(buffer)) { return -3; } nonCompressed = true; } + free(test); int fd = open(buffer, 0); if (fd >= 0) { @@ -225,6 +227,7 @@ int32_t FSOpenFile_for_ID(uint32_t id, const char *filepath, int *handle) { int slot = fileReadInformation_getSlot(); if (slot < 0) { DEBUG_FUNCTION_LINE("Failed to get a slot"); + close(fd); return -5; } fileReadInformation *info = &gFileReadInformation[slot];