diff --git a/source/banner/AnimatedBanner.cpp b/source/banner/AnimatedBanner.cpp index 2a2d519d..cb9477de 100644 --- a/source/banner/AnimatedBanner.cpp +++ b/source/banner/AnimatedBanner.cpp @@ -29,6 +29,7 @@ distribution. #include "unzip/lz77.h" #include "unzip/ash.h" +AnimatedBanner gameBanner; AnimatedBanner::AnimatedBanner() { layout_banner = NULL; @@ -55,10 +56,10 @@ void AnimatedBanner::Clear() } } -bool AnimatedBanner::LoadBanner(Banner *banner) +bool AnimatedBanner::LoadBanner() { u32 banner_bin_size; - u8 *banner_bin = banner->GetFile((char*)"banner.bin", &banner_bin_size); + u8 *banner_bin = CurrentBanner.GetFile((char*)"banner.bin", &banner_bin_size); if(banner_bin == NULL) return false; bool ret = LoadBannerBin(banner_bin, banner_bin_size); diff --git a/source/banner/AnimatedBanner.h b/source/banner/AnimatedBanner.h index bacf2441..664bf0dd 100644 --- a/source/banner/AnimatedBanner.h +++ b/source/banner/AnimatedBanner.h @@ -36,7 +36,7 @@ public: void LoadFont(u8 *font1, u8 *font2); void Clear(); - bool LoadBanner(Banner *banner); + bool LoadBanner(); bool LoadBannerBin(u8 *banner_bin, u32 banner_bin_size); Layout *getBanner() const { return layout_banner; } void SetBannerTexture(const char *tex_name, const u8 *data, float width, float height, u8 fmt); @@ -51,4 +51,5 @@ protected: u8 *DecompressCopy(u8 *stuff, u32 len, u32 *size); +extern AnimatedBanner gameBanner; #endif diff --git a/source/banner/BannerWindow.cpp b/source/banner/BannerWindow.cpp index 9286e0ef..2d05cd11 100644 --- a/source/banner/BannerWindow.cpp +++ b/source/banner/BannerWindow.cpp @@ -60,19 +60,19 @@ void BannerWindow::Init(u8 *font1, u8 *font2) stepy1 = ((ScreenProps.y * 0.9f - yDiff) - (AnimPosY + 0.5f * fIconHeight - 0.5f * iconHeight)) * ratioY; stepy2 = ((ScreenProps.y * 0.9f + yDiff) - (AnimPosY + 0.5f * fIconHeight + 0.5f * iconHeight)) * ratioY; - gameBanner->Clear(); + gameBanner.Clear(); if(!FontLoaded) { - gameBanner->LoadFont(sysFont1, sysFont2); + gameBanner.LoadFont(sysFont1, sysFont2); FontLoaded = true; } } -void BannerWindow::LoadBanner(Banner *banner, u8 *font1, u8 *font2) +void BannerWindow::LoadBanner(u8 *font1, u8 *font2) { changing = true; Init(font1, font2); - gameBanner->LoadBanner(banner); + gameBanner.LoadBanner(); gameSelected = 1; changing = false; ShowBanner = true; @@ -82,7 +82,7 @@ void BannerWindow::DeleteBanner(bool gamechange) { if(!gamechange) gameSelected = 0; - gameBanner->Clear(); + gameBanner.Clear(); } BannerWindow::BannerWindow() @@ -93,14 +93,13 @@ BannerWindow::BannerWindow() AnimZoom = false; AnimStep = 20; gameSelected = 0; - gameBanner = new AnimatedBanner; } void BannerWindow::LoadBannerBin(u8 *bnr, u32 bnr_size, u8 *font1, u8 *font2) { changing = true; Init(font1, font2); - gameBanner->LoadBannerBin(bnr, bnr_size); + gameBanner.LoadBannerBin(bnr, bnr_size); gameSelected = 1; changing = false; ShowBanner = true; @@ -110,8 +109,8 @@ void BannerWindow::CreateGCBanner(u8 *bnr, u8 *font1, u8 *font2, const wchar_t * { GC_OpeningBnr *openingBnr = (GC_OpeningBnr *)bnr; LoadBannerBin((u8*)custombanner_bin, (u32)custombanner_bin_size, font1, font2); - gameBanner->SetBannerTexture("GCIcon.tpl", openingBnr->tpl_data, 96, 32, GX_TF_RGB5A3); - gameBanner->SetBannerText("T_GameTitle", title); + gameBanner.SetBannerTexture("GCIcon.tpl", openingBnr->tpl_data, 96, 32, GX_TF_RGB5A3); + gameBanner.SetBannerText("T_GameTitle", title); } bool BannerWindow::ToogleZoom(void) @@ -203,10 +202,10 @@ void BannerWindow::Draw(void) // load projection matrix GX_LoadProjectionMtx(projection, GX_ORTHOGRAPHIC); - if(gameBanner->getBanner()) + if(gameBanner.getBanner()) { - gameBanner->getBanner()->Render(modelview, ScreenProps, m_vid.wide(), 255.f); - gameBanner->getBanner()->AdvanceFrame(); + gameBanner.getBanner()->Render(modelview, ScreenProps, m_vid.wide(), 255.f); + gameBanner.getBanner()->AdvanceFrame(); } // Setup GX diff --git a/source/banner/BannerWindow.hpp b/source/banner/BannerWindow.hpp index 6dae8f74..f9e54a1c 100644 --- a/source/banner/BannerWindow.hpp +++ b/source/banner/BannerWindow.hpp @@ -47,7 +47,7 @@ class BannerWindow public: BannerWindow(); void DeleteBanner(bool gamechange = false); - void LoadBanner(Banner *banner, u8 *font1, u8 *font2); + void LoadBanner(u8 *font1, u8 *font2); void LoadBannerBin(u8 *bnr, u32 bnr_size, u8 *font1, u8 *font2); int GetSelectedGame() { return gameSelected; } bool GetZoomSetting() { return AnimZoom; } @@ -95,7 +95,6 @@ class BannerWindow Mtx44 projection; Vec2f ScreenProps; - AnimatedBanner *gameBanner; u8 *sysFont1; u8 *sysFont2; bool FontLoaded; diff --git a/source/booter/external_booter.cpp b/source/booter/external_booter.cpp index 402acfd9..d5ab84da 100644 --- a/source/booter/external_booter.cpp +++ b/source/booter/external_booter.cpp @@ -117,6 +117,6 @@ void ExternalBooter_ChannelSetup(u64 title) void ShutdownBeforeExit() { DeviceHandle.UnMountAll(); - Nand::Instance()->DeInit_ISFS(); + NandHandle.DeInit_ISFS(); WDVD_Close(); } diff --git a/source/channel/banner.cpp b/source/channel/banner.cpp index 3cb966ca..d0c7d2dd 100644 --- a/source/channel/banner.cpp +++ b/source/channel/banner.cpp @@ -42,22 +42,32 @@ #define IMET_OFFSET 0x40 #define IMET_SIGNATURE 0x494d4554 -Banner::Banner(u8 *bnr, u32 bnr_size, u64 title, bool custom) +Banner CurrentBanner; + +Banner::Banner() { + opening = NULL; + opening_size = 0; + title = 0; + imet = NULL; +} + +void Banner::SetBanner(u8 *bnr, u32 bnr_size, u64 title, bool custom) +{ + ClearBanner(); + if(bnr == NULL || bnr_size == 0) + return; + this->title = title; opening = bnr; opening_size = bnr_size; - imet = NULL; - - if(opening == NULL) - return; - - IMET *imet = (IMET *)opening; + imet = (IMET *)opening; if(imet->sig != IMET_SIGNATURE) imet = (IMET *) (opening + IMET_OFFSET); if(imet->sig == IMET_SIGNATURE) { + DCFlushRange(opening, opening_size); unsigned char md5[16]; unsigned char imetmd5[16]; @@ -72,15 +82,15 @@ Banner::Banner(u8 *bnr, u32 bnr_size, u64 title, bool custom) gprintf("Invalid md5, banner not valid for title %08x\n", title); } else - { - gprintf("Invalid signature found, banner not valid for title %08x\n", title); - } + gprintf("Invalid signature found, banner not valid for title %08x\n", title); } -Banner::~Banner() +void Banner::ClearBanner() { if(opening != NULL) free(opening); + opening = NULL; + opening_size = 0; } bool Banner::IsValid() @@ -151,7 +161,7 @@ u8 *Banner::GetFile(char *name, u32 *size) return file; } -Banner * Banner::GetBanner(u64 title, char *appname, bool isfs, bool imetOnly) +void Banner::GetBanner(u64 title, char *appname, bool isfs, bool imetOnly) { void *buf = NULL; u32 size = 0; @@ -162,14 +172,14 @@ Banner * Banner::GetBanner(u64 title, char *appname, bool isfs, bool imetOnly) { if(buf != NULL) free(buf); - return NULL; + return; } } else { FILE *fp = fopen(appname, "rb"); if(fp == NULL) - return NULL; + return; u32 size = sizeof(IMET) + IMET_OFFSET; if (!imetOnly) @@ -181,11 +191,10 @@ Banner * Banner::GetBanner(u64 title, char *appname, bool isfs, bool imetOnly) buf = malloc(size); if(!buf) - return NULL; + return; fread(buf, size, 1, fp); fclose(fp); } - - return new Banner((u8 *)buf, size, title); + SetBanner((u8 *)buf, size, title); } diff --git a/source/channel/banner.h b/source/channel/banner.h index f99fd443..44643fef 100644 --- a/source/channel/banner.h +++ b/source/channel/banner.h @@ -60,8 +60,9 @@ typedef struct class Banner { public: - Banner(u8 *bnr, u32 bnr_size, u64 title = 0, bool custom = false); - ~Banner(); + Banner(); + void SetBanner(u8 *bnr, u32 bnr_size, u64 title = 0, bool custom = false); + void ClearBanner(); bool IsValid(); @@ -69,7 +70,7 @@ class Banner bool GetName(wchar_t *name, int language); u8 *GetFile(char *name, u32 *size); - static Banner *GetBanner(u64 title, char *appname, bool isfs, bool imetOnly = false); + void GetBanner(u64 title, char *appname, bool isfs, bool imetOnly = false); u8 *GetBannerFile() { return opening; } u32 GetBannerFileSize() { return opening_size; } protected: @@ -81,5 +82,6 @@ class Banner u16 *GetName(int language); static bool GetChannelNameFromApp(u64 title, wchar_t* name, int language); }; +extern Banner CurrentBanner; #endif //_BANNER_H_ diff --git a/source/channel/channels.cpp b/source/channel/channels.cpp index f663cf06..5fd54066 100644 --- a/source/channel/channels.cpp +++ b/source/channel/channels.cpp @@ -46,10 +46,6 @@ Channels ChannelHandle; -Channels::Channels() -{ -} - void Channels::Init(u32 channelType, string lang, bool reload) { if (reload) init = !reload; @@ -65,8 +61,9 @@ void Channels::Init(u32 channelType, string lang, bool reload) } } -Channels::~Channels() +void Channels::Cleanup() { + this->channels.clear(); } u8 Channels::GetRequestedIOS(u64 title) @@ -156,16 +153,16 @@ bool Channels::GetAppNameFromTmd(u64 title, char *app, bool dol, u32 *bootconten return ret; } -Banner * Channels::GetBanner(u64 title, bool imetOnly) +void Channels::GetBanner(u64 title, bool imetOnly) { char app[ISFS_MAXPATH] ATTRIBUTE_ALIGN(32); u32 cid; if (!GetAppNameFromTmd(title, app, false, &cid)) { gprintf("No title found\n"); - return NULL; + return; } - return Banner::GetBanner(title, app, true, imetOnly); + CurrentBanner.GetBanner(title, app, true, imetOnly); } bool Channels::GetChannelNameFromApp(u64 title, wchar_t* name, int language) @@ -175,14 +172,13 @@ bool Channels::GetChannelNameFromApp(u64 title, wchar_t* name, int language) if (language > CONF_LANG_KOREAN) language = CONF_LANG_ENGLISH; - Banner *banner = GetBanner(title, true); - if (banner != NULL) + GetBanner(title, true); + if(CurrentBanner.IsValid()) { - ret = banner->GetName(name, language); - delete banner; - banner = NULL; + ret = CurrentBanner.GetName(name, language); + CurrentBanner.ClearBanner(); } - + return ret; } diff --git a/source/channel/channels.h b/source/channel/channels.h index 5e05fa40..bc14e8ee 100644 --- a/source/channel/channels.h +++ b/source/channel/channels.h @@ -49,10 +49,8 @@ typedef struct class Channels { public: - Channels(); - ~Channels(); - void Init(u32 channelType, string lang, bool reload = false); + void Cleanup(); u32 Load(u64 title); u8 GetRequestedIOS(u64 title); @@ -63,7 +61,7 @@ public: u64 GetTitle(int index); Channel *GetChannel(int index); - static Banner * GetBanner(u64 title, bool imetOnly = false); + void GetBanner(u64 title, bool imetOnly = false); private: bool init; u32 channelType; @@ -71,10 +69,10 @@ private: vector channels; - static int GetLanguage(const char *lang); + int GetLanguage(const char *lang); u64* GetChannelList(u32* count); - static bool GetAppNameFromTmd(u64 title, char* app, bool dol = false, u32* bootcontent = NULL); - static bool GetChannelNameFromApp(u64 title, wchar_t* name, int language); + bool GetAppNameFromTmd(u64 title, char* app, bool dol = false, u32* bootcontent = NULL); + bool GetChannelNameFromApp(u64 title, wchar_t* name, int language); void Search(u32 channelType, string lang); }; diff --git a/source/channel/nand.cpp b/source/channel/nand.cpp index 2966e11b..4522f5e8 100644 --- a/source/channel/nand.cpp +++ b/source/channel/nand.cpp @@ -57,6 +57,8 @@ bool tbdec = false; bool configloaded = false; bool emu_enabled = false; +Nand NandHandle; + static NandDevice NandDeviceList[] = { { "Disable", 0, 0x00, 0x00 }, @@ -64,22 +66,17 @@ static NandDevice NandDeviceList[] = { "USB 2.0 Mass Storage Device", 2, 0xF2, 0xF3 }, }; -Nand * Nand::instance = NULL; - -Nand * Nand::Instance() +void Nand::Init() { - if(instance == NULL) - instance = new Nand(); - return instance; + MountedDevice = 0; + EmuDevice = REAL_NAND; + Disabled = true; + Partition = 0; + FullMode = 0x100; + memset(NandPath, 0, sizeof(NandPath)); } -void Nand::DestroyInstance() -{ - if(instance) delete instance; - instance = NULL; -} - -void Nand::Init(string path, u32 partition, bool disable) +void Nand::SetPaths(string path, u32 partition, bool disable) { EmuDevice = disable ? REAL_NAND : partition == 0 ? EMU_SD : EMU_USB; Partition = disable ? REAL_NAND : partition > 0 ? partition - 1 : partition; diff --git a/source/channel/nand.hpp b/source/channel/nand.hpp index 37e4328a..3079509c 100644 --- a/source/channel/nand.hpp +++ b/source/channel/nand.hpp @@ -54,11 +54,10 @@ using namespace std; class Nand { public: - static Nand * Instance(); - static void DestroyInstance(); + void Init(); /* Prototypes */ - void Init(string path, u32 partition, bool disable = false); + void SetPaths(string path, u32 partition, bool disable = false); s32 Enable_Emu(); s32 Disable_Emu(); bool EmulationEnabled(void); @@ -89,9 +88,6 @@ public: 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); @@ -137,8 +133,7 @@ private: char NandPath[32] ATTRIBUTE_ALIGN(32); char cfgpath[1024]; char settxtpath[1024]; - - static Nand * instance; }; +extern Nand NandHandle; #endif diff --git a/source/devicemounter/DeviceHandler.cpp b/source/devicemounter/DeviceHandler.cpp index fef8fca2..a5acb22f 100644 --- a/source/devicemounter/DeviceHandler.cpp +++ b/source/devicemounter/DeviceHandler.cpp @@ -42,12 +42,9 @@ DeviceHandler DeviceHandle; void DeviceHandler::Init() { - sd = NULL; - gca = NULL; - gcb = NULL; - usb0 = NULL; - usb1 = NULL; - OGC_Device = NULL; + sd.Init(); + usb0.Init(); + OGC_Device.Init(); } void DeviceHandler::MountAll() @@ -64,21 +61,12 @@ void DeviceHandler::UnMountAll() for(u32 i = SD; i < MAXDEVICES; i++) UnMount(i); - - if(sd) - delete sd; - if(usb0) - delete usb0; - if(usb1) - delete usb1; - - sd = NULL; - usb0 = NULL; - usb1 = NULL; - USBStorage2_Deinit(); USB_Deinitialize(); SDHC_Close(); + + sd.Cleanup(); + usb0.Cleanup(); } bool DeviceHandler::Mount(int dev) @@ -95,14 +83,11 @@ bool DeviceHandler::Mount(int dev) bool DeviceHandler::IsInserted(int dev) { if(dev == SD) - return SD_Inserted() && sd->IsMounted(0); - + return SD_Inserted() && sd.IsMounted(0); else if(dev >= USB1 && dev <= USB8) { int portPart = PartitionToPortPartition(dev-USB1); - PartitionHandle *usb = GetUSBHandleFromPartition(dev-USB1); - if(usb) - return usb->IsMounted(portPart); + return usb0.IsMounted(portPart); } return false; @@ -112,7 +97,6 @@ void DeviceHandler::UnMount(int dev) { if(dev == SD) UnMountSD(); - else if(dev >= USB1 && dev <= USB8) UnMountUSB(dev-USB1); } @@ -132,7 +116,7 @@ void DeviceHandler::SetModes() bool DeviceHandler::MountSD() { - if(!sd) + if(!sd.IsInserted() || !sd.IsMounted(0)) { if(CurrentIOS.Type == IOS_TYPE_HERMES) { /* Slowass Hermes SDHC Module */ @@ -143,26 +127,22 @@ bool DeviceHandler::MountSD() usleep(1000); } } - sd = new PartitionHandle(&__io_sdhc); + sd.SetDevice(&__io_sdhc); + //! Mount only one SD Partition + return sd.Mount(0, DeviceName[SD], true); /* Force FAT */ } - //! Mount only one SD Partition - return sd->Mount(0, DeviceName[SD], true); /* Force FAT */ + return true; } bool DeviceHandler::MountUSB(int pos) { - if(!usb0 && !usb1) - return false; - if(pos >= GetUSBPartitionCount()) return false; int portPart = PartitionToPortPartition(pos); - if(PartitionToUSBPort(pos) == 0 && usb0) - return usb0->Mount(portPart, DeviceName[USB1+pos]); - else if(usb1) - return usb1->Mount(portPart, DeviceName[USB1+pos]); + if(PartitionToUSBPort(pos) == 0) + return usb0.Mount(portPart, DeviceName[USB1+pos]); return false; } @@ -174,8 +154,8 @@ bool DeviceHandler::MountAllUSB() /* Wait for our slowass HDD */ WaitForDevice(GetUSB0Interface()); /* Get Partitions and Mount them */ - if(!usb0) - usb0 = new PartitionHandle(GetUSB0Interface()); + if(!usb0.IsInserted() || !usb0.IsMounted(0)) + usb0.SetDevice(GetUSB0Interface()); bool result = false; int partCount = GetUSBPartitionCount(); for(int i = 0; i < partCount; i++) @@ -184,7 +164,7 @@ bool DeviceHandler::MountAllUSB() result = true; } if(!result) - result = usb0->Mount(0, DeviceName[USB1], true); /* Force FAT */ + result = usb0.Mount(0, DeviceName[USB1], true); /* Force FAT */ if(result && usb_libogc_mode) CreateUSBKeepAliveThread(); return result; @@ -197,10 +177,10 @@ void DeviceHandler::UnMountUSB(int pos) int portPart = PartitionToPortPartition(pos); - if(PartitionToUSBPort(pos) == 0 && usb0) - return usb0->UnMount(portPart); - else if(usb1) - return usb1->UnMount(portPart); + if(PartitionToUSBPort(pos) == 0) + return usb0.UnMount(portPart); + //else if(usb1) + // return usb1->UnMount(portPart); } void DeviceHandler::UnMountAllUSB() @@ -209,11 +189,6 @@ void DeviceHandler::UnMountAllUSB() for(int i = 0; i < partCount; i++) UnMountUSB(i); - - delete usb0; - usb0 = NULL; - delete usb1; - usb1 = NULL; } int DeviceHandler::PathToDriveType(const char *path) @@ -232,21 +207,21 @@ int DeviceHandler::PathToDriveType(const char *path) const char *DeviceHandler::GetFSName(int dev) { - if(dev == SD && sd) - return sd->GetFSName(0); + if(dev == SD) + return sd.GetFSName(0); else if(dev >= USB1 && dev <= USB8) { int partCount0 = 0; - int partCount1 = 0; - if(usb0) - partCount0 += usb0->GetPartitionCount(); - if(usb1) - partCount1 += usb1->GetPartitionCount(); + //int partCount1 = 0; + //if(usb0) + partCount0 += usb0.GetPartitionCount(); + //if(usb1) + // partCount1 += usb1->GetPartitionCount(); - if(dev-USB1 < partCount0 && usb0) - return usb0->GetFSName(dev-USB1); - else if(usb1) - return usb1->GetFSName(dev-USB1-partCount0); + if(dev-USB1 < partCount0) + return usb0.GetFSName(dev-USB1); + //else if(usb1) + // return usb1->GetFSName(dev-USB1-partCount0); } return ""; @@ -273,22 +248,21 @@ u16 DeviceHandler::GetUSBPartitionCount() { u16 partCount0 = 0; u16 partCount1 = 0; - if(usb0) - partCount0 = usb0->GetPartitionCount(); - if(usb1) - partCount1 = usb1->GetPartitionCount(); + partCount0 = usb0.GetPartitionCount(); + //if(usb1) + // partCount1 = usb1->GetPartitionCount(); return partCount0+partCount1; } wbfs_t * DeviceHandler::GetWbfsHandle(int dev) { - if(dev == SD && sd) - return sd->GetWbfsHandle(0); - else if(dev >= USB1 && dev <= USB8 && usb0) - return usb0->GetWbfsHandle(dev-USB1); - else if(dev >= USB1 && dev <= USB8 && usb1) - return usb1->GetWbfsHandle(dev-USB1); + if(dev == SD) + return sd.GetWbfsHandle(0); + else if(dev >= USB1 && dev <= USB8) + return usb0.GetWbfsHandle(dev-USB1); + //else if(dev >= USB1 && dev <= USB8 && usb1) + // return usb1->GetWbfsHandle(dev-USB1); return NULL; } @@ -299,11 +273,11 @@ s32 DeviceHandler::OpenWBFS(int dev) char *partition = (char *)DeviceName[dev]; if(dev == SD && IsInserted(dev)) - part_lba = sd->GetLBAStart(dev); + part_lba = sd.GetLBAStart(dev); else if(dev >= USB1 && dev <= USB8 && IsInserted(dev)) { part_idx = dev; - part_lba = usb0->GetLBAStart(dev - USB1); + part_lba = usb0.GetLBAStart(dev - USB1); } else return -1; @@ -314,10 +288,9 @@ s32 DeviceHandler::OpenWBFS(int dev) int DeviceHandler::PartitionToUSBPort(int part) { u16 partCount0 = 0; - if(usb0) - partCount0 = usb0->GetPartitionCount(); - - if(!usb0 || part >= partCount0) + //if(usb0) + partCount0 = usb0.GetPartitionCount(); + if(part >= partCount0) return 1; else return 0; @@ -326,15 +299,15 @@ int DeviceHandler::PartitionToUSBPort(int part) int DeviceHandler::PartitionToPortPartition(int part) { u16 partCount0 = 0; - if(usb0) - partCount0 = usb0->GetPartitionCount(); + //if(usb0) + partCount0 = usb0.GetPartitionCount(); - if(!usb0 || part >= partCount0) + if(part >= partCount0) return part-partCount0; else return part; } - +/* PartitionHandle *DeviceHandler::GetUSBHandleFromPartition(int part) { if(PartitionToUSBPort(part) == 0) @@ -342,7 +315,7 @@ PartitionHandle *DeviceHandler::GetUSBHandleFromPartition(int part) else return usb1; } - +*/ void DeviceHandler::WaitForDevice(const DISC_INTERFACE *Handle) { if(Handle == NULL) @@ -363,15 +336,15 @@ bool DeviceHandler::MountDevolution(int CurrentPartition) /* We need to wait for the device to get ready for a remount */ WaitForDevice(handle); /* Only mount the partition we need */ - OGC_Device = new PartitionHandle(handle); - return OGC_Device->Mount(NewPartition, DeviceName[CurrentPartition], true); + OGC_Device.SetDevice(handle); + return OGC_Device.Mount(NewPartition, DeviceName[CurrentPartition], true); } void DeviceHandler::UnMountDevolution(int CurrentPartition) { int NewPartition = (CurrentPartition == SD ? CurrentPartition : CurrentPartition - 1); - OGC_Device->UnMount(NewPartition); - delete OGC_Device; + OGC_Device.UnMount(NewPartition); + OGC_Device.Cleanup(); } bool DeviceHandler::UsablePartitionMounted() diff --git a/source/devicemounter/DeviceHandler.hpp b/source/devicemounter/DeviceHandler.hpp index 6b4f6112..601d5601 100644 --- a/source/devicemounter/DeviceHandler.hpp +++ b/source/devicemounter/DeviceHandler.hpp @@ -77,21 +77,16 @@ public: bool MountAllUSB(); bool MountUSBPort1(); - bool SD_Inserted() { if(sd) return sd->IsInserted(); return false; } - bool USB0_Inserted() { if(usb0) return usb0->IsInserted(); return false; } - bool USB1_Inserted() { if(usb1) return usb1->IsInserted(); return false; } + bool SD_Inserted() { return sd.IsInserted(); } + bool USB0_Inserted() { return usb0.IsInserted(); } bool UsablePartitionMounted(); bool PartitionUsableForNandEmu(int Partition); void WaitForDevice(const DISC_INTERFACE *Handle); - void UnMountSD() { if(sd) delete sd; sd = NULL; } + void UnMountSD() { sd.UnMountAll(); } void UnMountUSB(int pos); void UnMountAllUSB(); - PartitionHandle * GetSDHandle() const { return sd; } - PartitionHandle * GetUSB0Handle() const { return usb0; } - PartitionHandle * GetUSB1Handle() const { return usb1; } - PartitionHandle * GetUSBHandleFromPartition(int part); const DISC_INTERFACE *GetUSB0Interface() { return &__io_usbstorage2_port0; } const DISC_INTERFACE *GetUSB1Interface() { return &__io_usbstorage2_port1; } @@ -112,13 +107,10 @@ public: private: bool MountUSB(int part); - PartitionHandle *sd; - PartitionHandle *gca; - PartitionHandle *gcb; - PartitionHandle *usb0; - PartitionHandle *usb1; + PartitionHandle sd; + PartitionHandle usb0; /* Special Devolution Stuff */ - PartitionHandle *OGC_Device; + PartitionHandle OGC_Device; }; extern DeviceHandler DeviceHandle; diff --git a/source/devicemounter/PartitionHandle.cpp b/source/devicemounter/PartitionHandle.cpp index 385ab379..2db0f48c 100644 --- a/source/devicemounter/PartitionHandle.cpp +++ b/source/devicemounter/PartitionHandle.cpp @@ -74,30 +74,38 @@ static inline const char *PartFromType(int type) } } -PartitionHandle::PartitionHandle(const DISC_INTERFACE *discio) - : interface(discio) +void PartitionHandle::Init() { + interface = NULL; +} + +void PartitionHandle::SetDevice(const DISC_INTERFACE *discio) +{ + Cleanup(); + interface = discio; + // Sanity check - if (!interface) + if(!interface) return; // Start the device and check that it is inserted - if (!interface->startup()) + if(!interface->startup()) return; - if (!interface->isInserted()) + if(!interface->isInserted()) return; FindPartitions(); } -PartitionHandle::~PartitionHandle() +void PartitionHandle::Cleanup() { - UnMountAll(); - - //shutdown device - if(!neek2o()) + UnMountAll(); + if(interface != NULL) interface->shutdown(); + interface = NULL; + PartitionList.clear(); + MountNameList.clear(); } bool PartitionHandle::IsMounted(int pos) diff --git a/source/devicemounter/PartitionHandle.h b/source/devicemounter/PartitionHandle.h index c91b3026..ad441949 100644 --- a/source/devicemounter/PartitionHandle.h +++ b/source/devicemounter/PartitionHandle.h @@ -117,10 +117,11 @@ typedef struct _PartitionFS { class PartitionHandle { public: - //! Constructor reads the MBR and all EBRs and lists up the Partitions - PartitionHandle(const DISC_INTERFACE *discio); - //! Destructor unmounts drives - ~PartitionHandle(); + void Init(); + //! Read the MBR and all EBRs and lists up the Partitions + void SetDevice(const DISC_INTERFACE *discio); + //! Unmount drives + void Cleanup(); //! Is Drive inserted bool IsInserted() { if(!interface) return false; else return interface->isInserted(); }; //! Is the partition Mounted diff --git a/source/gui/gcvid.cpp b/source/gui/gcvid.cpp index 3d8a668f..6fe2b456 100644 --- a/source/gui/gcvid.cpp +++ b/source/gui/gcvid.cpp @@ -698,13 +698,12 @@ void decodeJpeg(const u8* data, int size, VideoFrame& dest) //convert format so jpeglib understands it... int start, end; int newSize = countRequiredSize(data, size, start, end); - u8* buff = new u8[newSize]; + u8 *buff = (u8*)MEM2_alloc(newSize); convertToRealJpeg(buff, data, size, start, end); //...and feed it to jpeglib decodeRealJpeg(buff, newSize, dest); - - delete [] buff; + MEM2_free(buff); } extern "C" diff --git a/source/loader/alt_ios.cpp b/source/loader/alt_ios.cpp index ea75cc42..1278b706 100644 --- a/source/loader/alt_ios.cpp +++ b/source/loader/alt_ios.cpp @@ -83,10 +83,10 @@ bool loadIOS(int ios, bool MountDevices) WDVD_Close(); Close_Inputs(); gprintf("Reloading into IOS %i from %i...\n", ios, CurIOS); - Nand::Instance()->Patch_AHB(); //No AHBPROT for the next IOS + NandHandle.Patch_AHB(); //No AHBPROT for the next IOS ShutdownBeforeExit(); ret = IOS_ReloadIOS(ios) == 0; - Nand::Instance()->Init_ISFS(); + NandHandle.Init_ISFS(); gprintf("AHBPROT after IOS Reload: %u\n", AHBRPOT_Patched()); WDVD_Init(); } diff --git a/source/main.cpp b/source/main.cpp index 89539b7e..c8fbd364 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -33,9 +33,9 @@ int main(int argc, char **argv) gprintf(" \nWelcome to %s (%s-r%s)!\nThis is the debug output.\n", APP_NAME, APP_VERSION, SVN_REV); m_vid.init(); // Init video - Nand::Instance()->Init_ISFS(); //Just init ISFS, no patches yet MEM_init(); //Inits both mem1lo and mem2 DeviceHandle.Init(); + NandHandle.Init(); char *gameid = NULL; bool Emulator_boot = false; @@ -62,7 +62,9 @@ int main(int argc, char **argv) else if(argv[i] != NULL && strcasestr(argv[i], "EMULATOR_MAGIC") != NULL) Emulator_boot = true; } - // Load Custom IOS + /* Init ISFS */ + NandHandle.Init_ISFS(); + /* Handle (c)IOS Loading */ if(neek2o() || Sys_DolphinMode()) { iosOK = true; diff --git a/source/menu/menu.cpp b/source/menu/menu.cpp index fbd1b713..45e83724 100644 --- a/source/menu/menu.cpp +++ b/source/menu/menu.cpp @@ -143,12 +143,13 @@ CMenu::CMenu() m_wbf2_font = NULL; m_current_view = COVERFLOW_USB; m_Emulator_boot = false; - m_gameSound.SetVoice(1); m_music_info = true; } void CMenu::init() { + SoundHandle.Init(); + m_gameSound.SetVoice(1); const char *drive = "empty"; const char *check = "empty"; struct stat dummy; @@ -497,7 +498,7 @@ void CMenu::cleanup() MusicPlayer.Cleanup(); m_cameraSound.release(); ClearGameSoundThreadStack(); - SoundHandler::DestroyInstance(); + SoundHandle.Cleanup(); soundDeinit(); m_vid.cleanup(); @@ -2138,12 +2139,12 @@ bool CMenu::_loadChannelList(void) { char basepath[64]; snprintf(basepath, sizeof(basepath), "%s:%s", DeviceName[currentPartition], emuPath.c_str()); - Nand::Instance()->PreNandCfg(basepath, m_cfg.getBool("NAND", "real_nand_miis", false), m_cfg.getBool("NAND", "real_nand_config", false)); + NandHandle.PreNandCfg(basepath, m_cfg.getBool("NAND", "real_nand_miis", false), m_cfg.getBool("NAND", "real_nand_config", false)); first = false; } string nandpath = sfmt("%s:%s/", DeviceName[currentPartition], emuPath.empty() ? "" : emuPath.c_str()); - Nand::Instance()->Disable_Emu(); + NandHandle.Disable_Emu(); if(!disable_emu) { MusicPlayer.Stop(); @@ -2153,9 +2154,9 @@ bool CMenu::_loadChannelList(void) DeviceHandle.UnMount(currentPartition); - Nand::Instance()->Init(emuPath.c_str(), currentPartition, disable_emu); - if(Nand::Instance()->Enable_Emu() < 0) - Nand::Instance()->Disable_Emu(); + NandHandle.SetPaths(emuPath.c_str(), currentPartition, disable_emu); + if(NandHandle.Enable_Emu() < 0) + NandHandle.Disable_Emu(); gprintf("Using path: \"%s\" for NAND emulation\n", nandpath.c_str()); } @@ -2163,7 +2164,7 @@ bool CMenu::_loadChannelList(void) if(!DeviceHandle.IsInserted(currentPartition)) DeviceHandle.Mount(currentPartition); - if(Nand::Instance()->EmulationEnabled() || disable_emu) + if(NandHandle.EmulationEnabled() || disable_emu) { string cacheDir; if(!disable_emu) @@ -2184,10 +2185,10 @@ bool CMenu::_loadList(void) { m_cf.clear(); if((m_current_view == COVERFLOW_CHANNEL && m_cfg.getBool("NAND", "disable", true)) - || (m_current_view != COVERFLOW_CHANNEL && Nand::Instance()->EmulationEnabled())) + || (m_current_view != COVERFLOW_CHANNEL && NandHandle.EmulationEnabled())) { MusicPlayer.Stop(); - Nand::Instance()->Disable_Emu(); + NandHandle.Disable_Emu(); _TempLoadIOS(IOS_TYPE_NORMAL_IOS); } gprintf("Switching Views\n"); diff --git a/source/menu/menu_config4.cpp b/source/menu/menu_config4.cpp index 708a67fc..38f6e459 100644 --- a/source/menu/menu_config4.cpp +++ b/source/menu/menu_config4.cpp @@ -76,7 +76,7 @@ void CMenu::_showConfig4(void) wstringEx channelName = m_loc.getWString(m_curLanguage, "disabled", L"Disabled"); - Nand::Instance()->Disable_Emu(); + NandHandle.Disable_Emu(); ChannelHandle.Init(0, m_loc.getString(m_curLanguage, "gametdb_code", "EN"), true); amountOfChannels = ChannelHandle.Count(); @@ -146,7 +146,7 @@ int CMenu::_config4(void) } } if(!neek2o() && m_current_view == COVERFLOW_CHANNEL && m_cfg.getBool("NAND", "disable", true) == false) - Nand::Instance()->Enable_Emu(); + NandHandle.Enable_Emu(); _hideConfig4(); return change; } diff --git a/source/menu/menu_download.cpp b/source/menu/menu_download.cpp index 439eb78e..e779949d 100644 --- a/source/menu/menu_download.cpp +++ b/source/menu/menu_download.cpp @@ -427,7 +427,7 @@ s32 CMenu::_networkComplete(s32 ok, void *usrData) int CMenu::_initNetwork() { - Nand::Instance()->Disable_Emu(); + NandHandle.Disable_Emu(); while (net_get_status() == -EBUSY || m_thrdNetwork) {}; // Async initialization may be busy, wait to see if it succeeds. if (m_networkInit) return 0; if (!_isNetworkAvailable()) return -2; diff --git a/source/menu/menu_game.cpp b/source/menu/menu_game.cpp index d5b655d7..794e10d7 100644 --- a/source/menu/menu_game.cpp +++ b/source/menu/menu_game.cpp @@ -247,24 +247,20 @@ static inline int loopNum(int i, int s) } -static void _extractBannerTitle(Banner *bnr, int language) +static void _extractBannerTitle(int language) { - if (bnr != NULL) - { - memset(banner_title, 0, 84); - bnr->GetName(banner_title, language); - } + memset(banner_title, 0, 84); + CurrentBanner.GetName(banner_title, language); } -static Banner *_extractChannelBnr(const u64 chantitle) +static void _extractChannelBnr(const u64 chantitle) { - return ChannelHandle.GetBanner(chantitle); + ChannelHandle.GetBanner(chantitle); } -static Banner *_extractBnr(dir_discHdr *hdr) +static void _extractBnr(dir_discHdr *hdr) { u32 size = 0; - Banner *banner = NULL; DeviceHandle.OpenWBFS(currentPartition); wbfs_disc_t *disc = WBFS_OpenDisc((u8 *) &hdr->id, (char *) hdr->path); if(disc != NULL) @@ -272,11 +268,10 @@ static Banner *_extractBnr(dir_discHdr *hdr) void *bnr = NULL; size = wbfs_extract_file(disc, (char *) "opening.bnr", &bnr); if(size > 0) - banner = new Banner((u8 *)bnr, size); + CurrentBanner.SetBanner((u8*)bnr, size); WBFS_CloseDisc(disc); } WBFS_Close(); - return banner; } static int GetLanguage(const char *lang) @@ -613,22 +608,22 @@ void CMenu::_game(bool launch) _showWaitMessage(); exitHandler(PRIILOADER_DEF); //Making wiiflow ready to boot something + CurrentBanner.ClearBanner(); + // Get banner_title + if(hdr->type == TYPE_CHANNEL) + _extractChannelBnr(chantitle); + else if(hdr->type == TYPE_WII_GAME) + _extractBnr(hdr); + if(CurrentBanner.IsValid()) + { + _extractBannerTitle(GetLanguage(m_loc.getString(m_curLanguage, "gametdb_code", "EN").c_str())); + CurrentBanner.ClearBanner(); + } if(hdr->type != TYPE_HOMEBREW && hdr->type != TYPE_PLUGIN) { - // Get banner_title - Banner *banner = hdr->type == TYPE_CHANNEL ? _extractChannelBnr(chantitle) : (hdr->type == TYPE_WII_GAME ? _extractBnr(hdr) : NULL); - if(banner != NULL) - { - if(banner->IsValid()) - _extractBannerTitle(banner, GetLanguage(m_loc.getString(m_curLanguage, "gametdb_code", "EN").c_str())); - delete banner; - } - banner = NULL; - if(Playlog_Update((char *)hdr->id, banner_title) < 0) Playlog_Delete(); } - gprintf("Launching game %s\n", (char *)hdr->id); _launch(hdr); @@ -777,7 +772,7 @@ void CMenu::directlaunch(const char *GameID) void CMenu::_launch(dir_discHdr *hdr) { /* No need to do that separate */ - Nand::Instance()->Disable_Emu(); + NandHandle.Disable_Emu(); /* Lets boot that shit */ if(hdr->type == TYPE_WII_GAME) _launchGame(hdr, false); @@ -1097,11 +1092,11 @@ void CMenu::_launchChannel(dir_discHdr *hdr) while(1); } DeviceHandle.UnMount(emuPartition); - Nand::Instance()->Init(emuPath.c_str(), emuPartition, false); - Nand::Instance()->Enable_Emu(); + NandHandle.SetPaths(emuPath.c_str(), emuPartition, false); + NandHandle.Enable_Emu(); } gameIOS = ChannelHandle.GetRequestedIOS(gameTitle); - Nand::Instance()->Disable_Emu(); + NandHandle.Disable_Emu(); if(_loadIOS(gameIOS, WII_Launch ? gameIOS : userIOS, id) == LOAD_IOS_FAILED) Sys_Exit(); if((CurrentIOS.Type == IOS_TYPE_D2X || neek2o()) && rtrn != NULL && strlen(rtrn) == 4) @@ -1128,14 +1123,14 @@ void CMenu::_launchChannel(dir_discHdr *hdr) { if(NAND_Emu) { - Nand::Instance()->Init(emuPath.c_str(), emuPartition, false); + NandHandle.SetPaths(emuPath.c_str(), emuPartition, false); if(emulate_mode == 1) - Nand::Instance()->Set_FullMode(true); + NandHandle.Set_FullMode(true); else - Nand::Instance()->Set_FullMode(false); - if(Nand::Instance()->Enable_Emu() < 0) + NandHandle.Set_FullMode(false); + if(NandHandle.Enable_Emu() < 0) { - Nand::Instance()->Disable_Emu(); + NandHandle.Disable_Emu(); error(_t("errgame5", L"Enabling emu failed!")); Sys_Exit(); } @@ -1272,8 +1267,8 @@ void CMenu::_launchGame(dir_discHdr *hdr, bool dvd) else { emuPartition = _FindEmuPart(&emuPath, 1, true); - Nand::Instance()->CreatePath("%s:/wiiflow", DeviceName[emuPartition]); - Nand::Instance()->CreatePath("%s:/wiiflow/nandemu", DeviceName[emuPartition]); + NandHandle.CreatePath("%s:/wiiflow", DeviceName[emuPartition]); + NandHandle.CreatePath("%s:/wiiflow/nandemu", DeviceName[emuPartition]); } } @@ -1291,14 +1286,14 @@ void CMenu::_launchGame(dir_discHdr *hdr, bool dvd) m_forceext = false; _hideWaitMessage(); if(!_AutoExtractSave(id)) - Nand::Instance()->CreateTitleTMD(basepath, hdr); + NandHandle.CreateTitleTMD(basepath, hdr); _showWaitMessage(); } } if(emulate_mode > 2) { - Nand::Instance()->CreateConfig(basepath); - Nand::Instance()->Do_Region_Change(id); + NandHandle.CreateConfig(basepath); + NandHandle.Do_Region_Change(id); } } @@ -1375,18 +1370,18 @@ void CMenu::_launchGame(dir_discHdr *hdr, bool dvd) } if(emulate_mode && !neek2o() && CurrentIOS.Type == IOS_TYPE_D2X) { - Nand::Instance()->Init(emuPath.c_str(), emuPartition, false); + NandHandle.SetPaths(emuPath.c_str(), emuPartition, false); DeviceHandle.UnMount(emuPartition); if(emulate_mode == 3) - Nand::Instance()->Set_RCMode(true); + NandHandle.Set_RCMode(true); else if(emulate_mode == 4) - Nand::Instance()->Set_FullMode(true); + NandHandle.Set_FullMode(true); else - Nand::Instance()->Set_FullMode(false); - if(Nand::Instance()->Enable_Emu() < 0) + NandHandle.Set_FullMode(false); + if(NandHandle.Enable_Emu() < 0) { - Nand::Instance()->Disable_Emu(); + NandHandle.Disable_Emu(); error(_t("errgame6", L"Enabling emu after reload failed!")); Sys_Exit(); } @@ -1509,9 +1504,9 @@ SmartBuf gameSoundThreadStack; u32 gameSoundThreadStackSize = (u32)32768; void CMenu::_gameSoundThread(CMenu *m) { + CurrentBanner.ClearBanner(); m->m_gameSoundHdr = m->m_cf.getHdr(); m->m_gamesound_changed = false; - if(m->m_cf.getHdr()->type == TYPE_PLUGIN) { m_banner.DeleteBanner(); @@ -1529,7 +1524,8 @@ void CMenu::_gameSoundThread(CMenu *m) u32 cached_bnr_size = 0; char cached_banner[256]; - snprintf(cached_banner, sizeof(cached_banner), "%s/%.6s.bnr", m->m_bnrCacheDir.c_str(), m->m_cf.getHdr()->id); + cached_banner[255] = '\0'; + strncpy(cached_banner, fmt("%s/%.6s.bnr", m->m_bnrCacheDir.c_str(), m->m_cf.getHdr()->id), 255); FILE *fp = fopen(cached_banner, "rb"); if(fp) { @@ -1537,7 +1533,7 @@ void CMenu::_gameSoundThread(CMenu *m) fseek(fp, 0, SEEK_END); cached_bnr_size = ftell(fp); fseek(fp, 0, SEEK_SET); - cached_bnr_file = (u8*)malloc(cached_bnr_size); + cached_bnr_file = (u8*)MEM2_alloc(cached_bnr_size); if(cached_bnr_file == NULL) { m->m_gameSound.FreeMemory(); @@ -1551,25 +1547,13 @@ void CMenu::_gameSoundThread(CMenu *m) else { char custom_banner[256]; - snprintf(custom_banner, sizeof(custom_banner), "%s/%.6s.bnr", m->m_customBnrDir.c_str(), m->m_cf.getHdr()->id); + custom_banner[255] = '\0'; + strncpy(custom_banner, fmt("%s/%.6s.bnr", m->m_customBnrDir.c_str(), m->m_cf.getHdr()->id), 255); FILE *fp = fopen(custom_banner, "rb"); if(!fp) { - snprintf(custom_banner, sizeof(custom_banner), "%s/%.3s.bnr", m->m_customBnrDir.c_str(), m->m_cf.getHdr()->id); + strncpy(custom_banner, fmt("%s/%.3s.bnr", m->m_customBnrDir.c_str(), m->m_cf.getHdr()->id), 255); fp = fopen(custom_banner, "rb"); - if(!fp && m->m_cf.getHdr()->type == TYPE_GC_GAME) - { - GC_Disc disc; - disc.init(m->m_cf.getHdr()->path); - u8 *opening_bnr = disc.GetGameCubeBanner(); - if(opening_bnr != NULL) - m_banner.CreateGCBanner(opening_bnr, m->m_wbf1_font, m->m_wbf2_font, m->m_cf.getHdr()->title); - m->m_gameSound.Load(gc_ogg, gc_ogg_size, false); - m->m_gamesound_changed = true; - m->m_gameSoundHdr = NULL; - disc.clear(); - return; - } } if(fp) { @@ -1577,7 +1561,7 @@ void CMenu::_gameSoundThread(CMenu *m) fseek(fp, 0, SEEK_END); custom_bnr_size = ftell(fp); fseek(fp, 0, SEEK_SET); - custom_bnr_file = (u8*)malloc(custom_bnr_size); + custom_bnr_file = (u8*)MEM2_alloc(custom_bnr_size); if(custom_bnr_file == NULL) { m->m_gameSound.FreeMemory(); @@ -1588,34 +1572,50 @@ void CMenu::_gameSoundThread(CMenu *m) fread(custom_bnr_file, 1, custom_bnr_size, fp); fclose(fp); } + if(!fp && m->m_cf.getHdr()->type == TYPE_GC_GAME) + { + GC_Disc disc; + disc.init(m->m_cf.getHdr()->path); + u8 *opening_bnr = disc.GetGameCubeBanner(); + if(opening_bnr != NULL) + m_banner.CreateGCBanner(opening_bnr, m->m_wbf1_font, m->m_wbf2_font, m->m_cf.getHdr()->title); + m->m_gameSound.Load(gc_ogg, gc_ogg_size, false); + m->m_gamesound_changed = true; + m->m_gameSoundHdr = NULL; + disc.clear(); + return; + } } + u32 sndSize = 0; u8 *soundBin = NULL; - - Banner *banner = cached ? new Banner(cached_bnr_file, cached_bnr_size) : - (custom ? new Banner((u8 *)custom_bnr_file, custom_bnr_size, 0, true) : - (m->m_gameSoundHdr->type == TYPE_WII_GAME ? _extractBnr(m->m_gameSoundHdr) : (m->m_gameSoundHdr->type == TYPE_CHANNEL ? - _extractChannelBnr(TITLE_ID(m->m_gameSoundHdr->settings[0],m->m_gameSoundHdr->settings[1])) : NULL))); - if(banner != NULL && banner->IsValid()) - { - m_banner.LoadBanner(banner, m->m_wbf1_font, m->m_wbf2_font); - soundBin = banner->GetFile((char *)"sound.bin", &sndSize); - } - else + if(cached) + CurrentBanner.SetBanner(cached_bnr_file, cached_bnr_size); + else if(custom) + CurrentBanner.SetBanner(custom_bnr_file, custom_bnr_size, 0, true); + else if(m->m_gameSoundHdr->type == TYPE_WII_GAME) + _extractBnr(m->m_gameSoundHdr); + else if(m->m_gameSoundHdr->type == TYPE_CHANNEL) + _extractChannelBnr(TITLE_ID(m->m_gameSoundHdr->settings[0], + m->m_gameSoundHdr->settings[1])); + if(!CurrentBanner.IsValid()) { m->m_gameSound.FreeMemory(); m_banner.DeleteBanner(); m->m_gameSoundHdr = NULL; - delete banner; + CurrentBanner.ClearBanner(); return; } - if(!custom && !cached) + if(!custom && !cached && CurrentBanner.GetBannerFileSize() > 0) { FILE *fp = fopen(cached_banner, "wb"); - fwrite(banner->GetBannerFile(), 1, banner->GetBannerFileSize(), fp); + fwrite(CurrentBanner.GetBannerFile(), 1, CurrentBanner.GetBannerFileSize(), fp); fclose(fp); } - delete banner; + m_banner.LoadBanner(m->m_wbf1_font, m->m_wbf2_font); + soundBin = CurrentBanner.GetFile((char *)"sound.bin", &sndSize); + CurrentBanner.ClearBanner(); + if(soundBin != NULL) { if(memcmp(&((IMD5Header *)soundBin)->fcc, "IMD5", 4) == 0) diff --git a/source/menu/menu_main.cpp b/source/menu/menu_main.cpp index b13d74ec..4d190052 100644 --- a/source/menu/menu_main.cpp +++ b/source/menu/menu_main.cpp @@ -153,7 +153,7 @@ void CMenu::_showMain(void) case COVERFLOW_CHANNEL: if(!m_cfg.getBool("NAND", "disable", true)) { - Nand::Instance()->Disable_Emu(); + NandHandle.Disable_Emu(); DeviceHandle.MountAll(); _hideMain(); if(!_AutoCreateNand()) @@ -176,7 +176,7 @@ void CMenu::_showMain(void) } } else if(!neek2o() && m_current_view == COVERFLOW_CHANNEL && !m_cfg.getBool("NAND", "disable", true)) - Nand::Instance()->Enable_Emu(); + NandHandle.Enable_Emu(); } void CMenu::LoadView(void) @@ -415,7 +415,7 @@ int CMenu::main(void) _showWaitMessage(); m_gameSound.Stop(); CheckGameSoundThread(); - Nand::Instance()->Disable_Emu(); + NandHandle.Disable_Emu(); /* Create Fake Header */ dir_discHdr hdr; memset(&hdr, 0, sizeof(dir_discHdr)); @@ -647,7 +647,7 @@ int CMenu::main(void) 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(); + NandHandle.Enable_Emu(); u8 limiter = 0; currentPartition = loopNum(currentPartition + 1, (int)USB8); while(!DeviceHandle.IsInserted(currentPartition) || diff --git a/source/menu/menu_nandemu.cpp b/source/menu/menu_nandemu.cpp index 08efb8f4..d5bce09e 100644 --- a/source/menu/menu_nandemu.cpp +++ b/source/menu/menu_nandemu.cpp @@ -93,7 +93,7 @@ bool CMenu::_TestEmuNand(int epart, const char *path, bool indept) int CMenu::_FindEmuPart(string *emuPath, int part, bool searchvalid) { - Nand::Instance()->Disable_Emu(); + NandHandle.Disable_Emu(); int emuPartition = -1; string tmpPath; @@ -199,7 +199,7 @@ void CMenu::_enableNandEmu(bool fromconfig) 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(); + NandHandle.Enable_Emu(); u8 limiter = 0; s8 direction = m_btnMgr.selected(m_configBtnPartitionP) ? 1 : -1; if (!fromconfig) @@ -548,14 +548,14 @@ int CMenu::_AutoExtractSave(string gameId) { char basepath[MAX_FAT_PATH]; snprintf(basepath, sizeof(basepath), "%s:%s", DeviceName[emuPartition], emuPath.c_str()); - Nand::Instance()->CreatePath("%s/import", basepath); - Nand::Instance()->CreatePath("%s/meta", basepath); - Nand::Instance()->CreatePath("%s/shared1", basepath); - Nand::Instance()->CreatePath("%s/shared2", basepath); - Nand::Instance()->CreatePath("%s/sys", basepath); - Nand::Instance()->CreatePath("%s/title", basepath); - Nand::Instance()->CreatePath("%s/ticket", basepath); - Nand::Instance()->CreatePath("%s/tmp", basepath); + NandHandle.CreatePath("%s/import", basepath); + NandHandle.CreatePath("%s/meta", basepath); + NandHandle.CreatePath("%s/shared1", basepath); + NandHandle.CreatePath("%s/shared2", basepath); + NandHandle.CreatePath("%s/sys", basepath); + NandHandle.CreatePath("%s/title", basepath); + NandHandle.CreatePath("%s/ticket", basepath); + NandHandle.CreatePath("%s/tmp", basepath); _hideNandEmu(); return 0; } @@ -722,11 +722,11 @@ int CMenu::_NandFlasher(void *obj) snprintf(source, sizeof(source), "%s:%s/title/00010004/%08x", DeviceName[emuPartition], emuPath.c_str(), flashID); snprintf(dest, sizeof(dest), "/title/00010004/%08x", flashID); } - Nand::Instance()->ResetCounters(); + NandHandle.ResetCounters(); m.m_nandexentry = 1; - m.m_dumpsize = Nand::Instance()->CalcFlashSize(source, CMenu::_ShowProgress, obj); + m.m_dumpsize = NandHandle.CalcFlashSize(source, CMenu::_ShowProgress, obj); m_nandext = true; - Nand::Instance()->FlashToNAND(source, dest, CMenu::_ShowProgress, obj); + NandHandle.FlashToNAND(source, dest, CMenu::_ShowProgress, obj); m.m_thrdWorking = false; LWP_MutexLock(m.m_mutex); @@ -748,7 +748,7 @@ int CMenu::_NandDumper(void *obj) m.m_filesdone = 0; m.m_foldersdone = 0; - Nand::Instance()->ResetCounters(); + NandHandle.ResetCounters(); if(m.m_current_view == COVERFLOW_CHANNEL) m.m_partRequest = m.m_cfg.getInt("NAND", "partition", -1); @@ -772,9 +772,9 @@ int CMenu::_NandDumper(void *obj) if(m_fulldump) { - m.m_dumpsize = Nand::Instance()->CalcDumpSpace("/", CMenu::_ShowProgress, obj); + m.m_dumpsize = NandHandle.CalcDumpSpace("/", CMenu::_ShowProgress, obj); m_nandext = true; - Nand::Instance()->DoNandDump("/", basepath, CMenu::_ShowProgress, obj); + NandHandle.DoNandDump("/", basepath, CMenu::_ShowProgress, obj); } else { @@ -818,7 +818,7 @@ int CMenu::_NandDumper(void *obj) if(!m._checkSave(saveList[i], true)) snprintf(source, sizeof(source), "/title/00010004/%08x", savePath); - m.m_dumpsize = Nand::Instance()->CalcDumpSpace(source, CMenu::_ShowProgress, obj); + m.m_dumpsize = NandHandle.CalcDumpSpace(source, CMenu::_ShowProgress, obj); } for(u32 i = 0; i < saveList.size() && !m.m_thrdStop; ++i) { @@ -829,7 +829,7 @@ int CMenu::_NandDumper(void *obj) snprintf(source, sizeof(source), "/title/00010004/%08x", savePath); m_nandext = true; - Nand::Instance()->DoNandDump(source, basepath, CMenu::_ShowProgress, obj); + NandHandle.DoNandDump(source, basepath, CMenu::_ShowProgress, obj); } } diff --git a/source/menu/menu_wbfs.cpp b/source/menu/menu_wbfs.cpp index 63ff3f97..579eb197 100644 --- a/source/menu/menu_wbfs.cpp +++ b/source/menu/menu_wbfs.cpp @@ -436,9 +436,9 @@ bool CMenu::_wbfsOp(CMenu::WBFS_OP op) m_cf.stopCoverLoader(); _stopSounds(); MusicPlayer.Cleanup(); - SoundHandler::DestroyInstance(); + SoundHandle.Cleanup(); soundDeinit(); - Nand::Instance()->Disable_Emu(); + NandHandle.Disable_Emu(); LWP_CreateThread(&thread, (void *(*)(void *))CMenu::_GCcopyGame, (void *)this, 0, 8 * 1024, 64); break; } diff --git a/source/music/BNSDecoder.cpp b/source/music/BNSDecoder.cpp index 817e6684..2be65f41 100644 --- a/source/music/BNSDecoder.cpp +++ b/source/music/BNSDecoder.cpp @@ -28,6 +28,7 @@ #include #include #include "BNSDecoder.hpp" +#include "memory/mem2.hpp" SoundBlock DecodefromBNS(const u8 *buffer, u32 size); @@ -69,7 +70,7 @@ BNSDecoder::~BNSDecoder() void BNSDecoder::OpenFile() { - u8 * tempbuff = new (std::nothrow) u8[file_fd->size()]; + u8 *tempbuff = (u8*)MEM2_alloc(file_fd->size()); if(!tempbuff) { CloseFile(); @@ -86,20 +87,18 @@ void BNSDecoder::OpenFile() else { CloseFile(); + MEM2_free(tempbuff); return; } } SoundData = DecodefromBNS(tempbuff, done); + MEM2_free(tempbuff); if(SoundData.buffer == NULL) { CloseFile(); return; } - - delete [] tempbuff; - tempbuff = NULL; - Decode(); } diff --git a/source/music/MusicPlayer.cpp b/source/music/MusicPlayer.cpp index 679638c7..dacb40b5 100644 --- a/source/music/MusicPlayer.cpp +++ b/source/music/MusicPlayer.cpp @@ -103,7 +103,7 @@ bool Musicplayer::PosFromPrevFile() return false; MusicFile.Load((*CurrentFileName).c_str()); - SoundHandler::Instance()->Decoder(MusicFile.GetVoice())->Seek(CurrentPosition); + SoundHandle.Decoder(MusicFile.GetVoice())->Seek(CurrentPosition); SetVolume(CurrentVolume); MusicFile.Play(); CurrentPosition = 0; @@ -117,7 +117,7 @@ void Musicplayer::Stop() if(!MusicFile.IsPlaying()) return; MusicFile.Pause(); - CurrentPosition = SoundHandler::Instance()->Decoder(MusicFile.GetVoice())->Tell(); + CurrentPosition = SoundHandle.Decoder(MusicFile.GetVoice())->Tell(); MusicFile.FreeMemory(); MusicStopped = true; } diff --git a/source/music/SoundHandler.cpp b/source/music/SoundHandler.cpp index a0f34f3f..f8d9c82d 100644 --- a/source/music/SoundHandler.cpp +++ b/source/music/SoundHandler.cpp @@ -34,9 +34,9 @@ #include "gecko/gecko.h" #include "memory/mem2.hpp" -SoundHandler * SoundHandler::instance = NULL; +SoundHandler SoundHandle; -SoundHandler::SoundHandler() +void SoundHandler::Init() { Decoding = false; ExitRequested = false; @@ -51,7 +51,7 @@ SoundHandler::SoundHandler() gprintf("SHND: Running sound thread\n"); } -SoundHandler::~SoundHandler() +void SoundHandler::Cleanup() { gprintf("SHND: Stopping sound thread\n"); @@ -69,22 +69,6 @@ SoundHandler::~SoundHandler() gprintf("SHND: Stopped sound thread\n"); } -SoundHandler * SoundHandler::Instance() -{ - if (instance == NULL) - instance = new SoundHandler(); - return instance; -} - -void SoundHandler::DestroyInstance() -{ - if(instance) - { - delete instance; - instance = NULL; - } -} - void SoundHandler::AddDecoder(int voice, const char * filepath) { if(voice < 0 || voice >= MAX_DECODERS) diff --git a/source/music/SoundHandler.hpp b/source/music/SoundHandler.hpp index 664d181f..43224049 100644 --- a/source/music/SoundHandler.hpp +++ b/source/music/SoundHandler.hpp @@ -35,34 +35,32 @@ class SoundHandler { public: - static SoundHandler * Instance(); - static void DestroyInstance(); + void Init(); + void Cleanup(); - void AddDecoder(int voice, const char * filepath); - void AddDecoder(int voice, const u8 * snd, int len); + void AddDecoder(int voice, const char *filepath); + void AddDecoder(int voice, const u8 *snd, int len); void RemoveDecoder(int voice); - void DestroyDecoder(SoundDecoder * decoder); + void DestroyDecoder(SoundDecoder *decoder); - SoundDecoder * Decoder(int i) { return ((i < 0 || i >= MAX_DECODERS) ? NULL : DecoderList[i]); }; + SoundDecoder *Decoder(int i) { return ((i < 0 || i >= MAX_DECODERS) ? NULL : DecoderList[i]); }; void ThreadSignal() { LWP_ThreadSignal(ThreadQueue); }; bool IsDecoding() { return Decoding; }; protected: - SoundHandler(); - ~SoundHandler(); - static void * UpdateThread(void *arg); + static void *UpdateThread(void *arg); void InternalSoundUpdates(); void ClearDecoderList(); - SoundDecoder * GetSoundDecoder(const char * filepath); - SoundDecoder * GetSoundDecoder(const u8 * sound, int length); + SoundDecoder *GetSoundDecoder(const char *filepath); + SoundDecoder *GetSoundDecoder(const u8 *sound, int length); - static SoundHandler * instance; - u8 * ThreadStack; + u8 *ThreadStack; lwp_t SoundThread; lwpq_t ThreadQueue; bool Decoding; bool ExitRequested; - SoundDecoder * DecoderList[MAX_DECODERS]; + SoundDecoder *DecoderList[MAX_DECODERS]; }; +extern SoundHandler SoundHandle; #endif diff --git a/source/music/gui_sound.cpp b/source/music/gui_sound.cpp index 18e22055..1ccc495f 100644 --- a/source/music/gui_sound.cpp +++ b/source/music/gui_sound.cpp @@ -58,7 +58,7 @@ static inline int GetFirstUnusedVoice() extern "C" void SoundCallback(s32 voice) { - SoundDecoder *decoder = SoundHandler::Instance()->Decoder(voice); + SoundDecoder *decoder = SoundHandle.Decoder(voice); if(!decoder) return; @@ -67,13 +67,13 @@ extern "C" void SoundCallback(s32 voice) if(ASND_AddVoice(voice, decoder->GetBuffer(), decoder->GetBufferSize()) == SND_OK) { decoder->LoadNext(); - SoundHandler::Instance()->ThreadSignal(); + SoundHandle.ThreadSignal(); } } else if(decoder->IsEOF()) ASND_StopVoice(voice); else - SoundHandler::Instance()->ThreadSignal(); + SoundHandle.ThreadSignal(); } GuiSound::GuiSound() @@ -143,7 +143,7 @@ void GuiSound::FreeMemory() // Prevent reinitialization of SoundHandler since we're exiting if(!Sys_Exiting()) - SoundHandler::Instance()->RemoveDecoder(this->voice); + SoundHandle.RemoveDecoder(this->voice); if(allocated && sound != NULL) free(sound); @@ -173,9 +173,9 @@ bool GuiSound::Load(const char * filepath) fread(&magic, 1, 4, f); fclose(f); - SoundHandler::Instance()->AddDecoder(this->voice, filepath); + SoundHandle.AddDecoder(this->voice, filepath); //gprintf("gui_sound.cpp: Loading %s using voice %d\n", filepath, this->voice); - SoundDecoder * decoder = SoundHandler::Instance()->Decoder(this->voice); + SoundDecoder *decoder = SoundHandle.Decoder(this->voice); if(!decoder) { gprintf("gui_sound.cpp: No Decoder!\n"); @@ -185,7 +185,7 @@ bool GuiSound::Load(const char * filepath) if(!decoder->IsBufferReady()) { gprintf("gui_sound.cpp: Buffer not ready!\n"); - SoundHandler::Instance()->RemoveDecoder(this->voice); + SoundHandle.RemoveDecoder(this->voice); return false; } @@ -209,11 +209,11 @@ bool GuiSound::Load(const u8 * snd, u32 len, bool isallocated) length = len; allocated = isallocated; - SoundHandler::Instance()->AddDecoder(this->voice, sound, length); - SoundDecoder *decoder = SoundHandler::Instance()->Decoder(this->voice); + SoundHandle.AddDecoder(this->voice, sound, length); + SoundDecoder *decoder = SoundHandle.Decoder(this->voice); if(!decoder || !decoder->IsBufferReady()) { - SoundHandler::Instance()->RemoveDecoder(this->voice); + SoundHandle.RemoveDecoder(this->voice); return false; } @@ -270,7 +270,7 @@ void GuiSound::Play(int vol, bool restart) if((IsPlaying() && !restart) || this->voice < 0 || this->voice >= 16) return; - SoundDecoder *decoder = SoundHandler::Instance()->Decoder(this->voice); + SoundDecoder *decoder = SoundHandle.Decoder(this->voice); if(!decoder) return; @@ -285,7 +285,7 @@ void GuiSound::Play(int vol, bool restart) u8 * curbuffer = decoder->GetBuffer(); int bufsize = decoder->GetBufferSize(); decoder->LoadNext(); - SoundHandler::Instance()->ThreadSignal(); + SoundHandle.ThreadSignal(); ASND_SetVoice(this->voice, decoder->GetFormat(), decoder->GetSampleRate(), 0, curbuffer, bufsize, vol, vol, SoundCallback); } @@ -303,14 +303,14 @@ void GuiSound::Stop() ASND_StopVoice(this->voice); - SoundDecoder *decoder = SoundHandler::Instance()->Decoder(this->voice); + SoundDecoder *decoder = SoundHandle.Decoder(this->voice); if(!decoder) return; decoder->ClearBuffer(); Rewind(); - SoundHandler::Instance()->ThreadSignal(); + SoundHandle.ThreadSignal(); } void GuiSound::Pause() @@ -357,7 +357,7 @@ void GuiSound::SetLoop(u8 l) { loop = l; - SoundDecoder *decoder = SoundHandler::Instance()->Decoder(this->voice); + SoundDecoder *decoder = SoundHandle.Decoder(this->voice); if(!decoder) return; @@ -366,7 +366,7 @@ void GuiSound::SetLoop(u8 l) void GuiSound::Rewind() { - SoundDecoder *decoder = SoundHandler::Instance()->Decoder(this->voice); + SoundDecoder *decoder = SoundHandle.Decoder(this->voice); if(!decoder) return; diff --git a/source/unzip/ZipFile.cpp b/source/unzip/ZipFile.cpp index f6072aab..5b9f2f66 100644 --- a/source/unzip/ZipFile.cpp +++ b/source/unzip/ZipFile.cpp @@ -36,6 +36,7 @@ #include "ZipFile.h" #include "fileOps/fileOps.h" +#include "memory/mem2.hpp" ZipFile::ZipFile(const char *filepath) { @@ -61,10 +62,9 @@ bool ZipFile::ExtractAll(const char *dest) bool Stop = false; - u32 blocksize = 1024 * 50; - u8 *buffer = new u8[blocksize]; - - if(!buffer) + u32 blocksize = 1024*50; + u8 *buffer = (u8*)MEM2_memalign(32, blocksize); + if(buffer == NULL) return false; char writepath[MAXPATHLEN]; @@ -126,8 +126,7 @@ bool ZipFile::ExtractAll(const char *dest) if(unzGoToNextFile(File) != UNZ_OK) Stop = true; } - - delete[] buffer; + MEM2_free(buffer); buffer = NULL; return true;