diff --git a/Makefile b/Makefile index bfa6dc5f..09770497 100644 --- a/Makefile +++ b/Makefile @@ -123,6 +123,7 @@ export OFILES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) \ $(JPGFILES:.jpg=.jpg.o) $(PNGFILES:.png=.png.o) $(DOLFILES:.dol=.dol.o) \ $(OGGFILES:.ogg=.ogg.o) $(WAVFILES:.wav=.wav.o) $(MP3FILES:.mp3=.mp3.o) \ $(ELFFILES:.elf=.elf.o) $(BINFILES:.bin=.bin.o) $(TXTFILES:.txt=.txt.o) \ + $(CURDIR)/data/magic_patcher.o #--------------------------------------------------------------------------------- # build a list of include paths diff --git a/data/magic_patcher.o b/data/magic_patcher.o new file mode 100644 index 00000000..a7de9a03 Binary files /dev/null and b/data/magic_patcher.o differ diff --git a/source/channel/channel_launcher.cpp b/source/channel/channel_launcher.cpp index eae09811..f5812fad 100644 --- a/source/channel/channel_launcher.cpp +++ b/source/channel/channel_launcher.cpp @@ -11,6 +11,7 @@ #include "loader/fs.h" #include "loader/fst.h" #include "loader/utils.h" +#include "memory/memory.h" #include "unzip/lz77.h" #include "types.h" @@ -33,16 +34,16 @@ u32 dolchunkcount; s32 BootChannel(u32 entry, u64 chantitle, u32 ios, u8 vidMode, bool vipatch, bool countryString, u8 patchVidMode, int aspectRatio) { - // IOS Version Check - *(vu32*)0x80003140 = ((ios << 16)) | 0xFFFF; - *(vu32*)0x80003188 = ((ios << 16)) | 0xFFFF; - DCFlushRange((void *)0x80003140, 4); - DCFlushRange((void *)0x80003188, 4); + // IOS Version Check + *Real_IOSVersion = ((ios << 16)) | 0xFFFF; + *Game_IOSVersion = ((ios << 16)) | 0xFFFF; + DCFlushRange((void*)Real_IOSVersion, 4); + DCFlushRange((void*)Game_IOSVersion, 4); - // Game ID Online Check - memset((void *)0x80000000, 0, 4); - *(vu32 *)0x80000000 = TITLE_LOWER(chantitle); - DCFlushRange((void *)0x80000000, 4); + // Game ID Online Check + memset((void*)Disc_ID, 0, 4); + *Disc_ID = TITLE_LOWER(chantitle); + DCFlushRange((void*)Disc_ID, 4); ExternalBooter_ChannelSetup(dolchunkoffset, dolchunksize, dolchunkcount, entry); WiiFlow_ExternalBooter(vidMode, vipatch, countryString, patchVidMode, aspectRatio, 0, TYPE_CHANNEL); diff --git a/source/channel/nand.cpp b/source/channel/nand.cpp index 28bc837c..575060c3 100644 --- a/source/channel/nand.cpp +++ b/source/channel/nand.cpp @@ -26,7 +26,7 @@ * Nand/Emulation Handling Class for Wiiflow * ***************************************************************************/ - +#include #include #include #include @@ -39,6 +39,7 @@ #include "fileOps/fileOps.h" #include "gecko/gecko.h" #include "loader/wbfs.h" +#include "memory/memory.h" u8 *confbuffer ATTRIBUTE_ALIGN(32); u8 CCode[0x1008]; @@ -1035,3 +1036,52 @@ s32 Nand::Do_Region_Change(string id) __configwrite(); return 1; } + +extern "C" { extern s32 MagicPatches(s32); } + +void Nand::Init_ISFS() +{ + gprintf("Init ISFS\n"); + ISFS_Initialize(); + if(*HW_AHBPROT == 0xFFFFFFFF) //AHBPROT patched out + { + PatchAHB(); + MagicPatches(1); + } +} + +void Nand::DeInit_ISFS() +{ + gprintf("Deinit ISFS\n"); + ISFS_Deinitialize(); + if(*HW_AHBPROT == 0xFFFFFFFF) //AHBPROT patched out + MagicPatches(0); +} + +/* Thanks to postloader for that patch */ +#define ES_MODULE_START (u16*)0x939F0000 + +static const u16 ticket_check[] = { + 0x685B, // ldr r3,[r3,#4] ; get TMD pointer + 0x22EC, 0x0052, // movls r2, 0x1D8 + 0x189B, // adds r3, r3, r2; add offset of access rights field in TMD + 0x681B, // ldr r3, [r3] ; load access rights (haxxme!) + 0x4698, // mov r8, r3 ; store it for the DVD video bitcheck later + 0x07DB // lsls r3, r3, #31; check AHBPROT bit +}; + +void Nand::PatchAHB() +{ + // Disable memory protection + write16(MEM_PROT, 2); + for(u16 *patchme = ES_MODULE_START; patchme < ES_MODULE_START + 0x4000; patchme++) + { + if(!memcmp(patchme, ticket_check, sizeof(ticket_check))) + { + // write16/uncached poke doesn't work for this. Go figure. + patchme[4] = 0x23FF; // li r3, 0xFF + DCFlushRange(patchme + 4, 2); + break; + } + } +} diff --git a/source/channel/nand.hpp b/source/channel/nand.hpp index 3dbbff76..9300db62 100644 --- a/source/channel/nand.hpp +++ b/source/channel/nand.hpp @@ -53,82 +53,85 @@ using namespace std; class Nand { - public: - static Nand * Instance(); - static void DestroyInstance(); +public: + static Nand * Instance(); + static void DestroyInstance(); - /* Prototypes */ - void Init(string path, u32 partition, bool disable = false); - s32 Enable_Emu(); - s32 Disable_Emu(); + /* Prototypes */ + void Init(string path, u32 partition, bool disable = false); + s32 Enable_Emu(); + s32 Disable_Emu(); - void Set_Partition(u32 partition) { Partition = partition; }; - void Set_FullMode(bool fullmode) { FullMode = fullmode ? 0x100 : 0; }; - void Set_RCMode(bool rcmode) { FullMode = rcmode ? 0x40 : 0; }; - void Set_SSMode(bool ssmode) { FullMode = ssmode ? 0x60 : 0; }; + void Set_Partition(u32 partition) { Partition = partition; }; + void Set_FullMode(bool fullmode) { FullMode = fullmode ? 0x100 : 0; }; + void Set_RCMode(bool rcmode) { FullMode = rcmode ? 0x40 : 0; }; + void Set_SSMode(bool ssmode) { FullMode = ssmode ? 0x60 : 0; }; + void Init_ISFS(); + void DeInit_ISFS(); - const char * Get_NandPath(void) { return NandPath; }; - u32 Get_Partition(void) { return Partition; }; + const char * Get_NandPath(void) { return NandPath; }; + u32 Get_Partition(void) { return Partition; }; - void Set_NandPath(string path); - void CreatePath(const char *path, ...); - - void CreateTitleTMD(const char *path, dir_discHdr *hdr); - s32 CreateConfig(const char *path); - s32 PreNandCfg(const char *path, bool miis, bool realconfig); - s32 Do_Region_Change(string id); - 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 CalcFlashSize(const char *source, dump_callback_t i_dumper, void *i_data); - s32 CalcDumpSpace(const char *source, dump_callback_t i_dumper, void *i_data); - void ResetCounters(void); + void Set_NandPath(string path); + void CreatePath(const char *path, ...); + + void CreateTitleTMD(const char *path, dir_discHdr *hdr); + s32 CreateConfig(const char *path); + s32 PreNandCfg(const char *path, bool miis, bool realconfig); + s32 Do_Region_Change(string id); + 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 CalcFlashSize(const char *source, dump_callback_t i_dumper, void *i_data); + s32 CalcDumpSpace(const char *source, dump_callback_t i_dumper, void *i_data); + void ResetCounters(void); + +private: + Nand() : MountedDevice(0), EmuDevice(REAL_NAND), Disabled(true), Partition(0), FullMode(0x100), NandPath() {} + ~Nand(void){} + + /* Prototypes */ + s32 Nand_Mount(NandDevice *Device); + s32 Nand_Unmount(NandDevice *Device); + s32 Nand_Enable(NandDevice *Device); + s32 Nand_Disable(void); + void PatchAHB(void); + void __Dec_Enc_TB(void); + void __configshifttxt(char *str); + void __GetNameList(const char *source, namelist **entries, int *count); + s32 __configread(void); + s32 __configwrite(void); + u32 __configsetbyte(const char *item, u8 val); + u32 __configsetbigarray(const char *item, void *val, u32 size); + u32 __configsetsetting(const char *item, const char *val); + void __NANDify(char *str); + void __FATify(char *dst, const char *src); + s32 __Unescaped2x(const char *path); + s32 __FlashNandFile(const char *source, const char *dest); + s32 __FlashNandFolder(const char *source, const char *dest); + s32 __DumpNandFile(const char *source, const char *dest); + s32 __DumpNandFolder(const char *source, const char *dest); + + u32 MountedDevice; + u32 EmuDevice; + u32 NandSize; + u32 NandDone; + u32 FileDone; + u32 FilesDone; + u32 FoldersDone; + bool Disabled; + bool fake; + bool showprogress; - private: - Nand() : MountedDevice(0), EmuDevice(REAL_NAND), Disabled(true), Partition(0), FullMode(0x100), NandPath() {} - ~Nand(void){} + void *data; + dump_callback_t dumper; + u32 Partition ATTRIBUTE_ALIGN(32); + u32 FullMode ATTRIBUTE_ALIGN(32); + char NandPath[32] ATTRIBUTE_ALIGN(32); + char cfgpath[1024]; + char settxtpath[1024]; - /* Prototypes */ - s32 Nand_Mount(NandDevice *Device); - s32 Nand_Unmount(NandDevice *Device); - s32 Nand_Enable(NandDevice *Device); - s32 Nand_Disable(void); - void __Dec_Enc_TB(void); - void __configshifttxt(char *str); - void __GetNameList(const char *source, namelist **entries, int *count); - s32 __configread(void); - s32 __configwrite(void); - u32 __configsetbyte(const char *item, u8 val); - u32 __configsetbigarray(const char *item, void *val, u32 size); - u32 __configsetsetting(const char *item, const char *val); - void __NANDify(char *str); - void __FATify(char *dst, const char *src); - s32 __Unescaped2x(const char *path); - s32 __FlashNandFile(const char *source, const char *dest); - s32 __FlashNandFolder(const char *source, const char *dest); - s32 __DumpNandFile(const char *source, const char *dest); - s32 __DumpNandFolder(const char *source, const char *dest); - - u32 MountedDevice; - u32 EmuDevice; - u32 NandSize; - u32 NandDone; - u32 FileDone; - u32 FilesDone; - u32 FoldersDone; - bool Disabled; - bool fake; - bool showprogress; - - void *data; - dump_callback_t dumper; - u32 Partition ATTRIBUTE_ALIGN(32); - u32 FullMode ATTRIBUTE_ALIGN(32); - char NandPath[32] ATTRIBUTE_ALIGN(32); - char cfgpath[1024]; - char settxtpath[1024]; - - static Nand * instance; + static Nand * instance; }; #endif diff --git a/source/gui/video.cpp b/source/gui/video.cpp index 0b40961a..ebb07ce6 100644 --- a/source/gui/video.cpp +++ b/source/gui/video.cpp @@ -257,10 +257,12 @@ void CVideo::cleanup(void) { gprintf("Cleaning up video...\n"); + hideWaitMessage(); _clearScreen(); + VIDEO_SetBlack(TRUE); VIDEO_Flush(); - hideWaitMessage(); + GX_DrawDone(); GX_AbortFrame(); diff --git a/source/loader/alt_ios.cpp b/source/loader/alt_ios.cpp index 92ce2add..35dde7bf 100644 --- a/source/loader/alt_ios.cpp +++ b/source/loader/alt_ios.cpp @@ -8,10 +8,12 @@ #include "sys.h" #include "wbfs.h" #include "wdvd.h" +#include "channel/nand.hpp" #include "devicemounter/DeviceHandler.hpp" #include "devicemounter/usbstorage.h" #include "gecko/gecko.h" #include "memory/mem2.hpp" +#include "memory/memory.h" #include "types.h" // mload from uloader by Hermes @@ -21,12 +23,9 @@ #include "odip_frag.h" #include "mload_modules.h" -extern "C" {extern u8 currentPartition;} -extern int __Arena2Lo; +extern "C" { extern u8 currentPartition; } u8 use_port1 = 0; -#define HAVE_AHBPROT ((*(vu32*)0xcd800064 == 0xFFFFFFFF) ? 1 : 0) - static int load_ehc_module_ex(void) { ehcmodule = ehcmodule_5; @@ -79,36 +78,6 @@ void load_dip_249() mload_close(); } -/* Thanks to postloader for that patch */ -#define MEM2_PROT 0x0D8B420A -#define ES_MODULE_START (u16*)0x939F0000 - -static const u16 ticket_check[] = { - 0x685B, // ldr r3,[r3,#4] ; get TMD pointer - 0x22EC, 0x0052, // movls r2, 0x1D8 - 0x189B, // adds r3, r3, r2; add offset of access rights field in TMD - 0x681B, // ldr r3, [r3] ; load access rights (haxxme!) - 0x4698, // mov r8, r3 ; store it for the DVD video bitcheck later - 0x07DB // lsls r3, r3, #31; check AHBPROT bit -}; - -static void PatchAHB() -{ - // Disable memory protection - write16(MEM2_PROT, 2); - - for(u16 *patchme = ES_MODULE_START; patchme < ES_MODULE_START + 0x4000; patchme++) - { - if(!memcmp(patchme, ticket_check, sizeof(ticket_check))) - { - // write16/uncached poke doesn't work for this. Go figure. - patchme[4] = 0x23FF; // li r3, 0xFF - DCFlushRange(patchme + 4, 2); - break; - } - } -} - bool loadIOS(int ios, bool launch_game, bool emu_channel) { #ifndef DOLPHIN @@ -119,12 +88,10 @@ bool loadIOS(int ios, bool launch_game, bool emu_channel) mload_close(); gprintf("Reloading into IOS %i from %i...\n", ios, IOS_GetVersion()); - if(HAVE_AHBPROT && ios == 58) //IOS58 with AHBPROT patched out for Homebrew - PatchAHB(); - - ISFS_Deinitialize(); + Nand::Instance()->DeInit_ISFS(); bool iosOK = IOS_ReloadIOS(ios) == 0; - ISFS_Initialize(); + Nand::Instance()->Init_ISFS(); + gprintf("AHBPROT after IOS Reload: %u\n", (*HW_AHBPROT == 0xFFFFFFFF)); IOS_GetCurrentIOSInfo(); if(CurrentIOS.Type == IOS_TYPE_HERMES) @@ -132,7 +99,6 @@ bool loadIOS(int ios, bool launch_game, bool emu_channel) else if(CurrentIOS.Type == IOS_TYPE_WANIN && CurrentIOS.Revision >= 18) load_dip_249(); - gprintf("AHBPROT after IOS Reload: %u\n", HAVE_AHBPROT); if(!emu_channel) { if(launch_game) diff --git a/source/loader/nk.c b/source/loader/nk.c index 6441889f..3bcc7aea 100644 --- a/source/loader/nk.c +++ b/source/loader/nk.c @@ -41,7 +41,6 @@ bool neek2o(void) if(!checked) { u32 num = 0; - ISFS_Initialize(); neek = !(ISFS_ReadDir("/sneek", NULL, &num)); gprintf("WiiFlow is in %s mode\n", neek ? "neek2o" : "real nand"); checked = true; diff --git a/source/main.cpp b/source/main.cpp index e98edb1f..7f259189 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -23,7 +23,7 @@ CMenu *mainMenu; extern "C" -{ +{ extern void __exception_setreload(int t); extern int mainIOS; } @@ -37,6 +37,7 @@ int main(int argc, char **argv) CVideo vid; vid.init(); + Nand::Instance()->Init_ISFS(); MEM2_init(47); //Should be safe to use vid.waitMessage(0.15f); @@ -147,9 +148,7 @@ int main(int argc, char **argv) } } mainMenu->cleanup(); -#ifndef DOLPHIN - ISFS_Deinitialize(); -#endif + Nand::Instance()->DeInit_ISFS(); Sys_Exit(); exit(1); return 0; diff --git a/source/memory/memory.h b/source/memory/memory.h index 7f6f4e75..9864443a 100644 --- a/source/memory/memory.h +++ b/source/memory/memory.h @@ -6,30 +6,35 @@ extern "C" { #endif -#define Disc_ID ((vu32*)0x80000000) -#define Disc_Region ((vu32*)0x80000003) -#define Disc_Magic ((vu32*)0x80000018) -#define Sys_Magic ((vu32*)0x80000020) -#define Sys_Version ((vu32*)0x80000024) -#define Mem_Size ((vu32*)0x80000028) -#define Board_Model ((vu32*)0x8000002C) -#define Arena_L ((vu32*)0x80000030) -#define Arena_H ((vu32*)0x80000034) -#define FST ((vu32*)0x80000038) -#define Max_FST ((vu32*)0x8000003C) -#define Assembler ((vu32*)0x80000060) -#define Video_Mode ((vu32*)0x800000CC) -#define Dev_Debugger ((vu32*)0x800000EC) -#define Simulated_Mem ((vu32*)0x800000F0) -#define BI2 ((vu32*)0x800000F4) -#define Bus_Speed ((vu32*)0x800000F8) -#define CPU_Speed ((vu32*)0x800000FC) -#define Online_Check ((vu32*)0x80003180) -#define GameID_Address ((vu32*)0x80003184) +#define Disc_ID ((vu32*)0x80000000) +#define Disc_Region ((vu32*)0x80000003) +#define Disc_Magic ((vu32*)0x80000018) +#define Sys_Magic ((vu32*)0x80000020) +#define Sys_Version ((vu32*)0x80000024) +#define Mem_Size ((vu32*)0x80000028) +#define Board_Model ((vu32*)0x8000002C) +#define Arena_L ((vu32*)0x80000030) +#define Arena_H ((vu32*)0x80000034) +#define FST ((vu32*)0x80000038) +#define Max_FST ((vu32*)0x8000003C) +#define Assembler ((vu32*)0x80000060) +#define Video_Mode ((vu32*)0x800000CC) +#define Dev_Debugger ((vu32*)0x800000EC) +#define Simulated_Mem ((vu32*)0x800000F0) +#define BI2 ((vu32*)0x800000F4) +#define Bus_Speed ((vu32*)0x800000F8) +#define CPU_Speed ((vu32*)0x800000FC) +#define Real_IOSVersion ((vu32*)0x80003140) +#define Online_Check ((vu32*)0x80003180) +#define GameID_Address ((vu32*)0x80003184) +#define Game_IOSVersion ((vu32*)0x80003188) #define Priiloader_CFG1 ((vu32*)0x8132FFFB) #define Priiloader_CFG2 ((vu32*)0x817FEFF0) +#define HW_AHBPROT ((vu32*)0xCD800064) +#define MEM_PROT ((vu32)0xCD8B420A) + #ifdef __cplusplus } #endif diff --git a/source/menu/menu_game.cpp b/source/menu/menu_game.cpp index f36ebaf9..a9c1a9a4 100644 --- a/source/menu/menu_game.cpp +++ b/source/menu/menu_game.cpp @@ -878,6 +878,8 @@ void CMenu::_launchGC(dir_discHdr *hdr, bool disc) DEVO_Boot(); } DML_New_WriteOptions(); + + Nand::Instance()->DeInit_ISFS(); WII_Initialize(); if(WII_LaunchTitle(0x100000100LL) < 0) Sys_LoadMenu(); @@ -1143,6 +1145,7 @@ void CMenu::_launchChannel(dir_discHdr *hdr) } if(forwarder) { + Nand::Instance()->DeInit_ISFS(); WII_Initialize(); if(WII_LaunchTitle(gameTitle) < 0) Sys_LoadMenu(); @@ -1595,7 +1598,7 @@ void CMenu::_gameSoundThread(CMenu *m) if(opening_bnr != NULL) m_banner->CreateGCBanner(opening_bnr, &m->m_vid, m_wbf1_font.get(), m_wbf2_font.get(), m->m_cf.getHdr()->title); m->m_gameSound.Load(gc_ogg, gc_ogg_size, false); - m->m_gamesound_changed = true; + m->m_gamesound_changed = true; m->m_gameSoundHdr = NULL; disc.clear(); return; diff --git a/source/menu/menu_wbfs.cpp b/source/menu/menu_wbfs.cpp index 99b51c89..4c26d9c6 100644 --- a/source/menu/menu_wbfs.cpp +++ b/source/menu/menu_wbfs.cpp @@ -439,7 +439,6 @@ bool CMenu::_wbfsOp(CMenu::WBFS_OP op) SoundHandler::DestroyInstance(); soundDeinit(); Nand::Instance()->Disable_Emu(); - Nand::DestroyInstance(); LWP_CreateThread(&thread, (void *(*)(void *))CMenu::_GCcopyGame, (void *)this, 0, 8 * 1024, 64); break; }