Changed plugin argument system, now you can decide everything,

all previous INIs cant boot any games until you add those lines:
For fceugx, genplusgx, wii64, snes9xgx, vbagx and wiimednafen add:
"arguments={device}:/{path}|{name}|{loader}"
For mplayerce and not64 (havent tested yet) add:
"arguments={device}:/{path}/{name}"
And for scummvm add:
"arguments={name}"
You can also remove the "ReturnLoader" line from the INIs.
Any magicword for scummvm and mplayerce is accepted now, just
make sure in scummvm the "romdir" is still "scummvm.ini".
This commit is contained in:
fix94.1 2012-10-01 19:55:55 +00:00
parent 483b3921f8
commit dd50c080a2
7 changed files with 91 additions and 140 deletions

View File

@ -150,7 +150,7 @@ void CList<dir_discHdr>::GetHeaders(vector<string> pathlist, vector<dir_discHdr>
{
strncpy(tmp.path, (*itr).c_str(), sizeof(tmp.path));
strncpy(tmp.id, "PLUGIN", sizeof(tmp.id));
sscanf(plugin.getString("PLUGIN","coverColor","").c_str(), "%08x", &tmp.casecolor);
tmp.casecolor = strtoul(plugin.getString("PLUGIN","coverColor","").c_str(), NULL, 16);
char tempname[64];
(*itr).assign(&(*itr)[(*itr).find_last_of('/') + 1]);
@ -164,7 +164,7 @@ void CList<dir_discHdr>::GetHeaders(vector<string> pathlist, vector<dir_discHdr>
Asciify(tmp.title);
//gprintf("Found: %ls\n", tmp.title);
sscanf(plugin.getString("PLUGIN","magic","").c_str(), "%08x", &tmp.settings[0]); //Plugin magic
tmp.settings[0] = strtoul(plugin.getString("PLUGIN","magic","").c_str(), NULL, 16); //Plugin magic
tmp.type = TYPE_PLUGIN;
headerlist.push_back(tmp);
break;

View File

@ -116,6 +116,7 @@ int main(int argc, char **argv)
mainMenu->terror("errboot3", L"Could not initialize the DIP module!");
else
{
writeStub();
if(Emulator_boot)
mainMenu->m_Emulator_boot = true;
if(gameid != NULL && strlen(gameid) == 6)

View File

@ -1574,12 +1574,10 @@ void CMenu::_initCF(void)
}
else if(m_gameList[i].type == TYPE_PLUGIN)
{
if(!m_plugin.isScummVM(m_gameList[i].settings[0]))
if(tempname.find(':') != string::npos)
{
if(tempname.empty() || tempname.find_first_of('/') == string::npos)
{
continue;
}
tempname.erase(0, tempname.find_first_of('/')+1);
string dirName = tempname.substr(0, tempname.find_first_of('/')+1);
if (tempname.find_first_of('/') == string::npos)
@ -2295,7 +2293,7 @@ bool CMenu::_loadEmuList()
{
m_plugin.AddPlugin(m_plugin_cfg);
m_gameList.clear();
if(strcasestr(m_plugin_cfg.getString("PLUGIN","romDir","").c_str(), "scummvm.ini") == NULL)
if(m_plugin_cfg.getString("PLUGIN","romDir","").find("scummvm.ini") == string::npos)
{
m_gameList.Load(sfmt("%s:/%s", DeviceName[currentPartition], m_plugin_cfg.getString("PLUGIN","romDir","").c_str()), m_plugin_cfg.getString("PLUGIN","fileTypes","").c_str(), m_cfg.getString("EMULATOR", "lastlanguage", "EN").c_str(), m_plugin_cfg);
for(vector<dir_discHdr>::iterator tmp_itr = m_gameList.begin(); tmp_itr != m_gameList.end(); tmp_itr++)
@ -2520,7 +2518,7 @@ string CMenu::_getId()
}
else if(hdr->type == TYPE_PLUGIN)
{
if(!m_plugin.isScummVM(hdr->settings[0]))
if(tempname.find(':') != string::npos)
{
tempname.erase(0, tempname.find_first_of('/')+1);
string dirName = tempname.substr(0, tempname.find_first_of('/')+1);

View File

@ -788,34 +788,28 @@ void CMenu::_launch(dir_discHdr *hdr)
_launchChannel(hdr);
else if(hdr->type == TYPE_PLUGIN)
{
string title(&hdr->path[string(hdr->path).find_last_of("/")+1]);
string wiiflow_dol(m_dol);
if(strstr(wiiflow_dol.c_str(), "sd:/") == NULL)
wiiflow_dol.erase(3,1);
string path((char*)hdr->path, size_t(strlen((char*)hdr->path) - title.size()));
vector<string> arguments;
gprintf("Game title: %s\n", title.c_str());
if(m_plugin.isMplayerCE(hdr->settings[0]))
arguments = m_plugin.CreateMplayerCEArguments(string(hdr->path).c_str());
else if(strstr(path.c_str(), ":/") != NULL)
string title;
string path(hdr->path);
if(path.find(':') != string::npos)
{
if(strstr(path.c_str(), "sd:/") == NULL)
path.erase(3,1);
arguments.push_back(path);
arguments.push_back(title);
if(m_plugin.UseReturnLoader(hdr->settings[0]))
arguments.push_back(sfmt("%s/WiiFlowLoader.dol",m_pluginsDir.c_str()));
else
arguments.push_back(wiiflow_dol);
m_cfg.setString("EMULATOR", "current_item", title);
path.erase(path.begin(), path.begin() + path.find_first_of('/') + 1);
title = string(path.begin() + path.find_last_of('/') + 1, path.end());
path.erase(path.end() - title.size() - 1, path.end());
}
else
{
arguments.push_back(title);
char gametitle[64];
wcstombs(gametitle, hdr->title, sizeof(gametitle));
m_cfg.setString("EMULATOR", "current_item", gametitle);
wcstombs(gametitle, hdr->title, 63);
title = gametitle;
}
string loader(m_pluginsDir);
if(loader.find("usb") != string::npos)
loader.erase(3,1);
loader.append("/WiiFlowLoader.dol");
m_cfg.setString("EMULATOR", "current_item", title);
string device(currentPartition == 0 ? "sd" :
(DeviceHandle.GetFSType(currentPartition) == PART_FS_NTFS ? "ntfs" : "usb"));
vector<string> arguments = m_plugin.CreateArgs(device, path, title, loader, hdr->settings[0]);
_launchHomebrew(fmt("%s/%s", m_pluginsDir.c_str(), m_plugin.GetDolName(hdr->settings[0])), arguments);
}
else if(hdr->type == TYPE_HOMEBREW)
@ -920,7 +914,6 @@ void CMenu::_launchGC(dir_discHdr *hdr, bool disc)
loadIOS(mainIOS, false);
ShutdownBeforeExit();
DEVO_SetOptions(path.c_str(), currentPartition, id.c_str(), memcard_emu);
writeStub();
DEVO_Boot();
}
else
@ -946,11 +939,12 @@ void CMenu::_launchHomebrew(const char *filepath, vector<string> arguments)
LoadHomebrew(filepath);
AddBootArgument(filepath);
for(u32 i = 0; i < arguments.size(); ++i)
{
gprintf("Argument: %s\n", arguments[i].c_str());
AddBootArgument(arguments[i].c_str());
}
loadIOS(58, false);
ShutdownBeforeExit();
writeStub();
BootHomebrew();
}
@ -1545,7 +1539,7 @@ void CMenu::_gameSoundThread(CMenu *m)
if(m->m_cf.getHdr()->type == TYPE_PLUGIN)
{
m_banner->DeleteBanner();
m->m_gameSound.Load(m->m_plugin.GetBannerSound(m->m_cf.getHdr()->settings[0]), m->m_plugin.GetBannerSoundSize(), false);
m->m_gameSound.Load(m->m_plugin.GetBannerSound(m->m_cf.getHdr()->settings[0]), m->m_plugin.GetBannerSoundSize());
m->m_gamesound_changed = true;
m->m_gameSoundHdr = NULL;
return;

View File

@ -1,7 +1,4 @@
#include "menu.hpp"
#include <string.h>
#include <gccore.h>
#include "defines.h"
extern const u8 btnchannel_png[];
@ -331,15 +328,13 @@ bool CMenu::_Source()
}
if (source == "plugin")
{
if (!show_emu) _showSourceNotice();
if(!show_emu)
_showSourceNotice();
else
{
m_current_view = COVERFLOW_EMU;
imgSelected = true;
u32 sourceMagic;
sscanf(m_source.getString(fmt("BUTTON_%i", i + j), "magic","").c_str(), "%08x", &sourceMagic);
u32 sourceMagic = strtoul(m_source.getString(fmt("BUTTON_%i", i + j), "magic","").c_str(), NULL, 16);
for (u8 k = 0; k < numPlugins; ++k)
{
if (sourceMagic == m_plugin.getPluginMagic(k))

View File

@ -31,11 +31,9 @@
static const string emptyString;
static const string emptyString2("/");
static char* emptyChar = (char*)" ";
u32 ScummVM_magic;
void Plugin::init(string m_pluginsDir)
{
ScummVM_magic = 0;
pluginsDir = m_pluginsDir;
//Ready to add plugins
adding = true;
@ -48,11 +46,8 @@ void Plugin::EndAdd()
void Plugin::Cleanup()
{
for(u8 pos = 0; pos < Plugins.size(); pos++)
{
if(Plugins[pos].BannerSound != NULL)
free(Plugins[pos].BannerSound);
}
Plugins.clear();
adding = true;
}
bool Plugin::AddPlugin(Config &plugin)
@ -61,45 +56,36 @@ bool Plugin::AddPlugin(Config &plugin)
return false;
PluginOptions NewPlugin;
NewPlugin.DolName = plugin.getString("PLUGIN","dolFile","");
NewPlugin.coverFolder = plugin.getString("PLUGIN","coverFolder","");
sscanf(plugin.getString("PLUGIN","magic","").c_str(), "%08x", &NewPlugin.magicWord);
sscanf(plugin.getString("PLUGIN","coverColor","").c_str(), "%08x", &NewPlugin.caseColor);
NewPlugin.ReturnLoader = plugin.getBool("PLUGIN","ReturnLoader");
string PluginName = plugin.getString("PLUGIN","displayname","");
NewPlugin.DolName = plugin.getString(PLUGIN_DOMAIN, "dolFile",emptyChar);
NewPlugin.coverFolder = plugin.getString(PLUGIN_DOMAIN, "coverFolder",emptyChar);
NewPlugin.magicWord = strtoul(plugin.getString(PLUGIN_DOMAIN, "magic",emptyChar).c_str(), NULL, 16);
NewPlugin.caseColor = strtoul(plugin.getString(PLUGIN_DOMAIN, "coverColor",emptyChar).c_str(), NULL, 16);
NewPlugin.Args = plugin.getStrings(PLUGIN_DOMAIN, "arguments", '|');
string PluginName = plugin.getString(PLUGIN_DOMAIN, "displayname",emptyChar);
if(PluginName == emptyString || PluginName == emptyString2)
{
PluginName = NewPlugin.DolName;
PluginName.erase(PluginName.end() - 4, PluginName.end());
}
NewPlugin.DisplayName.fromUTF8(PluginName.c_str());
NewPlugin.consoleCoverID = plugin.getString("PLUGIN","consoleCoverID","");
NewPlugin.consoleCoverID = plugin.getString(PLUGIN_DOMAIN,"consoleCoverID",emptyChar);
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())
const char *bannerfilepath = fmt("%s/%s", pluginsDir.c_str(), plugin.getString(PLUGIN_DOMAIN,"bannerSound",emptyChar).c_str());
FILE *fp = fopen(bannerfilepath, "rb");
if(fp != NULL)
{
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*)malloc(size);
infile.read(FileReadBuffer, size);
NewPlugin.BannerSound = (u8*)FileReadBuffer;
NewPlugin.BannerSoundSize = size;
Plugins.push_back(NewPlugin);
infile.close();
return true;
fseek(fp, 0, SEEK_END);
NewPlugin.BannerSound = string(bannerfilepath);
NewPlugin.BannerSoundSize = ftell(fp);
rewind(fp);
fclose(fp);
}
else
{
NewPlugin.BannerSound = 0;
NewPlugin.BannerSound = std::string();
NewPlugin.BannerSoundSize = 0;
Plugins.push_back(NewPlugin);
}
Plugins.push_back(NewPlugin);
return false;
}
@ -113,17 +99,20 @@ s8 Plugin::GetPluginPosition(u32 magic)
return -1;
}
bool Plugin::UseReturnLoader(u32 magic)
{
if((Plugin_Pos = GetPluginPosition(magic)) >= 0)
return Plugins[Plugin_Pos].ReturnLoader;
return false;
}
u8* Plugin::GetBannerSound(u32 magic)
{
if((Plugin_Pos = GetPluginPosition(magic)) >= 0)
return Plugins[Plugin_Pos].BannerSound;
{
u8 *FileReadBuffer = NULL;
FILE *fp = fopen(Plugins[Plugin_Pos].BannerSound.c_str(), "rb");
if(fp)
{
FileReadBuffer = (u8*)MEM2_alloc(Plugins[Plugin_Pos].BannerSoundSize);
fread(FileReadBuffer, 1, Plugins[Plugin_Pos].BannerSoundSize, fp);
fclose(fp);
}
return FileReadBuffer;
}
return NULL;
}
@ -168,11 +157,11 @@ void Plugin::SetEnablePlugin(Config &cfg, u8 pos, u8 ForceMode)
char PluginMagicWord[9];
snprintf(PluginMagicWord, sizeof(PluginMagicWord), "%08x", Plugins[pos].magicWord);
if(ForceMode == 1)
cfg.setBool("PLUGIN", PluginMagicWord, false);
cfg.setBool(PLUGIN_DOMAIN, PluginMagicWord, false);
else if(ForceMode == 2)
cfg.setBool("PLUGIN", PluginMagicWord, true);
cfg.setBool(PLUGIN_DOMAIN, PluginMagicWord, true);
else
cfg.setBool("PLUGIN", PluginMagicWord, cfg.getBool("PLUGIN", PluginMagicWord) ? false : true);
cfg.setBool(PLUGIN_DOMAIN, PluginMagicWord, cfg.getBool(PLUGIN_DOMAIN, PluginMagicWord) ? false : true);
}
}
@ -184,7 +173,7 @@ vector<bool> Plugin::GetEnabledPlugins(Config &cfg)
for(u8 i = 0; i < Plugins.size(); i++)
{
snprintf(PluginMagicWord, sizeof(PluginMagicWord), "%08x", Plugins[i].magicWord);
if(cfg.getBool("PLUGIN", PluginMagicWord, true))
if(cfg.getBool(PLUGIN_DOMAIN, PluginMagicWord, true))
{
enabledPluginsNumber++;
enabledPlugins.push_back(true);
@ -208,7 +197,6 @@ vector<dir_discHdr> Plugin::ParseScummvmINI(Config &ini, string Device)
vector<dir_discHdr> gameHeader;
if(!ini.loaded())
return gameHeader;
ScummVM_magic = Plugins[Plugins.size()-1].magicWord;
string game(ini.firstDomain());
string GameName;
@ -225,7 +213,7 @@ vector<dir_discHdr> Plugin::ParseScummvmINI(Config &ini, string Device)
continue;
}
memset(&tmp, 0, sizeof(dir_discHdr));
strncpy((char*)tmp.id, "PLUGIN", sizeof(tmp.id));
strncpy((char*)tmp.id, PLUGIN_DOMAIN, sizeof(tmp.id));
tmp.casecolor = Plugins.back().caseColor;
wstringEx tmpString;
tmpString.fromUTF8(GameName.c_str());
@ -240,56 +228,29 @@ vector<dir_discHdr> Plugin::ParseScummvmINI(Config &ini, string Device)
return gameHeader;
}
/* Thanks to dimok for this */
vector<string> Plugin::CreateMplayerCEArguments(const char *filepath)
vector<string> Plugin::CreateArgs(string device, string path, string title, string loader, u32 magic)
{
vector<string> args;
char dst[1024];
int i = 0;
char device[10];
while(filepath[i] != ':')
Plugin_Pos = GetPluginPosition(magic);
if(Plugin_Pos < 0)
return args;
for(vector<string>::iterator arg = Plugins[Plugin_Pos].Args.begin();
arg != Plugins[Plugin_Pos].Args.end(); arg++)
{
device[i] = filepath[i];
device[i+1] = 0;
i++;
string Argument(*arg);
if(Argument.find(PLUGIN_DEV) != string::npos)
Argument.replace(Argument.find(PLUGIN_DEV), strlen(PLUGIN_DEV), device);
if(Argument.find(PLUGIN_PATH) != string::npos)
Argument.replace(Argument.find(PLUGIN_PATH), strlen(PLUGIN_PATH), path);
if(Argument.find(PLUGIN_NAME) != string::npos)
Argument.replace(Argument.find(PLUGIN_NAME), strlen(PLUGIN_NAME), title);
if(Argument.find(PLUGIN_LDR) != string::npos)
Argument.replace(Argument.find(PLUGIN_LDR), strlen(PLUGIN_LDR), loader);
args.push_back(Argument);
}
char * ptr = (char *) &filepath[i];
while(ptr[0] != '/' || ptr[1] == '/')
ptr++;
if(strncmp(DeviceHandle.PathToFSName(filepath), "NTF", 3) == 0)
{
sprintf(dst, "ntfs:%s", ptr);
}
else if(strncmp(device, "usb", 3) == 0)
{
sprintf(dst, "usb:%s", ptr);
}
else
{
sprintf(dst, "%s:%s", device, ptr);
}
args.push_back(dst);
return args;
}
bool Plugin::isMplayerCE(u32 magic)
{
if((Plugin_Pos = GetPluginPosition(magic)) >= 0)
return (Plugins[Plugin_Pos].magicWord == 0x4D504345);
return false;
}
bool Plugin::isScummVM(u32 magic)
{
return (magic == ScummVM_magic);
}
string Plugin::GenerateCoverLink(dir_discHdr gameHeader, string url, Config &Checksums)
{
Plugin_Pos = GetPluginPosition(gameHeader.settings[0]);

View File

@ -31,17 +31,23 @@ using namespace std;
#define TAG_LOC "{loc}"
#define TAG_CONSOLE "{console}"
#define PLUGIN_DOMAIN "PLUGIN"
#define PLUGIN_DEV "{device}"
#define PLUGIN_PATH "{path}"
#define PLUGIN_NAME "{name}"
#define PLUGIN_LDR "{loader}"
struct PluginOptions
{
u8 *BannerSound;
u32 BannerSoundSize;
u32 magicWord;
u32 caseColor;
string DolName;
string coverFolder;
string consoleCoverID;
string BannerSound;
u32 BannerSoundSize;
vector<string> Args;
wstringEx DisplayName;
u32 caseColor;
bool ReturnLoader;
};
class Plugin
@ -58,15 +64,11 @@ public:
bool PluginExist(u8 pos);
void SetEnablePlugin(Config &cfg, u8 pos, u8 ForceMode = 0);
vector<bool> GetEnabledPlugins(Config &cfg);
bool UseReturnLoader(u32 magic);
bool isScummVM(u32 magic);
bool isMplayerCE(u32 magic);
vector<string> CreateMplayerCEArguments(const char *src);
vector<string> CreateArgs(string device, string path, string title, string loader, u32 magic);
void init(string);
void Cleanup();
void EndAdd();
vector<dir_discHdr> ParseScummvmINI(Config &ini, string Device);
private:
s8 GetPluginPosition(u32 magic);
vector<PluginOptions> Plugins;