From 2b32db857aca8587afaea5911018e0891ee8ac28 Mon Sep 17 00:00:00 2001 From: "fix94.1" Date: Sat, 11 Aug 2012 12:27:38 +0000 Subject: [PATCH] -removed alot of unneeded cIOS checks, saving the info about our currently loaded cIOS instead -fixed bug of missing remount if no games are found with enabled NAND emulation which made wiiflow hang -added information for neek2o -removed ios reload on boot when wiiflow is in neek2o mode -made NAND file extraction MEM2 only -fixed two not free'd memory allocations which could fill the memory with unused stuff --- scripts/buildtype.sh | 1 - source/devicemounter/PartitionHandle.cpp | 2 +- source/loader/alt_ios.cpp | 38 +++--- source/loader/alt_ios.h | 3 - source/loader/apploader.c | 4 +- source/loader/cios.c | 146 ++++++++++++----------- source/loader/cios.h | 30 +++-- source/loader/disc.c | 4 +- source/loader/fs.c | 20 ++-- source/loader/nk.c | 19 ++- source/loader/nk.h | 1 + source/main.cpp | 9 +- source/menu/menu.cpp | 10 +- source/menu/menu_about.cpp | 8 +- source/menu/menu_config.cpp | 3 +- source/menu/menu_config4.cpp | 1 + source/menu/menu_game.cpp | 44 ++++--- source/menu/menu_gameinfo.cpp | 1 - source/menu/menu_main.cpp | 6 +- source/menu/menu_nandemu.cpp | 6 +- source/menu/menu_system.cpp | 2 - 21 files changed, 185 insertions(+), 173 deletions(-) diff --git a/scripts/buildtype.sh b/scripts/buildtype.sh index 88522266..c295063b 100644 --- a/scripts/buildtype.sh +++ b/scripts/buildtype.sh @@ -24,7 +24,6 @@ if [ $GENERATE -eq 1 ]; then cat < $FILENAME -#include "alt_ios.h" int mainIOS = $VERSION; EOF fi \ No newline at end of file diff --git a/source/devicemounter/PartitionHandle.cpp b/source/devicemounter/PartitionHandle.cpp index d0f40f33..2e63893f 100644 --- a/source/devicemounter/PartitionHandle.cpp +++ b/source/devicemounter/PartitionHandle.cpp @@ -34,7 +34,7 @@ #include "ext2.h" #include "sdhc.h" #include "usbstorage.h" -#include "loader/cios.h" +#include "loader/nk.h" #include "loader/utils.h" #include "loader/wbfs.h" diff --git a/source/loader/alt_ios.cpp b/source/loader/alt_ios.cpp index c4c2d685..df11cf3b 100644 --- a/source/loader/alt_ios.cpp +++ b/source/loader/alt_ios.cpp @@ -4,6 +4,7 @@ #include "alt_ios.h" #include "cios.h" #include "disc.h" +#include "nk.h" #include "sys.h" #include "wbfs.h" #include "wdvd.h" @@ -81,7 +82,16 @@ void load_dip_249() bool loadIOS(int ios, bool launch_game, bool emu_channel) { #ifndef DOLPHIN - gprintf("Reloading into IOS %i from %i (AHBPROT: %u)...\n", ios, IOS_GetVersion(), HAVE_AHBPROT); + if(neek2o()) + { + memset(&CurrentIOS, 0, sizeof(IOS_Info)); + CurrentIOS.Version = 254; + CurrentIOS.Type = IOS_TYPE_D2X; + CurrentIOS.Base = 254; + CurrentIOS.Revision = 999; + DCFlushRange(&CurrentIOS, sizeof(IOS_Info)); + return true; + } Close_Inputs(); DeviceHandler::Instance()->UnMountAll(); @@ -89,21 +99,17 @@ bool loadIOS(int ios, bool launch_game, bool emu_channel) USBStorage2_Deinit(); mload_close(); + gprintf("Reloading into IOS %i from %i (AHBPROT: %u)...\n", ios, IOS_GetVersion(), HAVE_AHBPROT); ISFS_Deinitialize(); bool iosOK = IOS_ReloadIOS(ios) == 0; ISFS_Initialize(); - gprintf("%s, Current IOS: %i\n", iosOK ? "OK" : "FAILED!", IOS_GetVersion()); - if(is_ios_type(IOS_TYPE_HERMES, IOS_GetVersion())) - { + IOS_GetCurrentIOSInfo(); + if(CurrentIOS.Type == IOS_TYPE_HERMES) load_ehc_module_ex(); - gprintf("Hermes cIOS Base IOS%i\n", get_ios_base()); - } - else if(is_ios_type(IOS_TYPE_WANIN, IOS_GetVersion()) && IOS_GetRevision() >= 18) - { + else if(CurrentIOS.Type == IOS_TYPE_WANIN && CurrentIOS.Revision >= 18) load_dip_249(); - gprintf("Waninkoko cIOS Base IOS%i\n", get_ios_base()); - } + if(!emu_channel) { if(launch_game) @@ -121,15 +127,3 @@ bool loadIOS(int ios, bool launch_game, bool emu_channel) return true; #endif } - -u32 get_ios_base() -{ - u32 revision = IOS_GetRevision(); - if (is_ios_type(IOS_TYPE_WANIN, IOS_GetVersion()) && revision >= 17) - return wanin_mload_get_IOS_base(); - - else if (is_ios_type(IOS_TYPE_HERMES, IOS_GetVersion()) && revision >= 4) - return mload_get_IOS_base(); - - return 0; -} diff --git a/source/loader/alt_ios.h b/source/loader/alt_ios.h index 989d00fc..5c3ceab5 100644 --- a/source/loader/alt_ios.h +++ b/source/loader/alt_ios.h @@ -8,9 +8,6 @@ extern "C" { #endif bool loadIOS(int ios, bool launch_game, bool emu_channel); -u32 get_ios_base(); - -extern int mainIOS; #ifdef __cplusplus } diff --git a/source/loader/apploader.c b/source/loader/apploader.c index 1e6ce907..55154759 100644 --- a/source/loader/apploader.c +++ b/source/loader/apploader.c @@ -108,7 +108,7 @@ void maindolpatches(void *dst, int len, u8 vidMode, GXRModeObj *vmode, bool vipa PrinceOfPersiaPatch(); NewSuperMarioBrosPatch(); // Patch NoDiscInDrive only for IOS 249 < rev13 or IOS 222/223/224 - if((is_ios_type(IOS_TYPE_WANIN, IOS_GetVersion()) && IOS_GetRevision() < 13) || (is_ios_type(IOS_TYPE_HERMES, IOS_GetVersion()))) + if((CurrentIOS.Type == IOS_TYPE_WANIN && CurrentIOS.Revision < 13) || CurrentIOS.Type == IOS_TYPE_HERMES) patch_NoDiscinDrive(dst, len); patchVideoModes(dst, len, vidMode, vmode, patchVidModes); if(hooktype != 0 && dogamehooks(dst, len, false)) @@ -117,7 +117,7 @@ void maindolpatches(void *dst, int len, u8 vidMode, GXRModeObj *vmode, bool vipa vidolpatcher(dst, len); if(configbytes[0] != 0xCD) langpatcher(dst, len); - if(is_ios_type(IOS_TYPE_WANIN, IOS_GetVersion()) && IOS_GetRevision() < 13) + if(CurrentIOS.Type == IOS_TYPE_WANIN && CurrentIOS.Revision < 13) Anti_002_fix(dst, len); if(countryString) PatchCountryStrings(dst, len); // Country Patch by WiiPower diff --git a/source/loader/cios.c b/source/loader/cios.c index 317994a7..e3cc5bfe 100644 --- a/source/loader/cios.c +++ b/source/loader/cios.c @@ -3,6 +3,7 @@ * by Dimok * Modifications by xFede * Wiiflowized and heavily improved by Miigotu + * 2012 Converted, corrected and extended by FIX94 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any @@ -24,60 +25,19 @@ * distribution. ***************************************************************************/ #include -#include #include #include #include "cios.h" +#include "alt_ios.h" #include "utils.h" #include "fs.h" +#include "nk.h" #include "mload.h" #include "gecko/gecko.h" #include "memory/mem2.hpp" -static bool checked = false; -static bool neek = false; -extern u32 get_ios_base(); - -bool neek2o(void) -{ - if(!checked) - { - u32 num = 0; - neek = !(ISFS_ReadDir("/sneek", NULL, &num)); - gprintf("WiiFlow is in %s mode\n", neek ? "neek2o" : "real nand"); - checked = true; - } - return neek; -} - -/* Check if the cIOS is a D2X. */ -bool D2X(u8 ios, u8 *base) -{ - if(neek2o()) - { - *base = (u8)IOS_GetVersion(); - return true; - } - - iosinfo_t *info = GetInfo(ios); - if(!info) - return false; - - if(info->magicword != 0x1ee7c105 /* Magic Word */ - || info->magicversion != 1 /* Magic Version */ - || info->version < 6 /* Version */ - || strncasecmp(info->name, "d2x", 3) != 0) /* Name */ - { - free(info); - return false; - } - - *base = (u8)info->baseios; - free(info); - return true; -} - +IOS_Info CurrentIOS; signed_blob *GetTMD(u8 ios, u32 *TMD_Length) { if(ES_GetStoredTMDSize(TITLE_ID(1, ios), TMD_Length) < 0) @@ -88,7 +48,7 @@ signed_blob *GetTMD(u8 ios, u32 *TMD_Length) return NULL; if(ES_GetStoredTMD(TITLE_ID(1, ios), TMD, *TMD_Length) < 0) { - free(TMD); + MEM2_free(TMD); return NULL; } return TMD; @@ -99,17 +59,15 @@ signed_blob *GetTMD(u8 ios, u32 *TMD_Length) * @return pointer to iosinfo_t on success else NULL. The user is responsible for freeing the buffer. */ -iosinfo_t *GetInfo(u8 ios) +iosinfo_t *IOS_GetInfo(u8 ios) { u32 TMD_Length; signed_blob *TMD = GetTMD(ios, &TMD_Length); if(TMD == NULL) return NULL; - char filepath[ISFS_MAXPATH] ATTRIBUTE_ALIGN(32); sprintf(filepath, "/title/00000001/%08x/content/%08x.app", ios, *(u8 *)((u32)TMD+0x1E7)); - - free(TMD); + MEM2_free(TMD); u32 size = 0; u8 *buffer = ISFS_GetFile((u8 *)filepath, &size, sizeof(iosinfo_t)); @@ -125,9 +83,9 @@ u32 Title_GetSize_FromTMD(tmd *tmd_data) u32 cnt, size = 0; /* Calculate title size */ - for (cnt = 0; cnt < tmd_data->num_contents; cnt++) { + for(cnt = 0; cnt < tmd_data->num_contents; cnt++) + { tmd_content *content = &tmd_data->contents[cnt]; - /* Add content size */ size += content->size; } @@ -135,7 +93,34 @@ u32 Title_GetSize_FromTMD(tmd *tmd_data) return size; } -int get_ios_type(u8 slot) +/* Check if the cIOS is a D2X. */ +bool IOS_D2X(u8 ios, u8 *base) +{ + if(neek2o()) + { + *base = (u8)IOS_GetVersion(); + return true; + } + + iosinfo_t *info = IOS_GetInfo(ios); + if(!info) + return false; + + if(info->magicword != 0x1ee7c105 /* Magic Word */ + || info->magicversion != 1 /* Magic Version */ + || info->version < 6 /* Version */ + || strncasecmp(info->name, "d2x", 3) != 0) /* Name */ + { + MEM2_free(info); + return false; + } + + *base = (u8)info->baseios; + MEM2_free(info); + return true; +} + +u8 IOS_GetType(u8 slot) { u32 TMD_Length; signed_blob *TMD_Buffer = GetTMD(slot, &TMD_Length); @@ -145,18 +130,13 @@ int get_ios_type(u8 slot) tmd *iosTMD = (tmd*)SIGNATURE_PAYLOAD(TMD_Buffer); if(Title_GetSize_FromTMD(iosTMD) < 0x100000 || iosTMD->title_version == 65280) { - free(TMD_Buffer); + MEM2_free(TMD_Buffer); return IOS_TYPE_NO_CIOS; } u32 title_rev = iosTMD->title_version; - free(TMD_Buffer); + MEM2_free(TMD_Buffer); iosTMD = NULL; - iosinfo_t *info = GetInfo(slot); - if(info == NULL) - return IOS_TYPE_NO_CIOS; - free(info); - u8 base = 0; switch(slot) { @@ -175,35 +155,61 @@ int get_ios_type(u8 slot) case 249: case 250: case 251: - if(D2X(slot, &base)) + if(IOS_D2X(slot, &base)) return IOS_TYPE_D2X; else return IOS_TYPE_WANIN; default: - if(D2X(slot, &base)) + if(IOS_D2X(slot, &base)) return IOS_TYPE_D2X; else return IOS_TYPE_NO_CIOS; } } -int is_ios_type(int type, u8 slot) +void IOS_GetCurrentIOSInfo() { - return (get_ios_type(slot) == type); + memset(&CurrentIOS, 0, sizeof(IOS_Info)); + CurrentIOS.Revision = IOS_GetRevision(); + CurrentIOS.Version = IOS_GetVersion(); + CurrentIOS.Type = IOS_GetType(CurrentIOS.Version); + if(CurrentIOS.Type == IOS_TYPE_D2X) + { + iosinfo_t *iosInfo = IOS_GetInfo(CurrentIOS.Version); + CurrentIOS.Revision = iosInfo->version; + CurrentIOS.Base = iosInfo->baseios; + gprintf("D2X cIOS Base IOS%i\n", CurrentIOS.Base); + MEM2_free(iosInfo); + } + else if(CurrentIOS.Type == IOS_TYPE_WANIN && CurrentIOS.Revision >= 18) + { + CurrentIOS.Base = wanin_mload_get_IOS_base(); + gprintf("Waninkoko cIOS Base IOS%i\n", CurrentIOS.Base); + } + else if(CurrentIOS.Type == IOS_TYPE_HERMES && CurrentIOS.Revision >= 4) + { + CurrentIOS.Base = mload_get_IOS_base(); + gprintf("Hermes cIOS Base IOS%i\n", CurrentIOS.Base); + } + else + CurrentIOS.Base = CurrentIOS.Version; + DCFlushRange(&CurrentIOS, sizeof(IOS_Info)); } -bool shadow_mload() +bool Hermes_shadow_mload() { - if(!is_ios_type(IOS_TYPE_HERMES, IOS_GetVersion())) - return false; int v51 = (5 << 4) & 1; - if (mload_get_version() >= v51) + if(mload_get_version() >= v51) { - // shadow /dev/mload supported in hermes cios v5.1 - //IOS_Open("/dev/usb123/OFF",0);// this disables ehc completely - IOS_Open("/dev/mload/OFF",0); + IOS_Open("/dev/mload/OFF",0); // shadow /dev/mload supported in hermes cios v5.1 gprintf("Shadow mload\n"); return true; } return false; } + +void Hermes_Disable_EHC() +{ + IOS_Open("/dev/usb123/OFF", 0);// this disables ehc completely + gprintf("Hermes EHC Disabled\n"); +} diff --git a/source/loader/cios.h b/source/loader/cios.h index e2841a6f..8d379499 100644 --- a/source/loader/cios.h +++ b/source/loader/cios.h @@ -1,3 +1,4 @@ + #ifndef _CIOSINFO_H_ #define _CIOSINFO_H_ @@ -8,26 +9,33 @@ extern "C" { #endif /* __cplusplus */ -typedef struct _iosinfo_t -{ +typedef struct _iosinfo_t { u32 magicword; //0x1ee7c105 u32 magicversion; // 1 u32 version; // Example: 5 u32 baseios; // Example: 56 char name[0x10]; // Example: d2x char versionstring[0x10]; // Example: beta2 -} __attribute__((packed)) iosinfo_t; +} iosinfo_t; -bool neek2o(void); -bool D2X(u8 ios, u8 *base); -iosinfo_t *GetInfo(u8 ios); -signed_blob *GetTMD(u8 ios, u32 *TMD_Length); -int is_ios_type(int type, u8 slot); -int get_ios_type(u8 slot); -bool shadow_mload(); +typedef struct _IOS_Info { + u32 Revision; + u8 Version; + u8 Type; + u8 Base; +} IOS_Info; + +extern IOS_Info CurrentIOS; +void IOS_GetCurrentIOSInfo(); + +bool IOS_D2X(u8 ios, u8 *base); +u8 IOS_GetType(u8 slot); + +bool Hermes_shadow_mload(); +void Hermes_Disable_EHC(); #ifdef __cplusplus } #endif /* __cplusplus */ -#endif \ No newline at end of file +#endif diff --git a/source/loader/disc.c b/source/loader/disc.c index 0f715914..07386287 100644 --- a/source/loader/disc.c +++ b/source/loader/disc.c @@ -59,7 +59,7 @@ void __Disc_SetLowMem() *(vu32*)0xCD00643C = 0x00000000; // 32Mhz on Bus /* Fix for Sam & Max (WiiPower) */ - if (!is_ios_type(IOS_TYPE_HERMES, IOS_GetVersion())) + if(CurrentIOS.Type != IOS_TYPE_HERMES) *GameID_Address = 0x80000000; /* Copy disc ID */ @@ -309,7 +309,7 @@ s32 Disc_SetUSB(const u8 *id, bool frag) if(frag) return set_frag_list(); s32 part = -1; - if(is_ios_type(IOS_TYPE_HERMES, IOS_GetVersion())) + if(CurrentIOS.Type == IOS_TYPE_HERMES) part = wbfs_part_idx ? wbfs_part_idx - 1 : 0; return WDVD_SetUSBMode(wbfsDev, (u8*)id, part); } diff --git a/source/loader/fs.c b/source/loader/fs.c index e57b89ca..be9427ad 100644 --- a/source/loader/fs.c +++ b/source/loader/fs.c @@ -1,9 +1,14 @@ + #include #include #include -#include -#include "utils.h" +#include + #include "fs.h" +#include "utils.h" +#include "memory/mem2.hpp" + +static fstats stats ATTRIBUTE_ALIGN(32); u8 *ISFS_GetFile(u8 *path, u32 *size, s32 length) { @@ -11,31 +16,30 @@ u8 *ISFS_GetFile(u8 *path, u32 *size, s32 length) s32 fd = ISFS_Open((const char *)path, ISFS_OPEN_READ); u8 *buf = NULL; - static fstats stats ATTRIBUTE_ALIGN(32); - + if(fd >= 0) { + memset(&stats, 0, sizeof(fstats)); if(ISFS_GetFileStats(fd, &stats) >= 0) { if(length <= 0) length = stats.file_length; if(length > 0) - buf = (u8 *)memalign(32, ALIGN32(length)); - + buf = (u8 *)MEM2_memalign(32, ALIGN32(length)); if(buf) { *size = stats.file_length; if(ISFS_Read(fd, (char*)buf, length) != length) { *size = 0; - free(buf); + MEM2_free(buf); } } } ISFS_Close(fd); } - if (*size > 0) + if(*size > 0) { DCFlushRange(buf, *size); ICInvalidateRange(buf, *size); diff --git a/source/loader/nk.c b/source/loader/nk.c index 758cdb4d..3bcc7aea 100644 --- a/source/loader/nk.c +++ b/source/loader/nk.c @@ -29,9 +29,24 @@ #include #include "nk.h" -#include "cios.h" #include "armboot.h" #include "memory/mem2.hpp" +#include "gecko/gecko.h" + +bool checked = false; +bool neek = false; + +bool neek2o(void) +{ + if(!checked) + { + u32 num = 0; + neek = !(ISFS_ReadDir("/sneek", NULL, &num)); + gprintf("WiiFlow is in %s mode\n", neek ? "neek2o" : "real nand"); + checked = true; + } + return neek; +} s32 Launch_nk(u64 TitleID, const char *nandpath) { @@ -95,4 +110,4 @@ s32 Launch_nk(u64 TitleID, const char *nandpath) IOS_ReloadIOS(0xfe); MEM1_free(mini); return 1; -} \ No newline at end of file +} diff --git a/source/loader/nk.h b/source/loader/nk.h index bf9731bb..58f9ac06 100644 --- a/source/loader/nk.h +++ b/source/loader/nk.h @@ -25,6 +25,7 @@ extern "C" { #endif /* __cplusplus */ s32 Launch_nk(u64 TitleID, const char *nandpath); +bool neek2o(void); #ifdef __cplusplus } diff --git a/source/main.cpp b/source/main.cpp index 149eec25..de7701d9 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -24,6 +24,7 @@ CMenu *mainMenu; extern "C" { extern void __exception_setreload(int t); + extern int mainIOS; void ShowError(const wstringEx &error) { mainMenu->error(error); } void HideWaitMessage() { mainMenu->_hideWaitMessage(); } @@ -69,13 +70,7 @@ int main(int argc, char **argv) // Load Custom IOS gprintf("Loading cIOS: %d\n", mainIOS); bool iosOK = loadIOS(mainIOS, false, false); - - u8 mainIOSBase = 0; - D2X(mainIOS, &mainIOSBase); - if(!mainIOSBase) - mainIOSBase = get_ios_base(); - iosOK = iosOK && mainIOSBase > 0; - gprintf("Loaded cIOS: %u has base %u\n", mainIOS, mainIOSBase); + iosOK = iosOK && CurrentIOS.Type != IOS_TYPE_NO_CIOS; #else bool iosOK = true; #endif diff --git a/source/menu/menu.cpp b/source/menu/menu.cpp index 58146f6b..ed9ab5d7 100644 --- a/source/menu/menu.cpp +++ b/source/menu/menu.cpp @@ -19,6 +19,7 @@ #include "loader/alt_ios.h" #include "loader/cios.h" #include "loader/fs.h" +#include "loader/nk.h" #include "loader/playlog.h" #include "loader/sys.h" #include "loader/wbfs.h" @@ -280,10 +281,7 @@ void CMenu::init(void) if(!neek2o()) _load_installed_cioses(); else - { - extern int mainIOS; - _installed_cios[mainIOS] = mainIOS; - } + _installed_cios[CurrentIOS.Version] = CurrentIOS.Version; snprintf(m_app_update_drive, sizeof(m_app_update_drive), "%s:/", drive); m_dataDir = sfmt("%s:/%s", drive, APPDATA_DIR); @@ -2307,12 +2305,12 @@ void CMenu::_load_installed_cioses() for(u8 slot = 200; slot < 254; slot++) { u8 base = 1; - if(D2X(slot, &base)) + if(IOS_D2X(slot, &base)) { gprintf("Found d2x base %u in slot %u\n", base, slot); _installed_cios[slot] = base; } - else if(!is_ios_type(IOS_TYPE_NO_CIOS, slot)) + else if(IOS_GetType(slot) != IOS_TYPE_NO_CIOS) { gprintf("Found cIOS in slot %u\n", slot); _installed_cios[slot] = slot; diff --git a/source/menu/menu_about.cpp b/source/menu/menu_about.cpp index efa09094..39f35d60 100644 --- a/source/menu/menu_about.cpp +++ b/source/menu/menu_about.cpp @@ -158,11 +158,5 @@ void CMenu::_textAbout(void) false ); - Nand::Instance()->Disable_Emu(); - iosinfo_t * iosInfo = GetInfo(mainIOS); - if(iosInfo != NULL) - { - m_btnMgr.setText(m_aboutLblIOS, wfmt(_fmt("ios", L"IOS%i base %i v%i"), mainIOS, iosInfo->baseios, iosInfo->version), true); - free(iosInfo); - } + m_btnMgr.setText(m_aboutLblIOS, wfmt(_fmt("ios", L"IOS%i base %i v%i"), CurrentIOS.Version, CurrentIOS.Base, CurrentIOS.Revision), true); } diff --git a/source/menu/menu_config.cpp b/source/menu/menu_config.cpp index 0815502f..f4308cc6 100644 --- a/source/menu/menu_config.cpp +++ b/source/menu/menu_config.cpp @@ -1,8 +1,7 @@ #include "menu.hpp" #include "channel/nand.hpp" -#include "loader/alt_ios.h" -#include "loader/cios.h" +#include "loader/nk.h" #include "loader/sys.h" const int CMenu::_nbCfgPages = 6; diff --git a/source/menu/menu_config4.cpp b/source/menu/menu_config4.cpp index 2c012858..1d52d9fd 100644 --- a/source/menu/menu_config4.cpp +++ b/source/menu/menu_config4.cpp @@ -5,6 +5,7 @@ #include "channel/nand.hpp" #include "gecko/gecko.h" #include "loader/cios.h" +#include "loader/nk.h" #include "loader/sys.h" static const int g_curPage = 4; diff --git a/source/menu/menu_game.cpp b/source/menu/menu_game.cpp index 55b197ee..76fbb04e 100644 --- a/source/menu/menu_game.cpp +++ b/source/menu/menu_game.cpp @@ -56,7 +56,6 @@ extern const u8 gc_ogg[]; extern const u32 gc_ogg_size; extern u32 boot2version; -extern int mainIOS; static u64 sm_title_id[8] ATTRIBUTE_ALIGN(32); bool m_zoom_banner = false; @@ -934,7 +933,7 @@ int CMenu::_loadIOS(u8 gameIOS, int userIOS, string id, bool emu_channel) } } else if(gameIOS != 57) - gameIOS = mainIOS; + gameIOS = CurrentIOS.Version; gprintf("Changed requested IOS to %d.\n", gameIOS); // remap IOS to CIOS @@ -970,7 +969,7 @@ int CMenu::_loadIOS(u8 gameIOS, int userIOS, string id, bool emu_channel) return LOAD_IOS_FAILED; } - if(gameIOS != mainIOS) + if(gameIOS != CurrentIOS.Version) { gprintf("Reloading IOS into %d\n", gameIOS); if(!loadIOS(gameIOS, true, false)) @@ -1053,7 +1052,7 @@ void CMenu::_launchChannel(dir_discHdr *hdr) m_gcfg2.save(true); m_cat.save(true); m_cfg.save(true); - + if(useNK2o && !emu_disabled) { cleanup(true); @@ -1064,9 +1063,9 @@ void CMenu::_launchChannel(dir_discHdr *hdr) } while(1); } - - cleanup(); - + else + cleanup(); + if(!forwarder) { if(!emu_disabled) @@ -1083,12 +1082,12 @@ void CMenu::_launchChannel(dir_discHdr *hdr) if(_loadIOS(gameIOS, userIOS, id, !emu_disabled) == LOAD_IOS_FAILED) return; } - if(rtrn != NULL && strlen(rtrn) == 4) + if(CurrentIOS.Type == IOS_TYPE_D2X && rtrn != NULL && strlen(rtrn) == 4) { int rtrnID = rtrn[0] << 24 | rtrn[1] << 16 | rtrn[2] << 8 | rtrn[3]; static ioctlv vector[1] ATTRIBUTE_ALIGN(32); - sm_title_id[0] = (((u64)(0x00010001) << 32) | (rtrnID&0xFFFFFFFF)); + sm_title_id[0] = (((u64)(0x00010001) << 32) | (rtrnID & 0xFFFFFFFF)); vector[0].data = sm_title_id; vector[0].len = 8; @@ -1344,13 +1343,12 @@ void CMenu::_launchGame(dir_discHdr *hdr, bool dvd) #else bool iosLoaded = true; #endif - u8 base; - if(D2X(IOS_GetVersion(), &base)) + if(CurrentIOS.Type == IOS_TYPE_D2X) { if(!m_directLaunch && returnTo) { static ioctlv vector[1] ATTRIBUTE_ALIGN(32); - sm_title_id[0] = (((u64)(0x00010001) << 32) | (returnTo&0xFFFFFFFF)); + sm_title_id[0] = (((u64)(0x00010001) << 32) | (returnTo & 0xFFFFFFFF)); vector[0].data = sm_title_id; vector[0].len = 8; s32 ESHandle = IOS_Open("/dev/es", 0); @@ -1358,7 +1356,7 @@ void CMenu::_launchGame(dir_discHdr *hdr, bool dvd) IOS_Close(ESHandle); returnTo = 0; } - IOSReloadBlock(IOS_GetVersion(), true); + IOSReloadBlock(CurrentIOS.Version, true); } if(emulate_mode && !neek2o()) { @@ -1411,15 +1409,23 @@ void CMenu::_launchGame(dir_discHdr *hdr, bool dvd) #ifndef DOLPHIN USBStorage2_Deinit(); USB_Deinitialize(); - shadow_mload(); + if(CurrentIOS.Type == IOS_TYPE_HERMES) + { + if(dvd) + Hermes_Disable_EHC(); + else + Hermes_shadow_mload(); + } #endif /* Last check if the Disc ID is correct */ - char discid[32] ATTRIBUTE_ALIGN(32); - memset(discid, 0, sizeof(discid)); - WDVD_UnencryptedRead(discid, 32, 0); - gprintf("WDVD_UnencryptedRead ID: %s (expected: %s)\n", discid, id.c_str()); - if(strncasecmp(id.c_str(), discid, 6) != 0) + void *ReadBuffer = MEM2_memalign(32, 32); + WDVD_UnencryptedRead(ReadBuffer, 32, 0); + string ReadedID((char*)ReadBuffer, 6); + MEM2_free(ReadBuffer); + + gprintf("WDVD_UnencryptedRead ID: %s (expected: %s)\n", ReadedID.c_str(), id.c_str()); + if(strncasecmp(id.c_str(), ReadedID.c_str(), 6) != 0) return; DisableMEM1allocR(); diff --git a/source/menu/menu_gameinfo.cpp b/source/menu/menu_gameinfo.cpp index 4720d54c..aeb2375c 100644 --- a/source/menu/menu_gameinfo.cpp +++ b/source/menu/menu_gameinfo.cpp @@ -2,7 +2,6 @@ #include "menu.hpp" #include "gui/GameTDB.hpp" -#include "loader/alt_ios.h" #include "loader/sys.h" extern const u8 wifi1_png[]; diff --git a/source/menu/menu_main.cpp b/source/menu/menu_main.cpp index c38b78f1..6867f956 100644 --- a/source/menu/menu_main.cpp +++ b/source/menu/menu_main.cpp @@ -10,6 +10,7 @@ #include "loader/alt_ios.h" #include "loader/cios.h" #include "loader/disc.h" +#include "loader/nk.h" #include "loader/sys.h" #include "loader/wbfs.h" #include "loader/wdvd.h" @@ -153,6 +154,7 @@ void CMenu::_showMain(void) if(!m_cfg.getBool("NAND", "disable", true)) { Nand::Instance()->Disable_Emu(); + DeviceHandler::Instance()->MountAll(); _hideMain(); if(!_AutoCreateNand()) m_cfg.setBool("NAND", "disable", true); @@ -633,10 +635,8 @@ int CMenu::main(void) { _showWaitMessage(); _hideMain(); - Nand::Instance()->Disable_Emu(); bool isD2XnewerThanV6 = false; - iosinfo_t * iosInfo = GetInfo(mainIOS); - if (iosInfo->version > 6) + if(CurrentIOS.Revision > 6 && CurrentIOS.Type == IOS_TYPE_D2X) isD2XnewerThanV6 = true; if(m_current_view == COVERFLOW_CHANNEL && m_cfg.getInt("NAND", "emulation", 0)) Nand::Instance()->Enable_Emu(); diff --git a/source/menu/menu_nandemu.cpp b/source/menu/menu_nandemu.cpp index 73dcd397..19d4e456 100644 --- a/source/menu/menu_nandemu.cpp +++ b/source/menu/menu_nandemu.cpp @@ -4,8 +4,8 @@ #include "lockMutex.hpp" #include "channel/nand.hpp" #include "fileOps/fileOps.h" -#include "loader/alt_ios.h" #include "loader/cios.h" +#include "loader/nk.h" #include "loader/sys.h" // NandEmulation menu @@ -201,9 +201,7 @@ void CMenu::_enableNandEmu(bool fromconfig) if(!disable) { bool isD2XnewerThanV6 = false; - Nand::Instance()->Disable_Emu(); - iosinfo_t * iosInfo = GetInfo(mainIOS); - if(iosInfo->version > 6 || neek2o()) + if(CurrentIOS.Revision > 6 && CurrentIOS.Type == IOS_TYPE_D2X) isD2XnewerThanV6 = true; if(m_current_view == COVERFLOW_CHANNEL && !m_cfg.getBool("NAND", "disable", true) && !neek2o() && !m_tempView) Nand::Instance()->Enable_Emu(); diff --git a/source/menu/menu_system.cpp b/source/menu/menu_system.cpp index 824a0a3a..16343198 100644 --- a/source/menu/menu_system.cpp +++ b/source/menu/menu_system.cpp @@ -6,8 +6,6 @@ #include "loader/sys.h" #include "loader/wbfs.h" -extern int mainIOS; - int version_num = 0, num_versions = 0, i; int CMenu::_version[9] = {0, atoi(SVN_REV), atoi(SVN_REV), atoi(SVN_REV), atoi(SVN_REV), atoi(SVN_REV), atoi(SVN_REV), atoi(SVN_REV), atoi(SVN_REV)};