-added magic patcher of gx (thanks giantpune) this should make it

possible to always have full NAND access no matter which IOS is
loaded currently
-fixed the sometimes again flashing wait message on game boot
-added some proper ISFS init and deinit methods with debug prints
This commit is contained in:
fix94.1 2012-08-21 16:33:44 +00:00
parent a31fb36a37
commit 14d4efe478
12 changed files with 175 additions and 147 deletions

View File

@ -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

BIN
data/magic_patcher.o Normal file

Binary file not shown.

View File

@ -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"
@ -34,15 +35,15 @@ 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);
*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);
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);

View File

@ -26,7 +26,7 @@
* Nand/Emulation Handling Class for Wiiflow
*
***************************************************************************/
#include <ogc/machine/processor.h>
#include <stdio.h>
#include <ogcsys.h>
#include <string.h>
@ -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;
}
}
}

View File

@ -53,7 +53,7 @@ using namespace std;
class Nand
{
public:
public:
static Nand * Instance();
static void DestroyInstance();
@ -67,6 +67,8 @@ class Nand
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; };
@ -84,7 +86,7 @@ class Nand
s32 CalcDumpSpace(const char *source, dump_callback_t i_dumper, void *i_data);
void ResetCounters(void);
private:
private:
Nand() : MountedDevice(0), EmuDevice(REAL_NAND), Disabled(true), Partition(0), FullMode(0x100), NandPath() {}
~Nand(void){}
@ -93,6 +95,7 @@ class Nand
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);

View File

@ -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();

View File

@ -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)

View File

@ -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;

View File

@ -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;

View File

@ -24,12 +24,17 @@ extern "C"
#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

View File

@ -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();

View File

@ -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;
}