-unfinished modified code for nand emulation, you can now enter the

nand emu view without loading into some cios, only if you boot a game
it will need to reload it (dont even think about it to report bugs yet)
This commit is contained in:
fix94.1 2012-12-22 16:47:02 +00:00
parent 9c4626ab77
commit f6d08052d2
15 changed files with 204 additions and 223 deletions

View File

@ -34,6 +34,7 @@
#include <malloc.h> #include <malloc.h>
#include "banner.h" #include "banner.h"
#include "MD5.h" #include "MD5.h"
#include "nand.hpp"
#include "gecko/gecko.hpp" #include "gecko/gecko.hpp"
#include "loader/fs.h" #include "loader/fs.h"
#include "unzip/U8Archive.h" #include "unzip/U8Archive.h"
@ -162,40 +163,20 @@ u8 *Banner::GetFile(char *name, u32 *size)
return file; return file;
} }
void Banner::GetBanner(u64 title, char *appname, bool isfs, bool imetOnly) void Banner::GetBanner(u64 title, char *appname, bool imetOnly)
{ {
void *buf = NULL; u8 *buf = NULL;
u32 size = 0; u32 size = 0;
if (isfs) s32 len = imetOnly ? sizeof(IMET) + IMET_OFFSET : -1;
{ if(NandHandle.EmulationEnabled())
buf = ISFS_GetFile(appname, &size, imetOnly ? sizeof(IMET) + IMET_OFFSET : 0); buf = NandHandle.GetEmuFile(appname, &size, len);
else
buf = ISFS_GetFile(appname, &size, len);
if(size == 0) if(size == 0)
{ {
if(buf != NULL) if(buf != NULL)
free(buf); free(buf);
return; return;
} }
} SetBanner(buf, size, title);
else
{
FILE *fp = fopen(appname, "rb");
if(fp == NULL)
return;
u32 size = sizeof(IMET) + IMET_OFFSET;
if (!imetOnly)
{
fseek(fp, 0, SEEK_END);
size = ftell(fp);
fseek(fp, 0, SEEK_SET);
}
buf = malloc(size);
if(!buf)
return;
fread(buf, size, 1, fp);
fclose(fp);
}
SetBanner((u8 *)buf, size, title);
} }

View File

@ -70,7 +70,7 @@ class Banner
bool GetName(wchar_t *name, int language); bool GetName(wchar_t *name, int language);
u8 *GetFile(char *name, u32 *size); u8 *GetFile(char *name, u32 *size);
void GetBanner(u64 title, char *appname, bool isfs, bool imetOnly = false); void GetBanner(u64 title, char *appname, bool imetOnly = false);
u8 *GetBannerFile() { return opening; } u8 *GetBannerFile() { return opening; }
u32 GetBannerFileSize() { return opening_size; } u32 GetBannerFileSize() { return opening_size; }
protected: protected:

View File

@ -32,10 +32,12 @@
#include "channel_launcher.h" #include "channel_launcher.h"
#include "channels.h" #include "channels.h"
#include "banner.h" #include "banner.h"
#include "nand.hpp"
#include "config/config.hpp" #include "config/config.hpp"
#include "gecko/gecko.hpp" #include "gecko/gecko.hpp"
#include "gui/text.hpp" #include "gui/text.hpp"
#include "loader/fs.h" #include "loader/fs.h"
#include "loader/sys.h"
#include "memory/mem2.hpp" #include "memory/mem2.hpp"
#include "wstringEx/wstringEx.hpp" #include "wstringEx/wstringEx.hpp"
@ -63,12 +65,16 @@ void Channels::Cleanup()
u8 Channels::GetRequestedIOS(u64 title) u8 Channels::GetRequestedIOS(u64 title)
{ {
u8 IOS = 0; u8 IOS = 0;
u32 size = 0;
u8 *titleTMD = NULL;
if(NANDemuView)
titleTMD = NandHandle.GetTMD(title, &size);
else
{
char tmd[ISFS_MAXPATH] ATTRIBUTE_ALIGN(32); char tmd[ISFS_MAXPATH] ATTRIBUTE_ALIGN(32);
sprintf(tmd, "/title/%08x/%08x/content/title.tmd", TITLE_UPPER(title), TITLE_LOWER(title)); sprintf(tmd, "/title/%08x/%08x/content/title.tmd", TITLE_UPPER(title), TITLE_LOWER(title));
titleTMD = ISFS_GetFile(tmd, &size, -1);
u32 size; }
u8 *titleTMD = (u8 *)ISFS_GetFile(tmd, &size, -1);
if(titleTMD == NULL) if(titleTMD == NULL)
return 0; return 0;
@ -100,15 +106,19 @@ u64 *Channels::GetChannelList(u32 *count)
return titles; return titles;
} }
bool Channels::GetAppNameFromTmd(u64 title, char *app, bool dol, u32 *bootcontent) bool Channels::GetAppNameFromTmd(u64 title, char *app, u32 *bootcontent)
{ {
bool ret = false; bool ret = false;
u32 size = 0;
u8 *data = NULL;
if(NANDemuView)
data = NandHandle.GetTMD(title, &size);
else
{
char tmd[ISFS_MAXPATH] ATTRIBUTE_ALIGN(32); char tmd[ISFS_MAXPATH] ATTRIBUTE_ALIGN(32);
sprintf(tmd, "/title/%08x/%08x/content/title.tmd", TITLE_UPPER(title), TITLE_LOWER(title)); sprintf(tmd, "/title/%08x/%08x/content/title.tmd", TITLE_UPPER(title), TITLE_LOWER(title));
data = ISFS_GetFile(tmd, &size, -1);
u32 size; }
u8 *data = ISFS_GetFile(tmd, &size, -1);
if (data == NULL || size < 0x208) if (data == NULL || size < 0x208)
return ret; return ret;
@ -116,7 +126,7 @@ bool Channels::GetAppNameFromTmd(u64 title, char *app, bool dol, u32 *bootconten
u16 i; u16 i;
for(i = 0; i < tmd_file->num_contents; ++i) for(i = 0; i < tmd_file->num_contents; ++i)
{ {
if(tmd_file->contents[i].index == (dol ? tmd_file->boot_index : 0)) if(tmd_file->contents[i].index == 0)
{ {
*bootcontent = tmd_file->contents[i].cid; *bootcontent = tmd_file->contents[i].cid;
sprintf(app, "/title/%08x/%08x/content/%08x.app", TITLE_UPPER(title), TITLE_LOWER(title), *bootcontent); sprintf(app, "/title/%08x/%08x/content/%08x.app", TITLE_UPPER(title), TITLE_LOWER(title), *bootcontent);
@ -132,15 +142,12 @@ bool Channels::GetAppNameFromTmd(u64 title, char *app, bool dol, u32 *bootconten
void Channels::GetBanner(u64 title, bool imetOnly) void Channels::GetBanner(u64 title, bool imetOnly)
{ {
u32 cid = 0;
CurrentBanner.ClearBanner(); CurrentBanner.ClearBanner();
char app[ISFS_MAXPATH] ATTRIBUTE_ALIGN(32); char app[ISFS_MAXPATH] ATTRIBUTE_ALIGN(32);
u32 cid; if(!GetAppNameFromTmd(title, app, &cid))
if(!GetAppNameFromTmd(title, app, false, &cid))
{
gprintf("No title found for %08x %08x\n", (u32)(title&0xFFFFFFFF),(u32)(title>>32));
return; return;
} CurrentBanner.GetBanner(title, app, imetOnly);
CurrentBanner.GetBanner(title, app, true, imetOnly);
} }
bool Channels::GetChannelNameFromApp(u64 title, wchar_t* name, int language) bool Channels::GetChannelNameFromApp(u64 title, wchar_t* name, int language)
@ -179,7 +186,11 @@ int Channels::GetLanguage(const char *lang)
void Channels::Search() void Channels::Search()
{ {
u32 count; u32 count;
u64 *list = GetChannelList(&count); u64 *list = NULL;
if(NANDemuView)
list = NandHandle.GetChannels(&count);
else
list = GetChannelList(&count);
if(list == NULL) if(list == NULL)
return; return;
@ -190,20 +201,20 @@ void Channels::Search()
u32 Type = TITLE_UPPER(list[i]); u32 Type = TITLE_UPPER(list[i]);
if(Type == SYSTEM_CHANNELS || Type == DOWNLOADED_CHANNELS || Type == GAME_CHANNELS) if(Type == SYSTEM_CHANNELS || Type == DOWNLOADED_CHANNELS || Type == GAME_CHANNELS)
{ {
u32 Title = TITLE_LOWER(list[i]);
if(Title == RF_NEWS_CHANNEL || Title == RF_FORECAST_CHANNEL)
continue; //skip region free news and forecast channel
Channel CurrentChan; Channel CurrentChan;
memset(&CurrentChan, 0, sizeof(Channel)); memset(&CurrentChan, 0, sizeof(Channel));
if(GetChannelNameFromApp(list[i], CurrentChan.name, language)) if(GetChannelNameFromApp(list[i], CurrentChan.name, language))
{ {
u32 Title = TITLE_LOWER(list[i]);
if(Title == RF_NEWS_CHANNEL || Title == RF_FORECAST_CHANNEL)
continue; //skip region free news and forecast channel
CurrentChan.title = list[i]; CurrentChan.title = list[i];
memcpy(CurrentChan.id, &Title, sizeof(CurrentChan.id)); memcpy(CurrentChan.id, &Title, sizeof(CurrentChan.id));
this->push_back(CurrentChan); this->push_back(CurrentChan);
} }
} }
} }
MEM2_free(list); free(list);
} }
wchar_t * Channels::GetName(int index) wchar_t * Channels::GetName(int index)

View File

@ -65,7 +65,7 @@ private:
int GetLanguage(const char *lang); int GetLanguage(const char *lang);
u64* GetChannelList(u32* count); u64* GetChannelList(u32* count);
bool GetAppNameFromTmd(u64 title, char* app, bool dol = false, u32* bootcontent = NULL); bool GetAppNameFromTmd(u64 title, char* app, u32* bootcontent = NULL);
bool GetChannelNameFromApp(u64 title, wchar_t* name, int language); bool GetChannelNameFromApp(u64 title, wchar_t* name, int language);
void Search(); void Search();

View File

@ -39,6 +39,7 @@
#include "identify.h" #include "identify.h"
#include "fileOps/fileOps.h" #include "fileOps/fileOps.h"
#include "gecko/gecko.hpp" #include "gecko/gecko.hpp"
#include "gui/text.hpp"
#include "loader/alt_ios.h" #include "loader/alt_ios.h"
#include "loader/cios.h" #include "loader/cios.h"
#include "loader/fs.h" #include "loader/fs.h"
@ -71,19 +72,16 @@ void Nand::Init()
{ {
MountedDevice = 0; MountedDevice = 0;
EmuDevice = REAL_NAND; EmuDevice = REAL_NAND;
Disabled = true;
AccessPatched = false; AccessPatched = false;
Partition = 0; Partition = 0;
FullMode = 0x100; FullMode = 0x100;
memset(NandPath, 0, sizeof(NandPath)); memset(NandPath, 0, sizeof(NandPath));
} }
void Nand::SetPaths(string path, u32 partition, bool disable) void Nand::SetNANDEmu(u32 partition)
{ {
EmuDevice = disable ? REAL_NAND : partition == 0 ? EMU_SD : EMU_USB; EmuDevice = partition == 0 ? EMU_SD : EMU_USB;
Partition = disable ? REAL_NAND : partition > 0 ? partition - 1 : partition; Partition = partition > 0 ? partition - 1 : partition;
Set_NandPath(path);
Disabled = disable;
} }
s32 Nand::Nand_Mount(NandDevice *Device) s32 Nand::Nand_Mount(NandDevice *Device)
@ -182,17 +180,17 @@ s32 Nand::Enable_Emu()
s32 Nand::Disable_Emu() s32 Nand::Disable_Emu()
{ {
if(MountedDevice == 0 || !emu_enabled) if(MountedDevice == 0 || !emu_enabled)
{
emu_enabled = false;
return 0; return 0;
}
emu_enabled = false;
NandDevice *Device = &NandDeviceList[MountedDevice]; NandDevice *Device = &NandDeviceList[MountedDevice];
Nand_Disable(); Nand_Disable();
Nand_Unmount(Device); Nand_Unmount(Device);
MountedDevice = 0; MountedDevice = 0;
emu_enabled = false;
usleep(1000);
return 0; return 0;
} }
@ -201,21 +199,6 @@ bool Nand::EmulationEnabled(void)
return emu_enabled; return emu_enabled;
} }
void Nand::Set_NandPath(string path)
{
if(isalnum(*(path.begin())))
path.insert(path.begin(), '/');
else
*(path.begin()) = '/';
if(path.size() <= 32)
memcpy(NandPath, path.c_str(), path.size());
else
memset(NandPath, 0, sizeof(NandPath));
gprintf("NandPath = %s\n", NandPath);
}
void Nand::__Dec_Enc_TB(void) void Nand::__Dec_Enc_TB(void)
{ {
u32 key = 0x73B5DBFA; u32 key = 0x73B5DBFA;
@ -815,7 +798,7 @@ void Nand::CreatePath(const char *path, ...)
va_end(args); va_end(args);
} }
void Nand::CreateTitleTMD(const char *path, dir_discHdr *hdr) void Nand::CreateTitleTMD(dir_discHdr *hdr)
{ {
wbfs_disc_t *disc = WBFS_OpenDisc((u8 *)&hdr->id, (char *)hdr->path); wbfs_disc_t *disc = WBFS_OpenDisc((u8 *)&hdr->id, (char *)hdr->path);
if(!disc) if(!disc)
@ -831,14 +814,11 @@ void Nand::CreateTitleTMD(const char *path, dir_discHdr *hdr)
u32 highTID = *(u32*)(titleTMD+0x18c); u32 highTID = *(u32*)(titleTMD+0x18c);
u32 lowTID = *(u32*)(titleTMD+0x190); u32 lowTID = *(u32*)(titleTMD+0x190);
CreatePath("%s/title/%08x/%08x/data", path, highTID, lowTID); CreatePath("%s/title/%08x/%08x/data", FullNANDPath, highTID, lowTID);
CreatePath("%s/title/%08x/%08x/content", path, highTID, lowTID); CreatePath("%s/title/%08x/%08x/content", FullNANDPath, highTID, lowTID);
char nandpath[MAX_FAT_PATH]; char nandpath[MAX_FAT_PATH];
if(path[strlen(path)-1] == '/') snprintf(nandpath, sizeof(nandpath), "%s/title/%08x/%08x/content/title.tmd", FullNANDPath, highTID, lowTID);
snprintf(nandpath, sizeof(nandpath), "%stitle/%08x/%08x/content/title.tmd", path, highTID, lowTID);
else
snprintf(nandpath, sizeof(nandpath), "%s/title/%08x/%08x/content/title.tmd", path, highTID, lowTID);
struct stat filestat; struct stat filestat;
if(stat(nandpath, &filestat) == 0) if(stat(nandpath, &filestat) == 0)
@ -930,41 +910,41 @@ void Nand::ResetCounters(void)
NandDone = 0; NandDone = 0;
} }
s32 Nand::CreateConfig(const char *path) s32 Nand::CreateConfig()
{ {
CreatePath(path); CreatePath(FullNANDPath);
CreatePath("%s/shared2", path); CreatePath("%s/shared2", FullNANDPath);
CreatePath("%s/shared2/sys", path); CreatePath("%s/shared2/sys", FullNANDPath);
CreatePath("%s/title", path); CreatePath("%s/title", FullNANDPath);
CreatePath("%s/title/00000001", path); CreatePath("%s/title/00000001", FullNANDPath);
CreatePath("%s/title/00000001/00000002", path); CreatePath("%s/title/00000001/00000002", FullNANDPath);
CreatePath("%s/title/00000001/00000002/data", path); CreatePath("%s/title/00000001/00000002/data", FullNANDPath);
fake = false; fake = false;
showprogress = false; showprogress = false;
memset(cfgpath, 0, sizeof(cfgpath)); memset(cfgpath, 0, sizeof(cfgpath));
snprintf(cfgpath, sizeof(cfgpath), "%s%s", path, SYSCONFPATH); snprintf(cfgpath, sizeof(cfgpath), "%s%s", FullNANDPath, SYSCONFPATH);
__DumpNandFile(SYSCONFPATH, cfgpath); __DumpNandFile(SYSCONFPATH, cfgpath);
memset(settxtpath, 0, sizeof(settxtpath)); memset(settxtpath, 0, sizeof(settxtpath));
snprintf(settxtpath, sizeof(settxtpath), "%s%s", path, TXTPATH); snprintf(settxtpath, sizeof(settxtpath), "%s%s", FullNANDPath, TXTPATH);
__DumpNandFile(TXTPATH, settxtpath); __DumpNandFile(TXTPATH, settxtpath);
return 0; return 0;
} }
s32 Nand::PreNandCfg(const char *path, bool miis, bool realconfig) s32 Nand::PreNandCfg(bool miis, bool realconfig)
{ {
CreatePath(path); CreatePath(FullNANDPath);
CreatePath("%s/shared2", path); CreatePath("%s/shared2", FullNANDPath);
CreatePath("%s/shared2/sys", path); CreatePath("%s/shared2/sys", FullNANDPath);
CreatePath("%s/shared2/menu", path); CreatePath("%s/shared2/menu", FullNANDPath);
CreatePath("%s/shared2/menu/FaceLib", path); CreatePath("%s/shared2/menu/FaceLib", FullNANDPath);
CreatePath("%s/title", path); CreatePath("%s/title", FullNANDPath);
CreatePath("%s/title/00000001", path); CreatePath("%s/title/00000001", FullNANDPath);
CreatePath("%s/title/00000001/00000002", path); CreatePath("%s/title/00000001/00000002", FullNANDPath);
CreatePath("%s/title/00000001/00000002/data", path); CreatePath("%s/title/00000001/00000002/data", FullNANDPath);
char dest[MAX_FAT_PATH]; char dest[MAX_FAT_PATH];
@ -973,16 +953,15 @@ s32 Nand::PreNandCfg(const char *path, bool miis, bool realconfig)
if(realconfig) if(realconfig)
{ {
snprintf(dest, sizeof(dest), "%s%s", path, SYSCONFPATH); snprintf(dest, sizeof(dest), "%s%s", FullNANDPath, SYSCONFPATH);
__DumpNandFile(SYSCONFPATH, dest); __DumpNandFile(SYSCONFPATH, dest);
snprintf(dest, sizeof(dest), "%s%s", path, TXTPATH); snprintf(dest, sizeof(dest), "%s%s", FullNANDPath, TXTPATH);
__DumpNandFile(TXTPATH, dest); __DumpNandFile(TXTPATH, dest);
} }
if(miis) if(miis)
{ {
snprintf(dest, sizeof(dest), "%s%s", path, MIIPATH); snprintf(dest, sizeof(dest), "%s%s", FullNANDPath, MIIPATH);
__DumpNandFile(MIIPATH, dest); __DumpNandFile(MIIPATH, dest);
} }
return 0; return 0;
@ -1123,6 +1102,76 @@ void Nand::Patch_AHB()
} }
} }
u8 *Nand::GetEmuFile(const char *path, u32 *size, s32 len)
{
u32 filesize = 0;
const char *tmp_path = fmt("%s%s", FullNANDPath, path);
bool ret = fsop_GetFileSizeBytes(tmp_path, &filesize);
if(ret == false || filesize == 0)
return NULL;
if(len > 0)
filesize = min(filesize, (u32)len);
u8 *tmp_buf = (u8*)MEM2_alloc(filesize);
FILE *f = fopen(tmp_path, "rb");
fread(tmp_buf, filesize, 1, f);
fclose(f);
DCFlushRange(tmp_buf, filesize);
*size = filesize;
return tmp_buf;
}
u64 *Nand::GetChannels(u32 *count)
{
u32 size = 0;
u8 *uid_buf = GetEmuFile("/sys/uid.sys", &size);
if(uid_buf == NULL || size == 0)
return NULL;
uid *uid_file = (uid*)uid_buf;
u32 chans = size/sizeof(uid);
u64 *title_buf = (u64*)MEM2_alloc(chans*sizeof(u64));
for(u32 i = 0; i < chans; ++i)
title_buf[i] = uid_file[i].TitleID;
MEM2_free(uid_buf);
DCFlushRange(title_buf, chans);
*count = chans;
return title_buf;
}
u8 *Nand::GetTMD(u64 title, u32 *size)
{
u32 tmd_size = 0;
const char *tmd_path = fmt("/title/%08x/%08x/content/title.tmd",
TITLE_UPPER(title), TITLE_LOWER(title));
u8 *tmd_buf = GetEmuFile(tmd_path, &tmd_size);
*size = tmd_size;
return tmd_buf;
}
void Nand::SetPaths(const char *emuPath, const char *currentPart)
{
memset(&FullNANDPath, 0, sizeof(FullNANDPath));
strcat(FullNANDPath, fmt("%s:", currentPart));
if(emuPath[0] == '\0' || emuPath[0] == ' ')
return;
else if(emuPath[0] != '/' && emuPath[1] != '\0') //missing / before path
strcat(FullNANDPath, "/");
for(u32 i = 0; emuPath[i] != '\0'; i++)
{
if(emuPath[i] == '/' && emuPath[i+1] == '\0')
break;
strncat(FullNANDPath, &emuPath[i], 1);
}
gprintf("Emu NAND Full Path = %s\n", FullNANDPath);
strncpy(NandPath, fmt("/%s", strchr(FullNANDPath, ':') + 1), sizeof(NandPath));
gprintf("IOS Compatible NAND Path = %s\n", NandPath);
}
/* /*
part of miniunz.c part of miniunz.c
Version 1.01e, February 12th, 2005 Version 1.01e, February 12th, 2005

View File

@ -49,6 +49,12 @@ typedef struct _namelist
int type; int type;
} namelist; } namelist;
typedef struct _uid
{
u64 TitleID;
u32 unused;
} __attribute__((packed)) uid;
using namespace std; using namespace std;
class Nand class Nand
@ -57,7 +63,7 @@ public:
void Init(); void Init();
/* Prototypes */ /* Prototypes */
void SetPaths(string path, u32 partition, bool disable = false); void SetNANDEmu(u32 partition);
s32 Enable_Emu(); s32 Enable_Emu();
s32 Disable_Emu(); s32 Disable_Emu();
bool EmulationEnabled(void); bool EmulationEnabled(void);
@ -74,12 +80,16 @@ public:
const char *Get_NandPath(void) { return NandPath; }; const char *Get_NandPath(void) { return NandPath; };
u32 Get_Partition(void) { return Partition; }; u32 Get_Partition(void) { return Partition; };
void Set_NandPath(string path); u64 *GetChannels(u32 *count);
void CreatePath(const char *path, ...); u8 *GetTMD(u64 title, u32 *size);
u8 *GetEmuFile(const char *path, u32 *size, s32 len = -1);
void SetPaths(const char *emuPath, const char *currentPart);
void CreateTitleTMD(const char *path, dir_discHdr *hdr); void CreatePath(const char *path, ...);
s32 CreateConfig(const char *path); void CreateTitleTMD(dir_discHdr *hdr);
s32 PreNandCfg(const char *path, bool miis, bool realconfig); s32 CreateConfig();
s32 PreNandCfg(bool miis, bool realconfig);
s32 Do_Region_Change(string id); s32 Do_Region_Change(string id);
s32 FlashToNAND(const char *source, const char *dest, dump_callback_t i_dumper, void *i_data); s32 FlashToNAND(const char *source, const char *dest, dump_callback_t i_dumper, void *i_data);
s32 DoNandDump(const char *source, const char *dest, dump_callback_t i_dumper, void *i_data); s32 DoNandDump(const char *source, const char *dest, dump_callback_t i_dumper, void *i_data);
@ -123,7 +133,6 @@ private:
u32 FileDone; u32 FileDone;
u32 FilesDone; u32 FilesDone;
u32 FoldersDone; u32 FoldersDone;
bool Disabled;
bool fake; bool fake;
bool showprogress; bool showprogress;
bool AccessPatched; bool AccessPatched;
@ -133,6 +142,7 @@ private:
u32 Partition ATTRIBUTE_ALIGN(32); u32 Partition ATTRIBUTE_ALIGN(32);
u32 FullMode ATTRIBUTE_ALIGN(32); u32 FullMode ATTRIBUTE_ALIGN(32);
char NandPath[32] ATTRIBUTE_ALIGN(32); char NandPath[32] ATTRIBUTE_ALIGN(32);
char FullNANDPath[64] ATTRIBUTE_ALIGN(32);
char cfgpath[1024]; char cfgpath[1024];
char settxtpath[1024]; char settxtpath[1024];
}; };

View File

@ -47,6 +47,7 @@ bool AHBRPOT_Patched(void);
extern void __exception_setreload(int t); extern void __exception_setreload(int t);
extern int mainIOS; extern int mainIOS;
extern bool useMainIOS; extern bool useMainIOS;
extern volatile bool NANDemuView;
extern u8 currentPartition; extern u8 currentPartition;
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -22,11 +22,12 @@
CMenu mainMenu; CMenu mainMenu;
bool useMainIOS = false; bool useMainIOS = false;
volatile bool NANDemuView = false;
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
mainIOS = DOL_MAIN_IOS; mainIOS = DOL_MAIN_IOS;
__exception_setreload(5); __exception_setreload(10);
Gecko_Init(); //USB Gecko and SD/WiFi buffer Gecko_Init(); //USB Gecko and SD/WiFi buffer
gprintf(" \nWelcome to %s!\nThis is the debug output.\n", VERSION_STRING.c_str()); gprintf(" \nWelcome to %s!\nThis is the debug output.\n", VERSION_STRING.c_str());

View File

@ -2222,46 +2222,26 @@ const wstringEx CMenu::_fmt(const char *key, const wchar_t *def)
bool CMenu::_loadChannelList(void) bool CMenu::_loadChannelList(void)
{ {
string emuPath; string emuPath;
string cacheDir;
int emuPartition = -1; int emuPartition = -1;
NANDemuView = (!neek2o() && m_cfg.getBool(CHANNEL_DOMAIN, "disable", true) == false);
bool disable_emu = (m_cfg.getBool(CHANNEL_DOMAIN, "disable", true) || neek2o()); if(NANDemuView)
if(!disable_emu)
{ {
m_partRequest = m_cfg.getInt(CHANNEL_DOMAIN, "partition", 1); m_partRequest = m_cfg.getInt(CHANNEL_DOMAIN, "partition", 1);
emuPartition = _FindEmuPart(&emuPath, m_partRequest, false); emuPartition = _FindEmuPart(&emuPath, m_partRequest, false);
if(emuPartition < 0) if(emuPartition < 0)
emuPartition = _FindEmuPart(&emuPath, m_partRequest, true); emuPartition = _FindEmuPart(&emuPath, m_partRequest, true);
if(emuPartition < 0) if(emuPartition < 0)
return false; return false;
else
currentPartition = emuPartition; currentPartition = emuPartition;
} NandHandle.SetNANDEmu(currentPartition); /* Init NAND Emu */
NandHandle.SetPaths(emuPath.c_str(), DeviceName[currentPartition]);
if(!disable_emu) NandHandle.PreNandCfg(m_cfg.getBool(CHANNEL_DOMAIN, "real_nand_miis", false),
{ m_cfg.getBool(CHANNEL_DOMAIN, "real_nand_config", false));
char basepath[64];
snprintf(basepath, sizeof(basepath), "%s:%s", DeviceName[currentPartition], emuPath.c_str());
NandHandle.PreNandCfg(basepath, m_cfg.getBool(CHANNEL_DOMAIN, "real_nand_miis", false), m_cfg.getBool(CHANNEL_DOMAIN, "real_nand_config", false));
}
NandHandle.Disable_Emu();
if(!disable_emu)
{
MusicPlayer.Stop();
TempLoadIOS();
DeviceHandle.UnMount(currentPartition);
NandHandle.SetPaths(emuPath.c_str(), currentPartition, disable_emu);
if(NandHandle.Enable_Emu() < 0)
NandHandle.Disable_Emu();
}
if(!DeviceHandle.IsInserted(currentPartition))
DeviceHandle.Mount(currentPartition);
string cacheDir;
if(!disable_emu)
cacheDir = fmt("%s/%s_channels.db", m_listCacheDir.c_str(), DeviceName[currentPartition]); cacheDir = fmt("%s/%s_channels.db", m_listCacheDir.c_str(), DeviceName[currentPartition]);
}
bool updateCache = m_cfg.getBool(_domainFromView(), "update_cache"); bool updateCache = m_cfg.getBool(_domainFromView(), "update_cache");
vector<string> NullVector; vector<string> NullVector;
m_gameList.CreateList(m_current_view, currentPartition, std::string(), m_gameList.CreateList(m_current_view, currentPartition, std::string(),
@ -2272,13 +2252,7 @@ bool CMenu::_loadChannelList(void)
bool CMenu::_loadList(void) bool CMenu::_loadList(void)
{ {
CoverFlow.clear(); CoverFlow.clear();
if((m_current_view == COVERFLOW_CHANNEL && m_cfg.getBool(CHANNEL_DOMAIN, "disable", true)) NANDemuView = false;
|| (m_current_view != COVERFLOW_CHANNEL && NandHandle.EmulationEnabled()))
{
MusicPlayer.Stop();
NandHandle.Disable_Emu();
TempLoadIOS(IOS_TYPE_NORMAL_IOS);
}
gprintf("Switching View to %s\n", _domainFromView()); gprintf("Switching View to %s\n", _domainFromView());
bool retval; bool retval;

View File

@ -207,19 +207,12 @@ int CMenu::_config1(void)
} }
} }
} }
if(currentPartition != bCurrentPartition) if(currentPartition != bCurrentPartition)
{
bool disable = (m_cfg.getBool(CHANNEL_DOMAIN, "disable", true) || neek2o())
&& m_current_view == COVERFLOW_CHANNEL && !m_tempView;
if(!disable)
{ {
_showWaitMessage(); _showWaitMessage();
_loadList(); _loadList();
_hideWaitMessage(); _hideWaitMessage();
} }
}
_hideConfig(); _hideConfig();
return change; return change;

View File

@ -74,7 +74,6 @@ void CMenu::_showConfig4(void)
wstringEx channelName = m_loc.getWString(m_curLanguage, "disabled", L"Disabled"); wstringEx channelName = m_loc.getWString(m_curLanguage, "disabled", L"Disabled");
NandHandle.Disable_Emu();
ChannelHandle.Init(m_loc.getString(m_curLanguage, "gametdb_code", "EN")); ChannelHandle.Init(m_loc.getString(m_curLanguage, "gametdb_code", "EN"));
amountOfChannels = ChannelHandle.Count(); amountOfChannels = ChannelHandle.Count();
@ -143,8 +142,6 @@ int CMenu::_config4(void)
} }
} }
} }
if(!neek2o() && m_current_view == COVERFLOW_CHANNEL && m_cfg.getBool(CHANNEL_DOMAIN, "disable", true) == false)
NandHandle.Enable_Emu();
_hideConfig4(); _hideConfig4();
return change; return change;
} }

View File

@ -427,7 +427,6 @@ s32 CMenu::_networkComplete(s32 ok, void *usrData)
int CMenu::_initNetwork() int CMenu::_initNetwork()
{ {
NandHandle.Disable_Emu();
while (net_get_status() == -EBUSY || m_thrdNetwork) {}; // Async initialization may be busy, wait to see if it succeeds. while (net_get_status() == -EBUSY || m_thrdNetwork) {}; // Async initialization may be busy, wait to see if it succeeds.
if (m_networkInit) return 0; if (m_networkInit) return 0;
if (!_isNetworkAvailable()) return -2; if (!_isNetworkAvailable()) return -2;

View File

@ -765,8 +765,6 @@ void CMenu::directlaunch(const char *GameID)
void CMenu::_launch(dir_discHdr *hdr) void CMenu::_launch(dir_discHdr *hdr)
{ {
/* No need to do that separate */
NandHandle.Disable_Emu();
/* Lets boot that shit */ /* Lets boot that shit */
if(hdr->type == TYPE_WII_GAME) if(hdr->type == TYPE_WII_GAME)
_launchGame(hdr, false); _launchGame(hdr, false);
@ -1090,15 +1088,12 @@ void CMenu::_launchChannel(dir_discHdr *hdr)
ShutdownBeforeExit(); ShutdownBeforeExit();
Launch_nk(gameTitle, emuPath.size() > 1 ? emuPath.c_str() : NULL, Launch_nk(gameTitle, emuPath.size() > 1 ? emuPath.c_str() : NULL,
returnTo ? (((u64)(0x00010001) << 32) | (returnTo & 0xFFFFFFFF)) : 0); returnTo ? (((u64)(0x00010001) << 32) | (returnTo & 0xFFFFFFFF)) : 0);
while(1); while(1) usleep(500);
} }
DeviceHandle.UnMount(emuPartition); NandHandle.SetPaths(emuPath.c_str(), DeviceName[emuPartition]);
NandHandle.SetPaths(emuPath.c_str(), emuPartition, false); NANDemuView = true;
NandHandle.Enable_Emu();
} }
gameIOS = ChannelHandle.GetRequestedIOS(gameTitle); gameIOS = ChannelHandle.GetRequestedIOS(gameTitle);
if(NAND_Emu && !neek2o())
NandHandle.Disable_Emu();
if(_loadIOS(gameIOS, userIOS, id, !NAND_Emu) == LOAD_IOS_FAILED) if(_loadIOS(gameIOS, userIOS, id, !NAND_Emu) == LOAD_IOS_FAILED)
Sys_Exit(); Sys_Exit();
if((CurrentIOS.Type == IOS_TYPE_D2X || neek2o()) && returnTo != 0) if((CurrentIOS.Type == IOS_TYPE_D2X || neek2o()) && returnTo != 0)
@ -1108,7 +1103,6 @@ void CMenu::_launchChannel(dir_discHdr *hdr)
} }
if(NAND_Emu && !neek2o()) if(NAND_Emu && !neek2o())
{ {
NandHandle.SetPaths(emuPath.c_str(), emuPartition, false);
if(emulate_mode == 1) if(emulate_mode == 1)
NandHandle.Set_FullMode(true); NandHandle.Set_FullMode(true);
else else
@ -1264,14 +1258,10 @@ void CMenu::_launchGame(dir_discHdr *hdr, bool dvd)
NandHandle.CreatePath("%s:/wiiflow/nandemu", DeviceName[emuPartition]); NandHandle.CreatePath("%s:/wiiflow/nandemu", DeviceName[emuPartition]);
} }
} }
m_cfg.setInt(WII_DOMAIN, "savepartition", emuPartition); m_cfg.setInt(WII_DOMAIN, "savepartition", emuPartition);
m_cfg.setString(WII_DOMAIN, "savepath", emuPath); m_cfg.setString(WII_DOMAIN, "savepath", emuPath);
m_cfg.save(); m_cfg.save();
char basepath[64];
snprintf(basepath, sizeof(basepath), "%s:%s", DeviceName[emuPartition], emuPath.c_str());
if(emulate_mode == 2 || emulate_mode > 3) if(emulate_mode == 2 || emulate_mode > 3)
{ {
if(emulate_mode == 2) if(emulate_mode == 2)
@ -1279,13 +1269,13 @@ void CMenu::_launchGame(dir_discHdr *hdr, bool dvd)
m_forceext = false; m_forceext = false;
_hideWaitMessage(); _hideWaitMessage();
if(!_AutoExtractSave(id)) if(!_AutoExtractSave(id))
NandHandle.CreateTitleTMD(basepath, hdr); NandHandle.CreateTitleTMD(hdr);
_showWaitMessage(); _showWaitMessage();
} }
} }
if(emulate_mode > 2) if(emulate_mode > 2)
{ {
NandHandle.CreateConfig(basepath); NandHandle.CreateConfig();
NandHandle.Do_Region_Change(id); NandHandle.Do_Region_Change(id);
} }
} }
@ -1338,9 +1328,9 @@ void CMenu::_launchGame(dir_discHdr *hdr, bool dvd)
} }
if(emulate_mode && !neek2o() && CurrentIOS.Type == IOS_TYPE_D2X) if(emulate_mode && !neek2o() && CurrentIOS.Type == IOS_TYPE_D2X)
{ {
NandHandle.SetPaths(emuPath.c_str(), emuPartition, false); NANDemuView = true;
NandHandle.SetPaths(emuPath.c_str(), DeviceName[emuPartition]);
DeviceHandle.UnMount(emuPartition); DeviceHandle.UnMount(emuPartition);
if(emulate_mode == 3) if(emulate_mode == 3)
NandHandle.Set_RCMode(true); NandHandle.Set_RCMode(true);
else if(emulate_mode == 4) else if(emulate_mode == 4)
@ -1353,8 +1343,6 @@ void CMenu::_launchGame(dir_discHdr *hdr, bool dvd)
error(_t("errgame6", L"Enabling emu after reload failed!")); error(_t("errgame6", L"Enabling emu after reload failed!"));
Sys_Exit(); Sys_Exit();
} }
if(!DeviceHandle.IsInserted(currentPartition))
DeviceHandle.Mount(currentPartition);
DeviceHandle.Mount(emuPartition); DeviceHandle.Mount(emuPartition);
} }
bool wbfs_partition = false; bool wbfs_partition = false;

View File

@ -150,10 +150,8 @@ void CMenu::_showMain(void)
m_btnMgr.show(m_mainLblInit); m_btnMgr.show(m_mainLblInit);
break; break;
case COVERFLOW_CHANNEL: case COVERFLOW_CHANNEL:
if(!m_cfg.getBool(CHANNEL_DOMAIN, "disable", true)) if(NANDemuView)
{ {
NandHandle.Disable_Emu();
DeviceHandle.MountAll();
_hideMain(); _hideMain();
if(!_AutoCreateNand()) if(!_AutoCreateNand())
m_cfg.setBool(CHANNEL_DOMAIN, "disable", true); m_cfg.setBool(CHANNEL_DOMAIN, "disable", true);
@ -174,8 +172,6 @@ void CMenu::_showMain(void)
break; break;
} }
} }
else if(!neek2o() && m_current_view == COVERFLOW_CHANNEL && !m_cfg.getBool(CHANNEL_DOMAIN, "disable", true))
NandHandle.Enable_Emu();
} }
void CMenu::LoadView(void) void CMenu::LoadView(void)
@ -403,7 +399,6 @@ int CMenu::main(void)
_showWaitMessage(); _showWaitMessage();
m_gameSound.Stop(); m_gameSound.Stop();
CheckGameSoundThread(); CheckGameSoundThread();
NandHandle.Disable_Emu();
/* Create Fake Header */ /* Create Fake Header */
dir_discHdr hdr; dir_discHdr hdr;
memset(&hdr, 0, sizeof(dir_discHdr)); memset(&hdr, 0, sizeof(dir_discHdr));
@ -1043,15 +1038,9 @@ wstringEx CMenu::_getNoticeTranslation(int sorting, wstringEx curLetter)
void CMenu::_setPartition(s8 direction) void CMenu::_setPartition(s8 direction)
{ {
_cfNeedsUpdate(); if(m_current_view == COVERFLOW_CHANNEL && NANDemuView == false)
bool disable = m_current_view == COVERFLOW_CHANNEL && !m_tempView &&
(m_cfg.getBool(CHANNEL_DOMAIN, "disable", true) || neek2o());
if(disable)
return; return;
_cfNeedsUpdate();
if(m_current_view == COVERFLOW_CHANNEL)
NandHandle.Enable_Emu();
if(direction != 0) if(direction != 0)
{ {
u8 limiter = 0; u8 limiter = 0;

View File

@ -92,8 +92,6 @@ bool CMenu::_TestEmuNand(int epart, const char *path, bool indept)
int CMenu::_FindEmuPart(string *emuPath, int part, bool searchvalid) int CMenu::_FindEmuPart(string *emuPath, int part, bool searchvalid)
{ {
NandHandle.Disable_Emu();
int emuPartition = -1; int emuPartition = -1;
string tmpPath; string tmpPath;
if(m_current_view == COVERFLOW_CHANNEL) if(m_current_view == COVERFLOW_CHANNEL)
@ -118,10 +116,6 @@ int CMenu::_FindEmuPart(string *emuPath, int part, bool searchvalid)
tmpPath = m_cfg.getString(WII_DOMAIN, "savepath", STDEMU_DIR); tmpPath = m_cfg.getString(WII_DOMAIN, "savepath", STDEMU_DIR);
} }
} }
if(!DeviceHandle.IsInserted(emuPartition))
DeviceHandle.Mount(emuPartition);
if(_TestEmuNand(emuPartition, tmpPath.c_str(), true) && DeviceHandle.PartitionUsableForNandEmu(emuPartition)) if(_TestEmuNand(emuPartition, tmpPath.c_str(), true) && DeviceHandle.PartitionUsableForNandEmu(emuPartition))
{ {
*emuPath = tmpPath; *emuPath = tmpPath;
@ -132,12 +126,8 @@ int CMenu::_FindEmuPart(string *emuPath, int part, bool searchvalid)
bool fllscn = emuPartition == -1; bool fllscn = emuPartition == -1;
for(u8 i = part; i <= USB8; ++i) for(u8 i = part; i <= USB8; ++i)
{ {
if(!DeviceHandle.IsInserted(i))
DeviceHandle.Mount(i);
if(!DeviceHandle.PartitionUsableForNandEmu(i)) if(!DeviceHandle.PartitionUsableForNandEmu(i))
continue; continue;
if(_TestEmuNand(i, tmpPath.c_str(), true) || searchvalid) if(_TestEmuNand(i, tmpPath.c_str(), true) || searchvalid)
{ {
if(m_current_view == COVERFLOW_CHANNEL) if(m_current_view == COVERFLOW_CHANNEL)
@ -150,7 +140,6 @@ int CMenu::_FindEmuPart(string *emuPath, int part, bool searchvalid)
return i; return i;
} }
if(i == USB8 && !fllscn) if(i == USB8 && !fllscn)
{ {
i = -1; i = -1;
@ -158,7 +147,6 @@ int CMenu::_FindEmuPart(string *emuPath, int part, bool searchvalid)
} }
} }
} }
return -1; return -1;
} }