-added possibility to use own banner sounds for plugins, the

names just need to be added to the ini, see for example here:
http://www.mediafire.com/?o1oxfw8c7icp753
This commit is contained in:
fix94.1 2012-04-10 17:12:38 +00:00
parent b4ca1536b5
commit fc1c81d601
9 changed files with 152 additions and 34 deletions

View File

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

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -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())
{
@ -459,6 +461,8 @@ 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<dir_discHdr> 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<dir_discHdr>::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<dir_discHdr>::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();

View File

@ -7,6 +7,7 @@
#include "safe_vector.hpp"
#include "cachedlist.hpp"
#include "plugin/plugin.hpp"
#include <map>
#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<std::string> m_homebrewArgs;
SmartBuf m_base_font;

View File

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

97
source/plugin/plugin.cpp Normal file
View File

@ -0,0 +1,97 @@
//============================================================================
// Name : plugin.cpp
// Copyright : 2012 FIX94
//============================================================================
#include <gccore.h>
#include <ogcsys.h>
#include <stdio.h>
#include <string.h>
#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;
}

38
source/plugin/plugin.hpp Normal file
View File

@ -0,0 +1,38 @@
//============================================================================
// Name : plugin.hpp
// Copyright : 2012 FIX94
//============================================================================
#ifndef _PLUGIN_HPP_
#define _PLUGIN_HPP_
#include <fstream>
#include <iostream>
#include <string>
#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<u8*> BannerSound;
safe_vector<u32> BannerSoundSize;
safe_vector<u32> magicWords;
safe_vector<string> DolName;
u8 banner_pos;
string pluginsDir;
bool adding;
};
#endif