2019-09-06 17:02:09 +02:00
|
|
|
#include <wups.h>
|
2019-12-07 22:15:43 +01:00
|
|
|
#include <stdarg.h>
|
2019-09-06 17:02:09 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2019-09-08 21:06:53 +02:00
|
|
|
#include <coreinit/title.h>
|
|
|
|
#include <coreinit/cache.h>
|
2019-09-06 17:02:09 +02:00
|
|
|
#include <coreinit/systeminfo.h>
|
|
|
|
#include <coreinit/mcp.h>
|
|
|
|
#include <coreinit/filesystem.h>
|
2019-09-08 21:06:53 +02:00
|
|
|
#include <sysapp/title.h>
|
|
|
|
#include <nn/acp.h>
|
2019-09-06 17:02:09 +02:00
|
|
|
#include <nsysnet/socket.h>
|
|
|
|
#include <coreinit/ios.h>
|
|
|
|
#include <utils/logger.h>
|
2019-12-08 22:49:08 +01:00
|
|
|
#include "utils/StringTools.h"
|
2019-09-06 17:02:09 +02:00
|
|
|
#include <fs/DirList.h>
|
2019-12-08 22:49:08 +01:00
|
|
|
#include <wut_romfs_dev.h>
|
2020-06-17 22:11:57 +02:00
|
|
|
#include <utils/utils.h>
|
2019-12-08 22:49:08 +01:00
|
|
|
#include "readFileWrapper.h"
|
2020-06-17 22:19:23 +02:00
|
|
|
#include <whb/log_udp.h>
|
2019-12-08 22:49:08 +01:00
|
|
|
#include "romfs_helper.h"
|
2020-06-17 22:14:36 +02:00
|
|
|
#include "filelist.h"
|
2019-12-07 22:15:43 +01:00
|
|
|
|
2020-06-17 22:15:45 +02:00
|
|
|
struct _ACPMetaData {
|
|
|
|
char bootmovie[80696];
|
|
|
|
char bootlogo[28604];
|
|
|
|
} _ACPMetaData;
|
|
|
|
|
2019-11-24 14:15:53 +01:00
|
|
|
WUPS_PLUGIN_NAME("Homebrew SysLauncher");
|
2019-11-24 14:14:45 +01:00
|
|
|
WUPS_PLUGIN_DESCRIPTION("Allows the user to load homebrew from the System Menu");
|
|
|
|
WUPS_PLUGIN_VERSION("0.1");
|
2019-09-06 17:02:09 +02:00
|
|
|
WUPS_PLUGIN_AUTHOR("Maschell");
|
|
|
|
WUPS_PLUGIN_LICENSE("GPL");
|
|
|
|
|
2020-06-17 14:28:15 +02:00
|
|
|
#define UPPER_TITLE_ID_HOMEBREW 0x0005000F
|
2020-06-17 16:37:17 +02:00
|
|
|
#define TITLE_ID_HOMEBREW_MASK (((uint64_t) UPPER_TITLE_ID_HOMEBREW) << 32)
|
2020-06-17 14:28:15 +02:00
|
|
|
|
2019-12-08 22:49:08 +01:00
|
|
|
char gIconCache[65580] __attribute__((section(".data")));
|
2019-09-08 21:06:53 +02:00
|
|
|
ACPMetaXml gLaunchXML __attribute__((section(".data")));
|
|
|
|
MCPTitleListType template_title __attribute__((section(".data")));
|
|
|
|
BOOL gHomebrewLaunched __attribute__((section(".data")));
|
|
|
|
|
2019-11-24 14:14:45 +01:00
|
|
|
WUPS_USE_WUT_CRT()
|
|
|
|
|
2019-09-08 21:06:53 +02:00
|
|
|
INITIALIZE_PLUGIN() {
|
2020-06-17 13:45:15 +02:00
|
|
|
memset((void *) &template_title, 0, sizeof(template_title));
|
|
|
|
memset((void *) &gLaunchXML, 0, sizeof(gLaunchXML));
|
|
|
|
memset((void *) &gFileInfos, 0, sizeof(gFileInfos));
|
|
|
|
memset((void *) &gFileReadInformation, 0, sizeof(gFileReadInformation));
|
|
|
|
memset((void *) &gIconCache, 0, sizeof(gIconCache));
|
2019-09-08 21:06:53 +02:00
|
|
|
gHomebrewLaunched = FALSE;
|
|
|
|
}
|
2019-09-06 17:02:09 +02:00
|
|
|
|
|
|
|
ON_APPLICATION_START(args) {
|
2020-06-17 22:19:23 +02:00
|
|
|
WHBLogUdpInit();
|
|
|
|
DEBUG_FUNCTION_LINE("IN PLUGIN");
|
2019-09-08 21:06:53 +02:00
|
|
|
|
2020-06-17 13:45:15 +02:00
|
|
|
if (_SYSGetSystemApplicationTitleId(SYSTEM_APP_ID_HEALTH_AND_SAFETY) != OSGetTitleID()) {
|
2020-06-17 22:19:23 +02:00
|
|
|
DEBUG_FUNCTION_LINE("gHomebrewLaunched to FALSE");
|
2019-09-08 21:06:53 +02:00
|
|
|
gHomebrewLaunched = FALSE;
|
|
|
|
}
|
2019-09-06 17:02:09 +02:00
|
|
|
}
|
|
|
|
|
2019-11-24 14:14:45 +01:00
|
|
|
ON_APPLICATION_END() {
|
2019-12-08 22:49:08 +01:00
|
|
|
DeInitAllFiles();
|
2019-11-24 14:14:45 +01:00
|
|
|
unmountAllRomfs();
|
2019-09-06 17:02:09 +02:00
|
|
|
}
|
|
|
|
|
2020-06-17 13:45:15 +02:00
|
|
|
void fillXmlForTitleID(uint32_t titleid_upper, uint32_t titleid_lower, ACPMetaXml *out_buf) {
|
2020-06-17 16:37:17 +02:00
|
|
|
int32_t id = getIDByLowerTitleID(titleid_lower);
|
2020-06-17 22:16:10 +02:00
|
|
|
if (id < 0) {
|
2020-06-17 22:19:23 +02:00
|
|
|
DEBUG_FUNCTION_LINE("Failed to get id by titleid");
|
2020-06-17 16:37:17 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (id >= FILE_INFO_SIZE) {
|
2019-12-07 22:15:43 +01:00
|
|
|
return;
|
|
|
|
}
|
2020-06-17 13:45:15 +02:00
|
|
|
out_buf->title_id = ((uint64_t) titleid_upper * 0x100000000) + titleid_lower;
|
2020-06-17 16:37:17 +02:00
|
|
|
strncpy(out_buf->longname_en, gFileInfos[id].name, 511);
|
|
|
|
strncpy(out_buf->shortname_en, gFileInfos[id].name, 255);
|
|
|
|
strncpy(out_buf->publisher_en, gFileInfos[id].name, 255);
|
2019-09-12 18:55:49 +02:00
|
|
|
out_buf->e_manual = 1;
|
2019-11-24 14:14:45 +01:00
|
|
|
out_buf->e_manual_version = 0;
|
|
|
|
out_buf->title_version = 1;
|
|
|
|
out_buf->network_use = 1;
|
|
|
|
out_buf->launching_flag = 4;
|
|
|
|
out_buf->online_account_use = 1;
|
|
|
|
out_buf->os_version = 0x000500101000400A;
|
2019-09-12 18:55:49 +02:00
|
|
|
out_buf->region = 0xFFFFFFFF;
|
2019-11-24 14:14:45 +01:00
|
|
|
out_buf->common_save_size = 0x0000000001790000;
|
|
|
|
out_buf->group_id = 0x400;
|
|
|
|
out_buf->drc_use = 1;
|
|
|
|
out_buf->version = 1;
|
2020-06-17 13:45:15 +02:00
|
|
|
out_buf->reserved_flag0 = 0x00010001;
|
|
|
|
out_buf->reserved_flag6 = 0x00000003;
|
|
|
|
out_buf->pc_usk = 128;
|
2020-06-17 14:26:01 +02:00
|
|
|
strncpy(out_buf->product_code, "WUP-P-HBLD", strlen("WUP-P-HBLD") + 1);
|
|
|
|
strncpy(out_buf->content_platform, "WUP", strlen("WUP") + 1);
|
|
|
|
strncpy(out_buf->company_code, "0001", strlen("0001") + 1);
|
2019-11-24 14:14:45 +01:00
|
|
|
}
|
|
|
|
|
2020-06-17 14:31:38 +02:00
|
|
|
/* hash: compute hash value of string */
|
|
|
|
unsigned int hash(char *str) {
|
|
|
|
unsigned int h;
|
|
|
|
unsigned char *p;
|
|
|
|
|
|
|
|
h = 0;
|
|
|
|
for (p = (unsigned char *) str; *p != '\0'; p++) {
|
|
|
|
h = 37 * h + *p;
|
|
|
|
}
|
|
|
|
return h; // or, h % ARRAY_SIZE;
|
|
|
|
}
|
|
|
|
|
2020-06-17 13:45:15 +02:00
|
|
|
DECL_FUNCTION(int32_t, MCP_TitleList, uint32_t handle, uint32_t *outTitleCount, MCPTitleListType *titleList, uint32_t size) {
|
2019-09-06 17:02:09 +02:00
|
|
|
int32_t result = real_MCP_TitleList(handle, outTitleCount, titleList, size);
|
|
|
|
uint32_t titlecount = *outTitleCount;
|
|
|
|
|
2019-11-24 14:14:45 +01:00
|
|
|
DirList dirList("fs:/vol/external01/wiiu/apps", ".rpx,.wbf", DirList::Files | DirList::CheckSubfolders, 1);
|
2019-09-06 17:02:09 +02:00
|
|
|
dirList.SortList();
|
2019-11-24 14:14:45 +01:00
|
|
|
|
2019-09-06 17:02:09 +02:00
|
|
|
int j = 0;
|
2020-06-17 13:45:15 +02:00
|
|
|
for (int i = 0; i < dirList.GetFilecount(); i++) {
|
|
|
|
if (j >= FILE_INFO_SIZE) {
|
2020-06-17 22:19:23 +02:00
|
|
|
DEBUG_FUNCTION_LINE("TOO MANY TITLES");
|
2019-12-07 22:15:43 +01:00
|
|
|
break;
|
|
|
|
}
|
2019-09-06 17:02:09 +02:00
|
|
|
//! skip our own application in the listing
|
2020-06-17 13:45:15 +02:00
|
|
|
if (strcasecmp(dirList.GetFilename(i), "homebrew_launcher.rpx") == 0) {
|
2019-09-06 17:02:09 +02:00
|
|
|
continue;
|
2019-11-24 14:14:45 +01:00
|
|
|
}
|
2019-09-06 17:02:09 +02:00
|
|
|
//! skip our own application in the listing
|
2020-06-17 13:45:15 +02:00
|
|
|
if (strcasecmp(dirList.GetFilename(i), "temp.rpx") == 0) {
|
2019-09-06 17:02:09 +02:00
|
|
|
continue;
|
2019-11-24 14:14:45 +01:00
|
|
|
}
|
2019-09-06 17:02:09 +02:00
|
|
|
|
|
|
|
//! skip hidden linux and mac files
|
2020-06-17 13:45:15 +02:00
|
|
|
if (dirList.GetFilename(i)[0] == '.' || dirList.GetFilename(i)[0] == '_') {
|
2019-09-06 17:02:09 +02:00
|
|
|
continue;
|
2019-11-24 14:14:45 +01:00
|
|
|
}
|
2019-09-08 21:06:53 +02:00
|
|
|
|
2020-06-17 13:45:15 +02:00
|
|
|
char *repl = (char *) "fs:/vol/external01/";
|
|
|
|
char *with = (char *) "";
|
|
|
|
char *input = (char *) dirList.GetFilepath(i);
|
2019-11-24 14:14:45 +01:00
|
|
|
|
2020-06-17 13:45:15 +02:00
|
|
|
char *path = StringTools::str_replace(input, repl, with);
|
|
|
|
if (path != NULL) {
|
|
|
|
strncpy(gFileInfos[j].path, path, 255);
|
2019-11-24 14:14:45 +01:00
|
|
|
free(path);
|
|
|
|
}
|
|
|
|
|
2020-06-17 22:13:21 +02:00
|
|
|
gFileInfos[j].lowerTitleID = hash(gFileInfos[j].path);
|
|
|
|
|
|
|
|
char buffer[25];
|
|
|
|
snprintf(buffer, 25, "/custom/%08X%08X", UPPER_TITLE_ID_HOMEBREW, gFileInfos[j].lowerTitleID);
|
|
|
|
strcpy(template_title.path, buffer);
|
|
|
|
|
2020-06-17 13:45:15 +02:00
|
|
|
strncpy(gFileInfos[j].name, dirList.GetFilename(i), 255);
|
2019-11-24 14:14:45 +01:00
|
|
|
gFileInfos[j].source = 0; //SD Card;
|
|
|
|
|
2020-06-17 13:45:15 +02:00
|
|
|
const char *indexedDevice = "mlc";
|
|
|
|
strcpy(template_title.indexedDevice, indexedDevice);
|
|
|
|
if (StringTools::EndsWith(gFileInfos[j].name, ".wbf")) {
|
2019-11-24 14:14:45 +01:00
|
|
|
template_title.appType = MCP_APP_TYPE_GAME;
|
|
|
|
} else {
|
|
|
|
// System apps don't have a splash screen.
|
|
|
|
template_title.appType = MCP_APP_TYPE_SYSTEM_APPS;
|
|
|
|
}
|
2020-06-17 14:36:41 +02:00
|
|
|
template_title.titleId = TITLE_ID_HOMEBREW_MASK | gFileInfos[j].lowerTitleID;
|
2019-09-08 21:06:53 +02:00
|
|
|
template_title.titleVersion = 1;
|
|
|
|
template_title.groupId = 0x400;
|
2019-11-24 14:14:45 +01:00
|
|
|
|
2019-09-08 21:06:53 +02:00
|
|
|
template_title.osVersion = OSGetOSID();
|
|
|
|
template_title.sdkVersion = __OSGetProcessSDKVersion();
|
2019-11-24 14:14:45 +01:00
|
|
|
template_title.unk0x60 = 0;
|
2019-09-08 21:06:53 +02:00
|
|
|
|
2020-06-17 22:19:23 +02:00
|
|
|
DEBUG_FUNCTION_LINE("[%d] %s [%016llX]", j, gFileInfos[j].path, template_title.titleId);
|
2020-06-17 14:31:38 +02:00
|
|
|
|
2020-06-17 13:45:15 +02:00
|
|
|
memcpy(&(titleList[titlecount]), &template_title, sizeof(template_title));
|
2019-12-07 22:15:43 +01:00
|
|
|
|
2019-09-06 17:02:09 +02:00
|
|
|
titlecount++;
|
|
|
|
j++;
|
|
|
|
}
|
2019-09-08 21:06:53 +02:00
|
|
|
|
2019-09-06 17:02:09 +02:00
|
|
|
*outTitleCount = titlecount;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2020-06-17 13:45:15 +02:00
|
|
|
DECL_FUNCTION(int32_t, MCP_GetTitleInfoByTitleAndDevice, uint32_t mcp_handle, uint32_t titleid_lower_1, uint32_t titleid_upper, uint32_t titleid_lower_2, uint32_t unknown, MCPTitleListType *title) {
|
|
|
|
if (gHomebrewLaunched) {
|
2019-09-08 21:06:53 +02:00
|
|
|
memcpy(title, &(template_title), sizeof(MCPTitleListType));
|
2020-06-17 14:28:15 +02:00
|
|
|
} else if (titleid_upper == UPPER_TITLE_ID_HOMEBREW) {
|
2020-06-17 13:45:15 +02:00
|
|
|
char buffer[25];
|
|
|
|
snprintf(buffer, 25, "/custom/%08X%08X", titleid_upper, titleid_lower_2);
|
|
|
|
strcpy(template_title.path, buffer);
|
2020-06-17 14:36:41 +02:00
|
|
|
template_title.titleId = TITLE_ID_HOMEBREW_MASK | titleid_lower_1;
|
2019-09-08 21:06:53 +02:00
|
|
|
memcpy(title, &(template_title), sizeof(MCPTitleListType));
|
2019-09-06 17:02:09 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2019-09-08 21:06:53 +02:00
|
|
|
int result = real_MCP_GetTitleInfoByTitleAndDevice(mcp_handle, titleid_lower_1, titleid_upper, titleid_lower_2, unknown, title);
|
|
|
|
|
2019-09-06 17:02:09 +02:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-11-24 14:14:45 +01:00
|
|
|
typedef struct __attribute((packed)) {
|
|
|
|
uint32_t command;
|
|
|
|
uint32_t target;
|
|
|
|
uint32_t filesize;
|
|
|
|
uint32_t fileoffset;
|
|
|
|
char path[256];
|
2020-06-17 13:46:26 +02:00
|
|
|
} LOAD_REQUEST;
|
2019-11-24 14:14:45 +01:00
|
|
|
|
2020-06-17 13:45:15 +02:00
|
|
|
int32_t getRPXInfoForID(uint32_t id, romfs_fileInfo *info);
|
2019-09-06 17:02:09 +02:00
|
|
|
|
2020-06-17 13:45:15 +02:00
|
|
|
DECL_FUNCTION(int32_t, ACPCheckTitleLaunchByTitleListTypeEx, MCPTitleListType *title, uint32_t u2) {
|
2020-06-17 14:36:41 +02:00
|
|
|
if ((title->titleId & TITLE_ID_HOMEBREW_MASK) == TITLE_ID_HOMEBREW_MASK) {
|
2020-06-17 14:31:38 +02:00
|
|
|
int32_t id = getIDByLowerTitleID(title->titleId & 0xFFFFFFFF);
|
2020-06-17 22:13:02 +02:00
|
|
|
if (id >= 0) {
|
2020-06-17 22:19:23 +02:00
|
|
|
DEBUG_FUNCTION_LINE("Started homebrew");
|
2020-06-17 14:31:38 +02:00
|
|
|
gHomebrewLaunched = TRUE;
|
|
|
|
fillXmlForTitleID((title->titleId & 0xFFFFFFFF00000000) >> 32, (title->titleId & 0xFFFFFFFF), &gLaunchXML);
|
|
|
|
|
|
|
|
LOAD_REQUEST request;
|
|
|
|
memset(&request, 0, sizeof(request));
|
|
|
|
|
|
|
|
request.command = 0xFC; // IPC_CUSTOM_LOAD_CUSTOM_RPX;
|
|
|
|
request.target = 0; // LOAD_FILE_TARGET_SD_CARD
|
|
|
|
request.filesize = 0; // unknown
|
|
|
|
request.fileoffset = 0; //
|
|
|
|
|
|
|
|
romfs_fileInfo info;
|
2020-06-17 16:37:17 +02:00
|
|
|
int res = getRPXInfoForID(id, &info);
|
2020-06-17 14:31:38 +02:00
|
|
|
if (res >= 0) {
|
|
|
|
request.filesize = ((uint32_t *) &info.length)[1];
|
|
|
|
request.fileoffset = ((uint32_t *) &info.offset)[1];
|
|
|
|
loadFileIntoBuffer((title->titleId & 0xFFFFFFFF), "meta/iconTex.tga", gIconCache, sizeof(gIconCache));
|
|
|
|
}
|
2019-11-24 14:14:45 +01:00
|
|
|
|
2020-06-17 16:37:17 +02:00
|
|
|
strncpy(request.path, gFileInfos[id].path, 255);
|
2019-12-08 22:49:08 +01:00
|
|
|
|
|
|
|
|
2020-06-17 22:19:23 +02:00
|
|
|
DEBUG_FUNCTION_LINE("Loading file %s size: %08X offset: %08X", request.path, request.filesize, request.fileoffset);
|
2019-11-24 14:14:45 +01:00
|
|
|
|
2020-06-17 14:31:38 +02:00
|
|
|
DCFlushRange(&request, sizeof(LOAD_REQUEST));
|
2019-11-24 14:14:45 +01:00
|
|
|
|
2020-06-17 14:31:38 +02:00
|
|
|
int mcpFd = IOS_Open("/dev/mcp", (IOSOpenMode) 0);
|
|
|
|
if (mcpFd >= 0) {
|
|
|
|
int out = 0;
|
|
|
|
IOS_Ioctl(mcpFd, 100, &request, sizeof(request), &out, sizeof(out));
|
|
|
|
IOS_Close(mcpFd);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
DEBUG_FUNCTION_LINE("Failed to get the id for titleID %016llX", title->titleId);
|
2019-11-24 14:14:45 +01:00
|
|
|
}
|
2019-09-12 18:55:49 +02:00
|
|
|
}
|
2019-09-08 21:06:53 +02:00
|
|
|
|
2019-09-12 18:55:49 +02:00
|
|
|
int result = real_ACPCheckTitleLaunchByTitleListTypeEx(title, u2);
|
|
|
|
return result;
|
2019-09-08 21:06:53 +02:00
|
|
|
|
2019-09-06 17:02:09 +02:00
|
|
|
}
|
|
|
|
|
2019-11-24 14:14:45 +01:00
|
|
|
DECL_FUNCTION(int, FSOpenFile, FSClient *client, FSCmdBlock *block, char *path, const char *mode, int *handle, int error) {
|
2020-06-17 14:36:41 +02:00
|
|
|
const char *start = "/vol/storage_mlc01/sys/title/0005000F";
|
|
|
|
const char *icon = ".tga";
|
|
|
|
const char *iconTex = "iconTex.tga";
|
|
|
|
const char *sound = ".btsnd";
|
2019-11-24 14:14:45 +01:00
|
|
|
|
2020-06-17 13:45:15 +02:00
|
|
|
if (StringTools::EndsWith(path, icon) || StringTools::EndsWith(path, sound)) {
|
|
|
|
if (strncmp(path, start, strlen(start)) == 0) {
|
2019-11-24 14:14:45 +01:00
|
|
|
int res = FS_STATUS_NOT_FOUND;
|
2020-06-17 13:45:15 +02:00
|
|
|
if (StringTools::EndsWith(path, iconTex)) {
|
2019-11-24 14:14:45 +01:00
|
|
|
// fallback to dummy icon if loaded homebrew is no .wbf
|
2020-06-17 22:14:36 +02:00
|
|
|
*handle = 0x13371338;
|
|
|
|
res = FS_STATUS_OK;
|
2019-11-24 14:14:45 +01:00
|
|
|
}
|
|
|
|
|
2020-06-17 16:37:17 +02:00
|
|
|
uint32_t lowerTitleID;
|
2020-06-17 13:45:15 +02:00
|
|
|
char *id = path + 1 + strlen(start);
|
2019-11-24 14:14:45 +01:00
|
|
|
id[8] = 0;
|
2020-06-17 13:45:15 +02:00
|
|
|
char *ending = id + 9;
|
2020-06-17 16:37:17 +02:00
|
|
|
sscanf(id, "%08X", &lowerTitleID);
|
|
|
|
int32_t idVal = getIDByLowerTitleID(lowerTitleID);
|
|
|
|
if (idVal < 0) {
|
2020-06-17 22:19:23 +02:00
|
|
|
DEBUG_FUNCTION_LINE("Failed to find id for titleID %08X", lowerTitleID);
|
2020-06-17 16:37:17 +02:00
|
|
|
} else {
|
|
|
|
if (FSOpenFile_for_ID(idVal, ending, handle) < 0) {
|
|
|
|
return res;
|
|
|
|
}
|
2019-11-24 14:14:45 +01:00
|
|
|
}
|
|
|
|
return FS_STATUS_OK;
|
2020-06-17 13:45:15 +02:00
|
|
|
} else if (gHomebrewLaunched) {
|
|
|
|
if (StringTools::EndsWith(path, iconTex)) {
|
2019-12-08 22:49:08 +01:00
|
|
|
*handle = 0x13371337;
|
2020-06-17 22:19:23 +02:00
|
|
|
DEBUG_FUNCTION_LINE("yooo let's do it");
|
2019-12-08 22:49:08 +01:00
|
|
|
return FS_STATUS_OK;
|
2020-06-17 13:45:15 +02:00
|
|
|
} else {
|
2020-06-17 22:19:23 +02:00
|
|
|
DEBUG_FUNCTION_LINE("%s", path);
|
2019-12-08 22:49:08 +01:00
|
|
|
}
|
|
|
|
|
2019-11-24 14:14:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int result = real_FSOpenFile(client, block, path, mode, handle, error);
|
2019-09-12 18:55:49 +02:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-11-24 14:14:45 +01:00
|
|
|
DECL_FUNCTION(FSStatus, FSCloseFile, FSClient *client, FSCmdBlock *block, FSFileHandle handle, uint32_t flags) {
|
2020-06-17 22:14:36 +02:00
|
|
|
if (handle == 0x13371337 || handle == 0x13371338) {
|
2019-12-08 22:49:08 +01:00
|
|
|
return FS_STATUS_OK;
|
2019-11-24 14:14:45 +01:00
|
|
|
}
|
2020-06-17 13:45:15 +02:00
|
|
|
if ((handle & 0xFF000000) == 0xFF000000) {
|
2019-12-08 22:49:08 +01:00
|
|
|
int32_t fd = (handle & 0x00000FFF);
|
|
|
|
int32_t romid = (handle & 0x00FFF000) >> 12;
|
2020-06-17 22:19:23 +02:00
|
|
|
DEBUG_FUNCTION_LINE("Close %d %d", fd, romid);
|
2019-12-07 22:15:43 +01:00
|
|
|
DeInitFile(fd);
|
2020-06-17 13:45:15 +02:00
|
|
|
if (gFileInfos[romid].openedFiles--) {
|
|
|
|
if (gFileInfos[romid].openedFiles <= 0) {
|
2020-06-17 22:19:23 +02:00
|
|
|
DEBUG_FUNCTION_LINE("unmount romfs no more handles");
|
2019-12-08 22:49:08 +01:00
|
|
|
unmountRomfs(romid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//unmountAllRomfs();
|
2019-11-24 14:14:45 +01:00
|
|
|
return FS_STATUS_OK;
|
|
|
|
}
|
2020-06-17 13:45:15 +02:00
|
|
|
return real_FSCloseFile(client, block, handle, flags);
|
2019-11-24 14:14:45 +01:00
|
|
|
}
|
|
|
|
|
2020-06-17 13:45:15 +02:00
|
|
|
DECL_FUNCTION(FSStatus, FSReadFile, FSClient *client, FSCmdBlock *block, uint8_t *buffer, uint32_t size, uint32_t count, FSFileHandle handle, uint32_t unk1, uint32_t flags) {
|
|
|
|
if (handle == 0x13371337) {
|
2020-06-17 14:36:41 +02:00
|
|
|
uint32_t cpySize = size * count;
|
2020-06-17 13:45:15 +02:00
|
|
|
if (sizeof(gIconCache) < cpySize) {
|
2019-12-08 22:49:08 +01:00
|
|
|
cpySize = sizeof(gIconCache);
|
2019-11-24 14:14:45 +01:00
|
|
|
}
|
2019-12-08 22:49:08 +01:00
|
|
|
memcpy(buffer, gIconCache, cpySize);
|
2020-06-17 22:19:23 +02:00
|
|
|
DEBUG_FUNCTION_LINE("DUMMY");
|
2020-06-17 13:45:15 +02:00
|
|
|
return (FSStatus) (cpySize / size);
|
2020-06-17 22:14:36 +02:00
|
|
|
} else if (handle == 0x13371338) {
|
|
|
|
uint32_t cpySize = size * count;
|
|
|
|
if (iconTex_tga_size < cpySize) {
|
|
|
|
cpySize = iconTex_tga_size;
|
|
|
|
}
|
|
|
|
memcpy(buffer, iconTex_tga, cpySize);
|
2020-06-17 22:19:23 +02:00
|
|
|
DEBUG_FUNCTION_LINE("DUMMY");
|
2020-06-17 22:14:36 +02:00
|
|
|
return (FSStatus) (cpySize / size);
|
2019-11-24 14:14:45 +01:00
|
|
|
}
|
2020-06-17 13:45:15 +02:00
|
|
|
if ((handle & 0xFF000000) == 0xFF000000) {
|
2019-12-08 22:49:08 +01:00
|
|
|
int32_t fd = (handle & 0x00000FFF);
|
|
|
|
int32_t romid = (handle & 0x00FFF000) >> 12;
|
|
|
|
|
2020-06-17 22:19:23 +02:00
|
|
|
DEBUG_FUNCTION_LINE("READ %d from %d rom: %d", size * count, fd, romid);
|
2019-12-07 22:15:43 +01:00
|
|
|
|
2020-06-17 13:45:15 +02:00
|
|
|
int readSize = readFile(fd, buffer, (size * count));
|
2019-12-07 22:15:43 +01:00
|
|
|
|
2020-06-17 13:45:15 +02:00
|
|
|
return (FSStatus) (readSize / size);
|
2019-11-24 14:14:45 +01:00
|
|
|
}
|
|
|
|
FSStatus result = real_FSReadFile(client, block, buffer, size, count, handle, unk1, flags);
|
2019-09-06 17:02:09 +02:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2020-06-17 13:45:15 +02:00
|
|
|
DECL_FUNCTION(int32_t, ACPGetTitleMetaXmlByDevice, uint32_t titleid_upper, uint32_t titleid_lower, ACPMetaXml *out_buf, uint32_t device, uint32_t u1) {
|
|
|
|
int result = real_ACPGetTitleMetaXmlByDevice(titleid_upper, titleid_lower, out_buf, device, u1);
|
2020-06-17 14:28:15 +02:00
|
|
|
if (titleid_upper == UPPER_TITLE_ID_HOMEBREW) {
|
2020-06-17 13:45:15 +02:00
|
|
|
fillXmlForTitleID(titleid_upper, titleid_lower, out_buf);
|
2019-09-06 17:02:09 +02:00
|
|
|
result = 0;
|
|
|
|
}
|
2019-09-08 21:06:53 +02:00
|
|
|
return result;
|
2019-09-06 17:02:09 +02:00
|
|
|
}
|
|
|
|
|
2020-06-17 13:45:15 +02:00
|
|
|
DECL_FUNCTION(int32_t, ACPGetTitleMetaDirByDevice, uint32_t titleid_upper, uint32_t titleid_lower, char *out_buf, uint32_t size, int device) {
|
2020-06-17 14:28:15 +02:00
|
|
|
if (titleid_upper == UPPER_TITLE_ID_HOMEBREW) {
|
2020-06-17 13:45:15 +02:00
|
|
|
snprintf(out_buf, 53, "/vol/storage_mlc01/sys/title/%08X/%08X/meta", titleid_upper, titleid_lower);
|
2019-11-24 14:14:45 +01:00
|
|
|
return 0;
|
2019-09-06 17:02:09 +02:00
|
|
|
}
|
2019-11-24 14:14:45 +01:00
|
|
|
int result = real_ACPGetTitleMetaDirByDevice(titleid_upper, titleid_lower, out_buf, size, device);
|
2019-09-06 17:02:09 +02:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2020-06-17 13:45:15 +02:00
|
|
|
DECL_FUNCTION(int32_t, _SYSLaunchTitleByPathFromLauncher, char *pathToLoad, uint32_t u2) {
|
|
|
|
const char *start = "/custom/";
|
|
|
|
if (strncmp(pathToLoad, start, strlen(start)) == 0) {
|
|
|
|
strcpy(template_title.path, pathToLoad);
|
2019-11-24 14:14:45 +01:00
|
|
|
uint64_t titleID = _SYSGetSystemApplicationTitleId(SYSTEM_APP_ID_HEALTH_AND_SAFETY);
|
2020-06-17 13:45:15 +02:00
|
|
|
snprintf(pathToLoad, 47, "/vol/storage_mlc01/sys/title/%08x/%08x", (uint32_t) (titleID >> 32), (uint32_t) (0x00000000FFFFFFFF & titleID));
|
2019-09-08 21:06:53 +02:00
|
|
|
}
|
|
|
|
|
2019-09-06 17:02:09 +02:00
|
|
|
int32_t result = real__SYSLaunchTitleByPathFromLauncher(pathToLoad, strlen(pathToLoad));
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2020-06-17 13:45:15 +02:00
|
|
|
DECL_FUNCTION(int32_t, ACPGetLaunchMetaXml, ACPMetaXml *metaxml) {
|
2019-09-08 21:06:53 +02:00
|
|
|
int result = real_ACPGetLaunchMetaXml(metaxml);
|
2020-06-17 13:45:15 +02:00
|
|
|
if (gHomebrewLaunched) {
|
2019-09-08 21:06:53 +02:00
|
|
|
memcpy(metaxml, &gLaunchXML, sizeof(gLaunchXML));
|
|
|
|
}
|
2019-09-06 17:02:09 +02:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2020-06-17 13:45:15 +02:00
|
|
|
DECL_FUNCTION(uint32_t, ACPGetApplicationBox, uint32_t *u1, uint32_t *u2, uint32_t u3, uint32_t u4) {
|
2020-06-17 14:28:15 +02:00
|
|
|
if (u3 == UPPER_TITLE_ID_HOMEBREW) {
|
2019-11-24 14:14:45 +01:00
|
|
|
uint64_t titleID = _SYSGetSystemApplicationTitleId(SYSTEM_APP_ID_HEALTH_AND_SAFETY);
|
|
|
|
u3 = (uint32_t) (titleID >> 32);
|
|
|
|
u4 = (uint32_t) (0x00000000FFFFFFFF & titleID);
|
2019-09-08 21:06:53 +02:00
|
|
|
}
|
2020-06-17 13:45:15 +02:00
|
|
|
uint32_t result = real_ACPGetApplicationBox(u1, u2, u3, u4);
|
2019-09-12 18:55:49 +02:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2020-06-17 13:45:15 +02:00
|
|
|
DECL_FUNCTION(uint32_t, PatchChkStart__3RplFRCQ3_2nn6drmapp8StartArg, uint32_t *param) {
|
2020-06-17 14:28:15 +02:00
|
|
|
if (param[2] == UPPER_TITLE_ID_HOMEBREW) {
|
2019-11-24 14:14:45 +01:00
|
|
|
uint64_t titleID = _SYSGetSystemApplicationTitleId(SYSTEM_APP_ID_HEALTH_AND_SAFETY);
|
|
|
|
param[2] = (uint32_t) (titleID >> 32);
|
|
|
|
param[3] = (uint32_t) (0x00000000FFFFFFFF & titleID);
|
2019-09-12 18:55:49 +02:00
|
|
|
}
|
2019-11-24 14:14:45 +01:00
|
|
|
uint32_t result = real_PatchChkStart__3RplFRCQ3_2nn6drmapp8StartArg(param);
|
2019-09-12 18:55:49 +02:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2020-06-17 13:45:15 +02:00
|
|
|
DECL_FUNCTION(uint32_t, MCP_RightCheckLaunchable, uint32_t *u1, uint32_t *u2, uint32_t u3, uint32_t u4, uint32_t u5) {
|
2020-06-17 14:28:15 +02:00
|
|
|
if (u3 == UPPER_TITLE_ID_HOMEBREW) {
|
2019-11-24 14:14:45 +01:00
|
|
|
uint64_t titleID = _SYSGetSystemApplicationTitleId(SYSTEM_APP_ID_HEALTH_AND_SAFETY);
|
|
|
|
u3 = (uint32_t) (titleID >> 32);
|
|
|
|
u4 = (uint32_t) (0x00000000FFFFFFFF & titleID);
|
|
|
|
}
|
2020-06-17 13:45:15 +02:00
|
|
|
uint32_t result = real_MCP_RightCheckLaunchable(u1, u2, u3, u4, u5);
|
2019-11-24 14:14:45 +01:00
|
|
|
return result;
|
|
|
|
}
|
2019-09-12 18:55:49 +02:00
|
|
|
|
2020-06-17 13:45:15 +02:00
|
|
|
DECL_FUNCTION(int32_t, HBM_NN_ACP_ACPGetTitleMetaXmlByDevice, uint32_t titleid_upper, uint32_t titleid_lower, ACPMetaXml *metaxml, uint32_t device) {
|
|
|
|
if (gHomebrewLaunched) {
|
2019-11-24 14:14:45 +01:00
|
|
|
memcpy(metaxml, &gLaunchXML, sizeof(gLaunchXML));
|
|
|
|
return 0;
|
2019-09-12 18:55:49 +02:00
|
|
|
}
|
2019-11-24 14:14:45 +01:00
|
|
|
int result = real_HBM_NN_ACP_ACPGetTitleMetaXmlByDevice(titleid_upper, titleid_lower, metaxml, device);
|
2019-09-06 17:02:09 +02:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2020-06-17 22:15:45 +02:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// WUPS_MUST_REPLACE_PHYSICAL(HBM_NN_ACP_ACPGetTitleMetaXmlByDevice, 0x2E36CE44, 0x0E36CE44);
|
2020-06-17 13:45:15 +02:00
|
|
|
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);
|
|
|
|
|
|
|
|
WUPS_MUST_REPLACE(ACPCheckTitleLaunchByTitleListTypeEx, WUPS_LOADER_LIBRARY_NN_ACP, ACPCheckTitleLaunchByTitleListTypeEx);
|
|
|
|
WUPS_MUST_REPLACE(ACPGetTitleMetaXmlByDevice, WUPS_LOADER_LIBRARY_NN_ACP, ACPGetTitleMetaXmlByDevice);
|
|
|
|
WUPS_MUST_REPLACE(ACPGetLaunchMetaXml, WUPS_LOADER_LIBRARY_NN_ACP, ACPGetLaunchMetaXml);
|
|
|
|
WUPS_MUST_REPLACE(ACPGetTitleMetaDirByDevice, WUPS_LOADER_LIBRARY_NN_ACP, ACPGetTitleMetaDirByDevice);
|
|
|
|
WUPS_MUST_REPLACE(_SYSLaunchTitleByPathFromLauncher, WUPS_LOADER_LIBRARY_SYSAPP, _SYSLaunchTitleByPathFromLauncher);
|
2020-06-17 22:15:45 +02:00
|
|
|
WUPS_MUST_REPLACE(ACPGetLaunchMetaData, WUPS_LOADER_LIBRARY_NN_ACP, ACPGetLaunchMetaData);
|