diff --git a/Makefile b/Makefile index c10b3119..0aa924fd 100644 --- a/Makefile +++ b/Makefile @@ -33,6 +33,7 @@ SOURCES := source \ source/menu \ source/music \ source/network \ + source/plugin \ source/unzip \ source/xml \ source/wstringEx \ @@ -57,6 +58,7 @@ INCLUDES := source \ source/menu \ source/music \ source/network \ + source/plugin \ source/unzip \ source/wstringEx \ source/xml diff --git a/data/sounds/gba.ogg b/data/sounds/gba.ogg deleted file mode 100644 index 45137c42..00000000 Binary files a/data/sounds/gba.ogg and /dev/null differ diff --git a/data/sounds/nes.ogg b/data/sounds/nes.ogg deleted file mode 100644 index c2660554..00000000 Binary files a/data/sounds/nes.ogg and /dev/null differ diff --git a/data/sounds/snes.ogg b/data/sounds/snes.ogg deleted file mode 100644 index efb3d78d..00000000 Binary files a/data/sounds/snes.ogg and /dev/null differ diff --git a/source/menu/menu.cpp b/source/menu/menu.cpp index eed498e4..33a9eb25 100644 --- a/source/menu/menu.cpp +++ b/source/menu/menu.cpp @@ -336,6 +336,8 @@ void CMenu::init(void) m_themeDataDir = sfmt("%s/%s", m_themeDir.c_str(), themeName.c_str()); m_theme.load(sfmt("%s.ini", m_themeDataDir.c_str()).c_str()); + m_plugin.init(m_pluginsDir); + u8 defaultMenuLanguage = 7; //English switch (CONF_GetLanguage()) { @@ -458,7 +460,9 @@ void CMenu::cleanup(bool ios_reload) { SMART_FREE(m_cameraSound); } - + + m_plugin.Cleanup(); + MusicPlayer::DestroyInstance(); SoundHandler::DestroyInstance(); soundDeinit(); @@ -1954,7 +1958,6 @@ bool CMenu::_loadEmuList() DIR *pdir; struct dirent *pent; - m_plugin.load(fmt("%s/plugins.ini", m_pluginsDir.c_str())); pdir = opendir(m_pluginsDir.c_str()); safe_vector emuList; @@ -1973,17 +1976,18 @@ bool CMenu::_loadEmuList() m_gameList.Load(sfmt("%s:/%s", DeviceName[currentPartition], m_gameList.m_plugin.getString("PLUGIN","romDir","").c_str()), m_gameList.m_plugin.getString("PLUGIN","fileTypes","").c_str(), m_cfg.getString("EMULATOR", "lastlanguage", "EN").c_str()); for(safe_vector::iterator tmp_itr = m_gameList.begin(); tmp_itr != m_gameList.end(); tmp_itr++) emuList.push_back(*tmp_itr); - m_plugin.setString("GENERAL",m_gameList.m_plugin.getString("PLUGIN","magic","").c_str(),m_gameList.m_plugin.getString("PLUGIN","dolFile","").c_str()); + m_plugin.AddPlugin(m_gameList.m_plugin); } m_gameList.m_plugin.unload(); } } closedir(pdir); - m_plugin.save(true); m_gameList.clear(); for(safe_vector::iterator tmp_itr = emuList.begin(); tmp_itr != emuList.end(); tmp_itr++) m_gameList.push_back(*tmp_itr); emuList.clear(); + //If we return to the coverflow before wiiflow quit we dont need to reload plugins + m_plugin.EndAdd(); m_cfg.setString("EMULATOR", "lastlanguage", m_loc.getString(m_curLanguage, "gametdb_code", "EN")); m_cfg.save(); diff --git a/source/menu/menu.hpp b/source/menu/menu.hpp index 02b35b20..fc387b0f 100644 --- a/source/menu/menu.hpp +++ b/source/menu/menu.hpp @@ -7,6 +7,7 @@ #include "safe_vector.hpp" #include "cachedlist.hpp" +#include "plugin/plugin.hpp" #include #include "gui_sound.h" @@ -66,7 +67,7 @@ private: Config m_theme; Config m_titles; Config m_version; - Config m_plugin; + Plugin m_plugin; Channels m_channels; safe_vector m_homebrewArgs; SmartBuf m_base_font; diff --git a/source/menu/menu_game.cpp b/source/menu/menu_game.cpp index 0d89061c..d0118fdc 100644 --- a/source/menu/menu_game.cpp +++ b/source/menu/menu_game.cpp @@ -52,15 +52,6 @@ extern const u8 deletes_png[]; extern const u8 gc_ogg[]; extern const u32 gc_ogg_size; -extern const u8 nes_ogg[]; -extern const u32 nes_ogg_size; - -extern const u8 snes_ogg[]; -extern const u32 snes_ogg_size; - -extern const u8 gba_ogg[]; -extern const u32 gba_ogg_size; - extern u32 sector_size; extern int mainIOS; static u64 sm_title_id[8] ATTRIBUTE_ALIGN(32); @@ -623,7 +614,8 @@ void CMenu::_directlaunch(const string &id) strncasecmp(DeviceHandler::Instance()->PathToFSName(path.c_str()), "WBFS", 4) == 0); m_gameList.clear(); - list.GetHeaders(pathlist, m_gameList, m_settingsDir, m_curLanguage, m_DMLgameDir, m_plugin); + Config nullCfg; + list.GetHeaders(pathlist, m_gameList, m_settingsDir, m_curLanguage, m_DMLgameDir, nullCfg); if(m_gameList.size() > 0) { gprintf("Game found on partition #%i\n", i); @@ -651,11 +643,7 @@ void CMenu::_launch(dir_discHdr *hdr) arguments.push_back(path); arguments.push_back(title); arguments.push_back(wiiflow_dol); - char magic[10]; - snprintf(magic,sizeof(magic),"%08x",hdr->hdr.magic); - m_plugin.load(fmt("%s/plugins.ini", m_pluginsDir.c_str())); - _launchHomebrew(fmt("%s/%s", m_pluginsDir.c_str(), m_plugin.getString("GENERAL",magic,"").c_str()), arguments); - m_plugin.save(true); + _launchHomebrew(fmt("%s/%s", m_pluginsDir.c_str(), m_plugin.GetDolName(hdr->hdr.magic)), arguments); return; } else if(hdr->hdr.gc_magic == 0xc2339f3d) @@ -1387,21 +1375,9 @@ void CMenu::_gameSoundThread(CMenu *m) m->m_gamesound_changed = true; return; } - else if(m->m_cf.getHdr()->hdr.magic == 0x46434555) + else if(m->m_cf.getHdr()->hdr.gc_magic == 0x4c4f4c4f) { - m->m_gameSound.Load(nes_ogg, nes_ogg_size, false); - m->m_gamesound_changed = true; - return; - } - else if(m->m_cf.getHdr()->hdr.magic == 0x534e4553) - { - m->m_gameSound.Load(snes_ogg, snes_ogg_size, false); - m->m_gamesound_changed = true; - return; - } - else if(m->m_cf.getHdr()->hdr.magic == 0x56424158) - { - m->m_gameSound.Load(gba_ogg, gba_ogg_size, false); + m->m_gameSound.Load(m->m_plugin.GetBannerSound(m->m_cf.getHdr()->hdr.magic), m->m_plugin.GetBannerSoundSize(), false); m->m_gamesound_changed = true; return; } diff --git a/source/plugin/plugin.cpp b/source/plugin/plugin.cpp new file mode 100644 index 00000000..89d1aca4 --- /dev/null +++ b/source/plugin/plugin.cpp @@ -0,0 +1,97 @@ + +//============================================================================ +// Name : plugin.cpp +// Copyright : 2012 FIX94 +//============================================================================ + +#include +#include +#include +#include +#include "plugin.hpp" +#include "memory/mem2.hpp" +#include "gui/text.hpp" + +void Plugin::init(string m_pluginsDir) +{ + pluginsDir = m_pluginsDir; + //Ready to add plugins + adding = true; +} + +void Plugin::EndAdd() +{ + adding = false; +} + +void Plugin::Cleanup() +{ + for(banner_pos = 0; banner_pos < magicWords.size(); banner_pos++) + MEM2_free(BannerSound[banner_pos]); + BannerSound.clear(); + BannerSoundSize.clear(); + magicWords.clear(); + DolName.clear(); + banner_pos = 0; + pluginsDir.erase(0, pluginsDir.size()); +} + +bool Plugin::AddPlugin(Config &plugin) +{ + if(!adding) + return false; + u32 magic; + sscanf(plugin.getString("PLUGIN","magic","").c_str(), "%08x", &magic); + magicWords.push_back(magic); + DolName.push_back(plugin.getString("PLUGIN","dolFile","")); + + string bannerfilepath = sfmt("%s/%s", pluginsDir.c_str(), plugin.getString("PLUGIN","bannerSound","").c_str()); + ifstream infile; + infile.open(bannerfilepath.c_str(), ios::binary); + if(infile.is_open()) + { + int size; + infile.seekg(0, ios::end); + size = infile.tellg(); + infile.seekg(0, ios::beg); + //Don't free that, otherwise you would delete the sound + char* FileReadBuffer = (char*)MEM2_alloc(size); + infile.read(FileReadBuffer, size); + BannerSound.push_back((u8*)FileReadBuffer); + BannerSoundSize.push_back(size); + return true; + } + else + { + BannerSound.push_back(0); + BannerSoundSize.push_back(0); + } + return false; +} + +u8* Plugin::GetBannerSound(u32 magic) +{ + for(banner_pos = 0; banner_pos < magicWords.size(); banner_pos++) + { + if(magic == magicWords[banner_pos]) + return BannerSound[banner_pos]; + } + return NULL; +} + +u32 Plugin::GetBannerSoundSize() +{ + //We call that directly after GetBannerSound, so no need to search for the magic again + if(BannerSoundSize[banner_pos] > 0) + return BannerSoundSize[banner_pos]; + return 0; +} + +char* Plugin::GetDolName(u32 magic) +{ + char *null = (char*)" "; + for(banner_pos = 0; banner_pos < magicWords.size(); banner_pos++) + if(magic == magicWords[banner_pos]) + return (char*)DolName[banner_pos].c_str(); + return null; +} diff --git a/source/plugin/plugin.hpp b/source/plugin/plugin.hpp new file mode 100644 index 00000000..aa6ebfaf --- /dev/null +++ b/source/plugin/plugin.hpp @@ -0,0 +1,38 @@ + +//============================================================================ +// Name : plugin.hpp +// Copyright : 2012 FIX94 +//============================================================================ + +#ifndef _PLUGIN_HPP_ +#define _PLUGIN_HPP_ + +#include +#include +#include + +#include "config/config.hpp" +#include "safe_vector.hpp" + +using namespace std; + +class Plugin +{ +public: + bool AddPlugin(Config &plugin); + u8* GetBannerSound(u32 magic); + u32 GetBannerSoundSize(); + char* GetDolName(u32 magic); + void init(string); + void Cleanup(); + void EndAdd(); +private: + safe_vector BannerSound; + safe_vector BannerSoundSize; + safe_vector magicWords; + safe_vector DolName; + u8 banner_pos; + string pluginsDir; + bool adding; +}; +#endif